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/globals.h" | 9 #include "src/globals.h" |
10 #include "src/zone/zone.h" | 10 #include "src/zone/zone.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 // The AST refers to variables via VariableProxies - placeholders for the actual | 15 // The AST refers to variables via VariableProxies - placeholders for the actual |
16 // variables. Variables themselves are never directly referred to from the AST, | 16 // variables. Variables themselves are never directly referred to from the AST, |
17 // 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 |
18 // after binding and variable allocation. | 18 // after binding and variable allocation. |
19 class Variable final : public ZoneObject { | 19 class Variable final : public ZoneObject { |
20 public: | 20 public: |
21 Variable(Scope* scope, const AstRawString* name, VariableMode mode, | 21 Variable(Scope* scope, const AstRawString* name, VariableMode mode, |
22 VariableKind kind, InitializationFlag initialization_flag, | 22 VariableKind kind, InitializationFlag initialization_flag, |
23 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); | 23 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned) |
| 24 : scope_(scope), |
| 25 name_(name), |
| 26 local_if_not_shadowed_(nullptr), |
| 27 next_(nullptr), |
| 28 index_(-1), |
| 29 initializer_position_(kNoSourcePosition), |
| 30 bit_field_(MaybeAssignedFlagField::encode(maybe_assigned_flag) | |
| 31 InitializationFlagField::encode(initialization_flag) | |
| 32 VariableModeField::encode(mode) | |
| 33 IsUsedField::encode(false) | |
| 34 ForceContextAllocationField::encode(false) | |
| 35 ForceHoleInitializationField::encode(false) | |
| 36 LocationField::encode(VariableLocation::UNALLOCATED) | |
| 37 VariableKindField::encode(kind)) { |
| 38 // Var declared variables never need initialization. |
| 39 DCHECK(!(mode == VAR && initialization_flag == kNeedsInitialization)); |
| 40 } |
24 | 41 |
25 // The source code for an eval() call may refer to a variable that is | 42 // The source code for an eval() call may refer to a variable that is |
26 // in an outer scope about which we don't know anything (it may not | 43 // in an outer scope about which we don't know anything (it may not |
27 // be the script scope). scope() is NULL in that case. Currently the | 44 // be the script scope). scope() is NULL in that case. Currently the |
28 // scope is only used to follow the context chain length. | 45 // scope is only used to follow the context chain length. |
29 Scope* scope() const { return scope_; } | 46 Scope* scope() const { return scope_; } |
30 | 47 |
31 // This is for adjusting the scope of temporaries used when desugaring | 48 // This is for adjusting the scope of temporaries used when desugaring |
32 // parameter initializers. | 49 // parameter initializers. |
33 void set_scope(Scope* scope) { scope_ = scope; } | 50 void set_scope(Scope* scope) { scope_ = scope; } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 class MaybeAssignedFlagField | 208 class MaybeAssignedFlagField |
192 : public BitField16<MaybeAssignedFlag, | 209 : public BitField16<MaybeAssignedFlag, |
193 ForceHoleInitializationField::kNext, 1> {}; | 210 ForceHoleInitializationField::kNext, 1> {}; |
194 Variable** next() { return &next_; } | 211 Variable** next() { return &next_; } |
195 friend List; | 212 friend List; |
196 }; | 213 }; |
197 } // namespace internal | 214 } // namespace internal |
198 } // namespace v8 | 215 } // namespace v8 |
199 | 216 |
200 #endif // V8_AST_VARIABLES_H_ | 217 #endif // V8_AST_VARIABLES_H_ |
OLD | NEW |