Mercurial > octave-nkf
comparison libinterp/parse-tree/pt-eval.cc @ 20592:56fee8f84fe7
eliminate more simple uses of error_state
* cellfun.cc, syscalls.cc, urlwrite.cc, ov.cc, pt-eval.cc:
Eliminate uses of error_state.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 05 Oct 2015 22:47:42 -0400 |
parents | b70cc4bd8109 |
children | b65888ec820e |
comparison
equal
deleted
inserted
replaced
20591:0650b8431037 | 20592:56fee8f84fe7 |
---|---|
95 } | 95 } |
96 | 96 |
97 void | 97 void |
98 tree_evaluator::visit_break_command (tree_break_command& cmd) | 98 tree_evaluator::visit_break_command (tree_break_command& cmd) |
99 { | 99 { |
100 if (! error_state) | 100 if (debug_mode) |
101 { | 101 do_breakpoint (cmd.is_breakpoint ()); |
102 if (debug_mode) | 102 |
103 do_breakpoint (cmd.is_breakpoint ()); | 103 if (statement_context == function || statement_context == script |
104 | 104 || in_loop_command) |
105 if (statement_context == function || statement_context == script | 105 tree_break_command::breaking = 1; |
106 || in_loop_command) | |
107 tree_break_command::breaking = 1; | |
108 } | |
109 } | 106 } |
110 | 107 |
111 void | 108 void |
112 tree_evaluator::visit_colon_expression (tree_colon_expression&) | 109 tree_evaluator::visit_colon_expression (tree_colon_expression&) |
113 { | 110 { |
115 } | 112 } |
116 | 113 |
117 void | 114 void |
118 tree_evaluator::visit_continue_command (tree_continue_command& cmd) | 115 tree_evaluator::visit_continue_command (tree_continue_command& cmd) |
119 { | 116 { |
120 if (! error_state) | 117 if (debug_mode) |
121 { | 118 do_breakpoint (cmd.is_breakpoint ()); |
122 if (debug_mode) | 119 |
123 do_breakpoint (cmd.is_breakpoint ()); | 120 if (statement_context == function || statement_context == script |
124 | 121 || in_loop_command) |
125 if (statement_context == function || statement_context == script | 122 tree_continue_command::continuing = 1; |
126 || in_loop_command) | |
127 tree_continue_command::continuing = 1; | |
128 } | |
129 } | 123 } |
130 | 124 |
131 void | 125 void |
132 tree_evaluator::reset_debug_state (void) | 126 tree_evaluator::reset_debug_state (void) |
133 { | 127 { |
149 tree_identifier *id = elt.ident (); | 143 tree_identifier *id = elt.ident (); |
150 | 144 |
151 if (id) | 145 if (id) |
152 { | 146 { |
153 id->mark_global (); | 147 id->mark_global (); |
154 | |
155 if (! error_state) | |
156 { | |
157 octave_lvalue ult = id->lvalue (); | |
158 | |
159 if (ult.is_undefined ()) | |
160 { | |
161 tree_expression *expr = elt.expression (); | |
162 | |
163 octave_value init_val; | |
164 | |
165 if (expr) | |
166 init_val = expr->rvalue1 (); | |
167 else | |
168 init_val = Matrix (); | |
169 | |
170 ult.assign (octave_value::op_asn_eq, init_val); | |
171 } | |
172 } | |
173 } | |
174 } | |
175 | |
176 static inline void | |
177 do_static_init (tree_decl_elt& elt) | |
178 { | |
179 tree_identifier *id = elt.ident (); | |
180 | |
181 if (id) | |
182 { | |
183 id->mark_as_static (); | |
184 | 148 |
185 octave_lvalue ult = id->lvalue (); | 149 octave_lvalue ult = id->lvalue (); |
186 | 150 |
187 if (ult.is_undefined ()) | 151 if (ult.is_undefined ()) |
188 { | 152 { |
198 ult.assign (octave_value::op_asn_eq, init_val); | 162 ult.assign (octave_value::op_asn_eq, init_val); |
199 } | 163 } |
200 } | 164 } |
201 } | 165 } |
202 | 166 |
167 static inline void | |
168 do_static_init (tree_decl_elt& elt) | |
169 { | |
170 tree_identifier *id = elt.ident (); | |
171 | |
172 if (id) | |
173 { | |
174 id->mark_as_static (); | |
175 | |
176 octave_lvalue ult = id->lvalue (); | |
177 | |
178 if (ult.is_undefined ()) | |
179 { | |
180 tree_expression *expr = elt.expression (); | |
181 | |
182 octave_value init_val; | |
183 | |
184 if (expr) | |
185 init_val = expr->rvalue1 (); | |
186 else | |
187 init_val = Matrix (); | |
188 | |
189 ult.assign (octave_value::op_asn_eq, init_val); | |
190 } | |
191 } | |
192 } | |
193 | |
203 void | 194 void |
204 tree_evaluator::do_decl_init_list (decl_elt_init_fcn fcn, | 195 tree_evaluator::do_decl_init_list (decl_elt_init_fcn fcn, |
205 tree_decl_init_list *init_list) | 196 tree_decl_init_list *init_list) |
206 { | 197 { |
207 if (init_list) | 198 if (init_list) |
210 p != init_list->end (); p++) | 201 p != init_list->end (); p++) |
211 { | 202 { |
212 tree_decl_elt *elt = *p; | 203 tree_decl_elt *elt = *p; |
213 | 204 |
214 fcn (*elt); | 205 fcn (*elt); |
215 | |
216 if (error_state) | |
217 break; | |
218 } | 206 } |
219 } | 207 } |
220 } | 208 } |
221 | 209 |
222 void | 210 void |
253 { | 241 { |
254 octave_lvalue ult = id->lvalue (); | 242 octave_lvalue ult = id->lvalue (); |
255 | 243 |
256 octave_value init_val = expr->rvalue1 (); | 244 octave_value init_val = expr->rvalue1 (); |
257 | 245 |
258 if (! error_state) | 246 ult.assign (octave_value::op_asn_eq, init_val); |
259 { | 247 |
260 ult.assign (octave_value::op_asn_eq, init_val); | 248 retval = true; |
261 | |
262 retval = true; | |
263 } | |
264 } | 249 } |
265 | 250 |
266 return retval; | 251 return retval; |
267 } | 252 } |
268 #endif | 253 #endif |
282 // Maybe handle 'continue N' someday... | 267 // Maybe handle 'continue N' someday... |
283 | 268 |
284 if (tree_continue_command::continuing) | 269 if (tree_continue_command::continuing) |
285 tree_continue_command::continuing--; | 270 tree_continue_command::continuing--; |
286 | 271 |
287 bool quit = (error_state | 272 bool quit = (tree_return_command::returning |
288 || tree_return_command::returning | |
289 || tree_break_command::breaking | 273 || tree_break_command::breaking |
290 || tree_continue_command::continuing); | 274 || tree_continue_command::continuing); |
291 | 275 |
292 if (tree_break_command::breaking) | 276 if (tree_break_command::breaking) |
293 tree_break_command::breaking--; | 277 tree_break_command::breaking--; |
296 } | 280 } |
297 | 281 |
298 void | 282 void |
299 tree_evaluator::visit_simple_for_command (tree_simple_for_command& cmd) | 283 tree_evaluator::visit_simple_for_command (tree_simple_for_command& cmd) |
300 { | 284 { |
301 if (error_state) | |
302 return; | |
303 | |
304 if (debug_mode) | 285 if (debug_mode) |
305 do_breakpoint (cmd.is_breakpoint ()); | 286 do_breakpoint (cmd.is_breakpoint ()); |
306 | 287 |
307 // FIXME: need to handle PARFOR loops here using cmd.in_parallel () | 288 // FIXME: need to handle PARFOR loops here using cmd.in_parallel () |
308 // and cmd.maxproc_expr (); | 289 // and cmd.maxproc_expr (); |
320 #if HAVE_LLVM | 301 #if HAVE_LLVM |
321 if (tree_jit::execute (cmd, rhs)) | 302 if (tree_jit::execute (cmd, rhs)) |
322 return; | 303 return; |
323 #endif | 304 #endif |
324 | 305 |
325 if (error_state || rhs.is_undefined ()) | 306 if (rhs.is_undefined ()) |
326 return; | 307 return; |
327 | 308 |
328 { | 309 { |
329 tree_expression *lhs = cmd.left_hand_side (); | 310 tree_expression *lhs = cmd.left_hand_side (); |
330 | 311 |
331 octave_lvalue ult = lhs->lvalue (); | 312 octave_lvalue ult = lhs->lvalue (); |
332 | |
333 if (error_state) | |
334 return; | |
335 | 313 |
336 tree_statement_list *loop_body = cmd.body (); | 314 tree_statement_list *loop_body = cmd.body (); |
337 | 315 |
338 if (rhs.is_range ()) | 316 if (rhs.is_range ()) |
339 { | 317 { |
345 { | 323 { |
346 octave_value val (rng.elem (i)); | 324 octave_value val (rng.elem (i)); |
347 | 325 |
348 ult.assign (octave_value::op_asn_eq, val); | 326 ult.assign (octave_value::op_asn_eq, val); |
349 | 327 |
350 if (! error_state && loop_body) | 328 if (loop_body) |
351 loop_body->accept (*this); | 329 loop_body->accept (*this); |
352 | 330 |
353 if (quit_loop_now ()) | 331 if (quit_loop_now ()) |
354 break; | 332 break; |
355 } | 333 } |
356 } | 334 } |
357 else if (rhs.is_scalar_type ()) | 335 else if (rhs.is_scalar_type ()) |
358 { | 336 { |
359 ult.assign (octave_value::op_asn_eq, rhs); | 337 ult.assign (octave_value::op_asn_eq, rhs); |
360 | 338 |
361 if (! error_state && loop_body) | 339 if (loop_body) |
362 loop_body->accept (*this); | 340 loop_body->accept (*this); |
363 | 341 |
364 // Maybe decrement break and continue states. | 342 // Maybe decrement break and continue states. |
365 quit_loop_now (); | 343 quit_loop_now (); |
366 } | 344 } |
402 idx(iidx) = i; | 380 idx(iidx) = i; |
403 octave_value val = arg.do_index_op (idx); | 381 octave_value val = arg.do_index_op (idx); |
404 | 382 |
405 ult.assign (octave_value::op_asn_eq, val); | 383 ult.assign (octave_value::op_asn_eq, val); |
406 | 384 |
407 if (! error_state && loop_body) | 385 if (loop_body) |
408 loop_body->accept (*this); | 386 loop_body->accept (*this); |
409 | 387 |
410 if (quit_loop_now ()) | 388 if (quit_loop_now ()) |
411 break; | 389 break; |
412 } | 390 } |
421 } | 399 } |
422 | 400 |
423 void | 401 void |
424 tree_evaluator::visit_complex_for_command (tree_complex_for_command& cmd) | 402 tree_evaluator::visit_complex_for_command (tree_complex_for_command& cmd) |
425 { | 403 { |
426 if (error_state) | |
427 return; | |
428 | |
429 if (debug_mode) | 404 if (debug_mode) |
430 do_breakpoint (cmd.is_breakpoint ()); | 405 do_breakpoint (cmd.is_breakpoint ()); |
431 | 406 |
432 unwind_protect frame; | 407 unwind_protect frame; |
433 | 408 |
437 | 412 |
438 tree_expression *expr = cmd.control_expr (); | 413 tree_expression *expr = cmd.control_expr (); |
439 | 414 |
440 octave_value rhs = expr->rvalue1 (); | 415 octave_value rhs = expr->rvalue1 (); |
441 | 416 |
442 if (error_state || rhs.is_undefined ()) | 417 if (rhs.is_undefined ()) |
443 return; | 418 return; |
444 | 419 |
445 if (rhs.is_map ()) | 420 if (rhs.is_map ()) |
446 { | 421 { |
447 // Cycle through structure elements. First element of id_list | 422 // Cycle through structure elements. First element of id_list |
479 octave_value val = (n == 1) ? val_lst(0) : octave_value (val_lst); | 454 octave_value val = (n == 1) ? val_lst(0) : octave_value (val_lst); |
480 | 455 |
481 val_ref.assign (octave_value::op_asn_eq, val); | 456 val_ref.assign (octave_value::op_asn_eq, val); |
482 key_ref.assign (octave_value::op_asn_eq, key); | 457 key_ref.assign (octave_value::op_asn_eq, key); |
483 | 458 |
484 if (! error_state && loop_body) | 459 if (loop_body) |
485 loop_body->accept (*this); | 460 loop_body->accept (*this); |
486 | 461 |
487 if (quit_loop_now ()) | 462 if (quit_loop_now ()) |
488 break; | 463 break; |
489 } | 464 } |
572 if (debug_mode && ! tic->is_else_clause ()) | 547 if (debug_mode && ! tic->is_else_clause ()) |
573 do_breakpoint (tic->is_breakpoint ()); | 548 do_breakpoint (tic->is_breakpoint ()); |
574 | 549 |
575 if (tic->is_else_clause () || expr->is_logically_true ("if")) | 550 if (tic->is_else_clause () || expr->is_logically_true ("if")) |
576 { | 551 { |
577 if (! error_state) | 552 tree_statement_list *stmt_lst = tic->commands (); |
578 { | 553 |
579 tree_statement_list *stmt_lst = tic->commands (); | 554 if (stmt_lst) |
580 | 555 stmt_lst->accept (*this); |
581 if (stmt_lst) | |
582 stmt_lst->accept (*this); | |
583 } | |
584 | 556 |
585 break; | 557 break; |
586 } | 558 } |
587 } | 559 } |
588 } | 560 } |
655 } | 627 } |
656 | 628 |
657 void | 629 void |
658 tree_evaluator::visit_return_command (tree_return_command& cmd) | 630 tree_evaluator::visit_return_command (tree_return_command& cmd) |
659 { | 631 { |
660 if (! error_state) | 632 if (debug_mode) |
661 { | 633 do_breakpoint (cmd.is_breakpoint ()); |
662 if (debug_mode) | 634 |
663 do_breakpoint (cmd.is_breakpoint ()); | 635 // Act like dbcont. |
664 | 636 |
665 // Act like dbcont. | 637 if (Vdebugging |
666 | 638 && octave_call_stack::current_frame () == current_frame) |
667 if (Vdebugging | 639 { |
668 && octave_call_stack::current_frame () == current_frame) | 640 Vdebugging = false; |
669 { | 641 |
670 Vdebugging = false; | 642 reset_debug_state (); |
671 | 643 } |
672 reset_debug_state (); | 644 else if (statement_context == function || statement_context == script |
673 } | 645 || in_loop_command) |
674 else if (statement_context == function || statement_context == script | 646 tree_return_command::returning = 1; |
675 || in_loop_command) | |
676 tree_return_command::returning = 1; | |
677 } | |
678 } | 647 } |
679 | 648 |
680 void | 649 void |
681 tree_evaluator::visit_return_list (tree_return_list&) | 650 tree_evaluator::visit_return_list (tree_return_list&) |
682 { | 651 { |
743 else | 712 else |
744 do_bind_ans = (! expr->is_assignment_expression ()); | 713 do_bind_ans = (! expr->is_assignment_expression ()); |
745 | 714 |
746 octave_value tmp_result = expr->rvalue1 (0); | 715 octave_value tmp_result = expr->rvalue1 (0); |
747 | 716 |
748 if (do_bind_ans && ! (error_state || tmp_result.is_undefined ())) | 717 if (do_bind_ans && tmp_result.is_defined ()) |
749 bind_ans (tmp_result, expr->print_result () | 718 bind_ans (tmp_result, expr->print_result () |
750 && statement_printing_enabled ()); | 719 && statement_printing_enabled ()); |
751 | 720 |
752 // if (tmp_result.is_defined ()) | 721 // if (tmp_result.is_defined ()) |
753 // result_values(0) = tmp_result; | 722 // result_values(0) = tmp_result; |
754 } | 723 } |
755 } | 724 } |
756 catch (const std::bad_alloc&) | 725 catch (const std::bad_alloc&) |
757 { | 726 { |
758 // FIXME: We want to use error_with_id here so that we set | 727 // FIXME: We want to use error_with_id here so that give users |
759 // the error state, give users control over this error | 728 // control over this error message but error_with_id will |
760 // message, and so that we set the error_state appropriately | 729 // require some memory allocations. Is there anything we can |
761 // so we'll get stack trace info when appropriate. But | 730 // do to make those more likely to succeed? |
762 // error_with_id will require some memory allocations. Is | |
763 // there anything we can do to make those more likely to | |
764 // succeed? | |
765 | 731 |
766 error_with_id ("Octave:bad-alloc", | 732 error_with_id ("Octave:bad-alloc", |
767 "out of memory or dimension too large for Octave's index type"); | 733 "out of memory or dimension too large for Octave's index type"); |
768 } | 734 } |
769 } | 735 } |
771 | 737 |
772 void | 738 void |
773 tree_evaluator::visit_statement_list (tree_statement_list& lst) | 739 tree_evaluator::visit_statement_list (tree_statement_list& lst) |
774 { | 740 { |
775 static octave_value_list empty_list; | 741 static octave_value_list empty_list; |
776 | |
777 if (error_state) | |
778 return; | |
779 | 742 |
780 tree_statement_list::iterator p = lst.begin (); | 743 tree_statement_list::iterator p = lst.begin (); |
781 | 744 |
782 if (p != lst.end ()) | 745 if (p != lst.end ()) |
783 { | 746 { |
788 if (elt) | 751 if (elt) |
789 { | 752 { |
790 octave_quit (); | 753 octave_quit (); |
791 | 754 |
792 elt->accept (*this); | 755 elt->accept (*this); |
793 | |
794 if (error_state) | |
795 break; | |
796 | 756 |
797 if (tree_break_command::breaking | 757 if (tree_break_command::breaking |
798 || tree_continue_command::continuing) | 758 || tree_continue_command::continuing) |
799 break; | 759 break; |
800 | 760 |
851 { | 811 { |
852 octave_value val = expr->rvalue1 (); | 812 octave_value val = expr->rvalue1 (); |
853 | 813 |
854 tree_switch_case_list *lst = cmd.case_list (); | 814 tree_switch_case_list *lst = cmd.case_list (); |
855 | 815 |
856 if (! error_state && lst) | 816 if (lst) |
857 { | 817 { |
858 for (tree_switch_case_list::iterator p = lst->begin (); | 818 for (tree_switch_case_list::iterator p = lst->begin (); |
859 p != lst->end (); p++) | 819 p != lst->end (); p++) |
860 { | 820 { |
861 tree_switch_case *t = *p; | 821 tree_switch_case *t = *p; |
862 | 822 |
863 if (t->is_default_case () || t->label_matches (val)) | 823 if (t->is_default_case () || t->label_matches (val)) |
864 { | 824 { |
865 if (error_state) | |
866 break; | |
867 | |
868 tree_statement_list *stmt_lst = t->commands (); | 825 tree_statement_list *stmt_lst = t->commands (); |
869 | 826 |
870 if (stmt_lst) | 827 if (stmt_lst) |
871 stmt_lst->accept (*this); | 828 stmt_lst->accept (*this); |
872 | 829 |
1058 | 1015 |
1059 // Run the cleanup code on exceptions, so that it is run even in case | 1016 // Run the cleanup code on exceptions, so that it is run even in case |
1060 // of interrupt or out-of-memory. | 1017 // of interrupt or out-of-memory. |
1061 do_unwind_protect_cleanup_code (cleanup_code); | 1018 do_unwind_protect_cleanup_code (cleanup_code); |
1062 | 1019 |
1063 // FIXME: should error_state be checked here? | 1020 // We want to rethrow the exception so that interrupts continue. |
1064 // We want to rethrow the exception, even if error_state is set, so | |
1065 // that interrupts continue. | |
1066 throw; | 1021 throw; |
1067 } | 1022 } |
1068 | 1023 |
1069 do_unwind_protect_cleanup_code (cleanup_code); | 1024 do_unwind_protect_cleanup_code (cleanup_code); |
1070 } | 1025 } |
1071 } | 1026 } |
1072 | 1027 |
1073 void | 1028 void |
1074 tree_evaluator::visit_while_command (tree_while_command& cmd) | 1029 tree_evaluator::visit_while_command (tree_while_command& cmd) |
1075 { | 1030 { |
1076 if (error_state) | |
1077 return; | |
1078 | |
1079 #if HAVE_LLVM | 1031 #if HAVE_LLVM |
1080 if (tree_jit::execute (cmd)) | 1032 if (tree_jit::execute (cmd)) |
1081 return; | 1033 return; |
1082 #endif | 1034 #endif |
1083 | 1035 |
1100 if (expr->is_logically_true ("while")) | 1052 if (expr->is_logically_true ("while")) |
1101 { | 1053 { |
1102 tree_statement_list *loop_body = cmd.body (); | 1054 tree_statement_list *loop_body = cmd.body (); |
1103 | 1055 |
1104 if (loop_body) | 1056 if (loop_body) |
1105 { | 1057 loop_body->accept (*this); |
1106 loop_body->accept (*this); | |
1107 | |
1108 if (error_state) | |
1109 return; | |
1110 } | |
1111 | 1058 |
1112 if (quit_loop_now ()) | 1059 if (quit_loop_now ()) |
1113 break; | 1060 break; |
1114 } | 1061 } |
1115 else | 1062 else |
1118 } | 1065 } |
1119 | 1066 |
1120 void | 1067 void |
1121 tree_evaluator::visit_do_until_command (tree_do_until_command& cmd) | 1068 tree_evaluator::visit_do_until_command (tree_do_until_command& cmd) |
1122 { | 1069 { |
1123 if (error_state) | |
1124 return; | |
1125 | |
1126 #if HAVE_LLVM | 1070 #if HAVE_LLVM |
1127 if (tree_jit::execute (cmd)) | 1071 if (tree_jit::execute (cmd)) |
1128 return; | 1072 return; |
1129 #endif | 1073 #endif |
1130 | 1074 |
1142 for (;;) | 1086 for (;;) |
1143 { | 1087 { |
1144 tree_statement_list *loop_body = cmd.body (); | 1088 tree_statement_list *loop_body = cmd.body (); |
1145 | 1089 |
1146 if (loop_body) | 1090 if (loop_body) |
1147 { | 1091 loop_body->accept (*this); |
1148 loop_body->accept (*this); | |
1149 | |
1150 if (error_state) | |
1151 return; | |
1152 } | |
1153 | 1092 |
1154 if (quit_loop_now ()) | 1093 if (quit_loop_now ()) |
1155 break; | 1094 break; |
1156 | 1095 |
1157 if (debug_mode) | 1096 if (debug_mode) |