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