diff libinterp/corefcn/debug.cc @ 20962:3aa293be0e8d

maint: Invert simple conditionals in if/else/error paradigm. Invert conditional in if statement and place error next to if. Delete else, and decrease code indent by 4. * cellfun.cc, data.cc, debug.cc, dirfns.cc, dynamic-ld.cc, file-io.cc, gl2ps-renderer.cc, graphics.cc, graphics.in.h, hex2num.cc, load-save.cc, ls-mat-ascii.cc, ls-oct-text.cc, oct-hist.cc, oct-lvalue.cc, oct-map.cc, toplev.cc, __init_fltk__.cc, ov-base-int.cc, ov-bool-mat.cc, ov-cell.cc, ov-class.cc, ov-classdef.cc, ov-cx-mat.cc, ov-fcn-handle.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-oncleanup.cc, ov-re-mat.cc, ov-str-mat.cc, ov-struct.cc, ov-usr-fcn.cc, ov.cc, pt-arg-list.cc, pt-assign.cc, pt-colon.cc, pt-eval.cc, pt-exp.cc: Invert conditional in if statement and place error next to if. Delete else, and decrease code indent by 4.
author Rik <rik@octave.org>
date Tue, 22 Dec 2015 10:29:22 -0800
parents a4f5da7c5463
children 81c2b14c209f
line wrap: on
line diff
--- a/libinterp/corefcn/debug.cc	Tue Dec 22 07:43:44 2015 -0500
+++ b/libinterp/corefcn/debug.cc	Tue Dec 22 10:29:22 2015 -0800
@@ -83,13 +83,11 @@
 
           file.read (&buf[0], sz+1);
 
-          if (file.eof ())
-            {
-              // Expected to read the entire file.
-              retval = buf;
-            }
-          else
+          if (! file.eof ())
             error ("error reading file %s", fname.c_str ());
+
+          // Expected to read the entire file.
+          retval = buf;
         }
     }
 
@@ -220,13 +218,11 @@
       else
         {
           // It was a line number.  Need to get function name from debugger.
-          if (Vdebugging)
-            {
-              symbol_name = get_user_code ()->name ();
-              idx = 0;
-            }
-          else
+          if (! Vdebugging)
             error ("%s: no function specified", who);
+
+          symbol_name = get_user_code ()->name ();
+          idx = 0;
         }
     }
   else if (args(0).is_map ())
@@ -265,8 +261,6 @@
 bool
 bp_table::instance_ok (void)
 {
-  bool retval = true;
-
   if (! instance)
     {
       instance = new bp_table ();
@@ -278,7 +272,7 @@
   if (! instance)
     error ("unable to create breakpoint table!");
 
-  return retval;
+  return true;
 }
 
 bool
@@ -315,40 +309,38 @@
 bp_table::do_add_breakpoint (const std::string& fname,
                              const bp_table::intmap& line)
 {
-  intmap retval;
-
   octave_user_code *dbg_fcn = get_user_code (fname);
 
-  if (dbg_fcn)
-    {
-      if (! do_add_breakpoint_1 (dbg_fcn, fname, line, retval))
-        {
-          // Search subfunctions in the order they appear in the file.
+  if (! dbg_fcn)
+    error ("add_breakpoint: unable to find the requested function\n");
+
+  intmap retval;
 
-          const std::list<std::string> subfcn_names
-            = dbg_fcn->subfunction_names ();
+  if (! do_add_breakpoint_1 (dbg_fcn, fname, line, retval))
+    {
+      // Search subfunctions in the order they appear in the file.
 
-          std::map<std::string, octave_value> subfcns
-            = dbg_fcn->subfunctions ();
+      const std::list<std::string> subfcn_names
+        = dbg_fcn->subfunction_names ();
 
-          for (std::list<std::string>::const_iterator p = subfcn_names.begin ();
-               p != subfcn_names.end (); p++)
-            {
-              std::map<std::string, octave_value>::const_iterator
-                q = subfcns.find (*p);
+      std::map<std::string, octave_value> subfcns
+        = dbg_fcn->subfunctions ();
 
-              if (q != subfcns.end ())
-                {
-                  octave_user_code *dbg_subfcn = q->second.user_code_value ();
+      for (std::list<std::string>::const_iterator p = subfcn_names.begin ();
+           p != subfcn_names.end (); p++)
+        {
+          std::map<std::string, octave_value>::const_iterator
+            q = subfcns.find (*p);
 
-                  if (do_add_breakpoint_1 (dbg_subfcn, fname, line, retval))
-                    break;
-                }
+          if (q != subfcns.end ())
+            {
+              octave_user_code *dbg_subfcn = q->second.user_code_value ();
+
+              if (do_add_breakpoint_1 (dbg_subfcn, fname, line, retval))
+                break;
             }
         }
     }
-  else
-    error ("add_breakpoint: unable to find the requested function\n");
 
   tree_evaluator::debug_mode = bp_table::have_breakpoints () || Vdebugging;
 
@@ -421,34 +413,32 @@
     {
       octave_user_code *dbg_fcn = get_user_code (fname);
 
-      if (dbg_fcn)
-        {
-          retval = do_remove_breakpoint_1 (dbg_fcn, fname, line);
+      if (! dbg_fcn)
+        error ("remove_breakpoint: unable to find the requested function\n");
 
-          // Search subfunctions in the order they appear in the file.
+      retval = do_remove_breakpoint_1 (dbg_fcn, fname, line);
 
-          const std::list<std::string> subfcn_names
-            = dbg_fcn->subfunction_names ();
+      // Search subfunctions in the order they appear in the file.
 
-          std::map<std::string, octave_value> subfcns
-            = dbg_fcn->subfunctions ();
+      const std::list<std::string> subfcn_names
+        = dbg_fcn->subfunction_names ();
 
-          for (std::list<std::string>::const_iterator p = subfcn_names.begin ();
-               p != subfcn_names.end (); p++)
-            {
-              std::map<std::string, octave_value>::const_iterator
-                q = subfcns.find (*p);
+      std::map<std::string, octave_value> subfcns
+        = dbg_fcn->subfunctions ();
 
-              if (q != subfcns.end ())
-                {
-                  octave_user_code *dbg_subfcn = q->second.user_code_value ();
+      for (std::list<std::string>::const_iterator p = subfcn_names.begin ();
+           p != subfcn_names.end (); p++)
+        {
+          std::map<std::string, octave_value>::const_iterator
+            q = subfcns.find (*p);
 
-                  retval += do_remove_breakpoint_1 (dbg_subfcn, fname, line);
-                }
+          if (q != subfcns.end ())
+            {
+              octave_user_code *dbg_subfcn = q->second.user_code_value ();
+
+              retval += do_remove_breakpoint_1 (dbg_subfcn, fname, line);
             }
         }
-      else
-        error ("remove_breakpoint: unable to find the requested function\n");
     }
 
   tree_evaluator::debug_mode = bp_table::have_breakpoints () || Vdebugging;
@@ -505,8 +495,7 @@
 }
 
 std::string
-do_find_bkpt_list (octave_value_list slist,
-                   std::string match)
+do_find_bkpt_list (octave_value_list slist, std::string match)
 {
   std::string retval;
 
@@ -673,7 +662,6 @@
 @seealso{dbstop, dbstatus, dbwhere}\n\
 @end deftypefn")
 {
-  octave_value retval;
   std::string symbol_name = "";
   bp_table::intmap lines;
 
@@ -684,7 +672,7 @@
   else
     bp_table::remove_breakpoint (symbol_name, lines);
 
-  return retval;
+  return ovl ();
 }
 
 DEFUN (dbstatus, args, nargout,
@@ -721,15 +709,15 @@
 @seealso{dbclear, dbwhere}\n\
 @end deftypefn")
 {
-  octave_map retval;
   int nargin = args.length ();
+
+  if (nargin != 0 && nargin != 1)
+    error ("dbstatus: only zero or one arguments accepted\n");
+
   octave_value_list fcn_list;
   bp_table::fname_line_map bp_list;
   std::string symbol_name;
 
-  if (nargin != 0 && nargin != 1)
-    error ("dbstatus: only zero or one arguments accepted\n");
-
   if (nargin == 1)
     {
       if (args(0).is_string ())
@@ -779,7 +767,7 @@
           if (nel > 0)
             octave_stdout << std::endl;
         }
-      return octave_value ();
+      return ovl ();
     }
   else
     {
@@ -799,11 +787,12 @@
           i++;
         }
 
+      octave_map retval;
       retval.assign ("name", names);
       retval.assign ("file", file);
       retval.assign ("line", line);
 
-      return octave_value (retval);
+      return ovl (retval);
     }
 }
 
@@ -815,46 +804,42 @@
 @seealso{dbstatus, dbcont, dbstep, dbup}\n\
 @end deftypefn")
 {
-  octave_value retval;
-
   octave_user_code *dbg_fcn = get_user_code ();
 
-  if (dbg_fcn)
-    {
-      bool have_file = true;
+  if (! dbg_fcn)
+    error ("dbwhere: must be inside a user function to use dbwhere\n");
 
-      std::string name = dbg_fcn->fcn_file_name ();
+  bool have_file = true;
+
+  std::string name = dbg_fcn->fcn_file_name ();
 
-      if (name.empty ())
-        {
-          have_file = false;
+  if (name.empty ())
+    {
+      have_file = false;
 
-          name = dbg_fcn->name ();
-        }
-
-      octave_stdout << "stopped in " << name << " at ";
+      name = dbg_fcn->name ();
+    }
 
-      int l = octave_call_stack::caller_user_code_line ();
+  octave_stdout << "stopped in " << name << " at ";
+
+  int l = octave_call_stack::caller_user_code_line ();
 
-      if (l > 0)
-        {
-          octave_stdout << "line " << l << std::endl;
+  if (l > 0)
+    {
+      octave_stdout << "line " << l << std::endl;
 
-          if (have_file)
-            {
-              std::string line = get_file_line (name, l);
+      if (have_file)
+        {
+          std::string line = get_file_line (name, l);
 
-              if (! line.empty ())
-                octave_stdout << l << ": " << line << std::endl;
-            }
+          if (! line.empty ())
+            octave_stdout << l << ": " << line << std::endl;
         }
-      else
-        octave_stdout << "<unknown line>" << std::endl;
     }
   else
-    error ("dbwhere: must be inside a user function to use dbwhere\n");
+    octave_stdout << "<unknown line>" << std::endl;
 
-  return retval;
+  return ovl ();
 }
 
 void
@@ -863,27 +848,23 @@
   std::string ff = fcn_file_in_path (name);
 
   if (! ff.empty ())
-    {
-      std::ifstream fs (ff.c_str (), std::ios::in);
+    os << "dbtype: unknown function " << name << "\n";
 
-      if (fs)
-        {
-          int line = 1;
-          std::string text;
+  std::ifstream fs (ff.c_str (), std::ios::in);
+
+  if (! fs)
+    os << "dbtype: unable to open '" << ff << "' for reading!\n";
 
-          while (std::getline (fs, text) && line <= end)
-            {
-              if (line >= start)
-                os << line << "\t" << text << "\n";
+  int line = 1;
+  std::string text;
 
-              line++;
-            }
-        }
-      else
-        os << "dbtype: unable to open '" << ff << "' for reading!\n";
+  while (std::getline (fs, text) && line <= end)
+    {
+      if (line >= start)
+        os << line << "\t" << text << "\n";
+
+      line++;
     }
-  else
-    os << "dbtype: unknown function " << name << "\n";
 
   os.flush ();
 }
@@ -912,7 +893,6 @@
 @seealso{dbwhere, dbstatus, dbstop}\n\
 @end deftypefn")
 {
-  octave_value retval;
   octave_user_code *dbg_fcn;
 
   string_vector argv = args.make_argv ("dbtype");
@@ -992,50 +972,47 @@
       break;
 
     case 2: // (dbtype func start:end) || (dbtype func start)
-      dbg_fcn = get_user_code (argv[1]);
+      {
+        dbg_fcn = get_user_code (argv[1]);
+
+        if (! dbg_fcn)
+          error ("dbtype: function <%s> not found\n", argv[1].c_str ());
 
-      if (dbg_fcn)
-        {
-          std::string arg = argv[2];
-          int start, end;
-          size_t ind = arg.find (':');
+        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);
+        if (ind != std::string::npos)
+          {
+            std::string start_str = arg.substr (0, ind);
+            std::string end_str = arg.substr (ind + 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;
-            }
+            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 (std::min (start, end) <= 0)
-            error ("dbtype: start and end lines must be >= 1\n");
+        if (std::min (start, end) <= 0)
+          error ("dbtype: start and end lines must be >= 1\n");
+        else if (start > end)
+          error ("dbtype: start line must be less than end line\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 ());
-
+        do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (), start, end);
+      }
       break;
 
     default:
       error ("dbtype: expecting zero, one, or two arguments\n");
     }
 
-  return retval;
+  return ovl ();
 }
 
 DEFUN (dblist, args, ,
@@ -1049,8 +1026,6 @@
 @seealso{dbwhere, dbtype}\n\
 @end deftypefn")
 {
-  octave_value retval;
-
   int n = 10;
 
   if (args.length () == 1)
@@ -1072,45 +1047,43 @@
 
   octave_user_code *dbg_fcn = get_user_code ();
 
-  if (dbg_fcn)
-    {
-      bool have_file = true;
+  if (! dbg_fcn)
+    error ("dblist: must be inside a user function to use dblist\n");
 
-      std::string name = dbg_fcn->fcn_file_name ();
+  bool have_file = true;
+
+  std::string name = dbg_fcn->fcn_file_name ();
 
-      if (name.empty ())
-        {
-          have_file = false;
-          name = dbg_fcn->name ();
-        }
+  if (name.empty ())
+    {
+      have_file = false;
+      name = dbg_fcn->name ();
+    }
 
-      int l = octave_call_stack::caller_user_code_line ();
+  int l = octave_call_stack::caller_user_code_line ();
 
-      if (l > 0)
+  if (l > 0)
+    {
+      if (have_file)
         {
-          if (have_file)
-            {
-              int l_min = std::max (l - n/2, 0);
-              int l_max = l + n/2;
-              do_dbtype (octave_stdout, name, l_min, l-1);
+          int l_min = std::max (l - n/2, 0);
+          int l_max = l + n/2;
+          do_dbtype (octave_stdout, name, l_min, l-1);
 
-              std::string line = get_file_line (name, l);
-              if (! line.empty ())
-                octave_stdout << l << "-->\t" << line << std::endl;
+          std::string line = get_file_line (name, l);
+          if (! line.empty ())
+            octave_stdout << l << "-->\t" << line << std::endl;
 
-              do_dbtype (octave_stdout, name, l+1, l_max);
-            }
-        }
-      else
-        {
-          octave_stdout << "dblist: unable to determine source code line"
-                        << std::endl;
+          do_dbtype (octave_stdout, name, l+1, l_max);
         }
     }
   else
-    error ("dblist: must be inside a user function to use dblist\n");
+    {
+      octave_stdout << "dblist: unable to determine source code line"
+                    << std::endl;
+    }
 
-  return retval;
+  return ovl ();
 }
 
 static octave_value_list
@@ -1207,21 +1180,18 @@
     }
   else
     {
-      octave_map stk = octave_call_stack::backtrace (nskip,
-                                                     curr_frame,
-                                                     false);
+      octave_map stk = octave_call_stack::backtrace (nskip, curr_frame, false);
 
-      retval = ovl (stk,
-                    curr_frame < 0 ? 1 : curr_frame + 1);
+      retval = ovl (stk, curr_frame < 0 ? 1 : curr_frame + 1);
     }
 
   return retval;
 }
 
-// A function that can be easily called from a debugger print the Octave
-// stack.  This can be useful for finding what line of code the
-// interpreter is currently executing when the debugger is stopped in
-// some C++ function, for example.
+// A function that can be easily called from a debugger print the Octave stack.
+// This can be useful for finding what line of code the interpreter is
+// currently executing when the debugger is stopped in some C++ function,
+// for example.
 
 void
 show_octave_dbstack (void)
@@ -1312,11 +1282,9 @@
 @seealso{dbstack, dbdown}\n\
 @end deftypefn")
 {
-  octave_value retval;
-
   do_dbupdown (args, "dbup");
 
-  return retval;
+  return ovl ();
 }
 
 DEFUN (dbdown, args, ,
@@ -1329,11 +1297,9 @@
 @seealso{dbstack, dbup}\n\
 @end deftypefn")
 {
-  octave_value retval;
-
   do_dbupdown (args, "dbdown");
 
-  return retval;
+  return ovl ();
 }
 
 DEFUN (dbstep, args, ,
@@ -1387,14 +1353,12 @@
         {
           int n = atoi (arg.c_str ());
 
-          if (n > 0)
-            {
-              Vdebugging = false;
+          if (n < 1)
+            error ("dbstep: invalid argument");
 
-              tree_evaluator::dbstep_flag = n;
-            }
-          else
-            error ("dbstep: invalid argument");
+          Vdebugging = false;
+
+          tree_evaluator::dbstep_flag = n;
         }
     }
   else