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