# HG changeset patch # User John W. Eaton # Date 1444418228 14400 # Node ID 22618d5fb6ad54afa21daa926eda75efe8df4829 # Parent e5f36a7854a55150067b5a77c784aa510ba93f70 eliminate remaining uses of error_state in parse-tree files * oct-parse.in.yy, pt-arg-list.cc, pt-colon.cc: Eliminate all uses of error_state. diff -r e5f36a7854a5 -r 22618d5fb6ad libinterp/parse-tree/oct-parse.in.yy --- a/libinterp/parse-tree/oct-parse.in.yy Fri Oct 09 12:03:23 2015 -0700 +++ b/libinterp/parse-tree/oct-parse.in.yy Fri Oct 09 15:17:08 2015 -0400 @@ -4548,15 +4548,7 @@ std::string arg; if (nargin == 1) - { - arg = args(0).string_value (); - - if (error_state) - { - error ("mfilename: expecting argument to be a character string"); - return retval; - } - } + arg = args(0).string_value ("mfilename: expecting argument to be a character string"); std::string fname; @@ -4607,22 +4599,14 @@ if (nargin == 1 || nargin == 2) { - std::string file_name = args(0).string_value (); - - if (! error_state) - { - std::string context; - - if (nargin == 2) - context = args(1).string_value (); - - if (! error_state) - source_file (file_name, context); - else - error ("source: expecting context to be character string"); - } - else - error ("source: expecting file name as argument"); + std::string file_name = args(0).string_value ("source: expecting file name as argument"); + + std::string context; + + if (nargin == 2) + context = args(1).string_value ("source: expecting context to be character string"); + + source_file (file_name, context); } else print_usage (); @@ -4801,20 +4785,14 @@ if (nargin > 0) { - const std::string name (args(0).string_value ()); - - if (! error_state) - { - octave_value fcn = symbol_table::builtin_find (name); - - if (fcn.is_defined ()) - retval = feval (fcn.function_value (), args.splice (0, 1), - nargout); - else - error ("builtin: lookup for symbol '%s' failed", name.c_str ()); - } + const std::string name (args(0).string_value ("builtin: function name (F) must be a string")); + + octave_value fcn = symbol_table::builtin_find (name); + + if (fcn.is_defined ()) + retval = feval (fcn.function_value (), args.splice (0, 1), nargout); else - error ("builtin: function name (F) must be a string"); + error ("builtin: lookup for symbol '%s' failed", name.c_str ()); } else print_usage (); @@ -4907,13 +4885,7 @@ eval_string (const octave_value& arg, bool silent, int& parse_status, int nargout) { - std::string s = arg.string_value (); - - if (error_state) - { - error ("eval: expecting std::string argument"); - return octave_value (-1); - } + std::string s = arg.string_value ("eval: expecting std::string argument"); return eval_string (s, silent, parse_status, nargout); } @@ -5077,35 +5049,25 @@ if (nargin == 3) { - std::string context = args(0).string_value (); - - if (! error_state) - { - unwind_protect frame; - - if (context == "caller") - octave_call_stack::goto_caller_frame (); - else if (context == "base") - octave_call_stack::goto_base_frame (); - else - error ("assignin: CONTEXT must be \"caller\" or \"base\""); - - frame.add_fcn (octave_call_stack::pop); - - std::string nm = args(1).string_value (); - - if (! error_state) - { - if (valid_identifier (nm)) - symbol_table::assign (nm, args(2)); - else - error ("assignin: invalid variable name in argument VARNAME"); - } - else - error ("assignin: VARNAME must be a string"); - } + std::string context = args(0).string_value ("assignin: CONTEXT must be a string"); + + unwind_protect frame; + + if (context == "caller") + octave_call_stack::goto_caller_frame (); + else if (context == "base") + octave_call_stack::goto_base_frame (); else - error ("assignin: CONTEXT must be a string"); + error ("assignin: CONTEXT must be \"caller\" or \"base\""); + + frame.add_fcn (octave_call_stack::pop); + + std::string nm = args(1).string_value ("assignin: VARNAME must be a string"); + + if (valid_identifier (nm)) + symbol_table::assign (nm, args(2)); + else + error ("assignin: invalid variable name in argument VARNAME"); } else print_usage (); @@ -5128,69 +5090,64 @@ if (nargin > 1) { - std::string context = args(0).string_value (); - - if (! error_state) + std::string context = args(0).string_value ("evalin: CONTEXT must be a string"); + + unwind_protect frame; + + if (context == "caller") + octave_call_stack::goto_caller_frame (); + else if (context == "base") + octave_call_stack::goto_base_frame (); + else + error ("evalin: CONTEXT must be \"caller\" or \"base\""); + + frame.add_fcn (octave_call_stack::pop); + + if (nargin > 2) { - unwind_protect frame; - - if (context == "caller") - octave_call_stack::goto_caller_frame (); - else if (context == "base") - octave_call_stack::goto_base_frame (); - else - error ("evalin: CONTEXT must be \"caller\" or \"base\""); - - frame.add_fcn (octave_call_stack::pop); - - if (nargin > 2) - { - frame.protect_var (buffer_error_messages); - buffer_error_messages++; - } - - int parse_status = 0; - - bool execution_error = false; - - octave_value_list tmp; - - try - { - tmp = eval_string (args(1), nargout > 0, - parse_status, nargout); - } - catch (const octave_execution_exception&) - { - execution_error = true; - } - - if (nargin > 2 && (parse_status != 0 || execution_error)) - { - // Set up for letting the user print any messages from - // errors that occurred in the first part of this eval(). - - buffer_error_messages--; - - tmp = eval_string (args(2), nargout > 0, - parse_status, nargout); - - retval = (nargout > 0) ? tmp : octave_value_list (); - } - else - { - if (nargout > 0) - retval = tmp; - - // FIXME: we should really be rethrowing whatever - // exception occurred, not just throwing an - // execution exception. - if (execution_error) - octave_throw_execution_exception (); - } + frame.protect_var (buffer_error_messages); + buffer_error_messages++; + } + + int parse_status = 0; + + bool execution_error = false; + + octave_value_list tmp; + + try + { + tmp = eval_string (args(1), nargout > 0, + parse_status, nargout); + } + catch (const octave_execution_exception&) + { + execution_error = true; + } + + if (nargin > 2 && (parse_status != 0 || execution_error)) + { + // Set up for letting the user print any messages from + // errors that occurred in the first part of this eval(). + + buffer_error_messages--; + + tmp = eval_string (args(2), nargout > 0, + parse_status, nargout); + + retval = (nargout > 0) ? tmp : octave_value_list (); } else - error ("evalin: CONTEXT must be a string"); + { + if (nargout > 0) + retval = tmp; + + // FIXME: we should really be rethrowing whatever + // exception occurred, not just throwing an + // execution exception. + if (execution_error) + octave_throw_execution_exception (); + } } else print_usage (); @@ -5231,7 +5188,7 @@ if (nargin == 1 || nargin == 2) { - std::string file = args(0).string_value (); + std::string file = args(0).string_value ("__parse_file__: expecting file name as argument"); std::string full_file = octave_env::make_absolute (file); @@ -5249,20 +5206,15 @@ file = file.substr (pos+1); } - if (! error_state) - { - if (nargin == 2) - octave_stdout << "parsing " << full_file << std::endl; - - octave_function *fcn = parse_fcn_file (full_file, file, "", "", - true, false, false, - false, "__parse_file__"); - - if (fcn) - delete fcn; - } - else - error ("__parse_file__: expecting file name as argument"); + if (nargin == 2) + octave_stdout << "parsing " << full_file << std::endl; + + octave_function *fcn = parse_fcn_file (full_file, file, "", "", + true, false, false, + false, "__parse_file__"); + + if (fcn) + delete fcn; } else print_usage (); diff -r e5f36a7854a5 -r 22618d5fb6ad libinterp/parse-tree/pt-arg-list.cc --- a/libinterp/parse-tree/pt-arg-list.cc Fri Oct 09 12:03:23 2015 -0700 +++ b/libinterp/parse-tree/pt-arg-list.cc Fri Oct 09 15:17:08 2015 -0400 @@ -240,21 +240,21 @@ if (elt) { - octave_value tmp = elt->rvalue1 (); - - if (error_state) + try { - error ("evaluating argument list element number %d", k+1); - args.clear (); - break; - } - else - { + octave_value tmp = elt->rvalue1 (); + if (tmp.is_cs_list ()) args.push_back (tmp.list_value ()); else if (tmp.is_defined ()) args.push_back (tmp); } + catch (const octave_execution_exception&) + { + args.clear (); + + error ("evaluating argument list element number %d", k+1); + } } else { diff -r e5f36a7854a5 -r 22618d5fb6ad libinterp/parse-tree/pt-colon.cc --- a/libinterp/parse-tree/pt-colon.cc Fri Oct 09 12:03:23 2015 -0700 +++ b/libinterp/parse-tree/pt-colon.cc Fri Oct 09 15:17:08 2015 -0400 @@ -90,64 +90,46 @@ octave_value ov_base = op_base->rvalue1 (); - if (error_state || ov_base.is_undefined ()) - eval_error ("invalid base value in colon expression"); - else - { - octave_value ov_limit = op_limit->rvalue1 (); + octave_value ov_limit = op_limit->rvalue1 (); - if (error_state || ov_limit.is_undefined ()) - eval_error ("invalid limit value in colon expression"); - else if (ov_base.is_object () || ov_limit.is_object ()) - { - octave_value_list tmp1; - - if (op_increment) - { - octave_value ov_increment = op_increment->rvalue1 (); + if (ov_base.is_object () || ov_limit.is_object ()) + { + octave_value_list tmp1; - if (error_state || ov_increment.is_undefined ()) - eval_error ("invalid increment value in colon expression"); - else - { - tmp1(2) = ov_limit; - tmp1(1) = ov_increment; - tmp1(0) = ov_base; - } - } - else - { - tmp1(1) = ov_limit; - tmp1(0) = ov_base; - } + if (op_increment) + { + octave_value ov_increment = op_increment->rvalue1 (); - octave_value fcn = symbol_table::find_function ("colon", tmp1); - - if (fcn.is_defined ()) - { - octave_value_list tmp2 = fcn.do_multi_index_op (1, tmp1); - - if (! error_state) - retval = tmp2 (0); - } - else - error ("can not find overloaded colon function"); + tmp1(2) = ov_limit; + tmp1(1) = ov_increment; + tmp1(0) = ov_base; } else { - octave_value ov_increment = 1.0; + tmp1(1) = ov_limit; + tmp1(0) = ov_base; + } - if (op_increment) - { - ov_increment = op_increment->rvalue1 (); + octave_value fcn = symbol_table::find_function ("colon", tmp1); + + if (fcn.is_defined ()) + { + octave_value_list tmp2 = fcn.do_multi_index_op (1, tmp1); - if (error_state || ov_increment.is_undefined ()) - eval_error ("invalid increment value in colon expression"); - } + retval = tmp2 (0); + } + else + error ("can not find overloaded colon function"); + } + else + { + octave_value ov_increment = 1.0; - retval = do_colon_op (ov_base, ov_increment, ov_limit, - is_for_cmd_expr ()); - } + if (op_increment) + ov_increment = op_increment->rvalue1 (); + + retval = do_colon_op (ov_base, ov_increment, ov_limit, + is_for_cmd_expr ()); } return retval;