add ec_node_bypass
[protos/libecoli.git] / include / ecoli_node_expr.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
3  */
4
5 #ifndef ECOLI_NODE_EXPR_
6 #define ECOLI_NODE_EXPR_
7
8 #include <ecoli_node.h>
9
10 /**
11  * Callback function type for evaluating a variable
12  *
13  * @param result
14  *   On success, this pointer must be set by the user to point
15  *   to a user structure describing the evaluated result.
16  * @param userctx
17  *   A user-defined context passed to all callback functions, which
18  *   can be used to maintain a state or store global information.
19  * @param var
20  *   The parse result referencing the variable.
21  * @return
22  *   0 on success (*result must be set), or -errno on error (*result
23  *   is undefined).
24  */
25 typedef int (*ec_node_expr_eval_var_t)(
26         void **result, void *userctx,
27         const struct ec_parse *var);
28
29 /**
30  * Callback function type for evaluating a prefix-operator
31  *
32  * @param result
33  *   On success, this pointer must be set by the user to point
34  *   to a user structure describing the evaluated result.
35  * @param userctx
36  *   A user-defined context passed to all callback functions, which
37  *   can be used to maintain a state or store global information.
38  * @param operand
39  *   The evaluated expression on which the operation should be applied.
40  * @param var
41  *   The parse result referencing the operator.
42  * @return
43  *   0 on success (*result must be set, operand is freed),
44  *   or -errno on error (*result is undefined, operand is not freed).
45  */
46 typedef int (*ec_node_expr_eval_pre_op_t)(
47         void **result, void *userctx,
48         void *operand,
49         const struct ec_parse *operator);
50
51 typedef int (*ec_node_expr_eval_post_op_t)(
52         void **result, void *userctx,
53         void *operand,
54         const struct ec_parse *operator);
55
56 typedef int (*ec_node_expr_eval_bin_op_t)(
57         void **result, void *userctx,
58         void *operand1,
59         const struct ec_parse *operator,
60         void *operand2);
61
62 typedef int (*ec_node_expr_eval_parenthesis_t)(
63         void **result, void *userctx,
64         const struct ec_parse *open_paren,
65         const struct ec_parse *close_paren,
66         void * value);
67
68 typedef void (*ec_node_expr_eval_free_t)(
69         void *result, void *userctx);
70
71
72 struct ec_node *ec_node_expr(const char *id);
73 int ec_node_expr_set_val_node(struct ec_node *gen_node, struct ec_node *val_node);
74 int ec_node_expr_add_bin_op(struct ec_node *gen_node, struct ec_node *op);
75 int ec_node_expr_add_pre_op(struct ec_node *gen_node, struct ec_node *op);
76 int ec_node_expr_add_post_op(struct ec_node *gen_node, struct ec_node *op);
77 int ec_node_expr_add_parenthesis(struct ec_node *gen_node,
78         struct ec_node *open, struct ec_node *close);
79
80 struct ec_node_expr_eval_ops {
81         ec_node_expr_eval_var_t eval_var;
82         ec_node_expr_eval_pre_op_t eval_pre_op;
83         ec_node_expr_eval_post_op_t eval_post_op;
84         ec_node_expr_eval_bin_op_t eval_bin_op;
85         ec_node_expr_eval_parenthesis_t eval_parenthesis;
86         ec_node_expr_eval_free_t eval_free;
87 };
88
89 int ec_node_expr_eval(void **result, const struct ec_node *node,
90         struct ec_parse *parse, const struct ec_node_expr_eval_ops *ops,
91         void *userctx);
92
93 #endif