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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 int start_position = RelocInfo::kNoPosition, | 147 int start_position = RelocInfo::kNoPosition, |
148 int end_position = RelocInfo::kNoPosition) { | 148 int end_position = RelocInfo::kNoPosition, |
149 Variable::Kind kind = Variable::NORMAL) { | |
arv (Not doing code reviews)
2015/04/28 14:26:18
Can we keep the position last for consistency.
wingo
2015/04/28 15:07:42
Acknowledged.
| |
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 bool has_this_declaration() const { | |
359 return (is_function_scope() && !is_arrow_scope()) || is_module_scope() || | |
360 is_script_scope(); | |
arv (Not doing code reviews)
2015/04/28 14:26:18
What about eval scope?
wingo
2015/04/28 15:07:42
Doesn't declare a "this" :) Grep the spec for Get
| |
361 } | |
350 | 362 |
351 // The variable corresponding to the 'new.target' value. | 363 // The variable corresponding to the 'new.target' value. |
352 Variable* new_target_var() { return new_target_; } | 364 Variable* new_target_var() { return new_target_; } |
353 | 365 |
354 // The variable holding the function literal for named function | 366 // The variable holding the function literal for named function |
355 // literals, or NULL. Only valid for function scopes. | 367 // literals, or NULL. Only valid for function scopes. |
356 VariableDeclaration* function() const { | 368 VariableDeclaration* function() const { |
357 DCHECK(is_function_scope()); | 369 DCHECK(is_function_scope()); |
358 return function_; | 370 return function_; |
359 } | 371 } |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
699 bool MustAllocateInContext(Variable* var); | 711 bool MustAllocateInContext(Variable* var); |
700 bool HasArgumentsParameter(Isolate* isolate); | 712 bool HasArgumentsParameter(Isolate* isolate); |
701 | 713 |
702 // Variable allocation. | 714 // Variable allocation. |
703 void AllocateStackSlot(Variable* var); | 715 void AllocateStackSlot(Variable* var); |
704 void AllocateHeapSlot(Variable* var); | 716 void AllocateHeapSlot(Variable* var); |
705 void AllocateParameterLocals(Isolate* isolate); | 717 void AllocateParameterLocals(Isolate* isolate); |
706 void AllocateNonParameterLocal(Isolate* isolate, Variable* var); | 718 void AllocateNonParameterLocal(Isolate* isolate, Variable* var); |
707 void AllocateNonParameterLocals(Isolate* isolate); | 719 void AllocateNonParameterLocals(Isolate* isolate); |
708 void AllocateVariablesRecursively(Isolate* isolate); | 720 void AllocateVariablesRecursively(Isolate* isolate); |
721 void AllocateParameter(Variable* var, int index); | |
722 void AllocateReceiver(); | |
709 void AllocateModules(); | 723 void AllocateModules(); |
710 | 724 |
711 // Resolve and fill in the allocation information for all variables | 725 // Resolve and fill in the allocation information for all variables |
712 // in this scopes. Must be called *after* all scopes have been | 726 // in this scopes. Must be called *after* all scopes have been |
713 // processed (parsed) to ensure that unresolved variables can be | 727 // processed (parsed) to ensure that unresolved variables can be |
714 // resolved properly. | 728 // resolved properly. |
715 // | 729 // |
716 // In the case of code compiled and run using 'eval', the context | 730 // 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 | 731 // parameter is the context in which eval was called. In all other |
718 // cases the context parameter is an empty handle. | 732 // cases the context parameter is an empty handle. |
(...skipping 26 matching lines...) Expand all Loading... | |
745 PendingCompilationErrorHandler pending_error_handler_; | 759 PendingCompilationErrorHandler pending_error_handler_; |
746 | 760 |
747 // For tracking which classes are declared consecutively. Needed for strong | 761 // For tracking which classes are declared consecutively. Needed for strong |
748 // mode. | 762 // mode. |
749 int class_declaration_group_start_; | 763 int class_declaration_group_start_; |
750 }; | 764 }; |
751 | 765 |
752 } } // namespace v8::internal | 766 } } // namespace v8::internal |
753 | 767 |
754 #endif // V8_SCOPES_H_ | 768 #endif // V8_SCOPES_H_ |
OLD | NEW |