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_VARIABLES_H_ | 5 #ifndef V8_VARIABLES_H_ |
6 #define V8_VARIABLES_H_ | 6 #define V8_VARIABLES_H_ |
7 | 7 |
8 #include "src/ast-value-factory.h" | 8 #include "src/ast-value-factory.h" |
9 #include "src/zone.h" | 9 #include "src/zone.h" |
10 | 10 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 int index() const { return index_; } | 117 int index() const { return index_; } |
118 InitializationFlag initialization_flag() const { | 118 InitializationFlag initialization_flag() const { |
119 return initialization_flag_; | 119 return initialization_flag_; |
120 } | 120 } |
121 | 121 |
122 void AllocateTo(VariableLocation location, int index) { | 122 void AllocateTo(VariableLocation location, int index) { |
123 location_ = location; | 123 location_ = location; |
124 index_ = index; | 124 index_ = index; |
125 } | 125 } |
126 | 126 |
| 127 void SetFromEval() { is_from_eval_ = true; } |
| 128 |
127 static int CompareIndex(Variable* const* v, Variable* const* w); | 129 static int CompareIndex(Variable* const* v, Variable* const* w); |
128 | 130 |
129 void RecordStrongModeReference(int start_position, int end_position) { | 131 void RecordStrongModeReference(int start_position, int end_position) { |
130 // Record the earliest reference to the variable. Used in error messages for | 132 // Record the earliest reference to the variable. Used in error messages for |
131 // strong mode references to undeclared variables. | 133 // strong mode references to undeclared variables. |
132 if (has_strong_mode_reference_ && | 134 if (has_strong_mode_reference_ && |
133 strong_mode_reference_start_position_ < start_position) | 135 strong_mode_reference_start_position_ < start_position) |
134 return; | 136 return; |
135 has_strong_mode_reference_ = true; | 137 has_strong_mode_reference_ = true; |
136 strong_mode_reference_start_position_ = start_position; | 138 strong_mode_reference_start_position_ = start_position; |
137 strong_mode_reference_end_position_ = end_position; | 139 strong_mode_reference_end_position_ = end_position; |
138 } | 140 } |
139 | 141 |
140 bool has_strong_mode_reference() const { return has_strong_mode_reference_; } | 142 bool has_strong_mode_reference() const { return has_strong_mode_reference_; } |
141 int strong_mode_reference_start_position() const { | 143 int strong_mode_reference_start_position() const { |
142 return strong_mode_reference_start_position_; | 144 return strong_mode_reference_start_position_; |
143 } | 145 } |
144 int strong_mode_reference_end_position() const { | 146 int strong_mode_reference_end_position() const { |
145 return strong_mode_reference_end_position_; | 147 return strong_mode_reference_end_position_; |
146 } | 148 } |
| 149 PropertyAttributes DeclarationPropertyAttributes() const { |
| 150 int property_attributes = NONE; |
| 151 if (IsImmutableVariableMode(mode_)) { |
| 152 property_attributes |= READ_ONLY; |
| 153 } |
| 154 if (is_from_eval_) { |
| 155 property_attributes |= EVAL_DECLARED; |
| 156 } |
| 157 return static_cast<PropertyAttributes>(property_attributes); |
| 158 } |
147 | 159 |
148 private: | 160 private: |
149 Scope* scope_; | 161 Scope* scope_; |
150 const AstRawString* name_; | 162 const AstRawString* name_; |
151 VariableMode mode_; | 163 VariableMode mode_; |
152 Kind kind_; | 164 Kind kind_; |
153 VariableLocation location_; | 165 VariableLocation location_; |
154 int index_; | 166 int index_; |
155 int initializer_position_; | 167 int initializer_position_; |
156 // Tracks whether the variable is bound to a VariableProxy which is in strong | 168 // Tracks whether the variable is bound to a VariableProxy which is in strong |
157 // mode, and if yes, the source location of the reference. | 169 // mode, and if yes, the source location of the reference. |
158 bool has_strong_mode_reference_; | 170 bool has_strong_mode_reference_; |
159 int strong_mode_reference_start_position_; | 171 int strong_mode_reference_start_position_; |
160 int strong_mode_reference_end_position_; | 172 int strong_mode_reference_end_position_; |
161 | 173 |
162 // If this field is set, this variable references the stored locally bound | 174 // If this field is set, this variable references the stored locally bound |
163 // variable, but it might be shadowed by variable bindings introduced by | 175 // variable, but it might be shadowed by variable bindings introduced by |
164 // sloppy 'eval' calls between the reference scope (inclusive) and the | 176 // sloppy 'eval' calls between the reference scope (inclusive) and the |
165 // binding scope (exclusive). | 177 // binding scope (exclusive). |
166 Variable* local_if_not_shadowed_; | 178 Variable* local_if_not_shadowed_; |
167 | 179 |
| 180 // True if this variable is introduced by a sloppy eval |
| 181 bool is_from_eval_; |
| 182 |
168 // Usage info. | 183 // Usage info. |
169 bool force_context_allocation_; // set by variable resolver | 184 bool force_context_allocation_; // set by variable resolver |
170 bool is_used_; | 185 bool is_used_; |
171 InitializationFlag initialization_flag_; | 186 InitializationFlag initialization_flag_; |
172 MaybeAssignedFlag maybe_assigned_; | 187 MaybeAssignedFlag maybe_assigned_; |
173 }; | 188 }; |
174 | 189 |
175 class ClassVariable : public Variable { | 190 class ClassVariable : public Variable { |
176 public: | 191 public: |
177 ClassVariable(Scope* scope, const AstRawString* name, VariableMode mode, | 192 ClassVariable(Scope* scope, const AstRawString* name, VariableMode mode, |
(...skipping 11 matching lines...) Expand all Loading... |
189 | 204 |
190 private: | 205 private: |
191 // For classes we keep track of consecutive groups of delcarations. They are | 206 // For classes we keep track of consecutive groups of delcarations. They are |
192 // needed for strong mode scoping checks. TODO(marja, rossberg): Implement | 207 // needed for strong mode scoping checks. TODO(marja, rossberg): Implement |
193 // checks for functions too. | 208 // checks for functions too. |
194 int declaration_group_start_; | 209 int declaration_group_start_; |
195 }; | 210 }; |
196 } } // namespace v8::internal | 211 } } // namespace v8::internal |
197 | 212 |
198 #endif // V8_VARIABLES_H_ | 213 #endif // V8_VARIABLES_H_ |
OLD | NEW |