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

Unified Diff: src/ast/scopes.cc

Issue 2212383003: Revert of Separate Scope into DeclarationScope and Scope (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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/compiler.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 f272931b9258a01afe4573718db2861c322fc828..35507c36fb4221b838b52227201e48514d875c73 100644
--- a/src/ast/scopes.cc
+++ b/src/ast/scopes.cc
@@ -83,11 +83,19 @@
// ----------------------------------------------------------------------------
// Implementation of Scope
-Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type)
+Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type,
+ FunctionKind function_kind)
: outer_scope_(outer_scope),
variables_(zone),
+ temps_(4, zone),
+ params_(4, zone),
decls_(4, zone),
+ module_descriptor_(scope_type == MODULE_SCOPE ? new (zone)
+ ModuleDescriptor(zone)
+ : NULL),
+ sloppy_block_function_map_(zone),
scope_type_(scope_type),
+ function_kind_(function_kind),
already_resolved_(false) {
SetDefaults();
if (outer_scope == nullptr) {
@@ -106,38 +114,25 @@
}
}
-Scope::Snapshot::Snapshot(Scope* scope)
- : outer_scope_(scope),
- top_inner_scope_(scope->inner_scope_),
- top_unresolved_(scope->unresolved_),
- top_temp_(scope->GetClosureScope()->temps()->length()) {}
-
-DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope,
- ScopeType scope_type,
- FunctionKind function_kind)
- : Scope(zone, outer_scope, scope_type),
- function_kind_(function_kind),
- temps_(4, zone),
- params_(4, zone),
- sloppy_block_function_map_(zone),
- module_descriptor_(scope_type == MODULE_SCOPE ? new (zone)
- ModuleDescriptor(zone)
- : NULL) {
- SetDefaults();
-}
-
Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type,
Handle<ScopeInfo> scope_info)
: outer_scope_(nullptr),
variables_(zone),
+ temps_(4, zone),
+ params_(4, zone),
decls_(4, zone),
- scope_info_(scope_info),
+ module_descriptor_(nullptr),
+ sloppy_block_function_map_(zone),
scope_type_(scope_type),
- already_resolved_(true) {
+ function_kind_(scope_info.is_null() ? kNormalFunction
+ : scope_info->function_kind()),
+ already_resolved_(true),
+ scope_info_(scope_info) {
SetDefaults();
if (!scope_info.is_null()) {
scope_calls_eval_ = scope_info->CallsEval();
language_mode_ = scope_info->language_mode();
+ is_declaration_scope_ = scope_info->is_declaration_scope();
num_heap_slots_ = scope_info_->ContextLength();
}
// Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context.
@@ -146,25 +141,17 @@
AddInnerScope(inner_scope);
}
-DeclarationScope::DeclarationScope(Zone* zone, Scope* inner_scope,
- ScopeType scope_type,
- Handle<ScopeInfo> scope_info)
- : Scope(zone, inner_scope, scope_type, scope_info),
- function_kind_(scope_info.is_null() ? kNormalFunction
- : scope_info->function_kind()),
- temps_(4, zone),
- params_(4, zone),
- sloppy_block_function_map_(zone),
- module_descriptor_(nullptr) {
- SetDefaults();
-}
-
Scope::Scope(Zone* zone, Scope* inner_scope,
const AstRawString* catch_variable_name)
: outer_scope_(nullptr),
variables_(zone),
+ temps_(0, zone),
+ params_(0, zone),
decls_(0, zone),
+ module_descriptor_(nullptr),
+ sloppy_block_function_map_(zone),
scope_type_(CATCH_SCOPE),
+ function_kind_(kNormalFunction),
already_resolved_(true) {
SetDefaults();
AddInnerScope(inner_scope);
@@ -177,28 +164,22 @@
AllocateHeapSlot(variable);
}
-void DeclarationScope::SetDefaults() {
- is_declaration_scope_ = true;
+void Scope::SetDefaults() {
+ is_declaration_scope_ =
+ is_eval_scope() || is_function_scope() ||
+ is_module_scope() || is_script_scope();
+ inner_scope_ = nullptr;
+ sibling_ = nullptr;
+ unresolved_ = nullptr;
+#ifdef DEBUG
+ scope_name_ = nullptr;
+#endif
+ dynamics_ = nullptr;
receiver_ = nullptr;
new_target_ = nullptr;
function_ = nullptr;
arguments_ = nullptr;
this_function_ = nullptr;
- arity_ = 0;
- has_simple_parameters_ = true;
- rest_parameter_ = NULL;
- rest_index_ = -1;
-}
-
-void Scope::SetDefaults() {
-#ifdef DEBUG
- scope_name_ = nullptr;
-#endif
- is_declaration_scope_ = false;
- inner_scope_ = nullptr;
- sibling_ = nullptr;
- unresolved_ = nullptr;
- dynamics_ = nullptr;
scope_inside_with_ = false;
scope_calls_eval_ = false;
has_arguments_parameter_ = false;
@@ -214,14 +195,13 @@
num_stack_slots_ = 0;
num_heap_slots_ = 0;
num_global_slots_ = 0;
+ arity_ = 0;
+ has_simple_parameters_ = true;
+ rest_parameter_ = NULL;
+ rest_index_ = -1;
start_position_ = kNoSourcePosition;
end_position_ = kNoSourcePosition;
is_hidden_ = false;
-}
-
-bool Scope::HasSimpleParameters() {
- DeclarationScope* scope = GetClosureScope();
- return !scope->is_function_scope() || scope->has_simple_parameters();
}
Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone,
@@ -243,23 +223,18 @@
}
} else if (context->IsScriptContext()) {
ScopeInfo* scope_info = context->scope_info();
- current_scope = new (zone) DeclarationScope(
- zone, current_scope, SCRIPT_SCOPE, Handle<ScopeInfo>(scope_info));
+ current_scope = new (zone) Scope(zone, current_scope, SCRIPT_SCOPE,
+ Handle<ScopeInfo>(scope_info));
} else if (context->IsFunctionContext()) {
ScopeInfo* scope_info = context->closure()->shared()->scope_info();
- current_scope = new (zone) DeclarationScope(
- zone, current_scope, FUNCTION_SCOPE, Handle<ScopeInfo>(scope_info));
+ current_scope = new (zone) Scope(zone, current_scope, FUNCTION_SCOPE,
+ Handle<ScopeInfo>(scope_info));
if (scope_info->IsAsmFunction()) current_scope->asm_function_ = true;
if (scope_info->IsAsmModule()) current_scope->asm_module_ = true;
} else if (context->IsBlockContext()) {
ScopeInfo* scope_info = context->scope_info();
- if (scope_info->is_declaration_scope()) {
- current_scope = new (zone) DeclarationScope(
- zone, current_scope, BLOCK_SCOPE, Handle<ScopeInfo>(scope_info));
- } else {
- current_scope = new (zone) Scope(zone, current_scope, BLOCK_SCOPE,
- Handle<ScopeInfo>(scope_info));
- }
+ current_scope = new (zone) Scope(zone, current_scope, BLOCK_SCOPE,
+ Handle<ScopeInfo>(scope_info));
} else {
DCHECK(context->IsCatchContext());
String* name = context->catch_name();
@@ -344,47 +319,36 @@
VariableProxy* proxy = factory.NewVariableProxy(result);
VariableDeclaration* declaration =
factory.NewVariableDeclaration(proxy, mode, this, kNoSourcePosition);
- AsDeclarationScope()->DeclareFunctionVar(declaration);
+ DeclareFunctionVar(declaration);
result->AllocateTo(VariableLocation::CONTEXT, index);
}
}
scope_info_ = Handle<ScopeInfo>::null();
-}
-
-DeclarationScope* Scope::AsDeclarationScope() {
- DCHECK(is_declaration_scope());
- return static_cast<DeclarationScope*>(this);
-}
-
-const DeclarationScope* Scope::AsDeclarationScope() const {
- DCHECK(is_declaration_scope());
- return static_cast<const DeclarationScope*>(this);
-}
-
-int Scope::num_parameters() const {
- return is_declaration_scope() ? AsDeclarationScope()->num_parameters() : 0;
}
bool Scope::Analyze(ParseInfo* info) {
DCHECK(info->literal() != NULL);
DCHECK(info->scope() == NULL);
- DeclarationScope* scope = info->literal()->scope();
- DeclarationScope* top = scope;
+ Scope* scope = info->literal()->scope();
+ Scope* top = scope;
// Traverse the scope tree up to the first unresolved scope or the global
// scope and start scope resolution and variable allocation from that scope.
- // Such a scope is always a closure-scope, so always skip to the next closure
- // scope.
while (!top->is_script_scope() &&
!top->outer_scope()->already_resolved()) {
- top = top->outer_scope()->GetClosureScope();
+ top = top->outer_scope();
}
// Allocate the variables.
{
AstNodeFactory ast_node_factory(info->ast_value_factory());
- if (!top->AllocateVariables(info, &ast_node_factory)) return false;
+ if (!top->AllocateVariables(info, &ast_node_factory)) {
+ DCHECK(top->pending_error_handler_.has_pending_error());
+ top->pending_error_handler_.ThrowPendingError(info->isolate(),
+ info->script());
+ return false;
+ }
}
#ifdef DEBUG
@@ -400,7 +364,7 @@
return true;
}
-void DeclarationScope::DeclareThis(AstValueFactory* ast_value_factory) {
+void Scope::DeclareThis(AstValueFactory* ast_value_factory) {
DCHECK(!already_resolved());
DCHECK(is_declaration_scope());
DCHECK(has_this_declaration());
@@ -413,7 +377,7 @@
receiver_ = var;
}
-void DeclarationScope::DeclareDefaultFunctionVariables(
+void Scope::DeclareDefaultFunctionVariables(
AstValueFactory* ast_value_factory) {
DCHECK(is_function_scope());
DCHECK(!is_arrow_scope());
@@ -439,6 +403,8 @@
Scope* Scope::FinalizeBlockScope() {
DCHECK(is_block_scope());
+ DCHECK(temps_.is_empty());
+ DCHECK(params_.is_empty());
if (variables_.occupancy() > 0 ||
(is_declaration_scope() && calls_sloppy_eval())) {
@@ -479,13 +445,13 @@
return NULL;
}
-void Scope::Snapshot::Reparent(DeclarationScope* new_parent) const {
+void Scope::Snapshot::Reparent(Scope* new_parent) const {
DCHECK_EQ(new_parent, outer_scope_->inner_scope_);
DCHECK_EQ(new_parent->outer_scope_, outer_scope_);
- DCHECK_EQ(new_parent, new_parent->GetClosureScope());
+ DCHECK_EQ(new_parent, new_parent->ClosureScope());
DCHECK_NULL(new_parent->inner_scope_);
DCHECK_NULL(new_parent->unresolved_);
- DCHECK_EQ(0, new_parent->temps()->length());
+ DCHECK_EQ(0, new_parent->temps_.length());
Scope* inner_scope = new_parent->sibling_;
if (inner_scope != top_inner_scope_) {
for (; inner_scope->sibling() != top_inner_scope_;
@@ -512,11 +478,11 @@
outer_scope_->unresolved_ = top_unresolved_;
}
- if (outer_scope_->GetClosureScope()->temps()->length() != top_temp_) {
- ZoneList<Variable*>* temps = outer_scope_->GetClosureScope()->temps();
+ if (outer_scope_->ClosureScope()->temps_.length() != top_temp_) {
+ ZoneList<Variable*>* temps = &outer_scope_->ClosureScope()->temps_;
for (int i = top_temp_; i < temps->length(); i++) {
Variable* temp = temps->at(i);
- DCHECK_EQ(temp->scope(), temp->scope()->GetClosureScope());
+ DCHECK_EQ(temp->scope(), temp->scope()->ClosureScope());
DCHECK_NE(temp->scope(), new_parent);
temp->set_scope(new_parent);
new_parent->AddTemporary(temp);
@@ -603,8 +569,9 @@
return var;
}
-Variable* DeclarationScope::LookupFunctionVar(const AstRawString* name,
- AstNodeFactory* factory) {
+
+Variable* Scope::LookupFunctionVar(const AstRawString* name,
+ AstNodeFactory* factory) {
if (function_ != NULL && function_->proxy()->raw_name() == name) {
return function_->proxy()->var();
} else if (!scope_info_.is_null()) {
@@ -638,9 +605,10 @@
return NULL;
}
-Variable* DeclarationScope::DeclareParameter(
- const AstRawString* name, VariableMode mode, bool is_optional, bool is_rest,
- bool* is_duplicate, AstValueFactory* ast_value_factory) {
+Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode,
+ bool is_optional, bool is_rest,
+ bool* is_duplicate,
+ AstValueFactory* ast_value_factory) {
DCHECK(!already_resolved());
DCHECK(is_function_scope());
DCHECK(!is_optional || !is_rest);
@@ -680,7 +648,8 @@
maybe_assigned_flag);
}
-Variable* DeclarationScope::DeclareDynamicGlobal(const AstRawString* name) {
+
+Variable* Scope::DeclareDynamicGlobal(const AstRawString* name) {
DCHECK(is_script_scope());
return variables_.Declare(this,
name,
@@ -712,7 +681,7 @@
Variable* Scope::NewTemporary(const AstRawString* name) {
DCHECK(!already_resolved());
- DeclarationScope* scope = GetClosureScope();
+ Scope* scope = this->ClosureScope();
Variable* var = new(zone()) Variable(scope,
name,
TEMPORARY,
@@ -722,11 +691,11 @@
return var;
}
-int DeclarationScope::RemoveTemporary(Variable* var) {
+int Scope::RemoveTemporary(Variable* var) {
DCHECK_NOT_NULL(var);
// Temporaries are only placed in ClosureScopes.
- DCHECK_EQ(GetClosureScope(), this);
- DCHECK_EQ(var->scope()->GetClosureScope(), var->scope());
+ DCHECK_EQ(ClosureScope(), this);
+ DCHECK_EQ(var->scope()->ClosureScope(), var->scope());
// If the temporary is not here, return quickly.
if (var->scope() != this) return -1;
// Most likely (always?) any temporary variable we want to remove
@@ -755,8 +724,7 @@
// We don't create a separate scope to hold the function name of a function
// expression, so we have to make sure not to consider it when checking for
// conflicts (since it's conceptually "outside" the declaration scope).
- if (is_function_scope() && decl == AsDeclarationScope()->function())
- continue;
+ if (is_function_scope() && decl == function()) continue;
if (IsLexicalVariableMode(decl->mode()) && !is_block_scope()) continue;
const AstRawString* name = decl->proxy()->raw_name();
@@ -824,20 +792,17 @@
// Collect temporaries which are always allocated on the stack, unless the
// context as a whole has forced context allocation.
- if (is_declaration_scope()) {
- ZoneList<Variable*>* temps = AsDeclarationScope()->temps();
- for (int i = 0; i < temps->length(); i++) {
- Variable* var = (*temps)[i];
- if (var == nullptr) continue;
- if (var->is_used()) {
- if (var->IsContextSlot()) {
- DCHECK(has_forced_context_allocation());
- context_locals->Add(var, zone());
- } else if (var->IsStackLocal()) {
- stack_locals->Add(var, zone());
- } else {
- DCHECK(var->IsParameter());
- }
+ for (int i = 0; i < temps_.length(); i++) {
+ Variable* var = temps_[i];
+ if (var == nullptr) continue;
+ if (var->is_used()) {
+ if (var->IsContextSlot()) {
+ DCHECK(has_forced_context_allocation());
+ context_locals->Add(var, zone());
+ } else if (var->IsStackLocal()) {
+ stack_locals->Add(var, zone());
+ } else {
+ DCHECK(var->IsParameter());
}
}
}
@@ -866,8 +831,7 @@
}
}
-bool DeclarationScope::AllocateVariables(ParseInfo* info,
- AstNodeFactory* factory) {
+bool Scope::AllocateVariables(ParseInfo* info, AstNodeFactory* factory) {
// 1) Propagate scope information.
bool outer_scope_calls_sloppy_eval = false;
if (outer_scope_ != NULL) {
@@ -878,11 +842,7 @@
PropagateScopeInfo(outer_scope_calls_sloppy_eval);
// 2) Resolve variables.
- if (!ResolveVariablesRecursively(info, factory)) {
- DCHECK(pending_error_handler_.has_pending_error());
- pending_error_handler_.ThrowPendingError(info->isolate(), info->script());
- return false;
- }
+ if (!ResolveVariablesRecursively(info, factory)) return false;
// 3) Allocate variables.
AllocateVariablesRecursively(info->ast_value_factory());
@@ -957,30 +917,32 @@
return max_context_chain_length;
}
-DeclarationScope* Scope::GetDeclarationScope() {
+
+Scope* Scope::DeclarationScope() {
Scope* scope = this;
while (!scope->is_declaration_scope()) {
scope = scope->outer_scope();
}
- return scope->AsDeclarationScope();
-}
-
-DeclarationScope* Scope::GetClosureScope() {
+ return scope;
+}
+
+
+Scope* Scope::ClosureScope() {
Scope* scope = this;
while (!scope->is_declaration_scope() || scope->is_block_scope()) {
scope = scope->outer_scope();
}
- return scope->AsDeclarationScope();
-}
-
-DeclarationScope* Scope::GetReceiverScope() {
+ return scope;
+}
+
+
+Scope* Scope::ReceiverScope() {
Scope* scope = this;
while (!scope->is_script_scope() &&
- (!scope->is_function_scope() ||
- scope->AsDeclarationScope()->is_arrow_scope())) {
+ (!scope->is_function_scope() || scope->is_arrow_scope())) {
scope = scope->outer_scope();
}
- return scope->AsDeclarationScope();
+ return scope;
}
@@ -1008,8 +970,8 @@
return non_locals;
}
-void DeclarationScope::AnalyzePartially(DeclarationScope* migrate_to,
- AstNodeFactory* ast_node_factory) {
+void Scope::AnalyzePartially(Scope* migrate_to,
+ AstNodeFactory* ast_node_factory) {
// Gather info from inner scopes.
PropagateScopeInfo(false);
@@ -1129,46 +1091,38 @@
}
}
-void DeclarationScope::PrintParameters() {
- PrintF(" (");
- for (int i = 0; i < params_.length(); i++) {
- if (i > 0) PrintF(", ");
- const AstRawString* name = params_[i]->raw_name();
- if (name->IsEmpty())
- PrintF(".%p", reinterpret_cast<void*>(params_[i]));
- else
- PrintName(name);
- }
- PrintF(")");
-}
void Scope::Print(int n) {
int n0 = (n > 0 ? n : 0);
int n1 = n0 + 2; // indentation
// Print header.
- FunctionKind function_kind = is_function_scope()
- ? AsDeclarationScope()->function_kind()
- : kNormalFunction;
- Indent(n0, Header(scope_type_, function_kind, is_declaration_scope()));
+ Indent(n0, Header(scope_type_, function_kind_, is_declaration_scope()));
if (scope_name_ != nullptr && !scope_name_->IsEmpty()) {
PrintF(" ");
PrintName(scope_name_);
}
// Print parameters, if any.
- VariableDeclaration* function = nullptr;
if (is_function_scope()) {
- AsDeclarationScope()->PrintParameters();
- function = AsDeclarationScope()->function();
+ PrintF(" (");
+ for (int i = 0; i < params_.length(); i++) {
+ if (i > 0) PrintF(", ");
+ const AstRawString* name = params_[i]->raw_name();
+ if (name->IsEmpty())
+ PrintF(".%p", reinterpret_cast<void*>(params_[i]));
+ else
+ PrintName(name);
+ }
+ PrintF(")");
}
PrintF(" { // (%d, %d)\n", start_position(), end_position());
// Function name, if any (named function literals, only).
- if (function != nullptr) {
+ if (function_ != NULL) {
Indent(n1, "// (local) function name: ");
- PrintName(function->proxy()->raw_name());
+ PrintName(function_->proxy()->raw_name());
PrintF("\n");
}
@@ -1200,21 +1154,20 @@
}
// Print locals.
- if (function != nullptr) {
+ if (function_ != NULL) {
Indent(n1, "// function var:\n");
- PrintVar(n1, function->proxy()->var());
- }
-
- if (is_declaration_scope()) {
+ PrintVar(n1, function_->proxy()->var());
+ }
+
+ if (temps_.length() > 0) {
bool printed_header = false;
- ZoneList<Variable*>* temps = AsDeclarationScope()->temps();
- for (int i = 0; i < temps->length(); i++) {
- if ((*temps)[i] != nullptr) {
+ for (int i = 0; i < temps_.length(); i++) {
+ if (temps_[i] != nullptr) {
if (!printed_header) {
printed_header = true;
Indent(n1, "// temporary vars:\n");
}
- PrintVar(n1, (*temps)[i]);
+ PrintVar(n1, temps_[i]);
}
}
}
@@ -1305,13 +1258,11 @@
return var;
}
- // We did not find a variable locally. Check against the function variable, if
- // any.
+ // We did not find a variable locally. Check against the function variable,
+ // if any. We can do this for all scopes, since the function variable is
+ // only present - if at all - for function scopes.
*binding_kind = UNBOUND;
- var =
- is_function_scope()
- ? AsDeclarationScope()->LookupFunctionVar(proxy->raw_name(), factory)
- : nullptr;
+ var = LookupFunctionVar(proxy->raw_name(), factory);
if (var != NULL) {
*binding_kind = BOUND;
} else if (outer_scope_ != nullptr && this != max_outer_scope) {
@@ -1454,9 +1405,9 @@
return true;
}
-void Scope::MigrateUnresolvableLocals(DeclarationScope* migrate_to,
+void Scope::MigrateUnresolvableLocals(Scope* migrate_to,
AstNodeFactory* ast_node_factory,
- DeclarationScope* max_outer_scope) {
+ Scope* max_outer_scope) {
BindingKind binding_kind;
for (VariableProxy *proxy = unresolved_, *next = nullptr; proxy != nullptr;
proxy = next) {
@@ -1539,7 +1490,7 @@
void Scope::AllocateStackSlot(Variable* var) {
if (is_block_scope()) {
- outer_scope()->GetDeclarationScope()->AllocateStackSlot(var);
+ outer_scope()->DeclarationScope()->AllocateStackSlot(var);
} else {
var->AllocateTo(VariableLocation::LOCAL, num_stack_slots_++);
}
@@ -1550,7 +1501,7 @@
var->AllocateTo(VariableLocation::CONTEXT, num_heap_slots_++);
}
-void DeclarationScope::AllocateParameterLocals() {
+void Scope::AllocateParameterLocals() {
DCHECK(is_function_scope());
bool uses_sloppy_arguments = false;
@@ -1603,7 +1554,8 @@
}
}
-void DeclarationScope::AllocateParameter(Variable* var, int index) {
+
+void Scope::AllocateParameter(Variable* var, int index) {
if (MustAllocate(var)) {
if (MustAllocateInContext(var)) {
DCHECK(var->IsUnallocated() || var->IsContextSlot());
@@ -1621,8 +1573,8 @@
}
}
-void DeclarationScope::AllocateReceiver() {
- if (!has_this_declaration()) return;
+
+void Scope::AllocateReceiver() {
DCHECK_NOT_NULL(receiver());
DCHECK_EQ(receiver()->scope(), this);
@@ -1668,12 +1620,9 @@
void Scope::AllocateNonParameterLocalsAndDeclaredGlobals(
AstValueFactory* ast_value_factory) {
// All variables that have no rewrite yet are non-parameter locals.
- if (is_declaration_scope()) {
- ZoneList<Variable*>* temps = AsDeclarationScope()->temps();
- for (int i = 0; i < temps->length(); i++) {
- if ((*temps)[i] == nullptr) continue;
- AllocateNonParameterLocal((*temps)[i], ast_value_factory);
- }
+ for (int i = 0; i < temps_.length(); i++) {
+ if (temps_[i] == nullptr) continue;
+ AllocateNonParameterLocal(temps_[i], ast_value_factory);
}
ZoneList<VarAndOrder> vars(variables_.occupancy(), zone());
@@ -1695,12 +1644,6 @@
}
}
- if (is_declaration_scope()) {
- AsDeclarationScope()->AllocateLocals(ast_value_factory);
- }
-}
-
-void DeclarationScope::AllocateLocals(AstValueFactory* ast_value_factory) {
// For now, function_ must be allocated at the very end. If it gets
// allocated in the context, it must be the last slot in the context,
// because of the current ScopeInfo implementation (see
@@ -1739,10 +1682,8 @@
// Allocate variables for this scope.
// Parameters must be allocated first, if any.
- if (is_declaration_scope()) {
- if (is_function_scope()) AsDeclarationScope()->AllocateParameterLocals();
- AsDeclarationScope()->AllocateReceiver();
- }
+ if (is_function_scope()) AllocateParameterLocals();
+ if (has_this_declaration()) AllocateReceiver();
AllocateNonParameterLocalsAndDeclaredGlobals(ast_value_factory);
// Force allocation of a context for this scope if necessary. For a 'with'
@@ -1766,19 +1707,15 @@
int Scope::StackLocalCount() const {
- VariableDeclaration* function =
- is_function_scope() ? AsDeclarationScope()->function() : nullptr;
return num_stack_slots() -
- (function != NULL && function->proxy()->var()->IsStackLocal() ? 1 : 0);
+ (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0);
}
int Scope::ContextLocalCount() const {
if (num_heap_slots() == 0) return 0;
- VariableDeclaration* function =
- is_function_scope() ? AsDeclarationScope()->function() : nullptr;
bool is_function_var_in_context =
- function != NULL && function->proxy()->var()->IsContextSlot();
+ function_ != NULL && function_->proxy()->var()->IsContextSlot();
return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() -
(is_function_var_in_context ? 1 : 0);
}
« no previous file with comments | « src/ast/scopes.h ('k') | src/compiler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698