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; |
2971
|
36 class tree_assignment_lhs; |
1739
|
37 |
2124
|
38 class tree_walker; |
|
39 |
2879
|
40 class octave_value; |
|
41 class octave_value_list; |
|
42 class octave_variable_reference; |
|
43 |
2971
|
44 #include "oct-obj.h" |
1739
|
45 #include "pt-exp-base.h" |
|
46 |
2960
|
47 // Unary expressions. |
|
48 |
|
49 class |
|
50 tree_unary_expression : public tree_expression |
|
51 { |
|
52 public: |
|
53 |
|
54 tree_unary_expression (int l = -1, int c = -1) |
|
55 : tree_expression (l, c), op (0) { } |
|
56 |
|
57 tree_unary_expression (tree_expression *e, int l = -1, int c = -1) |
|
58 : tree_expression (l, c), op (e) { } |
|
59 |
|
60 ~tree_unary_expression (void) { delete op; } |
|
61 |
|
62 tree_expression *operand (void) { return op; } |
|
63 |
|
64 protected: |
|
65 |
|
66 // The operand for the expression. |
|
67 tree_expression *op; |
|
68 }; |
|
69 |
1739
|
70 // Prefix expressions. |
|
71 |
|
72 class |
2960
|
73 tree_prefix_expression : public tree_unary_expression |
1739
|
74 { |
2124
|
75 public: |
|
76 |
2388
|
77 enum type |
|
78 { |
|
79 unknown, |
2960
|
80 unot, |
|
81 uminus, |
2388
|
82 increment, |
|
83 decrement |
|
84 }; |
1739
|
85 |
2960
|
86 tree_prefix_expression (int l = -1, int c = -1) |
|
87 : tree_unary_expression (l, c), etype (unknown) { } |
2388
|
88 |
2960
|
89 tree_prefix_expression (type t = unknown, tree_expression *e, |
|
90 int l = -1, int c = -1) |
|
91 : tree_unary_expression (e, l, c), etype (t) { } |
1739
|
92 |
2960
|
93 ~tree_prefix_expression (void) { } |
1739
|
94 |
2971
|
95 bool rvalue_ok (void) const |
|
96 { return true; } |
|
97 |
|
98 octave_value rvalue (void); |
|
99 |
|
100 octave_value_list rvalue (int nargou); |
1739
|
101 |
|
102 void eval_error (void); |
|
103 |
2900
|
104 string oper (void) const; |
1739
|
105 |
2124
|
106 void accept (tree_walker& tw); |
1739
|
107 |
2124
|
108 private: |
|
109 |
2388
|
110 // The type of the expression. |
|
111 type etype; |
1739
|
112 }; |
|
113 |
|
114 // Postfix expressions. |
|
115 |
|
116 class |
2960
|
117 tree_postfix_expression : public tree_unary_expression |
1739
|
118 { |
2124
|
119 public: |
|
120 |
2388
|
121 enum type |
|
122 { |
|
123 unknown, |
2960
|
124 hermitian, |
|
125 transpose, |
2388
|
126 increment, |
|
127 decrement |
|
128 }; |
1739
|
129 |
2960
|
130 tree_postfix_expression (int l = -1, int c = -1) |
|
131 : tree_unary_expression (l, c), etype (unknown) { } |
2388
|
132 |
2960
|
133 tree_postfix_expression (type t = unknown, tree_expression *e, |
|
134 int l = -1, int c = -1) |
|
135 : tree_unary_expression (e, l, c), etype (t) { } |
1739
|
136 |
2960
|
137 ~tree_postfix_expression (void) { } |
1739
|
138 |
2971
|
139 bool rvalue_ok (void) const |
|
140 { return true; } |
|
141 |
|
142 octave_value rvalue (void); |
|
143 |
|
144 octave_value_list rvalue (int nargout); |
1739
|
145 |
|
146 void eval_error (void); |
|
147 |
2900
|
148 string oper (void) const; |
1739
|
149 |
2124
|
150 void accept (tree_walker& tw); |
1739
|
151 |
2124
|
152 private: |
|
153 |
2388
|
154 // The type of the expression. |
|
155 type etype; |
1739
|
156 }; |
|
157 |
|
158 // Binary expressions. |
|
159 |
|
160 class |
|
161 tree_binary_expression : public tree_expression |
|
162 { |
2124
|
163 public: |
|
164 |
2879
|
165 tree_binary_expression (int l = -1, int c = -1, |
|
166 octave_value::binary_op t |
|
167 = octave_value::unknown_binary_op) |
2388
|
168 : tree_expression (l, c), op_lhs (0), op_rhs (0), etype (t) { } |
1739
|
169 |
|
170 tree_binary_expression (tree_expression *a, tree_expression *b, |
2879
|
171 int l = -1, int c = -1, |
|
172 octave_value::binary_op t |
|
173 = octave_value::unknown_binary_op) |
2388
|
174 : tree_expression (l, c), op_lhs (a), op_rhs (b), etype (t) { } |
1739
|
175 |
|
176 ~tree_binary_expression (void) |
|
177 { |
2124
|
178 delete op_lhs; |
|
179 delete op_rhs; |
1739
|
180 } |
|
181 |
2971
|
182 bool rvalue_ok (void) const |
|
183 { return true; } |
|
184 |
|
185 octave_value rvalue (void); |
|
186 |
|
187 octave_value_list rvalue (int nargou); |
1739
|
188 |
|
189 void eval_error (void); |
|
190 |
2900
|
191 string oper (void) const; |
1739
|
192 |
2124
|
193 tree_expression *lhs (void) { return op_lhs; } |
|
194 tree_expression *rhs (void) { return op_rhs; } |
|
195 |
|
196 void accept (tree_walker& tw); |
1739
|
197 |
2388
|
198 protected: |
2124
|
199 |
|
200 // The operands for the expression. |
|
201 tree_expression *op_lhs; |
|
202 tree_expression *op_rhs; |
2388
|
203 |
|
204 private: |
|
205 |
|
206 // The type of the expression. |
2879
|
207 octave_value::binary_op etype; |
2388
|
208 }; |
|
209 |
|
210 // Boolean expressions. |
|
211 |
|
212 class |
|
213 tree_boolean_expression : public tree_binary_expression |
|
214 { |
|
215 public: |
|
216 |
|
217 enum type |
|
218 { |
|
219 unknown, |
2805
|
220 bool_and, |
|
221 bool_or |
2388
|
222 }; |
|
223 |
2879
|
224 tree_boolean_expression (int l = -1, int c = -1, type t = unknown) |
2388
|
225 : tree_binary_expression (l, c), etype (t) { } |
|
226 |
|
227 tree_boolean_expression (tree_expression *a, tree_expression *b, |
|
228 int l = -1, int c = -1, type t = unknown) |
|
229 : tree_binary_expression (a, b, l, c), etype (t) { } |
|
230 |
|
231 ~tree_boolean_expression (void) { } |
|
232 |
2971
|
233 bool rvalue_ok (void) const |
|
234 { return true; } |
|
235 |
|
236 octave_value rvalue (void); |
|
237 |
|
238 octave_value_list rvalue (int nargout); |
2388
|
239 |
2900
|
240 string oper (void) const; |
2388
|
241 |
|
242 private: |
|
243 |
|
244 // The type of the expression. |
|
245 type etype; |
1739
|
246 }; |
|
247 |
|
248 // Simple assignment expressions. |
|
249 |
|
250 class |
2971
|
251 tree_simple_assignment : public tree_expression |
1739
|
252 { |
2124
|
253 public: |
1739
|
254 |
2971
|
255 tree_simple_assignment (bool plhs = false, int l = -1, int c = -1, |
|
256 octave_value::assign_op t = octave_value::asn_eq) |
|
257 : tree_expression (l, c), lhs (0), rhs (0), preserve (plhs), etype (t) { } |
1739
|
258 |
2971
|
259 tree_simple_assignment (tree_expression *le, tree_expression *re, |
|
260 bool plhs = false, int l = -1, int c = -1, |
|
261 octave_value::assign_op t = octave_value::asn_eq) |
|
262 : tree_expression (l, c), lhs (le), rhs (re), preserve (plhs), |
|
263 etype (t) { } |
1739
|
264 |
2971
|
265 ~tree_simple_assignment (void); |
1739
|
266 |
2971
|
267 bool rvalue_ok (void) const |
|
268 { return true; } |
1739
|
269 |
2971
|
270 octave_value rvalue (void); |
1739
|
271 |
2971
|
272 octave_value_list rvalue (int nargout); |
1739
|
273 |
1827
|
274 bool is_assignment_expression (void) const |
|
275 { return true; } |
1739
|
276 |
|
277 void eval_error (void); |
|
278 |
2900
|
279 string oper (void) const; |
2879
|
280 |
2971
|
281 tree_expression *left_hand_side (void) { return lhs; } |
2124
|
282 |
|
283 tree_expression *right_hand_side (void) { return rhs; } |
|
284 |
|
285 void accept (tree_walker& tw); |
1739
|
286 |
2124
|
287 private: |
|
288 |
2879
|
289 void do_assign (octave_variable_reference& ult, |
|
290 const octave_value_list& args, |
|
291 const octave_value& rhs_val); |
|
292 |
|
293 void do_assign (octave_variable_reference& ult, |
|
294 const octave_value& rhs_val); |
|
295 |
2971
|
296 // The left hand side of the assignment. |
|
297 tree_expression *lhs; |
2124
|
298 |
|
299 // The right hand side of the assignment. |
1739
|
300 tree_expression *rhs; |
2124
|
301 |
|
302 // True if we should not delete the lhs. |
1827
|
303 bool preserve; |
2124
|
304 |
|
305 // True if this is an assignment to the built-in variable ans. |
1827
|
306 bool ans_ass; |
2124
|
307 |
2879
|
308 // The type of the expression. |
|
309 octave_value::assign_op etype; |
1739
|
310 }; |
|
311 |
|
312 // Colon expressions. |
|
313 |
|
314 class |
|
315 tree_colon_expression : public tree_expression |
|
316 { |
2124
|
317 public: |
|
318 |
1739
|
319 tree_colon_expression (int l = -1, int c = -1) |
2960
|
320 : tree_expression (l, c), op_base (0), op_limit (0), op_increment (0) { } |
1739
|
321 |
2971
|
322 tree_colon_expression (tree_expression *e, int l = -1, int c = -1) |
|
323 : tree_expression (l, c), op_base (e), op_limit (0), op_increment (0) { } |
1739
|
324 |
|
325 ~tree_colon_expression (void) |
|
326 { |
2124
|
327 delete op_base; |
|
328 delete op_limit; |
|
329 delete op_increment; |
1739
|
330 } |
|
331 |
2971
|
332 tree_colon_expression *append (tree_expression *t); |
|
333 |
|
334 bool rvalue_ok (void) const |
|
335 { return true; } |
1739
|
336 |
2971
|
337 octave_value rvalue (void); |
1739
|
338 |
2971
|
339 octave_value_list rvalue (int nargout); |
|
340 |
|
341 void eval_error (const string& s = string ()); |
1739
|
342 |
2124
|
343 tree_expression *base (void) { return op_base; } |
|
344 tree_expression *limit (void) { return op_limit; } |
|
345 tree_expression *increment (void) { return op_increment; } |
|
346 |
|
347 void accept (tree_walker& tw); |
1739
|
348 |
2124
|
349 private: |
|
350 |
|
351 // The components of the expression. |
|
352 tree_expression *op_base; |
|
353 tree_expression *op_limit; |
|
354 tree_expression *op_increment; |
1739
|
355 }; |
|
356 |
2971
|
357 // Index expressions. |
|
358 |
|
359 class |
|
360 tree_index_expression : public tree_expression |
|
361 { |
|
362 public: |
|
363 |
|
364 tree_index_expression (tree_expression *e = 0, tree_argument_list *lst = 0, |
|
365 int l = -1, int c = -1) |
|
366 : tree_expression (l, c), expr (e), list (lst), arg_nm () { } |
|
367 |
|
368 ~tree_index_expression (void); |
|
369 |
|
370 bool is_index_expression (void) const |
|
371 { return true; } |
|
372 |
|
373 tree_expression *expression (void) |
|
374 { return expr; } |
|
375 |
|
376 tree_argument_list *arg_list (void) |
|
377 { return list; } |
|
378 |
|
379 bool rvalue_ok (void) const |
|
380 { return true; } |
|
381 |
|
382 octave_value rvalue (void); |
|
383 |
|
384 octave_value_list rvalue (int nargout); |
|
385 |
|
386 octave_variable_reference lvalue (void); |
|
387 |
|
388 void eval_error (void); |
|
389 |
|
390 void accept (tree_walker& tw); |
|
391 |
|
392 private: |
|
393 |
|
394 tree_expression *expr; |
|
395 |
|
396 tree_argument_list *list; |
|
397 |
|
398 string_vector arg_nm; |
|
399 }; |
|
400 |
|
401 // Multi-valued assignment expressions. |
|
402 |
|
403 class |
|
404 tree_multi_assignment : public tree_expression |
|
405 { |
|
406 public: |
|
407 |
|
408 tree_multi_assignment (bool plhs = false, int l = -1, int c = -1) |
|
409 : tree_expression (l, c), preserve (plhs), lhs (0), rhs (0) { } |
|
410 |
|
411 tree_multi_assignment (tree_argument_list *lst, tree_expression *r, |
|
412 bool plhs = false, int l = -1, int c = -1) |
|
413 : tree_expression (l, c), preserve (plhs), lhs (lst), rhs (r) { } |
|
414 |
|
415 ~tree_multi_assignment (void); |
|
416 |
|
417 bool is_assignment_expression (void) const |
|
418 { return true; } |
|
419 |
|
420 bool rvalue_ok (void) const |
|
421 { return true; } |
|
422 |
|
423 octave_value rvalue (void); |
|
424 |
|
425 octave_value_list rvalue (int nargout); |
|
426 |
|
427 void eval_error (void); |
|
428 |
|
429 tree_argument_list *left_hand_side (void) { return lhs; } |
|
430 |
|
431 tree_expression *right_hand_side (void) { return rhs; } |
|
432 |
|
433 void accept (tree_walker& tw); |
|
434 |
|
435 private: |
|
436 |
|
437 bool preserve; |
|
438 tree_argument_list *lhs; |
|
439 tree_expression *rhs; |
|
440 }; |
|
441 |
1739
|
442 #endif |
|
443 |
|
444 /* |
|
445 ;;; Local Variables: *** |
|
446 ;;; mode: C++ *** |
|
447 ;;; End: *** |
|
448 */ |