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_real_type (void) const |
628
|
122 { |
|
123 return (type_tag == scalar_constant |
|
124 || type_tag == matrix_constant |
|
125 || type_tag == range_constant |
|
126 || type_tag == string_constant); |
|
127 } |
492
|
128 |
|
129 int is_complex_type (void) const |
628
|
130 { |
|
131 return (type_tag == complex_matrix_constant |
|
132 || type_tag == complex_scalar_constant); |
|
133 } |
492
|
134 |
636
|
135 // Would be nice to get rid of the next four functions: |
|
136 |
|
137 int is_scalar_type (void) const |
|
138 { |
|
139 return (type_tag == scalar_constant |
|
140 || type_tag == complex_scalar_constant); |
|
141 } |
|
142 |
|
143 int is_matrix_type (void) const |
|
144 { |
|
145 return (type_tag == matrix_constant |
|
146 || type_tag == complex_matrix_constant); |
|
147 } |
|
148 |
492
|
149 int is_numeric_type (void) const |
628
|
150 { |
|
151 return (type_tag == scalar_constant |
|
152 || type_tag == matrix_constant |
|
153 || type_tag == complex_matrix_constant |
|
154 || type_tag == complex_scalar_constant); |
|
155 } |
492
|
156 |
|
157 int is_numeric_or_range_type (void) const |
628
|
158 { |
|
159 return (type_tag == scalar_constant |
|
160 || type_tag == matrix_constant |
|
161 || type_tag == complex_matrix_constant |
|
162 || type_tag == complex_scalar_constant |
|
163 || type_tag == range_constant); |
|
164 } |
492
|
165 |
620
|
166 int valid_as_scalar_index (void) const; |
|
167 |
|
168 int is_true (void) const; |
|
169 |
628
|
170 double double_value (int force_string_conversion = 0) const; |
|
171 Matrix matrix_value (int force_string_conversion = 0) const; |
|
172 Complex complex_value (int force_string_conversion = 0) const; |
|
173 ComplexMatrix complex_matrix_value (int force_string_conversion = 0) const; |
620
|
174 char *string_value (void) const; |
|
175 Range range_value (void) const; |
|
176 |
628
|
177 ColumnVector vector_value (int force_string_conversion = 0, |
|
178 int force_vector_conversion = 0) const; |
|
179 |
|
180 ComplexColumnVector complex_vector_value (int force_string_conv = 0, |
|
181 int force_vec_conv = 0) const; |
|
182 |
620
|
183 tree_constant convert_to_str (void); |
|
184 |
|
185 void convert_to_row_or_column_vector (void); |
|
186 |
|
187 void force_numeric (int force_str_conv = 0); |
|
188 tree_constant make_numeric (int force_str_conv = 0) const; |
|
189 |
|
190 void bump_value (tree_expression::type); |
|
191 |
|
192 void resize (int i, int j); |
|
193 void resize (int i, int j, double val); |
|
194 |
|
195 void maybe_resize (int imax, force_orient fo = no_orient); |
|
196 void maybe_resize (int imax, int jmax); |
492
|
197 |
581
|
198 void stash_original_text (char *s); |
|
199 |
620
|
200 // Indexing. |
|
201 |
|
202 tree_constant do_index (const Octave_object& args); |
|
203 |
|
204 tree_constant do_scalar_index (const Octave_object& args) const; |
|
205 |
|
206 tree_constant do_matrix_index (const Octave_object& args) const; |
|
207 |
|
208 tree_constant do_matrix_index (const tree_constant& i_arg) const; |
|
209 |
|
210 tree_constant do_matrix_index (const tree_constant& i_arg, |
|
211 const tree_constant& j_arg) const; |
|
212 |
|
213 tree_constant do_matrix_index (constant_type i) const; |
|
214 |
|
215 tree_constant fortran_style_matrix_index (const tree_constant& i_arg) const; |
|
216 tree_constant fortran_style_matrix_index (const Matrix& mi) const; |
|
217 |
|
218 tree_constant do_vector_index (const tree_constant& i_arg) const; |
|
219 |
|
220 tree_constant do_matrix_index (int i, const tree_constant& i_arg) const; |
|
221 tree_constant do_matrix_index (const idx_vector& i, |
|
222 const tree_constant& i_arg) const; |
|
223 tree_constant do_matrix_index (const Range& i, |
|
224 const tree_constant& i_arg) const; |
|
225 tree_constant do_matrix_index (constant_type i, |
|
226 const tree_constant& i_arg) const; |
|
227 |
|
228 tree_constant do_matrix_index (int i, int j) const; |
|
229 tree_constant do_matrix_index (int i, const idx_vector& j) const; |
|
230 tree_constant do_matrix_index (int i, const Range& j) const; |
|
231 tree_constant do_matrix_index (int i, constant_type cj) const; |
|
232 |
|
233 tree_constant do_matrix_index (const idx_vector& i, int j) const; |
|
234 tree_constant do_matrix_index (const idx_vector& i, |
|
235 const idx_vector& j) const; |
|
236 tree_constant do_matrix_index (const idx_vector& i, const Range& j) const; |
|
237 tree_constant do_matrix_index (const idx_vector& i, constant_type j) const; |
|
238 |
|
239 tree_constant do_matrix_index (const Range& i, int j) const; |
|
240 tree_constant do_matrix_index (const Range& i, const idx_vector& j) const; |
|
241 tree_constant do_matrix_index (const Range& i, const Range& j) const; |
|
242 tree_constant do_matrix_index (const Range& i, constant_type j) const; |
|
243 |
|
244 tree_constant do_matrix_index (constant_type i, int j) const; |
|
245 tree_constant do_matrix_index (constant_type i, const idx_vector& j) const; |
|
246 tree_constant do_matrix_index (constant_type i, const Range& j) const; |
|
247 tree_constant do_matrix_index (constant_type i, constant_type j) const; |
|
248 |
|
249 // Assignment. |
492
|
250 |
529
|
251 void assign (const tree_constant& rhs, const Octave_object& args); |
492
|
252 |
529
|
253 void do_scalar_assignment (const tree_constant& rhs, |
|
254 const Octave_object& args); |
492
|
255 |
529
|
256 void do_matrix_assignment (const tree_constant& rhs, |
|
257 const Octave_object& args); |
492
|
258 |
529
|
259 void do_matrix_assignment (const tree_constant& rhs, |
|
260 const tree_constant& i_arg); |
492
|
261 |
529
|
262 void fortran_style_matrix_assignment (const tree_constant& rhs, |
|
263 const tree_constant& i_arg); |
492
|
264 |
529
|
265 void fortran_style_matrix_assignment (const tree_constant& rhs, |
|
266 constant_type ci); |
492
|
267 |
529
|
268 void fortran_style_matrix_assignment (const tree_constant& rhs, |
|
269 idx_vector& i); |
492
|
270 |
529
|
271 void vector_assignment (const tree_constant& rhs, |
|
272 const tree_constant& i_arg); |
492
|
273 |
|
274 void check_vector_assign (int rhs_nr, int rhs_nc, int ilen, |
|
275 const char *rm); |
|
276 |
529
|
277 void do_vector_assign (const tree_constant& rhs, int i); |
|
278 void do_vector_assign (const tree_constant& rhs, idx_vector& i); |
|
279 void do_vector_assign (const tree_constant& rhs, Range& i); |
|
280 |
628
|
281 void do_matrix_assignment (const tree_constant& rhs, |
|
282 const tree_constant& i_arg, |
|
283 const tree_constant& j_arg); |
|
284 |
529
|
285 void do_matrix_assignment (const tree_constant& rhs, int i, |
|
286 const tree_constant& j_arg); |
|
287 void do_matrix_assignment (const tree_constant& rhs, idx_vector& i, |
|
288 const tree_constant& j_arg); |
|
289 void do_matrix_assignment (const tree_constant& rhs, Range& i, |
|
290 const tree_constant& j_arg); |
|
291 void do_matrix_assignment (const tree_constant& rhs, constant_type i, |
|
292 const tree_constant& j_arg); |
492
|
293 |
529
|
294 void do_matrix_assignment (const tree_constant& rhs, int i, int j); |
|
295 void do_matrix_assignment (const tree_constant& rhs, int i, idx_vector& jv); |
|
296 void do_matrix_assignment (const tree_constant& rhs, int i, Range& j); |
|
297 void do_matrix_assignment (const tree_constant& rhs, int i, constant_type cj); |
492
|
298 |
529
|
299 void do_matrix_assignment (const tree_constant& rhs, idx_vector& iv, |
|
300 int j); |
|
301 void do_matrix_assignment (const tree_constant& rhs, idx_vector& iv, |
492
|
302 idx_vector& jv); |
529
|
303 void do_matrix_assignment (const tree_constant& rhs, idx_vector& iv, |
|
304 Range& j); |
|
305 void do_matrix_assignment (const tree_constant& rhs, idx_vector& iv, |
492
|
306 constant_type j); |
|
307 |
529
|
308 void do_matrix_assignment (const tree_constant& rhs, Range& i, int j); |
|
309 void do_matrix_assignment (const tree_constant& rhs, Range& i, |
|
310 idx_vector& jv); |
|
311 void do_matrix_assignment (const tree_constant& rhs, Range& i, |
|
312 Range& j); |
|
313 void do_matrix_assignment (const tree_constant& rhs, Range& i, |
|
314 constant_type j); |
492
|
315 |
529
|
316 void do_matrix_assignment (const tree_constant& rhs, constant_type i, int j); |
|
317 void do_matrix_assignment (const tree_constant& rhs, constant_type i, |
492
|
318 idx_vector& jv); |
529
|
319 void do_matrix_assignment (const tree_constant& rhs, constant_type i, |
|
320 Range& j); |
|
321 void do_matrix_assignment (const tree_constant& rhs, |
|
322 const constant_type i, |
492
|
323 constant_type j); |
|
324 |
|
325 void delete_row (int); |
|
326 void delete_rows (idx_vector& i); |
|
327 void delete_rows (Range& i); |
|
328 |
|
329 void delete_column (int); |
|
330 void delete_columns (idx_vector& j); |
|
331 void delete_columns (Range& j); |
|
332 |
620
|
333 void maybe_mutate (void); |
492
|
334 |
|
335 void print (void); |
|
336 |
581
|
337 void print_code (ostream& os); |
|
338 |
628
|
339 char *type_as_string (void) const; |
|
340 |
620
|
341 // Binary and unary operations. |
492
|
342 |
620
|
343 friend tree_constant do_binary_op (tree_constant& a, tree_constant& b, |
|
344 tree_expression::type t); |
492
|
345 |
620
|
346 friend tree_constant do_unary_op (tree_constant& a, |
|
347 tree_expression::type t); |
492
|
348 |
620
|
349 // Data. |
492
|
350 |
|
351 int count; |
|
352 constant_type type_tag; |
|
353 union |
|
354 { |
|
355 double scalar; // A real scalar constant. |
|
356 Matrix *matrix; // A real matrix constant. |
|
357 Complex *complex_scalar; // A real scalar constant. |
|
358 ComplexMatrix *complex_matrix; // A real matrix constant. |
|
359 char *string; // A character string constant. |
|
360 Range *range; // A set of evenly spaced values. |
|
361 }; |
581
|
362 char *orig_text; |
620
|
363 |
|
364 // ------------------------------------------------------------------- |
|
365 |
|
366 // These may not need to be member functions. |
|
367 |
|
368 tree_constant cumprod (void) const; |
|
369 tree_constant cumsum (void) const; |
|
370 tree_constant prod (void) const; |
|
371 tree_constant sum (void) const; |
|
372 tree_constant sumsq (void) const; |
|
373 |
|
374 tree_constant diag (void) const; |
|
375 tree_constant diag (const tree_constant& a) const; |
492
|
376 |
620
|
377 tree_constant mapper (Mapper_fcn& m_fcn, int print) const; |
|
378 |
|
379 // ------------------------------------------------------------------- |
|
380 |
|
381 // We want to eliminate this. |
|
382 |
|
383 constant_type const_type (void) const { return type_tag; } |
|
384 }; |
492
|
385 |
|
386 #endif |
|
387 |
|
388 /* |
|
389 ;;; Local Variables: *** |
|
390 ;;; mode: C++ *** |
|
391 ;;; page-delimiter: "^/\\*" *** |
|
392 ;;; End: *** |
|
393 */ |