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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
1
|
21 |
|
22 */ |
|
23 |
383
|
24 #if !defined (octave_tree_const_h) |
|
25 #define octave_tree_const_h 1 |
1
|
26 |
3503
|
27 #include <iostream> |
1728
|
28 #include <string> |
|
29 |
2475
|
30 #include "oct-alloc.h" |
500
|
31 |
3770
|
32 #include "pt-bp.h" |
2980
|
33 #include "pt-exp.h" |
164
|
34 |
2086
|
35 class octave_value_list; |
529
|
36 |
2124
|
37 class tree_walker; |
|
38 |
2390
|
39 #include "ov.h" |
581
|
40 |
1
|
41 class |
2971
|
42 tree_constant : public tree_expression |
1
|
43 { |
|
44 public: |
620
|
45 |
2879
|
46 tree_constant (int l = -1, int c = -1) |
2971
|
47 : tree_expression (l, c), val (), orig_text () { } |
620
|
48 |
2390
|
49 tree_constant (const octave_value& v, int l = -1, int c = -1) |
2971
|
50 : tree_expression (l, c), val (v), orig_text () { } |
1
|
51 |
2390
|
52 ~tree_constant (void) { } |
|
53 |
4267
|
54 bool has_magic_end (void) const { return false; } |
|
55 |
3933
|
56 void *operator new (size_t size) { return allocator.alloc (size); } |
2475
|
57 |
3933
|
58 void operator delete (void *p, size_t size) { allocator.free (p, size); } |
1
|
59 |
1558
|
60 // Type. It would be nice to eliminate the need for this. |
620
|
61 |
3933
|
62 bool is_constant (void) const { return true; } |
620
|
63 |
3933
|
64 void maybe_mutate (void) { val.maybe_mutate (); } |
2409
|
65 |
3523
|
66 void print (std::ostream& os, bool pr_as_read_syntax = false, |
2532
|
67 bool pr_orig_txt = true); |
1199
|
68 |
3523
|
69 void print_raw (std::ostream& os, bool pr_as_read_syntax = false, |
2942
|
70 bool pr_orig_txt = true); |
|
71 |
3933
|
72 bool rvalue_ok (void) const { return true; } |
1
|
73 |
2971
|
74 octave_value rvalue (void) |
3770
|
75 { |
|
76 MAYBE_DO_BREAKPOINT; |
|
77 return val; |
|
78 } |
2971
|
79 |
|
80 octave_value_list rvalue (int nargout); |
|
81 |
|
82 void accept (tree_walker& tw); |
1
|
83 |
1558
|
84 // Store the original text corresponding to this constant for later |
|
85 // pretty printing. |
620
|
86 |
3933
|
87 void stash_original_text (const std::string& s) { orig_text = s; } |
620
|
88 |
3933
|
89 std::string original_text (void) const { return orig_text; } |
2124
|
90 |
747
|
91 private: |
|
92 |
2475
|
93 // For custom memory management. |
|
94 static octave_allocator allocator; |
|
95 |
|
96 // The actual value that this constant refers to. |
2390
|
97 octave_value val; |
747
|
98 |
2475
|
99 // The original text form of this constant. |
3523
|
100 std::string orig_text; |
2988
|
101 |
|
102 // No copying! |
|
103 |
|
104 tree_constant (const tree_constant&); |
|
105 |
|
106 tree_constant& operator = (const tree_constant&); |
2390
|
107 }; |
2179
|
108 |
1
|
109 #endif |
|
110 |
|
111 /* |
|
112 ;;; Local Variables: *** |
|
113 ;;; mode: C++ *** |
|
114 ;;; End: *** |
|
115 */ |