| 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/ast/ast.h" | 10 #include "src/ast/ast.h" |
| (...skipping 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 Scope* Scope::GetOuterScopeWithContext() { | 1240 Scope* Scope::GetOuterScopeWithContext() { |
| 1241 Scope* scope = outer_scope_; | 1241 Scope* scope = outer_scope_; |
| 1242 while (scope && !scope->NeedsContext()) { | 1242 while (scope && !scope->NeedsContext()) { |
| 1243 scope = scope->outer_scope(); | 1243 scope = scope->outer_scope(); |
| 1244 } | 1244 } |
| 1245 return scope; | 1245 return scope; |
| 1246 } | 1246 } |
| 1247 | 1247 |
| 1248 Handle<StringSet> DeclarationScope::CollectNonLocals( | 1248 Handle<StringSet> DeclarationScope::CollectNonLocals( |
| 1249 ParseInfo* info, Handle<StringSet> non_locals) { | 1249 ParseInfo* info, Handle<StringSet> non_locals) { |
| 1250 VariableProxy* free_variables = FetchFreeVariables(this, true, info); | 1250 VariableProxy* free_variables = FetchFreeVariables(this, true); |
| 1251 for (VariableProxy* proxy = free_variables; proxy != nullptr; | 1251 for (VariableProxy* proxy = free_variables; proxy != nullptr; |
| 1252 proxy = proxy->next_unresolved()) { | 1252 proxy = proxy->next_unresolved()) { |
| 1253 non_locals = StringSet::Add(non_locals, proxy->name()); | 1253 non_locals = StringSet::Add(non_locals, proxy->name()); |
| 1254 } | 1254 } |
| 1255 return non_locals; | 1255 return non_locals; |
| 1256 } | 1256 } |
| 1257 | 1257 |
| 1258 void DeclarationScope::ResetAfterPreparsing(AstValueFactory* ast_value_factory, | 1258 void DeclarationScope::ResetAfterPreparsing(AstValueFactory* ast_value_factory, |
| 1259 bool aborted) { | 1259 bool aborted) { |
| 1260 DCHECK(is_function_scope()); | 1260 DCHECK(is_function_scope()); |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1727 ResolveVariable(info, proxy); | 1727 ResolveVariable(info, proxy); |
| 1728 } | 1728 } |
| 1729 | 1729 |
| 1730 // Resolve unresolved variables for inner scopes. | 1730 // Resolve unresolved variables for inner scopes. |
| 1731 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { | 1731 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { |
| 1732 scope->ResolveVariablesRecursively(info); | 1732 scope->ResolveVariablesRecursively(info); |
| 1733 } | 1733 } |
| 1734 } | 1734 } |
| 1735 | 1735 |
| 1736 VariableProxy* Scope::FetchFreeVariables(DeclarationScope* max_outer_scope, | 1736 VariableProxy* Scope::FetchFreeVariables(DeclarationScope* max_outer_scope, |
| 1737 bool try_to_resolve, ParseInfo* info, | 1737 bool try_to_resolve, |
| 1738 VariableProxy* stack) { | 1738 VariableProxy* stack) { |
| 1739 for (VariableProxy *proxy = unresolved_, *next = nullptr; proxy != nullptr; | 1739 for (VariableProxy *proxy = unresolved_, *next = nullptr; proxy != nullptr; |
| 1740 proxy = next) { | 1740 proxy = next) { |
| 1741 next = proxy->next_unresolved(); | 1741 next = proxy->next_unresolved(); |
| 1742 DCHECK(!proxy->is_resolved()); | 1742 DCHECK(!proxy->is_resolved()); |
| 1743 Variable* var = nullptr; | 1743 Variable* var = nullptr; |
| 1744 if (try_to_resolve) { | 1744 if (try_to_resolve) { |
| 1745 var = LookupRecursive(proxy, max_outer_scope->outer_scope()); | 1745 var = LookupRecursive(proxy, max_outer_scope->outer_scope()); |
| 1746 } | 1746 } |
| 1747 if (var == nullptr) { | 1747 if (var == nullptr) { |
| 1748 proxy->set_next_unresolved(stack); | 1748 proxy->set_next_unresolved(stack); |
| 1749 stack = proxy; | 1749 stack = proxy; |
| 1750 } else if (info != nullptr) { | |
| 1751 ResolveTo(info, proxy, var); | |
| 1752 } else { | 1750 } else { |
| 1753 var->set_is_used(); | 1751 var->set_is_used(); |
| 1754 } | 1752 } |
| 1755 } | 1753 } |
| 1756 | 1754 |
| 1757 // Clear unresolved_ as it's in an inconsistent state. | 1755 // Clear unresolved_ as it's in an inconsistent state. |
| 1758 unresolved_ = nullptr; | 1756 unresolved_ = nullptr; |
| 1759 | 1757 |
| 1760 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { | 1758 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { |
| 1761 stack = | 1759 stack = scope->FetchFreeVariables(max_outer_scope, try_to_resolve, stack); |
| 1762 scope->FetchFreeVariables(max_outer_scope, try_to_resolve, info, stack); | |
| 1763 } | 1760 } |
| 1764 | 1761 |
| 1765 return stack; | 1762 return stack; |
| 1766 } | 1763 } |
| 1767 | 1764 |
| 1768 bool Scope::MustAllocate(Variable* var) { | 1765 bool Scope::MustAllocate(Variable* var) { |
| 1769 DCHECK(var->location() != VariableLocation::MODULE); | 1766 DCHECK(var->location() != VariableLocation::MODULE); |
| 1770 // Give var a read/write use if there is a chance it might be accessed | 1767 // Give var a read/write use if there is a chance it might be accessed |
| 1771 // via an eval() call. This is only possible if the variable has a | 1768 // via an eval() call. This is only possible if the variable has a |
| 1772 // visible name. | 1769 // visible name. |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2027 Variable* function = | 2024 Variable* function = |
| 2028 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 2025 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
| 2029 bool is_function_var_in_context = | 2026 bool is_function_var_in_context = |
| 2030 function != nullptr && function->IsContextSlot(); | 2027 function != nullptr && function->IsContextSlot(); |
| 2031 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 2028 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 2032 (is_function_var_in_context ? 1 : 0); | 2029 (is_function_var_in_context ? 1 : 0); |
| 2033 } | 2030 } |
| 2034 | 2031 |
| 2035 } // namespace internal | 2032 } // namespace internal |
| 2036 } // namespace v8 | 2033 } // namespace v8 |
| OLD | NEW |