Mercurial > hg > octave-nkf
annotate src/pt-loop.h @ 7767:71f068b22fcc
scope and context fixes for function handles
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 07 May 2008 13:45:30 -0400 |
parents | 745a8299c2b5 |
children | 3100283874d7 |
rev | line source |
---|---|
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 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
82 tree_command *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
83 symbol_table::context_id context); |
5861 | 84 |
2982 | 85 void accept (tree_walker& tw); |
86 | |
3484 | 87 protected: |
2982 | 88 |
89 // Expression to test. | |
90 tree_expression *expr; | |
91 | |
92 // List of commands to execute. | |
93 tree_statement_list *list; | |
2988 | 94 |
3665 | 95 // Comment preceding WHILE token. |
96 octave_comment_list *lead_comm; | |
97 | |
98 // Comment preceding ENDWHILE token. | |
99 octave_comment_list *trail_comm; | |
100 | |
3484 | 101 private: |
102 | |
2988 | 103 // No copying! |
104 | |
105 tree_while_command (const tree_while_command&); | |
106 | |
107 tree_while_command& operator = (const tree_while_command&); | |
2982 | 108 }; |
109 | |
3484 | 110 // Do-Until. |
111 | |
112 class | |
113 tree_do_until_command : public tree_while_command | |
114 { | |
115 public: | |
116 | |
117 tree_do_until_command (int l = -1, int c = -1) | |
118 : tree_while_command (l, c) { } | |
119 | |
3665 | 120 tree_do_until_command (tree_expression *e, |
121 octave_comment_list *lc = 0, | |
122 octave_comment_list *tc = 0, | |
123 int l = -1, int c = -1) | |
124 : tree_while_command (e, lc, tc, l, c) { } | |
3484 | 125 |
126 tree_do_until_command (tree_expression *e, tree_statement_list *lst, | |
3665 | 127 octave_comment_list *lc = 0, |
128 octave_comment_list *tc = 0, | |
129 int l = -1, int c = -1) | |
130 : tree_while_command (e, lst, lc, tc, l, c) { } | |
3484 | 131 |
132 ~tree_do_until_command (void) { } | |
133 | |
134 void eval (void); | |
135 | |
136 void eval_error (void); | |
137 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
138 tree_command *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
139 symbol_table::context_id context); |
5861 | 140 |
3484 | 141 void accept (tree_walker& tw); |
142 | |
143 private: | |
144 | |
145 // No copying! | |
146 | |
147 tree_do_until_command (const tree_do_until_command&); | |
148 | |
149 tree_do_until_command& operator = (const tree_do_until_command&); | |
150 }; | |
151 | |
2982 | 152 // For. |
153 | |
154 class | |
155 tree_simple_for_command : public tree_command | |
156 { | |
157 public: | |
158 | |
159 tree_simple_for_command (int l = -1, int c = -1) | |
3665 | 160 : tree_command (l, c), lhs (0), expr (0), list (0), lead_comm (0), |
161 trail_comm (0) { } | |
2982 | 162 |
163 tree_simple_for_command (tree_expression *le, tree_expression *re, | |
3665 | 164 tree_statement_list *lst, |
165 octave_comment_list *lc = 0, | |
166 octave_comment_list *tc = 0, | |
167 int l = -1, int c = -1) | |
168 : tree_command (l, c), lhs (le), expr (re), list (lst), | |
169 lead_comm (lc), trail_comm (tc) { } | |
2982 | 170 |
171 ~tree_simple_for_command (void); | |
172 | |
173 void eval (void); | |
174 | |
175 void eval_error (void); | |
176 | |
177 tree_expression *left_hand_side (void) { return lhs; } | |
178 | |
179 tree_expression *control_expr (void) { return expr; } | |
180 | |
181 tree_statement_list *body (void) { return list; } | |
182 | |
3665 | 183 octave_comment_list *leading_comment (void) { return lead_comm; } |
184 | |
185 octave_comment_list *trailing_comment (void) { return trail_comm; } | |
186 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
187 tree_command *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
188 symbol_table::context_id context); |
5861 | 189 |
2982 | 190 void accept (tree_walker& tw); |
191 | |
192 private: | |
193 | |
194 // Expression to modify. | |
195 tree_expression *lhs; | |
196 | |
197 // Expression to evaluate. | |
198 tree_expression *expr; | |
199 | |
200 // List of commands to execute. | |
201 tree_statement_list *list; | |
202 | |
3665 | 203 // Comment preceding FOR token. |
204 octave_comment_list *lead_comm; | |
205 | |
206 // Comment preceding ENDFOR token. | |
207 octave_comment_list *trail_comm; | |
208 | |
2982 | 209 void do_for_loop_once (octave_lvalue &ult, const octave_value& rhs, |
210 bool& quit); | |
2988 | 211 |
212 // No copying! | |
213 | |
214 tree_simple_for_command (const tree_simple_for_command&); | |
215 | |
216 tree_simple_for_command& operator = (const tree_simple_for_command&); | |
2982 | 217 }; |
218 | |
219 class | |
220 tree_complex_for_command : public tree_command | |
221 { | |
222 public: | |
223 | |
224 tree_complex_for_command (int l = -1, int c = -1) | |
3665 | 225 : tree_command (l, c), lhs (0), expr (0), list (0), lead_comm (0), |
226 trail_comm (0) { } | |
2982 | 227 |
228 tree_complex_for_command (tree_argument_list *le, tree_expression *re, | |
3665 | 229 tree_statement_list *lst, |
230 octave_comment_list *lc = 0, | |
231 octave_comment_list *tc = 0, | |
232 int l = -1, int c = -1) | |
233 : tree_command (l, c), lhs (le), expr (re), list (lst), | |
234 lead_comm (lc), trail_comm (tc) { } | |
2982 | 235 |
236 ~tree_complex_for_command (void); | |
237 | |
238 void eval (void); | |
239 | |
240 void eval_error (void); | |
241 | |
242 tree_argument_list *left_hand_side (void) { return lhs; } | |
243 | |
244 tree_expression *control_expr (void) { return expr; } | |
245 | |
246 tree_statement_list *body (void) { return list; } | |
247 | |
3665 | 248 octave_comment_list *leading_comment (void) { return lead_comm; } |
249 | |
250 octave_comment_list *trailing_comment (void) { return trail_comm; } | |
251 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
252 tree_command *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
253 symbol_table::context_id context); |
5861 | 254 |
2982 | 255 void accept (tree_walker& tw); |
256 | |
257 private: | |
258 | |
259 // Expression to modify. | |
260 tree_argument_list *lhs; | |
261 | |
262 // Expression to evaluate. | |
263 tree_expression *expr; | |
264 | |
265 // List of commands to execute. | |
266 tree_statement_list *list; | |
267 | |
3665 | 268 // Comment preceding FOR token. |
269 octave_comment_list *lead_comm; | |
270 | |
271 // Comment preceding ENDFOR token. | |
272 octave_comment_list *trail_comm; | |
273 | |
2982 | 274 void do_for_loop_once (octave_lvalue &val_ref, octave_lvalue &key_ref, |
275 const octave_value& val, const octave_value& key, | |
276 bool& quit); | |
2988 | 277 |
278 // No copying! | |
279 | |
280 tree_complex_for_command (const tree_complex_for_command&); | |
281 | |
282 tree_complex_for_command& operator = (const tree_complex_for_command&); | |
2982 | 283 }; |
284 | |
285 #endif | |
286 | |
287 /* | |
288 ;;; Local Variables: *** | |
289 ;;; mode: C++ *** | |
290 ;;; End: *** | |
291 */ |