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 for (int i = 0; i < unresolved_.length(); i++) { | |
rossberg
2015/12/09 14:53:46
This scares me! It assumes that all non-locals are
| |
848 VariableProxy* proxy = unresolved_[i]; | |
849 if (proxy->is_resolved() && proxy->var()->IsStackAllocated()) continue; | |
850 Handle<String> name = proxy->name(); | |
851 void* key = reinterpret_cast<void*>(name.location()); | |
852 HashMap::Entry* entry = non_locals->LookupOrInsert(key, name->Hash()); | |
853 entry->value = key; | |
854 } | |
855 for (int i = 0; i < inner_scopes_.length(); i++) { | |
856 inner_scopes_[i]->CollectNonLocals(non_locals); | |
857 } | |
858 } | |
859 | |
860 | |
845 void Scope::ReportMessage(int start_position, int end_position, | 861 void Scope::ReportMessage(int start_position, int end_position, |
846 MessageTemplate::Template message, | 862 MessageTemplate::Template message, |
847 const AstRawString* arg) { | 863 const AstRawString* arg) { |
848 // Propagate the error to the topmost scope targeted by this scope analysis | 864 // Propagate the error to the topmost scope targeted by this scope analysis |
849 // phase. | 865 // phase. |
850 Scope* top = this; | 866 Scope* top = this; |
851 while (!top->is_script_scope() && !top->outer_scope()->already_resolved()) { | 867 while (!top->is_script_scope() && !top->outer_scope()->already_resolved()) { |
852 top = top->outer_scope(); | 868 top = top->outer_scope(); |
853 } | 869 } |
854 | 870 |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1650 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1666 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
1651 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1667 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1652 (is_function_var_in_context ? 1 : 0); | 1668 (is_function_var_in_context ? 1 : 0); |
1653 } | 1669 } |
1654 | 1670 |
1655 | 1671 |
1656 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1672 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1657 | 1673 |
1658 } // namespace internal | 1674 } // namespace internal |
1659 } // namespace v8 | 1675 } // namespace v8 |
OLD | NEW |