24 using namespace clang;
33 bool AllowOpenMPStandalone) {
40 Res = ParseStatementOrDeclaration(
41 Stmts, AllowOpenMPStandalone ? ACK_StatementsOpenMPAnyExecutable
42 : ACK_StatementsOpenMPNonStandalone,
44 }
while (!Res.isInvalid() && !Res.get());
99 Parser::ParseStatementOrDeclaration(StmtVector &Stmts,
100 AllowedConstructsKind Allowed,
105 ParsedAttributesWithRange Attrs(AttrFactory);
106 MaybeParseCXX11Attributes(Attrs,
nullptr,
true);
107 if (!MaybeParseOpenCLUnrollHintAttribute(Attrs))
110 StmtResult Res = ParseStatementOrDeclarationAfterAttributes(
111 Stmts, Allowed, TrailingElseLoc, Attrs);
113 assert((Attrs.empty() || Res.isInvalid() || Res.isUsable()) &&
114 "attributes on empty statement");
116 if (Attrs.empty() || Res.isInvalid())
126 WantTypeSpecifiers = nextTok.
isOneOf(tok::l_paren, tok::less, tok::l_square,
127 tok::identifier, tok::star, tok::amp);
128 WantExpressionKeywords =
129 nextTok.
isOneOf(tok::l_paren, tok::identifier, tok::arrow, tok::period);
130 WantRemainingKeywords =
131 nextTok.
isOneOf(tok::l_paren, tok::semi, tok::identifier, tok::l_brace);
132 WantCXXNamedCasts =
false;
135 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
152 Parser::ParseStatementOrDeclarationAfterAttributes(StmtVector &Stmts,
154 ParsedAttributesWithRange &Attrs) {
155 const char *SemiError =
nullptr;
167 ProhibitAttributes(Attrs);
169 return ParseObjCAtStatement(AtLoc);
172 case tok::code_completion:
177 case tok::identifier: {
179 if (Next.
is(tok::colon)) {
181 return ParseLabeledStatement(Attrs);
186 if (Next.
isNot(tok::coloncolon)) {
189 if (TryAnnotateName(
false,
190 llvm::make_unique<StatementFilterCCC>(Next)) ==
195 if (
Tok.
is(tok::semi))
211 Allowed == ACK_Any) &&
212 isDeclarationStatement()) {
216 return Actions.ActOnDeclStmt(Decl, DeclStart, DeclEnd);
219 if (
Tok.
is(tok::r_brace)) {
220 Diag(Tok, diag::err_expected_statement);
224 return ParseExprStatement();
228 return ParseCaseStatement();
229 case tok::kw_default:
230 return ParseDefaultStatement();
233 return ParseCompoundStatement();
235 bool HasLeadingEmptyMacro =
Tok.hasLeadingEmptyMacro();
236 return Actions.ActOnNullStmt(
ConsumeToken(), HasLeadingEmptyMacro);
240 return ParseIfStatement(TrailingElseLoc);
242 return ParseSwitchStatement(TrailingElseLoc);
245 return ParseWhileStatement(TrailingElseLoc);
247 Res = ParseDoStatement();
248 SemiError =
"do/while";
251 return ParseForStatement(TrailingElseLoc);
254 Res = ParseGotoStatement();
257 case tok::kw_continue:
258 Res = ParseContinueStatement();
259 SemiError =
"continue";
262 Res = ParseBreakStatement();
266 Res = ParseReturnStatement();
267 SemiError =
"return";
269 case tok::kw_co_return:
270 Res = ParseReturnStatement();
271 SemiError =
"co_return";
275 ProhibitAttributes(Attrs);
277 Res = ParseAsmStatement(msAsm);
278 Res = Actions.ActOnFinishFullStmt(Res.get());
279 if (msAsm)
return Res;
284 case tok::kw___if_exists:
285 case tok::kw___if_not_exists:
286 ProhibitAttributes(Attrs);
287 ParseMicrosoftIfExistsStatement(Stmts);
293 return ParseCXXTryBlock();
296 ProhibitAttributes(Attrs);
297 return ParseSEHTryBlock();
299 case tok::kw___leave:
300 Res = ParseSEHLeaveStatement();
301 SemiError =
"__leave";
304 case tok::annot_pragma_vis:
305 ProhibitAttributes(Attrs);
306 HandlePragmaVisibility();
309 case tok::annot_pragma_pack:
310 ProhibitAttributes(Attrs);
314 case tok::annot_pragma_msstruct:
315 ProhibitAttributes(Attrs);
316 HandlePragmaMSStruct();
319 case tok::annot_pragma_align:
320 ProhibitAttributes(Attrs);
324 case tok::annot_pragma_weak:
325 ProhibitAttributes(Attrs);
329 case tok::annot_pragma_weakalias:
330 ProhibitAttributes(Attrs);
331 HandlePragmaWeakAlias();
334 case tok::annot_pragma_redefine_extname:
335 ProhibitAttributes(Attrs);
336 HandlePragmaRedefineExtname();
339 case tok::annot_pragma_fp_contract:
340 ProhibitAttributes(Attrs);
341 Diag(Tok, diag::err_pragma_fp_contract_scope);
342 ConsumeAnnotationToken();
345 case tok::annot_pragma_fp:
346 ProhibitAttributes(Attrs);
347 Diag(Tok, diag::err_pragma_fp_scope);
348 ConsumeAnnotationToken();
351 case tok::annot_pragma_opencl_extension:
352 ProhibitAttributes(Attrs);
353 HandlePragmaOpenCLExtension();
356 case tok::annot_pragma_captured:
357 ProhibitAttributes(Attrs);
358 return HandlePragmaCaptured();
360 case tok::annot_pragma_openmp:
361 ProhibitAttributes(Attrs);
362 return ParseOpenMPDeclarativeOrExecutableDirective(Allowed);
364 case tok::annot_pragma_ms_pointers_to_members:
365 ProhibitAttributes(Attrs);
366 HandlePragmaMSPointersToMembers();
369 case tok::annot_pragma_ms_pragma:
370 ProhibitAttributes(Attrs);
371 HandlePragmaMSPragma();
374 case tok::annot_pragma_ms_vtordisp:
375 ProhibitAttributes(Attrs);
376 HandlePragmaMSVtorDisp();
379 case tok::annot_pragma_loop_hint:
380 ProhibitAttributes(Attrs);
381 return ParsePragmaLoopHint(Stmts, Allowed, TrailingElseLoc, Attrs);
383 case tok::annot_pragma_dump:
387 case tok::annot_pragma_attribute:
388 HandlePragmaAttribute();
397 ExpectAndConsume(tok::semi, diag::err_expected_semi_after_stmt, SemiError);
410 ExprStatementTokLoc =
Tok.getLocation();
414 if (
Expr.isInvalid()) {
419 if (
Tok.
is(tok::semi))
421 return Actions.ActOnExprStmtError();
425 Actions.CheckCaseExpression(
Expr.get())) {
428 Diag(OldToken, diag::err_expected_case_before_expression)
432 return ParseCaseStatement(
true,
Expr);
436 ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
437 return Actions.ActOnExprStmt(
Expr);
450 assert(
Tok.
is(tok::kw___try) &&
"Expected '__try'");
454 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
459 if (TryBlock.isInvalid())
463 if (
Tok.
is(tok::identifier) &&
464 Tok.getIdentifierInfo() == getSEHExceptKeyword()) {
466 Handler = ParseSEHExceptBlock(Loc);
467 }
else if (
Tok.
is(tok::kw___finally)) {
469 Handler = ParseSEHFinallyBlock(Loc);
474 if(Handler.isInvalid())
477 return Actions.ActOnSEHTryBlock(
false ,
490 raii2(Ident___exception_code,
false),
491 raii3(Ident_GetExceptionCode,
false);
493 if (ExpectAndConsume(tok::l_paren))
500 Ident__exception_info->setIsPoisoned(
false);
501 Ident___exception_info->setIsPoisoned(
false);
502 Ident_GetExceptionInfo->setIsPoisoned(
false);
507 ParseScopeFlags FilterScope(
this,
getCurScope()->getFlags() |
513 Ident__exception_info->setIsPoisoned(
true);
514 Ident___exception_info->setIsPoisoned(
true);
515 Ident_GetExceptionInfo->setIsPoisoned(
true);
521 if (ExpectAndConsume(tok::r_paren))
525 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
529 if(Block.isInvalid())
532 return Actions.ActOnSEHExceptBlock(ExceptLoc, FilterExpr.
get(), Block.get());
542 raii2(Ident___abnormal_termination,
false),
543 raii3(Ident_AbnormalTermination,
false);
546 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
548 ParseScope FinallyScope(
this, 0);
549 Actions.ActOnStartSEHFinallyBlock();
552 if(Block.isInvalid()) {
553 Actions.ActOnAbortSEHFinallyBlock();
557 return Actions.ActOnFinishSEHFinallyBlock(FinallyLoc, Block.get());
567 return Actions.ActOnSEHLeaveStmt(LeaveLoc,
getCurScope());
576 StmtResult Parser::ParseLabeledStatement(ParsedAttributesWithRange &attrs) {
577 assert(
Tok.
is(tok::identifier) &&
Tok.getIdentifierInfo() &&
578 "Not an identifier!");
583 assert(
Tok.
is(tok::colon) &&
"Not a label!");
590 if (
Tok.
is(tok::kw___attribute)) {
591 ParsedAttributesWithRange TempAttrs(AttrFactory);
592 ParseGNUAttributes(TempAttrs);
602 attrs.takeAllFrom(TempAttrs);
603 else if (isDeclarationStatement()) {
609 SubStmt = ParseStatementOrDeclarationAfterAttributes(
610 Stmts, ACK_StatementsOpenMPNonStandalone,
nullptr,
612 if (!TempAttrs.empty() && !SubStmt.isInvalid())
613 SubStmt = Actions.ProcessStmtAttributes(
614 SubStmt.get(), TempAttrs.getList(), TempAttrs.Range);
616 Diag(Tok, diag::err_expected_after) <<
"__attribute__" << tok::semi;
621 if (!SubStmt.isInvalid() && !SubStmt.isUsable())
622 SubStmt = ParseStatement();
625 if (SubStmt.isInvalid())
626 SubStmt = Actions.ActOnNullStmt(ColonLoc);
628 LabelDecl *LD = Actions.LookupOrCreateLabel(IdentTok.getIdentifierInfo(),
629 IdentTok.getLocation());
631 Actions.ProcessDeclAttributeList(Actions.CurScope, LD, Attrs);
635 return Actions.ActOnLabelStmt(IdentTok.getLocation(), LD,
ColonLoc,
645 assert((MissingCase ||
Tok.
is(tok::kw_case)) &&
"Not a case stmt!");
668 Stmt *DeepestParsedCaseStmt =
nullptr;
677 if (
Tok.
is(tok::code_completion)) {
692 LHS = Actions.CorrectDelayedTyposInExpr(LHS, [
this](
class Expr *E) {
693 return Actions.VerifyIntegerConstantExpression(E);
714 Diag(DotDotDotLoc, diag::ext_gnu_case_range);
725 ColonProtection.restore();
731 Diag(ColonLoc, diag::err_expected_after)
732 <<
"'case'" << tok::colon
735 SourceLocation ExpectedLoc = PP.getLocForEndOfToken(PrevTokLocation);
736 Diag(ExpectedLoc, diag::err_expected_after)
737 <<
"'case'" << tok::colon
739 ColonLoc = ExpectedLoc;
743 Actions.ActOnCaseStmt(CaseLoc, LHS.
get(), DotDotDotLoc,
748 if (Case.isInvalid()) {
749 if (TopLevelCase.isInvalid())
750 return ParseStatement(
nullptr,
756 Stmt *NextDeepest = Case.get();
757 if (TopLevelCase.isInvalid())
760 Actions.ActOnCaseStmtBody(DeepestParsedCaseStmt, Case.get());
761 DeepestParsedCaseStmt = NextDeepest;
765 }
while (
Tok.
is(tok::kw_case));
771 SubStmt = ParseStatement(
nullptr,
779 Diag(AfterColonLoc, diag::err_label_end_of_compound_statement)
786 if (DeepestParsedCaseStmt) {
788 if (SubStmt.isInvalid())
790 Actions.ActOnCaseStmtBody(DeepestParsedCaseStmt, SubStmt.get());
803 assert(
Tok.
is(tok::kw_default) &&
"Not a default stmt!");
810 Diag(ColonLoc, diag::err_expected_after)
811 <<
"'default'" << tok::colon
814 SourceLocation ExpectedLoc = PP.getLocForEndOfToken(PrevTokLocation);
815 Diag(ExpectedLoc, diag::err_expected_after)
816 <<
"'default'" << tok::colon
818 ColonLoc = ExpectedLoc;
824 SubStmt = ParseStatement(
nullptr,
830 Diag(AfterColonLoc, diag::err_label_end_of_compound_statement)
836 if (SubStmt.isInvalid())
837 SubStmt = Actions.ActOnNullStmt(ColonLoc);
839 return Actions.ActOnDefaultStmt(DefaultLoc, ColonLoc,
843 StmtResult Parser::ParseCompoundStatement(
bool isStmtExpr) {
844 return ParseCompoundStatement(isStmtExpr,
870 StmtResult Parser::ParseCompoundStatement(
bool isStmtExpr,
871 unsigned ScopeFlags) {
872 assert(
Tok.
is(tok::l_brace) &&
"Not a compount stmt!");
876 ParseScope CompoundScope(
this, ScopeFlags);
879 return ParseCompoundStatementBody(isStmtExpr);
885 void Parser::ParseCompoundStatementLeadingPragmas() {
886 bool checkForPragmas =
true;
887 while (checkForPragmas) {
888 switch (
Tok.getKind()) {
889 case tok::annot_pragma_vis:
890 HandlePragmaVisibility();
892 case tok::annot_pragma_pack:
895 case tok::annot_pragma_msstruct:
896 HandlePragmaMSStruct();
898 case tok::annot_pragma_align:
901 case tok::annot_pragma_weak:
904 case tok::annot_pragma_weakalias:
905 HandlePragmaWeakAlias();
907 case tok::annot_pragma_redefine_extname:
908 HandlePragmaRedefineExtname();
910 case tok::annot_pragma_opencl_extension:
911 HandlePragmaOpenCLExtension();
913 case tok::annot_pragma_fp_contract:
914 HandlePragmaFPContract();
916 case tok::annot_pragma_fp:
919 case tok::annot_pragma_ms_pointers_to_members:
920 HandlePragmaMSPointersToMembers();
922 case tok::annot_pragma_ms_pragma:
923 HandlePragmaMSPragma();
925 case tok::annot_pragma_ms_vtordisp:
926 HandlePragmaMSVtorDisp();
928 case tok::annot_pragma_dump:
932 checkForPragmas =
false;
943 StmtResult Parser::ParseCompoundStatementBody(
bool isStmtExpr) {
946 "in compound statement ('{}')");
960 ParseCompoundStatementLeadingPragmas();
966 while (
Tok.
is(tok::kw___label__)) {
972 Diag(Tok, diag::err_expected) << tok::identifier;
978 DeclsInGroup.push_back(Actions.LookupOrCreateLabel(II, IdLoc, LabelLoc));
986 Actions.FinalizeDeclaratorGroup(
getCurScope(), DS, DeclsInGroup);
987 StmtResult R = Actions.ActOnDeclStmt(Res, LabelLoc,
Tok.getLocation());
989 ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
991 Stmts.push_back(R.get());
994 while (!tryParseMisplacedModuleImport() &&
Tok.
isNot(tok::r_brace) &&
996 if (
Tok.
is(tok::annot_pragma_unused)) {
997 HandlePragmaUnused();
1002 if (
Tok.
isNot(tok::kw___extension__)) {
1003 R = ParseStatementOrDeclaration(Stmts, ACK_Any);
1010 while (
Tok.
is(tok::kw___extension__))
1013 ParsedAttributesWithRange attrs(AttrFactory);
1014 MaybeParseCXX11Attributes(attrs,
nullptr,
1018 if (isDeclarationStatement()) {
1026 R = Actions.ActOnDeclStmt(Res, DeclStart, DeclEnd);
1029 ExprResult Res(ParseExpressionWithLeadingExtension(ExtLoc));
1031 if (Res.isInvalid()) {
1039 ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
1040 R = Actions.ActOnExprStmt(Res);
1045 Stmts.push_back(R.get());
1051 if (!
T.consumeClose())
1054 CloseLoc =
T.getCloseLocation();
1056 return Actions.ActOnCompoundStmt(
T.getOpenLocation(), CloseLoc,
1072 bool Parser::ParseParenExprOrCondition(
StmtResult *InitStmt,
1080 Cond = ParseCXXCondition(InitStmt, Loc, CK);
1088 Cond = Actions.ActOnCondition(
getCurScope(), Loc, CondExpr.
get(), CK);
1108 while (
Tok.
is(tok::r_paren)) {
1109 Diag(Tok, diag::err_extraneous_rparen_in_condition)
1126 assert(
Tok.
is(tok::kw_if) &&
"Not an if stmt!");
1129 bool IsConstexpr =
false;
1130 if (
Tok.
is(tok::kw_constexpr)) {
1132 : diag::ext_constexpr_if);
1138 Diag(Tok, diag::err_expected_lparen_after) <<
"if";
1162 if (ParseParenExprOrCondition(&InitStmt, Cond, IfLoc,
1200 ConstexprCondition && !*ConstexprCondition);
1201 ThenStmt = ParseStatement(&InnerStatementTrailingElseLoc);
1212 if (
Tok.
is(tok::kw_else)) {
1213 if (TrailingElseLoc)
1214 *TrailingElseLoc =
Tok.getLocation();
1217 ElseStmtLoc =
Tok.getLocation();
1229 Tok.
is(tok::l_brace));
1234 ConstexprCondition && *ConstexprCondition);
1235 ElseStmt = ParseStatement();
1239 }
else if (
Tok.
is(tok::code_completion)) {
1243 }
else if (InnerStatementTrailingElseLoc.
isValid()) {
1244 Diag(InnerStatementTrailingElseLoc, diag::warn_dangling_else);
1252 if ((ThenStmt.isInvalid() && ElseStmt.isInvalid()) ||
1253 (ThenStmt.isInvalid() && ElseStmt.get() ==
nullptr) ||
1254 (ThenStmt.get() ==
nullptr && ElseStmt.isInvalid())) {
1260 if (ThenStmt.isInvalid())
1261 ThenStmt = Actions.ActOnNullStmt(ThenStmtLoc);
1262 if (ElseStmt.isInvalid())
1263 ElseStmt = Actions.ActOnNullStmt(ElseStmtLoc);
1265 return Actions.ActOnIfStmt(IfLoc, IsConstexpr, InitStmt.get(), Cond,
1266 ThenStmt.
get(), ElseLoc, ElseStmt.get());
1274 assert(
Tok.
is(tok::kw_switch) &&
"Not a switch stmt!");
1278 Diag(Tok, diag::err_expected_lparen_after) <<
"switch";
1300 ParseScope SwitchScope(
this, ScopeFlags);
1305 if (ParseParenExprOrCondition(&InitStmt, Cond, SwitchLoc,
1310 Actions.ActOnStartOfSwitchStmt(SwitchLoc, InitStmt.get(), Cond);
1312 if (Switch.isInvalid()) {
1317 if (
Tok.
is(tok::l_brace)) {
1345 StmtResult Body(ParseStatement(TrailingElseLoc));
1351 return Actions.ActOnFinishSwitchStmt(SwitchLoc, Switch.get(), Body.get());
1359 assert(
Tok.
is(tok::kw_while) &&
"Not a while stmt!");
1364 Diag(Tok, diag::err_expected_lparen_after) <<
"while";
1383 unsigned ScopeFlags;
1389 ParseScope WhileScope(
this, ScopeFlags);
1393 if (ParseParenExprOrCondition(
nullptr, Cond, WhileLoc,
1394 Sema::ConditionKind::Boolean))
1411 StmtResult Body(ParseStatement(TrailingElseLoc));
1417 if (Cond.
isInvalid() || Body.isInvalid())
1420 return Actions.ActOnWhileStmt(WhileLoc, Cond, Body.
get());
1428 assert(
Tok.
is(tok::kw_do) &&
"Not a do stmt!");
1433 unsigned ScopeFlags;
1439 ParseScope DoScope(
this, ScopeFlags);
1459 if (!Body.isInvalid()) {
1460 Diag(Tok, diag::err_expected_while);
1461 Diag(DoLoc, diag::note_matching) <<
"'do'";
1469 Diag(Tok, diag::err_expected_lparen_after) <<
"do/while";
1479 DiagnoseAndSkipCXX11Attributes();
1484 Cond = Actions.CorrectDelayedTyposInExpr(Cond);
1488 if (Cond.
isInvalid() || Body.isInvalid())
1491 return Actions.ActOnDoStmt(DoLoc, Body.get(), WhileLoc,
T.getOpenLocation(),
1492 Cond.
get(),
T.getCloseLocation());
1495 bool Parser::isForRangeIdentifier() {
1496 assert(
Tok.
is(tok::identifier));
1499 if (Next.is(tok::colon))
1502 if (Next.isOneOf(tok::l_square, tok::kw_alignas)) {
1503 TentativeParsingAction PA(*
this);
1505 SkipCXX11Attributes();
1537 assert(
Tok.
is(tok::kw_for) &&
"Not a for stmt!");
1541 if (
Tok.
is(tok::kw_co_await))
1545 Diag(Tok, diag::err_expected_lparen_after) <<
"for";
1568 unsigned ScopeFlags = 0;
1572 ParseScope ForScope(
this, ScopeFlags);
1579 bool ForEach =
false, ForRange =
false;
1583 ForRangeInit ForRangeInit;
1586 if (
Tok.
is(tok::code_completion)) {
1594 ParsedAttributesWithRange attrs(AttrFactory);
1595 MaybeParseCXX11Attributes(attrs);
1598 if (
Tok.
is(tok::semi)) {
1599 ProhibitAttributes(attrs);
1603 isForRangeIdentifier()) {
1604 ProhibitAttributes(attrs);
1607 MaybeParseCXX11Attributes(attrs);
1610 if (
Tok.
is(tok::l_brace))
1611 ForRangeInit.RangeExpr = ParseBraceInitializer();
1615 Diag(Loc, diag::err_for_range_identifier)
1620 FirstPart = Actions.ActOnCXXForRangeIdentifier(
getCurScope(), Loc, Name,
1621 attrs, attrs.Range.getEnd());
1623 }
else if (isForInitDeclaration()) {
1625 if (!C99orCXXorObjC)
1626 Diag(Tok, diag::ext_c99_variable_decl_in_for_loop);
1629 bool MightBeForRangeStmt =
getLangOpts().CPlusPlus;
1635 MightBeForRangeStmt ? &ForRangeInit :
nullptr);
1636 FirstPart = Actions.ActOnDeclStmt(DG, DeclStart,
Tok.getLocation());
1637 if (ForRangeInit.ParsedForRangeDecl()) {
1639 diag::warn_cxx98_compat_for_range : diag::ext_for_range);
1642 }
else if (
Tok.
is(tok::semi)) {
1644 }
else if ((ForEach = isTokIdentifier_in())) {
1645 Actions.ActOnForEachDeclStmt(DG);
1649 if (
Tok.
is(tok::code_completion)) {
1650 Actions.CodeCompleteObjCForCollection(
getCurScope(), DG);
1656 Diag(Tok, diag::err_expected_semi_for);
1659 ProhibitAttributes(attrs);
1662 ForEach = isTokIdentifier_in();
1667 FirstPart = Actions.ActOnForEachLValueExpr(Value.
get());
1669 FirstPart = Actions.ActOnExprStmt(Value);
1672 if (
Tok.
is(tok::semi)) {
1674 }
else if (ForEach) {
1677 if (
Tok.
is(tok::code_completion)) {
1678 Actions.CodeCompleteObjCForCollection(
getCurScope(),
nullptr);
1686 Diag(Tok, diag::err_for_range_expected_decl)
1687 << FirstPart.get()->getSourceRange();
1692 Diag(Tok, diag::err_expected_semi_for);
1696 if (
Tok.
is(tok::semi))
1704 if (!ForEach && !ForRange && !SecondPart.
isInvalid()) {
1706 if (
Tok.
is(tok::semi)) {
1708 }
else if (
Tok.
is(tok::r_paren)) {
1713 ParseCXXCondition(
nullptr, ForLoc, Sema::ConditionKind::Boolean);
1727 Diag(Tok, diag::err_expected_semi_for);
1733 if (
Tok.
is(tok::semi)) {
1742 ThirdPart = Actions.MakeFullDiscardedValueExpr(Third.
get());
1750 if (CoawaitLoc.
isValid() && !ForRange) {
1751 Diag(CoawaitLoc, diag::err_for_co_await_not_range_for);
1763 Actions.CorrectDelayedTyposInExpr(ForRangeInit.RangeExpr.get());
1764 ForRangeStmt = Actions.ActOnCXXForRangeStmt(
1765 getCurScope(), ForLoc, CoawaitLoc, FirstPart.get(),
1766 ForRangeInit.ColonLoc, CorrectedRange.
get(),
1771 }
else if (ForEach) {
1772 ForEachStmt = Actions.ActOnObjCForCollectionStmt(ForLoc,
1775 T.getCloseLocation());
1779 if (
getLangOpts().OpenMP && FirstPart.isUsable()) {
1780 Actions.ActOnOpenMPLoopInitialization(ForLoc, FirstPart.get());
1796 Tok.
is(tok::l_brace));
1806 StmtResult Body(ParseStatement(TrailingElseLoc));
1814 if (Body.isInvalid())
1818 return Actions.FinishObjCForCollectionStmt(ForEachStmt.get(),
1822 return Actions.FinishCXXForRangeStmt(ForRangeStmt.get(), Body.get());
1824 return Actions.ActOnForStmt(ForLoc,
T.getOpenLocation(), FirstPart.get(),
1825 SecondPart, ThirdPart,
T.getCloseLocation(),
1837 assert(
Tok.
is(tok::kw_goto) &&
"Not a goto stmt!");
1841 if (
Tok.
is(tok::identifier)) {
1842 LabelDecl *LD = Actions.LookupOrCreateLabel(
Tok.getIdentifierInfo(),
1844 Res = Actions.ActOnGotoStmt(GotoLoc,
Tok.getLocation(), LD);
1846 }
else if (
Tok.
is(tok::star)) {
1848 Diag(Tok, diag::ext_gnu_indirect_goto);
1851 if (R.isInvalid()) {
1855 Res = Actions.ActOnIndirectGotoStmt(GotoLoc, StarLoc, R.get());
1857 Diag(Tok, diag::err_expected) << tok::identifier;
1870 StmtResult Parser::ParseContinueStatement() {
1872 return Actions.ActOnContinueStmt(ContinueLoc,
getCurScope());
1883 return Actions.ActOnBreakStmt(BreakLoc,
getCurScope());
1893 assert((
Tok.
is(tok::kw_return) ||
Tok.
is(tok::kw_co_return)) &&
1894 "Not a return stmt!");
1895 bool IsCoreturn =
Tok.
is(tok::kw_co_return);
1901 if (
Tok.
is(tok::code_completion) && !IsCoreturn) {
1908 R = ParseInitializer();
1911 diag::warn_cxx98_compat_generalized_initializer_lists :
1912 diag::ext_generalized_initializer_lists)
1913 << R.
get()->getSourceRange();
1922 return Actions.ActOnCoreturnStmt(
getCurScope(), ReturnLoc, R.
get());
1923 return Actions.ActOnReturnStmt(ReturnLoc, R.
get(),
getCurScope());
1926 StmtResult Parser::ParsePragmaLoopHint(StmtVector &Stmts,
1927 AllowedConstructsKind Allowed,
1929 ParsedAttributesWithRange &Attrs) {
1931 ParsedAttributesWithRange TempAttrs(AttrFactory);
1934 while (
Tok.
is(tok::annot_pragma_loop_hint)) {
1936 if (!HandlePragmaLoopHint(Hint))
1947 MaybeParseCXX11Attributes(Attrs);
1949 StmtResult S = ParseStatementOrDeclarationAfterAttributes(
1950 Stmts, Allowed, TrailingElseLoc, Attrs);
1952 Attrs.takeAllFrom(TempAttrs);
1956 Decl *Parser::ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope) {
1957 assert(
Tok.
is(tok::l_brace));
1961 "parsing function body");
1965 getLangOpts().CPlusPlus && Decl && isa<CXXMethodDecl>(Decl);
1967 PragmaStackSentinel(Actions,
"InternalPragmaState", IsCXXMethod);
1972 StmtResult FnBody(ParseCompoundStatementBody());
1975 if (FnBody.isInvalid()) {
1977 FnBody = Actions.ActOnCompoundStmt(LBraceLoc, LBraceLoc,
None,
false);
1981 return Actions.ActOnFinishFunctionBody(Decl, FnBody.get());
1989 Decl *Parser::ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope) {
1990 assert(
Tok.
is(tok::kw_try) &&
"Expected 'try'");
1994 "parsing function try block");
1997 if (
Tok.
is(tok::colon))
1998 ParseConstructorInitializer(Decl);
2000 Actions.ActOnDefaultCtorInitializers(Decl);
2004 getLangOpts().CPlusPlus && Decl && isa<CXXMethodDecl>(Decl);
2006 PragmaStackSentinel(Actions,
"InternalPragmaState", IsCXXMethod);
2009 StmtResult FnBody(ParseCXXTryBlockCommon(TryLoc,
true));
2012 if (FnBody.isInvalid()) {
2014 FnBody = Actions.ActOnCompoundStmt(LBraceLoc, LBraceLoc,
None,
false);
2018 return Actions.ActOnFinishFunctionBody(Decl, FnBody.get());
2021 bool Parser::trySkippingFunctionBody() {
2022 assert(SkipFunctionBodies &&
2023 "Should only be called when SkipFunctionBodies is enabled");
2024 if (!PP.isCodeCompletionEnabled()) {
2031 TentativeParsingAction PA(*
this);
2032 bool IsTryCatch =
Tok.
is(tok::kw_try);
2034 bool ErrorInPrologue = ConsumeAndStoreFunctionPrologue(Toks);
2035 if (llvm::any_of(Toks, [](
const Token &Tok) {
2036 return Tok.
is(tok::code_completion);
2041 if (ErrorInPrologue) {
2050 while (IsTryCatch && Tok.
is(tok::kw_catch)) {
2067 assert(Tok.
is(tok::kw_try) &&
"Expected 'try'");
2070 return ParseCXXTryBlockCommon(TryLoc);
2090 if (Tok.
isNot(tok::l_brace))
2091 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
2097 if (TryBlock.isInvalid())
2102 if ((Tok.
is(tok::identifier) &&
2104 Tok.
is(tok::kw___finally)) {
2109 Handler = ParseSEHExceptBlock(Loc);
2113 Handler = ParseSEHFinallyBlock(Loc);
2115 if(Handler.isInvalid())
2118 return Actions.ActOnSEHTryBlock(
true ,
2124 StmtVector Handlers;
2128 DiagnoseAndSkipCXX11Attributes();
2130 if (Tok.
isNot(tok::kw_catch))
2132 while (Tok.
is(tok::kw_catch)) {
2133 StmtResult Handler(ParseCXXCatchBlock(FnTry));
2134 if (!Handler.isInvalid())
2135 Handlers.push_back(Handler.get());
2139 if (Handlers.empty())
2142 return Actions.ActOnCXXTryBlock(TryLoc, TryBlock.get(), Handlers);
2156 StmtResult Parser::ParseCXXCatchBlock(
bool FnCatch) {
2157 assert(Tok.
is(tok::kw_catch) &&
"Expected 'catch'");
2162 if (
T.expectAndConsume())
2173 Decl *ExceptionDecl =
nullptr;
2174 if (Tok.
isNot(tok::ellipsis)) {
2175 ParsedAttributesWithRange Attributes(AttrFactory);
2176 MaybeParseCXX11Attributes(Attributes);
2179 DS.takeAttributesFrom(Attributes);
2181 if (ParseCXXTypeSpecifierSeq(DS))
2185 ParseDeclarator(ExDecl);
2186 ExceptionDecl = Actions.ActOnExceptionDeclarator(
getCurScope(), ExDecl);
2191 if (
T.getCloseLocation().isInvalid())
2194 if (Tok.
isNot(tok::l_brace))
2195 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
2199 if (Block.isInvalid())
2202 return Actions.ActOnCXXCatchBlock(CatchLoc, ExceptionDecl, Block.get());
2205 void Parser::ParseMicrosoftIfExistsStatement(StmtVector &Stmts) {
2206 IfExistsCondition
Result;
2207 if (ParseMicrosoftIfExistsCondition(Result))
2214 if (Result.Behavior == IEB_Dependent) {
2215 if (!Tok.
is(tok::l_brace)) {
2216 Diag(Tok, diag::err_expected) << tok::l_brace;
2220 StmtResult Compound = ParseCompoundStatement();
2221 if (Compound.isInvalid())
2224 StmtResult DepResult = Actions.ActOnMSDependentExistsStmt(Result.KeywordLoc,
2229 if (DepResult.isUsable())
2230 Stmts.push_back(DepResult.get());
2235 if (Braces.consumeOpen()) {
2236 Diag(Tok, diag::err_expected) << tok::l_brace;
2240 switch (Result.Behavior) {
2246 llvm_unreachable(
"Dependent case handled above");
2254 while (Tok.
isNot(tok::r_brace)) {
2255 StmtResult R = ParseStatementOrDeclaration(Stmts, ACK_Any);
2257 Stmts.push_back(R.get());
2259 Braces.consumeClose();
2263 MaybeParseGNUAttributes(Attrs);
2268 if (Attrs.
getList()->
getKind() != AttributeList::AT_OpenCLUnrollHint)
2271 if (!(Tok.
is(tok::kw_for) || Tok.
is(tok::kw_while) || Tok.
is(tok::kw_do))) {
2272 Diag(Tok, diag::err_opencl_unroll_hint_on_non_loop);
void AddFlags(unsigned Flags)
Sets up the specified scope flags and adjusts the scope state variables accordingly.
IdentifierLoc * PragmaNameLoc
This is the scope of a C++ try statement.
Sema::FullExprArg FullExprArg
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
Simple class containing the result of Sema::CorrectTypo.
static ConditionResult ConditionError()
Stmt - This represents one statement.
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {...
Decl - This represents one declaration (or definition), e.g.
Defines the PrettyStackTraceEntry class, which is used to make crashes give more contextual informati...
This is a while, do, switch, for, etc that can have break statements embedded into it...
NamespaceDecl - Represent a C++ namespace.
RAII object that enters a new expression evaluation context.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Information about one declarator, including the parsed type information and the identifier.
IdentifierLoc * OptionLoc
Records and restores the FP_CONTRACT state on entry/exit of compound statements.
NestedNameSpecifier * getCorrectionSpecifier() const
Gets the NestedNameSpecifier needed to use the typo correction.
DeclClass * getCorrectionDeclAs() const
RAII object that makes sure paren/bracket/brace count is correct after declaration/statement parsing...
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed...
AttributeList * getList() const
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
bool TryConsumeToken(tok::TokenKind Expected)
One of these records is kept for each identifier that is lexed.
llvm::PointerUnion< Expr *, IdentifierLoc * > ArgsUnion
A union of the various pointer types that can be passed to an AttributeList as an argument...
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
void decrementMSManglingNumber()
Token - This structure provides full information about a lexed token.
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ...
std::pair< VarDecl *, Expr * > get() const
The controlling scope in a if/switch/while/for statement.
This is a scope that corresponds to a switch statement.
This is a while, do, for, which can have continue statements embedded into it.
Code completion occurs within an expression.
If a crash happens while one of these objects are live, the message is printed out along with the spe...
The current expression occurs within a discarded statement.
llvm::Optional< bool > getKnownValue() const
A RAII object to enter scope of a compound statement.
virtual bool ValidateCandidate(const TypoCorrection &candidate)
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
Expr - This represents one expression.
const FunctionProtoType * T
This scope corresponds to an SEH try.
This file defines the classes used to store parsed information about declaration-specifiers and decla...
void SkipMalformedDecl()
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a s...
This scope corresponds to an SEH except.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Initial building of a for-range statement.
This is a compound statement scope.
Code completion occurs within a statement, which may also be an expression or a declaration.
A boolean condition, from 'if', 'while', 'for', or 'do'.
The result type of a method or function.
StmtResult ProcessStmtAttributes(Stmt *Stmt, AttributeList *Attrs, SourceRange Range)
Stmt attributes - this routine is the top level dispatcher.
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
PrettyDeclStackTraceEntry - If a crash occurs in the parser while parsing something related to a decl...
const LangOptions & getLangOpts() const
Stop skipping at semicolon.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Encodes a location in the source.
IdentifierInfo * getIdentifierInfo() const
LabelDecl - Represents the declaration of a label.
ExtensionRAIIObject - This saves the state of extension warnings when constructed and disables them...
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Scope * getCurScope() const
We are currently in the filter expression of an SEH except block.
bool isNot(tok::TokenKind K) const
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
A constant boolean condition from 'if constexpr'.
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
This is the scope for a function-level C++ try or catch scope.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
ActionResult< Stmt * > StmtResult
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
This is a scope that can contain a declaration.
ExprResult ParseConstantExpression(TypeCastState isTypeCast=NotTypeCast)
An integral condition for a 'switch' statement.
Captures information about "declaration specifiers".
Code completion occurs at the beginning of the initialization statement (or expression) in a for loop...
bool isSwitchScope() const
isSwitchScope - Return true if this scope is a switch scope.
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
Loop optimization hint for loop and unroll pragmas.
ParsedAttributes - A collection of parsed attributes.
SourceLocation ColonLoc
Location of ':'.
An RAII object for [un]poisoning an identifier within a scope.
AttributeList - Represents a syntactic attribute.
Stop skipping at specified token, but don't skip the token itself.