diff libinterp/parse-tree/bp-table.cc @ 27160:6b0c61a5a0f0

move global error configuration and status variables inside a class * error.h, error.cc (error_system): New class. (Vbacktrace_on_warning, Vbeep_on_error, Vdebug_on_caught, Vdebug_on_error, Vdebug_on_warning, Vlast_error_id, Vlast_error_message, Vlast_error_stack, Vlast_warning_id, Vlast_warning_message, Vquiet_warning, Vverbose_warning, buffer_error_messages, discard_error_messages, discard_warning_messages, in_try_catch, warning_options): Move global and file-scope static variables inside error_system class. Change all uses. * interpreter.h, interpreter.cc (m_error_system): New member variable. (get_error_system): New function. * interpreter-private.h, interpreter-private.cc (__get_error_system__): New function.
author John W. Eaton <jwe@octave.org>
date Fri, 31 May 2019 15:49:38 +0000
parents 8408acb7ca4f
children 04889e45f54e
line wrap: on
line diff
--- a/libinterp/parse-tree/bp-table.cc	Fri Jun 07 13:29:41 2019 -0400
+++ b/libinterp/parse-tree/bp-table.cc	Fri May 31 15:49:38 2019 +0000
@@ -57,13 +57,16 @@
 
   void bp_table::dbclear_all_signals (void)
   {
-    Vdebug_on_error = false;
+    interpreter& interp = m_evaluator.get_interpreter ();
+    error_system& es = interp.get_error_system ();
+
+    es.debug_on_error (false);
     bp_table::m_errors_that_stop.clear ();
 
-    Vdebug_on_caught = false;
+    es.debug_on_caught (false);
     bp_table::m_caught_that_stop.clear ();
 
-    Vdebug_on_warning = false;
+    es.debug_on_warning (false);
     bp_table::m_warnings_that_stop.clear ();
 
     Vdebug_on_interrupt = false;
@@ -74,6 +77,9 @@
 
   void bp_table::dbstop_process_map_args (const octave_map& mv)
   {
+    interpreter& interp = m_evaluator.get_interpreter ();
+    error_system& es = interp.get_error_system ();
+
     // process errs
     // why so many levels of indirection needed?
     bool fail = false;
@@ -84,7 +90,7 @@
       {
         Array<octave_value> W = U.index (static_cast<octave_idx_type> (0));
         if (W.isempty () || W(0).isempty ())
-          Vdebug_on_error = 1;    // like "dbstop if error" with no identifier
+          es.debug_on_error (true);    // like "dbstop if error" with no identifier
         else if (! W(0).iscell ())
           fail = true;
         else
@@ -93,7 +99,7 @@
             for (int i = 0; i < V.numel (); i++)
               {
                 m_errors_that_stop.insert (V(i).string_value ());
-                Vdebug_on_error = 1;
+                es.debug_on_error (true);
               }
           }
       }
@@ -111,7 +117,7 @@
       {
         Array<octave_value> W = U.index (static_cast<octave_idx_type> (0));
         if (W.isempty () || W(0).isempty ())
-          Vdebug_on_caught = 1;    // like "dbstop if caught error" with no ID
+          es.debug_on_caught (true);    // like "dbstop if caught error" with no ID
         else if (! W(0).iscell ())
           fail = true;
         else
@@ -120,7 +126,7 @@
             for (int i = 0; i < V.numel (); i++)
               {
                 m_caught_that_stop.insert (V(i).string_value ());
-                Vdebug_on_caught = 1;
+                es.debug_on_caught (true);
               }
           }
       }
@@ -138,7 +144,7 @@
       {
         Array<octave_value> W = U.index (static_cast<octave_idx_type> (0));
         if (W.isempty () || W(0).isempty ())
-          Vdebug_on_warning = 1;    // like "dbstop if warning" with no identifier
+          es.debug_on_warning (true);    // like "dbstop if warning" with no identifier
         else if (! W(0).iscell ())
           fail = true;
         else
@@ -147,7 +153,7 @@
             for (int i = 0; i < V.numel (); i++)
               {
                 m_warnings_that_stop.insert (V(i).string_value ());
-                Vdebug_on_warning = 1;
+                es.debug_on_warning (true);
               }
           }
       }
@@ -157,7 +163,7 @@
 
     // process interrupt
     if (mv.isfield ("intr"))
-      Vdebug_on_interrupt = 1;
+      Vdebug_on_interrupt = true;
   }
 
   // Insert a breakpoint in function fcn at line within file fname,
@@ -415,28 +421,23 @@
             else    // stop on event (error, warning, interrupt, NaN/inf)
               {
                 std::string condition = args(pos).string_value ();
-                int on_off = ! strcmp(who, "dbstop");
+                bool on_off = ! strcmp (who, "dbstop");
 
-                // list of error/warning IDs to update
-                std::set<std::string> *id_list = nullptr;
-                bool *stop_flag = nullptr;         // Vdebug_on_... flag
+                // FIXME: the following seems a bit messy in the way it
+                // duplicates checks on CONDITION.
 
                 if (condition == "error")
-                  {
-                    id_list = &m_errors_that_stop;
-                    stop_flag = &Vdebug_on_error;
-                  }
+                  process_id_list (who, condition, args, nargin, pos, on_off,
+                                   m_errors_that_stop);
                 else if (condition == "warning")
-                  {
-                    id_list = &m_warnings_that_stop;
-                    stop_flag = &Vdebug_on_warning;
-                  }
+                  process_id_list (who, condition, args, nargin, pos, on_off,
+                                   m_warnings_that_stop);
                 else if (condition == "caught" && nargin > pos+1
                          && args(pos+1).string_value () == "error")
                   {
-                    id_list = &m_caught_that_stop;
-                    stop_flag = &Vdebug_on_caught;
                     pos++;
+                    process_id_list (who, condition, args, nargin, pos, on_off,
+                                     m_caught_that_stop);
                   }
                 else if (condition == "interrupt")
                   {
@@ -456,38 +457,6 @@
                   error ("%s: invalid condition %s",
                          who, condition.c_str ());
 
-                // process ID list for "dbstop if error <error_ID>" etc
-                if (id_list)
-                  {
-                    pos++;
-                    if (pos < nargin)       // only affect a single error ID
-                      {
-                        if (! args(pos).is_string () || nargin > pos+1)
-                          error ("%s: ID must be a single string", who);
-                        else if (on_off == 1)
-                          {
-                            id_list->insert (args(pos).string_value ());
-                            *stop_flag = true;
-                          }
-                        else
-                          {
-                            id_list->erase (args(pos).string_value ());
-                            if (id_list->empty ())
-                              *stop_flag = false;
-                          }
-                      }
-                    else   // unqualified.  Turn all on or off
-                      {
-                        id_list->clear ();
-                        *stop_flag = on_off;
-                        if (stop_flag == &Vdebug_on_error)
-                          {
-                            // Matlab stops on both.
-                            Vdebug_on_interrupt = on_off;
-                          }
-                      }
-                  }
-
                 pos = nargin;
               }
             break;
@@ -514,6 +483,59 @@
     %! assert (s.errs, {"Octave:undefined-function"});
   */
 
+  void bp_table::set_stop_flag (const char *who, const std::string& condition,
+                                bool on_off)
+  {
+    interpreter& interp = m_evaluator.get_interpreter ();
+    error_system& es = interp.get_error_system ();
+
+    if (condition == "error")
+      es.debug_on_error (on_off);
+    else if (condition == "warning")
+      es.debug_on_warning (on_off);
+    else if (condition == "caught")
+      es.debug_on_caught (on_off);
+    else
+      error ("%s: internal error in set_stop_flag", who);
+  }
+
+  void bp_table::process_id_list (const char *who,
+                                  const std::string& condition,
+                                  const octave_value_list& args,
+                                  int nargin, int& pos, bool on_off,
+                                  std::set<std::string>& id_list)
+  {
+    pos++;
+
+    if (nargin > pos)       // only affect a single error ID
+      {
+        if (! args(pos).is_string () || nargin > pos+1)
+          error ("%s: ID must be a single string", who);
+        else if (on_off)
+          {
+            id_list.insert (args(pos).string_value ());
+            set_stop_flag (who, condition, true);
+          }
+        else
+          {
+            id_list.erase (args(pos).string_value ());
+            if (id_list.empty ())
+              set_stop_flag (who, condition, false);
+          }
+      }
+    else   // unqualified.  Turn all on or off
+      {
+        id_list.clear ();
+        set_stop_flag (who, condition, on_off);
+
+        if (condition == "error")
+          {
+            // Matlab stops on both.
+            Vdebug_on_interrupt = on_off;
+          }
+      }
+  }
+
   // Return the sub/nested/main function of MAIN_FCN that contains
   // line number LINENO of the source file.
   // If END_LINE != 0, *END_LINE is set to last line of the returned function.
@@ -861,8 +883,11 @@
   {
     octave_map retval;
 
+    interpreter& interp = m_evaluator.get_interpreter ();
+    error_system& es = interp.get_error_system ();
+
     // print dbstop if error information
-    if (Vdebug_on_error)
+    if (es.debug_on_error ())
       {
         if (m_errors_that_stop.empty ())
           {
@@ -889,7 +914,7 @@
       }
 
     // print dbstop if caught error information
-    if (Vdebug_on_caught)
+    if (es.debug_on_caught ())
       {
         if (m_caught_that_stop.empty ())
           {
@@ -916,7 +941,7 @@
       }
 
     // print dbstop if warning information
-    if (Vdebug_on_warning)
+    if (es.debug_on_warning ())
       {
         if (m_warnings_that_stop.empty ())
           {