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