Code

Allow the left operand of comparison operations to be NULL (initially).
authorSebastian Harl <sh@tokkee.org>
Wed, 4 Mar 2015 20:13:49 +0000 (21:13 +0100)
committerSebastian Harl <sh@tokkee.org>
Wed, 4 Mar 2015 20:13:49 +0000 (21:13 +0100)
However, when evaluating the expression, the operand has to be set. We'll use
this as a placeholder for inserting values dynamically.

src/core/store_lookup.c
src/frontend/analyzer.c

index 2d1b3ca11e5fc895ddf7fca662412e345ba84e32..5aa69152f237576cb4d2995e15c9a3c771b5b976 100644 (file)
@@ -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, &regex, 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 */
index c7a6ee0c6ff547c906a101f6b2509725b1c9dd60..62bae1c134904af8a84ede0d7906912fe3704f3e 100644 (file)
@@ -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 */