[refactoring] update ast structure of "Declare" and "ConstList" nodes
This commit is contained in:
@@ -189,7 +189,6 @@ type NodeVisitor interface {
|
||||
NameRelative(n *NameRelative)
|
||||
NameNamePart(n *NameNamePart)
|
||||
|
||||
ParserAs(n *ParserAs)
|
||||
ParserNsSeparator(n *ParserNsSeparator)
|
||||
ParserBrackets(n *ParserBrackets)
|
||||
ParserSeparatedList(n *ParserSeparatedList)
|
||||
}
|
||||
|
||||
@@ -278,9 +278,10 @@ func (n *StmtClassMethod) Accept(v NodeVisitor) {
|
||||
// StmtConstList node
|
||||
type StmtConstList struct {
|
||||
Node
|
||||
ConstTkn *token.Token
|
||||
Consts []Vertex
|
||||
SemiColonTkn *token.Token
|
||||
ConstTkn *token.Token
|
||||
Consts []Vertex
|
||||
SeparatorTkns []*token.Token
|
||||
SemiColonTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *StmtConstList) Accept(v NodeVisitor) {
|
||||
@@ -315,9 +316,16 @@ func (n *StmtContinue) Accept(v NodeVisitor) {
|
||||
// StmtDeclare node
|
||||
type StmtDeclare struct {
|
||||
Node
|
||||
Alt bool
|
||||
Consts []Vertex
|
||||
Stmt Vertex
|
||||
Alt bool
|
||||
DeclareTkn *token.Token
|
||||
OpenParenthesisTkn *token.Token
|
||||
Consts []Vertex
|
||||
SeparatorTkns []*token.Token
|
||||
CloseParenthesisTkn *token.Token
|
||||
ColonTkn *token.Token
|
||||
Stmt Vertex
|
||||
EndDeclareTkn *token.Token
|
||||
SemiColonTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *StmtDeclare) Accept(v NodeVisitor) {
|
||||
@@ -1887,24 +1895,6 @@ func (n *NameNamePart) Accept(v NodeVisitor) {
|
||||
v.NameNamePart(n)
|
||||
}
|
||||
|
||||
type ParserAs struct {
|
||||
Node
|
||||
Child Vertex
|
||||
}
|
||||
|
||||
func (n *ParserAs) Accept(v NodeVisitor) {
|
||||
v.ParserAs(n)
|
||||
}
|
||||
|
||||
type ParserNsSeparator struct {
|
||||
Node
|
||||
Child Vertex
|
||||
}
|
||||
|
||||
func (n *ParserNsSeparator) Accept(v NodeVisitor) {
|
||||
v.ParserNsSeparator(n)
|
||||
}
|
||||
|
||||
type ParserBrackets struct {
|
||||
Node
|
||||
OpenBracketTkn *token.Token
|
||||
@@ -1915,3 +1905,13 @@ type ParserBrackets struct {
|
||||
func (n *ParserBrackets) Accept(v NodeVisitor) {
|
||||
v.ParserBrackets(n)
|
||||
}
|
||||
|
||||
type ParserSeparatedList struct {
|
||||
Node
|
||||
Items []Vertex
|
||||
SeparatorTkns []*token.Token
|
||||
}
|
||||
|
||||
func (n *ParserSeparatedList) Accept(v NodeVisitor) {
|
||||
v.ParserSeparatedList(n)
|
||||
}
|
||||
|
||||
@@ -2607,30 +2607,6 @@ func (t *DFS) Traverse(n ast.Vertex) {
|
||||
if !t.visitor.EnterNode(nn) {
|
||||
return
|
||||
}
|
||||
case *ast.ParserAs:
|
||||
if nn == nil {
|
||||
return
|
||||
}
|
||||
if !t.visitor.EnterNode(nn) {
|
||||
return
|
||||
}
|
||||
if nn.Child != nil {
|
||||
t.visitor.Enter("Child", true)
|
||||
t.Traverse(nn.Child)
|
||||
t.visitor.Leave("Child", true)
|
||||
}
|
||||
case *ast.ParserNsSeparator:
|
||||
if nn == nil {
|
||||
return
|
||||
}
|
||||
if !t.visitor.EnterNode(nn) {
|
||||
return
|
||||
}
|
||||
if nn.Child != nil {
|
||||
t.visitor.Enter("Child", true)
|
||||
t.Traverse(nn.Child)
|
||||
t.visitor.Leave("Child", true)
|
||||
}
|
||||
case *ast.ParserBrackets:
|
||||
if nn == nil {
|
||||
return
|
||||
|
||||
@@ -1293,20 +1293,12 @@ func (v *Dump) NameNamePart(n *ast.NameNamePart) {
|
||||
v.print(fmt.Sprintf("Value: []byte(%q),\n", n.Value))
|
||||
}
|
||||
|
||||
func (v *Dump) ParserAs(n *ast.ParserAs) {
|
||||
v.printIndentIfNotSingle(v.indent - 1)
|
||||
v.print("&ast.ParserAs{\n")
|
||||
v.printNode(n.GetNode())
|
||||
}
|
||||
|
||||
func (v *Dump) ParserNsSeparator(n *ast.ParserNsSeparator) {
|
||||
v.printIndentIfNotSingle(v.indent - 1)
|
||||
v.print("&ast.ParserNsSeparator{\n")
|
||||
v.printNode(n.GetNode())
|
||||
}
|
||||
|
||||
func (v *Dump) ParserBrackets(n *ast.ParserBrackets) {
|
||||
v.printIndentIfNotSingle(v.indent - 1)
|
||||
v.print("&ast.ParserBrackets{\n")
|
||||
v.printNode(n.GetNode())
|
||||
}
|
||||
|
||||
func (v *Dump) ParserSeparatedList(n *ast.ParserSeparatedList) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ func (v *FilterTokens) StmtHaltCompiler(n *ast.StmtHaltCompiler) {
|
||||
|
||||
func (v *FilterTokens) StmtConstList(n *ast.StmtConstList) {
|
||||
n.ConstTkn = nil
|
||||
n.SeparatorTkns = nil
|
||||
n.SemiColonTkn = nil
|
||||
}
|
||||
|
||||
@@ -224,3 +225,13 @@ func (v *FilterTokens) StmtForeach(n *ast.StmtForeach) {
|
||||
n.EndForeachTkn = nil
|
||||
n.SemiColonTkn = nil
|
||||
}
|
||||
|
||||
func (v *FilterTokens) StmtDeclare(n *ast.StmtDeclare) {
|
||||
n.DeclareTkn = nil
|
||||
n.OpenParenthesisTkn = nil
|
||||
n.SeparatorTkns = nil
|
||||
n.CloseParenthesisTkn = nil
|
||||
n.ColonTkn = nil
|
||||
n.EndDeclareTkn = nil
|
||||
n.SemiColonTkn = nil
|
||||
}
|
||||
|
||||
@@ -674,14 +674,10 @@ func (v *Null) NameNamePart(_ *ast.NameNamePart) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) ParserAs(_ *ast.ParserAs) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) ParserNsSeparator(_ *ast.ParserNsSeparator) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) ParserBrackets(_ *ast.ParserBrackets) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) ParserSeparatedList(_ *ast.ParserSeparatedList) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@@ -484,10 +484,6 @@ func (p *Printer) printNode(n ast.Vertex) {
|
||||
p.printStmtUseDeclaration(n)
|
||||
case *ast.StmtWhile:
|
||||
p.printStmtWhile(n)
|
||||
case *ast.ParserAs:
|
||||
p.printParserAs(n)
|
||||
case *ast.ParserNsSeparator:
|
||||
p.printParserNsSeparator(n)
|
||||
case *ast.ParserBrackets:
|
||||
p.printParserBrackets(n)
|
||||
}
|
||||
@@ -2158,7 +2154,7 @@ func (p *Printer) printStmtClassConstList(n *ast.StmtClassConstList) {
|
||||
func (p *Printer) printStmtConstList(n *ast.StmtConstList) {
|
||||
p.printToken(n.ConstTkn, "const")
|
||||
p.bufStart = " "
|
||||
p.joinPrintRefactored(",", n.Consts)
|
||||
p.printSeparatedList(n.Consts, n.SeparatorTkns, ",")
|
||||
p.printToken(n.SemiColonTkn, ";")
|
||||
}
|
||||
|
||||
@@ -2180,37 +2176,33 @@ func (p *Printer) printStmtContinue(n *ast.StmtContinue) {
|
||||
p.printToken(n.SemiColonTkn, ";")
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtDeclare(n ast.Vertex) {
|
||||
nn := n.(*ast.StmtDeclare)
|
||||
p.printFreeFloating(nn, token.Start)
|
||||
func (p *Printer) printStmtDeclare(n *ast.StmtDeclare) {
|
||||
if n.Alt {
|
||||
p.printStmtAltDeclare(n)
|
||||
return
|
||||
}
|
||||
p.printToken(n.DeclareTkn, "declare")
|
||||
p.printToken(n.OpenParenthesisTkn, "(")
|
||||
p.printSeparatedList(n.Consts, n.SeparatorTkns, ",")
|
||||
p.printToken(n.CloseParenthesisTkn, ")")
|
||||
p.Print(n.Stmt)
|
||||
}
|
||||
|
||||
p.write([]byte("declare"))
|
||||
p.printFreeFloating(nn, token.Declare)
|
||||
p.write([]byte("("))
|
||||
p.joinPrintRefactored(",", nn.Consts)
|
||||
p.printFreeFloating(nn, token.ConstList)
|
||||
p.write([]byte(")"))
|
||||
func (p *Printer) printStmtAltDeclare(n *ast.StmtDeclare) {
|
||||
p.printToken(n.DeclareTkn, "declare")
|
||||
p.printToken(n.OpenParenthesisTkn, "(")
|
||||
p.printSeparatedList(n.Consts, n.SeparatorTkns, ",")
|
||||
p.printToken(n.CloseParenthesisTkn, ")")
|
||||
p.printToken(n.ColonTkn, ":")
|
||||
|
||||
if nn.Alt {
|
||||
p.printFreeFloating(nn, token.Cond)
|
||||
p.write([]byte(":"))
|
||||
|
||||
s := nn.Stmt.(*ast.StmtStmtList)
|
||||
p.printNodes(s.Stmts)
|
||||
p.printFreeFloating(nn, token.Stmts)
|
||||
|
||||
p.write([]byte("enddeclare"))
|
||||
p.printFreeFloating(nn, token.AltEnd)
|
||||
|
||||
p.printFreeFloating(nn, token.SemiColon)
|
||||
if nn.GetNode().Tokens.IsEmpty() {
|
||||
p.write([]byte(";"))
|
||||
}
|
||||
if stmtList, ok := n.Stmt.(*ast.StmtStmtList); ok {
|
||||
p.printNodes(stmtList.Stmts)
|
||||
} else {
|
||||
p.Print(nn.Stmt)
|
||||
p.Print(n.Stmt)
|
||||
}
|
||||
|
||||
p.printFreeFloating(nn, token.End)
|
||||
p.printToken(n.EndDeclareTkn, "enddeclare")
|
||||
p.printToken(n.SemiColonTkn, ";")
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtDefault(n *ast.StmtDefault) {
|
||||
@@ -2960,26 +2952,6 @@ func (p *Printer) printStmtAltWhile(n *ast.StmtWhile) {
|
||||
p.printToken(n.SemiColonTkn, ";")
|
||||
}
|
||||
|
||||
func (p *Printer) printParserAs(n ast.Vertex) {
|
||||
nn := n.(*ast.ParserAs)
|
||||
p.printFreeFloating(nn, token.Start)
|
||||
|
||||
p.write([]byte("as"))
|
||||
p.Print(nn.Child)
|
||||
|
||||
p.printFreeFloating(nn, token.End)
|
||||
}
|
||||
|
||||
func (p *Printer) printParserNsSeparator(n ast.Vertex) {
|
||||
nn := n.(*ast.ParserNsSeparator)
|
||||
p.printFreeFloating(nn, token.Start)
|
||||
|
||||
p.write([]byte("\\"))
|
||||
p.Print(nn.Child)
|
||||
|
||||
p.printFreeFloating(nn, token.End)
|
||||
}
|
||||
|
||||
func (p *Printer) printParserBrackets(n ast.Vertex) {
|
||||
nn := n.(*ast.ParserBrackets)
|
||||
p.printFreeFloating(nn, token.Start)
|
||||
|
||||
Reference in New Issue
Block a user