1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
5 #ifndef ECOLI_NODE_EXPR_
6 #define ECOLI_NODE_EXPR_
8 #include <ecoli_node.h>
10 /* XXX remove the _new for all other nodes */
13 * Callback function type for evaluating a variable
16 * On success, this pointer must be set by the user to point
17 * to a user structure describing the evaluated result.
19 * A user-defined context passed to all callback functions, which
20 * can be used to maintain a state or store global information.
22 * The parsed result referencing the variable.
24 * 0 on success (*result must be set), or -errno on error (*result
27 typedef int (*ec_node_expr_eval_var_t)(
28 void **result, void *userctx,
29 const struct ec_parsed *var);
32 * Callback function type for evaluating a prefix-operator
35 * On success, this pointer must be set by the user to point
36 * to a user structure describing the evaluated result.
38 * A user-defined context passed to all callback functions, which
39 * can be used to maintain a state or store global information.
41 * The evaluated expression on which the operation should be applied.
43 * The parsed result referencing the operator.
45 * 0 on success (*result must be set, operand is freed),
46 * or -errno on error (*result is undefined, operand is not freed).
48 typedef int (*ec_node_expr_eval_pre_op_t)(
49 void **result, void *userctx,
51 const struct ec_parsed *operator);
53 typedef int (*ec_node_expr_eval_post_op_t)(
54 void **result, void *userctx,
56 const struct ec_parsed *operator);
58 typedef int (*ec_node_expr_eval_bin_op_t)(
59 void **result, void *userctx,
61 const struct ec_parsed *operator,
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,
70 typedef void (*ec_node_expr_eval_free_t)(
71 void *result, void *userctx);
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);
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;
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,