OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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_SCOPES_H_ | 5 #ifndef V8_SCOPES_H_ |
6 #define V8_SCOPES_H_ | 6 #define V8_SCOPES_H_ |
7 | 7 |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/pending-compilation-error-handler.h" | 9 #include "src/pending-compilation-error-handler.h" |
10 #include "src/zone.h" | 10 #include "src/zone.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 class ParseInfo; | 15 class ParseInfo; |
16 | 16 |
17 // A hash map to support fast variable declaration and lookup. | 17 // A hash map to support fast variable declaration and lookup. |
18 class VariableMap: public ZoneHashMap { | 18 class VariableMap: public ZoneHashMap { |
19 public: | 19 public: |
20 explicit VariableMap(Zone* zone); | 20 explicit VariableMap(Zone* zone); |
21 | 21 |
22 virtual ~VariableMap(); | 22 virtual ~VariableMap(); |
23 | 23 |
24 Variable* Declare(Scope* scope, const AstRawString* name, VariableMode mode, | 24 Variable* Declare(Scope* scope, const AstRawString* name, VariableMode mode, |
25 bool is_valid_lhs, Variable::Kind kind, | 25 Variable::Kind kind, InitializationFlag initialization_flag, |
26 InitializationFlag initialization_flag, | |
27 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); | 26 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); |
28 | 27 |
29 Variable* Lookup(const AstRawString* name); | 28 Variable* Lookup(const AstRawString* name); |
30 | 29 |
31 Zone* zone() const { return zone_; } | 30 Zone* zone() const { return zone_; } |
32 | 31 |
33 private: | 32 private: |
34 Zone* zone_; | 33 Zone* zone_; |
35 }; | 34 }; |
36 | 35 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 | 141 |
143 // Create a new unresolved variable. | 142 // Create a new unresolved variable. |
144 VariableProxy* NewUnresolved(AstNodeFactory* factory, | 143 VariableProxy* NewUnresolved(AstNodeFactory* factory, |
145 const AstRawString* name, | 144 const AstRawString* name, |
146 int start_position = RelocInfo::kNoPosition, | 145 int start_position = RelocInfo::kNoPosition, |
147 int end_position = RelocInfo::kNoPosition) { | 146 int end_position = RelocInfo::kNoPosition) { |
148 // Note that we must not share the unresolved variables with | 147 // Note that we must not share the unresolved variables with |
149 // the same name because they may be removed selectively via | 148 // the same name because they may be removed selectively via |
150 // RemoveUnresolved(). | 149 // RemoveUnresolved(). |
151 DCHECK(!already_resolved()); | 150 DCHECK(!already_resolved()); |
152 VariableProxy* proxy = | 151 VariableProxy* proxy = factory->NewVariableProxy( |
153 factory->NewVariableProxy(name, false, start_position, end_position); | 152 name, Variable::NORMAL, start_position, end_position); |
154 unresolved_.Add(proxy, zone_); | 153 unresolved_.Add(proxy, zone_); |
155 return proxy; | 154 return proxy; |
156 } | 155 } |
157 | 156 |
158 // Remove a unresolved variable. During parsing, an unresolved variable | 157 // Remove a unresolved variable. During parsing, an unresolved variable |
159 // may have been added optimistically, but then only the variable name | 158 // may have been added optimistically, but then only the variable name |
160 // was used (typically for labels). If the variable was not declared, the | 159 // was used (typically for labels). If the variable was not declared, the |
161 // addition introduced a new unresolved variable which may end up being | 160 // addition introduced a new unresolved variable which may end up being |
162 // allocated globally as a "ghost" variable. RemoveUnresolved removes | 161 // allocated globally as a "ghost" variable. RemoveUnresolved removes |
163 // such a variable again if it was added; otherwise this is a no-op. | 162 // such a variable again if it was added; otherwise this is a no-op. |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 ScopeType scope_type() const { return scope_type_; } | 339 ScopeType scope_type() const { return scope_type_; } |
341 | 340 |
342 FunctionKind function_kind() const { return function_kind_; } | 341 FunctionKind function_kind() const { return function_kind_; } |
343 | 342 |
344 // The language mode of this scope. | 343 // The language mode of this scope. |
345 LanguageMode language_mode() const { return language_mode_; } | 344 LanguageMode language_mode() const { return language_mode_; } |
346 | 345 |
347 // The variable corresponding to the 'this' value. | 346 // The variable corresponding to the 'this' value. |
348 Variable* receiver() { return receiver_; } | 347 Variable* receiver() { return receiver_; } |
349 | 348 |
349 bool has_this_declaration() const { | |
wingo
2015/03/23 15:11:14
Given that we won't include the codegen changes in
| |
350 return !is_arrow_scope() && is_declaration_scope(); | |
351 } | |
352 | |
350 // The variable corresponding to the 'new.target' value. | 353 // The variable corresponding to the 'new.target' value. |
351 Variable* new_target_var() { return new_target_; } | 354 Variable* new_target_var() { return new_target_; } |
352 | 355 |
353 // The variable holding the function literal for named function | 356 // The variable holding the function literal for named function |
354 // literals, or NULL. Only valid for function scopes. | 357 // literals, or NULL. Only valid for function scopes. |
355 VariableDeclaration* function() const { | 358 VariableDeclaration* function() const { |
356 DCHECK(is_function_scope()); | 359 DCHECK(is_function_scope()); |
357 return function_; | 360 return function_; |
358 } | 361 } |
359 | 362 |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
727 | 730 |
728 AstValueFactory* ast_value_factory_; | 731 AstValueFactory* ast_value_factory_; |
729 Zone* zone_; | 732 Zone* zone_; |
730 | 733 |
731 PendingCompilationErrorHandler pending_error_handler_; | 734 PendingCompilationErrorHandler pending_error_handler_; |
732 }; | 735 }; |
733 | 736 |
734 } } // namespace v8::internal | 737 } } // namespace v8::internal |
735 | 738 |
736 #endif // V8_SCOPES_H_ | 739 #endif // V8_SCOPES_H_ |
OLD | NEW |