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