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 #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 1576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 if (new_target_ != nullptr && !MustAllocate(new_target_)) { | 1587 if (new_target_ != nullptr && !MustAllocate(new_target_)) { |
1588 new_target_ = nullptr; | 1588 new_target_ = nullptr; |
1589 } | 1589 } |
1590 | 1590 |
1591 if (this_function_ != nullptr && !MustAllocate(this_function_)) { | 1591 if (this_function_ != nullptr && !MustAllocate(this_function_)) { |
1592 this_function_ = nullptr; | 1592 this_function_ = nullptr; |
1593 } | 1593 } |
1594 } | 1594 } |
1595 | 1595 |
1596 void ModuleScope::AllocateModuleVariables() { | 1596 void ModuleScope::AllocateModuleVariables() { |
1597 for (auto it = module()->regular_imports().begin(); | 1597 for (const auto& it : module()->regular_imports()) { |
1598 it != module()->regular_imports().end(); ++it) { | 1598 Variable* var = LookupLocal(it.first); |
1599 Variable* var = LookupLocal(it->second->local_name); | |
1600 // TODO(neis): Use a meaningful index. | 1599 // TODO(neis): Use a meaningful index. |
1601 var->AllocateTo(VariableLocation::MODULE, 42); | 1600 var->AllocateTo(VariableLocation::MODULE, 42); |
1602 } | 1601 } |
1603 | 1602 |
1604 for (auto entry : module()->exports()) { | 1603 for (const auto& it : module()->regular_exports()) { |
1605 if (entry->local_name == nullptr) continue; | 1604 Variable* var = LookupLocal(it.first); |
1606 Variable* var = LookupLocal(entry->local_name); | 1605 var->AllocateTo(VariableLocation::MODULE, 0); |
1607 var->AllocateTo(VariableLocation::MODULE, 42); | |
1608 } | 1606 } |
1609 } | 1607 } |
1610 | 1608 |
1611 void Scope::AllocateVariablesRecursively() { | 1609 void Scope::AllocateVariablesRecursively() { |
1612 DCHECK(!already_resolved_); | 1610 DCHECK(!already_resolved_); |
1613 DCHECK_EQ(0, num_stack_slots_); | 1611 DCHECK_EQ(0, num_stack_slots_); |
1614 | 1612 |
1615 // Allocate variables for inner scopes. | 1613 // Allocate variables for inner scopes. |
1616 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { | 1614 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { |
1617 scope->AllocateVariablesRecursively(); | 1615 scope->AllocateVariablesRecursively(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1668 function != nullptr && function->IsContextSlot(); | 1666 function != nullptr && function->IsContextSlot(); |
1669 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1667 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1670 (is_function_var_in_context ? 1 : 0); | 1668 (is_function_var_in_context ? 1 : 0); |
1671 } | 1669 } |
1672 | 1670 |
1673 | 1671 |
1674 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1672 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1675 | 1673 |
1676 } // namespace internal | 1674 } // namespace internal |
1677 } // namespace v8 | 1675 } // namespace v8 |
OLD | NEW |