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 2160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2171 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { | 2171 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { |
2172 if (scope->is_function_scope()) continue; | 2172 if (scope->is_function_scope()) continue; |
2173 scope->AllocateDebuggerScopeInfos(isolate, outer); | 2173 scope->AllocateDebuggerScopeInfos(isolate, outer); |
2174 } | 2174 } |
2175 } | 2175 } |
2176 | 2176 |
2177 void Scope::CollectVariableData(PreParsedScopeData* data) { | 2177 void Scope::CollectVariableData(PreParsedScopeData* data) { |
2178 PreParsedScopeData::ScopeScope scope_scope(data, scope_type(), | 2178 PreParsedScopeData::ScopeScope scope_scope(data, scope_type(), |
2179 start_position(), end_position()); | 2179 start_position(), end_position()); |
2180 for (Variable* local : locals_) { | 2180 for (Variable* local : locals_) { |
2181 if (local->mode() == VAR || local->mode() == LET || | 2181 scope_scope.MaybeAddVariable(local); |
2182 local->mode() == CONST) { | |
2183 scope_scope.AddVariable(local->location(), local->maybe_assigned()); | |
2184 } | |
2185 } | 2182 } |
2186 for (Scope* inner = inner_scope_; inner != nullptr; inner = inner->sibling_) { | 2183 for (Scope* inner = inner_scope_; inner != nullptr; inner = inner->sibling_) { |
2187 inner->CollectVariableData(data); | 2184 inner->CollectVariableData(data); |
2188 } | 2185 } |
2189 } | 2186 } |
2190 | 2187 |
2191 int Scope::StackLocalCount() const { | 2188 int Scope::StackLocalCount() const { |
2192 Variable* function = | 2189 Variable* function = |
2193 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 2190 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
2194 return num_stack_slots() - | 2191 return num_stack_slots() - |
2195 (function != nullptr && function->IsStackLocal() ? 1 : 0); | 2192 (function != nullptr && function->IsStackLocal() ? 1 : 0); |
2196 } | 2193 } |
2197 | 2194 |
2198 | 2195 |
2199 int Scope::ContextLocalCount() const { | 2196 int Scope::ContextLocalCount() const { |
2200 if (num_heap_slots() == 0) return 0; | 2197 if (num_heap_slots() == 0) return 0; |
2201 Variable* function = | 2198 Variable* function = |
2202 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 2199 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
2203 bool is_function_var_in_context = | 2200 bool is_function_var_in_context = |
2204 function != nullptr && function->IsContextSlot(); | 2201 function != nullptr && function->IsContextSlot(); |
2205 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 2202 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
2206 (is_function_var_in_context ? 1 : 0); | 2203 (is_function_var_in_context ? 1 : 0); |
2207 } | 2204 } |
2208 | 2205 |
2209 } // namespace internal | 2206 } // namespace internal |
2210 } // namespace v8 | 2207 } // namespace v8 |
OLD | NEW |