From fbde890ee22a9d4294ac6bc4c1ffd9626e698f4b Mon Sep 17 00:00:00 2001 From: =?utf8?q?M=C3=A1rcio=20Almada?= Date: Thu, 29 Jan 2015 02:16:53 -0300 Subject: [PATCH] allow non mixed use declarations, CC @nikic #1005 ``` use function N\S { foo, bar, etc }; use const N\S { FOO, BAR, ETC }; ``` Related tests: ``` make test -j4 TESTS="-m Zend/tests/ns_0{88..92}*.phpt" ``` All namespace tests: ``` make test -j4 TESTS="Zend/tests/ns_*.phpt" ``` --- Zend/zend_compile.c | 2 +- Zend/zend_language_parser.y | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 28c7ea3d42..c32e7cb193 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -4949,7 +4949,7 @@ void zend_compile_batch_use(zend_ast *ast) /* {{{ */ zend_string_release(name); ZVAL_STR(name_zval, compound_ns); zend_ast_list *inline_use = zend_ast_create_list(1, ZEND_AST_USE, use); - inline_use->attr = use->attr; + inline_use->attr = ast->attr ? ast->attr : use->attr; zend_compile_use(inline_use); } } diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index 1bded228ab..88d9e2fa97 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -230,7 +230,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*); %type class_declaration_statement trait_declaration_statement %type interface_declaration_statement interface_extends_list %type batch_use_declarations inline_use_declarations inline_use_declaration -%type use_declaration const_decl inner_statement +%type mixed_batch_use_declarations use_declaration const_decl inner_statement %type expr optional_expr while_statement for_statement foreach_variable %type foreach_statement declare_statement finally_statement unset_variable variable %type extends_from parameter optional_type argument expr_without_variable global_var @@ -298,14 +298,21 @@ top_statement: | T_NAMESPACE { RESET_DOC_COMMENT(); } '{' top_statement_list '}' { $$ = zend_ast_create(ZEND_AST_NAMESPACE, NULL, $4); } - | T_USE batch_use_declarations ';' { $$ = $2; } - | T_USE use_declarations ';' { $$ = $2; $$->attr = T_CLASS; } - | T_USE T_FUNCTION use_declarations ';' { $$ = $3; $$->attr = T_FUNCTION; } - | T_USE T_CONST use_declarations ';' { $$ = $3; $$->attr = T_CONST; } - | T_CONST const_list ';' { $$ = $2; } + | T_USE mixed_batch_use_declarations ';' { $$ = $2; } + | T_USE T_FUNCTION batch_use_declarations ';' { $$ = $3; $3->attr = T_FUNCTION; } + | T_USE T_CONST batch_use_declarations ';' { $$ = $3; $3->attr = T_CONST; } + | T_USE use_declarations ';' { $$ = $2; $$->attr = T_CLASS; } + | T_USE T_FUNCTION use_declarations ';' { $$ = $3; $$->attr = T_FUNCTION; } + | T_USE T_CONST use_declarations ';' { $$ = $3; $$->attr = T_CONST; } + | T_CONST const_list ';' { $$ = $2; } ; batch_use_declarations: + namespace_name '{' use_declarations '}' + {$$ = zend_ast_create(ZEND_AST_BATCH_USE, $1, $3); } +; + +mixed_batch_use_declarations: namespace_name '{' inline_use_declarations '}' {$$ = zend_ast_create(ZEND_AST_BATCH_USE, $1, $3);} ; -- 2.40.0