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 |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_tree_cmd_h) |
|
25 #define octave_tree_cmd_h 1 |
|
26 |
581
|
27 #include <iostream.h> |
|
28 |
1228
|
29 class Octave_object; |
|
30 |
578
|
31 class tree_statement_list; |
|
32 class tree_global_init_list; |
|
33 class tree_if_command_list; |
494
|
34 class tree_expression; |
|
35 class tree_index_expression; |
1168
|
36 class tree_identifier; |
1228
|
37 class tree_return_list; |
494
|
38 class tree_constant; |
|
39 class symbol_record; |
|
40 |
|
41 class tree_command; |
|
42 class tree_global_command; |
|
43 class tree_while_command; |
|
44 class tree_for_command; |
|
45 class tree_if_command; |
916
|
46 class tree_unwind_protect_command; |
494
|
47 class tree_break_command; |
|
48 class tree_continue_command; |
|
49 class tree_return_command; |
|
50 |
578
|
51 #include "tree-base.h" |
|
52 |
|
53 // A base class for commands. |
|
54 |
494
|
55 class |
|
56 tree_command : public tree |
|
57 { |
578
|
58 public: |
|
59 tree_command (int l = -1, int c = -1) : tree (l, c) { } |
|
60 |
1270
|
61 virtual ~tree_command (void) { } |
|
62 |
578
|
63 virtual void eval (void) = 0; |
494
|
64 }; |
|
65 |
|
66 class |
|
67 tree_global_command : public tree_command |
|
68 { |
916
|
69 public: |
578
|
70 tree_global_command (int l = -1, int c = -1) : tree_command (l, c) |
|
71 { init_list = 0; } |
|
72 |
|
73 tree_global_command (tree_global_init_list *t, int l = -1, int c = -1) |
|
74 : tree_command (l, c) |
|
75 { init_list = t; } |
494
|
76 |
|
77 ~tree_global_command (void); |
|
78 |
578
|
79 void eval (void); |
494
|
80 |
581
|
81 void print_code (ostream& os); |
|
82 |
578
|
83 private: |
|
84 tree_global_init_list *init_list; |
494
|
85 }; |
|
86 |
578
|
87 // While. |
|
88 |
494
|
89 class |
|
90 tree_while_command : public tree_command |
|
91 { |
916
|
92 public: |
578
|
93 tree_while_command (int l = -1, int c = -1) : tree_command (l, c) |
|
94 { |
|
95 expr = 0; |
|
96 list = 0; |
|
97 } |
|
98 |
|
99 tree_while_command (tree_expression *e, int l = -1, int c = -1) |
|
100 : tree_command (l, c) |
|
101 { |
|
102 expr = e; |
|
103 list = 0; |
|
104 } |
|
105 |
|
106 tree_while_command (tree_expression *e, tree_statement_list *lst, |
|
107 int l = -1, int c = -1) |
|
108 : tree_command (l, c) |
|
109 { |
|
110 expr = e; |
|
111 list = lst; |
|
112 } |
494
|
113 |
|
114 ~tree_while_command (void); |
|
115 |
578
|
116 void eval (void); |
494
|
117 |
|
118 void eval_error (void); |
|
119 |
581
|
120 void print_code (ostream& os); |
|
121 |
916
|
122 private: |
494
|
123 tree_expression *expr; // Expression to test. |
578
|
124 tree_statement_list *list; // List of commands to execute. |
494
|
125 }; |
|
126 |
578
|
127 // For. |
|
128 |
494
|
129 class |
|
130 tree_for_command : public tree_command |
|
131 { |
916
|
132 public: |
578
|
133 tree_for_command (int l = -1, int c = -1) : tree_command (l, c) |
|
134 { |
|
135 id = 0; |
1228
|
136 id_list = 0; |
578
|
137 expr = 0; |
|
138 list = 0; |
|
139 } |
|
140 |
|
141 tree_for_command (tree_index_expression *ident, tree_expression *e, |
|
142 tree_statement_list *lst, int l = -1, int c = -1) |
|
143 : tree_command (l, c) |
|
144 { |
|
145 id = ident; |
1228
|
146 id_list = 0; |
|
147 expr = e; |
|
148 list = lst; |
|
149 } |
|
150 |
|
151 tree_for_command (tree_return_list *ident, tree_expression *e, |
|
152 tree_statement_list *lst, int l = -1, int c = -1) |
|
153 : tree_command (l, c) |
|
154 { |
|
155 id = 0; |
|
156 id_list = ident; |
578
|
157 expr = e; |
|
158 list = lst; |
|
159 } |
494
|
160 |
|
161 ~tree_for_command (void); |
|
162 |
578
|
163 void eval (void); |
494
|
164 |
|
165 void eval_error (void); |
|
166 |
581
|
167 void print_code (ostream& os); |
|
168 |
916
|
169 private: |
1228
|
170 void do_for_loop_once (tree_return_list *lst, |
|
171 const Octave_object& rhs, int& quit); |
|
172 |
|
173 void do_for_loop_once (tree_index_expression *idx_expr, |
|
174 const tree_constant& rhs, int& quit); |
|
175 |
1168
|
176 void do_for_loop_once (tree_identifier *ident, |
|
177 tree_constant& rhs, int& quit); |
|
178 |
494
|
179 tree_index_expression *id; // Identifier to modify. |
1228
|
180 tree_return_list *id_list; // List of identifiers to modify. |
494
|
181 tree_expression *expr; // Expression to evaluate. |
578
|
182 tree_statement_list *list; // List of commands to execute. |
494
|
183 }; |
|
184 |
578
|
185 // If. |
|
186 |
494
|
187 class |
|
188 tree_if_command : public tree_command |
|
189 { |
916
|
190 public: |
578
|
191 tree_if_command (int l = -1, int c = -1) : tree_command (l, c) |
|
192 { list = 0; } |
|
193 |
|
194 tree_if_command (tree_if_command_list *lst, int l = -1, int c = -1) |
|
195 : tree_command (l, c) |
|
196 { list = lst; } |
494
|
197 |
|
198 ~tree_if_command (void); |
|
199 |
578
|
200 void eval (void); |
494
|
201 |
|
202 void eval_error (void); |
|
203 |
581
|
204 void print_code (ostream& os); |
|
205 |
916
|
206 private: |
578
|
207 tree_if_command_list *list; |
494
|
208 }; |
|
209 |
916
|
210 // Simple exception handling. |
|
211 |
|
212 class |
|
213 tree_unwind_protect_command : public tree_command |
|
214 { |
|
215 public: |
|
216 tree_unwind_protect_command (int l = -1, int c = -1) : tree_command (l, c) |
|
217 { |
|
218 unwind_protect_code = 0; |
|
219 cleanup_code = 0; |
|
220 } |
|
221 |
|
222 tree_unwind_protect_command (tree_statement_list *tc, |
|
223 tree_statement_list *cc, |
|
224 int l = -1, int c = -1) |
|
225 : tree_command (l, c) |
|
226 { |
|
227 unwind_protect_code = tc; |
|
228 cleanup_code = cc; |
|
229 } |
|
230 |
|
231 ~tree_unwind_protect_command (void); |
|
232 |
|
233 void eval (void); |
|
234 |
|
235 void print_code (ostream& os); |
|
236 |
|
237 private: |
|
238 tree_statement_list *unwind_protect_code; |
|
239 tree_statement_list *cleanup_code; |
|
240 }; |
|
241 |
578
|
242 // Break. |
|
243 |
494
|
244 class |
|
245 tree_break_command : public tree_command |
|
246 { |
916
|
247 public: |
578
|
248 tree_break_command (int l = -1, int c = -1) : tree_command (l, c) { } |
494
|
249 |
578
|
250 ~tree_break_command (void) { } |
494
|
251 |
578
|
252 void eval (void); |
581
|
253 |
|
254 void print_code (ostream& os); |
494
|
255 }; |
|
256 |
578
|
257 // Continue. |
|
258 |
494
|
259 class |
|
260 tree_continue_command : public tree_command |
|
261 { |
916
|
262 public: |
578
|
263 tree_continue_command (int l = -1, int c = -1) : tree_command (l, c) { } |
494
|
264 |
578
|
265 ~tree_continue_command (void) { } |
494
|
266 |
578
|
267 void eval (void); |
581
|
268 |
|
269 void print_code (ostream& os); |
494
|
270 }; |
|
271 |
578
|
272 // Return. |
|
273 |
494
|
274 class |
|
275 tree_return_command : public tree_command |
|
276 { |
578
|
277 public: |
|
278 tree_return_command (int l = -1, int c = -1) : tree_command (l, c) { } |
494
|
279 |
578
|
280 ~tree_return_command (void) { } |
494
|
281 |
578
|
282 void eval (void); |
581
|
283 |
|
284 void print_code (ostream& os); |
494
|
285 }; |
|
286 |
|
287 #endif |
|
288 |
|
289 /* |
|
290 ;;; Local Variables: *** |
|
291 ;;; mode: C++ *** |
|
292 ;;; page-delimiter: "^/\\*" *** |
|
293 ;;; End: *** |
|
294 */ |