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

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

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

View File

@ -1344,7 +1344,9 @@ func (n *ExprRequireOnce) Accept(v NodeVisitor) {
// ExprShellExec node // ExprShellExec node
type ExprShellExec struct { type ExprShellExec struct {
Node Node
Parts []Vertex OpenBacktickTkn *token.Token
Parts []Vertex
CloseBacktickTkn *token.Token
} }
func (n *ExprShellExec) Accept(v NodeVisitor) { func (n *ExprShellExec) Accept(v NodeVisitor) {
@ -1354,9 +1356,12 @@ func (n *ExprShellExec) Accept(v NodeVisitor) {
// ExprStaticCall node // ExprStaticCall node
type ExprStaticCall struct { type ExprStaticCall struct {
Node Node
Class Vertex Class Vertex
Call Vertex DoubleColonTkn *token.Token
ArgumentList *ArgumentList Call Vertex
OpenParenthesisTkn *token.Token
Arguments []Vertex
CloseParenthesisTkn *token.Token
} }
func (n *ExprStaticCall) Accept(v NodeVisitor) { func (n *ExprStaticCall) Accept(v NodeVisitor) {
@ -1366,8 +1371,9 @@ func (n *ExprStaticCall) Accept(v NodeVisitor) {
// ExprStaticPropertyFetch node // ExprStaticPropertyFetch node
type ExprStaticPropertyFetch struct { type ExprStaticPropertyFetch struct {
Node Node
Class Vertex Class Vertex
Property Vertex DoubleColonTkn *token.Token
Property Vertex
} }
func (n *ExprStaticPropertyFetch) Accept(v NodeVisitor) { func (n *ExprStaticPropertyFetch) Accept(v NodeVisitor) {
@ -1377,9 +1383,11 @@ func (n *ExprStaticPropertyFetch) Accept(v NodeVisitor) {
// ExprTernary node // ExprTernary node
type ExprTernary struct { type ExprTernary struct {
Node Node
Condition Vertex Condition Vertex
IfTrue Vertex QuestionTkn *token.Token
IfFalse Vertex IfTrue Vertex
ColonTkn *token.Token
IfFalse Vertex
} }
func (n *ExprTernary) Accept(v NodeVisitor) { func (n *ExprTernary) Accept(v NodeVisitor) {

View File

@ -1566,10 +1566,12 @@ func (t *DFS) Traverse(n ast.Vertex) {
t.Traverse(nn.Call) t.Traverse(nn.Call)
t.visitor.Leave("Call", true) t.visitor.Leave("Call", 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.ExprStaticPropertyFetch: case *ast.ExprStaticPropertyFetch:
if nn == nil { if nn == nil {

View File

@ -1239,7 +1239,7 @@ func (p *PrettyPrinter) printExprStaticCall(n ast.Vertex) {
io.WriteString(p.w, "::") io.WriteString(p.w, "::")
p.Print(nn.Call) p.Print(nn.Call)
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

@ -1842,9 +1842,9 @@ func (p *Printer) printExprStaticCall(n ast.Vertex) {
p.write([]byte("::")) p.write([]byte("::"))
p.Print(nn.Call) p.Print(nn.Call)
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)
} }