X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Fecoli_node_expr_test.c;h=93e33a4e4bbbe07c106dc2f08954fd54887da823;hb=51028779e0a8772091aec5ab96bcf2519cf2f1ad;hp=7f1b44915d5f2446a3037cfe0dae377b12fcf3d5;hpb=7cbb8a1000b85db2a487afd4d17e688b8c0aa756;p=protos%2Flibecoli.git diff --git a/lib/ecoli_node_expr_test.c b/lib/ecoli_node_expr_test.c index 7f1b449..93e33a4 100644 --- a/lib/ecoli_node_expr_test.c +++ b/lib/ecoli_node_expr_test.c @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause - * Copyright (c) 2016, Olivier MATZ + * Copyright 2016, Olivier MATZ */ #include @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include @@ -25,7 +25,7 @@ struct my_eval_result { static int ec_node_expr_test_eval_var(void **result, void *userctx, - const struct ec_parsed *var) + const struct ec_parse *var) { const struct ec_strvec *vec; const struct ec_node *node; @@ -35,17 +35,19 @@ ec_node_expr_test_eval_var(void **result, void *userctx, (void)userctx; /* get parsed string vector, it should contain only one str */ - vec = ec_parsed_strvec(var); - if (ec_strvec_len(vec) != 1) - return -EINVAL; + vec = ec_parse_strvec(var); + if (ec_strvec_len(vec) != 1) { + errno = EINVAL; + return -1; + } - node = ec_parsed_get_node(var); + node = ec_parse_get_node(var); if (ec_node_int_getval(node, ec_strvec_val(vec, 0), &val) < 0) - return -EINVAL; + return -1; eval = ec_malloc(sizeof(*eval)); if (eval == NULL) - return -ENOMEM; + return -1; eval->val = val; EC_LOG(EC_LOG_DEBUG, "eval var %d\n", eval->val); @@ -56,7 +58,7 @@ ec_node_expr_test_eval_var(void **result, void *userctx, static int ec_node_expr_test_eval_pre_op(void **result, void *userctx, void *operand, - const struct ec_parsed *operator) + const struct ec_parse *operator) { const struct ec_strvec *vec; struct my_eval_result *eval = operand;; @@ -64,14 +66,19 @@ ec_node_expr_test_eval_pre_op(void **result, void *userctx, void *operand, (void)userctx; /* get parsed string vector, it should contain only one str */ - vec = ec_parsed_strvec(operator); - if (ec_strvec_len(vec) != 1) - return -EINVAL; + vec = ec_parse_strvec(operator); + if (ec_strvec_len(vec) != 1) { + errno = EINVAL; + return -1; + } - if (!strcmp(ec_strvec_val(vec, 0), "!")) + if (!strcmp(ec_strvec_val(vec, 0), "!")) { eval->val = !eval->val; - else - return -EINVAL; + } else { + errno = EINVAL; + return -1; + } + EC_LOG(EC_LOG_DEBUG, "eval pre_op %d\n", eval->val); *result = eval; @@ -81,7 +88,7 @@ ec_node_expr_test_eval_pre_op(void **result, void *userctx, void *operand, static int ec_node_expr_test_eval_post_op(void **result, void *userctx, void *operand, - const struct ec_parsed *operator) + const struct ec_parse *operator) { const struct ec_strvec *vec; struct my_eval_result *eval = operand;; @@ -89,14 +96,18 @@ ec_node_expr_test_eval_post_op(void **result, void *userctx, void *operand, (void)userctx; /* get parsed string vector, it should contain only one str */ - vec = ec_parsed_strvec(operator); - if (ec_strvec_len(vec) != 1) - return -EINVAL; + vec = ec_parse_strvec(operator); + if (ec_strvec_len(vec) != 1) { + errno = EINVAL; + return -1; + } - if (!strcmp(ec_strvec_val(vec, 0), "^")) + if (!strcmp(ec_strvec_val(vec, 0), "^")) { eval->val = eval->val * eval->val; - else - return -EINVAL; + } else { + errno = EINVAL; + return -1; + } EC_LOG(EC_LOG_DEBUG, "eval post_op %d\n", eval->val); *result = eval; @@ -106,7 +117,7 @@ ec_node_expr_test_eval_post_op(void **result, void *userctx, void *operand, static int ec_node_expr_test_eval_bin_op(void **result, void *userctx, void *operand1, - const struct ec_parsed *operator, void *operand2) + const struct ec_parse *operator, void *operand2) { const struct ec_strvec *vec; @@ -116,16 +127,20 @@ ec_node_expr_test_eval_bin_op(void **result, void *userctx, void *operand1, (void)userctx; /* get parsed string vector, it should contain only one str */ - vec = ec_parsed_strvec(operator); - if (ec_strvec_len(vec) != 1) - return -EINVAL; + vec = ec_parse_strvec(operator); + if (ec_strvec_len(vec) != 1) { + errno = EINVAL; + return -1; + } - if (!strcmp(ec_strvec_val(vec, 0), "+")) + if (!strcmp(ec_strvec_val(vec, 0), "+")) { eval1->val = eval1->val + eval2->val; - else if (!strcmp(ec_strvec_val(vec, 0), "*")) + } else if (!strcmp(ec_strvec_val(vec, 0), "*")) { eval1->val = eval1->val * eval2->val; - else - return -EINVAL; + } else { + errno = EINVAL; + return -1; + } EC_LOG(EC_LOG_DEBUG, "eval bin_op %d\n", eval1->val); ec_free(eval2); @@ -136,8 +151,8 @@ ec_node_expr_test_eval_bin_op(void **result, void *userctx, void *operand1, static int ec_node_expr_test_eval_parenthesis(void **result, void *userctx, - const struct ec_parsed *open_paren, - const struct ec_parsed *close_paren, + const struct ec_parse *open_paren, + const struct ec_parse *close_paren, void *value) { (void)userctx; @@ -170,7 +185,7 @@ static int ec_node_expr_test_eval(struct ec_node *lex_node, const struct ec_node *expr_node, const char *str, int val) { - struct ec_parsed *p; + struct ec_parse *p; void *result; struct my_eval_result *eval; int ret; @@ -180,11 +195,11 @@ static int ec_node_expr_test_eval(struct ec_node *lex_node, return -1; ret = ec_node_expr_eval(&result, expr_node, p, &test_ops, NULL); - ec_parsed_free(p); + ec_parse_free(p); if (ret < 0) return -1; - /* the parsed value is an integer */ + /* the parse value is an integer */ eval = result; assert(eval != NULL);