[refactoring] update ast structure of "ClassMethod", "Function", "ArrowFunction" and "Closure" nodes
This commit is contained in:
@@ -292,12 +292,16 @@ func (n *StmtClassImplements) Accept(v NodeVisitor) {
|
||||
// StmtClassMethod node
|
||||
type StmtClassMethod struct {
|
||||
Node
|
||||
ReturnsRef bool
|
||||
MethodName Vertex
|
||||
Modifiers []Vertex
|
||||
Params []Vertex
|
||||
ReturnType Vertex
|
||||
Stmt Vertex
|
||||
Modifiers []Vertex
|
||||
FunctionTkn *token.Token
|
||||
AmpersandTkn *token.Token
|
||||
MethodName Vertex
|
||||
OpenParenthesisTkn *token.Token
|
||||
Params []Vertex
|
||||
CloseParenthesisTkn *token.Token
|
||||
ColonTkn *token.Token
|
||||
ReturnType Vertex
|
||||
Stmt Vertex
|
||||
}
|
||||
|
||||
func (n *StmtClassMethod) Accept(v NodeVisitor) {
|
||||
@@ -501,11 +505,17 @@ func (n *StmtForeach) Accept(v NodeVisitor) {
|
||||
// StmtFunction node
|
||||
type StmtFunction struct {
|
||||
Node
|
||||
ReturnsRef bool
|
||||
FunctionName Vertex
|
||||
Params []Vertex
|
||||
ReturnType Vertex
|
||||
Stmts []Vertex
|
||||
FunctionTkn *token.Token
|
||||
AmpersandTkn *token.Token
|
||||
FunctionName Vertex
|
||||
OpenParenthesisTkn *token.Token
|
||||
Params []Vertex
|
||||
CloseParenthesisTkn *token.Token
|
||||
ColonTkn *token.Token
|
||||
ReturnType Vertex
|
||||
OpenCurlyBracketTkn *token.Token
|
||||
Stmts []Vertex
|
||||
CloseCurlyBracketTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *StmtFunction) Accept(v NodeVisitor) {
|
||||
@@ -951,11 +961,16 @@ func (n *ExprArrayItem) Accept(v NodeVisitor) {
|
||||
// ExprArrowFunction node
|
||||
type ExprArrowFunction struct {
|
||||
Node
|
||||
ReturnsRef bool
|
||||
Static bool
|
||||
Params []Vertex
|
||||
ReturnType Vertex
|
||||
Expr Vertex
|
||||
StaticTkn *token.Token
|
||||
FnTkn *token.Token
|
||||
AmpersandTkn *token.Token
|
||||
OpenParenthesisTkn *token.Token
|
||||
Params []Vertex
|
||||
CloseParenthesisTkn *token.Token
|
||||
ColonTkn *token.Token
|
||||
ReturnType Vertex
|
||||
DoubleArrowTkn *token.Token
|
||||
Expr Vertex
|
||||
}
|
||||
|
||||
func (n *ExprArrowFunction) Accept(v NodeVisitor) {
|
||||
@@ -1006,12 +1021,18 @@ func (n *ExprClone) Accept(v NodeVisitor) {
|
||||
// ExprClosure node
|
||||
type ExprClosure struct {
|
||||
Node
|
||||
ReturnsRef bool
|
||||
Static bool
|
||||
Params []Vertex
|
||||
ClosureUse *ExprClosureUse
|
||||
ReturnType Vertex
|
||||
Stmts []Vertex
|
||||
StaticTkn *token.Token
|
||||
FunctionTkn *token.Token
|
||||
AmpersandTkn *token.Token
|
||||
OpenParenthesisTkn *token.Token
|
||||
Params []Vertex
|
||||
CloseParenthesisTkn *token.Token
|
||||
ClosureUse *ExprClosureUse
|
||||
ColonTkn *token.Token
|
||||
ReturnType Vertex
|
||||
OpenCurlyBracketTkn *token.Token
|
||||
Stmts []Vertex
|
||||
CloseCurlyBracketTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *ExprClosure) Accept(v NodeVisitor) {
|
||||
@@ -1947,6 +1968,8 @@ func (n *NameNamePart) Accept(v NodeVisitor) {
|
||||
v.NameNamePart(n)
|
||||
}
|
||||
|
||||
// TODO: move to private section
|
||||
|
||||
type ParserBrackets struct {
|
||||
Node
|
||||
OpenBracketTkn *token.Token
|
||||
@@ -1967,3 +1990,13 @@ type ParserSeparatedList struct {
|
||||
func (n *ParserSeparatedList) Accept(v NodeVisitor) {
|
||||
v.ParserSeparatedList(n)
|
||||
}
|
||||
|
||||
type ReturnType struct {
|
||||
Node
|
||||
ColonTkn *token.Token
|
||||
Type Vertex
|
||||
}
|
||||
|
||||
func (n *ReturnType) Accept(v NodeVisitor) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@@ -288,11 +288,6 @@ func (v *Dump) StmtClassMethod(n *ast.StmtClassMethod) {
|
||||
v.printIndentIfNotSingle(v.indent - 1)
|
||||
v.print("&ast.StmtClassMethod{\n")
|
||||
v.printNode(n.GetNode())
|
||||
|
||||
if n.ReturnsRef {
|
||||
v.printIndent(v.indent)
|
||||
v.print("ReturnsRef: true,\n")
|
||||
}
|
||||
}
|
||||
|
||||
func (v *Dump) StmtConstList(n *ast.StmtConstList) {
|
||||
@@ -397,11 +392,6 @@ func (v *Dump) StmtFunction(n *ast.StmtFunction) {
|
||||
v.printIndentIfNotSingle(v.indent - 1)
|
||||
v.print("&ast.StmtFunction{\n")
|
||||
v.printNode(n.GetNode())
|
||||
|
||||
if n.ReturnsRef {
|
||||
v.printIndent(v.indent)
|
||||
v.print("ReturnsRef: true,\n")
|
||||
}
|
||||
}
|
||||
|
||||
func (v *Dump) StmtGlobal(n *ast.StmtGlobal) {
|
||||
@@ -641,16 +631,6 @@ func (v *Dump) ExprArrowFunction(n *ast.ExprArrowFunction) {
|
||||
v.printIndentIfNotSingle(v.indent - 1)
|
||||
v.print("&ast.ExprArrowFunction{\n")
|
||||
v.printNode(n.GetNode())
|
||||
|
||||
if n.ReturnsRef {
|
||||
v.printIndent(v.indent)
|
||||
v.print("ReturnsRef: true,\n")
|
||||
}
|
||||
|
||||
if n.Static {
|
||||
v.printIndent(v.indent)
|
||||
v.print("Static: true,\n")
|
||||
}
|
||||
}
|
||||
|
||||
func (v *Dump) ExprBitwiseNot(n *ast.ExprBitwiseNot) {
|
||||
@@ -681,16 +661,6 @@ func (v *Dump) ExprClosure(n *ast.ExprClosure) {
|
||||
v.printIndentIfNotSingle(v.indent - 1)
|
||||
v.print("&ast.ExprClosure{\n")
|
||||
v.printNode(n.GetNode())
|
||||
|
||||
if n.ReturnsRef {
|
||||
v.printIndent(v.indent)
|
||||
v.print("ReturnsRef: true,\n")
|
||||
}
|
||||
|
||||
if n.Static {
|
||||
v.printIndent(v.indent)
|
||||
v.print("Static: true,\n")
|
||||
}
|
||||
}
|
||||
|
||||
func (v *Dump) ExprClosureUse(n *ast.ExprClosureUse) {
|
||||
|
||||
@@ -1015,13 +1015,13 @@ func (p *PrettyPrinter) printExprClosureUse(n ast.Vertex) {
|
||||
func (p *PrettyPrinter) printExprClosure(n ast.Vertex) {
|
||||
nn := n.(*ast.ExprClosure)
|
||||
|
||||
if nn.Static {
|
||||
if nn.StaticTkn != nil {
|
||||
io.WriteString(p.w, "static ")
|
||||
}
|
||||
|
||||
io.WriteString(p.w, "function ")
|
||||
|
||||
if nn.ReturnsRef {
|
||||
if nn.AmpersandTkn != nil {
|
||||
io.WriteString(p.w, "&")
|
||||
}
|
||||
|
||||
@@ -1432,7 +1432,7 @@ func (p *PrettyPrinter) printStmtClassMethod(n ast.Vertex) {
|
||||
}
|
||||
io.WriteString(p.w, "function ")
|
||||
|
||||
if nn.ReturnsRef {
|
||||
if nn.AmpersandTkn != nil {
|
||||
io.WriteString(p.w, "&")
|
||||
}
|
||||
|
||||
@@ -1785,7 +1785,7 @@ func (p *PrettyPrinter) printStmtFunction(n ast.Vertex) {
|
||||
|
||||
io.WriteString(p.w, "function ")
|
||||
|
||||
if nn.ReturnsRef {
|
||||
if nn.AmpersandTkn != nil {
|
||||
io.WriteString(p.w, "&")
|
||||
}
|
||||
|
||||
|
||||
@@ -1405,18 +1405,18 @@ func (p *Printer) printExprArrowFunction(n ast.Vertex) {
|
||||
nn := n.(*ast.ExprArrowFunction)
|
||||
p.printFreeFloating(nn, token.Start)
|
||||
|
||||
if nn.Static {
|
||||
if nn.StaticTkn != nil {
|
||||
p.write([]byte("static"))
|
||||
}
|
||||
p.printFreeFloating(nn, token.Static)
|
||||
if nn.Static && n.GetNode().Tokens.IsEmpty() {
|
||||
if nn.StaticTkn != nil && n.GetNode().Tokens.IsEmpty() {
|
||||
p.write([]byte(" "))
|
||||
}
|
||||
|
||||
p.write([]byte("fn"))
|
||||
p.printFreeFloating(nn, token.Function)
|
||||
|
||||
if nn.ReturnsRef {
|
||||
if nn.AmpersandTkn != nil {
|
||||
p.write([]byte("&"))
|
||||
}
|
||||
p.printFreeFloating(nn, token.Ampersand)
|
||||
@@ -1496,18 +1496,18 @@ func (p *Printer) printExprClosure(n ast.Vertex) {
|
||||
nn := n.(*ast.ExprClosure)
|
||||
p.printFreeFloating(nn, token.Start)
|
||||
|
||||
if nn.Static {
|
||||
if nn.StaticTkn != nil {
|
||||
p.write([]byte("static"))
|
||||
}
|
||||
p.printFreeFloating(nn, token.Static)
|
||||
if nn.Static && n.GetNode().Tokens.IsEmpty() {
|
||||
if nn.StaticTkn != nil && n.GetNode().Tokens.IsEmpty() {
|
||||
p.write([]byte(" "))
|
||||
}
|
||||
|
||||
p.write([]byte("function"))
|
||||
p.printFreeFloating(nn, token.Function)
|
||||
|
||||
if nn.ReturnsRef {
|
||||
if nn.AmpersandTkn != nil {
|
||||
p.write([]byte("&"))
|
||||
}
|
||||
p.printFreeFloating(nn, token.Ampersand)
|
||||
@@ -2040,7 +2040,7 @@ func (p *Printer) printStmtClassMethod(n ast.Vertex) {
|
||||
p.write([]byte("function"))
|
||||
p.printFreeFloating(nn, token.Function)
|
||||
|
||||
if nn.ReturnsRef {
|
||||
if nn.AmpersandTkn != nil {
|
||||
if nn.GetNode().Tokens.IsEmpty() {
|
||||
p.write([]byte(" "))
|
||||
}
|
||||
@@ -2384,7 +2384,7 @@ func (p *Printer) printStmtFunction(n ast.Vertex) {
|
||||
p.write([]byte("function"))
|
||||
p.printFreeFloating(nn, token.Function)
|
||||
|
||||
if nn.ReturnsRef {
|
||||
if nn.AmpersandTkn != nil {
|
||||
if nn.GetNode().Tokens.IsEmpty() {
|
||||
p.write([]byte(" "))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user