Skip to content

Commit 1a270b2

Browse files
kooldevbeberlei
authored andcommitted
Refactored declaration AST to store attributes in child[4].
1 parent 8192d8b commit 1a270b2

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) {
@@ -2187,7 +2185,7 @@ zend_ast * ZEND_FASTCALL zend_ast_with_attributes(zend_ast *ast, zend_ast *attr)
21872185
case ZEND_AST_METHOD:
21882186
case ZEND_AST_CLASS:
21892187
case ZEND_AST_ARROW_FUNC:
2190-
((zend_ast_decl *) ast)->attributes = attr;
2188+
((zend_ast_decl *) ast)->child[4] = attr;
21912189
break;
21922190
case ZEND_AST_PROP_GROUP:
21932191
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
@@ -6370,14 +6370,14 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, zend_bool toplevel) /*
63706370
if (decl->doc_comment) {
63716371
op_array->doc_comment = zend_string_copy(decl->doc_comment);
63726372
}
6373-
if (decl->attributes) {
6373+
if (decl->child[4]) {
63746374
int target = ZEND_ATTRIBUTE_TARGET_FUNCTION;
63756375

63766376
if (is_method) {
63776377
target = ZEND_ATTRIBUTE_TARGET_METHOD;
63786378
}
63796379
op_array->attributes = create_attribute_array();
6380-
zend_compile_attributes(op_array->attributes, decl->attributes, 0, target);
6380+
zend_compile_attributes(op_array->attributes, decl->child[4], 0, target);
63816381
}
63826382
if (decl->kind == ZEND_AST_CLOSURE || decl->kind == ZEND_AST_ARROW_FUNC) {
63836383
op_array->fn_flags |= ZEND_ACC_CLOSURE;
@@ -6823,9 +6823,9 @@ void zend_compile_class_decl(znode *result, zend_ast *ast, zend_bool toplevel) /
68236823
if (decl->doc_comment) {
68246824
ce->info.user.doc_comment = zend_string_copy(decl->doc_comment);
68256825
}
6826-
if (decl->attributes) {
6826+
if (decl->child[4]) {
68276827
ce->attributes = create_attribute_array();
6828-
zend_compile_attributes(ce->attributes, decl->attributes, 0, ZEND_ATTRIBUTE_TARGET_CLASS);
6828+
zend_compile_attributes(ce->attributes, decl->child[4], 0, ZEND_ATTRIBUTE_TARGET_CLASS);
68296829
}
68306830

68316831
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
@@ -526,7 +526,7 @@ function_declaration_statement:
526526
function returns_ref T_STRING backup_doc_comment '(' parameter_list ')' return_type
527527
backup_fn_flags '{' inner_statement_list '}' backup_fn_flags
528528
{ $$ = zend_ast_create_decl(ZEND_AST_FUNC_DECL, $2 | $13, $1, $4,
529-
zend_ast_get_str($3), $6, NULL, $11, $8); CG(extra_fn_flags) = $9; }
529+
zend_ast_get_str($3), $6, NULL, $11, $8, NULL); CG(extra_fn_flags) = $9; }
530530
;
531531

532532
is_reference:
@@ -542,10 +542,10 @@ is_variadic:
542542
class_declaration_statement:
543543
class_modifiers T_CLASS { $<num>$ = CG(zend_lineno); }
544544
T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
545-
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, $1, $<num>3, $7, zend_ast_get_str($4), $5, $6, $9, NULL); }
545+
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, $1, $<num>3, $7, zend_ast_get_str($4), $5, $6, $9, NULL, NULL); }
546546
| T_CLASS { $<num>$ = CG(zend_lineno); }
547547
T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
548-
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, 0, $<num>2, $6, zend_ast_get_str($3), $4, $5, $8, NULL); }
548+
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, 0, $<num>2, $6, zend_ast_get_str($3), $4, $5, $8, NULL, NULL); }
549549
;
550550

551551
class_modifiers:
@@ -562,13 +562,13 @@ class_modifier:
562562
trait_declaration_statement:
563563
T_TRAIT { $<num>$ = CG(zend_lineno); }
564564
T_STRING backup_doc_comment '{' class_statement_list '}'
565-
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_TRAIT, $<num>2, $4, zend_ast_get_str($3), NULL, NULL, $6, NULL); }
565+
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_TRAIT, $<num>2, $4, zend_ast_get_str($3), NULL, NULL, $6, NULL, NULL); }
566566
;
567567

568568
interface_declaration_statement:
569569
T_INTERFACE { $<num>$ = CG(zend_lineno); }
570570
T_STRING interface_extends_list backup_doc_comment '{' class_statement_list '}'
571-
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_INTERFACE, $<num>2, $5, zend_ast_get_str($3), NULL, $4, $7, NULL); }
571+
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_INTERFACE, $<num>2, $5, zend_ast_get_str($3), NULL, $4, $7, NULL, NULL); }
572572
;
573573

574574
extends_from:
@@ -795,7 +795,7 @@ attributed_class_statement:
795795
| method_modifiers function returns_ref identifier backup_doc_comment '(' parameter_list ')'
796796
return_type backup_fn_flags method_body backup_fn_flags
797797
{ $$ = zend_ast_create_decl(ZEND_AST_METHOD, $3 | $1 | $12, $2, $5,
798-
zend_ast_get_str($4), $7, NULL, $11, $9); CG(extra_fn_flags) = $10; }
798+
zend_ast_get_str($4), $7, NULL, $11, $9, NULL); CG(extra_fn_flags) = $10; }
799799

800800
class_statement:
801801
attributed_class_statement { $$ = $1; }
@@ -933,7 +933,7 @@ anonymous_class:
933933
extends_from implements_list backup_doc_comment '{' class_statement_list '}' {
934934
zend_ast *decl = zend_ast_create_decl(
935935
ZEND_AST_CLASS, ZEND_ACC_ANON_CLASS, $<num>2, $6, NULL,
936-
$4, $5, $8, NULL);
936+
$4, $5, $8, NULL, NULL);
937937
$$ = zend_ast_create(ZEND_AST_NEW, decl, $3);
938938
}
939939
;
@@ -1077,11 +1077,11 @@ inline_function:
10771077
backup_fn_flags '{' inner_statement_list '}' backup_fn_flags
10781078
{ $$ = zend_ast_create_decl(ZEND_AST_CLOSURE, $2 | $13, $1, $3,
10791079
zend_string_init("{closure}", sizeof("{closure}") - 1, 0),
1080-
$5, $7, $11, $8); CG(extra_fn_flags) = $9; }
1080+
$5, $7, $11, $8, NULL); CG(extra_fn_flags) = $9; }
10811081
| fn returns_ref '(' parameter_list ')' return_type backup_doc_comment T_DOUBLE_ARROW backup_fn_flags backup_lex_pos expr backup_fn_flags
10821082
{ $$ = zend_ast_create_decl(ZEND_AST_ARROW_FUNC, $2 | $12, $1, $7,
10831083
zend_string_init("{closure}", sizeof("{closure}") - 1, 0), $4, NULL,
1084-
zend_ast_create(ZEND_AST_RETURN, $11), $6);
1084+
zend_ast_create(ZEND_AST_RETURN, $11), $6, NULL);
10851085
((zend_ast_decl *) $$)->lex_pos = $10;
10861086
CG(extra_fn_flags) = $9; }
10871087
;

0 commit comments

Comments
 (0)