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