Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1532)

Unified Diff: src/parsing/preparser.cc

Issue 2323763002: [parser] Refactor of Parse*Statement*, part 4 (Closed)
Patch Set: Rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/preparser.cc
diff --git a/src/parsing/preparser.cc b/src/parsing/preparser.cc
index 027b75deda3bfd54f12a6d2a1ea149118ac128a9..cf0a5ee6c4504076b4a05c4feb90f0a441f19622 100644
--- a/src/parsing/preparser.cc
+++ b/src/parsing/preparser.cc
@@ -164,175 +164,6 @@ PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) {
return ParseHoistableDeclaration(pos, flags, nullptr, false, ok);
}
-PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(
- ZoneList<const AstRawString*>* names,
- AllowLabelledFunctionStatement allow_function, bool* ok) {
- // ExpressionStatement | LabelledStatement ::
- // Expression ';'
- // Identifier ':' Statement
-
- switch (peek()) {
- case Token::FUNCTION:
- case Token::LBRACE:
- UNREACHABLE(); // Always handled by the callers.
- case Token::CLASS:
- ReportUnexpectedToken(Next());
- *ok = false;
- return Statement::Default();
-
- default:
- break;
- }
-
- bool starts_with_identifier = peek_any_identifier();
- ExpressionClassifier classifier(this);
- Expression expr = ParseExpressionCoverGrammar(true, CHECK_OK);
- ValidateExpression(CHECK_OK);
-
- // Even if the expression starts with an identifier, it is not necessarily an
- // identifier. For example, "foo + bar" starts with an identifier but is not
- // an identifier.
- if (starts_with_identifier && expr.IsIdentifier() && peek() == Token::COLON) {
- // Expression is a single identifier, and not, e.g., a parenthesized
- // identifier.
- DCHECK(!expr.AsIdentifier().IsEnum());
- DCHECK(!parsing_module_ || !expr.AsIdentifier().IsAwait());
- DCHECK(is_sloppy(language_mode()) ||
- !IsFutureStrictReserved(expr.AsIdentifier()));
- Consume(Token::COLON);
- // ES#sec-labelled-function-declarations Labelled Function Declarations
- if (peek() == Token::FUNCTION && is_sloppy(language_mode())) {
- if (allow_function == kAllowLabelledFunctionStatement) {
- return ParseFunctionDeclaration(ok);
- } else {
- return ParseScopedStatement(names, true, ok);
- }
- }
- Statement statement =
- ParseStatement(nullptr, kDisallowLabelledFunctionStatement, ok);
- return statement.IsJumpStatement() ? Statement::Default() : statement;
- // Preparsing is disabled for extensions (because the extension details
- // aren't passed to lazily compiled functions), so we don't
- // accept "native function" in the preparser.
- }
- // Parsed expression statement.
- ExpectSemicolon(CHECK_OK);
- return Statement::ExpressionStatement(expr);
-}
-
-PreParser::Statement PreParser::ParseIfStatement(
- ZoneList<const AstRawString*>* labels, bool* ok) {
- // IfStatement ::
- // 'if' '(' Expression ')' Statement ('else' Statement)?
-
- Expect(Token::IF, CHECK_OK);
- Expect(Token::LPAREN, CHECK_OK);
- ParseExpression(true, CHECK_OK);
- Expect(Token::RPAREN, CHECK_OK);
- Statement stat = ParseScopedStatement(labels, false, CHECK_OK);
- if (peek() == Token::ELSE) {
- Next();
- Statement else_stat = ParseScopedStatement(labels, false, CHECK_OK);
- stat = (stat.IsJumpStatement() && else_stat.IsJumpStatement()) ?
- Statement::Jump() : Statement::Default();
- } else {
- stat = Statement::Default();
- }
- return stat;
-}
-
-
-PreParser::Statement PreParser::ParseContinueStatement(bool* ok) {
- // ContinueStatement ::
- // 'continue' [no line terminator] Identifier? ';'
-
- Expect(Token::CONTINUE, CHECK_OK);
- Token::Value tok = peek();
- if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
- tok != Token::SEMICOLON &&
- tok != Token::RBRACE &&
- tok != Token::EOS) {
- // ECMA allows "eval" or "arguments" as labels even in strict mode.
- ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK);
- }
- ExpectSemicolon(CHECK_OK);
- return Statement::Jump();
-}
-
-PreParser::Statement PreParser::ParseBreakStatement(
- ZoneList<const AstRawString*>* labels, bool* ok) {
- // BreakStatement ::
- // 'break' [no line terminator] Identifier? ';'
-
- Expect(Token::BREAK, CHECK_OK);
- Token::Value tok = peek();
- if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
- tok != Token::SEMICOLON &&
- tok != Token::RBRACE &&
- tok != Token::EOS) {
- // ECMA allows "eval" or "arguments" as labels even in strict mode.
- ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK);
- }
- ExpectSemicolon(CHECK_OK);
- return Statement::Jump();
-}
-
-
-PreParser::Statement PreParser::ParseReturnStatement(bool* ok) {
- // ReturnStatement ::
- // 'return' [no line terminator] Expression? ';'
-
- // Consume the return token. It is necessary to do before
- // reporting any errors on it, because of the way errors are
- // reported (underlining).
- Expect(Token::RETURN, CHECK_OK);
-
- // An ECMAScript program is considered syntactically incorrect if it
- // contains a return statement that is not within the body of a
- // function. See ECMA-262, section 12.9, page 67.
- // This is not handled during preparsing.
-
- Token::Value tok = peek();
- if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
- tok != Token::SEMICOLON &&
- tok != Token::RBRACE &&
- tok != Token::EOS) {
- // Because of the return code rewriting that happens in case of a subclass
- // constructor we don't want to accept tail calls, therefore we don't set
- // ReturnExprScope to kInsideValidReturnStatement here.
- ReturnExprContext return_expr_context =
- IsSubclassConstructor(function_state_->kind())
- ? function_state_->return_expr_context()
- : ReturnExprContext::kInsideValidReturnStatement;
-
- ReturnExprScope maybe_allow_tail_calls(function_state_,
- return_expr_context);
- ParseExpression(true, CHECK_OK);
- }
- ExpectSemicolon(CHECK_OK);
- return Statement::Jump();
-}
-
-PreParser::Statement PreParser::ParseWithStatement(
- ZoneList<const AstRawString*>* labels, bool* ok) {
- // WithStatement ::
- // 'with' '(' Expression ')' Statement
- Expect(Token::WITH, CHECK_OK);
- if (is_strict(language_mode())) {
- ReportMessageAt(scanner()->location(), MessageTemplate::kStrictWith);
- *ok = false;
- return Statement::Default();
- }
- Expect(Token::LPAREN, CHECK_OK);
- ParseExpression(true, CHECK_OK);
- Expect(Token::RPAREN, CHECK_OK);
-
- Scope* with_scope = NewScope(WITH_SCOPE);
- BlockState block_state(&scope_state_, with_scope);
- ParseScopedStatement(labels, true, CHECK_OK);
- return Statement::Default();
-}
-
PreParser::Statement PreParser::ParseSwitchStatement(
ZoneList<const AstRawString*>* labels, bool* ok) {
// SwitchStatement ::
« no previous file with comments | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698