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 |
4066
|
26 #if defined (__GNUG__) && ! defined (NO_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 |
|
91 tree_if_command_list : public SLList<tree_if_clause *> |
|
92 { |
|
93 public: |
|
94 |
|
95 tree_if_command_list (void) |
|
96 : SLList<tree_if_clause *> () { } |
|
97 |
|
98 tree_if_command_list (tree_if_clause *t) |
|
99 : SLList<tree_if_clause *> () { append (t); } |
|
100 |
|
101 ~tree_if_command_list (void) |
|
102 { |
|
103 while (! empty ()) |
|
104 { |
|
105 tree_if_clause *t = remove_front (); |
|
106 delete t; |
|
107 } |
|
108 } |
|
109 |
|
110 void eval (void); |
|
111 |
|
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 |
2982
|
145 void accept (tree_walker& tw); |
|
146 |
|
147 private: |
|
148 |
|
149 // List of if commands (if, elseif, elseif, ... else, endif) |
|
150 tree_if_command_list *list; |
2988
|
151 |
3665
|
152 // Comment preceding IF token. |
|
153 octave_comment_list *lead_comm; |
|
154 |
|
155 // Comment preceding ENDIF token. |
|
156 octave_comment_list *trail_comm; |
|
157 |
2988
|
158 // No copying! |
|
159 |
|
160 tree_if_command (const tree_if_command&); |
|
161 |
|
162 tree_if_command& operator = (const tree_if_command&); |
2982
|
163 }; |
|
164 |
|
165 // Switch. |
|
166 |
|
167 class |
|
168 tree_switch_case |
|
169 { |
|
170 public: |
|
171 |
|
172 tree_switch_case (void) |
3665
|
173 : label (0), list (0), lead_comm (0) { } |
2982
|
174 |
3665
|
175 tree_switch_case (tree_statement_list *l, octave_comment_list *lc = 0) |
|
176 : label (0), list (l), lead_comm (lc) { } |
2982
|
177 |
3665
|
178 tree_switch_case (tree_expression *e, tree_statement_list *l, |
|
179 octave_comment_list *lc = 0) |
|
180 : label (e), list (l), lead_comm (lc) { } |
2982
|
181 |
|
182 ~tree_switch_case (void); |
|
183 |
3933
|
184 bool is_default_case (void) { return ! label; } |
2982
|
185 |
|
186 bool label_matches (const octave_value& val); |
|
187 |
|
188 int eval (const octave_value& val); |
|
189 |
|
190 void eval_error (void); |
|
191 |
|
192 tree_expression *case_label (void) { return label; } |
|
193 |
|
194 tree_statement_list *commands (void) { return list; } |
|
195 |
3665
|
196 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
197 |
2982
|
198 void accept (tree_walker& tw); |
|
199 |
|
200 private: |
|
201 |
|
202 // The case label. |
|
203 tree_expression *label; |
|
204 |
|
205 // The list of statements to evaluate if the label matches. |
|
206 tree_statement_list *list; |
2988
|
207 |
3665
|
208 // Comment preceding CASE or OTHERWISE token. |
|
209 octave_comment_list *lead_comm; |
|
210 |
2988
|
211 // No copying! |
|
212 |
|
213 tree_switch_case (const tree_switch_case&); |
|
214 |
|
215 tree_switch_case& operator = (const tree_switch_case&); |
2982
|
216 }; |
|
217 |
|
218 class |
|
219 tree_switch_case_list : public SLList<tree_switch_case *> |
|
220 { |
|
221 public: |
|
222 |
|
223 tree_switch_case_list (void) |
|
224 : SLList<tree_switch_case *> () { } |
|
225 |
|
226 tree_switch_case_list (tree_switch_case *t) |
|
227 : SLList<tree_switch_case *> () { append (t); } |
|
228 |
|
229 ~tree_switch_case_list (void) |
|
230 { |
|
231 while (! empty ()) |
|
232 { |
|
233 tree_switch_case *t = remove_front (); |
|
234 delete t; |
|
235 } |
|
236 } |
|
237 |
|
238 void eval (const octave_value& val); |
|
239 |
|
240 void accept (tree_walker& tw); |
2988
|
241 |
|
242 private: |
|
243 |
|
244 // No copying! |
|
245 |
|
246 tree_switch_case_list (const tree_switch_case_list&); |
|
247 |
|
248 tree_switch_case_list& operator = (const tree_switch_case_list&); |
2982
|
249 }; |
|
250 |
|
251 class |
|
252 tree_switch_command : public tree_command |
|
253 { |
|
254 public: |
|
255 |
|
256 tree_switch_command (int l = -1, int c = -1) |
3665
|
257 : tree_command (l, c), expr (0), list (0), lead_comm (0), |
|
258 trail_comm (0) { } |
2982
|
259 |
|
260 tree_switch_command (tree_expression *e, tree_switch_case_list *lst, |
3665
|
261 octave_comment_list *lc, octave_comment_list *tc, |
2982
|
262 int l = -1, int c = -1) |
3665
|
263 : tree_command (l, c), expr (e), list (lst), lead_comm (lc), |
|
264 trail_comm (tc) { } |
2982
|
265 |
|
266 ~tree_switch_command (void); |
|
267 |
|
268 void eval (void); |
|
269 |
|
270 void eval_error (void); |
|
271 |
|
272 tree_expression *switch_value (void) { return expr; } |
|
273 |
|
274 tree_switch_case_list *case_list (void) { return list; } |
|
275 |
3665
|
276 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
277 |
|
278 octave_comment_list *trailing_comment (void) { return trail_comm; } |
|
279 |
2982
|
280 void accept (tree_walker& tw); |
|
281 |
|
282 private: |
|
283 |
|
284 // Value on which to switch. |
|
285 tree_expression *expr; |
|
286 |
|
287 // List of cases (case 1, case 2, ..., default) |
|
288 tree_switch_case_list *list; |
2988
|
289 |
3665
|
290 // Comment preceding SWITCH token. |
|
291 octave_comment_list *lead_comm; |
|
292 |
|
293 // Comment preceding ENDSWITCH token. |
|
294 octave_comment_list *trail_comm; |
|
295 |
2988
|
296 // No copying! |
|
297 |
|
298 tree_switch_command (const tree_switch_command&); |
|
299 |
|
300 tree_switch_command& operator = (const tree_switch_command&); |
2982
|
301 }; |
|
302 |
|
303 #endif |
|
304 |
|
305 /* |
|
306 ;;; Local Variables: *** |
|
307 ;;; mode: C++ *** |
|
308 ;;; End: *** |
|
309 */ |