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 |
2388
|
48 enum type |
|
49 { |
|
50 unknown, |
|
51 increment, |
|
52 decrement |
|
53 }; |
1739
|
54 |
2388
|
55 tree_prefix_expression (int l = -1, int c = -1, type t = unknown) |
|
56 : tree_expression (l, c), id (0), etype (t) { } |
|
57 |
|
58 tree_prefix_expression (tree_identifier *i, int l = -1, int c = -1, |
|
59 type t = unknown) |
|
60 : tree_expression (l, c), id (i), etype (t) { } |
1739
|
61 |
|
62 ~tree_prefix_expression (void); |
|
63 |
2086
|
64 octave_value eval (bool print); |
1739
|
65 |
|
66 void eval_error (void); |
|
67 |
1827
|
68 bool is_prefix_expression (void) const |
|
69 { return true; } |
1739
|
70 |
|
71 char *oper (void) const; |
|
72 |
2124
|
73 tree_identifier *ident (void) { return id; } |
|
74 |
|
75 void accept (tree_walker& tw); |
1739
|
76 |
2124
|
77 private: |
|
78 |
|
79 // Currently, a prefix expression can only apply to an identifier. |
1739
|
80 tree_identifier *id; |
2388
|
81 |
|
82 // The type of the expression. |
|
83 type etype; |
1739
|
84 }; |
|
85 |
|
86 // Postfix expressions. |
|
87 |
|
88 class |
|
89 tree_postfix_expression : public tree_expression |
|
90 { |
2124
|
91 public: |
|
92 |
2388
|
93 enum type |
|
94 { |
|
95 unknown, |
|
96 increment, |
|
97 decrement |
|
98 }; |
1739
|
99 |
2388
|
100 tree_postfix_expression (int l = -1, int c = -1, type t = unknown) |
|
101 : tree_expression (l, c), id (0), etype (t) { } |
|
102 |
|
103 tree_postfix_expression (tree_identifier *i, int l = -1, int c = -1, |
|
104 type t = unknown) |
|
105 : tree_expression (l, c), id (i), etype (t) { } |
1739
|
106 |
|
107 ~tree_postfix_expression (void); |
|
108 |
2086
|
109 octave_value eval (bool print); |
1739
|
110 |
|
111 void eval_error (void); |
|
112 |
|
113 char *oper (void) const; |
|
114 |
2124
|
115 tree_identifier *ident (void) { return id; } |
|
116 |
|
117 void accept (tree_walker& tw); |
1739
|
118 |
2124
|
119 private: |
|
120 |
|
121 // Currently, a prefix expression can only apply to an identifier. |
1739
|
122 tree_identifier *id; |
2388
|
123 |
|
124 // The type of the expression. |
|
125 type etype; |
1739
|
126 }; |
|
127 |
|
128 // Unary expressions. |
|
129 |
|
130 class |
|
131 tree_unary_expression : public tree_expression |
|
132 { |
2124
|
133 public: |
|
134 |
2388
|
135 enum type |
|
136 { |
|
137 unknown, |
|
138 not, |
|
139 unot, |
|
140 uminus, |
|
141 hermitian, |
|
142 transpose |
|
143 }; |
1739
|
144 |
2388
|
145 tree_unary_expression (int l = -1, int c = -1, type t = unknown) |
|
146 : tree_expression (l, c), op (0), etype (t) { } |
|
147 |
|
148 tree_unary_expression (tree_expression *a, int l = -1, int c = -1, |
|
149 type t = unknown) |
|
150 : tree_expression (l, c), op (a), etype (t) { } |
1739
|
151 |
|
152 ~tree_unary_expression (void) |
|
153 { delete op; } |
|
154 |
2086
|
155 octave_value eval (bool print); |
1739
|
156 |
|
157 void eval_error (void); |
|
158 |
|
159 char *oper (void) const; |
|
160 |
2388
|
161 bool is_prefix_op (void) { return (etype == not || etype == uminus); } |
|
162 |
2124
|
163 tree_expression *operand (void) { return op; } |
|
164 |
|
165 void accept (tree_walker& tw); |
1739
|
166 |
2124
|
167 private: |
|
168 |
|
169 // The operand for the expression. |
1739
|
170 tree_expression *op; |
2388
|
171 |
|
172 // The type of the expression. |
|
173 type etype; |
1739
|
174 }; |
|
175 |
|
176 // Binary expressions. |
|
177 |
|
178 class |
|
179 tree_binary_expression : public tree_expression |
|
180 { |
2124
|
181 public: |
|
182 |
2388
|
183 enum type |
|
184 { |
|
185 unknown, |
|
186 add, |
|
187 subtract, |
|
188 multiply, |
|
189 el_mul, |
|
190 divide, |
|
191 el_div, |
|
192 leftdiv, |
|
193 el_leftdiv, |
|
194 power, |
|
195 elem_pow, |
|
196 cmp_lt, |
|
197 cmp_le, |
|
198 cmp_eq, |
|
199 cmp_ge, |
|
200 cmp_gt, |
|
201 cmp_ne, |
|
202 and, |
|
203 or |
|
204 }; |
|
205 |
|
206 tree_binary_expression (int l = -1, int c = -1, type t = unknown) |
|
207 : tree_expression (l, c), op_lhs (0), op_rhs (0), etype (t) { } |
1739
|
208 |
|
209 tree_binary_expression (tree_expression *a, tree_expression *b, |
2388
|
210 int l = -1, int c = -1, type t = unknown) |
|
211 : tree_expression (l, c), op_lhs (a), op_rhs (b), etype (t) { } |
1739
|
212 |
|
213 ~tree_binary_expression (void) |
|
214 { |
2124
|
215 delete op_lhs; |
|
216 delete op_rhs; |
1739
|
217 } |
|
218 |
2086
|
219 octave_value eval (bool print); |
1739
|
220 |
|
221 void eval_error (void); |
|
222 |
|
223 char *oper (void) const; |
|
224 |
2124
|
225 tree_expression *lhs (void) { return op_lhs; } |
|
226 tree_expression *rhs (void) { return op_rhs; } |
|
227 |
|
228 void accept (tree_walker& tw); |
1739
|
229 |
2388
|
230 protected: |
2124
|
231 |
|
232 // The operands for the expression. |
|
233 tree_expression *op_lhs; |
|
234 tree_expression *op_rhs; |
2388
|
235 |
|
236 private: |
|
237 |
|
238 // The type of the expression. |
|
239 type etype; |
|
240 }; |
|
241 |
|
242 // Boolean expressions. |
|
243 |
|
244 class |
|
245 tree_boolean_expression : public tree_binary_expression |
|
246 { |
|
247 public: |
|
248 |
|
249 enum type |
|
250 { |
|
251 unknown, |
|
252 and, |
|
253 or |
|
254 }; |
|
255 |
|
256 tree_boolean_expression (int l = -1, int c = -1, type t) |
|
257 : tree_binary_expression (l, c), etype (t) { } |
|
258 |
|
259 tree_boolean_expression (tree_expression *a, tree_expression *b, |
|
260 int l = -1, int c = -1, type t = unknown) |
|
261 : tree_binary_expression (a, b, l, c), etype (t) { } |
|
262 |
|
263 ~tree_boolean_expression (void) { } |
|
264 |
|
265 octave_value eval (bool print); |
|
266 |
|
267 char *oper (void) const; |
|
268 |
|
269 private: |
|
270 |
|
271 // The type of the expression. |
|
272 type etype; |
1739
|
273 }; |
|
274 |
|
275 // Simple assignment expressions. |
|
276 |
|
277 class |
|
278 tree_simple_assignment_expression : public tree_expression |
|
279 { |
2124
|
280 public: |
1739
|
281 |
1827
|
282 tree_simple_assignment_expression (bool plhs = false, |
|
283 bool ans_assign = false, |
1739
|
284 int l = -1, int c = -1) |
|
285 : tree_expression (l, c) |
|
286 { init (plhs, ans_assign); } |
|
287 |
|
288 tree_simple_assignment_expression (tree_identifier *i, |
|
289 tree_expression *r, |
1827
|
290 bool plhs = false, |
|
291 bool ans_assign = false, |
1739
|
292 int l = -1, int c = -1); |
|
293 |
|
294 tree_simple_assignment_expression (tree_indirect_ref *i, |
|
295 tree_expression *r, |
1827
|
296 bool plhs = false, |
|
297 bool ans_assign = false, |
1739
|
298 int l = -1, int c = -1) |
|
299 : tree_expression (l, c) |
|
300 { |
|
301 init (plhs, ans_assign); |
|
302 lhs = i; |
|
303 rhs = r; |
|
304 } |
|
305 |
|
306 tree_simple_assignment_expression (tree_index_expression *idx_expr, |
|
307 tree_expression *r, |
1827
|
308 bool plhs = false, |
|
309 bool ans_assign = false, |
1739
|
310 int l = -1, int c = -1); |
|
311 |
|
312 ~tree_simple_assignment_expression (void); |
|
313 |
1827
|
314 bool left_hand_side_is_identifier_only (void); |
1739
|
315 |
|
316 tree_identifier *left_hand_side_id (void); |
|
317 |
1827
|
318 bool is_ans_assign (void) |
1739
|
319 { return ans_ass; } |
|
320 |
2086
|
321 octave_value eval (bool print); |
1739
|
322 |
1827
|
323 bool is_assignment_expression (void) const |
|
324 { return true; } |
1739
|
325 |
|
326 void eval_error (void); |
|
327 |
2124
|
328 tree_indirect_ref *left_hand_side (void) { return lhs; } |
|
329 |
|
330 tree_argument_list *lhs_index (void) { return index; } |
|
331 |
|
332 tree_expression *right_hand_side (void) { return rhs; } |
|
333 |
|
334 void accept (tree_walker& tw); |
1739
|
335 |
2124
|
336 private: |
|
337 |
|
338 // The left hand side of the assignment, as an index expression. If |
|
339 // the assignment is constructed from an index expression, the index |
|
340 // expression is split into the its components in the constructor. |
1739
|
341 tree_index_expression *lhs_idx_expr; |
2124
|
342 |
|
343 // The indirect reference (id or structure reference) on the left |
|
344 // hand side of the assignemnt. |
1739
|
345 tree_indirect_ref *lhs; |
2124
|
346 |
|
347 // The index of the left hand side of the assignment, if any. |
1739
|
348 tree_argument_list *index; |
2124
|
349 |
|
350 // The right hand side of the assignment. |
1739
|
351 tree_expression *rhs; |
2124
|
352 |
|
353 // True if we should not delete the lhs. |
1827
|
354 bool preserve; |
2124
|
355 |
|
356 // True if this is an assignment to the built-in variable ans. |
1827
|
357 bool ans_ass; |
2124
|
358 |
|
359 void init (bool plhs, bool ans_assign) |
|
360 { |
|
361 etype = tree_expression::assignment; |
|
362 lhs_idx_expr = 0; |
|
363 lhs = 0; |
|
364 index = 0; |
|
365 rhs = 0; |
|
366 preserve = plhs; |
|
367 ans_ass = ans_assign; |
|
368 } |
1739
|
369 }; |
|
370 |
|
371 // Colon expressions. |
|
372 |
|
373 class |
|
374 tree_colon_expression : public tree_expression |
|
375 { |
2124
|
376 public: |
|
377 |
1739
|
378 tree_colon_expression (int l = -1, int c = -1) |
|
379 : tree_expression (l, c, tree_expression::colon), |
2124
|
380 op_base (0), op_limit (0), op_increment (0) { } |
1739
|
381 |
|
382 tree_colon_expression (tree_expression *a, tree_expression *b, |
|
383 int l = -1, int c = -1) |
|
384 : tree_expression (l, c, tree_expression::colon), |
2124
|
385 op_base (a), op_limit (b), op_increment (0) { } |
1739
|
386 |
|
387 ~tree_colon_expression (void) |
|
388 { |
2124
|
389 delete op_base; |
|
390 delete op_limit; |
|
391 delete op_increment; |
1739
|
392 } |
|
393 |
1827
|
394 bool is_range_constant (void) const; |
1739
|
395 |
|
396 tree_colon_expression *chain (tree_expression *t); |
|
397 |
2086
|
398 octave_value eval (bool print); |
1739
|
399 |
|
400 void eval_error (const char *s); |
|
401 |
2124
|
402 tree_expression *base (void) { return op_base; } |
|
403 tree_expression *limit (void) { return op_limit; } |
|
404 tree_expression *increment (void) { return op_increment; } |
|
405 |
|
406 void accept (tree_walker& tw); |
1739
|
407 |
2124
|
408 private: |
|
409 |
|
410 // The components of the expression. |
|
411 tree_expression *op_base; |
|
412 tree_expression *op_limit; |
|
413 tree_expression *op_increment; |
1739
|
414 }; |
|
415 |
|
416 #endif |
|
417 |
|
418 /* |
|
419 ;;; Local Variables: *** |
|
420 ;;; mode: C++ *** |
|
421 ;;; End: *** |
|
422 */ |