[refactoring] update ast structure of "ExprMethodCall" and "ExprPropertyFetch" nodes

This commit is contained in:
Vadym Slizov 2020-12-03 21:42:16 +02:00
parent b5ef30eb36
commit b1e9f5e167
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
9 changed files with 638 additions and 519 deletions

View File

@ -17236,6 +17236,8 @@ func TestExprPrint(t *testing.T) {
assert.DeepEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
} }
// TODO add test for `echo $a->b["c"]()->d["e"]();`
func TestExprPropertyFetch(t *testing.T) { func TestExprPropertyFetch(t *testing.T) {
src := `<? $a->foo;` src := `<? $a->foo;`

647
internal/php5/php5.go generated

File diff suppressed because it is too large Load Diff

View File

@ -3744,24 +3744,26 @@ expr_without_variable:
for _, n := range($4) { for _, n := range($4) {
switch nn := n.(type) { switch nn := n.(type) {
case *ast.ExprFunctionCall:
nn.Function = $$
nn.Node.Position = position.NewNodesPosition($$, nn)
$$ = nn
case *ast.ExprArrayDimFetch: case *ast.ExprArrayDimFetch:
nn.Var = $$ nn.Var = $$
nn.Node.Position = position.NewNodesPosition($$, nn)
$$ = nn $$ = nn
yylex.(*Parser).MoveFreeFloating(nn.Var, $$)
case *ast.ExprPropertyFetch: case *ast.ExprPropertyFetch:
nn.Var = $$ nn.Var = $$
nn.Node.Position = position.NewNodesPosition($$, nn)
$$ = nn $$ = nn
yylex.(*Parser).MoveFreeFloating(nn.Var, $$)
case *ast.ExprMethodCall: case *ast.ExprMethodCall:
nn.Var = $$ nn.Var = $$
nn.Node.Position = position.NewNodesPosition($$, nn)
$$ = nn $$ = nn
yylex.(*Parser).MoveFreeFloating(nn.Var, $$)
} }
// save position
$$.GetNode().Position = position.NewNodesPosition($$, n)
} }
} }
| expr '?' expr ':' expr | expr '?' expr ':' expr
@ -5448,55 +5450,75 @@ variable:
{ {
$$ = $1 $$ = $1
if $4 != nil { $3[0].(*ast.ExprPropertyFetch).ObjectOperatorTkn = $2
$4[0].(*ast.ExprMethodCall).Method = $3[len($3)-1].(*ast.ExprPropertyFetch).Property
$3 = append($3[:len($3)-1], $4...)
}
// save comments if $4 != nil {
yylex.(*Parser).setFreeFloating($3[0], token.Var, $2.SkippedTokens) last := $3[len($3)-1]
switch l := last.(type) {
case *ast.ExprArrayDimFetch:
mc := $4[0].(*ast.ExprMethodCall)
$3 = append($3, &ast.ExprFunctionCall{
Node: ast.Node{
Position: position.NewNodePosition(mc),
},
OpenParenthesisTkn: mc.OpenParenthesisTkn,
Arguments: mc.Arguments,
CloseParenthesisTkn: mc.OpenParenthesisTkn,
},
)
$3 = append($3, $4[1:len($4)]...)
case *ast.ExprPropertyFetch:
$4[0].(*ast.ExprMethodCall).Method = l.Property
$4[0].(*ast.ExprMethodCall).ObjectOperatorTkn = l.ObjectOperatorTkn
$3 = append($3[:len($3)-1], $4...)
}
}
for _, n := range($3) { for _, n := range($3) {
switch nn := n.(type) { switch nn := n.(type) {
case *ast.ExprFunctionCall:
nn.Function = $$
nn.Node.Position = position.NewNodesPosition($$, nn)
$$ = nn
case *ast.ExprArrayDimFetch: case *ast.ExprArrayDimFetch:
nn.Var = $$ nn.Var = $$
nn.GetNode().Position = position.NewNodesPosition($$, nn) nn.Node.Position = position.NewNodesPosition($$, nn)
$$ = nn $$ = nn
yylex.(*Parser).MoveFreeFloating(nn.Var, $$)
case *ast.ExprPropertyFetch: case *ast.ExprPropertyFetch:
nn.Var = $$ nn.Var = $$
nn.GetNode().Position = position.NewNodesPosition($$, nn) nn.Node.Position = position.NewNodesPosition($$, nn)
$$ = nn $$ = nn
yylex.(*Parser).MoveFreeFloating(nn.Var, $$)
case *ast.ExprMethodCall: case *ast.ExprMethodCall:
nn.Var = $$ nn.Var = $$
nn.GetNode().Position = position.NewNodesPosition($$, nn) nn.Node.Position = position.NewNodesPosition($$, nn)
$$ = nn $$ = nn
yylex.(*Parser).MoveFreeFloating(nn.Var, $$)
} }
} }
for _, n := range($5) { for _, n := range($5) {
switch nn := n.(type) { switch nn := n.(type) {
case *ast.ExprFunctionCall:
nn.Function = $$
nn.Node.Position = position.NewNodesPosition($$, nn)
$$ = nn
case *ast.ExprArrayDimFetch: case *ast.ExprArrayDimFetch:
nn.Var = $$ nn.Var = $$
nn.GetNode().Position = position.NewNodesPosition($$, nn) nn.Node.Position = position.NewNodesPosition($$, nn)
$$ = nn $$ = nn
yylex.(*Parser).MoveFreeFloating(nn.Var, $$)
case *ast.ExprPropertyFetch: case *ast.ExprPropertyFetch:
nn.Var = $$ nn.Var = $$
nn.GetNode().Position = position.NewNodesPosition($$, nn) nn.Node.Position = position.NewNodesPosition($$, nn)
$$ = nn $$ = nn
yylex.(*Parser).MoveFreeFloating(nn.Var, $$)
case *ast.ExprMethodCall: case *ast.ExprMethodCall:
nn.Var = $$ nn.Var = $$
nn.GetNode().Position = position.NewNodesPosition($$, nn) nn.Node.Position = position.NewNodesPosition($$, nn)
$$ = nn $$ = nn
yylex.(*Parser).MoveFreeFloating(nn.Var, $$)
} }
} }
} }
@ -5520,16 +5542,32 @@ variable_properties:
variable_property: variable_property:
T_OBJECT_OPERATOR object_property method_or_not T_OBJECT_OPERATOR object_property method_or_not
{ {println("FOOFOOFOOFOOFOOFOOFOOFOOFOO")
$2[0].(*ast.ExprPropertyFetch).ObjectOperatorTkn = $1
if $3 != nil { if $3 != nil {
$3[0].(*ast.ExprMethodCall).Method = $2[len($2)-1].(*ast.ExprPropertyFetch).Property last := $2[len($2)-1]
$2 = append($2[:len($2)-1], $3...) switch l := last.(type) {
case *ast.ExprArrayDimFetch:
mc := $3[0].(*ast.ExprMethodCall)
$2 = append($2, &ast.ExprFunctionCall{
Node: ast.Node{
Position: position.NewNodePosition(mc),
},
OpenParenthesisTkn: mc.OpenParenthesisTkn,
Arguments: mc.Arguments,
CloseParenthesisTkn: mc.OpenParenthesisTkn,
},
)
$2 = append($2, $3[1:len($3)]...)
case *ast.ExprPropertyFetch:
$3[0].(*ast.ExprMethodCall).Method = l.Property
$3[0].(*ast.ExprMethodCall).ObjectOperatorTkn = l.ObjectOperatorTkn
$2 = append($2[:len($2)-1], $3...)
}
} }
$$ = $2 $$ = $2
// save comments
yylex.(*Parser).setFreeFloating($2[0], token.Var, $1.SkippedTokens)
} }
; ;
@ -5567,10 +5605,14 @@ array_method_dereference:
method: method:
function_call_parameter_list function_call_parameter_list
{ {
$$ = &ast.ExprMethodCall{ast.Node{}, nil, nil, $1.(*ast.ArgumentList)} $$ = &ast.ExprMethodCall{
Node: ast.Node{
// save position Position: position.NewNodePosition($1),
$$.GetNode().Position = position.NewNodePosition($1) },
OpenParenthesisTkn: $1.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $1.(*ast.ArgumentList).Arguments,
CloseParenthesisTkn: $1.(*ast.ArgumentList).CloseParenthesisTkn,
}
} }
; ;
@ -5785,11 +5827,14 @@ object_property:
} }
| variable_without_objects | variable_without_objects
{ {
fetch := &ast.ExprPropertyFetch{ast.Node{}, nil, $1} $$ = []ast.Vertex{
$$ = []ast.Vertex{fetch} &ast.ExprPropertyFetch{
Node: ast.Node{
// save position Position: position.NewNodePosition($1),
fetch.GetNode().Position = position.NewNodePosition($1) },
Property: $1,
},
}
} }
; ;
@ -5824,11 +5869,14 @@ object_dim_list:
} }
| variable_name | variable_name
{ {
fetch := &ast.ExprPropertyFetch{ast.Node{}, nil, $1} $$ = []ast.Vertex{
$$ = []ast.Vertex{fetch} &ast.ExprPropertyFetch{
Node: ast.Node{
// save position Position: position.NewNodePosition($1),
fetch.GetNode().Position = position.NewNodePosition($1) },
Property: $1,
},
}
} }
; ;
@ -6179,29 +6227,31 @@ encaps_var:
} }
| T_VARIABLE T_OBJECT_OPERATOR T_STRING | T_VARIABLE T_OBJECT_OPERATOR T_STRING
{ {
identifier := &ast.Identifier{ $$ = &ast.ExprPropertyFetch{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokensPosition($1, $3),
}, },
IdentifierTkn: $1, Var: &ast.ExprVariable{
Value: $1.Value, Node: ast.Node{
} Position: position.NewTokenPosition($1),
variable := &ast.ExprVariable{ast.Node{}, identifier} },
fetch := &ast.Identifier{ VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($3), Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
},
},
ObjectOperatorTkn: $2,
Property: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
IdentifierTkn: $3,
Value: $3.Value,
}, },
IdentifierTkn: $3,
Value: $3.Value,
} }
$$ = &ast.ExprPropertyFetch{ast.Node{}, variable, fetch}
// save position
variable.GetNode().Position = position.NewTokenPosition($1)
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Var, $2.SkippedTokens)
} }
| T_DOLLAR_OPEN_CURLY_BRACES expr '}' | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
{ {

209
internal/php7/php7.go generated
View File

@ -343,7 +343,7 @@ const yyEofCode = 1
const yyErrCode = 2 const yyErrCode = 2
const yyInitialStackSize = 16 const yyInitialStackSize = 16
// line internal/php7/php7.y:4995 // line internal/php7/php7.y:5000
// line yacctab:1 // line yacctab:1
var yyExca = [...]int{ var yyExca = [...]int{
@ -6923,49 +6923,52 @@ yydefault:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4276 // line internal/php7/php7.y:4276
{ {
yyVAL.node = &ast.ExprMethodCall{ast.Node{}, yyDollar[1].node, yyDollar[3].node, yyDollar[4].node.(*ast.ArgumentList)} yyVAL.node = &ast.ExprMethodCall{
Node: ast.Node{
// save position Position: position.NewNodesPosition(yyDollar[1].node, yyDollar[4].node),
yyVAL.node.GetNode().Position = position.NewNodesPosition(yyDollar[1].node, yyDollar[4].node) },
Var: yyDollar[1].node,
// save comments ObjectOperatorTkn: yyDollar[2].token,
yylex.(*Parser).MoveFreeFloating(yyDollar[1].node, yyVAL.node) Method: yyDollar[3].node,
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Var, yyDollar[2].token.SkippedTokens) OpenParenthesisTkn: yyDollar[4].node.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: yyDollar[4].node.(*ast.ArgumentList).Arguments,
CloseParenthesisTkn: yyDollar[4].node.(*ast.ArgumentList).CloseParenthesisTkn,
}
} }
case 437: case 437:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4287 // line internal/php7/php7.y:4290
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 438: case 438:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4294 // line internal/php7/php7.y:4297
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 439: case 439:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4298 // line internal/php7/php7.y:4301
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 440: case 440:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4302 // line internal/php7/php7.y:4305
{ {
yyVAL.node = &ast.ExprPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node} yyVAL.node = &ast.ExprPropertyFetch{
Node: ast.Node{
// save position Position: position.NewNodesPosition(yyDollar[1].node, yyDollar[3].node),
yyVAL.node.GetNode().Position = position.NewNodesPosition(yyDollar[1].node, yyDollar[3].node) },
Var: yyDollar[1].node,
// save comments ObjectOperatorTkn: yyDollar[2].token,
yylex.(*Parser).MoveFreeFloating(yyDollar[1].node, yyVAL.node) Property: yyDollar[3].node,
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Var, yyDollar[2].token.SkippedTokens) }
} }
case 441: case 441:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4316 // line internal/php7/php7.y:4319
{ {
name := &ast.Identifier{ name := &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
@ -6984,7 +6987,7 @@ yydefault:
} }
case 442: case 442:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4333 // line internal/php7/php7.y:4336
{ {
yyVAL.node = &ast.ExprVariable{ast.Node{}, yyDollar[3].node} yyVAL.node = &ast.ExprVariable{ast.Node{}, yyDollar[3].node}
@ -6998,7 +7001,7 @@ yydefault:
} }
case 443: case 443:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4345 // line internal/php7/php7.y:4348
{ {
yyVAL.node = &ast.ExprVariable{ast.Node{}, yyDollar[2].node} yyVAL.node = &ast.ExprVariable{ast.Node{}, yyDollar[2].node}
@ -7010,7 +7013,7 @@ yydefault:
} }
case 444: case 444:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4358 // line internal/php7/php7.y:4361
{ {
yyVAL.node = &ast.ExprStaticPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node} yyVAL.node = &ast.ExprStaticPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node}
@ -7023,7 +7026,7 @@ yydefault:
} }
case 445: case 445:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4369 // line internal/php7/php7.y:4372
{ {
yyVAL.node = &ast.ExprStaticPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node} yyVAL.node = &ast.ExprStaticPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node}
@ -7036,13 +7039,13 @@ yydefault:
} }
case 446: case 446:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4383 // line internal/php7/php7.y:4386
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 447: case 447:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4387 // line internal/php7/php7.y:4390
{ {
yyVAL.node = &ast.ExprArrayDimFetch{ yyVAL.node = &ast.ExprArrayDimFetch{
Node: ast.Node{ Node: ast.Node{
@ -7056,7 +7059,7 @@ yydefault:
} }
case 448: case 448:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4399 // line internal/php7/php7.y:4402
{ {
yyVAL.node = &ast.ExprArrayDimFetch{ yyVAL.node = &ast.ExprArrayDimFetch{
Node: ast.Node{ Node: ast.Node{
@ -7070,20 +7073,20 @@ yydefault:
} }
case 449: case 449:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4411 // line internal/php7/php7.y:4414
{ {
yyVAL.node = &ast.ExprPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node} yyVAL.node = &ast.ExprPropertyFetch{
Node: ast.Node{
// save position Position: position.NewNodesPosition(yyDollar[1].node, yyDollar[3].node),
yyVAL.node.GetNode().Position = position.NewNodesPosition(yyDollar[1].node, yyDollar[3].node) },
Var: yyDollar[1].node,
// save comments ObjectOperatorTkn: yyDollar[2].token,
yylex.(*Parser).MoveFreeFloating(yyDollar[1].node, yyVAL.node) Property: yyDollar[3].node,
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Var, yyDollar[2].token.SkippedTokens) }
} }
case 450: case 450:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4422 // line internal/php7/php7.y:4425
{ {
yyVAL.node = &ast.ExprStaticPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node} yyVAL.node = &ast.ExprStaticPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node}
@ -7096,7 +7099,7 @@ yydefault:
} }
case 451: case 451:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4433 // line internal/php7/php7.y:4436
{ {
yyVAL.node = &ast.ExprStaticPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node} yyVAL.node = &ast.ExprStaticPropertyFetch{ast.Node{}, yyDollar[1].node, yyDollar[3].node}
@ -7109,7 +7112,7 @@ yydefault:
} }
case 452: case 452:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4447 // line internal/php7/php7.y:4450
{ {
yyVAL.node = &ast.Identifier{ yyVAL.node = &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
@ -7121,7 +7124,7 @@ yydefault:
} }
case 453: case 453:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4457 // line internal/php7/php7.y:4460
{ {
yyVAL.node = yyDollar[2].node yyVAL.node = yyDollar[2].node
@ -7131,13 +7134,13 @@ yydefault:
} }
case 454: case 454:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4465 // line internal/php7/php7.y:4468
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 455: case 455:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4472 // line internal/php7/php7.y:4475
{ {
yyVAL.node = &ast.Identifier{ yyVAL.node = &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
@ -7149,7 +7152,7 @@ yydefault:
} }
case 456: case 456:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4482 // line internal/php7/php7.y:4485
{ {
yyVAL.node = yyDollar[2].node yyVAL.node = yyDollar[2].node
@ -7159,13 +7162,13 @@ yydefault:
} }
case 457: case 457:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4490 // line internal/php7/php7.y:4493
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 458: case 458:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4497 // line internal/php7/php7.y:4500
{ {
pairList := yyDollar[1].node.(*ast.ParserSeparatedList) pairList := yyDollar[1].node.(*ast.ParserSeparatedList)
fistPair := pairList.Items[0].(*ast.ExprArrayItem) fistPair := pairList.Items[0].(*ast.ExprArrayItem)
@ -7178,19 +7181,19 @@ yydefault:
} }
case 459: case 459:
yyDollar = yyS[yypt-0 : yypt+1] yyDollar = yyS[yypt-0 : yypt+1]
// line internal/php7/php7.y:4511 // line internal/php7/php7.y:4514
{ {
yyVAL.node = &ast.ExprArrayItem{} yyVAL.node = &ast.ExprArrayItem{}
} }
case 460: case 460:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4515 // line internal/php7/php7.y:4518
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 461: case 461:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4522 // line internal/php7/php7.y:4525
{ {
yyDollar[1].node.(*ast.ParserSeparatedList).SeparatorTkns = append(yyDollar[1].node.(*ast.ParserSeparatedList).SeparatorTkns, yyDollar[2].token) yyDollar[1].node.(*ast.ParserSeparatedList).SeparatorTkns = append(yyDollar[1].node.(*ast.ParserSeparatedList).SeparatorTkns, yyDollar[2].token)
yyDollar[1].node.(*ast.ParserSeparatedList).Items = append(yyDollar[1].node.(*ast.ParserSeparatedList).Items, yyDollar[3].node) yyDollar[1].node.(*ast.ParserSeparatedList).Items = append(yyDollar[1].node.(*ast.ParserSeparatedList).Items, yyDollar[3].node)
@ -7199,7 +7202,7 @@ yydefault:
} }
case 462: case 462:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4529 // line internal/php7/php7.y:4532
{ {
yyVAL.node = &ast.ParserSeparatedList{ yyVAL.node = &ast.ParserSeparatedList{
Items: []ast.Vertex{yyDollar[1].node}, Items: []ast.Vertex{yyDollar[1].node},
@ -7207,7 +7210,7 @@ yydefault:
} }
case 463: case 463:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4538 // line internal/php7/php7.y:4541
{ {
yyVAL.node = &ast.ExprArrayItem{ yyVAL.node = &ast.ExprArrayItem{
Node: ast.Node{ Node: ast.Node{
@ -7220,7 +7223,7 @@ yydefault:
} }
case 464: case 464:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4549 // line internal/php7/php7.y:4552
{ {
yyVAL.node = &ast.ExprArrayItem{ yyVAL.node = &ast.ExprArrayItem{
Node: ast.Node{ Node: ast.Node{
@ -7231,7 +7234,7 @@ yydefault:
} }
case 465: case 465:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4558 // line internal/php7/php7.y:4561
{ {
yyVAL.node = &ast.ExprArrayItem{ yyVAL.node = &ast.ExprArrayItem{
Node: ast.Node{ Node: ast.Node{
@ -7249,7 +7252,7 @@ yydefault:
} }
case 466: case 466:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4574 // line internal/php7/php7.y:4577
{ {
yyVAL.node = &ast.ExprArrayItem{ yyVAL.node = &ast.ExprArrayItem{
Node: ast.Node{ Node: ast.Node{
@ -7265,7 +7268,7 @@ yydefault:
} }
case 467: case 467:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4588 // line internal/php7/php7.y:4591
{ {
yyVAL.node = &ast.ExprArrayItem{ yyVAL.node = &ast.ExprArrayItem{
Node: ast.Node{ Node: ast.Node{
@ -7277,7 +7280,7 @@ yydefault:
} }
case 468: case 468:
yyDollar = yyS[yypt-6 : yypt+1] yyDollar = yyS[yypt-6 : yypt+1]
// line internal/php7/php7.y:4598 // line internal/php7/php7.y:4601
{ {
yyVAL.node = &ast.ExprArrayItem{ yyVAL.node = &ast.ExprArrayItem{
Node: ast.Node{ Node: ast.Node{
@ -7299,7 +7302,7 @@ yydefault:
} }
case 469: case 469:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4618 // line internal/php7/php7.y:4621
{ {
yyVAL.node = &ast.ExprArrayItem{ yyVAL.node = &ast.ExprArrayItem{
Node: ast.Node{ Node: ast.Node{
@ -7319,13 +7322,13 @@ yydefault:
} }
case 470: case 470:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4639 // line internal/php7/php7.y:4642
{ {
yyVAL.list = append(yyDollar[1].list, yyDollar[2].node) yyVAL.list = append(yyDollar[1].list, yyDollar[2].node)
} }
case 471: case 471:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4643 // line internal/php7/php7.y:4646
{ {
yyVAL.list = append( yyVAL.list = append(
yyDollar[1].list, yyDollar[1].list,
@ -7340,13 +7343,13 @@ yydefault:
} }
case 472: case 472:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4656 // line internal/php7/php7.y:4659
{ {
yyVAL.list = []ast.Vertex{yyDollar[1].node} yyVAL.list = []ast.Vertex{yyDollar[1].node}
} }
case 473: case 473:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4660 // line internal/php7/php7.y:4663
{ {
yyVAL.list = []ast.Vertex{ yyVAL.list = []ast.Vertex{
&ast.ScalarEncapsedStringPart{ &ast.ScalarEncapsedStringPart{
@ -7361,7 +7364,7 @@ yydefault:
} }
case 474: case 474:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4676 // line internal/php7/php7.y:4679
{ {
name := &ast.Identifier{ name := &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
@ -7380,7 +7383,7 @@ yydefault:
} }
case 475: case 475:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4693 // line internal/php7/php7.y:4696
{ {
yyVAL.node = &ast.ExprArrayDimFetch{ yyVAL.node = &ast.ExprArrayDimFetch{
Node: ast.Node{ Node: ast.Node{
@ -7405,35 +7408,37 @@ yydefault:
} }
case 476: case 476:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4716 // line internal/php7/php7.y:4719
{ {
identifier := &ast.Identifier{ yyVAL.node = &ast.ExprPropertyFetch{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition(yyDollar[1].token), Position: position.NewTokensPosition(yyDollar[1].token, yyDollar[3].token),
}, },
IdentifierTkn: yyDollar[1].token, Var: &ast.ExprVariable{
Value: yyDollar[1].token.Value, Node: ast.Node{
} Position: position.NewTokenPosition(yyDollar[1].token),
variable := &ast.ExprVariable{ast.Node{}, identifier} },
fetch := &ast.Identifier{ VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition(yyDollar[3].token), Position: position.NewTokenPosition(yyDollar[1].token),
},
IdentifierTkn: yyDollar[1].token,
Value: yyDollar[1].token.Value,
},
},
ObjectOperatorTkn: yyDollar[2].token,
Property: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition(yyDollar[3].token),
},
IdentifierTkn: yyDollar[3].token,
Value: yyDollar[3].token.Value,
}, },
IdentifierTkn: yyDollar[3].token,
Value: yyDollar[3].token.Value,
} }
yyVAL.node = &ast.ExprPropertyFetch{ast.Node{}, variable, fetch}
// save position
variable.GetNode().Position = position.NewTokenPosition(yyDollar[1].token)
yyVAL.node.GetNode().Position = position.NewTokensPosition(yyDollar[1].token, yyDollar[3].token)
// save comments
yylex.(*Parser).setFreeFloating(yyVAL.node, token.Var, yyDollar[2].token.SkippedTokens)
} }
case 477: case 477:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4742 // line internal/php7/php7.y:4747
{ {
variable := &ast.ExprVariable{ast.Node{}, yyDollar[2].node} variable := &ast.ExprVariable{ast.Node{}, yyDollar[2].node}
@ -7448,7 +7453,7 @@ yydefault:
} }
case 478: case 478:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4755 // line internal/php7/php7.y:4760
{ {
name := &ast.Identifier{ name := &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
@ -7470,7 +7475,7 @@ yydefault:
} }
case 479: case 479:
yyDollar = yyS[yypt-6 : yypt+1] yyDollar = yyS[yypt-6 : yypt+1]
// line internal/php7/php7.y:4775 // line internal/php7/php7.y:4780
{ {
yyVAL.node = &ast.ExprArrayDimFetch{ yyVAL.node = &ast.ExprArrayDimFetch{
Node: ast.Node{ Node: ast.Node{
@ -7497,7 +7502,7 @@ yydefault:
} }
case 480: case 480:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4800 // line internal/php7/php7.y:4805
{ {
yyVAL.node = yyDollar[2].node yyVAL.node = yyDollar[2].node
@ -7507,7 +7512,7 @@ yydefault:
} }
case 481: case 481:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4811 // line internal/php7/php7.y:4816
{ {
yyVAL.node = &ast.ScalarString{ yyVAL.node = &ast.ScalarString{
Node: ast.Node{ Node: ast.Node{
@ -7519,7 +7524,7 @@ yydefault:
} }
case 482: case 482:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4821 // line internal/php7/php7.y:4826
{ {
// TODO: add option to handle 64 bit integer // TODO: add option to handle 64 bit integer
if _, err := strconv.Atoi(string(yyDollar[1].token.Value)); err == nil { if _, err := strconv.Atoi(string(yyDollar[1].token.Value)); err == nil {
@ -7542,7 +7547,7 @@ yydefault:
} }
case 483: case 483:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4842 // line internal/php7/php7.y:4847
{ {
_, err := strconv.Atoi(string(yyDollar[2].token.Value)) _, err := strconv.Atoi(string(yyDollar[2].token.Value))
isInt := err == nil isInt := err == nil
@ -7570,7 +7575,7 @@ yydefault:
} }
case 484: case 484:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4868 // line internal/php7/php7.y:4873
{ {
identifier := &ast.Identifier{ identifier := &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
@ -7589,7 +7594,7 @@ yydefault:
} }
case 485: case 485:
yyDollar = yyS[yypt-5 : yypt+1] yyDollar = yyS[yypt-5 : yypt+1]
// line internal/php7/php7.y:4888 // line internal/php7/php7.y:4893
{ {
if yyDollar[4].token != nil { if yyDollar[4].token != nil {
yyDollar[3].node.(*ast.ParserSeparatedList).SeparatorTkns = append(yyDollar[3].node.(*ast.ParserSeparatedList).SeparatorTkns, yyDollar[4].token) yyDollar[3].node.(*ast.ParserSeparatedList).SeparatorTkns = append(yyDollar[3].node.(*ast.ParserSeparatedList).SeparatorTkns, yyDollar[4].token)
@ -7608,7 +7613,7 @@ yydefault:
} }
case 486: case 486:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4905 // line internal/php7/php7.y:4910
{ {
yyVAL.node = &ast.ExprEmpty{ yyVAL.node = &ast.ExprEmpty{
Node: ast.Node{ Node: ast.Node{
@ -7622,7 +7627,7 @@ yydefault:
} }
case 487: case 487:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4917 // line internal/php7/php7.y:4922
{ {
yyVAL.node = &ast.ExprInclude{ yyVAL.node = &ast.ExprInclude{
Node: ast.Node{ Node: ast.Node{
@ -7634,7 +7639,7 @@ yydefault:
} }
case 488: case 488:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4927 // line internal/php7/php7.y:4932
{ {
yyVAL.node = &ast.ExprIncludeOnce{ yyVAL.node = &ast.ExprIncludeOnce{
Node: ast.Node{ Node: ast.Node{
@ -7646,7 +7651,7 @@ yydefault:
} }
case 489: case 489:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
// line internal/php7/php7.y:4937 // line internal/php7/php7.y:4942
{ {
yyVAL.node = &ast.ExprEval{ yyVAL.node = &ast.ExprEval{
Node: ast.Node{ Node: ast.Node{
@ -7660,7 +7665,7 @@ yydefault:
} }
case 490: case 490:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4949 // line internal/php7/php7.y:4954
{ {
yyVAL.node = &ast.ExprRequire{ast.Node{}, yyDollar[2].node} yyVAL.node = &ast.ExprRequire{ast.Node{}, yyDollar[2].node}
@ -7672,7 +7677,7 @@ yydefault:
} }
case 491: case 491:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
// line internal/php7/php7.y:4959 // line internal/php7/php7.y:4964
{ {
yyVAL.node = &ast.ExprRequireOnce{ast.Node{}, yyDollar[2].node} yyVAL.node = &ast.ExprRequireOnce{ast.Node{}, yyDollar[2].node}
@ -7684,7 +7689,7 @@ yydefault:
} }
case 492: case 492:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4972 // line internal/php7/php7.y:4977
{ {
yyVAL.node = &ast.ParserSeparatedList{ yyVAL.node = &ast.ParserSeparatedList{
Items: []ast.Vertex{yyDollar[1].node}, Items: []ast.Vertex{yyDollar[1].node},
@ -7692,7 +7697,7 @@ yydefault:
} }
case 493: case 493:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
// line internal/php7/php7.y:4978 // line internal/php7/php7.y:4983
{ {
yyDollar[1].node.(*ast.ParserSeparatedList).SeparatorTkns = append(yyDollar[1].node.(*ast.ParserSeparatedList).SeparatorTkns, yyDollar[2].token) yyDollar[1].node.(*ast.ParserSeparatedList).SeparatorTkns = append(yyDollar[1].node.(*ast.ParserSeparatedList).SeparatorTkns, yyDollar[2].token)
yyDollar[1].node.(*ast.ParserSeparatedList).Items = append(yyDollar[1].node.(*ast.ParserSeparatedList).Items, yyDollar[3].node) yyDollar[1].node.(*ast.ParserSeparatedList).Items = append(yyDollar[1].node.(*ast.ParserSeparatedList).Items, yyDollar[3].node)
@ -7701,7 +7706,7 @@ yydefault:
} }
case 494: case 494:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
// line internal/php7/php7.y:4988 // line internal/php7/php7.y:4993
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }

View File

@ -4274,14 +4274,17 @@ callable_variable:
} }
| dereferencable T_OBJECT_OPERATOR property_name argument_list | dereferencable T_OBJECT_OPERATOR property_name argument_list
{ {
$$ = &ast.ExprMethodCall{ast.Node{}, $1, $3, $4.(*ast.ArgumentList)} $$ = &ast.ExprMethodCall{
Node: ast.Node{
// save position Position: position.NewNodesPosition($1, $4),
$$.GetNode().Position = position.NewNodesPosition($1, $4) },
Var: $1,
// save comments ObjectOperatorTkn: $2,
yylex.(*Parser).MoveFreeFloating($1, $$) Method: $3,
yylex.(*Parser).setFreeFloating($$, token.Var, $2.SkippedTokens) OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments,
CloseParenthesisTkn: $4.(*ast.ArgumentList).CloseParenthesisTkn,
}
} }
| function_call | function_call
{ {
@ -4300,14 +4303,14 @@ variable:
} }
| dereferencable T_OBJECT_OPERATOR property_name | dereferencable T_OBJECT_OPERATOR property_name
{ {
$$ = &ast.ExprPropertyFetch{ast.Node{}, $1, $3} $$ = &ast.ExprPropertyFetch{
Node: ast.Node{
// save position Position: position.NewNodesPosition($1, $3),
$$.GetNode().Position = position.NewNodesPosition($1, $3) },
Var: $1,
// save comments ObjectOperatorTkn: $2,
yylex.(*Parser).MoveFreeFloating($1, $$) Property: $3,
yylex.(*Parser).setFreeFloating($$, token.Var, $2.SkippedTokens) }
} }
; ;
@ -4409,14 +4412,14 @@ new_variable:
} }
| new_variable T_OBJECT_OPERATOR property_name | new_variable T_OBJECT_OPERATOR property_name
{ {
$$ = &ast.ExprPropertyFetch{ast.Node{}, $1, $3} $$ = &ast.ExprPropertyFetch{
Node: ast.Node{
// save position Position: position.NewNodesPosition($1, $3),
$$.GetNode().Position = position.NewNodesPosition($1, $3) },
Var: $1,
// save comments ObjectOperatorTkn: $2,
yylex.(*Parser).MoveFreeFloating($1, $$) Property: $3,
yylex.(*Parser).setFreeFloating($$, token.Var, $2.SkippedTokens) }
} }
| class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable | class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable
{ {
@ -4714,29 +4717,31 @@ encaps_var:
} }
| T_VARIABLE T_OBJECT_OPERATOR T_STRING | T_VARIABLE T_OBJECT_OPERATOR T_STRING
{ {
identifier := &ast.Identifier{ $$ = &ast.ExprPropertyFetch{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($1), Position: position.NewTokensPosition($1, $3),
}, },
IdentifierTkn: $1, Var: &ast.ExprVariable{
Value: $1.Value, Node: ast.Node{
} Position: position.NewTokenPosition($1),
variable := &ast.ExprVariable{ast.Node{}, identifier} },
fetch := &ast.Identifier{ VarName: &ast.Identifier{
Node: ast.Node{ Node: ast.Node{
Position: position.NewTokenPosition($3), Position: position.NewTokenPosition($1),
},
IdentifierTkn: $1,
Value: $1.Value,
},
},
ObjectOperatorTkn: $2,
Property: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($3),
},
IdentifierTkn: $3,
Value: $3.Value,
}, },
IdentifierTkn: $3,
Value: $3.Value,
} }
$$ = &ast.ExprPropertyFetch{ast.Node{}, variable, fetch}
// save position
variable.GetNode().Position = position.NewTokenPosition($1)
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Var, $2.SkippedTokens)
} }
| T_DOLLAR_OPEN_CURLY_BRACES expr '}' | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
{ {

View File

@ -1215,9 +1215,12 @@ func (n *ExprList) Accept(v NodeVisitor) {
// ExprMethodCall node // ExprMethodCall node
type ExprMethodCall struct { type ExprMethodCall struct {
Node Node
Var Vertex Var Vertex
Method Vertex ObjectOperatorTkn *token.Token
ArgumentList *ArgumentList Method Vertex
OpenParenthesisTkn *token.Token
Arguments []Vertex
CloseParenthesisTkn *token.Token
} }
func (n *ExprMethodCall) Accept(v NodeVisitor) { func (n *ExprMethodCall) Accept(v NodeVisitor) {
@ -1288,8 +1291,9 @@ func (n *ExprPrint) Accept(v NodeVisitor) {
// ExprPropertyFetch node // ExprPropertyFetch node
type ExprPropertyFetch struct { type ExprPropertyFetch struct {
Node Node
Var Vertex Var Vertex
Property Vertex ObjectOperatorTkn *token.Token
Property Vertex
} }
func (n *ExprPropertyFetch) Accept(v NodeVisitor) { func (n *ExprPropertyFetch) Accept(v NodeVisitor) {

View File

@ -1396,10 +1396,12 @@ func (t *DFS) Traverse(n ast.Vertex) {
t.Traverse(nn.Method) t.Traverse(nn.Method)
t.visitor.Leave("Method", true) t.visitor.Leave("Method", true)
} }
if nn.ArgumentList != nil { if nn.Arguments != nil {
t.visitor.Enter("ArgumentList", true) t.visitor.Enter("Arguments", false)
t.Traverse(nn.ArgumentList) for _, c := range nn.Arguments {
t.visitor.Leave("ArgumentList", true) t.Traverse(c)
}
t.visitor.Leave("Arguments", false)
} }
case *ast.ExprNew: case *ast.ExprNew:
if nn == nil { if nn == nil {

View File

@ -1133,7 +1133,7 @@ func (p *PrettyPrinter) printExprMethodCall(n ast.Vertex) {
io.WriteString(p.w, "->") io.WriteString(p.w, "->")
p.Print(nn.Method) p.Print(nn.Method)
io.WriteString(p.w, "(") io.WriteString(p.w, "(")
p.joinPrint(", ", nn.ArgumentList.Arguments) p.joinPrint(", ", nn.Arguments)
io.WriteString(p.w, ")") io.WriteString(p.w, ")")
} }

View File

@ -1695,9 +1695,9 @@ func (p *Printer) printExprMethodCall(n ast.Vertex) {
p.write([]byte("->")) p.write([]byte("->"))
p.Print(nn.Method) p.Print(nn.Method)
p.printFreeFloatingOrDefault(nn.ArgumentList, token.Start, "(") p.printToken(nn.OpenParenthesisTkn, "(")
p.joinPrint(",", nn.ArgumentList.Arguments) p.joinPrint(",", nn.Arguments)
p.printFreeFloatingOrDefault(nn.ArgumentList, token.End, ")") p.printToken(nn.CloseParenthesisTkn, ")")
p.printFreeFloating(nn, token.End) p.printFreeFloating(nn, token.End)
} }