Commit 4424f5d1 authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[parser|cleanup] Remove unnecessary ExpressionClassifying.

ExpressionClassifier was used just for transmitting information back and forth
to DeclareFormalParameters.

As a bonus, we now do the Scope::IsDeclaredParameter check only when we're going
to use the information it produces.

BUG=v8:6092,v8:6474

Change-Id: Ib5ac6a779705caa74e933e1c6f03eaaf0f49bf05
Reviewed-on: https://chromium-review.googlesource.com/455836
Commit-Queue: Marja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45809}
parent 05b9778d
...@@ -1023,7 +1023,9 @@ Variable* DeclarationScope::DeclareParameter( ...@@ -1023,7 +1023,9 @@ Variable* DeclarationScope::DeclareParameter(
DCHECK_EQ(mode, VAR); DCHECK_EQ(mode, VAR);
var = Declare(zone(), name, mode); var = Declare(zone(), name, mode);
// TODO(wingo): Avoid O(n^2) check. // TODO(wingo): Avoid O(n^2) check.
*is_duplicate = IsDeclaredParameter(name); if (is_duplicate != nullptr) {
*is_duplicate = *is_duplicate || IsDeclaredParameter(name);
}
} }
has_rest_ = is_rest; has_rest_ = is_rest;
var->set_initializer_position(position); var->set_initializer_position(position);
......
...@@ -3763,7 +3763,8 @@ void ParserBase<Impl>::ParseFormalParameterList(FormalParametersT* parameters, ...@@ -3763,7 +3763,8 @@ void ParserBase<Impl>::ParseFormalParameterList(FormalParametersT* parameters,
} }
} }
impl()->DeclareFormalParameters(parameters->scope, parameters->params); impl()->DeclareFormalParameters(parameters->scope, parameters->params,
parameters->is_simple);
} }
template <typename Impl> template <typename Impl>
......
...@@ -682,7 +682,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) { ...@@ -682,7 +682,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
if (parsing_module_) { if (parsing_module_) {
// Declare the special module parameter. // Declare the special module parameter.
auto name = ast_value_factory()->empty_string(); auto name = ast_value_factory()->empty_string();
bool is_duplicate; bool is_duplicate = false;
bool is_rest = false; bool is_rest = false;
bool is_optional = false; bool is_optional = false;
auto var = auto var =
...@@ -901,7 +901,10 @@ FunctionLiteral* Parser::DoParseFunction(ParseInfo* info) { ...@@ -901,7 +901,10 @@ FunctionLiteral* Parser::DoParseFunction(ParseInfo* info) {
} else { } else {
// BindingIdentifier // BindingIdentifier
ParseFormalParameter(&formals, &ok); ParseFormalParameter(&formals, &ok);
if (ok) DeclareFormalParameters(formals.scope, formals.params); if (ok) {
DeclareFormalParameters(formals.scope, formals.params,
formals.is_simple);
}
} }
} }
...@@ -2506,15 +2509,11 @@ void Parser::DeclareArrowFunctionFormalParameters( ...@@ -2506,15 +2509,11 @@ void Parser::DeclareArrowFunctionFormalParameters(
return; return;
} }
ExpressionClassifier classifier(this); bool has_duplicate = false;
if (!parameters->is_simple) { DeclareFormalParameters(parameters->scope, parameters->params,
this->classifier()->RecordNonSimpleParameter(); parameters->is_simple, &has_duplicate);
} if (has_duplicate) {
DeclareFormalParameters(parameters->scope, parameters->params); *duplicate_loc = scanner()->location();
if (!this->classifier()
->is_valid_formal_parameter_list_without_duplicates()) {
*duplicate_loc =
this->classifier()->duplicate_formal_parameter_error().location;
} }
DCHECK_EQ(parameters->is_simple, parameters->scope->has_simple_parameters()); DCHECK_EQ(parameters->is_simple, parameters->scope->has_simple_parameters());
} }
......
...@@ -1085,11 +1085,10 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -1085,11 +1085,10 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
V8_INLINE void DeclareFormalParameters( V8_INLINE void DeclareFormalParameters(
DeclarationScope* scope, DeclarationScope* scope,
const ThreadedList<ParserFormalParameters::Parameter>& parameters) { const ThreadedList<ParserFormalParameters::Parameter>& parameters,
bool is_simple = classifier()->is_simple_parameter_list(); bool is_simple, bool* has_duplicate = nullptr) {
if (!is_simple) scope->SetHasNonSimpleParameters(); if (!is_simple) scope->SetHasNonSimpleParameters();
for (auto parameter : parameters) { for (auto parameter : parameters) {
bool is_duplicate = false;
bool is_optional = parameter->initializer != nullptr; bool is_optional = parameter->initializer != nullptr;
// If the parameter list is simple, declare the parameters normally with // If the parameter list is simple, declare the parameters normally with
// their names. If the parameter list is not simple, declare a temporary // their names. If the parameter list is not simple, declare a temporary
...@@ -1098,12 +1097,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -1098,12 +1097,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
scope->DeclareParameter( scope->DeclareParameter(
is_simple ? parameter->name : ast_value_factory()->empty_string(), is_simple ? parameter->name : ast_value_factory()->empty_string(),
is_simple ? VAR : TEMPORARY, is_optional, parameter->is_rest, is_simple ? VAR : TEMPORARY, is_optional, parameter->is_rest,
&is_duplicate, ast_value_factory(), parameter->position); has_duplicate, ast_value_factory(), parameter->position);
if (is_duplicate &&
classifier()->is_valid_formal_parameter_list_without_duplicates()) {
classifier()->RecordDuplicateFormalParameterError(
scanner()->location());
}
} }
} }
......
...@@ -1619,8 +1619,8 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1619,8 +1619,8 @@ class PreParser : public ParserBase<PreParser> {
V8_INLINE void DeclareFormalParameters( V8_INLINE void DeclareFormalParameters(
DeclarationScope* scope, DeclarationScope* scope,
const ThreadedList<PreParserFormalParameters::Parameter>& parameters) { const ThreadedList<PreParserFormalParameters::Parameter>& parameters,
bool is_simple = classifier()->is_simple_parameter_list(); bool is_simple) {
if (!is_simple) scope->SetHasNonSimpleParameters(); if (!is_simple) scope->SetHasNonSimpleParameters();
if (track_unresolved_variables_) { if (track_unresolved_variables_) {
DCHECK(FLAG_lazy_inner_functions); DCHECK(FLAG_lazy_inner_functions);
......
...@@ -126,7 +126,7 @@ function testHelper(type, strict, lazy, duplicate_params_string, ok) { ...@@ -126,7 +126,7 @@ function testHelper(type, strict, lazy, duplicate_params_string, ok) {
function test(type, strict, lazy, ok_if_param_list_simple) { function test(type, strict, lazy, ok_if_param_list_simple) {
// Simple duplicate params. // Simple duplicate params.
testHelper(type, strict, lazy, "dup, dup", ok_if_param_list_simple) testHelper(type, strict, lazy, "a, dup, dup, b", ok_if_param_list_simple)
if (strict != Strictness.STRICT_FUNCTION) { if (strict != Strictness.STRICT_FUNCTION) {
// Generate test cases where the duplicate parameter occurs because of // Generate test cases where the duplicate parameter occurs because of
...@@ -134,12 +134,12 @@ function test(type, strict, lazy, ok_if_param_list_simple) { ...@@ -134,12 +134,12 @@ function test(type, strict, lazy, ok_if_param_list_simple) {
// parameters are only allowed in simple parameter lists. These tests are // parameters are only allowed in simple parameter lists. These tests are
// not possible if a function declares itself strict, since non-simple // not possible if a function declares itself strict, since non-simple
// parameters are not allowed then. // parameters are not allowed then.
testHelper(type, strict, lazy, "[dup], dup", false); testHelper(type, strict, lazy, "a, [dup], dup, b", false);
testHelper(type, strict, lazy, "dup, {a: dup}", false); testHelper(type, strict, lazy, "a, dup, {b: dup}, c", false);
testHelper(type, strict, lazy, "{dup}, [dup]", false); testHelper(type, strict, lazy, "a, {dup}, [dup], b", false);
testHelper(type, strict, lazy, "dup, ...dup", false); testHelper(type, strict, lazy, "a, dup, ...dup", false);
testHelper(type, strict, lazy, "dup, dup, ...rest", false); testHelper(type, strict, lazy, "a, dup, dup, ...rest", false);
testHelper(type, strict, lazy, "dup, dup, a = 1", false); testHelper(type, strict, lazy, "a, dup, dup, b = 1", false);
} }
} }
......
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