[refactoring] parameters: new node structure
This commit is contained in:
@@ -20,6 +20,8 @@ type Visitor interface {
|
||||
type NodeVisitor interface {
|
||||
Root(n *Root)
|
||||
Nullable(n *Nullable)
|
||||
Reference(n *Reference)
|
||||
Variadic(n *Variadic)
|
||||
Parameter(n *Parameter)
|
||||
Identifier(n *Identifier)
|
||||
ArgumentList(n *ArgumentList)
|
||||
|
||||
@@ -36,11 +36,29 @@ func (n *Nullable) Accept(v NodeVisitor) {
|
||||
v.Nullable(n)
|
||||
}
|
||||
|
||||
// Reference node
|
||||
type Reference struct {
|
||||
Node
|
||||
Var Vertex
|
||||
}
|
||||
|
||||
func (n *Reference) Accept(v NodeVisitor) {
|
||||
v.Reference(n)
|
||||
}
|
||||
|
||||
// Variadic node
|
||||
type Variadic struct {
|
||||
Node
|
||||
Var Vertex
|
||||
}
|
||||
|
||||
func (n *Variadic) Accept(v NodeVisitor) {
|
||||
v.Variadic(n)
|
||||
}
|
||||
|
||||
// Parameter node
|
||||
type Parameter struct {
|
||||
Node
|
||||
ByRef bool
|
||||
Variadic bool
|
||||
Type Vertex
|
||||
Var Vertex
|
||||
DefaultValue Vertex
|
||||
|
||||
@@ -40,6 +40,30 @@ func (t *DFS) Traverse(n ast.Vertex) {
|
||||
t.Traverse(nn.Expr)
|
||||
t.visitor.Leave("Expr", true)
|
||||
}
|
||||
case *ast.Reference:
|
||||
if nn == nil {
|
||||
return
|
||||
}
|
||||
if !t.visitor.EnterNode(nn) {
|
||||
return
|
||||
}
|
||||
if nn.Var != nil {
|
||||
t.visitor.Enter("Var", true)
|
||||
t.Traverse(nn.Var)
|
||||
t.visitor.Leave("Var", true)
|
||||
}
|
||||
case *ast.Variadic:
|
||||
if nn == nil {
|
||||
return
|
||||
}
|
||||
if !t.visitor.EnterNode(nn) {
|
||||
return
|
||||
}
|
||||
if nn.Var != nil {
|
||||
t.visitor.Enter("Var", true)
|
||||
t.Traverse(nn.Var)
|
||||
t.visitor.Leave("Var", true)
|
||||
}
|
||||
case *ast.Parameter:
|
||||
if nn == nil {
|
||||
return
|
||||
|
||||
@@ -33,10 +33,18 @@ func (v *Dump) print(str string) {
|
||||
}
|
||||
|
||||
func (v *Dump) printIndent(indentDepth int) {
|
||||
if indentDepth < 0 {
|
||||
indentDepth = 0
|
||||
}
|
||||
|
||||
v.print(strings.Repeat("\t", indentDepth))
|
||||
}
|
||||
|
||||
func (v *Dump) printIndentIfNotSingle(indentDepth int) {
|
||||
if indentDepth < 0 {
|
||||
indentDepth = 0
|
||||
}
|
||||
|
||||
if !v.stack[v.depth-1].singleNode {
|
||||
v.print(strings.Repeat("\t", indentDepth))
|
||||
}
|
||||
@@ -173,20 +181,22 @@ func (v *Dump) Nullable(n *ast.Nullable) {
|
||||
v.printNode(n.GetNode())
|
||||
}
|
||||
|
||||
func (v *Dump) Reference(n *ast.Reference) {
|
||||
v.printIndentIfNotSingle(v.indent - 1)
|
||||
v.print("&ast.Reference{\n")
|
||||
v.printNode(n.GetNode())
|
||||
}
|
||||
|
||||
func (v *Dump) Variadic(n *ast.Variadic) {
|
||||
v.printIndentIfNotSingle(v.indent - 1)
|
||||
v.print("&ast.Variadic{\n")
|
||||
v.printNode(n.GetNode())
|
||||
}
|
||||
|
||||
func (v *Dump) Parameter(n *ast.Parameter) {
|
||||
v.printIndent(v.indent - 1)
|
||||
v.print("&ast.Parameter{\n")
|
||||
v.printNode(n.GetNode())
|
||||
|
||||
if n.ByRef {
|
||||
v.printIndent(v.indent)
|
||||
v.print("ByRef: true,\n")
|
||||
}
|
||||
|
||||
if n.Variadic {
|
||||
v.printIndent(v.indent)
|
||||
v.print("Variadic: true,\n")
|
||||
}
|
||||
}
|
||||
|
||||
func (v *Dump) Identifier(n *ast.Identifier) {
|
||||
|
||||
@@ -30,8 +30,7 @@ func ExampleDump() {
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.Identifier{},
|
||||
&ast.Parameter{
|
||||
Variadic: true,
|
||||
Var: &ast.ExprVariable{},
|
||||
Var: &ast.ExprVariable{},
|
||||
},
|
||||
&ast.StmtInlineHtml{
|
||||
Value: []byte("foo"),
|
||||
@@ -64,7 +63,6 @@ func ExampleDump() {
|
||||
// Value: []byte(""),
|
||||
// },
|
||||
// &ast.Parameter{
|
||||
// Variadic: true,
|
||||
// Var: &ast.ExprVariable{
|
||||
// },
|
||||
// },
|
||||
|
||||
@@ -502,10 +502,8 @@ func TestResolveFunctionName(t *testing.T) {
|
||||
FunctionName: &ast.Identifier{Value: []byte("A")},
|
||||
Params: []ast.Vertex{
|
||||
&ast.Parameter{
|
||||
ByRef: false,
|
||||
Variadic: false,
|
||||
Type: nameAB,
|
||||
Var: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("foo")}},
|
||||
Type: nameAB,
|
||||
Var: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("foo")}},
|
||||
},
|
||||
},
|
||||
ReturnType: &ast.Nullable{Expr: nameBC},
|
||||
@@ -540,10 +538,8 @@ func TestResolveMethodName(t *testing.T) {
|
||||
MethodName: &ast.Identifier{Value: []byte("A")},
|
||||
Params: []ast.Vertex{
|
||||
&ast.Parameter{
|
||||
ByRef: false,
|
||||
Variadic: false,
|
||||
Type: nameAB,
|
||||
Var: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("foo")}},
|
||||
Type: nameAB,
|
||||
Var: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("foo")}},
|
||||
},
|
||||
},
|
||||
ReturnType: &ast.Nullable{Expr: nameBC},
|
||||
@@ -573,10 +569,8 @@ func TestResolveClosureName(t *testing.T) {
|
||||
Static: false,
|
||||
Params: []ast.Vertex{
|
||||
&ast.Parameter{
|
||||
ByRef: false,
|
||||
Variadic: false,
|
||||
Type: nameAB,
|
||||
Var: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("foo")}},
|
||||
Type: nameAB,
|
||||
Var: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("foo")}},
|
||||
},
|
||||
},
|
||||
ClosureUse: nil,
|
||||
|
||||
@@ -30,6 +30,14 @@ func (v *Null) Nullable(_ *ast.Nullable) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) Reference(_ *ast.Reference) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) Variadic(_ *ast.Variadic) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) Parameter(_ *ast.Parameter) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user