1739
|
1 // tree-expr2.h -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_tree_expr2_h) |
|
25 #define octave_tree_expr2_h 1 |
|
26 |
|
27 #if defined (__GNUG__) |
|
28 #pragma interface |
|
29 #endif |
|
30 |
|
31 class ostream; |
|
32 |
|
33 class tree_identifier; |
|
34 class tree_index_expression; |
|
35 class tree_indirect_ref; |
|
36 class tree_argument_list; |
|
37 |
|
38 #include "pt-exp-base.h" |
|
39 |
|
40 // Prefix expressions. |
|
41 |
|
42 class |
|
43 tree_prefix_expression : public tree_expression |
|
44 { |
|
45 public: |
|
46 tree_prefix_expression (int l = -1, int c = -1) |
|
47 : tree_expression (l, c), id (0) { } |
|
48 |
|
49 tree_prefix_expression (tree_identifier *t, tree_expression::type et, |
|
50 int l = -1, int c = -1) |
|
51 : tree_expression (l, c, et), id (t) { } |
|
52 |
|
53 ~tree_prefix_expression (void); |
|
54 |
|
55 tree_constant eval (int print); |
|
56 |
|
57 void eval_error (void); |
|
58 |
|
59 int is_prefix_expression (void) const |
|
60 { return 1; } |
|
61 |
|
62 char *oper (void) const; |
|
63 |
|
64 void print_code (ostream& os); |
|
65 |
|
66 private: |
|
67 tree_identifier *id; |
|
68 }; |
|
69 |
|
70 // Postfix expressions. |
|
71 |
|
72 class |
|
73 tree_postfix_expression : public tree_expression |
|
74 { |
|
75 public: |
|
76 tree_postfix_expression (int l = -1, int c = -1) |
|
77 : tree_expression (l, c), id (0) { } |
|
78 |
|
79 tree_postfix_expression (tree_identifier *t, tree_expression::type et, |
|
80 int l = -1, int c = -1) |
|
81 : tree_expression (l, c, et), id (t) { } |
|
82 |
|
83 ~tree_postfix_expression (void); |
|
84 |
|
85 tree_constant eval (int print); |
|
86 |
|
87 void eval_error (void); |
|
88 |
|
89 char *oper (void) const; |
|
90 |
|
91 void print_code (ostream& os); |
|
92 |
|
93 private: |
|
94 tree_identifier *id; |
|
95 }; |
|
96 |
|
97 // Unary expressions. |
|
98 |
|
99 class |
|
100 tree_unary_expression : public tree_expression |
|
101 { |
|
102 public: |
|
103 tree_unary_expression (int l = -1, int c = -1) |
|
104 : tree_expression (l, c), op (0) { } |
|
105 |
|
106 tree_unary_expression (tree_expression *a, tree_expression::type t, |
|
107 int l = -1, int c = -1) |
|
108 : tree_expression (l, c, t), op (a) { } |
|
109 |
|
110 ~tree_unary_expression (void) |
|
111 { delete op; } |
|
112 |
|
113 tree_constant eval (int print); |
|
114 |
|
115 void eval_error (void); |
|
116 |
|
117 char *oper (void) const; |
|
118 |
|
119 void print_code (ostream& os); |
|
120 |
|
121 private: |
|
122 tree_expression *op; |
|
123 }; |
|
124 |
|
125 // Binary expressions. |
|
126 |
|
127 class |
|
128 tree_binary_expression : public tree_expression |
|
129 { |
|
130 public: |
|
131 tree_binary_expression (int l = -1, int c = -1) |
|
132 : tree_expression (l, c), op1 (0), op2 (0) { } |
|
133 |
|
134 tree_binary_expression (tree_expression *a, tree_expression *b, |
|
135 tree_expression::type t, int l = -1, int c = -1) |
|
136 : tree_expression (l, c, t), op1 (a), op2 (b) { } |
|
137 |
|
138 ~tree_binary_expression (void) |
|
139 { |
|
140 delete op1; |
|
141 delete op2; |
|
142 } |
|
143 |
|
144 tree_constant eval (int print); |
|
145 |
|
146 void eval_error (void); |
|
147 |
|
148 char *oper (void) const; |
|
149 |
|
150 void print_code (ostream& os); |
|
151 |
|
152 private: |
|
153 tree_expression *op1; |
|
154 tree_expression *op2; |
|
155 }; |
|
156 |
|
157 // Simple assignment expressions. |
|
158 |
|
159 class |
|
160 tree_simple_assignment_expression : public tree_expression |
|
161 { |
|
162 private: |
|
163 void init (int plhs, int ans_assign) |
|
164 { |
|
165 etype = tree_expression::assignment; |
|
166 lhs_idx_expr = 0; |
|
167 lhs = 0; |
|
168 index = 0; |
|
169 rhs = 0; |
|
170 preserve = plhs; |
|
171 ans_ass = ans_assign; |
|
172 } |
|
173 |
|
174 public: |
|
175 tree_simple_assignment_expression (int plhs = 0, int ans_assign = 0, |
|
176 int l = -1, int c = -1) |
|
177 : tree_expression (l, c) |
|
178 { init (plhs, ans_assign); } |
|
179 |
|
180 tree_simple_assignment_expression (tree_identifier *i, |
|
181 tree_expression *r, |
|
182 int plhs = 0, int ans_assign = 0, |
|
183 int l = -1, int c = -1); |
|
184 |
|
185 tree_simple_assignment_expression (tree_indirect_ref *i, |
|
186 tree_expression *r, |
|
187 int plhs = 0, int ans_assign = 0, |
|
188 int l = -1, int c = -1) |
|
189 : tree_expression (l, c) |
|
190 { |
|
191 init (plhs, ans_assign); |
|
192 lhs = i; |
|
193 rhs = r; |
|
194 } |
|
195 |
|
196 tree_simple_assignment_expression (tree_index_expression *idx_expr, |
|
197 tree_expression *r, |
|
198 int plhs = 0, int ans_assign = 0, |
|
199 int l = -1, int c = -1); |
|
200 |
|
201 ~tree_simple_assignment_expression (void); |
|
202 |
|
203 int left_hand_side_is_identifier_only (void); |
|
204 |
|
205 tree_identifier *left_hand_side_id (void); |
|
206 |
|
207 int is_ans_assign (void) |
|
208 { return ans_ass; } |
|
209 |
|
210 tree_constant eval (int print); |
|
211 |
|
212 int is_assignment_expression (void) const |
|
213 { return 1; } |
|
214 |
|
215 void eval_error (void); |
|
216 |
|
217 void print_code (ostream& os); |
|
218 |
|
219 private: |
|
220 tree_index_expression *lhs_idx_expr; |
|
221 tree_indirect_ref *lhs; |
|
222 tree_argument_list *index; |
|
223 tree_expression *rhs; |
|
224 int preserve; |
|
225 int ans_ass; |
|
226 }; |
|
227 |
|
228 // Colon expressions. |
|
229 |
|
230 class |
|
231 tree_colon_expression : public tree_expression |
|
232 { |
|
233 public: |
|
234 tree_colon_expression (int l = -1, int c = -1) |
|
235 : tree_expression (l, c, tree_expression::colon), |
|
236 op1(0), op2 (0), op3 (0) { } |
|
237 |
|
238 tree_colon_expression (tree_expression *a, tree_expression *b, |
|
239 int l = -1, int c = -1) |
|
240 : tree_expression (l, c, tree_expression::colon), |
|
241 op1 (a), op2 (b), op3 (0) { } |
|
242 |
|
243 ~tree_colon_expression (void) |
|
244 { |
|
245 delete op1; |
|
246 delete op2; |
|
247 delete op3; |
|
248 } |
|
249 |
|
250 int is_range_constant (void) const; |
|
251 |
|
252 tree_colon_expression *chain (tree_expression *t); |
|
253 |
|
254 tree_constant eval (int print); |
|
255 |
|
256 void eval_error (const char *s); |
|
257 |
|
258 void print_code (ostream& os); |
|
259 |
|
260 private: |
|
261 tree_expression *op1; |
|
262 tree_expression *op2; |
|
263 tree_expression *op3; |
|
264 }; |
|
265 |
|
266 #endif |
|
267 |
|
268 /* |
|
269 ;;; Local Variables: *** |
|
270 ;;; mode: C++ *** |
|
271 ;;; page-delimiter: "^/\\*" *** |
|
272 ;;; End: *** |
|
273 */ |