| 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 : uint8_t { |
| 21 NORMAL, | 21 NORMAL, |
| 22 FUNCTION, | 22 FUNCTION, |
| 23 THIS, | 23 THIS, |
| 24 ARGUMENTS, | 24 ARGUMENTS, |
| 25 kLastKind = ARGUMENTS | 25 SLOPPY_FUNCTION_NAME, |
| 26 kLastKind = SLOPPY_FUNCTION_NAME |
| 26 }; | 27 }; |
| 27 | 28 |
| 28 Variable(Scope* scope, const AstRawString* name, VariableMode mode, Kind kind, | 29 Variable(Scope* scope, const AstRawString* name, VariableMode mode, Kind kind, |
| 29 InitializationFlag initialization_flag, | 30 InitializationFlag initialization_flag, |
| 30 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); | 31 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); |
| 31 | 32 |
| 32 // Printing support | 33 // Printing support |
| 33 static const char* Mode2String(VariableMode mode); | 34 static const char* Mode2String(VariableMode mode); |
| 34 | 35 |
| 35 // The source code for an eval() call may refer to a variable that is | 36 // The source code for an eval() call may refer to a variable that is |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 70 } |
| 70 bool IsParameter() const { return location() == VariableLocation::PARAMETER; } | 71 bool IsParameter() const { return location() == VariableLocation::PARAMETER; } |
| 71 bool IsStackLocal() const { return location() == VariableLocation::LOCAL; } | 72 bool IsStackLocal() const { return location() == VariableLocation::LOCAL; } |
| 72 bool IsStackAllocated() const { return IsParameter() || IsStackLocal(); } | 73 bool IsStackAllocated() const { return IsParameter() || IsStackLocal(); } |
| 73 bool IsContextSlot() const { return location() == VariableLocation::CONTEXT; } | 74 bool IsContextSlot() const { return location() == VariableLocation::CONTEXT; } |
| 74 bool IsLookupSlot() const { return location() == VariableLocation::LOOKUP; } | 75 bool IsLookupSlot() const { return location() == VariableLocation::LOOKUP; } |
| 75 bool IsGlobalObjectProperty() const; | 76 bool IsGlobalObjectProperty() const; |
| 76 bool IsStaticGlobalObjectProperty() const; | 77 bool IsStaticGlobalObjectProperty() const; |
| 77 | 78 |
| 78 bool is_dynamic() const { return IsDynamicVariableMode(mode()); } | 79 bool is_dynamic() const { return IsDynamicVariableMode(mode()); } |
| 79 bool is_const_mode() const { return IsImmutableVariableMode(mode()); } | |
| 80 bool binding_needs_init() const { | 80 bool binding_needs_init() const { |
| 81 DCHECK(initialization_flag() != kNeedsInitialization || | 81 DCHECK(initialization_flag() != kNeedsInitialization || |
| 82 IsLexicalVariableMode(mode())); | 82 IsLexicalVariableMode(mode())); |
| 83 return initialization_flag() == kNeedsInitialization; | 83 return initialization_flag() == kNeedsInitialization; |
| 84 } | 84 } |
| 85 bool throw_on_const_assignment(LanguageMode language_mode) const { |
| 86 return kind() != SLOPPY_FUNCTION_NAME || is_strict(language_mode); |
| 87 } |
| 85 | 88 |
| 86 bool is_function() const { return kind() == FUNCTION; } | 89 bool is_function() const { return kind() == FUNCTION; } |
| 87 bool is_this() const { return kind() == THIS; } | 90 bool is_this() const { return kind() == THIS; } |
| 88 bool is_arguments() const { return kind() == ARGUMENTS; } | 91 bool is_arguments() const { return kind() == ARGUMENTS; } |
| 92 bool is_sloppy_function_name() const { |
| 93 return kind() == SLOPPY_FUNCTION_NAME; |
| 94 } |
| 89 | 95 |
| 90 Variable* local_if_not_shadowed() const { | 96 Variable* local_if_not_shadowed() const { |
| 91 DCHECK(mode() == DYNAMIC_LOCAL && local_if_not_shadowed_ != NULL); | 97 DCHECK(mode() == DYNAMIC_LOCAL && local_if_not_shadowed_ != NULL); |
| 92 return local_if_not_shadowed_; | 98 return local_if_not_shadowed_; |
| 93 } | 99 } |
| 94 | 100 |
| 95 void set_local_if_not_shadowed(Variable* local) { | 101 void set_local_if_not_shadowed(Variable* local) { |
| 96 local_if_not_shadowed_ = local; | 102 local_if_not_shadowed_ = local; |
| 97 } | 103 } |
| 98 | 104 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 121 // If this field is set, this variable references the stored locally bound | 127 // If this field is set, this variable references the stored locally bound |
| 122 // variable, but it might be shadowed by variable bindings introduced by | 128 // variable, but it might be shadowed by variable bindings introduced by |
| 123 // sloppy 'eval' calls between the reference scope (inclusive) and the | 129 // sloppy 'eval' calls between the reference scope (inclusive) and the |
| 124 // binding scope (exclusive). | 130 // binding scope (exclusive). |
| 125 Variable* local_if_not_shadowed_; | 131 Variable* local_if_not_shadowed_; |
| 126 int index_; | 132 int index_; |
| 127 int initializer_position_; | 133 int initializer_position_; |
| 128 uint16_t bit_field_; | 134 uint16_t bit_field_; |
| 129 | 135 |
| 130 class VariableModeField : public BitField16<VariableMode, 0, 3> {}; | 136 class VariableModeField : public BitField16<VariableMode, 0, 3> {}; |
| 131 class KindField : public BitField16<Kind, VariableModeField::kNext, 2> {}; | 137 class KindField : public BitField16<Kind, VariableModeField::kNext, 3> {}; |
| 132 class LocationField | 138 class LocationField |
| 133 : public BitField16<VariableLocation, KindField::kNext, 3> {}; | 139 : public BitField16<VariableLocation, KindField::kNext, 3> {}; |
| 134 class ForceContextAllocationField | 140 class ForceContextAllocationField |
| 135 : public BitField16<bool, LocationField::kNext, 1> {}; | 141 : public BitField16<bool, LocationField::kNext, 1> {}; |
| 136 class IsUsedField | 142 class IsUsedField |
| 137 : public BitField16<bool, ForceContextAllocationField::kNext, 1> {}; | 143 : public BitField16<bool, ForceContextAllocationField::kNext, 1> {}; |
| 138 class InitializationFlagField | 144 class InitializationFlagField |
| 139 : public BitField16<InitializationFlag, IsUsedField::kNext, 2> {}; | 145 : public BitField16<InitializationFlag, IsUsedField::kNext, 2> {}; |
| 140 class MaybeAssignedFlagField | 146 class MaybeAssignedFlagField |
| 141 : public BitField16<MaybeAssignedFlag, InitializationFlagField::kNext, | 147 : public BitField16<MaybeAssignedFlag, InitializationFlagField::kNext, |
| 142 2> {}; | 148 2> {}; |
| 143 }; | 149 }; |
| 144 } // namespace internal | 150 } // namespace internal |
| 145 } // namespace v8 | 151 } // namespace v8 |
| 146 | 152 |
| 147 #endif // V8_AST_VARIABLES_H_ | 153 #endif // V8_AST_VARIABLES_H_ |
| OLD | NEW |