Skip to content

Commit c95d3a1

Browse files
committed
more set / check flags for xlat expressions
verify that the arguments to functions are grouped correctly
1 parent 5c78b6b commit c95d3a1

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

src/lib/unlang/xlat_alloc.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ void _xlat_exp_set_type(NDEBUG_LOCATION_ARGS xlat_exp_t *node, xlat_type_t type)
9494
node->call.args = _xlat_exp_head_alloc(NDEBUG_LOCATION_VALS node);
9595
break;
9696

97+
case XLAT_BOX:
98+
node->flags.constant = node->flags.pure = node->flags.can_purify = true;
99+
break;
100+
97101
default:
98102
break;
99103
}
@@ -167,6 +171,10 @@ xlat_exp_t *_xlat_exp_alloc(NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx, xlat_type_t ty
167171
inlen + extra);
168172
_xlat_exp_set_type(NDEBUG_LOCATION_VALS node, type);
169173

174+
if (type == XLAT_BOX) {
175+
node->flags.constant = node->flags.pure = node->flags.can_purify = true;
176+
}
177+
170178
if (!in) return node;
171179

172180
node->fmt = talloc_bstrndup(node, in, inlen);
@@ -339,6 +347,16 @@ void xlat_exp_verify(xlat_exp_t const *node)
339347
return;
340348

341349
case XLAT_FUNC:
350+
xlat_exp_foreach(node->call.args, arg) {
351+
fr_assert(arg->type == XLAT_GROUP);
352+
353+
/*
354+
* We can't do this yet, because the old function argument parser doesn't do the
355+
* right thing.
356+
*/
357+
// fr_assert(arg->quote == T_BARE_WORD);
358+
}
359+
342360
xlat_exp_head_verify(node->call.args);
343361
(void)talloc_get_type_abort_const(node->fmt, char);
344362
return;
@@ -400,6 +418,12 @@ void xlat_exp_verify(xlat_exp_t const *node)
400418
return;
401419
}
402420

421+
case XLAT_BOX:
422+
fr_assert(node->flags.constant);
423+
fr_assert(node->flags.pure);
424+
// fr_assert(node->flags.can_purify);
425+
break;
426+
403427
default:
404428
break;
405429
}

src/lib/unlang/xlat_expr.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,6 @@ static xlat_exp_t *expr_cast_alloc(TALLOC_CTX *ctx, fr_type_t type, xlat_exp_t *
20952095
* number.
20962096
*/
20972097
MEM(node = xlat_exp_alloc(cast, XLAT_BOX, NULL, 0));
2098-
node->flags.constant = true;
20992098
{
21002099
char const *type_name = fr_table_str_by_value(fr_type_table, type, "<INVALID>");
21012100
xlat_exp_set_name(node, type_name, strlen(type_name));
@@ -2280,11 +2279,6 @@ static ssize_t tokenize_rcode(xlat_exp_head_t *head, xlat_exp_t **out, fr_sbuff_
22802279

22812280
MEM(arg = xlat_exp_alloc(node, XLAT_BOX, fr_sbuff_start(&our_in), slen));
22822281

2283-
/*
2284-
* Doesn't need resolving, isn't pure, doesn't need anything else.
2285-
*/
2286-
arg->flags = (xlat_flags_t) { };
2287-
22882282
/*
22892283
* We need a string for unit tests, but this should really be just a number.
22902284
*/

src/lib/unlang/xlat_tokenize.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,6 @@ static ssize_t xlat_tokenize_word(TALLOC_CTX *ctx, xlat_exp_t **out, fr_sbuff_t
14241424
xlat_exp_set_name_shallow(child, str);
14251425
fr_value_box_strdup(child, &child->data, NULL, str, false);
14261426
fr_value_box_mark_safe_for(&child->data, t_rules->literals_safe_for); /* Literal values are treated as implicitly safe */
1427-
child->flags.constant = true;
14281427
fr_assert(child->flags.pure);
14291428
xlat_exp_insert_tail(node->group, child);
14301429
}

0 commit comments

Comments
 (0)