diff libinterp/parse-tree/pt-eval.cc @ 23469:2699c5974844

handle global and persistent in tree_decl_command, not as separate classes * pt-decl.h, pt-decl.cc (tree_decl_command::mark_as_global, tree_decl_command::mark_as_persistent, tree_decl_command::dup): New functions. (tree_global_command, tree_persistent_command): Delete classes. (tree_decl_elt::decl_type): New enum. Store command type in each initializer list element. (tree_decl_elt::mark_as_global, tree_decl_elt::is_global, tree_decl_elt::mark_as_persistent, tree_decl_elt::is_persistent): New functions. (tree_decl_init_list::mark_as_global, tree_decl_init_list::is_global, tree_decl_init_list::mark_as_persistent, tree_decl_init_list::is_persistent): New functions. * pt-walk.h (tree_walker::visit_decl_command): New function. (tree_walker::visit_global_command, tree_walker::visit_persistent_command): Delete. Update all derived classes. * oct-parse.in.yy (base_parser::make_decl_command): Tag initialization lists as global or persistent here. * pt-eval.cc (tree_evaluator::visit_decl_command): New function. Visit initialization list instead of looping here. (tree_evaluator::visit_decl_init_list): Loop and visit elements here. (tree_evaluator::visit_decl_elt): Handle evaluation of elements here.
author John W. Eaton <jwe@octave.org>
date Thu, 04 May 2017 15:02:46 -0400
parents 0f4ed33886de
children a41fdb801db6
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-eval.cc	Thu May 04 10:29:51 2017 -0400
+++ b/libinterp/parse-tree/pt-eval.cc	Thu May 04 15:02:46 2017 -0400
@@ -608,40 +608,37 @@
   }
 
   void
-  tree_evaluator::do_global_init (octave::tree_decl_elt& elt)
+  tree_evaluator::visit_decl_command (tree_decl_command& cmd)
+  {
+    if (debug_mode)
+      do_breakpoint (cmd.is_breakpoint (true));
+
+    tree_decl_init_list *init_list = cmd.initializer_list ();
+
+    if (init_list)
+      init_list->accept (*this);
+  }
+
+  void
+  tree_evaluator::visit_decl_init_list (tree_decl_init_list& lst)
+  {
+    for (tree_decl_elt *elt : lst)
+      elt->accept (*this);
+  }
+
+  void
+  tree_evaluator::visit_decl_elt (tree_decl_elt& elt)
   {
     octave::tree_identifier *id = elt.ident ();
 
     if (id)
       {
-        id->mark_global ();
-
-        octave_lvalue ult = id->lvalue (this);
-
-        if (ult.is_undefined ())
-          {
-            octave::tree_expression *expr = elt.expression ();
-
-            octave_value init_val;
-
-            if (expr)
-              init_val = evaluate (expr);
-            else
-              init_val = Matrix ();
-
-            ult.assign (octave_value::op_asn_eq, init_val);
-          }
-      }
-  }
-
-  void
-  tree_evaluator::do_static_init (octave::tree_decl_elt& elt)
-  {
-    octave::tree_identifier *id = elt.ident ();
-
-    if (id)
-      {
-        id->mark_as_static ();
+        if (elt.is_global ())
+          id->mark_global ();
+        else if (elt.is_persistent ())
+          id->mark_as_static ();
+        else
+          error ("declaration list element not global or persistent");
 
         octave_lvalue ult = id->lvalue (this);
 
@@ -660,56 +657,6 @@
           }
       }
   }
-
-  void
-  tree_evaluator::visit_global_command (tree_global_command& cmd)
-  {
-    if (debug_mode)
-      do_breakpoint (cmd.is_breakpoint (true));
-
-    tree_decl_init_list *init_list = cmd.initializer_list ();
-
-    if (init_list)
-      {
-        // If we called init_list->accept (*this), we would need a way
-        // to tell tree_evaluator::visit_decl_init_list that we are
-        // evaluating a global init list.
-
-        for (tree_decl_elt *elt : *init_list)
-          do_global_init (*elt);
-      }
-  }
-
-  void
-  tree_evaluator::visit_persistent_command (tree_persistent_command& cmd)
-  {
-    if (debug_mode)
-      do_breakpoint (cmd.is_breakpoint (true));
-
-    tree_decl_init_list *init_list = cmd.initializer_list ();
-
-    if (init_list)
-      {
-        // If we called init_list->accept (*this), we would need a way
-        // to tell tree_evaluator::visit_decl_init_list that we are
-        // evaluating a static init list.
-
-        for (tree_decl_elt *elt : *init_list)
-          do_static_init (*elt);
-      }
-  }
-
-  void
-  tree_evaluator::visit_decl_elt (tree_decl_elt&)
-  {
-    panic_impossible ();
-  }
-
-  void
-  tree_evaluator::visit_decl_init_list (tree_decl_init_list&)
-  {
-    panic_impossible ();
-  }
 }
 
 // Decide if it's time to quit a for or while loop.