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