Commit 31beac34 authored by marja's avatar marja Committed by Commit bot

Scope cleanup: add default params for variable declaring functions.

This makes it clearer which places are creating variables which are
something else than NORMAL_VARIABLE + kCreatedInitialized.

BUG=

Review-Url: https://codereview.chromium.org/2631173002
Cr-Commit-Position: refs/heads/master@{#42395}
parent 5883bf21
...@@ -277,8 +277,7 @@ Scope::Scope(Zone* zone, const AstRawString* catch_variable_name, ...@@ -277,8 +277,7 @@ Scope::Scope(Zone* zone, const AstRawString* catch_variable_name,
// Cache the catch variable, even though it's also available via the // Cache the catch variable, even though it's also available via the
// scope_info, as the parser expects that a catch scope always has the catch // scope_info, as the parser expects that a catch scope always has the catch
// variable as first and only variable. // variable as first and only variable.
Variable* variable = Declare(zone, catch_variable_name, VAR, NORMAL_VARIABLE, Variable* variable = Declare(zone, catch_variable_name, VAR);
kCreatedInitialized);
AllocateHeapSlot(variable); AllocateHeapSlot(variable);
} }
...@@ -655,8 +654,7 @@ void DeclarationScope::DeclareArguments(AstValueFactory* ast_value_factory) { ...@@ -655,8 +654,7 @@ void DeclarationScope::DeclareArguments(AstValueFactory* ast_value_factory) {
// Declare 'arguments' variable which exists in all non arrow functions. // Declare 'arguments' variable which exists in all non arrow functions.
// 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_ = Declare(zone(), ast_value_factory->arguments_string(), VAR, arguments_ = Declare(zone(), ast_value_factory->arguments_string(), VAR);
NORMAL_VARIABLE, kCreatedInitialized);
} else if (IsLexicalVariableMode(arguments_->mode())) { } else if (IsLexicalVariableMode(arguments_->mode())) {
// Check if there's lexically declared variable named arguments to avoid // Check if there's lexically declared variable named arguments to avoid
// redeclaration. See ES#sec-functiondeclarationinstantiation, step 20. // redeclaration. See ES#sec-functiondeclarationinstantiation, step 20.
...@@ -670,13 +668,12 @@ void DeclarationScope::DeclareDefaultFunctionVariables( ...@@ -670,13 +668,12 @@ void DeclarationScope::DeclareDefaultFunctionVariables(
DCHECK(!is_arrow_scope()); DCHECK(!is_arrow_scope());
DeclareThis(ast_value_factory); DeclareThis(ast_value_factory);
new_target_ = Declare(zone(), ast_value_factory->new_target_string(), CONST, new_target_ = Declare(zone(), ast_value_factory->new_target_string(), CONST);
NORMAL_VARIABLE, kCreatedInitialized);
if (IsConciseMethod(function_kind_) || IsClassConstructor(function_kind_) || if (IsConciseMethod(function_kind_) || IsClassConstructor(function_kind_) ||
IsAccessorFunction(function_kind_)) { IsAccessorFunction(function_kind_)) {
this_function_ = Declare(zone(), ast_value_factory->this_function_string(), this_function_ =
CONST, NORMAL_VARIABLE, kCreatedInitialized); Declare(zone(), ast_value_factory->this_function_string(), CONST);
} }
} }
...@@ -931,7 +928,7 @@ Variable* DeclarationScope::DeclareParameter( ...@@ -931,7 +928,7 @@ Variable* DeclarationScope::DeclareParameter(
if (mode == TEMPORARY) { if (mode == TEMPORARY) {
var = NewTemporary(name); var = NewTemporary(name);
} else { } else {
var = Declare(zone(), name, mode, NORMAL_VARIABLE, kCreatedInitialized); var = Declare(zone(), name, mode);
// TODO(wingo): Avoid O(n^2) check. // TODO(wingo): Avoid O(n^2) check.
*is_duplicate = IsDeclaredParameter(name); *is_duplicate = IsDeclaredParameter(name);
} }
...@@ -1108,8 +1105,7 @@ void Scope::AddUnresolved(VariableProxy* proxy) { ...@@ -1108,8 +1105,7 @@ void Scope::AddUnresolved(VariableProxy* proxy) {
Variable* DeclarationScope::DeclareDynamicGlobal(const AstRawString* name, Variable* DeclarationScope::DeclareDynamicGlobal(const AstRawString* name,
VariableKind kind) { VariableKind kind) {
DCHECK(is_script_scope()); DCHECK(is_script_scope());
return variables_.Declare(zone(), this, name, DYNAMIC_GLOBAL, kind, return variables_.Declare(zone(), this, name, DYNAMIC_GLOBAL, kind);
kCreatedInitialized);
} }
...@@ -1637,8 +1633,7 @@ void Scope::CheckZones() { ...@@ -1637,8 +1633,7 @@ void Scope::CheckZones() {
Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) { Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) {
// Declare a new non-local. // Declare a new non-local.
DCHECK(IsDynamicVariableMode(mode)); DCHECK(IsDynamicVariableMode(mode));
Variable* var = variables_.Declare(zone(), NULL, name, mode, NORMAL_VARIABLE, Variable* var = variables_.Declare(zone(), nullptr, name, mode);
kCreatedInitialized);
// 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);
return var; return var;
......
...@@ -30,11 +30,12 @@ class VariableMap: public ZoneHashMap { ...@@ -30,11 +30,12 @@ class VariableMap: public ZoneHashMap {
public: public:
explicit VariableMap(Zone* zone); explicit VariableMap(Zone* zone);
Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, Variable* Declare(
VariableMode mode, VariableKind kind, Zone* zone, Scope* scope, const AstRawString* name, VariableMode mode,
InitializationFlag initialization_flag, VariableKind kind = NORMAL_VARIABLE,
MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, InitializationFlag initialization_flag = kCreatedInitialized,
bool* added = nullptr); MaybeAssignedFlag maybe_assigned_flag = kNotAssigned,
bool* added = nullptr);
// Records that "name" exists (if not recorded yet) but doesn't create a // Records that "name" exists (if not recorded yet) but doesn't create a
// Variable. Useful for preparsing. // Variable. Useful for preparsing.
...@@ -169,7 +170,8 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) { ...@@ -169,7 +170,8 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
// Declare a local variable in this scope. If the variable has been // Declare a local variable in this scope. If the variable has been
// declared before, the previously declared variable is returned. // declared before, the previously declared variable is returned.
Variable* DeclareLocal(const AstRawString* name, VariableMode mode, Variable* DeclareLocal(const AstRawString* name, VariableMode mode,
InitializationFlag init_flag, VariableKind kind, InitializationFlag init_flag = kCreatedInitialized,
VariableKind kind = NORMAL_VARIABLE,
MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); MaybeAssignedFlag maybe_assigned_flag = kNotAssigned);
Variable* DeclareVariable(Declaration* declaration, VariableMode mode, Variable* DeclareVariable(Declaration* declaration, VariableMode mode,
...@@ -467,9 +469,11 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) { ...@@ -467,9 +469,11 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
} }
private: private:
Variable* Declare(Zone* zone, const AstRawString* name, VariableMode mode, Variable* Declare(
VariableKind kind, InitializationFlag initialization_flag, Zone* zone, const AstRawString* name, VariableMode mode,
MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); VariableKind kind = NORMAL_VARIABLE,
InitializationFlag initialization_flag = kCreatedInitialized,
MaybeAssignedFlag maybe_assigned_flag = kNotAssigned);
// This method should only be invoked on scopes created during parsing (i.e., // This method should only be invoked on scopes created during parsing (i.e.,
// not deserialized from a context). Also, since NeedsContext() is only // not deserialized from a context). Also, since NeedsContext() is only
......
...@@ -1669,8 +1669,7 @@ void Parser::RewriteCatchPattern(CatchInfo* catch_info, bool* ok) { ...@@ -1669,8 +1669,7 @@ void Parser::RewriteCatchPattern(CatchInfo* catch_info, bool* ok) {
DCHECK_NOT_NULL(catch_info->pattern); DCHECK_NOT_NULL(catch_info->pattern);
catch_info->name = ast_value_factory()->dot_catch_string(); catch_info->name = ast_value_factory()->dot_catch_string();
} }
catch_info->variable = catch_info->scope->DeclareLocal( catch_info->variable = catch_info->scope->DeclareLocal(catch_info->name, VAR);
catch_info->name, VAR, kCreatedInitialized, NORMAL_VARIABLE);
if (catch_info->pattern != nullptr) { if (catch_info->pattern != nullptr) {
DeclarationDescriptor descriptor; DeclarationDescriptor descriptor;
descriptor.declaration_kind = DeclarationDescriptor::NORMAL; descriptor.declaration_kind = DeclarationDescriptor::NORMAL;
...@@ -2951,8 +2950,7 @@ Block* Parser::BuildRejectPromiseOnException(Block* inner_block, bool* ok) { ...@@ -2951,8 +2950,7 @@ Block* Parser::BuildRejectPromiseOnException(Block* inner_block, bool* ok) {
Scope* catch_scope = NewScope(CATCH_SCOPE); Scope* catch_scope = NewScope(CATCH_SCOPE);
catch_scope->set_is_hidden(); catch_scope->set_is_hidden();
Variable* catch_variable = Variable* catch_variable =
catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR, catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR);
kCreatedInitialized, NORMAL_VARIABLE);
Block* catch_block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); Block* catch_block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition);
Expression* promise_reject = BuildRejectPromise( Expression* promise_reject = BuildRejectPromise(
...@@ -4586,8 +4584,7 @@ Expression* Parser::RewriteYieldStar(Expression* generator, ...@@ -4586,8 +4584,7 @@ Expression* Parser::RewriteYieldStar(Expression* generator,
Scope* catch_scope = NewScope(CATCH_SCOPE); Scope* catch_scope = NewScope(CATCH_SCOPE);
catch_scope->set_is_hidden(); catch_scope->set_is_hidden();
const AstRawString* name = ast_value_factory()->dot_catch_string(); const AstRawString* name = ast_value_factory()->dot_catch_string();
Variable* catch_variable = catch_scope->DeclareLocal( Variable* catch_variable = catch_scope->DeclareLocal(name, VAR);
name, VAR, kCreatedInitialized, NORMAL_VARIABLE);
try_catch = factory()->NewTryCatchStatementForDesugaring( try_catch = factory()->NewTryCatchStatementForDesugaring(
try_block, catch_scope, catch_variable, catch_block, nopos); try_block, catch_scope, catch_variable, catch_block, nopos);
...@@ -4873,8 +4870,7 @@ void Parser::FinalizeIteratorUse(Scope* use_scope, Variable* completion, ...@@ -4873,8 +4870,7 @@ void Parser::FinalizeIteratorUse(Scope* use_scope, Variable* completion,
{ {
Scope* catch_scope = NewScopeWithParent(use_scope, CATCH_SCOPE); Scope* catch_scope = NewScopeWithParent(use_scope, CATCH_SCOPE);
Variable* catch_variable = Variable* catch_variable =
catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR, catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR);
kCreatedInitialized, NORMAL_VARIABLE);
catch_scope->set_is_hidden(); catch_scope->set_is_hidden();
Statement* rethrow; Statement* rethrow;
...@@ -4980,8 +4976,7 @@ void Parser::BuildIteratorCloseForCompletion(Scope* scope, ...@@ -4980,8 +4976,7 @@ void Parser::BuildIteratorCloseForCompletion(Scope* scope,
Scope* catch_scope = NewScopeWithParent(scope, CATCH_SCOPE); Scope* catch_scope = NewScopeWithParent(scope, CATCH_SCOPE);
Variable* catch_variable = Variable* catch_variable =
catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR, catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR);
kCreatedInitialized, NORMAL_VARIABLE);
catch_scope->set_is_hidden(); catch_scope->set_is_hidden();
try_call_return = factory()->NewTryCatchStatement( try_call_return = factory()->NewTryCatchStatement(
......
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