1
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003, |
|
4 2004, 2005, 2006, 2007 John W. Eaton |
1
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
1
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
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 |
5861
|
52 tree_constant (const octave_value& v, const std::string& ot, |
|
53 int l = -1, int c = -1) |
|
54 : tree_expression (l, c), val (v), orig_text (ot) { } |
|
55 |
2390
|
56 ~tree_constant (void) { } |
|
57 |
4267
|
58 bool has_magic_end (void) const { return false; } |
|
59 |
3933
|
60 void *operator new (size_t size) { return allocator.alloc (size); } |
2475
|
61 |
3933
|
62 void operator delete (void *p, size_t size) { allocator.free (p, size); } |
1
|
63 |
1558
|
64 // Type. It would be nice to eliminate the need for this. |
620
|
65 |
3933
|
66 bool is_constant (void) const { return true; } |
620
|
67 |
3933
|
68 void maybe_mutate (void) { val.maybe_mutate (); } |
2409
|
69 |
3523
|
70 void print (std::ostream& os, bool pr_as_read_syntax = false, |
2532
|
71 bool pr_orig_txt = true); |
1199
|
72 |
3523
|
73 void print_raw (std::ostream& os, bool pr_as_read_syntax = false, |
2942
|
74 bool pr_orig_txt = true); |
|
75 |
3933
|
76 bool rvalue_ok (void) const { return true; } |
1
|
77 |
2971
|
78 octave_value rvalue (void) |
3770
|
79 { |
|
80 MAYBE_DO_BREAKPOINT; |
|
81 return val; |
|
82 } |
2971
|
83 |
|
84 octave_value_list rvalue (int nargout); |
|
85 |
5861
|
86 tree_expression *dup (symbol_table *sym_tab); |
|
87 |
2971
|
88 void accept (tree_walker& tw); |
1
|
89 |
1558
|
90 // Store the original text corresponding to this constant for later |
|
91 // pretty printing. |
620
|
92 |
3933
|
93 void stash_original_text (const std::string& s) { orig_text = s; } |
620
|
94 |
3933
|
95 std::string original_text (void) const { return orig_text; } |
2124
|
96 |
747
|
97 private: |
|
98 |
2475
|
99 // For custom memory management. |
|
100 static octave_allocator allocator; |
|
101 |
|
102 // The actual value that this constant refers to. |
2390
|
103 octave_value val; |
747
|
104 |
2475
|
105 // The original text form of this constant. |
3523
|
106 std::string orig_text; |
2988
|
107 |
|
108 // No copying! |
|
109 |
|
110 tree_constant (const tree_constant&); |
|
111 |
|
112 tree_constant& operator = (const tree_constant&); |
2390
|
113 }; |
2179
|
114 |
1
|
115 #endif |
|
116 |
|
117 /* |
|
118 ;;; Local Variables: *** |
|
119 ;;; mode: C++ *** |
|
120 ;;; End: *** |
|
121 */ |