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