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 (void) { } |
|
56 |
2475
|
57 void *operator new (size_t size) |
|
58 { return allocator.alloc (size); } |
|
59 |
|
60 void operator delete (void *p, size_t size) |
|
61 { allocator.free (p, size); } |
1
|
62 |
1558
|
63 // Type. It would be nice to eliminate the need for this. |
620
|
64 |
2971
|
65 bool is_constant (void) const |
|
66 { return true; } |
620
|
67 |
2409
|
68 void maybe_mutate (void) |
|
69 { val.maybe_mutate (); } |
|
70 |
2532
|
71 void print (ostream& os, bool pr_as_read_syntax = false, |
|
72 bool pr_orig_txt = true); |
1199
|
73 |
2942
|
74 void print_raw (ostream& os, bool pr_as_read_syntax = false, |
|
75 bool pr_orig_txt = true); |
|
76 |
2971
|
77 bool rvalue_ok (void) const |
|
78 { return true; } |
1
|
79 |
2971
|
80 octave_value rvalue (void) |
|
81 { return val; } |
|
82 |
|
83 octave_value_list rvalue (int nargout); |
|
84 |
|
85 void accept (tree_walker& tw); |
1
|
86 |
1558
|
87 // Store the original text corresponding to this constant for later |
|
88 // pretty printing. |
620
|
89 |
2879
|
90 void stash_original_text (const string& s) |
|
91 { orig_text = s; } |
620
|
92 |
2879
|
93 string original_text (void) const |
|
94 { return orig_text; } |
2124
|
95 |
747
|
96 private: |
|
97 |
2475
|
98 // For custom memory management. |
|
99 static octave_allocator allocator; |
|
100 |
|
101 // The actual value that this constant refers to. |
2390
|
102 octave_value val; |
747
|
103 |
2475
|
104 // The original text form of this constant. |
2390
|
105 string orig_text; |
2988
|
106 |
|
107 // No copying! |
|
108 |
|
109 tree_constant (const tree_constant&); |
|
110 |
|
111 tree_constant& operator = (const tree_constant&); |
2390
|
112 }; |
2179
|
113 |
1
|
114 #endif |
|
115 |
|
116 /* |
|
117 ;;; Local Variables: *** |
|
118 ;;; mode: C++ *** |
|
119 ;;; End: *** |
|
120 */ |