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