diff libinterp/corefcn/debug.cc @ 20557:b10432a40432

eliminate more simple uses of error_state * dasrt.cc, debug.cc, find.cc, gammainc.cc, matrix_type.cc, ov-usr-fcn.cc, pt-assign.cc, pt-binop.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Mon, 05 Oct 2015 20:37:19 -0400
parents 7ac907da9fba
children ba2b07c13913
line wrap: on
line diff
--- a/libinterp/corefcn/debug.cc	Mon Oct 05 20:21:55 2015 -0400
+++ b/libinterp/corefcn/debug.cc	Mon Oct 05 20:37:19 2015 -0400
@@ -210,15 +210,11 @@
       // string could be function name or line number
       int isint = atoi (args(0).string_value ().c_str ());
 
-      if (error_state)
-        return;
-
       if (isint == 0)
         {
           // It was a function name
           symbol_name = args(0).string_value ();
-          if (error_state)
-            return;
+
           idx = 1;
         }
       else
@@ -250,8 +246,7 @@
       if (args(i).is_string ())
         {
           int line = atoi (args(i).string_value ().c_str ());
-          if (error_state)
-            break;
+
           lines[list_idx++] = line;
         }
       else if (args(i).is_map ())
@@ -260,19 +255,12 @@
         {
           const NDArray arg = args(i).array_value ();
 
-          if (error_state)
-            break;
-
           for (octave_idx_type j = 0; j < arg.numel (); j++)
             {
               int line = static_cast<int> (arg.elem (j));
-              if (error_state)
-                break;
+
               lines[list_idx++] = line;
             }
-
-          if (error_state)
-            break;
         }
     }
 }
@@ -677,8 +665,7 @@
   if (lines.size () == 0)
     lines[0] = 1;
 
-  if (! error_state)
-    retval = bp_table::add_breakpoint (symbol_name, lines);
+  retval = bp_table::add_breakpoint (symbol_name, lines);
 
   return intmap_to_ov (retval);
 }
@@ -731,10 +718,7 @@
   if (nargin == 1 && symbol_name == "all")
     bp_table::remove_all_breakpoints ();
   else
-    {
-      if (! error_state)
-        bp_table::remove_breakpoint (symbol_name, lines);
-    }
+    bp_table::remove_breakpoint (symbol_name, lines);
 
   return retval;
 }
@@ -973,134 +957,131 @@
   int nargin = args.length ();
   string_vector argv = args.make_argv ("dbtype");
 
-  if (! error_state)
+  switch (nargin)
     {
-      switch (nargin)
-        {
-        case 0: // dbtype
-          dbg_fcn = get_user_code ();
+    case 0: // dbtype
+      dbg_fcn = get_user_code ();
+
+      if (dbg_fcn)
+        do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (),
+                   0, std::numeric_limits<int>::max ());
+      else
+        error ("dbtype: must be inside a user function to give no arguments to dbtype\n");
+
+      break;
+
+    case 1: // (dbtype start:end) || (dbtype func) || (dbtype lineno)
+      {
+        std::string arg = argv[1];
+
+        size_t ind = arg.find (':');
+
+        if (ind != std::string::npos)  // (dbtype start:end)
+          {
+            dbg_fcn = get_user_code ();
+
+            if (dbg_fcn)
+              {
+                std::string start_str = arg.substr (0, ind);
+                std::string end_str = arg.substr (ind + 1);
+
+                int start, end;
+                start = atoi (start_str.c_str ());
+                if (end_str == "end")
+                  end = std::numeric_limits<int>::max ();
+                else
+                  end = atoi (end_str.c_str ());
 
-          if (dbg_fcn)
-            do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (),
-                       0, std::numeric_limits<int>::max ());
-          else
-            error ("dbtype: must be inside a user function to give no arguments to dbtype\n");
+                if (std::min (start, end) <= 0)
+                  {
+                    error ("dbtype: start and end lines must be >= 1\n");
+                    break;
+                  }
 
-          break;
+                if (start <= end)
+                  do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (),
+                             start, end);
+                else
+                  error ("dbtype: start line must be less than end line\n");
+              }
+          }
+        else  // (dbtype func) || (dbtype lineno)
+          {
+            int line = atoi (arg.c_str ());
 
-        case 1: // (dbtype start:end) || (dbtype func) || (dbtype lineno)
-          {
-            std::string arg = argv[1];
+            if (line == 0)  // (dbtype func)
+              {
+                dbg_fcn = get_user_code (arg);
 
-            size_t ind = arg.find (':');
+                if (dbg_fcn)
+                  do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (),
+                             0, std::numeric_limits<int>::max ());
+                else
+                  error ("dbtype: function <%s> not found\n", arg.c_str ());
+              }
+            else  // (dbtype lineno)
+              {
+                if (line <= 0)
+                  {
+                    error ("dbtype: start and end lines must be >= 1\n");
+                    break;
+                  }
 
-            if (ind != std::string::npos)  // (dbtype start:end)
-              {
                 dbg_fcn = get_user_code ();
 
                 if (dbg_fcn)
-                  {
-                    std::string start_str = arg.substr (0, ind);
-                    std::string end_str = arg.substr (ind + 1);
-
-                    int start, end;
-                    start = atoi (start_str.c_str ());
-                    if (end_str == "end")
-                      end = std::numeric_limits<int>::max ();
-                    else
-                      end = atoi (end_str.c_str ());
-
-                    if (std::min (start, end) <= 0)
-                      {
-                        error ("dbtype: start and end lines must be >= 1\n");
-                        break;
-                      }
-
-                    if (start <= end)
-                      do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (),
-                                 start, end);
-                    else
-                      error ("dbtype: start line must be less than end line\n");
-                  }
-              }
-            else  // (dbtype func) || (dbtype lineno)
-              {
-                int line = atoi (arg.c_str ());
-
-                if (line == 0)  // (dbtype func)
-                  {
-                    dbg_fcn = get_user_code (arg);
-
-                    if (dbg_fcn)
-                      do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (),
-                                 0, std::numeric_limits<int>::max ());
-                    else
-                      error ("dbtype: function <%s> not found\n", arg.c_str ());
-                  }
-                else  // (dbtype lineno)
-                  {
-                    if (line <= 0)
-                      {
-                        error ("dbtype: start and end lines must be >= 1\n");
-                        break;
-                      }
-
-                    dbg_fcn = get_user_code ();
-
-                    if (dbg_fcn)
-                      do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (),
-                                 line, line);
-                  }
+                  do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (),
+                             line, line);
               }
           }
-          break;
-
-        case 2: // (dbtype func start:end) || (dbtype func start)
-          dbg_fcn = get_user_code (argv[1]);
+      }
+      break;
 
-          if (dbg_fcn)
-            {
-              std::string arg = argv[2];
-              int start, end;
-              size_t ind = arg.find (':');
-
-              if (ind != std::string::npos)
-                {
-                  std::string start_str = arg.substr (0, ind);
-                  std::string end_str = arg.substr (ind + 1);
+    case 2: // (dbtype func start:end) || (dbtype func start)
+      dbg_fcn = get_user_code (argv[1]);
 
-                  start = atoi (start_str.c_str ());
-                  if (end_str == "end")
-                    end = std::numeric_limits<int>::max ();
-                  else
-                    end = atoi (end_str.c_str ());
-                }
-              else
-                {
-                  start = atoi (arg.c_str ());
-                  end = start;
-                }
+      if (dbg_fcn)
+        {
+          std::string arg = argv[2];
+          int start, end;
+          size_t ind = arg.find (':');
 
-              if (std::min (start, end) <= 0)
-                {
-                  error ("dbtype: start and end lines must be >= 1\n");
-                  break;
-                }
+          if (ind != std::string::npos)
+            {
+              std::string start_str = arg.substr (0, ind);
+              std::string end_str = arg.substr (ind + 1);
 
-              if (start <= end)
-                do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (),
-                           start, end);
+              start = atoi (start_str.c_str ());
+              if (end_str == "end")
+                end = std::numeric_limits<int>::max ();
               else
-                error ("dbtype: start line must be less than end line\n");
+                end = atoi (end_str.c_str ());
             }
           else
-            error ("dbtype: function <%s> not found\n", argv[1].c_str ());
+            {
+              start = atoi (arg.c_str ());
+              end = start;
+            }
 
-          break;
+          if (std::min (start, end) <= 0)
+            {
+              error ("dbtype: start and end lines must be >= 1\n");
+              break;
+            }
 
-        default:
-          error ("dbtype: expecting zero, one, or two arguments\n");
+          if (start <= end)
+            do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (),
+                       start, end);
+          else
+            error ("dbtype: start line must be less than end line\n");
         }
+      else
+        error ("dbtype: function <%s> not found\n", argv[1].c_str ());
+
+      break;
+
+    default:
+      error ("dbtype: expecting zero, one, or two arguments\n");
     }
 
   return retval;
@@ -1200,7 +1181,7 @@
     {
       int n = 0;
 
-      for (octave_idx_type i = 0; i < len && ! error_state; i++)
+      for (octave_idx_type i = 0; i < len; i++)
         {
           octave_value arg = args(i);
 
@@ -1218,7 +1199,7 @@
           else
             n = arg.int_value ();
 
-          if (! error_state && n <= 0)
+          if (n <= 0)
             error ("dbstack: N must be a non-negative integer");
         }
 
@@ -1228,63 +1209,60 @@
   else if (len)
     print_usage ();
 
-  if (! error_state)
+  if (nargout == 0)
     {
-      if (nargout == 0)
+      octave_map stk = octave_call_stack::backtrace (nskip, curr_frame);
+      octave_idx_type nframes_to_display = stk.numel ();
+
+      if (nframes_to_display > 0)
         {
-          octave_map stk = octave_call_stack::backtrace (nskip, curr_frame);
-          octave_idx_type nframes_to_display = stk.numel ();
+          octave_preserve_stream_state stream_state (os);
 
-          if (nframes_to_display > 0)
-            {
-              octave_preserve_stream_state stream_state (os);
-
-              os << "stopped in:\n\n";
+          os << "stopped in:\n\n";
 
-              Cell names = stk.contents ("name");
-              Cell files = stk.contents ("file");
-              Cell lines = stk.contents ("line");
+          Cell names = stk.contents ("name");
+          Cell files = stk.contents ("file");
+          Cell lines = stk.contents ("line");
 
-              bool show_top_level = true;
+          bool show_top_level = true;
 
-              size_t max_name_len = 0;
+          size_t max_name_len = 0;
 
-              for (octave_idx_type i = 0; i < nframes_to_display; i++)
-                {
-                  std::string name = names(i).string_value ();
+          for (octave_idx_type i = 0; i < nframes_to_display; i++)
+            {
+              std::string name = names(i).string_value ();
 
-                  max_name_len = std::max (name.length (), max_name_len);
-                }
+              max_name_len = std::max (name.length (), max_name_len);
+            }
 
-              for (octave_idx_type i = 0; i < nframes_to_display; i++)
-                {
-                  std::string name = names(i).string_value ();
-                  std::string file = files(i).string_value ();
-                  int line = lines(i).int_value ();
+          for (octave_idx_type i = 0; i < nframes_to_display; i++)
+            {
+              std::string name = names(i).string_value ();
+              std::string file = files(i).string_value ();
+              int line = lines(i).int_value ();
 
-                  if (show_top_level && i == curr_frame)
-                    show_top_level = false;
+              if (show_top_level && i == curr_frame)
+                show_top_level = false;
 
-                  os << (i == curr_frame ? "  --> " : "      ")
-                     << std::setw (max_name_len) << name
-                     << " at line " << line
-                     << " [" << file << "]"
-                     << std::endl;
-                }
-
-              if (show_top_level)
-                os << "  --> top level" << std::endl;
+              os << (i == curr_frame ? "  --> " : "      ")
+                 << std::setw (max_name_len) << name
+                 << " at line " << line
+                 << " [" << file << "]"
+                 << std::endl;
             }
+
+          if (show_top_level)
+            os << "  --> top level" << std::endl;
         }
-      else
-        {
-          octave_map stk = octave_call_stack::backtrace (nskip,
-                                                         curr_frame,
-                                                         false);
+    }
+  else
+    {
+      octave_map stk = octave_call_stack::backtrace (nskip,
+                                                     curr_frame,
+                                                     false);
 
-          retval(1) = curr_frame < 0 ? 1 : curr_frame + 1;
-          retval(0) = stk;
-        }
+      retval(1) = curr_frame < 0 ? 1 : curr_frame + 1;
+      retval(0) = stk;
     }
 
   return retval;
@@ -1367,14 +1345,11 @@
         n = args(0).int_value ();
     }
 
-  if (! error_state)
-    {
-      if (who == "dbup")
-        n = -n;
+  if (who == "dbup")
+    n = -n;
 
-      if (! octave_call_stack::goto_frame_relative (n, true))
-        error ("%s: invalid stack frame", who.c_str ());
-    }
+  if (! octave_call_stack::goto_frame_relative (n, true))
+    error ("%s: invalid stack frame", who.c_str ());
 }
 
 DEFUN (dbup, args, ,