Commit 9ae45af5 authored by verwaest's avatar verwaest Committed by Commit bot

Move zone_ to Scope

Pass in zone() explicitly to SloppyBlockFunctionMap::Declare and VariableMap::Declare instead.

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2223773002
Cr-Commit-Position: refs/heads/master@{#38424}
parent 2b10616b
...@@ -24,12 +24,11 @@ namespace internal { ...@@ -24,12 +24,11 @@ namespace internal {
// this is ensured. // this is ensured.
VariableMap::VariableMap(Zone* zone) VariableMap::VariableMap(Zone* zone)
: ZoneHashMap(ZoneHashMap::PointersMatch, 8, ZoneAllocationPolicy(zone)), : ZoneHashMap(ZoneHashMap::PointersMatch, 8, ZoneAllocationPolicy(zone)) {}
zone_(zone) {}
VariableMap::~VariableMap() {}
Variable* VariableMap::Declare(Scope* scope, const AstRawString* name, Variable* VariableMap::Declare(Zone* zone, Scope* scope,
VariableMode mode, Variable::Kind kind, const AstRawString* name, VariableMode mode,
Variable::Kind kind,
InitializationFlag initialization_flag, InitializationFlag initialization_flag,
MaybeAssignedFlag maybe_assigned_flag) { MaybeAssignedFlag maybe_assigned_flag) {
// AstRawStrings are unambiguous, i.e., the same string is always represented // AstRawStrings are unambiguous, i.e., the same string is always represented
...@@ -37,12 +36,12 @@ Variable* VariableMap::Declare(Scope* scope, const AstRawString* name, ...@@ -37,12 +36,12 @@ Variable* VariableMap::Declare(Scope* scope, const AstRawString* name,
// FIXME(marja): fix the type of Lookup. // FIXME(marja): fix the type of Lookup.
Entry* p = Entry* p =
ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(), ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(),
ZoneAllocationPolicy(zone())); ZoneAllocationPolicy(zone));
if (p->value == NULL) { if (p->value == NULL) {
// The variable has not been declared yet -> insert it. // The variable has not been declared yet -> insert it.
DCHECK(p->key == name); DCHECK(p->key == name);
p->value = new (zone()) Variable(scope, name, mode, kind, p->value = new (zone) Variable(scope, name, mode, kind, initialization_flag,
initialization_flag, maybe_assigned_flag); maybe_assigned_flag);
} }
return reinterpret_cast<Variable*>(p->value); return reinterpret_cast<Variable*>(p->value);
} }
...@@ -58,22 +57,18 @@ Variable* VariableMap::Lookup(const AstRawString* name) { ...@@ -58,22 +57,18 @@ Variable* VariableMap::Lookup(const AstRawString* name) {
return NULL; return NULL;
} }
SloppyBlockFunctionMap::SloppyBlockFunctionMap(Zone* zone) SloppyBlockFunctionMap::SloppyBlockFunctionMap(Zone* zone)
: ZoneHashMap(ZoneHashMap::PointersMatch, 8, ZoneAllocationPolicy(zone)), : ZoneHashMap(ZoneHashMap::PointersMatch, 8, ZoneAllocationPolicy(zone)) {}
zone_(zone) {}
SloppyBlockFunctionMap::~SloppyBlockFunctionMap() {}
void SloppyBlockFunctionMap::Declare(const AstRawString* name, void SloppyBlockFunctionMap::Declare(Zone* zone, const AstRawString* name,
SloppyBlockFunctionStatement* stmt) { SloppyBlockFunctionStatement* stmt) {
// AstRawStrings are unambiguous, i.e., the same string is always represented // AstRawStrings are unambiguous, i.e., the same string is always represented
// by the same AstRawString*. // by the same AstRawString*.
Entry* p = Entry* p =
ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(), ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(),
ZoneAllocationPolicy(zone_)); ZoneAllocationPolicy(zone));
if (p->value == nullptr) { if (p->value == nullptr) {
p->value = new (zone_->New(sizeof(Vector))) Vector(zone_); p->value = new (zone->New(sizeof(Vector))) Vector(zone);
} }
Vector* delegates = static_cast<Vector*>(p->value); Vector* delegates = static_cast<Vector*>(p->value);
delegates->push_back(stmt); delegates->push_back(stmt);
...@@ -84,7 +79,8 @@ void SloppyBlockFunctionMap::Declare(const AstRawString* name, ...@@ -84,7 +79,8 @@ void SloppyBlockFunctionMap::Declare(const AstRawString* name,
// Implementation of Scope // Implementation of Scope
Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type) Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type)
: outer_scope_(outer_scope), : zone_(zone),
outer_scope_(outer_scope),
variables_(zone), variables_(zone),
decls_(4, zone), decls_(4, zone),
scope_type_(scope_type), scope_type_(scope_type),
...@@ -128,7 +124,8 @@ DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope, ...@@ -128,7 +124,8 @@ DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope,
Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type,
Handle<ScopeInfo> scope_info) Handle<ScopeInfo> scope_info)
: outer_scope_(nullptr), : zone_(zone),
outer_scope_(nullptr),
variables_(zone), variables_(zone),
decls_(4, zone), decls_(4, zone),
scope_info_(scope_info), scope_info_(scope_info),
...@@ -161,7 +158,8 @@ DeclarationScope::DeclarationScope(Zone* zone, Scope* inner_scope, ...@@ -161,7 +158,8 @@ DeclarationScope::DeclarationScope(Zone* zone, Scope* inner_scope,
Scope::Scope(Zone* zone, Scope* inner_scope, Scope::Scope(Zone* zone, Scope* inner_scope,
const AstRawString* catch_variable_name) const AstRawString* catch_variable_name)
: outer_scope_(nullptr), : zone_(zone),
outer_scope_(nullptr),
variables_(zone), variables_(zone),
decls_(0, zone), decls_(0, zone),
scope_type_(CATCH_SCOPE), scope_type_(CATCH_SCOPE),
...@@ -169,11 +167,9 @@ Scope::Scope(Zone* zone, Scope* inner_scope, ...@@ -169,11 +167,9 @@ Scope::Scope(Zone* zone, Scope* inner_scope,
SetDefaults(); SetDefaults();
AddInnerScope(inner_scope); AddInnerScope(inner_scope);
num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; num_heap_slots_ = Context::MIN_CONTEXT_SLOTS;
Variable* variable = variables_.Declare(this, Variable* variable =
catch_variable_name, variables_.Declare(zone, this, catch_variable_name, VAR, Variable::NORMAL,
VAR, kCreatedInitialized);
Variable::NORMAL,
kCreatedInitialized);
AllocateHeapSlot(variable); AllocateHeapSlot(variable);
} }
...@@ -313,8 +309,8 @@ void Scope::DeserializeScopeInfo(Isolate* isolate, ...@@ -313,8 +309,8 @@ void Scope::DeserializeScopeInfo(Isolate* isolate,
kind = Variable::THIS; kind = Variable::THIS;
} }
Variable* result = variables_.Declare(this, name, mode, kind, init_flag, Variable* result = variables_.Declare(zone(), this, name, mode, kind,
maybe_assigned_flag); init_flag, maybe_assigned_flag);
result->AllocateTo(location, index); result->AllocateTo(location, index);
} }
...@@ -333,8 +329,8 @@ void Scope::DeserializeScopeInfo(Isolate* isolate, ...@@ -333,8 +329,8 @@ void Scope::DeserializeScopeInfo(Isolate* isolate,
VariableLocation location = VariableLocation::LOOKUP; VariableLocation location = VariableLocation::LOOKUP;
Variable::Kind kind = Variable::NORMAL; Variable::Kind kind = Variable::NORMAL;
Variable* result = variables_.Declare(this, name, mode, kind, init_flag, Variable* result = variables_.Declare(zone(), this, name, mode, kind,
maybe_assigned_flag); init_flag, maybe_assigned_flag);
result->AllocateTo(location, index); result->AllocateTo(location, index);
} }
...@@ -408,7 +404,7 @@ void DeclarationScope::DeclareThis(AstValueFactory* ast_value_factory) { ...@@ -408,7 +404,7 @@ void DeclarationScope::DeclareThis(AstValueFactory* ast_value_factory) {
bool subclass_constructor = IsSubclassConstructor(function_kind_); bool subclass_constructor = IsSubclassConstructor(function_kind_);
Variable* var = variables_.Declare( Variable* var = variables_.Declare(
this, ast_value_factory->this_string(), zone(), this, ast_value_factory->this_string(),
subclass_constructor ? CONST : VAR, Variable::THIS, subclass_constructor ? CONST : VAR, Variable::THIS,
subclass_constructor ? kNeedsInitialization : kCreatedInitialized); subclass_constructor ? kNeedsInitialization : kCreatedInitialized);
receiver_ = var; receiver_ = var;
...@@ -422,18 +418,18 @@ void DeclarationScope::DeclareDefaultFunctionVariables( ...@@ -422,18 +418,18 @@ void DeclarationScope::DeclareDefaultFunctionVariables(
// Note that it might never be accessed, in which case it won't be // Note that it might never be accessed, in which case it won't be
// allocated during variable allocation. // allocated during variable allocation.
arguments_ = arguments_ =
variables_.Declare(this, ast_value_factory->arguments_string(), VAR, variables_.Declare(zone(), this, ast_value_factory->arguments_string(),
Variable::ARGUMENTS, kCreatedInitialized); VAR, Variable::ARGUMENTS, kCreatedInitialized);
new_target_ = new_target_ =
variables_.Declare(this, ast_value_factory->new_target_string(), CONST, variables_.Declare(zone(), this, ast_value_factory->new_target_string(),
Variable::NORMAL, kCreatedInitialized); CONST, Variable::NORMAL, kCreatedInitialized);
if (IsConciseMethod(function_kind_) || IsClassConstructor(function_kind_) || if (IsConciseMethod(function_kind_) || IsClassConstructor(function_kind_) ||
IsAccessorFunction(function_kind_)) { IsAccessorFunction(function_kind_)) {
this_function_ = this_function_ = variables_.Declare(
variables_.Declare(this, ast_value_factory->this_function_string(), zone(), this, ast_value_factory->this_function_string(), CONST,
CONST, Variable::NORMAL, kCreatedInitialized); Variable::NORMAL, kCreatedInitialized);
} }
} }
...@@ -598,7 +594,7 @@ Variable* Scope::LookupLocal(const AstRawString* name) { ...@@ -598,7 +594,7 @@ Variable* Scope::LookupLocal(const AstRawString* name) {
// TODO(marja, rossberg): Correctly declare FUNCTION, CLASS, NEW_TARGET, and // TODO(marja, rossberg): Correctly declare FUNCTION, CLASS, NEW_TARGET, and
// ARGUMENTS bindings as their corresponding Variable::Kind. // ARGUMENTS bindings as their corresponding Variable::Kind.
Variable* var = variables_.Declare(this, name, mode, kind, init_flag, Variable* var = variables_.Declare(zone(), this, name, mode, kind, init_flag,
maybe_assigned_flag); maybe_assigned_flag);
var->AllocateTo(location, index); var->AllocateTo(location, index);
return var; return var;
...@@ -649,7 +645,7 @@ Variable* DeclarationScope::DeclareParameter( ...@@ -649,7 +645,7 @@ Variable* DeclarationScope::DeclareParameter(
if (mode == TEMPORARY) { if (mode == TEMPORARY) {
var = NewTemporary(name); var = NewTemporary(name);
} else { } else {
var = variables_.Declare(this, name, mode, Variable::NORMAL, var = variables_.Declare(zone(), this, name, mode, Variable::NORMAL,
kCreatedInitialized); kCreatedInitialized);
// TODO(wingo): Avoid O(n^2) check. // TODO(wingo): Avoid O(n^2) check.
*is_duplicate = IsDeclaredParameter(name); *is_duplicate = IsDeclaredParameter(name);
...@@ -677,17 +673,14 @@ Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, ...@@ -677,17 +673,14 @@ Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode,
// introduced during variable allocation, and TEMPORARY variables are // introduced during variable allocation, and TEMPORARY variables are
// allocated via NewTemporary(). // allocated via NewTemporary().
DCHECK(IsDeclaredVariableMode(mode)); DCHECK(IsDeclaredVariableMode(mode));
return variables_.Declare(this, name, mode, kind, init_flag, return variables_.Declare(zone(), this, name, mode, kind, init_flag,
maybe_assigned_flag); maybe_assigned_flag);
} }
Variable* DeclarationScope::DeclareDynamicGlobal(const AstRawString* name) { Variable* DeclarationScope::DeclareDynamicGlobal(const AstRawString* name) {
DCHECK(is_script_scope()); DCHECK(is_script_scope());
return variables_.Declare(this, return variables_.Declare(zone(), this, name, DYNAMIC_GLOBAL,
name, Variable::NORMAL, kCreatedInitialized);
DYNAMIC_GLOBAL,
Variable::NORMAL,
kCreatedInitialized);
} }
...@@ -1266,11 +1259,7 @@ Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) { ...@@ -1266,11 +1259,7 @@ Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) {
// Declare a new non-local. // Declare a new non-local.
InitializationFlag init_flag = (mode == VAR) InitializationFlag init_flag = (mode == VAR)
? kCreatedInitialized : kNeedsInitialization; ? kCreatedInitialized : kNeedsInitialization;
var = map->Declare(NULL, var = map->Declare(zone(), NULL, name, mode, Variable::NORMAL, init_flag);
name,
mode,
Variable::NORMAL,
init_flag);
// Allocate it by giving it a dynamic lookup. // Allocate it by giving it a dynamic lookup.
var->AllocateTo(VariableLocation::LOOKUP, -1); var->AllocateTo(VariableLocation::LOOKUP, -1);
} }
......
...@@ -20,18 +20,12 @@ class VariableMap: public ZoneHashMap { ...@@ -20,18 +20,12 @@ class VariableMap: public ZoneHashMap {
public: public:
explicit VariableMap(Zone* zone); explicit VariableMap(Zone* zone);
virtual ~VariableMap(); Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name,
VariableMode mode, Variable::Kind kind,
Variable* Declare(Scope* scope, const AstRawString* name, VariableMode mode, InitializationFlag initialization_flag,
Variable::Kind kind, InitializationFlag initialization_flag,
MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); MaybeAssignedFlag maybe_assigned_flag = kNotAssigned);
Variable* Lookup(const AstRawString* name); Variable* Lookup(const AstRawString* name);
Zone* zone() const { return zone_; }
private:
Zone* zone_;
}; };
...@@ -61,16 +55,9 @@ class DynamicScopePart : public ZoneObject { ...@@ -61,16 +55,9 @@ class DynamicScopePart : public ZoneObject {
class SloppyBlockFunctionMap : public ZoneHashMap { class SloppyBlockFunctionMap : public ZoneHashMap {
public: public:
explicit SloppyBlockFunctionMap(Zone* zone); explicit SloppyBlockFunctionMap(Zone* zone);
void Declare(Zone* zone, const AstRawString* name,
virtual ~SloppyBlockFunctionMap();
void Declare(const AstRawString* name,
SloppyBlockFunctionStatement* statement); SloppyBlockFunctionStatement* statement);
typedef ZoneVector<SloppyBlockFunctionStatement*> Vector; typedef ZoneVector<SloppyBlockFunctionStatement*> Vector;
private:
Zone* zone_;
}; };
...@@ -150,7 +137,7 @@ class Scope: public ZoneObject { ...@@ -150,7 +137,7 @@ class Scope: public ZoneObject {
// to the passed-in scope. // to the passed-in scope.
void PropagateUsageFlagsToScope(Scope* other); void PropagateUsageFlagsToScope(Scope* other);
Zone* zone() const { return variables_.zone(); } Zone* zone() const { return zone_; }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Declarations // Declarations
...@@ -464,6 +451,8 @@ class Scope: public ZoneObject { ...@@ -464,6 +451,8 @@ class Scope: public ZoneObject {
bool HasSimpleParameters(); bool HasSimpleParameters();
private: private:
Zone* zone_;
// Scope tree. // Scope tree.
Scope* outer_scope_; // the immediately enclosing outer scope, or NULL Scope* outer_scope_; // the immediately enclosing outer scope, or NULL
Scope* inner_scope_; // an inner scope of this scope Scope* inner_scope_; // an inner scope of this scope
...@@ -835,6 +824,11 @@ class DeclarationScope : public Scope { ...@@ -835,6 +824,11 @@ class DeclarationScope : public Scope {
ZoneList<Variable*>* temps() { return &temps_; } ZoneList<Variable*>* temps() { return &temps_; }
void DeclareSloppyBlockFunction(const AstRawString* name,
SloppyBlockFunctionStatement* statement) {
sloppy_block_function_map_.Declare(zone(), name, statement);
}
SloppyBlockFunctionMap* sloppy_block_function_map() { SloppyBlockFunctionMap* sloppy_block_function_map() {
return &sloppy_block_function_map_; return &sloppy_block_function_map_;
} }
......
...@@ -2274,8 +2274,8 @@ Statement* Parser::ParseHoistableDeclaration( ...@@ -2274,8 +2274,8 @@ Statement* Parser::ParseHoistableDeclaration(
!is_async && !(allow_harmony_restrictive_generators() && is_generator)) { !is_async && !(allow_harmony_restrictive_generators() && is_generator)) {
SloppyBlockFunctionStatement* delegate = SloppyBlockFunctionStatement* delegate =
factory()->NewSloppyBlockFunctionStatement(empty, scope()); factory()->NewSloppyBlockFunctionStatement(empty, scope());
scope()->GetDeclarationScope()->sloppy_block_function_map()->Declare( DeclarationScope* target_scope = scope()->GetDeclarationScope();
variable_name, delegate); target_scope->DeclareSloppyBlockFunction(variable_name, delegate);
return delegate; return delegate;
} }
return empty; return empty;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment