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

Side by Side Diff: src/ast/scopes.cc

Issue 2281073002: Create ScopeInfos while analyzing the Scope chain (Closed)
Patch Set: updates Created 4 years, 3 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
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 #include "src/ast/scopes.h" 5 #include "src/ast/scopes.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "src/accessors.h" 9 #include "src/accessors.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 stack_locals->Add(var, zone()); 804 stack_locals->Add(var, zone());
805 } else if (var->IsContextSlot()) { 805 } else if (var->IsContextSlot()) {
806 context_locals->Add(var, zone()); 806 context_locals->Add(var, zone());
807 } else if (var->IsGlobalSlot()) { 807 } else if (var->IsGlobalSlot()) {
808 context_globals->Add(var, zone()); 808 context_globals->Add(var, zone());
809 } 809 }
810 } 810 }
811 } 811 }
812 812
813 void DeclarationScope::AllocateVariables(ParseInfo* info) { 813 void DeclarationScope::AllocateVariables(ParseInfo* info) {
814 // 1) Propagate scope information.
815 PropagateScopeInfo(); 814 PropagateScopeInfo();
816
817 // 2) Resolve variables.
818 ResolveVariablesRecursively(info); 815 ResolveVariablesRecursively(info);
819
820 // 3) Allocate variables.
jochen (gone - plz use gerrit) 2016/08/29 09:15:48 // Do foo. foo();
821 AllocateVariablesRecursively(); 816 AllocateVariablesRecursively();
817 AllocateScopeInfosRecursively(info);
822 } 818 }
823 819
824 820
825 bool Scope::AllowsLazyParsing() const { 821 bool Scope::AllowsLazyParsing() const {
826 // If we are inside a block scope, we must parse eagerly to find out how 822 // If we are inside a block scope, we must parse eagerly to find out how
827 // to allocate variables on the block scope. At this point, declarations may 823 // to allocate variables on the block scope. At this point, declarations may
828 // not have yet been parsed. 824 // not have yet been parsed.
829 for (const Scope* s = this; s != nullptr; s = s->outer_scope_) { 825 for (const Scope* s = this; s != nullptr; s = s->outer_scope_) {
830 if (s->is_block_scope()) return false; 826 if (s->is_block_scope()) return false;
831 } 827 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 DeclarationScope* Scope::GetReceiverScope() { 896 DeclarationScope* Scope::GetReceiverScope() {
901 Scope* scope = this; 897 Scope* scope = this;
902 while (!scope->is_script_scope() && 898 while (!scope->is_script_scope() &&
903 (!scope->is_function_scope() || 899 (!scope->is_function_scope() ||
904 scope->AsDeclarationScope()->is_arrow_scope())) { 900 scope->AsDeclarationScope()->is_arrow_scope())) {
905 scope = scope->outer_scope(); 901 scope = scope->outer_scope();
906 } 902 }
907 return scope->AsDeclarationScope(); 903 return scope->AsDeclarationScope();
908 } 904 }
909 905
910
911
912 Handle<ScopeInfo> Scope::GetScopeInfo(Isolate* isolate) {
913 if (scope_info_.is_null()) {
914 scope_info_ = ScopeInfo::Create(isolate, zone(), this);
915 }
916 return scope_info_;
917 }
918
919 Handle<StringSet> DeclarationScope::CollectNonLocals( 906 Handle<StringSet> DeclarationScope::CollectNonLocals(
920 ParseInfo* info, Handle<StringSet> non_locals) { 907 ParseInfo* info, Handle<StringSet> non_locals) {
921 VariableProxy* free_variables = FetchFreeVariables(this, info); 908 VariableProxy* free_variables = FetchFreeVariables(this, info);
922 for (VariableProxy* proxy = free_variables; proxy != nullptr; 909 for (VariableProxy* proxy = free_variables; proxy != nullptr;
923 proxy = proxy->next_unresolved()) { 910 proxy = proxy->next_unresolved()) {
924 non_locals = StringSet::Add(non_locals, proxy->name()); 911 non_locals = StringSet::Add(non_locals, proxy->name());
925 } 912 }
926 return non_locals; 913 return non_locals;
927 } 914 }
928 915
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 // If we didn't allocate any locals in the local context, then we only 1579 // If we didn't allocate any locals in the local context, then we only
1593 // need the minimal number of slots if we must have a context. 1580 // need the minimal number of slots if we must have a context.
1594 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && !must_have_context) { 1581 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && !must_have_context) {
1595 num_heap_slots_ = 0; 1582 num_heap_slots_ = 0;
1596 } 1583 }
1597 1584
1598 // Allocation done. 1585 // Allocation done.
1599 DCHECK(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); 1586 DCHECK(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS);
1600 } 1587 }
1601 1588
1589 void Scope::AllocateScopeInfosRecursively(ParseInfo* info) {
1590 DCHECK(scope_info_.is_null());
1591 scope_info_ = ScopeInfo::Create(info->isolate(), zone(), this);
jochen (gone - plz use gerrit) 2016/08/29 09:15:48 the debugger wants all scopes anyways.
1592
1593 // Allocate variables for inner scopes.
marja 2016/08/29 09:26:25 This comment is a copy-paste error.
1594 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) {
1595 scope->AllocateScopeInfosRecursively(info);
1596 }
1597 }
1602 1598
1603 int Scope::StackLocalCount() const { 1599 int Scope::StackLocalCount() const {
1604 Variable* function = 1600 Variable* function =
1605 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; 1601 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
1606 return num_stack_slots() - 1602 return num_stack_slots() -
1607 (function != nullptr && function->IsStackLocal() ? 1 : 0); 1603 (function != nullptr && function->IsStackLocal() ? 1 : 0);
1608 } 1604 }
1609 1605
1610 1606
1611 int Scope::ContextLocalCount() const { 1607 int Scope::ContextLocalCount() const {
1612 if (num_heap_slots() == 0) return 0; 1608 if (num_heap_slots() == 0) return 0;
1613 Variable* function = 1609 Variable* function =
1614 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; 1610 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
1615 bool is_function_var_in_context = 1611 bool is_function_var_in_context =
1616 function != nullptr && function->IsContextSlot(); 1612 function != nullptr && function->IsContextSlot();
1617 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - 1613 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() -
1618 (is_function_var_in_context ? 1 : 0); 1614 (is_function_var_in_context ? 1 : 0);
1619 } 1615 }
1620 1616
1621 1617
1622 int Scope::ContextGlobalCount() const { return num_global_slots(); } 1618 int Scope::ContextGlobalCount() const { return num_global_slots(); }
1623 1619
1624 } // namespace internal 1620 } // namespace internal
1625 } // namespace v8 1621 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698