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