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