1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 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 |
2475
|
34 #include "oct-alloc.h" |
500
|
35 |
1740
|
36 #include "pt-fvc.h" |
164
|
37 |
2086
|
38 class octave_value_list; |
529
|
39 |
2124
|
40 class tree_walker; |
|
41 |
2390
|
42 #include "ov.h" |
581
|
43 |
1
|
44 class |
2390
|
45 tree_constant : public tree_fvc |
1
|
46 { |
|
47 public: |
620
|
48 |
2879
|
49 tree_constant (int l = -1, int c = -1) |
|
50 : tree_fvc (l, c), val (), orig_text () { } |
620
|
51 |
2390
|
52 tree_constant (const octave_value& v, int l = -1, int c = -1) |
|
53 : tree_fvc (l, c), val (v), orig_text () { } |
1
|
54 |
2390
|
55 tree_constant (const tree_constant& a) |
2431
|
56 : tree_fvc (), val (a.val), orig_text () { } |
747
|
57 |
2390
|
58 ~tree_constant (void) { } |
|
59 |
|
60 tree_constant& operator = (const tree_constant& a) |
620
|
61 { |
2390
|
62 if (this != &a) |
|
63 { |
|
64 tree_fvc::operator = (a); |
|
65 val = a.val; |
|
66 } |
|
67 return *this; |
620
|
68 } |
|
69 |
2475
|
70 void *operator new (size_t size) |
|
71 { return allocator.alloc (size); } |
|
72 |
|
73 void operator delete (void *p, size_t size) |
|
74 { allocator.free (p, size); } |
1
|
75 |
1558
|
76 // Indexed assignment. |
1
|
77 |
2390
|
78 octave_value index (const octave_value_list& idx) const |
|
79 { return val.index (idx); } |
|
80 |
|
81 octave_value& reference (void) |
1
|
82 { |
2390
|
83 val.make_unique (); |
|
84 return val; |
1
|
85 } |
|
86 |
2390
|
87 octave_value value (void) const |
2879
|
88 { return val; } |
2390
|
89 |
2879
|
90 octave_value assign (octave_value::assign_op op, |
|
91 const octave_value_list& idx, |
|
92 const octave_value& rhs) |
2390
|
93 { |
2879
|
94 val.assign (op, idx, rhs); |
2390
|
95 return val; |
|
96 } |
|
97 |
1558
|
98 // Type. It would be nice to eliminate the need for this. |
620
|
99 |
1827
|
100 bool is_constant (void) const { return true; } |
620
|
101 |
2409
|
102 void maybe_mutate (void) |
|
103 { val.maybe_mutate (); } |
|
104 |
2532
|
105 void print (ostream& os, bool pr_as_read_syntax = false, |
|
106 bool pr_orig_txt = true); |
1199
|
107 |
2859
|
108 octave_value eval (bool print = false); |
1
|
109 |
2086
|
110 octave_value_list eval (bool, int, const octave_value_list&); |
1
|
111 |
1558
|
112 // Store the original text corresponding to this constant for later |
|
113 // pretty printing. |
620
|
114 |
2879
|
115 void stash_original_text (const string& s) |
|
116 { orig_text = s; } |
620
|
117 |
2879
|
118 string original_text (void) const |
|
119 { return orig_text; } |
2124
|
120 |
|
121 void accept (tree_walker& tw); |
581
|
122 |
747
|
123 private: |
|
124 |
2475
|
125 // For custom memory management. |
|
126 static octave_allocator allocator; |
|
127 |
|
128 // The actual value that this constant refers to. |
2390
|
129 octave_value val; |
747
|
130 |
2475
|
131 // The original text form of this constant. |
2390
|
132 string orig_text; |
|
133 }; |
2179
|
134 |
1
|
135 #endif |
|
136 |
|
137 /* |
|
138 ;;; Local Variables: *** |
|
139 ;;; mode: C++ *** |
|
140 ;;; End: *** |
|
141 */ |