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