Skip to content

Commit 69a4678

Browse files
committed
* macros
1 parent 71a53e8 commit 69a4678

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

node_call.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct _call {
1616
struct ulist nodes; ///< Nodes stack. struct node*
1717
struct node *args[MACRO_MAX_ARGS_NUM];
1818
int nn_idx;
19+
int arg_idx;
1920
};
2021

2122
static int _call_macro_visit(struct node *n, int lvl, void *d) {
@@ -31,15 +32,23 @@ static int _call_macro_visit(struct node *n, int lvl, void *d) {
3132
}
3233

3334
// Macro arg
34-
if (n->value[0] == '&' && n->value[1] == '\0' && n->child && !n->child->next) {
35+
if (n->value[0] == '&' && n->value[1] == '\0') {
3536
int rc = 0;
36-
int idx = utils_strtol(n->child->value, 10, &rc);
37-
if (rc || idx < 1 || idx >= MACRO_MAX_ARGS_NUM) {
38-
node_fatal(rc, n, "Invalid macro arg index: %d", idx);
39-
return 0;
37+
int idx;
38+
39+
if (n->child) {
40+
idx = utils_strtol(n->child->value, 10, &rc);
41+
if (rc || idx < 1 || idx >= MACRO_MAX_ARGS_NUM) {
42+
node_fatal(rc, n, "Invalid macro arg index: %d", idx);
43+
return 0;
44+
}
45+
n->child = 0;
46+
idx--;
47+
} else {
48+
call->arg_idx++;
49+
idx = call->arg_idx;
4050
}
41-
n->child = 0; // Do not traverse arg index
42-
idx--;
51+
call->arg_idx = idx;
4352
n = call->args[idx];
4453
if (!n) {
4554
node_fatal(rc, call->n, "Call argument: %d for macro: %s is not set", (idx + 1), call->key);
@@ -91,6 +100,7 @@ static void _call_init(struct node *n) {
91100
}
92101
struct _call *call = xcalloc(1, sizeof(*call));
93102
call->nn_idx = -1;
103+
call->arg_idx = -1;
94104
call->key = key;
95105
call->mn = mn;
96106
call->n = n;

0 commit comments

Comments
 (0)