diff libinterp/parse-tree/oct-parse.in.yy @ 20586:22618d5fb6ad

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.
author John W. Eaton <jwe@octave.org>
date Fri, 09 Oct 2015 15:17:08 -0400
parents f90c8372b7ba
children e0e2c2ce7e94
line wrap: on
line diff
--- 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 ();