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 |
|
26 #if defined (__GNUG__) |
|
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 |
|
184 bool is_default_case (void) |
|
185 { return ! label; } |
|
186 |
|
187 bool label_matches (const octave_value& val); |
|
188 |
|
189 int eval (const octave_value& val); |
|
190 |
|
191 void eval_error (void); |
|
192 |
|
193 tree_expression *case_label (void) { return label; } |
|
194 |
|
195 tree_statement_list *commands (void) { return list; } |
|
196 |
3665
|
197 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
198 |
2982
|
199 void accept (tree_walker& tw); |
|
200 |
|
201 private: |
|
202 |
|
203 // The case label. |
|
204 tree_expression *label; |
|
205 |
|
206 // The list of statements to evaluate if the label matches. |
|
207 tree_statement_list *list; |
2988
|
208 |
3665
|
209 // Comment preceding CASE or OTHERWISE token. |
|
210 octave_comment_list *lead_comm; |
|
211 |
2988
|
212 // No copying! |
|
213 |
|
214 tree_switch_case (const tree_switch_case&); |
|
215 |
|
216 tree_switch_case& operator = (const tree_switch_case&); |
2982
|
217 }; |
|
218 |
|
219 class |
|
220 tree_switch_case_list : public SLList<tree_switch_case *> |
|
221 { |
|
222 public: |
|
223 |
|
224 tree_switch_case_list (void) |
|
225 : SLList<tree_switch_case *> () { } |
|
226 |
|
227 tree_switch_case_list (tree_switch_case *t) |
|
228 : SLList<tree_switch_case *> () { append (t); } |
|
229 |
|
230 ~tree_switch_case_list (void) |
|
231 { |
|
232 while (! empty ()) |
|
233 { |
|
234 tree_switch_case *t = remove_front (); |
|
235 delete t; |
|
236 } |
|
237 } |
|
238 |
|
239 void eval (const octave_value& val); |
|
240 |
|
241 void accept (tree_walker& tw); |
2988
|
242 |
|
243 private: |
|
244 |
|
245 // No copying! |
|
246 |
|
247 tree_switch_case_list (const tree_switch_case_list&); |
|
248 |
|
249 tree_switch_case_list& operator = (const tree_switch_case_list&); |
2982
|
250 }; |
|
251 |
|
252 class |
|
253 tree_switch_command : public tree_command |
|
254 { |
|
255 public: |
|
256 |
|
257 tree_switch_command (int l = -1, int c = -1) |
3665
|
258 : tree_command (l, c), expr (0), list (0), lead_comm (0), |
|
259 trail_comm (0) { } |
2982
|
260 |
|
261 tree_switch_command (tree_expression *e, tree_switch_case_list *lst, |
3665
|
262 octave_comment_list *lc, octave_comment_list *tc, |
2982
|
263 int l = -1, int c = -1) |
3665
|
264 : tree_command (l, c), expr (e), list (lst), lead_comm (lc), |
|
265 trail_comm (tc) { } |
2982
|
266 |
|
267 ~tree_switch_command (void); |
|
268 |
|
269 void eval (void); |
|
270 |
|
271 void eval_error (void); |
|
272 |
|
273 tree_expression *switch_value (void) { return expr; } |
|
274 |
|
275 tree_switch_case_list *case_list (void) { return list; } |
|
276 |
3665
|
277 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
278 |
|
279 octave_comment_list *trailing_comment (void) { return trail_comm; } |
|
280 |
2982
|
281 void accept (tree_walker& tw); |
|
282 |
|
283 private: |
|
284 |
|
285 // Value on which to switch. |
|
286 tree_expression *expr; |
|
287 |
|
288 // List of cases (case 1, case 2, ..., default) |
|
289 tree_switch_case_list *list; |
2988
|
290 |
3665
|
291 // Comment preceding SWITCH token. |
|
292 octave_comment_list *lead_comm; |
|
293 |
|
294 // Comment preceding ENDSWITCH token. |
|
295 octave_comment_list *trail_comm; |
|
296 |
2988
|
297 // No copying! |
|
298 |
|
299 tree_switch_command (const tree_switch_command&); |
|
300 |
|
301 tree_switch_command& operator = (const tree_switch_command&); |
2982
|
302 }; |
|
303 |
|
304 #endif |
|
305 |
|
306 /* |
|
307 ;;; Local Variables: *** |
|
308 ;;; mode: C++ *** |
|
309 ;;; End: *** |
|
310 */ |