diff --git a/include/custom.h b/include/custom.h index 2f2115a..df2f5c8 100644 --- a/include/custom.h +++ b/include/custom.h @@ -67,7 +67,11 @@ struct libab_operator_s { * Corresponds to token types associated with * each operator. */ - enum libab_operator_variant_e type; + enum libab_operator_variant_e variant; + /** + * The type of this operator. + */ + libab_ref type; /** * The precedence of the operator. */ diff --git a/src/custom.c b/src/custom.c index bc7312e..cdf241f 100644 --- a/src/custom.c +++ b/src/custom.c @@ -21,13 +21,15 @@ void libab_behavior_free(libab_behavior* behavior) { void libab_operator_init(libab_operator* op, libab_operator_variant variant, int precedence, int associativity, libab_ref* type, libab_function_ptr func) { - op->type = variant; + op->variant = variant; op->precedence = precedence; op->associativity = associativity; + libab_ref_copy(type, &op->type); libab_behavior_init_internal(&op->behavior, func); } void libab_operator_free(libab_operator* op) { + libab_ref_free(&op->type); libab_behavior_free(&op->behavior); } diff --git a/src/table.c b/src/table.c index 3e8a9a8..34f7aa3 100644 --- a/src/table.c +++ b/src/table.c @@ -30,7 +30,7 @@ libab_table_entry* libab_table_search(libab_table* table, const char* string) { #define OP_TYPE_COMPARATOR(NAME, TYPE) \ int NAME(const void* left, const void* right) { \ const libab_table_entry* entry = right; \ - return entry->variant == ENTRY_OP && entry->data_u.op.type == TYPE; \ + return entry->variant == ENTRY_OP && entry->data_u.op.variant == TYPE; \ } OP_TYPE_COMPARATOR(libab_table_compare_op_prefix, OPERATOR_PREFIX)