| 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/zone.h" | 9 #include "src/zone.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 | 13 |
| 14 class CompilationInfo; | 14 class CompilationInfo; |
| 15 | 15 |
| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 134 |
| 136 // Declare an implicit global variable in this scope which must be a | 135 // Declare an implicit global variable in this scope which must be a |
| 137 // script scope. The variable was introduced (possibly from an inner | 136 // script scope. The variable was introduced (possibly from an inner |
| 138 // scope) by a reference to an unresolved variable with no intervening | 137 // scope) by a reference to an unresolved variable with no intervening |
| 139 // with statements or eval calls. | 138 // with statements or eval calls. |
| 140 Variable* DeclareDynamicGlobal(const AstRawString* name); | 139 Variable* DeclareDynamicGlobal(const AstRawString* name); |
| 141 | 140 |
| 142 // Create a new unresolved variable. | 141 // Create a new unresolved variable. |
| 143 VariableProxy* NewUnresolved(AstNodeFactory* factory, | 142 VariableProxy* NewUnresolved(AstNodeFactory* factory, |
| 144 const AstRawString* name, | 143 const AstRawString* name, |
| 144 Variable::Kind variable_kind, |
| 145 int position = RelocInfo::kNoPosition) { | 145 int position = RelocInfo::kNoPosition) { |
| 146 // Note that we must not share the unresolved variables with | 146 // Note that we must not share the unresolved variables with |
| 147 // the same name because they may be removed selectively via | 147 // the same name because they may be removed selectively via |
| 148 // RemoveUnresolved(). | 148 // RemoveUnresolved(). |
| 149 DCHECK(!already_resolved()); | 149 DCHECK(!already_resolved()); |
| 150 VariableProxy* proxy = factory->NewVariableProxy(name, false, position); | 150 VariableProxy* proxy = |
| 151 factory->NewVariableProxy(name, variable_kind, position); |
| 151 unresolved_.Add(proxy, zone_); | 152 unresolved_.Add(proxy, zone_); |
| 152 return proxy; | 153 return proxy; |
| 153 } | 154 } |
| 154 | 155 |
| 155 // Remove a unresolved variable. During parsing, an unresolved variable | 156 // Remove a unresolved variable. During parsing, an unresolved variable |
| 156 // may have been added optimistically, but then only the variable name | 157 // may have been added optimistically, but then only the variable name |
| 157 // was used (typically for labels). If the variable was not declared, the | 158 // was used (typically for labels). If the variable was not declared, the |
| 158 // addition introduced a new unresolved variable which may end up being | 159 // addition introduced a new unresolved variable which may end up being |
| 159 // allocated globally as a "ghost" variable. RemoveUnresolved removes | 160 // allocated globally as a "ghost" variable. RemoveUnresolved removes |
| 160 // such a variable again if it was added; otherwise this is a no-op. | 161 // such a variable again if it was added; otherwise this is a no-op. |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 // --------------------------------------------------------------------------- | 321 // --------------------------------------------------------------------------- |
| 321 // Accessors. | 322 // Accessors. |
| 322 | 323 |
| 323 // The type of this scope. | 324 // The type of this scope. |
| 324 ScopeType scope_type() const { return scope_type_; } | 325 ScopeType scope_type() const { return scope_type_; } |
| 325 | 326 |
| 326 // The language mode of this scope. | 327 // The language mode of this scope. |
| 327 LanguageMode language_mode() const { return language_mode_; } | 328 LanguageMode language_mode() const { return language_mode_; } |
| 328 | 329 |
| 329 // The variable corresponding to the 'this' value. | 330 // The variable corresponding to the 'this' value. |
| 330 Variable* receiver() { return receiver_; } | 331 Variable* receiver() { |
| 332 DCHECK(has_this_declaration()); |
| 333 DCHECK_NOT_NULL(receiver_); |
| 334 return receiver_; |
| 335 } |
| 336 |
| 337 bool has_this_declaration() const { |
| 338 return !is_arrow_scope() && is_declaration_scope(); |
| 339 } |
| 331 | 340 |
| 332 // The variable corresponding to the 'new.target' value. | 341 // The variable corresponding to the 'new.target' value. |
| 333 Variable* new_target_var() { return new_target_; } | 342 Variable* new_target_var() { return new_target_; } |
| 334 | 343 |
| 335 // The variable holding the function literal for named function | 344 // The variable holding the function literal for named function |
| 336 // literals, or NULL. Only valid for function scopes. | 345 // literals, or NULL. Only valid for function scopes. |
| 337 VariableDeclaration* function() const { | 346 VariableDeclaration* function() const { |
| 338 DCHECK(is_function_scope()); | 347 DCHECK(is_function_scope()); |
| 339 return function_; | 348 return function_; |
| 340 } | 349 } |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 bool HasArgumentsParameter(Isolate* isolate); | 664 bool HasArgumentsParameter(Isolate* isolate); |
| 656 | 665 |
| 657 // Variable allocation. | 666 // Variable allocation. |
| 658 void AllocateStackSlot(Variable* var); | 667 void AllocateStackSlot(Variable* var); |
| 659 void AllocateHeapSlot(Variable* var); | 668 void AllocateHeapSlot(Variable* var); |
| 660 void AllocateParameterLocals(Isolate* isolate); | 669 void AllocateParameterLocals(Isolate* isolate); |
| 661 void AllocateNonParameterLocal(Isolate* isolate, Variable* var); | 670 void AllocateNonParameterLocal(Isolate* isolate, Variable* var); |
| 662 void AllocateNonParameterLocals(Isolate* isolate); | 671 void AllocateNonParameterLocals(Isolate* isolate); |
| 663 void AllocateVariablesRecursively(Isolate* isolate); | 672 void AllocateVariablesRecursively(Isolate* isolate); |
| 664 void AllocateModulesRecursively(Scope* host_scope); | 673 void AllocateModulesRecursively(Scope* host_scope); |
| 674 void AllocateParameter(Variable* var, int index); |
| 675 void AllocateReceiver(); |
| 665 | 676 |
| 666 // Resolve and fill in the allocation information for all variables | 677 // Resolve and fill in the allocation information for all variables |
| 667 // in this scopes. Must be called *after* all scopes have been | 678 // in this scopes. Must be called *after* all scopes have been |
| 668 // processed (parsed) to ensure that unresolved variables can be | 679 // processed (parsed) to ensure that unresolved variables can be |
| 669 // resolved properly. | 680 // resolved properly. |
| 670 // | 681 // |
| 671 // In the case of code compiled and run using 'eval', the context | 682 // In the case of code compiled and run using 'eval', the context |
| 672 // parameter is the context in which eval was called. In all other | 683 // parameter is the context in which eval was called. In all other |
| 673 // cases the context parameter is an empty handle. | 684 // cases the context parameter is an empty handle. |
| 674 MUST_USE_RESULT | 685 MUST_USE_RESULT |
| (...skipping 19 matching lines...) Expand all Loading... |
| 694 Scope* outer_scope, | 705 Scope* outer_scope, |
| 695 Handle<ScopeInfo> scope_info); | 706 Handle<ScopeInfo> scope_info); |
| 696 | 707 |
| 697 AstValueFactory* ast_value_factory_; | 708 AstValueFactory* ast_value_factory_; |
| 698 Zone* zone_; | 709 Zone* zone_; |
| 699 }; | 710 }; |
| 700 | 711 |
| 701 } } // namespace v8::internal | 712 } } // namespace v8::internal |
| 702 | 713 |
| 703 #endif // V8_SCOPES_H_ | 714 #endif // V8_SCOPES_H_ |
| OLD | NEW |