Commit ccd71204 authored by nikolaos's avatar nikolaos Committed by Commit bot

[parser] Refactor of ParseFunctionDeclaration

This patch moves the method ParseFunctionDeclaration to ParserBase.
It also cleans up some forgotten method headers in parser and preparser.

R=adamk@chromium.org, verwaest@chromium.org
BUG=
LOG=N

Review-Url: https://codereview.chromium.org/2376293002
Cr-Commit-Position: refs/heads/master@{#39901}
parent 42724232
......@@ -1212,6 +1212,7 @@ class ParserBase {
bool* ok);
StatementT ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names,
bool default_export, bool* ok);
StatementT ParseFunctionDeclaration(bool* ok);
StatementT ParseHoistableDeclaration(ZoneList<const AstRawString*>* names,
bool default_export, bool* ok);
StatementT ParseHoistableDeclaration(int pos, ParseFunctionFlags flags,
......@@ -3663,6 +3664,24 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseVariableDeclarations(
return init_block;
}
template <typename Impl>
typename ParserBase<Impl>::StatementT
ParserBase<Impl>::ParseFunctionDeclaration(bool* ok) {
Consume(Token::FUNCTION);
int pos = position();
ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal;
if (Check(Token::MUL)) {
flags |= ParseFunctionFlags::kIsGenerator;
if (allow_harmony_restrictive_declarations()) {
impl()->ReportMessageAt(scanner()->location(),
MessageTemplate::kGeneratorInLegacyContext);
*ok = false;
return impl()->NullStatement();
}
}
return ParseHoistableDeclaration(pos, flags, nullptr, false, ok);
}
template <typename Impl>
typename ParserBase<Impl>::StatementT
ParserBase<Impl>::ParseHoistableDeclaration(
......@@ -4615,7 +4634,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseScopedStatement(
BlockState block_state(zone(), &scope_state_);
block_state.set_start_position(scanner()->location().beg_pos);
BlockT block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition);
StatementT body = impl()->ParseFunctionDeclaration(CHECK_OK);
StatementT body = ParseFunctionDeclaration(CHECK_OK);
block->statements()->Add(body, zone());
block_state.set_end_position(scanner()->location().end_pos);
block->set_scope(block_state.FinalizedBlockScope());
......@@ -4702,7 +4721,7 @@ ParserBase<Impl>::ParseExpressionOrLabelledStatement(
// ES#sec-labelled-function-declarations Labelled Function Declarations
if (peek() == Token::FUNCTION && is_sloppy(language_mode())) {
if (allow_function == kAllowLabelledFunctionStatement) {
return impl()->ParseFunctionDeclaration(ok);
return ParseFunctionDeclaration(ok);
} else {
return ParseScopedStatement(labels, true, ok);
}
......
......@@ -1719,23 +1719,6 @@ Expression* Parser::RewriteDoExpression(Block* body, int pos, bool* ok) {
return expr;
}
Statement* Parser::ParseFunctionDeclaration(bool* ok) {
Consume(Token::FUNCTION);
int pos = position();
ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal;
if (Check(Token::MUL)) {
flags |= ParseFunctionFlags::kIsGenerator;
if (allow_harmony_restrictive_declarations()) {
ReportMessageAt(scanner()->location(),
MessageTemplate::kGeneratorInLegacyContext);
*ok = false;
return nullptr;
}
}
return ParseHoistableDeclaration(pos, flags, nullptr, false, CHECK_OK);
}
Statement* Parser::RewriteSwitchStatement(Expression* tag,
SwitchStatement* switch_statement,
ZoneList<CaseClause*>* cases,
......
......@@ -271,7 +271,6 @@ class Parser : public ParserBase<Parser> {
location(location) {}
};
ZoneList<const NamedImport*>* ParseNamedImports(int pos, bool* ok);
Statement* ParseFunctionDeclaration(bool* ok);
Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result,
ZoneList<const AstRawString*>* names,
bool* ok);
......@@ -313,8 +312,6 @@ class Parser : public ParserBase<Parser> {
V8_INLINE Statement* DeclareNative(const AstRawString* name, int pos,
bool* ok);
Expression* ParseYieldStarExpression(bool* ok);
class PatternRewriter final : public AstVisitor<PatternRewriter> {
public:
static void DeclareAndInitializeVariables(
......
......@@ -35,7 +35,7 @@ namespace internal {
#define DUMMY ) // to make indentation work
#undef DUMMY
#define CHECK_OK CHECK_OK_VALUE(Statement::Default())
#define CHECK_OK CHECK_OK_VALUE(Expression::Default())
#define CHECK_OK_VOID CHECK_OK_VALUE(this->Void())
namespace {
......@@ -135,29 +135,6 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction(
// That means that contextual checks (like a label being declared where
// it is used) are generally omitted.
PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) {
Consume(Token::FUNCTION);
int pos = position();
ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal;
if (Check(Token::MUL)) {
flags |= ParseFunctionFlags::kIsGenerator;
if (allow_harmony_restrictive_declarations()) {
ReportMessageAt(scanner()->location(),
MessageTemplate::kGeneratorInLegacyContext);
*ok = false;
return Statement::Default();
}
}
// PreParser is not able to parse "export default" yet (since PreParser is
// at the moment only used for functions, and it cannot occur
// there). TODO(marja): update this when it is.
return ParseHoistableDeclaration(pos, flags, nullptr, false, ok);
}
// Redefinition of CHECK_OK for parsing expressions.
#undef CHECK_OK
#define CHECK_OK CHECK_OK_VALUE(Expression::Default())
PreParser::Expression PreParser::ParseFunctionLiteral(
Identifier function_name, Scanner::Location function_name_location,
FunctionNameValidity function_name_validity, FunctionKind kind,
......
......@@ -837,9 +837,6 @@ class PreParser : public ParserBase<PreParser> {
// which is set to false if parsing failed; it is unchanged otherwise.
// By making the 'exception handling' explicit, we are forced to check
// for failure at the call sites.
Statement ParseFunctionDeclaration(bool* ok);
Expression ParseConditionalExpression(bool accept_IN, bool* ok);
Expression ParseObjectLiteral(bool* ok);
V8_INLINE PreParserStatementList ParseEagerFunctionBody(
PreParserIdentifier function_name, int 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