1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
6 * @defgroup nodes Nodes
10 #ifndef ECOLI_NODE_EXPR_
11 #define ECOLI_NODE_EXPR_
13 #include <ecoli_node.h>
16 * Callback function type for evaluating a variable
19 * On success, this pointer must be set by the user to point
20 * to a user structure describing the evaluated result.
22 * A user-defined context passed to all callback functions, which
23 * can be used to maintain a state or store global information.
25 * The parse result referencing the variable.
27 * 0 on success (*result must be set), or -errno on error (*result
30 typedef int (*ec_node_expr_eval_var_t)(
31 void **result, void *userctx,
32 const struct ec_parse *var);
35 * Callback function type for evaluating a prefix-operator
38 * On success, this pointer must be set by the user to point
39 * to a user structure describing the evaluated result.
41 * A user-defined context passed to all callback functions, which
42 * can be used to maintain a state or store global information.
44 * The evaluated expression on which the operation should be applied.
46 * The parse result referencing the operator.
48 * 0 on success (*result must be set, operand is freed),
49 * or -errno on error (*result is undefined, operand is not freed).
51 typedef int (*ec_node_expr_eval_pre_op_t)(
52 void **result, void *userctx,
54 const struct ec_parse *operator);
56 typedef int (*ec_node_expr_eval_post_op_t)(
57 void **result, void *userctx,
59 const struct ec_parse *operator);
61 typedef int (*ec_node_expr_eval_bin_op_t)(
62 void **result, void *userctx,
64 const struct ec_parse *operator,
67 typedef int (*ec_node_expr_eval_parenthesis_t)(
68 void **result, void *userctx,
69 const struct ec_parse *open_paren,
70 const struct ec_parse *close_paren,
73 typedef void (*ec_node_expr_eval_free_t)(
74 void *result, void *userctx);
77 struct ec_node *ec_node_expr(const char *id);
78 int ec_node_expr_set_val_node(struct ec_node *gen_node, struct ec_node *val_node);
79 int ec_node_expr_add_bin_op(struct ec_node *gen_node, struct ec_node *op);
80 int ec_node_expr_add_pre_op(struct ec_node *gen_node, struct ec_node *op);
81 int ec_node_expr_add_post_op(struct ec_node *gen_node, struct ec_node *op);
82 int ec_node_expr_add_parenthesis(struct ec_node *gen_node,
83 struct ec_node *open, struct ec_node *close);
85 struct ec_node_expr_eval_ops {
86 ec_node_expr_eval_var_t eval_var;
87 ec_node_expr_eval_pre_op_t eval_pre_op;
88 ec_node_expr_eval_post_op_t eval_post_op;
89 ec_node_expr_eval_bin_op_t eval_bin_op;
90 ec_node_expr_eval_parenthesis_t eval_parenthesis;
91 ec_node_expr_eval_free_t eval_free;
94 int ec_node_expr_eval(void **result, const struct ec_node *node,
95 struct ec_parse *parse, const struct ec_node_expr_eval_ops *ops,