529
|
1 // tree-cmd.h -*- C++ -*- |
494
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton |
494
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
494
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_tree_cmd_h) |
|
25 #define octave_tree_cmd_h 1 |
|
26 |
1297
|
27 #if defined (__GNUG__) |
|
28 #pragma interface |
|
29 #endif |
|
30 |
581
|
31 #include <iostream.h> |
|
32 |
1228
|
33 class Octave_object; |
|
34 |
578
|
35 class tree_statement_list; |
|
36 class tree_global_init_list; |
|
37 class tree_if_command_list; |
494
|
38 class tree_expression; |
|
39 class tree_index_expression; |
1168
|
40 class tree_identifier; |
1228
|
41 class tree_return_list; |
494
|
42 class tree_constant; |
|
43 class symbol_record; |
|
44 |
|
45 class tree_command; |
|
46 class tree_global_command; |
|
47 class tree_while_command; |
|
48 class tree_for_command; |
|
49 class tree_if_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 |
578
|
55 #include "tree-base.h" |
|
56 |
|
57 // A base class for commands. |
|
58 |
494
|
59 class |
|
60 tree_command : public tree |
|
61 { |
578
|
62 public: |
|
63 tree_command (int l = -1, int c = -1) : tree (l, c) { } |
|
64 |
1270
|
65 virtual ~tree_command (void) { } |
|
66 |
578
|
67 virtual void eval (void) = 0; |
494
|
68 }; |
|
69 |
|
70 class |
|
71 tree_global_command : public tree_command |
|
72 { |
916
|
73 public: |
578
|
74 tree_global_command (int l = -1, int c = -1) : tree_command (l, c) |
|
75 { init_list = 0; } |
|
76 |
|
77 tree_global_command (tree_global_init_list *t, int l = -1, int c = -1) |
|
78 : tree_command (l, c) |
|
79 { init_list = t; } |
494
|
80 |
|
81 ~tree_global_command (void); |
|
82 |
578
|
83 void eval (void); |
494
|
84 |
581
|
85 void print_code (ostream& os); |
|
86 |
578
|
87 private: |
|
88 tree_global_init_list *init_list; |
494
|
89 }; |
|
90 |
578
|
91 // While. |
|
92 |
494
|
93 class |
|
94 tree_while_command : public tree_command |
|
95 { |
916
|
96 public: |
578
|
97 tree_while_command (int l = -1, int c = -1) : tree_command (l, c) |
|
98 { |
|
99 expr = 0; |
|
100 list = 0; |
|
101 } |
|
102 |
|
103 tree_while_command (tree_expression *e, int l = -1, int c = -1) |
|
104 : tree_command (l, c) |
|
105 { |
|
106 expr = e; |
|
107 list = 0; |
|
108 } |
|
109 |
|
110 tree_while_command (tree_expression *e, tree_statement_list *lst, |
|
111 int l = -1, int c = -1) |
|
112 : tree_command (l, c) |
|
113 { |
|
114 expr = e; |
|
115 list = lst; |
|
116 } |
494
|
117 |
|
118 ~tree_while_command (void); |
|
119 |
578
|
120 void eval (void); |
494
|
121 |
|
122 void eval_error (void); |
|
123 |
581
|
124 void print_code (ostream& os); |
|
125 |
916
|
126 private: |
494
|
127 tree_expression *expr; // Expression to test. |
578
|
128 tree_statement_list *list; // List of commands to execute. |
494
|
129 }; |
|
130 |
578
|
131 // For. |
|
132 |
494
|
133 class |
|
134 tree_for_command : public tree_command |
|
135 { |
916
|
136 public: |
578
|
137 tree_for_command (int l = -1, int c = -1) : tree_command (l, c) |
|
138 { |
|
139 id = 0; |
1228
|
140 id_list = 0; |
578
|
141 expr = 0; |
|
142 list = 0; |
|
143 } |
|
144 |
|
145 tree_for_command (tree_index_expression *ident, tree_expression *e, |
|
146 tree_statement_list *lst, int l = -1, int c = -1) |
|
147 : tree_command (l, c) |
|
148 { |
|
149 id = ident; |
1228
|
150 id_list = 0; |
|
151 expr = e; |
|
152 list = lst; |
|
153 } |
|
154 |
|
155 tree_for_command (tree_return_list *ident, tree_expression *e, |
|
156 tree_statement_list *lst, int l = -1, int c = -1) |
|
157 : tree_command (l, c) |
|
158 { |
|
159 id = 0; |
|
160 id_list = ident; |
578
|
161 expr = e; |
|
162 list = lst; |
|
163 } |
494
|
164 |
|
165 ~tree_for_command (void); |
|
166 |
578
|
167 void eval (void); |
494
|
168 |
|
169 void eval_error (void); |
|
170 |
581
|
171 void print_code (ostream& os); |
|
172 |
916
|
173 private: |
1228
|
174 void do_for_loop_once (tree_return_list *lst, |
|
175 const Octave_object& rhs, int& quit); |
|
176 |
|
177 void do_for_loop_once (tree_index_expression *idx_expr, |
|
178 const tree_constant& rhs, int& quit); |
|
179 |
1168
|
180 void do_for_loop_once (tree_identifier *ident, |
|
181 tree_constant& rhs, int& quit); |
|
182 |
494
|
183 tree_index_expression *id; // Identifier to modify. |
1228
|
184 tree_return_list *id_list; // List of identifiers to modify. |
494
|
185 tree_expression *expr; // Expression to evaluate. |
578
|
186 tree_statement_list *list; // List of commands to execute. |
494
|
187 }; |
|
188 |
578
|
189 // If. |
|
190 |
494
|
191 class |
|
192 tree_if_command : public tree_command |
|
193 { |
916
|
194 public: |
578
|
195 tree_if_command (int l = -1, int c = -1) : tree_command (l, c) |
|
196 { list = 0; } |
|
197 |
|
198 tree_if_command (tree_if_command_list *lst, int l = -1, int c = -1) |
|
199 : tree_command (l, c) |
|
200 { list = lst; } |
494
|
201 |
|
202 ~tree_if_command (void); |
|
203 |
578
|
204 void eval (void); |
494
|
205 |
|
206 void eval_error (void); |
|
207 |
581
|
208 void print_code (ostream& os); |
|
209 |
916
|
210 private: |
578
|
211 tree_if_command_list *list; |
494
|
212 }; |
|
213 |
916
|
214 // Simple exception handling. |
|
215 |
|
216 class |
|
217 tree_unwind_protect_command : public tree_command |
|
218 { |
|
219 public: |
|
220 tree_unwind_protect_command (int l = -1, int c = -1) : tree_command (l, c) |
|
221 { |
|
222 unwind_protect_code = 0; |
|
223 cleanup_code = 0; |
|
224 } |
|
225 |
|
226 tree_unwind_protect_command (tree_statement_list *tc, |
|
227 tree_statement_list *cc, |
|
228 int l = -1, int c = -1) |
|
229 : tree_command (l, c) |
|
230 { |
|
231 unwind_protect_code = tc; |
|
232 cleanup_code = cc; |
|
233 } |
|
234 |
|
235 ~tree_unwind_protect_command (void); |
|
236 |
|
237 void eval (void); |
|
238 |
|
239 void print_code (ostream& os); |
|
240 |
|
241 private: |
|
242 tree_statement_list *unwind_protect_code; |
|
243 tree_statement_list *cleanup_code; |
|
244 }; |
|
245 |
578
|
246 // Break. |
|
247 |
494
|
248 class |
|
249 tree_break_command : public tree_command |
|
250 { |
916
|
251 public: |
578
|
252 tree_break_command (int l = -1, int c = -1) : tree_command (l, c) { } |
494
|
253 |
578
|
254 ~tree_break_command (void) { } |
494
|
255 |
578
|
256 void eval (void); |
581
|
257 |
|
258 void print_code (ostream& os); |
494
|
259 }; |
|
260 |
578
|
261 // Continue. |
|
262 |
494
|
263 class |
|
264 tree_continue_command : public tree_command |
|
265 { |
916
|
266 public: |
578
|
267 tree_continue_command (int l = -1, int c = -1) : tree_command (l, c) { } |
494
|
268 |
578
|
269 ~tree_continue_command (void) { } |
494
|
270 |
578
|
271 void eval (void); |
581
|
272 |
|
273 void print_code (ostream& os); |
494
|
274 }; |
|
275 |
578
|
276 // Return. |
|
277 |
494
|
278 class |
|
279 tree_return_command : public tree_command |
|
280 { |
578
|
281 public: |
|
282 tree_return_command (int l = -1, int c = -1) : tree_command (l, c) { } |
494
|
283 |
578
|
284 ~tree_return_command (void) { } |
494
|
285 |
578
|
286 void eval (void); |
581
|
287 |
|
288 void print_code (ostream& os); |
494
|
289 }; |
|
290 |
|
291 #endif |
|
292 |
|
293 /* |
|
294 ;;; Local Variables: *** |
|
295 ;;; mode: C++ *** |
|
296 ;;; page-delimiter: "^/\\*" *** |
|
297 ;;; End: *** |
|
298 */ |