Commit 25dde52d authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Drop ParserFormalParameters::Parameter::name

It's anyway only read in case of simple parameters. In that case pattern is
guaranteed to be a VariableProxy, from which we can read the name as well.

Change-Id: Ie340064453594ab4f84b1d0223506801635c289d
Reviewed-on: https://chromium-review.googlesource.com/c/1402782
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58668}
parent d586857c
...@@ -84,24 +84,22 @@ class Parser; ...@@ -84,24 +84,22 @@ class Parser;
struct ParserFormalParameters : FormalParametersBase { struct ParserFormalParameters : FormalParametersBase {
struct Parameter : public ZoneObject { struct Parameter : public ZoneObject {
Parameter(const AstRawString* name, Expression* pattern, Parameter(Expression* pattern, Expression* initializer, int position,
Expression* initializer, int position,
int initializer_end_position, bool is_rest) int initializer_end_position, bool is_rest)
: name(name), : initializer_and_is_rest(initializer, is_rest),
name_and_is_rest(initializer, is_rest),
pattern(pattern), pattern(pattern),
position(position), position(position),
initializer_end_position(initializer_end_position) {} initializer_end_position(initializer_end_position) {}
const AstRawString* name; PointerWithPayload<Expression, bool, 1> initializer_and_is_rest;
PointerWithPayload<Expression, bool, 1> name_and_is_rest;
Expression* pattern; Expression* pattern;
Expression* initializer() const { return name_and_is_rest.GetPointer(); } Expression* initializer() const {
return initializer_and_is_rest.GetPointer();
}
int position; int position;
int initializer_end_position; int initializer_end_position;
inline bool is_rest() const { return name_and_is_rest.GetPayload(); } inline bool is_rest() const { return initializer_and_is_rest.GetPayload(); }
Parameter* next_parameter = nullptr; Parameter* next_parameter = nullptr;
bool is_simple() const { bool is_simple() const {
...@@ -109,6 +107,11 @@ struct ParserFormalParameters : FormalParametersBase { ...@@ -109,6 +107,11 @@ struct ParserFormalParameters : FormalParametersBase {
!is_rest(); !is_rest();
} }
const AstRawString* name() const {
DCHECK(is_simple());
return pattern->AsVariableProxy()->raw_name();
}
Parameter** next() { return &next_parameter; } Parameter** next() { return &next_parameter; }
Parameter* const* next() const { return &next_parameter; } Parameter* const* next() const { return &next_parameter; }
}; };
...@@ -894,12 +897,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -894,12 +897,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 has_simple_name = pattern->IsVariableProxy() && initializer == nullptr;
const AstRawString* name = has_simple_name
? pattern->AsVariableProxy()->raw_name()
: ast_value_factory()->empty_string();
auto parameter = new (parameters->scope->zone()) auto parameter = new (parameters->scope->zone())
ParserFormalParameters::Parameter(name, pattern, initializer, ParserFormalParameters::Parameter(pattern, initializer,
scanner()->location().beg_pos, scanner()->location().beg_pos,
initializer_end_position, is_rest); initializer_end_position, is_rest);
...@@ -917,13 +916,13 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -917,13 +916,13 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
// for each parameter - the corresponding named variable is declared by // for each parameter - the corresponding named variable is declared by
// BuildParamerterInitializationBlock. // BuildParamerterInitializationBlock.
if (is_simple && !parameters->has_duplicate() && if (is_simple && !parameters->has_duplicate() &&
scope->LookupLocal(parameter->name)) { scope->LookupLocal(parameter->name())) {
parameters->duplicate_loc = parameters->duplicate_loc = Scanner::Location(
Scanner::Location(parameter->position, parameter->position,
parameter->position + parameter->name->length()); parameter->position + parameter->name()->length());
} }
scope->DeclareParameter( scope->DeclareParameter(
is_simple ? parameter->name : ast_value_factory()->empty_string(), is_simple ? parameter->name() : ast_value_factory()->empty_string(),
is_simple ? VariableMode::kVar : VariableMode::kTemporary, is_simple ? VariableMode::kVar : VariableMode::kTemporary,
is_optional, parameter->is_rest(), ast_value_factory(), is_optional, parameter->is_rest(), ast_value_factory(),
parameter->position); parameter->position);
......
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