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>
11 * Callback function type for evaluating a variable
14 * On success, this pointer must be set by the user to point
15 * to a user structure describing the evaluated result.
17 * A user-defined context passed to all callback functions, which
18 * can be used to maintain a state or store global information.
20 * The parse result referencing the variable.
22 * 0 on success (*result must be set), or -errno on error (*result
25 typedef int (*ec_node_expr_eval_var_t)(
26 void **result, void *userctx,
27 const struct ec_parse *var);
30 * Callback function type for evaluating a prefix-operator
33 * On success, this pointer must be set by the user to point
34 * to a user structure describing the evaluated result.
36 * A user-defined context passed to all callback functions, which
37 * can be used to maintain a state or store global information.
39 * The evaluated expression on which the operation should be applied.
41 * The parse result referencing the operator.
43 * 0 on success (*result must be set, operand is freed),
44 * or -errno on error (*result is undefined, operand is not freed).
46 typedef int (*ec_node_expr_eval_pre_op_t)(
47 void **result, void *userctx,
49 const struct ec_parse *operator);
51 typedef int (*ec_node_expr_eval_post_op_t)(
52 void **result, void *userctx,
54 const struct ec_parse *operator);
56 typedef int (*ec_node_expr_eval_bin_op_t)(
57 void **result, void *userctx,
59 const struct ec_parse *operator,
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,
68 typedef void (*ec_node_expr_eval_free_t)(
69 void *result, void *userctx);
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);
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;
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,