Mercurial > octave-nkf
comparison libinterp/parse-tree/oct-parse.in.yy @ 20621: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 |
comparison
equal
deleted
inserted
replaced
20620:e5f36a7854a5 | 20621:22618d5fb6ad |
---|---|
4546 } | 4546 } |
4547 | 4547 |
4548 std::string arg; | 4548 std::string arg; |
4549 | 4549 |
4550 if (nargin == 1) | 4550 if (nargin == 1) |
4551 { | 4551 arg = args(0).string_value ("mfilename: expecting argument to be a character string"); |
4552 arg = args(0).string_value (); | |
4553 | |
4554 if (error_state) | |
4555 { | |
4556 error ("mfilename: expecting argument to be a character string"); | |
4557 return retval; | |
4558 } | |
4559 } | |
4560 | 4552 |
4561 std::string fname; | 4553 std::string fname; |
4562 | 4554 |
4563 octave_user_code *fcn = octave_call_stack::caller_user_code (); | 4555 octave_user_code *fcn = octave_call_stack::caller_user_code (); |
4564 | 4556 |
4605 | 4597 |
4606 int nargin = args.length (); | 4598 int nargin = args.length (); |
4607 | 4599 |
4608 if (nargin == 1 || nargin == 2) | 4600 if (nargin == 1 || nargin == 2) |
4609 { | 4601 { |
4610 std::string file_name = args(0).string_value (); | 4602 std::string file_name = args(0).string_value ("source: expecting file name as argument"); |
4611 | 4603 |
4612 if (! error_state) | 4604 std::string context; |
4613 { | 4605 |
4614 std::string context; | 4606 if (nargin == 2) |
4615 | 4607 context = args(1).string_value ("source: expecting context to be character string"); |
4616 if (nargin == 2) | 4608 |
4617 context = args(1).string_value (); | 4609 source_file (file_name, context); |
4618 | |
4619 if (! error_state) | |
4620 source_file (file_name, context); | |
4621 else | |
4622 error ("source: expecting context to be character string"); | |
4623 } | |
4624 else | |
4625 error ("source: expecting file name as argument"); | |
4626 } | 4610 } |
4627 else | 4611 else |
4628 print_usage (); | 4612 print_usage (); |
4629 | 4613 |
4630 return retval; | 4614 return retval; |
4799 | 4783 |
4800 int nargin = args.length (); | 4784 int nargin = args.length (); |
4801 | 4785 |
4802 if (nargin > 0) | 4786 if (nargin > 0) |
4803 { | 4787 { |
4804 const std::string name (args(0).string_value ()); | 4788 const std::string name (args(0).string_value ("builtin: function name (F) must be a string")); |
4805 | 4789 |
4806 if (! error_state) | 4790 octave_value fcn = symbol_table::builtin_find (name); |
4807 { | 4791 |
4808 octave_value fcn = symbol_table::builtin_find (name); | 4792 if (fcn.is_defined ()) |
4809 | 4793 retval = feval (fcn.function_value (), args.splice (0, 1), nargout); |
4810 if (fcn.is_defined ()) | |
4811 retval = feval (fcn.function_value (), args.splice (0, 1), | |
4812 nargout); | |
4813 else | |
4814 error ("builtin: lookup for symbol '%s' failed", name.c_str ()); | |
4815 } | |
4816 else | 4794 else |
4817 error ("builtin: function name (F) must be a string"); | 4795 error ("builtin: lookup for symbol '%s' failed", name.c_str ()); |
4818 } | 4796 } |
4819 else | 4797 else |
4820 print_usage (); | 4798 print_usage (); |
4821 | 4799 |
4822 return retval; | 4800 return retval; |
4905 | 4883 |
4906 static octave_value_list | 4884 static octave_value_list |
4907 eval_string (const octave_value& arg, bool silent, int& parse_status, | 4885 eval_string (const octave_value& arg, bool silent, int& parse_status, |
4908 int nargout) | 4886 int nargout) |
4909 { | 4887 { |
4910 std::string s = arg.string_value (); | 4888 std::string s = arg.string_value ("eval: expecting std::string argument"); |
4911 | |
4912 if (error_state) | |
4913 { | |
4914 error ("eval: expecting std::string argument"); | |
4915 return octave_value (-1); | |
4916 } | |
4917 | 4889 |
4918 return eval_string (s, silent, parse_status, nargout); | 4890 return eval_string (s, silent, parse_status, nargout); |
4919 } | 4891 } |
4920 | 4892 |
4921 void | 4893 void |
5075 | 5047 |
5076 int nargin = args.length (); | 5048 int nargin = args.length (); |
5077 | 5049 |
5078 if (nargin == 3) | 5050 if (nargin == 3) |
5079 { | 5051 { |
5080 std::string context = args(0).string_value (); | 5052 std::string context = args(0).string_value ("assignin: CONTEXT must be a string"); |
5081 | 5053 |
5082 if (! error_state) | 5054 unwind_protect frame; |
5083 { | 5055 |
5084 unwind_protect frame; | 5056 if (context == "caller") |
5085 | 5057 octave_call_stack::goto_caller_frame (); |
5086 if (context == "caller") | 5058 else if (context == "base") |
5087 octave_call_stack::goto_caller_frame (); | 5059 octave_call_stack::goto_base_frame (); |
5088 else if (context == "base") | |
5089 octave_call_stack::goto_base_frame (); | |
5090 else | |
5091 error ("assignin: CONTEXT must be \"caller\" or \"base\""); | |
5092 | |
5093 frame.add_fcn (octave_call_stack::pop); | |
5094 | |
5095 std::string nm = args(1).string_value (); | |
5096 | |
5097 if (! error_state) | |
5098 { | |
5099 if (valid_identifier (nm)) | |
5100 symbol_table::assign (nm, args(2)); | |
5101 else | |
5102 error ("assignin: invalid variable name in argument VARNAME"); | |
5103 } | |
5104 else | |
5105 error ("assignin: VARNAME must be a string"); | |
5106 } | |
5107 else | 5060 else |
5108 error ("assignin: CONTEXT must be a string"); | 5061 error ("assignin: CONTEXT must be \"caller\" or \"base\""); |
5062 | |
5063 frame.add_fcn (octave_call_stack::pop); | |
5064 | |
5065 std::string nm = args(1).string_value ("assignin: VARNAME must be a string"); | |
5066 | |
5067 if (valid_identifier (nm)) | |
5068 symbol_table::assign (nm, args(2)); | |
5069 else | |
5070 error ("assignin: invalid variable name in argument VARNAME"); | |
5109 } | 5071 } |
5110 else | 5072 else |
5111 print_usage (); | 5073 print_usage (); |
5112 | 5074 |
5113 return retval; | 5075 return retval; |
5126 | 5088 |
5127 int nargin = args.length (); | 5089 int nargin = args.length (); |
5128 | 5090 |
5129 if (nargin > 1) | 5091 if (nargin > 1) |
5130 { | 5092 { |
5131 std::string context = args(0).string_value (); | 5093 std::string context = args(0).string_value ("evalin: CONTEXT must be a string"); |
5132 | 5094 |
5133 if (! error_state) | 5095 unwind_protect frame; |
5096 | |
5097 if (context == "caller") | |
5098 octave_call_stack::goto_caller_frame (); | |
5099 else if (context == "base") | |
5100 octave_call_stack::goto_base_frame (); | |
5101 else | |
5102 error ("evalin: CONTEXT must be \"caller\" or \"base\""); | |
5103 | |
5104 frame.add_fcn (octave_call_stack::pop); | |
5105 | |
5106 if (nargin > 2) | |
5134 { | 5107 { |
5135 unwind_protect frame; | 5108 frame.protect_var (buffer_error_messages); |
5136 | 5109 buffer_error_messages++; |
5137 if (context == "caller") | 5110 } |
5138 octave_call_stack::goto_caller_frame (); | 5111 |
5139 else if (context == "base") | 5112 int parse_status = 0; |
5140 octave_call_stack::goto_base_frame (); | 5113 |
5141 else | 5114 bool execution_error = false; |
5142 error ("evalin: CONTEXT must be \"caller\" or \"base\""); | 5115 |
5143 | 5116 octave_value_list tmp; |
5144 frame.add_fcn (octave_call_stack::pop); | 5117 |
5145 | 5118 try |
5146 if (nargin > 2) | 5119 { |
5147 { | 5120 tmp = eval_string (args(1), nargout > 0, |
5148 frame.protect_var (buffer_error_messages); | 5121 parse_status, nargout); |
5149 buffer_error_messages++; | 5122 } |
5150 } | 5123 catch (const octave_execution_exception&) |
5151 | 5124 { |
5152 int parse_status = 0; | 5125 execution_error = true; |
5153 | 5126 } |
5154 bool execution_error = false; | 5127 |
5155 | 5128 if (nargin > 2 && (parse_status != 0 || execution_error)) |
5156 octave_value_list tmp; | 5129 { |
5157 | 5130 // Set up for letting the user print any messages from |
5158 try | 5131 // errors that occurred in the first part of this eval(). |
5159 { | 5132 |
5160 tmp = eval_string (args(1), nargout > 0, | 5133 buffer_error_messages--; |
5161 parse_status, nargout); | 5134 |
5162 } | 5135 tmp = eval_string (args(2), nargout > 0, |
5163 catch (const octave_execution_exception&) | 5136 parse_status, nargout); |
5164 { | 5137 |
5165 execution_error = true; | 5138 retval = (nargout > 0) ? tmp : octave_value_list (); |
5166 } | |
5167 | |
5168 if (nargin > 2 && (parse_status != 0 || execution_error)) | |
5169 { | |
5170 // Set up for letting the user print any messages from | |
5171 // errors that occurred in the first part of this eval(). | |
5172 | |
5173 buffer_error_messages--; | |
5174 | |
5175 tmp = eval_string (args(2), nargout > 0, | |
5176 parse_status, nargout); | |
5177 | |
5178 retval = (nargout > 0) ? tmp : octave_value_list (); | |
5179 } | |
5180 else | |
5181 { | |
5182 if (nargout > 0) | |
5183 retval = tmp; | |
5184 | |
5185 // FIXME: we should really be rethrowing whatever | |
5186 // exception occurred, not just throwing an | |
5187 // execution exception. | |
5188 if (execution_error) | |
5189 octave_throw_execution_exception (); | |
5190 } | |
5191 } | 5139 } |
5192 else | 5140 else |
5193 error ("evalin: CONTEXT must be a string"); | 5141 { |
5142 if (nargout > 0) | |
5143 retval = tmp; | |
5144 | |
5145 // FIXME: we should really be rethrowing whatever | |
5146 // exception occurred, not just throwing an | |
5147 // execution exception. | |
5148 if (execution_error) | |
5149 octave_throw_execution_exception (); | |
5150 } | |
5194 } | 5151 } |
5195 else | 5152 else |
5196 print_usage (); | 5153 print_usage (); |
5197 | 5154 |
5198 return retval; | 5155 return retval; |
5229 | 5186 |
5230 int nargin = args.length (); | 5187 int nargin = args.length (); |
5231 | 5188 |
5232 if (nargin == 1 || nargin == 2) | 5189 if (nargin == 1 || nargin == 2) |
5233 { | 5190 { |
5234 std::string file = args(0).string_value (); | 5191 std::string file = args(0).string_value ("__parse_file__: expecting file name as argument"); |
5235 | 5192 |
5236 std::string full_file = octave_env::make_absolute (file); | 5193 std::string full_file = octave_env::make_absolute (file); |
5237 | 5194 |
5238 size_t file_len = file.length (); | 5195 size_t file_len = file.length (); |
5239 | 5196 |
5247 size_t pos = file.find_last_of (file_ops::dir_sep_str ()); | 5204 size_t pos = file.find_last_of (file_ops::dir_sep_str ()); |
5248 if (pos != std::string::npos) | 5205 if (pos != std::string::npos) |
5249 file = file.substr (pos+1); | 5206 file = file.substr (pos+1); |
5250 } | 5207 } |
5251 | 5208 |
5252 if (! error_state) | 5209 if (nargin == 2) |
5253 { | 5210 octave_stdout << "parsing " << full_file << std::endl; |
5254 if (nargin == 2) | 5211 |
5255 octave_stdout << "parsing " << full_file << std::endl; | 5212 octave_function *fcn = parse_fcn_file (full_file, file, "", "", |
5256 | 5213 true, false, false, |
5257 octave_function *fcn = parse_fcn_file (full_file, file, "", "", | 5214 false, "__parse_file__"); |
5258 true, false, false, | 5215 |
5259 false, "__parse_file__"); | 5216 if (fcn) |
5260 | 5217 delete fcn; |
5261 if (fcn) | |
5262 delete fcn; | |
5263 } | |
5264 else | |
5265 error ("__parse_file__: expecting file name as argument"); | |
5266 } | 5218 } |
5267 else | 5219 else |
5268 print_usage (); | 5220 print_usage (); |
5269 | 5221 |
5270 return retval; | 5222 return retval; |