Add a type specifically to operators.
This commit is contained in:
parent
47a57d66ee
commit
325c9b9ef7
|
@ -67,7 +67,11 @@ struct libab_operator_s {
|
||||||
* Corresponds to token types associated with
|
* Corresponds to token types associated with
|
||||||
* each operator.
|
* 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.
|
* The precedence of the operator.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -21,13 +21,15 @@ void libab_behavior_free(libab_behavior* behavior) {
|
||||||
void libab_operator_init(libab_operator* op, libab_operator_variant variant,
|
void libab_operator_init(libab_operator* op, libab_operator_variant variant,
|
||||||
int precedence, int associativity, libab_ref* type,
|
int precedence, int associativity, libab_ref* type,
|
||||||
libab_function_ptr func) {
|
libab_function_ptr func) {
|
||||||
op->type = variant;
|
op->variant = variant;
|
||||||
op->precedence = precedence;
|
op->precedence = precedence;
|
||||||
op->associativity = associativity;
|
op->associativity = associativity;
|
||||||
|
libab_ref_copy(type, &op->type);
|
||||||
libab_behavior_init_internal(&op->behavior, func);
|
libab_behavior_init_internal(&op->behavior, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
void libab_operator_free(libab_operator* op) {
|
void libab_operator_free(libab_operator* op) {
|
||||||
|
libab_ref_free(&op->type);
|
||||||
libab_behavior_free(&op->behavior);
|
libab_behavior_free(&op->behavior);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ libab_table_entry* libab_table_search(libab_table* table, const char* string) {
|
||||||
#define OP_TYPE_COMPARATOR(NAME, TYPE) \
|
#define OP_TYPE_COMPARATOR(NAME, TYPE) \
|
||||||
int NAME(const void* left, const void* right) { \
|
int NAME(const void* left, const void* right) { \
|
||||||
const libab_table_entry* entry = 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)
|
OP_TYPE_COMPARATOR(libab_table_compare_op_prefix, OPERATOR_PREFIX)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user