@@ -228,7 +228,9 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
228
228
%token T_POW_EQUAL " **= (T_POW_EQUAL)"
229
229
230
230
%type <ast> top_statement namespace_name name statement function_declaration_statement
231
- %type <ast> class_declaration_statement use_declaration const_decl inner_statement
231
+ %type <ast> class_declaration_statement trait_declaration_statement
232
+ %type <ast> interface_declaration_statement interface_extends_list
233
+ %type <ast> use_declaration const_decl inner_statement
232
234
%type <ast> expr optional_expr while_statement for_statement foreach_variable
233
235
%type <ast> foreach_statement declare_statement finally_statement unset_variable variable
234
236
%type <ast> extends_from parameter optional_type argument expr_without_variable global_var
@@ -243,15 +245,16 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
243
245
%type <ast> top_statement_list use_declarations const_list inner_statement_list if_stmt
244
246
%type <ast> alt_if_stmt for_exprs switch_case_list global_var_list static_var_list
245
247
%type <ast> echo_expr_list unset_variables catch_list parameter_list class_statement_list
246
- %type <ast> implements_list interface_extends_list case_list if_stmt_without_else
248
+ %type <ast> implements_list case_list if_stmt_without_else
247
249
%type <ast> non_empty_parameter_list argument_list non_empty_argument_list property_list
248
250
%type <ast> class_const_list name_list trait_adaptations method_body non_empty_for_exprs
249
251
%type <ast> ctor_arguments alt_if_stmt_without_else trait_adaptation_list lexical_vars
250
252
%type <ast> lexical_var_list encaps_list array_pair_list non_empty_array_pair_list
251
253
%type <ast> assignment_list
252
254
253
- %type <num> returns_ref function is_reference is_variadic class_type variable_modifiers
255
+ %type <num> returns_ref function is_reference is_variadic variable_modifiers
254
256
%type <num> method_modifiers trait_modifiers non_empty_member_modifiers member_modifier
257
+ %type <num> class_modifiers class_modifier
255
258
256
259
%type <str> backup_doc_comment
257
260
@@ -278,9 +281,11 @@ name:
278
281
;
279
282
280
283
top_statement :
281
- statement { $$ = $1 ; }
282
- | function_declaration_statement { $$ = $1 ; }
283
- | class_declaration_statement { $$ = $1 ; }
284
+ statement { $$ = $1 ; }
285
+ | function_declaration_statement { $$ = $1 ; }
286
+ | class_declaration_statement { $$ = $1 ; }
287
+ | trait_declaration_statement { $$ = $1 ; }
288
+ | interface_declaration_statement { $$ = $1 ; }
284
289
| T_HALT_COMPILER ' (' ' )' ' ;'
285
290
{ $$ = zend_ast_create(ZEND_AST_HALT_COMPILER,
286
291
zend_ast_create_zval_from_long (zend_get_scanned_file_offset()));
@@ -333,8 +338,10 @@ inner_statement_list:
333
338
334
339
inner_statement :
335
340
statement { $$ = $1 ; }
336
- | function_declaration_statement { $$ = $1 ; }
337
- | class_declaration_statement { $$ = $1 ; }
341
+ | function_declaration_statement { $$ = $1 ; }
342
+ | class_declaration_statement { $$ = $1 ; }
343
+ | trait_declaration_statement { $$ = $1 ; }
344
+ | interface_declaration_statement { $$ = $1 ; }
338
345
| T_HALT_COMPILER ' (' ' )' ' ;'
339
346
{ $$ = NULL ; zend_error_noreturn(E_COMPILE_ERROR,
340
347
" __HALT_COMPILER() can only be used from the outermost scope" ); }
@@ -418,21 +425,34 @@ is_variadic:
418
425
;
419
426
420
427
class_declaration_statement :
421
- class_type { $<num>$ = CG(zend_lineno); }
428
+ class_modifiers T_CLASS { $<num>$ = CG(zend_lineno); }
422
429
T_STRING extends_from implements_list backup_doc_comment ' {' class_statement_list ' }'
423
- { $$ = zend_ast_create_decl(ZEND_AST_CLASS, $1 , $<num>2 , $6 ,
424
- zend_ast_get_str ($3 ), $4, $5, $8); }
425
- | T_INTERFACE { $<num>$ = CG(zend_lineno); }
426
- T_STRING interface_extends_list backup_doc_comment ' {' class_statement_list ' }'
427
- { $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_INTERFACE, $<num>2 , $5 ,
428
- zend_ast_get_str ($3 ), NULL, $4, $7); }
430
+ { $$ = zend_ast_create_decl(ZEND_AST_CLASS, $1 , $<num>3 , $7 , zend_ast_get_str($4 ), $5 , $6 , $9 ); }
431
+ | T_CLASS { $<num>$ = CG(zend_lineno); }
432
+ T_STRING extends_from implements_list backup_doc_comment ' {' class_statement_list ' }'
433
+ { $$ = zend_ast_create_decl(ZEND_AST_CLASS, 0 , $<num>2 , $6 , zend_ast_get_str($3 ), $4 , $5 , $8 ); }
434
+ ;
435
+
436
+ class_modifiers :
437
+ class_modifier { $$ = $1 ; }
438
+ | class_modifiers class_modifier { $$ = zend_add_class_modifier($1 , $2 ); }
439
+ ;
440
+
441
+ class_modifier :
442
+ T_ABSTRACT { $$ = ZEND_ACC_EXPLICIT_ABSTRACT_CLASS; }
443
+ | T_FINAL { $$ = ZEND_ACC_FINAL; }
429
444
;
430
445
431
- class_type :
432
- T_CLASS { $$ = 0 ; }
433
- | T_ABSTRACT T_CLASS { $$ = ZEND_ACC_EXPLICIT_ABSTRACT_CLASS; }
434
- | T_FINAL T_CLASS { $$ = ZEND_ACC_FINAL; }
435
- | T_TRAIT { $$ = ZEND_ACC_TRAIT; }
446
+ trait_declaration_statement :
447
+ T_TRAIT { $<num>$ = CG(zend_lineno); }
448
+ T_STRING extends_from implements_list backup_doc_comment ' {' class_statement_list ' }'
449
+ { $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_TRAIT, $<num>2 , $6 , zend_ast_get_str($3 ), $4 , $5 , $8 ); }
450
+ ;
451
+
452
+ interface_declaration_statement :
453
+ T_INTERFACE { $<num>$ = CG(zend_lineno); }
454
+ T_STRING interface_extends_list backup_doc_comment ' {' class_statement_list ' }'
455
+ { $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_INTERFACE, $<num>2 , $5 , zend_ast_get_str($3 ), NULL , $4 , $7 ); }
436
456
;
437
457
438
458
extends_from :
0 commit comments