diff --git a/include/table.h b/include/table.h index 1b88fb8..f7faf69 100644 --- a/include/table.h +++ b/include/table.h @@ -94,6 +94,17 @@ libab_table_entry* libab_table_search(libab_table* table, const char* string); */ libab_operator* libab_table_search_operator(libab_table* table, const char* string, int type); +/** + * Searches for a given string in the table, + * returning the entry that holds it only if it is an operator. + * @param table the table to search. + * @param string the string to search for. + * @param type the type of operator to search for (infix, prefix, postfix) + * @return the entry, or NULL if it was not found. + */ +libab_table_entry* libab_table_search_entry_operator(libab_table* table, + const char* string, + int type); /** * Searches for the given basetype in the table, returning a value * only if it's a basetype. @@ -103,6 +114,15 @@ libab_operator* libab_table_search_operator(libab_table* table, */ libab_basetype* libab_table_search_basetype(libab_table* table, const char* string); +/** + * Searches for the given basetype in the table, returning a table + * entry only if it holds a basetype. + * @param table to table to search. + * @param string the string to search for. + * @return the entry holding the basetype, or NULL if it was not found. + */ +libab_table_entry* libab_table_search_entry_basetype(libab_table* table, + const char* string); /** * Searches for the given value in the table. * @param table the table to search. @@ -112,13 +132,30 @@ libab_basetype* libab_table_search_basetype(libab_table* table, void libab_table_search_value(libab_table* table, const char* string, libab_ref* ref); /** - * Searches for the given type parameter in the talb.e + * Searches for a value with the given name in the table, + * and returns an entry that holds it. + * @param table the table to search. + * @param string the tabe entry key. + * @return the table entry holding the value, or NULL if it was not found. + */ +libab_table_entry* libab_table_search_entry_value(libab_table* table, + const char* string); +/** + * Searches for the given type parameter in the table. * @param table the table to search in. - * @param string the key ot search for. + * @param string the key to search for. * @param ref the reference to store the type into. */ void libab_table_search_type_param(libab_table* table, const char* string, libab_ref* ref); +/** + * Searches for the given type parameter in the table. + * @param table the table to search in. + * @param string the key to search for. + * @return the table entry holding the type parameter, or NULL. + */ +libab_table_entry* libab_table_search_entry_type_param(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. diff --git a/src/table.c b/src/table.c index 0556c47..97a76fe 100644 --- a/src/table.c +++ b/src/table.c @@ -54,6 +54,12 @@ int libab_table_compare_type_param(const void* left, const void* right) { libab_operator* libab_table_search_operator(libab_table* table, const char* string, int type) { + libab_table_entry* entry = + libab_table_search_entry_operator(table, string, type); + return entry ? &entry->data_u.op : NULL; +} +libab_table_entry* libab_table_search_entry_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, @@ -65,37 +71,52 @@ libab_operator* libab_table_search_operator(libab_table* table, entry = libab_table_search_filter(table, string, NULL, libab_table_compare_op_postfix); } - return entry ? &entry->data_u.op : NULL; + return entry; } libab_basetype* libab_table_search_basetype(libab_table* table, const char* string) { - libab_table_entry* entry = libab_table_search_filter( - table, string, NULL, libab_table_compare_basetype); + libab_table_entry* entry = + libab_table_search_entry_basetype(table, string); return entry ? entry->data_u.basetype : NULL; } +libab_table_entry* libab_table_search_entry_basetype(libab_table* table, + const char* string) { + return libab_table_search_filter(table, string, NULL, + libab_table_compare_basetype); +} 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, libab_table_compare_value); + libab_table_entry* entry = + libab_table_search_entry_value(table, string); if (entry) { libab_ref_copy(&entry->data_u.value, ref); } else { libab_ref_null(ref); } } +libab_table_entry* libab_table_search_entry_value(libab_table* table, + const char* string) { + return libab_table_search_filter(table, string, NULL, + libab_table_compare_value); +} void libab_table_search_type_param(libab_table* table, const char* string, libab_ref* ref) { - libab_table_entry* entry = libab_table_search_filter( - table, string, NULL, libab_table_compare_type_param); + libab_table_entry* entry = + libab_table_search_entry_type_param(table, string); if (entry) { libab_ref_copy(&entry->data_u.type_param, ref); } else { libab_ref_null(ref); } } +libab_table_entry* libab_table_search_entry_type_param(libab_table* table, + const char* string) { + return libab_table_search_filter( + table, string, NULL, libab_table_compare_type_param); +} libab_result libab_table_put(libab_table* table, const char* string, libab_table_entry* entry) {