Skip to content

Commit 0990424

Browse files
committed
Avoid gap in AST_CLASS child nodes for attributes
See nikic/php-ast#181 > Hm, I'm thinking it would make more sense to change the structure in php-src. > All the function types have consistent AST structure, but there's no reason at > all why classes should be consistent with functions. It's unusual to have an unused child node between other child nodes that are used (for name, extends, implements, and attributes of AST_CLASS) > That gap is a leftover from a previous refactoring. An earlier version of > attributes extended `zend_ast_decl` with a new member called `attributes` and > therefore did not need to handle functions and classes in different ways. Closes GH-6088
1 parent 8710429 commit 0990424

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

Zend/zend_ast.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -1553,8 +1553,8 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
15531553
break;
15541554
case ZEND_AST_CLASS:
15551555
decl = (zend_ast_decl *) ast;
1556-
if (decl->child[4]) {
1557-
zend_ast_export_attributes(str, decl->child[4], indent, 1);
1556+
if (decl->child[3]) {
1557+
zend_ast_export_attributes(str, decl->child[3], indent, 1);
15581558
}
15591559
if (decl->flags & ZEND_ACC_INTERFACE) {
15601560
smart_str_appends(str, "interface ");
@@ -1889,8 +1889,8 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
18891889
smart_str_appends(str, "new ");
18901890
if (ast->child[0]->kind == ZEND_AST_CLASS) {
18911891
zend_ast_decl *decl = (zend_ast_decl *) ast->child[0];
1892-
if (decl->child[4]) {
1893-
zend_ast_export_attributes(str, decl->child[4], indent, 0);
1892+
if (decl->child[3]) {
1893+
zend_ast_export_attributes(str, decl->child[3], indent, 0);
18941894
}
18951895
smart_str_appends(str, "class");
18961896
if (zend_ast_get_list(ast->child[1])->children) {
@@ -2260,10 +2260,12 @@ zend_ast * ZEND_FASTCALL zend_ast_with_attributes(zend_ast *ast, zend_ast *attr)
22602260
case ZEND_AST_FUNC_DECL:
22612261
case ZEND_AST_CLOSURE:
22622262
case ZEND_AST_METHOD:
2263-
case ZEND_AST_CLASS:
22642263
case ZEND_AST_ARROW_FUNC:
22652264
((zend_ast_decl *) ast)->child[4] = attr;
22662265
break;
2266+
case ZEND_AST_CLASS:
2267+
((zend_ast_decl *) ast)->child[3] = attr;
2268+
break;
22672269
case ZEND_AST_PROP_GROUP:
22682270
ast->child[2] = attr;
22692271
break;

Zend/zend_compile.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -4502,7 +4502,7 @@ void zend_compile_new(znode *result, zend_ast *ast) /* {{{ */
45024502

45034503
if (class_ast->kind == ZEND_AST_CLASS) {
45044504
/* anon class declaration */
4505-
zend_compile_class_decl(&class_node, class_ast, 0);
4505+
zend_compile_class_decl(&class_node, class_ast, 0);
45064506
} else {
45074507
zend_compile_class_ref(&class_node, class_ast, ZEND_FETCH_CLASS_EXCEPTION);
45084508
}
@@ -7371,8 +7371,8 @@ void zend_compile_class_decl(znode *result, zend_ast *ast, zend_bool toplevel) /
73717371

73727372
CG(active_class_entry) = ce;
73737373

7374-
if (decl->child[4]) {
7375-
zend_compile_attributes(&ce->attributes, decl->child[4], 0, ZEND_ATTRIBUTE_TARGET_CLASS);
7374+
if (decl->child[3]) {
7375+
zend_compile_attributes(&ce->attributes, decl->child[3], 0, ZEND_ATTRIBUTE_TARGET_CLASS);
73767376
}
73777377

73787378
if (implements_ast) {

0 commit comments

Comments
 (0)