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