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