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

[parser] Minor refactoring: parameter handling

- Different places used is_simple to mean different things; renamed one.

- No need to do Scope::SetHasNoSimpleParameters multiple times.

- Normally we create VAR parameters with a name, or (for destructuring
  parameters), TEMPORARY parmeters with an empty name. *Except* for
  destructuring rest parameters; then we create VAR a parameter with an empty
  name. This CL makes the empty-named parameter TEMPORARY instead of VAR.

- This makes it clear that Parser::DeclareFormalParameters declares exactly
  those params which Parser::BuildParamerterInitializationBlock doesn't declare.

- This unification doesn't change any functionality, but it makes sense to do
  since I'll need to make PreParser emulate what Parser does; this way I don't
  need to emulate the weird behavior.

BUG=v8:5501

Change-Id: Ifa6c116bc5908f4e03a36e74f47558888d1582bd
Reviewed-on: https://chromium-review.googlesource.com/443106Reviewed-by: 's avatarDaniel Vogelheim <vogelheim@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43220}
parent 717c8f2c
...@@ -2908,7 +2908,7 @@ Block* Parser::BuildParameterInitializationBlock( ...@@ -2908,7 +2908,7 @@ Block* Parser::BuildParameterInitializationBlock(
Block* init_block = factory()->NewBlock(NULL, 1, true, kNoSourcePosition); Block* init_block = factory()->NewBlock(NULL, 1, true, kNoSourcePosition);
int index = 0; int index = 0;
for (auto parameter : parameters.params) { for (auto parameter : parameters.params) {
if (parameter->is_rest && parameter->pattern->IsVariableProxy()) break; if (parameter->is_nondestructuring_rest()) break;
DeclarationDescriptor descriptor; DeclarationDescriptor descriptor;
descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; descriptor.declaration_kind = DeclarationDescriptor::PARAMETER;
descriptor.scope = scope(); descriptor.scope = scope();
......
...@@ -158,6 +158,12 @@ struct ParserFormalParameters : FormalParametersBase { ...@@ -158,6 +158,12 @@ struct ParserFormalParameters : FormalParametersBase {
bool is_simple() const { bool is_simple() const {
return pattern->IsVariableProxy() && initializer == nullptr && !is_rest; return pattern->IsVariableProxy() && initializer == nullptr && !is_rest;
} }
bool is_nondestructuring_rest() const {
DCHECK_IMPLIES(is_rest, initializer == nullptr);
return is_rest && pattern->IsVariableProxy();
}
Parameter** next() { return &next_parameter; } Parameter** next() { return &next_parameter; }
Parameter* const* next() const { return &next_parameter; } Parameter* const* next() const { return &next_parameter; }
}; };
...@@ -1040,8 +1046,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -1040,8 +1046,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
int initializer_end_position, int initializer_end_position,
bool is_rest) { bool is_rest) {
parameters->UpdateArityAndFunctionLength(initializer != nullptr, is_rest); parameters->UpdateArityAndFunctionLength(initializer != nullptr, is_rest);
bool is_simple = pattern->IsVariableProxy() && initializer == nullptr; bool has_simple_name = pattern->IsVariableProxy() && initializer == nullptr;
const AstRawString* name = is_simple const AstRawString* name = has_simple_name
? pattern->AsVariableProxy()->raw_name() ? pattern->AsVariableProxy()->raw_name()
: ast_value_factory()->empty_string(); : ast_value_factory()->empty_string();
auto parameter = auto parameter =
...@@ -1054,17 +1060,16 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -1054,17 +1060,16 @@ 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();
if (!is_simple) scope->SetHasNonSimpleParameters();
for (auto parameter : parameters) { for (auto parameter : parameters) {
bool is_duplicate = false; bool is_duplicate = false;
bool is_simple = classifier()->is_simple_parameter_list(); bool use_name = is_simple || parameter->is_nondestructuring_rest();
auto name = is_simple || parameter->is_rest
? parameter->name
: ast_value_factory()->empty_string();
auto mode = is_simple || parameter->is_rest ? VAR : TEMPORARY;
if (!is_simple) scope->SetHasNonSimpleParameters();
bool is_optional = parameter->initializer != nullptr; bool is_optional = parameter->initializer != nullptr;
scope->DeclareParameter(name, mode, is_optional, parameter->is_rest, scope->DeclareParameter(
&is_duplicate, ast_value_factory()); use_name ? parameter->name : ast_value_factory()->empty_string(),
use_name ? VAR : TEMPORARY, is_optional, parameter->is_rest,
&is_duplicate, ast_value_factory());
if (is_duplicate && if (is_duplicate &&
classifier()->is_valid_formal_parameter_list_without_duplicates()) { classifier()->is_valid_formal_parameter_list_without_duplicates()) {
classifier()->RecordDuplicateFormalParameterError( classifier()->RecordDuplicateFormalParameterError(
......
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