From: Sebastian Harl Date: Tue, 5 May 2015 22:15:09 +0000 (+0200) Subject: parser: Convert AST op types to data op types when necessary. X-Git-Tag: sysdb-0.8.0~106 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a2dd816b36b96cbbb1df882912f43e60ee7879ff;p=sysdb.git parser: Convert AST op types to data op types when necessary. --- diff --git a/src/include/parser/ast.h b/src/include/parser/ast.h index 41fb217..6a86d06 100644 --- a/src/include/parser/ast.h +++ b/src/include/parser/ast.h @@ -139,6 +139,15 @@ typedef enum { : ((op) == SDB_AST_ANY) ? "ANY" \ : "UNKNOWN") +#define SDB_AST_OP_TO_DATA_OP(op) \ + (((op) == SDB_AST_ADD) ? SDB_DATA_ADD \ + : ((op) == SDB_AST_SUB) ? SDB_DATA_SUB \ + : ((op) == SDB_AST_MUL) ? SDB_DATA_MUL \ + : ((op) == SDB_AST_DIV) ? SDB_DATA_DIV \ + : ((op) == SDB_AST_MOD) ? SDB_DATA_MOD \ + : ((op) == SDB_AST_CONCAT) ? SDB_DATA_CONCAT \ + : -1) + #define SDB_AST_TYPE_TO_STRING(n) \ (((n)->type == SDB_AST_TYPE_FETCH) ? "FETCH" \ : ((n)->type == SDB_AST_TYPE_LIST) ? "LIST" \ diff --git a/src/parser/analyzer.c b/src/parser/analyzer.c index 79c99e3..7193fea 100644 --- a/src/parser/analyzer.c +++ b/src/parser/analyzer.c @@ -105,7 +105,7 @@ analyze_arith(int context, sdb_ast_op_t *op, sdb_strbuf_t *errbuf) return -1; if (analyze_node(context, op->right, errbuf)) return -1; - SDB_AST_NODE(op)->data_type = sdb_data_expr_type(op->kind, + SDB_AST_NODE(op)->data_type = sdb_data_expr_type(SDB_AST_OP_TO_DATA_OP(op->kind), op->left->data_type, op->right->data_type); /* TODO: replace constant arithmetic operations with a constant value */