Mercurial > octave-nkf
comparison libinterp/parse-tree/oct-parse.in.yy @ 20579:52ce821a52fd
eliminate simple uses of error_state in parser and lexer
* lex.ll, oct-parse.in.yy: Eliminate simple uses of global error_state
variable.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 03 Oct 2015 16:21:58 -0400 |
parents | b70cc4bd8109 |
children | 235d059cf329 |
comparison
equal
deleted
inserted
replaced
20578:2f8500ca91d3 | 20579:52ce821a52fd |
---|---|
2244 { | 2244 { |
2245 tree_expression *retval = e; | 2245 tree_expression *retval = e; |
2246 | 2246 |
2247 unwind_protect frame; | 2247 unwind_protect frame; |
2248 | 2248 |
2249 frame.protect_var (error_state); | |
2250 | |
2251 frame.protect_var (discard_error_messages); | 2249 frame.protect_var (discard_error_messages); |
2252 frame.protect_var (discard_warning_messages); | 2250 frame.protect_var (discard_warning_messages); |
2253 | 2251 |
2254 discard_error_messages = true; | 2252 discard_error_messages = true; |
2255 discard_warning_messages = true; | 2253 discard_warning_messages = true; |
2265 if (base->is_constant () && limit->is_constant () | 2263 if (base->is_constant () && limit->is_constant () |
2266 && (! incr || (incr && incr->is_constant ()))) | 2264 && (! incr || (incr && incr->is_constant ()))) |
2267 { | 2265 { |
2268 octave_value tmp = e->rvalue1 (); | 2266 octave_value tmp = e->rvalue1 (); |
2269 | 2267 |
2270 if (! error_state) | 2268 tree_constant *tc_retval |
2271 { | 2269 = new tree_constant (tmp, base->line (), base->column ()); |
2272 tree_constant *tc_retval | 2270 |
2273 = new tree_constant (tmp, base->line (), base->column ()); | 2271 std::ostringstream buf; |
2274 | 2272 |
2275 std::ostringstream buf; | 2273 tree_print_code tpc (buf); |
2276 | 2274 |
2277 tree_print_code tpc (buf); | 2275 e->accept (tpc); |
2278 | 2276 |
2279 e->accept (tpc); | 2277 tc_retval->stash_original_text (buf.str ()); |
2280 | 2278 |
2281 tc_retval->stash_original_text (buf.str ()); | 2279 delete e; |
2282 | 2280 |
2283 delete e; | 2281 retval = tc_retval; |
2284 | |
2285 retval = tc_retval; | |
2286 } | |
2287 } | 2282 } |
2288 } | 2283 } |
2289 else | 2284 else |
2290 { | 2285 { |
2291 e->preserve_base (); | 2286 e->preserve_base (); |
3796 { | 3791 { |
3797 tree_expression *retval = array_list; | 3792 tree_expression *retval = array_list; |
3798 | 3793 |
3799 unwind_protect frame; | 3794 unwind_protect frame; |
3800 | 3795 |
3801 frame.protect_var (error_state); | |
3802 | |
3803 frame.protect_var (discard_error_messages); | 3796 frame.protect_var (discard_error_messages); |
3804 frame.protect_var (discard_warning_messages); | 3797 frame.protect_var (discard_warning_messages); |
3805 | 3798 |
3806 discard_error_messages = true; | 3799 discard_error_messages = true; |
3807 discard_warning_messages = true; | 3800 discard_warning_messages = true; |
3808 | 3801 |
3809 if (array_list->all_elements_are_constant ()) | 3802 if (array_list->all_elements_are_constant ()) |
3810 { | 3803 { |
3811 octave_value tmp = array_list->rvalue1 (); | 3804 octave_value tmp = array_list->rvalue1 (); |
3812 | 3805 |
3813 if (! error_state) | 3806 tree_constant *tc_retval |
3814 { | 3807 = new tree_constant (tmp, array_list->line (), |
3815 tree_constant *tc_retval | 3808 array_list->column ()); |
3816 = new tree_constant (tmp, array_list->line (), | 3809 |
3817 array_list->column ()); | 3810 std::ostringstream buf; |
3818 | 3811 |
3819 std::ostringstream buf; | 3812 tree_print_code tpc (buf); |
3820 | 3813 |
3821 tree_print_code tpc (buf); | 3814 array_list->accept (tpc); |
3822 | 3815 |
3823 array_list->accept (tpc); | 3816 tc_retval->stash_original_text (buf.str ()); |
3824 | 3817 |
3825 tc_retval->stash_original_text (buf.str ()); | 3818 delete array_list; |
3826 | 3819 |
3827 delete array_list; | 3820 retval = tc_retval; |
3828 | |
3829 retval = tc_retval; | |
3830 } | |
3831 } | 3821 } |
3832 | 3822 |
3833 return retval; | 3823 return retval; |
3834 } | 3824 } |
3835 | 3825 |
4375 } | 4365 } |
4376 else if (nargin == 2 || nargin == 3) | 4366 else if (nargin == 2 || nargin == 3) |
4377 { | 4367 { |
4378 string_vector argv = args.make_argv ("autoload"); | 4368 string_vector argv = args.make_argv ("autoload"); |
4379 | 4369 |
4380 if (! error_state) | 4370 std::string nm = argv[2]; |
4371 | |
4372 if (! octave_env::absolute_pathname (nm)) | |
4381 { | 4373 { |
4382 std::string nm = argv[2]; | 4374 octave_user_code *fcn = octave_call_stack::caller_user_code (); |
4383 | 4375 |
4384 if (! octave_env::absolute_pathname (nm)) | 4376 bool found = false; |
4377 | |
4378 if (fcn) | |
4385 { | 4379 { |
4386 octave_user_code *fcn = octave_call_stack::caller_user_code (); | 4380 std::string fname = fcn->fcn_file_name (); |
4387 | 4381 |
4388 bool found = false; | 4382 if (! fname.empty ()) |
4389 | |
4390 if (fcn) | |
4391 { | 4383 { |
4392 std::string fname = fcn->fcn_file_name (); | 4384 fname = octave_env::make_absolute (fname); |
4393 | 4385 fname = fname.substr (0, fname.find_last_of (file_ops::dir_sep_str ()) + 1); |
4394 if (! fname.empty ()) | 4386 |
4387 file_stat fs (fname + nm); | |
4388 | |
4389 if (fs.exists ()) | |
4395 { | 4390 { |
4396 fname = octave_env::make_absolute (fname); | 4391 nm = fname + nm; |
4397 fname = fname.substr (0, fname.find_last_of (file_ops::dir_sep_str ()) + 1); | 4392 found = true; |
4398 | |
4399 file_stat fs (fname + nm); | |
4400 | |
4401 if (fs.exists ()) | |
4402 { | |
4403 nm = fname + nm; | |
4404 found = true; | |
4405 } | |
4406 } | 4393 } |
4407 } | 4394 } |
4408 if (! found) | |
4409 warning_with_id ("Octave:autoload-relative-file-name", | |
4410 "autoload: '%s' is not an absolute file name", | |
4411 nm.c_str ()); | |
4412 } | 4395 } |
4413 if (nargin == 2) | 4396 if (! found) |
4414 autoload_map[argv[1]] = nm; | 4397 warning_with_id ("Octave:autoload-relative-file-name", |
4415 else if (nargin == 3) | 4398 "autoload: '%s' is not an absolute file name", |
4416 { | 4399 nm.c_str ()); |
4417 if (argv[3].compare ("remove") != 0) | 4400 } |
4418 error_with_id ("Octave:invalid-input-arg", | 4401 if (nargin == 2) |
4419 "autoload: third argument can only be 'remove'"); | 4402 autoload_map[argv[1]] = nm; |
4420 | 4403 else if (nargin == 3) |
4421 // Remove function from symbol table and autoload map. | 4404 { |
4422 symbol_table::clear_dld_function (argv[1]); | 4405 if (argv[3].compare ("remove") != 0) |
4423 autoload_map.erase (argv[1]); | 4406 error_with_id ("Octave:invalid-input-arg", |
4424 } | 4407 "autoload: third argument can only be 'remove'"); |
4408 | |
4409 // Remove function from symbol table and autoload map. | |
4410 symbol_table::clear_dld_function (argv[1]); | |
4411 autoload_map.erase (argv[1]); | |
4425 } | 4412 } |
4426 } | 4413 } |
4427 else | 4414 else |
4428 print_usage (); | 4415 print_usage (); |
4429 | 4416 |
4495 else if (context == "base") | 4482 else if (context == "base") |
4496 octave_call_stack::goto_base_frame (); | 4483 octave_call_stack::goto_base_frame (); |
4497 else | 4484 else |
4498 error ("source: context must be \"caller\" or \"base\""); | 4485 error ("source: context must be \"caller\" or \"base\""); |
4499 | 4486 |
4500 if (! error_state) | 4487 frame.add_fcn (octave_call_stack::pop); |
4501 frame.add_fcn (octave_call_stack::pop); | 4488 } |
4502 } | 4489 |
4503 | 4490 try |
4504 if (! error_state) | |
4505 { | 4491 { |
4506 octave_function *fcn = parse_fcn_file (file_full_name, file_name, | 4492 octave_function *fcn = parse_fcn_file (file_full_name, file_name, |
4507 "", "", require_file, true, | 4493 "", "", require_file, true, |
4508 false, false, warn_for); | 4494 false, false, warn_for); |
4509 | 4495 } |
4510 if (! error_state) | 4496 catch (const octave_execution_error) |
4497 { | |
4498 error ("source: error sourcing file '%s'", | |
4499 file_full_name.c_str ()); | |
4500 } | |
4501 | |
4502 if (fcn && fcn->is_user_script ()) | |
4503 { | |
4504 octave_value_list args; | |
4505 | |
4506 if (verbose) | |
4511 { | 4507 { |
4512 if (fcn && fcn->is_user_script ()) | 4508 std::cout << "executing commands from " << file_full_name << " ... "; |
4513 { | 4509 reading_startup_message_printed = true; |
4514 octave_value_list args; | 4510 std::cout.flush (); |
4515 | |
4516 if (verbose) | |
4517 { | |
4518 std::cout << "executing commands from " << file_full_name << " ... "; | |
4519 reading_startup_message_printed = true; | |
4520 std::cout.flush (); | |
4521 } | |
4522 | |
4523 fcn->do_multi_index_op (0, args); | |
4524 | |
4525 if (verbose) | |
4526 std::cout << "done." << std::endl; | |
4527 | |
4528 delete fcn; | |
4529 } | |
4530 } | 4511 } |
4531 else | 4512 |
4532 error ("source: error sourcing file '%s'", | 4513 fcn->do_multi_index_op (0, args); |
4533 file_full_name.c_str ()); | 4514 |
4515 if (verbose) | |
4516 std::cout << "done." << std::endl; | |
4517 | |
4518 delete fcn; | |
4534 } | 4519 } |
4535 } | 4520 } |
4536 | 4521 |
4537 DEFUN (mfilename, args, , | 4522 DEFUN (mfilename, args, , |
4538 "-*- texinfo -*-\n\ | 4523 "-*- texinfo -*-\n\ |
4659 | 4644 |
4660 if (fcn.is_defined ()) | 4645 if (fcn.is_defined ()) |
4661 retval = fcn.do_multi_index_op (nargout, args); | 4646 retval = fcn.do_multi_index_op (nargout, args); |
4662 else | 4647 else |
4663 { | 4648 { |
4664 maybe_missing_function_hook (name); | 4649 try |
4665 if (! error_state) | 4650 { |
4666 error ("feval: function '%s' not found", name.c_str ()); | 4651 maybe_missing_function_hook (name); |
4652 } | |
4653 catch (const octave_execution_exception&) | |
4654 { | |
4655 error ("feval: function '%s' not found", name.c_str ()); | |
4656 } | |
4667 } | 4657 } |
4668 | 4658 |
4669 return retval; | 4659 return retval; |
4670 } | 4660 } |
4671 | 4661 |
4706 | 4696 |
4707 if (f_arg.is_string ()) | 4697 if (f_arg.is_string ()) |
4708 { | 4698 { |
4709 std::string name = f_arg.string_value (); | 4699 std::string name = f_arg.string_value (); |
4710 | 4700 |
4711 if (! error_state) | 4701 octave_value_list tmp_args = get_feval_args (args); |
4712 { | 4702 |
4713 octave_value_list tmp_args = get_feval_args (args); | 4703 retval = feval (name, tmp_args, nargout); |
4714 | |
4715 retval = feval (name, tmp_args, nargout); | |
4716 } | |
4717 } | 4704 } |
4718 else if (f_arg.is_function_handle () | 4705 else if (f_arg.is_function_handle () |
4719 || f_arg.is_anonymous_function () | 4706 || f_arg.is_anonymous_function () |
4720 || f_arg.is_inline_function ()) | 4707 || f_arg.is_inline_function ()) |
4721 { | 4708 { |
4876 else | 4863 else |
4877 do_bind_ans = (! expr->is_assignment_expression ()); | 4864 do_bind_ans = (! expr->is_assignment_expression ()); |
4878 | 4865 |
4879 retval = expr->rvalue (nargout); | 4866 retval = expr->rvalue (nargout); |
4880 | 4867 |
4881 if (do_bind_ans && ! (error_state || retval.empty ())) | 4868 if (do_bind_ans && ! retval.empty ()) |
4882 bind_ans (retval(0), expr->print_result ()); | 4869 bind_ans (retval(0), expr->print_result ()); |
4883 | 4870 |
4884 if (nargout == 0) | 4871 if (nargout == 0) |
4885 retval = octave_value_list (); | 4872 retval = octave_value_list (); |
4886 } | 4873 } |
4887 else if (nargout == 0) | 4874 else if (nargout == 0) |
4888 parser.stmt_list->accept (*current_evaluator); | 4875 parser.stmt_list->accept (*current_evaluator); |
4889 else | 4876 else |
4890 error ("eval: invalid use of statement list"); | 4877 error ("eval: invalid use of statement list"); |
4891 | 4878 |
4892 if (error_state | 4879 if (tree_return_command::returning |
4893 || tree_return_command::returning | |
4894 || tree_break_command::breaking | 4880 || tree_break_command::breaking |
4895 || tree_continue_command::continuing) | 4881 || tree_continue_command::continuing) |
4896 break; | 4882 break; |
4897 } | 4883 } |
4898 else if (parser.lexer.end_of_input) | 4884 else if (parser.lexer.end_of_input) |
5156 else if (context == "base") | 5142 else if (context == "base") |
5157 octave_call_stack::goto_base_frame (); | 5143 octave_call_stack::goto_base_frame (); |
5158 else | 5144 else |
5159 error ("evalin: CONTEXT must be \"caller\" or \"base\""); | 5145 error ("evalin: CONTEXT must be \"caller\" or \"base\""); |
5160 | 5146 |
5161 if (! error_state) | 5147 frame.add_fcn (octave_call_stack::pop); |
5148 | |
5149 if (nargin > 2) | |
5162 { | 5150 { |
5163 frame.add_fcn (octave_call_stack::pop); | 5151 frame.protect_var (buffer_error_messages); |
5164 | 5152 buffer_error_messages++; |
5165 if (nargin > 2) | 5153 } |
5166 { | 5154 |
5167 frame.protect_var (buffer_error_messages); | 5155 int parse_status = 0; |
5168 buffer_error_messages++; | 5156 |
5169 } | 5157 bool execution_error = false; |
5170 | 5158 |
5171 int parse_status = 0; | 5159 octave_value_list tmp; |
5172 | 5160 |
5173 bool execution_error = false; | 5161 try |
5174 | 5162 { |
5175 octave_value_list tmp; | 5163 tmp = eval_string (args(1), nargout > 0, |
5176 | 5164 parse_status, nargout); |
5177 try | 5165 } |
5178 { | 5166 catch (const octave_execution_exception&) |
5179 tmp = eval_string (args(1), nargout > 0, | 5167 { |
5180 parse_status, nargout); | 5168 execution_error = true; |
5181 } | 5169 } |
5182 catch (const octave_execution_exception&) | 5170 |
5183 { | 5171 if (nargin > 2 && (parse_status != 0 || execution_error)) |
5184 execution_error = true; | 5172 { |
5185 } | 5173 // Set up for letting the user print any messages from |
5186 | 5174 // errors that occurred in the first part of this eval(). |
5187 if (nargin > 2 && (parse_status != 0 || execution_error)) | 5175 |
5188 { | 5176 buffer_error_messages--; |
5189 // Set up for letting the user print any messages from | 5177 |
5190 // errors that occurred in the first part of this eval(). | 5178 tmp = eval_string (args(2), nargout > 0, |
5191 | 5179 parse_status, nargout); |
5192 buffer_error_messages--; | 5180 |
5193 | 5181 retval = (nargout > 0) ? tmp : octave_value_list (); |
5194 tmp = eval_string (args(2), nargout > 0, | 5182 } |
5195 parse_status, nargout); | 5183 else |
5196 | 5184 { |
5197 retval = (nargout > 0) ? tmp : octave_value_list (); | 5185 if (nargout > 0) |
5198 } | 5186 retval = tmp; |
5199 else | 5187 |
5200 { | 5188 // FIXME: we should really be rethrowing whatever |
5201 if (nargout > 0) | 5189 // exception occurred, not just throwing an |
5202 retval = tmp; | 5190 // execution exception. |
5203 | 5191 if (execution_error) |
5204 // FIXME: we should really be rethrowing whatever | 5192 octave_throw_execution_exception (); |
5205 // exception occurred, not just throwing an | |
5206 // execution exception. | |
5207 if (execution_error) | |
5208 octave_throw_execution_exception (); | |
5209 } | |
5210 } | 5193 } |
5211 } | 5194 } |
5212 else | 5195 else |
5213 error ("evalin: CONTEXT must be a string"); | 5196 error ("evalin: CONTEXT must be a string"); |
5214 } | 5197 } |