# HG changeset patch # User John W. Eaton # Date 1444091839 14400 # Node ID b10432a40432297c1c97f39ec1bb410307d0241d # Parent 4bed806ee3d46878babfa79138ac97a88e8220f7 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. diff -r 4bed806ee3d4 -r b10432a40432 libinterp/corefcn/dasrt.cc --- a/libinterp/corefcn/dasrt.cc Mon Oct 05 20:21:55 2015 -0400 +++ b/libinterp/corefcn/dasrt.cc Mon Oct 05 20:37:19 2015 -0400 @@ -448,27 +448,24 @@ { string_vector tmp = args(0).all_strings (); - if (! error_state) - { - fcn_name = unique_symbol_name ("__dasrt_fcn__"); - fname = "function y = "; - fname.append (fcn_name); - fname.append (" (x, xdot, t) y = "); - dasrt_f = extract_function (tmp(0), "dasrt", fcn_name, - fname, "; endfunction"); + fcn_name = unique_symbol_name ("__dasrt_fcn__"); + fname = "function y = "; + fname.append (fcn_name); + fname.append (" (x, xdot, t) y = "); + dasrt_f = extract_function (tmp(0), "dasrt", fcn_name, + fname, "; endfunction"); - if (dasrt_f) - { - jac_name = unique_symbol_name ("__dasrt_jac__"); - jname = "function jac = "; - jname.append (jac_name); - jname.append (" (x, xdot, t, cj) jac = "); - dasrt_j = extract_function (tmp(1), "dasrt", jac_name, - jname, "; endfunction"); + if (dasrt_f) + { + jac_name = unique_symbol_name ("__dasrt_jac__"); + jname = "function jac = "; + jname.append (jac_name); + jname.append (" (x, xdot, t, cj) jac = "); + dasrt_j = extract_function (tmp(1), "dasrt", jac_name, + jname, "; endfunction"); - if (! dasrt_j) - dasrt_f = 0; - } + if (! dasrt_j) + dasrt_f = 0; } } break; @@ -560,28 +557,25 @@ if (jac_name.length ()) clear_function (jac_name); - if (! error_state) - { - std::string msg = dae.error_message (); + std::string msg = dae.error_message (); - retval(4) = msg; - retval(3) = static_cast (dae.integration_state ()); + retval(4) = msg; + retval(3) = static_cast (dae.integration_state ()); - if (dae.integration_ok ()) - { - retval(2) = output.times (); - retval(1) = output.deriv (); - retval(0) = output.state (); - } - else - { - retval(2) = Matrix (); - retval(1) = Matrix (); - retval(0) = Matrix (); + if (dae.integration_ok ()) + { + retval(2) = output.times (); + retval(1) = output.deriv (); + retval(0) = output.state (); + } + else + { + retval(2) = Matrix (); + retval(1) = Matrix (); + retval(0) = Matrix (); - if (nargout < 4) - error ("dasrt: %s", msg.c_str ()); - } + if (nargout < 4) + error ("dasrt: %s", msg.c_str ()); } return retval; diff -r 4bed806ee3d4 -r b10432a40432 libinterp/corefcn/debug.cc --- 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 (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::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::max (); + else + end = atoi (end_str.c_str ()); - if (dbg_fcn) - do_dbtype (octave_stdout, dbg_fcn->fcn_file_name (), - 0, std::numeric_limits::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::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::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::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::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::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, , diff -r 4bed806ee3d4 -r b10432a40432 libinterp/corefcn/find.cc --- a/libinterp/corefcn/find.cc Mon Oct 05 20:21:55 2015 -0400 +++ b/libinterp/corefcn/find.cc Mon Oct 05 20:37:19 2015 -0400 @@ -424,13 +424,10 @@ std::string s_arg = args(2).string_value (); - if (! error_state) - { - if (s_arg == "first") - direction = 1; - else if (s_arg == "last") - direction = -1; - } + if (s_arg == "first") + direction = 1; + else if (s_arg == "last") + direction = -1; if (direction == 0) { @@ -447,9 +444,7 @@ { SparseBoolMatrix v = arg.sparse_bool_matrix_value (); - if (! error_state) - retval = find_nonzero_elem_idx (v, nargout, - n_to_find, direction); + retval = find_nonzero_elem_idx (v, nargout, n_to_find, direction); } else if (nargout <= 1 && n_to_find == -1 && direction == 1) { @@ -466,9 +461,7 @@ { boolNDArray v = arg.bool_array_value (); - if (! error_state) - retval = find_nonzero_elem_idx (v, nargout, - n_to_find, direction); + retval = find_nonzero_elem_idx (v, nargout, n_to_find, direction); } } else if (arg.is_integer_type ()) @@ -477,10 +470,8 @@ else if (arg.is_ ## INTT ## _type ()) \ { \ INTT ## NDArray v = arg.INTT ## _array_value (); \ - \ - if (! error_state) \ - retval = find_nonzero_elem_idx (v, nargout, \ - n_to_find, direction);\ + \ + retval = find_nonzero_elem_idx (v, nargout, n_to_find, direction); \ } if (false) @@ -502,17 +493,13 @@ { SparseMatrix v = arg.sparse_matrix_value (); - if (! error_state) - retval = find_nonzero_elem_idx (v, nargout, - n_to_find, direction); + retval = find_nonzero_elem_idx (v, nargout, n_to_find, direction); } else if (arg.is_complex_type ()) { SparseComplexMatrix v = arg.sparse_complex_matrix_value (); - if (! error_state) - retval = find_nonzero_elem_idx (v, nargout, - n_to_find, direction); + retval = find_nonzero_elem_idx (v, nargout, n_to_find, direction); } else gripe_wrong_type_arg ("find", arg); @@ -521,15 +508,13 @@ { PermMatrix P = arg.perm_matrix_value (); - if (! error_state) - retval = find_nonzero_elem_idx (P, nargout, n_to_find, direction); + retval = find_nonzero_elem_idx (P, nargout, n_to_find, direction); } else if (arg.is_string ()) { charNDArray chnda = arg.char_array_value (); - if (! error_state) - retval = find_nonzero_elem_idx (chnda, nargout, n_to_find, direction); + retval = find_nonzero_elem_idx (chnda, nargout, n_to_find, direction); } else if (arg.is_single_type ()) { @@ -537,32 +522,26 @@ { FloatNDArray nda = arg.float_array_value (); - if (! error_state) - retval = find_nonzero_elem_idx (nda, nargout, n_to_find, - direction); + retval = find_nonzero_elem_idx (nda, nargout, n_to_find, direction); } else if (arg.is_complex_type ()) { FloatComplexNDArray cnda = arg.float_complex_array_value (); - if (! error_state) - retval = find_nonzero_elem_idx (cnda, nargout, n_to_find, - direction); + retval = find_nonzero_elem_idx (cnda, nargout, n_to_find, direction); } } else if (arg.is_real_type ()) { NDArray nda = arg.array_value (); - if (! error_state) - retval = find_nonzero_elem_idx (nda, nargout, n_to_find, direction); + retval = find_nonzero_elem_idx (nda, nargout, n_to_find, direction); } else if (arg.is_complex_type ()) { ComplexNDArray cnda = arg.complex_array_value (); - if (! error_state) - retval = find_nonzero_elem_idx (cnda, nargout, n_to_find, direction); + retval = find_nonzero_elem_idx (cnda, nargout, n_to_find, direction); } else gripe_wrong_type_arg ("find", arg); diff -r 4bed806ee3d4 -r b10432a40432 libinterp/corefcn/gammainc.cc --- a/libinterp/corefcn/gammainc.cc Mon Oct 05 20:21:55 2015 -0400 +++ b/libinterp/corefcn/gammainc.cc Mon Oct 05 20:37:19 2015 -0400 @@ -99,113 +99,87 @@ } - if (!error_state && nargin >= 2 && nargin <= 3) - { - octave_value x_arg = args(0); - octave_value a_arg = args(1); + if (nargin < 2 || nargin > 3) + print_usage (); - // FIXME: Can we make a template version of the duplicated code below - if (x_arg.is_single_type () || a_arg.is_single_type ()) - { - if (x_arg.is_scalar_type ()) - { - float x = x_arg.float_value (); + octave_value x_arg = args(0); + octave_value a_arg = args(1); - if (! error_state) - { - if (a_arg.is_scalar_type ()) - { - float a = a_arg.float_value (); + // FIXME: Can we make a template version of the duplicated code below + if (x_arg.is_single_type () || a_arg.is_single_type ()) + { + if (x_arg.is_scalar_type ()) + { + float x = x_arg.float_value (); - if (! error_state) - retval = lower ? gammainc (x, a) - : 1.0f - gammainc (x, a); - } - else - { - FloatNDArray a = a_arg.float_array_value (); + if (a_arg.is_scalar_type ()) + { + float a = a_arg.float_value (); - if (! error_state) - retval = lower ? gammainc (x, a) - : 1.0f - gammainc (x, a); - } - } + retval = lower ? gammainc (x, a) : 1.0f - gammainc (x, a); } else { - FloatNDArray x = x_arg.float_array_value (); - - if (! error_state) - { - if (a_arg.is_scalar_type ()) - { - float a = a_arg.float_value (); + FloatNDArray a = a_arg.float_array_value (); - if (! error_state) - retval = lower ? gammainc (x, a) - : 1.0f - gammainc (x, a); - } - else - { - FloatNDArray a = a_arg.float_array_value (); - - if (! error_state) - retval = lower ? gammainc (x, a) - : 1.0f - gammainc (x, a); - } - } + retval = lower ? gammainc (x, a) : 1.0f - gammainc (x, a); } } else { - if (x_arg.is_scalar_type ()) - { - double x = x_arg.double_value (); - - if (! error_state) - { - if (a_arg.is_scalar_type ()) - { - double a = a_arg.double_value (); + FloatNDArray x = x_arg.float_array_value (); - if (! error_state) - retval = lower ? gammainc (x, a) : 1. - gammainc (x, a); - } - else - { - NDArray a = a_arg.array_value (); + if (a_arg.is_scalar_type ()) + { + float a = a_arg.float_value (); - if (! error_state) - retval = lower ? gammainc (x, a) : 1. - gammainc (x, a); - } - } + retval = lower ? gammainc (x, a) : 1.0f - gammainc (x, a); } else { - NDArray x = x_arg.array_value (); - - if (! error_state) - { - if (a_arg.is_scalar_type ()) - { - double a = a_arg.double_value (); + FloatNDArray a = a_arg.float_array_value (); - if (! error_state) - retval = lower ? gammainc (x, a) : 1. - gammainc (x, a); - } - else - { - NDArray a = a_arg.array_value (); - - if (! error_state) - retval = lower ? gammainc (x, a) : 1. - gammainc (x, a); - } - } + retval = lower ? gammainc (x, a) : 1.0f - gammainc (x, a); } } } else - print_usage (); + { + if (x_arg.is_scalar_type ()) + { + double x = x_arg.double_value (); + + if (a_arg.is_scalar_type ()) + { + double a = a_arg.double_value (); + + retval = lower ? gammainc (x, a) : 1. - gammainc (x, a); + } + else + { + NDArray a = a_arg.array_value (); + + retval = lower ? gammainc (x, a) : 1. - gammainc (x, a); + } + } + else + { + NDArray x = x_arg.array_value (); + + if (a_arg.is_scalar_type ()) + { + double a = a_arg.double_value (); + + retval = lower ? gammainc (x, a) : 1. - gammainc (x, a); + } + else + { + NDArray a = a_arg.array_value (); + + retval = lower ? gammainc (x, a) : 1. - gammainc (x, a); + } + } + } return retval; } diff -r 4bed806ee3d4 -r b10432a40432 libinterp/corefcn/matrix_type.cc --- a/libinterp/corefcn/matrix_type.cc Mon Oct 05 20:21:55 2015 -0400 +++ b/libinterp/corefcn/matrix_type.cc Mon Oct 05 20:37:19 2015 -0400 @@ -157,11 +157,9 @@ { SparseComplexMatrix m = args(0).sparse_complex_matrix_value (); - if (!error_state) - { - mattyp = MatrixType (m); - args(0).matrix_type (mattyp); - } + + mattyp = MatrixType (m); + args(0).matrix_type (mattyp); } } else @@ -171,11 +169,9 @@ if (mattyp.is_unknown () && autocomp) { SparseMatrix m = args(0).sparse_matrix_value (); - if (!error_state) - { - mattyp = MatrixType (m); - args(0).matrix_type (mattyp); - } + + mattyp = MatrixType (m); + args(0).matrix_type (mattyp); } } @@ -280,54 +276,46 @@ else error ("matrix_type: Unknown matrix type %s", str_typ.c_str ()); - if (! error_state) + if (nargin == 3 + && (str_typ == "upper" || str_typ == "lower")) { - if (nargin == 3 - && (str_typ == "upper" || str_typ == "lower")) + const ColumnVector perm = + ColumnVector (args(2).vector_value ()); + + if (error_state) + error ("matrix_type: Invalid permutation vector PERM"); + else { - const ColumnVector perm = - ColumnVector (args(2).vector_value ()); + octave_idx_type len = perm.numel (); + dim_vector dv = args(0).dims (); - if (error_state) + if (len != dv(0)) error ("matrix_type: Invalid permutation vector PERM"); else { - octave_idx_type len = perm.numel (); - dim_vector dv = args(0).dims (); + OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len); - if (len != dv(0)) - error ("matrix_type: Invalid permutation vector PERM"); - else - { - OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len); + for (octave_idx_type i = 0; i < len; i++) + p[i] = static_cast + (perm (i)) + - 1; - for (octave_idx_type i = 0; i < len; i++) - p[i] = static_cast - (perm (i)) - - 1; - - mattyp.mark_as_permuted (len, p); - } + mattyp.mark_as_permuted (len, p); } } - else if (nargin != 2 - && str_typ != "banded positive definite" - && str_typ != "banded") - error ("matrix_type: Invalid number of arguments"); + } + else if (nargin != 2 + && str_typ != "banded positive definite" + && str_typ != "banded") + error ("matrix_type: Invalid number of arguments"); - if (! error_state) - { - // Set the matrix type - if (args(0).is_complex_type ()) - retval = - octave_value (args(0).sparse_complex_matrix_value (), - mattyp); - else - retval - = octave_value (args(0).sparse_matrix_value (), - mattyp); - } - } + // Set the matrix type + if (args(0).is_complex_type ()) + retval = octave_value (args(0).sparse_complex_matrix_value (), + mattyp); + else + retval = octave_value (args(0).sparse_matrix_value (), + mattyp); } } } @@ -347,20 +335,16 @@ { FloatComplexMatrix m; m = args(0).float_complex_matrix_value (); - if (!error_state) - { - mattyp = MatrixType (m); - args(0).matrix_type (mattyp); - } + + mattyp = MatrixType (m); + args(0).matrix_type (mattyp); } else { ComplexMatrix m = args(0).complex_matrix_value (); - if (!error_state) - { - mattyp = MatrixType (m); - args(0).matrix_type (mattyp); - } + + mattyp = MatrixType (m); + args(0).matrix_type (mattyp); } } } @@ -373,20 +357,16 @@ if (args(0).is_single_type ()) { FloatMatrix m = args(0).float_matrix_value (); - if (!error_state) - { - mattyp = MatrixType (m); - args(0).matrix_type (mattyp); - } + + mattyp = MatrixType (m); + args(0).matrix_type (mattyp); } else { Matrix m = args(0).matrix_value (); - if (!error_state) - { - mattyp = MatrixType (m); - args(0).matrix_type (mattyp); - } + + mattyp = MatrixType (m); + args(0).matrix_type (mattyp); } } } @@ -450,65 +430,55 @@ error ("matrix_type: Unknown matrix type %s", str_typ.c_str ()); - if (! error_state) + if (nargin == 3 && (str_typ == "upper" + || str_typ == "lower")) { - if (nargin == 3 && (str_typ == "upper" - || str_typ == "lower")) + const ColumnVector perm = + ColumnVector (args(2).vector_value ()); + + if (error_state) + error ("matrix_type: Invalid permutation vector PERM"); + else { - const ColumnVector perm = - ColumnVector (args(2).vector_value ()); + octave_idx_type len = perm.numel (); + dim_vector dv = args(0).dims (); - if (error_state) + if (len != dv(0)) error ("matrix_type: Invalid permutation vector PERM"); else { - octave_idx_type len = perm.numel (); - dim_vector dv = args(0).dims (); + OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len); - if (len != dv(0)) - error ("matrix_type: Invalid permutation vector PERM"); - else - { - OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len); + for (octave_idx_type i = 0; i < len; i++) + p[i] = static_cast + (perm (i)) + - 1; - for (octave_idx_type i = 0; i < len; i++) - p[i] = static_cast - (perm (i)) - - 1; - - mattyp.mark_as_permuted (len, p); - } + mattyp.mark_as_permuted (len, p); } } - else if (nargin != 2) - error ("matrix_type: Invalid number of arguments"); + } + else if (nargin != 2) + error ("matrix_type: Invalid number of arguments"); - if (! error_state) - { - // Set the matrix type - if (args(0).is_single_type ()) - { - if (args(0).is_complex_type ()) - retval = octave_value - (args(0).float_complex_matrix_value (), - mattyp); - else - retval = octave_value - (args(0).float_matrix_value (), - mattyp); - } - else - { - if (args(0).is_complex_type ()) - retval = octave_value - (args(0).complex_matrix_value (), - mattyp); - else - retval = octave_value - (args(0).matrix_value (), - mattyp); - } - } + // Set the matrix type + if (args(0).is_single_type ()) + { + if (args(0).is_complex_type ()) + retval = octave_value (args(0).float_complex_matrix_value (), + mattyp); + else + retval = octave_value (args(0).float_matrix_value (), + mattyp); + } + else + { + if (args(0).is_complex_type ()) + retval = octave_value (args(0).complex_matrix_value (), + mattyp); + else + retval = octave_value (args(0).matrix_value (), + mattyp); } } } diff -r 4bed806ee3d4 -r b10432a40432 libinterp/octave-value/ov-usr-fcn.cc --- a/libinterp/octave-value/ov-usr-fcn.cc Mon Oct 05 20:21:55 2015 -0400 +++ b/libinterp/octave-value/ov-usr-fcn.cc Mon Oct 05 20:37:19 2015 -0400 @@ -130,43 +130,40 @@ unwind_protect frame; - if (! error_state) + if (args.length () == 0 && nargout == 0) { - if (args.length () == 0 && nargout == 0) + if (cmd_list) { - if (cmd_list) - { - frame.protect_var (call_depth); - call_depth++; + frame.protect_var (call_depth); + call_depth++; - if (call_depth < Vmax_recursion_depth) - { - octave_call_stack::push (this); + if (call_depth < Vmax_recursion_depth) + { + octave_call_stack::push (this); - frame.add_fcn (octave_call_stack::pop); + frame.add_fcn (octave_call_stack::pop); - frame.protect_var (tree_evaluator::statement_context); - tree_evaluator::statement_context = tree_evaluator::script; + frame.protect_var (tree_evaluator::statement_context); + tree_evaluator::statement_context = tree_evaluator::script; - BEGIN_PROFILER_BLOCK (octave_user_script) + BEGIN_PROFILER_BLOCK (octave_user_script) - cmd_list->accept (*current_evaluator); + cmd_list->accept (*current_evaluator); - END_PROFILER_BLOCK + END_PROFILER_BLOCK - if (tree_return_command::returning) - tree_return_command::returning = 0; + if (tree_return_command::returning) + tree_return_command::returning = 0; - if (tree_break_command::breaking) - tree_break_command::breaking--; - } - else - error ("max_recursion_depth exceeded"); + if (tree_break_command::breaking) + tree_break_command::breaking--; } + else + error ("max_recursion_depth exceeded"); } - else - error ("invalid call to script %s", file_name.c_str ()); } + else + error ("invalid call to script %s", file_name.c_str ()); return retval; } @@ -476,9 +473,6 @@ { octave_value_list retval; - if (error_state) - return retval; - if (! cmd_list) return retval; @@ -536,11 +530,7 @@ string_vector arg_names = args.name_tags (); if (param_list && ! param_list->varargs_only ()) - { - param_list->define_from_arg_vector (args); - if (error_state) - return retval; - } + param_list->define_from_arg_vector (args); // For classdef constructor, pre-populate the output arguments // with the pre-initialized object instance, extracted above. @@ -548,11 +538,7 @@ if (is_classdef_constructor ()) { if (ret_list) - { - ret_list->define_from_arg_vector (ret_args); - if (error_state) - return retval; - } + ret_list->define_from_arg_vector (ret_args); else { error ("%s: invalid classdef constructor, no output argument defined", @@ -636,9 +622,6 @@ if (tree_break_command::breaking) tree_break_command::breaking--; - if (error_state) - return retval; - // Copy return values out. if (ret_list && ! is_special_expr ()) @@ -660,8 +643,7 @@ } } - if (! error_state) - retval = ret_list->convert_to_const_vector (nargout, varargout); + retval = ret_list->convert_to_const_vector (nargout, varargout); } return retval; @@ -803,11 +785,8 @@ if (val.is_defined ()) { - // Don't use the usual approach of attempting to extract a value - // and then checking error_state since this code might be - // executing when error_state is already set. But do fail - // spectacularly if .saved_warning_states. is not an octave_map - // (or octave_scalar_map) object. + // Fail spectacularly if .saved_warning_states. is not an + // octave_map (or octave_scalar_map) object. if (! val.is_map ()) panic_impossible (); @@ -1123,22 +1102,20 @@ if (args(0).is_scalar_type ()) { double k = args(0).double_value (); - if (! error_state) - retval = isargout1 (nargout1, ignored, k); + + retval = isargout1 (nargout1, ignored, k); } else if (args(0).is_numeric_type ()) { const NDArray ka = args(0).array_value (); - if (! error_state) - { - boolNDArray r (ka.dims ()); - for (octave_idx_type i = 0; - i < ka.numel () && ! error_state; - i++) - r(i) = isargout1 (nargout1, ignored, ka(i)); - retval = r; - } + boolNDArray r (ka.dims ()); + for (octave_idx_type i = 0; + i < ka.numel () && ! error_state; + i++) + r(i) = isargout1 (nargout1, ignored, ka(i)); + + retval = r; } else gripe_wrong_type_arg ("isargout", args(0)); diff -r 4bed806ee3d4 -r b10432a40432 libinterp/parse-tree/pt-assign.cc --- a/libinterp/parse-tree/pt-assign.cc Mon Oct 05 20:21:55 2015 -0400 +++ b/libinterp/parse-tree/pt-assign.cc Mon Oct 05 20:37:19 2015 -0400 @@ -77,78 +77,65 @@ { octave_value retval; - if (error_state) - return retval; - if (rhs) { octave_value rhs_val = rhs->rvalue1 (); - if (! error_state) + if (rhs_val.is_undefined ()) { - if (rhs_val.is_undefined ()) + error ("value on right hand side of assignment is undefined"); + return retval; + } + else + { + 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"); + return retval; } + } - try - { - octave_lvalue ult = lhs->lvalue (); + try + { + octave_lvalue ult = lhs->lvalue (); - if (ult.numel () != 1) - gripe_nonbraced_cs_list_assignment (); - - if (! error_state) - { - ult.assign (etype, rhs_val); + if (ult.numel () != 1) + gripe_nonbraced_cs_list_assignment (); - if (! error_state) - { - if (etype == octave_value::op_asn_eq) - retval = rhs_val; - else - retval = ult.value (); + ult.assign (etype, rhs_val); - 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 (etype == octave_value::op_asn_eq) + retval = rhs_val; + else + retval = ult.value (); - ult.clear_index (); + 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). - octave_value lhs_val = ult.value (); + ult.clear_index (); - if (! error_state) - lhs_val.print_with_name (octave_stdout, - lhs->name ()); - } - } - } + octave_value lhs_val = ult.value (); + + lhs_val.print_with_name (octave_stdout, + lhs->name ()); } - catch (index_exception& e) - { // problems with range, invalid index type etc. - e.set_var (lhs->name ()); - (*current_liboctave_error_with_id_handler) (e.id(), e.err()); - } + } + catch (index_exception& e) + { // problems with range, invalid index type etc. + e.set_var (lhs->name ()); + (*current_liboctave_error_with_id_handler) (e.id(), e.err()); } } } @@ -219,16 +206,10 @@ { octave_value_list retval; - if (error_state) - return retval; - if (rhs) { std::list lvalue_list = lhs->lvalue_list (); - if (error_state) - return retval; - octave_idx_type n_out = 0; for (std::list::const_iterator p = lvalue_list.begin (); @@ -243,9 +224,6 @@ ? rhs_val1(0).list_value () : rhs_val1); - if (error_state) - return retval; - octave_idx_type k = 0; octave_idx_type n = rhs_val.length (); @@ -303,12 +281,9 @@ ult.assign (octave_value::op_asn_eq, octave_value (ovl, true)); - if (! error_state) - { - retval_list.push_back (ovl); + retval_list.push_back (ovl); - k += nel; - } + k += nel; } else error ("some elements undefined in return list"); @@ -324,7 +299,7 @@ k++; continue; } - else if (! error_state) + else { retval_list.push_back (rhs_val(k)); @@ -358,10 +333,8 @@ } } - if (error_state) - break; - else if (print_result () - && tree_evaluator::statement_printing_enabled ()) + 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, @@ -372,19 +345,12 @@ octave_value lhs_val = ult.value (); - if (! error_state) - lhs_val.print_with_name (octave_stdout, - lhs_elt->name ()); + lhs_val.print_with_name (octave_stdout, lhs_elt->name ()); } - - if (error_state) - break; - } // Concatenate return values. retval = retval_list; - } return retval; diff -r 4bed806ee3d4 -r b10432a40432 libinterp/parse-tree/pt-binop.cc --- a/libinterp/parse-tree/pt-binop.cc Mon Oct 05 20:21:55 2015 -0400 +++ b/libinterp/parse-tree/pt-binop.cc Mon Oct 05 20:37:19 2015 -0400 @@ -69,9 +69,6 @@ { octave_value retval; - if (error_state) - return retval; - if (Vdo_braindead_shortcircuit_evaluation && eligible_for_braindead_shortcircuit) { @@ -79,48 +76,40 @@ { octave_value a = op_lhs->rvalue1 (); - if (! error_state) + if (a.ndims () == 2 && a.rows () == 1 && a.columns () == 1) { - if (a.ndims () == 2 && a.rows () == 1 && a.columns () == 1) + bool result = false; + + bool a_true = a.is_true (); + + if (a_true) { - bool result = false; - - bool a_true = a.is_true (); - - if (! error_state) + if (etype == octave_value::op_el_or) { - if (a_true) - { - if (etype == octave_value::op_el_or) - { - matlab_style_short_circuit_warning ("|"); - result = true; - goto done; - } - } - else - { - if (etype == octave_value::op_el_and) - { - matlab_style_short_circuit_warning ("&"); - goto done; - } - } - - if (op_rhs) - { - octave_value b = op_rhs->rvalue1 (); - - if (! error_state) - result = b.is_true (); - } - - done: - - if (! error_state) - return octave_value (result); + matlab_style_short_circuit_warning ("|"); + result = true; + goto done; } } + else + { + if (etype == octave_value::op_el_and) + { + matlab_style_short_circuit_warning ("&"); + goto done; + } + } + + if (op_rhs) + { + octave_value b = op_rhs->rvalue1 (); + + result = b.is_true (); + } + + done: + + return octave_value (result); } } } @@ -129,11 +118,11 @@ { octave_value a = op_lhs->rvalue1 (); - if (! error_state && a.is_defined () && op_rhs) + if (a.is_defined () && op_rhs) { octave_value b = op_rhs->rvalue1 (); - if (! error_state && b.is_defined ()) + if (b.is_defined ()) { BEGIN_PROFILER_BLOCK (tree_binary_expression) @@ -145,9 +134,6 @@ retval = ::do_binary_op (etype, a, b); - if (error_state) - retval = octave_value (); - END_PROFILER_BLOCK } } @@ -203,9 +189,6 @@ { octave_value retval; - if (error_state) - return retval; - bool result = false; // This evaluation is not caught by the profiler, since we can't find @@ -217,40 +200,32 @@ { octave_value a = op_lhs->rvalue1 (); - if (! error_state) + bool a_true = a.is_true (); + + if (a_true) { - bool a_true = a.is_true (); - - if (! error_state) + if (etype == bool_or) { - if (a_true) - { - if (etype == bool_or) - { - result = true; - goto done; - } - } - else - { - if (etype == bool_and) - goto done; - } - - if (op_rhs) - { - octave_value b = op_rhs->rvalue1 (); - - if (! error_state) - result = b.is_true (); - } - - done: - - if (! error_state) - retval = octave_value (result); + result = true; + goto done; } } + else + { + if (etype == bool_and) + goto done; + } + + if (op_rhs) + { + octave_value b = op_rhs->rvalue1 (); + + result = b.is_true (); + } + + done: + + retval = octave_value (result); } return retval;