Skip to content

Commit 3649c5c

Browse files
committed
Refactored declaration AST to store attributes in child[4].
1 parent 9eb084d commit 3649c5c

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

Zend/zend_ast.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_class_const_or_name(zend_ast *
114114

115115
ZEND_API zend_ast *zend_ast_create_decl(
116116
zend_ast_kind kind, uint32_t flags, uint32_t start_lineno, zend_string *doc_comment,
117-
zend_string *name, zend_ast *child0, zend_ast *child1, zend_ast *child2, zend_ast *child3
117+
zend_string *name, zend_ast *child0, zend_ast *child1, zend_ast *child2, zend_ast *child3, zend_ast *child4
118118
) {
119119
zend_ast_decl *ast;
120120

@@ -126,12 +126,12 @@ ZEND_API zend_ast *zend_ast_create_decl(
126126
ast->flags = flags;
127127
ast->lex_pos = LANG_SCNG(yy_text);
128128
ast->doc_comment = doc_comment;
129-
ast->attributes = NULL;
130129
ast->name = name;
131130
ast->child[0] = child0;
132131
ast->child[1] = child1;
133132
ast->child[2] = child2;
134133
ast->child[3] = child3;
134+
ast->child[4] = child4;
135135

136136
return (zend_ast *) ast;
137137
}
@@ -858,13 +858,11 @@ ZEND_API void ZEND_FASTCALL zend_ast_destroy(zend_ast *ast)
858858
if (decl->doc_comment) {
859859
zend_string_release_ex(decl->doc_comment, 0);
860860
}
861-
if (decl->attributes) {
862-
zend_ast_destroy(decl->attributes);
863-
}
864861
zend_ast_destroy(decl->child[0]);
865862
zend_ast_destroy(decl->child[1]);
866863
zend_ast_destroy(decl->child[2]);
867-
ast = decl->child[3];
864+
zend_ast_destroy(decl->child[3]);
865+
ast = decl->child[4];
868866
goto tail_call;
869867
}
870868
}
@@ -1445,9 +1443,9 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
14451443
case ZEND_AST_ARROW_FUNC:
14461444
case ZEND_AST_METHOD:
14471445
decl = (zend_ast_decl *) ast;
1448-
if (decl->attributes) {
1446+
if (decl->child[4]) {
14491447
zend_bool newlines = !(ast->kind == ZEND_AST_CLOSURE || ast->kind == ZEND_AST_ARROW_FUNC);
1450-
zend_ast_export_attributes(str, decl->attributes, indent, newlines);
1448+
zend_ast_export_attributes(str, decl->child[4], indent, newlines);
14511449
}
14521450
if (decl->flags & ZEND_ACC_PUBLIC) {
14531451
smart_str_appends(str, "public ");
@@ -1505,8 +1503,8 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
15051503
break;
15061504
case ZEND_AST_CLASS:
15071505
decl = (zend_ast_decl *) ast;
1508-
if (decl->attributes) {
1509-
zend_ast_export_attributes(str, decl->attributes, indent, 1);
1506+
if (decl->child[4]) {
1507+
zend_ast_export_attributes(str, decl->child[4], indent, 1);
15101508
}
15111509
if (decl->flags & ZEND_ACC_INTERFACE) {
15121510
smart_str_appends(str, "interface ");
@@ -1839,8 +1837,8 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
18391837
smart_str_appends(str, "new ");
18401838
if (ast->child[0]->kind == ZEND_AST_CLASS) {
18411839
zend_ast_decl *decl = (zend_ast_decl *) ast->child[0];
1842-
if (decl->attributes) {
1843-
zend_ast_export_attributes(str, decl->attributes, indent, 0);
1840+
if (decl->child[4]) {
1841+
zend_ast_export_attributes(str, decl->child[4], indent, 0);
18441842
}
18451843
smart_str_appends(str, "class");
18461844
if (zend_ast_get_list(ast->child[1])->children) {
@@ -2185,7 +2183,7 @@ zend_ast * ZEND_FASTCALL zend_ast_with_attributes(zend_ast *ast, zend_ast *attr)
21852183
case ZEND_AST_METHOD:
21862184
case ZEND_AST_CLASS:
21872185
case ZEND_AST_ARROW_FUNC:
2188-
((zend_ast_decl *) ast)->attributes = attr;
2186+
((zend_ast_decl *) ast)->child[4] = attr;
21892187
break;
21902188
case ZEND_AST_PROP_GROUP:
21912189
ast->child[2] = attr;

Zend/zend_ast.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,8 @@ typedef struct _zend_ast_decl {
194194
uint32_t flags;
195195
unsigned char *lex_pos;
196196
zend_string *doc_comment;
197-
zend_ast *attributes;
198197
zend_string *name;
199-
zend_ast *child[4];
198+
zend_ast *child[5];
200199
} zend_ast_decl;
201200

202201
typedef void (*zend_ast_process_t)(zend_ast *ast);
@@ -274,7 +273,7 @@ ZEND_API zend_ast * ZEND_FASTCALL zend_ast_list_add(zend_ast *list, zend_ast *op
274273

275274
ZEND_API zend_ast *zend_ast_create_decl(
276275
zend_ast_kind kind, uint32_t flags, uint32_t start_lineno, zend_string *doc_comment,
277-
zend_string *name, zend_ast *child0, zend_ast *child1, zend_ast *child2, zend_ast *child3
276+
zend_string *name, zend_ast *child0, zend_ast *child1, zend_ast *child2, zend_ast *child3, zend_ast *child4
278277
);
279278

280279
ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *scope);

Zend/zend_compile.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6371,14 +6371,14 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, zend_bool toplevel) /*
63716371
if (decl->doc_comment) {
63726372
op_array->doc_comment = zend_string_copy(decl->doc_comment);
63736373
}
6374-
if (decl->attributes) {
6374+
if (decl->child[4]) {
63756375
int target = ZEND_ATTRIBUTE_TARGET_FUNCTION;
63766376

63776377
if (is_method) {
63786378
target = ZEND_ATTRIBUTE_TARGET_METHOD;
63796379
}
63806380
op_array->attributes = create_attribute_array();
6381-
zend_compile_attributes(op_array->attributes, decl->attributes, 0, target);
6381+
zend_compile_attributes(op_array->attributes, decl->child[4], 0, target);
63826382
}
63836383
if (decl->kind == ZEND_AST_CLOSURE || decl->kind == ZEND_AST_ARROW_FUNC) {
63846384
op_array->fn_flags |= ZEND_ACC_CLOSURE;
@@ -6824,9 +6824,9 @@ void zend_compile_class_decl(znode *result, zend_ast *ast, zend_bool toplevel) /
68246824
if (decl->doc_comment) {
68256825
ce->info.user.doc_comment = zend_string_copy(decl->doc_comment);
68266826
}
6827-
if (decl->attributes) {
6827+
if (decl->child[4]) {
68286828
ce->attributes = create_attribute_array();
6829-
zend_compile_attributes(ce->attributes, decl->attributes, 0, ZEND_ATTRIBUTE_TARGET_CLASS);
6829+
zend_compile_attributes(ce->attributes, decl->child[4], 0, ZEND_ATTRIBUTE_TARGET_CLASS);
68306830
}
68316831

68326832
if (UNEXPECTED((decl->flags & ZEND_ACC_ANON_CLASS))) {

Zend/zend_language_parser.y

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ function_declaration_statement:
521521
function returns_ref T_STRING backup_doc_comment '(' parameter_list ')' return_type
522522
backup_fn_flags '{' inner_statement_list '}' backup_fn_flags
523523
{ $$ = zend_ast_create_decl(ZEND_AST_FUNC_DECL, $2 | $13, $1, $4,
524-
zend_ast_get_str($3), $6, NULL, $11, $8); CG(extra_fn_flags) = $9; }
524+
zend_ast_get_str($3), $6, NULL, $11, $8, NULL); CG(extra_fn_flags) = $9; }
525525
;
526526

527527
is_reference:
@@ -537,10 +537,10 @@ is_variadic:
537537
class_declaration_statement:
538538
class_modifiers T_CLASS { $<num>$ = CG(zend_lineno); }
539539
T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
540-
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, $1, $<num>3, $7, zend_ast_get_str($4), $5, $6, $9, NULL); }
540+
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, $1, $<num>3, $7, zend_ast_get_str($4), $5, $6, $9, NULL, NULL); }
541541
| T_CLASS { $<num>$ = CG(zend_lineno); }
542542
T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
543-
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, 0, $<num>2, $6, zend_ast_get_str($3), $4, $5, $8, NULL); }
543+
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, 0, $<num>2, $6, zend_ast_get_str($3), $4, $5, $8, NULL, NULL); }
544544
;
545545

546546
class_modifiers:
@@ -557,13 +557,13 @@ class_modifier:
557557
trait_declaration_statement:
558558
T_TRAIT { $<num>$ = CG(zend_lineno); }
559559
T_STRING backup_doc_comment '{' class_statement_list '}'
560-
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_TRAIT, $<num>2, $4, zend_ast_get_str($3), NULL, NULL, $6, NULL); }
560+
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_TRAIT, $<num>2, $4, zend_ast_get_str($3), NULL, NULL, $6, NULL, NULL); }
561561
;
562562

563563
interface_declaration_statement:
564564
T_INTERFACE { $<num>$ = CG(zend_lineno); }
565565
T_STRING interface_extends_list backup_doc_comment '{' class_statement_list '}'
566-
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_INTERFACE, $<num>2, $5, zend_ast_get_str($3), NULL, $4, $7, NULL); }
566+
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_INTERFACE, $<num>2, $5, zend_ast_get_str($3), NULL, $4, $7, NULL, NULL); }
567567
;
568568

569569
extends_from:
@@ -790,7 +790,7 @@ attributed_class_statement:
790790
| method_modifiers function returns_ref identifier backup_doc_comment '(' parameter_list ')'
791791
return_type backup_fn_flags method_body backup_fn_flags
792792
{ $$ = zend_ast_create_decl(ZEND_AST_METHOD, $3 | $1 | $12, $2, $5,
793-
zend_ast_get_str($4), $7, NULL, $11, $9); CG(extra_fn_flags) = $10; }
793+
zend_ast_get_str($4), $7, NULL, $11, $9, NULL); CG(extra_fn_flags) = $10; }
794794

795795
class_statement:
796796
attributed_class_statement { $$ = $1; }
@@ -928,7 +928,7 @@ anonymous_class:
928928
extends_from implements_list backup_doc_comment '{' class_statement_list '}' {
929929
zend_ast *decl = zend_ast_create_decl(
930930
ZEND_AST_CLASS, ZEND_ACC_ANON_CLASS, $<num>2, $6, NULL,
931-
$4, $5, $8, NULL);
931+
$4, $5, $8, NULL, NULL);
932932
$$ = zend_ast_create(ZEND_AST_NEW, decl, $3);
933933
}
934934
;
@@ -1072,11 +1072,11 @@ inline_function:
10721072
backup_fn_flags '{' inner_statement_list '}' backup_fn_flags
10731073
{ $$ = zend_ast_create_decl(ZEND_AST_CLOSURE, $2 | $13, $1, $3,
10741074
zend_string_init("{closure}", sizeof("{closure}") - 1, 0),
1075-
$5, $7, $11, $8); CG(extra_fn_flags) = $9; }
1075+
$5, $7, $11, $8, NULL); CG(extra_fn_flags) = $9; }
10761076
| fn returns_ref '(' parameter_list ')' return_type backup_doc_comment T_DOUBLE_ARROW backup_fn_flags backup_lex_pos expr backup_fn_flags
10771077
{ $$ = zend_ast_create_decl(ZEND_AST_ARROW_FUNC, $2 | $12, $1, $7,
10781078
zend_string_init("{closure}", sizeof("{closure}") - 1, 0), $4, NULL,
1079-
zend_ast_create(ZEND_AST_RETURN, $11), $6);
1079+
zend_ast_create(ZEND_AST_RETURN, $11), $6, NULL);
10801080
((zend_ast_decl *) $$)->lex_pos = $10;
10811081
CG(extra_fn_flags) = $9; }
10821082
;

0 commit comments

Comments
 (0)