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