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