494
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 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" |
2373
|
48 #include "ov.h" |
1742
|
49 #include "pt-exp.h" |
|
50 #include "pt-fvc.h" |
|
51 #include "pt-misc.h" |
|
52 #include "pt-mvr.h" |
2124
|
53 #include "pt-walk.h" |
916
|
54 #include "unwind-prot.h" |
1352
|
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 |
2846
|
74 // Base class for declaration commands (global, static). |
|
75 |
|
76 tree_decl_command::~tree_decl_command (void) |
|
77 { |
|
78 delete init_list; |
|
79 } |
|
80 |
|
81 void |
|
82 tree_decl_command::accept (tree_walker& tw) |
|
83 { |
|
84 tw.visit_decl_command (*this); |
|
85 } |
|
86 |
578
|
87 // Global. |
494
|
88 |
2846
|
89 static void |
|
90 do_global_init (tree_decl_elt& elt, bool skip_initializer) |
494
|
91 { |
2846
|
92 tree_identifier *id = elt.ident (); |
|
93 |
|
94 if (id) |
|
95 id->link_to_global (); |
|
96 else |
|
97 { |
|
98 tree_simple_assignment_expression *expr = elt.assign_expr (); |
|
99 |
|
100 if (expr) |
|
101 { |
|
102 if (expr->left_hand_side_is_identifier_only () |
|
103 && (id = expr->left_hand_side_id ())) |
|
104 { |
|
105 id->link_to_global (); |
|
106 |
|
107 if (! (skip_initializer || error_state)) |
|
108 expr->eval (false); |
|
109 } |
|
110 else |
|
111 error ("global: unable to make structure elements global"); |
|
112 } |
|
113 } |
494
|
114 } |
|
115 |
|
116 void |
578
|
117 tree_global_command::eval (void) |
494
|
118 { |
578
|
119 if (init_list) |
2846
|
120 { |
|
121 init_list->eval (do_global_init, initialized); |
|
122 |
|
123 initialized = true; |
|
124 } |
494
|
125 |
|
126 if (error_state > 0) |
|
127 ::error ("evaluating global command near line %d, column %d", |
|
128 line (), column ()); |
|
129 } |
|
130 |
2846
|
131 // Static. |
|
132 |
|
133 static void |
|
134 do_static_init (tree_decl_elt& elt, bool) |
|
135 { |
|
136 tree_identifier *id = elt.ident (); |
|
137 |
|
138 if (id) |
|
139 id->mark_as_static (); |
|
140 else |
|
141 { |
|
142 tree_simple_assignment_expression *expr = elt.assign_expr (); |
|
143 |
|
144 if (expr) |
|
145 { |
|
146 if (expr->left_hand_side_is_identifier_only () |
|
147 && (id = expr->left_hand_side_id ())) |
|
148 { |
|
149 id->mark_as_static (); |
|
150 |
|
151 if (! error_state) |
|
152 expr->eval (false); |
|
153 } |
|
154 else |
|
155 error ("global: unable to make structure elements global"); |
|
156 } |
|
157 } |
|
158 } |
|
159 |
581
|
160 void |
2846
|
161 tree_static_command::eval (void) |
581
|
162 { |
2846
|
163 // Static variables only need to be marked and initialized once. |
|
164 |
|
165 if (init_list && ! initialized) |
|
166 { |
|
167 init_list->eval (do_static_init, initialized); |
|
168 |
|
169 initialized = true; |
|
170 |
|
171 if (error_state > 0) |
|
172 ::error ("evaluating static command near line %d, column %d", |
|
173 line (), column ()); |
|
174 } |
581
|
175 } |
|
176 |
578
|
177 // While. |
494
|
178 |
|
179 tree_while_command::~tree_while_command (void) |
|
180 { |
|
181 delete expr; |
|
182 delete list; |
|
183 } |
|
184 |
578
|
185 void |
|
186 tree_while_command::eval (void) |
494
|
187 { |
|
188 if (error_state) |
578
|
189 return; |
494
|
190 |
1491
|
191 if (! expr) |
|
192 panic_impossible (); |
|
193 |
494
|
194 for (;;) |
|
195 { |
1491
|
196 if (expr->is_logically_true ("while")) |
494
|
197 { |
529
|
198 if (list) |
494
|
199 { |
578
|
200 list->eval (1); |
494
|
201 if (error_state) |
|
202 { |
|
203 eval_error (); |
578
|
204 return; |
494
|
205 } |
|
206 } |
|
207 |
|
208 if (quit_loop_now ()) |
|
209 break; |
|
210 } |
|
211 else |
|
212 break; |
|
213 } |
|
214 } |
|
215 |
|
216 void |
|
217 tree_while_command::eval_error (void) |
|
218 { |
|
219 if (error_state > 0) |
|
220 ::error ("evaluating while command near line %d, column %d", |
|
221 line (), column ()); |
|
222 } |
|
223 |
581
|
224 void |
2124
|
225 tree_while_command::accept (tree_walker& tw) |
581
|
226 { |
2124
|
227 tw.visit_while_command (*this); |
581
|
228 } |
|
229 |
578
|
230 // For. |
494
|
231 |
|
232 tree_for_command::~tree_for_command (void) |
|
233 { |
|
234 delete id; |
1228
|
235 delete id_list; |
494
|
236 delete expr; |
|
237 delete list; |
|
238 } |
|
239 |
1168
|
240 inline void |
1228
|
241 tree_for_command::do_for_loop_once (tree_return_list *lst, |
2086
|
242 const octave_value_list& rhs, bool& quit) |
1228
|
243 { |
1827
|
244 quit = false; |
1228
|
245 |
|
246 tree_oct_obj *tmp = new tree_oct_obj (rhs); |
|
247 tree_multi_assignment_expression tmp_ass (lst, tmp, 1); |
1827
|
248 tmp_ass.eval (false); |
1228
|
249 |
|
250 if (error_state) |
|
251 { |
|
252 eval_error (); |
|
253 return; |
|
254 } |
|
255 |
|
256 if (list) |
|
257 { |
|
258 list->eval (1); |
|
259 if (error_state) |
|
260 { |
|
261 eval_error (); |
1827
|
262 quit = true; |
1228
|
263 return; |
|
264 } |
|
265 } |
|
266 |
|
267 quit = quit_loop_now (); |
|
268 } |
|
269 |
|
270 inline void |
|
271 tree_for_command::do_for_loop_once (tree_index_expression *idx_expr, |
2086
|
272 const octave_value& rhs, bool& quit) |
1168
|
273 { |
1827
|
274 quit = false; |
1168
|
275 |
2086
|
276 octave_value *tmp = new octave_value (rhs); |
1827
|
277 tree_simple_assignment_expression tmp_ass (idx_expr, tmp, true); |
|
278 tmp_ass.eval (false); |
1168
|
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 inline void |
|
301 tree_for_command::do_for_loop_once (tree_identifier *ident, |
2086
|
302 octave_value& rhs, bool& quit) |
1168
|
303 { |
1827
|
304 quit = false; |
1168
|
305 |
2373
|
306 octave_variable_reference tmp (ident); |
1168
|
307 |
|
308 if (error_state) |
|
309 { |
|
310 eval_error (); |
|
311 return; |
|
312 } |
|
313 |
2373
|
314 tmp.assign (rhs); |
|
315 |
1168
|
316 if (list) |
|
317 { |
|
318 list->eval (1); |
|
319 if (error_state) |
|
320 { |
|
321 eval_error (); |
1827
|
322 quit = true; |
1168
|
323 return; |
|
324 } |
|
325 } |
|
326 |
|
327 quit = quit_loop_now (); |
|
328 } |
|
329 |
|
330 #define DO_LOOP(val) \ |
|
331 do \ |
|
332 { \ |
|
333 if (ident) \ |
|
334 for (int i = 0; i < steps; i++) \ |
|
335 { \ |
2086
|
336 octave_value rhs (val); \ |
1827
|
337 bool quit = false; \ |
1168
|
338 do_for_loop_once (ident, rhs, quit); \ |
|
339 if (quit) \ |
|
340 break; \ |
|
341 } \ |
1228
|
342 else if (id_list) \ |
|
343 for (int i = 0; i < steps; i++) \ |
|
344 { \ |
2086
|
345 octave_value_list rhs (val); \ |
1827
|
346 bool quit = false; \ |
1228
|
347 do_for_loop_once (id_list, rhs, quit); \ |
|
348 if (quit) \ |
|
349 break; \ |
|
350 } \ |
1168
|
351 else \ |
|
352 for (int i = 0; i < steps; i++) \ |
|
353 { \ |
2086
|
354 octave_value rhs (val); \ |
1827
|
355 bool quit = false; \ |
1228
|
356 do_for_loop_once (tmp_id, rhs, quit); \ |
1168
|
357 if (quit) \ |
|
358 break; \ |
|
359 } \ |
|
360 } \ |
|
361 while (0) |
|
362 |
578
|
363 void |
|
364 tree_for_command::eval (void) |
494
|
365 { |
529
|
366 if (error_state || ! expr) |
578
|
367 return; |
494
|
368 |
2086
|
369 octave_value tmp_expr = expr->eval (false); |
494
|
370 |
|
371 if (error_state || tmp_expr.is_undefined ()) |
|
372 { |
|
373 eval_error (); |
578
|
374 return; |
494
|
375 } |
|
376 |
1228
|
377 tree_index_expression *tmp_id = id; |
|
378 if (id_list && id_list->length () == 1) |
|
379 tmp_id = id_list->front (); |
|
380 |
1168
|
381 tree_identifier *ident = 0; |
1228
|
382 if (tmp_id && ! tmp_id->arg_list ()) |
1168
|
383 { |
1228
|
384 tree_indirect_ref *idr = tmp_id->ident (); |
1168
|
385 if (idr->is_identifier_only ()) |
|
386 ident = idr->ident (); |
|
387 } |
|
388 |
1234
|
389 if (id_list && ! ident && ! tmp_expr.is_map ()) |
1228
|
390 { |
|
391 error ("in statement `for [X, Y] = VAL', VAL must be a structure"); |
|
392 return; |
|
393 } |
|
394 |
620
|
395 if (tmp_expr.is_scalar_type ()) |
|
396 { |
1827
|
397 bool quit = false; |
1168
|
398 if (ident) |
|
399 do_for_loop_once (ident, tmp_expr, quit); |
1228
|
400 else if (id_list) |
|
401 { |
2086
|
402 octave_value_list rhs (tmp_expr); |
1228
|
403 do_for_loop_once (id_list, rhs, quit); |
|
404 } |
1168
|
405 else |
1228
|
406 do_for_loop_once (tmp_id, tmp_expr, quit); |
620
|
407 } |
|
408 else if (tmp_expr.is_matrix_type ()) |
494
|
409 { |
620
|
410 Matrix m_tmp; |
|
411 ComplexMatrix cm_tmp; |
|
412 int nr; |
|
413 int steps; |
|
414 if (tmp_expr.is_real_matrix ()) |
|
415 { |
|
416 m_tmp = tmp_expr.matrix_value (); |
|
417 nr = m_tmp.rows (); |
|
418 steps = m_tmp.columns (); |
|
419 } |
|
420 else |
|
421 { |
|
422 cm_tmp = tmp_expr.complex_matrix_value (); |
|
423 nr = cm_tmp.rows (); |
|
424 steps = cm_tmp.columns (); |
|
425 } |
494
|
426 |
1168
|
427 if (tmp_expr.is_real_matrix ()) |
620
|
428 { |
|
429 if (nr == 1) |
1168
|
430 DO_LOOP(m_tmp (0, i)); |
620
|
431 else |
1168
|
432 DO_LOOP(m_tmp.extract (0, i, nr-1, i)); |
|
433 } |
|
434 else |
|
435 { |
|
436 if (nr == 1) |
|
437 DO_LOOP(cm_tmp (0, i)); |
|
438 else |
|
439 DO_LOOP(cm_tmp.extract (0, i, nr-1, i)); |
620
|
440 } |
|
441 } |
|
442 else if (tmp_expr.is_string ()) |
|
443 { |
494
|
444 gripe_string_invalid (); |
620
|
445 } |
|
446 else if (tmp_expr.is_range ()) |
|
447 { |
|
448 Range rng = tmp_expr.range_value (); |
494
|
449 |
620
|
450 int steps = rng.nelem (); |
|
451 double b = rng.base (); |
|
452 double increment = rng.inc (); |
494
|
453 |
1168
|
454 if (ident) |
620
|
455 { |
1168
|
456 for (int i = 0; i < steps; i++) |
|
457 { |
|
458 double tmp_val = b + i * increment; |
|
459 |
2086
|
460 octave_value rhs (tmp_val); |
1168
|
461 |
1827
|
462 bool quit = false; |
1168
|
463 do_for_loop_once (ident, rhs, quit); |
494
|
464 |
1168
|
465 if (quit) |
|
466 break; |
|
467 } |
|
468 } |
1228
|
469 else if (id_list) |
|
470 { |
|
471 for (int i = 0; i < steps; i++) |
|
472 { |
|
473 double tmp_val = b + i * increment; |
|
474 |
2086
|
475 octave_value_list rhs (tmp_val); |
1228
|
476 |
1827
|
477 bool quit = false; |
1228
|
478 do_for_loop_once (id_list, rhs, quit); |
|
479 |
|
480 if (quit) |
|
481 break; |
|
482 } |
|
483 } |
1168
|
484 else |
|
485 { |
|
486 for (int i = 0; i < steps; i++) |
|
487 { |
|
488 double tmp_val = b + i * increment; |
494
|
489 |
2086
|
490 octave_value rhs (tmp_val); |
1168
|
491 |
1827
|
492 bool quit = false; |
1228
|
493 do_for_loop_once (tmp_id, rhs, quit); |
|
494 |
|
495 if (quit) |
|
496 break; |
|
497 } |
|
498 } |
|
499 } |
|
500 else if (tmp_expr.is_map ()) |
|
501 { |
|
502 if (ident) |
|
503 { |
|
504 Octave_map tmp_val (tmp_expr.map_value ()); |
|
505 |
|
506 for (Pix p = tmp_val.first (); p != 0; tmp_val.next (p)) |
|
507 { |
2086
|
508 octave_value rhs (tmp_val.contents (p)); |
1228
|
509 |
1827
|
510 bool quit = false; |
1228
|
511 do_for_loop_once (ident, rhs, quit); |
|
512 |
|
513 if (quit) |
|
514 break; |
|
515 } |
|
516 } |
|
517 else if (id_list) |
|
518 { |
|
519 // Cycle through structure elements. First element of |
|
520 // id_list is set to value and the second is set to the name |
|
521 // of the structure element. |
|
522 |
|
523 Octave_map tmp_val (tmp_expr.map_value ()); |
|
524 |
|
525 for (Pix p = tmp_val.first (); p != 0; tmp_val.next (p)) |
|
526 { |
2086
|
527 octave_value_list tmp; |
1228
|
528 tmp (1) = tmp_val.key (p); |
|
529 tmp (0) = tmp_val.contents (p); |
|
530 |
1827
|
531 bool quit = false; |
1228
|
532 do_for_loop_once (id_list, tmp, quit); |
|
533 |
|
534 if (quit) |
|
535 break; |
|
536 } |
|
537 } |
|
538 else |
|
539 { |
|
540 Octave_map tmp_val (tmp_expr.map_value ()); |
|
541 |
|
542 for (Pix p = tmp_val.first (); p != 0; tmp_val.next (p)) |
|
543 { |
2086
|
544 octave_value rhs = tmp_val.contents (p); |
1228
|
545 |
1827
|
546 bool quit = false; |
1228
|
547 do_for_loop_once (tmp_id, rhs, quit); |
1168
|
548 |
|
549 if (quit) |
|
550 break; |
|
551 } |
620
|
552 } |
|
553 } |
|
554 else |
|
555 { |
|
556 ::error ("invalid type in for loop expression near line %d, column %d", |
|
557 line (), column ()); |
494
|
558 } |
|
559 } |
|
560 |
|
561 void |
|
562 tree_for_command::eval_error (void) |
|
563 { |
|
564 if (error_state > 0) |
|
565 ::error ("evaluating for command near line %d, column %d", |
|
566 line (), column ()); |
|
567 } |
|
568 |
578
|
569 void |
2124
|
570 tree_for_command::accept (tree_walker& tw) |
581
|
571 { |
2124
|
572 tw.visit_for_command (*this); |
581
|
573 } |
|
574 |
578
|
575 // If. |
494
|
576 |
|
577 tree_if_command::~tree_if_command (void) |
|
578 { |
|
579 delete list; |
|
580 } |
|
581 |
|
582 void |
578
|
583 tree_if_command::eval (void) |
494
|
584 { |
578
|
585 if (list) |
|
586 list->eval (); |
|
587 |
494
|
588 if (error_state > 0) |
|
589 ::error ("evaluating if command near line %d, column %d", |
|
590 line (), column ()); |
|
591 } |
|
592 |
581
|
593 void |
2124
|
594 tree_if_command::accept (tree_walker& tw) |
581
|
595 { |
2124
|
596 tw.visit_if_command (*this); |
581
|
597 } |
|
598 |
2764
|
599 // Switch. |
|
600 |
|
601 tree_switch_command::~tree_switch_command (void) |
|
602 { |
|
603 delete expr; |
|
604 delete list; |
|
605 } |
|
606 |
|
607 void |
|
608 tree_switch_command::eval (void) |
|
609 { |
|
610 if (expr) |
|
611 { |
|
612 octave_value val = expr->eval (0); |
|
613 |
|
614 if (! error_state) |
|
615 { |
|
616 if (list) |
|
617 list->eval (val); |
|
618 |
|
619 if (error_state) |
|
620 eval_error (); |
|
621 } |
|
622 else |
|
623 eval_error (); |
|
624 } |
|
625 else |
|
626 ::error ("missing value in switch command near line %d, column %d", |
|
627 line (), column ()); |
|
628 } |
|
629 |
|
630 void |
|
631 tree_switch_command::eval_error (void) |
|
632 { |
|
633 ::error ("evaluating switch command near line %d, column %d", |
|
634 line (), column ()); |
|
635 } |
|
636 |
|
637 void |
|
638 tree_switch_command::accept (tree_walker& tw) |
|
639 { |
|
640 tw.visit_switch_command (*this); |
|
641 } |
|
642 |
916
|
643 // Simple exception handling. |
|
644 |
1489
|
645 tree_try_catch_command::~tree_try_catch_command (void) |
|
646 { |
|
647 delete try_code; |
|
648 delete catch_code; |
|
649 } |
|
650 |
|
651 static void |
|
652 do_catch_code (void *ptr) |
|
653 { |
2800
|
654 tree_statement_list *list = static_cast<tree_statement_list *> (ptr); |
1489
|
655 |
|
656 // Set up for letting the user print any messages from errors that |
|
657 // occurred in the body of the try_catch statement. |
|
658 |
|
659 buffer_error_messages = 0; |
|
660 bind_global_error_variable (); |
|
661 add_unwind_protect (clear_global_error_variable, 0); |
|
662 |
|
663 // Similarly, if we have seen a return or break statement, allow all |
|
664 // the catch code to run before returning or handling the break. |
|
665 // We don't have to worry about continue statements because they can |
|
666 // only occur in loops. |
|
667 |
|
668 unwind_protect_int (returning); |
|
669 returning = 0; |
|
670 |
|
671 unwind_protect_int (breaking); |
|
672 breaking = 0; |
|
673 |
|
674 if (list) |
1827
|
675 list->eval (true); |
1489
|
676 |
|
677 // This is the one for breaking. (The unwind_protects are popped |
|
678 // off the stack in the reverse of the order they are pushed on). |
|
679 |
|
680 // XXX FIXME XXX -- inside a try-catch, should break work like |
|
681 // a return, or just jump to the end of the try_catch block? |
|
682 // The following code makes it just jump to the end of the block. |
|
683 |
|
684 run_unwind_protect (); |
|
685 if (breaking) |
|
686 breaking--; |
|
687 |
|
688 // This is the one for returning. |
|
689 |
|
690 if (returning) |
|
691 discard_unwind_protect (); |
|
692 else |
|
693 run_unwind_protect (); |
|
694 |
|
695 run_unwind_protect (); |
|
696 } |
|
697 |
|
698 void |
|
699 tree_try_catch_command::eval (void) |
|
700 { |
|
701 begin_unwind_frame ("tree_try_catch::eval"); |
|
702 |
|
703 add_unwind_protect (do_catch_code, catch_code); |
|
704 |
|
705 if (catch_code) |
|
706 { |
|
707 unwind_protect_int (buffer_error_messages); |
|
708 buffer_error_messages = 1; |
|
709 } |
|
710 |
|
711 if (try_code) |
1827
|
712 try_code->eval (true); |
1489
|
713 |
|
714 if (catch_code && error_state) |
|
715 { |
|
716 error_state = 0; |
|
717 run_unwind_frame ("tree_try_catch::eval"); |
|
718 } |
|
719 else |
|
720 { |
|
721 error_state = 0; |
|
722 discard_unwind_frame ("tree_try_catch::eval"); |
|
723 } |
|
724 } |
|
725 |
|
726 void |
2124
|
727 tree_try_catch_command::accept (tree_walker& tw) |
1489
|
728 { |
2124
|
729 tw.visit_try_catch_command (*this); |
1489
|
730 } |
|
731 |
|
732 // Simple exception handling. |
|
733 |
916
|
734 tree_unwind_protect_command::~tree_unwind_protect_command (void) |
|
735 { |
|
736 delete unwind_protect_code; |
|
737 delete cleanup_code; |
|
738 } |
|
739 |
|
740 static void |
|
741 do_unwind_protect_cleanup_code (void *ptr) |
|
742 { |
2800
|
743 tree_statement_list *list = static_cast<tree_statement_list *> (ptr); |
916
|
744 |
1228
|
745 // We want to run the cleanup code without error_state being set, |
|
746 // but we need to restore its value, so that any errors encountered |
|
747 // in the first part of the unwind_protect are not completely |
|
748 // ignored. |
916
|
749 |
|
750 unwind_protect_int (error_state); |
1266
|
751 error_state = 0; |
916
|
752 |
1266
|
753 // Similarly, if we have seen a return or break statement, allow all |
|
754 // the cleanup code to run before returning or handling the break. |
|
755 // We don't have to worry about continue statements because they can |
|
756 // only occur in loops. |
|
757 |
|
758 unwind_protect_int (returning); |
|
759 returning = 0; |
|
760 |
|
761 unwind_protect_int (breaking); |
|
762 breaking = 0; |
916
|
763 |
|
764 if (list) |
1827
|
765 list->eval (true); |
916
|
766 |
1266
|
767 // This is the one for breaking. (The unwind_protects are popped |
|
768 // off the stack in the reverse of the order they are pushed on). |
|
769 |
|
770 // XXX FIXME XXX -- inside an unwind_protect, should break work like |
|
771 // a return, or just jump to the end of the unwind_protect block? |
|
772 // The following code makes it just jump to the end of the block. |
|
773 |
|
774 run_unwind_protect (); |
|
775 if (breaking) |
|
776 breaking--; |
|
777 |
|
778 // This is the one for returning. |
|
779 |
|
780 if (returning) |
|
781 discard_unwind_protect (); |
|
782 else |
|
783 run_unwind_protect (); |
|
784 |
1228
|
785 // We don't want to ignore errors that occur in the cleanup code, so |
|
786 // if an error is encountered there, leave error_state alone. |
|
787 // Otherwise, set it back to what it was before. |
916
|
788 |
|
789 if (error_state) |
|
790 discard_unwind_protect (); |
|
791 else |
|
792 run_unwind_protect (); |
|
793 } |
|
794 |
|
795 void |
|
796 tree_unwind_protect_command::eval (void) |
|
797 { |
|
798 add_unwind_protect (do_unwind_protect_cleanup_code, cleanup_code); |
|
799 |
|
800 if (unwind_protect_code) |
1827
|
801 unwind_protect_code->eval (true); |
916
|
802 |
1489
|
803 run_unwind_protect (); |
916
|
804 } |
|
805 |
|
806 void |
2124
|
807 tree_unwind_protect_command::accept (tree_walker& tw) |
916
|
808 { |
2124
|
809 tw.visit_unwind_protect_command (*this); |
916
|
810 } |
|
811 |
2620
|
812 // No-op. |
|
813 |
|
814 void |
|
815 tree_no_op_command::accept (tree_walker& tw) |
|
816 { |
|
817 tw.visit_no_op_command (*this); |
|
818 } |
|
819 |
578
|
820 // Break. |
494
|
821 |
578
|
822 void |
|
823 tree_break_command::eval (void) |
494
|
824 { |
|
825 if (! error_state) |
|
826 breaking = 1; |
|
827 } |
|
828 |
581
|
829 void |
2124
|
830 tree_break_command::accept (tree_walker& tw) |
581
|
831 { |
2124
|
832 tw.visit_break_command (*this); |
581
|
833 } |
|
834 |
578
|
835 // Continue. |
494
|
836 |
578
|
837 void |
|
838 tree_continue_command::eval (void) |
494
|
839 { |
|
840 if (! error_state) |
|
841 continuing = 1; |
|
842 } |
|
843 |
581
|
844 void |
2124
|
845 tree_continue_command::accept (tree_walker& tw) |
581
|
846 { |
2124
|
847 tw.visit_continue_command (*this); |
581
|
848 } |
|
849 |
578
|
850 // Return. |
494
|
851 |
578
|
852 void |
|
853 tree_return_command::eval (void) |
494
|
854 { |
|
855 if (! error_state) |
|
856 returning = 1; |
|
857 } |
|
858 |
581
|
859 void |
2124
|
860 tree_return_command::accept (tree_walker& tw) |
581
|
861 { |
2124
|
862 tw.visit_return_command (*this); |
581
|
863 } |
|
864 |
494
|
865 /* |
|
866 ;;; Local Variables: *** |
|
867 ;;; mode: C++ *** |
|
868 ;;; End: *** |
|
869 */ |