From dd572a8fed96bd9dc4ee7836fd2f93cfd36a52f3 Mon Sep 17 00:00:00 2001 From: z7zmey Date: Mon, 18 Jun 2018 23:29:52 +0300 Subject: [PATCH] #31 dump to native golang struct --- main.go | 2 +- node/expr/assign/n_assign.go | 10 ++- node/expr/assign/n_assign_ref.go | 10 ++- node/expr/assign/n_bitwise_and.go | 10 ++- node/expr/assign/n_bitwise_or.go | 10 ++- node/expr/assign/n_bitwise_xor.go | 10 ++- node/expr/assign/n_concat.go | 10 ++- node/expr/assign/n_div.go | 10 ++- node/expr/assign/n_minus.go | 10 ++- node/expr/assign/n_mod.go | 10 ++- node/expr/assign/n_mul.go | 10 ++- node/expr/assign/n_plus.go | 10 ++- node/expr/assign/n_pow.go | 10 ++- node/expr/assign/n_shift_left.go | 10 ++- node/expr/assign/n_shift_right.go | 10 ++- node/expr/assign/t_visitor_test.go | 66 +++++++------- node/expr/binary/n_bitwise_and.go | 10 ++- node/expr/binary/n_bitwise_or.go | 10 ++- node/expr/binary/n_bitwise_xor.go | 10 ++- node/expr/binary/n_boolean_and.go | 10 ++- node/expr/binary/n_boolean_or.go | 10 ++- node/expr/binary/n_coalesce.go | 10 ++- node/expr/binary/n_concat.go | 10 ++- node/expr/binary/n_div.go | 10 ++- node/expr/binary/n_equal.go | 10 ++- node/expr/binary/n_greater.go | 10 ++- node/expr/binary/n_greater_or_equal.go | 10 ++- node/expr/binary/n_identical.go | 10 ++- node/expr/binary/n_logical_and.go | 10 ++- node/expr/binary/n_logical_or.go | 10 ++- node/expr/binary/n_logical_xor.go | 10 ++- node/expr/binary/n_minus.go | 10 ++- node/expr/binary/n_mod.go | 10 ++- node/expr/binary/n_mul.go | 10 ++- node/expr/binary/n_not_equal.go | 10 ++- node/expr/binary/n_not_identical.go | 10 ++- node/expr/binary/n_plus.go | 10 ++- node/expr/binary/n_pow.go | 10 ++- node/expr/binary/n_shift_left.go | 10 ++- node/expr/binary/n_shift_right.go | 10 ++- node/expr/binary/n_smaller.go | 10 ++- node/expr/binary/n_smaller_or_equal.go | 10 ++- node/expr/binary/n_spaceship.go | 10 ++- node/expr/binary/t_visitor_test.go | 118 +++++++++++++------------ node/expr/cast/n_cast_array.go | 5 +- node/expr/cast/n_cast_bool.go | 5 +- node/expr/cast/n_cast_double.go | 5 +- node/expr/cast/n_cast_int.go | 5 +- node/expr/cast/n_cast_object.go | 5 +- node/expr/cast/n_cast_string.go | 5 +- node/expr/cast/n_cast_unset.go | 5 +- node/expr/cast/t_visitor_test.go | 24 ++--- node/expr/n_array.go | 5 +- node/expr/n_array_dim_fetch.go | 10 ++- node/expr/n_array_item.go | 10 ++- node/expr/n_bitwise_not.go | 5 +- node/expr/n_boolean_not.go | 5 +- node/expr/n_class_const_fetch.go | 10 ++- node/expr/n_clone.go | 5 +- node/expr/n_closure.go | 20 +++-- node/expr/n_closure_use.go | 5 +- node/expr/n_const_fetch.go | 5 +- node/expr/n_die.go | 5 +- node/expr/n_empty.go | 5 +- node/expr/n_error_suppress.go | 5 +- node/expr/n_eval.go | 5 +- node/expr/n_exit.go | 5 +- node/expr/n_function_call.go | 10 ++- node/expr/n_include.go | 5 +- node/expr/n_include_once.go | 5 +- node/expr/n_instance_of.go | 10 ++- node/expr/n_isset.go | 5 +- node/expr/n_list.go | 5 +- node/expr/n_method_call.go | 15 ++-- node/expr/n_new.go | 10 ++- node/expr/n_post_dec.go | 5 +- node/expr/n_post_inc.go | 5 +- node/expr/n_pre_dec.go | 5 +- node/expr/n_pre_inc.go | 5 +- node/expr/n_print.go | 5 +- node/expr/n_property_fetch.go | 10 ++- node/expr/n_reference.go | 5 +- node/expr/n_require.go | 5 +- node/expr/n_require_once.go | 5 +- node/expr/n_shell_exec.go | 5 +- node/expr/n_short_array.go | 5 +- node/expr/n_short_list.go | 5 +- node/expr/n_static_call.go | 15 ++-- node/expr/n_static_property_fetch.go | 10 ++- node/expr/n_ternary.go | 15 ++-- node/expr/n_unary_minus.go | 5 +- node/expr/n_unary_plus.go | 5 +- node/expr/n_variable.go | 5 +- node/expr/n_yield.go | 10 ++- node/expr/n_yield_from.go | 5 +- node/expr/t_visitor_test.go | 83 ++++++++--------- node/n_argument.go | 5 +- node/n_argument_list.go | 5 +- node/n_nullable.go | 5 +- node/n_parameter.go | 15 ++-- node/n_root.go | 5 +- node/name/n_fully_qualified.go | 5 +- node/name/n_name.go | 5 +- node/name/n_relative.go | 5 +- node/name/t_visitor_test.go | 10 ++- node/scalar/node_encapsed.go | 5 +- node/scalar/node_heredoc.go | 5 +- node/scalar/t_visitor_test.go | 10 ++- node/stmt/n_alt_else.go | 5 +- node/stmt/n_alt_else_if.go | 10 ++- node/stmt/n_alt_for.go | 20 +++-- node/stmt/n_alt_foreach.go | 20 +++-- node/stmt/n_alt_if.go | 20 +++-- node/stmt/n_alt_switch.go | 10 ++- node/stmt/n_alt_while.go | 10 ++- node/stmt/n_break.go | 5 +- node/stmt/n_case.go | 10 ++- node/stmt/n_case_list.go | 5 +- node/stmt/n_catch.go | 15 ++-- node/stmt/n_class.go | 30 ++++--- node/stmt/n_class_const_list.go | 10 ++- node/stmt/n_class_extends.go | 5 +- node/stmt/n_class_implements.go | 5 +- node/stmt/n_class_method.go | 25 +++--- node/stmt/n_const_list.go | 5 +- node/stmt/n_constant.go | 10 ++- node/stmt/n_continue.go | 5 +- node/stmt/n_declare.go | 10 ++- node/stmt/n_default.go | 5 +- node/stmt/n_do.go | 10 ++- node/stmt/n_echo.go | 5 +- node/stmt/n_else.go | 5 +- node/stmt/n_else_if.go | 10 ++- node/stmt/n_expression.go | 5 +- node/stmt/n_finally.go | 5 +- node/stmt/n_for.go | 20 +++-- node/stmt/n_foreach.go | 20 +++-- node/stmt/n_function.go | 20 +++-- node/stmt/n_global.go | 5 +- node/stmt/n_goto.go | 5 +- node/stmt/n_group_use.go | 15 ++-- node/stmt/n_if.go | 20 +++-- node/stmt/n_interface.go | 15 ++-- node/stmt/n_interface_extends.go | 5 +- node/stmt/n_label.go | 5 +- node/stmt/n_namespace.go | 10 ++- node/stmt/n_property.go | 10 ++- node/stmt/n_property_list.go | 10 ++- node/stmt/n_return.go | 5 +- node/stmt/n_static.go | 5 +- node/stmt/n_static_var.go | 10 ++- node/stmt/n_stmt_list.go | 5 +- node/stmt/n_switch.go | 10 ++- node/stmt/n_throw.go | 5 +- node/stmt/n_trait.go | 10 ++- node/stmt/n_trait_adaptation_list.go | 5 +- node/stmt/n_trait_method_ref.go | 10 ++- node/stmt/n_trait_use.go | 10 ++- node/stmt/n_trait_use_alias.go | 15 ++-- node/stmt/n_trait_use_precedence.go | 10 ++- node/stmt/n_try.go | 15 ++-- node/stmt/n_unset.go | 5 +- node/stmt/n_use.go | 15 ++-- node/stmt/n_use_list.go | 10 ++- node/stmt/n_while.go | 10 ++- node/stmt/t_visitor_test.go | 12 ++- node/t_visitor_test.go | 16 ++-- visitor/dumper.go | 30 +++++-- visitor/dumper_test.go | 2 +- visitor/go_dumper.go | 93 +++++++++++++++++++ visitor/go_dumper_test.go | 111 +++++++++++++++++++++++ visitor/namespace_resolver.go | 21 +++-- walker/walker.go | 11 ++- 173 files changed, 1279 insertions(+), 735 deletions(-) create mode 100644 visitor/go_dumper.go create mode 100644 visitor/go_dumper_test.go diff --git a/main.go b/main.go index 53f9901..151d3b7 100644 --- a/main.go +++ b/main.go @@ -99,7 +99,7 @@ func printer(result <-chan parser.Parser) { nsResolver := visitor.NewNamespaceResolver() parserWorker.GetRootNode().Walk(nsResolver) - dumper := visitor.Dumper{ + dumper := &visitor.Dumper{ Writer: os.Stdout, Indent: " | ", Comments: parserWorker.GetComments(), diff --git a/node/expr/assign/n_assign.go b/node/expr/assign/n_assign.go index d94df64..65a9cb8 100644 --- a/node/expr/assign/n_assign.go +++ b/node/expr/assign/n_assign.go @@ -32,13 +32,15 @@ func (n *Assign) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Expression != nil { - vv := v.GetChildrenVisitor("Expression") - n.Expression.Walk(vv) + v.EnterChildNode("Expression", n) + n.Expression.Walk(v) + v.LeaveChildNode("Expression", n) } v.LeaveNode(n) diff --git a/node/expr/assign/n_assign_ref.go b/node/expr/assign/n_assign_ref.go index 8cbd264..c6d560f 100644 --- a/node/expr/assign/n_assign_ref.go +++ b/node/expr/assign/n_assign_ref.go @@ -32,13 +32,15 @@ func (n *Reference) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Expression != nil { - vv := v.GetChildrenVisitor("Expression") - n.Expression.Walk(vv) + v.EnterChildNode("Expression", n) + n.Expression.Walk(v) + v.LeaveChildNode("Expression", n) } v.LeaveNode(n) diff --git a/node/expr/assign/n_bitwise_and.go b/node/expr/assign/n_bitwise_and.go index bc112e6..ff01896 100644 --- a/node/expr/assign/n_bitwise_and.go +++ b/node/expr/assign/n_bitwise_and.go @@ -32,13 +32,15 @@ func (n *BitwiseAnd) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Expression != nil { - vv := v.GetChildrenVisitor("Expression") - n.Expression.Walk(vv) + v.EnterChildNode("Expression", n) + n.Expression.Walk(v) + v.LeaveChildNode("Expression", n) } v.LeaveNode(n) diff --git a/node/expr/assign/n_bitwise_or.go b/node/expr/assign/n_bitwise_or.go index b8ae059..2832633 100644 --- a/node/expr/assign/n_bitwise_or.go +++ b/node/expr/assign/n_bitwise_or.go @@ -32,13 +32,15 @@ func (n *BitwiseOr) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Expression != nil { - vv := v.GetChildrenVisitor("Expression") - n.Expression.Walk(vv) + v.EnterChildNode("Expression", n) + n.Expression.Walk(v) + v.LeaveChildNode("Expression", n) } v.LeaveNode(n) diff --git a/node/expr/assign/n_bitwise_xor.go b/node/expr/assign/n_bitwise_xor.go index 905158b..ad22009 100644 --- a/node/expr/assign/n_bitwise_xor.go +++ b/node/expr/assign/n_bitwise_xor.go @@ -32,13 +32,15 @@ func (n *BitwiseXor) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Expression != nil { - vv := v.GetChildrenVisitor("Expression") - n.Expression.Walk(vv) + v.EnterChildNode("Expression", n) + n.Expression.Walk(v) + v.LeaveChildNode("Expression", n) } v.LeaveNode(n) diff --git a/node/expr/assign/n_concat.go b/node/expr/assign/n_concat.go index a43e3a1..66c08fc 100644 --- a/node/expr/assign/n_concat.go +++ b/node/expr/assign/n_concat.go @@ -32,13 +32,15 @@ func (n *Concat) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Expression != nil { - vv := v.GetChildrenVisitor("Expression") - n.Expression.Walk(vv) + v.EnterChildNode("Expression", n) + n.Expression.Walk(v) + v.LeaveChildNode("Expression", n) } v.LeaveNode(n) diff --git a/node/expr/assign/n_div.go b/node/expr/assign/n_div.go index 05bc2ed..9d70e82 100644 --- a/node/expr/assign/n_div.go +++ b/node/expr/assign/n_div.go @@ -32,13 +32,15 @@ func (n *Div) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Expression != nil { - vv := v.GetChildrenVisitor("Expression") - n.Expression.Walk(vv) + v.EnterChildNode("Expression", n) + n.Expression.Walk(v) + v.LeaveChildNode("Expression", n) } v.LeaveNode(n) diff --git a/node/expr/assign/n_minus.go b/node/expr/assign/n_minus.go index c66b1d2..191e6fa 100644 --- a/node/expr/assign/n_minus.go +++ b/node/expr/assign/n_minus.go @@ -32,13 +32,15 @@ func (n *Minus) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Expression != nil { - vv := v.GetChildrenVisitor("Expression") - n.Expression.Walk(vv) + v.EnterChildNode("Expression", n) + n.Expression.Walk(v) + v.LeaveChildNode("Expression", n) } v.LeaveNode(n) diff --git a/node/expr/assign/n_mod.go b/node/expr/assign/n_mod.go index 6e394c5..b35dd22 100644 --- a/node/expr/assign/n_mod.go +++ b/node/expr/assign/n_mod.go @@ -32,13 +32,15 @@ func (n *Mod) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Expression != nil { - vv := v.GetChildrenVisitor("Expression") - n.Expression.Walk(vv) + v.EnterChildNode("Expression", n) + n.Expression.Walk(v) + v.LeaveChildNode("Expression", n) } v.LeaveNode(n) diff --git a/node/expr/assign/n_mul.go b/node/expr/assign/n_mul.go index 3dc8090..d241a4d 100644 --- a/node/expr/assign/n_mul.go +++ b/node/expr/assign/n_mul.go @@ -32,13 +32,15 @@ func (n *Mul) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Expression != nil { - vv := v.GetChildrenVisitor("Expression") - n.Expression.Walk(vv) + v.EnterChildNode("Expression", n) + n.Expression.Walk(v) + v.LeaveChildNode("Expression", n) } v.LeaveNode(n) diff --git a/node/expr/assign/n_plus.go b/node/expr/assign/n_plus.go index d5cc425..d010c54 100644 --- a/node/expr/assign/n_plus.go +++ b/node/expr/assign/n_plus.go @@ -32,13 +32,15 @@ func (n *Plus) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Expression != nil { - vv := v.GetChildrenVisitor("Expression") - n.Expression.Walk(vv) + v.EnterChildNode("Expression", n) + n.Expression.Walk(v) + v.LeaveChildNode("Expression", n) } v.LeaveNode(n) diff --git a/node/expr/assign/n_pow.go b/node/expr/assign/n_pow.go index a81cb0c..8623887 100644 --- a/node/expr/assign/n_pow.go +++ b/node/expr/assign/n_pow.go @@ -32,13 +32,15 @@ func (n *Pow) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Expression != nil { - vv := v.GetChildrenVisitor("Expression") - n.Expression.Walk(vv) + v.EnterChildNode("Expression", n) + n.Expression.Walk(v) + v.LeaveChildNode("Expression", n) } v.LeaveNode(n) diff --git a/node/expr/assign/n_shift_left.go b/node/expr/assign/n_shift_left.go index 6b52663..49f3fc5 100644 --- a/node/expr/assign/n_shift_left.go +++ b/node/expr/assign/n_shift_left.go @@ -32,13 +32,15 @@ func (n *ShiftLeft) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Expression != nil { - vv := v.GetChildrenVisitor("Expression") - n.Expression.Walk(vv) + v.EnterChildNode("Expression", n) + n.Expression.Walk(v) + v.LeaveChildNode("Expression", n) } v.LeaveNode(n) diff --git a/node/expr/assign/n_shift_right.go b/node/expr/assign/n_shift_right.go index 126b801..b07ff30 100644 --- a/node/expr/assign/n_shift_right.go +++ b/node/expr/assign/n_shift_right.go @@ -32,13 +32,15 @@ func (n *ShiftRight) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Expression != nil { - vv := v.GetChildrenVisitor("Expression") - n.Expression.Walk(vv) + v.EnterChildNode("Expression", n) + n.Expression.Walk(v) + v.LeaveChildNode("Expression", n) } v.LeaveNode(n) diff --git a/node/expr/assign/t_visitor_test.go b/node/expr/assign/t_visitor_test.go index 643d158..3b65670 100644 --- a/node/expr/assign/t_visitor_test.go +++ b/node/expr/assign/t_visitor_test.go @@ -20,112 +20,112 @@ var nodesToTest = []struct { }{ { &assign.Reference{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Variable: &expr.Variable{}, + Expression: &expr.Variable{}, }, []string{"Variable", "Expression"}, map[string]interface{}{}, }, { &assign.Assign{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Variable: &expr.Variable{}, + Expression: &expr.Variable{}, }, []string{"Variable", "Expression"}, map[string]interface{}{}, }, { &assign.BitwiseAnd{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Variable: &expr.Variable{}, + Expression: &expr.Variable{}, }, []string{"Variable", "Expression"}, map[string]interface{}{}, }, { &assign.BitwiseOr{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Variable: &expr.Variable{}, + Expression: &expr.Variable{}, }, []string{"Variable", "Expression"}, map[string]interface{}{}, }, { &assign.BitwiseXor{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Variable: &expr.Variable{}, + Expression: &expr.Variable{}, }, []string{"Variable", "Expression"}, map[string]interface{}{}, }, { &assign.Concat{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Variable: &expr.Variable{}, + Expression: &expr.Variable{}, }, []string{"Variable", "Expression"}, map[string]interface{}{}, }, { &assign.Div{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Variable: &expr.Variable{}, + Expression: &expr.Variable{}, }, []string{"Variable", "Expression"}, map[string]interface{}{}, }, { &assign.Minus{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Variable: &expr.Variable{}, + Expression: &expr.Variable{}, }, []string{"Variable", "Expression"}, map[string]interface{}{}, }, { &assign.Mod{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Variable: &expr.Variable{}, + Expression: &expr.Variable{}, }, []string{"Variable", "Expression"}, map[string]interface{}{}, }, { &assign.Mul{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Variable: &expr.Variable{}, + Expression: &expr.Variable{}, }, []string{"Variable", "Expression"}, map[string]interface{}{}, }, { &assign.Plus{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Variable: &expr.Variable{}, + Expression: &expr.Variable{}, }, []string{"Variable", "Expression"}, map[string]interface{}{}, }, { &assign.Pow{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Variable: &expr.Variable{}, + Expression: &expr.Variable{}, }, []string{"Variable", "Expression"}, map[string]interface{}{}, }, { &assign.ShiftLeft{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Variable: &expr.Variable{}, + Expression: &expr.Variable{}, }, []string{"Variable", "Expression"}, map[string]interface{}{}, }, { &assign.ShiftRight{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Variable: &expr.Variable{}, + Expression: &expr.Variable{}, }, []string{"Variable", "Expression"}, map[string]interface{}{}, @@ -138,11 +138,15 @@ type visitorMock struct { } 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) - 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) { for _, tt := range nodesToTest { diff --git a/node/expr/binary/n_bitwise_and.go b/node/expr/binary/n_bitwise_and.go index 842398d..5b24ccb 100644 --- a/node/expr/binary/n_bitwise_and.go +++ b/node/expr/binary/n_bitwise_and.go @@ -32,13 +32,15 @@ func (n *BitwiseAnd) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_bitwise_or.go b/node/expr/binary/n_bitwise_or.go index 2d257b5..0637ecb 100644 --- a/node/expr/binary/n_bitwise_or.go +++ b/node/expr/binary/n_bitwise_or.go @@ -32,13 +32,15 @@ func (n *BitwiseOr) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_bitwise_xor.go b/node/expr/binary/n_bitwise_xor.go index c67fe00..f675345 100644 --- a/node/expr/binary/n_bitwise_xor.go +++ b/node/expr/binary/n_bitwise_xor.go @@ -32,13 +32,15 @@ func (n *BitwiseXor) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_boolean_and.go b/node/expr/binary/n_boolean_and.go index e7ca96b..b0a5bae 100644 --- a/node/expr/binary/n_boolean_and.go +++ b/node/expr/binary/n_boolean_and.go @@ -32,13 +32,15 @@ func (n *BooleanAnd) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_boolean_or.go b/node/expr/binary/n_boolean_or.go index bb92e0a..b522baa 100644 --- a/node/expr/binary/n_boolean_or.go +++ b/node/expr/binary/n_boolean_or.go @@ -32,13 +32,15 @@ func (n *BooleanOr) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_coalesce.go b/node/expr/binary/n_coalesce.go index b0eb6f5..8339fdc 100644 --- a/node/expr/binary/n_coalesce.go +++ b/node/expr/binary/n_coalesce.go @@ -32,13 +32,15 @@ func (n *Coalesce) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_concat.go b/node/expr/binary/n_concat.go index 3a74a4d..a5953c1 100644 --- a/node/expr/binary/n_concat.go +++ b/node/expr/binary/n_concat.go @@ -32,13 +32,15 @@ func (n *Concat) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_div.go b/node/expr/binary/n_div.go index aa68b9a..d3f7a86 100644 --- a/node/expr/binary/n_div.go +++ b/node/expr/binary/n_div.go @@ -32,13 +32,15 @@ func (n *Div) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_equal.go b/node/expr/binary/n_equal.go index c02b1ec..b266679 100644 --- a/node/expr/binary/n_equal.go +++ b/node/expr/binary/n_equal.go @@ -32,13 +32,15 @@ func (n *Equal) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_greater.go b/node/expr/binary/n_greater.go index daab173..58f24fe 100644 --- a/node/expr/binary/n_greater.go +++ b/node/expr/binary/n_greater.go @@ -32,13 +32,15 @@ func (n *Greater) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_greater_or_equal.go b/node/expr/binary/n_greater_or_equal.go index 47f1df2..921b84a 100644 --- a/node/expr/binary/n_greater_or_equal.go +++ b/node/expr/binary/n_greater_or_equal.go @@ -32,13 +32,15 @@ func (n *GreaterOrEqual) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_identical.go b/node/expr/binary/n_identical.go index 6a782e0..06c1947 100644 --- a/node/expr/binary/n_identical.go +++ b/node/expr/binary/n_identical.go @@ -32,13 +32,15 @@ func (n *Identical) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_logical_and.go b/node/expr/binary/n_logical_and.go index b2d35b6..7015a74 100644 --- a/node/expr/binary/n_logical_and.go +++ b/node/expr/binary/n_logical_and.go @@ -32,13 +32,15 @@ func (n *LogicalAnd) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_logical_or.go b/node/expr/binary/n_logical_or.go index 5e7d88e..05dff50 100644 --- a/node/expr/binary/n_logical_or.go +++ b/node/expr/binary/n_logical_or.go @@ -32,13 +32,15 @@ func (n *LogicalOr) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_logical_xor.go b/node/expr/binary/n_logical_xor.go index 043e0a3..91e8408 100644 --- a/node/expr/binary/n_logical_xor.go +++ b/node/expr/binary/n_logical_xor.go @@ -32,13 +32,15 @@ func (n *LogicalXor) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_minus.go b/node/expr/binary/n_minus.go index 397fa68..6e42de6 100644 --- a/node/expr/binary/n_minus.go +++ b/node/expr/binary/n_minus.go @@ -32,13 +32,15 @@ func (n *Minus) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_mod.go b/node/expr/binary/n_mod.go index 30809e3..759737a 100644 --- a/node/expr/binary/n_mod.go +++ b/node/expr/binary/n_mod.go @@ -32,13 +32,15 @@ func (n *Mod) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_mul.go b/node/expr/binary/n_mul.go index c601bfd..c37d1c8 100644 --- a/node/expr/binary/n_mul.go +++ b/node/expr/binary/n_mul.go @@ -32,13 +32,15 @@ func (n *Mul) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_not_equal.go b/node/expr/binary/n_not_equal.go index e63cfcd..4cc6a89 100644 --- a/node/expr/binary/n_not_equal.go +++ b/node/expr/binary/n_not_equal.go @@ -32,13 +32,15 @@ func (n *NotEqual) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_not_identical.go b/node/expr/binary/n_not_identical.go index 4f8f13e..172d56d 100644 --- a/node/expr/binary/n_not_identical.go +++ b/node/expr/binary/n_not_identical.go @@ -32,13 +32,15 @@ func (n *NotIdentical) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_plus.go b/node/expr/binary/n_plus.go index 5d68c46..1e18553 100644 --- a/node/expr/binary/n_plus.go +++ b/node/expr/binary/n_plus.go @@ -32,13 +32,15 @@ func (n *Plus) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_pow.go b/node/expr/binary/n_pow.go index a21e115..ee3d6da 100644 --- a/node/expr/binary/n_pow.go +++ b/node/expr/binary/n_pow.go @@ -32,13 +32,15 @@ func (n *Pow) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_shift_left.go b/node/expr/binary/n_shift_left.go index 2b1dec0..c1ed698 100644 --- a/node/expr/binary/n_shift_left.go +++ b/node/expr/binary/n_shift_left.go @@ -32,13 +32,15 @@ func (n *ShiftLeft) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_shift_right.go b/node/expr/binary/n_shift_right.go index 44911cb..f522721 100644 --- a/node/expr/binary/n_shift_right.go +++ b/node/expr/binary/n_shift_right.go @@ -32,13 +32,15 @@ func (n *ShiftRight) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_smaller.go b/node/expr/binary/n_smaller.go index 1622871..eff9eed 100644 --- a/node/expr/binary/n_smaller.go +++ b/node/expr/binary/n_smaller.go @@ -32,13 +32,15 @@ func (n *Smaller) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_smaller_or_equal.go b/node/expr/binary/n_smaller_or_equal.go index 9a839d8..38c4432 100644 --- a/node/expr/binary/n_smaller_or_equal.go +++ b/node/expr/binary/n_smaller_or_equal.go @@ -32,13 +32,15 @@ func (n *SmallerOrEqual) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/n_spaceship.go b/node/expr/binary/n_spaceship.go index ea05c77..5d307ef 100644 --- a/node/expr/binary/n_spaceship.go +++ b/node/expr/binary/n_spaceship.go @@ -32,13 +32,15 @@ func (n *Spaceship) Walk(v walker.Visitor) { } if n.Left != nil { - vv := v.GetChildrenVisitor("Left") - n.Left.Walk(vv) + v.EnterChildNode("Left", n) + n.Left.Walk(v) + v.LeaveChildNode("Left", n) } if n.Right != nil { - vv := v.GetChildrenVisitor("Right") - n.Right.Walk(vv) + v.EnterChildNode("Right", n) + n.Right.Walk(v) + v.LeaveChildNode("Right", n) } v.LeaveNode(n) diff --git a/node/expr/binary/t_visitor_test.go b/node/expr/binary/t_visitor_test.go index 868bddf..a875cc5 100644 --- a/node/expr/binary/t_visitor_test.go +++ b/node/expr/binary/t_visitor_test.go @@ -19,216 +19,216 @@ var nodesToTest = []struct { }{ { &binary.BitwiseAnd{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.BitwiseOr{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.BitwiseXor{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.BooleanAnd{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.BooleanOr{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.Coalesce{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.Concat{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.Div{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.Equal{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.GreaterOrEqual{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.Greater{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.Identical{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.LogicalAnd{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.LogicalOr{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.LogicalXor{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.Minus{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.Mod{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.Mul{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.NotEqual{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.NotIdentical{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.Plus{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.Pow{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.ShiftLeft{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.ShiftRight{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.SmallerOrEqual{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.Smaller{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, }, { &binary.Spaceship{ - Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Left: &expr.Variable{}, + Right: &expr.Variable{}, }, []string{"Left", "Right"}, map[string]interface{}{}, @@ -241,11 +241,15 @@ type visitorMock struct { } 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) - 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) { for _, tt := range nodesToTest { diff --git a/node/expr/cast/n_cast_array.go b/node/expr/cast/n_cast_array.go index 56537a8..0776331 100644 --- a/node/expr/cast/n_cast_array.go +++ b/node/expr/cast/n_cast_array.go @@ -30,8 +30,9 @@ func (n *Array) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/cast/n_cast_bool.go b/node/expr/cast/n_cast_bool.go index f4c5988..00e5409 100644 --- a/node/expr/cast/n_cast_bool.go +++ b/node/expr/cast/n_cast_bool.go @@ -30,8 +30,9 @@ func (n *Bool) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/cast/n_cast_double.go b/node/expr/cast/n_cast_double.go index addbbc7..81c6c6a 100644 --- a/node/expr/cast/n_cast_double.go +++ b/node/expr/cast/n_cast_double.go @@ -30,8 +30,9 @@ func (n *Double) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/cast/n_cast_int.go b/node/expr/cast/n_cast_int.go index 2d70e16..0ad977d 100644 --- a/node/expr/cast/n_cast_int.go +++ b/node/expr/cast/n_cast_int.go @@ -30,8 +30,9 @@ func (n *Int) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/cast/n_cast_object.go b/node/expr/cast/n_cast_object.go index b25b919..7e38461 100644 --- a/node/expr/cast/n_cast_object.go +++ b/node/expr/cast/n_cast_object.go @@ -30,8 +30,9 @@ func (n *Object) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/cast/n_cast_string.go b/node/expr/cast/n_cast_string.go index 3fcd0d2..fab6637 100644 --- a/node/expr/cast/n_cast_string.go +++ b/node/expr/cast/n_cast_string.go @@ -30,8 +30,9 @@ func (n *String) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/cast/n_cast_unset.go b/node/expr/cast/n_cast_unset.go index a3dc011..ea37f26 100644 --- a/node/expr/cast/n_cast_unset.go +++ b/node/expr/cast/n_cast_unset.go @@ -30,8 +30,9 @@ func (n *Unset) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/cast/t_visitor_test.go b/node/expr/cast/t_visitor_test.go index 3f48c90..f574936 100644 --- a/node/expr/cast/t_visitor_test.go +++ b/node/expr/cast/t_visitor_test.go @@ -19,49 +19,49 @@ var nodesToTest = []struct { }{ { &cast.Array{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, }, { &cast.Bool{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, }, { &cast.Double{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, }, { &cast.Int{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, }, { &cast.Object{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, }, { &cast.String{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, }, { &cast.Unset{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, @@ -74,11 +74,15 @@ type visitorMock struct { } 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) - 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) { for _, tt := range nodesToTest { diff --git a/node/expr/n_array.go b/node/expr/n_array.go index d96793c..c555a8e 100644 --- a/node/expr/n_array.go +++ b/node/expr/n_array.go @@ -30,12 +30,13 @@ func (n *Array) Walk(v walker.Visitor) { } if n.Items != nil { - vv := v.GetChildrenVisitor("Items") + v.EnterChildList("Items", n) for _, nn := range n.Items { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Items", n) } v.LeaveNode(n) diff --git a/node/expr/n_array_dim_fetch.go b/node/expr/n_array_dim_fetch.go index e41135f..6eef938 100644 --- a/node/expr/n_array_dim_fetch.go +++ b/node/expr/n_array_dim_fetch.go @@ -32,13 +32,15 @@ func (n *ArrayDimFetch) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Dim != nil { - vv := v.GetChildrenVisitor("Dim") - n.Dim.Walk(vv) + v.EnterChildNode("Dim", n) + n.Dim.Walk(v) + v.LeaveChildNode("Dim", n) } v.LeaveNode(n) diff --git a/node/expr/n_array_item.go b/node/expr/n_array_item.go index b651358..9ae1752 100644 --- a/node/expr/n_array_item.go +++ b/node/expr/n_array_item.go @@ -32,13 +32,15 @@ func (n *ArrayItem) Walk(v walker.Visitor) { } if n.Key != nil { - vv := v.GetChildrenVisitor("Key") - n.Key.Walk(vv) + v.EnterChildNode("Key", n) + n.Key.Walk(v) + v.LeaveChildNode("Key", n) } if n.Val != nil { - vv := v.GetChildrenVisitor("Val") - n.Val.Walk(vv) + v.EnterChildNode("Val", n) + n.Val.Walk(v) + v.LeaveChildNode("Val", n) } v.LeaveNode(n) diff --git a/node/expr/n_bitwise_not.go b/node/expr/n_bitwise_not.go index e4ca599..0877bbc 100644 --- a/node/expr/n_bitwise_not.go +++ b/node/expr/n_bitwise_not.go @@ -30,8 +30,9 @@ func (n *BitwiseNot) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/n_boolean_not.go b/node/expr/n_boolean_not.go index a552eca..b28318a 100644 --- a/node/expr/n_boolean_not.go +++ b/node/expr/n_boolean_not.go @@ -30,8 +30,9 @@ func (n *BooleanNot) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/n_class_const_fetch.go b/node/expr/n_class_const_fetch.go index 6f9ecd0..3557c3e 100644 --- a/node/expr/n_class_const_fetch.go +++ b/node/expr/n_class_const_fetch.go @@ -32,13 +32,15 @@ func (n *ClassConstFetch) Walk(v walker.Visitor) { } if n.Class != nil { - vv := v.GetChildrenVisitor("Class") - n.Class.Walk(vv) + v.EnterChildNode("Class", n) + n.Class.Walk(v) + v.LeaveChildNode("Class", n) } if n.ConstantName != nil { - vv := v.GetChildrenVisitor("ConstantName") - n.ConstantName.Walk(vv) + v.EnterChildNode("ConstantName", n) + n.ConstantName.Walk(v) + v.LeaveChildNode("ConstantName", n) } v.LeaveNode(n) diff --git a/node/expr/n_clone.go b/node/expr/n_clone.go index 64ec320..ee712e4 100644 --- a/node/expr/n_clone.go +++ b/node/expr/n_clone.go @@ -30,8 +30,9 @@ func (n *Clone) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/n_closure.go b/node/expr/n_closure.go index 26d9949..e2761da 100644 --- a/node/expr/n_closure.go +++ b/node/expr/n_closure.go @@ -46,31 +46,35 @@ func (n *Closure) Walk(v walker.Visitor) { } if n.Params != nil { - vv := v.GetChildrenVisitor("Params") + v.EnterChildList("Params", n) for _, nn := range n.Params { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Params", n) } if n.ClosureUse != nil { - vv := v.GetChildrenVisitor("ClosureUse") - n.ClosureUse.Walk(vv) + v.EnterChildNode("ClosureUse", n) + n.ClosureUse.Walk(v) + v.LeaveChildNode("ClosureUse", n) } if n.ReturnType != nil { - vv := v.GetChildrenVisitor("ReturnType") - n.ReturnType.Walk(vv) + v.EnterChildNode("ReturnType", n) + n.ReturnType.Walk(v) + v.LeaveChildNode("ReturnType", n) } if n.Stmts != nil { - vv := v.GetChildrenVisitor("Stmts") + v.EnterChildList("Stmts", n) for _, nn := range n.Stmts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Stmts", n) } v.LeaveNode(n) diff --git a/node/expr/n_closure_use.go b/node/expr/n_closure_use.go index 6225208..fd9b0b2 100644 --- a/node/expr/n_closure_use.go +++ b/node/expr/n_closure_use.go @@ -30,12 +30,13 @@ func (n *ClosureUse) Walk(v walker.Visitor) { } if n.Uses != nil { - vv := v.GetChildrenVisitor("Uses") + v.EnterChildList("Uses", n) for _, nn := range n.Uses { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Uses", n) } v.LeaveNode(n) diff --git a/node/expr/n_const_fetch.go b/node/expr/n_const_fetch.go index 09313e4..c45481f 100644 --- a/node/expr/n_const_fetch.go +++ b/node/expr/n_const_fetch.go @@ -30,8 +30,9 @@ func (n *ConstFetch) Walk(v walker.Visitor) { } if n.Constant != nil { - vv := v.GetChildrenVisitor("Constant") - n.Constant.Walk(vv) + v.EnterChildNode("Constant", n) + n.Constant.Walk(v) + v.LeaveChildNode("Constant", n) } v.LeaveNode(n) diff --git a/node/expr/n_die.go b/node/expr/n_die.go index 5cae0d4..80fd988 100644 --- a/node/expr/n_die.go +++ b/node/expr/n_die.go @@ -30,8 +30,9 @@ func (n *Die) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/n_empty.go b/node/expr/n_empty.go index 0ce4e3c..44692bb 100644 --- a/node/expr/n_empty.go +++ b/node/expr/n_empty.go @@ -30,8 +30,9 @@ func (n *Empty) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/n_error_suppress.go b/node/expr/n_error_suppress.go index b927c8d..9699014 100644 --- a/node/expr/n_error_suppress.go +++ b/node/expr/n_error_suppress.go @@ -30,8 +30,9 @@ func (n *ErrorSuppress) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/n_eval.go b/node/expr/n_eval.go index 39bae38..0f48c24 100644 --- a/node/expr/n_eval.go +++ b/node/expr/n_eval.go @@ -30,8 +30,9 @@ func (n *Eval) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/n_exit.go b/node/expr/n_exit.go index 2567296..607cb30 100644 --- a/node/expr/n_exit.go +++ b/node/expr/n_exit.go @@ -30,8 +30,9 @@ func (n *Exit) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/n_function_call.go b/node/expr/n_function_call.go index 2d17fdc..929d387 100644 --- a/node/expr/n_function_call.go +++ b/node/expr/n_function_call.go @@ -32,13 +32,15 @@ func (n *FunctionCall) Walk(v walker.Visitor) { } if n.Function != nil { - vv := v.GetChildrenVisitor("Function") - n.Function.Walk(vv) + v.EnterChildNode("Function", n) + n.Function.Walk(v) + v.LeaveChildNode("Function", n) } if n.ArgumentList != nil { - vv := v.GetChildrenVisitor("ArgumentList") - n.ArgumentList.Walk(vv) + v.EnterChildNode("ArgumentList", n) + n.ArgumentList.Walk(v) + v.LeaveChildNode("ArgumentList", n) } v.LeaveNode(n) diff --git a/node/expr/n_include.go b/node/expr/n_include.go index afdac26..f4e33e8 100644 --- a/node/expr/n_include.go +++ b/node/expr/n_include.go @@ -30,8 +30,9 @@ func (n *Include) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/n_include_once.go b/node/expr/n_include_once.go index 08bcc6a..0841834 100644 --- a/node/expr/n_include_once.go +++ b/node/expr/n_include_once.go @@ -30,8 +30,9 @@ func (n *IncludeOnce) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/n_instance_of.go b/node/expr/n_instance_of.go index d71441d..f8941ca 100644 --- a/node/expr/n_instance_of.go +++ b/node/expr/n_instance_of.go @@ -32,13 +32,15 @@ func (n *InstanceOf) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } if n.Class != nil { - vv := v.GetChildrenVisitor("Class") - n.Class.Walk(vv) + v.EnterChildNode("Class", n) + n.Class.Walk(v) + v.LeaveChildNode("Class", n) } v.LeaveNode(n) diff --git a/node/expr/n_isset.go b/node/expr/n_isset.go index 3b96086..46f6e3b 100644 --- a/node/expr/n_isset.go +++ b/node/expr/n_isset.go @@ -30,12 +30,13 @@ func (n *Isset) Walk(v walker.Visitor) { } if n.Variables != nil { - vv := v.GetChildrenVisitor("Variables") + v.EnterChildList("Variables", n) for _, nn := range n.Variables { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Variables", n) } v.LeaveNode(n) diff --git a/node/expr/n_list.go b/node/expr/n_list.go index 0f6c5f6..9b09cc3 100644 --- a/node/expr/n_list.go +++ b/node/expr/n_list.go @@ -30,12 +30,13 @@ func (n *List) Walk(v walker.Visitor) { } if n.Items != nil { - vv := v.GetChildrenVisitor("Items") + v.EnterChildList("Items", n) for _, nn := range n.Items { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Items", n) } v.LeaveNode(n) diff --git a/node/expr/n_method_call.go b/node/expr/n_method_call.go index 1bcc4fb..5fe3f02 100644 --- a/node/expr/n_method_call.go +++ b/node/expr/n_method_call.go @@ -34,18 +34,21 @@ func (n *MethodCall) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Method != nil { - vv := v.GetChildrenVisitor("Method") - n.Method.Walk(vv) + v.EnterChildNode("Method", n) + n.Method.Walk(v) + v.LeaveChildNode("Method", n) } if n.ArgumentList != nil { - vv := v.GetChildrenVisitor("ArgumentList") - n.ArgumentList.Walk(vv) + v.EnterChildNode("ArgumentList", n) + n.ArgumentList.Walk(v) + v.LeaveChildNode("ArgumentList", n) } v.LeaveNode(n) diff --git a/node/expr/n_new.go b/node/expr/n_new.go index 9323f48..4dca5cf 100644 --- a/node/expr/n_new.go +++ b/node/expr/n_new.go @@ -32,13 +32,15 @@ func (n *New) Walk(v walker.Visitor) { } if n.Class != nil { - vv := v.GetChildrenVisitor("Class") - n.Class.Walk(vv) + v.EnterChildNode("Class", n) + n.Class.Walk(v) + v.LeaveChildNode("Class", n) } if n.ArgumentList != nil { - vv := v.GetChildrenVisitor("ArgumentList") - n.ArgumentList.Walk(vv) + v.EnterChildNode("ArgumentList", n) + n.ArgumentList.Walk(v) + v.LeaveChildNode("ArgumentList", n) } v.LeaveNode(n) diff --git a/node/expr/n_post_dec.go b/node/expr/n_post_dec.go index 1b68e8f..c120afd 100644 --- a/node/expr/n_post_dec.go +++ b/node/expr/n_post_dec.go @@ -30,8 +30,9 @@ func (n *PostDec) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } v.LeaveNode(n) diff --git a/node/expr/n_post_inc.go b/node/expr/n_post_inc.go index b6a007c..a2f394f 100644 --- a/node/expr/n_post_inc.go +++ b/node/expr/n_post_inc.go @@ -30,8 +30,9 @@ func (n *PostInc) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } v.LeaveNode(n) diff --git a/node/expr/n_pre_dec.go b/node/expr/n_pre_dec.go index fc7e27a..99d6025 100644 --- a/node/expr/n_pre_dec.go +++ b/node/expr/n_pre_dec.go @@ -30,8 +30,9 @@ func (n *PreDec) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } v.LeaveNode(n) diff --git a/node/expr/n_pre_inc.go b/node/expr/n_pre_inc.go index 6ba964b..a30b23e 100644 --- a/node/expr/n_pre_inc.go +++ b/node/expr/n_pre_inc.go @@ -30,8 +30,9 @@ func (n *PreInc) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } v.LeaveNode(n) diff --git a/node/expr/n_print.go b/node/expr/n_print.go index e60f3aa..02d8173 100644 --- a/node/expr/n_print.go +++ b/node/expr/n_print.go @@ -30,8 +30,9 @@ func (n *Print) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/n_property_fetch.go b/node/expr/n_property_fetch.go index 128f355..cfc155f 100644 --- a/node/expr/n_property_fetch.go +++ b/node/expr/n_property_fetch.go @@ -32,13 +32,15 @@ func (n *PropertyFetch) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Property != nil { - vv := v.GetChildrenVisitor("Property") - n.Property.Walk(vv) + v.EnterChildNode("Property", n) + n.Property.Walk(v) + v.LeaveChildNode("Property", n) } v.LeaveNode(n) diff --git a/node/expr/n_reference.go b/node/expr/n_reference.go index 9b864fc..523ba1d 100644 --- a/node/expr/n_reference.go +++ b/node/expr/n_reference.go @@ -30,8 +30,9 @@ func (n *Reference) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } v.LeaveNode(n) diff --git a/node/expr/n_require.go b/node/expr/n_require.go index 3f5c43f..79ba272 100644 --- a/node/expr/n_require.go +++ b/node/expr/n_require.go @@ -30,8 +30,9 @@ func (n *Require) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/n_require_once.go b/node/expr/n_require_once.go index 9d1436d..ee9cb2f 100644 --- a/node/expr/n_require_once.go +++ b/node/expr/n_require_once.go @@ -30,8 +30,9 @@ func (n *RequireOnce) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/n_shell_exec.go b/node/expr/n_shell_exec.go index 9310989..1432c92 100644 --- a/node/expr/n_shell_exec.go +++ b/node/expr/n_shell_exec.go @@ -30,12 +30,13 @@ func (n *ShellExec) Walk(v walker.Visitor) { } if n.Parts != nil { - vv := v.GetChildrenVisitor("Parts") + v.EnterChildList("Parts", n) for _, nn := range n.Parts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Parts", n) } v.LeaveNode(n) diff --git a/node/expr/n_short_array.go b/node/expr/n_short_array.go index 6bb45e0..694830f 100644 --- a/node/expr/n_short_array.go +++ b/node/expr/n_short_array.go @@ -30,12 +30,13 @@ func (n *ShortArray) Walk(v walker.Visitor) { } if n.Items != nil { - vv := v.GetChildrenVisitor("Items") + v.EnterChildList("Items", n) for _, nn := range n.Items { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Items", n) } v.LeaveNode(n) diff --git a/node/expr/n_short_list.go b/node/expr/n_short_list.go index dd00855..2e4f8a8 100644 --- a/node/expr/n_short_list.go +++ b/node/expr/n_short_list.go @@ -30,12 +30,13 @@ func (n *ShortList) Walk(v walker.Visitor) { } if n.Items != nil { - vv := v.GetChildrenVisitor("Items") + v.EnterChildList("Items", n) for _, nn := range n.Items { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Items", n) } v.LeaveNode(n) diff --git a/node/expr/n_static_call.go b/node/expr/n_static_call.go index 0f87f93..4c61a33 100644 --- a/node/expr/n_static_call.go +++ b/node/expr/n_static_call.go @@ -34,18 +34,21 @@ func (n *StaticCall) Walk(v walker.Visitor) { } if n.Class != nil { - vv := v.GetChildrenVisitor("Class") - n.Class.Walk(vv) + v.EnterChildNode("Class", n) + n.Class.Walk(v) + v.LeaveChildNode("Class", n) } if n.Call != nil { - vv := v.GetChildrenVisitor("Call") - n.Call.Walk(vv) + v.EnterChildNode("Call", n) + n.Call.Walk(v) + v.LeaveChildNode("Call", n) } if n.ArgumentList != nil { - vv := v.GetChildrenVisitor("ArgumentList") - n.ArgumentList.Walk(vv) + v.EnterChildNode("ArgumentList", n) + n.ArgumentList.Walk(v) + v.LeaveChildNode("ArgumentList", n) } v.LeaveNode(n) diff --git a/node/expr/n_static_property_fetch.go b/node/expr/n_static_property_fetch.go index a3d07d6..97f2714 100644 --- a/node/expr/n_static_property_fetch.go +++ b/node/expr/n_static_property_fetch.go @@ -32,13 +32,15 @@ func (n *StaticPropertyFetch) Walk(v walker.Visitor) { } if n.Class != nil { - vv := v.GetChildrenVisitor("Class") - n.Class.Walk(vv) + v.EnterChildNode("Class", n) + n.Class.Walk(v) + v.LeaveChildNode("Class", n) } if n.Property != nil { - vv := v.GetChildrenVisitor("Property") - n.Property.Walk(vv) + v.EnterChildNode("Property", n) + n.Property.Walk(v) + v.LeaveChildNode("Property", n) } v.LeaveNode(n) diff --git a/node/expr/n_ternary.go b/node/expr/n_ternary.go index 83729b2..c559b06 100644 --- a/node/expr/n_ternary.go +++ b/node/expr/n_ternary.go @@ -34,18 +34,21 @@ func (n *Ternary) Walk(v walker.Visitor) { } if n.Condition != nil { - vv := v.GetChildrenVisitor("Condition") - n.Condition.Walk(vv) + v.EnterChildNode("Condition", n) + n.Condition.Walk(v) + v.LeaveChildNode("Condition", n) } if n.IfTrue != nil { - vv := v.GetChildrenVisitor("IfTrue") - n.IfTrue.Walk(vv) + v.EnterChildNode("IfTrue", n) + n.IfTrue.Walk(v) + v.LeaveChildNode("IfTrue", n) } if n.IfFalse != nil { - vv := v.GetChildrenVisitor("IfFalse") - n.IfFalse.Walk(vv) + v.EnterChildNode("IfFalse", n) + n.IfFalse.Walk(v) + v.LeaveChildNode("IfFalse", n) } v.LeaveNode(n) diff --git a/node/expr/n_unary_minus.go b/node/expr/n_unary_minus.go index efeda8e..e075c96 100644 --- a/node/expr/n_unary_minus.go +++ b/node/expr/n_unary_minus.go @@ -30,8 +30,9 @@ func (n *UnaryMinus) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/n_unary_plus.go b/node/expr/n_unary_plus.go index cd6fcdb..bbd6228 100644 --- a/node/expr/n_unary_plus.go +++ b/node/expr/n_unary_plus.go @@ -30,8 +30,9 @@ func (n *UnaryPlus) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/n_variable.go b/node/expr/n_variable.go index caa0f10..a098d22 100644 --- a/node/expr/n_variable.go +++ b/node/expr/n_variable.go @@ -35,8 +35,9 @@ func (n *Variable) Walk(v walker.Visitor) { } if n.VarName != nil { - vv := v.GetChildrenVisitor("VarName") - n.VarName.Walk(vv) + v.EnterChildNode("VarName", n) + n.VarName.Walk(v) + v.LeaveChildNode("VarName", n) } v.LeaveNode(n) diff --git a/node/expr/n_yield.go b/node/expr/n_yield.go index dbbd811..51fafb4 100644 --- a/node/expr/n_yield.go +++ b/node/expr/n_yield.go @@ -32,13 +32,15 @@ func (n *Yield) Walk(v walker.Visitor) { } if n.Key != nil { - vv := v.GetChildrenVisitor("Key") - n.Key.Walk(vv) + v.EnterChildNode("Key", n) + n.Key.Walk(v) + v.LeaveChildNode("Key", n) } if n.Value != nil { - vv := v.GetChildrenVisitor("Value") - n.Value.Walk(vv) + v.EnterChildNode("Value", n) + n.Value.Walk(v) + v.LeaveChildNode("Value", n) } v.LeaveNode(n) diff --git a/node/expr/n_yield_from.go b/node/expr/n_yield_from.go index 1109d0d..47d1f34 100644 --- a/node/expr/n_yield_from.go +++ b/node/expr/n_yield_from.go @@ -30,8 +30,9 @@ func (n *YieldFrom) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/expr/t_visitor_test.go b/node/expr/t_visitor_test.go index 90d6741..bcb0c45 100644 --- a/node/expr/t_visitor_test.go +++ b/node/expr/t_visitor_test.go @@ -24,7 +24,7 @@ var nodesToTest = []struct { }{ { &expr.ArrayDimFetch{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Variable: &expr.Variable{}, Dim: &scalar.Lnumber{Value: "1"}, }, []string{"Variable", "Dim"}, @@ -41,10 +41,7 @@ var nodesToTest = []struct { { &expr.Array{ Items: []node.Node{ - &expr.ArrayItem{ - Key: &scalar.String{Value: "key"}, - Val: &scalar.Lnumber{Value: "1"}, - }, + &expr.ArrayItem{}, }, }, []string{"Items"}, @@ -52,21 +49,21 @@ var nodesToTest = []struct { }, { &expr.BitwiseNot{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, }, { &expr.BooleanNot{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, }, { &expr.ClassConstFetch{ - Class: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Class: &expr.Variable{}, ConstantName: &node.Identifier{Value: "foo"}, }, []string{"Class", "ConstantName"}, @@ -74,7 +71,7 @@ var nodesToTest = []struct { }, { &expr.Clone{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, @@ -82,7 +79,7 @@ var nodesToTest = []struct { { &expr.ClosureUse{ Uses: []node.Node{ - &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + &expr.Variable{}, }, }, []string{"Uses"}, @@ -110,42 +107,42 @@ var nodesToTest = []struct { }, { &expr.Empty{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, }, { &expr.ErrorSuppress{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, }, { &expr.Eval{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, }, { &expr.Exit{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, }, { &expr.Die{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, }, { &expr.FunctionCall{ - Function: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Function: &expr.Variable{}, ArgumentList: &node.ArgumentList{}, }, []string{"Function", "ArgumentList"}, @@ -153,21 +150,21 @@ var nodesToTest = []struct { }, { &expr.IncludeOnce{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, }, { &expr.Include{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, }, { &expr.InstanceOf{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, Class: &name.Name{}, }, []string{"Expr", "Class"}, @@ -176,7 +173,7 @@ var nodesToTest = []struct { { &expr.Isset{ Variables: []node.Node{ - &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + &expr.Variable{}, }, }, []string{"Variables"}, @@ -193,7 +190,7 @@ var nodesToTest = []struct { }, { &expr.MethodCall{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Variable: &expr.Variable{}, Method: &node.Identifier{Value: "foo"}, ArgumentList: &node.ArgumentList{}, }, @@ -210,42 +207,42 @@ var nodesToTest = []struct { }, { &expr.PostDec{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Variable: &expr.Variable{}, }, []string{"Variable"}, map[string]interface{}{}, }, { &expr.PostInc{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Variable: &expr.Variable{}, }, []string{"Variable"}, map[string]interface{}{}, }, { &expr.PreDec{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Variable: &expr.Variable{}, }, []string{"Variable"}, map[string]interface{}{}, }, { &expr.PreInc{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Variable: &expr.Variable{}, }, []string{"Variable"}, map[string]interface{}{}, }, { &expr.Print{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, }, { &expr.PropertyFetch{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Variable: &expr.Variable{}, Property: &node.Identifier{Value: "foo"}, }, []string{"Variable", "Property"}, @@ -253,21 +250,21 @@ var nodesToTest = []struct { }, { &expr.Reference{ - Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Variable: &expr.Variable{}, }, []string{"Variable"}, map[string]interface{}{}, }, { &expr.RequireOnce{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, }, { &expr.Require{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, @@ -318,23 +315,23 @@ var nodesToTest = []struct { }, { &expr.Ternary{ - Condition: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - IfTrue: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, - IfFalse: &expr.Variable{VarName: &node.Identifier{Value: "c"}}, + Condition: &expr.Variable{}, + IfTrue: &expr.Variable{}, + IfFalse: &expr.Variable{}, }, []string{"Condition", "IfTrue", "IfFalse"}, map[string]interface{}{}, }, { &expr.UnaryMinus{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, }, { &expr.UnaryPlus{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, @@ -346,15 +343,15 @@ var nodesToTest = []struct { }, { &expr.YieldFrom{ - Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, + Expr: &expr.Variable{}, }, []string{"Expr"}, map[string]interface{}{}, }, { &expr.Yield{ - Key: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, - Value: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, + Key: &expr.Variable{}, + Value: &expr.Variable{}, }, []string{"Key", "Value"}, map[string]interface{}{}, @@ -367,11 +364,15 @@ type visitorMock struct { } 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) - 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) { for _, tt := range nodesToTest { diff --git a/node/n_argument.go b/node/n_argument.go index 564532d..4b4d178 100644 --- a/node/n_argument.go +++ b/node/n_argument.go @@ -34,8 +34,9 @@ func (n *Argument) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/n_argument_list.go b/node/n_argument_list.go index 843030f..59857f4 100644 --- a/node/n_argument_list.go +++ b/node/n_argument_list.go @@ -29,12 +29,13 @@ func (n *ArgumentList) Walk(v walker.Visitor) { } if n.Arguments != nil { - vv := v.GetChildrenVisitor("Arguments") + v.EnterChildList("Arguments", n) for _, nn := range n.Arguments { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Arguments", n) } v.LeaveNode(n) diff --git a/node/n_nullable.go b/node/n_nullable.go index 1eca09e..f78a860 100644 --- a/node/n_nullable.go +++ b/node/n_nullable.go @@ -27,8 +27,9 @@ func (n *Nullable) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/n_parameter.go b/node/n_parameter.go index 0986874..9f5a08e 100644 --- a/node/n_parameter.go +++ b/node/n_parameter.go @@ -38,18 +38,21 @@ func (n *Parameter) Walk(v walker.Visitor) { } if n.VariableType != nil { - vv := v.GetChildrenVisitor("VariableType") - n.VariableType.Walk(vv) + v.EnterChildNode("VariableType", n) + n.VariableType.Walk(v) + v.LeaveChildNode("VariableType", n) } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.DefaultValue != nil { - vv := v.GetChildrenVisitor("DefaultValue") - n.DefaultValue.Walk(vv) + v.EnterChildNode("DefaultValue", n) + n.DefaultValue.Walk(v) + v.LeaveChildNode("DefaultValue", n) } v.LeaveNode(n) diff --git a/node/n_root.go b/node/n_root.go index 67db6dc..097c97e 100644 --- a/node/n_root.go +++ b/node/n_root.go @@ -29,12 +29,13 @@ func (n *Root) Walk(v walker.Visitor) { } if n.Stmts != nil { - vv := v.GetChildrenVisitor("Stmts") + v.EnterChildList("Stmts", n) for _, nn := range n.Stmts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Stmts", n) } v.LeaveNode(n) diff --git a/node/name/n_fully_qualified.go b/node/name/n_fully_qualified.go index 5e55b9a..bc868db 100644 --- a/node/name/n_fully_qualified.go +++ b/node/name/n_fully_qualified.go @@ -30,12 +30,13 @@ func (n *FullyQualified) Walk(v walker.Visitor) { } if n.Parts != nil { - vv := v.GetChildrenVisitor("Parts") + v.EnterChildList("Parts", n) for _, nn := range n.Parts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Parts", n) } v.LeaveNode(n) diff --git a/node/name/n_name.go b/node/name/n_name.go index e0edebe..db2fe8c 100644 --- a/node/name/n_name.go +++ b/node/name/n_name.go @@ -30,12 +30,13 @@ func (n *Name) Walk(v walker.Visitor) { } if n.Parts != nil { - vv := v.GetChildrenVisitor("Parts") + v.EnterChildList("Parts", n) for _, nn := range n.Parts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Parts", n) } v.LeaveNode(n) diff --git a/node/name/n_relative.go b/node/name/n_relative.go index b367831..2e7df34 100644 --- a/node/name/n_relative.go +++ b/node/name/n_relative.go @@ -30,12 +30,13 @@ func (n *Relative) Walk(v walker.Visitor) { } if n.Parts != nil { - vv := v.GetChildrenVisitor("Parts") + v.EnterChildList("Parts", n) for _, nn := range n.Parts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Parts", n) } v.LeaveNode(n) diff --git a/node/name/t_visitor_test.go b/node/name/t_visitor_test.go index 38a7a64..dad1d33 100644 --- a/node/name/t_visitor_test.go +++ b/node/name/t_visitor_test.go @@ -44,11 +44,15 @@ type visitorMock struct { } 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) - 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 TestNameVisitorDisableChildren(t *testing.T) { for _, tt := range nameNodesTests { diff --git a/node/scalar/node_encapsed.go b/node/scalar/node_encapsed.go index e6dceda..3ce0c2f 100644 --- a/node/scalar/node_encapsed.go +++ b/node/scalar/node_encapsed.go @@ -30,11 +30,12 @@ func (n *Encapsed) Walk(v walker.Visitor) { } if n.Parts != nil { - vv := v.GetChildrenVisitor("Parts") + v.EnterChildList("Parts", n) for _, nn := range n.Parts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Parts", n) } } diff --git a/node/scalar/node_heredoc.go b/node/scalar/node_heredoc.go index 1395134..c2f9e74 100644 --- a/node/scalar/node_heredoc.go +++ b/node/scalar/node_heredoc.go @@ -34,11 +34,12 @@ func (n *Heredoc) Walk(v walker.Visitor) { } if n.Parts != nil { - vv := v.GetChildrenVisitor("Parts") + v.EnterChildList("Parts", n) for _, nn := range n.Parts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Parts", n) } } diff --git a/node/scalar/t_visitor_test.go b/node/scalar/t_visitor_test.go index bea1192..f3bc581 100644 --- a/node/scalar/t_visitor_test.go +++ b/node/scalar/t_visitor_test.go @@ -58,11 +58,15 @@ type visitorMock struct { } 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) - 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 TestNameVisitorDisableChildren(t *testing.T) { for _, tt := range nameNodesTests { diff --git a/node/stmt/n_alt_else.go b/node/stmt/n_alt_else.go index 0c5f5cb..3dec33d 100644 --- a/node/stmt/n_alt_else.go +++ b/node/stmt/n_alt_else.go @@ -30,8 +30,9 @@ func (n *AltElse) Walk(v walker.Visitor) { } if n.Stmt != nil { - vv := v.GetChildrenVisitor("Stmt") - n.Stmt.Walk(vv) + v.EnterChildNode("Stmt", n) + n.Stmt.Walk(v) + v.LeaveChildNode("Stmt", n) } v.LeaveNode(n) diff --git a/node/stmt/n_alt_else_if.go b/node/stmt/n_alt_else_if.go index 813667d..feae465 100644 --- a/node/stmt/n_alt_else_if.go +++ b/node/stmt/n_alt_else_if.go @@ -32,13 +32,15 @@ func (n *AltElseIf) Walk(v walker.Visitor) { } if n.Cond != nil { - vv := v.GetChildrenVisitor("Cond") - n.Cond.Walk(vv) + v.EnterChildNode("Cond", n) + n.Cond.Walk(v) + v.LeaveChildNode("Cond", n) } if n.Stmt != nil { - vv := v.GetChildrenVisitor("Stmt") - n.Stmt.Walk(vv) + v.EnterChildNode("Stmt", n) + n.Stmt.Walk(v) + v.LeaveChildNode("Stmt", n) } v.LeaveNode(n) diff --git a/node/stmt/n_alt_for.go b/node/stmt/n_alt_for.go index 8be4591..a80765a 100644 --- a/node/stmt/n_alt_for.go +++ b/node/stmt/n_alt_for.go @@ -36,35 +36,39 @@ func (n *AltFor) Walk(v walker.Visitor) { } if n.Init != nil { - vv := v.GetChildrenVisitor("Init") + v.EnterChildList("Init", n) for _, nn := range n.Init { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Init", n) } if n.Cond != nil { - vv := v.GetChildrenVisitor("Cond") + v.EnterChildList("Cond", n) for _, nn := range n.Cond { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Cond", n) } if n.Loop != nil { - vv := v.GetChildrenVisitor("Loop") + v.EnterChildList("Loop", n) for _, nn := range n.Loop { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Loop", n) } if n.Stmt != nil { - vv := v.GetChildrenVisitor("Stmt") - n.Stmt.Walk(vv) + v.EnterChildNode("Stmt", n) + n.Stmt.Walk(v) + v.LeaveChildNode("Stmt", n) } v.LeaveNode(n) diff --git a/node/stmt/n_alt_foreach.go b/node/stmt/n_alt_foreach.go index deaa4c4..4488a45 100644 --- a/node/stmt/n_alt_foreach.go +++ b/node/stmt/n_alt_foreach.go @@ -36,23 +36,27 @@ func (n *AltForeach) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } if n.Key != nil { - vv := v.GetChildrenVisitor("Key") - n.Key.Walk(vv) + v.EnterChildNode("Key", n) + n.Key.Walk(v) + v.LeaveChildNode("Key", n) } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Stmt != nil { - vv := v.GetChildrenVisitor("Stmt") - n.Stmt.Walk(vv) + v.EnterChildNode("Stmt", n) + n.Stmt.Walk(v) + v.LeaveChildNode("Stmt", n) } v.LeaveNode(n) diff --git a/node/stmt/n_alt_if.go b/node/stmt/n_alt_if.go index eafacf0..b844dfc 100644 --- a/node/stmt/n_alt_if.go +++ b/node/stmt/n_alt_if.go @@ -54,27 +54,31 @@ func (n *AltIf) Walk(v walker.Visitor) { } if n.Cond != nil { - vv := v.GetChildrenVisitor("Cond") - n.Cond.Walk(vv) + v.EnterChildNode("Cond", n) + n.Cond.Walk(v) + v.LeaveChildNode("Cond", n) } if n.Stmt != nil { - vv := v.GetChildrenVisitor("Stmt") - n.Stmt.Walk(vv) + v.EnterChildNode("Stmt", n) + n.Stmt.Walk(v) + v.LeaveChildNode("Stmt", n) } if n.ElseIf != nil { - vv := v.GetChildrenVisitor("ElseIf") + v.EnterChildList("ElseIf", n) for _, nn := range n.ElseIf { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("ElseIf", n) } if n.Else != nil { - vv := v.GetChildrenVisitor("Else") - n.Else.Walk(vv) + v.EnterChildNode("Else", n) + n.Else.Walk(v) + v.LeaveChildNode("Else", n) } v.LeaveNode(n) diff --git a/node/stmt/n_alt_switch.go b/node/stmt/n_alt_switch.go index ef28404..d036c34 100644 --- a/node/stmt/n_alt_switch.go +++ b/node/stmt/n_alt_switch.go @@ -32,13 +32,15 @@ func (n *AltSwitch) Walk(v walker.Visitor) { } if n.Cond != nil { - vv := v.GetChildrenVisitor("Cond") - n.Cond.Walk(vv) + v.EnterChildNode("Cond", n) + n.Cond.Walk(v) + v.LeaveChildNode("Cond", n) } if n.CaseList != nil { - vv := v.GetChildrenVisitor("CaseList") - n.CaseList.Walk(vv) + v.EnterChildNode("CaseList", n) + n.CaseList.Walk(v) + v.LeaveChildNode("CaseList", n) } v.LeaveNode(n) diff --git a/node/stmt/n_alt_while.go b/node/stmt/n_alt_while.go index 2cacf79..b962807 100644 --- a/node/stmt/n_alt_while.go +++ b/node/stmt/n_alt_while.go @@ -32,13 +32,15 @@ func (n *AltWhile) Walk(v walker.Visitor) { } if n.Cond != nil { - vv := v.GetChildrenVisitor("Cond") - n.Cond.Walk(vv) + v.EnterChildNode("Cond", n) + n.Cond.Walk(v) + v.LeaveChildNode("Cond", n) } if n.Stmt != nil { - vv := v.GetChildrenVisitor("Stmt") - n.Stmt.Walk(vv) + v.EnterChildNode("Stmt", n) + n.Stmt.Walk(v) + v.LeaveChildNode("Stmt", n) } v.LeaveNode(n) diff --git a/node/stmt/n_break.go b/node/stmt/n_break.go index 3aaabc4..acf4fd2 100644 --- a/node/stmt/n_break.go +++ b/node/stmt/n_break.go @@ -30,8 +30,9 @@ func (n *Break) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/stmt/n_case.go b/node/stmt/n_case.go index 6eb4b40..6a8d736 100644 --- a/node/stmt/n_case.go +++ b/node/stmt/n_case.go @@ -32,17 +32,19 @@ func (n *Case) Walk(v walker.Visitor) { } if n.Cond != nil { - vv := v.GetChildrenVisitor("Cond") - n.Cond.Walk(vv) + v.EnterChildNode("Cond", n) + n.Cond.Walk(v) + v.LeaveChildNode("Cond", n) } if n.Stmts != nil { - vv := v.GetChildrenVisitor("Stmts") + v.EnterChildList("Stmts", n) for _, nn := range n.Stmts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Stmts", n) } v.LeaveNode(n) diff --git a/node/stmt/n_case_list.go b/node/stmt/n_case_list.go index ac43d6a..a12ef2a 100644 --- a/node/stmt/n_case_list.go +++ b/node/stmt/n_case_list.go @@ -30,12 +30,13 @@ func (n *CaseList) Walk(v walker.Visitor) { } if n.Cases != nil { - vv := v.GetChildrenVisitor("Cases") + v.EnterChildList("Cases", n) for _, nn := range n.Cases { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Cases", n) } v.LeaveNode(n) diff --git a/node/stmt/n_catch.go b/node/stmt/n_catch.go index 9d59efe..291f764 100644 --- a/node/stmt/n_catch.go +++ b/node/stmt/n_catch.go @@ -34,26 +34,29 @@ func (n *Catch) Walk(v walker.Visitor) { } if n.Types != nil { - vv := v.GetChildrenVisitor("Types") + v.EnterChildList("Types", n) for _, nn := range n.Types { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Types", n) } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Stmts != nil { - vv := v.GetChildrenVisitor("Stmts") + v.EnterChildList("Stmts", n) for _, nn := range n.Stmts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Stmts", n) } v.LeaveNode(n) diff --git a/node/stmt/n_class.go b/node/stmt/n_class.go index 305490d..2ad81d2 100644 --- a/node/stmt/n_class.go +++ b/node/stmt/n_class.go @@ -44,41 +44,47 @@ func (n *Class) Walk(v walker.Visitor) { } if n.ClassName != nil { - vv := v.GetChildrenVisitor("ClassName") - n.ClassName.Walk(vv) + v.EnterChildNode("ClassName", n) + n.ClassName.Walk(v) + v.LeaveChildNode("ClassName", n) } if n.Modifiers != nil { - vv := v.GetChildrenVisitor("Modifiers") + v.EnterChildList("Modifiers", n) for _, nn := range n.Modifiers { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Modifiers", n) } if n.ArgumentList != nil { - vv := v.GetChildrenVisitor("ArgumentList") - n.ArgumentList.Walk(vv) + v.EnterChildNode("ArgumentList", n) + n.ArgumentList.Walk(v) + v.LeaveChildNode("ArgumentList", n) } if n.Extends != nil { - vv := v.GetChildrenVisitor("Extends") - n.Extends.Walk(vv) + v.EnterChildNode("Extends", n) + n.Extends.Walk(v) + v.LeaveChildNode("Extends", n) } if n.Implements != nil { - vv := v.GetChildrenVisitor("Implements") - n.Implements.Walk(vv) + v.EnterChildNode("Implements", n) + n.Implements.Walk(v) + v.LeaveChildNode("Implements", n) } if n.Stmts != nil { - vv := v.GetChildrenVisitor("Stmts") + v.EnterChildList("Stmts", n) for _, nn := range n.Stmts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Stmts", n) } v.LeaveNode(n) diff --git a/node/stmt/n_class_const_list.go b/node/stmt/n_class_const_list.go index e7c76fc..b65c4e4 100644 --- a/node/stmt/n_class_const_list.go +++ b/node/stmt/n_class_const_list.go @@ -32,21 +32,23 @@ func (n *ClassConstList) Walk(v walker.Visitor) { } if n.Modifiers != nil { - vv := v.GetChildrenVisitor("Modifiers") + v.EnterChildList("Modifiers", n) for _, nn := range n.Modifiers { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Modifiers", n) } if n.Consts != nil { - vv := v.GetChildrenVisitor("Consts") + v.EnterChildList("Consts", n) for _, nn := range n.Consts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Consts", n) } v.LeaveNode(n) diff --git a/node/stmt/n_class_extends.go b/node/stmt/n_class_extends.go index 2d7efcc..70864b3 100644 --- a/node/stmt/n_class_extends.go +++ b/node/stmt/n_class_extends.go @@ -30,8 +30,9 @@ func (n *ClassExtends) Walk(v walker.Visitor) { } if n.ClassName != nil { - vv := v.GetChildrenVisitor("ClassName") - n.ClassName.Walk(vv) + v.EnterChildNode("ClassName", n) + n.ClassName.Walk(v) + v.LeaveChildNode("ClassName", n) } v.LeaveNode(n) diff --git a/node/stmt/n_class_implements.go b/node/stmt/n_class_implements.go index 00a37a1..0ac8688 100644 --- a/node/stmt/n_class_implements.go +++ b/node/stmt/n_class_implements.go @@ -30,12 +30,13 @@ func (n *ClassImplements) Walk(v walker.Visitor) { } if n.InterfaceNames != nil { - vv := v.GetChildrenVisitor("InterfaceNames") + v.EnterChildList("InterfaceNames", n) for _, nn := range n.InterfaceNames { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("InterfaceNames", n) } v.LeaveNode(n) diff --git a/node/stmt/n_class_method.go b/node/stmt/n_class_method.go index ec7d9ee..ad09e34 100644 --- a/node/stmt/n_class_method.go +++ b/node/stmt/n_class_method.go @@ -45,36 +45,41 @@ func (n *ClassMethod) Walk(v walker.Visitor) { } if n.MethodName != nil { - vv := v.GetChildrenVisitor("MethodName") - n.MethodName.Walk(vv) + v.EnterChildNode("MethodName", n) + n.MethodName.Walk(v) + v.LeaveChildNode("MethodName", n) } if n.Modifiers != nil { - vv := v.GetChildrenVisitor("Modifiers") + v.EnterChildList("Modifiers", n) for _, nn := range n.Modifiers { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Modifiers", n) } if n.Params != nil { - vv := v.GetChildrenVisitor("Params") + v.EnterChildList("Params", n) for _, nn := range n.Params { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Params", n) } if n.ReturnType != nil { - vv := v.GetChildrenVisitor("ReturnType") - n.ReturnType.Walk(vv) + v.EnterChildNode("ReturnType", n) + n.ReturnType.Walk(v) + v.LeaveChildNode("ReturnType", n) } if n.Stmt != nil { - vv := v.GetChildrenVisitor("Stmt") - n.Stmt.Walk(vv) + v.EnterChildNode("Stmt", n) + n.Stmt.Walk(v) + v.LeaveChildNode("Stmt", n) } v.LeaveNode(n) diff --git a/node/stmt/n_const_list.go b/node/stmt/n_const_list.go index 8490ec5..46c702f 100644 --- a/node/stmt/n_const_list.go +++ b/node/stmt/n_const_list.go @@ -30,12 +30,13 @@ func (n *ConstList) Walk(v walker.Visitor) { } if n.Consts != nil { - vv := v.GetChildrenVisitor("Consts") + v.EnterChildList("Consts", n) for _, nn := range n.Consts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Consts", n) } v.LeaveNode(n) diff --git a/node/stmt/n_constant.go b/node/stmt/n_constant.go index 4cc651c..3a98e43 100644 --- a/node/stmt/n_constant.go +++ b/node/stmt/n_constant.go @@ -36,13 +36,15 @@ func (n *Constant) Walk(v walker.Visitor) { } if n.ConstantName != nil { - vv := v.GetChildrenVisitor("ConstantName") - n.ConstantName.Walk(vv) + v.EnterChildNode("ConstantName", n) + n.ConstantName.Walk(v) + v.LeaveChildNode("ConstantName", n) } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/stmt/n_continue.go b/node/stmt/n_continue.go index afa8780..c14ee25 100644 --- a/node/stmt/n_continue.go +++ b/node/stmt/n_continue.go @@ -30,8 +30,9 @@ func (n *Continue) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/stmt/n_declare.go b/node/stmt/n_declare.go index f2e251d..057f6d2 100644 --- a/node/stmt/n_declare.go +++ b/node/stmt/n_declare.go @@ -32,17 +32,19 @@ func (n *Declare) Walk(v walker.Visitor) { } if n.Consts != nil { - vv := v.GetChildrenVisitor("Consts") + v.EnterChildList("Consts", n) for _, nn := range n.Consts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Consts", n) } if n.Stmt != nil { - vv := v.GetChildrenVisitor("Stmt") - n.Stmt.Walk(vv) + v.EnterChildNode("Stmt", n) + n.Stmt.Walk(v) + v.LeaveChildNode("Stmt", n) } v.LeaveNode(n) diff --git a/node/stmt/n_default.go b/node/stmt/n_default.go index 961d3d1..7203f30 100644 --- a/node/stmt/n_default.go +++ b/node/stmt/n_default.go @@ -30,12 +30,13 @@ func (n *Default) Walk(v walker.Visitor) { } if n.Stmts != nil { - vv := v.GetChildrenVisitor("Stmts") + v.EnterChildList("Stmts", n) for _, nn := range n.Stmts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Stmts", n) } v.LeaveNode(n) diff --git a/node/stmt/n_do.go b/node/stmt/n_do.go index c8da1b0..324d60b 100644 --- a/node/stmt/n_do.go +++ b/node/stmt/n_do.go @@ -32,13 +32,15 @@ func (n *Do) Walk(v walker.Visitor) { } if n.Stmt != nil { - vv := v.GetChildrenVisitor("Stmt") - n.Stmt.Walk(vv) + v.EnterChildNode("Stmt", n) + n.Stmt.Walk(v) + v.LeaveChildNode("Stmt", n) } if n.Cond != nil { - vv := v.GetChildrenVisitor("Cond") - n.Cond.Walk(vv) + v.EnterChildNode("Cond", n) + n.Cond.Walk(v) + v.LeaveChildNode("Cond", n) } v.LeaveNode(n) diff --git a/node/stmt/n_echo.go b/node/stmt/n_echo.go index 9deb7d9..df932f1 100644 --- a/node/stmt/n_echo.go +++ b/node/stmt/n_echo.go @@ -30,12 +30,13 @@ func (n *Echo) Walk(v walker.Visitor) { } if n.Exprs != nil { - vv := v.GetChildrenVisitor("Exprs") + v.EnterChildList("Exprs", n) for _, nn := range n.Exprs { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Exprs", n) } v.LeaveNode(n) diff --git a/node/stmt/n_else.go b/node/stmt/n_else.go index 15ad017..78ce8e8 100644 --- a/node/stmt/n_else.go +++ b/node/stmt/n_else.go @@ -30,8 +30,9 @@ func (n *Else) Walk(v walker.Visitor) { } if n.Stmt != nil { - vv := v.GetChildrenVisitor("Stmt") - n.Stmt.Walk(vv) + v.EnterChildNode("Stmt", n) + n.Stmt.Walk(v) + v.LeaveChildNode("Stmt", n) } v.LeaveNode(n) diff --git a/node/stmt/n_else_if.go b/node/stmt/n_else_if.go index 98db7f7..cf02f34 100644 --- a/node/stmt/n_else_if.go +++ b/node/stmt/n_else_if.go @@ -32,13 +32,15 @@ func (n *ElseIf) Walk(v walker.Visitor) { } if n.Cond != nil { - vv := v.GetChildrenVisitor("Cond") - n.Cond.Walk(vv) + v.EnterChildNode("Cond", n) + n.Cond.Walk(v) + v.LeaveChildNode("Cond", n) } if n.Stmt != nil { - vv := v.GetChildrenVisitor("Stmt") - n.Stmt.Walk(vv) + v.EnterChildNode("Stmt", n) + n.Stmt.Walk(v) + v.LeaveChildNode("Stmt", n) } v.LeaveNode(n) diff --git a/node/stmt/n_expression.go b/node/stmt/n_expression.go index 77dfe64..bc9374e 100644 --- a/node/stmt/n_expression.go +++ b/node/stmt/n_expression.go @@ -30,8 +30,9 @@ func (n *Expression) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/stmt/n_finally.go b/node/stmt/n_finally.go index 9436140..944ff23 100644 --- a/node/stmt/n_finally.go +++ b/node/stmt/n_finally.go @@ -30,12 +30,13 @@ func (n *Finally) Walk(v walker.Visitor) { } if n.Stmts != nil { - vv := v.GetChildrenVisitor("Stmts") + v.EnterChildList("Stmts", n) for _, nn := range n.Stmts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Stmts", n) } v.LeaveNode(n) diff --git a/node/stmt/n_for.go b/node/stmt/n_for.go index f8d3c91..6af170b 100644 --- a/node/stmt/n_for.go +++ b/node/stmt/n_for.go @@ -36,35 +36,39 @@ func (n *For) Walk(v walker.Visitor) { } if n.Init != nil { - vv := v.GetChildrenVisitor("Init") + v.EnterChildList("Init", n) for _, nn := range n.Init { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Init", n) } if n.Cond != nil { - vv := v.GetChildrenVisitor("Cond") + v.EnterChildList("Cond", n) for _, nn := range n.Cond { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Cond", n) } if n.Loop != nil { - vv := v.GetChildrenVisitor("Loop") + v.EnterChildList("Loop", n) for _, nn := range n.Loop { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Loop", n) } if n.Stmt != nil { - vv := v.GetChildrenVisitor("Stmt") - n.Stmt.Walk(vv) + v.EnterChildNode("Stmt", n) + n.Stmt.Walk(v) + v.LeaveChildNode("Stmt", n) } v.LeaveNode(n) diff --git a/node/stmt/n_foreach.go b/node/stmt/n_foreach.go index b82d2f5..68644df 100644 --- a/node/stmt/n_foreach.go +++ b/node/stmt/n_foreach.go @@ -36,23 +36,27 @@ func (n *Foreach) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } if n.Key != nil { - vv := v.GetChildrenVisitor("Key") - n.Key.Walk(vv) + v.EnterChildNode("Key", n) + n.Key.Walk(v) + v.LeaveChildNode("Key", n) } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Stmt != nil { - vv := v.GetChildrenVisitor("Stmt") - n.Stmt.Walk(vv) + v.EnterChildNode("Stmt", n) + n.Stmt.Walk(v) + v.LeaveChildNode("Stmt", n) } v.LeaveNode(n) diff --git a/node/stmt/n_function.go b/node/stmt/n_function.go index 762c710..effc13c 100644 --- a/node/stmt/n_function.go +++ b/node/stmt/n_function.go @@ -44,31 +44,35 @@ func (n *Function) Walk(v walker.Visitor) { } if n.FunctionName != nil { - vv := v.GetChildrenVisitor("FunctionName") - n.FunctionName.Walk(vv) + v.EnterChildNode("FunctionName", n) + n.FunctionName.Walk(v) + v.LeaveChildNode("FunctionName", n) } if n.Params != nil { - vv := v.GetChildrenVisitor("Params") + v.EnterChildList("Params", n) for _, nn := range n.Params { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Params", n) } if n.ReturnType != nil { - vv := v.GetChildrenVisitor("ReturnType") - n.ReturnType.Walk(vv) + v.EnterChildNode("ReturnType", n) + n.ReturnType.Walk(v) + v.LeaveChildNode("ReturnType", n) } if n.Stmts != nil { - vv := v.GetChildrenVisitor("Stmts") + v.EnterChildList("Stmts", n) for _, nn := range n.Stmts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Stmts", n) } v.LeaveNode(n) diff --git a/node/stmt/n_global.go b/node/stmt/n_global.go index b13861a..65621f9 100644 --- a/node/stmt/n_global.go +++ b/node/stmt/n_global.go @@ -30,12 +30,13 @@ func (n *Global) Walk(v walker.Visitor) { } if n.Vars != nil { - vv := v.GetChildrenVisitor("Vars") + v.EnterChildList("Vars", n) for _, nn := range n.Vars { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Vars", n) } v.LeaveNode(n) diff --git a/node/stmt/n_goto.go b/node/stmt/n_goto.go index 682699e..0815d65 100644 --- a/node/stmt/n_goto.go +++ b/node/stmt/n_goto.go @@ -30,8 +30,9 @@ func (n *Goto) Walk(v walker.Visitor) { } if n.Label != nil { - vv := v.GetChildrenVisitor("Label") - n.Label.Walk(vv) + v.EnterChildNode("Label", n) + n.Label.Walk(v) + v.LeaveChildNode("Label", n) } v.LeaveNode(n) diff --git a/node/stmt/n_group_use.go b/node/stmt/n_group_use.go index d62c1cd..3057fbc 100644 --- a/node/stmt/n_group_use.go +++ b/node/stmt/n_group_use.go @@ -40,22 +40,25 @@ func (n *GroupUse) Walk(v walker.Visitor) { } if n.UseType != nil { - vv := v.GetChildrenVisitor("UseType") - n.UseType.Walk(vv) + v.EnterChildNode("UseType", n) + n.UseType.Walk(v) + v.LeaveChildNode("UseType", n) } if n.Prefix != nil { - vv := v.GetChildrenVisitor("Prefix") - n.Prefix.Walk(vv) + v.EnterChildNode("Prefix", n) + n.Prefix.Walk(v) + v.LeaveChildNode("Prefix", n) } if n.UseList != nil { - vv := v.GetChildrenVisitor("UseList") + v.EnterChildList("UseList", n) for _, nn := range n.UseList { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("UseList", n) } v.LeaveNode(n) diff --git a/node/stmt/n_if.go b/node/stmt/n_if.go index b31af45..e20c0f3 100644 --- a/node/stmt/n_if.go +++ b/node/stmt/n_if.go @@ -54,27 +54,31 @@ func (n *If) Walk(v walker.Visitor) { } if n.Cond != nil { - vv := v.GetChildrenVisitor("Cond") - n.Cond.Walk(vv) + v.EnterChildNode("Cond", n) + n.Cond.Walk(v) + v.LeaveChildNode("Cond", n) } if n.Stmt != nil { - vv := v.GetChildrenVisitor("Stmt") - n.Stmt.Walk(vv) + v.EnterChildNode("Stmt", n) + n.Stmt.Walk(v) + v.LeaveChildNode("Stmt", n) } if n.ElseIf != nil { - vv := v.GetChildrenVisitor("ElseIf") + v.EnterChildList("ElseIf", n) for _, nn := range n.ElseIf { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("ElseIf", n) } if n.Else != nil { - vv := v.GetChildrenVisitor("Else") - n.Else.Walk(vv) + v.EnterChildNode("Else", n) + n.Else.Walk(v) + v.LeaveChildNode("Else", n) } v.LeaveNode(n) diff --git a/node/stmt/n_interface.go b/node/stmt/n_interface.go index 46524c6..13e296c 100644 --- a/node/stmt/n_interface.go +++ b/node/stmt/n_interface.go @@ -38,22 +38,25 @@ func (n *Interface) Walk(v walker.Visitor) { } if n.InterfaceName != nil { - vv := v.GetChildrenVisitor("InterfaceName") - n.InterfaceName.Walk(vv) + v.EnterChildNode("InterfaceName", n) + n.InterfaceName.Walk(v) + v.LeaveChildNode("InterfaceName", n) } if n.Extends != nil { - vv := v.GetChildrenVisitor("Extends") - n.Extends.Walk(vv) + v.EnterChildNode("Extends", n) + n.Extends.Walk(v) + v.LeaveChildNode("Extends", n) } if n.Stmts != nil { - vv := v.GetChildrenVisitor("Stmts") + v.EnterChildList("Stmts", n) for _, nn := range n.Stmts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Stmts", n) } v.LeaveNode(n) diff --git a/node/stmt/n_interface_extends.go b/node/stmt/n_interface_extends.go index 2b1c61a..eea76b2 100644 --- a/node/stmt/n_interface_extends.go +++ b/node/stmt/n_interface_extends.go @@ -30,12 +30,13 @@ func (n *InterfaceExtends) Walk(v walker.Visitor) { } if n.InterfaceNames != nil { - vv := v.GetChildrenVisitor("InterfaceNames") + v.EnterChildList("InterfaceNames", n) for _, nn := range n.InterfaceNames { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("InterfaceNames", n) } v.LeaveNode(n) diff --git a/node/stmt/n_label.go b/node/stmt/n_label.go index ea681b3..bf77c0e 100644 --- a/node/stmt/n_label.go +++ b/node/stmt/n_label.go @@ -30,8 +30,9 @@ func (n *Label) Walk(v walker.Visitor) { } if n.LabelName != nil { - vv := v.GetChildrenVisitor("LabelName") - n.LabelName.Walk(vv) + v.EnterChildNode("LabelName", n) + n.LabelName.Walk(v) + v.LeaveChildNode("LabelName", n) } v.LeaveNode(n) diff --git a/node/stmt/n_namespace.go b/node/stmt/n_namespace.go index 02399f6..c9147fa 100644 --- a/node/stmt/n_namespace.go +++ b/node/stmt/n_namespace.go @@ -32,17 +32,19 @@ func (n *Namespace) Walk(v walker.Visitor) { } if n.NamespaceName != nil { - vv := v.GetChildrenVisitor("NamespaceName") - n.NamespaceName.Walk(vv) + v.EnterChildNode("NamespaceName", n) + n.NamespaceName.Walk(v) + v.LeaveChildNode("NamespaceName", n) } if n.Stmts != nil { - vv := v.GetChildrenVisitor("Stmts") + v.EnterChildList("Stmts", n) for _, nn := range n.Stmts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Stmts", n) } v.LeaveNode(n) diff --git a/node/stmt/n_property.go b/node/stmt/n_property.go index 71a017b..607231f 100644 --- a/node/stmt/n_property.go +++ b/node/stmt/n_property.go @@ -36,13 +36,15 @@ func (n *Property) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/stmt/n_property_list.go b/node/stmt/n_property_list.go index 7ebbcba..51a5813 100644 --- a/node/stmt/n_property_list.go +++ b/node/stmt/n_property_list.go @@ -32,21 +32,23 @@ func (n *PropertyList) Walk(v walker.Visitor) { } if n.Modifiers != nil { - vv := v.GetChildrenVisitor("Modifiers") + v.EnterChildList("Modifiers", n) for _, nn := range n.Modifiers { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Modifiers", n) } if n.Properties != nil { - vv := v.GetChildrenVisitor("Properties") + v.EnterChildList("Properties", n) for _, nn := range n.Properties { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Properties", n) } v.LeaveNode(n) diff --git a/node/stmt/n_return.go b/node/stmt/n_return.go index 8f1c77c..5dcec71 100644 --- a/node/stmt/n_return.go +++ b/node/stmt/n_return.go @@ -30,8 +30,9 @@ func (n *Return) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/stmt/n_static.go b/node/stmt/n_static.go index 292ca3c..1b0e365 100644 --- a/node/stmt/n_static.go +++ b/node/stmt/n_static.go @@ -30,12 +30,13 @@ func (n *Static) Walk(v walker.Visitor) { } if n.Vars != nil { - vv := v.GetChildrenVisitor("Vars") + v.EnterChildList("Vars", n) for _, nn := range n.Vars { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Vars", n) } v.LeaveNode(n) diff --git a/node/stmt/n_static_var.go b/node/stmt/n_static_var.go index 4ae5624..9f953ac 100644 --- a/node/stmt/n_static_var.go +++ b/node/stmt/n_static_var.go @@ -32,13 +32,15 @@ func (n *StaticVar) Walk(v walker.Visitor) { } if n.Variable != nil { - vv := v.GetChildrenVisitor("Variable") - n.Variable.Walk(vv) + v.EnterChildNode("Variable", n) + n.Variable.Walk(v) + v.LeaveChildNode("Variable", n) } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/stmt/n_stmt_list.go b/node/stmt/n_stmt_list.go index 58adedb..e3a6084 100644 --- a/node/stmt/n_stmt_list.go +++ b/node/stmt/n_stmt_list.go @@ -30,12 +30,13 @@ func (n *StmtList) Walk(v walker.Visitor) { } if n.Stmts != nil { - vv := v.GetChildrenVisitor("Stmts") + v.EnterChildList("Stmts", n) for _, nn := range n.Stmts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Stmts", n) } v.LeaveNode(n) diff --git a/node/stmt/n_switch.go b/node/stmt/n_switch.go index af9bd65..cd6f047 100644 --- a/node/stmt/n_switch.go +++ b/node/stmt/n_switch.go @@ -32,13 +32,15 @@ func (n *Switch) Walk(v walker.Visitor) { } if n.Cond != nil { - vv := v.GetChildrenVisitor("Cond") - n.Cond.Walk(vv) + v.EnterChildNode("Cond", n) + n.Cond.Walk(v) + v.LeaveChildNode("Cond", n) } if n.CaseList != nil { - vv := v.GetChildrenVisitor("CaseList") - n.CaseList.Walk(vv) + v.EnterChildNode("CaseList", n) + n.CaseList.Walk(v) + v.LeaveChildNode("CaseList", n) } v.LeaveNode(n) diff --git a/node/stmt/n_throw.go b/node/stmt/n_throw.go index 1be5f2f..8d8d466 100644 --- a/node/stmt/n_throw.go +++ b/node/stmt/n_throw.go @@ -30,8 +30,9 @@ func (n *Throw) Walk(v walker.Visitor) { } if n.Expr != nil { - vv := v.GetChildrenVisitor("Expr") - n.Expr.Walk(vv) + v.EnterChildNode("Expr", n) + n.Expr.Walk(v) + v.LeaveChildNode("Expr", n) } v.LeaveNode(n) diff --git a/node/stmt/n_trait.go b/node/stmt/n_trait.go index 65a98d4..7d72719 100644 --- a/node/stmt/n_trait.go +++ b/node/stmt/n_trait.go @@ -36,17 +36,19 @@ func (n *Trait) Walk(v walker.Visitor) { } if n.TraitName != nil { - vv := v.GetChildrenVisitor("TraitName") - n.TraitName.Walk(vv) + v.EnterChildNode("TraitName", n) + n.TraitName.Walk(v) + v.LeaveChildNode("TraitName", n) } if n.Stmts != nil { - vv := v.GetChildrenVisitor("Stmts") + v.EnterChildList("Stmts", n) for _, nn := range n.Stmts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Stmts", n) } v.LeaveNode(n) diff --git a/node/stmt/n_trait_adaptation_list.go b/node/stmt/n_trait_adaptation_list.go index d2a4b73..fd2f814 100644 --- a/node/stmt/n_trait_adaptation_list.go +++ b/node/stmt/n_trait_adaptation_list.go @@ -30,12 +30,13 @@ func (n *TraitAdaptationList) Walk(v walker.Visitor) { } if n.Adaptations != nil { - vv := v.GetChildrenVisitor("Adaptations") + v.EnterChildList("Adaptations", n) for _, nn := range n.Adaptations { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Adaptations", n) } v.LeaveNode(n) diff --git a/node/stmt/n_trait_method_ref.go b/node/stmt/n_trait_method_ref.go index f75c381..a1e2bac 100644 --- a/node/stmt/n_trait_method_ref.go +++ b/node/stmt/n_trait_method_ref.go @@ -32,13 +32,15 @@ func (n *TraitMethodRef) Walk(v walker.Visitor) { } if n.Trait != nil { - vv := v.GetChildrenVisitor("Trait") - n.Trait.Walk(vv) + v.EnterChildNode("Trait", n) + n.Trait.Walk(v) + v.LeaveChildNode("Trait", n) } if n.Method != nil { - vv := v.GetChildrenVisitor("Method") - n.Method.Walk(vv) + v.EnterChildNode("Method", n) + n.Method.Walk(v) + v.LeaveChildNode("Method", n) } v.LeaveNode(n) diff --git a/node/stmt/n_trait_use.go b/node/stmt/n_trait_use.go index d39dbec..ebe319e 100644 --- a/node/stmt/n_trait_use.go +++ b/node/stmt/n_trait_use.go @@ -32,17 +32,19 @@ func (n *TraitUse) Walk(v walker.Visitor) { } if n.Traits != nil { - vv := v.GetChildrenVisitor("Traits") + v.EnterChildList("Traits", n) for _, nn := range n.Traits { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Traits", n) } if n.TraitAdaptationList != nil { - vv := v.GetChildrenVisitor("TraitAdaptationList") - n.TraitAdaptationList.Walk(vv) + v.EnterChildNode("TraitAdaptationList", n) + n.TraitAdaptationList.Walk(v) + v.LeaveChildNode("TraitAdaptationList", n) } v.LeaveNode(n) diff --git a/node/stmt/n_trait_use_alias.go b/node/stmt/n_trait_use_alias.go index 38201fb..32cc32f 100644 --- a/node/stmt/n_trait_use_alias.go +++ b/node/stmt/n_trait_use_alias.go @@ -34,18 +34,21 @@ func (n *TraitUseAlias) Walk(v walker.Visitor) { } if n.Ref != nil { - vv := v.GetChildrenVisitor("Ref") - n.Ref.Walk(vv) + v.EnterChildNode("Ref", n) + n.Ref.Walk(v) + v.LeaveChildNode("Ref", n) } if n.Modifier != nil { - vv := v.GetChildrenVisitor("Modifier") - n.Modifier.Walk(vv) + v.EnterChildNode("Modifier", n) + n.Modifier.Walk(v) + v.LeaveChildNode("Modifier", n) } if n.Alias != nil { - vv := v.GetChildrenVisitor("Alias") - n.Alias.Walk(vv) + v.EnterChildNode("Alias", n) + n.Alias.Walk(v) + v.LeaveChildNode("Alias", n) } v.LeaveNode(n) diff --git a/node/stmt/n_trait_use_precedence.go b/node/stmt/n_trait_use_precedence.go index e85624b..1dd159b 100644 --- a/node/stmt/n_trait_use_precedence.go +++ b/node/stmt/n_trait_use_precedence.go @@ -32,17 +32,19 @@ func (n *TraitUsePrecedence) Walk(v walker.Visitor) { } if n.Ref != nil { - vv := v.GetChildrenVisitor("Ref") - n.Ref.Walk(vv) + v.EnterChildNode("Ref", n) + n.Ref.Walk(v) + v.LeaveChildNode("Ref", n) } if n.Insteadof != nil { - vv := v.GetChildrenVisitor("Insteadof") + v.EnterChildList("Insteadof", n) for _, nn := range n.Insteadof { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Insteadof", n) } v.LeaveNode(n) diff --git a/node/stmt/n_try.go b/node/stmt/n_try.go index 9bd94d8..d7f3a3f 100644 --- a/node/stmt/n_try.go +++ b/node/stmt/n_try.go @@ -34,26 +34,29 @@ func (n *Try) Walk(v walker.Visitor) { } if n.Stmts != nil { - vv := v.GetChildrenVisitor("Stmts") + v.EnterChildList("Stmts", n) for _, nn := range n.Stmts { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Stmts", n) } if n.Catches != nil { - vv := v.GetChildrenVisitor("Catches") + v.EnterChildList("Catches", n) for _, nn := range n.Catches { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Catches", n) } if n.Finally != nil { - vv := v.GetChildrenVisitor("Finally") - n.Finally.Walk(vv) + v.EnterChildNode("Finally", n) + n.Finally.Walk(v) + v.LeaveChildNode("Finally", n) } v.LeaveNode(n) diff --git a/node/stmt/n_unset.go b/node/stmt/n_unset.go index c66f7e7..43ef4ac 100644 --- a/node/stmt/n_unset.go +++ b/node/stmt/n_unset.go @@ -30,12 +30,13 @@ func (n *Unset) Walk(v walker.Visitor) { } if n.Vars != nil { - vv := v.GetChildrenVisitor("Vars") + v.EnterChildList("Vars", n) for _, nn := range n.Vars { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Vars", n) } v.LeaveNode(n) diff --git a/node/stmt/n_use.go b/node/stmt/n_use.go index 1bbabe1..9261877 100644 --- a/node/stmt/n_use.go +++ b/node/stmt/n_use.go @@ -40,18 +40,21 @@ func (n *Use) Walk(v walker.Visitor) { } if n.UseType != nil { - vv := v.GetChildrenVisitor("UseType") - n.UseType.Walk(vv) + v.EnterChildNode("UseType", n) + n.UseType.Walk(v) + v.LeaveChildNode("UseType", n) } if n.Use != nil { - vv := v.GetChildrenVisitor("Use") - n.Use.Walk(vv) + v.EnterChildNode("Use", n) + n.Use.Walk(v) + v.LeaveChildNode("Use", n) } if n.Alias != nil { - vv := v.GetChildrenVisitor("Alias") - n.Alias.Walk(vv) + v.EnterChildNode("Alias", n) + n.Alias.Walk(v) + v.LeaveChildNode("Alias", n) } v.LeaveNode(n) diff --git a/node/stmt/n_use_list.go b/node/stmt/n_use_list.go index 197773d..a95d038 100644 --- a/node/stmt/n_use_list.go +++ b/node/stmt/n_use_list.go @@ -32,17 +32,19 @@ func (n *UseList) Walk(v walker.Visitor) { } if n.UseType != nil { - vv := v.GetChildrenVisitor("UseType") - n.UseType.Walk(vv) + v.EnterChildNode("UseType", n) + n.UseType.Walk(v) + v.LeaveChildNode("UseType", n) } if n.Uses != nil { - vv := v.GetChildrenVisitor("Uses") + v.EnterChildList("Uses", n) for _, nn := range n.Uses { if nn != nil { - nn.Walk(vv) + nn.Walk(v) } } + v.LeaveChildList("Uses", n) } v.LeaveNode(n) diff --git a/node/stmt/n_while.go b/node/stmt/n_while.go index 3d737b5..d20e296 100644 --- a/node/stmt/n_while.go +++ b/node/stmt/n_while.go @@ -32,13 +32,15 @@ func (n *While) Walk(v walker.Visitor) { } if n.Cond != nil { - vv := v.GetChildrenVisitor("Cond") - n.Cond.Walk(vv) + v.EnterChildNode("Cond", n) + n.Cond.Walk(v) + v.LeaveChildNode("Cond", n) } if n.Stmt != nil { - vv := v.GetChildrenVisitor("Stmt") - n.Stmt.Walk(vv) + v.EnterChildNode("Stmt", n) + n.Stmt.Walk(v) + v.LeaveChildNode("Stmt", n) } v.LeaveNode(n) diff --git a/node/stmt/t_visitor_test.go b/node/stmt/t_visitor_test.go index 7527dab..c7ac8bc 100644 --- a/node/stmt/t_visitor_test.go +++ b/node/stmt/t_visitor_test.go @@ -369,7 +369,7 @@ var nodesToTest = []struct { { &stmt.AltSwitch{ Cond: &expr.Variable{}, - CaseList: &stmt.CaseList{Cases: []node.Node{}}, + CaseList: &stmt.CaseList{}, }, []string{"Cond", "CaseList"}, map[string]interface{}{}, @@ -526,11 +526,15 @@ type visitorMock struct { } 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) - 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) { for _, tt := range nodesToTest { diff --git a/node/t_visitor_test.go b/node/t_visitor_test.go index 15def8d..bf0b85e 100644 --- a/node/t_visitor_test.go +++ b/node/t_visitor_test.go @@ -26,12 +26,12 @@ var nodesToTest = []struct { map[string]interface{}{"Value": "foo"}, }, { - &node.Nullable{Expr: &expr.Variable{VarName: &node.Identifier{Value: "foo"}}}, + &node.Nullable{Expr: &expr.Variable{}}, []string{"Expr"}, nil, }, { - &node.Argument{Variadic: true, Expr: &expr.Variable{VarName: &node.Identifier{Value: "foo"}}}, + &node.Argument{Variadic: true, Expr: &expr.Variable{}}, []string{"Expr"}, map[string]interface{}{"IsReference": false, "Variadic": true}, }, @@ -40,7 +40,7 @@ var nodesToTest = []struct { ByRef: false, Variadic: true, VariableType: &node.Identifier{Value: "foo"}, - Variable: &expr.Variable{VarName: &node.Identifier{Value: "bar"}}, + Variable: &expr.Variable{}, DefaultValue: &scalar.Lnumber{Value: "0"}, }, []string{"VariableType", "Variable", "DefaultValue"}, @@ -70,11 +70,15 @@ type visitorMock struct { } 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) - 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 TestNameVisitorDisableChildren(t *testing.T) { for _, tt := range nodesToTest { diff --git a/visitor/dumper.go b/visitor/dumper.go index 0cf56e1..e69f3a1 100644 --- a/visitor/dumper.go +++ b/visitor/dumper.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "reflect" + "strings" "github.com/z7zmey/php-parser/comment" "github.com/z7zmey/php-parser/node" @@ -24,7 +25,7 @@ type Dumper struct { } // EnterNode is invoked at every node in hierarchy -func (d Dumper) EnterNode(w walker.Walkable) bool { +func (d *Dumper) EnterNode(w walker.Walkable) bool { n := w.(node.Node) fmt.Fprintf(d.Writer, "%v[%v]\n", d.Indent, reflect.TypeOf(n)) @@ -59,13 +60,26 @@ func (d Dumper) EnterNode(w walker.Walkable) bool { return true } -// GetChildrenVisitor is invoked at every node parameter that contains children nodes -func (d Dumper) GetChildrenVisitor(key string) walker.Visitor { - fmt.Fprintf(d.Writer, "%v%q:\n", d.Indent+" ", key) - return Dumper{d.Writer, d.Indent + " ", d.Comments, d.Positions, d.NsResolver} -} - // LeaveNode is invoked after node process -func (d Dumper) LeaveNode(n walker.Walkable) { +func (d *Dumper) LeaveNode(n walker.Walkable) { // do nothing } + +// GetChildrenVisitor is invoked at every node parameter that contains children nodes +func (d *Dumper) EnterChildNode(key string, w walker.Walkable) { + fmt.Fprintf(d.Writer, "%v%q:\n", d.Indent+" ", key) + d.Indent = d.Indent + " " +} + +func (d *Dumper) LeaveChildNode(key string, w walker.Walkable) { + d.Indent = strings.TrimSuffix(d.Indent, " ") +} + +func (d *Dumper) EnterChildList(key string, w walker.Walkable) { + fmt.Fprintf(d.Writer, "%v%q:\n", d.Indent+" ", key) + d.Indent = d.Indent + " " +} + +func (d *Dumper) LeaveChildList(key string, w walker.Walkable) { + d.Indent = strings.TrimSuffix(d.Indent, " ") +} diff --git a/visitor/dumper_test.go b/visitor/dumper_test.go index c0d3bed..8fedd3b 100644 --- a/visitor/dumper_test.go +++ b/visitor/dumper_test.go @@ -29,7 +29,7 @@ func ExampleDumper() { nsResolver := visitor.NewNamespaceResolver() nodes.Walk(nsResolver) - dumper := visitor.Dumper{ + dumper := &visitor.Dumper{ Writer: os.Stdout, Indent: "| ", Comments: php7parser.GetComments(), diff --git a/visitor/go_dumper.go b/visitor/go_dumper.go new file mode 100644 index 0000000..a857cb0 --- /dev/null +++ b/visitor/go_dumper.go @@ -0,0 +1,93 @@ +// Package visitor contains walker.visitor implementations +package visitor + +import ( + "fmt" + "io" + "reflect" + "strings" + + "github.com/z7zmey/php-parser/node" + + "github.com/z7zmey/php-parser/walker" +) + +// GoDumper writes ast hierarchy to an io.Writer as native Golang struct +type GoDumper struct { + Writer io.Writer + depth int + isChildNode bool +} + +func printIndent(w io.Writer, d int) { + for i := 0; i < d; i++ { + io.WriteString(w, "\t") + } +} + +// EnterNode is invoked at every node in hierarchy +func (d *GoDumper) EnterNode(w walker.Walkable) bool { + n := w.(node.Node) + + nodeType := reflect.TypeOf(n).String() + nodeType = strings.Replace(nodeType, "*", "&", 1) + + if d.isChildNode { + d.isChildNode = false + } else { + printIndent(d.Writer, d.depth) + } + + io.WriteString(d.Writer, nodeType+"{\n") + + d.depth++ + + if a := n.Attributes(); len(a) > 0 { + for key, attr := range a { + printIndent(d.Writer, d.depth) + switch attr.(type) { + case string: + fmt.Fprintf(d.Writer, "%s: %q,\n", key, attr) + default: + fmt.Fprintf(d.Writer, "%s: %v,\n", key, attr) + } + } + } + + return true +} + +// LeaveNode is invoked after node process +func (d *GoDumper) LeaveNode(n walker.Walkable) { + d.depth-- + printIndent(d.Writer, d.depth) + if d.depth != 0 { + io.WriteString(d.Writer, "},\n") + } else { + io.WriteString(d.Writer, "}\n") + } +} + +func (d *GoDumper) EnterChildNode(key string, w walker.Walkable) { + printIndent(d.Writer, d.depth) + io.WriteString(d.Writer, key+": ") + d.isChildNode = true +} + +func (d *GoDumper) LeaveChildNode(key string, w walker.Walkable) { + // do nothing +} + +func (d *GoDumper) EnterChildList(key string, w walker.Walkable) { + printIndent(d.Writer, d.depth) + io.WriteString(d.Writer, key+": []node.Node{\n") + d.depth++ +} + +func (d *GoDumper) LeaveChildList(key string, w walker.Walkable) { + d.depth-- + printIndent(d.Writer, d.depth) + if d.depth != 0 { + io.WriteString(d.Writer, "},\n") + } +} diff --git a/visitor/go_dumper_test.go b/visitor/go_dumper_test.go new file mode 100644 index 0000000..7d29252 --- /dev/null +++ b/visitor/go_dumper_test.go @@ -0,0 +1,111 @@ +//Package visitor contains walker.visitor implementations +package visitor_test + +import ( + "bytes" + "os" + + "github.com/z7zmey/php-parser/php7" + "github.com/z7zmey/php-parser/visitor" +) + +func ExampleGoDumper() { + src := `