pass state to completed api
[protos/libecoli.git] / lib / ecoli_node_expr.c
index f80e3ba..78b6755 100644 (file)
@@ -39,6 +39,8 @@
 #include <ecoli_test.h>
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
+#include <ecoli_parsed.h>
+#include <ecoli_completed.h>
 #include <ecoli_node_seq.h>
 #include <ecoli_node_many.h>
 #include <ecoli_node_or.h>
@@ -64,20 +66,22 @@ struct ec_node_expr {
        unsigned int paren_len;
 };
 
-static struct ec_parsed *ec_node_expr_parse(const struct ec_node *gen_node,
-       const struct ec_strvec *strvec)
+static int ec_node_expr_parse(const struct ec_node *gen_node,
+                       struct ec_parsed *state,
+                       const struct ec_strvec *strvec)
 {
        struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
 
-       return ec_node_parse_strvec(node->child, strvec);
+       return ec_node_parse_child(node->child, state, strvec);
 }
 
 static struct ec_completed *ec_node_expr_complete(const struct ec_node *gen_node,
-       const struct ec_strvec *strvec)
+                                               struct ec_parsed *state,
+                                               const struct ec_strvec *strvec)
 {
        struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
 
-       return ec_node_complete_strvec(node->child, strvec);
+       return ec_node_complete_child(node->child, state, strvec);
 }
 
 static void ec_node_expr_free_priv(struct ec_node *gen_node)
@@ -125,12 +129,12 @@ static int ec_node_expr_build(struct ec_node *gen_node)
        /* create the object, we will initialize it later: this is
         * needed because we have a circular dependency */
        ret = -ENOMEM;
-       weak = ec_node_new("weakref", "weak");
+       weak = ec_node("weakref", "weak");
        if (weak == NULL)
                return -1;
 
        /* prefix unary operators */
-       pre_op = ec_node_new("or", "pre-op");
+       pre_op = ec_node("or", "pre-op");
        if (pre_op == NULL)
                goto fail;
        for (i = 0; i < node->pre_ops_len; i++) {
@@ -139,7 +143,7 @@ static int ec_node_expr_build(struct ec_node *gen_node)
        }
 
        /* suffix unary operators */
-       post_op = ec_node_new("or", "post-op");
+       post_op = ec_node("or", "post-op");
        if (post_op == NULL)
                goto fail;
        for (i = 0; i < node->post_ops_len; i++) {
@@ -147,7 +151,7 @@ static int ec_node_expr_build(struct ec_node *gen_node)
                        goto fail;
        }
 
-       post = ec_node_new("or", "post");
+       post = ec_node("or", "post");
        if (post == NULL)
                goto fail;
        if (ec_node_or_add(post, ec_node_clone(node->val_node)) < 0)
@@ -463,12 +467,15 @@ static int merge_results(void *userctx,
                return 0;
        }
 
-       if (x->has_val && x->op == NULL && y->has_val && y->op != NULL) {
-               ret = ops->eval_bin_op(&x->val, userctx, x->val, y->op, y->val);
-               if (ret < 0)
-                       return ret;
+       if (x->has_val && y->has_val && y->op != NULL) {
+               if (y->op_type == BIN_OP) {
+                       ret = ops->eval_bin_op(&x->val, userctx, x->val,
+                                       y->op, y->val);
+                       if (ret < 0)
+                               return ret;
 
-               return 0;
+                       return 0;
+               }
        }
 
        if (x->has_val == 0 && x->op != NULL && y->has_val && y->op == NULL) {
@@ -495,7 +502,7 @@ static int merge_results(void *userctx,
                return 0;
        }
 
-       assert(true); /* we should not get here */
+       assert(false); /* we should not get here */
        return -EINVAL;
 }