]> granicus.if.org Git - php/commitdiff
Avoid gap in AST_CLASS child nodes for attributes
authorTyson Andre <tysonandre775@hotmail.com>
Sun, 6 Sep 2020 20:47:34 +0000 (16:47 -0400)
committerTyson Andre <tysonandre775@hotmail.com>
Thu, 10 Sep 2020 13:33:46 +0000 (09:33 -0400)
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)

> 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

Zend/zend_ast.c
Zend/zend_compile.c

index 7932bf597471f16882b27f5dc11de64aeee98f5d..40aae750a5fd81d23bd02da370e3c58b5e80dc26 100644 (file)
@@ -1553,8 +1553,8 @@ tail_call:
                        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 @@ simple_list:
                        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;
index 5d1c4a6207a8d5146639ef5e3f96c5250c2215f1..6d07abe3e0980ced99d9378fcd93a7cf9e3cfa15 100644 (file)
@@ -4502,7 +4502,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);
        }
@@ -7371,8 +7371,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) {