1742
|
1 // pt-cmd.cc -*- C++ -*- |
494
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton |
494
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
494
|
21 |
|
22 */ |
|
23 |
1297
|
24 #if defined (__GNUG__) |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
494
|
28 #ifdef HAVE_CONFIG_H |
1192
|
29 #include <config.h> |
494
|
30 #endif |
|
31 |
|
32 #include <iostream.h> |
|
33 |
1059
|
34 // Nonzero means we're breaking out of a loop or function body. |
578
|
35 int breaking = 0; |
|
36 |
|
37 // Nonzero means we're jumping to the end of a loop. |
|
38 int continuing = 0; |
|
39 |
|
40 // Nonzero means we're returning from a function. Global because it |
|
41 // is also needed in tree-expr.cc. |
|
42 int returning = 0; |
|
43 |
494
|
44 #include "error.h" |
|
45 #include "gripes.h" |
1352
|
46 #include "oct-map.h" |
|
47 #include "symtab.h" |
1742
|
48 #include "pt-cmd.h" |
|
49 #include "pt-const.h" |
|
50 #include "pt-exp.h" |
|
51 #include "pt-fvc.h" |
|
52 #include "pt-misc.h" |
|
53 #include "pt-mvr.h" |
916
|
54 #include "unwind-prot.h" |
1352
|
55 #include "user-prefs.h" |
|
56 #include "variables.h" |
494
|
57 |
|
58 // Decide if it's time to quit a for or while loop. |
1168
|
59 static inline int |
494
|
60 quit_loop_now (void) |
|
61 { |
1228
|
62 // Maybe handle `continue N' someday... |
494
|
63 |
|
64 if (continuing) |
|
65 continuing--; |
|
66 |
|
67 int quit = (returning || breaking || continuing); |
|
68 |
|
69 if (breaking) |
|
70 breaking--; |
|
71 |
|
72 return quit; |
|
73 } |
|
74 |
|
75 // But first, some extra functions used by the tree classes. |
|
76 |
|
77 // We seem to have no use for this now. Maybe it will be needed at |
|
78 // some future date, so here it is. |
|
79 #if 0 |
578
|
80 |
|
81 // Convert a linked list of trees to a vector of pointers to trees. |
|
82 |
494
|
83 static tree ** |
|
84 list_to_vector (tree *list, int& len) |
|
85 { |
|
86 len = list->length () + 1; |
|
87 |
|
88 tree **args = new tree * [len]; |
|
89 |
1228
|
90 // args[0] may eventually hold something useful, like the function |
|
91 // name. |
|
92 |
494
|
93 tree *tmp_list = list; |
|
94 for (int k = 1; k < len; k++) |
|
95 { |
|
96 args[k] = tmp_list; |
|
97 tmp_list = tmp_list->next_elem (); |
|
98 } |
|
99 return args; |
|
100 } |
|
101 #endif |
|
102 |
578
|
103 // Global. |
494
|
104 |
578
|
105 tree_global_command::~tree_global_command (void) |
494
|
106 { |
578
|
107 delete init_list; |
494
|
108 } |
|
109 |
|
110 void |
578
|
111 tree_global_command::eval (void) |
494
|
112 { |
578
|
113 if (init_list) |
|
114 init_list->eval (); |
494
|
115 |
|
116 if (error_state > 0) |
|
117 ::error ("evaluating global command near line %d, column %d", |
|
118 line (), column ()); |
|
119 } |
|
120 |
581
|
121 void |
|
122 tree_global_command::print_code (ostream& os) |
|
123 { |
|
124 print_code_indent (os); |
|
125 |
|
126 os << "global "; |
|
127 |
|
128 if (init_list) |
|
129 init_list->print_code (os); |
|
130 } |
|
131 |
578
|
132 // While. |
494
|
133 |
|
134 tree_while_command::~tree_while_command (void) |
|
135 { |
|
136 delete expr; |
|
137 delete list; |
|
138 } |
|
139 |
578
|
140 void |
|
141 tree_while_command::eval (void) |
494
|
142 { |
|
143 if (error_state) |
578
|
144 return; |
494
|
145 |
1491
|
146 if (! expr) |
|
147 panic_impossible (); |
|
148 |
494
|
149 for (;;) |
|
150 { |
1491
|
151 if (expr->is_logically_true ("while")) |
494
|
152 { |
529
|
153 if (list) |
494
|
154 { |
578
|
155 list->eval (1); |
494
|
156 if (error_state) |
|
157 { |
|
158 eval_error (); |
578
|
159 return; |
494
|
160 } |
|
161 } |
|
162 |
|
163 if (quit_loop_now ()) |
|
164 break; |
|
165 } |
|
166 else |
|
167 break; |
|
168 } |
|
169 } |
|
170 |
|
171 void |
|
172 tree_while_command::eval_error (void) |
|
173 { |
|
174 if (error_state > 0) |
|
175 ::error ("evaluating while command near line %d, column %d", |
|
176 line (), column ()); |
|
177 } |
|
178 |
581
|
179 void |
|
180 tree_while_command::print_code (ostream& os) |
|
181 { |
|
182 print_code_indent (os); |
|
183 |
|
184 os << "while "; |
|
185 |
|
186 if (expr) |
|
187 expr->print_code (os); |
|
188 |
|
189 print_code_new_line (os); |
|
190 |
|
191 if (list) |
|
192 { |
|
193 increment_indent_level (); |
|
194 list->print_code (os); |
|
195 decrement_indent_level (); |
|
196 } |
|
197 |
|
198 print_code_indent (os); |
|
199 |
|
200 os << "endwhile"; |
|
201 } |
|
202 |
578
|
203 // For. |
494
|
204 |
|
205 tree_for_command::~tree_for_command (void) |
|
206 { |
|
207 delete id; |
1228
|
208 delete id_list; |
494
|
209 delete expr; |
|
210 delete list; |
|
211 } |
|
212 |
1168
|
213 inline void |
1228
|
214 tree_for_command::do_for_loop_once (tree_return_list *lst, |
|
215 const Octave_object& rhs, int& quit) |
|
216 { |
|
217 quit = 0; |
|
218 |
|
219 tree_oct_obj *tmp = new tree_oct_obj (rhs); |
|
220 tree_multi_assignment_expression tmp_ass (lst, tmp, 1); |
|
221 tmp_ass.eval (0); |
|
222 |
|
223 if (error_state) |
|
224 { |
|
225 eval_error (); |
|
226 return; |
|
227 } |
|
228 |
|
229 if (list) |
|
230 { |
|
231 list->eval (1); |
|
232 if (error_state) |
|
233 { |
|
234 eval_error (); |
|
235 quit = 1; |
|
236 return; |
|
237 } |
|
238 } |
|
239 |
|
240 quit = quit_loop_now (); |
|
241 } |
|
242 |
|
243 inline void |
|
244 tree_for_command::do_for_loop_once (tree_index_expression *idx_expr, |
|
245 const tree_constant& rhs, int& quit) |
1168
|
246 { |
|
247 quit = 0; |
|
248 |
|
249 tree_constant *tmp = new tree_constant (rhs); |
1228
|
250 tree_simple_assignment_expression tmp_ass (idx_expr, tmp, 1); |
1168
|
251 tmp_ass.eval (0); |
|
252 |
|
253 if (error_state) |
|
254 { |
|
255 eval_error (); |
|
256 return; |
|
257 } |
|
258 |
|
259 if (list) |
|
260 { |
|
261 list->eval (1); |
|
262 if (error_state) |
|
263 { |
|
264 eval_error (); |
|
265 quit = 1; |
|
266 return; |
|
267 } |
|
268 } |
|
269 |
|
270 quit = quit_loop_now (); |
|
271 } |
|
272 |
|
273 inline void |
|
274 tree_for_command::do_for_loop_once (tree_identifier *ident, |
|
275 tree_constant& rhs, int& quit) |
|
276 { |
|
277 quit = 0; |
|
278 |
|
279 ident->assign (rhs); |
|
280 |
|
281 if (error_state) |
|
282 { |
|
283 eval_error (); |
|
284 return; |
|
285 } |
|
286 |
|
287 if (list) |
|
288 { |
|
289 list->eval (1); |
|
290 if (error_state) |
|
291 { |
|
292 eval_error (); |
|
293 quit = 1; |
|
294 return; |
|
295 } |
|
296 } |
|
297 |
|
298 quit = quit_loop_now (); |
|
299 } |
|
300 |
|
301 #define DO_LOOP(val) \ |
|
302 do \ |
|
303 { \ |
|
304 if (ident) \ |
|
305 for (int i = 0; i < steps; i++) \ |
|
306 { \ |
|
307 tree_constant rhs (val); \ |
|
308 int quit = 0; \ |
|
309 do_for_loop_once (ident, rhs, quit); \ |
|
310 if (quit) \ |
|
311 break; \ |
|
312 } \ |
1228
|
313 else if (id_list) \ |
|
314 for (int i = 0; i < steps; i++) \ |
|
315 { \ |
|
316 Octave_object rhs (val); \ |
|
317 int quit = 0; \ |
|
318 do_for_loop_once (id_list, rhs, quit); \ |
|
319 if (quit) \ |
|
320 break; \ |
|
321 } \ |
1168
|
322 else \ |
|
323 for (int i = 0; i < steps; i++) \ |
|
324 { \ |
|
325 tree_constant rhs (val); \ |
|
326 int quit = 0; \ |
1228
|
327 do_for_loop_once (tmp_id, rhs, quit); \ |
1168
|
328 if (quit) \ |
|
329 break; \ |
|
330 } \ |
|
331 } \ |
|
332 while (0) |
|
333 |
578
|
334 void |
|
335 tree_for_command::eval (void) |
494
|
336 { |
529
|
337 if (error_state || ! expr) |
578
|
338 return; |
494
|
339 |
|
340 tree_constant tmp_expr = expr->eval (0); |
|
341 |
|
342 if (error_state || tmp_expr.is_undefined ()) |
|
343 { |
|
344 eval_error (); |
578
|
345 return; |
494
|
346 } |
|
347 |
1228
|
348 tree_index_expression *tmp_id = id; |
|
349 if (id_list && id_list->length () == 1) |
|
350 tmp_id = id_list->front (); |
|
351 |
1168
|
352 tree_identifier *ident = 0; |
1228
|
353 if (tmp_id && ! tmp_id->arg_list ()) |
1168
|
354 { |
1228
|
355 tree_indirect_ref *idr = tmp_id->ident (); |
1168
|
356 if (idr->is_identifier_only ()) |
|
357 ident = idr->ident (); |
|
358 } |
|
359 |
1234
|
360 if (id_list && ! ident && ! tmp_expr.is_map ()) |
1228
|
361 { |
|
362 error ("in statement `for [X, Y] = VAL', VAL must be a structure"); |
|
363 return; |
|
364 } |
|
365 |
620
|
366 if (tmp_expr.is_scalar_type ()) |
|
367 { |
|
368 int quit = 0; |
1168
|
369 if (ident) |
|
370 do_for_loop_once (ident, tmp_expr, quit); |
1228
|
371 else if (id_list) |
|
372 { |
|
373 Octave_object rhs (tmp_expr); |
|
374 do_for_loop_once (id_list, rhs, quit); |
|
375 } |
1168
|
376 else |
1228
|
377 do_for_loop_once (tmp_id, tmp_expr, quit); |
620
|
378 } |
|
379 else if (tmp_expr.is_matrix_type ()) |
494
|
380 { |
620
|
381 Matrix m_tmp; |
|
382 ComplexMatrix cm_tmp; |
|
383 int nr; |
|
384 int steps; |
|
385 if (tmp_expr.is_real_matrix ()) |
|
386 { |
|
387 m_tmp = tmp_expr.matrix_value (); |
|
388 nr = m_tmp.rows (); |
|
389 steps = m_tmp.columns (); |
|
390 } |
|
391 else |
|
392 { |
|
393 cm_tmp = tmp_expr.complex_matrix_value (); |
|
394 nr = cm_tmp.rows (); |
|
395 steps = cm_tmp.columns (); |
|
396 } |
494
|
397 |
1168
|
398 if (tmp_expr.is_real_matrix ()) |
620
|
399 { |
|
400 if (nr == 1) |
1168
|
401 DO_LOOP(m_tmp (0, i)); |
620
|
402 else |
1168
|
403 DO_LOOP(m_tmp.extract (0, i, nr-1, i)); |
|
404 } |
|
405 else |
|
406 { |
|
407 if (nr == 1) |
|
408 DO_LOOP(cm_tmp (0, i)); |
|
409 else |
|
410 DO_LOOP(cm_tmp.extract (0, i, nr-1, i)); |
620
|
411 } |
|
412 } |
|
413 else if (tmp_expr.is_string ()) |
|
414 { |
494
|
415 gripe_string_invalid (); |
620
|
416 } |
|
417 else if (tmp_expr.is_range ()) |
|
418 { |
|
419 Range rng = tmp_expr.range_value (); |
494
|
420 |
620
|
421 int steps = rng.nelem (); |
|
422 double b = rng.base (); |
|
423 double increment = rng.inc (); |
494
|
424 |
1168
|
425 if (ident) |
620
|
426 { |
1168
|
427 for (int i = 0; i < steps; i++) |
|
428 { |
|
429 double tmp_val = b + i * increment; |
|
430 |
|
431 tree_constant rhs (tmp_val); |
|
432 |
|
433 int quit = 0; |
|
434 do_for_loop_once (ident, rhs, quit); |
494
|
435 |
1168
|
436 if (quit) |
|
437 break; |
|
438 } |
|
439 } |
1228
|
440 else if (id_list) |
|
441 { |
|
442 for (int i = 0; i < steps; i++) |
|
443 { |
|
444 double tmp_val = b + i * increment; |
|
445 |
|
446 Octave_object rhs (tmp_val); |
|
447 |
|
448 int quit = 0; |
|
449 do_for_loop_once (id_list, rhs, quit); |
|
450 |
|
451 if (quit) |
|
452 break; |
|
453 } |
|
454 } |
1168
|
455 else |
|
456 { |
|
457 for (int i = 0; i < steps; i++) |
|
458 { |
|
459 double tmp_val = b + i * increment; |
494
|
460 |
1168
|
461 tree_constant rhs (tmp_val); |
|
462 |
|
463 int quit = 0; |
1228
|
464 do_for_loop_once (tmp_id, rhs, quit); |
|
465 |
|
466 if (quit) |
|
467 break; |
|
468 } |
|
469 } |
|
470 } |
|
471 else if (tmp_expr.is_map ()) |
|
472 { |
|
473 if (ident) |
|
474 { |
|
475 Octave_map tmp_val (tmp_expr.map_value ()); |
|
476 |
|
477 for (Pix p = tmp_val.first (); p != 0; tmp_val.next (p)) |
|
478 { |
|
479 tree_constant rhs (tmp_val.contents (p)); |
|
480 |
|
481 int quit; |
|
482 do_for_loop_once (ident, rhs, quit); |
|
483 |
|
484 if (quit) |
|
485 break; |
|
486 } |
|
487 } |
|
488 else if (id_list) |
|
489 { |
|
490 // Cycle through structure elements. First element of |
|
491 // id_list is set to value and the second is set to the name |
|
492 // of the structure element. |
|
493 |
|
494 Octave_map tmp_val (tmp_expr.map_value ()); |
|
495 |
|
496 for (Pix p = tmp_val.first (); p != 0; tmp_val.next (p)) |
|
497 { |
|
498 Octave_object tmp; |
|
499 tmp (1) = tmp_val.key (p); |
|
500 tmp (0) = tmp_val.contents (p); |
|
501 |
|
502 int quit; |
|
503 do_for_loop_once (id_list, tmp, quit); |
|
504 |
|
505 if (quit) |
|
506 break; |
|
507 } |
|
508 } |
|
509 else |
|
510 { |
|
511 Octave_map tmp_val (tmp_expr.map_value ()); |
|
512 |
|
513 for (Pix p = tmp_val.first (); p != 0; tmp_val.next (p)) |
|
514 { |
|
515 tree_constant rhs = tmp_val.contents (p); |
|
516 |
|
517 int quit; |
|
518 do_for_loop_once (tmp_id, rhs, quit); |
1168
|
519 |
|
520 if (quit) |
|
521 break; |
|
522 } |
620
|
523 } |
|
524 } |
|
525 else |
|
526 { |
|
527 ::error ("invalid type in for loop expression near line %d, column %d", |
|
528 line (), column ()); |
494
|
529 } |
|
530 } |
|
531 |
|
532 void |
|
533 tree_for_command::eval_error (void) |
|
534 { |
|
535 if (error_state > 0) |
|
536 ::error ("evaluating for command near line %d, column %d", |
|
537 line (), column ()); |
|
538 } |
|
539 |
578
|
540 void |
581
|
541 tree_for_command::print_code (ostream& os) |
|
542 { |
|
543 print_code_indent (os); |
|
544 |
|
545 os << "for "; |
|
546 |
|
547 if (id) |
|
548 id->print_code (os); |
|
549 |
|
550 os << " = "; |
|
551 |
|
552 if (expr) |
|
553 expr->print_code (os); |
|
554 |
|
555 print_code_new_line (os); |
|
556 |
|
557 if (list) |
|
558 { |
|
559 increment_indent_level (); |
|
560 list->print_code (os); |
|
561 decrement_indent_level (); |
|
562 } |
|
563 |
|
564 print_code_indent (os); |
|
565 |
|
566 os << "endfor"; |
|
567 } |
|
568 |
578
|
569 // If. |
494
|
570 |
|
571 tree_if_command::~tree_if_command (void) |
|
572 { |
|
573 delete list; |
|
574 } |
|
575 |
|
576 void |
578
|
577 tree_if_command::eval (void) |
494
|
578 { |
578
|
579 if (list) |
|
580 list->eval (); |
|
581 |
494
|
582 if (error_state > 0) |
|
583 ::error ("evaluating if command near line %d, column %d", |
|
584 line (), column ()); |
|
585 } |
|
586 |
581
|
587 void |
|
588 tree_if_command::print_code (ostream& os) |
|
589 { |
|
590 print_code_indent (os); |
|
591 |
|
592 os << "if "; |
|
593 |
|
594 if (list) |
|
595 list->print_code (os); |
|
596 |
|
597 print_code_indent (os); |
|
598 |
|
599 os << "endif"; |
|
600 } |
|
601 |
916
|
602 // Simple exception handling. |
|
603 |
1489
|
604 tree_try_catch_command::~tree_try_catch_command (void) |
|
605 { |
|
606 delete try_code; |
|
607 delete catch_code; |
|
608 } |
|
609 |
|
610 static void |
|
611 do_catch_code (void *ptr) |
|
612 { |
|
613 tree_statement_list *list = (tree_statement_list *) ptr; |
|
614 |
|
615 // Set up for letting the user print any messages from errors that |
|
616 // occurred in the body of the try_catch statement. |
|
617 |
|
618 buffer_error_messages = 0; |
|
619 bind_global_error_variable (); |
|
620 add_unwind_protect (clear_global_error_variable, 0); |
|
621 |
|
622 // Similarly, if we have seen a return or break statement, allow all |
|
623 // the catch code to run before returning or handling the break. |
|
624 // We don't have to worry about continue statements because they can |
|
625 // only occur in loops. |
|
626 |
|
627 unwind_protect_int (returning); |
|
628 returning = 0; |
|
629 |
|
630 unwind_protect_int (breaking); |
|
631 breaking = 0; |
|
632 |
|
633 if (list) |
|
634 list->eval (1); |
|
635 |
|
636 // This is the one for breaking. (The unwind_protects are popped |
|
637 // off the stack in the reverse of the order they are pushed on). |
|
638 |
|
639 // XXX FIXME XXX -- inside a try-catch, should break work like |
|
640 // a return, or just jump to the end of the try_catch block? |
|
641 // The following code makes it just jump to the end of the block. |
|
642 |
|
643 run_unwind_protect (); |
|
644 if (breaking) |
|
645 breaking--; |
|
646 |
|
647 // This is the one for returning. |
|
648 |
|
649 if (returning) |
|
650 discard_unwind_protect (); |
|
651 else |
|
652 run_unwind_protect (); |
|
653 |
|
654 run_unwind_protect (); |
|
655 } |
|
656 |
|
657 void |
|
658 tree_try_catch_command::eval (void) |
|
659 { |
|
660 begin_unwind_frame ("tree_try_catch::eval"); |
|
661 |
|
662 add_unwind_protect (do_catch_code, catch_code); |
|
663 |
|
664 if (catch_code) |
|
665 { |
|
666 unwind_protect_int (buffer_error_messages); |
|
667 buffer_error_messages = 1; |
|
668 } |
|
669 |
|
670 if (try_code) |
|
671 try_code->eval (1); |
|
672 |
|
673 if (catch_code && error_state) |
|
674 { |
|
675 error_state = 0; |
|
676 run_unwind_frame ("tree_try_catch::eval"); |
|
677 } |
|
678 else |
|
679 { |
|
680 error_state = 0; |
|
681 discard_unwind_frame ("tree_try_catch::eval"); |
|
682 } |
|
683 } |
|
684 |
|
685 void |
|
686 tree_try_catch_command::print_code (ostream& os) |
|
687 { |
|
688 print_code_indent (os); |
|
689 |
|
690 os << "try_catch"; |
|
691 |
|
692 print_code_new_line (os); |
|
693 |
|
694 if (try_code) |
|
695 { |
|
696 increment_indent_level (); |
|
697 try_code->print_code (os); |
|
698 decrement_indent_level (); |
|
699 } |
|
700 |
|
701 print_code_indent (os); |
|
702 |
|
703 os << "catch_code"; |
|
704 |
|
705 print_code_new_line (os); |
|
706 |
|
707 if (catch_code) |
|
708 { |
|
709 increment_indent_level (); |
|
710 catch_code->print_code (os); |
|
711 decrement_indent_level (); |
|
712 } |
|
713 |
|
714 print_code_indent (os); |
|
715 |
|
716 os << "end_try_catch"; |
|
717 } |
|
718 |
|
719 // Simple exception handling. |
|
720 |
916
|
721 tree_unwind_protect_command::~tree_unwind_protect_command (void) |
|
722 { |
|
723 delete unwind_protect_code; |
|
724 delete cleanup_code; |
|
725 } |
|
726 |
|
727 static void |
|
728 do_unwind_protect_cleanup_code (void *ptr) |
|
729 { |
|
730 tree_statement_list *list = (tree_statement_list *) ptr; |
|
731 |
1228
|
732 // We want to run the cleanup code without error_state being set, |
|
733 // but we need to restore its value, so that any errors encountered |
|
734 // in the first part of the unwind_protect are not completely |
|
735 // ignored. |
916
|
736 |
|
737 unwind_protect_int (error_state); |
1266
|
738 error_state = 0; |
916
|
739 |
1266
|
740 // Similarly, if we have seen a return or break statement, allow all |
|
741 // the cleanup code to run before returning or handling the break. |
|
742 // We don't have to worry about continue statements because they can |
|
743 // only occur in loops. |
|
744 |
|
745 unwind_protect_int (returning); |
|
746 returning = 0; |
|
747 |
|
748 unwind_protect_int (breaking); |
|
749 breaking = 0; |
916
|
750 |
|
751 if (list) |
|
752 list->eval (1); |
|
753 |
1266
|
754 // This is the one for breaking. (The unwind_protects are popped |
|
755 // off the stack in the reverse of the order they are pushed on). |
|
756 |
|
757 // XXX FIXME XXX -- inside an unwind_protect, should break work like |
|
758 // a return, or just jump to the end of the unwind_protect block? |
|
759 // The following code makes it just jump to the end of the block. |
|
760 |
|
761 run_unwind_protect (); |
|
762 if (breaking) |
|
763 breaking--; |
|
764 |
|
765 // This is the one for returning. |
|
766 |
|
767 if (returning) |
|
768 discard_unwind_protect (); |
|
769 else |
|
770 run_unwind_protect (); |
|
771 |
1228
|
772 // We don't want to ignore errors that occur in the cleanup code, so |
|
773 // if an error is encountered there, leave error_state alone. |
|
774 // Otherwise, set it back to what it was before. |
916
|
775 |
|
776 if (error_state) |
|
777 discard_unwind_protect (); |
|
778 else |
|
779 run_unwind_protect (); |
|
780 } |
|
781 |
|
782 void |
|
783 tree_unwind_protect_command::eval (void) |
|
784 { |
|
785 add_unwind_protect (do_unwind_protect_cleanup_code, cleanup_code); |
|
786 |
|
787 if (unwind_protect_code) |
|
788 unwind_protect_code->eval (1); |
|
789 |
1489
|
790 run_unwind_protect (); |
916
|
791 } |
|
792 |
|
793 void |
|
794 tree_unwind_protect_command::print_code (ostream& os) |
|
795 { |
|
796 print_code_indent (os); |
|
797 |
|
798 os << "unwind_protect"; |
|
799 |
|
800 print_code_new_line (os); |
|
801 |
|
802 if (unwind_protect_code) |
|
803 { |
|
804 increment_indent_level (); |
|
805 unwind_protect_code->print_code (os); |
|
806 decrement_indent_level (); |
|
807 } |
|
808 |
|
809 print_code_indent (os); |
|
810 |
|
811 os << "cleanup_code"; |
|
812 |
|
813 print_code_new_line (os); |
|
814 |
|
815 if (cleanup_code) |
|
816 { |
|
817 increment_indent_level (); |
|
818 cleanup_code->print_code (os); |
|
819 decrement_indent_level (); |
|
820 } |
|
821 |
|
822 print_code_indent (os); |
|
823 |
|
824 os << "end_unwind_protect"; |
|
825 } |
|
826 |
578
|
827 // Break. |
494
|
828 |
578
|
829 void |
|
830 tree_break_command::eval (void) |
494
|
831 { |
|
832 if (! error_state) |
|
833 breaking = 1; |
|
834 } |
|
835 |
581
|
836 void |
|
837 tree_break_command::print_code (ostream& os) |
|
838 { |
|
839 print_code_indent (os); |
|
840 |
|
841 os << "break"; |
|
842 } |
|
843 |
578
|
844 // Continue. |
494
|
845 |
578
|
846 void |
|
847 tree_continue_command::eval (void) |
494
|
848 { |
|
849 if (! error_state) |
|
850 continuing = 1; |
|
851 } |
|
852 |
581
|
853 void |
|
854 tree_continue_command::print_code (ostream& os) |
|
855 { |
|
856 print_code_indent (os); |
|
857 |
|
858 os << "continue"; |
|
859 } |
|
860 |
578
|
861 // Return. |
494
|
862 |
578
|
863 void |
|
864 tree_return_command::eval (void) |
494
|
865 { |
|
866 if (! error_state) |
|
867 returning = 1; |
|
868 } |
|
869 |
581
|
870 void |
|
871 tree_return_command::print_code (ostream& os) |
|
872 { |
|
873 print_code_indent (os); |
|
874 |
|
875 os << "return"; |
|
876 } |
|
877 |
494
|
878 /* |
|
879 ;;; Local Variables: *** |
|
880 ;;; mode: C++ *** |
|
881 ;;; page-delimiter: "^/\\*" *** |
|
882 ;;; End: *** |
|
883 */ |