[refactoring] update ast structure of "While" node

This commit is contained in:
Vadym Slizov
2020-09-04 10:33:47 +03:00
parent 6976388a82
commit 3b85f5e82b
21 changed files with 1066 additions and 1162 deletions

View File

@@ -30,7 +30,6 @@ type NodeVisitor interface {
StmtAltFor(n *StmtAltFor)
StmtAltForeach(n *StmtAltForeach)
StmtAltSwitch(n *StmtAltSwitch)
StmtAltWhile(n *StmtAltWhile)
StmtBreak(n *StmtBreak)
StmtCase(n *StmtCase)
StmtCaseList(n *StmtCaseList)

View File

@@ -212,17 +212,6 @@ func (n *StmtAltSwitch) Accept(v NodeVisitor) {
v.StmtAltSwitch(n)
}
// StmtAltWhile node
type StmtAltWhile struct {
Node
Cond Vertex
Stmt Vertex
}
func (n *StmtAltWhile) Accept(v NodeVisitor) {
v.StmtAltWhile(n)
}
// StmtBreak node
type StmtBreak struct {
Node
@@ -839,8 +828,15 @@ func (n *StmtUseDeclaration) Accept(v NodeVisitor) {
// StmtWhile node
type StmtWhile struct {
Node
Cond Vertex
Stmt Vertex
Alt bool
WhileTkn *token.Token
OpenParenthesisTkn *token.Token
Cond Vertex
CloseParenthesisTkn *token.Token
ColonTkn *token.Token
Stmt Vertex
EndWhileTkn *token.Token
SemiColonTkn *token.Token
}
func (n *StmtWhile) Accept(v NodeVisitor) {

View File

@@ -196,23 +196,6 @@ func (t *DFS) Traverse(n ast.Vertex) {
t.Traverse(nn.CaseList)
t.visitor.Leave("CaseList", true)
}
case *ast.StmtAltWhile:
if nn == nil {
return
}
if !t.visitor.EnterNode(nn) {
return
}
if nn.Cond != nil {
t.visitor.Enter("Cond", true)
t.Traverse(nn.Cond)
t.visitor.Leave("Cond", true)
}
if nn.Stmt != nil {
t.visitor.Enter("Stmt", true)
t.Traverse(nn.Stmt)
t.visitor.Leave("Stmt", true)
}
case *ast.StmtBreak:
if nn == nil {
return

View File

@@ -270,12 +270,6 @@ func (v *Dump) StmtAltSwitch(n *ast.StmtAltSwitch) {
v.printNode(n.GetNode())
}
func (v *Dump) StmtAltWhile(n *ast.StmtAltWhile) {
v.printIndentIfNotSingle(v.indent - 1)
v.print("&ast.StmtAltWhile{\n")
v.printNode(n.GetNode())
}
func (v *Dump) StmtBreak(n *ast.StmtBreak) {
v.printIndentIfNotSingle(v.indent - 1)
v.print("&ast.StmtBreak{\n")
@@ -637,6 +631,11 @@ func (v *Dump) StmtWhile(n *ast.StmtWhile) {
v.printIndentIfNotSingle(v.indent - 1)
v.print("&ast.StmtWhile{\n")
v.printNode(n.GetNode())
if n.Alt {
v.printIndent(v.indent)
v.print("Alt: true,\n")
}
}
func (v *Dump) ExprArray(n *ast.ExprArray) {

View File

@@ -13,26 +13,6 @@ func (v *FilterParserNodes) EnterNode(n ast.Vertex) bool {
return true
}
func (v *FilterParserNodes) StmtWhile(n *ast.StmtWhile) {
for {
if nn, ok := n.Cond.(*ast.ParserBrackets); ok {
n.Cond = nn.Child
} else {
break
}
}
}
func (v *FilterParserNodes) StmtAltWhile(n *ast.StmtAltWhile) {
for {
if nn, ok := n.Cond.(*ast.ParserBrackets); ok {
n.Cond = nn.Child
} else {
break
}
}
}
func (v *FilterParserNodes) StmtDo(n *ast.StmtDo) {
for {
if nn, ok := n.Cond.(*ast.ParserBrackets); ok {

View File

@@ -113,3 +113,12 @@ func (v *FilterTokens) ParserBrackets(n *ast.ParserBrackets) {
n.OpenBracketTkn = nil
n.CloseBracketTkn = nil
}
func (v *FilterTokens) StmtWhile(n *ast.StmtWhile) {
n.WhileTkn = nil
n.OpenParenthesisTkn = nil
n.CloseParenthesisTkn = nil
n.ColonTkn = nil
n.EndWhileTkn = nil
n.SemiColonTkn = nil
}

View File

@@ -66,10 +66,6 @@ func (v *Null) StmtAltSwitch(_ *ast.StmtAltSwitch) {
// do nothing
}
func (v *Null) StmtAltWhile(_ *ast.StmtAltWhile) {
// do nothing
}
func (v *Null) StmtBreak(_ *ast.StmtBreak) {
// do nothing
}