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