summaryrefslogtreecommitdiff
path: root/Zend/zend_language_parser.y
diff options
context:
space:
mode:
Diffstat (limited to 'Zend/zend_language_parser.y')
-rw-r--r--Zend/zend_language_parser.y56
1 files changed, 31 insertions, 25 deletions
diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y
index 69fc0995a7..7acec68b47 100644
--- a/Zend/zend_language_parser.y
+++ b/Zend/zend_language_parser.y
@@ -241,7 +241,6 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
%type <ast> variable_class_name dereferencable_scalar class_name_scalar constant dereferencable
%type <ast> callable_expr callable_variable static_member new_variable
%type <ast> assignment_list_element array_pair encaps_var encaps_var_offset isset_variables
-%type <ast> isset_variable
%type <ast> top_statement_list use_declarations const_list inner_statement_list if_stmt
%type <ast> alt_if_stmt for_exprs switch_case_list global_var_list static_var_list
%type <ast> echo_expr_list unset_variables catch_list parameter_list class_statement_list
@@ -250,7 +249,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
%type <ast> class_const_list name_list trait_adaptations method_body non_empty_for_exprs
%type <ast> ctor_arguments alt_if_stmt_without_else trait_adaptation_list lexical_vars
%type <ast> lexical_var_list encaps_list array_pair_list non_empty_array_pair_list
-%type <ast> assignment_list
+%type <ast> assignment_list isset_variable type return_type
%type <num> returns_ref function is_reference is_variadic variable_modifiers
%type <num> method_modifiers trait_modifiers non_empty_member_modifiers member_modifier
@@ -408,10 +407,10 @@ unset_variable:
;
function_declaration_statement:
- function returns_ref T_STRING '(' parameter_list ')' backup_doc_comment
- '{' inner_statement_list '}'
- { $$ = zend_ast_create_decl(ZEND_AST_FUNC_DECL, $2, $1, $7,
- zend_ast_get_str($3), $5, NULL, $9); }
+ function returns_ref T_STRING '(' parameter_list ')' return_type
+ backup_doc_comment '{' inner_statement_list '}'
+ { $$ = zend_ast_create_decl(ZEND_AST_FUNC_DECL, $2, $1, $8,
+ zend_ast_get_str($3), $5, NULL, $10, $7); }
;
is_reference:
@@ -427,10 +426,10 @@ is_variadic:
class_declaration_statement:
class_modifiers T_CLASS { $<num>$ = CG(zend_lineno); }
T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
- { $$ = zend_ast_create_decl(ZEND_AST_CLASS, $1, $<num>3, $7, zend_ast_get_str($4), $5, $6, $9); }
+ { $$ = zend_ast_create_decl(ZEND_AST_CLASS, $1, $<num>3, $7, zend_ast_get_str($4), $5, $6, $9, NULL); }
| T_CLASS { $<num>$ = CG(zend_lineno); }
T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
- { $$ = zend_ast_create_decl(ZEND_AST_CLASS, 0, $<num>2, $6, zend_ast_get_str($3), $4, $5, $8); }
+ { $$ = zend_ast_create_decl(ZEND_AST_CLASS, 0, $<num>2, $6, zend_ast_get_str($3), $4, $5, $8, NULL); }
;
class_modifiers:
@@ -446,13 +445,13 @@ class_modifier:
trait_declaration_statement:
T_TRAIT { $<num>$ = CG(zend_lineno); }
T_STRING backup_doc_comment '{' class_statement_list '}'
- { $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_TRAIT, $<num>2, $4, zend_ast_get_str($3), NULL, NULL, $6); }
+ { $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_TRAIT, $<num>2, $4, zend_ast_get_str($3), NULL, NULL, $6, NULL); }
;
interface_declaration_statement:
T_INTERFACE { $<num>$ = CG(zend_lineno); }
T_STRING interface_extends_list backup_doc_comment '{' class_statement_list '}'
- { $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_INTERFACE, $<num>2, $5, zend_ast_get_str($3), NULL, $4, $7); }
+ { $$ = zend_ast_create_decl(ZEND_AST_CLASS, ZEND_ACC_INTERFACE, $<num>2, $5, zend_ast_get_str($3), NULL, $4, $7, NULL); }
;
extends_from:
@@ -572,11 +571,20 @@ parameter:
optional_type:
/* empty */ { $$ = NULL; }
- | T_ARRAY { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_ARRAY); }
+ | type { $$ = $1; }
+;
+
+type:
+ T_ARRAY { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_ARRAY); }
| T_CALLABLE { $$ = zend_ast_create_ex(ZEND_AST_TYPE, IS_CALLABLE); }
| name { $$ = $1; }
;
+return_type:
+ /* empty */ { $$ = NULL; }
+ | ':' type { $$ = $2; }
+;
+
argument_list:
'(' ')' { $$ = zend_ast_create_list(0, ZEND_AST_ARG_LIST); }
| '(' non_empty_argument_list ')' { $$ = $2; }
@@ -631,10 +639,10 @@ class_statement:
{ $$ = $2; RESET_DOC_COMMENT(); }
| T_USE name_list trait_adaptations
{ $$ = zend_ast_create(ZEND_AST_USE_TRAIT, $2, $3); }
- | method_modifiers function returns_ref T_STRING '(' parameter_list ')' backup_doc_comment
- method_body
- { $$ = zend_ast_create_decl(ZEND_AST_METHOD, $3 | $1, $2, $8,
- zend_ast_get_str($4), $6, NULL, $9); }
+ | method_modifiers function returns_ref T_STRING '(' parameter_list ')'
+ return_type backup_doc_comment method_body
+ { $$ = zend_ast_create_decl(ZEND_AST_METHOD, $3 | $1, $2, $9,
+ zend_ast_get_str($4), $6, NULL, $10, $8); }
;
name_list:
@@ -769,8 +777,6 @@ expr_without_variable:
{ $$ = zend_ast_create(ZEND_AST_ASSIGN, $1, $3); }
| variable '=' '&' variable
{ $$ = zend_ast_create(ZEND_AST_ASSIGN_REF, $1, $4); }
- | variable '=' '&' new_expr
- { $$ = zend_ast_create(ZEND_AST_ASSIGN_REF, $1, $4); }
| T_CLONE expr { $$ = zend_ast_create(ZEND_AST_CLONE, $2); }
| variable T_PLUS_EQUAL expr
{ $$ = zend_ast_create_assign_op(ZEND_ASSIGN_ADD, $1, $3); }
@@ -868,16 +874,16 @@ expr_without_variable:
| T_YIELD { $$ = zend_ast_create(ZEND_AST_YIELD, NULL, NULL); }
| T_YIELD expr { $$ = zend_ast_create(ZEND_AST_YIELD, $2, NULL); }
| T_YIELD expr T_DOUBLE_ARROW expr { $$ = zend_ast_create(ZEND_AST_YIELD, $4, $2); }
- | function returns_ref '(' parameter_list ')' lexical_vars backup_doc_comment
- '{' inner_statement_list '}'
- { $$ = zend_ast_create_decl(ZEND_AST_CLOSURE, $2, $1, $7,
+ | function returns_ref '(' parameter_list ')' lexical_vars return_type
+ backup_doc_comment '{' inner_statement_list '}'
+ { $$ = zend_ast_create_decl(ZEND_AST_CLOSURE, $2, $1, $8,
zend_string_init("{closure}", sizeof("{closure}") - 1, 0),
- $4, $6, $9); }
- | T_STATIC function returns_ref '(' parameter_list ')' lexical_vars backup_doc_comment
- '{' inner_statement_list '}'
- { $$ = zend_ast_create_decl(ZEND_AST_CLOSURE, $3 | ZEND_ACC_STATIC, $2, $8,
+ $4, $6, $10, $7); }
+ | T_STATIC function returns_ref '(' parameter_list ')' lexical_vars
+ return_type backup_doc_comment '{' inner_statement_list '}'
+ { $$ = zend_ast_create_decl(ZEND_AST_CLOSURE, $3 | ZEND_ACC_STATIC, $2, $9,
zend_string_init("{closure}", sizeof("{closure}") - 1, 0),
- $5, $7, $10); }
+ $5, $7, $11, $8); }
;
function: