Commit ed2f9b8a authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Use VariableKind rather than DeclarationDescriptor::Kind in DeclareVariable

Change-Id: I3acb492f1b9930e574bfbad063f54b20eab26bf1
Reviewed-on: https://chromium-review.googlesource.com/c/1405033Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58705}
parent d0e95c7a
......@@ -1346,13 +1346,12 @@ VariableProxy* Parser::DeclareVariable(const AstRawString* name,
DCHECK_NOT_NULL(name);
VariableProxy* proxy =
factory()->NewVariableProxy(name, NORMAL_VARIABLE, position());
DeclareVariable(proxy, DeclarationDescriptor::NORMAL, mode, init, scope(),
pos, end_position());
DeclareVariable(proxy, NORMAL_VARIABLE, mode, init, scope(), pos,
end_position());
return proxy;
}
void Parser::DeclareVariable(VariableProxy* proxy,
DeclarationDescriptor::Kind kind,
void Parser::DeclareVariable(VariableProxy* proxy, VariableKind kind,
VariableMode mode, InitializationFlag init,
Scope* scope, int begin, int end) {
Declaration* declaration;
......@@ -1365,17 +1364,14 @@ void Parser::DeclareVariable(VariableProxy* proxy,
Declare(declaration, kind, mode, init, scope, end);
}
void Parser::Declare(Declaration* declaration,
DeclarationDescriptor::Kind declaration_kind,
void Parser::Declare(Declaration* declaration, VariableKind variable_kind,
VariableMode mode, InitializationFlag init, Scope* scope,
int var_end_pos) {
bool local_ok = true;
bool sloppy_mode_block_scope_function_redefinition = false;
scope->DeclareVariable(
declaration, mode,
declaration_kind == DeclarationDescriptor::PARAMETER ? PARAMETER_VARIABLE
: NORMAL_VARIABLE,
init, &sloppy_mode_block_scope_function_redefinition, &local_ok);
scope->DeclareVariable(declaration, mode, variable_kind, init,
&sloppy_mode_block_scope_function_redefinition,
&local_ok);
if (!local_ok) {
// If we only have the start position of a proxy, we can't highlight the
// whole variable name. Pretend its length is 1 so that we highlight at
......@@ -1384,7 +1380,7 @@ void Parser::Declare(Declaration* declaration,
var_end_pos != kNoSourcePosition
? var_end_pos
: declaration->proxy()->position() + 1);
if (declaration_kind == DeclarationDescriptor::PARAMETER) {
if (variable_kind == PARAMETER_VARIABLE) {
ReportMessageAt(loc, MessageTemplate::kParamDupe);
} else {
ReportMessageAt(loc, MessageTemplate::kVarRedeclaration,
......@@ -1414,8 +1410,7 @@ Statement* Parser::DeclareFunction(const AstRawString* variable_name,
factory()->NewVariableProxy(variable_name, NORMAL_VARIABLE, pos);
Declaration* declaration = factory()->NewFunctionDeclaration(
proxy, function, is_sloppy_block_function, pos);
Declare(declaration, DeclarationDescriptor::NORMAL, mode, kCreatedInitialized,
scope());
Declare(declaration, NORMAL_VARIABLE, mode, kCreatedInitialized, scope());
if (names) names->Add(variable_name, zone());
if (is_sloppy_block_function) {
SloppyBlockFunctionStatement* statement =
......
......@@ -445,12 +445,11 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
int pos);
VariableProxy* DeclareVariable(const AstRawString* name, VariableMode mode,
InitializationFlag init, int pos);
void DeclareVariable(VariableProxy* proxy, DeclarationDescriptor::Kind,
void DeclareVariable(VariableProxy* proxy, VariableKind kind,
VariableMode mode, InitializationFlag init,
Scope* declaration_scope, int begin,
int end = kNoSourcePosition);
void Declare(Declaration* declaration,
DeclarationDescriptor::Kind declaration_kind, VariableMode mode,
void Declare(Declaration* declaration, VariableKind kind, VariableMode mode,
InitializationFlag init, Scope* declaration_scope,
int var_end_pos = kNoSourcePosition);
......
......@@ -197,8 +197,12 @@ void PatternRewriter::VisitVariableProxy(VariableProxy* proxy) {
proxy->position());
}
VariableKind kind =
descriptor_->declaration_kind == DeclarationDescriptor::PARAMETER
? PARAMETER_VARIABLE
: NORMAL_VARIABLE;
parser_->DeclareVariable(
proxy, descriptor_->declaration_kind, descriptor_->mode,
proxy, kind, descriptor_->mode,
Variable::DefaultInitializationFlag(descriptor_->mode), target_scope,
descriptor_->declaration_pos);
......
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