Make table searching functions public to prevent their duplication.
This commit is contained in:
parent
70e0e75d24
commit
48f8d09405
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
36
src/table.c
36
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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user