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_AST_VARIABLES_H_ | 5 #ifndef V8_AST_VARIABLES_H_ |
6 #define V8_AST_VARIABLES_H_ | 6 #define V8_AST_VARIABLES_H_ |
7 | 7 |
8 #include "src/ast/ast-value-factory.h" | 8 #include "src/ast/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 class Variable final : public ZoneObject { | 18 class Variable final : public ZoneObject { |
19 public: | 19 public: |
20 enum Kind : uint8_t { | 20 enum Kind { NORMAL, FUNCTION, THIS, ARGUMENTS }; |
21 NORMAL, | |
22 FUNCTION, | |
23 THIS, | |
24 ARGUMENTS, | |
25 kLastKind = ARGUMENTS | |
26 }; | |
27 | 21 |
28 Variable(Scope* scope, const AstRawString* name, VariableMode mode, Kind kind, | 22 Variable(Scope* scope, const AstRawString* name, VariableMode mode, Kind kind, |
29 InitializationFlag initialization_flag, | 23 InitializationFlag initialization_flag, |
30 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); | 24 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); |
31 | 25 |
32 // Printing support | 26 // Printing support |
33 static const char* Mode2String(VariableMode mode); | 27 static const char* Mode2String(VariableMode mode); |
34 | 28 |
35 // The source code for an eval() call may refer to a variable that is | 29 // The source code for an eval() call may refer to a variable that is |
36 // in an outer scope about which we don't know anything (it may not | 30 // in an outer scope about which we don't know anything (it may not |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 void AllocateTo(VariableLocation location, int index) { | 98 void AllocateTo(VariableLocation location, int index) { |
105 location_ = location; | 99 location_ = location; |
106 index_ = index; | 100 index_ = index; |
107 } | 101 } |
108 | 102 |
109 static int CompareIndex(Variable* const* v, Variable* const* w); | 103 static int CompareIndex(Variable* const* v, Variable* const* w); |
110 | 104 |
111 private: | 105 private: |
112 Scope* scope_; | 106 Scope* scope_; |
113 const AstRawString* name_; | 107 const AstRawString* name_; |
| 108 VariableMode mode_; |
| 109 Kind kind_; |
| 110 VariableLocation location_; |
| 111 int index_; |
| 112 int initializer_position_; |
| 113 |
114 // If this field is set, this variable references the stored locally bound | 114 // If this field is set, this variable references the stored locally bound |
115 // variable, but it might be shadowed by variable bindings introduced by | 115 // variable, but it might be shadowed by variable bindings introduced by |
116 // sloppy 'eval' calls between the reference scope (inclusive) and the | 116 // sloppy 'eval' calls between the reference scope (inclusive) and the |
117 // binding scope (exclusive). | 117 // binding scope (exclusive). |
118 Variable* local_if_not_shadowed_; | 118 Variable* local_if_not_shadowed_; |
119 int index_; | |
120 int initializer_position_; | |
121 | |
122 STATIC_ASSERT(kLastVariableMode < (1 << 3)); | |
123 VariableMode mode_ : 3; | |
124 STATIC_ASSERT(kLastKind < (1 << 2)); | |
125 Kind kind_ : 2; | |
126 STATIC_ASSERT(static_cast<uint8_t>(VariableLocation::kLastVariableLocation) < | |
127 (1 << 3)); | |
128 VariableLocation location_ : 3; | |
129 | 119 |
130 // Usage info. | 120 // Usage info. |
131 bool force_context_allocation_ : 1; // set by variable resolver | 121 bool force_context_allocation_; // set by variable resolver |
132 bool is_used_ : 1; | 122 bool is_used_; |
133 InitializationFlag initialization_flag_ : 2; | 123 InitializationFlag initialization_flag_; |
134 MaybeAssignedFlag maybe_assigned_ : 2; | 124 MaybeAssignedFlag maybe_assigned_; |
135 }; | 125 }; |
136 } // namespace internal | 126 } // namespace internal |
137 } // namespace v8 | 127 } // namespace v8 |
138 | 128 |
139 #endif // V8_AST_VARIABLES_H_ | 129 #endif // V8_AST_VARIABLES_H_ |
OLD | NEW |