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 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 Handle<StringSet> DeclarationScope::CollectNonLocals( | 1181 Handle<StringSet> DeclarationScope::CollectNonLocals( |
1182 ParseInfo* info, Handle<StringSet> non_locals) { | 1182 ParseInfo* info, Handle<StringSet> non_locals) { |
1183 VariableProxy* free_variables = FetchFreeVariables(this, true, info); | 1183 VariableProxy* free_variables = FetchFreeVariables(this, true, info); |
1184 for (VariableProxy* proxy = free_variables; proxy != nullptr; | 1184 for (VariableProxy* proxy = free_variables; proxy != nullptr; |
1185 proxy = proxy->next_unresolved()) { | 1185 proxy = proxy->next_unresolved()) { |
1186 non_locals = StringSet::Add(non_locals, proxy->name()); | 1186 non_locals = StringSet::Add(non_locals, proxy->name()); |
1187 } | 1187 } |
1188 return non_locals; | 1188 return non_locals; |
1189 } | 1189 } |
1190 | 1190 |
| 1191 void DeclarationScope::ResetAfterPreparsing(bool aborted) { |
| 1192 // Reset all non-trivial members. |
| 1193 decls_.Clear(); |
| 1194 locals_.Clear(); |
| 1195 sloppy_block_function_map_.Clear(); |
| 1196 variables_.Clear(); |
| 1197 // Make sure we won't walk the scope tree from here on. |
| 1198 inner_scope_ = nullptr; |
| 1199 |
| 1200 // TODO(verwaest): We should properly preparse the parameters (no declarations |
| 1201 // should be created), and reparse on abort. |
| 1202 if (aborted) { |
| 1203 // Recreate declarations for parameters. |
| 1204 for (int i = 0; i < params_.length(); i++) { |
| 1205 Variable* var = params_[i]; |
| 1206 if (var->mode() == TEMPORARY) { |
| 1207 locals_.Add(var, zone()); |
| 1208 } else if (variables_.Lookup(var->raw_name()) == nullptr) { |
| 1209 variables_.Add(zone(), var); |
| 1210 locals_.Add(var, zone()); |
| 1211 } |
| 1212 } |
| 1213 } else { |
| 1214 params_.Clear(); |
| 1215 // Make sure we won't try to allocate the rest parameter. {params_} was |
| 1216 // cleared above. |
| 1217 has_rest_ = false; |
| 1218 } |
| 1219 } |
| 1220 |
1191 void DeclarationScope::AnalyzePartially(DeclarationScope* migrate_to, | 1221 void DeclarationScope::AnalyzePartially(DeclarationScope* migrate_to, |
1192 AstNodeFactory* ast_node_factory) { | 1222 AstNodeFactory* ast_node_factory) { |
1193 // Try to resolve unresolved variables for this Scope and migrate those which | 1223 // Try to resolve unresolved variables for this Scope and migrate those which |
1194 // cannot be resolved inside. It doesn't make sense to try to resolve them in | 1224 // cannot be resolved inside. It doesn't make sense to try to resolve them in |
1195 // the outer Scopes here, because they are incomplete. | 1225 // the outer Scopes here, because they are incomplete. |
1196 for (VariableProxy* proxy = | 1226 for (VariableProxy* proxy = |
1197 FetchFreeVariables(this, !FLAG_lazy_inner_functions); | 1227 FetchFreeVariables(this, !FLAG_lazy_inner_functions); |
1198 proxy != nullptr; proxy = proxy->next_unresolved()) { | 1228 proxy != nullptr; proxy = proxy->next_unresolved()) { |
1199 DCHECK(!proxy->is_resolved()); | 1229 DCHECK(!proxy->is_resolved()); |
1200 VariableProxy* copy = ast_node_factory->CopyVariableProxy(proxy); | 1230 VariableProxy* copy = ast_node_factory->CopyVariableProxy(proxy); |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1858 Variable* function = | 1888 Variable* function = |
1859 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 1889 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
1860 bool is_function_var_in_context = | 1890 bool is_function_var_in_context = |
1861 function != nullptr && function->IsContextSlot(); | 1891 function != nullptr && function->IsContextSlot(); |
1862 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1892 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1863 (is_function_var_in_context ? 1 : 0); | 1893 (is_function_var_in_context ? 1 : 0); |
1864 } | 1894 } |
1865 | 1895 |
1866 } // namespace internal | 1896 } // namespace internal |
1867 } // namespace v8 | 1897 } // namespace v8 |
OLD | NEW |