Chromium Code Reviews| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 FunctionKind function_kind) | 128 FunctionKind function_kind) |
| 129 : Scope(zone, outer_scope, scope_type), | 129 : Scope(zone, outer_scope, scope_type), |
| 130 function_kind_(function_kind), | 130 function_kind_(function_kind), |
| 131 temps_(4, zone), | 131 temps_(4, zone), |
| 132 params_(4, zone), | 132 params_(4, zone), |
| 133 sloppy_block_function_map_(zone) { | 133 sloppy_block_function_map_(zone) { |
| 134 SetDefaults(); | 134 SetDefaults(); |
| 135 asm_function_ = outer_scope_->IsAsmModule(); | 135 asm_function_ = outer_scope_->IsAsmModule(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 ModuleScope::ModuleScope(Zone* zone, DeclarationScope* script_scope, | 138 ModuleScope::ModuleScope(DeclarationScope* script_scope, |
| 139 AstValueFactory* ast_value_factory) | 139 AstValueFactory* ast_value_factory) |
| 140 : DeclarationScope(zone, script_scope, MODULE_SCOPE) { | 140 : DeclarationScope(ast_value_factory->zone(), script_scope, MODULE_SCOPE) { |
| 141 Zone* zone = ast_value_factory->zone(); | |
| 141 module_descriptor_ = new (zone) ModuleDescriptor(zone); | 142 module_descriptor_ = new (zone) ModuleDescriptor(zone); |
| 142 set_language_mode(STRICT); | 143 set_language_mode(STRICT); |
| 143 DeclareThis(ast_value_factory); | 144 DeclareThis(ast_value_factory); |
| 144 } | 145 } |
| 145 | 146 |
| 146 Scope::Scope(Zone* zone, ScopeType scope_type, Handle<ScopeInfo> scope_info) | 147 Scope::Scope(Zone* zone, ScopeType scope_type, Handle<ScopeInfo> scope_info) |
| 147 : zone_(zone), | 148 : zone_(zone), |
| 148 outer_scope_(nullptr), | 149 outer_scope_(nullptr), |
| 149 variables_(zone), | 150 variables_(zone), |
| 150 ordered_variables_(0, zone), | 151 ordered_variables_(0, zone), |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 591 | 592 |
| 592 Variable* Scope::LookupInScopeInfo(const AstRawString* name) { | 593 Variable* Scope::LookupInScopeInfo(const AstRawString* name) { |
| 593 Handle<String> name_handle = name->string(); | 594 Handle<String> name_handle = name->string(); |
| 594 // The Scope is backed up by ScopeInfo. This means it cannot operate in a | 595 // The Scope is backed up by ScopeInfo. This means it cannot operate in a |
| 595 // heap-independent mode, and all strings must be internalized immediately. So | 596 // heap-independent mode, and all strings must be internalized immediately. So |
| 596 // it's ok to get the Handle<String> here. | 597 // it's ok to get the Handle<String> here. |
| 597 // If we have a serialized scope info, we might find the variable there. | 598 // If we have a serialized scope info, we might find the variable there. |
| 598 // There should be no local slot with the given name. | 599 // There should be no local slot with the given name. |
| 599 DCHECK(scope_info_->StackSlotIndex(*name_handle) < 0); | 600 DCHECK(scope_info_->StackSlotIndex(*name_handle) < 0); |
| 600 | 601 |
| 601 // Check context slot lookup. | |
| 602 VariableMode mode; | 602 VariableMode mode; |
| 603 VariableLocation location = VariableLocation::CONTEXT; | |
| 604 InitializationFlag init_flag; | 603 InitializationFlag init_flag; |
| 605 MaybeAssignedFlag maybe_assigned_flag; | 604 MaybeAssignedFlag maybe_assigned_flag; |
| 605 | |
| 606 VariableLocation location = VariableLocation::CONTEXT; | |
| 606 int index = ScopeInfo::ContextSlotIndex(scope_info_, name_handle, &mode, | 607 int index = ScopeInfo::ContextSlotIndex(scope_info_, name_handle, &mode, |
| 607 &init_flag, &maybe_assigned_flag); | 608 &init_flag, &maybe_assigned_flag); |
| 608 if (index < 0) { | 609 if (index < 0) { |
| 609 location = VariableLocation::GLOBAL; | 610 location = VariableLocation::GLOBAL; |
| 610 index = ScopeInfo::ContextGlobalSlotIndex(scope_info_, name_handle, &mode, | 611 index = ScopeInfo::ContextGlobalSlotIndex(scope_info_, name_handle, &mode, |
| 611 &init_flag, &maybe_assigned_flag); | 612 &init_flag, &maybe_assigned_flag); |
| 613 DCHECK(index < 0 || (is_script_scope() && IsDeclaredVariableMode(mode) && | |
| 614 !IsLexicalVariableMode(mode))); | |
|
adamk
2016/08/25 16:04:08
You should actually be able to tighten this one mo
| |
| 612 } | 615 } |
| 613 if (index < 0) { | 616 if (index < 0) { |
| 614 // Check parameters. | 617 location = VariableLocation::LOOKUP; |
|
adamk
2016/08/25 16:04:09
Why did this move out of the "found a parameter" b
| |
| 615 index = scope_info_->ParameterIndex(*name_handle); | 618 index = scope_info_->ParameterIndex(*name_handle); |
| 616 if (index < 0) return NULL; | 619 if (index >= 0) { |
| 617 | 620 mode = DYNAMIC; |
| 618 mode = DYNAMIC; | 621 init_flag = kCreatedInitialized; |
| 619 location = VariableLocation::LOOKUP; | 622 // Be conservative and flag parameters as maybe assigned. Better |
| 620 init_flag = kCreatedInitialized; | 623 // information would require ScopeInfo to serialize the maybe_assigned bit |
| 621 // Be conservative and flag parameters as maybe assigned. Better information | 624 // also for parameters. |
| 622 // would require ScopeInfo to serialize the maybe_assigned bit also for | 625 maybe_assigned_flag = kMaybeAssigned; |
| 623 // parameters. | 626 } |
| 624 maybe_assigned_flag = kMaybeAssigned; | |
| 625 } else { | |
| 626 DCHECK(location != VariableLocation::GLOBAL || | |
| 627 (is_script_scope() && IsDeclaredVariableMode(mode) && | |
| 628 !IsLexicalVariableMode(mode))); | |
| 629 } | 627 } |
| 628 if (index < 0 && scope_type() == MODULE_SCOPE) { | |
| 629 location = VariableLocation::MODULE; | |
| 630 index = -1; // TODO(neis): Find module variables in scope info. | |
| 631 } | |
| 632 if (index < 0) return nullptr; // Nowhere found. | |
| 630 | 633 |
| 631 Variable::Kind kind = Variable::NORMAL; | 634 Variable::Kind kind = Variable::NORMAL; |
| 632 if (location == VariableLocation::CONTEXT && | 635 if (location == VariableLocation::CONTEXT && |
| 633 index == scope_info_->ReceiverContextSlotIndex()) { | 636 index == scope_info_->ReceiverContextSlotIndex()) { |
| 634 kind = Variable::THIS; | 637 kind = Variable::THIS; |
| 635 } | 638 } |
| 636 // TODO(marja, rossberg): Correctly declare FUNCTION, CLASS, NEW_TARGET, and | 639 // TODO(marja, rossberg): Correctly declare FUNCTION, CLASS, NEW_TARGET, and |
| 637 // ARGUMENTS bindings as their corresponding Variable::Kind. | 640 // ARGUMENTS bindings as their corresponding Variable::Kind. |
| 638 | 641 |
| 639 Variable* var = variables_.Declare(zone(), this, name, mode, kind, init_flag, | 642 Variable* var = variables_.Declare(zone(), this, name, mode, kind, init_flag, |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 795 if (decls_[j]->proxy()->raw_name() == name) { | 798 if (decls_[j]->proxy()->raw_name() == name) { |
| 796 return decls_[j]; | 799 return decls_[j]; |
| 797 } | 800 } |
| 798 } | 801 } |
| 799 DCHECK(false); | 802 DCHECK(false); |
| 800 } | 803 } |
| 801 } | 804 } |
| 802 return nullptr; | 805 return nullptr; |
| 803 } | 806 } |
| 804 | 807 |
| 805 void Scope::CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals, | 808 void Scope::CollectVariables(ZoneList<Variable*>* stack_locals, |
| 806 ZoneList<Variable*>* context_locals, | 809 ZoneList<Variable*>* context_locals, |
| 807 ZoneList<Variable*>* context_globals) { | 810 ZoneList<Variable*>* context_globals) { |
| 808 DCHECK(stack_locals != NULL); | 811 DCHECK(stack_locals != NULL); |
| 809 DCHECK(context_locals != NULL); | 812 DCHECK(context_locals != NULL); |
| 810 DCHECK(context_globals != NULL); | 813 DCHECK(context_globals != NULL); |
| 811 | 814 |
| 812 // Collect temporaries which are always allocated on the stack, unless the | 815 // Collect temporaries which are always allocated on the stack, unless the |
| 813 // context as a whole has forced context allocation. | 816 // context as a whole has forced context allocation. |
| 814 if (is_declaration_scope()) { | 817 if (is_declaration_scope()) { |
| 815 ZoneList<Variable*>* temps = AsDeclarationScope()->temps(); | 818 ZoneList<Variable*>* temps = AsDeclarationScope()->temps(); |
| 816 for (int i = 0; i < temps->length(); i++) { | 819 for (int i = 0; i < temps->length(); i++) { |
| 817 Variable* var = (*temps)[i]; | 820 Variable* var = (*temps)[i]; |
| (...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1666 function != nullptr && function->IsContextSlot(); | 1669 function != nullptr && function->IsContextSlot(); |
| 1667 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1670 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
| 1668 (is_function_var_in_context ? 1 : 0); | 1671 (is_function_var_in_context ? 1 : 0); |
| 1669 } | 1672 } |
| 1670 | 1673 |
| 1671 | 1674 |
| 1672 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1675 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
| 1673 | 1676 |
| 1674 } // namespace internal | 1677 } // namespace internal |
| 1675 } // namespace v8 | 1678 } // namespace v8 |
| OLD | NEW |