529
|
1 // tc-rep.h -*- C++ -*- |
492
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993, 1994 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, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_tree_const_rep_h) |
|
25 #define octave_tree_const_rep_h 1 |
|
26 |
|
27 #if defined (__GNUG__) |
|
28 #pragma interface |
|
29 #endif |
|
30 |
|
31 #include <stdlib.h> |
|
32 |
|
33 #include "tree-base.h" |
|
34 |
|
35 #include "mx-base.h" |
|
36 #include "Range.h" |
|
37 |
|
38 class idx_vector; |
|
39 |
529
|
40 struct Mapper_fcn; |
|
41 |
581
|
42 // Forward class declarations. |
|
43 |
492
|
44 class tree; |
|
45 class tree_constant; |
|
46 |
581
|
47 // The actual representation of the tree_constant. |
|
48 |
492
|
49 class |
|
50 tree_constant_rep |
|
51 { |
|
52 friend class tree_constant; |
|
53 |
|
54 public: |
|
55 enum constant_type |
|
56 { |
|
57 unknown_constant, |
|
58 scalar_constant, |
|
59 matrix_constant, |
|
60 complex_scalar_constant, |
|
61 complex_matrix_constant, |
|
62 string_constant, |
|
63 range_constant, |
|
64 magic_colon, |
|
65 }; |
|
66 |
581
|
67 enum force_orient |
|
68 { |
|
69 no_orient, |
|
70 row_orient, |
|
71 column_orient, |
|
72 }; |
|
73 |
|
74 private: |
492
|
75 tree_constant_rep (void); |
|
76 |
|
77 tree_constant_rep (double d); |
|
78 tree_constant_rep (const Matrix& m); |
|
79 tree_constant_rep (const DiagMatrix& d); |
|
80 tree_constant_rep (const RowVector& v, int pcv); |
|
81 tree_constant_rep (const ColumnVector& v, int pcv); |
|
82 |
|
83 tree_constant_rep (const Complex& c); |
|
84 tree_constant_rep (const ComplexMatrix& m); |
|
85 tree_constant_rep (const ComplexDiagMatrix& d); |
|
86 tree_constant_rep (const ComplexRowVector& v, int pcv); |
|
87 tree_constant_rep (const ComplexColumnVector& v, int pcv); |
|
88 |
|
89 tree_constant_rep (const char *s); |
|
90 |
|
91 tree_constant_rep (double base, double limit, double inc); |
|
92 tree_constant_rep (const Range& r); |
|
93 |
|
94 tree_constant_rep (tree_constant_rep::constant_type t); |
|
95 |
|
96 tree_constant_rep (const tree_constant_rep& t); |
|
97 |
|
98 ~tree_constant_rep (void); |
|
99 |
|
100 #if defined (MDEBUG) |
|
101 void *operator new (size_t size); |
|
102 void operator delete (void *p, size_t size); |
|
103 #endif |
|
104 |
|
105 void resize (int i, int j); |
|
106 void resize (int i, int j, double val); |
|
107 |
|
108 void maybe_resize (int imax, force_orient fo = no_orient); |
|
109 void maybe_resize (int imax, int jmax); |
|
110 |
|
111 int valid_as_scalar_index (void) const; |
|
112 |
605
|
113 // What type of constant am I? |
|
114 |
|
115 int is_unknown (void) const |
|
116 { return type_tag == tree_constant_rep::unknown_constant; } |
|
117 |
|
118 int is_scalar (void) const |
|
119 { return type_tag == tree_constant_rep::scalar_constant; } |
|
120 |
|
121 int is_matrix (void) const |
|
122 { return type_tag == tree_constant_rep::matrix_constant; } |
|
123 |
|
124 int is_complex_scalar (void) const |
|
125 { return type_tag == tree_constant_rep::complex_scalar_constant; } |
|
126 |
|
127 int is_complex_matrix (void) const |
|
128 { return type_tag == tree_constant_rep::complex_matrix_constant; } |
|
129 |
|
130 int is_string (void) const |
|
131 { return type_tag == tree_constant_rep::string_constant; } |
|
132 |
|
133 int is_range (void) const |
|
134 { return type_tag == tree_constant_rep::range_constant; } |
|
135 |
|
136 // Others tests, some more general, some just old names for the things |
|
137 // above. |
|
138 |
492
|
139 int is_defined (void) const |
|
140 { return type_tag != tree_constant_rep::unknown_constant; } |
|
141 |
|
142 int is_undefined (void) const |
|
143 { return type_tag == tree_constant_rep::unknown_constant; } |
|
144 |
|
145 int is_string_type (void) const |
|
146 { return type_tag == tree_constant_rep::string_constant; } |
|
147 |
|
148 int is_scalar_type (void) const |
|
149 { return type_tag == scalar_constant |
|
150 || type_tag == complex_scalar_constant; } |
|
151 |
|
152 int is_matrix_type (void) const |
|
153 { return type_tag == matrix_constant |
|
154 || type_tag == complex_matrix_constant; } |
|
155 |
|
156 int is_real_type (void) const |
|
157 { return type_tag == scalar_constant |
|
158 || type_tag == matrix_constant |
|
159 || type_tag == range_constant; } |
|
160 |
|
161 int is_complex_type (void) const |
|
162 { return type_tag == complex_matrix_constant |
|
163 || type_tag == complex_scalar_constant; } |
|
164 |
|
165 |
|
166 int is_numeric_type (void) const |
|
167 { return type_tag == scalar_constant |
|
168 || type_tag == matrix_constant |
|
169 || type_tag == complex_matrix_constant |
|
170 || type_tag == complex_scalar_constant; } |
|
171 |
|
172 int is_numeric_or_range_type (void) const |
|
173 { return type_tag == scalar_constant |
|
174 || type_tag == matrix_constant |
|
175 || type_tag == complex_matrix_constant |
|
176 || type_tag == complex_scalar_constant |
|
177 || type_tag == range_constant; } |
|
178 |
|
179 double to_scalar (void) const; |
|
180 ColumnVector to_vector (void) const; |
|
181 Matrix to_matrix (void) const; |
|
182 |
581
|
183 void stash_original_text (char *s); |
|
184 |
492
|
185 tree_constant_rep::constant_type force_numeric (int force_str_conv = 0); |
|
186 tree_constant make_numeric (int force_str_conv = 0) const; |
|
187 |
529
|
188 void assign (const tree_constant& rhs, const Octave_object& args); |
492
|
189 |
529
|
190 void do_scalar_assignment (const tree_constant& rhs, |
|
191 const Octave_object& args); |
492
|
192 |
529
|
193 void do_matrix_assignment (const tree_constant& rhs, |
|
194 const Octave_object& args); |
492
|
195 |
529
|
196 void do_matrix_assignment (const tree_constant& rhs, |
|
197 const tree_constant& i_arg); |
492
|
198 |
529
|
199 void do_matrix_assignment (const tree_constant& rhs, |
|
200 const tree_constant& i_arg, |
|
201 const tree_constant& j_arg); |
492
|
202 |
529
|
203 void fortran_style_matrix_assignment (const tree_constant& rhs, |
|
204 const tree_constant& i_arg); |
492
|
205 |
529
|
206 void fortran_style_matrix_assignment (const tree_constant& rhs, |
|
207 constant_type ci); |
492
|
208 |
529
|
209 void fortran_style_matrix_assignment (const tree_constant& rhs, |
|
210 idx_vector& i); |
492
|
211 |
529
|
212 void vector_assignment (const tree_constant& rhs, |
|
213 const tree_constant& i_arg); |
492
|
214 |
|
215 void check_vector_assign (int rhs_nr, int rhs_nc, int ilen, |
|
216 const char *rm); |
|
217 |
529
|
218 void do_vector_assign (const tree_constant& rhs, int i); |
|
219 void do_vector_assign (const tree_constant& rhs, idx_vector& i); |
|
220 void do_vector_assign (const tree_constant& rhs, Range& i); |
|
221 |
|
222 void do_matrix_assignment (const tree_constant& rhs, int i, |
|
223 const tree_constant& j_arg); |
|
224 void do_matrix_assignment (const tree_constant& rhs, idx_vector& i, |
|
225 const tree_constant& j_arg); |
|
226 void do_matrix_assignment (const tree_constant& rhs, Range& i, |
|
227 const tree_constant& j_arg); |
|
228 void do_matrix_assignment (const tree_constant& rhs, constant_type i, |
|
229 const tree_constant& j_arg); |
492
|
230 |
529
|
231 void do_matrix_assignment (const tree_constant& rhs, int i, int j); |
|
232 void do_matrix_assignment (const tree_constant& rhs, int i, idx_vector& jv); |
|
233 void do_matrix_assignment (const tree_constant& rhs, int i, Range& j); |
|
234 void do_matrix_assignment (const tree_constant& rhs, int i, constant_type cj); |
492
|
235 |
529
|
236 void do_matrix_assignment (const tree_constant& rhs, idx_vector& iv, |
|
237 int j); |
|
238 void do_matrix_assignment (const tree_constant& rhs, idx_vector& iv, |
492
|
239 idx_vector& jv); |
529
|
240 void do_matrix_assignment (const tree_constant& rhs, idx_vector& iv, |
|
241 Range& j); |
|
242 void do_matrix_assignment (const tree_constant& rhs, idx_vector& iv, |
492
|
243 constant_type j); |
|
244 |
529
|
245 void do_matrix_assignment (const tree_constant& rhs, Range& i, int j); |
|
246 void do_matrix_assignment (const tree_constant& rhs, Range& i, |
|
247 idx_vector& jv); |
|
248 void do_matrix_assignment (const tree_constant& rhs, Range& i, |
|
249 Range& j); |
|
250 void do_matrix_assignment (const tree_constant& rhs, Range& i, |
|
251 constant_type j); |
492
|
252 |
529
|
253 void do_matrix_assignment (const tree_constant& rhs, constant_type i, int j); |
|
254 void do_matrix_assignment (const tree_constant& rhs, constant_type i, |
492
|
255 idx_vector& jv); |
529
|
256 void do_matrix_assignment (const tree_constant& rhs, constant_type i, |
|
257 Range& j); |
|
258 void do_matrix_assignment (const tree_constant& rhs, |
|
259 const constant_type i, |
492
|
260 constant_type j); |
|
261 |
|
262 void delete_row (int); |
|
263 void delete_rows (idx_vector& i); |
|
264 void delete_rows (Range& i); |
|
265 |
|
266 void delete_column (int); |
|
267 void delete_columns (idx_vector& j); |
|
268 void delete_columns (Range& j); |
|
269 |
578
|
270 void bump_value (tree_expression::type); |
492
|
271 |
|
272 void maybe_mutate (void); |
|
273 void print (void); |
|
274 |
581
|
275 void print_code (ostream& os); |
|
276 |
506
|
277 tree_constant do_index (const Octave_object& args); |
492
|
278 |
506
|
279 tree_constant do_scalar_index (const Octave_object& args) const; |
492
|
280 |
506
|
281 tree_constant do_matrix_index (const Octave_object& args) const; |
492
|
282 |
|
283 tree_constant do_matrix_index (const tree_constant& i_arg) const; |
|
284 |
|
285 tree_constant do_matrix_index (const tree_constant& i_arg, |
|
286 const tree_constant& j_arg) const; |
|
287 |
|
288 tree_constant do_matrix_index (constant_type i) const; |
|
289 |
|
290 tree_constant fortran_style_matrix_index (const tree_constant& i_arg) const; |
|
291 tree_constant fortran_style_matrix_index (const Matrix& mi) const; |
|
292 |
|
293 tree_constant do_vector_index (const tree_constant& i_arg) const; |
|
294 |
|
295 tree_constant do_matrix_index (int i, const tree_constant& i_arg) const; |
|
296 tree_constant do_matrix_index (const idx_vector& i, |
|
297 const tree_constant& i_arg) const; |
|
298 tree_constant do_matrix_index (const Range& i, |
|
299 const tree_constant& i_arg) const; |
|
300 tree_constant do_matrix_index (constant_type i, |
|
301 const tree_constant& i_arg) const; |
|
302 |
|
303 tree_constant do_matrix_index (int i, int j) const; |
|
304 tree_constant do_matrix_index (int i, const idx_vector& j) const; |
|
305 tree_constant do_matrix_index (int i, const Range& j) const; |
|
306 tree_constant do_matrix_index (int i, constant_type cj) const; |
|
307 |
|
308 tree_constant do_matrix_index (const idx_vector& i, int j) const; |
|
309 tree_constant do_matrix_index (const idx_vector& i, |
|
310 const idx_vector& j) const; |
|
311 tree_constant do_matrix_index (const idx_vector& i, const Range& j) const; |
|
312 tree_constant do_matrix_index (const idx_vector& i, constant_type j) const; |
|
313 |
|
314 tree_constant do_matrix_index (const Range& i, int j) const; |
|
315 tree_constant do_matrix_index (const Range& i, const idx_vector& j) const; |
|
316 tree_constant do_matrix_index (const Range& i, const Range& j) const; |
|
317 tree_constant do_matrix_index (const Range& i, constant_type j) const; |
|
318 |
|
319 tree_constant do_matrix_index (constant_type i, int j) const; |
|
320 tree_constant do_matrix_index (constant_type i, const idx_vector& j) const; |
|
321 tree_constant do_matrix_index (constant_type i, const Range& j) const; |
|
322 tree_constant do_matrix_index (constant_type i, constant_type j) const; |
|
323 |
|
324 double double_value (void) const; |
|
325 Matrix matrix_value (void) const; |
|
326 Complex complex_value (void) const; |
|
327 ComplexMatrix complex_matrix_value (void) const; |
|
328 char *string_value (void) const; |
|
329 Range range_value (void) const; |
|
330 |
|
331 int rows (void) const; |
|
332 int columns (void) const; |
|
333 |
|
334 tree_constant all (void) const; |
|
335 tree_constant any (void) const; |
|
336 tree_constant isstr (void) const; |
|
337 |
|
338 tree_constant convert_to_str (void); |
|
339 |
|
340 void convert_to_row_or_column_vector (void); |
|
341 |
|
342 int is_true (void) const; |
|
343 |
|
344 tree_constant cumprod (void) const; |
|
345 tree_constant cumsum (void) const; |
|
346 tree_constant prod (void) const; |
|
347 tree_constant sum (void) const; |
|
348 tree_constant sumsq (void) const; |
|
349 |
|
350 tree_constant diag (void) const; |
|
351 tree_constant diag (const tree_constant& a) const; |
|
352 |
|
353 constant_type const_type (void) const { return type_tag; } |
|
354 |
|
355 tree_constant mapper (Mapper_fcn& m_fcn, int print) const; |
|
356 |
|
357 int count; |
|
358 constant_type type_tag; |
|
359 union |
|
360 { |
|
361 double scalar; // A real scalar constant. |
|
362 Matrix *matrix; // A real matrix constant. |
|
363 Complex *complex_scalar; // A real scalar constant. |
|
364 ComplexMatrix *complex_matrix; // A real matrix constant. |
|
365 char *string; // A character string constant. |
|
366 Range *range; // A set of evenly spaced values. |
|
367 }; |
581
|
368 char *orig_text; |
492
|
369 }; |
|
370 |
|
371 extern tree_constant do_binary_op (tree_constant& a, tree_constant& b, |
578
|
372 tree_expression::type t); |
492
|
373 |
|
374 extern tree_constant do_unary_op (tree_constant& a, |
578
|
375 tree_expression::type t); |
492
|
376 |
|
377 #endif |
|
378 |
|
379 /* |
|
380 ;;; Local Variables: *** |
|
381 ;;; mode: C++ *** |
|
382 ;;; page-delimiter: "^/\\*" *** |
|
383 ;;; End: *** |
|
384 */ |