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 |
4192
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
1298
|
27 #pragma interface |
|
28 #endif |
|
29 |
3503
|
30 #include <iostream> |
1728
|
31 #include <string> |
|
32 |
2475
|
33 #include "oct-alloc.h" |
500
|
34 |
3770
|
35 #include "pt-bp.h" |
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 |
4267
|
57 bool has_magic_end (void) const { return false; } |
|
58 |
3933
|
59 void *operator new (size_t size) { return allocator.alloc (size); } |
2475
|
60 |
3933
|
61 void operator delete (void *p, size_t size) { allocator.free (p, size); } |
1
|
62 |
1558
|
63 // Type. It would be nice to eliminate the need for this. |
620
|
64 |
3933
|
65 bool is_constant (void) const { return true; } |
620
|
66 |
3933
|
67 void maybe_mutate (void) { val.maybe_mutate (); } |
2409
|
68 |
3523
|
69 void print (std::ostream& os, bool pr_as_read_syntax = false, |
2532
|
70 bool pr_orig_txt = true); |
1199
|
71 |
3523
|
72 void print_raw (std::ostream& os, bool pr_as_read_syntax = false, |
2942
|
73 bool pr_orig_txt = true); |
|
74 |
3933
|
75 bool rvalue_ok (void) const { return true; } |
1
|
76 |
2971
|
77 octave_value rvalue (void) |
3770
|
78 { |
|
79 MAYBE_DO_BREAKPOINT; |
|
80 return val; |
|
81 } |
2971
|
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 |
3933
|
90 void stash_original_text (const std::string& s) { orig_text = s; } |
620
|
91 |
3933
|
92 std::string original_text (void) const { return orig_text; } |
2124
|
93 |
747
|
94 private: |
|
95 |
2475
|
96 // For custom memory management. |
|
97 static octave_allocator allocator; |
|
98 |
|
99 // The actual value that this constant refers to. |
2390
|
100 octave_value val; |
747
|
101 |
2475
|
102 // The original text form of this constant. |
3523
|
103 std::string orig_text; |
2988
|
104 |
|
105 // No copying! |
|
106 |
|
107 tree_constant (const tree_constant&); |
|
108 |
|
109 tree_constant& operator = (const tree_constant&); |
2390
|
110 }; |
2179
|
111 |
1
|
112 #endif |
|
113 |
|
114 /* |
|
115 ;;; Local Variables: *** |
|
116 ;;; mode: C++ *** |
|
117 ;;; End: *** |
|
118 */ |