[refactoring] update ast structure of "ArrayDimFetch", "UnaryMinus", "ExprUnaryPlus" and "Variable" nodes

This commit is contained in:
Vadym Slizov 2020-12-04 00:13:28 +02:00
parent 13436b88a7
commit 01d695c416
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
5 changed files with 477 additions and 490 deletions

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -15,7 +15,6 @@ import (
node ast.Vertex node ast.Vertex
token *token.Token token *token.Token
list []ast.Vertex list []ast.Vertex
simpleIndirectReference simpleIndirectReference
ClosureUse *ast.ExprClosureUse ClosureUse *ast.ExprClosureUse
} }
@ -260,7 +259,7 @@ import (
%type <list> method_or_not array_method_dereference object_property object_dim_list dynamic_class_name_variable_property %type <list> method_or_not array_method_dereference object_property object_dim_list dynamic_class_name_variable_property
%type <list> dynamic_class_name_variable_properties variable_properties %type <list> dynamic_class_name_variable_properties variable_properties
%type <simpleIndirectReference> simple_indirect_reference %type <list> simple_indirect_reference
%type <token> is_reference is_variadic %type <token> is_reference is_variadic
%% %%
@ -1206,14 +1205,6 @@ catch_statement:
} }
| T_CATCH '(' fully_qualified_class_name T_VARIABLE ')' '{' inner_statement_list '}' additional_catches | T_CATCH '(' fully_qualified_class_name T_VARIABLE ')' '{' inner_statement_list '}' additional_catches
{ {
identifier := &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
IdentifierTkn: $4,
Value: $4.Value,
}
variable := &ast.ExprVariable{ast.Node{}, identifier}
catch := &ast.StmtCatch{ catch := &ast.StmtCatch{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokensPosition($1, $8), Position: position.NewTokensPosition($1, $8),
@ -1221,19 +1212,24 @@ catch_statement:
CatchTkn: $1, CatchTkn: $1,
OpenParenthesisTkn: $2, OpenParenthesisTkn: $2,
Types: []ast.Vertex{$3}, Types: []ast.Vertex{$3},
Var: variable, Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
VarName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
IdentifierTkn: $4,
Value: $4.Value,
},
},
CloseParenthesisTkn: $5, CloseParenthesisTkn: $5,
OpenCurlyBracketTkn: $6, OpenCurlyBracketTkn: $6,
Stmts: $7, Stmts: $7,
CloseCurlyBracketTkn: $8, CloseCurlyBracketTkn: $8,
} }
$$ = append([]ast.Vertex{catch}, $9...) $$ = append([]ast.Vertex{catch}, $9...)
// save position
variable.GetNode().Position = position.NewTokenPosition($4)
// save comments
yylex.(*Parser).setFreeFloating(variable, token.Start, $4.SkippedTokens)
} }
; ;
@ -1281,14 +1277,6 @@ non_empty_additional_catches:
additional_catch: additional_catch:
T_CATCH '(' fully_qualified_class_name T_VARIABLE ')' '{' inner_statement_list '}' T_CATCH '(' fully_qualified_class_name T_VARIABLE ')' '{' inner_statement_list '}'
{ {
identifier := &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
IdentifierTkn: $4,
Value: $4.Value,
}
variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.StmtCatch{ $$ = &ast.StmtCatch{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokensPosition($1, $8), Position: position.NewTokensPosition($1, $8),
@ -1296,18 +1284,23 @@ additional_catch:
CatchTkn: $1, CatchTkn: $1,
OpenParenthesisTkn: $2, OpenParenthesisTkn: $2,
Types: []ast.Vertex{$3}, Types: []ast.Vertex{$3},
Var: variable, Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
VarName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
IdentifierTkn: $4,
Value: $4.Value,
},
},
CloseParenthesisTkn: $5, CloseParenthesisTkn: $5,
OpenCurlyBracketTkn: $6, OpenCurlyBracketTkn: $6,
Stmts: $7, Stmts: $7,
CloseCurlyBracketTkn: $8, CloseCurlyBracketTkn: $8,
} }
// save position
variable.GetNode().Position = position.NewTokenPosition($4)
// save comments
yylex.(*Parser).setFreeFloating(variable, token.Start, $4.SkippedTokens)
} }
; ;
@ -2032,19 +2025,20 @@ non_empty_parameter_list:
parameter: parameter:
optional_class_type is_reference is_variadic T_VARIABLE optional_class_type is_reference is_variadic T_VARIABLE
{ {
identifier := &ast.Identifier{ var variable ast.Vertex
variable = &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($4), Position: position.NewTokenPosition($4),
}, },
IdentifierTkn: $4, IdentifierTkn: $4,
Value: $4.Value, Value: $4.Value,
},
} }
var variable ast.Vertex
variable = &ast.ExprVariable{ast.Node{}, identifier}
variable.GetNode().Position = position.NewTokenPosition($4)
yylex.(*Parser).setFreeFloating(variable, token.Start, $4.SkippedTokens)
if $3 != nil { if $3 != nil {
variable = &ast.Variadic{ variable = &ast.Variadic{
Node: ast.Node{ Node: ast.Node{
@ -2084,20 +2078,20 @@ parameter:
} }
| optional_class_type is_reference is_variadic T_VARIABLE '=' expr | optional_class_type is_reference is_variadic T_VARIABLE '=' expr
{ {
identifier := &ast.Identifier{ var variable ast.Vertex
variable = &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($4), Position: position.NewTokenPosition($4),
}, },
IdentifierTkn: $4, IdentifierTkn: $4,
Value: $4.Value, Value: $4.Value,
},
} }
var variable ast.Vertex
variable = &ast.ExprVariable{ast.Node{}, identifier}
variable.GetNode().Position = position.NewTokenPosition($4)
yylex.(*Parser).setFreeFloating(variable, token.Start, $4.SkippedTokens)
yylex.(*Parser).setFreeFloating(variable, token.End, $5.SkippedTokens)
if $3 != nil { if $3 != nil {
variable = &ast.Variadic{ variable = &ast.Variadic{
Node: ast.Node{ Node: ast.Node{
@ -2290,42 +2284,45 @@ global_var_list:
global_var: global_var:
T_VARIABLE T_VARIABLE
{ {
name := &ast.Identifier{ $$ = &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokenPosition($1),
}, },
IdentifierTkn: $1, IdentifierTkn: $1,
Value: $1.Value, Value: $1.Value,
},
} }
$$ = &ast.ExprVariable{ast.Node{}, name}
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
} }
| '$' r_variable | '$' r_variable
{ {
$$ = &ast.ExprVariable{ast.Node{}, $2} $$ = &ast.ExprVariable{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
DollarTkn: $1,
// save comments VarName: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| '$' '{' expr '}' | '$' '{' expr '}'
{ {
$$ = &ast.ExprVariable{ast.Node{}, $3} $$ = &ast.ExprVariable{
Node: ast.Node{
// save position Position: position.NewTokensPosition($1, $4),
$$.GetNode().Position = position.NewTokensPosition($1, $4) },
DollarTkn: $1,
// save comments VarName: &ast.ParserBrackets{
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) Node: ast.Node{
yylex.(*Parser).setFreeFloatingTokens($3, token.Start, append($2.SkippedTokens, $3.GetNode().Tokens[token.Start]...)) Position: position.NewTokensPosition($2, $4),
yylex.(*Parser).setFreeFloatingTokens($3, token.End, append($3.GetNode().Tokens[token.End], $4.SkippedTokens...)) },
OpenBracketTkn: $2,
Child: $3,
CloseBracketTkn: $4,
},
}
} }
; ;
@ -2333,117 +2330,101 @@ global_var:
static_var_list: static_var_list:
static_var_list ',' T_VARIABLE static_var_list ',' T_VARIABLE
{ {
identifier := &ast.Identifier{ $1.(*ast.StmtStatic).Vars = append($1.(*ast.StmtStatic).Vars, &ast.StmtStaticVar{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($3), Position: position.NewTokenPosition($3),
}, },
IdentifierTkn: $3, IdentifierTkn: $3,
Value: $3.Value, Value: $3.Value,
}
variable := &ast.ExprVariable{ast.Node{}, identifier}
$1.(*ast.StmtStatic).Vars = append($1.(*ast.StmtStatic).Vars, &ast.StmtStaticVar{
Node: ast.Node{
Position: position.NewTokenPosition($3),
}, },
Var: variable, },
}) })
$1.(*ast.StmtStatic).SeparatorTkns = append($1.(*ast.StmtStatic).SeparatorTkns, $2) $1.(*ast.StmtStatic).SeparatorTkns = append($1.(*ast.StmtStatic).SeparatorTkns, $2)
$$ = $1 $$ = $1
// save position
variable.GetNode().Position = position.NewTokenPosition($3)
// save comments
yylex.(*Parser).setFreeFloating(variable, token.Start, $3.SkippedTokens)
} }
| static_var_list ',' T_VARIABLE '=' static_scalar | static_var_list ',' T_VARIABLE '=' static_scalar
{ {
identifier := &ast.Identifier{ $1.(*ast.StmtStatic).Vars = append($1.(*ast.StmtStatic).Vars, &ast.StmtStaticVar{
Node: ast.Node{
Position: position.NewTokenNodePosition($3, $5),
},
Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($3), Position: position.NewTokenPosition($3),
}, },
IdentifierTkn: $3, IdentifierTkn: $3,
Value: $3.Value, Value: $3.Value,
}
variable := &ast.ExprVariable{ast.Node{}, identifier}
$1.(*ast.StmtStatic).Vars = append($1.(*ast.StmtStatic).Vars, &ast.StmtStaticVar{
Node: ast.Node{
Position: position.NewTokenNodePosition($3, $5),
}, },
Var: variable, },
EqualTkn: $4, EqualTkn: $4,
Expr: $5, Expr: $5,
}) })
$1.(*ast.StmtStatic).SeparatorTkns = append($1.(*ast.StmtStatic).SeparatorTkns, $2) $1.(*ast.StmtStatic).SeparatorTkns = append($1.(*ast.StmtStatic).SeparatorTkns, $2)
$$ = $1 $$ = $1
// save position
variable.GetNode().Position = position.NewTokenPosition($3)
// save comments
yylex.(*Parser).setFreeFloating(variable, token.Start, $3.SkippedTokens)
} }
| T_VARIABLE | T_VARIABLE
{ {
identifier := &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
}
variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.StmtStatic{ $$ = &ast.StmtStatic{
Vars: []ast.Vertex{ Vars: []ast.Vertex{
&ast.StmtStaticVar{ &ast.StmtStaticVar{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokenPosition($1),
}, },
Var: variable, Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
}, },
}, VarName: &ast.Identifier{
}
// save position
variable.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating(variable, token.Start, $1.SkippedTokens)
}
| T_VARIABLE '=' static_scalar
{
identifier := &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokenPosition($1),
}, },
IdentifierTkn: $1, IdentifierTkn: $1,
Value: $1.Value, Value: $1.Value,
},
},
},
},
} }
variable := &ast.ExprVariable{ast.Node{}, identifier} }
| T_VARIABLE '=' static_scalar
{
$$ = &ast.StmtStatic{ $$ = &ast.StmtStatic{
Vars: []ast.Vertex{ Vars: []ast.Vertex{
&ast.StmtStaticVar{ &ast.StmtStaticVar{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodePosition($1, $3), Position: position.NewTokenNodePosition($1, $3),
}, },
Var: variable, Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
},
},
EqualTkn: $2, EqualTkn: $2,
Expr: $3, Expr: $3,
}, },
}, },
} }
// save position
variable.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating(variable, token.Start, $1.SkippedTokens)
} }
; ;
@ -3609,23 +3590,23 @@ expr_without_variable:
} }
| '+' expr %prec T_INC | '+' expr %prec T_INC
{ {
$$ = &ast.ExprUnaryPlus{ast.Node{}, $2} $$ = &ast.ExprUnaryPlus{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
PlusTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| '-' expr %prec T_INC | '-' expr %prec T_INC
{ {
$$ = &ast.ExprUnaryMinus{ast.Node{}, $2} $$ = &ast.ExprUnaryMinus{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
MinusTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| '!' expr | '!' expr
{ {
@ -5184,23 +5165,23 @@ static_operation:
} }
| '+' static_scalar_value | '+' static_scalar_value
{ {
$$ = &ast.ExprUnaryPlus{ast.Node{}, $2} $$ = &ast.ExprUnaryPlus{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
PlusTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| '-' static_scalar_value | '-' static_scalar_value
{ {
$$ = &ast.ExprUnaryMinus{ast.Node{}, $2} $$ = &ast.ExprUnaryMinus{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
MinusTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| '(' static_scalar_value ')' | '(' static_scalar_value ')'
{ {
@ -5267,20 +5248,18 @@ general_constant:
scalar: scalar:
T_STRING_VARNAME T_STRING_VARNAME
{ {
name := &ast.Identifier{ $$ = &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokenPosition($1),
}, },
IdentifierTkn: $1, IdentifierTkn: $1,
Value: $1.Value, Value: $1.Value,
},
} }
$$ = &ast.ExprVariable{ast.Node{}, name}
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
} }
| general_constant | general_constant
{ {
@ -5676,13 +5655,13 @@ variable_without_objects:
} }
| simple_indirect_reference reference_variable | simple_indirect_reference reference_variable
{ {
$1.last.VarName = $2 for i := len($1)-1; i>=0; i-- {
$1[i].(*ast.ExprVariable).VarName = $2
for _, n := range($1.all) { $1[i].(*ast.ExprVariable).Node.Position = position.NewNodesPosition($1[i], $2)
n.GetNode().Position = position.NewNodesPosition(n, $2) $2 = $1[i]
} }
$$ = $1.all[0] $$ = $1[0]
} }
; ;
@ -5768,13 +5747,13 @@ base_variable:
} }
| simple_indirect_reference reference_variable | simple_indirect_reference reference_variable
{ {
$1.last.VarName = $2 for i := len($1)-1; i>=0; i-- {
$1[i].(*ast.ExprVariable).VarName = $2
for _, n := range($1.all) { $1[i].(*ast.ExprVariable).Node.Position = position.NewNodesPosition($1[i], $2)
n.GetNode().Position = position.NewNodesPosition(n, $2) $2 = $1[i]
} }
$$ = $1.all[0] $$ = $1[0]
} }
| static_member | static_member
{ {
@ -5817,32 +5796,35 @@ reference_variable:
compound_variable: compound_variable:
T_VARIABLE T_VARIABLE
{ {
name := &ast.Identifier{ $$ = &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokenPosition($1),
}, },
IdentifierTkn: $1, IdentifierTkn: $1,
Value: $1.Value, Value: $1.Value,
},
} }
$$ = &ast.ExprVariable{ast.Node{}, name}
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
} }
| '$' '{' expr '}' | '$' '{' expr '}'
{ {
$$ = &ast.ExprVariable{ast.Node{}, $3} $$ = &ast.ExprVariable{
Node: ast.Node{
// save position Position: position.NewTokensPosition($1, $4),
$$.GetNode().Position = position.NewTokensPosition($1, $4) },
DollarTkn: $1,
// save comments VarName: &ast.ParserBrackets{
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) Node: ast.Node{
yylex.(*Parser).setFreeFloatingTokens($3, token.Start, append($2.SkippedTokens, $3.GetNode().Tokens[token.Start]...)) Position: position.NewTokensPosition($2, $4),
yylex.(*Parser).setFreeFloatingTokens($3, token.End, append($3.GetNode().Tokens[token.End], $4.SkippedTokens...)) },
OpenBracketTkn: $2,
Child: $3,
CloseBracketTkn: $4,
},
}
} }
; ;
@ -5945,29 +5927,23 @@ variable_name:
simple_indirect_reference: simple_indirect_reference:
'$' '$'
{ {
n := &ast.ExprVariable{ast.Node{}, nil} $$ = []ast.Vertex{
$$ = simpleIndirectReference{[]*ast.ExprVariable{n}, n} &ast.ExprVariable{
Node: ast.Node{
// save position Position: position.NewTokenPosition($1),
n.GetNode().Position = position.NewTokenPosition($1) },
DollarTkn: $1,
// save comments },
yylex.(*Parser).setFreeFloating(n, token.Start, $1.SkippedTokens) }
} }
| simple_indirect_reference '$' | simple_indirect_reference '$'
{ {
n := &ast.ExprVariable{ast.Node{}, nil} $$ = append($1, &ast.ExprVariable{
Node: ast.Node{
$1.last.VarName = n Position: position.NewTokenPosition($2),
$1.all = append($1.all, n) },
$1.last = n DollarTkn: $2,
$$ = $1 })
// save position
n.GetNode().Position = position.NewTokenPosition($2)
// save comments
yylex.(*Parser).setFreeFloating(n, token.Start, $2.SkippedTokens)
} }
; ;
@ -6229,20 +6205,18 @@ encaps_list:
encaps_var: encaps_var:
T_VARIABLE T_VARIABLE
{ {
name := &ast.Identifier{ $$ = &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokenPosition($1),
}, },
IdentifierTkn: $1, IdentifierTkn: $1,
Value: $1.Value, Value: $1.Value,
},
} }
$$ = &ast.ExprVariable{ast.Node{}, name}
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
} }
| T_VARIABLE '[' encaps_var_offset ']' | T_VARIABLE '[' encaps_var_offset ']'
{ {
@ -6297,44 +6271,53 @@ encaps_var:
} }
| T_DOLLAR_OPEN_CURLY_BRACES expr '}' | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
{ {
variable := &ast.ExprVariable{ast.Node{}, $2} $$ = &ast.ParserBrackets{
Node: ast.Node{
$$ = variable Position: position.NewTokensPosition($1, $3),
},
// save position OpenBracketTkn: $1,
$$.GetNode().Position = position.NewTokensPosition($1, $3) Child: &ast.ExprVariable{
Node: ast.Node{
// save comments Position: position.NewNodePosition($2),
yylex.(*Parser).setToken($$, token.Start, $1.SkippedTokens) },
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.SkippedTokens) VarName: $2,
},
CloseBracketTkn: $3,
}
} }
| T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '}' | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '}'
{ {
name := &ast.Identifier{ $$ = &ast.ParserBrackets{
Node: ast.Node{
Position: position.NewTokensPosition($1, $3),
},
OpenBracketTkn: $1,
Child: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($2),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($2), Position: position.NewTokenPosition($2),
}, },
IdentifierTkn: $2, IdentifierTkn: $2,
Value: $2.Value, Value: $2.Value,
},
},
CloseBracketTkn: $3,
} }
variable := &ast.ExprVariable{ast.Node{}, name}
$$ = variable
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments
yylex.(*Parser).setToken($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.SkippedTokens)
} }
| T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}' | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
{ {
$$ = &ast.ExprArrayDimFetch{ $$ = &ast.ParserBrackets{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokensPosition($1, $6), Position: position.NewTokensPosition($1, $6),
}, },
OpenCurlyBracketTkn: $1, OpenBracketTkn: $1,
Child: &ast.ExprArrayDimFetch{
Node: ast.Node{
Position: position.NewTokensPosition($2, $5),
},
Var: &ast.ExprVariable{ Var: &ast.ExprVariable{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($2), Position: position.NewTokenPosition($2),
@ -6350,16 +6333,20 @@ encaps_var:
OpenBracketTkn: $3, OpenBracketTkn: $3,
Dim: $4, Dim: $4,
CloseBracketTkn: $5, CloseBracketTkn: $5,
CloseCurlyBracketTkn: $6, },
CloseBracketTkn: $6,
} }
} }
| T_CURLY_OPEN variable '}' | T_CURLY_OPEN variable '}'
{ {
$$ = $2; $$ = &ast.ParserBrackets{
Node: ast.Node{
// save comments Position: position.NewTokensPosition($1, $3),
yylex.(*Parser).setToken($$, token.Start, $1.SkippedTokens) },
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.SkippedTokens) OpenBracketTkn: $1,
Child: $2,
CloseBracketTkn: $3,
}
} }
; ;
@ -6403,20 +6390,18 @@ encaps_var_offset:
} }
| T_VARIABLE | T_VARIABLE
{ {
identifier := &ast.Identifier{ $$ = &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokenPosition($1),
}, },
IdentifierTkn: $1, IdentifierTkn: $1,
Value: $1.Value, Value: $1.Value,
},
} }
$$ = &ast.ExprVariable{ast.Node{}, identifier}
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
} }
; ;
@ -6617,8 +6602,3 @@ class_name_scalar:
; ;
%% %%
type simpleIndirectReference struct {
all []*ast.ExprVariable
last *ast.ExprVariable
}

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -1122,19 +1122,21 @@ catch_list:
} }
| catch_list T_CATCH '(' catch_name_list T_VARIABLE ')' '{' inner_statement_list '}' | catch_list T_CATCH '(' catch_name_list T_VARIABLE ')' '{' inner_statement_list '}'
{ {
identifier := &ast.Identifier{ catch := $4.(*ast.StmtCatch)
catch.CatchTkn = $2
catch.OpenParenthesisTkn = $3
catch.Var = &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($5),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($5), Position: position.NewTokenPosition($5),
}, },
IdentifierTkn: $5, IdentifierTkn: $5,
Value: $5.Value, Value: $5.Value,
},
} }
variable := &ast.ExprVariable{ast.Node{}, identifier}
catch := $4.(*ast.StmtCatch)
catch.CatchTkn = $2
catch.OpenParenthesisTkn = $3
catch.Var = variable
catch.CloseParenthesisTkn = $6 catch.CloseParenthesisTkn = $6
catch.OpenCurlyBracketTkn = $7 catch.OpenCurlyBracketTkn = $7
catch.Stmts = $8 catch.Stmts = $8
@ -1142,12 +1144,6 @@ catch_list:
catch.GetNode().Position = position.NewTokensPosition($2, $9) catch.GetNode().Position = position.NewTokensPosition($2, $9)
$$ = append($1, catch) $$ = append($1, catch)
// save position
variable.GetNode().Position = position.NewTokenPosition($5)
// save comments
yylex.(*Parser).setFreeFloating(variable, token.Start, $5.SkippedTokens)
} }
; ;
catch_name_list: catch_name_list:
@ -1852,19 +1848,20 @@ non_empty_parameter_list:
parameter: parameter:
optional_type is_reference is_variadic T_VARIABLE optional_type is_reference is_variadic T_VARIABLE
{ {
identifier := &ast.Identifier{ var variable ast.Vertex
variable = &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($4), Position: position.NewTokenPosition($4),
}, },
IdentifierTkn: $4, IdentifierTkn: $4,
Value: $4.Value, Value: $4.Value,
},
} }
var variable ast.Vertex
variable = &ast.ExprVariable{ast.Node{}, identifier}
variable.GetNode().Position = position.NewTokenPosition($4)
yylex.(*Parser).setFreeFloating(variable, token.Start, $4.SkippedTokens)
if $3 != nil { if $3 != nil {
variable = &ast.Variadic{ variable = &ast.Variadic{
Node: ast.Node{ Node: ast.Node{
@ -1904,20 +1901,20 @@ parameter:
} }
| optional_type is_reference is_variadic T_VARIABLE '=' expr | optional_type is_reference is_variadic T_VARIABLE '=' expr
{ {
identifier := &ast.Identifier{ var variable ast.Vertex
variable = &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($4), Position: position.NewTokenPosition($4),
}, },
IdentifierTkn: $4, IdentifierTkn: $4,
Value: $4.Value, Value: $4.Value,
},
} }
var variable ast.Vertex
variable = &ast.ExprVariable{ast.Node{}, identifier}
variable.GetNode().Position = position.NewTokenPosition($4)
yylex.(*Parser).setFreeFloating(variable, token.Start, $4.SkippedTokens)
yylex.(*Parser).setFreeFloating(variable, token.End, $5.SkippedTokens)
if $3 != nil { if $3 != nil {
variable = &ast.Variadic{ variable = &ast.Variadic{
Node: ast.Node{ Node: ast.Node{
@ -2131,52 +2128,46 @@ static_var_list:
static_var: static_var:
T_VARIABLE T_VARIABLE
{ {
identifier := &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
}
variable := &ast.ExprVariable{ast.Node{}, identifier}
$$ = &ast.StmtStaticVar{ $$ = &ast.StmtStaticVar{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokenPosition($1),
}, },
Var: variable, Var: &ast.ExprVariable{
} Node: ast.Node{
Position: position.NewTokenPosition($1),
// save position },
variable.GetNode().Position = position.NewTokenPosition($1) VarName: &ast.Identifier{
// save comments
yylex.(*Parser).setFreeFloating(variable, token.Start, $1.SkippedTokens)
}
| T_VARIABLE '=' expr
{
identifier := &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokenPosition($1),
}, },
IdentifierTkn: $1, IdentifierTkn: $1,
Value: $1.Value, Value: $1.Value,
},
},
} }
variable := &ast.ExprVariable{ast.Node{}, identifier} }
| T_VARIABLE '=' expr
{
$$ = &ast.StmtStaticVar{ $$ = &ast.StmtStaticVar{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenNodePosition($1, $3), Position: position.NewTokenNodePosition($1, $3),
}, },
Var: variable, Var: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
},
},
EqualTkn: $2, EqualTkn: $2,
Expr: $3, Expr: $3,
} }
// save position
variable.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating(variable, token.Start, $1.SkippedTokens)
} }
; ;
@ -3254,23 +3245,23 @@ expr_without_variable:
} }
| '+' expr %prec T_INC | '+' expr %prec T_INC
{ {
$$ = &ast.ExprUnaryPlus{ast.Node{}, $2} $$ = &ast.ExprUnaryPlus{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
PlusTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| '-' expr %prec T_INC | '-' expr %prec T_INC
{ {
$$ = &ast.ExprUnaryMinus{ast.Node{}, $2} $$ = &ast.ExprUnaryMinus{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
MinusTkn: $1,
// save comments Expr: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
| '!' expr | '!' expr
{ {
@ -3744,20 +3735,18 @@ lexical_var_list:
lexical_var: lexical_var:
T_VARIABLE T_VARIABLE
{ {
identifier := &ast.Identifier{ $$ = &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokenPosition($1),
}, },
IdentifierTkn: $1, IdentifierTkn: $1,
Value: $1.Value, Value: $1.Value,
},
} }
$$ = &ast.ExprVariable{ast.Node{}, identifier}
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
} }
| '&' T_VARIABLE | '&' T_VARIABLE
{ {
@ -4334,42 +4323,45 @@ variable:
simple_variable: simple_variable:
T_VARIABLE T_VARIABLE
{ {
name := &ast.Identifier{ $$ = &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokenPosition($1),
}, },
IdentifierTkn: $1, IdentifierTkn: $1,
Value: $1.Value, Value: $1.Value,
},
} }
$$ = &ast.ExprVariable{ast.Node{}, name}
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
} }
| '$' '{' expr '}' | '$' '{' expr '}'
{ {
$$ = &ast.ExprVariable{ast.Node{}, $3} $$ = &ast.ExprVariable{
Node: ast.Node{
// save position Position: position.NewTokensPosition($1, $4),
$$.GetNode().Position = position.NewTokensPosition($1, $4) },
DollarTkn: $1,
// save comments VarName: &ast.ParserBrackets{
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) Node: ast.Node{
yylex.(*Parser).setFreeFloatingTokens($3, token.Start, append($2.SkippedTokens, $3.GetNode().Tokens[token.Start]...)) Position: position.NewTokensPosition($2, $4),
yylex.(*Parser).setFreeFloatingTokens($3, token.End, append($3.GetNode().Tokens[token.End], $4.SkippedTokens...)) },
OpenBracketTkn: $2,
Child: $3,
CloseBracketTkn: $4,
},
}
} }
| '$' simple_variable | '$' simple_variable
{ {
$$ = &ast.ExprVariable{ast.Node{}, $2} $$ = &ast.ExprVariable{
Node: ast.Node{
// save position Position: position.NewTokenNodePosition($1, $2),
$$.GetNode().Position = position.NewTokenNodePosition($1, $2) },
DollarTkn: $1,
// save comments VarName: $2,
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens) }
} }
; ;
@ -4696,20 +4688,18 @@ encaps_list:
encaps_var: encaps_var:
T_VARIABLE T_VARIABLE
{ {
name := &ast.Identifier{ $$ = &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokenPosition($1),
}, },
IdentifierTkn: $1, IdentifierTkn: $1,
Value: $1.Value, Value: $1.Value,
},
} }
$$ = &ast.ExprVariable{ast.Node{}, name}
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
} }
| T_VARIABLE '[' encaps_var_offset ']' | T_VARIABLE '[' encaps_var_offset ']'
{ {
@ -4764,44 +4754,53 @@ encaps_var:
} }
| T_DOLLAR_OPEN_CURLY_BRACES expr '}' | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
{ {
variable := &ast.ExprVariable{ast.Node{}, $2} $$ = &ast.ParserBrackets{
Node: ast.Node{
$$ = variable Position: position.NewTokensPosition($1, $3),
},
// save position OpenBracketTkn: $1,
$$.GetNode().Position = position.NewTokensPosition($1, $3) Child: &ast.ExprVariable{
Node: ast.Node{
// save comments Position: position.NewNodePosition($2),
yylex.(*Parser).setToken($$, token.Start, $1.SkippedTokens) },
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.SkippedTokens) VarName: $2,
},
CloseBracketTkn: $3,
}
} }
| T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '}' | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '}'
{ {
name := &ast.Identifier{ $$ = &ast.ParserBrackets{
Node: ast.Node{
Position: position.NewTokensPosition($1, $3),
},
OpenBracketTkn: $1,
Child: &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($2),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($2), Position: position.NewTokenPosition($2),
}, },
IdentifierTkn: $2, IdentifierTkn: $2,
Value: $2.Value, Value: $2.Value,
},
},
CloseBracketTkn: $3,
} }
variable := &ast.ExprVariable{ast.Node{}, name}
$$ = variable
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments
yylex.(*Parser).setToken($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.SkippedTokens)
} }
| T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}' | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
{ {
$$ = &ast.ExprArrayDimFetch{ $$ = &ast.ParserBrackets{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokensPosition($1, $6), Position: position.NewTokensPosition($1, $6),
}, },
OpenCurlyBracketTkn: $1, OpenBracketTkn: $1,
Child: &ast.ExprArrayDimFetch{
Node: ast.Node{
Position: position.NewTokensPosition($2, $5),
},
Var: &ast.ExprVariable{ Var: &ast.ExprVariable{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($2), Position: position.NewTokenPosition($2),
@ -4817,16 +4816,20 @@ encaps_var:
OpenBracketTkn: $3, OpenBracketTkn: $3,
Dim: $4, Dim: $4,
CloseBracketTkn: $5, CloseBracketTkn: $5,
CloseCurlyBracketTkn: $6, },
CloseBracketTkn: $6,
} }
} }
| T_CURLY_OPEN variable '}' | T_CURLY_OPEN variable '}'
{ {
$$ = $2; $$ = &ast.ParserBrackets{
Node: ast.Node{
// save comments Position: position.NewTokensPosition($1, $3),
yylex.(*Parser).setToken($$, token.Start, $1.SkippedTokens) },
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.SkippedTokens) OpenBracketTkn: $1,
Child: $2,
CloseBracketTkn: $3,
}
} }
; ;
@ -4868,14 +4871,19 @@ encaps_var_offset:
isInt := err == nil isInt := err == nil
if isInt { if isInt {
lnumber := &ast.ScalarLnumber{ $$ = &ast.ExprUnaryMinus{
Node: ast.Node{
Position: position.NewTokensPosition($1, $2),
},
MinusTkn: $1,
Expr: &ast.ScalarLnumber{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($2), Position: position.NewTokenPosition($2),
}, },
NumberTkn: $2, NumberTkn: $2,
Value: $2.Value, Value: $2.Value,
},
} }
$$ = &ast.ExprUnaryMinus{ast.Node{}, lnumber}
$$.GetNode().Position = position.NewTokensPosition($1, $2) $$.GetNode().Position = position.NewTokensPosition($1, $2)
} else { } else {
$$ = &ast.ScalarString{ $$ = &ast.ScalarString{
@ -4890,20 +4898,18 @@ encaps_var_offset:
} }
| T_VARIABLE | T_VARIABLE
{ {
identifier := &ast.Identifier{ $$ = &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokenPosition($1),
}, },
IdentifierTkn: $1, IdentifierTkn: $1,
Value: $1.Value, Value: $1.Value,
},
} }
$$ = &ast.ExprVariable{ast.Node{}, identifier}
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
} }
; ;

View File

@ -954,11 +954,9 @@ func (n *ExprArray) Accept(v NodeVisitor) {
type ExprArrayDimFetch struct { type ExprArrayDimFetch struct {
Node Node
Var Vertex Var Vertex
OpenCurlyBracketTkn *token.Token
OpenBracketTkn *token.Token OpenBracketTkn *token.Token
Dim Vertex Dim Vertex
CloseBracketTkn *token.Token CloseBracketTkn *token.Token
CloseCurlyBracketTkn *token.Token
} }
func (n *ExprArrayDimFetch) Accept(v NodeVisitor) { func (n *ExprArrayDimFetch) Accept(v NodeVisitor) {
@ -1397,6 +1395,7 @@ func (n *ExprTernary) Accept(v NodeVisitor) {
// ExprUnaryMinus node // ExprUnaryMinus node
type ExprUnaryMinus struct { type ExprUnaryMinus struct {
Node Node
MinusTkn *token.Token
Expr Vertex Expr Vertex
} }
@ -1407,6 +1406,7 @@ func (n *ExprUnaryMinus) Accept(v NodeVisitor) {
// ExprUnaryPlus node // ExprUnaryPlus node
type ExprUnaryPlus struct { type ExprUnaryPlus struct {
Node Node
PlusTkn *token.Token
Expr Vertex Expr Vertex
} }
@ -1417,6 +1417,7 @@ func (n *ExprUnaryPlus) Accept(v NodeVisitor) {
// ExprVariable node // ExprVariable node
type ExprVariable struct { type ExprVariable struct {
Node Node
DollarTkn *token.Token
VarName Vertex VarName Vertex
} }