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