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 |
|
23 #if !defined (octave_tree_cmd_h) |
|
24 #define octave_tree_cmd_h 1 |
|
25 |
1297
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
1740
|
30 class ostream; |
581
|
31 |
2086
|
32 class octave_value_list; |
1228
|
33 |
578
|
34 class tree_statement_list; |
|
35 class tree_global_init_list; |
|
36 class tree_if_command_list; |
494
|
37 class tree_expression; |
|
38 class tree_index_expression; |
1168
|
39 class tree_identifier; |
1228
|
40 class tree_return_list; |
2086
|
41 class octave_value; |
494
|
42 class symbol_record; |
|
43 |
|
44 class tree_command; |
|
45 class tree_global_command; |
|
46 class tree_while_command; |
|
47 class tree_for_command; |
|
48 class tree_if_command; |
1489
|
49 class tree_try_catch_command; |
916
|
50 class tree_unwind_protect_command; |
494
|
51 class tree_break_command; |
|
52 class tree_continue_command; |
|
53 class tree_return_command; |
|
54 |
2124
|
55 class tree_walker; |
|
56 |
1740
|
57 #include "pt-base.h" |
578
|
58 |
|
59 // A base class for commands. |
|
60 |
494
|
61 class |
|
62 tree_command : public tree |
|
63 { |
578
|
64 public: |
2124
|
65 |
578
|
66 tree_command (int l = -1, int c = -1) : tree (l, c) { } |
|
67 |
1270
|
68 virtual ~tree_command (void) { } |
|
69 |
578
|
70 virtual void eval (void) = 0; |
494
|
71 }; |
|
72 |
|
73 class |
|
74 tree_global_command : public tree_command |
|
75 { |
916
|
76 public: |
2124
|
77 |
1740
|
78 tree_global_command (int l = -1, int c = -1) |
|
79 : tree_command (l, c), init_list (0) { } |
578
|
80 |
|
81 tree_global_command (tree_global_init_list *t, int l = -1, int c = -1) |
1740
|
82 : tree_command (l, c), init_list (t) { } |
494
|
83 |
|
84 ~tree_global_command (void); |
|
85 |
578
|
86 void eval (void); |
494
|
87 |
2124
|
88 tree_global_init_list *initializer_list (void) { return init_list; } |
|
89 |
|
90 void accept (tree_walker& tw); |
581
|
91 |
578
|
92 private: |
2124
|
93 |
|
94 // The list of global variables or initializers in this global |
|
95 // command. |
578
|
96 tree_global_init_list *init_list; |
494
|
97 }; |
|
98 |
578
|
99 // While. |
|
100 |
494
|
101 class |
|
102 tree_while_command : public tree_command |
|
103 { |
916
|
104 public: |
2124
|
105 |
1740
|
106 tree_while_command (int l = -1, int c = -1) |
|
107 : tree_command (l, c), expr (0), list (0) { } |
578
|
108 |
|
109 tree_while_command (tree_expression *e, int l = -1, int c = -1) |
1740
|
110 : tree_command (l, c), expr (e), list (0) { } |
578
|
111 |
|
112 tree_while_command (tree_expression *e, tree_statement_list *lst, |
|
113 int l = -1, int c = -1) |
1740
|
114 : tree_command (l, c), expr (e), list (lst) { } |
494
|
115 |
|
116 ~tree_while_command (void); |
|
117 |
578
|
118 void eval (void); |
494
|
119 |
|
120 void eval_error (void); |
|
121 |
2124
|
122 tree_expression *condition (void) { return expr; } |
|
123 |
|
124 tree_statement_list *body (void) { return list; } |
|
125 |
|
126 void accept (tree_walker& tw); |
581
|
127 |
916
|
128 private: |
2124
|
129 |
|
130 // Expression to test. |
|
131 tree_expression *expr; |
|
132 |
|
133 // List of commands to execute. |
|
134 tree_statement_list *list; |
494
|
135 }; |
|
136 |
578
|
137 // For. |
|
138 |
494
|
139 class |
|
140 tree_for_command : public tree_command |
|
141 { |
916
|
142 public: |
2124
|
143 |
1740
|
144 tree_for_command (int l = -1, int c = -1) |
|
145 : tree_command (l, c), id (0), id_list (0), expr (0), list (0) { } |
578
|
146 |
|
147 tree_for_command (tree_index_expression *ident, tree_expression *e, |
|
148 tree_statement_list *lst, int l = -1, int c = -1) |
1740
|
149 : tree_command (l, c), id (ident), id_list (0), expr (e), |
|
150 list (lst) { } |
1228
|
151 |
|
152 tree_for_command (tree_return_list *ident, tree_expression *e, |
|
153 tree_statement_list *lst, int l = -1, int c = -1) |
1740
|
154 : tree_command (l, c), id (0), id_list (ident), expr (e), |
|
155 list (lst) { } |
494
|
156 |
|
157 ~tree_for_command (void); |
|
158 |
578
|
159 void eval (void); |
494
|
160 |
|
161 void eval_error (void); |
|
162 |
2124
|
163 tree_index_expression *ident (void) { return id; } |
|
164 |
|
165 tree_expression *control_expr (void) { return expr; } |
|
166 |
|
167 tree_statement_list *body (void) { return list; } |
|
168 |
|
169 void accept (tree_walker& tw); |
581
|
170 |
916
|
171 private: |
2124
|
172 |
|
173 // Identifier to modify. |
|
174 tree_index_expression *id; |
|
175 |
|
176 // List of identifiers to modify. |
|
177 tree_return_list *id_list; |
|
178 |
|
179 // Expression to evaluate. |
|
180 tree_expression *expr; |
|
181 |
|
182 // List of commands to execute. |
|
183 tree_statement_list *list; |
|
184 |
1228
|
185 void do_for_loop_once (tree_return_list *lst, |
2086
|
186 const octave_value_list& rhs, bool& quit); |
1228
|
187 |
|
188 void do_for_loop_once (tree_index_expression *idx_expr, |
2086
|
189 const octave_value& rhs, bool& quit); |
1228
|
190 |
1168
|
191 void do_for_loop_once (tree_identifier *ident, |
2086
|
192 octave_value& rhs, bool& quit); |
494
|
193 }; |
|
194 |
578
|
195 // If. |
|
196 |
494
|
197 class |
|
198 tree_if_command : public tree_command |
|
199 { |
916
|
200 public: |
2124
|
201 |
1740
|
202 tree_if_command (int l = -1, int c = -1) |
|
203 : tree_command (l, c), list (0) { } |
578
|
204 |
|
205 tree_if_command (tree_if_command_list *lst, int l = -1, int c = -1) |
1740
|
206 : tree_command (l, c), list (lst) { } |
494
|
207 |
|
208 ~tree_if_command (void); |
|
209 |
578
|
210 void eval (void); |
494
|
211 |
|
212 void eval_error (void); |
|
213 |
2124
|
214 tree_if_command_list *cmd_list (void) { return list; } |
|
215 |
|
216 void accept (tree_walker& tw); |
581
|
217 |
916
|
218 private: |
2124
|
219 |
|
220 // List of if commands (if, elseif, elseif, ... else, endif) |
578
|
221 tree_if_command_list *list; |
494
|
222 }; |
|
223 |
916
|
224 // Simple exception handling. |
|
225 |
|
226 class |
|
227 tree_unwind_protect_command : public tree_command |
|
228 { |
|
229 public: |
2124
|
230 |
1740
|
231 tree_unwind_protect_command (int l = -1, int c = -1) |
|
232 : tree_command (l, c), unwind_protect_code (0), cleanup_code (0) { } |
916
|
233 |
|
234 tree_unwind_protect_command (tree_statement_list *tc, |
|
235 tree_statement_list *cc, |
|
236 int l = -1, int c = -1) |
1740
|
237 : tree_command (l, c), unwind_protect_code (tc), cleanup_code (cc) { } |
916
|
238 |
|
239 ~tree_unwind_protect_command (void); |
|
240 |
|
241 void eval (void); |
|
242 |
2124
|
243 tree_statement_list *body (void) { return unwind_protect_code; } |
|
244 |
|
245 tree_statement_list *cleanup (void) { return cleanup_code; } |
|
246 |
|
247 void accept (tree_walker& tw); |
916
|
248 |
|
249 private: |
2124
|
250 |
|
251 // The first body of code to attempt to execute. |
916
|
252 tree_statement_list *unwind_protect_code; |
2124
|
253 |
|
254 // The body of code to execute no matter what happens in the first |
|
255 // body of code. |
916
|
256 tree_statement_list *cleanup_code; |
|
257 }; |
|
258 |
1489
|
259 // Simple exception handling. |
|
260 |
|
261 class |
|
262 tree_try_catch_command : public tree_command |
|
263 { |
|
264 public: |
2124
|
265 |
1740
|
266 tree_try_catch_command (int l = -1, int c = -1) |
|
267 : tree_command (l, c), try_code (0), catch_code (0) { } |
1489
|
268 |
|
269 tree_try_catch_command (tree_statement_list *tc, |
|
270 tree_statement_list *cc, |
|
271 int l = -1, int c = -1) |
1740
|
272 : tree_command (l, c), try_code (tc), catch_code (cc) { } |
1489
|
273 |
|
274 ~tree_try_catch_command (void); |
|
275 |
|
276 void eval (void); |
|
277 |
2124
|
278 tree_statement_list *body (void) { return try_code; } |
|
279 |
|
280 tree_statement_list *cleanup (void) { return catch_code; } |
|
281 |
|
282 void accept (tree_walker& tw); |
1489
|
283 |
|
284 private: |
2124
|
285 |
|
286 // The first block of code to attempt to execute. |
1489
|
287 tree_statement_list *try_code; |
2124
|
288 |
|
289 // The code to execute if an error occurs in the first block. |
1489
|
290 tree_statement_list *catch_code; |
|
291 }; |
|
292 |
578
|
293 // Break. |
|
294 |
494
|
295 class |
|
296 tree_break_command : public tree_command |
|
297 { |
916
|
298 public: |
2124
|
299 |
578
|
300 tree_break_command (int l = -1, int c = -1) : tree_command (l, c) { } |
494
|
301 |
578
|
302 ~tree_break_command (void) { } |
494
|
303 |
578
|
304 void eval (void); |
581
|
305 |
2124
|
306 void accept (tree_walker& tw); |
494
|
307 }; |
|
308 |
578
|
309 // Continue. |
|
310 |
494
|
311 class |
|
312 tree_continue_command : public tree_command |
|
313 { |
916
|
314 public: |
2124
|
315 |
578
|
316 tree_continue_command (int l = -1, int c = -1) : tree_command (l, c) { } |
494
|
317 |
578
|
318 ~tree_continue_command (void) { } |
494
|
319 |
578
|
320 void eval (void); |
581
|
321 |
2124
|
322 void accept (tree_walker& tw); |
494
|
323 }; |
|
324 |
578
|
325 // Return. |
|
326 |
494
|
327 class |
|
328 tree_return_command : public tree_command |
|
329 { |
578
|
330 public: |
2124
|
331 |
578
|
332 tree_return_command (int l = -1, int c = -1) : tree_command (l, c) { } |
494
|
333 |
578
|
334 ~tree_return_command (void) { } |
494
|
335 |
578
|
336 void eval (void); |
581
|
337 |
2124
|
338 void accept (tree_walker& tw); |
494
|
339 }; |
|
340 |
|
341 #endif |
|
342 |
|
343 /* |
|
344 ;;; Local Variables: *** |
|
345 ;;; mode: C++ *** |
|
346 ;;; End: *** |
|
347 */ |