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 { NORMAL, FUNCTION, THIS, ARGUMENTS }; | 20 enum Kind : uint8_t { |
| 21 NORMAL, |
| 22 FUNCTION, |
| 23 THIS, |
| 24 ARGUMENTS, |
| 25 kLastKind = ARGUMENTS |
| 26 }; |
21 | 27 |
22 Variable(Scope* scope, const AstRawString* name, VariableMode mode, Kind kind, | 28 Variable(Scope* scope, const AstRawString* name, VariableMode mode, Kind kind, |
23 InitializationFlag initialization_flag, | 29 InitializationFlag initialization_flag, |
24 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); | 30 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); |
25 | 31 |
26 // Printing support | 32 // Printing support |
27 static const char* Mode2String(VariableMode mode); | 33 static const char* Mode2String(VariableMode mode); |
28 | 34 |
29 // The source code for an eval() call may refer to a variable that is | 35 // The source code for an eval() call may refer to a variable that is |
30 // in an outer scope about which we don't know anything (it may not | 36 // 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... |
98 void AllocateTo(VariableLocation location, int index) { | 104 void AllocateTo(VariableLocation location, int index) { |
99 location_ = location; | 105 location_ = location; |
100 index_ = index; | 106 index_ = index; |
101 } | 107 } |
102 | 108 |
103 static int CompareIndex(Variable* const* v, Variable* const* w); | 109 static int CompareIndex(Variable* const* v, Variable* const* w); |
104 | 110 |
105 private: | 111 private: |
106 Scope* scope_; | 112 Scope* scope_; |
107 const AstRawString* name_; | 113 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; |
119 | 129 |
120 // Usage info. | 130 // Usage info. |
121 bool force_context_allocation_; // set by variable resolver | 131 bool force_context_allocation_ : 1; // set by variable resolver |
122 bool is_used_; | 132 bool is_used_ : 1; |
123 InitializationFlag initialization_flag_; | 133 InitializationFlag initialization_flag_ : 2; |
124 MaybeAssignedFlag maybe_assigned_; | 134 MaybeAssignedFlag maybe_assigned_ : 2; |
125 }; | 135 }; |
126 } // namespace internal | 136 } // namespace internal |
127 } // namespace v8 | 137 } // namespace v8 |
128 | 138 |
129 #endif // V8_AST_VARIABLES_H_ | 139 #endif // V8_AST_VARIABLES_H_ |
OLD | NEW |