2982
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_tree_select_h) |
|
24 #define octave_tree_select_h 1 |
|
25 |
4192
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2982
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <SLList.h> |
|
31 |
|
32 class expression; |
|
33 class tree_statement_list; |
|
34 |
|
35 class tree_walker; |
|
36 |
3665
|
37 #include "comment-list.h" |
2982
|
38 #include "pt-cmd.h" |
|
39 |
|
40 // If. |
|
41 |
|
42 class |
|
43 tree_if_clause |
|
44 { |
|
45 public: |
|
46 |
|
47 tree_if_clause (void) |
3665
|
48 : expr (0), list (0), lead_comm (0) { } |
2982
|
49 |
3665
|
50 tree_if_clause (tree_statement_list *l, octave_comment_list *lc = 0) |
|
51 : expr (0), list (l), lead_comm (lc) { } |
2982
|
52 |
3665
|
53 tree_if_clause (tree_expression *e, tree_statement_list *l, |
|
54 octave_comment_list *lc = 0) |
|
55 : expr (e), list (l), lead_comm (lc) { } |
2982
|
56 |
|
57 ~tree_if_clause (void); |
|
58 |
|
59 bool is_else_clause (void) |
|
60 { return ! expr; } |
|
61 |
|
62 int eval (void); |
|
63 |
|
64 tree_expression *condition (void) { return expr; } |
|
65 |
|
66 tree_statement_list *commands (void) { return list; } |
|
67 |
3665
|
68 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
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 |
4212
|
91 tree_if_command_list |
2982
|
92 { |
|
93 public: |
|
94 |
|
95 tree_if_command_list (void) |
4212
|
96 : lst () { } |
2982
|
97 |
|
98 tree_if_command_list (tree_if_clause *t) |
4212
|
99 : lst () { lst.append (t); } |
2982
|
100 |
|
101 ~tree_if_command_list (void) |
|
102 { |
4212
|
103 while (! lst.empty ()) |
2982
|
104 { |
4212
|
105 tree_if_clause *t = lst.remove_front (); |
2982
|
106 delete t; |
|
107 } |
|
108 } |
|
109 |
4212
|
110 void append (tree_if_clause *&s) { lst.append (s); } |
|
111 void append (tree_if_clause * const &s) { lst.append (s); } |
|
112 |
|
113 tree_if_clause *&operator () (Pix p) { return lst (p); } |
|
114 |
|
115 tree_if_clause * const &operator () (Pix p) const { return lst (p); } |
|
116 |
|
117 Pix first (void) const { return lst.first (); } |
|
118 |
|
119 void next (Pix& p) const { return lst.next (p); } |
|
120 |
2982
|
121 void eval (void); |
|
122 |
|
123 void accept (tree_walker& tw); |
2988
|
124 |
|
125 private: |
|
126 |
4212
|
127 // The list of if/elseif clauses. |
|
128 SLList<tree_if_clause *> lst; |
|
129 |
2988
|
130 // No copying! |
|
131 |
|
132 tree_if_command_list (const tree_if_command_list&); |
|
133 |
|
134 tree_if_command_list& operator = (const tree_if_command_list&); |
2982
|
135 }; |
|
136 |
|
137 class |
|
138 tree_if_command : public tree_command |
|
139 { |
|
140 public: |
|
141 |
|
142 tree_if_command (int l = -1, int c = -1) |
3665
|
143 : tree_command (l, c), list (0), lead_comm (0), trail_comm (0) { } |
2982
|
144 |
3665
|
145 tree_if_command (tree_if_command_list *lst, octave_comment_list *lc, |
|
146 octave_comment_list *tc, int l = -1, int c = -1) |
|
147 : tree_command (l, c), list (lst), lead_comm (lc), trail_comm (tc) { } |
2982
|
148 |
|
149 ~tree_if_command (void); |
|
150 |
|
151 void eval (void); |
|
152 |
|
153 tree_if_command_list *cmd_list (void) { return list; } |
|
154 |
3665
|
155 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
156 |
|
157 octave_comment_list *trailing_comment (void) { return trail_comm; } |
|
158 |
2982
|
159 void accept (tree_walker& tw); |
|
160 |
|
161 private: |
|
162 |
|
163 // List of if commands (if, elseif, elseif, ... else, endif) |
|
164 tree_if_command_list *list; |
2988
|
165 |
3665
|
166 // Comment preceding IF token. |
|
167 octave_comment_list *lead_comm; |
|
168 |
|
169 // Comment preceding ENDIF token. |
|
170 octave_comment_list *trail_comm; |
|
171 |
2988
|
172 // No copying! |
|
173 |
|
174 tree_if_command (const tree_if_command&); |
|
175 |
|
176 tree_if_command& operator = (const tree_if_command&); |
2982
|
177 }; |
|
178 |
|
179 // Switch. |
|
180 |
|
181 class |
|
182 tree_switch_case |
|
183 { |
|
184 public: |
|
185 |
|
186 tree_switch_case (void) |
3665
|
187 : label (0), list (0), lead_comm (0) { } |
2982
|
188 |
3665
|
189 tree_switch_case (tree_statement_list *l, octave_comment_list *lc = 0) |
|
190 : label (0), list (l), lead_comm (lc) { } |
2982
|
191 |
3665
|
192 tree_switch_case (tree_expression *e, tree_statement_list *l, |
|
193 octave_comment_list *lc = 0) |
|
194 : label (e), list (l), lead_comm (lc) { } |
2982
|
195 |
|
196 ~tree_switch_case (void); |
|
197 |
3933
|
198 bool is_default_case (void) { return ! label; } |
2982
|
199 |
|
200 bool label_matches (const octave_value& val); |
|
201 |
|
202 int eval (const octave_value& val); |
|
203 |
|
204 void eval_error (void); |
|
205 |
|
206 tree_expression *case_label (void) { return label; } |
|
207 |
|
208 tree_statement_list *commands (void) { return list; } |
|
209 |
3665
|
210 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
211 |
2982
|
212 void accept (tree_walker& tw); |
|
213 |
|
214 private: |
|
215 |
|
216 // The case label. |
|
217 tree_expression *label; |
|
218 |
|
219 // The list of statements to evaluate if the label matches. |
|
220 tree_statement_list *list; |
2988
|
221 |
3665
|
222 // Comment preceding CASE or OTHERWISE token. |
|
223 octave_comment_list *lead_comm; |
|
224 |
2988
|
225 // No copying! |
|
226 |
|
227 tree_switch_case (const tree_switch_case&); |
|
228 |
|
229 tree_switch_case& operator = (const tree_switch_case&); |
2982
|
230 }; |
|
231 |
|
232 class |
4212
|
233 tree_switch_case_list |
2982
|
234 { |
|
235 public: |
|
236 |
|
237 tree_switch_case_list (void) |
4212
|
238 : lst () { } |
2982
|
239 |
|
240 tree_switch_case_list (tree_switch_case *t) |
4212
|
241 : lst () { lst.append (t); } |
2982
|
242 |
|
243 ~tree_switch_case_list (void) |
|
244 { |
4212
|
245 while (! lst.empty ()) |
2982
|
246 { |
4212
|
247 tree_switch_case *t = lst.remove_front (); |
2982
|
248 delete t; |
|
249 } |
|
250 } |
|
251 |
4212
|
252 void append (tree_switch_case *&s) { lst.append (s); } |
|
253 void append (tree_switch_case * const &s) { lst.append (s); } |
|
254 |
|
255 tree_switch_case *&operator () (Pix p) { return lst (p); } |
|
256 |
|
257 tree_switch_case * const &operator () (Pix p) const { return lst (p); } |
|
258 |
|
259 Pix first (void) const { return lst.first (); } |
|
260 |
|
261 void next (Pix& p) const { return lst.next (p); } |
|
262 |
2982
|
263 void eval (const octave_value& val); |
|
264 |
|
265 void accept (tree_walker& tw); |
2988
|
266 |
|
267 private: |
|
268 |
4212
|
269 // The list of switch cases. |
|
270 SLList<tree_switch_case *> lst; |
|
271 |
2988
|
272 // No copying! |
|
273 |
|
274 tree_switch_case_list (const tree_switch_case_list&); |
|
275 |
|
276 tree_switch_case_list& operator = (const tree_switch_case_list&); |
2982
|
277 }; |
|
278 |
|
279 class |
|
280 tree_switch_command : public tree_command |
|
281 { |
|
282 public: |
|
283 |
|
284 tree_switch_command (int l = -1, int c = -1) |
3665
|
285 : tree_command (l, c), expr (0), list (0), lead_comm (0), |
|
286 trail_comm (0) { } |
2982
|
287 |
|
288 tree_switch_command (tree_expression *e, tree_switch_case_list *lst, |
3665
|
289 octave_comment_list *lc, octave_comment_list *tc, |
2982
|
290 int l = -1, int c = -1) |
3665
|
291 : tree_command (l, c), expr (e), list (lst), lead_comm (lc), |
|
292 trail_comm (tc) { } |
2982
|
293 |
|
294 ~tree_switch_command (void); |
|
295 |
|
296 void eval (void); |
|
297 |
|
298 void eval_error (void); |
|
299 |
|
300 tree_expression *switch_value (void) { return expr; } |
|
301 |
|
302 tree_switch_case_list *case_list (void) { return list; } |
|
303 |
3665
|
304 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
305 |
|
306 octave_comment_list *trailing_comment (void) { return trail_comm; } |
|
307 |
2982
|
308 void accept (tree_walker& tw); |
|
309 |
|
310 private: |
|
311 |
|
312 // Value on which to switch. |
|
313 tree_expression *expr; |
|
314 |
|
315 // List of cases (case 1, case 2, ..., default) |
|
316 tree_switch_case_list *list; |
2988
|
317 |
3665
|
318 // Comment preceding SWITCH token. |
|
319 octave_comment_list *lead_comm; |
|
320 |
|
321 // Comment preceding ENDSWITCH token. |
|
322 octave_comment_list *trail_comm; |
|
323 |
2988
|
324 // No copying! |
|
325 |
|
326 tree_switch_command (const tree_switch_command&); |
|
327 |
|
328 tree_switch_command& operator = (const tree_switch_command&); |
2982
|
329 }; |
|
330 |
|
331 #endif |
|
332 |
|
333 /* |
|
334 ;;; Local Variables: *** |
|
335 ;;; mode: C++ *** |
|
336 ;;; End: *** |
|
337 */ |