2982
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 2000, 2002, 2004, 2005, 2006, 2007 |
|
4 John W. Eaton |
2982
|
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 |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
2982
|
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 |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
2982
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_tree_loop_h) |
|
25 #define octave_tree_loop_h 1 |
|
26 |
|
27 class octave_value; |
|
28 class octave_lvalue; |
|
29 |
|
30 class tree_argument_list; |
|
31 class tree_expression; |
|
32 class tree_statement_list; |
|
33 |
|
34 class tree_walker; |
|
35 |
3665
|
36 #include "comment-list.h" |
2982
|
37 #include "pt-cmd.h" |
7336
|
38 #include "symtab.h" |
2982
|
39 |
3877
|
40 // TRUE means we are evaluating some kind of looping construct. |
|
41 extern bool evaluating_looping_command; |
|
42 |
2982
|
43 // While. |
|
44 |
|
45 class |
|
46 tree_while_command : public tree_command |
|
47 { |
|
48 public: |
|
49 |
|
50 tree_while_command (int l = -1, int c = -1) |
3665
|
51 : tree_command (l, c), expr (0), list (0), lead_comm (0), |
|
52 trail_comm (0) { } |
2982
|
53 |
3665
|
54 tree_while_command (tree_expression *e, |
|
55 octave_comment_list *lc = 0, |
|
56 octave_comment_list *tc = 0, |
|
57 int l = -1, int c = -1) |
|
58 : tree_command (l, c), expr (e), list (0), lead_comm (lc), |
|
59 trail_comm (tc) { } |
2982
|
60 |
|
61 tree_while_command (tree_expression *e, tree_statement_list *lst, |
3665
|
62 octave_comment_list *lc = 0, |
|
63 octave_comment_list *tc = 0, |
2982
|
64 int l = -1, int c = -1) |
3665
|
65 : tree_command (l, c), expr (e), list (lst), lead_comm (lc), |
|
66 trail_comm (tc) { } |
2982
|
67 |
|
68 ~tree_while_command (void); |
|
69 |
|
70 void eval (void); |
|
71 |
|
72 void eval_error (void); |
|
73 |
|
74 tree_expression *condition (void) { return expr; } |
|
75 |
|
76 tree_statement_list *body (void) { return list; } |
|
77 |
3665
|
78 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
79 |
|
80 octave_comment_list *trailing_comment (void) { return trail_comm; } |
|
81 |
7336
|
82 tree_command *dup (symbol_table::scope_id scope); |
5861
|
83 |
2982
|
84 void accept (tree_walker& tw); |
|
85 |
3484
|
86 protected: |
2982
|
87 |
|
88 // Expression to test. |
|
89 tree_expression *expr; |
|
90 |
|
91 // List of commands to execute. |
|
92 tree_statement_list *list; |
2988
|
93 |
3665
|
94 // Comment preceding WHILE token. |
|
95 octave_comment_list *lead_comm; |
|
96 |
|
97 // Comment preceding ENDWHILE token. |
|
98 octave_comment_list *trail_comm; |
|
99 |
3484
|
100 private: |
|
101 |
2988
|
102 // No copying! |
|
103 |
|
104 tree_while_command (const tree_while_command&); |
|
105 |
|
106 tree_while_command& operator = (const tree_while_command&); |
2982
|
107 }; |
|
108 |
3484
|
109 // Do-Until. |
|
110 |
|
111 class |
|
112 tree_do_until_command : public tree_while_command |
|
113 { |
|
114 public: |
|
115 |
|
116 tree_do_until_command (int l = -1, int c = -1) |
|
117 : tree_while_command (l, c) { } |
|
118 |
3665
|
119 tree_do_until_command (tree_expression *e, |
|
120 octave_comment_list *lc = 0, |
|
121 octave_comment_list *tc = 0, |
|
122 int l = -1, int c = -1) |
|
123 : tree_while_command (e, lc, tc, l, c) { } |
3484
|
124 |
|
125 tree_do_until_command (tree_expression *e, tree_statement_list *lst, |
3665
|
126 octave_comment_list *lc = 0, |
|
127 octave_comment_list *tc = 0, |
|
128 int l = -1, int c = -1) |
|
129 : tree_while_command (e, lst, lc, tc, l, c) { } |
3484
|
130 |
|
131 ~tree_do_until_command (void) { } |
|
132 |
|
133 void eval (void); |
|
134 |
|
135 void eval_error (void); |
|
136 |
7336
|
137 tree_command *dup (symbol_table::scope_id scope); |
5861
|
138 |
3484
|
139 void accept (tree_walker& tw); |
|
140 |
|
141 private: |
|
142 |
|
143 // No copying! |
|
144 |
|
145 tree_do_until_command (const tree_do_until_command&); |
|
146 |
|
147 tree_do_until_command& operator = (const tree_do_until_command&); |
|
148 }; |
|
149 |
2982
|
150 // For. |
|
151 |
|
152 class |
|
153 tree_simple_for_command : public tree_command |
|
154 { |
|
155 public: |
|
156 |
|
157 tree_simple_for_command (int l = -1, int c = -1) |
3665
|
158 : tree_command (l, c), lhs (0), expr (0), list (0), lead_comm (0), |
|
159 trail_comm (0) { } |
2982
|
160 |
|
161 tree_simple_for_command (tree_expression *le, tree_expression *re, |
3665
|
162 tree_statement_list *lst, |
|
163 octave_comment_list *lc = 0, |
|
164 octave_comment_list *tc = 0, |
|
165 int l = -1, int c = -1) |
|
166 : tree_command (l, c), lhs (le), expr (re), list (lst), |
|
167 lead_comm (lc), trail_comm (tc) { } |
2982
|
168 |
|
169 ~tree_simple_for_command (void); |
|
170 |
|
171 void eval (void); |
|
172 |
|
173 void eval_error (void); |
|
174 |
|
175 tree_expression *left_hand_side (void) { return lhs; } |
|
176 |
|
177 tree_expression *control_expr (void) { return expr; } |
|
178 |
|
179 tree_statement_list *body (void) { return list; } |
|
180 |
3665
|
181 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
182 |
|
183 octave_comment_list *trailing_comment (void) { return trail_comm; } |
|
184 |
7336
|
185 tree_command *dup (symbol_table::scope_id scope); |
5861
|
186 |
2982
|
187 void accept (tree_walker& tw); |
|
188 |
|
189 private: |
|
190 |
|
191 // Expression to modify. |
|
192 tree_expression *lhs; |
|
193 |
|
194 // Expression to evaluate. |
|
195 tree_expression *expr; |
|
196 |
|
197 // List of commands to execute. |
|
198 tree_statement_list *list; |
|
199 |
3665
|
200 // Comment preceding FOR token. |
|
201 octave_comment_list *lead_comm; |
|
202 |
|
203 // Comment preceding ENDFOR token. |
|
204 octave_comment_list *trail_comm; |
|
205 |
2982
|
206 void do_for_loop_once (octave_lvalue &ult, const octave_value& rhs, |
|
207 bool& quit); |
2988
|
208 |
|
209 // No copying! |
|
210 |
|
211 tree_simple_for_command (const tree_simple_for_command&); |
|
212 |
|
213 tree_simple_for_command& operator = (const tree_simple_for_command&); |
2982
|
214 }; |
|
215 |
|
216 class |
|
217 tree_complex_for_command : public tree_command |
|
218 { |
|
219 public: |
|
220 |
|
221 tree_complex_for_command (int l = -1, int c = -1) |
3665
|
222 : tree_command (l, c), lhs (0), expr (0), list (0), lead_comm (0), |
|
223 trail_comm (0) { } |
2982
|
224 |
|
225 tree_complex_for_command (tree_argument_list *le, tree_expression *re, |
3665
|
226 tree_statement_list *lst, |
|
227 octave_comment_list *lc = 0, |
|
228 octave_comment_list *tc = 0, |
|
229 int l = -1, int c = -1) |
|
230 : tree_command (l, c), lhs (le), expr (re), list (lst), |
|
231 lead_comm (lc), trail_comm (tc) { } |
2982
|
232 |
|
233 ~tree_complex_for_command (void); |
|
234 |
|
235 void eval (void); |
|
236 |
|
237 void eval_error (void); |
|
238 |
|
239 tree_argument_list *left_hand_side (void) { return lhs; } |
|
240 |
|
241 tree_expression *control_expr (void) { return expr; } |
|
242 |
|
243 tree_statement_list *body (void) { return list; } |
|
244 |
3665
|
245 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
246 |
|
247 octave_comment_list *trailing_comment (void) { return trail_comm; } |
|
248 |
7336
|
249 tree_command *dup (symbol_table::scope_id scope); |
5861
|
250 |
2982
|
251 void accept (tree_walker& tw); |
|
252 |
|
253 private: |
|
254 |
|
255 // Expression to modify. |
|
256 tree_argument_list *lhs; |
|
257 |
|
258 // Expression to evaluate. |
|
259 tree_expression *expr; |
|
260 |
|
261 // List of commands to execute. |
|
262 tree_statement_list *list; |
|
263 |
3665
|
264 // Comment preceding FOR token. |
|
265 octave_comment_list *lead_comm; |
|
266 |
|
267 // Comment preceding ENDFOR token. |
|
268 octave_comment_list *trail_comm; |
|
269 |
2982
|
270 void do_for_loop_once (octave_lvalue &val_ref, octave_lvalue &key_ref, |
|
271 const octave_value& val, const octave_value& key, |
|
272 bool& quit); |
2988
|
273 |
|
274 // No copying! |
|
275 |
|
276 tree_complex_for_command (const tree_complex_for_command&); |
|
277 |
|
278 tree_complex_for_command& operator = (const tree_complex_for_command&); |
2982
|
279 }; |
|
280 |
|
281 #endif |
|
282 |
|
283 /* |
|
284 ;;; Local Variables: *** |
|
285 ;;; mode: C++ *** |
|
286 ;;; End: *** |
|
287 */ |