From: Sebastian Harl Date: Wed, 4 Mar 2015 20:13:49 +0000 (+0100) Subject: Allow the left operand of comparison operations to be NULL (initially). X-Git-Tag: sysdb-0.8.0~140 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=64fcd0d638fdfd2ab5845cb7a9d368b8a76b39e9;p=sysdb.git Allow the left operand of comparison operations to be NULL (initially). However, when evaluating the expression, the operand has to be set. We'll use this as a placeholder for inserting values dynamically. --- diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index 2d1b3ca..5aa6915 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -201,6 +201,8 @@ match_iter_array(sdb_store_matcher_t *m, sdb_store_obj_t *obj, int status; + assert(CMP_M(m)->left && CMP_M(m)->right); + if ((ITER_M(m)->m->type < MATCHER_LT) || (MATCHER_NREGEX < ITER_M(m)->m->type)) return 0; @@ -308,6 +310,7 @@ match_cmp(sdb_store_matcher_t *m, sdb_store_obj_t *obj, || (m->type == MATCHER_NE) || (m->type == MATCHER_GE) || (m->type == MATCHER_GT)); + assert(e1 && e2); if (expr_eval2(e1, &v1, e2, &v2, obj, filter)) return 0; @@ -327,6 +330,7 @@ match_in(sdb_store_matcher_t *m, sdb_store_obj_t *obj, int status = 1; assert((m->type == MATCHER_IN) || (m->type == MATCHER_NIN)); + assert(CMP_M(m)->left && CMP_M(m)->right); if (expr_eval2(CMP_M(m)->left, &value, CMP_M(m)->right, &array, obj, filter)) @@ -350,6 +354,7 @@ match_regex(sdb_store_matcher_t *m, sdb_store_obj_t *obj, assert((m->type == MATCHER_REGEX) || (m->type == MATCHER_NREGEX)); + assert(CMP_M(m)->left && CMP_M(m)->right); if (expr_eval2(CMP_M(m)->left, &v, CMP_M(m)->right, ®ex, obj, filter)) return 0; @@ -480,7 +485,7 @@ cmp_matcher_init(sdb_object_t *obj, va_list ap) CMP_M(obj)->right = va_arg(ap, sdb_store_expr_t *); sdb_object_ref(SDB_OBJ(CMP_M(obj)->right)); - if ((! CMP_M(obj)->left) || (! CMP_M(obj)->right)) + if (! CMP_M(obj)->right) return -1; return 0; } /* cmp_matcher_init */ diff --git a/src/frontend/analyzer.c b/src/frontend/analyzer.c index c7a6ee0..62bae1c 100644 --- a/src/frontend/analyzer.c +++ b/src/frontend/analyzer.c @@ -127,7 +127,8 @@ analyze_expr(int context, sdb_store_expr_t *e, sdb_strbuf_t *errbuf) } /* analyze_expr */ static int -analyze_matcher(int context, sdb_store_matcher_t *m, sdb_strbuf_t *errbuf) +analyze_matcher(int context, int parent_type, + sdb_store_matcher_t *m, sdb_strbuf_t *errbuf) { if (! m) return 0; @@ -136,15 +137,15 @@ analyze_matcher(int context, sdb_store_matcher_t *m, sdb_strbuf_t *errbuf) case MATCHER_OR: case MATCHER_AND: assert(OP_M(m)->left && OP_M(m)->right); - if (analyze_matcher(context, OP_M(m)->left, errbuf)) + if (analyze_matcher(context, m->type, OP_M(m)->left, errbuf)) return -1; - if (analyze_matcher(context, OP_M(m)->right, errbuf)) + if (analyze_matcher(context, m->type, OP_M(m)->right, errbuf)) return -1; break; case MATCHER_NOT: assert(UOP_M(m)->op); - if (analyze_matcher(context, UOP_M(m)->op, errbuf)) + if (analyze_matcher(context, m->type, UOP_M(m)->op, errbuf)) return -1; break; @@ -213,7 +214,8 @@ analyze_matcher(int context, sdb_store_matcher_t *m, sdb_strbuf_t *errbuf) return -1; } } - else if (analyze_matcher(ITER_M(m)->type, ITER_M(m)->m, errbuf)) + else if (analyze_matcher(ITER_M(m)->type, m->type, + ITER_M(m)->m, errbuf)) return -1; break; @@ -223,7 +225,15 @@ analyze_matcher(int context, sdb_store_matcher_t *m, sdb_strbuf_t *errbuf) case MATCHER_NE: case MATCHER_GE: case MATCHER_GT: - assert(CMP_M(m)->left && CMP_M(m)->right); + assert(CMP_M(m)->right); + if ((parent_type == MATCHER_ALL) + || (parent_type == MATCHER_ANY)) { + // TODO: assert(! CMP_M(m)->left); + } + else { + assert(CMP_M(m)->left); + } + if (analyze_expr(context, CMP_M(m)->left, errbuf)) return -1; if (analyze_expr(context, CMP_M(m)->right, errbuf)) @@ -365,9 +375,9 @@ sdb_fe_analyze(sdb_conn_node_t *node, sdb_strbuf_t *errbuf) return -1; } - if (analyze_matcher(context, m, errbuf)) + if (analyze_matcher(context, -1, m, errbuf)) status = -1; - if (analyze_matcher(-1, filter, errbuf)) + if (analyze_matcher(-1, -1, filter, errbuf)) status = -1; return status; } /* sdb_fe_analyze */