Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: src/ast/scopes.cc

Issue 2275943005: [modules] Minor refactorings in scopes and scopeinfos. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@modules-serialize-entry
Patch Set: Rebase. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ast/scopes.h ('k') | src/crankshaft/typing.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 ScopeType scope_type, 141 ScopeType scope_type,
142 FunctionKind function_kind) 142 FunctionKind function_kind)
143 : Scope(zone, outer_scope, scope_type), 143 : Scope(zone, outer_scope, scope_type),
144 function_kind_(function_kind), 144 function_kind_(function_kind),
145 params_(4, zone), 145 params_(4, zone),
146 sloppy_block_function_map_(zone) { 146 sloppy_block_function_map_(zone) {
147 SetDefaults(); 147 SetDefaults();
148 asm_function_ = outer_scope_->IsAsmModule(); 148 asm_function_ = outer_scope_->IsAsmModule();
149 } 149 }
150 150
151 ModuleScope::ModuleScope(Zone* zone, DeclarationScope* script_scope, 151 ModuleScope::ModuleScope(DeclarationScope* script_scope,
152 AstValueFactory* ast_value_factory) 152 AstValueFactory* ast_value_factory)
153 : DeclarationScope(zone, script_scope, MODULE_SCOPE) { 153 : DeclarationScope(ast_value_factory->zone(), script_scope, MODULE_SCOPE) {
154 Zone* zone = ast_value_factory->zone();
154 module_descriptor_ = new (zone) ModuleDescriptor(zone); 155 module_descriptor_ = new (zone) ModuleDescriptor(zone);
155 set_language_mode(STRICT); 156 set_language_mode(STRICT);
156 DeclareThis(ast_value_factory); 157 DeclareThis(ast_value_factory);
157 } 158 }
158 159
159 Scope::Scope(Zone* zone, ScopeType scope_type, Handle<ScopeInfo> scope_info) 160 Scope::Scope(Zone* zone, ScopeType scope_type, Handle<ScopeInfo> scope_info)
160 : zone_(zone), 161 : zone_(zone),
161 outer_scope_(nullptr), 162 outer_scope_(nullptr),
162 variables_(zone), 163 variables_(zone),
163 locals_(0, zone), 164 locals_(0, zone),
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 611
611 Variable* Scope::LookupInScopeInfo(const AstRawString* name) { 612 Variable* Scope::LookupInScopeInfo(const AstRawString* name) {
612 Handle<String> name_handle = name->string(); 613 Handle<String> name_handle = name->string();
613 // The Scope is backed up by ScopeInfo. This means it cannot operate in a 614 // The Scope is backed up by ScopeInfo. This means it cannot operate in a
614 // heap-independent mode, and all strings must be internalized immediately. So 615 // heap-independent mode, and all strings must be internalized immediately. So
615 // it's ok to get the Handle<String> here. 616 // it's ok to get the Handle<String> here.
616 // If we have a serialized scope info, we might find the variable there. 617 // If we have a serialized scope info, we might find the variable there.
617 // There should be no local slot with the given name. 618 // There should be no local slot with the given name.
618 DCHECK(scope_info_->StackSlotIndex(*name_handle) < 0); 619 DCHECK(scope_info_->StackSlotIndex(*name_handle) < 0);
619 620
620 // Check context slot lookup.
621 VariableMode mode; 621 VariableMode mode;
622 VariableLocation location = VariableLocation::CONTEXT;
623 InitializationFlag init_flag; 622 InitializationFlag init_flag;
624 MaybeAssignedFlag maybe_assigned_flag; 623 MaybeAssignedFlag maybe_assigned_flag;
624
625 VariableLocation location = VariableLocation::CONTEXT;
625 int index = ScopeInfo::ContextSlotIndex(scope_info_, name_handle, &mode, 626 int index = ScopeInfo::ContextSlotIndex(scope_info_, name_handle, &mode,
626 &init_flag, &maybe_assigned_flag); 627 &init_flag, &maybe_assigned_flag);
627 if (index < 0) { 628 if (index < 0) {
628 location = VariableLocation::GLOBAL; 629 location = VariableLocation::GLOBAL;
629 index = ScopeInfo::ContextGlobalSlotIndex(scope_info_, name_handle, &mode, 630 index = ScopeInfo::ContextGlobalSlotIndex(scope_info_, name_handle, &mode,
630 &init_flag, &maybe_assigned_flag); 631 &init_flag, &maybe_assigned_flag);
632 DCHECK(index < 0 || (is_script_scope() && mode == VAR));
631 } 633 }
632 if (index < 0) { 634 if (index < 0) {
633 // Check parameters. 635 location = VariableLocation::LOOKUP;
634 index = scope_info_->ParameterIndex(*name_handle); 636 index = scope_info_->ParameterIndex(*name_handle);
635 if (index < 0) return NULL; 637 if (index >= 0) {
636 638 mode = DYNAMIC;
637 mode = DYNAMIC; 639 init_flag = kCreatedInitialized;
638 location = VariableLocation::LOOKUP; 640 // Be conservative and flag parameters as maybe assigned. Better
639 init_flag = kCreatedInitialized; 641 // information would require ScopeInfo to serialize the maybe_assigned bit
640 // Be conservative and flag parameters as maybe assigned. Better information 642 // also for parameters.
641 // would require ScopeInfo to serialize the maybe_assigned bit also for 643 maybe_assigned_flag = kMaybeAssigned;
642 // parameters. 644 }
643 maybe_assigned_flag = kMaybeAssigned;
644 } else {
645 DCHECK(location != VariableLocation::GLOBAL ||
646 (is_script_scope() && IsDeclaredVariableMode(mode) &&
647 !IsLexicalVariableMode(mode)));
648 } 645 }
646 if (index < 0 && scope_type() == MODULE_SCOPE) {
647 location = VariableLocation::MODULE;
648 index = -1; // TODO(neis): Find module variables in scope info.
649 }
650 if (index < 0) return nullptr; // Nowhere found.
649 651
650 Variable::Kind kind = Variable::NORMAL; 652 Variable::Kind kind = Variable::NORMAL;
651 if (location == VariableLocation::CONTEXT && 653 if (location == VariableLocation::CONTEXT &&
652 index == scope_info_->ReceiverContextSlotIndex()) { 654 index == scope_info_->ReceiverContextSlotIndex()) {
653 kind = Variable::THIS; 655 kind = Variable::THIS;
654 } 656 }
655 // TODO(marja, rossberg): Correctly declare FUNCTION, CLASS, NEW_TARGET, and 657 // TODO(marja, rossberg): Correctly declare FUNCTION, CLASS, NEW_TARGET, and
656 // ARGUMENTS bindings as their corresponding Variable::Kind. 658 // ARGUMENTS bindings as their corresponding Variable::Kind.
657 659
658 Variable* var = variables_.Declare(zone(), this, name, mode, kind, init_flag, 660 Variable* var = variables_.Declare(zone(), this, name, mode, kind, init_flag,
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 if (decls_[j]->proxy()->raw_name() == name) { 817 if (decls_[j]->proxy()->raw_name() == name) {
816 return decls_[j]; 818 return decls_[j];
817 } 819 }
818 } 820 }
819 DCHECK(false); 821 DCHECK(false);
820 } 822 }
821 } 823 }
822 return nullptr; 824 return nullptr;
823 } 825 }
824 826
825 void Scope::CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals, 827 void Scope::CollectVariables(ZoneList<Variable*>* stack_locals,
826 ZoneList<Variable*>* context_locals, 828 ZoneList<Variable*>* context_locals,
827 ZoneList<Variable*>* context_globals) { 829 ZoneList<Variable*>* context_globals) {
828 // TODO(verwaest): Just pass out locals_ directly and walk it? 830 // TODO(verwaest): Just pass out locals_ directly and walk it?
829 DCHECK_NOT_NULL(stack_locals); 831 DCHECK_NOT_NULL(stack_locals);
830 DCHECK_NOT_NULL(context_locals); 832 DCHECK_NOT_NULL(context_locals);
831 DCHECK_NOT_NULL(context_globals); 833 DCHECK_NOT_NULL(context_globals);
832 834
833 for (int i = 0; i < locals_.length(); i++) { 835 for (int i = 0; i < locals_.length(); i++) {
834 Variable* var = locals_[i]; 836 Variable* var = locals_[i];
835 if (var->IsStackLocal()) { 837 if (var->IsStackLocal()) {
836 stack_locals->Add(var, zone()); 838 stack_locals->Add(var, zone());
837 } else if (var->IsContextSlot()) { 839 } else if (var->IsContextSlot()) {
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 function != nullptr && function->IsContextSlot(); 1650 function != nullptr && function->IsContextSlot();
1649 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - 1651 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() -
1650 (is_function_var_in_context ? 1 : 0); 1652 (is_function_var_in_context ? 1 : 0);
1651 } 1653 }
1652 1654
1653 1655
1654 int Scope::ContextGlobalCount() const { return num_global_slots(); } 1656 int Scope::ContextGlobalCount() const { return num_global_slots(); }
1655 1657
1656 } // namespace internal 1658 } // namespace internal
1657 } // namespace v8 1659 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/scopes.h ('k') | src/crankshaft/typing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698