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 class expression; |
|
31 class tree_statement_list; |
|
32 |
|
33 class tree_walker; |
|
34 |
4219
|
35 #include "base-list.h" |
3665
|
36 #include "comment-list.h" |
2982
|
37 #include "pt-cmd.h" |
|
38 |
|
39 // If. |
|
40 |
|
41 class |
|
42 tree_if_clause |
|
43 { |
|
44 public: |
|
45 |
|
46 tree_if_clause (void) |
3665
|
47 : expr (0), list (0), lead_comm (0) { } |
2982
|
48 |
3665
|
49 tree_if_clause (tree_statement_list *l, octave_comment_list *lc = 0) |
|
50 : expr (0), list (l), lead_comm (lc) { } |
2982
|
51 |
3665
|
52 tree_if_clause (tree_expression *e, tree_statement_list *l, |
|
53 octave_comment_list *lc = 0) |
|
54 : expr (e), list (l), lead_comm (lc) { } |
2982
|
55 |
|
56 ~tree_if_clause (void); |
|
57 |
|
58 bool is_else_clause (void) |
|
59 { return ! expr; } |
|
60 |
|
61 int eval (void); |
|
62 |
|
63 tree_expression *condition (void) { return expr; } |
|
64 |
|
65 tree_statement_list *commands (void) { return list; } |
|
66 |
3665
|
67 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
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 |
|
110 void accept (tree_walker& tw); |
2988
|
111 |
|
112 private: |
|
113 |
|
114 // No copying! |
|
115 |
|
116 tree_if_command_list (const tree_if_command_list&); |
|
117 |
|
118 tree_if_command_list& operator = (const tree_if_command_list&); |
2982
|
119 }; |
|
120 |
|
121 class |
|
122 tree_if_command : public tree_command |
|
123 { |
|
124 public: |
|
125 |
|
126 tree_if_command (int l = -1, int c = -1) |
3665
|
127 : tree_command (l, c), list (0), lead_comm (0), trail_comm (0) { } |
2982
|
128 |
3665
|
129 tree_if_command (tree_if_command_list *lst, octave_comment_list *lc, |
|
130 octave_comment_list *tc, int l = -1, int c = -1) |
|
131 : tree_command (l, c), list (lst), lead_comm (lc), trail_comm (tc) { } |
2982
|
132 |
|
133 ~tree_if_command (void); |
|
134 |
|
135 void eval (void); |
|
136 |
|
137 tree_if_command_list *cmd_list (void) { return list; } |
|
138 |
3665
|
139 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
140 |
|
141 octave_comment_list *trailing_comment (void) { return trail_comm; } |
|
142 |
2982
|
143 void accept (tree_walker& tw); |
|
144 |
|
145 private: |
|
146 |
|
147 // List of if commands (if, elseif, elseif, ... else, endif) |
|
148 tree_if_command_list *list; |
2988
|
149 |
3665
|
150 // Comment preceding IF token. |
|
151 octave_comment_list *lead_comm; |
|
152 |
|
153 // Comment preceding ENDIF token. |
|
154 octave_comment_list *trail_comm; |
|
155 |
2988
|
156 // No copying! |
|
157 |
|
158 tree_if_command (const tree_if_command&); |
|
159 |
|
160 tree_if_command& operator = (const tree_if_command&); |
2982
|
161 }; |
|
162 |
|
163 // Switch. |
|
164 |
|
165 class |
|
166 tree_switch_case |
|
167 { |
|
168 public: |
|
169 |
|
170 tree_switch_case (void) |
3665
|
171 : label (0), list (0), lead_comm (0) { } |
2982
|
172 |
3665
|
173 tree_switch_case (tree_statement_list *l, octave_comment_list *lc = 0) |
|
174 : label (0), list (l), lead_comm (lc) { } |
2982
|
175 |
3665
|
176 tree_switch_case (tree_expression *e, tree_statement_list *l, |
|
177 octave_comment_list *lc = 0) |
|
178 : label (e), list (l), lead_comm (lc) { } |
2982
|
179 |
|
180 ~tree_switch_case (void); |
|
181 |
3933
|
182 bool is_default_case (void) { return ! label; } |
2982
|
183 |
|
184 bool label_matches (const octave_value& val); |
|
185 |
|
186 int eval (const octave_value& val); |
|
187 |
|
188 void eval_error (void); |
|
189 |
|
190 tree_expression *case_label (void) { return label; } |
|
191 |
|
192 tree_statement_list *commands (void) { return list; } |
|
193 |
3665
|
194 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
195 |
2982
|
196 void accept (tree_walker& tw); |
|
197 |
|
198 private: |
|
199 |
|
200 // The case label. |
|
201 tree_expression *label; |
|
202 |
|
203 // The list of statements to evaluate if the label matches. |
|
204 tree_statement_list *list; |
2988
|
205 |
3665
|
206 // Comment preceding CASE or OTHERWISE token. |
|
207 octave_comment_list *lead_comm; |
|
208 |
2988
|
209 // No copying! |
|
210 |
|
211 tree_switch_case (const tree_switch_case&); |
|
212 |
|
213 tree_switch_case& operator = (const tree_switch_case&); |
2982
|
214 }; |
|
215 |
|
216 class |
4219
|
217 tree_switch_case_list : public octave_base_list<tree_switch_case *> |
2982
|
218 { |
|
219 public: |
|
220 |
4219
|
221 tree_switch_case_list (void) { } |
2982
|
222 |
4219
|
223 tree_switch_case_list (tree_switch_case *t) { append (t); } |
2982
|
224 |
|
225 ~tree_switch_case_list (void) |
|
226 { |
4219
|
227 while (! empty ()) |
2982
|
228 { |
4219
|
229 iterator p = begin (); |
|
230 delete *p; |
|
231 erase (p); |
2982
|
232 } |
|
233 } |
|
234 |
|
235 void eval (const octave_value& val); |
|
236 |
|
237 void accept (tree_walker& tw); |
2988
|
238 |
|
239 private: |
|
240 |
|
241 // No copying! |
|
242 |
|
243 tree_switch_case_list (const tree_switch_case_list&); |
|
244 |
|
245 tree_switch_case_list& operator = (const tree_switch_case_list&); |
2982
|
246 }; |
|
247 |
|
248 class |
|
249 tree_switch_command : public tree_command |
|
250 { |
|
251 public: |
|
252 |
|
253 tree_switch_command (int l = -1, int c = -1) |
3665
|
254 : tree_command (l, c), expr (0), list (0), lead_comm (0), |
|
255 trail_comm (0) { } |
2982
|
256 |
|
257 tree_switch_command (tree_expression *e, tree_switch_case_list *lst, |
3665
|
258 octave_comment_list *lc, octave_comment_list *tc, |
2982
|
259 int l = -1, int c = -1) |
3665
|
260 : tree_command (l, c), expr (e), list (lst), lead_comm (lc), |
|
261 trail_comm (tc) { } |
2982
|
262 |
|
263 ~tree_switch_command (void); |
|
264 |
|
265 void eval (void); |
|
266 |
|
267 void eval_error (void); |
|
268 |
|
269 tree_expression *switch_value (void) { return expr; } |
|
270 |
|
271 tree_switch_case_list *case_list (void) { return list; } |
|
272 |
3665
|
273 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
274 |
|
275 octave_comment_list *trailing_comment (void) { return trail_comm; } |
|
276 |
2982
|
277 void accept (tree_walker& tw); |
|
278 |
|
279 private: |
|
280 |
|
281 // Value on which to switch. |
|
282 tree_expression *expr; |
|
283 |
|
284 // List of cases (case 1, case 2, ..., default) |
|
285 tree_switch_case_list *list; |
2988
|
286 |
3665
|
287 // Comment preceding SWITCH token. |
|
288 octave_comment_list *lead_comm; |
|
289 |
|
290 // Comment preceding ENDSWITCH token. |
|
291 octave_comment_list *trail_comm; |
|
292 |
2988
|
293 // No copying! |
|
294 |
|
295 tree_switch_command (const tree_switch_command&); |
|
296 |
|
297 tree_switch_command& operator = (const tree_switch_command&); |
2982
|
298 }; |
|
299 |
|
300 #endif |
|
301 |
|
302 /* |
|
303 ;;; Local Variables: *** |
|
304 ;;; mode: C++ *** |
|
305 ;;; End: *** |
|
306 */ |