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" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 VariableLocation location() const { | 93 VariableLocation location() const { |
94 return LocationField::decode(bit_field_); | 94 return LocationField::decode(bit_field_); |
95 } | 95 } |
96 VariableKind kind() const { return VariableKindField::decode(bit_field_); } | 96 VariableKind kind() const { return VariableKindField::decode(bit_field_); } |
97 InitializationFlag initialization_flag() const { | 97 InitializationFlag initialization_flag() const { |
98 return InitializationFlagField::decode(bit_field_); | 98 return InitializationFlagField::decode(bit_field_); |
99 } | 99 } |
100 | 100 |
101 int index() const { return index_; } | 101 int index() const { return index_; } |
102 | 102 |
| 103 // Sentinel index values for module exports and imports. |
| 104 enum { kModuleExportIndex, kModuleImportIndex }; |
| 105 |
103 bool IsExport() const { | 106 bool IsExport() const { |
104 DCHECK(location() == VariableLocation::MODULE); | 107 DCHECK(location() == VariableLocation::MODULE); |
105 return index() == 0; | 108 return index() == kModuleExportIndex; |
106 } | 109 } |
107 | 110 |
108 void AllocateTo(VariableLocation location, int index) { | 111 void AllocateTo(VariableLocation location, int index) { |
109 DCHECK(IsUnallocated() || | 112 DCHECK(IsUnallocated() || |
110 (this->location() == location && this->index() == index)); | 113 (this->location() == location && this->index() == index)); |
| 114 DCHECK_IMPLIES(location == VariableLocation::MODULE, |
| 115 index == kModuleExportIndex || index == kModuleImportIndex); |
111 bit_field_ = LocationField::update(bit_field_, location); | 116 bit_field_ = LocationField::update(bit_field_, location); |
112 DCHECK_EQ(location, this->location()); | 117 DCHECK_EQ(location, this->location()); |
113 index_ = index; | 118 index_ = index; |
114 } | 119 } |
115 | 120 |
116 static InitializationFlag DefaultInitializationFlag(VariableMode mode) { | 121 static InitializationFlag DefaultInitializationFlag(VariableMode mode) { |
117 DCHECK(IsDeclaredVariableMode(mode)); | 122 DCHECK(IsDeclaredVariableMode(mode)); |
118 return mode == VAR ? kCreatedInitialized : kNeedsInitialization; | 123 return mode == VAR ? kCreatedInitialized : kNeedsInitialization; |
119 } | 124 } |
120 | 125 |
(...skipping 22 matching lines...) Expand all Loading... |
143 class InitializationFlagField | 148 class InitializationFlagField |
144 : public BitField16<InitializationFlag, IsUsedField::kNext, 2> {}; | 149 : public BitField16<InitializationFlag, IsUsedField::kNext, 2> {}; |
145 class MaybeAssignedFlagField | 150 class MaybeAssignedFlagField |
146 : public BitField16<MaybeAssignedFlag, InitializationFlagField::kNext, | 151 : public BitField16<MaybeAssignedFlag, InitializationFlagField::kNext, |
147 2> {}; | 152 2> {}; |
148 }; | 153 }; |
149 } // namespace internal | 154 } // namespace internal |
150 } // namespace v8 | 155 } // namespace v8 |
151 | 156 |
152 #endif // V8_AST_VARIABLES_H_ | 157 #endif // V8_AST_VARIABLES_H_ |
OLD | NEW |