1
|
1 /* |
|
2 |
1827
|
3 Copyright (C) 1996 John W. Eaton |
1
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
383
|
23 #if !defined (octave_tree_const_h) |
|
24 #define octave_tree_const_h 1 |
1
|
25 |
1298
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
1728
|
30 #include <string> |
|
31 |
1740
|
32 class ostream; |
581
|
33 |
1355
|
34 #include "Range.h" |
500
|
35 #include "mx-base.h" |
1755
|
36 #include "str-vec.h" |
500
|
37 |
1740
|
38 #include "pt-fvc.h" |
164
|
39 |
747
|
40 class Octave_map; |
2086
|
41 class octave_value_list; |
529
|
42 |
2124
|
43 class tree_walker; |
|
44 |
2390
|
45 #include "ov.h" |
581
|
46 |
1
|
47 class |
2390
|
48 tree_constant : public tree_fvc |
1
|
49 { |
|
50 public: |
620
|
51 |
|
52 enum magic_colon { magic_colon_t }; |
922
|
53 enum all_va_args { all_va_args_t }; |
620
|
54 |
1558
|
55 // Constructors. It is possible to create the following types of |
|
56 // constants: |
|
57 // |
|
58 // constant type constructor arguments |
|
59 // ------------- --------------------- |
|
60 // unknown none |
|
61 // real scalar double |
|
62 // real matrix Matrix |
|
63 // DiagMatrix |
|
64 // RowVector |
|
65 // ColumnVector |
|
66 // complex scalar Complex |
|
67 // complex matrix ComplexMatrix |
|
68 // ComplexDiagMatrix |
|
69 // ComplexRowVector |
|
70 // ComplexColumnVector |
1572
|
71 // char matrix charMatrix |
1558
|
72 // string char* (null terminated) |
1731
|
73 // string |
1572
|
74 // charMatrix |
1558
|
75 // range double, double, double |
|
76 // Range |
|
77 // map Octave_map |
2390
|
78 // magic colon tree_constant::magic_colon |
|
79 // all_va_args tree_constant::all_va_args |
620
|
80 |
2390
|
81 tree_constant (void) |
|
82 : tree_fvc (), val (), orig_text () { } |
|
83 |
|
84 tree_constant (double d, int l = -1, int c = -1) |
|
85 : tree_fvc (l, c), val (d), orig_text () { } |
1
|
86 |
2390
|
87 tree_constant (const Matrix& m) |
|
88 : tree_fvc (), val (m), orig_text () { } |
620
|
89 |
2390
|
90 tree_constant (const DiagMatrix& d) |
|
91 : tree_fvc (), val (d), orig_text () { } |
620
|
92 |
2390
|
93 tree_constant (const RowVector& v, int pcv = -1) |
|
94 : tree_fvc (), val (v, pcv), orig_text () { } |
620
|
95 |
2390
|
96 tree_constant (const ColumnVector& v, int pcv = -1) |
|
97 : tree_fvc (), val (v, pcv), orig_text () { } |
620
|
98 |
2390
|
99 tree_constant (const Complex& C, int l = -1, int c = -1) |
|
100 : tree_fvc (l, c), val (C), orig_text () { } |
|
101 |
|
102 tree_constant (const ComplexMatrix& m) |
|
103 : tree_fvc (), val (m), orig_text () { } |
1
|
104 |
2390
|
105 tree_constant (const ComplexDiagMatrix& d) |
|
106 : tree_fvc (), val (d), orig_text () { } |
|
107 |
|
108 tree_constant (const ComplexRowVector& v, int pcv = -1) |
|
109 : tree_fvc (), val (v, pcv), orig_text () { } |
620
|
110 |
2390
|
111 tree_constant (const ComplexColumnVector& v, int pcv = -1) |
|
112 : tree_fvc (), val (v, pcv), orig_text () { } |
620
|
113 |
2390
|
114 tree_constant (const char *s, int l = -1, int c = -1) |
|
115 : tree_fvc (l, c), val (s), orig_text () { } |
620
|
116 |
2390
|
117 tree_constant (const string& s, int l = -1, int c = -1) |
|
118 : tree_fvc (l, c), val (s), orig_text () { } |
620
|
119 |
2390
|
120 tree_constant (const string_vector& s, int l = -1, int c = -1) |
|
121 : tree_fvc (l, c), val (s), orig_text () { } |
|
122 |
|
123 tree_constant (const charMatrix& chm, bool is_string = false) |
|
124 : tree_fvc (), val (chm, is_string), orig_text () { } |
1
|
125 |
2390
|
126 tree_constant (double base, double limit, double inc) |
|
127 : tree_fvc (), val (base, limit, inc), orig_text () { } |
1
|
128 |
2390
|
129 tree_constant (const Range& r) |
|
130 : tree_fvc (), val (r), orig_text () { } |
1731
|
131 |
2390
|
132 tree_constant (const Octave_map& m) |
|
133 : tree_fvc (), val (m), orig_text () { } |
1755
|
134 |
2390
|
135 tree_constant (tree_constant::magic_colon, int l = -1, int c = -1) |
|
136 : tree_fvc (l, c), val (octave_value::magic_colon_t), orig_text () { } |
1355
|
137 |
2390
|
138 tree_constant (tree_constant::all_va_args, int l = -1, int c = -1) |
|
139 : tree_fvc (l, c), val (octave_value::all_va_args_t), orig_text () { } |
620
|
140 |
2390
|
141 tree_constant (const octave_value& v, int l = -1, int c = -1) |
|
142 : tree_fvc (l, c), val (v), orig_text () { } |
1
|
143 |
2390
|
144 tree_constant (const tree_constant& a) |
|
145 : tree_fvc (a), val (a.val), orig_text () { } |
747
|
146 |
2390
|
147 ~tree_constant (void) { } |
|
148 |
|
149 tree_constant& operator = (const tree_constant& a) |
620
|
150 { |
2390
|
151 if (this != &a) |
|
152 { |
|
153 tree_fvc::operator = (a); |
|
154 val = a.val; |
|
155 } |
|
156 return *this; |
620
|
157 } |
|
158 |
2390
|
159 #if 0 |
1
|
160 void *operator new (size_t size); |
|
161 void operator delete (void *p, size_t size); |
2390
|
162 #endif |
1
|
163 |
1558
|
164 // Indexed assignment. |
1
|
165 |
2390
|
166 octave_value index (const octave_value_list& idx) const |
|
167 { return val.index (idx); } |
|
168 |
|
169 octave_value& reference (void) |
1
|
170 { |
2390
|
171 val.make_unique (); |
|
172 return val; |
1
|
173 } |
|
174 |
2390
|
175 octave_value value (void) const |
|
176 { |
|
177 return val; |
|
178 } |
|
179 |
|
180 octave_value assign (const octave_value_list& idx, const octave_value& rhs) |
|
181 { |
|
182 val.assign (idx, rhs); |
|
183 return val; |
|
184 } |
|
185 |
|
186 #if 0 |
1558
|
187 // Simple structure assignment. |
747
|
188 |
2086
|
189 octave_value assign_map_element (SLList<string>& list, |
2390
|
190 const octave_value& rhs); |
747
|
191 |
1558
|
192 // Indexed structure assignment. |
747
|
193 |
2086
|
194 octave_value assign_map_element (SLList<string>& list, |
2390
|
195 const octave_value_list& args, |
|
196 const octave_value& rhs); |
|
197 #endif |
747
|
198 |
1558
|
199 // Type. It would be nice to eliminate the need for this. |
620
|
200 |
1827
|
201 bool is_constant (void) const { return true; } |
620
|
202 |
1558
|
203 // Size. |
620
|
204 |
2390
|
205 int rows (void) const { return val.rows (); } |
|
206 int columns (void) const { return val.columns (); } |
620
|
207 |
1558
|
208 // Does this constant have a type? Both of these are provided since |
|
209 // it is sometimes more natural to write is_undefined() instead of |
|
210 // ! is_defined(). |
620
|
211 |
2390
|
212 bool is_defined (void) const { return val.is_defined (); } |
|
213 bool is_undefined (void) const { return val.is_undefined (); } |
620
|
214 |
1558
|
215 // Is this constant a particular type, or does it belong to a |
|
216 // particular class of types? |
620
|
217 |
2390
|
218 bool is_real_scalar (void) const { return val.is_real_scalar (); } |
|
219 bool is_real_matrix (void) const { return val.is_real_matrix (); } |
|
220 bool is_complex_scalar (void) const { return val.is_complex_scalar (); } |
|
221 bool is_complex_matrix (void) const { return val.is_complex_matrix (); } |
|
222 bool is_char_matrix (void) const { return val.is_char_matrix (); } |
|
223 bool is_string (void) const { return val.is_string (); } |
|
224 bool is_range (void) const { return val.is_range (); } |
|
225 bool is_map (void) const { return val.is_map (); } |
|
226 bool is_magic_colon (void) const { return val.is_magic_colon (); } |
|
227 bool is_all_va_args (void) const { return val.is_all_va_args (); } |
620
|
228 |
1558
|
229 // Are any or all of the elements in this constant nonzero? |
620
|
230 |
2390
|
231 octave_value all (void) const { return val.all (); } |
|
232 octave_value any (void) const { return val.any (); } |
620
|
233 |
1558
|
234 // Other type stuff. |
|
235 |
2390
|
236 bool is_real_type (void) const { return val.is_real_type (); } |
628
|
237 |
2390
|
238 bool is_complex_type (void) const { return val.is_complex_type (); } |
620
|
239 |
2390
|
240 bool is_scalar_type (void) const { return val.is_scalar_type (); } |
|
241 bool is_matrix_type (void) const { return val.is_matrix_type (); } |
620
|
242 |
1827
|
243 bool is_numeric_type (void) const |
2390
|
244 { return val.is_numeric_type (); } |
620
|
245 |
1827
|
246 bool valid_as_scalar_index (void) const |
2390
|
247 { return val.valid_as_scalar_index (); } |
620
|
248 |
1827
|
249 bool valid_as_zero_index (void) const |
2390
|
250 { return val.valid_as_zero_index (); } |
1041
|
251 |
1558
|
252 // Does this constant correspond to a truth value? |
620
|
253 |
2390
|
254 bool is_true (void) const { return val.is_true (); } |
620
|
255 |
1558
|
256 // Is at least one of the dimensions of this constant zero? |
620
|
257 |
1827
|
258 bool is_empty (void) const |
2390
|
259 { return val.is_empty (); } |
620
|
260 |
1558
|
261 // Are the dimensions of this constant zero by zero? |
620
|
262 |
1827
|
263 bool is_zero_by_zero (void) const |
2390
|
264 { return val.is_zero_by_zero (); } |
620
|
265 |
1558
|
266 // Values. |
620
|
267 |
1827
|
268 double double_value (bool frc_str_conv = false) const |
2390
|
269 { return val.double_value (frc_str_conv); } |
628
|
270 |
1827
|
271 Matrix matrix_value (bool frc_str_conv = false) const |
2390
|
272 { return val.matrix_value (frc_str_conv); } |
628
|
273 |
1827
|
274 Complex complex_value (bool frc_str_conv = false) const |
2390
|
275 { return val.complex_value (frc_str_conv); } |
628
|
276 |
1827
|
277 ComplexMatrix complex_matrix_value (bool frc_str_conv = false) const |
2390
|
278 { return val.complex_matrix_value (frc_str_conv); } |
628
|
279 |
1827
|
280 charMatrix char_matrix_value (bool frc_str_conv = false) const |
2390
|
281 { return val.char_matrix_value (frc_str_conv); } |
1572
|
282 |
|
283 charMatrix all_strings (void) const |
2390
|
284 { return val.all_strings (); } |
1355
|
285 |
1728
|
286 string string_value (void) const |
2390
|
287 { return val.string_value (); } |
628
|
288 |
|
289 Range range_value (void) const |
2390
|
290 { return val.range_value (); } |
628
|
291 |
747
|
292 Octave_map map_value (void) const; |
|
293 |
2086
|
294 octave_value lookup_map_element (const string& ref, |
1827
|
295 bool insert = false, |
|
296 bool silent = false); |
1277
|
297 |
2086
|
298 octave_value lookup_map_element (SLList<string>& list, |
1827
|
299 bool insert = false, |
|
300 bool silent = false); |
747
|
301 |
1827
|
302 ColumnVector vector_value (bool /* frc_str_conv */ = false, |
|
303 bool /* frc_vec_conv */ = false) const |
2390
|
304 { return val.vector_value (); } |
628
|
305 |
1827
|
306 ComplexColumnVector |
|
307 complex_vector_value (bool /* frc_str_conv */ = false, |
|
308 bool /* frc_vec_conv */ = false) const |
2390
|
309 { return val.complex_vector_value (); } |
1
|
310 |
1558
|
311 // Binary and unary operations. |
1204
|
312 |
2086
|
313 friend octave_value do_binary_op (octave_value& a, octave_value& b, |
2390
|
314 tree_expression::type t); |
1204
|
315 |
2086
|
316 friend octave_value do_unary_op (octave_value& a, |
2390
|
317 tree_expression::type t); |
1204
|
318 |
1558
|
319 // Conversions. These should probably be private. If a user of this |
|
320 // class wants a certain kind of constant, he should simply ask for |
|
321 // it, and we should convert it if possible. |
1
|
322 |
2089
|
323 octave_value convert_to_str (void) const |
2390
|
324 { return val.convert_to_str (); } |
1
|
325 |
435
|
326 void convert_to_row_or_column_vector (void) |
2390
|
327 { val.convert_to_row_or_column_vector (); } |
435
|
328 |
1558
|
329 // Increment or decrement this constant. |
1
|
330 |
2390
|
331 void increment (void) { val.increment (); } |
1004
|
332 |
2390
|
333 void decrement (void) { val.decrement (); } |
1
|
334 |
1199
|
335 void print (void); |
2390
|
336 void print (ostream& os) { val.print (os); } |
1199
|
337 |
1827
|
338 void print_with_name (const string& name, bool print_padding = true); |
1755
|
339 void print_with_name (ostream& os, const string& name, |
1827
|
340 bool print_padding = true); |
1755
|
341 |
2390
|
342 octave_value eval (bool print_result); |
1
|
343 |
2086
|
344 octave_value_list eval (bool, int, const octave_value_list&); |
1
|
345 |
1558
|
346 // Store the original text corresponding to this constant for later |
|
347 // pretty printing. |
620
|
348 |
2390
|
349 void stash_original_text (const string& s) { orig_text = s; } |
620
|
350 |
2390
|
351 string original_text (void) { return orig_text; } |
2124
|
352 |
|
353 void accept (tree_walker& tw); |
581
|
354 |
2390
|
355 string type_name (void) const { return val.type_name (); } |
747
|
356 |
|
357 private: |
|
358 |
2390
|
359 octave_value val; |
747
|
360 |
2390
|
361 string orig_text; |
|
362 |
|
363 #if 0 |
2086
|
364 octave_value_rep *make_unique_map (void); |
747
|
365 |
1558
|
366 // We want to eliminate this, or at least make it private. |
620
|
367 |
2086
|
368 octave_value_rep::constant_type const_type (void) const |
620
|
369 { return rep->const_type (); } |
2390
|
370 #endif |
620
|
371 |
1827
|
372 void convert_to_matrix_type (bool make_complex) |
2390
|
373 { val.convert_to_matrix_type (make_complex); } |
636
|
374 |
1558
|
375 // Can we make these go away? |
636
|
376 |
1558
|
377 // These need better names, since a range really is a numeric type. |
636
|
378 |
1827
|
379 void force_numeric (bool frc_str_conv = false) |
2390
|
380 { val.force_numeric (frc_str_conv); } |
636
|
381 |
2390
|
382 octave_value make_numeric (bool frc_str_conv = false) const; |
|
383 #if 0 |
636
|
384 { |
|
385 if (is_numeric_type ()) |
|
386 return *this; |
|
387 else |
1558
|
388 return rep->make_numeric (frc_str_conv); |
636
|
389 } |
2390
|
390 #endif |
1199
|
391 |
2390
|
392 bool print_as_scalar (void) { return val.print_as_scalar (); } |
2181
|
393 |
2390
|
394 bool print_as_structure (void) { return val.print_as_structure (); } |
|
395 }; |
2179
|
396 |
1
|
397 #endif |
|
398 |
|
399 /* |
|
400 ;;; Local Variables: *** |
|
401 ;;; mode: C++ *** |
|
402 ;;; End: *** |
|
403 */ |