From 6911ea23612233a012a79bd70f438538d92ad92c Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Sun, 6 Sep 2020 16:47:34 -0400 Subject: [PATCH] Avoid gap in AST_CLASS child nodes for attributes See https://github.com/nikic/php-ast/pull/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) --- Zend/zend_ast.c | 12 +++++++----- Zend/zend_compile.c | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index 7932bf597471f..40aae750a5fd8 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -1553,8 +1553,8 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio break; case ZEND_AST_CLASS: decl = (zend_ast_decl *) ast; - if (decl->child[4]) { - zend_ast_export_attributes(str, decl->child[4], indent, 1); + if (decl->child[3]) { + zend_ast_export_attributes(str, decl->child[3], indent, 1); } if (decl->flags & ZEND_ACC_INTERFACE) { 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 smart_str_appends(str, "new "); if (ast->child[0]->kind == ZEND_AST_CLASS) { zend_ast_decl *decl = (zend_ast_decl *) ast->child[0]; - if (decl->child[4]) { - zend_ast_export_attributes(str, decl->child[4], indent, 0); + if (decl->child[3]) { + zend_ast_export_attributes(str, decl->child[3], indent, 0); } smart_str_appends(str, "class"); 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) case ZEND_AST_FUNC_DECL: case ZEND_AST_CLOSURE: case ZEND_AST_METHOD: - case ZEND_AST_CLASS: case ZEND_AST_ARROW_FUNC: ((zend_ast_decl *) ast)->child[4] = attr; break; + case ZEND_AST_CLASS: + ((zend_ast_decl *) ast)->child[3] = attr; + break; case ZEND_AST_PROP_GROUP: ast->child[2] = attr; break; diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 36715c7bb5879..ddab4a31fb182 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -4501,7 +4501,7 @@ void zend_compile_new(znode *result, zend_ast *ast) /* {{{ */ if (class_ast->kind == ZEND_AST_CLASS) { /* anon class declaration */ - zend_compile_class_decl(&class_node, class_ast, 0); + zend_compile_class_decl(&class_node, class_ast, 0); } else { zend_compile_class_ref(&class_node, class_ast, ZEND_FETCH_CLASS_EXCEPTION); } @@ -7370,8 +7370,8 @@ void zend_compile_class_decl(znode *result, zend_ast *ast, zend_bool toplevel) / CG(active_class_entry) = ce; - if (decl->child[4]) { - zend_compile_attributes(&ce->attributes, decl->child[4], 0, ZEND_ATTRIBUTE_TARGET_CLASS); + if (decl->child[3]) { + zend_compile_attributes(&ce->attributes, decl->child[3], 0, ZEND_ATTRIBUTE_TARGET_CLASS); } if (implements_ast) {