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 "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/ast/scopeinfo.h" | 8 #include "src/ast/scopeinfo.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/messages.h" | 10 #include "src/messages.h" |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 int end_pos = scope->end_position(); | 835 int end_pos = scope->end_position(); |
836 DCHECK(beg_pos >= 0 && end_pos >= 0); | 836 DCHECK(beg_pos >= 0 && end_pos >= 0); |
837 if (beg_pos <= position && position < end_pos) { | 837 if (beg_pos <= position && position < end_pos) { |
838 scope->GetNestedScopeChain(isolate, chain, position); | 838 scope->GetNestedScopeChain(isolate, chain, position); |
839 return; | 839 return; |
840 } | 840 } |
841 } | 841 } |
842 } | 842 } |
843 | 843 |
844 | 844 |
| 845 void Scope::CollectNonLocals(HashMap* non_locals) { |
| 846 // Collect non-local variables referenced in the scope. |
| 847 // TODO(yangguo): store non-local variables explicitly if we can no longer |
| 848 // rely on unresolved_ to find them. |
| 849 for (int i = 0; i < unresolved_.length(); i++) { |
| 850 VariableProxy* proxy = unresolved_[i]; |
| 851 if (proxy->is_resolved() && proxy->var()->IsStackAllocated()) continue; |
| 852 Handle<String> name = proxy->name(); |
| 853 void* key = reinterpret_cast<void*>(name.location()); |
| 854 HashMap::Entry* entry = non_locals->LookupOrInsert(key, name->Hash()); |
| 855 entry->value = key; |
| 856 } |
| 857 for (int i = 0; i < inner_scopes_.length(); i++) { |
| 858 inner_scopes_[i]->CollectNonLocals(non_locals); |
| 859 } |
| 860 } |
| 861 |
| 862 |
845 void Scope::ReportMessage(int start_position, int end_position, | 863 void Scope::ReportMessage(int start_position, int end_position, |
846 MessageTemplate::Template message, | 864 MessageTemplate::Template message, |
847 const AstRawString* arg) { | 865 const AstRawString* arg) { |
848 // Propagate the error to the topmost scope targeted by this scope analysis | 866 // Propagate the error to the topmost scope targeted by this scope analysis |
849 // phase. | 867 // phase. |
850 Scope* top = this; | 868 Scope* top = this; |
851 while (!top->is_script_scope() && !top->outer_scope()->already_resolved()) { | 869 while (!top->is_script_scope() && !top->outer_scope()->already_resolved()) { |
852 top = top->outer_scope(); | 870 top = top->outer_scope(); |
853 } | 871 } |
854 | 872 |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1656 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1674 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
1657 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1675 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1658 (is_function_var_in_context ? 1 : 0); | 1676 (is_function_var_in_context ? 1 : 0); |
1659 } | 1677 } |
1660 | 1678 |
1661 | 1679 |
1662 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1680 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1663 | 1681 |
1664 } // namespace internal | 1682 } // namespace internal |
1665 } // namespace v8 | 1683 } // namespace v8 |
OLD | NEW |