2018-02-10 17:53:07 -08:00
|
|
|
#include "table.h"
|
|
|
|
#include <stdlib.h>
|
2018-02-11 22:50:08 -08:00
|
|
|
#include "util.h"
|
2018-02-10 17:53:07 -08:00
|
|
|
|
2018-02-17 19:08:35 -08:00
|
|
|
void libab_table_init(libab_table* table) {
|
2018-02-10 17:53:07 -08:00
|
|
|
ht_init(&table->table);
|
|
|
|
table->parent = NULL;
|
|
|
|
}
|
2018-02-11 21:09:41 -08:00
|
|
|
libab_table_entry* table_search(libab_table* table, const char* string) {
|
2018-02-10 17:57:24 -08:00
|
|
|
void* to_return = NULL;
|
|
|
|
do {
|
|
|
|
to_return = ht_get(&table->table, string);
|
|
|
|
table = table->parent;
|
|
|
|
} while(table && to_return == NULL);
|
|
|
|
return to_return;
|
|
|
|
}
|
2018-02-11 23:00:07 -08:00
|
|
|
libab_operator* libab_table_search_operator(libab_table* table, const char* string) {
|
|
|
|
libab_table_entry* entry = table_search(table, string);
|
|
|
|
libab_operator* to_return = NULL;
|
2018-02-17 14:00:37 -08:00
|
|
|
if(entry && entry->variant == ENTRY_OP) {
|
2018-02-11 23:00:07 -08:00
|
|
|
to_return = &entry->data_u.op;
|
|
|
|
}
|
|
|
|
return to_return;
|
|
|
|
}
|
|
|
|
libab_function* libab_table_search_function(libab_table* table, const char* string) {
|
|
|
|
libab_table_entry* entry = table_search(table, string);
|
|
|
|
libab_function* to_return = NULL;
|
2018-02-17 14:00:37 -08:00
|
|
|
if(entry && entry->variant == ENTRY_FUN) {
|
2018-02-11 23:00:07 -08:00
|
|
|
to_return = &entry->data_u.function;
|
|
|
|
}
|
|
|
|
return to_return;
|
|
|
|
}
|
2018-02-11 22:50:08 -08:00
|
|
|
libab_result libab_table_put(libab_table* table, const char* string, libab_table_entry* entry) {
|
|
|
|
return libab_convert_ds_result(ht_put(&table->table, string, entry));
|
|
|
|
}
|
2018-02-17 19:08:35 -08:00
|
|
|
void libab_table_free(libab_table* table) {
|
2018-02-10 17:53:07 -08:00
|
|
|
ht_free(&table->table);
|
|
|
|
}
|
2018-02-17 19:53:33 -08:00
|
|
|
void libab_table_entry_free(libab_table_entry* entry) {
|
|
|
|
|
|
|
|
}
|