[refactoring] update ast structure of "ShellExec", "StaticCall", "StaticPropertyFetch" and "Ternary" nodes

This commit is contained in:
Vadym Slizov 2020-12-03 22:41:08 +02:00
parent 592c9b9aff
commit 13436b88a7
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
8 changed files with 214 additions and 181 deletions

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -3789,27 +3789,28 @@ expr_without_variable:
}
| expr '?' expr ':' expr
{
$$ = &ast.ExprTernary{ast.Node{}, $1, $3, $5}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $5)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Cond, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.True, $4.SkippedTokens)
$$ = &ast.ExprTernary{
Node: ast.Node{
Position: position.NewNodesPosition($1, $5),
},
Condition: $1,
QuestionTkn: $2,
IfTrue: $3,
ColonTkn: $4,
IfFalse: $5,
}
}
| expr '?' ':' expr
{
$$ = &ast.ExprTernary{ast.Node{}, $1, nil, $4}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $4)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Cond, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.True, $3.SkippedTokens)
$$ = &ast.ExprTernary{
Node: ast.Node{
Position: position.NewNodesPosition($1, $4),
},
Condition: $1,
QuestionTkn: $2,
ColonTkn: $3,
IfFalse: $4,
}
}
| internal_functions_in_yacc
{
@ -3933,13 +3934,14 @@ expr_without_variable:
}
| '`' backticks_expr '`'
{
$$ = &ast.ExprShellExec{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ExprShellExec{
Node: ast.Node{
Position: position.NewTokensPosition($1, $3),
},
OpenBacktickTkn: $1,
Parts: $2,
CloseBacktickTkn: $3,
}
}
| T_PRINT expr
{
@ -4305,47 +4307,59 @@ function_call:
}
| class_name T_PAAMAYIM_NEKUDOTAYIM variable_name function_call_parameter_list
{
$$ = &ast.ExprStaticCall{ast.Node{}, $1, $3, $4.(*ast.ArgumentList)}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $4)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
$$ = &ast.ExprStaticCall{
Node: ast.Node{
Position: position.NewNodesPosition($1, $4),
},
Class: $1,
DoubleColonTkn: $2,
Call: $3,
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
}
}
| class_name T_PAAMAYIM_NEKUDOTAYIM variable_without_objects function_call_parameter_list
{
$$ = &ast.ExprStaticCall{ast.Node{}, $1, $3, $4.(*ast.ArgumentList)}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $4)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
$$ = &ast.ExprStaticCall{
Node: ast.Node{
Position: position.NewNodesPosition($1, $4),
},
Class: $1,
DoubleColonTkn: $2,
Call: $3,
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
}
}
| variable_class_name T_PAAMAYIM_NEKUDOTAYIM variable_name function_call_parameter_list
{
$$ = &ast.ExprStaticCall{ast.Node{}, $1, $3, $4.(*ast.ArgumentList)}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $4)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
$$ = &ast.ExprStaticCall{
Node: ast.Node{
Position: position.NewNodesPosition($1, $4),
},
Class: $1,
DoubleColonTkn: $2,
Call: $3,
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
}
}
| variable_class_name T_PAAMAYIM_NEKUDOTAYIM variable_without_objects function_call_parameter_list
{
$$ = &ast.ExprStaticCall{ast.Node{}, $1, $3, $4.(*ast.ArgumentList)}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $4)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
$$ = &ast.ExprStaticCall{
Node: ast.Node{
Position: position.NewNodesPosition($1, $4),
},
Class: $1,
DoubleColonTkn: $2,
Call: $3,
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
}
}
| variable_without_objects function_call_parameter_list
{
@ -5145,27 +5159,28 @@ static_operation:
}
| static_scalar_value '?' ':' static_scalar_value
{
$$ = &ast.ExprTernary{ast.Node{}, $1, nil, $4}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $4)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Cond, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.True, $3.SkippedTokens)
$$ = &ast.ExprTernary{
Node: ast.Node{
Position: position.NewNodesPosition($1, $4),
},
Condition: $1,
QuestionTkn: $2,
ColonTkn: $3,
IfFalse: $4,
}
}
| static_scalar_value '?' static_scalar_value ':' static_scalar_value
{
$$ = &ast.ExprTernary{ast.Node{}, $1, $3, $5}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $5)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Cond, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.True, $4.SkippedTokens)
$$ = &ast.ExprTernary{
Node: ast.Node{
Position: position.NewNodesPosition($1, $5),
},
Condition: $1,
QuestionTkn: $2,
IfTrue: $3,
ColonTkn: $4,
IfFalse: $5,
}
}
| '+' static_scalar_value
{
@ -5674,25 +5689,25 @@ variable_without_objects:
static_member:
class_name T_PAAMAYIM_NEKUDOTAYIM variable_without_objects
{
$$ = &ast.ExprStaticPropertyFetch{ast.Node{}, $1, $3}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
$$ = &ast.ExprStaticPropertyFetch{
Node: ast.Node{
Position: position.NewNodesPosition($1, $3),
},
Class: $1,
DoubleColonTkn: $2,
Property: $3,
}
}
| variable_class_name T_PAAMAYIM_NEKUDOTAYIM variable_without_objects
{
$$ = &ast.ExprStaticPropertyFetch{ast.Node{}, $1, $3}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
$$ = &ast.ExprStaticPropertyFetch{
Node: ast.Node{
Position: position.NewNodesPosition($1, $3),
},
Class: $1,
DoubleColonTkn: $2,
Property: $3,
}
}
;

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -3424,27 +3424,28 @@ expr_without_variable:
}
| expr '?' expr ':' expr
{
$$ = &ast.ExprTernary{ast.Node{}, $1, $3, $5}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $5)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Cond, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.True, $4.SkippedTokens)
$$ = &ast.ExprTernary{
Node: ast.Node{
Position: position.NewNodesPosition($1, $5),
},
Condition: $1,
QuestionTkn: $2,
IfTrue: $3,
ColonTkn: $4,
IfFalse: $5,
}
}
| expr '?' ':' expr
{
$$ = &ast.ExprTernary{ast.Node{}, $1, nil, $4}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $4)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Cond, $2.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.True, $3.SkippedTokens)
$$ = &ast.ExprTernary{
Node: ast.Node{
Position: position.NewNodesPosition($1, $4),
},
Condition: $1,
QuestionTkn: $2,
ColonTkn: $3,
IfFalse: $4,
}
}
| expr T_COALESCE expr
{
@ -3571,13 +3572,14 @@ expr_without_variable:
}
| '`' backticks_expr '`'
{
$$ = &ast.ExprShellExec{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ExprShellExec{
Node: ast.Node{
Position: position.NewTokensPosition($1, $3),
},
OpenBacktickTkn: $1,
Parts: $2,
CloseBacktickTkn: $3,
}
}
| T_PRINT expr
{
@ -3795,25 +3797,31 @@ function_call:
}
| class_name T_PAAMAYIM_NEKUDOTAYIM member_name argument_list
{
$$ = &ast.ExprStaticCall{ast.Node{}, $1, $3, $4.(*ast.ArgumentList)}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $4)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
$$ = &ast.ExprStaticCall{
Node: ast.Node{
Position: position.NewNodesPosition($1, $4),
},
Class: $1,
DoubleColonTkn: $2,
Call: $3,
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
}
}
| variable_class_name T_PAAMAYIM_NEKUDOTAYIM member_name argument_list
{
$$ = &ast.ExprStaticCall{ast.Node{}, $1, $3, $4.(*ast.ArgumentList)}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $4)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
$$ = &ast.ExprStaticCall{
Node: ast.Node{
Position: position.NewNodesPosition($1, $4),
},
Class: $1,
DoubleColonTkn: $2,
Call: $3,
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
}
}
| callable_expr argument_list
{
@ -4368,25 +4376,25 @@ simple_variable:
static_member:
class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable
{
$$ = &ast.ExprStaticPropertyFetch{ast.Node{}, $1, $3}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
$$ = &ast.ExprStaticPropertyFetch{
Node: ast.Node{
Position: position.NewNodesPosition($1, $3),
},
Class: $1,
DoubleColonTkn: $2,
Property: $3,
}
}
| variable_class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable
{
$$ = &ast.ExprStaticPropertyFetch{ast.Node{}, $1, $3}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
$$ = &ast.ExprStaticPropertyFetch{
Node: ast.Node{
Position: position.NewNodesPosition($1, $3),
},
Class: $1,
DoubleColonTkn: $2,
Property: $3,
}
}
;
@ -4432,25 +4440,25 @@ new_variable:
}
| class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable
{
$$ = &ast.ExprStaticPropertyFetch{ast.Node{}, $1, $3}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Var, $2.SkippedTokens)
$$ = &ast.ExprStaticPropertyFetch{
Node: ast.Node{
Position: position.NewNodesPosition($1, $3),
},
Class: $1,
DoubleColonTkn: $2,
Property: $3,
}
}
| new_variable T_PAAMAYIM_NEKUDOTAYIM simple_variable
{
$$ = &ast.ExprStaticPropertyFetch{ast.Node{}, $1, $3}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Var, $2.SkippedTokens)
$$ = &ast.ExprStaticPropertyFetch{
Node: ast.Node{
Position: position.NewNodesPosition($1, $3),
},
Class: $1,
DoubleColonTkn: $2,
Property: $3,
}
}
;

View File

@ -1344,7 +1344,9 @@ func (n *ExprRequireOnce) Accept(v NodeVisitor) {
// ExprShellExec node
type ExprShellExec struct {
Node
OpenBacktickTkn *token.Token
Parts []Vertex
CloseBacktickTkn *token.Token
}
func (n *ExprShellExec) Accept(v NodeVisitor) {
@ -1355,8 +1357,11 @@ func (n *ExprShellExec) Accept(v NodeVisitor) {
type ExprStaticCall struct {
Node
Class Vertex
DoubleColonTkn *token.Token
Call Vertex
ArgumentList *ArgumentList
OpenParenthesisTkn *token.Token
Arguments []Vertex
CloseParenthesisTkn *token.Token
}
func (n *ExprStaticCall) Accept(v NodeVisitor) {
@ -1367,6 +1372,7 @@ func (n *ExprStaticCall) Accept(v NodeVisitor) {
type ExprStaticPropertyFetch struct {
Node
Class Vertex
DoubleColonTkn *token.Token
Property Vertex
}
@ -1378,7 +1384,9 @@ func (n *ExprStaticPropertyFetch) Accept(v NodeVisitor) {
type ExprTernary struct {
Node
Condition Vertex
QuestionTkn *token.Token
IfTrue Vertex
ColonTkn *token.Token
IfFalse Vertex
}

View File

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

View File

@ -1239,7 +1239,7 @@ func (p *PrettyPrinter) printExprStaticCall(n ast.Vertex) {
io.WriteString(p.w, "::")
p.Print(nn.Call)
io.WriteString(p.w, "(")
p.joinPrint(", ", nn.ArgumentList.Arguments)
p.joinPrint(", ", nn.Arguments)
io.WriteString(p.w, ")")
}

View File

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