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