2 * Copyright (c) 2016, Olivier MATZ <zer0@droids-corp.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the University of California, Berkeley nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #ifndef ECOLI_NODE_EXPR_
29 #define ECOLI_NODE_EXPR_
31 #include <ecoli_node.h>
33 /* XXX remove the _new for all other nodes */
36 * Callback function type for evaluating a variable
39 * On success, this pointer must be set by the user to point
40 * to a user structure describing the evaluated result.
42 * A user-defined context passed to all callback functions, which
43 * can be used to maintain a state or store global information.
45 * The parsed result referencing the variable.
47 * 0 on success (*result must be set), or -errno on error (*result
50 typedef int (*ec_node_expr_eval_var_t)(
51 void **result, void *userctx,
52 const struct ec_parsed *var);
55 * Callback function type for evaluating a prefix-operator
58 * On success, this pointer must be set by the user to point
59 * to a user structure describing the evaluated result.
61 * A user-defined context passed to all callback functions, which
62 * can be used to maintain a state or store global information.
64 * The evaluated expression on which the operation should be applied.
66 * The parsed result referencing the operator.
68 * 0 on success (*result must be set, operand is freed),
69 * or -errno on error (*result is undefined, operand is not freed).
71 typedef int (*ec_node_expr_eval_pre_op_t)(
72 void **result, void *userctx,
74 const struct ec_parsed *operator);
76 typedef int (*ec_node_expr_eval_post_op_t)(
77 void **result, void *userctx,
79 const struct ec_parsed *operator);
81 typedef int (*ec_node_expr_eval_bin_op_t)(
82 void **result, void *userctx,
84 const struct ec_parsed *operator,
87 typedef int (*ec_node_expr_eval_parenthesis_t)(
88 void **result, void *userctx,
89 const struct ec_parsed *open_paren,
90 const struct ec_parsed *close_paren,
93 typedef void (*ec_node_expr_eval_free_t)(
94 void *result, void *userctx);
97 struct ec_node *ec_node_expr(const char *id);
98 int ec_node_expr_set_val_node(struct ec_node *gen_node, struct ec_node *val_node);
99 int ec_node_expr_add_bin_op(struct ec_node *gen_node, struct ec_node *op);
100 int ec_node_expr_add_pre_op(struct ec_node *gen_node, struct ec_node *op);
101 int ec_node_expr_add_post_op(struct ec_node *gen_node, struct ec_node *op);
102 int ec_node_expr_add_parenthesis(struct ec_node *gen_node,
103 struct ec_node *open, struct ec_node *close);
105 struct ec_node_expr_eval_ops {
106 ec_node_expr_eval_var_t eval_var;
107 ec_node_expr_eval_pre_op_t eval_pre_op;
108 ec_node_expr_eval_post_op_t eval_post_op;
109 ec_node_expr_eval_bin_op_t eval_bin_op;
110 ec_node_expr_eval_parenthesis_t eval_parenthesis;
111 ec_node_expr_eval_free_t eval_free;
114 int ec_node_expr_eval(void **result, const struct ec_node *node,
115 struct ec_parsed *parsed, const struct ec_node_expr_eval_ops *ops,