index 3bdc5b6c1e5d69d23d96f0175b6eb6ad9136efe5..8533fc705e6467b91840ce97b86cc20a09f14b14 100644 (file)
--- a/src/include/parser/ast.h
+++ b/src/include/parser/ast.h
|| (((n)->type == SDB_AST_TYPE_ITERATOR) \
&& ((SDB_AST_ALL <= SDB_AST_ITER(n)->kind) \
&& (SDB_AST_ITER(n)->kind <= SDB_AST_ANY))))
- SDB_AST_AND = 1000,
- SDB_AST_OR = 1001,
- SDB_AST_NOT = 1002,
-
- SDB_AST_LT = 1010,
- SDB_AST_LE = 1011,
- SDB_AST_EQ = 1012,
- SDB_AST_NE = 1013,
- SDB_AST_GE = 1014,
- SDB_AST_GT = 1015,
- SDB_AST_REGEX = 1016,
- SDB_AST_NREGEX = 1017,
- SDB_AST_ISNULL = 1018,
- SDB_AST_IN = 1019,
+ SDB_AST_AND = 1000,
+ SDB_AST_OR = 1001,
+ SDB_AST_NOT = 1002,
+
+ SDB_AST_LT = 1010,
+ SDB_AST_LE = 1011,
+ SDB_AST_EQ = 1012,
+ SDB_AST_NE = 1013,
+ SDB_AST_GE = 1014,
+ SDB_AST_GT = 1015,
+ SDB_AST_REGEX = 1016,
+ SDB_AST_NREGEX = 1017,
+ SDB_AST_ISNULL = 1018,
+ SDB_AST_ISTRUE = 1019,
+ SDB_AST_ISFALSE = 1020,
+ SDB_AST_IN = 1021,
/* arithmetic expressions */
#define SDB_AST_IS_ARITHMETIC(n) \
|| (((n)->type == SDB_AST_TYPE_OPERATOR) \
&& ((SDB_AST_ADD <= SDB_AST_OP(n)->kind) \
&& (SDB_AST_OP(n)->kind <= SDB_AST_CONCAT))))
- SDB_AST_ADD = 2000,
- SDB_AST_SUB = 2001,
- SDB_AST_MUL = 2002,
- SDB_AST_DIV = 2003,
- SDB_AST_MOD = 2004,
- SDB_AST_CONCAT = 2005,
+ SDB_AST_ADD = 2000,
+ SDB_AST_SUB = 2001,
+ SDB_AST_MUL = 2002,
+ SDB_AST_DIV = 2003,
+ SDB_AST_MOD = 2004,
+ SDB_AST_CONCAT = 2005,
/* iterators */
- SDB_AST_ALL = 3000,
- SDB_AST_ANY = 3001,
+#define SDB_AST_IS_ITERATOR(n) \
+ (((n)->type == SDB_AST_TYPE_ITERATOR) \
+ && ((SDB_AST_ALL <= SDB_AST_ITER(n)->kind) \
+ && (SDB_AST_ITER(n)->kind <= SDB_AST_ANY)))
+ SDB_AST_ALL = 3000,
+ SDB_AST_ANY = 3001,
} sdb_ast_operator_t;
#define SDB_AST_OP_TO_STRING(op) \
: ((op) == SDB_AST_GT) ? "GT" \
: ((op) == SDB_AST_REGEX) ? "REGEX" \
: ((op) == SDB_AST_NREGEX) ? "NREGEX" \
- : ((op) == SDB_AST_ISNULL) ? "ISNULL" \
+ : ((op) == SDB_AST_ISNULL) ? "IS NULL" \
+ : ((op) == SDB_AST_ISTRUE) ? "IS TRUE" \
+ : ((op) == SDB_AST_ISFALSE) ? "IS FALSE" \
: ((op) == SDB_AST_IN) ? "IN" \
: ((op) == SDB_AST_ADD) ? "ADD" \
: ((op) == SDB_AST_SUB) ? "SUB" \
: ((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" \
+ : ((n)->type == SDB_AST_TYPE_LOOKUP) ? "LOOKUP" \
+ : ((n)->type == SDB_AST_TYPE_STORE) ? "STORE" \
+ : ((n)->type == SDB_AST_TYPE_TIMESERIES) ? "TIMESERIES" \
+ : ((n)->type == SDB_AST_TYPE_OPERATOR) \
+ ? SDB_AST_OP_TO_STRING(SDB_AST_OP(n)->kind) \
+ : ((n)->type == SDB_AST_TYPE_ITERATOR) ? "ITERATOR" \
+ : ((n)->type == SDB_AST_TYPE_CONST) ? "CONSTANT" \
+ : ((n)->type == SDB_AST_TYPE_VALUE) ? "VALUE" \
+ : ((n)->type == SDB_AST_TYPE_TYPED) ? "TYPED VALUE" \
+ : "UNKNOWN")
+
/*
* sdb_ast_node_t is the interface for AST nodes. The first field of any
* actual implementation of the interface is of type sdb_ast_node_t to
/* type describes the type of the actual node */
int type;
+
+ /* data-type describes the type of the result value */
+ int data_type;
} sdb_ast_node_t;
#define SDB_AST_NODE(obj) ((sdb_ast_node_t *)(obj))
sdb_ast_node_t *right;
} sdb_ast_op_t;
#define SDB_AST_OP(obj) ((sdb_ast_op_t *)(obj))
+#define SDB_AST_OP_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_OPERATOR, -1 }, -1, NULL, NULL }
/*
* sdb_ast_iter_t represents an iterator.
typedef struct {
sdb_ast_node_t super;
int kind;
- int op;
sdb_ast_node_t *iter;
/* exactly one operand of the expression has to be unset and will be
* filled in by the iterator value */
sdb_ast_node_t *expr;
} sdb_ast_iter_t;
#define SDB_AST_ITER(obj) ((sdb_ast_iter_t *)(obj))
+#define SDB_AST_ITER_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_ITERATOR, -1 }, -1, NULL, NULL }
/*
* sdb_ast_typed_t represents a typed value.
sdb_ast_node_t *expr;
} sdb_ast_typed_t;
#define SDB_AST_TYPED(obj) ((sdb_ast_typed_t *)(obj))
+#define SDB_AST_TYPED_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_TYPED, -1 }, -1, NULL }
/*
* sdb_ast_const_t represents a constant value.
sdb_data_t value;
} sdb_ast_const_t;
#define SDB_AST_CONST(obj) ((sdb_ast_const_t *)(obj))
+#define SDB_AST_CONST_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_CONST, -1 }, SDB_DATA_INIT }
/*
- * sdb_ast_value_t represents an object-specific value: sibling nodes,
+ * sdb_ast_value_t represents an object-specific value:
* attributes, or field values.
*/
typedef struct {
char *name; /* object name; optional */
} sdb_ast_value_t;
#define SDB_AST_VALUE(obj) ((sdb_ast_value_t *)(obj))
+#define SDB_AST_VALUE_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_VALUE, -1 }, -1, NULL }
/*
* sdb_ast_fetch_t represents a FETCH command.
sdb_ast_node_t *filter; /* optional */
} sdb_ast_fetch_t;
#define SDB_AST_FETCH(obj) ((sdb_ast_fetch_t *)(obj))
+#define SDB_AST_FETCH_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_FETCH, -1 }, -1, NULL, NULL, NULL }
/*
* sdb_ast_list_t represents a LIST command.
sdb_ast_node_t *filter; /* optional */
} sdb_ast_list_t;
#define SDB_AST_LIST(obj) ((sdb_ast_list_t *)(obj))
+#define SDB_AST_LIST_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_LIST, -1 }, -1, NULL }
/*
* sdb_ast_lookup_t represents a LOOKUP command.
sdb_ast_node_t *filter; /* optional */
} sdb_ast_lookup_t;
#define SDB_AST_LOOKUP(obj) ((sdb_ast_lookup_t *)(obj))
+#define SDB_AST_LOOKUP_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_LOOKUP, -1 }, -1, NULL, NULL }
/*
* sdb_ast_store_t represents a STORE command.
sdb_data_t value;
} sdb_ast_store_t;
#define SDB_AST_STORE(obj) ((sdb_ast_store_t *)(obj))
+#define SDB_AST_STORE_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_STORE, -1 }, \
+ -1, NULL, -1, NULL, NULL, 0, NULL, NULL, SDB_DATA_INIT }
/*
* sdb_ast_timeseries_t represents a TIMESERIES command.
sdb_time_t end;
} sdb_ast_timeseries_t;
#define SDB_AST_TIMESERIES(obj) ((sdb_ast_timeseries_t *)(obj))
+#define SDB_AST_TIMESERIES_INIT \
+ { { SDB_OBJECT_INIT, SDB_AST_TYPE_TIMESERIES, -1 }, NULL, NULL, 0, 0 }
/*
* AST constructors:
* ownership of the iter and expr nodes.
*/
sdb_ast_node_t *
-sdb_ast_iter_create(int kind, int op,
- sdb_ast_node_t *iter, sdb_ast_node_t *expr);
+sdb_ast_iter_create(int kind, sdb_ast_node_t *iter, sdb_ast_node_t *expr);
/*
* sdb_ast_typed_create: