Commit dad79799 authored by rossberg's avatar rossberg Committed by Commit bot

[es6] Some renamings and minor clean-ups in parameter parsing

In particular, rename FormalParameterParsingState and friends to FormalParameters etc.

This should not change any logic, but is a preparatory CL for a bunch of follow-up fixes and clean-ups.

R=mstarzinger@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1247443004

Cr-Commit-Position: refs/heads/master@{#29807}
parent 9c249601
This diff is collapsed.
......@@ -539,8 +539,7 @@ class Parser;
class SingletonLogger;
struct ParserFormalParameterParsingState
: public PreParserFormalParameterParsingState {
struct ParserFormalParameters : public PreParserFormalParameters {
struct Parameter {
Parameter(Variable* var, Expression* pattern)
: var(var), pattern(pattern) {}
......@@ -548,8 +547,8 @@ struct ParserFormalParameterParsingState
Expression* pattern;
};
explicit ParserFormalParameterParsingState(Scope* scope)
: PreParserFormalParameterParsingState(scope), params(4, scope->zone()) {}
explicit ParserFormalParameters(Scope* scope)
: PreParserFormalParameters(scope), params(4, scope->zone()) {}
ZoneList<Parameter> params;
......@@ -581,7 +580,7 @@ class ParserTraits {
typedef ZoneList<v8::internal::Expression*>* ExpressionList;
typedef ZoneList<ObjectLiteral::Property*>* PropertyList;
typedef const v8::internal::AstRawString* FormalParameter;
typedef ParserFormalParameterParsingState FormalParameterParsingState;
typedef ParserFormalParameters FormalParameters;
typedef ZoneList<v8::internal::Statement*>* StatementList;
// For constructing objects returned by the traversing functions.
......@@ -774,21 +773,21 @@ class ParserTraits {
}
V8_INLINE void AddParameterInitializationBlock(
const ParserFormalParameterParsingState& formal_parameters,
const ParserFormalParameters& parameters,
ZoneList<v8::internal::Statement*>* body, bool* ok);
V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type,
FunctionKind kind = kNormalFunction);
V8_INLINE void DeclareFormalParameter(
ParserFormalParameterParsingState* parsing_state, Expression* name,
ExpressionClassifier* classifier, bool is_rest);
ParserFormalParameters* parameters, Expression* pattern, bool is_rest,
ExpressionClassifier* classifier);
void ParseArrowFunctionFormalParameters(
ParserFormalParameterParsingState* scope, Expression* params,
const Scanner::Location& params_loc, Scanner::Location* duplicate_loc,
bool* ok);
ParserFormalParameters* parameters, Expression* params,
const Scanner::Location& params_loc,
Scanner::Location* duplicate_loc, bool* ok);
void ReindexLiterals(const ParserFormalParameterParsingState& parsing_state);
void ReindexLiterals(const ParserFormalParameters& parameters);
// Temporary glue; these functions will move to ParserBase.
Expression* ParseV8Intrinsic(bool* ok);
......@@ -803,7 +802,7 @@ class ParserTraits {
Scanner::BookmarkScope* bookmark = nullptr);
V8_INLINE ZoneList<Statement*>* ParseEagerFunctionBody(
const AstRawString* name, int pos,
const ParserFormalParameterParsingState& formal_parameters,
const ParserFormalParameters& parameters,
Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok);
ClassLiteral* ParseClassLiteral(const AstRawString* name,
......@@ -1155,15 +1154,14 @@ class Parser : public ParserBase<ParserTraits> {
PreParser::PreParseResult ParseLazyFunctionBodyWithPreParser(
SingletonLogger* logger, Scanner::BookmarkScope* bookmark = nullptr);
bool IsSimpleParameterList(
const ParserFormalParameterParsingState& formal_parameters);
bool IsSimpleParameterList(const ParserFormalParameters& parameters);
Block* BuildParameterInitializationBlock(
const ParserFormalParameterParsingState& formal_parameters, bool* ok);
const ParserFormalParameters& parameters, bool* ok);
// Consumes the ending }.
ZoneList<Statement*>* ParseEagerFunctionBody(
const AstRawString* function_name, int pos,
const ParserFormalParameterParsingState& formal_parameters,
const ParserFormalParameters& parameters,
Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok);
void ThrowPendingError(Isolate* isolate, Handle<Script> script);
......@@ -1229,9 +1227,9 @@ void ParserTraits::SkipLazyFunctionBody(int* materialized_literal_count,
ZoneList<Statement*>* ParserTraits::ParseEagerFunctionBody(
const AstRawString* name, int pos,
const ParserFormalParameterParsingState& formal_parameters, Variable* fvar,
const ParserFormalParameters& parameters, Variable* fvar,
Token::Value fvar_init_op, FunctionKind kind, bool* ok) {
return parser_->ParseEagerFunctionBody(name, pos, formal_parameters, fvar,
return parser_->ParseEagerFunctionBody(name, pos, parameters, fvar,
fvar_init_op, kind, ok);
}
......@@ -1312,40 +1310,41 @@ Expression* ParserTraits::SpreadCallNew(
void ParserTraits::DeclareFormalParameter(
ParserFormalParameterParsingState* parsing_state, Expression* pattern,
ExpressionClassifier* classifier, bool is_rest) {
ParserFormalParameters* parameters, Expression* pattern, bool is_rest,
ExpressionClassifier* classifier) {
bool is_duplicate = false;
bool is_simple_name = pattern->IsVariableProxy();
DCHECK(parser_->allow_harmony_destructuring() || is_simple_name);
bool is_simple = pattern->IsVariableProxy();
DCHECK(parser_->allow_harmony_destructuring() || is_simple);
const AstRawString* name = is_simple_name
const AstRawString* name = is_simple
? pattern->AsVariableProxy()->raw_name()
: parser_->ast_value_factory()->empty_string();
Variable* var =
parsing_state->scope->DeclareParameter(name, VAR, is_rest, &is_duplicate);
parsing_state->AddParameter(var, is_simple_name ? nullptr : pattern);
if (is_sloppy(parsing_state->scope->language_mode())) {
parameters->scope->DeclareParameter(name, VAR, is_rest, &is_duplicate);
parameters->AddParameter(var, is_simple ? nullptr : pattern);
if (is_duplicate) {
classifier->RecordDuplicateFormalParameterError(
parser_->scanner()->location());
}
if (is_sloppy(parameters->scope->language_mode())) {
// TODO(sigurds) Mark every parameter as maybe assigned. This is a
// conservative approximation necessary to account for parameters
// that are assigned via the arguments array.
var->set_maybe_assigned();
}
if (is_duplicate) {
classifier->RecordDuplicateFormalParameterError(
parser_->scanner()->location());
}
}
void ParserTraits::AddParameterInitializationBlock(
const ParserFormalParameterParsingState& formal_parameters,
const ParserFormalParameters& parameters,
ZoneList<v8::internal::Statement*>* body, bool* ok) {
if (parser_->IsSimpleParameterList(formal_parameters)) return;
auto* init_block =
parser_->BuildParameterInitializationBlock(formal_parameters, ok);
if (!*ok) return;
if (init_block != nullptr) {
body->Add(init_block, parser_->zone());
if (!parser_->IsSimpleParameterList(parameters)) {
auto* init_block =
parser_->BuildParameterInitializationBlock(parameters, ok);
if (!*ok) return;
if (init_block != nullptr) {
body->Add(init_block, parser_->zone());
}
}
}
} } // namespace v8::internal
......
......@@ -1052,14 +1052,13 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
Expect(Token::LPAREN, CHECK_OK);
int start_position = scanner()->location().beg_pos;
function_scope->set_start_position(start_position);
PreParserFormalParameterParsingState parsing_state(nullptr);
int num_parameters =
ParseFormalParameterList(&parsing_state, &formals_classifier, CHECK_OK);
PreParserFormalParameters formals(nullptr);
int arity = ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK);
int formals_end_position = scanner()->location().end_pos;
CheckArityRestrictions(num_parameters, arity_restriction,
parsing_state.has_rest, start_position,
CheckArityRestrictions(arity, arity_restriction,
formals.has_rest, start_position,
formals_end_position, CHECK_OK);
// See Parser::ParseFunctionLiteral for more information about lazy parsing
......@@ -1083,10 +1082,8 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
// function, since the function can declare itself strict.
CheckFunctionName(language_mode, function_name, function_name_validity,
function_name_location, CHECK_OK);
const bool strict_formal_parameters =
!parsing_state.is_simple_parameter_list || IsConciseMethod(kind);
const bool allow_duplicate_parameters =
is_sloppy(language_mode) && !strict_formal_parameters;
is_sloppy(language_mode) && formals.is_simple && !IsConciseMethod(kind);
ValidateFormalParameters(&formals_classifier, language_mode,
allow_duplicate_parameters, CHECK_OK);
......
This diff is collapsed.
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