comparison src/pt-select.h @ 2982:20f5cec4f11c

[project @ 1997-05-16 03:29:26 by jwe]
author jwe
date Fri, 16 May 1997 03:30:14 +0000
parents
children daa1ed1f5462
comparison
equal deleted inserted replaced
2981:38365813950d 2982:20f5cec4f11c
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;
75 };
76
77 class
78 tree_if_command_list : public SLList<tree_if_clause *>
79 {
80 public:
81
82 tree_if_command_list (void)
83 : SLList<tree_if_clause *> () { }
84
85 tree_if_command_list (tree_if_clause *t)
86 : SLList<tree_if_clause *> () { append (t); }
87
88 ~tree_if_command_list (void)
89 {
90 while (! empty ())
91 {
92 tree_if_clause *t = remove_front ();
93 delete t;
94 }
95 }
96
97 void eval (void);
98
99 void accept (tree_walker& tw);
100 };
101
102 class
103 tree_if_command : public tree_command
104 {
105 public:
106
107 tree_if_command (int l = -1, int c = -1)
108 : tree_command (l, c), list (0) { }
109
110 tree_if_command (tree_if_command_list *lst, int l = -1, int c = -1)
111 : tree_command (l, c), list (lst) { }
112
113 ~tree_if_command (void);
114
115 void eval (void);
116
117 tree_if_command_list *cmd_list (void) { return list; }
118
119 void accept (tree_walker& tw);
120
121 private:
122
123 // List of if commands (if, elseif, elseif, ... else, endif)
124 tree_if_command_list *list;
125 };
126
127 // Switch.
128
129 class
130 tree_switch_case
131 {
132 public:
133
134 tree_switch_case (void)
135 : label (0), list (0) { }
136
137 tree_switch_case (tree_statement_list *l)
138 : label (0), list (l) { }
139
140 tree_switch_case (tree_expression *e, tree_statement_list *l)
141 : label (e), list (l) { }
142
143 ~tree_switch_case (void);
144
145 bool is_default_case (void)
146 { return ! label; }
147
148 bool label_matches (const octave_value& val);
149
150 int eval (const octave_value& val);
151
152 void eval_error (void);
153
154 tree_expression *case_label (void) { return label; }
155
156 tree_statement_list *commands (void) { return list; }
157
158 void accept (tree_walker& tw);
159
160 private:
161
162 // The case label.
163 tree_expression *label;
164
165 // The list of statements to evaluate if the label matches.
166 tree_statement_list *list;
167 };
168
169 class
170 tree_switch_case_list : public SLList<tree_switch_case *>
171 {
172 public:
173
174 tree_switch_case_list (void)
175 : SLList<tree_switch_case *> () { }
176
177 tree_switch_case_list (tree_switch_case *t)
178 : SLList<tree_switch_case *> () { append (t); }
179
180 ~tree_switch_case_list (void)
181 {
182 while (! empty ())
183 {
184 tree_switch_case *t = remove_front ();
185 delete t;
186 }
187 }
188
189 void eval (const octave_value& val);
190
191 void accept (tree_walker& tw);
192 };
193
194 class
195 tree_switch_command : public tree_command
196 {
197 public:
198
199 tree_switch_command (int l = -1, int c = -1)
200 : tree_command (l, c), expr (0), list (0) { }
201
202 tree_switch_command (tree_expression *e, tree_switch_case_list *lst,
203 int l = -1, int c = -1)
204 : tree_command (l, c), expr (e), list (lst) { }
205
206 ~tree_switch_command (void);
207
208 void eval (void);
209
210 void eval_error (void);
211
212 tree_expression *switch_value (void) { return expr; }
213
214 tree_switch_case_list *case_list (void) { return list; }
215
216 void accept (tree_walker& tw);
217
218 private:
219
220 // Value on which to switch.
221 tree_expression *expr;
222
223 // List of cases (case 1, case 2, ..., default)
224 tree_switch_case_list *list;
225 };
226
227 #endif
228
229 /*
230 ;;; Local Variables: ***
231 ;;; mode: C++ ***
232 ;;; End: ***
233 */