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