Code

parser: Convert AST op types to data op types when necessary.
authorSebastian Harl <sh@tokkee.org>
Tue, 5 May 2015 22:15:09 +0000 (00:15 +0200)
committerSebastian Harl <sh@tokkee.org>
Tue, 5 May 2015 22:15:09 +0000 (00:15 +0200)
src/include/parser/ast.h
src/parser/analyzer.c

index 41fb2179e805e5c1bbd9ea1e3a591b1a685735ae..6a86d06890d70d42c4de3773307b3ff04d489677 100644 (file)
@@ -139,6 +139,15 @@ typedef enum {
                : ((op) == SDB_AST_ANY) ? "ANY" \
                : "UNKNOWN")
 
                : ((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" \
 #define SDB_AST_TYPE_TO_STRING(n) \
        (((n)->type == SDB_AST_TYPE_FETCH) ? "FETCH" \
                : ((n)->type == SDB_AST_TYPE_LIST) ? "LIST" \
index 79c99e3e23e159ae8217a7dec323bf946c8d7e9b..7193fea90bf4281eea185cc862c8014b6108430b 100644 (file)
@@ -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;
                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 */
                        op->left->data_type, op->right->data_type);
 
        /* TODO: replace constant arithmetic operations with a constant value */