diff libinterp/parse-tree/pt-anon-scopes.cc @ 27725:6388a240de87

move some common actions into tree_walker base class Instead of having most tree_walker class methods be pure virtual functions, define them to be methods that walk the tree but do nothing else. This change allows us to eliminate some duplication in derived classes, and makes it easier to define derived classes that need to walk the parse tree but onny perform actions for a few parse tree elements. * pt-walk.h, pt-walk.cc (class tree_walker): Define most methods to walk the tree. * cdef-class.cc (class ctor_analyzer): Delete methods in base class that are now handled by the base tree_walker class. * pt-anon-scopes.h, pt-anon-scopes.cc (class tree_anon_scopes): Likewise. * pt-bp.h, pt-bp.cc (tree_breakpoint): Likewise. * pt-check.h, pt-check.cc (tree_checker): Likewise. * pt-eval.h, pt-eval.cc (tree_evaluator): Likewise. * pt-jit.cc (jit_convert): Likewise. * pt-pr-code.h, pt-pr-code.cc (tree_print_code): Likewise.
author John W. Eaton <jwe@octave.org>
date Wed, 20 Nov 2019 00:01:18 -0600
parents 581d01526b34
children b442ec6dda5c
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-anon-scopes.cc	Wed Nov 20 07:33:24 2019 +0100
+++ b/libinterp/parse-tree/pt-anon-scopes.cc	Wed Nov 20 00:01:18 2019 -0600
@@ -34,7 +34,7 @@
 namespace octave
 {
   tree_anon_scopes::tree_anon_scopes (tree_anon_fcn_handle& anon_fh)
-    : m_params (), m_vars ()
+    : tree_walker (), m_params (), m_vars ()
   {
     visit_anon_fcn_handle (anon_fh);
   }
@@ -74,115 +74,6 @@
   // e.g. identifiers and left hand sides of assignments are ignored).
 
   void
-  tree_anon_scopes::visit_argument_list (tree_argument_list& lst)
-  {
-    tree_argument_list::iterator p = lst.begin ();
-
-    while (p != lst.end ())
-      {
-        tree_expression *elt = *p++;
-
-        if (elt)
-          {
-            elt->accept (*this);
-          }
-      }
-  }
-
-  void
-  tree_anon_scopes::visit_binary_expression (tree_binary_expression& expr)
-  {
-    tree_expression *op1 = expr.lhs ();
-
-    if (op1)
-      op1->accept (*this);
-
-    tree_expression *op2 = expr.rhs ();
-
-    if (op2)
-      op2->accept (*this);
-  }
-
-  void
-  tree_anon_scopes::visit_break_command (tree_break_command&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_colon_expression (tree_colon_expression& expr)
-  {
-    tree_expression *op1 = expr.base ();
-
-    if (op1)
-      op1->accept (*this);
-
-    tree_expression *op3 = expr.increment ();
-
-    if (op3)
-      op3->accept (*this);
-
-    tree_expression *op2 = expr.limit ();
-
-    if (op2)
-      op2->accept (*this);
-  }
-
-  void
-  tree_anon_scopes::visit_continue_command (tree_continue_command&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_decl_command (tree_decl_command&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_decl_elt (tree_decl_elt&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_decl_init_list (tree_decl_init_list&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_simple_for_command (tree_simple_for_command&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_complex_for_command (tree_complex_for_command&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_octave_user_script (octave_user_script&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_octave_user_function (octave_user_function&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_function_def (tree_function_def&)
-  {
-    panic_impossible ();
-  }
-
-  void
   tree_anon_scopes::visit_identifier (tree_identifier& id)
   {
     std::string nm = id.name ();
@@ -192,116 +83,6 @@
   }
 
   void
-  tree_anon_scopes::visit_if_clause (tree_if_clause&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_if_command (tree_if_command&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_if_command_list (tree_if_command_list&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_switch_case (tree_switch_case&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_switch_case_list (tree_switch_case_list&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_switch_command (tree_switch_command&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_index_expression (tree_index_expression& expr)
-  {
-    tree_expression *e = expr.expression ();
-
-    if (e)
-      e->accept (*this);
-
-    std::list<tree_argument_list *> lst = expr.arg_lists ();
-
-    std::list<tree_argument_list *>::iterator p = lst.begin ();
-
-    while (p != lst.end ())
-      {
-        tree_argument_list *elt = *p++;
-
-        if (elt)
-          elt->accept (*this);
-      }
-  }
-
-  void
-  tree_anon_scopes::visit_matrix (tree_matrix& lst)
-  {
-    tree_matrix::iterator p = lst.begin ();
-
-    while (p != lst.end ())
-      {
-        tree_argument_list *elt = *p++;
-
-        if (elt)
-          elt->accept (*this);
-      }
-  }
-
-  void
-  tree_anon_scopes::visit_cell (tree_cell& lst)
-  {
-    tree_matrix::iterator p = lst.begin ();
-
-    while (p != lst.end ())
-      {
-        tree_argument_list *elt = *p++;
-
-        if (elt)
-          elt->accept (*this);
-      }
-  }
-
-  void
-  tree_anon_scopes::visit_multi_assignment (tree_multi_assignment& expr)
-  {
-    tree_expression *rhs = expr.right_hand_side ();
-
-    if (rhs)
-      rhs->accept (*this);
-  }
-
-  void
-  tree_anon_scopes::visit_no_op_command (tree_no_op_command&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_constant (tree_constant& /* val */)
-  {
-  }
-
-  void
-  tree_anon_scopes::visit_fcn_handle (tree_fcn_handle& /* fh */)
-  {
-  }
-
-  void
   tree_anon_scopes::visit_parameter_list (tree_parameter_list&)
   {
     // In visit_anon_fcn_handle we only accept/visit the body of
@@ -311,53 +92,6 @@
   }
 
   void
-  tree_anon_scopes::visit_postfix_expression (tree_postfix_expression& expr)
-  {
-    tree_expression *e = expr.operand ();
-
-    if (e)
-      e->accept (*this);
-  }
-
-  void
-  tree_anon_scopes::visit_prefix_expression (tree_prefix_expression& expr)
-  {
-    tree_expression *e = expr.operand ();
-
-    if (e)
-      e->accept (*this);
-  }
-
-  void
-  tree_anon_scopes::visit_return_command (tree_return_command&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_return_list (tree_return_list& lst)
-  {
-    tree_return_list::iterator p = lst.begin ();
-
-    while (p != lst.end ())
-      {
-        tree_index_expression *elt = *p++;
-
-        if (elt)
-          elt->accept (*this);
-      }
-  }
-
-  void
-  tree_anon_scopes::visit_simple_assignment (tree_simple_assignment& expr)
-  {
-    tree_expression *rhs = expr.right_hand_side ();
-
-    if (rhs)
-      rhs->accept (*this);
-  }
-
-  void
   tree_anon_scopes::visit_statement (tree_statement& stmt)
   {
     tree_command *cmd = stmt.command ();
@@ -384,29 +118,5 @@
           elt->accept (*this);
       }
   }
-
-  void
-  tree_anon_scopes::visit_try_catch_command (tree_try_catch_command&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_unwind_protect_command (tree_unwind_protect_command&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_while_command (tree_while_command&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_anon_scopes::visit_do_until_command (tree_do_until_command&)
-  {
-    panic_impossible ();
-  }
 }