[refactoring] update ast structure of "Parameter", "Class", "FunctionCall", "MethodCall", "New" and "StaticCall" nodes

This commit is contained in:
Vadym Slizov 2020-12-04 11:36:12 +02:00
parent df1626b7dc
commit f3203c0b5f
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
11 changed files with 85 additions and 252 deletions

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -2028,40 +2028,6 @@ non_empty_parameter_list:
parameter:
optional_class_type is_reference is_variadic T_VARIABLE
{
var variable ast.Vertex
variable = &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
VarName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
IdentifierTkn: $4,
Value: $4.Value,
},
}
if $3 != nil {
variable = &ast.Variadic{
Node: ast.Node{
Position: position.NewTokensPosition($3, $4),
},
VariadicTkn: $3,
Var: variable,
}
}
if $2 != nil {
variable = &ast.Reference{
Node: ast.Node{
Position: position.NewTokensPosition($2, $4),
},
AmpersandTkn: $2,
Var: variable,
}
}
pos := position.NewTokenPosition($4)
if $1 != nil {
pos = position.NewNodeTokenPosition($1, $4)
@ -2075,46 +2041,25 @@ parameter:
Node: ast.Node{
Position: pos,
},
Type: $1,
Var: variable,
Type: $1,
AmpersandTkn: $2,
VariadicTkn: $3,
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,
},
},
}
}
| optional_class_type is_reference is_variadic T_VARIABLE '=' expr
{
var variable ast.Vertex
variable = &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
VarName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
IdentifierTkn: $4,
Value: $4.Value,
},
}
if $3 != nil {
variable = &ast.Variadic{
Node: ast.Node{
Position: position.NewTokensPosition($3, $4),
},
VariadicTkn: $3,
Var: variable,
}
}
if $2 != nil {
variable = &ast.Reference{
Node: ast.Node{
Position: position.NewTokensPosition($2, $4),
},
AmpersandTkn: $2,
Var: variable,
}
}
pos := position.NewTokenNodePosition($4, $6)
if $1 != nil {
pos = position.NewNodesPosition($1, $6)
@ -2129,7 +2074,20 @@ parameter:
Position: pos,
},
Type: $1,
Var: variable,
AmpersandTkn: $2,
VariadicTkn: $3,
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,
},
},
EqualTkn: $5,
DefaultValue: $6,
}
@ -3116,6 +3074,7 @@ new_expr:
Class: $2,
OpenParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $3.(*ast.ArgumentList).Arguments,
SeparatorTkns: $3.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn,
}
} else {
@ -3185,6 +3144,7 @@ expr_without_variable:
Class: $5,
OpenParenthesisTkn: $6.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $6.(*ast.ArgumentList).Arguments,
SeparatorTkns: $6.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $6.(*ast.ArgumentList).OpenParenthesisTkn,
}
} else {
@ -4228,6 +4188,7 @@ function_call:
},
OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $2.(*ast.ArgumentList).Arguments,
SeparatorTkns: $2.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
}
}
@ -4247,6 +4208,7 @@ function_call:
},
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments,
SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
}
}
@ -4265,6 +4227,7 @@ function_call:
},
OpenParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $3.(*ast.ArgumentList).Arguments,
SeparatorTkns: $3.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn,
}
}
@ -4279,6 +4242,7 @@ function_call:
Call: $3,
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments,
SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
}
}
@ -4293,6 +4257,7 @@ function_call:
Call: $3,
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments,
SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
}
}
@ -4307,6 +4272,7 @@ function_call:
Call: $3,
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments,
SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
}
}
@ -4321,6 +4287,7 @@ function_call:
Call: $3,
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments,
SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
}
}
@ -4333,6 +4300,7 @@ function_call:
Function: $1,
OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $2.(*ast.ArgumentList).Arguments,
SeparatorTkns: $2.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
}
}
@ -5462,6 +5430,7 @@ variable:
},
OpenParenthesisTkn: mc.OpenParenthesisTkn,
Arguments: mc.Arguments,
SeparatorTkns: mc.SeparatorTkns,
CloseParenthesisTkn: mc.OpenParenthesisTkn,
},
)
@ -5555,6 +5524,7 @@ variable_property:
},
OpenParenthesisTkn: mc.OpenParenthesisTkn,
Arguments: mc.Arguments,
SeparatorTkns: mc.SeparatorTkns,
CloseParenthesisTkn: mc.OpenParenthesisTkn,
},
)
@ -5610,6 +5580,7 @@ method:
},
OpenParenthesisTkn: $1.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $1.(*ast.ArgumentList).Arguments,
SeparatorTkns: $1.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $1.(*ast.ArgumentList).CloseParenthesisTkn,
}
}

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -1849,40 +1849,6 @@ non_empty_parameter_list:
parameter:
optional_type is_reference is_variadic T_VARIABLE
{
var variable ast.Vertex
variable = &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
VarName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
IdentifierTkn: $4,
Value: $4.Value,
},
}
if $3 != nil {
variable = &ast.Variadic{
Node: ast.Node{
Position: position.NewTokensPosition($3, $4),
},
VariadicTkn: $3,
Var: variable,
}
}
if $2 != nil {
variable = &ast.Reference{
Node: ast.Node{
Position: position.NewTokensPosition($2, $4),
},
AmpersandTkn: $2,
Var: variable,
}
}
pos := position.NewTokenPosition($4)
if $1 != nil {
pos = position.NewNodeTokenPosition($1, $4)
@ -1896,46 +1862,25 @@ parameter:
Node: ast.Node{
Position: pos,
},
Type: $1,
Var: variable,
Type: $1,
AmpersandTkn: $2,
VariadicTkn: $3,
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,
},
},
}
}
| optional_type is_reference is_variadic T_VARIABLE '=' expr
{
var variable ast.Vertex
variable = &ast.ExprVariable{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
VarName: &ast.Identifier{
Node: ast.Node{
Position: position.NewTokenPosition($4),
},
IdentifierTkn: $4,
Value: $4.Value,
},
}
if $3 != nil {
variable = &ast.Variadic{
Node: ast.Node{
Position: position.NewTokensPosition($3, $4),
},
VariadicTkn: $3,
Var: variable,
}
}
if $2 != nil {
variable = &ast.Reference{
Node: ast.Node{
Position: position.NewTokensPosition($2, $4),
},
AmpersandTkn: $2,
Var: variable,
}
}
pos := position.NewTokenNodePosition($4, $6)
if $1 != nil {
pos = position.NewNodesPosition($1, $6)
@ -1950,7 +1895,20 @@ parameter:
Position: pos,
},
Type: $1,
Var: variable,
AmpersandTkn: $2,
VariadicTkn: $3,
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,
},
},
EqualTkn: $5,
DefaultValue: $6,
}
@ -2758,6 +2716,7 @@ anonymous_class:
ClassTkn: $1,
OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $2.(*ast.ArgumentList).Arguments,
SeparatorTkns: $2.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
Extends: $3,
Implements: $4,
@ -2780,6 +2739,7 @@ new_expr:
Class: $2,
OpenParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $3.(*ast.ArgumentList).Arguments,
SeparatorTkns: $3.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn,
}
} else {
@ -3777,6 +3737,7 @@ function_call:
Function: $1,
OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $2.(*ast.ArgumentList).Arguments,
SeparatorTkns: $2.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
}
}
@ -3791,6 +3752,7 @@ function_call:
Call: $3,
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments,
SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
}
}
@ -3805,6 +3767,7 @@ function_call:
Call: $3,
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments,
SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
}
}
@ -3817,6 +3780,7 @@ function_call:
Function: $1,
OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $2.(*ast.ArgumentList).Arguments,
SeparatorTkns: $2.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
}
}
@ -4285,6 +4249,7 @@ callable_variable:
Method: $3,
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments,
SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $4.(*ast.ArgumentList).CloseParenthesisTkn,
}
}

View File

@ -20,8 +20,6 @@ type Visitor interface {
type NodeVisitor interface {
Root(n *Root)
Nullable(n *Nullable)
Reference(n *Reference)
Variadic(n *Variadic)
Parameter(n *Parameter)
Identifier(n *Identifier)
Argument(n *Argument)

View File

@ -42,32 +42,12 @@ func (n *Nullable) Accept(v NodeVisitor) {
v.Nullable(n)
}
// Reference node
type Reference struct {
Node
AmpersandTkn *token.Token
Var Vertex
}
func (n *Reference) Accept(v NodeVisitor) {
v.Reference(n)
}
// Variadic node
type Variadic struct {
Node
VariadicTkn *token.Token
Var Vertex
}
func (n *Variadic) Accept(v NodeVisitor) {
v.Variadic(n)
}
// Parameter node
type Parameter struct {
Node
Type Vertex
AmpersandTkn *token.Token
VariadicTkn *token.Token
Var Vertex
EqualTkn *token.Token
DefaultValue Vertex
@ -231,6 +211,7 @@ type StmtClass struct {
ClassName Vertex
OpenParenthesisTkn *token.Token
Arguments []Vertex
SeparatorTkns []*token.Token
CloseParenthesisTkn *token.Token
Extends Vertex
Implements Vertex
@ -1131,6 +1112,7 @@ type ExprFunctionCall struct {
Function Vertex
OpenParenthesisTkn *token.Token
Arguments []Vertex
SeparatorTkns []*token.Token
CloseParenthesisTkn *token.Token
}
@ -1208,6 +1190,7 @@ type ExprMethodCall struct {
Method Vertex
OpenParenthesisTkn *token.Token
Arguments []Vertex
SeparatorTkns []*token.Token
CloseParenthesisTkn *token.Token
}
@ -1222,6 +1205,7 @@ type ExprNew struct {
Class Vertex
OpenParenthesisTkn *token.Token
Arguments []Vertex
SeparatorTkns []*token.Token
CloseParenthesisTkn *token.Token
}
@ -1349,6 +1333,7 @@ type ExprStaticCall struct {
Call Vertex
OpenParenthesisTkn *token.Token
Arguments []Vertex
SeparatorTkns []*token.Token
CloseParenthesisTkn *token.Token
}

View File

@ -40,30 +40,6 @@ func (t *DFS) Traverse(n ast.Vertex) {
t.Traverse(nn.Expr)
t.visitor.Leave("Expr", true)
}
case *ast.Reference:
if nn == nil {
return
}
if !t.visitor.EnterNode(nn) {
return
}
if nn.Var != nil {
t.visitor.Enter("Var", true)
t.Traverse(nn.Var)
t.visitor.Leave("Var", true)
}
case *ast.Variadic:
if nn == nil {
return
}
if !t.visitor.EnterNode(nn) {
return
}
if nn.Var != nil {
t.visitor.Enter("Var", true)
t.Traverse(nn.Var)
t.visitor.Leave("Var", true)
}
case *ast.Parameter:
if nn == nil {
return

View File

@ -203,18 +203,6 @@ func (v *Dump) Nullable(n *ast.Nullable) {
v.printNode(n.GetNode())
}
func (v *Dump) Reference(n *ast.Reference) {
v.printIndentIfNotSingle(v.indent - 1)
v.print("&ast.Reference{\n")
v.printNode(n.GetNode())
}
func (v *Dump) Variadic(n *ast.Variadic) {
v.printIndentIfNotSingle(v.indent - 1)
v.print("&ast.Variadic{\n")
v.printNode(n.GetNode())
}
func (v *Dump) Parameter(n *ast.Parameter) {
v.printIndent(v.indent - 1)
v.print("&ast.Parameter{\n")

View File

@ -30,14 +30,6 @@ func (v *Null) Nullable(_ *ast.Nullable) {
// do nothing
}
func (v *Null) Reference(_ *ast.Reference) {
// do nothing
}
func (v *Null) Variadic(_ *ast.Variadic) {
// do nothing
}
func (v *Null) Parameter(_ *ast.Parameter) {
// do nothing
}

View File

@ -64,10 +64,6 @@ func (p *PrettyPrinter) printNode(n ast.Vertex) {
p.printNodeRoot(n)
case *ast.Identifier:
p.printNodeIdentifier(n)
case *ast.Reference:
p.printNodeReference(n)
case *ast.Variadic:
p.printNodeVariadic(n)
case *ast.Parameter:
p.printNodeParameter(n)
case *ast.Nullable:
@ -421,20 +417,6 @@ func (p *PrettyPrinter) printNodeIdentifier(n ast.Vertex) {
io.WriteString(p.w, v)
}
func (p *PrettyPrinter) printNodeReference(n ast.Vertex) {
nn := n.(*ast.Reference)
io.WriteString(p.w, "&")
p.Print(nn.Var)
}
func (p *PrettyPrinter) printNodeVariadic(n ast.Vertex) {
nn := n.(*ast.Variadic)
io.WriteString(p.w, "...")
p.Print(nn.Var)
}
func (p *PrettyPrinter) printNodeParameter(n ast.Vertex) {
nn := n.(*ast.Parameter)

View File

@ -149,10 +149,6 @@ func (p *Printer) printNode(n ast.Vertex) {
p.printNodeRoot(n)
case *ast.Identifier:
p.printNodeIdentifier(n)
case *ast.Reference:
p.printNodeReference(n)
case *ast.Variadic:
p.printNodeVariadic(n)
case *ast.Parameter:
p.printNodeParameter(n)
case *ast.Nullable:
@ -505,26 +501,6 @@ func (p *Printer) printNodeIdentifier(n ast.Vertex) {
p.printFreeFloating(nn, token.End)
}
func (p *Printer) printNodeReference(n ast.Vertex) {
nn := n.(*ast.Reference)
p.printFreeFloating(nn, token.Start)
p.write([]byte("&"))
p.Print(nn.Var)
p.printFreeFloating(nn, token.End)
}
func (p *Printer) printNodeVariadic(n ast.Vertex) {
nn := n.(*ast.Variadic)
p.printFreeFloating(nn, token.Start)
p.write([]byte("..."))
p.Print(nn.Var)
p.printFreeFloating(nn, token.End)
}
func (p *Printer) printNodeParameter(n ast.Vertex) {
nn := n.(*ast.Parameter)
p.printFreeFloating(nn, token.Start)