Skip to content

Commit d139c38

Browse files
committed
modify grammar
Now we modify the grammar to allow specifying visibility on a class.
1 parent ab38c00 commit d139c38

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Zend/zend_compile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,7 @@ typedef enum {
894894
ZEND_MODIFIER_TARGET_CONSTANT,
895895
ZEND_MODIFIER_TARGET_CPP,
896896
ZEND_MODIFIER_TARGET_PROPERTY_HOOK,
897+
ZEND_MODIFIER_TARGET_INNER_CLASS,
897898
} zend_modifier_target;
898899

899900
/* Used during AST construction */

Zend/zend_language_parser.y

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,10 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
285285
%type <ast> enum_declaration_statement enum_backing_type enum_case enum_case_expr
286286
%type <ast> function_name non_empty_member_modifiers
287287
%type <ast> property_hook property_hook_list optional_property_hook_list hooked_property property_hook_body
288-
%type <ast> optional_parameter_list
288+
%type <ast> optional_parameter_list inner_class_statement
289289

290290
%type <num> returns_ref function fn is_reference is_variadic property_modifiers property_hook_modifiers
291-
%type <num> method_modifiers class_const_modifiers member_modifier optional_cpp_modifiers
291+
%type <num> method_modifiers class_const_modifiers member_modifier optional_cpp_modifiers inner_class_modifiers
292292
%type <num> class_modifiers class_modifier anonymous_class_modifiers anonymous_class_modifiers_optional use_type backup_fn_flags
293293

294294
%type <ptr> backup_lex_pos
@@ -628,6 +628,14 @@ class_modifier:
628628
| T_READONLY { $$ = ZEND_ACC_READONLY_CLASS|ZEND_ACC_NO_DYNAMIC_PROPERTIES; }
629629
;
630630

631+
inner_class_modifiers:
632+
non_empty_member_modifiers
633+
{ $$ = zend_modifier_list_to_flags(ZEND_MODIFIER_TARGET_INNER_CLASS, $1);
634+
if (!$$) { YYERROR; } }
635+
| %empty
636+
{ $$ = ZEND_ACC_PUBLIC; }
637+
;
638+
631639
trait_declaration_statement:
632640
T_TRAIT { $<num>$ = CG(zend_lineno); }
633641
T_STRING backup_doc_comment '{' class_statement_list '}'
@@ -943,6 +951,10 @@ class_statement_list:
943951
{ $$ = zend_ast_create_list(0, ZEND_AST_STMT_LIST); }
944952
;
945953

954+
inner_class_statement:
955+
T_CLASS T_STRING { $<num>$ = CG(zend_lineno); } extends_from implements_list backup_doc_comment '{' class_statement_list '}'
956+
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, 0, $<num>3, $6, zend_ast_get_str($2), $4, $5, $8, NULL, NULL); }
957+
;
946958

947959
attributed_class_statement:
948960
property_modifiers optional_type_without_static property_list ';'
@@ -962,6 +974,7 @@ attributed_class_statement:
962974
{ $$ = zend_ast_create_decl(ZEND_AST_METHOD, $3 | $1 | $12, $2, $5,
963975
zend_ast_get_str($4), $7, NULL, $11, $9, NULL); CG(extra_fn_flags) = $10; }
964976
| enum_case { $$ = $1; }
977+
| inner_class_modifiers inner_class_statement { $$ = $2; $$->attr = $1; }
965978
;
966979

967980
class_statement:

0 commit comments

Comments
 (0)