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