[refactoring] update ast structure of "InstanceOf" and "Isset" nodes

This commit is contained in:
Vadym Slizov 2020-12-01 12:16:46 +02:00
parent 9b122de8bf
commit b5ef30eb36
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
5 changed files with 62 additions and 51 deletions

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -240,7 +240,7 @@ import (
%type <node> trait_adaptations unset_variables declare_list non_empty_array_pair_list array_pair_list %type <node> trait_adaptations unset_variables declare_list non_empty_array_pair_list array_pair_list
%type <node> switch_case_list non_empty_function_call_parameter_list assignment_list lexical_var_list %type <node> switch_case_list non_empty_function_call_parameter_list assignment_list lexical_var_list
%type <node> method_body trait_reference_list static_array_pair_list non_empty_static_array_pair_list %type <node> method_body trait_reference_list static_array_pair_list non_empty_static_array_pair_list
%type <node> foreach_statement for_statement while_statement %type <node> foreach_statement for_statement while_statement isset_variables
%type <node> foreach_variable foreach_optional_arg %type <node> foreach_variable foreach_optional_arg
%type <node> extends_from interface_list trait_list %type <node> extends_from interface_list trait_list
%type <node> implements_list %type <node> implements_list
@ -248,7 +248,7 @@ import (
%type <ClosureUse> lexical_vars %type <ClosureUse> lexical_vars
%type <list> top_statement_list namespace_name use_declarations use_function_declarations use_const_declarations %type <list> top_statement_list namespace_name use_declarations use_function_declarations use_const_declarations
%type <list> inner_statement_list encaps_list isset_variables %type <list> inner_statement_list encaps_list
%type <list> elseif_list new_elseif_list non_empty_for_expr %type <list> elseif_list new_elseif_list non_empty_for_expr
%type <list> for_expr case_list catch_statement additional_catches %type <list> for_expr case_list catch_statement additional_catches
%type <list> non_empty_additional_catches parameter_list non_empty_parameter_list class_statement_list %type <list> non_empty_additional_catches parameter_list non_empty_parameter_list class_statement_list
@ -3717,14 +3717,14 @@ expr_without_variable:
} }
| expr T_INSTANCEOF class_name_reference | expr T_INSTANCEOF class_name_reference
{ {
$$ = &ast.ExprInstanceOf{ast.Node{}, $1, $3} $$ = &ast.ExprInstanceOf{
Node: ast.Node{
// save position Position: position.NewNodesPosition($1, $3),
$$.GetNode().Position = position.NewNodesPosition($1, $3) },
Expr: $1,
// save comments InstanceOfTkn: $2,
yylex.(*Parser).MoveFreeFloating($1, $$) Class: $3,
yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens) }
} }
| parenthesis_expr | parenthesis_expr
{ {
@ -6331,15 +6331,16 @@ encaps_var_offset:
internal_functions_in_yacc: internal_functions_in_yacc:
T_ISSET '(' isset_variables ')' T_ISSET '(' isset_variables ')'
{ {
$$ = &ast.ExprIsset{ast.Node{}, $3} $$ = &ast.ExprIsset{
Node: ast.Node{
// save position Position: position.NewTokensPosition($1, $4),
$$.GetNode().Position = position.NewTokensPosition($1, $4) },
IssetTkn: $1,
// save comments OpenParenthesisTkn: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) Vars: $3.(*ast.ParserSeparatedList).Items,
yylex.(*Parser).setFreeFloating($$, token.Isset, $2.SkippedTokens) SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
yylex.(*Parser).setFreeFloating($$, token.VarList, $4.SkippedTokens) CloseParenthesisTkn: $4,
}
} }
| T_EMPTY '(' variable ')' | T_EMPTY '(' variable ')'
{ {
@ -6422,14 +6423,16 @@ internal_functions_in_yacc:
isset_variables: isset_variables:
isset_variable isset_variable
{ {
$$ = []ast.Vertex{$1} $$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{$1},
}
} }
| isset_variables ',' isset_variable | isset_variables ',' isset_variable
{ {
$$ = append($1, $3) $1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, $3)
// save comments $$ = $1
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
} }
; ;

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -247,7 +247,7 @@ import (
%type <node> callable_expr callable_variable static_member new_variable %type <node> callable_expr callable_variable static_member new_variable
%type <node> encaps_var encaps_var_offset echo_expr_list catch_name_list name_list %type <node> encaps_var encaps_var_offset echo_expr_list catch_name_list name_list
%type <node> if_stmt const_list non_empty_argument_list property_list %type <node> if_stmt const_list non_empty_argument_list property_list
%type <node> alt_if_stmt lexical_var_list %type <node> alt_if_stmt lexical_var_list isset_variables
%type <node> if_stmt_without_else %type <node> if_stmt_without_else
%type <node> class_const_decl %type <node> class_const_decl
%type <node> alt_if_stmt_without_else %type <node> alt_if_stmt_without_else
@ -275,7 +275,7 @@ import (
%type <list> for_exprs non_empty_for_exprs %type <list> for_exprs non_empty_for_exprs
%type <list> unprefixed_use_declarations inline_use_declarations %type <list> unprefixed_use_declarations inline_use_declarations
%type <list> case_list trait_adaptation_list %type <list> case_list trait_adaptation_list
%type <list> use_declarations isset_variables %type <list> use_declarations
%type <list> top_statement_list %type <list> top_statement_list
%type <list> inner_statement_list parameter_list non_empty_parameter_list class_statement_list %type <list> inner_statement_list parameter_list non_empty_parameter_list class_statement_list
%type <list> method_modifiers variable_modifiers %type <list> method_modifiers variable_modifiers
@ -3386,14 +3386,14 @@ expr_without_variable:
} }
| expr T_INSTANCEOF class_name_reference | expr T_INSTANCEOF class_name_reference
{ {
$$ = &ast.ExprInstanceOf{ast.Node{}, $1, $3} $$ = &ast.ExprInstanceOf{
Node: ast.Node{
// save position Position: position.NewNodesPosition($1, $3),
$$.GetNode().Position = position.NewNodesPosition($1, $3) },
Expr: $1,
// save comments InstanceOfTkn: $2,
yylex.(*Parser).MoveFreeFloating($1, $$) Class: $3,
yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens) }
} }
| '(' expr ')' | '(' expr ')'
{ {
@ -4886,18 +4886,19 @@ encaps_var_offset:
internal_functions_in_yacc: internal_functions_in_yacc:
T_ISSET '(' isset_variables possible_comma ')' T_ISSET '(' isset_variables possible_comma ')'
{ {
$$ = &ast.ExprIsset{ast.Node{}, $3} if $4 != nil {
$3.(*ast.ParserSeparatedList).SeparatorTkns = append($3.(*ast.ParserSeparatedList).SeparatorTkns, $4)
}
// save position $$ = &ast.ExprIsset{
$$.GetNode().Position = position.NewTokensPosition($1, $5) Node: ast.Node{
Position: position.NewTokensPosition($1, $5),
// save comments },
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) IssetTkn: $1,
yylex.(*Parser).setFreeFloating($$, token.Isset, $2.SkippedTokens) OpenParenthesisTkn: $2,
if $4 == nil { Vars: $3.(*ast.ParserSeparatedList).Items,
yylex.(*Parser).setFreeFloating($$, token.VarList, $5.SkippedTokens) SeparatorTkns: $3.(*ast.ParserSeparatedList).SeparatorTkns,
} else { CloseParenthesisTkn: $5,
yylex.(*Parser).setFreeFloating($$, token.VarList, append($4.SkippedTokens, $5.SkippedTokens...))
} }
} }
| T_EMPTY '(' expr ')' | T_EMPTY '(' expr ')'
@ -4969,14 +4970,16 @@ internal_functions_in_yacc:
isset_variables: isset_variables:
isset_variable isset_variable
{ {
$$ = []ast.Vertex{$1} $$ = &ast.ParserSeparatedList{
Items: []ast.Vertex{$1},
}
} }
| isset_variables ',' isset_variable | isset_variables ',' isset_variable
{ {
$$ = append($1, $3) $1.(*ast.ParserSeparatedList).SeparatorTkns = append($1.(*ast.ParserSeparatedList).SeparatorTkns, $2)
$1.(*ast.ParserSeparatedList).Items = append($1.(*ast.ParserSeparatedList).Items, $3)
// save comments $$ = $1
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
} }
; ;

View File

@ -1175,8 +1175,9 @@ func (n *ExprIncludeOnce) Accept(v NodeVisitor) {
// ExprInstanceOf node // ExprInstanceOf node
type ExprInstanceOf struct { type ExprInstanceOf struct {
Node Node
Expr Vertex Expr Vertex
Class Vertex InstanceOfTkn *token.Token
Class Vertex
} }
func (n *ExprInstanceOf) Accept(v NodeVisitor) { func (n *ExprInstanceOf) Accept(v NodeVisitor) {
@ -1186,7 +1187,11 @@ func (n *ExprInstanceOf) Accept(v NodeVisitor) {
// ExprIsset node // ExprIsset node
type ExprIsset struct { type ExprIsset struct {
Node Node
Vars []Vertex IssetTkn *token.Token
OpenParenthesisTkn *token.Token
Vars []Vertex
SeparatorTkns []*token.Token
CloseParenthesisTkn *token.Token
} }
func (n *ExprIsset) Accept(v NodeVisitor) { func (n *ExprIsset) Accept(v NodeVisitor) {