Chromium Code Reviews| 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 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 force_context_allocation_ = true; | 48 force_context_allocation_ = true; |
| 49 } | 49 } |
| 50 bool is_used() { return is_used_; } | 50 bool is_used() { return is_used_; } |
| 51 void set_is_used() { is_used_ = true; } | 51 void set_is_used() { is_used_ = true; } |
| 52 MaybeAssignedFlag maybe_assigned() const { return maybe_assigned_; } | 52 MaybeAssignedFlag maybe_assigned() const { return maybe_assigned_; } |
| 53 void set_maybe_assigned() { maybe_assigned_ = kMaybeAssigned; } | 53 void set_maybe_assigned() { maybe_assigned_ = kMaybeAssigned; } |
| 54 | 54 |
| 55 int initializer_position() { return initializer_position_; } | 55 int initializer_position() { return initializer_position_; } |
| 56 void set_initializer_position(int pos) { initializer_position_ = pos; } | 56 void set_initializer_position(int pos) { initializer_position_ = pos; } |
| 57 | 57 |
| 58 bool IsVariable(Handle<String> n) const { | |
| 59 return !is_this() && name().is_identical_to(n); | |
| 60 } | |
| 61 | |
| 62 bool IsUnallocated() const { | 58 bool IsUnallocated() const { |
| 63 return location_ == VariableLocation::UNALLOCATED; | 59 return location_ == VariableLocation::UNALLOCATED; |
| 64 } | 60 } |
| 65 bool IsParameter() const { return location_ == VariableLocation::PARAMETER; } | 61 bool IsParameter() const { return location_ == VariableLocation::PARAMETER; } |
| 66 bool IsStackLocal() const { return location_ == VariableLocation::LOCAL; } | 62 bool IsStackLocal() const { return location_ == VariableLocation::LOCAL; } |
| 67 bool IsStackAllocated() const { return IsParameter() || IsStackLocal(); } | 63 bool IsStackAllocated() const { return IsParameter() || IsStackLocal(); } |
| 68 bool IsContextSlot() const { return location_ == VariableLocation::CONTEXT; } | 64 bool IsContextSlot() const { return location_ == VariableLocation::CONTEXT; } |
| 69 bool IsGlobalSlot() const { return location_ == VariableLocation::GLOBAL; } | 65 bool IsGlobalSlot() const { return location_ == VariableLocation::GLOBAL; } |
| 70 bool IsUnallocatedOrGlobalSlot() const { | 66 bool IsUnallocatedOrGlobalSlot() const { |
| 71 return IsUnallocated() || IsGlobalSlot(); | 67 return IsUnallocated() || IsGlobalSlot(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 83 bool is_function() const { return kind_ == FUNCTION; } | 79 bool is_function() const { return kind_ == FUNCTION; } |
| 84 bool is_this() const { return kind_ == THIS; } | 80 bool is_this() const { return kind_ == THIS; } |
| 85 bool is_arguments() const { return kind_ == ARGUMENTS; } | 81 bool is_arguments() const { return kind_ == ARGUMENTS; } |
| 86 | 82 |
| 87 // For script scopes, the "this" binding is provided by a ScriptContext added | 83 // For script scopes, the "this" binding is provided by a ScriptContext added |
| 88 // to the global's ScriptContextTable. This binding might not statically | 84 // to the global's ScriptContextTable. This binding might not statically |
| 89 // resolve to a Variable::THIS binding, instead being DYNAMIC_LOCAL. However | 85 // resolve to a Variable::THIS binding, instead being DYNAMIC_LOCAL. However |
| 90 // any variable named "this" does indeed refer to a Variable::THIS binding; | 86 // any variable named "this" does indeed refer to a Variable::THIS binding; |
| 91 // the grammar ensures this to be the case. So wherever a "this" binding | 87 // the grammar ensures this to be the case. So wherever a "this" binding |
| 92 // might be provided by the global, use HasThisName instead of is_this(). | 88 // might be provided by the global, use HasThisName instead of is_this(). |
| 93 bool HasThisName(Isolate* isolate) const { | 89 bool HasThisName(Isolate* isolate, |
| 94 return is_this() || *name() == *isolate->factory()->this_string(); | 90 HandleDereferenceMode deref_mode = |
| 91 HandleDereferenceMode::kHandleDereferenceAllowed) const { | |
| 92 return is_this() || | |
| 93 name_is_identical_to(isolate->factory()->this_string(), deref_mode); | |
|
marja
2016/08/08 08:20:13
If handle dereferencing is not allowed (i.e., we a
rmcilroy
2016/08/08 13:05:56
I believe it is OK to access constant heap roots o
| |
| 95 } | 94 } |
| 96 | 95 |
| 97 // True if the variable is named eval and not known to be shadowed. | 96 // True if the variable is named eval and not known to be shadowed. |
| 98 bool is_possibly_eval(Isolate* isolate) const { | 97 bool is_possibly_eval( |
| 99 return IsVariable(isolate->factory()->eval_string()); | 98 Isolate* isolate, |
| 99 HandleDereferenceMode deref_mode = | |
| 100 HandleDereferenceMode::kHandleDereferenceAllowed) const { | |
| 101 return !is_this() && | |
| 102 name_is_identical_to(isolate->factory()->eval_string(), deref_mode); | |
| 100 } | 103 } |
| 101 | 104 |
| 102 Variable* local_if_not_shadowed() const { | 105 Variable* local_if_not_shadowed() const { |
| 103 DCHECK(mode_ == DYNAMIC_LOCAL && local_if_not_shadowed_ != NULL); | 106 DCHECK(mode_ == DYNAMIC_LOCAL && local_if_not_shadowed_ != NULL); |
| 104 return local_if_not_shadowed_; | 107 return local_if_not_shadowed_; |
| 105 } | 108 } |
| 106 | 109 |
| 107 void set_local_if_not_shadowed(Variable* local) { | 110 void set_local_if_not_shadowed(Variable* local) { |
| 108 local_if_not_shadowed_ = local; | 111 local_if_not_shadowed_ = local; |
| 109 } | 112 } |
| 110 | 113 |
| 111 VariableLocation location() const { return location_; } | 114 VariableLocation location() const { return location_; } |
| 112 int index() const { return index_; } | 115 int index() const { return index_; } |
| 113 InitializationFlag initialization_flag() const { | 116 InitializationFlag initialization_flag() const { |
| 114 return initialization_flag_; | 117 return initialization_flag_; |
| 115 } | 118 } |
| 116 | 119 |
| 117 void AllocateTo(VariableLocation location, int index) { | 120 void AllocateTo(VariableLocation location, int index) { |
| 118 location_ = location; | 121 location_ = location; |
| 119 index_ = index; | 122 index_ = index; |
| 120 } | 123 } |
| 121 | 124 |
| 122 static int CompareIndex(Variable* const* v, Variable* const* w); | 125 static int CompareIndex(Variable* const* v, Variable* const* w); |
| 123 | 126 |
| 124 private: | 127 private: |
| 128 bool name_is_identical_to(Handle<Object> object, | |
| 129 HandleDereferenceMode deref_mode) const { | |
| 130 if (deref_mode == HandleDereferenceMode::kHandleDereferenceAllowed) { | |
| 131 return *name() == *object; | |
| 132 } else { | |
| 133 // If handle dereference isn't allowed use the handle address for | |
| 134 // identity. This depends on the variable name being internalized in a | |
| 135 // CanonicalHandleScope. | |
| 136 return name().address() == object.address(); | |
| 137 } | |
| 138 } | |
| 139 | |
| 125 Scope* scope_; | 140 Scope* scope_; |
| 126 const AstRawString* name_; | 141 const AstRawString* name_; |
| 127 VariableMode mode_; | 142 VariableMode mode_; |
| 128 Kind kind_; | 143 Kind kind_; |
| 129 VariableLocation location_; | 144 VariableLocation location_; |
| 130 int index_; | 145 int index_; |
| 131 int initializer_position_; | 146 int initializer_position_; |
| 132 | 147 |
| 133 // If this field is set, this variable references the stored locally bound | 148 // If this field is set, this variable references the stored locally bound |
| 134 // variable, but it might be shadowed by variable bindings introduced by | 149 // variable, but it might be shadowed by variable bindings introduced by |
| 135 // sloppy 'eval' calls between the reference scope (inclusive) and the | 150 // sloppy 'eval' calls between the reference scope (inclusive) and the |
| 136 // binding scope (exclusive). | 151 // binding scope (exclusive). |
| 137 Variable* local_if_not_shadowed_; | 152 Variable* local_if_not_shadowed_; |
| 138 | 153 |
| 139 // Usage info. | 154 // Usage info. |
| 140 bool force_context_allocation_; // set by variable resolver | 155 bool force_context_allocation_; // set by variable resolver |
| 141 bool is_used_; | 156 bool is_used_; |
| 142 InitializationFlag initialization_flag_; | 157 InitializationFlag initialization_flag_; |
| 143 MaybeAssignedFlag maybe_assigned_; | 158 MaybeAssignedFlag maybe_assigned_; |
| 144 }; | 159 }; |
| 145 } // namespace internal | 160 } // namespace internal |
| 146 } // namespace v8 | 161 } // namespace v8 |
| 147 | 162 |
| 148 #endif // V8_AST_VARIABLES_H_ | 163 #endif // V8_AST_VARIABLES_H_ |
| OLD | NEW |