Mercurial > hg > octave-lyh
annotate src/pt-select.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_select_h) | |
25 #define octave_tree_select_h 1 | |
26 | |
27 class expression; | |
28 class tree_statement_list; | |
29 | |
30 class tree_walker; | |
31 | |
4219 | 32 #include "base-list.h" |
3665 | 33 #include "comment-list.h" |
2982 | 34 #include "pt-cmd.h" |
7336 | 35 #include "symtab.h" |
2982 | 36 |
37 // If. | |
38 | |
39 class | |
40 tree_if_clause | |
41 { | |
42 public: | |
43 | |
44 tree_if_clause (void) | |
3665 | 45 : expr (0), list (0), lead_comm (0) { } |
2982 | 46 |
3665 | 47 tree_if_clause (tree_statement_list *l, octave_comment_list *lc = 0) |
48 : expr (0), list (l), lead_comm (lc) { } | |
2982 | 49 |
3665 | 50 tree_if_clause (tree_expression *e, tree_statement_list *l, |
51 octave_comment_list *lc = 0) | |
52 : expr (e), list (l), lead_comm (lc) { } | |
2982 | 53 |
54 ~tree_if_clause (void); | |
55 | |
56 bool is_else_clause (void) | |
57 { return ! expr; } | |
58 | |
59 int eval (void); | |
60 | |
61 tree_expression *condition (void) { return expr; } | |
62 | |
63 tree_statement_list *commands (void) { return list; } | |
64 | |
3665 | 65 octave_comment_list *leading_comment (void) { return lead_comm; } |
66 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
67 tree_if_clause *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
68 symbol_table::context_id context); |
5861 | 69 |
2982 | 70 void accept (tree_walker& tw); |
71 | |
72 private: | |
73 | |
74 // The condition to test. | |
75 tree_expression *expr; | |
76 | |
77 // The list of statements to evaluate if expr is true. | |
78 tree_statement_list *list; | |
2988 | 79 |
3665 | 80 // Comment preceding ELSE or ELSEIF token. |
81 octave_comment_list *lead_comm; | |
82 | |
2988 | 83 // No copying! |
84 | |
85 tree_if_clause (const tree_if_clause&); | |
86 | |
87 tree_if_clause& operator = (const tree_if_clause&); | |
2982 | 88 }; |
89 | |
90 class | |
4219 | 91 tree_if_command_list : public octave_base_list<tree_if_clause *> |
2982 | 92 { |
93 public: | |
94 | |
4219 | 95 tree_if_command_list (void) { } |
2982 | 96 |
4219 | 97 tree_if_command_list (tree_if_clause *t) { append (t); } |
2982 | 98 |
99 ~tree_if_command_list (void) | |
100 { | |
4219 | 101 while (! empty ()) |
2982 | 102 { |
4219 | 103 iterator p = begin (); |
104 delete *p; | |
105 erase (p); | |
2982 | 106 } |
107 } | |
108 | |
109 void eval (void); | |
110 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
111 tree_if_command_list *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
112 symbol_table::context_id context); |
5861 | 113 |
2982 | 114 void accept (tree_walker& tw); |
2988 | 115 |
116 private: | |
117 | |
118 // No copying! | |
119 | |
120 tree_if_command_list (const tree_if_command_list&); | |
121 | |
122 tree_if_command_list& operator = (const tree_if_command_list&); | |
2982 | 123 }; |
124 | |
125 class | |
126 tree_if_command : public tree_command | |
127 { | |
128 public: | |
129 | |
130 tree_if_command (int l = -1, int c = -1) | |
3665 | 131 : tree_command (l, c), list (0), lead_comm (0), trail_comm (0) { } |
2982 | 132 |
3665 | 133 tree_if_command (tree_if_command_list *lst, octave_comment_list *lc, |
134 octave_comment_list *tc, int l = -1, int c = -1) | |
135 : tree_command (l, c), list (lst), lead_comm (lc), trail_comm (tc) { } | |
2982 | 136 |
137 ~tree_if_command (void); | |
138 | |
139 void eval (void); | |
140 | |
141 tree_if_command_list *cmd_list (void) { return list; } | |
142 | |
3665 | 143 octave_comment_list *leading_comment (void) { return lead_comm; } |
144 | |
145 octave_comment_list *trailing_comment (void) { return trail_comm; } | |
146 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
147 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
|
148 symbol_table::context_id context); |
5861 | 149 |
2982 | 150 void accept (tree_walker& tw); |
151 | |
152 private: | |
153 | |
154 // List of if commands (if, elseif, elseif, ... else, endif) | |
155 tree_if_command_list *list; | |
2988 | 156 |
3665 | 157 // Comment preceding IF token. |
158 octave_comment_list *lead_comm; | |
159 | |
160 // Comment preceding ENDIF token. | |
161 octave_comment_list *trail_comm; | |
162 | |
2988 | 163 // No copying! |
164 | |
165 tree_if_command (const tree_if_command&); | |
166 | |
167 tree_if_command& operator = (const tree_if_command&); | |
2982 | 168 }; |
169 | |
170 // Switch. | |
171 | |
172 class | |
173 tree_switch_case | |
174 { | |
175 public: | |
176 | |
177 tree_switch_case (void) | |
3665 | 178 : label (0), list (0), lead_comm (0) { } |
2982 | 179 |
3665 | 180 tree_switch_case (tree_statement_list *l, octave_comment_list *lc = 0) |
181 : label (0), list (l), lead_comm (lc) { } | |
2982 | 182 |
3665 | 183 tree_switch_case (tree_expression *e, tree_statement_list *l, |
184 octave_comment_list *lc = 0) | |
185 : label (e), list (l), lead_comm (lc) { } | |
2982 | 186 |
187 ~tree_switch_case (void); | |
188 | |
3933 | 189 bool is_default_case (void) { return ! label; } |
2982 | 190 |
191 bool label_matches (const octave_value& val); | |
192 | |
193 int eval (const octave_value& val); | |
194 | |
195 void eval_error (void); | |
196 | |
197 tree_expression *case_label (void) { return label; } | |
198 | |
199 tree_statement_list *commands (void) { return list; } | |
200 | |
3665 | 201 octave_comment_list *leading_comment (void) { return lead_comm; } |
202 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
203 tree_switch_case *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
204 symbol_table::context_id context); |
5861 | 205 |
2982 | 206 void accept (tree_walker& tw); |
207 | |
208 private: | |
209 | |
210 // The case label. | |
211 tree_expression *label; | |
212 | |
213 // The list of statements to evaluate if the label matches. | |
214 tree_statement_list *list; | |
2988 | 215 |
3665 | 216 // Comment preceding CASE or OTHERWISE token. |
217 octave_comment_list *lead_comm; | |
218 | |
2988 | 219 // No copying! |
220 | |
221 tree_switch_case (const tree_switch_case&); | |
222 | |
223 tree_switch_case& operator = (const tree_switch_case&); | |
2982 | 224 }; |
225 | |
226 class | |
4219 | 227 tree_switch_case_list : public octave_base_list<tree_switch_case *> |
2982 | 228 { |
229 public: | |
230 | |
4219 | 231 tree_switch_case_list (void) { } |
2982 | 232 |
4219 | 233 tree_switch_case_list (tree_switch_case *t) { append (t); } |
2982 | 234 |
235 ~tree_switch_case_list (void) | |
236 { | |
4219 | 237 while (! empty ()) |
2982 | 238 { |
4219 | 239 iterator p = begin (); |
240 delete *p; | |
241 erase (p); | |
2982 | 242 } |
243 } | |
244 | |
245 void eval (const octave_value& val); | |
246 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
247 tree_switch_case_list *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
248 symbol_table::context_id context); |
5861 | 249 |
2982 | 250 void accept (tree_walker& tw); |
2988 | 251 |
252 private: | |
253 | |
254 // No copying! | |
255 | |
256 tree_switch_case_list (const tree_switch_case_list&); | |
257 | |
258 tree_switch_case_list& operator = (const tree_switch_case_list&); | |
2982 | 259 }; |
260 | |
261 class | |
262 tree_switch_command : public tree_command | |
263 { | |
264 public: | |
265 | |
266 tree_switch_command (int l = -1, int c = -1) | |
3665 | 267 : tree_command (l, c), expr (0), list (0), lead_comm (0), |
268 trail_comm (0) { } | |
2982 | 269 |
270 tree_switch_command (tree_expression *e, tree_switch_case_list *lst, | |
3665 | 271 octave_comment_list *lc, octave_comment_list *tc, |
2982 | 272 int l = -1, int c = -1) |
3665 | 273 : tree_command (l, c), expr (e), list (lst), lead_comm (lc), |
274 trail_comm (tc) { } | |
2982 | 275 |
276 ~tree_switch_command (void); | |
277 | |
278 void eval (void); | |
279 | |
280 void eval_error (void); | |
281 | |
282 tree_expression *switch_value (void) { return expr; } | |
283 | |
284 tree_switch_case_list *case_list (void) { return list; } | |
285 | |
3665 | 286 octave_comment_list *leading_comment (void) { return lead_comm; } |
287 | |
288 octave_comment_list *trailing_comment (void) { return trail_comm; } | |
289 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
290 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
|
291 symbol_table::context_id context); |
5861 | 292 |
2982 | 293 void accept (tree_walker& tw); |
294 | |
295 private: | |
296 | |
297 // Value on which to switch. | |
298 tree_expression *expr; | |
299 | |
300 // List of cases (case 1, case 2, ..., default) | |
301 tree_switch_case_list *list; | |
2988 | 302 |
3665 | 303 // Comment preceding SWITCH token. |
304 octave_comment_list *lead_comm; | |
305 | |
306 // Comment preceding ENDSWITCH token. | |
307 octave_comment_list *trail_comm; | |
308 | |
2988 | 309 // No copying! |
310 | |
311 tree_switch_command (const tree_switch_command&); | |
312 | |
313 tree_switch_command& operator = (const tree_switch_command&); | |
2982 | 314 }; |
315 | |
316 #endif | |
317 | |
318 /* | |
319 ;;; Local Variables: *** | |
320 ;;; mode: C++ *** | |
321 ;;; End: *** | |
322 */ |