#31 dump to native golang struct

This commit is contained in:
z7zmey 2018-06-18 23:29:52 +03:00
parent 063726aac4
commit dd572a8fed
173 changed files with 1279 additions and 735 deletions

View File

@ -99,7 +99,7 @@ func printer(result <-chan parser.Parser) {
nsResolver := visitor.NewNamespaceResolver() nsResolver := visitor.NewNamespaceResolver()
parserWorker.GetRootNode().Walk(nsResolver) parserWorker.GetRootNode().Walk(nsResolver)
dumper := visitor.Dumper{ dumper := &visitor.Dumper{
Writer: os.Stdout, Writer: os.Stdout,
Indent: " | ", Indent: " | ",
Comments: parserWorker.GetComments(), Comments: parserWorker.GetComments(),

View File

@ -32,13 +32,15 @@ func (n *Assign) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Reference) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *BitwiseAnd) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *BitwiseOr) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *BitwiseXor) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Concat) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Div) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Minus) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Mod) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Mul) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Plus) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Pow) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *ShiftLeft) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *ShiftRight) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -20,112 +20,112 @@ var nodesToTest = []struct {
}{ }{
{ {
&assign.Reference{ &assign.Reference{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&assign.Assign{ &assign.Assign{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&assign.BitwiseAnd{ &assign.BitwiseAnd{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&assign.BitwiseOr{ &assign.BitwiseOr{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&assign.BitwiseXor{ &assign.BitwiseXor{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&assign.Concat{ &assign.Concat{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&assign.Div{ &assign.Div{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&assign.Minus{ &assign.Minus{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&assign.Mod{ &assign.Mod{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&assign.Mul{ &assign.Mul{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&assign.Plus{ &assign.Plus{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&assign.Pow{ &assign.Pow{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&assign.ShiftLeft{ &assign.ShiftLeft{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&assign.ShiftRight{ &assign.ShiftRight{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, map[string]interface{}{},
@ -138,11 +138,15 @@ type visitorMock struct {
} }
func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren } func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren }
func (v *visitorMock) GetChildrenVisitor(key string) walker.Visitor { func (v *visitorMock) LeaveNode(n walker.Walkable) {}
func (v *visitorMock) EnterChildNode(key string, w walker.Walkable) {
v.visitedKeys = append(v.visitedKeys, key) v.visitedKeys = append(v.visitedKeys, key)
return &visitorMock{v.visitChildren, nil}
} }
func (v *visitorMock) LeaveNode(n walker.Walkable) {} func (v *visitorMock) LeaveChildNode(key string, w walker.Walkable) {}
func (v *visitorMock) EnterChildList(key string, w walker.Walkable) {
v.visitedKeys = append(v.visitedKeys, key)
}
func (v *visitorMock) LeaveChildList(key string, w walker.Walkable) {}
func TestVisitorDisableChildren(t *testing.T) { func TestVisitorDisableChildren(t *testing.T) {
for _, tt := range nodesToTest { for _, tt := range nodesToTest {

View File

@ -32,13 +32,15 @@ func (n *BitwiseAnd) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *BitwiseOr) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *BitwiseXor) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *BooleanAnd) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *BooleanOr) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Coalesce) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Concat) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Div) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Equal) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Greater) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *GreaterOrEqual) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Identical) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *LogicalAnd) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *LogicalOr) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *LogicalXor) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Minus) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Mod) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Mul) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *NotEqual) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *NotIdentical) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Plus) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Pow) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *ShiftLeft) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *ShiftRight) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Smaller) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *SmallerOrEqual) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Spaceship) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -19,216 +19,216 @@ var nodesToTest = []struct {
}{ }{
{ {
&binary.BitwiseAnd{ &binary.BitwiseAnd{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.BitwiseOr{ &binary.BitwiseOr{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.BitwiseXor{ &binary.BitwiseXor{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.BooleanAnd{ &binary.BooleanAnd{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.BooleanOr{ &binary.BooleanOr{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.Coalesce{ &binary.Coalesce{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.Concat{ &binary.Concat{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.Div{ &binary.Div{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.Equal{ &binary.Equal{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.GreaterOrEqual{ &binary.GreaterOrEqual{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.Greater{ &binary.Greater{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.Identical{ &binary.Identical{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.LogicalAnd{ &binary.LogicalAnd{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.LogicalOr{ &binary.LogicalOr{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.LogicalXor{ &binary.LogicalXor{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.Minus{ &binary.Minus{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.Mod{ &binary.Mod{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.Mul{ &binary.Mul{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.NotEqual{ &binary.NotEqual{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.NotIdentical{ &binary.NotIdentical{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.Plus{ &binary.Plus{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.Pow{ &binary.Pow{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.ShiftLeft{ &binary.ShiftLeft{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.ShiftRight{ &binary.ShiftRight{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.SmallerOrEqual{ &binary.SmallerOrEqual{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.Smaller{ &binary.Smaller{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&binary.Spaceship{ &binary.Spaceship{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, map[string]interface{}{},
@ -241,11 +241,15 @@ type visitorMock struct {
} }
func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren } func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren }
func (v *visitorMock) GetChildrenVisitor(key string) walker.Visitor { func (v *visitorMock) LeaveNode(n walker.Walkable) {}
func (v *visitorMock) EnterChildNode(key string, w walker.Walkable) {
v.visitedKeys = append(v.visitedKeys, key) v.visitedKeys = append(v.visitedKeys, key)
return &visitorMock{v.visitChildren, nil}
} }
func (v *visitorMock) LeaveNode(n walker.Walkable) {} func (v *visitorMock) LeaveChildNode(key string, w walker.Walkable) {}
func (v *visitorMock) EnterChildList(key string, w walker.Walkable) {
v.visitedKeys = append(v.visitedKeys, key)
}
func (v *visitorMock) LeaveChildList(key string, w walker.Walkable) {}
func TestVisitorDisableChildren(t *testing.T) { func TestVisitorDisableChildren(t *testing.T) {
for _, tt := range nodesToTest { for _, tt := range nodesToTest {

View File

@ -30,8 +30,9 @@ func (n *Array) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *Bool) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *Double) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *Int) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *Object) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *String) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *Unset) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -19,49 +19,49 @@ var nodesToTest = []struct {
}{ }{
{ {
&cast.Array{ &cast.Array{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&cast.Bool{ &cast.Bool{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&cast.Double{ &cast.Double{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&cast.Int{ &cast.Int{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&cast.Object{ &cast.Object{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&cast.String{ &cast.String{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&cast.Unset{ &cast.Unset{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
@ -74,11 +74,15 @@ type visitorMock struct {
} }
func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren } func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren }
func (v *visitorMock) GetChildrenVisitor(key string) walker.Visitor { func (v *visitorMock) LeaveNode(n walker.Walkable) {}
func (v *visitorMock) EnterChildNode(key string, w walker.Walkable) {
v.visitedKeys = append(v.visitedKeys, key) v.visitedKeys = append(v.visitedKeys, key)
return &visitorMock{v.visitChildren, nil}
} }
func (v *visitorMock) LeaveNode(n walker.Walkable) {} func (v *visitorMock) LeaveChildNode(key string, w walker.Walkable) {}
func (v *visitorMock) EnterChildList(key string, w walker.Walkable) {
v.visitedKeys = append(v.visitedKeys, key)
}
func (v *visitorMock) LeaveChildList(key string, w walker.Walkable) {}
func TestVisitorDisableChildren(t *testing.T) { func TestVisitorDisableChildren(t *testing.T) {
for _, tt := range nodesToTest { for _, tt := range nodesToTest {

View File

@ -30,12 +30,13 @@ func (n *Array) Walk(v walker.Visitor) {
} }
if n.Items != nil { if n.Items != nil {
vv := v.GetChildrenVisitor("Items") v.EnterChildList("Items", n)
for _, nn := range n.Items { for _, nn := range n.Items {
if nn != nil { if nn != nil {
nn.Walk(vv) nn.Walk(v)
} }
} }
v.LeaveChildList("Items", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *ArrayDimFetch) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Dim != nil { if n.Dim != nil {
vv := v.GetChildrenVisitor("Dim") v.EnterChildNode("Dim", n)
n.Dim.Walk(vv) n.Dim.Walk(v)
v.LeaveChildNode("Dim", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *ArrayItem) Walk(v walker.Visitor) {
} }
if n.Key != nil { if n.Key != nil {
vv := v.GetChildrenVisitor("Key") v.EnterChildNode("Key", n)
n.Key.Walk(vv) n.Key.Walk(v)
v.LeaveChildNode("Key", n)
} }
if n.Val != nil { if n.Val != nil {
vv := v.GetChildrenVisitor("Val") v.EnterChildNode("Val", n)
n.Val.Walk(vv) n.Val.Walk(v)
v.LeaveChildNode("Val", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *BitwiseNot) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *BooleanNot) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *ClassConstFetch) Walk(v walker.Visitor) {
} }
if n.Class != nil { if n.Class != nil {
vv := v.GetChildrenVisitor("Class") v.EnterChildNode("Class", n)
n.Class.Walk(vv) n.Class.Walk(v)
v.LeaveChildNode("Class", n)
} }
if n.ConstantName != nil { if n.ConstantName != nil {
vv := v.GetChildrenVisitor("ConstantName") v.EnterChildNode("ConstantName", n)
n.ConstantName.Walk(vv) n.ConstantName.Walk(v)
v.LeaveChildNode("ConstantName", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *Clone) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -46,31 +46,35 @@ func (n *Closure) Walk(v walker.Visitor) {
} }
if n.Params != nil { if n.Params != nil {
vv := v.GetChildrenVisitor("Params") v.EnterChildList("Params", n)
for _, nn := range n.Params { for _, nn := range n.Params {
if nn != nil { if nn != nil {
nn.Walk(vv) nn.Walk(v)
} }
} }
v.LeaveChildList("Params", n)
} }
if n.ClosureUse != nil { if n.ClosureUse != nil {
vv := v.GetChildrenVisitor("ClosureUse") v.EnterChildNode("ClosureUse", n)
n.ClosureUse.Walk(vv) n.ClosureUse.Walk(v)
v.LeaveChildNode("ClosureUse", n)
} }
if n.ReturnType != nil { if n.ReturnType != nil {
vv := v.GetChildrenVisitor("ReturnType") v.EnterChildNode("ReturnType", n)
n.ReturnType.Walk(vv) n.ReturnType.Walk(v)
v.LeaveChildNode("ReturnType", n)
} }
if n.Stmts != nil { if n.Stmts != nil {
vv := v.GetChildrenVisitor("Stmts") v.EnterChildList("Stmts", n)
for _, nn := range n.Stmts { for _, nn := range n.Stmts {
if nn != nil { if nn != nil {
nn.Walk(vv) nn.Walk(v)
} }
} }
v.LeaveChildList("Stmts", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,12 +30,13 @@ func (n *ClosureUse) Walk(v walker.Visitor) {
} }
if n.Uses != nil { if n.Uses != nil {
vv := v.GetChildrenVisitor("Uses") v.EnterChildList("Uses", n)
for _, nn := range n.Uses { for _, nn := range n.Uses {
if nn != nil { if nn != nil {
nn.Walk(vv) nn.Walk(v)
} }
} }
v.LeaveChildList("Uses", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *ConstFetch) Walk(v walker.Visitor) {
} }
if n.Constant != nil { if n.Constant != nil {
vv := v.GetChildrenVisitor("Constant") v.EnterChildNode("Constant", n)
n.Constant.Walk(vv) n.Constant.Walk(v)
v.LeaveChildNode("Constant", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *Die) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *Empty) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *ErrorSuppress) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *Eval) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *Exit) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *FunctionCall) Walk(v walker.Visitor) {
} }
if n.Function != nil { if n.Function != nil {
vv := v.GetChildrenVisitor("Function") v.EnterChildNode("Function", n)
n.Function.Walk(vv) n.Function.Walk(v)
v.LeaveChildNode("Function", n)
} }
if n.ArgumentList != nil { if n.ArgumentList != nil {
vv := v.GetChildrenVisitor("ArgumentList") v.EnterChildNode("ArgumentList", n)
n.ArgumentList.Walk(vv) n.ArgumentList.Walk(v)
v.LeaveChildNode("ArgumentList", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *Include) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *IncludeOnce) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *InstanceOf) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
if n.Class != nil { if n.Class != nil {
vv := v.GetChildrenVisitor("Class") v.EnterChildNode("Class", n)
n.Class.Walk(vv) n.Class.Walk(v)
v.LeaveChildNode("Class", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,12 +30,13 @@ func (n *Isset) Walk(v walker.Visitor) {
} }
if n.Variables != nil { if n.Variables != nil {
vv := v.GetChildrenVisitor("Variables") v.EnterChildList("Variables", n)
for _, nn := range n.Variables { for _, nn := range n.Variables {
if nn != nil { if nn != nil {
nn.Walk(vv) nn.Walk(v)
} }
} }
v.LeaveChildList("Variables", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,12 +30,13 @@ func (n *List) Walk(v walker.Visitor) {
} }
if n.Items != nil { if n.Items != nil {
vv := v.GetChildrenVisitor("Items") v.EnterChildList("Items", n)
for _, nn := range n.Items { for _, nn := range n.Items {
if nn != nil { if nn != nil {
nn.Walk(vv) nn.Walk(v)
} }
} }
v.LeaveChildList("Items", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -34,18 +34,21 @@ func (n *MethodCall) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Method != nil { if n.Method != nil {
vv := v.GetChildrenVisitor("Method") v.EnterChildNode("Method", n)
n.Method.Walk(vv) n.Method.Walk(v)
v.LeaveChildNode("Method", n)
} }
if n.ArgumentList != nil { if n.ArgumentList != nil {
vv := v.GetChildrenVisitor("ArgumentList") v.EnterChildNode("ArgumentList", n)
n.ArgumentList.Walk(vv) n.ArgumentList.Walk(v)
v.LeaveChildNode("ArgumentList", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *New) Walk(v walker.Visitor) {
} }
if n.Class != nil { if n.Class != nil {
vv := v.GetChildrenVisitor("Class") v.EnterChildNode("Class", n)
n.Class.Walk(vv) n.Class.Walk(v)
v.LeaveChildNode("Class", n)
} }
if n.ArgumentList != nil { if n.ArgumentList != nil {
vv := v.GetChildrenVisitor("ArgumentList") v.EnterChildNode("ArgumentList", n)
n.ArgumentList.Walk(vv) n.ArgumentList.Walk(v)
v.LeaveChildNode("ArgumentList", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *PostDec) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *PostInc) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *PreDec) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *PreInc) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *Print) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *PropertyFetch) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Property != nil { if n.Property != nil {
vv := v.GetChildrenVisitor("Property") v.EnterChildNode("Property", n)
n.Property.Walk(vv) n.Property.Walk(v)
v.LeaveChildNode("Property", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *Reference) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *Require) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *RequireOnce) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,12 +30,13 @@ func (n *ShellExec) Walk(v walker.Visitor) {
} }
if n.Parts != nil { if n.Parts != nil {
vv := v.GetChildrenVisitor("Parts") v.EnterChildList("Parts", n)
for _, nn := range n.Parts { for _, nn := range n.Parts {
if nn != nil { if nn != nil {
nn.Walk(vv) nn.Walk(v)
} }
} }
v.LeaveChildList("Parts", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,12 +30,13 @@ func (n *ShortArray) Walk(v walker.Visitor) {
} }
if n.Items != nil { if n.Items != nil {
vv := v.GetChildrenVisitor("Items") v.EnterChildList("Items", n)
for _, nn := range n.Items { for _, nn := range n.Items {
if nn != nil { if nn != nil {
nn.Walk(vv) nn.Walk(v)
} }
} }
v.LeaveChildList("Items", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,12 +30,13 @@ func (n *ShortList) Walk(v walker.Visitor) {
} }
if n.Items != nil { if n.Items != nil {
vv := v.GetChildrenVisitor("Items") v.EnterChildList("Items", n)
for _, nn := range n.Items { for _, nn := range n.Items {
if nn != nil { if nn != nil {
nn.Walk(vv) nn.Walk(v)
} }
} }
v.LeaveChildList("Items", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -34,18 +34,21 @@ func (n *StaticCall) Walk(v walker.Visitor) {
} }
if n.Class != nil { if n.Class != nil {
vv := v.GetChildrenVisitor("Class") v.EnterChildNode("Class", n)
n.Class.Walk(vv) n.Class.Walk(v)
v.LeaveChildNode("Class", n)
} }
if n.Call != nil { if n.Call != nil {
vv := v.GetChildrenVisitor("Call") v.EnterChildNode("Call", n)
n.Call.Walk(vv) n.Call.Walk(v)
v.LeaveChildNode("Call", n)
} }
if n.ArgumentList != nil { if n.ArgumentList != nil {
vv := v.GetChildrenVisitor("ArgumentList") v.EnterChildNode("ArgumentList", n)
n.ArgumentList.Walk(vv) n.ArgumentList.Walk(v)
v.LeaveChildNode("ArgumentList", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *StaticPropertyFetch) Walk(v walker.Visitor) {
} }
if n.Class != nil { if n.Class != nil {
vv := v.GetChildrenVisitor("Class") v.EnterChildNode("Class", n)
n.Class.Walk(vv) n.Class.Walk(v)
v.LeaveChildNode("Class", n)
} }
if n.Property != nil { if n.Property != nil {
vv := v.GetChildrenVisitor("Property") v.EnterChildNode("Property", n)
n.Property.Walk(vv) n.Property.Walk(v)
v.LeaveChildNode("Property", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -34,18 +34,21 @@ func (n *Ternary) Walk(v walker.Visitor) {
} }
if n.Condition != nil { if n.Condition != nil {
vv := v.GetChildrenVisitor("Condition") v.EnterChildNode("Condition", n)
n.Condition.Walk(vv) n.Condition.Walk(v)
v.LeaveChildNode("Condition", n)
} }
if n.IfTrue != nil { if n.IfTrue != nil {
vv := v.GetChildrenVisitor("IfTrue") v.EnterChildNode("IfTrue", n)
n.IfTrue.Walk(vv) n.IfTrue.Walk(v)
v.LeaveChildNode("IfTrue", n)
} }
if n.IfFalse != nil { if n.IfFalse != nil {
vv := v.GetChildrenVisitor("IfFalse") v.EnterChildNode("IfFalse", n)
n.IfFalse.Walk(vv) n.IfFalse.Walk(v)
v.LeaveChildNode("IfFalse", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *UnaryMinus) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *UnaryPlus) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -35,8 +35,9 @@ func (n *Variable) Walk(v walker.Visitor) {
} }
if n.VarName != nil { if n.VarName != nil {
vv := v.GetChildrenVisitor("VarName") v.EnterChildNode("VarName", n)
n.VarName.Walk(vv) n.VarName.Walk(v)
v.LeaveChildNode("VarName", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -32,13 +32,15 @@ func (n *Yield) Walk(v walker.Visitor) {
} }
if n.Key != nil { if n.Key != nil {
vv := v.GetChildrenVisitor("Key") v.EnterChildNode("Key", n)
n.Key.Walk(vv) n.Key.Walk(v)
v.LeaveChildNode("Key", n)
} }
if n.Value != nil { if n.Value != nil {
vv := v.GetChildrenVisitor("Value") v.EnterChildNode("Value", n)
n.Value.Walk(vv) n.Value.Walk(v)
v.LeaveChildNode("Value", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -30,8 +30,9 @@ func (n *YieldFrom) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -24,7 +24,7 @@ var nodesToTest = []struct {
}{ }{
{ {
&expr.ArrayDimFetch{ &expr.ArrayDimFetch{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Dim: &scalar.Lnumber{Value: "1"}, Dim: &scalar.Lnumber{Value: "1"},
}, },
[]string{"Variable", "Dim"}, []string{"Variable", "Dim"},
@ -41,10 +41,7 @@ var nodesToTest = []struct {
{ {
&expr.Array{ &expr.Array{
Items: []node.Node{ Items: []node.Node{
&expr.ArrayItem{ &expr.ArrayItem{},
Key: &scalar.String{Value: "key"},
Val: &scalar.Lnumber{Value: "1"},
},
}, },
}, },
[]string{"Items"}, []string{"Items"},
@ -52,21 +49,21 @@ var nodesToTest = []struct {
}, },
{ {
&expr.BitwiseNot{ &expr.BitwiseNot{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&expr.BooleanNot{ &expr.BooleanNot{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&expr.ClassConstFetch{ &expr.ClassConstFetch{
Class: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Class: &expr.Variable{},
ConstantName: &node.Identifier{Value: "foo"}, ConstantName: &node.Identifier{Value: "foo"},
}, },
[]string{"Class", "ConstantName"}, []string{"Class", "ConstantName"},
@ -74,7 +71,7 @@ var nodesToTest = []struct {
}, },
{ {
&expr.Clone{ &expr.Clone{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
@ -82,7 +79,7 @@ var nodesToTest = []struct {
{ {
&expr.ClosureUse{ &expr.ClosureUse{
Uses: []node.Node{ Uses: []node.Node{
&expr.Variable{VarName: &node.Identifier{Value: "a"}}, &expr.Variable{},
}, },
}, },
[]string{"Uses"}, []string{"Uses"},
@ -110,42 +107,42 @@ var nodesToTest = []struct {
}, },
{ {
&expr.Empty{ &expr.Empty{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&expr.ErrorSuppress{ &expr.ErrorSuppress{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&expr.Eval{ &expr.Eval{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&expr.Exit{ &expr.Exit{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&expr.Die{ &expr.Die{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&expr.FunctionCall{ &expr.FunctionCall{
Function: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Function: &expr.Variable{},
ArgumentList: &node.ArgumentList{}, ArgumentList: &node.ArgumentList{},
}, },
[]string{"Function", "ArgumentList"}, []string{"Function", "ArgumentList"},
@ -153,21 +150,21 @@ var nodesToTest = []struct {
}, },
{ {
&expr.IncludeOnce{ &expr.IncludeOnce{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&expr.Include{ &expr.Include{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&expr.InstanceOf{ &expr.InstanceOf{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
Class: &name.Name{}, Class: &name.Name{},
}, },
[]string{"Expr", "Class"}, []string{"Expr", "Class"},
@ -176,7 +173,7 @@ var nodesToTest = []struct {
{ {
&expr.Isset{ &expr.Isset{
Variables: []node.Node{ Variables: []node.Node{
&expr.Variable{VarName: &node.Identifier{Value: "a"}}, &expr.Variable{},
}, },
}, },
[]string{"Variables"}, []string{"Variables"},
@ -193,7 +190,7 @@ var nodesToTest = []struct {
}, },
{ {
&expr.MethodCall{ &expr.MethodCall{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Method: &node.Identifier{Value: "foo"}, Method: &node.Identifier{Value: "foo"},
ArgumentList: &node.ArgumentList{}, ArgumentList: &node.ArgumentList{},
}, },
@ -210,42 +207,42 @@ var nodesToTest = []struct {
}, },
{ {
&expr.PostDec{ &expr.PostDec{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
}, },
[]string{"Variable"}, []string{"Variable"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&expr.PostInc{ &expr.PostInc{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
}, },
[]string{"Variable"}, []string{"Variable"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&expr.PreDec{ &expr.PreDec{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
}, },
[]string{"Variable"}, []string{"Variable"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&expr.PreInc{ &expr.PreInc{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
}, },
[]string{"Variable"}, []string{"Variable"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&expr.Print{ &expr.Print{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&expr.PropertyFetch{ &expr.PropertyFetch{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Property: &node.Identifier{Value: "foo"}, Property: &node.Identifier{Value: "foo"},
}, },
[]string{"Variable", "Property"}, []string{"Variable", "Property"},
@ -253,21 +250,21 @@ var nodesToTest = []struct {
}, },
{ {
&expr.Reference{ &expr.Reference{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
}, },
[]string{"Variable"}, []string{"Variable"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&expr.RequireOnce{ &expr.RequireOnce{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&expr.Require{ &expr.Require{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
@ -318,23 +315,23 @@ var nodesToTest = []struct {
}, },
{ {
&expr.Ternary{ &expr.Ternary{
Condition: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Condition: &expr.Variable{},
IfTrue: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, IfTrue: &expr.Variable{},
IfFalse: &expr.Variable{VarName: &node.Identifier{Value: "c"}}, IfFalse: &expr.Variable{},
}, },
[]string{"Condition", "IfTrue", "IfFalse"}, []string{"Condition", "IfTrue", "IfFalse"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&expr.UnaryMinus{ &expr.UnaryMinus{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&expr.UnaryPlus{ &expr.UnaryPlus{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
@ -346,15 +343,15 @@ var nodesToTest = []struct {
}, },
{ {
&expr.YieldFrom{ &expr.YieldFrom{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, map[string]interface{}{},
}, },
{ {
&expr.Yield{ &expr.Yield{
Key: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Key: &expr.Variable{},
Value: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Value: &expr.Variable{},
}, },
[]string{"Key", "Value"}, []string{"Key", "Value"},
map[string]interface{}{}, map[string]interface{}{},
@ -367,11 +364,15 @@ type visitorMock struct {
} }
func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren } func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren }
func (v *visitorMock) GetChildrenVisitor(key string) walker.Visitor { func (v *visitorMock) LeaveNode(n walker.Walkable) {}
func (v *visitorMock) EnterChildNode(key string, w walker.Walkable) {
v.visitedKeys = append(v.visitedKeys, key) v.visitedKeys = append(v.visitedKeys, key)
return &visitorMock{v.visitChildren, nil}
} }
func (v *visitorMock) LeaveNode(n walker.Walkable) {} func (v *visitorMock) LeaveChildNode(key string, w walker.Walkable) {}
func (v *visitorMock) EnterChildList(key string, w walker.Walkable) {
v.visitedKeys = append(v.visitedKeys, key)
}
func (v *visitorMock) LeaveChildList(key string, w walker.Walkable) {}
func TestVisitorDisableChildren(t *testing.T) { func TestVisitorDisableChildren(t *testing.T) {
for _, tt := range nodesToTest { for _, tt := range nodesToTest {

View File

@ -34,8 +34,9 @@ func (n *Argument) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -29,12 +29,13 @@ func (n *ArgumentList) Walk(v walker.Visitor) {
} }
if n.Arguments != nil { if n.Arguments != nil {
vv := v.GetChildrenVisitor("Arguments") v.EnterChildList("Arguments", n)
for _, nn := range n.Arguments { for _, nn := range n.Arguments {
if nn != nil { if nn != nil {
nn.Walk(vv) nn.Walk(v)
} }
} }
v.LeaveChildList("Arguments", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -27,8 +27,9 @@ func (n *Nullable) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -38,18 +38,21 @@ func (n *Parameter) Walk(v walker.Visitor) {
} }
if n.VariableType != nil { if n.VariableType != nil {
vv := v.GetChildrenVisitor("VariableType") v.EnterChildNode("VariableType", n)
n.VariableType.Walk(vv) n.VariableType.Walk(v)
v.LeaveChildNode("VariableType", n)
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.DefaultValue != nil { if n.DefaultValue != nil {
vv := v.GetChildrenVisitor("DefaultValue") v.EnterChildNode("DefaultValue", n)
n.DefaultValue.Walk(vv) n.DefaultValue.Walk(v)
v.LeaveChildNode("DefaultValue", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

Some files were not shown because too many files have changed in this diff Show More