[refactoring] update ast structure of "For" node

This commit is contained in:
Vadym Slizov
2020-09-04 11:37:17 +03:00
parent c274c4f92f
commit 0e73cd8852
21 changed files with 1041 additions and 1156 deletions

View File

@@ -27,7 +27,6 @@ type NodeVisitor interface {
ArgumentList(n *ArgumentList)
Argument(n *Argument)
StmtAltFor(n *StmtAltFor)
StmtAltForeach(n *StmtAltForeach)
StmtAltSwitch(n *StmtAltSwitch)
StmtBreak(n *StmtBreak)

View File

@@ -175,19 +175,6 @@ func (n *ScalarString) Accept(v NodeVisitor) {
v.ScalarString(n)
}
// StmtAltFor node
type StmtAltFor struct {
Node
Init []Vertex
Cond []Vertex
Loop []Vertex
Stmt Vertex
}
func (n *StmtAltFor) Accept(v NodeVisitor) {
v.StmtAltFor(n)
}
// StmtAltForeach node
type StmtAltForeach struct {
Node
@@ -453,10 +440,19 @@ func (n *StmtFinally) Accept(v NodeVisitor) {
// StmtFor node
type StmtFor struct {
Node
Init []Vertex
Cond []Vertex
Loop []Vertex
Stmt Vertex
Alt bool
ForTkn *token.Token
OpenParenthesisTkn *token.Token
Init []Vertex
InitSemiColonTkn *token.Token
Cond []Vertex
CondSemiColonTkn *token.Token
Loop []Vertex
CloseParenthesisTkn *token.Token
ColonTkn *token.Token
Stmt Vertex
EndForTkn *token.Token
SemiColonTkn *token.Token
}
func (n *StmtFor) Accept(v NodeVisitor) {

View File

@@ -119,39 +119,6 @@ func (t *DFS) Traverse(n ast.Vertex) {
t.Traverse(nn.Expr)
t.visitor.Leave("Expr", true)
}
case *ast.StmtAltFor:
if nn == nil {
return
}
if !t.visitor.EnterNode(nn) {
return
}
if nn.Init != nil {
t.visitor.Enter("Init", false)
for _, c := range nn.Init {
t.Traverse(c)
}
t.visitor.Leave("Init", false)
}
if nn.Cond != nil {
t.visitor.Enter("Cond", false)
for _, c := range nn.Cond {
t.Traverse(c)
}
t.visitor.Leave("Cond", false)
}
if nn.Loop != nil {
t.visitor.Enter("Loop", false)
for _, c := range nn.Loop {
t.Traverse(c)
}
t.visitor.Leave("Loop", false)
}
if nn.Stmt != nil {
t.visitor.Enter("Stmt", true)
t.Traverse(nn.Stmt)
t.visitor.Leave("Stmt", true)
}
case *ast.StmtAltForeach:
if nn == nil {
return

View File

@@ -252,12 +252,6 @@ func (v *Dump) Argument(n *ast.Argument) {
}
}
func (v *Dump) StmtAltFor(n *ast.StmtAltFor) {
v.printIndentIfNotSingle(v.indent - 1)
v.print("&ast.StmtAltFor{\n")
v.printNode(n.GetNode())
}
func (v *Dump) StmtAltForeach(n *ast.StmtAltForeach) {
v.printIndentIfNotSingle(v.indent - 1)
v.print("&ast.StmtAltForeach{\n")
@@ -414,6 +408,11 @@ func (v *Dump) StmtFor(n *ast.StmtFor) {
v.printIndentIfNotSingle(v.indent - 1)
v.print("&ast.StmtFor{\n")
v.printNode(n.GetNode())
if n.Alt {
v.printIndent(v.indent)
v.print("Alt: true,\n")
}
}
func (v *Dump) StmtForeach(n *ast.StmtForeach) {

View File

@@ -209,44 +209,6 @@ func (v *FilterParserNodes) ExprVariable(n *ast.ExprVariable) {
}
}
func (v *FilterParserNodes) StmtFor(n *ast.StmtFor) {
for k, v := range n.Init {
for {
if nn, ok := v.(*ast.ParserBrackets); ok {
v = nn.Child
} else {
break
}
}
n.Init[k] = v
}
for k, v := range n.Cond {
for {
if nn, ok := v.(*ast.ParserBrackets); ok {
v = nn.Child
} else {
break
}
}
n.Cond[k] = v
}
for k, v := range n.Loop {
for {
if nn, ok := v.(*ast.ParserBrackets); ok {
v = nn.Child
} else {
break
}
}
n.Loop[k] = v
}
}
func (v *FilterParserNodes) ExprAssign(n *ast.ExprAssign) {
for {
if nn, ok := n.Expr.(*ast.ParserBrackets); ok {

View File

@@ -130,3 +130,14 @@ func (v *FilterTokens) StmtDo(n *ast.StmtDo) {
n.CloseParenthesisTkn = nil
n.SemiColonTkn = nil
}
func (v *FilterTokens) StmtFor(n *ast.StmtFor) {
n.ForTkn = nil
n.OpenParenthesisTkn = nil
n.InitSemiColonTkn = nil
n.CondSemiColonTkn = nil
n.CloseParenthesisTkn = nil
n.ColonTkn = nil
n.EndForTkn = nil
n.SemiColonTkn = nil
}

View File

@@ -54,10 +54,6 @@ func (v *Null) Argument(_ *ast.Argument) {
// do nothing
}
func (v *Null) StmtAltFor(_ *ast.StmtAltFor) {
// do nothing
}
func (v *Null) StmtAltForeach(_ *ast.StmtAltForeach) {
// do nothing
}