[refactoring] update ast structure of "PostDec", "PostInc", "PreDec", "PreInc" and "New" nodes
This commit is contained in:
parent
b1e9f5e167
commit
45e959056b
BIN
internal/php5/php5.go
generated
BIN
internal/php5/php5.go
generated
Binary file not shown.
@ -3123,17 +3123,25 @@ instance_call:
|
|||||||
new_expr:
|
new_expr:
|
||||||
T_NEW class_name_reference ctor_arguments
|
T_NEW class_name_reference ctor_arguments
|
||||||
{
|
{
|
||||||
|
|
||||||
if $3 != nil {
|
if $3 != nil {
|
||||||
$$ = &ast.ExprNew{ast.Node{}, $2, $3.(*ast.ArgumentList)}
|
$$ = &ast.ExprNew{
|
||||||
$$.GetNode().Position = position.NewTokenNodePosition($1, $3)
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenNodePosition($1, $3),
|
||||||
|
},
|
||||||
|
NewTkn: $1,
|
||||||
|
Class: $2,
|
||||||
|
OpenParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn,
|
||||||
|
Arguments: $3.(*ast.ArgumentList).Arguments,
|
||||||
|
CloseParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn,
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$$ = &ast.ExprNew{ast.Node{}, $2, nil}
|
$$ = &ast.ExprNew{
|
||||||
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenNodePosition($1, $2),
|
||||||
|
},
|
||||||
|
Class: $2,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -3195,12 +3203,27 @@ expr_without_variable:
|
|||||||
| variable '=' '&' T_NEW class_name_reference ctor_arguments
|
| variable '=' '&' T_NEW class_name_reference ctor_arguments
|
||||||
{
|
{
|
||||||
var _new *ast.ExprNew
|
var _new *ast.ExprNew
|
||||||
|
if $3 != nil {
|
||||||
if $6 != nil {
|
_new = &ast.ExprNew{
|
||||||
_new = &ast.ExprNew{ast.Node{}, $5, $6.(*ast.ArgumentList)}
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenNodePosition($4, $6),
|
||||||
|
},
|
||||||
|
NewTkn: $4,
|
||||||
|
Class: $5,
|
||||||
|
OpenParenthesisTkn: $6.(*ast.ArgumentList).OpenParenthesisTkn,
|
||||||
|
Arguments: $6.(*ast.ArgumentList).Arguments,
|
||||||
|
CloseParenthesisTkn: $6.(*ast.ArgumentList).OpenParenthesisTkn,
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
_new = &ast.ExprNew{ast.Node{}, $5, nil}
|
_new = &ast.ExprNew{
|
||||||
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenNodePosition($4, $5),
|
||||||
|
},
|
||||||
|
NewTkn: $4,
|
||||||
|
Class: $5,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$$ = &ast.ExprAssignReference{ast.Node{}, $1, _new}
|
$$ = &ast.ExprAssignReference{ast.Node{}, $1, _new}
|
||||||
|
|
||||||
// save position
|
// save position
|
||||||
@ -3360,45 +3383,43 @@ expr_without_variable:
|
|||||||
}
|
}
|
||||||
| rw_variable T_INC
|
| rw_variable T_INC
|
||||||
{
|
{
|
||||||
$$ = &ast.ExprPostInc{ast.Node{}, $1}
|
$$ = &ast.ExprPostInc{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewNodeTokenPosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewNodeTokenPosition($1, $2)
|
},
|
||||||
|
Var: $1,
|
||||||
// save comments
|
IncTkn: $2,
|
||||||
yylex.(*Parser).MoveFreeFloating($1, $$)
|
}
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Var, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| T_INC rw_variable
|
| T_INC rw_variable
|
||||||
{
|
{
|
||||||
$$ = &ast.ExprPreInc{ast.Node{}, $2}
|
$$ = &ast.ExprPreInc{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenNodePosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
|
},
|
||||||
|
IncTkn: $1,
|
||||||
// save comments
|
Var: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
}
|
||||||
}
|
}
|
||||||
| rw_variable T_DEC
|
| rw_variable T_DEC
|
||||||
{
|
{
|
||||||
$$ = &ast.ExprPostDec{ast.Node{}, $1}
|
$$ = &ast.ExprPostDec{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewNodeTokenPosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewNodeTokenPosition($1, $2)
|
},
|
||||||
|
Var: $1,
|
||||||
// save comments
|
DecTkn: $2,
|
||||||
yylex.(*Parser).MoveFreeFloating($1, $$)
|
}
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Var, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| T_DEC rw_variable
|
| T_DEC rw_variable
|
||||||
{
|
{
|
||||||
$$ = &ast.ExprPreDec{ast.Node{}, $2}
|
$$ = &ast.ExprPreDec{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenNodePosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
|
},
|
||||||
|
DecTkn: $1,
|
||||||
// save comments
|
Var: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
}
|
||||||
}
|
}
|
||||||
| expr T_BOOLEAN_OR expr
|
| expr T_BOOLEAN_OR expr
|
||||||
{
|
{
|
||||||
|
BIN
internal/php7/php7.go
generated
BIN
internal/php7/php7.go
generated
Binary file not shown.
@ -2778,25 +2778,35 @@ new_expr:
|
|||||||
T_NEW class_name_reference ctor_arguments
|
T_NEW class_name_reference ctor_arguments
|
||||||
{
|
{
|
||||||
if $3 != nil {
|
if $3 != nil {
|
||||||
$$ = &ast.ExprNew{ast.Node{}, $2, $3.(*ast.ArgumentList)}
|
$$ = &ast.ExprNew{
|
||||||
$$.GetNode().Position = position.NewTokenNodePosition($1, $3)
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenNodePosition($1, $3),
|
||||||
|
},
|
||||||
|
NewTkn: $1,
|
||||||
|
Class: $2,
|
||||||
|
OpenParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn,
|
||||||
|
Arguments: $3.(*ast.ArgumentList).Arguments,
|
||||||
|
CloseParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn,
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$$ = &ast.ExprNew{ast.Node{}, $2, nil}
|
$$ = &ast.ExprNew{
|
||||||
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenNodePosition($1, $2),
|
||||||
|
},
|
||||||
|
NewTkn: $1,
|
||||||
|
Class: $2,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| T_NEW anonymous_class
|
| T_NEW anonymous_class
|
||||||
{
|
{
|
||||||
$$ = &ast.ExprNew{ast.Node{}, $2, nil}
|
$$ = &ast.ExprNew{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenNodePosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
|
},
|
||||||
|
NewTkn: $1,
|
||||||
// save comments
|
Class: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -3018,45 +3028,43 @@ expr_without_variable:
|
|||||||
}
|
}
|
||||||
| variable T_INC
|
| variable T_INC
|
||||||
{
|
{
|
||||||
$$ = &ast.ExprPostInc{ast.Node{}, $1}
|
$$ = &ast.ExprPostInc{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewNodeTokenPosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewNodeTokenPosition($1, $2)
|
},
|
||||||
|
Var: $1,
|
||||||
// save comments
|
IncTkn: $2,
|
||||||
yylex.(*Parser).MoveFreeFloating($1, $$)
|
}
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Var, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| T_INC variable
|
| T_INC variable
|
||||||
{
|
{
|
||||||
$$ = &ast.ExprPreInc{ast.Node{}, $2}
|
$$ = &ast.ExprPreInc{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenNodePosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
|
},
|
||||||
|
IncTkn: $1,
|
||||||
// save comments
|
Var: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
}
|
||||||
}
|
}
|
||||||
| variable T_DEC
|
| variable T_DEC
|
||||||
{
|
{
|
||||||
$$ = &ast.ExprPostDec{ast.Node{}, $1}
|
$$ = &ast.ExprPostDec{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewNodeTokenPosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewNodeTokenPosition($1, $2)
|
},
|
||||||
|
Var: $1,
|
||||||
// save comments
|
DecTkn: $2,
|
||||||
yylex.(*Parser).MoveFreeFloating($1, $$)
|
}
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Var, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| T_DEC variable
|
| T_DEC variable
|
||||||
{
|
{
|
||||||
$$ = &ast.ExprPreDec{ast.Node{}, $2}
|
$$ = &ast.ExprPreDec{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenNodePosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
|
},
|
||||||
|
DecTkn: $1,
|
||||||
// save comments
|
Var: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
}
|
||||||
}
|
}
|
||||||
| expr T_BOOLEAN_OR expr
|
| expr T_BOOLEAN_OR expr
|
||||||
{
|
{
|
||||||
|
@ -1230,8 +1230,11 @@ func (n *ExprMethodCall) Accept(v NodeVisitor) {
|
|||||||
// ExprNew node
|
// ExprNew node
|
||||||
type ExprNew struct {
|
type ExprNew struct {
|
||||||
Node
|
Node
|
||||||
Class Vertex
|
NewTkn *token.Token
|
||||||
ArgumentList *ArgumentList
|
Class Vertex
|
||||||
|
OpenParenthesisTkn *token.Token
|
||||||
|
Arguments []Vertex
|
||||||
|
CloseParenthesisTkn *token.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *ExprNew) Accept(v NodeVisitor) {
|
func (n *ExprNew) Accept(v NodeVisitor) {
|
||||||
@ -1241,7 +1244,8 @@ func (n *ExprNew) Accept(v NodeVisitor) {
|
|||||||
// ExprPostDec node
|
// ExprPostDec node
|
||||||
type ExprPostDec struct {
|
type ExprPostDec struct {
|
||||||
Node
|
Node
|
||||||
Var Vertex
|
Var Vertex
|
||||||
|
DecTkn *token.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *ExprPostDec) Accept(v NodeVisitor) {
|
func (n *ExprPostDec) Accept(v NodeVisitor) {
|
||||||
@ -1251,7 +1255,8 @@ func (n *ExprPostDec) Accept(v NodeVisitor) {
|
|||||||
// ExprPostInc node
|
// ExprPostInc node
|
||||||
type ExprPostInc struct {
|
type ExprPostInc struct {
|
||||||
Node
|
Node
|
||||||
Var Vertex
|
Var Vertex
|
||||||
|
IncTkn *token.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *ExprPostInc) Accept(v NodeVisitor) {
|
func (n *ExprPostInc) Accept(v NodeVisitor) {
|
||||||
@ -1261,7 +1266,8 @@ func (n *ExprPostInc) Accept(v NodeVisitor) {
|
|||||||
// ExprPreDec node
|
// ExprPreDec node
|
||||||
type ExprPreDec struct {
|
type ExprPreDec struct {
|
||||||
Node
|
Node
|
||||||
Var Vertex
|
DecTkn *token.Token
|
||||||
|
Var Vertex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *ExprPreDec) Accept(v NodeVisitor) {
|
func (n *ExprPreDec) Accept(v NodeVisitor) {
|
||||||
@ -1271,7 +1277,8 @@ func (n *ExprPreDec) Accept(v NodeVisitor) {
|
|||||||
// ExprPreInc node
|
// ExprPreInc node
|
||||||
type ExprPreInc struct {
|
type ExprPreInc struct {
|
||||||
Node
|
Node
|
||||||
Var Vertex
|
IncTkn *token.Token
|
||||||
|
Var Vertex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *ExprPreInc) Accept(v NodeVisitor) {
|
func (n *ExprPreInc) Accept(v NodeVisitor) {
|
||||||
|
@ -1415,10 +1415,12 @@ func (t *DFS) Traverse(n ast.Vertex) {
|
|||||||
t.Traverse(nn.Class)
|
t.Traverse(nn.Class)
|
||||||
t.visitor.Leave("Class", true)
|
t.visitor.Leave("Class", 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.ExprPostDec:
|
case *ast.ExprPostDec:
|
||||||
if nn == nil {
|
if nn == nil {
|
||||||
|
@ -1143,9 +1143,9 @@ func (p *PrettyPrinter) printExprNew(n ast.Vertex) {
|
|||||||
io.WriteString(p.w, "new ")
|
io.WriteString(p.w, "new ")
|
||||||
p.Print(nn.Class)
|
p.Print(nn.Class)
|
||||||
|
|
||||||
if nn.ArgumentList != nil {
|
if nn.Arguments != nil {
|
||||||
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, ")")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1710,10 +1710,10 @@ func (p *Printer) printExprNew(n ast.Vertex) {
|
|||||||
p.bufStart = " "
|
p.bufStart = " "
|
||||||
p.Print(nn.Class)
|
p.Print(nn.Class)
|
||||||
|
|
||||||
if nn.ArgumentList != nil {
|
if nn.Arguments != nil {
|
||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user