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 |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
2982
|
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 |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
2982
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_tree_select_h) |
|
24 #define octave_tree_select_h 1 |
|
25 |
|
26 class expression; |
|
27 class tree_statement_list; |
|
28 |
|
29 class tree_walker; |
|
30 |
4219
|
31 #include "base-list.h" |
3665
|
32 #include "comment-list.h" |
2982
|
33 #include "pt-cmd.h" |
|
34 |
|
35 // If. |
|
36 |
|
37 class |
|
38 tree_if_clause |
|
39 { |
|
40 public: |
|
41 |
|
42 tree_if_clause (void) |
3665
|
43 : expr (0), list (0), lead_comm (0) { } |
2982
|
44 |
3665
|
45 tree_if_clause (tree_statement_list *l, octave_comment_list *lc = 0) |
|
46 : expr (0), list (l), lead_comm (lc) { } |
2982
|
47 |
3665
|
48 tree_if_clause (tree_expression *e, tree_statement_list *l, |
|
49 octave_comment_list *lc = 0) |
|
50 : expr (e), list (l), lead_comm (lc) { } |
2982
|
51 |
|
52 ~tree_if_clause (void); |
|
53 |
|
54 bool is_else_clause (void) |
|
55 { return ! expr; } |
|
56 |
|
57 int eval (void); |
|
58 |
|
59 tree_expression *condition (void) { return expr; } |
|
60 |
|
61 tree_statement_list *commands (void) { return list; } |
|
62 |
3665
|
63 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
64 |
5861
|
65 tree_if_clause *dup (symbol_table *sym_tab); |
|
66 |
2982
|
67 void accept (tree_walker& tw); |
|
68 |
|
69 private: |
|
70 |
|
71 // The condition to test. |
|
72 tree_expression *expr; |
|
73 |
|
74 // The list of statements to evaluate if expr is true. |
|
75 tree_statement_list *list; |
2988
|
76 |
3665
|
77 // Comment preceding ELSE or ELSEIF token. |
|
78 octave_comment_list *lead_comm; |
|
79 |
2988
|
80 // No copying! |
|
81 |
|
82 tree_if_clause (const tree_if_clause&); |
|
83 |
|
84 tree_if_clause& operator = (const tree_if_clause&); |
2982
|
85 }; |
|
86 |
|
87 class |
4219
|
88 tree_if_command_list : public octave_base_list<tree_if_clause *> |
2982
|
89 { |
|
90 public: |
|
91 |
4219
|
92 tree_if_command_list (void) { } |
2982
|
93 |
4219
|
94 tree_if_command_list (tree_if_clause *t) { append (t); } |
2982
|
95 |
|
96 ~tree_if_command_list (void) |
|
97 { |
4219
|
98 while (! empty ()) |
2982
|
99 { |
4219
|
100 iterator p = begin (); |
|
101 delete *p; |
|
102 erase (p); |
2982
|
103 } |
|
104 } |
|
105 |
|
106 void eval (void); |
|
107 |
5861
|
108 tree_if_command_list *dup (symbol_table *sym_tab); |
|
109 |
2982
|
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 |
5861
|
143 tree_command *dup (symbol_table *sym_tab); |
|
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 |
5861
|
198 tree_switch_case *dup (symbol_table *sym_tab); |
|
199 |
2982
|
200 void accept (tree_walker& tw); |
|
201 |
|
202 private: |
|
203 |
|
204 // The case label. |
|
205 tree_expression *label; |
|
206 |
|
207 // The list of statements to evaluate if the label matches. |
|
208 tree_statement_list *list; |
2988
|
209 |
3665
|
210 // Comment preceding CASE or OTHERWISE token. |
|
211 octave_comment_list *lead_comm; |
|
212 |
2988
|
213 // No copying! |
|
214 |
|
215 tree_switch_case (const tree_switch_case&); |
|
216 |
|
217 tree_switch_case& operator = (const tree_switch_case&); |
2982
|
218 }; |
|
219 |
|
220 class |
4219
|
221 tree_switch_case_list : public octave_base_list<tree_switch_case *> |
2982
|
222 { |
|
223 public: |
|
224 |
4219
|
225 tree_switch_case_list (void) { } |
2982
|
226 |
4219
|
227 tree_switch_case_list (tree_switch_case *t) { append (t); } |
2982
|
228 |
|
229 ~tree_switch_case_list (void) |
|
230 { |
4219
|
231 while (! empty ()) |
2982
|
232 { |
4219
|
233 iterator p = begin (); |
|
234 delete *p; |
|
235 erase (p); |
2982
|
236 } |
|
237 } |
|
238 |
|
239 void eval (const octave_value& val); |
|
240 |
5861
|
241 tree_switch_case_list *dup (symbol_table *sym_tab); |
|
242 |
2982
|
243 void accept (tree_walker& tw); |
2988
|
244 |
|
245 private: |
|
246 |
|
247 // No copying! |
|
248 |
|
249 tree_switch_case_list (const tree_switch_case_list&); |
|
250 |
|
251 tree_switch_case_list& operator = (const tree_switch_case_list&); |
2982
|
252 }; |
|
253 |
|
254 class |
|
255 tree_switch_command : public tree_command |
|
256 { |
|
257 public: |
|
258 |
|
259 tree_switch_command (int l = -1, int c = -1) |
3665
|
260 : tree_command (l, c), expr (0), list (0), lead_comm (0), |
|
261 trail_comm (0) { } |
2982
|
262 |
|
263 tree_switch_command (tree_expression *e, tree_switch_case_list *lst, |
3665
|
264 octave_comment_list *lc, octave_comment_list *tc, |
2982
|
265 int l = -1, int c = -1) |
3665
|
266 : tree_command (l, c), expr (e), list (lst), lead_comm (lc), |
|
267 trail_comm (tc) { } |
2982
|
268 |
|
269 ~tree_switch_command (void); |
|
270 |
|
271 void eval (void); |
|
272 |
|
273 void eval_error (void); |
|
274 |
|
275 tree_expression *switch_value (void) { return expr; } |
|
276 |
|
277 tree_switch_case_list *case_list (void) { return list; } |
|
278 |
3665
|
279 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
280 |
|
281 octave_comment_list *trailing_comment (void) { return trail_comm; } |
|
282 |
5861
|
283 tree_command *dup (symbol_table *sym_tab); |
|
284 |
2982
|
285 void accept (tree_walker& tw); |
|
286 |
|
287 private: |
|
288 |
|
289 // Value on which to switch. |
|
290 tree_expression *expr; |
|
291 |
|
292 // List of cases (case 1, case 2, ..., default) |
|
293 tree_switch_case_list *list; |
2988
|
294 |
3665
|
295 // Comment preceding SWITCH token. |
|
296 octave_comment_list *lead_comm; |
|
297 |
|
298 // Comment preceding ENDSWITCH token. |
|
299 octave_comment_list *trail_comm; |
|
300 |
2988
|
301 // No copying! |
|
302 |
|
303 tree_switch_command (const tree_switch_command&); |
|
304 |
|
305 tree_switch_command& operator = (const tree_switch_command&); |
2982
|
306 }; |
|
307 |
|
308 #endif |
|
309 |
|
310 /* |
|
311 ;;; Local Variables: *** |
|
312 ;;; mode: C++ *** |
|
313 ;;; End: *** |
|
314 */ |