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 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <SLList.h> |
|
31 |
|
32 class expression; |
|
33 class tree_statement_list; |
|
34 |
|
35 class tree_walker; |
|
36 |
|
37 #include "pt-cmd.h" |
|
38 |
|
39 // If. |
|
40 |
|
41 class |
|
42 tree_if_clause |
|
43 { |
|
44 public: |
|
45 |
|
46 tree_if_clause (void) |
|
47 : expr (0), list (0) { } |
|
48 |
|
49 tree_if_clause (tree_statement_list *l) |
|
50 : expr (0), list (l) { } |
|
51 |
|
52 tree_if_clause (tree_expression *e, tree_statement_list *l) |
|
53 : expr (e), list (l) { } |
|
54 |
|
55 ~tree_if_clause (void); |
|
56 |
|
57 bool is_else_clause (void) |
|
58 { return ! expr; } |
|
59 |
|
60 int eval (void); |
|
61 |
|
62 tree_expression *condition (void) { return expr; } |
|
63 |
|
64 tree_statement_list *commands (void) { return list; } |
|
65 |
|
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 |
|
76 // No copying! |
|
77 |
|
78 tree_if_clause (const tree_if_clause&); |
|
79 |
|
80 tree_if_clause& operator = (const tree_if_clause&); |
2982
|
81 }; |
|
82 |
|
83 class |
|
84 tree_if_command_list : public SLList<tree_if_clause *> |
|
85 { |
|
86 public: |
|
87 |
|
88 tree_if_command_list (void) |
|
89 : SLList<tree_if_clause *> () { } |
|
90 |
|
91 tree_if_command_list (tree_if_clause *t) |
|
92 : SLList<tree_if_clause *> () { append (t); } |
|
93 |
|
94 ~tree_if_command_list (void) |
|
95 { |
|
96 while (! empty ()) |
|
97 { |
|
98 tree_if_clause *t = remove_front (); |
|
99 delete t; |
|
100 } |
|
101 } |
|
102 |
|
103 void eval (void); |
|
104 |
|
105 void accept (tree_walker& tw); |
2988
|
106 |
|
107 private: |
|
108 |
|
109 // No copying! |
|
110 |
|
111 tree_if_command_list (const tree_if_command_list&); |
|
112 |
|
113 tree_if_command_list& operator = (const tree_if_command_list&); |
2982
|
114 }; |
|
115 |
|
116 class |
|
117 tree_if_command : public tree_command |
|
118 { |
|
119 public: |
|
120 |
|
121 tree_if_command (int l = -1, int c = -1) |
|
122 : tree_command (l, c), list (0) { } |
|
123 |
|
124 tree_if_command (tree_if_command_list *lst, int l = -1, int c = -1) |
|
125 : tree_command (l, c), list (lst) { } |
|
126 |
|
127 ~tree_if_command (void); |
|
128 |
|
129 void eval (void); |
|
130 |
|
131 tree_if_command_list *cmd_list (void) { return list; } |
|
132 |
|
133 void accept (tree_walker& tw); |
|
134 |
|
135 private: |
|
136 |
|
137 // List of if commands (if, elseif, elseif, ... else, endif) |
|
138 tree_if_command_list *list; |
2988
|
139 |
|
140 // No copying! |
|
141 |
|
142 tree_if_command (const tree_if_command&); |
|
143 |
|
144 tree_if_command& operator = (const tree_if_command&); |
2982
|
145 }; |
|
146 |
|
147 // Switch. |
|
148 |
|
149 class |
|
150 tree_switch_case |
|
151 { |
|
152 public: |
|
153 |
|
154 tree_switch_case (void) |
|
155 : label (0), list (0) { } |
|
156 |
|
157 tree_switch_case (tree_statement_list *l) |
|
158 : label (0), list (l) { } |
|
159 |
|
160 tree_switch_case (tree_expression *e, tree_statement_list *l) |
|
161 : label (e), list (l) { } |
|
162 |
|
163 ~tree_switch_case (void); |
|
164 |
|
165 bool is_default_case (void) |
|
166 { return ! label; } |
|
167 |
|
168 bool label_matches (const octave_value& val); |
|
169 |
|
170 int eval (const octave_value& val); |
|
171 |
|
172 void eval_error (void); |
|
173 |
|
174 tree_expression *case_label (void) { return label; } |
|
175 |
|
176 tree_statement_list *commands (void) { return list; } |
|
177 |
|
178 void accept (tree_walker& tw); |
|
179 |
|
180 private: |
|
181 |
|
182 // The case label. |
|
183 tree_expression *label; |
|
184 |
|
185 // The list of statements to evaluate if the label matches. |
|
186 tree_statement_list *list; |
2988
|
187 |
|
188 // No copying! |
|
189 |
|
190 tree_switch_case (const tree_switch_case&); |
|
191 |
|
192 tree_switch_case& operator = (const tree_switch_case&); |
2982
|
193 }; |
|
194 |
|
195 class |
|
196 tree_switch_case_list : public SLList<tree_switch_case *> |
|
197 { |
|
198 public: |
|
199 |
|
200 tree_switch_case_list (void) |
|
201 : SLList<tree_switch_case *> () { } |
|
202 |
|
203 tree_switch_case_list (tree_switch_case *t) |
|
204 : SLList<tree_switch_case *> () { append (t); } |
|
205 |
|
206 ~tree_switch_case_list (void) |
|
207 { |
|
208 while (! empty ()) |
|
209 { |
|
210 tree_switch_case *t = remove_front (); |
|
211 delete t; |
|
212 } |
|
213 } |
|
214 |
|
215 void eval (const octave_value& val); |
|
216 |
|
217 void accept (tree_walker& tw); |
2988
|
218 |
|
219 private: |
|
220 |
|
221 // No copying! |
|
222 |
|
223 tree_switch_case_list (const tree_switch_case_list&); |
|
224 |
|
225 tree_switch_case_list& operator = (const tree_switch_case_list&); |
2982
|
226 }; |
|
227 |
|
228 class |
|
229 tree_switch_command : public tree_command |
|
230 { |
|
231 public: |
|
232 |
|
233 tree_switch_command (int l = -1, int c = -1) |
|
234 : tree_command (l, c), expr (0), list (0) { } |
|
235 |
|
236 tree_switch_command (tree_expression *e, tree_switch_case_list *lst, |
|
237 int l = -1, int c = -1) |
|
238 : tree_command (l, c), expr (e), list (lst) { } |
|
239 |
|
240 ~tree_switch_command (void); |
|
241 |
|
242 void eval (void); |
|
243 |
|
244 void eval_error (void); |
|
245 |
|
246 tree_expression *switch_value (void) { return expr; } |
|
247 |
|
248 tree_switch_case_list *case_list (void) { return list; } |
|
249 |
|
250 void accept (tree_walker& tw); |
|
251 |
|
252 private: |
|
253 |
|
254 // Value on which to switch. |
|
255 tree_expression *expr; |
|
256 |
|
257 // List of cases (case 1, case 2, ..., default) |
|
258 tree_switch_case_list *list; |
2988
|
259 |
|
260 // No copying! |
|
261 |
|
262 tree_switch_command (const tree_switch_command&); |
|
263 |
|
264 tree_switch_command& operator = (const tree_switch_command&); |
2982
|
265 }; |
|
266 |
|
267 #endif |
|
268 |
|
269 /* |
|
270 ;;; Local Variables: *** |
|
271 ;;; mode: C++ *** |
|
272 ;;; End: *** |
|
273 */ |