Commit 50f52476 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Simplify Scope::Declare

Change-Id: I3f2f6f82af84489f0563fa74c315e46b9c746325
Reviewed-on: https://chromium-review.googlesource.com/c/1322950
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57318}
parent 014d9e4f
......@@ -48,19 +48,20 @@ Variable* VariableMap::Declare(Zone* zone, Scope* scope,
VariableKind kind,
InitializationFlag initialization_flag,
MaybeAssignedFlag maybe_assigned_flag,
bool* added) {
base::ThreadedList<Variable>* variable_list) {
// AstRawStrings are unambiguous, i.e., the same string is always represented
// by the same AstRawString*.
// FIXME(marja): fix the type of Lookup.
Entry* p =
ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->Hash(),
ZoneAllocationPolicy(zone));
if (added) *added = p->value == nullptr;
if (p->value == nullptr) {
// The variable has not been declared yet -> insert it.
DCHECK_EQ(name, p->key);
p->value = new (zone) Variable(scope, name, mode, kind, initialization_flag,
maybe_assigned_flag);
Variable* variable = new (zone) Variable(
scope, name, mode, kind, initialization_flag, maybe_assigned_flag);
if (variable_list) variable_list->Add(variable);
p->value = variable;
}
return reinterpret_cast<Variable*>(p->value);
}
......@@ -850,18 +851,6 @@ void DeclarationScope::AddLocal(Variable* var) {
locals_.Add(var);
}
Variable* Scope::Declare(Zone* zone, const AstRawString* name,
VariableMode mode, VariableKind kind,
InitializationFlag initialization_flag,
MaybeAssignedFlag maybe_assigned_flag) {
bool added;
Variable* var =
variables_.Declare(zone, this, name, mode, kind, initialization_flag,
maybe_assigned_flag, &added);
if (added) locals_.Add(var);
return var;
}
void Scope::Snapshot::Reparent(DeclarationScope* new_parent) const {
DCHECK_EQ(new_parent, outer_scope_and_calls_eval_.GetPointer()->inner_scope_);
DCHECK_EQ(new_parent->outer_scope_, outer_scope_and_calls_eval_.GetPointer());
......
......@@ -37,7 +37,7 @@ class VariableMap: public ZoneHashMap {
VariableKind kind = NORMAL_VARIABLE,
InitializationFlag initialization_flag = kCreatedInitialized,
MaybeAssignedFlag maybe_assigned_flag = kNotAssigned,
bool* added = nullptr);
base::ThreadedList<Variable>* variable_list = nullptr);
// Records that "name" exists (if not recorded yet) but doesn't create a
// Variable. Useful for preparsing.
......@@ -497,7 +497,10 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
Zone* zone, const AstRawString* name, VariableMode mode,
VariableKind kind = NORMAL_VARIABLE,
InitializationFlag initialization_flag = kCreatedInitialized,
MaybeAssignedFlag maybe_assigned_flag = kNotAssigned);
MaybeAssignedFlag maybe_assigned_flag = kNotAssigned) {
return variables_.Declare(zone, this, name, mode, kind, initialization_flag,
maybe_assigned_flag, &locals_);
}
// This method should only be invoked on scopes created during parsing (i.e.,
// not deserialized from a context). Also, since NeedsContext() is only
......
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