changeset 20832:3951d420556c

eliminate return statements after calls to error * pt-assign.cc, pt-cell.cc, pt-colon.cc, pt-mat.cc, pt-misc.cc: Eliminate return statements after calls to error.
author John W. Eaton <jwe@octave.org>
date Wed, 09 Dec 2015 14:18:52 -0500
parents 35241c4b696c
children 9c4c87679985
files libinterp/parse-tree/pt-assign.cc libinterp/parse-tree/pt-cell.cc libinterp/parse-tree/pt-colon.cc libinterp/parse-tree/pt-mat.cc libinterp/parse-tree/pt-misc.cc
diffstat 5 files changed, 59 insertions(+), 101 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-assign.cc	Wed Dec 09 14:00:43 2015 -0500
+++ b/libinterp/parse-tree/pt-assign.cc	Wed Dec 09 14:18:52 2015 -0500
@@ -62,14 +62,10 @@
 octave_value_list
 tree_simple_assignment::rvalue (int nargout)
 {
-  octave_value_list retval;
-
   if (nargout > 1)
     error ("invalid number of output arguments for expression X = RHS");
-  else
-    retval = rvalue1 (nargout);
 
-  return retval;
+  return rvalue1 (nargout);
 }
 
 octave_value
@@ -82,62 +78,54 @@
       octave_value rhs_val = rhs->rvalue1 ();
 
       if (rhs_val.is_undefined ())
+        error ("value on right hand side of assignment is undefined");
+
+      if (rhs_val.is_cs_list ())
         {
-          error ("value on right hand side of assignment is undefined");
-          return retval;
-        }
-      else
-        {
-          if (rhs_val.is_cs_list ())
-            {
-              const octave_value_list lst = rhs_val.list_value ();
+          const octave_value_list lst = rhs_val.list_value ();
 
-              if (! lst.empty ())
-                rhs_val = lst(0);
-              else
-                {
-                  error ("invalid number of elements on RHS of assignment");
-                  return retval;
-                }
-            }
+          if (! lst.empty ())
+            rhs_val = lst(0);
+          else
+            error ("invalid number of elements on RHS of assignment");
+        }
 
-          try
-            {
-              octave_lvalue ult = lhs->lvalue ();
+      try
+        {
+          octave_lvalue ult = lhs->lvalue ();
 
-              if (ult.numel () != 1)
-                gripe_nonbraced_cs_list_assignment ();
+          if (ult.numel () != 1)
+            gripe_nonbraced_cs_list_assignment ();
 
-              ult.assign (etype, rhs_val);
+          ult.assign (etype, rhs_val);
 
-              if (etype == octave_value::op_asn_eq)
-                retval = rhs_val;
-              else
-                retval = ult.value ();
+          if (etype == octave_value::op_asn_eq)
+            retval = rhs_val;
+          else
+            retval = ult.value ();
 
-              if (print_result ()
-                  && tree_evaluator::statement_printing_enabled ())
-                {
-                  // We clear any index here so that we can
-                  // get the new value of the referenced
-                  // object below, instead of the indexed
-                  // value (which should be the same as the
-                  // right hand side value).
+          if (print_result ()
+              && tree_evaluator::statement_printing_enabled ())
+            {
+              // We clear any index here so that we can
+              // get the new value of the referenced
+              // object below, instead of the indexed
+              // value (which should be the same as the
+              // right hand side value).
 
-                  ult.clear_index ();
+              ult.clear_index ();
 
-                  octave_value lhs_val = ult.value ();
+              octave_value lhs_val = ult.value ();
 
-                  lhs_val.print_with_name (octave_stdout,
-                                           lhs->name ());
-                }
+              lhs_val.print_with_name (octave_stdout,
+                                       lhs->name ());
             }
-          catch (index_exception& e)
-            {
-              e.set_var (lhs->name ());
-              std::string msg = e.message ();
-              error_with_id (e.err_id (), msg.c_str ());
-            }
+        }
+      catch (index_exception& e)
+        {
+          e.set_var (lhs->name ());
+          std::string msg = e.message ();
+          error_with_id (e.err_id (), msg.c_str ());
         }
     }
 
--- a/libinterp/parse-tree/pt-cell.cc	Wed Dec 09 14:00:43 2015 -0500
+++ b/libinterp/parse-tree/pt-cell.cc	Wed Dec 09 14:18:52 2015 -0500
@@ -70,10 +70,7 @@
               if (this_nc == 0)
                 continue;  // blank line
               else
-                {
-                  error ("number of columns must match");
-                  return retval;
-                }
+                error ("number of columns must match");
             }
         }
 
@@ -93,14 +90,10 @@
 octave_value_list
 tree_cell::rvalue (int nargout)
 {
-  octave_value_list retval;
-
   if (nargout > 1)
     error ("invalid number of output arguments for cell array");
-  else
-    retval = rvalue1 (nargout);
 
-  return retval;
+  return rvalue1 (nargout);
 }
 
 tree_expression *
--- a/libinterp/parse-tree/pt-colon.cc	Wed Dec 09 14:00:43 2015 -0500
+++ b/libinterp/parse-tree/pt-colon.cc	Wed Dec 09 14:18:52 2015 -0500
@@ -45,16 +45,14 @@
         {
           if (op_increment)
             error ("invalid colon expression");
-          else
-            {
-              // Stupid syntax:
-              //
-              // base : limit
-              // base : increment : limit
 
-              op_increment = op_limit;
-              op_limit = t;
-            }
+          // Stupid syntax:
+          //
+          // base : limit
+          // base : increment : limit
+
+          op_increment = op_limit;
+          op_limit = t;
         }
       else
         op_limit = t;
@@ -70,14 +68,10 @@
 octave_value_list
 tree_colon_expression::rvalue (int nargout)
 {
-  octave_value_list retval;
-
   if (nargout > 1)
     error ("invalid number of output arguments for colon expression");
-  else
-    retval = rvalue1 (nargout);
 
-  return retval;
+  return rvalue1 (nargout);
 }
 
 octave_value
--- a/libinterp/parse-tree/pt-mat.cc	Wed Dec 09 14:00:43 2015 -0500
+++ b/libinterp/parse-tree/pt-mat.cc	Wed Dec 09 14:18:52 2015 -0500
@@ -274,6 +274,10 @@
 }
 
 static void
+eval_error (const char *msg, const dim_vector& x,
+            const dim_vector& y) GCC_ATTR_NORETURN;
+
+static void
 eval_error (const char *msg, const dim_vector& x, const dim_vector& y)
 {
   error ("%s (%s vs %s)", msg, x.str ().c_str (), y.str ().c_str ());
@@ -406,10 +410,7 @@
               dv = this_elt_dv;
             }
           else if ((! any_class) && (! dv.hvcat (this_elt_dv, 1)))
-            {
-              eval_error ("horizontal dimensions mismatch", dv, this_elt_dv);
-              break;
-            }
+            eval_error ("horizontal dimensions mismatch", dv, this_elt_dv);
         }
     }
 
@@ -453,11 +454,7 @@
                   dv = this_elt_dv;
                 }
               else if (! dv.hvcat (this_elt_dv, 1))
-                {
-                  eval_error ("horizontal dimensions mismatch",
-                              dv, this_elt_dv);
-                  break;
-                }
+                eval_error ("horizontal dimensions mismatch", dv, this_elt_dv);
             }
         }
     }
@@ -647,10 +644,7 @@
           dv(0) += this_elt_nr;
         }
       else if ((!any_class) && (!dv.hvcat (this_elt_dv, 0)))
-        {
-          eval_error ("vertical dimensions mismatch", dv, this_elt_dv);
-          return;
-        }
+        eval_error ("vertical dimensions mismatch", dv, this_elt_dv);
     }
 
   ok = true;
@@ -659,14 +653,10 @@
 octave_value_list
 tree_matrix::rvalue (int nargout)
 {
-  octave_value_list retval;
-
   if (nargout > 1)
     error ("invalid number of output arguments for matrix list");
-  else
-    retval = rvalue1 (nargout);
 
-  return retval;
+  return rvalue1 (nargout);
 }
 
 void
--- a/libinterp/parse-tree/pt-misc.cc	Wed Dec 09 14:00:43 2015 -0500
+++ b/libinterp/parse-tree/pt-misc.cc	Wed Dec 09 14:18:52 2015 -0500
@@ -81,12 +81,8 @@
                 error ("invalid use of ~ in output list");
             }
           else if (dict.find (name) != dict.end ())
-            {
-              retval = false;
-              error ("'%s' appears more than once in parameter list",
-                     name.c_str ());
-              break;
-            }
+            error ("'%s' appears more than once in parameter list",
+                   name.c_str ());
           else
             dict.insert (name);
         }
@@ -194,10 +190,7 @@
           if (args(i).is_defined () && args(i).is_magic_colon ())
             {
               if (! elt->eval ())
-                {
-                  error ("no default value for argument %d", i+1);
-                  return;
-                }
+                error ("no default value for argument %d", i+1);
             }
           else
             ref.define (args(i));