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