1739
|
1 /* |
|
2 |
1827
|
3 Copyright (C) 1996 John W. Eaton |
1739
|
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_expr2_h) |
|
24 #define octave_tree_expr2_h 1 |
|
25 |
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 class ostream; |
|
31 |
|
32 class tree_identifier; |
|
33 class tree_index_expression; |
|
34 class tree_indirect_ref; |
|
35 class tree_argument_list; |
|
36 |
2124
|
37 class tree_walker; |
|
38 |
1739
|
39 #include "pt-exp-base.h" |
|
40 |
|
41 // Prefix expressions. |
|
42 |
|
43 class |
|
44 tree_prefix_expression : public tree_expression |
|
45 { |
2124
|
46 public: |
|
47 |
1739
|
48 tree_prefix_expression (int l = -1, int c = -1) |
|
49 : tree_expression (l, c), id (0) { } |
|
50 |
|
51 tree_prefix_expression (tree_identifier *t, tree_expression::type et, |
|
52 int l = -1, int c = -1) |
|
53 : tree_expression (l, c, et), id (t) { } |
|
54 |
|
55 ~tree_prefix_expression (void); |
|
56 |
2086
|
57 octave_value eval (bool print); |
1739
|
58 |
|
59 void eval_error (void); |
|
60 |
1827
|
61 bool is_prefix_expression (void) const |
|
62 { return true; } |
1739
|
63 |
|
64 char *oper (void) const; |
|
65 |
2124
|
66 tree_identifier *ident (void) { return id; } |
|
67 |
|
68 void accept (tree_walker& tw); |
1739
|
69 |
2124
|
70 private: |
|
71 |
|
72 // Currently, a prefix expression can only apply to an identifier. |
1739
|
73 tree_identifier *id; |
|
74 }; |
|
75 |
|
76 // Postfix expressions. |
|
77 |
|
78 class |
|
79 tree_postfix_expression : public tree_expression |
|
80 { |
2124
|
81 public: |
|
82 |
1739
|
83 tree_postfix_expression (int l = -1, int c = -1) |
|
84 : tree_expression (l, c), id (0) { } |
|
85 |
|
86 tree_postfix_expression (tree_identifier *t, tree_expression::type et, |
|
87 int l = -1, int c = -1) |
|
88 : tree_expression (l, c, et), id (t) { } |
|
89 |
|
90 ~tree_postfix_expression (void); |
|
91 |
2086
|
92 octave_value eval (bool print); |
1739
|
93 |
|
94 void eval_error (void); |
|
95 |
|
96 char *oper (void) const; |
|
97 |
2124
|
98 tree_identifier *ident (void) { return id; } |
|
99 |
|
100 void accept (tree_walker& tw); |
1739
|
101 |
2124
|
102 private: |
|
103 |
|
104 // Currently, a prefix expression can only apply to an identifier. |
1739
|
105 tree_identifier *id; |
|
106 }; |
|
107 |
|
108 // Unary expressions. |
|
109 |
|
110 class |
|
111 tree_unary_expression : public tree_expression |
|
112 { |
2124
|
113 public: |
|
114 |
1739
|
115 tree_unary_expression (int l = -1, int c = -1) |
|
116 : tree_expression (l, c), op (0) { } |
|
117 |
|
118 tree_unary_expression (tree_expression *a, tree_expression::type t, |
|
119 int l = -1, int c = -1) |
|
120 : tree_expression (l, c, t), op (a) { } |
|
121 |
|
122 ~tree_unary_expression (void) |
|
123 { delete op; } |
|
124 |
2086
|
125 octave_value eval (bool print); |
1739
|
126 |
|
127 void eval_error (void); |
|
128 |
|
129 char *oper (void) const; |
|
130 |
2124
|
131 tree_expression *operand (void) { return op; } |
|
132 |
|
133 void accept (tree_walker& tw); |
1739
|
134 |
2124
|
135 private: |
|
136 |
|
137 // The operand for the expression. |
1739
|
138 tree_expression *op; |
|
139 }; |
|
140 |
|
141 // Binary expressions. |
|
142 |
|
143 class |
|
144 tree_binary_expression : public tree_expression |
|
145 { |
2124
|
146 public: |
|
147 |
1739
|
148 tree_binary_expression (int l = -1, int c = -1) |
2124
|
149 : tree_expression (l, c), op_lhs (0), op_rhs (0) { } |
1739
|
150 |
|
151 tree_binary_expression (tree_expression *a, tree_expression *b, |
|
152 tree_expression::type t, int l = -1, int c = -1) |
2124
|
153 : tree_expression (l, c, t), op_lhs (a), op_rhs (b) { } |
1739
|
154 |
|
155 ~tree_binary_expression (void) |
|
156 { |
2124
|
157 delete op_lhs; |
|
158 delete op_rhs; |
1739
|
159 } |
|
160 |
2086
|
161 octave_value eval (bool print); |
1739
|
162 |
|
163 void eval_error (void); |
|
164 |
|
165 char *oper (void) const; |
|
166 |
2124
|
167 tree_expression *lhs (void) { return op_lhs; } |
|
168 tree_expression *rhs (void) { return op_rhs; } |
|
169 |
|
170 void accept (tree_walker& tw); |
1739
|
171 |
2124
|
172 private: |
|
173 |
|
174 // The operands for the expression. |
|
175 tree_expression *op_lhs; |
|
176 tree_expression *op_rhs; |
1739
|
177 }; |
|
178 |
|
179 // Simple assignment expressions. |
|
180 |
|
181 class |
|
182 tree_simple_assignment_expression : public tree_expression |
|
183 { |
2124
|
184 public: |
1739
|
185 |
1827
|
186 tree_simple_assignment_expression (bool plhs = false, |
|
187 bool ans_assign = false, |
1739
|
188 int l = -1, int c = -1) |
|
189 : tree_expression (l, c) |
|
190 { init (plhs, ans_assign); } |
|
191 |
|
192 tree_simple_assignment_expression (tree_identifier *i, |
|
193 tree_expression *r, |
1827
|
194 bool plhs = false, |
|
195 bool ans_assign = false, |
1739
|
196 int l = -1, int c = -1); |
|
197 |
|
198 tree_simple_assignment_expression (tree_indirect_ref *i, |
|
199 tree_expression *r, |
1827
|
200 bool plhs = false, |
|
201 bool ans_assign = false, |
1739
|
202 int l = -1, int c = -1) |
|
203 : tree_expression (l, c) |
|
204 { |
|
205 init (plhs, ans_assign); |
|
206 lhs = i; |
|
207 rhs = r; |
|
208 } |
|
209 |
|
210 tree_simple_assignment_expression (tree_index_expression *idx_expr, |
|
211 tree_expression *r, |
1827
|
212 bool plhs = false, |
|
213 bool ans_assign = false, |
1739
|
214 int l = -1, int c = -1); |
|
215 |
|
216 ~tree_simple_assignment_expression (void); |
|
217 |
1827
|
218 bool left_hand_side_is_identifier_only (void); |
1739
|
219 |
|
220 tree_identifier *left_hand_side_id (void); |
|
221 |
1827
|
222 bool is_ans_assign (void) |
1739
|
223 { return ans_ass; } |
|
224 |
2086
|
225 octave_value eval (bool print); |
1739
|
226 |
1827
|
227 bool is_assignment_expression (void) const |
|
228 { return true; } |
1739
|
229 |
|
230 void eval_error (void); |
|
231 |
2124
|
232 tree_indirect_ref *left_hand_side (void) { return lhs; } |
|
233 |
|
234 tree_argument_list *lhs_index (void) { return index; } |
|
235 |
|
236 tree_expression *right_hand_side (void) { return rhs; } |
|
237 |
|
238 void accept (tree_walker& tw); |
1739
|
239 |
2124
|
240 private: |
|
241 |
|
242 // The left hand side of the assignment, as an index expression. If |
|
243 // the assignment is constructed from an index expression, the index |
|
244 // expression is split into the its components in the constructor. |
1739
|
245 tree_index_expression *lhs_idx_expr; |
2124
|
246 |
|
247 // The indirect reference (id or structure reference) on the left |
|
248 // hand side of the assignemnt. |
1739
|
249 tree_indirect_ref *lhs; |
2124
|
250 |
|
251 // The index of the left hand side of the assignment, if any. |
1739
|
252 tree_argument_list *index; |
2124
|
253 |
|
254 // The right hand side of the assignment. |
1739
|
255 tree_expression *rhs; |
2124
|
256 |
|
257 // True if we should not delete the lhs. |
1827
|
258 bool preserve; |
2124
|
259 |
|
260 // True if this is an assignment to the built-in variable ans. |
1827
|
261 bool ans_ass; |
2124
|
262 |
|
263 void init (bool plhs, bool ans_assign) |
|
264 { |
|
265 etype = tree_expression::assignment; |
|
266 lhs_idx_expr = 0; |
|
267 lhs = 0; |
|
268 index = 0; |
|
269 rhs = 0; |
|
270 preserve = plhs; |
|
271 ans_ass = ans_assign; |
|
272 } |
|
273 |
1739
|
274 }; |
|
275 |
|
276 // Colon expressions. |
|
277 |
|
278 class |
|
279 tree_colon_expression : public tree_expression |
|
280 { |
2124
|
281 public: |
|
282 |
1739
|
283 tree_colon_expression (int l = -1, int c = -1) |
|
284 : tree_expression (l, c, tree_expression::colon), |
2124
|
285 op_base (0), op_limit (0), op_increment (0) { } |
1739
|
286 |
|
287 tree_colon_expression (tree_expression *a, tree_expression *b, |
|
288 int l = -1, int c = -1) |
|
289 : tree_expression (l, c, tree_expression::colon), |
2124
|
290 op_base (a), op_limit (b), op_increment (0) { } |
1739
|
291 |
|
292 ~tree_colon_expression (void) |
|
293 { |
2124
|
294 delete op_base; |
|
295 delete op_limit; |
|
296 delete op_increment; |
1739
|
297 } |
|
298 |
1827
|
299 bool is_range_constant (void) const; |
1739
|
300 |
|
301 tree_colon_expression *chain (tree_expression *t); |
|
302 |
2086
|
303 octave_value eval (bool print); |
1739
|
304 |
|
305 void eval_error (const char *s); |
|
306 |
2124
|
307 tree_expression *base (void) { return op_base; } |
|
308 tree_expression *limit (void) { return op_limit; } |
|
309 tree_expression *increment (void) { return op_increment; } |
|
310 |
|
311 void accept (tree_walker& tw); |
1739
|
312 |
2124
|
313 private: |
|
314 |
|
315 // The components of the expression. |
|
316 tree_expression *op_base; |
|
317 tree_expression *op_limit; |
|
318 tree_expression *op_increment; |
1739
|
319 }; |
|
320 |
|
321 #endif |
|
322 |
|
323 /* |
|
324 ;;; Local Variables: *** |
|
325 ;;; mode: C++ *** |
|
326 ;;; End: *** |
|
327 */ |