@@ -258,6 +258,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
258
258
%type <ast> foreach_statement declare_statement finally_statement unset_variable variable
259
259
%type <ast> extends_from parameter optional_type_without_static argument global_var
260
260
%type <ast> static_var class_statement trait_adaptation trait_precedence trait_alias
261
+ %type <ast> class_statement_anon class_statement_list_anon
261
262
%type <ast> absolute_trait_method_reference trait_method_reference property echo_expr
262
263
%type <ast> new_dereferenceable new_non_dereferenceable anonymous_class class_name class_name_reference simple_variable
263
264
%type <ast> internal_functions_in_yacc
@@ -278,6 +279,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
278
279
%type <ast> isset_variable type return_type type_expr type_without_static
279
280
%type <ast> identifier type_expr_without_static union_type_without_static_element union_type_without_static intersection_type_without_static
280
281
%type <ast> inline_function union_type_element union_type intersection_type
282
+ %type <ast> attributed_class_statement_common attributed_class_statement_anon
281
283
%type <ast> attributed_statement attributed_class_statement attributed_parameter
282
284
%type <ast> attribute_decl attribute attributes attribute_group namespace_declaration_name
283
285
%type <ast> match match_arm_list non_empty_match_arm_list match_arm match_arm_cond_list
@@ -288,6 +290,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
288
290
289
291
%type <num> returns_ref function fn is_reference is_variadic property_modifiers property_hook_modifiers
290
292
%type <num> method_modifiers class_const_modifiers member_modifier optional_cpp_modifiers
293
+ %type <num> method_modifiers_anon
291
294
%type <num> class_modifiers class_modifier anonymous_class_modifiers anonymous_class_modifiers_optional use_type backup_fn_flags
292
295
293
296
%type <ptr> backup_lex_pos
@@ -941,8 +944,17 @@ class_statement_list:
941
944
{ $$ = zend_ast_create_list(0 , ZEND_AST_STMT_LIST); }
942
945
;
943
946
947
+ class_statement_list_anon :
948
+ class_statement_list_anon class_statement_anon
949
+ { $$ = zend_ast_list_add($1 , $2 ); }
950
+ | %empty
951
+ { $$ = zend_ast_create_list(0 , ZEND_AST_STMT_LIST); }
952
+ ;
944
953
945
- attributed_class_statement :
954
+ /* Attributed class statements allowed in anonymous classes as well as normal
955
+ * classes/interfaces/traits/enums
956
+ */
957
+ attributed_class_statement_common :
946
958
property_modifiers optional_type_without_static property_list ' ;'
947
959
{ $$ = zend_ast_create(ZEND_AST_PROP_GROUP, $2 , $3 , NULL );
948
960
$$ ->attr = $1 ; }
@@ -955,11 +967,23 @@ attributed_class_statement:
955
967
| class_const_modifiers T_CONST type_expr class_const_list ' ;'
956
968
{ $$ = zend_ast_create(ZEND_AST_CLASS_CONST_GROUP, $4 , NULL , $3 );
957
969
$$ ->attr = $1 ; }
970
+ | enum_case { $$ = $1 ; }
971
+ ;
972
+
973
+ attributed_class_statement :
974
+ attributed_class_statement_common { $$ = $1 ; }
958
975
| method_modifiers function returns_ref identifier backup_doc_comment ' (' parameter_list ' )'
959
976
return_type backup_fn_flags method_body backup_fn_flags
960
- { $$ = zend_ast_create_decl(ZEND_AST_METHOD, $3 | $1 | $12 , $2 , $5 ,
961
- zend_ast_get_str ($4 ), $7, NULL, $11, $9, NULL); CG(extra_fn_flags) = $10 ; }
962
- | enum_case { $$ = $1 ; }
977
+ { $$ = zend_ast_create_decl(ZEND_AST_METHOD, $3 | $1 | $12 , $2 , $5 ,
978
+ zend_ast_get_str ($4 ), $7, NULL, $11, $9, NULL); CG(extra_fn_flags) = $10 ; }
979
+ ;
980
+
981
+ attributed_class_statement_anon :
982
+ attributed_class_statement_common { $$ = $1 ; }
983
+ | method_modifiers_anon function returns_ref identifier backup_doc_comment ' (' parameter_list ' )'
984
+ return_type backup_fn_flags method_body backup_fn_flags
985
+ { $$ = zend_ast_create_decl(ZEND_AST_METHOD, $3 | $1 | $12 , $2 , $5 ,
986
+ zend_ast_get_str ($4 ), $7, NULL, $11, $9, NULL); CG(extra_fn_flags) = $10 ; }
963
987
;
964
988
965
989
class_statement :
@@ -969,6 +993,13 @@ class_statement:
969
993
{ $$ = zend_ast_create(ZEND_AST_USE_TRAIT, $2 , $3 ); }
970
994
;
971
995
996
+ class_statement_anon :
997
+ attributed_class_statement_anon { $$ = $1 ; }
998
+ | attributes attributed_class_statement_anon { $$ = zend_ast_with_attributes($2 , $1 ); }
999
+ | T_USE class_name_list trait_adaptations
1000
+ { $$ = zend_ast_create(ZEND_AST_USE_TRAIT, $2 , $3 ); }
1001
+ ;
1002
+
972
1003
class_name_list :
973
1004
class_name { $$ = zend_ast_create_list(1 , ZEND_AST_NAME_LIST, $1 ); }
974
1005
| class_name_list ' ,' class_name { $$ = zend_ast_list_add($1 , $3 ); }
@@ -1049,6 +1080,15 @@ method_modifiers:
1049
1080
if (!($$ & ZEND_ACC_PPP_MASK)) { $$ |= ZEND_ACC_PUBLIC; } }
1050
1081
;
1051
1082
1083
+ method_modifiers_anon :
1084
+ %empty
1085
+ { $$ = ZEND_ACC_PUBLIC; }
1086
+ | non_empty_member_modifiers
1087
+ { $$ = zend_modifier_list_to_flags(ZEND_MODIFIER_TARGET_ANON_CLASS_METHOD, $1 );
1088
+ if (!$$ ) { YYERROR ; }
1089
+ if (!($$ & ZEND_ACC_PPP_MASK)) { $$ |= ZEND_ACC_PUBLIC; } }
1090
+ ;
1091
+
1052
1092
class_const_modifiers :
1053
1093
%empty
1054
1094
{ $$ = ZEND_ACC_PUBLIC; }
@@ -1179,7 +1219,7 @@ non_empty_for_exprs:
1179
1219
1180
1220
anonymous_class :
1181
1221
anonymous_class_modifiers_optional T_CLASS { $<num>$ = CG(zend_lineno); } ctor_arguments
1182
- extends_from implements_list backup_doc_comment ' {' class_statement_list ' }' {
1222
+ extends_from implements_list backup_doc_comment ' {' class_statement_list_anon ' }' {
1183
1223
zend_ast *decl = zend_ast_create_decl(
1184
1224
ZEND_AST_CLASS, ZEND_ACC_ANON_CLASS | $1 , $<num>3 , $7 , NULL ,
1185
1225
$5 , $6 , $9 , NULL , NULL );
0 commit comments