Skip to content

Commit 92b248a

Browse files
Add and use zend_ast_export_list_ex()
1 parent 3689d93 commit 92b248a

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

Zend/zend_ast.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,11 +1595,14 @@ static ZEND_COLD void zend_ast_export_var(smart_str *str, zend_ast *ast, int pri
15951595
smart_str_appendc(str, '}');
15961596
}
15971597

1598-
static ZEND_COLD void zend_ast_export_list(smart_str *str, zend_ast_list *list, bool separator, int priority, int indent)
1598+
// Use zend_ast_export_list() unless fewer than `list->children` children
1599+
// should be exported
1600+
static ZEND_COLD void zend_ast_export_list_ex(smart_str *str, zend_ast_list *list, bool separator, int priority, int indent, int children)
15991601
{
1602+
ZEND_ASSERT(children <= list->children);
16001603
uint32_t i = 0;
16011604

1602-
while (i < list->children) {
1605+
while (i < children) {
16031606
if (i != 0 && separator) {
16041607
smart_str_appends(str, ", ");
16051608
}
@@ -1608,6 +1611,11 @@ static ZEND_COLD void zend_ast_export_list(smart_str *str, zend_ast_list *list,
16081611
}
16091612
}
16101613

1614+
static ZEND_COLD void zend_ast_export_list(smart_str *str, zend_ast_list *list, bool separator, int priority, int indent)
1615+
{
1616+
zend_ast_export_list_ex(str, list, separator, priority, indent, list->children);
1617+
}
1618+
16111619
static ZEND_COLD void zend_ast_export_encaps_list(smart_str *str, char quote, zend_ast_list *list, int indent)
16121620
{
16131621
uint32_t i = 0;
@@ -2191,13 +2199,10 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
21912199
1
21922200
);
21932201
// So that the list printing doesn't try to print the attributes,
2194-
// decrease the number of children; since we need to increase it
2195-
// afterwards, instead of jumping to simple_list we need to
2196-
// put the zend_ast_export_list() call here
2197-
ast_list->children--;
2202+
// use zend_ast_export_list_ex() to override the number of children
2203+
// to print
21982204
smart_str_appends(str, "const ");
2199-
zend_ast_export_list(str, ast_list, 1, 20, indent);
2200-
ast_list->children++;
2205+
zend_ast_export_list_ex(str, ast_list, 1, 20, indent, ast_list->children - 1);
22012206
break;
22022207
}
22032208
smart_str_appends(str, "const ");

0 commit comments

Comments
 (0)