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