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 #include "src/ast/variables.h" | 5 #include "src/ast/variables.h" |
6 | 6 |
7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 #include "src/globals.h" | 8 #include "src/globals.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 | 12 |
13 // ---------------------------------------------------------------------------- | 13 // ---------------------------------------------------------------------------- |
14 // Implementation Variable. | 14 // Implementation Variable. |
15 | 15 |
16 const char* Variable::Mode2String(VariableMode mode) { | |
17 switch (mode) { | |
18 case VAR: return "VAR"; | |
19 case LET: return "LET"; | |
20 case CONST: return "CONST"; | |
21 case DYNAMIC: return "DYNAMIC"; | |
22 case DYNAMIC_GLOBAL: return "DYNAMIC_GLOBAL"; | |
23 case DYNAMIC_LOCAL: return "DYNAMIC_LOCAL"; | |
24 case TEMPORARY: return "TEMPORARY"; | |
25 } | |
26 UNREACHABLE(); | |
27 return NULL; | |
28 } | |
29 | |
30 Variable::Variable(Scope* scope, const AstRawString* name, VariableMode mode, | 16 Variable::Variable(Scope* scope, const AstRawString* name, VariableMode mode, |
31 Kind kind, InitializationFlag initialization_flag, | 17 VariableKind kind, InitializationFlag initialization_flag, |
32 MaybeAssignedFlag maybe_assigned_flag) | 18 MaybeAssignedFlag maybe_assigned_flag) |
33 : scope_(scope), | 19 : scope_(scope), |
34 name_(name), | 20 name_(name), |
35 local_if_not_shadowed_(nullptr), | 21 local_if_not_shadowed_(nullptr), |
36 index_(-1), | 22 index_(-1), |
37 initializer_position_(kNoSourcePosition), | 23 initializer_position_(kNoSourcePosition), |
38 bit_field_(MaybeAssignedFlagField::encode(maybe_assigned_flag) | | 24 bit_field_(MaybeAssignedFlagField::encode(maybe_assigned_flag) | |
39 InitializationFlagField::encode(initialization_flag) | | 25 InitializationFlagField::encode(initialization_flag) | |
40 VariableModeField::encode(mode) | IsUsedField::encode(false) | | 26 VariableModeField::encode(mode) | IsUsedField::encode(false) | |
41 ForceContextAllocationField::encode(false) | | 27 ForceContextAllocationField::encode(false) | |
42 LocationField::encode(VariableLocation::UNALLOCATED) | | 28 LocationField::encode(VariableLocation::UNALLOCATED) | |
43 KindField::encode(kind)) { | 29 VariableKindField::encode(kind)) { |
44 // Var declared variables never need initialization. | 30 // Var declared variables never need initialization. |
45 DCHECK(!(mode == VAR && initialization_flag == kNeedsInitialization)); | 31 DCHECK(!(mode == VAR && initialization_flag == kNeedsInitialization)); |
46 } | 32 } |
47 | 33 |
48 | 34 |
49 bool Variable::IsGlobalObjectProperty() const { | 35 bool Variable::IsGlobalObjectProperty() const { |
50 // Temporaries are never global, they must always be allocated in the | 36 // Temporaries are never global, they must always be allocated in the |
51 // activation frame. | 37 // activation frame. |
52 return (IsDynamicVariableMode(mode()) || | 38 return (IsDynamicVariableMode(mode()) || |
53 (IsDeclaredVariableMode(mode()) && !IsLexicalVariableMode(mode()))) && | 39 (IsDeclaredVariableMode(mode()) && !IsLexicalVariableMode(mode()))) && |
54 scope_ != NULL && scope_->is_script_scope(); | 40 scope_ != NULL && scope_->is_script_scope(); |
55 } | 41 } |
56 | 42 |
57 | 43 |
58 bool Variable::IsStaticGlobalObjectProperty() const { | 44 bool Variable::IsStaticGlobalObjectProperty() const { |
59 // Temporaries are never global, they must always be allocated in the | 45 // Temporaries are never global, they must always be allocated in the |
60 // activation frame. | 46 // activation frame. |
61 return (IsDeclaredVariableMode(mode()) && !IsLexicalVariableMode(mode())) && | 47 return (IsDeclaredVariableMode(mode()) && !IsLexicalVariableMode(mode())) && |
62 scope_ != NULL && scope_->is_script_scope(); | 48 scope_ != NULL && scope_->is_script_scope(); |
63 } | 49 } |
64 | 50 |
65 | 51 |
66 } // namespace internal | 52 } // namespace internal |
67 } // namespace v8 | 53 } // namespace v8 |
OLD | NEW |