| 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" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 // Declare an implicit global variable in this scope which must be a | 138 // Declare an implicit global variable in this scope which must be a |
| 139 // script scope. The variable was introduced (possibly from an inner | 139 // script scope. The variable was introduced (possibly from an inner |
| 140 // scope) by a reference to an unresolved variable with no intervening | 140 // scope) by a reference to an unresolved variable with no intervening |
| 141 // with statements or eval calls. | 141 // with statements or eval calls. |
| 142 Variable* DeclareDynamicGlobal(const AstRawString* name); | 142 Variable* DeclareDynamicGlobal(const AstRawString* name); |
| 143 | 143 |
| 144 // Create a new unresolved variable. | 144 // Create a new unresolved variable. |
| 145 VariableProxy* NewUnresolved(AstNodeFactory* factory, | 145 VariableProxy* NewUnresolved(AstNodeFactory* factory, |
| 146 const AstRawString* name, | 146 const AstRawString* name, |
| 147 Variable::Kind kind = Variable::NORMAL, |
| 147 int start_position = RelocInfo::kNoPosition, | 148 int start_position = RelocInfo::kNoPosition, |
| 148 int end_position = RelocInfo::kNoPosition) { | 149 int end_position = RelocInfo::kNoPosition) { |
| 149 // Note that we must not share the unresolved variables with | 150 // Note that we must not share the unresolved variables with |
| 150 // the same name because they may be removed selectively via | 151 // the same name because they may be removed selectively via |
| 151 // RemoveUnresolved(). | 152 // RemoveUnresolved(). |
| 152 DCHECK(!already_resolved()); | 153 DCHECK(!already_resolved()); |
| 153 VariableProxy* proxy = factory->NewVariableProxy( | 154 VariableProxy* proxy = |
| 154 name, Variable::NORMAL, start_position, end_position); | 155 factory->NewVariableProxy(name, kind, start_position, end_position); |
| 155 unresolved_.Add(proxy, zone_); | 156 unresolved_.Add(proxy, zone_); |
| 156 return proxy; | 157 return proxy; |
| 157 } | 158 } |
| 158 | 159 |
| 159 // Remove a unresolved variable. During parsing, an unresolved variable | 160 // Remove a unresolved variable. During parsing, an unresolved variable |
| 160 // may have been added optimistically, but then only the variable name | 161 // may have been added optimistically, but then only the variable name |
| 161 // was used (typically for labels). If the variable was not declared, the | 162 // was used (typically for labels). If the variable was not declared, the |
| 162 // addition introduced a new unresolved variable which may end up being | 163 // addition introduced a new unresolved variable which may end up being |
| 163 // allocated globally as a "ghost" variable. RemoveUnresolved removes | 164 // allocated globally as a "ghost" variable. RemoveUnresolved removes |
| 164 // such a variable again if it was added; otherwise this is a no-op. | 165 // such a variable again if it was added; otherwise this is a no-op. |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 340 |
| 340 // The type of this scope. | 341 // The type of this scope. |
| 341 ScopeType scope_type() const { return scope_type_; } | 342 ScopeType scope_type() const { return scope_type_; } |
| 342 | 343 |
| 343 FunctionKind function_kind() const { return function_kind_; } | 344 FunctionKind function_kind() const { return function_kind_; } |
| 344 | 345 |
| 345 // The language mode of this scope. | 346 // The language mode of this scope. |
| 346 LanguageMode language_mode() const { return language_mode_; } | 347 LanguageMode language_mode() const { return language_mode_; } |
| 347 | 348 |
| 348 // The variable corresponding to the 'this' value. | 349 // The variable corresponding to the 'this' value. |
| 349 Variable* receiver() { return receiver_; } | 350 Variable* receiver() { |
| 351 DCHECK(has_this_declaration()); |
| 352 DCHECK_NOT_NULL(receiver_); |
| 353 return receiver_; |
| 354 } |
| 355 |
| 356 Variable* LookupThis() { return Lookup(ast_value_factory_->this_string()); } |
| 357 |
| 358 // TODO(wingo): Add a GLOBAL_SCOPE scope type which will lexically allocate |
| 359 // "this" (and no other variable) on the native context. Script scopes then |
| 360 // will not have a "this" declaration. |
| 361 bool has_this_declaration() const { |
| 362 return (is_function_scope() && !is_arrow_scope()) || is_module_scope() || |
| 363 is_script_scope(); |
| 364 } |
| 350 | 365 |
| 351 // The variable corresponding to the 'new.target' value. | 366 // The variable corresponding to the 'new.target' value. |
| 352 Variable* new_target_var() { return new_target_; } | 367 Variable* new_target_var() { return new_target_; } |
| 353 | 368 |
| 354 // The variable holding the function literal for named function | 369 // The variable holding the function literal for named function |
| 355 // literals, or NULL. Only valid for function scopes. | 370 // literals, or NULL. Only valid for function scopes. |
| 356 VariableDeclaration* function() const { | 371 VariableDeclaration* function() const { |
| 357 DCHECK(is_function_scope()); | 372 DCHECK(is_function_scope()); |
| 358 return function_; | 373 return function_; |
| 359 } | 374 } |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 bool MustAllocateInContext(Variable* var); | 714 bool MustAllocateInContext(Variable* var); |
| 700 bool HasArgumentsParameter(Isolate* isolate); | 715 bool HasArgumentsParameter(Isolate* isolate); |
| 701 | 716 |
| 702 // Variable allocation. | 717 // Variable allocation. |
| 703 void AllocateStackSlot(Variable* var); | 718 void AllocateStackSlot(Variable* var); |
| 704 void AllocateHeapSlot(Variable* var); | 719 void AllocateHeapSlot(Variable* var); |
| 705 void AllocateParameterLocals(Isolate* isolate); | 720 void AllocateParameterLocals(Isolate* isolate); |
| 706 void AllocateNonParameterLocal(Isolate* isolate, Variable* var); | 721 void AllocateNonParameterLocal(Isolate* isolate, Variable* var); |
| 707 void AllocateNonParameterLocals(Isolate* isolate); | 722 void AllocateNonParameterLocals(Isolate* isolate); |
| 708 void AllocateVariablesRecursively(Isolate* isolate); | 723 void AllocateVariablesRecursively(Isolate* isolate); |
| 724 void AllocateParameter(Variable* var, int index); |
| 725 void AllocateReceiver(); |
| 709 void AllocateModules(); | 726 void AllocateModules(); |
| 710 | 727 |
| 711 // Resolve and fill in the allocation information for all variables | 728 // Resolve and fill in the allocation information for all variables |
| 712 // in this scopes. Must be called *after* all scopes have been | 729 // in this scopes. Must be called *after* all scopes have been |
| 713 // processed (parsed) to ensure that unresolved variables can be | 730 // processed (parsed) to ensure that unresolved variables can be |
| 714 // resolved properly. | 731 // resolved properly. |
| 715 // | 732 // |
| 716 // In the case of code compiled and run using 'eval', the context | 733 // In the case of code compiled and run using 'eval', the context |
| 717 // parameter is the context in which eval was called. In all other | 734 // parameter is the context in which eval was called. In all other |
| 718 // cases the context parameter is an empty handle. | 735 // cases the context parameter is an empty handle. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 745 PendingCompilationErrorHandler pending_error_handler_; | 762 PendingCompilationErrorHandler pending_error_handler_; |
| 746 | 763 |
| 747 // For tracking which classes are declared consecutively. Needed for strong | 764 // For tracking which classes are declared consecutively. Needed for strong |
| 748 // mode. | 765 // mode. |
| 749 int class_declaration_group_start_; | 766 int class_declaration_group_start_; |
| 750 }; | 767 }; |
| 751 | 768 |
| 752 } } // namespace v8::internal | 769 } } // namespace v8::internal |
| 753 | 770 |
| 754 #endif // V8_SCOPES_H_ | 771 #endif // V8_SCOPES_H_ |
| OLD | NEW |