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