| 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/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 AllocateHeapSlot(variable); | 192 AllocateHeapSlot(variable); |
| 193 } | 193 } |
| 194 | 194 |
| 195 void DeclarationScope::SetDefaults() { | 195 void DeclarationScope::SetDefaults() { |
| 196 is_declaration_scope_ = true; | 196 is_declaration_scope_ = true; |
| 197 has_simple_parameters_ = true; | 197 has_simple_parameters_ = true; |
| 198 asm_module_ = false; | 198 asm_module_ = false; |
| 199 asm_function_ = false; | 199 asm_function_ = false; |
| 200 force_eager_compilation_ = false; | 200 force_eager_compilation_ = false; |
| 201 has_arguments_parameter_ = false; | 201 has_arguments_parameter_ = false; |
| 202 scope_uses_super_property_ = false; |
| 202 receiver_ = nullptr; | 203 receiver_ = nullptr; |
| 203 new_target_ = nullptr; | 204 new_target_ = nullptr; |
| 204 function_ = nullptr; | 205 function_ = nullptr; |
| 205 arguments_ = nullptr; | 206 arguments_ = nullptr; |
| 206 this_function_ = nullptr; | 207 this_function_ = nullptr; |
| 207 arity_ = 0; | 208 arity_ = 0; |
| 208 rest_parameter_ = nullptr; | 209 rest_parameter_ = nullptr; |
| 209 rest_index_ = -1; | 210 rest_index_ = -1; |
| 210 } | 211 } |
| 211 | 212 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 222 start_position_ = kNoSourcePosition; | 223 start_position_ = kNoSourcePosition; |
| 223 end_position_ = kNoSourcePosition; | 224 end_position_ = kNoSourcePosition; |
| 224 | 225 |
| 225 num_stack_slots_ = 0; | 226 num_stack_slots_ = 0; |
| 226 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; | 227 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; |
| 227 num_global_slots_ = 0; | 228 num_global_slots_ = 0; |
| 228 | 229 |
| 229 set_language_mode(SLOPPY); | 230 set_language_mode(SLOPPY); |
| 230 | 231 |
| 231 scope_calls_eval_ = false; | 232 scope_calls_eval_ = false; |
| 232 scope_uses_super_property_ = false; | |
| 233 scope_nonlinear_ = false; | 233 scope_nonlinear_ = false; |
| 234 is_hidden_ = false; | 234 is_hidden_ = false; |
| 235 is_debug_evaluate_scope_ = false; | 235 is_debug_evaluate_scope_ = false; |
| 236 | 236 |
| 237 inner_scope_calls_eval_ = false; | 237 inner_scope_calls_eval_ = false; |
| 238 force_context_allocation_ = false; | 238 force_context_allocation_ = false; |
| 239 | 239 |
| 240 is_declaration_scope_ = false; | 240 is_declaration_scope_ = false; |
| 241 } | 241 } |
| 242 | 242 |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 outer_scope_->RemoveInnerScope(this); | 580 outer_scope_->RemoveInnerScope(this); |
| 581 outer->AddInnerScope(this); | 581 outer->AddInnerScope(this); |
| 582 outer_scope_ = outer; | 582 outer_scope_ = outer; |
| 583 } | 583 } |
| 584 | 584 |
| 585 | 585 |
| 586 void Scope::PropagateUsageFlagsToScope(Scope* other) { | 586 void Scope::PropagateUsageFlagsToScope(Scope* other) { |
| 587 DCHECK_NOT_NULL(other); | 587 DCHECK_NOT_NULL(other); |
| 588 DCHECK(!already_resolved_); | 588 DCHECK(!already_resolved_); |
| 589 DCHECK(!other->already_resolved_); | 589 DCHECK(!other->already_resolved_); |
| 590 if (uses_super_property()) other->RecordSuperPropertyUsage(); | |
| 591 if (calls_eval()) other->RecordEvalCall(); | 590 if (calls_eval()) other->RecordEvalCall(); |
| 592 } | 591 } |
| 593 | 592 |
| 594 | 593 |
| 595 Variable* Scope::LookupLocal(const AstRawString* name) { | 594 Variable* Scope::LookupLocal(const AstRawString* name) { |
| 596 Variable* result = variables_.Lookup(name); | 595 Variable* result = variables_.Lookup(name); |
| 597 if (result != NULL || scope_info_.is_null()) { | 596 if (result != NULL || scope_info_.is_null()) { |
| 598 return result; | 597 return result; |
| 599 } | 598 } |
| 600 Handle<String> name_handle = name->string(); | 599 Handle<String> name_handle = name->string(); |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 for (VariableProxy* proxy = FetchFreeVariables(this); proxy != nullptr; | 977 for (VariableProxy* proxy = FetchFreeVariables(this); proxy != nullptr; |
| 979 proxy = proxy->next_unresolved()) { | 978 proxy = proxy->next_unresolved()) { |
| 980 DCHECK(!proxy->is_resolved()); | 979 DCHECK(!proxy->is_resolved()); |
| 981 VariableProxy* copy = ast_node_factory->CopyVariableProxy(proxy); | 980 VariableProxy* copy = ast_node_factory->CopyVariableProxy(proxy); |
| 982 migrate_to->AddUnresolved(copy); | 981 migrate_to->AddUnresolved(copy); |
| 983 } | 982 } |
| 984 | 983 |
| 985 // Push scope data up to migrate_to. Note that migrate_to and this Scope | 984 // Push scope data up to migrate_to. Note that migrate_to and this Scope |
| 986 // describe the same Scope, just in different Zones. | 985 // describe the same Scope, just in different Zones. |
| 987 PropagateUsageFlagsToScope(migrate_to); | 986 PropagateUsageFlagsToScope(migrate_to); |
| 988 if (inner_scope_calls_eval_) { | 987 if (scope_uses_super_property_) migrate_to->scope_uses_super_property_ = true; |
| 989 migrate_to->inner_scope_calls_eval_ = true; | 988 if (inner_scope_calls_eval_) migrate_to->inner_scope_calls_eval_ = true; |
| 990 } | |
| 991 DCHECK(!force_eager_compilation_); | 989 DCHECK(!force_eager_compilation_); |
| 992 migrate_to->set_start_position(start_position_); | 990 migrate_to->set_start_position(start_position_); |
| 993 migrate_to->set_end_position(end_position_); | 991 migrate_to->set_end_position(end_position_); |
| 994 migrate_to->set_language_mode(language_mode()); | 992 migrate_to->set_language_mode(language_mode()); |
| 995 migrate_to->arity_ = arity_; | 993 migrate_to->arity_ = arity_; |
| 996 migrate_to->force_context_allocation_ = force_context_allocation_; | 994 migrate_to->force_context_allocation_ = force_context_allocation_; |
| 997 outer_scope_->RemoveInnerScope(this); | 995 outer_scope_->RemoveInnerScope(this); |
| 998 DCHECK_EQ(outer_scope_, migrate_to->outer_scope_); | 996 DCHECK_EQ(outer_scope_, migrate_to->outer_scope_); |
| 999 DCHECK_EQ(outer_scope_->zone(), migrate_to->zone()); | 997 DCHECK_EQ(outer_scope_->zone(), migrate_to->zone()); |
| 1000 DCHECK_EQ(NeedsHomeObject(), migrate_to->NeedsHomeObject()); | 998 DCHECK_EQ(NeedsHomeObject(), migrate_to->NeedsHomeObject()); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 PrintF("\n"); | 1137 PrintF("\n"); |
| 1140 } | 1138 } |
| 1141 | 1139 |
| 1142 // Scope info. | 1140 // Scope info. |
| 1143 if (is_strict(language_mode())) { | 1141 if (is_strict(language_mode())) { |
| 1144 Indent(n1, "// strict mode scope\n"); | 1142 Indent(n1, "// strict mode scope\n"); |
| 1145 } | 1143 } |
| 1146 if (IsAsmModule()) Indent(n1, "// scope is an asm module\n"); | 1144 if (IsAsmModule()) Indent(n1, "// scope is an asm module\n"); |
| 1147 if (IsAsmFunction()) Indent(n1, "// scope is an asm function\n"); | 1145 if (IsAsmFunction()) Indent(n1, "// scope is an asm function\n"); |
| 1148 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); | 1146 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); |
| 1149 if (scope_uses_super_property_) | 1147 if (is_declaration_scope() && AsDeclarationScope()->uses_super_property()) { |
| 1150 Indent(n1, "// scope uses 'super' property\n"); | 1148 Indent(n1, "// scope uses 'super' property\n"); |
| 1149 } |
| 1151 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); | 1150 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); |
| 1152 if (num_stack_slots_ > 0) { | 1151 if (num_stack_slots_ > 0) { |
| 1153 Indent(n1, "// "); | 1152 Indent(n1, "// "); |
| 1154 PrintF("%d stack slots\n", num_stack_slots_); | 1153 PrintF("%d stack slots\n", num_stack_slots_); |
| 1155 } | 1154 } |
| 1156 if (num_heap_slots_ > 0) { | 1155 if (num_heap_slots_ > 0) { |
| 1157 Indent(n1, "// "); | 1156 Indent(n1, "// "); |
| 1158 PrintF("%d heap slots (including %d global slots)\n", num_heap_slots_, | 1157 PrintF("%d heap slots (including %d global slots)\n", num_heap_slots_, |
| 1159 num_global_slots_); | 1158 num_global_slots_); |
| 1160 } | 1159 } |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1734 function != nullptr && function->IsContextSlot(); | 1733 function != nullptr && function->IsContextSlot(); |
| 1735 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1734 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
| 1736 (is_function_var_in_context ? 1 : 0); | 1735 (is_function_var_in_context ? 1 : 0); |
| 1737 } | 1736 } |
| 1738 | 1737 |
| 1739 | 1738 |
| 1740 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1739 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
| 1741 | 1740 |
| 1742 } // namespace internal | 1741 } // namespace internal |
| 1743 } // namespace v8 | 1742 } // namespace v8 |
| OLD | NEW |