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 |
2980
|
36 #include "pt-exp.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 |
2971
|
45 tree_constant : public tree_expression |
1
|
46 { |
|
47 public: |
620
|
48 |
2879
|
49 tree_constant (int l = -1, int c = -1) |
2971
|
50 : tree_expression (l, c), val (), orig_text () { } |
620
|
51 |
2390
|
52 tree_constant (const octave_value& v, int l = -1, int c = -1) |
2971
|
53 : tree_expression (l, c), val (v), orig_text () { } |
1
|
54 |
2390
|
55 tree_constant (const tree_constant& a) |
2971
|
56 : tree_expression (-1, -1), 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 { |
2971
|
64 tree_expression::operator = (a); |
2390
|
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 // Type. It would be nice to eliminate the need for this. |
620
|
77 |
2971
|
78 bool is_constant (void) const |
|
79 { return true; } |
620
|
80 |
2409
|
81 void maybe_mutate (void) |
|
82 { val.maybe_mutate (); } |
|
83 |
2532
|
84 void print (ostream& os, bool pr_as_read_syntax = false, |
|
85 bool pr_orig_txt = true); |
1199
|
86 |
2942
|
87 void print_raw (ostream& os, bool pr_as_read_syntax = false, |
|
88 bool pr_orig_txt = true); |
|
89 |
2971
|
90 bool rvalue_ok (void) const |
|
91 { return true; } |
1
|
92 |
2971
|
93 octave_value rvalue (void) |
|
94 { return val; } |
|
95 |
|
96 octave_value_list rvalue (int nargout); |
|
97 |
|
98 void accept (tree_walker& tw); |
1
|
99 |
1558
|
100 // Store the original text corresponding to this constant for later |
|
101 // pretty printing. |
620
|
102 |
2879
|
103 void stash_original_text (const string& s) |
|
104 { orig_text = s; } |
620
|
105 |
2879
|
106 string original_text (void) const |
|
107 { return orig_text; } |
2124
|
108 |
747
|
109 private: |
|
110 |
2475
|
111 // For custom memory management. |
|
112 static octave_allocator allocator; |
|
113 |
|
114 // The actual value that this constant refers to. |
2390
|
115 octave_value val; |
747
|
116 |
2475
|
117 // The original text form of this constant. |
2390
|
118 string orig_text; |
|
119 }; |
2179
|
120 |
1
|
121 #endif |
|
122 |
|
123 /* |
|
124 ;;; Local Variables: *** |
|
125 ;;; mode: C++ *** |
|
126 ;;; End: *** |
|
127 */ |