Mercurial > octave
changeset 20879:5357423bca0a
Code Sprint 2015: remove return/break/goto after error
author | Andreas Weber <andy.weber.aw@gmail.com> |
---|---|
date | Sat, 12 Dec 2015 20:54:01 +0100 |
parents | 90f241188941 |
children | 40da964c3add |
files | libinterp/octave-value/ov-base.cc libinterp/octave-value/ov-bool-sparse.cc libinterp/octave-value/ov-bool.cc libinterp/octave-value/ov-cell.cc libinterp/octave-value/ov-class.cc |
diffstat | 5 files changed, 40 insertions(+), 154 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-base.cc Sat Dec 12 11:21:58 2015 -0800 +++ b/libinterp/octave-value/ov-base.cc Sat Dec 12 20:54:01 2015 +0100 @@ -128,7 +128,6 @@ { std::string nm = type_name (); error ("squeeze: invalid operation for %s type", nm.c_str ()); - return octave_value (); } octave_value @@ -160,7 +159,6 @@ { std::string nm = type_name (); error ("can't perform indexing operations for %s type", nm.c_str ()); - return octave_value (); } octave_value_list @@ -169,7 +167,6 @@ { std::string nm = type_name (); error ("can't perform indexing operations for %s type", nm.c_str ()); - return octave_value (); } octave_value @@ -196,7 +193,6 @@ { std::string nm = type_name (); error ("can't perform indexing operations for %s type", nm.c_str ()); - return octave_value (); } octave_value_list @@ -204,7 +200,6 @@ { std::string nm = type_name (); error ("can't perform indexing operations for %s type", nm.c_str ()); - return octave_value (); } octave_value_list @@ -946,16 +941,12 @@ octave_scalar_map octave_base_value::scalar_map_value (void) const { - octave_scalar_map retval; - octave_map tmp = map_value (); - if (tmp.numel () == 1) - retval = tmp.checkelem (0); - else + if (tmp.numel () != 1) error ("invalid conversion of multi-dimensional struct to scalar struct"); - return retval; + return octave_scalar_map (tmp.checkelem (0)); } string_vector @@ -1286,7 +1277,6 @@ octave_base_value::map (unary_mapper_t umap) const { error ("%s: not defined for %s", get_umap_name (umap), type_name ().c_str ()); - return octave_value (); } void @@ -1342,10 +1332,7 @@ octave_value retval; if (idx.front ().empty ()) - { - error ("missing index in indexed assignment"); - return retval; - } + error ("missing index in indexed assignment"); int t_lhs = type_id (); int t_rhs = rhs.type_id (); @@ -1621,16 +1608,10 @@ if (val.is_string ()) subs_field(i) = val; else - { - error ("string argument required for '.' index"); - return retval; - } + error ("string argument required for '.' index"); } else - { - error ("only single argument permitted for '.' index"); - return retval; - } + error ("only single argument permitted for '.' index"); } break;
--- a/libinterp/octave-value/ov-bool-sparse.cc Sat Dec 12 11:21:58 2015 -0800 +++ b/libinterp/octave-value/ov-bool-sparse.cc Sat Dec 12 20:54:01 2015 +0100 @@ -276,10 +276,7 @@ swap_bytes<4> (&tmp); if (tmp != -2) - { - error ("load: only 2-D sparse matrices are supported"); - return false; - } + error ("load: only 2-D sparse matrices are supported"); if (! is.read (reinterpret_cast<char *> (&nr), 4)) return false;
--- a/libinterp/octave-value/ov-bool.cc Sat Dec 12 11:21:58 2015 -0800 +++ b/libinterp/octave-value/ov-bool.cc Sat Dec 12 20:54:01 2015 +0100 @@ -130,10 +130,7 @@ scalar = (octave_read_value<double> (is) != 0.); if (!is) - { - error ("load: failed to load scalar constant"); - return false; - } + error ("load: failed to load scalar constant"); return true; }
--- a/libinterp/octave-value/ov-cell.cc Sat Dec 12 11:21:58 2015 -0800 +++ b/libinterp/octave-value/ov-cell.cc Sat Dec 12 20:54:01 2015 +0100 @@ -239,10 +239,7 @@ clear_cellstr_cache (); if (idx.front ().empty ()) - { - error ("missing index in indexed assignment"); - return retval; - } + error ("missing index in indexed assignment"); if (n > 1) { @@ -546,7 +543,6 @@ octave_cell::is_true (void) const { error ("invalid conversion from cell array to logical value"); - return false; } octave_value_list @@ -770,8 +766,6 @@ bool octave_cell::load_ascii (std::istream& is) { - bool success = true; - clear_cellstr_cache (); string_vector keywords(2); @@ -813,26 +807,16 @@ tmp.elem (i) = t2; } else - { - error ("load: cell array element had unexpected name"); - success = false; - break; - } + error ("load: cell array element had unexpected name"); } if (is) matrix = tmp; else - { - error ("load: failed to load matrix constant"); - success = false; - } + error ("load: failed to load matrix constant"); } else - { - error ("load: failed to extract number of rows and columns"); - success = false; - } + error ("load: failed to extract number of rows and columns"); } else if (kw == "rows") { @@ -862,23 +846,14 @@ tmp.elem (i, j) = t2; } else - { - error ("load: cell array element had unexpected name"); - success = false; - goto cell_read_error; - } + error ("load: cell array element had unexpected name"); } } - cell_read_error: - if (is) matrix = tmp; else - { - error ("load: failed to load cell element"); - success = false; - } + error ("load: failed to load cell element"); } else if (nr == 0 || nc == 0) matrix = Cell (nr, nc); @@ -886,21 +861,15 @@ panic_impossible (); } else - { - error ("load: failed to extract number of rows and columns for cell array"); - success = false; - } + error ("load: failed to extract number of rows and columns for cell array"); } else panic_impossible (); } else - { - error ("load: failed to extract number of rows and columns"); - success = false; - } + error ("load: failed to extract number of rows and columns"); - return success; + return true; } bool @@ -942,7 +911,6 @@ { clear_cellstr_cache (); - bool success = true; int32_t mdims; if (! is.read (reinterpret_cast<char *> (&mdims), 4)) return false; @@ -996,22 +964,15 @@ tmp.elem (i) = t2; } else - { - error ("load: cell array element had unexpected name"); - success = false; - break; - } + error ("load: cell array element had unexpected name"); } if (is) matrix = tmp; else - { - error ("load: failed to load matrix constant"); - success = false; - } + error ("load: failed to load matrix constant"); - return success; + return true; } void *
--- a/libinterp/octave-value/ov-class.cc Sat Dec 12 11:21:58 2015 -0800 +++ b/libinterp/octave-value/ov-class.cc Sat Dec 12 20:54:01 2015 +0100 @@ -276,10 +276,7 @@ octave_base_value *obvp = find_parent_class (method_class); if (obvp == 0) - { - error ("malformed class"); - return retval; - } + error ("malformed class"); octave_map my_map = (obvp != this) ? obvp->map_value () : map; @@ -1225,7 +1222,6 @@ { octave_idx_type len = 0; std::string classname; - bool success = true; if (extract_keyword (is, "classname", classname) && classname != "") { @@ -1272,10 +1268,7 @@ } } else - { - error ("load: failed to load class"); - success = false; - } + error ("load: failed to load class"); } else if (len == 0) { @@ -1286,18 +1279,12 @@ panic_impossible (); } else - { - error ("load: failed to extract number of elements in class"); - success = false; - } + error ("load: failed to extract number of elements in class"); } else - { - error ("load: failed to extract name of class"); - success = false; - } + error ("load: failed to extract name of class"); - return success; + return true; } bool @@ -1697,7 +1684,6 @@ bool octave_class::exemplar_info::compare (const octave_value& obj) const { - bool retval = true; if (obj.is_object ()) { @@ -1710,11 +1696,7 @@ for (octave_idx_type i = 0; i < nfields (); i++) { if (obj_fnames[i] != fnames[i]) - { - retval = false; - error ("mismatch in field names"); - break; - } + error ("mismatch in field names"); } if (nparents () == obj.nparents ()) @@ -1729,32 +1711,19 @@ while (p != obj_parents.end ()) { if (*p++ != *q++) - { - retval = false; - error ("mismatch in parent classes"); - break; - } + error ("mismatch in parent classes"); } } else - { - retval = false; - error ("mismatch in number of parent classes"); - } + error ("mismatch in number of parent classes"); } else - { - retval = false; - error ("mismatch in number of fields"); - } + error ("mismatch in number of fields"); } else - { - retval = false; - error ("invalid comparison of class exemplar to non-class object"); - } + error ("invalid comparison of class exemplar to non-class object"); - return retval; + return true; } DEFUN (class, args, , @@ -2080,14 +2049,9 @@ @seealso{inferiorto}\n\ @end deftypefn") { - octave_value retval; - octave_function *fcn = octave_call_stack::caller (); if ((! fcn) || (! fcn->is_class_constructor ())) - { - error ("superiorto: invalid call from outside class constructor"); - return retval; - } + error ("superiorto: invalid call from outside class constructor"); for (int i = 0; i < args.length (); i++) { @@ -2100,14 +2064,11 @@ std::string sup_class = fcn->name (); if (! symbol_table::set_class_relationship (sup_class, inf_class)) - { - error ("superiorto: opposite precedence already set for %s and %s", - sup_class.c_str (), inf_class.c_str ()); - break; - } + error ("superiorto: opposite precedence already set for %s and %s", + sup_class.c_str (), inf_class.c_str ()); } - return retval; + return octave_value (); } DEFUN (inferiorto, args, , @@ -2121,34 +2082,23 @@ @seealso{superiorto}\n\ @end deftypefn") { - octave_value retval; - octave_function *fcn = octave_call_stack::caller (); if ((! fcn) || (! fcn->is_class_constructor ())) - { - error ("inferiorto: invalid call from outside class constructor"); - return retval; - } + error ("inferiorto: invalid call from outside class constructor"); for (int i = 0; i < args.length (); i++) { std::string sup_class = args(i).xstring_value ("inferiorto: CLASS_NAME must be a string"); if (is_built_in_class (sup_class)) - { - error ("inferiorto: cannot give user-defined class lower " - "precedence than built-in class"); - break; - } + error ("inferiorto: cannot give user-defined class lower " + "precedence than built-in class"); std::string inf_class = fcn->name (); if (! symbol_table::set_class_relationship (sup_class, inf_class)) - { - error ("inferiorto: opposite precedence already set for %s and %s", - inf_class.c_str (), sup_class.c_str ()); - break; - } + error ("inferiorto: opposite precedence already set for %s and %s", + inf_class.c_str (), sup_class.c_str ()); } - return retval; + return octave_value(); }