diff --git a/include/table.h b/include/table.h index 95490df..5896a08 100644 --- a/include/table.h +++ b/include/table.h @@ -131,6 +131,26 @@ void libab_table_set_parent(libab_table* table, libab_ref* parent); * @param table the table to free. */ void libab_table_free(libab_table* table); +/** + * Comparison function used to search the table for a prefix operator. + */ +int libab_table_compare_op_prefix(const void* left, const void* right); +/** + * Comparison function used to search the table for a infix operator. + */ +int libab_table_compare_op_infix(const void* left, const void* right); +/** + * Comparison function used to search the table for a postfix operator. + */ +int libab_table_compare_op_postfix(const void* left, const void* right); +/** + * Comparison function used to search the table for a value. + */ +int libab_table_compare_value(const void* left, const void* right); +/** + * Comparison function used to search the table for a basetype. + */ +int libab_table_compare_basetype(const void* left, const void* right); /** * Frees the given table entry. * @param entry the entry to free. diff --git a/src/libabacus.c b/src/libabacus.c index 4874c04..fade17f 100644 --- a/src/libabacus.c +++ b/src/libabacus.c @@ -180,11 +180,6 @@ libab_result _create_value_function_list(libab_ref* into, libab_ref* type) { return result; } -static int _table_compare_value(const void* left, const void* right) { - const libab_table_entry* entry = right; - return entry->variant == ENTRY_VALUE; -} - libab_result _libab_register_function_existing(libab* ab, libab_table_entry* entry, libab_ref* function_val) { libab_value* old_value; libab_parsetype* old_type; @@ -245,7 +240,7 @@ libab_result libab_register_function(libab* ab, const char* name, if(result == LIBAB_SUCCESS) { existing_entry = - libab_table_search_filter(libab_ref_get(&ab->table), name, NULL, _table_compare_value); + libab_table_search_filter(libab_ref_get(&ab->table), name, NULL, libab_table_compare_value); if(existing_entry) { result = _libab_register_function_existing(ab, existing_entry, &function_value); } else { diff --git a/src/table.c b/src/table.c index 8e2945f..3e8a9a8 100644 --- a/src/table.c +++ b/src/table.c @@ -33,48 +33,48 @@ libab_table_entry* libab_table_search(libab_table* table, const char* string) { return entry->variant == ENTRY_OP && entry->data_u.op.type == TYPE; \ } -OP_TYPE_COMPARATOR(_table_compare_prefix, OPERATOR_PREFIX) -OP_TYPE_COMPARATOR(_table_compare_infix, OPERATOR_INFIX) -OP_TYPE_COMPARATOR(_table_compare_postfix, OPERATOR_POSTFIX) +OP_TYPE_COMPARATOR(libab_table_compare_op_prefix, OPERATOR_PREFIX) +OP_TYPE_COMPARATOR(libab_table_compare_op_infix, OPERATOR_INFIX) +OP_TYPE_COMPARATOR(libab_table_compare_op_postfix, OPERATOR_POSTFIX) + +int libab_table_compare_value(const void* left, const void* right) { + const libab_table_entry* entry = right; + return entry->variant == ENTRY_VALUE; +} + +int libab_table_compare_basetype(const void* left, const void* right) { + const libab_table_entry* entry = right; + return entry->variant == ENTRY_BASETYPE; +} libab_operator* libab_table_search_operator(libab_table* table, const char* string, int type) { libab_table_entry* entry = NULL; if (type == OPERATOR_PREFIX) { entry = libab_table_search_filter(table, string, NULL, - _table_compare_prefix); + libab_table_compare_op_prefix); } else if (type == OPERATOR_INFIX) { entry = libab_table_search_filter(table, string, NULL, - _table_compare_infix); + libab_table_compare_op_infix); } else if (type == OPERATOR_PREFIX) { entry = libab_table_search_filter(table, string, NULL, - _table_compare_postfix); + libab_table_compare_op_postfix); } return entry ? &entry->data_u.op : NULL; } -int _table_compare_basetype(const void* left, const void* right) { - const libab_table_entry* entry = right; - return entry->variant == ENTRY_BASETYPE; -} - libab_basetype* libab_table_search_basetype(libab_table* table, const char* string) { libab_table_entry* entry = - libab_table_search_filter(table, string, NULL, _table_compare_basetype); + libab_table_search_filter(table, string, NULL, libab_table_compare_basetype); return entry ? entry->data_u.basetype : NULL; } -int _table_compare_value(const void* left, const void* right) { - const libab_table_entry* entry = right; - return entry->variant == ENTRY_VALUE; -} - void libab_table_search_value(libab_table* table, const char* string, libab_ref* ref) { libab_table_entry* entry = - libab_table_search_filter(table, string, NULL, _table_compare_value); + libab_table_search_filter(table, string, NULL, libab_table_compare_value); if(entry) { libab_ref_copy(&entry->data_u.value, ref); } else {