1
|
1 /* |
|
2 |
1827
|
3 Copyright (C) 1996 John W. Eaton |
1
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
383
|
23 #if !defined (octave_tree_const_h) |
|
24 #define octave_tree_const_h 1 |
1
|
25 |
1298
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
1355
|
30 #include <cstdlib> |
|
31 |
1728
|
32 #include <string> |
|
33 |
1740
|
34 class ostream; |
581
|
35 |
1355
|
36 #include "Range.h" |
500
|
37 #include "mx-base.h" |
1755
|
38 #include "str-vec.h" |
500
|
39 |
1740
|
40 #include "pt-fvc.h" |
164
|
41 |
747
|
42 class Octave_map; |
1740
|
43 class Octave_object; |
529
|
44 |
581
|
45 // Constants. |
|
46 |
1
|
47 class |
495
|
48 tree_constant : public tree_fvc |
1
|
49 { |
620
|
50 private: |
|
51 |
1558
|
52 // The actual representation of the tree_constant. |
|
53 |
|
54 class |
|
55 tree_constant_rep |
1827
|
56 { |
|
57 public: |
1815
|
58 |
1827
|
59 enum constant_type |
|
60 { |
|
61 unknown_constant, |
|
62 scalar_constant, |
|
63 matrix_constant, |
|
64 complex_scalar_constant, |
|
65 complex_matrix_constant, |
|
66 char_matrix_constant, |
|
67 char_matrix_constant_str, |
|
68 range_constant, |
|
69 map_constant, |
|
70 magic_colon, |
|
71 all_va_args, |
|
72 }; |
1558
|
73 |
1827
|
74 enum force_orient |
|
75 { |
|
76 no_orient, |
|
77 row_orient, |
|
78 column_orient, |
|
79 }; |
1558
|
80 |
1827
|
81 tree_constant_rep (void); |
1558
|
82 |
1827
|
83 tree_constant_rep (double d); |
|
84 tree_constant_rep (const Matrix& m); |
|
85 tree_constant_rep (const DiagMatrix& d); |
|
86 tree_constant_rep (const RowVector& v, int pcv); |
|
87 tree_constant_rep (const ColumnVector& v, int pcv); |
1558
|
88 |
1827
|
89 tree_constant_rep (const Complex& c); |
|
90 tree_constant_rep (const ComplexMatrix& m); |
|
91 tree_constant_rep (const ComplexDiagMatrix& d); |
|
92 tree_constant_rep (const ComplexRowVector& v, int pcv); |
|
93 tree_constant_rep (const ComplexColumnVector& v, int pcv); |
1558
|
94 |
1827
|
95 tree_constant_rep (const char *s); |
|
96 tree_constant_rep (const string& s); |
|
97 tree_constant_rep (const string_vector& s); |
|
98 tree_constant_rep (const charMatrix& chm, bool is_string); |
1558
|
99 |
1827
|
100 tree_constant_rep (double base, double limit, double inc); |
|
101 tree_constant_rep (const Range& r); |
1558
|
102 |
1827
|
103 tree_constant_rep (const Octave_map& m); |
1558
|
104 |
1827
|
105 tree_constant_rep (tree_constant_rep::constant_type t); |
|
106 |
|
107 tree_constant_rep (const tree_constant_rep& t); |
1558
|
108 |
1827
|
109 ~tree_constant_rep (void); |
1558
|
110 |
1827
|
111 void *operator new (size_t size); |
|
112 void operator delete (void *p, size_t size); |
1558
|
113 |
1827
|
114 int rows (void) const; |
|
115 int columns (void) const; |
1558
|
116 |
1827
|
117 bool is_defined (void) const |
|
118 { return type_tag != unknown_constant; } |
1558
|
119 |
1827
|
120 bool is_undefined (void) const |
|
121 { return type_tag == unknown_constant; } |
1558
|
122 |
1827
|
123 bool is_unknown (void) const |
|
124 { return type_tag == unknown_constant; } |
1558
|
125 |
1827
|
126 bool is_real_scalar (void) const |
|
127 { return type_tag == scalar_constant; } |
1558
|
128 |
1827
|
129 bool is_real_matrix (void) const |
|
130 { return type_tag == matrix_constant; } |
1558
|
131 |
1827
|
132 bool is_complex_scalar (void) const |
|
133 { return type_tag == complex_scalar_constant; } |
1558
|
134 |
1827
|
135 bool is_complex_matrix (void) const |
|
136 { return type_tag == complex_matrix_constant; } |
1558
|
137 |
1827
|
138 bool is_char_matrix (void) const |
|
139 { return type_tag == char_matrix_constant; } |
|
140 |
|
141 bool is_string (void) const |
|
142 { return type_tag == char_matrix_constant_str; } |
1572
|
143 |
1827
|
144 bool is_range (void) const |
|
145 { return type_tag == range_constant; } |
1558
|
146 |
1827
|
147 bool is_map (void) const |
|
148 { return type_tag == map_constant; } |
1558
|
149 |
1827
|
150 bool is_magic_colon (void) const |
|
151 { return type_tag == magic_colon; } |
1558
|
152 |
1827
|
153 bool is_all_va_args (void) const |
|
154 { return type_tag == all_va_args; } |
1558
|
155 |
1827
|
156 tree_constant all (void) const; |
|
157 tree_constant any (void) const; |
1558
|
158 |
1827
|
159 bool is_real_type (void) const |
|
160 { |
|
161 return (type_tag == scalar_constant |
|
162 || type_tag == matrix_constant |
|
163 || type_tag == range_constant |
|
164 || type_tag == char_matrix_constant |
|
165 || type_tag == char_matrix_constant_str); |
|
166 } |
1558
|
167 |
1827
|
168 bool is_complex_type (void) const |
|
169 { |
|
170 return (type_tag == complex_matrix_constant |
|
171 || type_tag == complex_scalar_constant); |
|
172 } |
|
173 |
|
174 // Would be nice to get rid of the next four functions: |
1558
|
175 |
1827
|
176 bool is_scalar_type (void) const |
|
177 { |
|
178 return (type_tag == scalar_constant |
|
179 || type_tag == complex_scalar_constant); |
|
180 } |
1558
|
181 |
1827
|
182 bool is_matrix_type (void) const |
|
183 { |
|
184 return (type_tag == matrix_constant |
|
185 || type_tag == complex_matrix_constant); |
|
186 } |
1168
|
187 |
1827
|
188 bool is_numeric_type (void) const |
|
189 { |
|
190 return (type_tag == scalar_constant |
|
191 || type_tag == matrix_constant |
|
192 || type_tag == complex_matrix_constant |
|
193 || type_tag == complex_scalar_constant); |
|
194 } |
1558
|
195 |
1827
|
196 bool valid_as_scalar_index (void) const; |
|
197 bool valid_as_zero_index (void) const; |
|
198 |
|
199 bool is_true (void) const; |
1558
|
200 |
1827
|
201 bool is_empty (void) const |
|
202 { |
|
203 return ((! (is_magic_colon () |
|
204 || is_all_va_args () |
|
205 || is_unknown ())) |
|
206 && (rows () == 0 |
|
207 || columns () == 0)); |
|
208 } |
1558
|
209 |
1827
|
210 double double_value (bool frc_str_conv = false) const; |
|
211 Matrix matrix_value (bool frc_str_conv = false) const; |
|
212 Complex complex_value (bool frc_str_conv = false) const; |
|
213 ComplexMatrix complex_matrix_value (bool frc_str_conv = false) const; |
|
214 charMatrix char_matrix_value (bool frc_str_conv = false) const; |
|
215 charMatrix all_strings (void) const; |
|
216 string string_value (void) const; |
|
217 Range range_value (void) const; |
|
218 Octave_map map_value (void) const; |
1558
|
219 |
1827
|
220 tree_constant& lookup_map_element (const string& name, |
|
221 bool insert = false, |
|
222 bool silent = false); |
|
223 |
|
224 ColumnVector vector_value (bool frc_str_conv = false, |
|
225 bool frc_vec_conv = false) const; |
1558
|
226 |
1827
|
227 ComplexColumnVector |
|
228 complex_vector_value (bool frc_str_conv = false, |
|
229 bool frc_vec_conv = false) const; |
1558
|
230 |
1827
|
231 tree_constant convert_to_str (void) const; |
|
232 |
|
233 void convert_to_row_or_column_vector (void); |
|
234 |
|
235 void bump_value (tree_expression::type); |
1558
|
236 |
1827
|
237 void resize (int i, int j); |
|
238 void resize (int i, int j, double val); |
1558
|
239 |
1827
|
240 void stash_original_text (const string& s); |
1558
|
241 |
1827
|
242 void maybe_mutate (void); |
1558
|
243 |
1827
|
244 void print (void); |
|
245 void print (ostream& os); |
1558
|
246 |
1827
|
247 void print_code (ostream& os); |
1558
|
248 |
1827
|
249 void gripe_wrong_type_arg (const char *name, |
|
250 const tree_constant_rep& tcr) const; |
1558
|
251 |
1827
|
252 char *type_as_string (void) const; |
1558
|
253 |
1827
|
254 // Binary and unary operations. |
1558
|
255 |
1827
|
256 friend tree_constant do_binary_op (tree_constant& a, tree_constant& b, |
|
257 tree_expression::type t); |
1558
|
258 |
1827
|
259 friend tree_constant do_unary_op (tree_constant& a, |
|
260 tree_expression::type t); |
1558
|
261 |
1827
|
262 // We want to eliminate this. |
1558
|
263 |
1827
|
264 constant_type const_type (void) const { return type_tag; } |
|
265 |
|
266 // We want to get rid of these too: |
1558
|
267 |
1827
|
268 void force_numeric (bool frc_str_conv = false); |
|
269 tree_constant make_numeric (bool frc_str_conv = false) const; |
1558
|
270 |
1827
|
271 // But not this. |
1558
|
272 |
1827
|
273 void convert_to_matrix_type (bool make_complex); |
1558
|
274 |
1827
|
275 // Indexing and assignment. |
1558
|
276 |
1827
|
277 void clear_index (void); |
1558
|
278 |
1827
|
279 // void set_index (double d); |
|
280 void set_index (const Range& r); |
|
281 void set_index (const ColumnVector& v); |
|
282 void set_index (const Matrix& m); |
|
283 void set_index (char c); |
1558
|
284 |
1827
|
285 void set_index (const Octave_object& args, |
|
286 bool rhs_is_complex = false); |
1558
|
287 |
1827
|
288 tree_constant do_index (const Octave_object& args); |
1558
|
289 |
1827
|
290 void maybe_widen (constant_type t); |
1558
|
291 |
1827
|
292 void assign (tree_constant& rhs, const Octave_object& args); |
1558
|
293 |
1827
|
294 bool print_as_scalar (void); |
1558
|
295 |
1827
|
296 bool print_as_structure (void); |
1755
|
297 |
1827
|
298 // Data. |
1558
|
299 |
1827
|
300 union |
|
301 { |
|
302 double scalar; // A real scalar constant. |
|
303 Matrix *matrix; // A real matrix constant. |
|
304 Complex *complex_scalar; // A real scalar constant. |
|
305 ComplexMatrix *complex_matrix; // A real matrix constant. |
|
306 charMatrix *char_matrix; // A character string constant. |
|
307 Range *range; // A set of evenly spaced values. |
|
308 Octave_map *a_map; // An associative array. |
1558
|
309 |
1827
|
310 tree_constant_rep *freeptr; // For custom memory management. |
|
311 }; |
1558
|
312 |
1827
|
313 constant_type type_tag; |
1558
|
314 |
1827
|
315 int count; |
1558
|
316 |
1827
|
317 string orig_text; |
|
318 }; |
620
|
319 |
1168
|
320 union |
|
321 { |
|
322 tree_constant *freeptr; // For custom memory management. |
|
323 tree_constant_rep *rep; // The real representation. |
|
324 }; |
1
|
325 |
|
326 public: |
620
|
327 |
|
328 enum magic_colon { magic_colon_t }; |
922
|
329 enum all_va_args { all_va_args_t }; |
620
|
330 |
1558
|
331 // Constructors. It is possible to create the following types of |
|
332 // constants: |
|
333 // |
|
334 // constant type constructor arguments |
|
335 // ------------- --------------------- |
|
336 // unknown none |
|
337 // real scalar double |
|
338 // real matrix Matrix |
|
339 // DiagMatrix |
|
340 // RowVector |
|
341 // ColumnVector |
|
342 // complex scalar Complex |
|
343 // complex matrix ComplexMatrix |
|
344 // ComplexDiagMatrix |
|
345 // ComplexRowVector |
|
346 // ComplexColumnVector |
1572
|
347 // char matrix charMatrix |
1558
|
348 // string char* (null terminated) |
1731
|
349 // string |
1572
|
350 // charMatrix |
1558
|
351 // range double, double, double |
|
352 // Range |
|
353 // map Octave_map |
|
354 // magic colon tree_constant::magic_colon |
|
355 // all_va_args tree_constant::all_va_args |
620
|
356 |
581
|
357 tree_constant (void) : tree_fvc () |
1
|
358 { rep = new tree_constant_rep (); rep->count = 1; } |
|
359 |
1606
|
360 tree_constant (double d, int l = -1, int c = -1) : tree_fvc (l, c) |
1
|
361 { rep = new tree_constant_rep (d); rep->count = 1; } |
620
|
362 |
581
|
363 tree_constant (const Matrix& m) : tree_fvc () |
1
|
364 { rep = new tree_constant_rep (m); rep->count = 1; } |
620
|
365 |
581
|
366 tree_constant (const DiagMatrix& d) : tree_fvc () |
1
|
367 { rep = new tree_constant_rep (d); rep->count = 1; } |
620
|
368 |
581
|
369 tree_constant (const RowVector& v, int pcv = -1) : tree_fvc () |
1
|
370 { rep = new tree_constant_rep (v, pcv); rep->count = 1; } |
620
|
371 |
581
|
372 tree_constant (const ColumnVector& v, int pcv = -1) : tree_fvc () |
1
|
373 { rep = new tree_constant_rep (v, pcv); rep->count = 1; } |
|
374 |
1606
|
375 tree_constant (const Complex& C, int l = -1, int c = -1) : tree_fvc (l, c) |
|
376 { rep = new tree_constant_rep (C); rep->count = 1; } |
620
|
377 |
581
|
378 tree_constant (const ComplexMatrix& m) : tree_fvc () |
1
|
379 { rep = new tree_constant_rep (m); rep->count = 1; } |
620
|
380 |
581
|
381 tree_constant (const ComplexDiagMatrix& d) : tree_fvc () |
1
|
382 { rep = new tree_constant_rep (d); rep->count = 1; } |
620
|
383 |
581
|
384 tree_constant (const ComplexRowVector& v, int pcv = -1) : tree_fvc () |
1572
|
385 { rep = new tree_constant_rep (v, pcv); rep->count = 1; } |
620
|
386 |
581
|
387 tree_constant (const ComplexColumnVector& v, int pcv = -1) : tree_fvc () |
1572
|
388 { rep = new tree_constant_rep (v, pcv); rep->count = 1; } |
1
|
389 |
1606
|
390 tree_constant (const char *s, int l = -1, int c = -1) : tree_fvc (l, c) |
1
|
391 { rep = new tree_constant_rep (s); rep->count = 1; } |
|
392 |
1731
|
393 tree_constant (const string& s, int l = -1, int c = -1) : tree_fvc (l, c) |
|
394 { rep = new tree_constant_rep (s); rep->count = 1; } |
|
395 |
1755
|
396 tree_constant (const string_vector& s, int l = -1, int c = -1) |
|
397 : tree_fvc (l, c) |
|
398 { rep = new tree_constant_rep (s); rep->count = 1; } |
|
399 |
1827
|
400 tree_constant (const charMatrix& chm, bool is_string = false) : tree_fvc () |
1572
|
401 { rep = new tree_constant_rep (chm, is_string); rep->count = 1; } |
1355
|
402 |
581
|
403 tree_constant (double base, double limit, double inc) : tree_fvc () |
1
|
404 { rep = new tree_constant_rep (base, limit, inc); rep->count = 1; } |
620
|
405 |
581
|
406 tree_constant (const Range& r) : tree_fvc () |
1
|
407 { rep = new tree_constant_rep (r); rep->count = 1; } |
|
408 |
747
|
409 tree_constant (const Octave_map& m) : tree_fvc () |
|
410 { rep = new tree_constant_rep (m); rep->count = 1; } |
|
411 |
1487
|
412 tree_constant (tree_constant::magic_colon) : tree_fvc () |
620
|
413 { |
|
414 tree_constant_rep::constant_type tmp; |
|
415 tmp = tree_constant_rep::magic_colon; |
|
416 rep = new tree_constant_rep (tmp); |
|
417 rep->count = 1; |
|
418 } |
|
419 |
1487
|
420 tree_constant (tree_constant::all_va_args) : tree_fvc () |
922
|
421 { |
|
422 tree_constant_rep::constant_type tmp; |
|
423 tmp = tree_constant_rep::all_va_args; |
|
424 rep = new tree_constant_rep (tmp); |
|
425 rep->count = 1; |
|
426 } |
|
427 |
1558
|
428 // Copy constructor. |
1
|
429 |
581
|
430 tree_constant (const tree_constant& a) : tree_fvc () |
1
|
431 { rep = a.rep; rep->count++; } |
|
432 |
1558
|
433 // Delete the representation of this constant if the count drops to |
|
434 // zero. |
620
|
435 |
1
|
436 ~tree_constant (void); |
|
437 |
|
438 void *operator new (size_t size); |
|
439 void operator delete (void *p, size_t size); |
|
440 |
1558
|
441 // Simple assignment. |
620
|
442 |
747
|
443 tree_constant operator = (const tree_constant& a); |
1
|
444 |
1558
|
445 // Indexed assignment. |
1
|
446 |
782
|
447 tree_constant assign (tree_constant& rhs, const Octave_object& args) |
1
|
448 { |
|
449 if (rep->count > 1) |
|
450 { |
|
451 --rep->count; |
|
452 rep = new tree_constant_rep (*rep); |
|
453 rep->count = 1; |
|
454 } |
1004
|
455 |
506
|
456 rep->assign (rhs, args); |
1004
|
457 |
1
|
458 return *this; |
|
459 } |
|
460 |
1558
|
461 // Simple structure assignment. |
747
|
462 |
1755
|
463 tree_constant assign_map_element (SLList<string>& list, |
782
|
464 tree_constant& rhs); |
747
|
465 |
1558
|
466 // Indexed structure assignment. |
747
|
467 |
1755
|
468 tree_constant assign_map_element (SLList<string>& list, |
782
|
469 tree_constant& rhs, |
747
|
470 const Octave_object& args); |
|
471 |
1558
|
472 // Type. It would be nice to eliminate the need for this. |
620
|
473 |
1827
|
474 bool is_constant (void) const { return true; } |
620
|
475 |
1558
|
476 // Size. |
620
|
477 |
|
478 int rows (void) const { return rep->rows (); } |
|
479 int columns (void) const { return rep->columns (); } |
|
480 |
1558
|
481 // Does this constant have a type? Both of these are provided since |
|
482 // it is sometimes more natural to write is_undefined() instead of |
|
483 // ! is_defined(). |
620
|
484 |
1827
|
485 bool is_defined (void) const { return rep->is_defined (); } |
|
486 bool is_undefined (void) const { return rep->is_undefined (); } |
620
|
487 |
1558
|
488 // Is this constant a particular type, or does it belong to a |
|
489 // particular class of types? |
620
|
490 |
1827
|
491 bool is_unknown (void) const { return rep->is_unknown (); } |
|
492 bool is_real_scalar (void) const { return rep->is_real_scalar (); } |
|
493 bool is_real_matrix (void) const { return rep->is_real_matrix (); } |
|
494 bool is_complex_scalar (void) const { return rep->is_complex_scalar (); } |
|
495 bool is_complex_matrix (void) const { return rep->is_complex_matrix (); } |
|
496 bool is_string (void) const { return rep->is_string (); } |
|
497 bool is_range (void) const { return rep->is_range (); } |
|
498 bool is_map (void) const { return rep->is_map (); } |
|
499 bool is_magic_colon (void) const { return rep->is_magic_colon (); } |
|
500 bool is_all_va_args (void) const { return rep->is_all_va_args (); } |
620
|
501 |
1558
|
502 // Are any or all of the elements in this constant nonzero? |
620
|
503 |
|
504 tree_constant all (void) const { return rep->all (); } |
|
505 tree_constant any (void) const { return rep->any (); } |
|
506 |
1558
|
507 // Other type stuff. |
|
508 |
1827
|
509 bool is_real_type (void) const { return rep->is_real_type (); } |
628
|
510 |
1827
|
511 bool is_complex_type (void) const { return rep->is_complex_type (); } |
620
|
512 |
1827
|
513 bool is_scalar_type (void) const { return rep->is_scalar_type (); } |
|
514 bool is_matrix_type (void) const { return rep->is_matrix_type (); } |
620
|
515 |
1827
|
516 bool is_numeric_type (void) const |
628
|
517 { return rep->is_numeric_type (); } |
620
|
518 |
1827
|
519 bool valid_as_scalar_index (void) const |
620
|
520 { return rep->valid_as_scalar_index (); } |
|
521 |
1827
|
522 bool valid_as_zero_index (void) const |
1041
|
523 { return rep->valid_as_zero_index (); } |
|
524 |
1558
|
525 // Does this constant correspond to a truth value? |
620
|
526 |
1827
|
527 bool is_true (void) const { return rep->is_true (); } |
620
|
528 |
1558
|
529 // Is at least one of the dimensions of this constant zero? |
620
|
530 |
1827
|
531 bool is_empty (void) const |
1277
|
532 { return rep->is_empty (); } |
620
|
533 |
1558
|
534 // Are the dimensions of this constant zero by zero? |
620
|
535 |
1827
|
536 bool is_zero_by_zero (void) const |
620
|
537 { |
922
|
538 return ((! (is_magic_colon () || is_all_va_args () || is_unknown ())) |
620
|
539 && rows () == 0 && columns () == 0); |
|
540 } |
|
541 |
1558
|
542 // Values. |
620
|
543 |
1827
|
544 double double_value (bool frc_str_conv = false) const |
1558
|
545 { return rep->double_value (frc_str_conv); } |
628
|
546 |
1827
|
547 Matrix matrix_value (bool frc_str_conv = false) const |
1558
|
548 { return rep->matrix_value (frc_str_conv); } |
628
|
549 |
1827
|
550 Complex complex_value (bool frc_str_conv = false) const |
1558
|
551 { return rep->complex_value (frc_str_conv); } |
628
|
552 |
1827
|
553 ComplexMatrix complex_matrix_value (bool frc_str_conv = false) const |
1558
|
554 { return rep->complex_matrix_value (frc_str_conv); } |
628
|
555 |
1827
|
556 charMatrix char_matrix_value (bool frc_str_conv = false) const |
1572
|
557 { return rep->char_matrix_value (frc_str_conv); } |
|
558 |
|
559 charMatrix all_strings (void) const |
1355
|
560 { return rep->all_strings (); } |
|
561 |
1728
|
562 string string_value (void) const |
628
|
563 { return rep->string_value (); } |
|
564 |
|
565 Range range_value (void) const |
|
566 { return rep->range_value (); } |
|
567 |
747
|
568 Octave_map map_value (void) const; |
|
569 |
1827
|
570 tree_constant lookup_map_element (const string& ref, |
|
571 bool insert = false, |
|
572 bool silent = false); |
1277
|
573 |
1755
|
574 tree_constant lookup_map_element (SLList<string>& list, |
1827
|
575 bool insert = false, |
|
576 bool silent = false); |
747
|
577 |
1827
|
578 ColumnVector vector_value (bool /* frc_str_conv */ = false, |
|
579 bool /* frc_vec_conv */ = false) const |
628
|
580 { return rep->vector_value (); } |
|
581 |
1827
|
582 ComplexColumnVector |
|
583 complex_vector_value (bool /* frc_str_conv */ = false, |
|
584 bool /* frc_vec_conv */ = false) const |
628
|
585 { return rep->complex_vector_value (); } |
1
|
586 |
1558
|
587 // Binary and unary operations. |
1204
|
588 |
|
589 friend tree_constant do_binary_op (tree_constant& a, tree_constant& b, |
|
590 tree_expression::type t); |
|
591 |
|
592 friend tree_constant do_unary_op (tree_constant& a, |
|
593 tree_expression::type t); |
|
594 |
1558
|
595 // Conversions. These should probably be private. If a user of this |
|
596 // class wants a certain kind of constant, he should simply ask for |
|
597 // it, and we should convert it if possible. |
1
|
598 |
628
|
599 tree_constant convert_to_str (void) |
|
600 { return rep->convert_to_str (); } |
1
|
601 |
435
|
602 void convert_to_row_or_column_vector (void) |
455
|
603 { rep->convert_to_row_or_column_vector (); } |
435
|
604 |
1558
|
605 // Increment or decrement this constant. |
1
|
606 |
578
|
607 void bump_value (tree_expression::type et) |
1
|
608 { |
|
609 if (rep->count > 1) |
|
610 { |
|
611 --rep->count; |
|
612 rep = new tree_constant_rep (*rep); |
|
613 rep->count = 1; |
|
614 } |
1004
|
615 |
1
|
616 rep->bump_value (et); |
|
617 } |
|
618 |
1199
|
619 void print (void); |
|
620 void print (ostream& os) { rep->print (os); } |
|
621 |
1827
|
622 void print_with_name (const string& name, bool print_padding = true); |
1755
|
623 void print_with_name (ostream& os, const string& name, |
1827
|
624 bool print_padding = true); |
1755
|
625 |
1558
|
626 // Evaluate this constant, possibly converting complex to real, or |
|
627 // matrix to scalar, etc. |
620
|
628 |
1827
|
629 tree_constant eval (bool print_result) |
495
|
630 { |
1199
|
631 if (print_result) |
1616
|
632 { |
|
633 rep->maybe_mutate (); // XXX FIXME XXX -- is this necessary? |
|
634 print (); |
|
635 } |
1004
|
636 |
495
|
637 return *this; |
|
638 } |
1
|
639 |
1827
|
640 Octave_object eval (bool, int, const Octave_object&); |
1
|
641 |
1558
|
642 // Store the original text corresponding to this constant for later |
|
643 // pretty printing. |
620
|
644 |
1755
|
645 void stash_original_text (const string& s) |
620
|
646 { rep->stash_original_text (s); } |
|
647 |
1558
|
648 // Pretty print this constant. |
620
|
649 |
581
|
650 void print_code (ostream& os); |
|
651 |
628
|
652 char *type_as_string (void) const |
|
653 { return rep->type_as_string (); } |
|
654 |
1558
|
655 // We really do need this, and it should be private: |
747
|
656 |
|
657 private: |
|
658 |
|
659 void make_unique (void); |
|
660 |
|
661 tree_constant_rep *make_unique_map (void); |
|
662 |
1558
|
663 // We want to eliminate this, or at least make it private. |
620
|
664 |
|
665 tree_constant_rep::constant_type const_type (void) const |
|
666 { return rep->const_type (); } |
|
667 |
1827
|
668 void convert_to_matrix_type (bool make_complex) |
1581
|
669 { rep->convert_to_matrix_type (make_complex); } |
636
|
670 |
1558
|
671 // Can we make these go away? |
636
|
672 |
1558
|
673 // These need better names, since a range really is a numeric type. |
636
|
674 |
1827
|
675 void force_numeric (bool frc_str_conv = false) |
1558
|
676 { rep->force_numeric (frc_str_conv); } |
636
|
677 |
1827
|
678 tree_constant make_numeric (bool frc_str_conv = false) const |
636
|
679 { |
|
680 if (is_numeric_type ()) |
|
681 return *this; |
|
682 else |
1558
|
683 return rep->make_numeric (frc_str_conv); |
636
|
684 } |
1755
|
685 |
1827
|
686 bool print_as_scalar (void) { return rep->print_as_scalar (); } |
1
|
687 |
1827
|
688 bool print_as_structure (void) { return rep->print_as_structure (); } |
1755
|
689 }; |
1199
|
690 |
1
|
691 #endif |
|
692 |
|
693 /* |
|
694 ;;; Local Variables: *** |
|
695 ;;; mode: C++ *** |
|
696 ;;; End: *** |
|
697 */ |