Chromium Code Reviews

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

Issue 2270743003: Get rid of PropagateScopeInfo, update asm_function in set_asm_module instead. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« src/ast/scopes.h ('K') | « src/ast/scopes.h ('k') | no next file » | 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 #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 297 matching lines...)
308 ast_value_factory->GetString(handle(name, isolate))); 308 ast_value_factory->GetString(handle(name, isolate)));
309 } 309 }
310 if (deserialization_mode == DeserializationMode::kDeserializeOffHeap) { 310 if (deserialization_mode == DeserializationMode::kDeserializeOffHeap) {
311 current_scope->DeserializeScopeInfo(isolate, ast_value_factory); 311 current_scope->DeserializeScopeInfo(isolate, ast_value_factory);
312 } 312 }
313 if (innermost_scope == nullptr) innermost_scope = current_scope; 313 if (innermost_scope == nullptr) innermost_scope = current_scope;
314 context = context->previous(); 314 context = context->previous();
315 } 315 }
316 316
317 script_scope->AddInnerScope(current_scope); 317 script_scope->AddInnerScope(current_scope);
318 script_scope->PropagateScopeInfo();
319 return (innermost_scope == NULL) ? script_scope : innermost_scope; 318 return (innermost_scope == NULL) ? script_scope : innermost_scope;
320 } 319 }
321 320
322 void Scope::DeserializeScopeInfo(Isolate* isolate, 321 void Scope::DeserializeScopeInfo(Isolate* isolate,
323 AstValueFactory* ast_value_factory) { 322 AstValueFactory* ast_value_factory) {
324 if (scope_info_.is_null()) return; 323 if (scope_info_.is_null()) return;
325 324
326 DCHECK(ThreadId::Current().Equals(isolate->thread_id())); 325 DCHECK(ThreadId::Current().Equals(isolate->thread_id()));
327 326
328 std::set<const AstRawString*> names_seen; 327 std::set<const AstRawString*> names_seen;
(...skipping 516 matching lines...)
845 } else if (var->IsContextSlot()) { 844 } else if (var->IsContextSlot()) {
846 context_locals->Add(var, zone()); 845 context_locals->Add(var, zone());
847 } else if (var->IsGlobalSlot()) { 846 } else if (var->IsGlobalSlot()) {
848 context_globals->Add(var, zone()); 847 context_globals->Add(var, zone());
849 } 848 }
850 } 849 }
851 } 850 }
852 851
853 void DeclarationScope::AllocateVariables(ParseInfo* info, 852 void DeclarationScope::AllocateVariables(ParseInfo* info,
854 AstNodeFactory* factory) { 853 AstNodeFactory* factory) {
855 // 1) Propagate scope information. 854 // Resolve variables.
856 PropagateScopeInfo();
857
858 // 2) Resolve variables.
859 ResolveVariablesRecursively(info, factory); 855 ResolveVariablesRecursively(info, factory);
860 856 // Allocate variables.
861 // 3) Allocate variables.
862 AllocateVariablesRecursively(); 857 AllocateVariablesRecursively();
863 } 858 }
864 859
865 860
866 bool Scope::AllowsLazyParsing() const { 861 bool Scope::AllowsLazyParsing() const {
867 // If we are inside a block scope, we must parse eagerly to find out how 862 // If we are inside a block scope, we must parse eagerly to find out how
868 // to allocate variables on the block scope. At this point, declarations may 863 // to allocate variables on the block scope. At this point, declarations may
869 // not have yet been parsed. 864 // not have yet been parsed.
870 for (const Scope* s = this; s != nullptr; s = s->outer_scope_) { 865 for (const Scope* s = this; s != nullptr; s = s->outer_scope_) {
871 if (s->is_block_scope()) return false; 866 if (s->is_block_scope()) return false;
(...skipping 90 matching lines...)
962 VariableProxy* free_variables = FetchFreeVariables(this, info); 957 VariableProxy* free_variables = FetchFreeVariables(this, info);
963 for (VariableProxy* proxy = free_variables; proxy != nullptr; 958 for (VariableProxy* proxy = free_variables; proxy != nullptr;
964 proxy = proxy->next_unresolved()) { 959 proxy = proxy->next_unresolved()) {
965 non_locals = StringSet::Add(non_locals, proxy->name()); 960 non_locals = StringSet::Add(non_locals, proxy->name());
966 } 961 }
967 return non_locals; 962 return non_locals;
968 } 963 }
969 964
970 void DeclarationScope::AnalyzePartially(DeclarationScope* migrate_to, 965 void DeclarationScope::AnalyzePartially(DeclarationScope* migrate_to,
971 AstNodeFactory* ast_node_factory) { 966 AstNodeFactory* ast_node_factory) {
972 // Gather info from inner scopes.
973 PropagateScopeInfo();
974
975 // Try to resolve unresolved variables for this Scope and migrate those which 967 // Try to resolve unresolved variables for this Scope and migrate those which
976 // cannot be resolved inside. It doesn't make sense to try to resolve them in 968 // cannot be resolved inside. It doesn't make sense to try to resolve them in
977 // the outer Scopes here, because they are incomplete. 969 // the outer Scopes here, because they are incomplete.
978 for (VariableProxy* proxy = FetchFreeVariables(this); proxy != nullptr; 970 for (VariableProxy* proxy = FetchFreeVariables(this); proxy != nullptr;
979 proxy = proxy->next_unresolved()) { 971 proxy = proxy->next_unresolved()) {
980 DCHECK(!proxy->is_resolved()); 972 DCHECK(!proxy->is_resolved());
981 VariableProxy* copy = ast_node_factory->CopyVariableProxy(proxy); 973 VariableProxy* copy = ast_node_factory->CopyVariableProxy(proxy);
982 migrate_to->AddUnresolved(copy); 974 migrate_to->AddUnresolved(copy);
983 } 975 }
984 976
(...skipping 463 matching lines...)
1448 // Clear unresolved_ as it's in an inconsistent state. 1440 // Clear unresolved_ as it's in an inconsistent state.
1449 unresolved_ = nullptr; 1441 unresolved_ = nullptr;
1450 1442
1451 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { 1443 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) {
1452 stack = scope->FetchFreeVariables(max_outer_scope, info, stack); 1444 stack = scope->FetchFreeVariables(max_outer_scope, info, stack);
1453 } 1445 }
1454 1446
1455 return stack; 1447 return stack;
1456 } 1448 }
1457 1449
1458 void Scope::PropagateScopeInfo() {
1459 for (Scope* inner = inner_scope_; inner != nullptr; inner = inner->sibling_) {
1460 inner->PropagateScopeInfo();
1461 if (IsAsmModule() && inner->is_function_scope()) {
1462 inner->AsDeclarationScope()->set_asm_function();
1463 }
1464 }
1465 }
1466
1467
1468 bool Scope::MustAllocate(Variable* var) { 1450 bool Scope::MustAllocate(Variable* var) {
1469 DCHECK(var->location() != VariableLocation::MODULE); 1451 DCHECK(var->location() != VariableLocation::MODULE);
1470 // Give var a read/write use if there is a chance it might be accessed 1452 // Give var a read/write use if there is a chance it might be accessed
1471 // via an eval() call. This is only possible if the variable has a 1453 // via an eval() call. This is only possible if the variable has a
1472 // visible name. 1454 // visible name.
1473 if ((var->is_this() || !var->raw_name()->IsEmpty()) && 1455 if ((var->is_this() || !var->raw_name()->IsEmpty()) &&
1474 (inner_scope_calls_eval_ || is_catch_scope() || is_script_scope())) { 1456 (inner_scope_calls_eval_ || is_catch_scope() || is_script_scope())) {
1475 var->set_is_used(); 1457 var->set_is_used();
1476 if (inner_scope_calls_eval_) var->set_maybe_assigned(); 1458 if (inner_scope_calls_eval_) var->set_maybe_assigned();
1477 } 1459 }
(...skipping 256 matching lines...)
1734 function != nullptr && function->IsContextSlot(); 1716 function != nullptr && function->IsContextSlot();
1735 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - 1717 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() -
1736 (is_function_var_in_context ? 1 : 0); 1718 (is_function_var_in_context ? 1 : 0);
1737 } 1719 }
1738 1720
1739 1721
1740 int Scope::ContextGlobalCount() const { return num_global_slots(); } 1722 int Scope::ContextGlobalCount() const { return num_global_slots(); }
1741 1723
1742 } // namespace internal 1724 } // namespace internal
1743 } // namespace v8 1725 } // namespace v8
OLDNEW
« src/ast/scopes.h ('K') | « src/ast/scopes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine