OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_VARIABLES_H_ | 5 #ifndef V8_VARIABLES_H_ |
6 #define V8_VARIABLES_H_ | 6 #define V8_VARIABLES_H_ |
7 | 7 |
| 8 #include "src/ast-value-factory.h" |
8 #include "src/zone.h" | 9 #include "src/zone.h" |
9 #include "src/interface.h" | 10 #include "src/interface.h" |
10 | 11 |
11 namespace v8 { | 12 namespace v8 { |
12 namespace internal { | 13 namespace internal { |
13 | 14 |
14 // The AST refers to variables via VariableProxies - placeholders for the actual | 15 // The AST refers to variables via VariableProxies - placeholders for the actual |
15 // variables. Variables themselves are never directly referred to from the AST, | 16 // variables. Variables themselves are never directly referred to from the AST, |
16 // they are maintained by scopes, and referred to from VariableProxies and Slots | 17 // they are maintained by scopes, and referred to from VariableProxies and Slots |
17 // after binding and variable allocation. | 18 // after binding and variable allocation. |
(...skipping 27 matching lines...) Expand all Loading... |
45 // corresponding scope. | 46 // corresponding scope. |
46 CONTEXT, | 47 CONTEXT, |
47 | 48 |
48 // A named slot in a heap context. name() is the variable name in the | 49 // A named slot in a heap context. name() is the variable name in the |
49 // context object on the heap, with lookup starting at the current | 50 // context object on the heap, with lookup starting at the current |
50 // context. index() is invalid. | 51 // context. index() is invalid. |
51 LOOKUP | 52 LOOKUP |
52 }; | 53 }; |
53 | 54 |
54 Variable(Scope* scope, | 55 Variable(Scope* scope, |
55 Handle<String> name, | 56 const AstString* name, |
56 VariableMode mode, | 57 VariableMode mode, |
57 bool is_valid_ref, | 58 bool is_valid_ref, |
58 Kind kind, | 59 Kind kind, |
59 InitializationFlag initialization_flag, | 60 InitializationFlag initialization_flag, |
60 Interface* interface = Interface::NewValue()); | 61 Interface* interface = Interface::NewValue()); |
61 | 62 |
62 // Printing support | 63 // Printing support |
63 static const char* Mode2String(VariableMode mode); | 64 static const char* Mode2String(VariableMode mode); |
64 | 65 |
65 bool IsValidReference() { return is_valid_ref_; } | 66 bool IsValidReference() { return is_valid_ref_; } |
66 | 67 |
67 // The source code for an eval() call may refer to a variable that is | 68 // The source code for an eval() call may refer to a variable that is |
68 // in an outer scope about which we don't know anything (it may not | 69 // in an outer scope about which we don't know anything (it may not |
69 // be the global scope). scope() is NULL in that case. Currently the | 70 // be the global scope). scope() is NULL in that case. Currently the |
70 // scope is only used to follow the context chain length. | 71 // scope is only used to follow the context chain length. |
71 Scope* scope() const { return scope_; } | 72 Scope* scope() const { return scope_; } |
72 | 73 |
73 Handle<String> name() const { return name_; } | 74 Handle<String> name() const { return name_->string(); } |
| 75 const AstString* raw_name() const { return name_; } |
74 VariableMode mode() const { return mode_; } | 76 VariableMode mode() const { return mode_; } |
75 bool has_forced_context_allocation() const { | 77 bool has_forced_context_allocation() const { |
76 return force_context_allocation_; | 78 return force_context_allocation_; |
77 } | 79 } |
78 void ForceContextAllocation() { | 80 void ForceContextAllocation() { |
79 ASSERT(mode_ != TEMPORARY); | 81 ASSERT(mode_ != TEMPORARY); |
80 force_context_allocation_ = true; | 82 force_context_allocation_ = true; |
81 } | 83 } |
82 bool is_used() { return is_used_; } | 84 bool is_used() { return is_used_; } |
83 void set_is_used(bool flag) { is_used_ = flag; } | 85 void set_is_used(bool flag) { is_used_ = flag; } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 131 |
130 void AllocateTo(Location location, int index) { | 132 void AllocateTo(Location location, int index) { |
131 location_ = location; | 133 location_ = location; |
132 index_ = index; | 134 index_ = index; |
133 } | 135 } |
134 | 136 |
135 static int CompareIndex(Variable* const* v, Variable* const* w); | 137 static int CompareIndex(Variable* const* v, Variable* const* w); |
136 | 138 |
137 private: | 139 private: |
138 Scope* scope_; | 140 Scope* scope_; |
139 Handle<String> name_; | 141 const AstString* name_; |
140 VariableMode mode_; | 142 VariableMode mode_; |
141 Kind kind_; | 143 Kind kind_; |
142 Location location_; | 144 Location location_; |
143 int index_; | 145 int index_; |
144 int initializer_position_; | 146 int initializer_position_; |
145 | 147 |
146 // If this field is set, this variable references the stored locally bound | 148 // If this field is set, this variable references the stored locally bound |
147 // variable, but it might be shadowed by variable bindings introduced by | 149 // variable, but it might be shadowed by variable bindings introduced by |
148 // sloppy 'eval' calls between the reference scope (inclusive) and the | 150 // sloppy 'eval' calls between the reference scope (inclusive) and the |
149 // binding scope (exclusive). | 151 // binding scope (exclusive). |
150 Variable* local_if_not_shadowed_; | 152 Variable* local_if_not_shadowed_; |
151 | 153 |
152 // Valid as a reference? (const and this are not valid, for example) | 154 // Valid as a reference? (const and this are not valid, for example) |
153 bool is_valid_ref_; | 155 bool is_valid_ref_; |
154 | 156 |
155 // Usage info. | 157 // Usage info. |
156 bool force_context_allocation_; // set by variable resolver | 158 bool force_context_allocation_; // set by variable resolver |
157 bool is_used_; | 159 bool is_used_; |
158 InitializationFlag initialization_flag_; | 160 InitializationFlag initialization_flag_; |
159 | 161 |
160 // Module type info. | 162 // Module type info. |
161 Interface* interface_; | 163 Interface* interface_; |
162 }; | 164 }; |
163 | 165 |
164 | 166 |
165 } } // namespace v8::internal | 167 } } // namespace v8::internal |
166 | 168 |
167 #endif // V8_VARIABLES_H_ | 169 #endif // V8_VARIABLES_H_ |
OLD | NEW |