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/ast-value-factory.h" |
9 #include "src/zone.h" | 9 #include "src/zone.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 // The AST refers to variables via VariableProxies - placeholders for the actual | 14 // The AST refers to variables via VariableProxies - placeholders for the actual |
15 // variables. Variables themselves are never directly referred to from the AST, | 15 // variables. Variables themselves are never directly referred to from the AST, |
16 // they are maintained by scopes, and referred to from VariableProxies and Slots | 16 // they are maintained by scopes, and referred to from VariableProxies and Slots |
17 // after binding and variable allocation. | 17 // after binding and variable allocation. |
18 | 18 |
19 class Variable: public ZoneObject { | 19 class Variable: public ZoneObject { |
20 public: | 20 public: |
21 enum Kind { NORMAL, THIS, NEW_TARGET, ARGUMENTS }; | 21 enum Kind { NORMAL, FUNCTION, THIS, NEW_TARGET, ARGUMENTS }; |
22 | 22 |
23 enum Location { | 23 enum Location { |
24 // Before and during variable allocation, a variable whose location is | 24 // Before and during variable allocation, a variable whose location is |
25 // not yet determined. After allocation, a variable looked up as a | 25 // not yet determined. After allocation, a variable looked up as a |
26 // property on the global object (and possibly absent). name() is the | 26 // property on the global object (and possibly absent). name() is the |
27 // variable name, index() is invalid. | 27 // variable name, index() is invalid. |
28 UNALLOCATED, | 28 UNALLOCATED, |
29 | 29 |
30 // A slot in the parameter section on the stack. index() is the | 30 // A slot in the parameter section on the stack. index() is the |
31 // parameter index, counting left-to-right. The receiver is index -1; | 31 // parameter index, counting left-to-right. The receiver is index -1; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 bool IsContextSlot() const { return location_ == CONTEXT; } | 91 bool IsContextSlot() const { return location_ == CONTEXT; } |
92 bool IsLookupSlot() const { return location_ == LOOKUP; } | 92 bool IsLookupSlot() const { return location_ == LOOKUP; } |
93 bool IsGlobalObjectProperty() const; | 93 bool IsGlobalObjectProperty() const; |
94 | 94 |
95 bool is_dynamic() const { return IsDynamicVariableMode(mode_); } | 95 bool is_dynamic() const { return IsDynamicVariableMode(mode_); } |
96 bool is_const_mode() const { return IsImmutableVariableMode(mode_); } | 96 bool is_const_mode() const { return IsImmutableVariableMode(mode_); } |
97 bool binding_needs_init() const { | 97 bool binding_needs_init() const { |
98 return initialization_flag_ == kNeedsInitialization; | 98 return initialization_flag_ == kNeedsInitialization; |
99 } | 99 } |
100 | 100 |
| 101 bool is_function() const { return kind_ == FUNCTION; } |
101 bool is_this() const { return kind_ == THIS; } | 102 bool is_this() const { return kind_ == THIS; } |
102 bool is_new_target() const { return kind_ == NEW_TARGET; } | 103 bool is_new_target() const { return kind_ == NEW_TARGET; } |
103 bool is_arguments() const { return kind_ == ARGUMENTS; } | 104 bool is_arguments() const { return kind_ == ARGUMENTS; } |
104 | 105 |
105 // True if the variable is named eval and not known to be shadowed. | 106 // True if the variable is named eval and not known to be shadowed. |
106 bool is_possibly_eval(Isolate* isolate) const { | 107 bool is_possibly_eval(Isolate* isolate) const { |
107 return IsVariable(isolate->factory()->eval_string()); | 108 return IsVariable(isolate->factory()->eval_string()); |
108 } | 109 } |
109 | 110 |
110 Variable* local_if_not_shadowed() const { | 111 Variable* local_if_not_shadowed() const { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 bool force_context_allocation_; // set by variable resolver | 152 bool force_context_allocation_; // set by variable resolver |
152 bool is_used_; | 153 bool is_used_; |
153 InitializationFlag initialization_flag_; | 154 InitializationFlag initialization_flag_; |
154 MaybeAssignedFlag maybe_assigned_; | 155 MaybeAssignedFlag maybe_assigned_; |
155 }; | 156 }; |
156 | 157 |
157 | 158 |
158 } } // namespace v8::internal | 159 } } // namespace v8::internal |
159 | 160 |
160 #endif // V8_VARIABLES_H_ | 161 #endif // V8_VARIABLES_H_ |
OLD | NEW |