template <typename Impl>
typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStatement(
ZonePtrList<const AstRawString>* labels,
ZonePtrList<const AstRawString>* own_labels,
AllowLabelledFunctionStatement allow_function) {
DCHECK_IMPLIES(labels == nullptr, own_labels == nullptr);
switch (peek()) {
case Token::kLeftBrace:
return ParseBlock(labels);
case Token::kSemicolon:
Next();
return factory()->EmptyStatement();
case Token::kIf:
return ParseIfStatement(labels);
case Token::kDo:
return ParseDoWhileStatement(labels, own_labels);
case Token::kWhile:
return ParseWhileStatement(labels, own_labels);
case Token::kFor:
if (V8_UNLIKELY(is_await_allowed() && PeekAhead() == Token::kAwait)) {
return ParseForAwaitStatement(labels, own_labels);
}
return ParseForStatement(labels, own_labels);
case Token::kContinue:
return ParseContinueStatement();
case Token::kBreak:
return ParseBreakStatement(labels);
case Token::kReturn:
return ParseReturnStatement();
case Token::kThrow:
return ParseThrowStatement();
case Token::kTry: {
if (labels == nullptr) return ParseTryStatement();
StatementListT statements(pointer_buffer());
BlockT result = factory()->NewBlock(false, true);
Target target(this, result, labels, nullptr,
Target::TARGET_FOR_NAMED_ONLY);
StatementT statement = ParseTryStatement();
statements.Add(statement);
result->InitializeStatements(statements, zone());
return result;
}
case Token::kWith:
return ParseWithStatement(labels);
case Token::kSwitch:
return ParseSwitchStatement(labels);
case Token::kFunction:
impl()->ReportMessageAt(scanner()->peek_location(),
is_strict(language_mode())
? MessageTemplate::kStrictFunction
: MessageTemplate::kSloppyFunction);
return impl()->NullStatement();
case Token::kDebugger:
return ParseDebuggerStatement();
case Token::kVar:
return ParseVariableStatement(kStatement, nullptr);
case Token::kAsync:
if (!impl()->HasCheckedSyntax() &&
!scanner()->HasLineTerminatorAfterNext() &&
PeekAhead() == Token::kFunction) {
impl()->ReportMessageAt(
scanner()->peek_location(),
MessageTemplate::kAsyncFunctionInSingleStatementContext);
return impl()->NullStatement();
}
[[fallthrough]];
default:
return ParseExpressionOrLabelledStatement(labels, own_labels,
allow_function);
}
}