annotate src/pt-except.cc @ 8184:bb3bdcdaa063

oct-type-conv.h (octave_type_conv_body): avoid shadow warning from GCC
author John W. Eaton <jwe@octave.org>
date Mon, 06 Oct 2008 14:12:09 -0400
parents 71f068b22fcc
children 73c4516fae10
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
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005,
7353
516ddd88e45a [project @ 2008-01-07 19:32:40 by jwe]
jwe
parents: 7336
diff changeset
4 2006, 2007, 2008 John W. Eaton
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
5
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
7
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
8 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
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5861
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5861
diff changeset
11 option) any later version.
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
12
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
13 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
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
15 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
16 for more details.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
17
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5861
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5861
diff changeset
20 <http://www.gnu.org/licenses/>.
2982
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 */
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
23
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
25 #include <config.h>
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
26 #endif
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
27
4429
c1f6200b5f0e [project @ 2003-06-17 04:36:08 by jwe]
jwe
parents: 4207
diff changeset
28 #include "quit.h"
c1f6200b5f0e [project @ 2003-06-17 04:36:08 by jwe]
jwe
parents: 4207
diff changeset
29
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
30 #include "error.h"
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
31 #include "oct-lvalue.h"
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
32 #include "ov.h"
3770
bf6116ca10eb [project @ 2001-02-02 02:21:40 by jwe]
jwe
parents: 3665
diff changeset
33 #include "pt-bp.h"
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
34 #include "pt-cmd.h"
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
35 #include "pt-except.h"
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
36 #include "pt-exp.h"
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
37 #include "pt-jump.h"
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
38 #include "pt-stmt.h"
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
39 #include "pt-walk.h"
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
40 #include "unwind-prot.h"
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
41 #include "variables.h"
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
42
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
43 // Simple exception handling.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
44
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
45 tree_try_catch_command::~tree_try_catch_command (void)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
46 {
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
47 delete try_code;
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
48 delete catch_code;
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3585
diff changeset
49 delete lead_comm;
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3585
diff changeset
50 delete mid_comm;
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3585
diff changeset
51 delete trail_comm;
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
52 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
53
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
54 static void
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
55 do_catch_code (void *ptr)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
56 {
4793
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
57 // Is it safe to call OCTAVE_QUIT here? We are already running
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
58 // something on the unwind_protect stack, but the element for this
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
59 // action would have already been popped from the top of the stack,
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
60 // so we should not be attempting to run it again.
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
61
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
62 OCTAVE_QUIT;
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
63
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
64 // If we are interrupting immediately, or if an interrupt is in
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
65 // progress (octave_interrupt_state < 0), then we don't want to run
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
66 // the catch code (it should only run on errors, not interrupts).
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
67
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
68 // If octave_interrupt_state is positive, an interrupt is pending.
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
69 // The only way that could happen would be for the interrupt to
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
70 // come in after the OCTAVE_QUIT above and before the if statement
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
71 // below -- it's possible, but unlikely. In any case, we should
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
72 // probably let the catch code throw the exception because we don't
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
73 // want to skip that and potentially run some other code. For
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
74 // example, an error may have originally brought us here for some
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
75 // cleanup operation and we shouldn't skip that.
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
76
a62215ab8a03 [project @ 2004-02-20 20:59:34 by jwe]
jwe
parents: 4699
diff changeset
77 if (octave_interrupt_immediately || octave_interrupt_state < 0)
4429
c1f6200b5f0e [project @ 2003-06-17 04:36:08 by jwe]
jwe
parents: 4207
diff changeset
78 return;
c1f6200b5f0e [project @ 2003-06-17 04:36:08 by jwe]
jwe
parents: 4207
diff changeset
79
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
80 tree_statement_list *list = static_cast<tree_statement_list *> (ptr);
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 // 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
83 // occurred in the body of the try_catch statement.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
84
4699
5e2c68946f30 [project @ 2004-01-20 23:04:46 by jwe]
jwe
parents: 4429
diff changeset
85 buffer_error_messages--;
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
86
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
87 if (list)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
88 list->eval ();
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
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
91 void
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
92 tree_try_catch_command::eval (void)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
93 {
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
94 unwind_protect::begin_frame ("tree_try_catch::eval");
3770
bf6116ca10eb [project @ 2001-02-02 02:21:40 by jwe]
jwe
parents: 3665
diff changeset
95
bf6116ca10eb [project @ 2001-02-02 02:21:40 by jwe]
jwe
parents: 3665
diff changeset
96 MAYBE_DO_BREAKPOINT;
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
97
5344
b427cca320b8 [project @ 2005-05-09 19:03:02 by jwe]
jwe
parents: 5307
diff changeset
98 unwind_protect_int (buffer_error_messages);
7353
516ddd88e45a [project @ 2008-01-07 19:32:40 by jwe]
jwe
parents: 7336
diff changeset
99 unwind_protect_bool (Vdebug_on_error);
516ddd88e45a [project @ 2008-01-07 19:32:40 by jwe]
jwe
parents: 7336
diff changeset
100 unwind_protect_bool (Vdebug_on_warning);
516ddd88e45a [project @ 2008-01-07 19:32:40 by jwe]
jwe
parents: 7336
diff changeset
101
5344
b427cca320b8 [project @ 2005-05-09 19:03:02 by jwe]
jwe
parents: 5307
diff changeset
102 buffer_error_messages++;
7353
516ddd88e45a [project @ 2008-01-07 19:32:40 by jwe]
jwe
parents: 7336
diff changeset
103 Vdebug_on_error = false;
516ddd88e45a [project @ 2008-01-07 19:32:40 by jwe]
jwe
parents: 7336
diff changeset
104 Vdebug_on_warning = false;
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
105
3490
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3162
diff changeset
106 unwind_protect::add (do_catch_code, catch_code);
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3162
diff changeset
107
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
108 if (try_code)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
109 try_code->eval ();
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
110
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
111 if (catch_code && error_state)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
112 {
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
113 error_state = 0;
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
114 unwind_protect::run_frame ("tree_try_catch::eval");
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
115 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
116 else
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
117 {
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
118 error_state = 0;
3490
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3162
diff changeset
119
4699
5e2c68946f30 [project @ 2004-01-20 23:04:46 by jwe]
jwe
parents: 4429
diff changeset
120 // Unwind stack elements must be cleared or run in the reverse
5e2c68946f30 [project @ 2004-01-20 23:04:46 by jwe]
jwe
parents: 4429
diff changeset
121 // order in which they were added to the stack.
5e2c68946f30 [project @ 2004-01-20 23:04:46 by jwe]
jwe
parents: 4429
diff changeset
122
3490
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3162
diff changeset
123 // For clearing the do_catch_code cleanup function.
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3162
diff changeset
124 unwind_protect::discard ();
fc5eac74640d [project @ 2000-01-28 10:13:25 by jwe]
jwe
parents: 3162
diff changeset
125
7353
516ddd88e45a [project @ 2008-01-07 19:32:40 by jwe]
jwe
parents: 7336
diff changeset
126 // For restoring Vdebug_on_warning, Vdebug_on_error, and
516ddd88e45a [project @ 2008-01-07 19:32:40 by jwe]
jwe
parents: 7336
diff changeset
127 // buffer_error_messages.
516ddd88e45a [project @ 2008-01-07 19:32:40 by jwe]
jwe
parents: 7336
diff changeset
128 unwind_protect::run ();
516ddd88e45a [project @ 2008-01-07 19:32:40 by jwe]
jwe
parents: 7336
diff changeset
129 unwind_protect::run ();
5344
b427cca320b8 [project @ 2005-05-09 19:03:02 by jwe]
jwe
parents: 5307
diff changeset
130 unwind_protect::run ();
3585
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3584
diff changeset
131
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3584
diff changeset
132 // Also clear the frame marker.
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3584
diff changeset
133 unwind_protect::discard ();
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
134 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
135 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
136
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5775
diff changeset
137 tree_command *
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7353
diff changeset
138 tree_try_catch_command::dup (symbol_table::scope_id scope,
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7353
diff changeset
139 symbol_table::context_id context)
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5775
diff changeset
140 {
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7353
diff changeset
141 return new
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7353
diff changeset
142 tree_try_catch_command (try_code ? try_code->dup (scope, context) : 0,
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7353
diff changeset
143 catch_code ? catch_code->dup (scope, context) : 0,
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7353
diff changeset
144 lead_comm ? lead_comm->dup () : 0,
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7353
diff changeset
145 mid_comm ? mid_comm->dup () : 0,
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7353
diff changeset
146 trail_comm ? trail_comm->dup () : 0,
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7353
diff changeset
147 line (), column ());
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5775
diff changeset
148 }
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5775
diff changeset
149
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
150 void
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
151 tree_try_catch_command::accept (tree_walker& tw)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
152 {
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
153 tw.visit_try_catch_command (*this);
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
154 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
155
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
156 // Simple exception handling.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
157
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
158 tree_unwind_protect_command::~tree_unwind_protect_command (void)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
159 {
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
160 delete unwind_protect_code;
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
161 delete cleanup_code;
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3585
diff changeset
162 delete lead_comm;
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3585
diff changeset
163 delete mid_comm;
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3585
diff changeset
164 delete trail_comm;
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
165 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
166
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
167 static void
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
168 do_unwind_protect_cleanup_code (void *ptr)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
169 {
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
170 tree_statement_list *list = static_cast<tree_statement_list *> (ptr);
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
171
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
172 // 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
173 // 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
174 // 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
175 // ignored.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
176
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
177 unwind_protect_int (error_state);
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
178 error_state = 0;
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
179
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
180 // 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
181 // 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
182 // 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
183 // only occur in loops.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
184
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4192
diff changeset
185 unwind_protect_int (tree_return_command::returning);
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4192
diff changeset
186 tree_return_command::returning = 0;
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
187
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4192
diff changeset
188 unwind_protect_int (tree_break_command::breaking);
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4192
diff changeset
189 tree_break_command::breaking = 0;
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
190
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
191 if (list)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
192 list->eval ();
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
193
3491
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
194 // 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
195 // the order they are pushed on.
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
196
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5344
diff changeset
197 // FIXME -- these statements say that if we see a break or
3491
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
198 // 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
199 // 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
200 // 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
201 // Consider the case of
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
202 //
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
203 // function foo ()
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
204 // unwind_protect
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
205 // stderr << "1: this should always be executed\n";
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
206 // break;
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
207 // stderr << "1: this should never be executed\n";
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
208 // unwind_protect_cleanup
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
209 // stderr << "2: this should always be executed\n";
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
210 // return;
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
211 // stderr << "2: this should never be executed\n";
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
212 // end_unwind_protect
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
213 // endfunction
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
214 //
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
215 // 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
216 // 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
217 // 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
218 // 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
219 // whatever they were when the cleanup block was entered.
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
220
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4192
diff changeset
221 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
222 {
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
223 unwind_protect::discard ();
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
224 unwind_protect::discard ();
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
225 }
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
226 else
3491
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
227 {
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
228 unwind_protect::run ();
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
229 unwind_protect::run ();
2c7524ffdbf5 [project @ 2000-01-28 22:44:13 by jwe]
jwe
parents: 3490
diff changeset
230 }
2982
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 // 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
233 // if an error is encountered there, leave error_state alone.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
234 // Otherwise, set it back to what it was before.
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
235
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
236 if (error_state)
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
237 unwind_protect::discard ();
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
238 else
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
239 unwind_protect::run ();
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
240 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
241
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
242 void
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
243 tree_unwind_protect_command::eval (void)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
244 {
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
245 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
246
3770
bf6116ca10eb [project @ 2001-02-02 02:21:40 by jwe]
jwe
parents: 3665
diff changeset
247 MAYBE_DO_BREAKPOINT;
bf6116ca10eb [project @ 2001-02-02 02:21:40 by jwe]
jwe
parents: 3665
diff changeset
248
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
249 if (unwind_protect_code)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
250 unwind_protect_code->eval ();
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
251
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
252 unwind_protect::run ();
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
253 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
254
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5775
diff changeset
255 tree_command *
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7353
diff changeset
256 tree_unwind_protect_command::dup (symbol_table::scope_id scope,
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7353
diff changeset
257 symbol_table::context_id context)
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5775
diff changeset
258 {
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5775
diff changeset
259 return new tree_unwind_protect_command
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7353
diff changeset
260 (unwind_protect_code ? unwind_protect_code->dup (scope, context) : 0,
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7353
diff changeset
261 cleanup_code ? cleanup_code->dup (scope, context) : 0,
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5775
diff changeset
262 lead_comm ? lead_comm->dup () : 0,
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5775
diff changeset
263 mid_comm ? mid_comm->dup () : 0,
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5775
diff changeset
264 trail_comm ? trail_comm->dup () : 0,
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5775
diff changeset
265 line (), column ());
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5775
diff changeset
266 }
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5775
diff changeset
267
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
268 void
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
269 tree_unwind_protect_command::accept (tree_walker& tw)
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
270 {
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
271 tw.visit_unwind_protect_command (*this);
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
272 }
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
273
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
274 /*
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
275 ;;; Local Variables: ***
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
276 ;;; mode: C++ ***
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
277 ;;; End: ***
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents:
diff changeset
278 */