Lines Matching refs:node
29 expr_init_common(struct expr_node *node, enum expr_node_kind kind)
31 node->kind = kind;
32 node->lhs = NULL;
33 node->own_lhs = 0;
34 memset(&node->u, 0, sizeof(node->u));
38 expr_init_self(struct expr_node *node)
40 expr_init_common(node, EXPR_OP_SELF);
44 expr_init_named(struct expr_node *node,
47 expr_init_common(node, EXPR_OP_NAMED);
48 node->u.name.s = name;
49 node->u.name.own = own_name;
53 expr_init_argno(struct expr_node *node, size_t num)
55 expr_init_common(node, EXPR_OP_ARGNO);
56 node->u.num = num;
60 expr_init_const(struct expr_node *node, struct value *val)
62 expr_init_common(node, EXPR_OP_CONST);
63 node->u.value = *val;
67 expr_init_const_word(struct expr_node *node, long l,
73 expr_init_const(node, &val);
77 expr_init_index(struct expr_node *node,
81 expr_init_common(node, EXPR_OP_INDEX);
82 node->lhs = lhs;
83 node->own_lhs = own_lhs;
84 node->u.node.n = rhs;
85 node->u.node.own = own_rhs;
89 expr_init_up(struct expr_node *node, struct expr_node *lhs, int own_lhs)
92 expr_init_common(node, EXPR_OP_UP);
93 node->lhs = lhs;
94 node->own_lhs = own_lhs;
98 expr_init_cb1(struct expr_node *node,
103 expr_init_common(node, EXPR_OP_CALL1);
104 node->lhs = lhs;
105 node->own_lhs = own_lhs;
106 node->u.call.u.cb1 = cb;
107 node->u.call.data = data;
111 expr_init_cb2(struct expr_node *node,
118 expr_init_common(node, EXPR_OP_CALL2);
119 node->lhs = lhs;
120 node->own_lhs = own_lhs;
121 node->u.call.rhs = rhs;
122 node->u.call.own_rhs = own_rhs;
123 node->u.call.u.cb2 = cb;
124 node->u.call.data = data;
128 release_expr(struct expr_node *node, int own)
131 expr_destroy(node);
132 free(node);
137 expr_destroy(struct expr_node *node)
139 if (node == NULL)
142 switch (node->kind) {
148 value_destroy(&node->u.value);
152 if (node->u.name.own)
153 free((char *)node->u.name.s);
157 release_expr(node->lhs, node->own_lhs);
158 release_expr(node->u.node.n, node->u.node.own);
162 release_expr(node->u.call.rhs, node->u.call.own_rhs);
166 release_expr(node->lhs, node->own_lhs);
170 assert(!"Invalid value of node kind");
175 expr_alloc_and_clone(struct expr_node **retpp, struct expr_node *node, int own)
177 *retpp = node;
180 if (*retpp == NULL || expr_clone(*retpp, node) < 0) {
189 expr_clone(struct expr_node *retp, const struct expr_node *node)
191 *retp = *node;
193 switch (node->kind) {
202 return value_clone(&retp->u.value, &node->u.value);
205 if (node->u.name.own
206 && (retp->u.name.s = strdup(node->u.name.s)) == NULL)
211 if (expr_alloc_and_clone(&nlhs, node->lhs, node->own_lhs) < 0)
214 if (expr_alloc_and_clone(&nrhs, node->u.node.n,
215 node->u.node.own) < 0) {
216 if (nlhs != node->lhs) {
224 retp->u.node.n = nrhs;
228 if (expr_alloc_and_clone(&nrhs, node->u.call.rhs,
229 node->u.call.own_rhs) < 0)
236 if (expr_alloc_and_clone(&nlhs, node->lhs, node->own_lhs) < 0) {
237 if (node->kind == EXPR_OP_CALL2
238 && node->u.call.own_rhs) {
249 assert(!"Invalid value of node kind");
254 expr_is_compile_constant(struct expr_node *node)
256 return node->kind == EXPR_OP_CONST;
260 eval_up(struct expr_node *node, struct value *context,
263 if (expr_eval(node->lhs, context, arguments, ret_value) < 0)
275 eval_cb1(struct expr_node *node, struct value *context,
279 if (expr_eval(node->lhs, context, arguments, &val) < 0)
283 if (node->u.call.u.cb1(ret_value, &val, arguments,
284 node->u.call.data) < 0)
294 eval_cb2(struct expr_node *node, struct value *context,
298 if (expr_eval(node->lhs, context, arguments, &lhs) < 0)
302 if (expr_eval(node->u.call.rhs, context, arguments, &rhs) < 0) {
308 if (node->u.call.u.cb2(ret_value, &lhs, &rhs, arguments,
309 node->u.call.data) < 0)
320 eval_index(struct expr_node *node, struct value *context,
324 if (expr_eval(node->lhs, context, arguments, &lhs) < 0)
328 if (expr_eval_word(node->u.node.n, context, arguments, &l) < 0) {
340 expr_eval(struct expr_node *node, struct value *context,
343 switch (node->kind) {
346 valp = val_dict_get_num(arguments, node->u.num);
353 valp = val_dict_get_name(arguments, node->u.name.s);
364 *ret_value = node->u.value;
368 return eval_index(node, context, arguments, ret_value);
371 return eval_up(node, context, arguments, ret_value);
374 return eval_cb1(node, context, arguments, ret_value);
377 return eval_cb2(node, context, arguments, ret_value);
380 assert(!"Unknown node kind.");
385 expr_eval_word(struct expr_node *node, struct value *context,
389 if (expr_eval(node, context, arguments, &val) < 0)
399 expr_eval_constant(struct expr_node *node, long *valuep)
401 assert(expr_is_compile_constant(node));
402 return expr_eval_word(node, NULL, NULL, valuep);
410 static struct expr_node node;
411 expr_init_self(&node);
412 nodep = &node;