changeset 25403:2b7d7a3f5f57

move returning, breaking, and continuing flags to evaluator * pt-jump.cc: Delete. * libinterp/parse-tree/module.mk: Update. * pt-eval.h, pt-eval.cc (tree_evaluator::m_breaking, tree_evaluator::m_continuing, tree_evaluator::m_returning, tree_evaluator::breaking, tree_evaluator::continuing, tree_evaluator::returning): New data members and functions. * pt-jump.h (tree_break_command::breaking, tree_continue_command::continuing, tree_return_command:returning): Delete. Change all uses to the corresponding evaluator variables. (tree_evaluator::quit_loop_now): Now a private member function instead of file-scope static function.
author John W. Eaton <jwe@octave.org>
date Tue, 22 May 2018 13:23:49 -0400
parents ef2b9d4abf4a
children e37d857716c3
files libinterp/corefcn/interpreter.cc libinterp/parse-tree/module.mk libinterp/parse-tree/oct-parse.in.yy libinterp/parse-tree/pt-eval.cc libinterp/parse-tree/pt-eval.h libinterp/parse-tree/pt-jump.cc libinterp/parse-tree/pt-jump.h
diffstat 7 files changed, 65 insertions(+), 107 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/interpreter.cc	Tue May 22 11:39:44 2018 -0400
+++ b/libinterp/corefcn/interpreter.cc	Tue May 22 13:23:49 2018 -0400
@@ -952,14 +952,14 @@
 
                     if (! application::interactive ())
                       {
-                        bool quit = (tree_return_command::returning
-                                     || tree_break_command::breaking);
+                        bool quit = (m_evaluator.returning ()
+                                     || m_evaluator.breaking ());
 
-                        if (tree_return_command::returning)
-                          tree_return_command::returning = 0;
+                        if (m_evaluator.returning ())
+                          m_evaluator.returning (0);
 
-                        if (tree_break_command::breaking)
-                          tree_break_command::breaking--;
+                        if (m_evaluator.breaking ())
+                          m_evaluator.breaking (m_evaluator.breaking () - 1)
 
                         if (quit)
                           break;
--- a/libinterp/parse-tree/module.mk	Tue May 22 11:39:44 2018 -0400
+++ b/libinterp/parse-tree/module.mk	Tue May 22 13:23:49 2018 -0400
@@ -79,7 +79,6 @@
   %reldir%/pt-id.cc \
   %reldir%/pt-idx.cc \
   %reldir%/pt-jit.cc \
-  %reldir%/pt-jump.cc \
   %reldir%/pt-loop.cc \
   %reldir%/pt-mat.cc \
   %reldir%/pt-misc.cc \
--- a/libinterp/parse-tree/oct-parse.in.yy	Tue May 22 11:39:44 2018 -0400
+++ b/libinterp/parse-tree/oct-parse.in.yy	Tue May 22 13:23:49 2018 -0400
@@ -5445,9 +5445,7 @@
                 else
                   error ("eval: invalid use of statement list");
 
-                if (tree_return_command::returning
-                    || tree_break_command::breaking
-                    || tree_continue_command::continuing)
+                if (tw.returning () || tw.breaking () || tw.continuing ())
                   break;
               }
             else if (parser.m_lexer.m_end_of_input)
--- a/libinterp/parse-tree/pt-eval.cc	Tue May 22 11:39:44 2018 -0400
+++ b/libinterp/parse-tree/pt-eval.cc	Tue May 22 13:23:49 2018 -0400
@@ -332,7 +332,7 @@
       do_breakpoint (cmd.is_breakpoint (true));
 
     if (m_in_loop_command)
-      tree_break_command::breaking = 1;
+      m_breaking = 1;
     else
       error ("break must appear in a loop in the same file as loop command");
   }
@@ -414,7 +414,7 @@
       do_breakpoint (cmd.is_breakpoint (true));
 
     if (m_in_loop_command)
-      tree_continue_command::continuing = 1;
+      m_continuing = 1;
   }
 
   bool
@@ -937,27 +937,6 @@
       }
   }
 
-  // Decide if it's time to quit a for or while loop.
-  static inline bool
-  quit_loop_now (void)
-  {
-    octave_quit ();
-
-    // Maybe handle 'continue N' someday...
-
-    if (tree_continue_command::continuing)
-      tree_continue_command::continuing--;
-
-    bool quit = (tree_return_command::returning
-                 || tree_break_command::breaking
-                 || tree_continue_command::continuing);
-
-    if (tree_break_command::breaking)
-      tree_break_command::breaking--;
-
-    return quit;
-  }
-
   void
   tree_evaluator::visit_simple_for_command (tree_simple_for_command& cmd)
   {
@@ -1234,11 +1213,11 @@
 
     cmd_list->accept (*this);
 
-    if (tree_return_command::returning)
-      tree_return_command::returning = 0;
-
-    if (tree_break_command::breaking)
-      tree_break_command::breaking--;
+    if (m_returning)
+      m_returning = 0;
+
+    if (m_breaking)
+      m_breaking--;
 
     return retval;
   }
@@ -1419,11 +1398,11 @@
         cmd_list->accept (*this);
     }
 
-    if (tree_return_command::returning)
-      tree_return_command::returning = 0;
-
-    if (tree_break_command::breaking)
-      tree_break_command::breaking--;
+    if (m_returning)
+      m_returning = 0;
+
+    if (m_breaking)
+      m_breaking--;
 
     // Copy return values out.
 
@@ -2364,7 +2343,7 @@
     else if (m_statement_context == SC_FUNCTION
              || m_statement_context == SC_SCRIPT
              || m_in_loop_command)
-      tree_return_command::returning = 1;
+      m_returning = 1;
   }
 
   void
@@ -2567,11 +2546,10 @@
 
             elt->accept (*this);
 
-            if (tree_break_command::breaking
-                || tree_continue_command::continuing)
+            if (m_breaking || m_continuing)
               break;
 
-            if (tree_return_command::returning)
+            if (m_returning)
               break;
 
             if (p == lst.end ())
@@ -2747,11 +2725,11 @@
     // We don't have to worry about continue statements because they can
     // only occur in loops.
 
-    frame.protect_var (tree_return_command::returning);
-    tree_return_command::returning = 0;
-
-    frame.protect_var (tree_break_command::breaking);
-    tree_break_command::breaking = 0;
+    frame.protect_var (m_returning);
+    m_returning = 0;
+
+    frame.protect_var (m_breaking);
+    m_breaking = 0;
 
     try
       {
@@ -2762,7 +2740,7 @@
       {
         interpreter::recover_from_exception ();
 
-        if (tree_break_command::breaking || tree_return_command::returning)
+        if (m_breaking || m_returning)
           frame.discard (2);
         else
           frame.run (2);
@@ -2799,7 +2777,7 @@
     // break in the cleanup block, the values should be reset to
     // whatever they were when the cleanup block was entered.
 
-    if (tree_break_command::breaking || tree_return_command::returning)
+    if (m_breaking || m_returning)
       frame.discard (2);
     else
       frame.run (2);
@@ -3466,6 +3444,24 @@
 
     error_with_id (e.err_id (), msg.c_str ());
   }
+
+  // Decide if it's time to quit a for or while loop.
+  bool tree_evaluator::quit_loop_now (void)
+  {
+    octave_quit ();
+
+    // Maybe handle 'continue N' someday...
+
+    if (m_continuing)
+      m_continuing--;
+
+    bool quit = (m_returning || m_breaking || m_continuing);
+
+    if (m_breaking)
+      m_breaking--;
+
+    return quit;
+  }
 }
 
 DEFMETHOD (max_recursion_depth, interp, args, nargout,
--- a/libinterp/parse-tree/pt-eval.h	Tue May 22 11:39:44 2018 -0400
+++ b/libinterp/parse-tree/pt-eval.h	Tue May 22 13:23:49 2018 -0400
@@ -136,6 +136,7 @@
         m_PS4 ("+ "), m_dbstep_flag (0), m_echo (ECHO_OFF),
         m_echo_state (false), m_echo_file_name (), m_echo_file_pos (1),
         m_echo_files (), m_in_loop_command (false),
+        m_breaking (0), m_continuing (0), m_returning (0),
         m_indexed_object (nullptr), m_index_position (0), m_num_indices (0)
     { }
 
@@ -463,6 +464,12 @@
 
     int num_indices (void) const { return m_num_indices; }
 
+    int breaking (void) const { return m_breaking; }
+
+    int continuing (void) const { return m_continuing; }
+
+    int returning (void) const { return m_returning; }
+
     octave_value echo (const octave_value_list& args, int nargout);
 
     int echo (void) const { return m_echo; }
@@ -528,6 +535,8 @@
 
     void final_index_error (index_exception& e, const tree_expression *expr);
 
+    bool quit_loop_now (void);
+
     interpreter& m_interpreter;
 
     // The context for the current evaluation.
@@ -596,6 +605,15 @@
     // TRUE means we are evaluating some kind of looping construct.
     bool m_in_loop_command;
 
+    // Nonzero means we're breaking out of a loop or function body.
+    int m_breaking;
+
+    // Nonzero means we're jumping to the end of a loop.
+    int m_continuing;
+
+    // Nonzero means we're returning from a function.
+    int m_returning;
+
     // Used by END function.
     const octave_value *m_indexed_object;
     int m_index_position;
--- a/libinterp/parse-tree/pt-jump.cc	Tue May 22 11:39:44 2018 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/*
-
-Copyright (C) 1996-2018 John W. Eaton
-
-This file is part of Octave.
-
-Octave is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-Octave is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with Octave; see the file COPYING.  If not, see
-<https://www.gnu.org/licenses/>.
-
-*/
-
-#if defined (HAVE_CONFIG_H)
-#  include "config.h"
-#endif
-
-#include "pt-jump.h"
-
-class octave_value_list;
-
-namespace octave
-{
-  // Break.
-
-  // Nonzero means we're breaking out of a loop or function body.
-  int tree_break_command::breaking = 0;
-
-  // Continue.
-
-  // Nonzero means we're jumping to the end of a loop.
-  int tree_continue_command::continuing = 0;
-
-  // Return.
-
-  // Nonzero means we're returning from a function.
-  int tree_return_command::returning = 0;
-}
--- a/libinterp/parse-tree/pt-jump.h	Tue May 22 11:39:44 2018 -0400
+++ b/libinterp/parse-tree/pt-jump.h	Tue May 22 13:23:49 2018 -0400
@@ -51,8 +51,6 @@
     {
       tw.visit_break_command (*this);
     }
-
-    static int breaking;
   };
 
   // Continue.
@@ -76,8 +74,6 @@
     {
       tw.visit_continue_command (*this);
     }
-
-    static int continuing;
   };
 
   // Return.
@@ -101,8 +97,6 @@
     {
       tw.visit_return_command (*this);
     }
-
-    static int returning;
   };
 }