Format the code with clang-format.

This commit is contained in:
2018-04-21 14:09:01 -07:00
parent 22ed67f0a4
commit 5d3130d39d
33 changed files with 718 additions and 595 deletions

View File

@@ -1,17 +1,14 @@
#ifndef LIBABACUS_BASETYPE_H
#define LIBABACUS_BASETYPE_H
#include "vec.h"
#include "result.h"
#include "vec.h"
/**
* An enum that represents the various
* types of the basetype parameters.
*/
enum libab_basetype_variant_e {
BT_NAME,
BT_LIST
};
enum libab_basetype_variant_e { BT_NAME, BT_LIST };
/**
* A struct that holds information about the basetype
@@ -58,8 +55,8 @@ typedef struct libab_basetype_s libab_basetype;
* @param n the number of type parameters it has.
* @param params the parameters this basetype accepts.
*/
void libab_basetype_init(libab_basetype* basetype, int n,
const libab_basetype_param params[]);
void libab_basetype_init(libab_basetype* basetype, int n,
const libab_basetype_param params[]);
/**
* Frees the given basetype.
* @param basetype the type to free.

View File

@@ -7,7 +7,7 @@
* A function pointer that is called
* to execute a certain type of function.
*/
typedef void(*libab_function_ptr)();
typedef void (*libab_function_ptr)();
/**
* The variant of the operator that
@@ -22,10 +22,7 @@ enum libab_operator_variant_e {
/**
* The variant of the implementation of a behavior.
*/
enum libab_behavior_variant_e {
BIMPL_INTERNAL,
BIMPL_TREE
};
enum libab_behavior_variant_e { BIMPL_INTERNAL, BIMPL_TREE };
/**
* A struct that represents the implementation of a behavior.

View File

@@ -90,7 +90,8 @@ libab_result libab_lexer_init(libab_lexer* lexer);
* @param lex_into the list which should be populated with matches.
* @return the result of the operation.
*/
libab_result libab_lexer_lex(libab_lexer* lexer, const char* string, ll* lext_into);
libab_result libab_lexer_lex(libab_lexer* lexer, const char* string,
ll* lext_into);
/**
* Releases the memory associated with the given lexer,
* removing all registered patterns from it.

View File

@@ -1,12 +1,12 @@
#ifndef LIBABACUS_H
#define LIBABACUS_H
#include "custom.h"
#include "ht.h"
#include "lexer.h"
#include "table.h"
#include "parser.h"
#include "result.h"
#include "custom.h"
#include "table.h"
/**
* The main struct of libabacus,
@@ -50,7 +50,10 @@ libab_result libab_init(libab* ab);
* @param func the function that describes the functionality of the operator.
* @return the result of the initialization.
*/
libab_result libab_register_operator_infix(libab* ab, const char* op, int precedence, int associativity, libab_ref* type, libab_function_ptr func);
libab_result libab_register_operator_infix(libab* ab, const char* op,
int precedence, int associativity,
libab_ref* type,
libab_function_ptr func);
/**
* Registers an operation with libabacus that appears
* before its operand.
@@ -60,7 +63,9 @@ libab_result libab_register_operator_infix(libab* ab, const char* op, int preced
* @param func the function that describes the functionality of the operator.
* @return the result of the registration.
*/
libab_result libab_register_operator_prefix(libab* ab, const char* op, libab_ref* type, libab_function_ptr func);
libab_result libab_register_operator_prefix(libab* ab, const char* op,
libab_ref* type,
libab_function_ptr func);
/**
* Registers an operation with libabacus that appears
* after its operand.
@@ -70,7 +75,9 @@ libab_result libab_register_operator_prefix(libab* ab, const char* op, libab_ref
* @param func the function that describes the functionality of the operator.
* @return the result of the registration.
*/
libab_result libab_register_operator_postfix(libab* ab, const char* op, libab_ref* type, libab_function_ptr func);
libab_result libab_register_operator_postfix(libab* ab, const char* op,
libab_ref* type,
libab_function_ptr func);
/**
* Registers a function with libabacus.
@@ -80,7 +87,8 @@ libab_result libab_register_operator_postfix(libab* ab, const char* op, libab_re
* @param func the function that describes the functionality of the function.
* @return the result of the registration.
*/
libab_result libab_register_function(libab* ab, const char* name, libab_ref* type, libab_function_ptr func);
libab_result libab_register_function(libab* ab, const char* name,
libab_ref* type, libab_function_ptr func);
/**
* Registers a base type with abacus.
* @param ab the libabacus instance used to keep state.
@@ -88,7 +96,8 @@ libab_result libab_register_function(libab* ab, const char* name, libab_ref* typ
* @param basetype the basetype to register.
* @return the result of the registration.
*/
libab_result libab_register_basetype(libab* ab, const char* name, libab_basetype* basetype);
libab_result libab_register_basetype(libab* ab, const char* name,
libab_basetype* basetype);
/**
* Constructs and resolves a parse type, similarly to how it's done in the
* parser.

View File

@@ -1,10 +1,10 @@
#ifndef LIBABACUS_PARSER_H
#define LIBABACUS_PARSER_H
#include "table.h"
#include "ll.h"
#include "tree.h"
#include "parsetype.h"
#include "table.h"
#include "tree.h"
/**
* The parser that is used by libabacus
@@ -31,9 +31,9 @@ void libab_parser_init(libab_parser* parser, libab_table* table);
* @param store_into tree pointer to store the new data into.
*/
libab_result libab_parser_parse(libab_parser* parser, ll* tokens,
const char* string, libab_tree** store_into);
const char* string, libab_tree** store_into);
libab_result libab_parser_parse_type(libab_parser* parser, ll* tokens,
const char* string, libab_ref* store_into);
const char* string, libab_ref* store_into);
/**
* Releases the resources allocated by the parser.
* @param parser the parser to release.

View File

@@ -1,9 +1,9 @@
#ifndef LIBABACUS_PARSETYPE_H
#define LIBABACUS_PARSETYPE_H
#include "result.h"
#include "ref_vec.h"
#include "basetype.h"
#include "ref_vec.h"
#include "result.h"
#define LIBABACUS_TYPE_F_PARENT (1)
#define LIBABACUS_TYPE_F_PLACE (1 << 1)

View File

@@ -62,14 +62,16 @@ void libab_ref_trie_init(libab_ref_trie* trie);
* @param ref the reference to insert.
* @return the result of the insertion.
*/
libab_result libab_ref_trie_put(libab_ref_trie* trie, const char* key, libab_ref* ref);
libab_result libab_ref_trie_put(libab_ref_trie* trie, const char* key,
libab_ref* ref);
/**
* Retreives a reference under the given key in the trie.
* @param trie the trie to retreive from.
* @param key the key to look under.
* @return a reference stored under the given key. This can be a NULL reference.
*/
const libab_ref* libab_ref_trie_get(const libab_ref_trie* trie, const char* key);
const libab_ref* libab_ref_trie_get(const libab_ref_trie* trie,
const char* key);
/**
* Releases the trie, decrementing the refcounts of all
* the values stored inside.

View File

@@ -1,8 +1,8 @@
#ifndef LIBABACUS_REF_VEC_H
#define LIBABACUS_REF_VEC_H
#include "result.h"
#include "refcount.h"
#include "result.h"
#include <stdlib.h>
#define LIBABACUS_REF_VEC_INITIAL_SIZE 4
@@ -50,10 +50,11 @@ libab_result libab_ref_vec_insert(libab_ref_vec* vec, libab_ref* data);
* @param free_func the function called to release the value (besides free)
* @return the result of the insertion.
*/
libab_result libab_ref_vec_insert_value(libab_ref_vec* vec, void* data, void (*free_func)(void*));
libab_result libab_ref_vec_insert_value(libab_ref_vec* vec, void* data,
void (*free_func)(void*));
/**
* Returns the value at the given index in the vector, or null or the value doesn't
* exist.
* Returns the value at the given index in the vector, or null or the value
* doesn't exist.
* @param vec the vector to get a value from.
* @param index the index to look at.
* @return the reference stored at the given index.

View File

@@ -53,10 +53,12 @@ typedef struct libab_ref_count_s libab_ref_count;
* Creates a new referene, using the given data and free function.
* @param ref the reference to initialize with the given data.
* @param data the data to reference count.
* @param free_func the function to use to realease the data when refcount reaches 0.
* @param free_func the function to use to realease the data when refcount
* reaches 0.
* @return the result of the construction of the reference.
*/
libab_result libab_ref_new(libab_ref* ref, void* data, void (*free_func)(void* data));
libab_result libab_ref_new(libab_ref* ref, void* data,
void (*free_func)(void* data));
/**
* Creates a reference to NULL. This does
* not require a memory allocation.

View File

@@ -1,10 +1,10 @@
#ifndef LIBABACUS_RESERVED_H
#define LIBABACUS_RESERVED_H
#include "result.h"
#include "parsetype.h"
#include "tree.h"
#include "libabacus.h"
#include "parsetype.h"
#include "result.h"
#include "tree.h"
/**
* Struct that represents a reserved operator that contains
@@ -31,7 +31,8 @@ typedef struct libab_reserved_operator_s libab_reserved_operator;
* Attempts to find a reserved operator with the given name.
* This function operates under the assumption that there are
* few reserved operators in libabacus. As such, it does effectively
* a polynomial time search - strcmp for every element until the operator is found.
* a polynomial time search - strcmp for every element until the operator is
* found.
* @param name the name to search for.
* @return the reserved operator, if it is found.
*/

View File

@@ -1,10 +1,10 @@
#ifndef LIBABACUS_TABLE_H
#define LIBABACUS_TABLE_H
#include "result.h"
#include "custom.h"
#include "trie.h"
#include "basetype.h"
#include "custom.h"
#include "result.h"
#include "trie.h"
/**
* A struct that represents a structure
@@ -72,7 +72,9 @@ void libab_table_init(libab_table* table);
* @param compare the comparison function to use.
* @return the table entry, or NULL if an entry was not found.
*/
libab_table_entry* libab_table_search_filter(libab_table* table, const char* string, void* data, compare_func compare);
libab_table_entry* libab_table_search_filter(libab_table* table,
const char* string, void* data,
compare_func compare);
/**
* Searches for the given string in the table.
* @param table the table to search.
@@ -88,7 +90,8 @@ libab_table_entry* libab_table_search(libab_table* table, const char* string);
* @param type the type of operator to search for (infix, prefix, postfix)
* @return the found operator, or NULL if it was not found.
*/
libab_operator* libab_table_search_operator(libab_table* table, const char* string, int type);
libab_operator* libab_table_search_operator(libab_table* table,
const char* string, int type);
/**
* Searches for the given string in the table, returning a value only
* if it is a function.
@@ -96,7 +99,8 @@ libab_operator* libab_table_search_operator(libab_table* table, const char* stri
* @param string the string to search for.
* @return the found function, or NULL if it was not found.
*/
libab_function* libab_table_search_function(libab_table* table, const char* string);
libab_function* libab_table_search_function(libab_table* table,
const char* string);
/**
* Searches for the given basetype in the table, returning a value
* only if it's a basetype.
@@ -104,7 +108,8 @@ libab_function* libab_table_search_function(libab_table* table, const char* stri
* @param string the string to search for.
* @return the found basetype, or NULL if it was not found.
*/
libab_basetype* libab_table_search_basetype(libab_table* table, const char* string);
libab_basetype* libab_table_search_basetype(libab_table* table,
const char* string);
/**
* Stores the given entry in the table under the given key.
* @param table the table to store the entry into.
@@ -112,7 +117,8 @@ libab_basetype* libab_table_search_basetype(libab_table* table, const char* stri
* @param entry the new entry to put into the table.
* @return the result of the insertion, which could be LIBAB_MALLOC.
*/
libab_result libab_table_put(libab_table* table, const char* string, libab_table_entry* entry);
libab_result libab_table_put(libab_table* table, const char* string,
libab_table_entry* entry);
/**
* Frees the resources allocated by the
* given table.

View File

@@ -1,8 +1,8 @@
#ifndef LIBABACUS_TREE_H
#define LIBABACUS_TREE_H
#include "result.h"
#include "parsetype.h"
#include "result.h"
#include "vec.h"
/**
@@ -115,7 +115,7 @@ int libab_tree_has_vector(libab_tree_variant var);
/**
* Frees the given tree recursively,
* deleting the children first and the moving on
* to the parents.
* to the parents.
* @param tree the tree to free.
*/
void libab_tree_free_recursive(libab_tree* tree);

View File

@@ -39,12 +39,12 @@ struct libab_trie_s {
/**
* The first search node in this trie.
*/
struct libab_trie_node_s* head;
struct libab_trie_node_s* head;
/**
* The empty list returned if no value is found.
* Note that existing nodes return their own linked
* list of values, even if empty. However, for keys
* that don't exist as prefixes in the trie,
* that don't exist as prefixes in the trie,
* this list is returned to maintain consistency:
* a list is always returned containing the values
* of the trie associated with the given key.
@@ -58,7 +58,8 @@ typedef struct libab_trie_node_s libab_trie_node;
void libab_trie_init(libab_trie* trie);
libab_result libab_trie_put(libab_trie* trie, const char* key, void* value);
const ll* libab_trie_get(const libab_trie* trie, const char* key);
int libab_trie_foreach(const libab_trie* trie, void* data, compare_func compare, foreach_func foreach);
int libab_trie_foreach(const libab_trie* trie, void* data, compare_func compare,
foreach_func foreach);
void libab_trie_free(libab_trie* trie);
#endif

View File

@@ -3,8 +3,8 @@
#include "libds.h"
#include "liblex.h"
#include "result.h"
#include "parsetype.h"
#include "result.h"
#include "table.h"
#include <string.h>
@@ -21,15 +21,16 @@ libab_result libab_convert_lex_result(liblex_result to_convert);
*/
libab_result libab_convert_ds_result(libds_result to_convert);
/**
* Copies a range of the given string into a new, null-terminated string allocated
* on the heap.
* Copies a range of the given string into a new, null-terminated string
* allocated on the heap.
* @param destination the pointer to populate with the newly created string.
* @param source the source from which to pull character information from.
* @param from the index (inclusive) at which to begin copying.
* @param to the index (exclusive) at which to end copying.
* @return the result of the operation.
*/
libab_result libab_copy_string_range(char** destination, const char* source, size_t from, size_t to);
libab_result libab_copy_string_range(char** destination, const char* source,
size_t from, size_t to);
/**
* Copies the given string, starting at 0 and copying length bytes.
* @param destination the pointer to populate with the newly created string.
@@ -37,7 +38,8 @@ libab_result libab_copy_string_range(char** destination, const char* source, siz
* @param length the number of bytes to copy.
* @return the result of the operation.
*/
libab_result libab_copy_string_size(char** destination, const char* source, size_t length);
libab_result libab_copy_string_size(char** destination, const char* source,
size_t length);
/**
* Copies the entire string into a null-terminated string allocated
* on the heap.
@@ -52,6 +54,7 @@ libab_result libab_copy_string(char** destination, const char* source);
* @param to_resolve the parsetype to resolve.
* @param scope the scope to use for resolving the type info.
*/
libab_result libab_resolve_parsetype(libab_parsetype* to_resolve, libab_table* scope);
libab_result libab_resolve_parsetype(libab_parsetype* to_resolve,
libab_table* scope);
#endif

View File

@@ -1,8 +1,8 @@
#ifndef LIBABACUS_VALUE_H
#define LIBABACUS_VALUE_H
#include "result.h"
#include "refcount.h"
#include "result.h"
/**
* A struct that represents a value.