diff --git a/CMakeLists.txt b/CMakeLists.txt index 40ac8da..919f0f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ project(libabacus) add_compile_options(-pedantic -Wall) -add_library(abacus STATIC src/lexer.c src/util.c src/table.c src/parser.c src/libabacus.c src/tree.c src/debug.c src/parsetype.c src/reserved.c src/trie.c src/refcount.c src/ref_vec.c src/ref_trie.c src/basetype.c src/type.c src/value.c) +add_library(abacus STATIC src/lexer.c src/util.c src/table.c src/parser.c src/libabacus.c src/tree.c src/debug.c src/parsetype.c src/reserved.c src/trie.c src/refcount.c src/ref_vec.c src/ref_trie.c src/basetype.c src/type.c src/value.c src/custom.c) add_executable(libabacus src/main.c) add_subdirectory(external/liblex) diff --git a/include/custom.h b/include/custom.h index 92ed12c..6db76d7 100644 --- a/include/custom.h +++ b/include/custom.h @@ -76,4 +76,20 @@ typedef struct libab_behavior_s libab_behavior; typedef struct libab_operator_s libab_operator; typedef struct libab_function_s libab_function; +/** + * Frees the given behavior. + * @param behavior the behavior to free. + */ +void libab_behavior_free(libab_behavior* behavior); +/** + * Frees the given operator. + * @param op the operator to free. + */ +void libab_operator_free(libab_operator* op); +/** + * Frees the given function. + * @param fun the function to free. + */ +void libab_function_free(libab_function* fun); + #endif diff --git a/src/custom.c b/src/custom.c new file mode 100644 index 0000000..dc2afae --- /dev/null +++ b/src/custom.c @@ -0,0 +1,13 @@ +#include "custom.h" + +void libab_behavior_free(libab_behavior* behavior) { + libab_parsetype_free_recursive(behavior->type); +} + +void libab_operator_free(libab_operator* op) { + libab_behavior_free(&op->behavior); +} + +void libab_function_free(libab_function* fun) { + libab_behavior_free(&fun->behavior); +} diff --git a/src/table.c b/src/table.c index 6c7f0ec..bb88261 100644 --- a/src/table.c +++ b/src/table.c @@ -69,8 +69,8 @@ void libab_table_free(libab_table* table) { } void libab_table_entry_free(libab_table_entry* entry) { if(entry->variant == ENTRY_OP) { - libab_parsetype_free_recursive(entry->data_u.op.behavior.type); + libab_operator_free(&entry->data_u.op); } else if(entry->variant == ENTRY_FUN) { - libab_parsetype_free_recursive(entry->data_u.function.behavior.type); + libab_function_free(&entry->data_u.function); } }