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

Unified Diff: src/ast/scopes.cc

Issue 2287173002: Replace CollectVariables with locals(), update callsites to walk locals instead (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: restore undefined handling Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ast/scopes.h ('k') | src/ast/variables.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast/scopes.cc
diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc
index 129cbceaf5bef5c1104efa1332481c23582f7ce3..ba0008a7cd415dc86ce36fa5dbeb7f34ec5882b3 100644
--- a/src/ast/scopes.cc
+++ b/src/ast/scopes.cc
@@ -232,7 +232,6 @@ void Scope::SetDefaults() {
num_stack_slots_ = 0;
num_heap_slots_ = Context::MIN_CONTEXT_SLOTS;
- num_global_slots_ = 0;
set_language_mode(SLOPPY);
@@ -340,10 +339,8 @@ void Scope::DeserializeScopeInfo(Isolate* isolate,
DCHECK(ThreadId::Current().Equals(isolate->thread_id()));
- // Internalize context local & globals variables.
- for (int var = 0; var < scope_info_->ContextLocalCount() +
- scope_info_->ContextGlobalCount();
- ++var) {
+ // Internalize context local variables.
+ for (int var = 0; var < scope_info_->ContextLocalCount(); ++var) {
Handle<String> name_handle(scope_info_->ContextLocalName(var), isolate);
const AstRawString* name = ast_value_factory->GetString(name_handle);
int index = Context::MIN_CONTEXT_SLOTS + var;
@@ -351,9 +348,7 @@ void Scope::DeserializeScopeInfo(Isolate* isolate,
InitializationFlag init_flag = scope_info_->ContextLocalInitFlag(var);
MaybeAssignedFlag maybe_assigned_flag =
scope_info_->ContextLocalMaybeAssignedFlag(var);
- VariableLocation location = var < scope_info_->ContextLocalCount()
- ? VariableLocation::CONTEXT
- : VariableLocation::GLOBAL;
+ VariableLocation location = VariableLocation::CONTEXT;
Variable::Kind kind = Variable::NORMAL;
if (index == scope_info_->ReceiverContextSlotIndex()) {
kind = Variable::THIS;
@@ -603,12 +598,6 @@ Variable* Scope::LookupInScopeInfo(const AstRawString* name) {
VariableLocation location = VariableLocation::CONTEXT;
int index = ScopeInfo::ContextSlotIndex(scope_info_, name_handle, &mode,
&init_flag, &maybe_assigned_flag);
- if (index < 0) {
- location = VariableLocation::GLOBAL;
- index = ScopeInfo::ContextGlobalSlotIndex(scope_info_, name_handle, &mode,
- &init_flag, &maybe_assigned_flag);
- DCHECK(index < 0 || (is_script_scope() && mode == VAR));
- }
if (index < 0 && scope_type() == MODULE_SCOPE) {
location = VariableLocation::MODULE;
index = -1; // TODO(neis): Find module variables in scope info.
@@ -790,26 +779,6 @@ Declaration* Scope::CheckLexDeclarationsConflictingWith(
return nullptr;
}
-void Scope::CollectVariables(ZoneList<Variable*>* stack_locals,
- ZoneList<Variable*>* context_locals,
- ZoneList<Variable*>* context_globals) {
- // TODO(verwaest): Just pass out locals_ directly and walk it?
- DCHECK_NOT_NULL(stack_locals);
- DCHECK_NOT_NULL(context_locals);
- DCHECK_NOT_NULL(context_globals);
-
- for (int i = 0; i < locals_.length(); i++) {
- Variable* var = locals_[i];
- if (var->IsStackLocal()) {
- stack_locals->Add(var, zone());
- } else if (var->IsContextSlot()) {
- context_locals->Add(var, zone());
- } else if (var->IsGlobalSlot()) {
- context_globals->Add(var, zone());
- }
- }
-}
-
void DeclarationScope::AllocateVariables(ParseInfo* info) {
// 1) Propagate scope information.
PropagateScopeInfo();
@@ -1116,8 +1085,7 @@ void Scope::Print(int n) {
}
if (num_heap_slots_ > 0) {
Indent(n1, "// ");
- PrintF("%d heap slots (including %d global slots)\n", num_heap_slots_,
- num_global_slots_);
+ PrintF("%d heap slots\n", num_heap_slots_);
}
// Print locals.
@@ -1468,8 +1436,6 @@ void DeclarationScope::AllocateParameter(Variable* var, int index) {
var->AllocateTo(VariableLocation::PARAMETER, index);
}
}
- } else {
- DCHECK(!var->IsGlobalSlot());
}
}
@@ -1491,32 +1457,11 @@ void Scope::AllocateNonParameterLocal(Variable* var) {
}
}
-void Scope::AllocateDeclaredGlobal(Variable* var) {
- DCHECK(var->scope() == this);
- if (var->IsUnallocated()) {
- if (var->IsStaticGlobalObjectProperty()) {
- DCHECK_EQ(-1, var->index());
- DCHECK(var->name()->IsString());
- var->AllocateTo(VariableLocation::GLOBAL, num_heap_slots_++);
- num_global_slots_++;
- } else {
- // There must be only DYNAMIC_GLOBAL in the script scope.
- DCHECK(!is_script_scope() || DYNAMIC_GLOBAL == var->mode());
- }
- }
-}
-
void Scope::AllocateNonParameterLocalsAndDeclaredGlobals() {
for (int i = 0; i < locals_.length(); i++) {
AllocateNonParameterLocal(locals_[i]);
}
- if (FLAG_global_var_shortcuts) {
- for (int i = 0; i < locals_.length(); i++) {
- AllocateDeclaredGlobal(locals_[i]);
- }
- }
-
if (is_declaration_scope()) {
AsDeclarationScope()->AllocateLocals();
}
@@ -1614,12 +1559,9 @@ int Scope::ContextLocalCount() const {
is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
bool is_function_var_in_context =
function != nullptr && function->IsContextSlot();
- return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() -
+ return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
(is_function_var_in_context ? 1 : 0);
}
-
-int Scope::ContextGlobalCount() const { return num_global_slots(); }
-
} // namespace internal
} // namespace v8
« no previous file with comments | « src/ast/scopes.h ('k') | src/ast/variables.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698