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