Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Side by Side Diff: src/scopes.h

Issue 1140633003: Reapply "Resolve references to "this" the same way as normal variables"" (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: ScopeInfo records slot of "this" binding; formatting Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/scopeinfo.cc ('k') | src/scopes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 211
211 // Inform the scope that the corresponding code contains an eval call. 212 // Inform the scope that the corresponding code contains an eval call.
212 void RecordEvalCall() { if (!is_script_scope()) scope_calls_eval_ = true; } 213 void RecordEvalCall() { if (!is_script_scope()) scope_calls_eval_ = true; }
213 214
214 // Inform the scope that the corresponding code uses "arguments". 215 // Inform the scope that the corresponding code uses "arguments".
215 void RecordArgumentsUsage() { scope_uses_arguments_ = true; } 216 void RecordArgumentsUsage() { scope_uses_arguments_ = true; }
216 217
217 // Inform the scope that the corresponding code uses "super". 218 // Inform the scope that the corresponding code uses "super".
218 void RecordSuperPropertyUsage() { scope_uses_super_property_ = true; } 219 void RecordSuperPropertyUsage() { scope_uses_super_property_ = true; }
219 220
220 // Inform the scope that the corresponding code uses "this".
221 void RecordThisUsage() { scope_uses_this_ = true; }
222
223 // Set the language mode flag (unless disabled by a global flag). 221 // Set the language mode flag (unless disabled by a global flag).
224 void SetLanguageMode(LanguageMode language_mode) { 222 void SetLanguageMode(LanguageMode language_mode) {
225 language_mode_ = language_mode; 223 language_mode_ = language_mode;
226 } 224 }
227 225
228 // Set the ASM module flag. 226 // Set the ASM module flag.
229 void SetAsmModule() { asm_module_ = true; } 227 void SetAsmModule() { asm_module_ = true; }
230 228
231 // Position in the source where this scope begins and ends. 229 // Position in the source where this scope begins and ends.
232 // 230 //
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 // Does this scope access "arguments". 314 // Does this scope access "arguments".
317 bool uses_arguments() const { return scope_uses_arguments_; } 315 bool uses_arguments() const { return scope_uses_arguments_; }
318 // Does any inner scope access "arguments". 316 // Does any inner scope access "arguments".
319 bool inner_uses_arguments() const { return inner_scope_uses_arguments_; } 317 bool inner_uses_arguments() const { return inner_scope_uses_arguments_; }
320 // Does this scope access "super" property (super.foo). 318 // Does this scope access "super" property (super.foo).
321 bool uses_super_property() const { return scope_uses_super_property_; } 319 bool uses_super_property() const { return scope_uses_super_property_; }
322 // Does any inner scope access "super" property. 320 // Does any inner scope access "super" property.
323 bool inner_uses_super_property() const { 321 bool inner_uses_super_property() const {
324 return inner_scope_uses_super_property_; 322 return inner_scope_uses_super_property_;
325 } 323 }
326 // Does this scope access "this".
327 bool uses_this() const { return scope_uses_this_; }
328 // Does any inner scope access "this".
329 bool inner_uses_this() const { return inner_scope_uses_this_; }
330 324
331 const Scope* NearestOuterEvalScope() const { 325 const Scope* NearestOuterEvalScope() const {
332 if (is_eval_scope()) return this; 326 if (is_eval_scope()) return this;
333 if (outer_scope() == nullptr) return nullptr; 327 if (outer_scope() == nullptr) return nullptr;
334 return outer_scope()->NearestOuterEvalScope(); 328 return outer_scope()->NearestOuterEvalScope();
335 } 329 }
336 330
337 // --------------------------------------------------------------------------- 331 // ---------------------------------------------------------------------------
338 // Accessors. 332 // Accessors.
339 333
340 // The type of this scope. 334 // The type of this scope.
341 ScopeType scope_type() const { return scope_type_; } 335 ScopeType scope_type() const { return scope_type_; }
342 336
343 FunctionKind function_kind() const { return function_kind_; } 337 FunctionKind function_kind() const { return function_kind_; }
344 338
345 // The language mode of this scope. 339 // The language mode of this scope.
346 LanguageMode language_mode() const { return language_mode_; } 340 LanguageMode language_mode() const { return language_mode_; }
347 341
348 // The variable corresponding to the 'this' value. 342 // The variable corresponding to the 'this' value.
349 Variable* receiver() { return receiver_; } 343 Variable* receiver() {
344 DCHECK(has_this_declaration());
345 DCHECK_NOT_NULL(receiver_);
346 return receiver_;
347 }
348
349 Variable* LookupThis() { return Lookup(ast_value_factory_->this_string()); }
350
351 // TODO(wingo): Add a GLOBAL_SCOPE scope type which will lexically allocate
352 // "this" (and no other variable) on the native context. Script scopes then
353 // will not have a "this" declaration.
354 bool has_this_declaration() const {
355 return (is_function_scope() && !is_arrow_scope()) || is_module_scope() ||
356 is_script_scope();
357 }
350 358
351 // The variable corresponding to the 'new.target' value. 359 // The variable corresponding to the 'new.target' value.
352 Variable* new_target_var() { return new_target_; } 360 Variable* new_target_var() { return new_target_; }
353 361
354 // The variable holding the function literal for named function 362 // The variable holding the function literal for named function
355 // literals, or NULL. Only valid for function scopes. 363 // literals, or NULL. Only valid for function scopes.
356 VariableDeclaration* function() const { 364 VariableDeclaration* function() const {
357 DCHECK(is_function_scope()); 365 DCHECK(is_function_scope());
358 return function_; 366 return function_;
359 } 367 }
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 bool scope_inside_with_; 579 bool scope_inside_with_;
572 // This scope contains a 'with' statement. 580 // This scope contains a 'with' statement.
573 bool scope_contains_with_; 581 bool scope_contains_with_;
574 // This scope or a nested catch scope or with scope contain an 'eval' call. At 582 // This scope or a nested catch scope or with scope contain an 'eval' call. At
575 // the 'eval' call site this scope is the declaration scope. 583 // the 'eval' call site this scope is the declaration scope.
576 bool scope_calls_eval_; 584 bool scope_calls_eval_;
577 // This scope uses "arguments". 585 // This scope uses "arguments".
578 bool scope_uses_arguments_; 586 bool scope_uses_arguments_;
579 // This scope uses "super" property ('super.foo'). 587 // This scope uses "super" property ('super.foo').
580 bool scope_uses_super_property_; 588 bool scope_uses_super_property_;
581 // This scope uses "this".
582 bool scope_uses_this_;
583 // This scope contains an "use asm" annotation. 589 // This scope contains an "use asm" annotation.
584 bool asm_module_; 590 bool asm_module_;
585 // This scope's outer context is an asm module. 591 // This scope's outer context is an asm module.
586 bool asm_function_; 592 bool asm_function_;
587 // The language mode of this scope. 593 // The language mode of this scope.
588 LanguageMode language_mode_; 594 LanguageMode language_mode_;
589 // Source positions. 595 // Source positions.
590 int start_position_; 596 int start_position_;
591 int end_position_; 597 int end_position_;
592 598
593 // Computed via PropagateScopeInfo. 599 // Computed via PropagateScopeInfo.
594 bool outer_scope_calls_sloppy_eval_; 600 bool outer_scope_calls_sloppy_eval_;
595 bool inner_scope_calls_eval_; 601 bool inner_scope_calls_eval_;
596 bool inner_scope_uses_arguments_; 602 bool inner_scope_uses_arguments_;
597 bool inner_scope_uses_super_property_; 603 bool inner_scope_uses_super_property_;
598 bool inner_scope_uses_this_;
599 bool force_eager_compilation_; 604 bool force_eager_compilation_;
600 bool force_context_allocation_; 605 bool force_context_allocation_;
601 606
602 // True if it doesn't need scope resolution (e.g., if the scope was 607 // True if it doesn't need scope resolution (e.g., if the scope was
603 // constructed based on a serialized scope info or a catch context). 608 // constructed based on a serialized scope info or a catch context).
604 bool already_resolved_; 609 bool already_resolved_;
605 610
606 // Computed as variables are declared. 611 // Computed as variables are declared.
607 int num_var_or_const_; 612 int num_var_or_const_;
608 613
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 bool MustAllocateInContext(Variable* var); 705 bool MustAllocateInContext(Variable* var);
701 bool HasArgumentsParameter(Isolate* isolate); 706 bool HasArgumentsParameter(Isolate* isolate);
702 707
703 // Variable allocation. 708 // Variable allocation.
704 void AllocateStackSlot(Variable* var); 709 void AllocateStackSlot(Variable* var);
705 void AllocateHeapSlot(Variable* var); 710 void AllocateHeapSlot(Variable* var);
706 void AllocateParameterLocals(Isolate* isolate); 711 void AllocateParameterLocals(Isolate* isolate);
707 void AllocateNonParameterLocal(Isolate* isolate, Variable* var); 712 void AllocateNonParameterLocal(Isolate* isolate, Variable* var);
708 void AllocateNonParameterLocals(Isolate* isolate); 713 void AllocateNonParameterLocals(Isolate* isolate);
709 void AllocateVariablesRecursively(Isolate* isolate); 714 void AllocateVariablesRecursively(Isolate* isolate);
715 void AllocateParameter(Variable* var, int index);
716 void AllocateReceiver();
710 void AllocateModules(); 717 void AllocateModules();
711 718
712 // Resolve and fill in the allocation information for all variables 719 // Resolve and fill in the allocation information for all variables
713 // in this scopes. Must be called *after* all scopes have been 720 // in this scopes. Must be called *after* all scopes have been
714 // processed (parsed) to ensure that unresolved variables can be 721 // processed (parsed) to ensure that unresolved variables can be
715 // resolved properly. 722 // resolved properly.
716 // 723 //
717 // In the case of code compiled and run using 'eval', the context 724 // In the case of code compiled and run using 'eval', the context
718 // parameter is the context in which eval was called. In all other 725 // parameter is the context in which eval was called. In all other
719 // cases the context parameter is an empty handle. 726 // cases the context parameter is an empty handle.
(...skipping 26 matching lines...) Expand all
746 PendingCompilationErrorHandler pending_error_handler_; 753 PendingCompilationErrorHandler pending_error_handler_;
747 754
748 // For tracking which classes are declared consecutively. Needed for strong 755 // For tracking which classes are declared consecutively. Needed for strong
749 // mode. 756 // mode.
750 int class_declaration_group_start_; 757 int class_declaration_group_start_;
751 }; 758 };
752 759
753 } } // namespace v8::internal 760 } } // namespace v8::internal
754 761
755 #endif // V8_SCOPES_H_ 762 #endif // V8_SCOPES_H_
OLDNEW
« no previous file with comments | « src/scopeinfo.cc ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698