annotate src/pt-except.cc @ 4429:c1f6200b5f0e

[project @ 2003-06-17 04:36:08 by jwe]
author jwe
date Tue, 17 Jun 2003 04:36:08 +0000
parents fa3482b34599
children 5e2c68946f30
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
1 /*
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
2
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
3 Copyright (C) 1996, 1997 John W. Eaton
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
4
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
6
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
10 later version.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
11
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
15 for more details.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
16
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, write to the Free
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
20
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
21 */
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
22
4192
5719210fff4c [project @ 2002-11-20 16:56:47 by jwe]
jwe
parents: 4173
diff changeset
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION)
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
24 #pragma implementation
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
25 #endif
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
26
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
27 #ifdef HAVE_CONFIG_H
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
28 #include <config.h>
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
29 #endif
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
30
4429
c1f6200b5f0e [project @ 2003-06-17 04:36:08 by jwe]
jwe
parents: 4207
diff changeset
31 #include "quit.h"
c1f6200b5f0e [project @ 2003-06-17 04:36:08 by jwe]
jwe
parents: 4207
diff changeset
32
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
33 #include "error.h"
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
34 #include "oct-lvalue.h"
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
35 #include "ov.h"
3770
bf6116ca10eb [project @ 2001-02-02 02:21:40 by jwe]
jwe
parents: 3665
diff changeset
36 #include "pt-bp.h"
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
37 #include "pt-cmd.h"
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
38 #include "pt-except.h"
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
39 #include "pt-exp.h"
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
40 #include "pt-jump.h"
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
41 #include "pt-stmt.h"
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
42 #include "pt-walk.h"
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
43 #include "unwind-prot.h"
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
44 #include "variables.h"
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
45
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
46 // Simple exception handling.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
47
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
48 tree_try_catch_command::~tree_try_catch_command (void)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
49 {
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
50 delete try_code;
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
51 delete catch_code;
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3585
diff changeset
52 delete lead_comm;
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3585
diff changeset
53 delete mid_comm;
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3585
diff changeset
54 delete trail_comm;
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
55 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
56
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
57 static void
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
58 do_catch_code (void *ptr)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
59 {
4429
c1f6200b5f0e [project @ 2003-06-17 04:36:08 by jwe]
jwe
parents: 4207
diff changeset
60 if (octave_interrupt_immediately)
c1f6200b5f0e [project @ 2003-06-17 04:36:08 by jwe]
jwe
parents: 4207
diff changeset
61 return;
c1f6200b5f0e [project @ 2003-06-17 04:36:08 by jwe]
jwe
parents: 4207
diff changeset
62
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
63 tree_statement_list *list = static_cast<tree_statement_list *> (ptr);
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
64
3490
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3162
diff changeset
65 unwind_protect::begin_frame ("do_catch_code");
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3162
diff changeset
66
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
67 // Set up for letting the user print any messages from errors that
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
68 // occurred in the body of the try_catch statement.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
69
3490
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3162
diff changeset
70 unwind_protect_bool (buffer_error_messages);
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2985
diff changeset
71 buffer_error_messages = false;
3490
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3162
diff changeset
72
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
73 bind_global_error_variable ();
3490
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3162
diff changeset
74
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
75 unwind_protect::add (clear_global_error_variable, 0);
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
76
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
77 if (list)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
78 list->eval ();
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
79
3490
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3162
diff changeset
80 unwind_protect::run_frame ("do_catch_code");
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
81 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
82
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
83 void
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
84 tree_try_catch_command::eval (void)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
85 {
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
86 unwind_protect::begin_frame ("tree_try_catch::eval");
3770
bf6116ca10eb [project @ 2001-02-02 02:21:40 by jwe]
jwe
parents: 3665
diff changeset
87
bf6116ca10eb [project @ 2001-02-02 02:21:40 by jwe]
jwe
parents: 3665
diff changeset
88 MAYBE_DO_BREAKPOINT;
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
89
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
90 if (catch_code)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
91 {
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2985
diff changeset
92 unwind_protect_bool (buffer_error_messages);
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 2985
diff changeset
93 buffer_error_messages = true;
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
94 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
95
3490
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3162
diff changeset
96 unwind_protect::add (do_catch_code, catch_code);
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3162
diff changeset
97
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
98 if (try_code)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
99 try_code->eval ();
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
100
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
101 if (catch_code && error_state)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
102 {
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
103 error_state = 0;
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
104 unwind_protect::run_frame ("tree_try_catch::eval");
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
105 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
106 else
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
107 {
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
108 error_state = 0;
3490
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3162
diff changeset
109
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3162
diff changeset
110 // For clearing the do_catch_code cleanup function.
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3162
diff changeset
111 unwind_protect::discard ();
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3162
diff changeset
112
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3162
diff changeset
113 // For restoring buffer_error_messages.
3584
aa31644d9779 [project @ 2000-02-07 09:24:38 by jwe]
jwe
parents: 3491
diff changeset
114 if (catch_code)
aa31644d9779 [project @ 2000-02-07 09:24:38 by jwe]
jwe
parents: 3491
diff changeset
115 unwind_protect::run ();
3585
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3584
diff changeset
116
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3584
diff changeset
117 // Also clear the frame marker.
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3584
diff changeset
118 unwind_protect::discard ();
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
119 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
120 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
121
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
122 void
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
123 tree_try_catch_command::accept (tree_walker& tw)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
124 {
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
125 tw.visit_try_catch_command (*this);
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
126 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
127
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
128 // Simple exception handling.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
129
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
130 tree_unwind_protect_command::~tree_unwind_protect_command (void)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
131 {
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
132 delete unwind_protect_code;
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
133 delete cleanup_code;
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3585
diff changeset
134 delete lead_comm;
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3585
diff changeset
135 delete mid_comm;
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3585
diff changeset
136 delete trail_comm;
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
137 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
138
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
139 static void
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
140 do_unwind_protect_cleanup_code (void *ptr)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
141 {
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
142 tree_statement_list *list = static_cast<tree_statement_list *> (ptr);
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
143
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
144 // We want to run the cleanup code without error_state being set,
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
145 // but we need to restore its value, so that any errors encountered
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
146 // in the first part of the unwind_protect are not completely
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
147 // ignored.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
148
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
149 unwind_protect_int (error_state);
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
150 error_state = 0;
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
151
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
152 // Similarly, if we have seen a return or break statement, allow all
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
153 // the cleanup code to run before returning or handling the break.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
154 // We don't have to worry about continue statements because they can
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
155 // only occur in loops.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
156
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4192
diff changeset
157 unwind_protect_int (tree_return_command::returning);
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4192
diff changeset
158 tree_return_command::returning = 0;
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
159
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4192
diff changeset
160 unwind_protect_int (tree_break_command::breaking);
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4192
diff changeset
161 tree_break_command::breaking = 0;
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
162
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
163 if (list)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
164 list->eval ();
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
165
3491
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
166 // The unwind_protects are popped off the stack in the reverse of
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
167 // the order they are pushed on.
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
168
3491
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
169 // XXX FIXME XXX -- these statements say that if we see a break or
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
170 // return statement in the cleanup block, that we want to use the
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
171 // new value of the breaking or returning flag instead of restoring
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
172 // the previous value. Is that the right thing to do? I think so.
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
173 // Consider the case of
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
174 //
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
175 // function foo ()
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
176 // unwind_protect
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
177 // stderr << "1: this should always be executed\n";
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
178 // break;
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
179 // stderr << "1: this should never be executed\n";
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
180 // unwind_protect_cleanup
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
181 // stderr << "2: this should always be executed\n";
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
182 // return;
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
183 // stderr << "2: this should never be executed\n";
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
184 // end_unwind_protect
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
185 // endfunction
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
186 //
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
187 // If we reset the value of the breaking flag, both the returning
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
188 // flag and the breaking flag will be set, and we shouldn't have
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
189 // both. So, use the most recent one. If there is no return or
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
190 // break in the cleanup block, the values should be reset to
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
191 // whatever they were when the cleanup block was entered.
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
192
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4192
diff changeset
193 if (tree_break_command::breaking || tree_return_command::returning)
3491
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
194 {
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
195 unwind_protect::discard ();
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
196 unwind_protect::discard ();
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
197 }
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
198 else
3491
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
199 {
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
200 unwind_protect::run ();
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
201 unwind_protect::run ();
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
202 }
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
203
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
204 // We don't want to ignore errors that occur in the cleanup code, so
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
205 // if an error is encountered there, leave error_state alone.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
206 // Otherwise, set it back to what it was before.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
207
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
208 if (error_state)
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
209 unwind_protect::discard ();
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
210 else
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
211 unwind_protect::run ();
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
212 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
213
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
214 void
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
215 tree_unwind_protect_command::eval (void)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
216 {
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
217 unwind_protect::add (do_unwind_protect_cleanup_code, cleanup_code);
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
218
3770
bf6116ca10eb [project @ 2001-02-02 02:21:40 by jwe]
jwe
parents: 3665
diff changeset
219 MAYBE_DO_BREAKPOINT;
bf6116ca10eb [project @ 2001-02-02 02:21:40 by jwe]
jwe
parents: 3665
diff changeset
220
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
221 if (unwind_protect_code)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
222 unwind_protect_code->eval ();
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
223
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
224 unwind_protect::run ();
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
225 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
226
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
227 void
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
228 tree_unwind_protect_command::accept (tree_walker& tw)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
229 {
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
230 tw.visit_unwind_protect_command (*this);
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
231 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
232
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
233 /*
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
234 ;;; Local Variables: ***
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
235 ;;; mode: C++ ***
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
236 ;;; End: ***
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
237 */