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(SubStmt.get(), TempAttrs,
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());
630 Actions.ProcessDeclAttributeList(Actions.CurScope, LD, attrs);
633 return Actions.ActOnLabelStmt(IdentTok.getLocation(), LD,
ColonLoc,
643 assert((MissingCase ||
Tok.
is(tok::kw_case)) &&
"Not a case stmt!");
666 Stmt *DeepestParsedCaseStmt =
nullptr;
675 if (
Tok.
is(tok::code_completion)) {
704 Diag(DotDotDotLoc, diag::ext_gnu_case_range);
712 ColonProtection.restore();
718 Diag(ColonLoc, diag::err_expected_after)
719 <<
"'case'" << tok::colon
722 SourceLocation ExpectedLoc = PP.getLocForEndOfToken(PrevTokLocation);
723 Diag(ExpectedLoc, diag::err_expected_after)
724 <<
"'case'" << tok::colon
726 ColonLoc = ExpectedLoc;
730 Actions.ActOnCaseStmt(CaseLoc, LHS, DotDotDotLoc, RHS, ColonLoc);
734 if (Case.isInvalid()) {
735 if (TopLevelCase.isInvalid())
736 return ParseStatement(
nullptr,
742 Stmt *NextDeepest = Case.get();
743 if (TopLevelCase.isInvalid())
746 Actions.ActOnCaseStmtBody(DeepestParsedCaseStmt, Case.get());
747 DeepestParsedCaseStmt = NextDeepest;
751 }
while (
Tok.
is(tok::kw_case));
757 SubStmt = ParseStatement(
nullptr,
765 Diag(AfterColonLoc, diag::err_label_end_of_compound_statement)
772 if (DeepestParsedCaseStmt) {
774 if (SubStmt.isInvalid())
776 Actions.ActOnCaseStmtBody(DeepestParsedCaseStmt, SubStmt.get());
789 assert(
Tok.
is(tok::kw_default) &&
"Not a default stmt!");
796 Diag(ColonLoc, diag::err_expected_after)
797 <<
"'default'" << tok::colon
800 SourceLocation ExpectedLoc = PP.getLocForEndOfToken(PrevTokLocation);
801 Diag(ExpectedLoc, diag::err_expected_after)
802 <<
"'default'" << tok::colon
804 ColonLoc = ExpectedLoc;
810 SubStmt = ParseStatement(
nullptr,
816 Diag(AfterColonLoc, diag::err_label_end_of_compound_statement)
822 if (SubStmt.isInvalid())
823 SubStmt = Actions.ActOnNullStmt(ColonLoc);
825 return Actions.ActOnDefaultStmt(DefaultLoc, ColonLoc,
829 StmtResult Parser::ParseCompoundStatement(
bool isStmtExpr) {
830 return ParseCompoundStatement(isStmtExpr,
856 StmtResult Parser::ParseCompoundStatement(
bool isStmtExpr,
857 unsigned ScopeFlags) {
858 assert(
Tok.
is(tok::l_brace) &&
"Not a compount stmt!");
862 ParseScope CompoundScope(
this, ScopeFlags);
865 return ParseCompoundStatementBody(isStmtExpr);
871 void Parser::ParseCompoundStatementLeadingPragmas() {
872 bool checkForPragmas =
true;
873 while (checkForPragmas) {
874 switch (
Tok.getKind()) {
875 case tok::annot_pragma_vis:
876 HandlePragmaVisibility();
878 case tok::annot_pragma_pack:
881 case tok::annot_pragma_msstruct:
882 HandlePragmaMSStruct();
884 case tok::annot_pragma_align:
887 case tok::annot_pragma_weak:
890 case tok::annot_pragma_weakalias:
891 HandlePragmaWeakAlias();
893 case tok::annot_pragma_redefine_extname:
894 HandlePragmaRedefineExtname();
896 case tok::annot_pragma_opencl_extension:
897 HandlePragmaOpenCLExtension();
899 case tok::annot_pragma_fp_contract:
900 HandlePragmaFPContract();
902 case tok::annot_pragma_fp:
905 case tok::annot_pragma_ms_pointers_to_members:
906 HandlePragmaMSPointersToMembers();
908 case tok::annot_pragma_ms_pragma:
909 HandlePragmaMSPragma();
911 case tok::annot_pragma_ms_vtordisp:
912 HandlePragmaMSVtorDisp();
914 case tok::annot_pragma_dump:
918 checkForPragmas =
false;
929 StmtResult Parser::ParseCompoundStatementBody(
bool isStmtExpr) {
932 "in compound statement ('{}')");
946 ParseCompoundStatementLeadingPragmas();
952 while (
Tok.
is(tok::kw___label__)) {
958 Diag(Tok, diag::err_expected) << tok::identifier;
964 DeclsInGroup.push_back(Actions.LookupOrCreateLabel(II, IdLoc, LabelLoc));
972 Actions.FinalizeDeclaratorGroup(
getCurScope(), DS, DeclsInGroup);
973 StmtResult R = Actions.ActOnDeclStmt(Res, LabelLoc,
Tok.getLocation());
975 ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
977 Stmts.push_back(R.get());
980 while (!tryParseMisplacedModuleImport() &&
Tok.
isNot(tok::r_brace) &&
982 if (
Tok.
is(tok::annot_pragma_unused)) {
983 HandlePragmaUnused();
988 if (
Tok.
isNot(tok::kw___extension__)) {
989 R = ParseStatementOrDeclaration(Stmts, ACK_Any);
996 while (
Tok.
is(tok::kw___extension__))
999 ParsedAttributesWithRange attrs(AttrFactory);
1000 MaybeParseCXX11Attributes(attrs,
nullptr,
1004 if (isDeclarationStatement()) {
1012 R = Actions.ActOnDeclStmt(Res, DeclStart, DeclEnd);
1015 ExprResult Res(ParseExpressionWithLeadingExtension(ExtLoc));
1017 if (Res.isInvalid()) {
1025 ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
1026 R = Actions.ActOnExprStmt(Res);
1031 Stmts.push_back(R.get());
1037 if (!T.consumeClose())
1040 CloseLoc = T.getCloseLocation();
1042 return Actions.ActOnCompoundStmt(T.getOpenLocation(), CloseLoc,
1058 bool Parser::ParseParenExprOrCondition(
StmtResult *InitStmt,
1066 Cond = ParseCXXCondition(InitStmt, Loc, CK);
1074 Cond = Actions.ActOnCondition(
getCurScope(), Loc, CondExpr.
get(), CK);
1094 while (
Tok.
is(tok::r_paren)) {
1095 Diag(Tok, diag::err_extraneous_rparen_in_condition)
1112 assert(
Tok.
is(tok::kw_if) &&
"Not an if stmt!");
1115 bool IsConstexpr =
false;
1116 if (
Tok.
is(tok::kw_constexpr)) {
1118 : diag::ext_constexpr_if);
1124 Diag(Tok, diag::err_expected_lparen_after) <<
"if";
1148 if (ParseParenExprOrCondition(&InitStmt, Cond, IfLoc,
1186 ConstexprCondition && !*ConstexprCondition);
1187 ThenStmt = ParseStatement(&InnerStatementTrailingElseLoc);
1198 if (
Tok.
is(tok::kw_else)) {
1199 if (TrailingElseLoc)
1200 *TrailingElseLoc =
Tok.getLocation();
1203 ElseStmtLoc =
Tok.getLocation();
1215 Tok.
is(tok::l_brace));
1220 ConstexprCondition && *ConstexprCondition);
1221 ElseStmt = ParseStatement();
1225 }
else if (
Tok.
is(tok::code_completion)) {
1229 }
else if (InnerStatementTrailingElseLoc.
isValid()) {
1230 Diag(InnerStatementTrailingElseLoc, diag::warn_dangling_else);
1238 if ((ThenStmt.isInvalid() && ElseStmt.isInvalid()) ||
1239 (ThenStmt.isInvalid() && ElseStmt.get() ==
nullptr) ||
1240 (ThenStmt.get() ==
nullptr && ElseStmt.isInvalid())) {
1246 if (ThenStmt.isInvalid())
1247 ThenStmt = Actions.ActOnNullStmt(ThenStmtLoc);
1248 if (ElseStmt.isInvalid())
1249 ElseStmt = Actions.ActOnNullStmt(ElseStmtLoc);
1251 return Actions.ActOnIfStmt(IfLoc, IsConstexpr, InitStmt.get(), Cond,
1252 ThenStmt.
get(), ElseLoc, ElseStmt.get());
1260 assert(
Tok.
is(tok::kw_switch) &&
"Not a switch stmt!");
1264 Diag(Tok, diag::err_expected_lparen_after) <<
"switch";
1286 ParseScope SwitchScope(
this, ScopeFlags);
1291 if (ParseParenExprOrCondition(&InitStmt, Cond, SwitchLoc,
1296 Actions.ActOnStartOfSwitchStmt(SwitchLoc, InitStmt.get(), Cond);
1298 if (Switch.isInvalid()) {
1303 if (
Tok.
is(tok::l_brace)) {
1331 StmtResult Body(ParseStatement(TrailingElseLoc));
1337 return Actions.ActOnFinishSwitchStmt(SwitchLoc, Switch.get(), Body.get());
1345 assert(
Tok.
is(tok::kw_while) &&
"Not a while stmt!");
1350 Diag(Tok, diag::err_expected_lparen_after) <<
"while";
1369 unsigned ScopeFlags;
1375 ParseScope WhileScope(
this, ScopeFlags);
1379 if (ParseParenExprOrCondition(
nullptr, Cond, WhileLoc,
1380 Sema::ConditionKind::Boolean))
1397 StmtResult Body(ParseStatement(TrailingElseLoc));
1403 if (Cond.
isInvalid() || Body.isInvalid())
1406 return Actions.ActOnWhileStmt(WhileLoc, Cond, Body.
get());
1414 assert(
Tok.
is(tok::kw_do) &&
"Not a do stmt!");
1419 unsigned ScopeFlags;
1425 ParseScope DoScope(
this, ScopeFlags);
1445 if (!Body.isInvalid()) {
1446 Diag(Tok, diag::err_expected_while);
1447 Diag(DoLoc, diag::note_matching) <<
"'do'";
1455 Diag(Tok, diag::err_expected_lparen_after) <<
"do/while";
1465 DiagnoseAndSkipCXX11Attributes();
1470 Cond = Actions.CorrectDelayedTyposInExpr(Cond);
1474 if (Cond.
isInvalid() || Body.isInvalid())
1477 return Actions.ActOnDoStmt(DoLoc, Body.get(), WhileLoc, T.getOpenLocation(),
1478 Cond.
get(), T.getCloseLocation());
1481 bool Parser::isForRangeIdentifier() {
1482 assert(
Tok.
is(tok::identifier));
1485 if (Next.is(tok::colon))
1488 if (Next.isOneOf(tok::l_square, tok::kw_alignas)) {
1489 TentativeParsingAction PA(*
this);
1491 SkipCXX11Attributes();
1523 assert(
Tok.
is(tok::kw_for) &&
"Not a for stmt!");
1527 if (
Tok.
is(tok::kw_co_await))
1531 Diag(Tok, diag::err_expected_lparen_after) <<
"for";
1554 unsigned ScopeFlags = 0;
1558 ParseScope ForScope(
this, ScopeFlags);
1565 bool ForEach =
false, ForRange =
false;
1569 ForRangeInit ForRangeInit;
1572 if (
Tok.
is(tok::code_completion)) {
1580 ParsedAttributesWithRange attrs(AttrFactory);
1581 MaybeParseCXX11Attributes(attrs);
1584 if (
Tok.
is(tok::semi)) {
1585 ProhibitAttributes(attrs);
1589 isForRangeIdentifier()) {
1590 ProhibitAttributes(attrs);
1593 MaybeParseCXX11Attributes(attrs);
1596 if (
Tok.
is(tok::l_brace))
1597 ForRangeInit.RangeExpr = ParseBraceInitializer();
1601 Diag(Loc, diag::err_for_range_identifier)
1606 FirstPart = Actions.ActOnCXXForRangeIdentifier(
getCurScope(), Loc, Name,
1607 attrs, attrs.Range.getEnd());
1609 }
else if (isForInitDeclaration()) {
1613 if (!C99orCXXorObjC) {
1614 Diag(Tok, diag::ext_c99_variable_decl_in_for_loop);
1615 Diag(Tok, diag::warn_gcc_variable_decl_in_for_loop);
1619 bool MightBeForRangeStmt =
getLangOpts().CPlusPlus;
1625 MightBeForRangeStmt ? &ForRangeInit :
nullptr);
1626 FirstPart = Actions.ActOnDeclStmt(DG, DeclStart,
Tok.getLocation());
1627 if (ForRangeInit.ParsedForRangeDecl()) {
1629 diag::warn_cxx98_compat_for_range : diag::ext_for_range);
1632 }
else if (
Tok.
is(tok::semi)) {
1634 }
else if ((ForEach = isTokIdentifier_in())) {
1635 Actions.ActOnForEachDeclStmt(DG);
1639 if (
Tok.
is(tok::code_completion)) {
1640 Actions.CodeCompleteObjCForCollection(
getCurScope(), DG);
1646 Diag(Tok, diag::err_expected_semi_for);
1649 ProhibitAttributes(attrs);
1652 ForEach = isTokIdentifier_in();
1657 FirstPart = Actions.ActOnForEachLValueExpr(Value.
get());
1659 FirstPart = Actions.ActOnExprStmt(Value);
1662 if (
Tok.
is(tok::semi)) {
1664 }
else if (ForEach) {
1667 if (
Tok.
is(tok::code_completion)) {
1668 Actions.CodeCompleteObjCForCollection(
getCurScope(),
nullptr);
1676 Diag(Tok, diag::err_for_range_expected_decl)
1677 << FirstPart.get()->getSourceRange();
1682 Diag(Tok, diag::err_expected_semi_for);
1686 if (
Tok.
is(tok::semi))
1694 if (!ForEach && !ForRange && !SecondPart.
isInvalid()) {
1696 if (
Tok.
is(tok::semi)) {
1698 }
else if (
Tok.
is(tok::r_paren)) {
1703 ParseCXXCondition(
nullptr, ForLoc, Sema::ConditionKind::Boolean);
1717 Diag(Tok, diag::err_expected_semi_for);
1723 if (
Tok.
is(tok::semi)) {
1732 ThirdPart = Actions.MakeFullDiscardedValueExpr(Third.
get());
1740 if (CoawaitLoc.
isValid() && !ForRange) {
1741 Diag(CoawaitLoc, diag::err_for_co_await_not_range_for);
1753 Actions.CorrectDelayedTyposInExpr(ForRangeInit.RangeExpr.get());
1754 ForRangeStmt = Actions.ActOnCXXForRangeStmt(
1755 getCurScope(), ForLoc, CoawaitLoc, FirstPart.get(),
1756 ForRangeInit.ColonLoc, CorrectedRange.
get(),
1761 }
else if (ForEach) {
1762 ForEachStmt = Actions.ActOnObjCForCollectionStmt(ForLoc,
1765 T.getCloseLocation());
1769 if (
getLangOpts().OpenMP && FirstPart.isUsable()) {
1770 Actions.ActOnOpenMPLoopInitialization(ForLoc, FirstPart.get());
1786 Tok.
is(tok::l_brace));
1796 StmtResult Body(ParseStatement(TrailingElseLoc));
1804 if (Body.isInvalid())
1808 return Actions.FinishObjCForCollectionStmt(ForEachStmt.get(),
1812 return Actions.FinishCXXForRangeStmt(ForRangeStmt.get(), Body.get());
1814 return Actions.ActOnForStmt(ForLoc, T.getOpenLocation(), FirstPart.get(),
1815 SecondPart, ThirdPart, T.getCloseLocation(),
1827 assert(
Tok.
is(tok::kw_goto) &&
"Not a goto stmt!");
1831 if (
Tok.
is(tok::identifier)) {
1832 LabelDecl *LD = Actions.LookupOrCreateLabel(
Tok.getIdentifierInfo(),
1834 Res = Actions.ActOnGotoStmt(GotoLoc,
Tok.getLocation(), LD);
1836 }
else if (
Tok.
is(tok::star)) {
1838 Diag(Tok, diag::ext_gnu_indirect_goto);
1841 if (R.isInvalid()) {
1845 Res = Actions.ActOnIndirectGotoStmt(GotoLoc, StarLoc, R.get());
1847 Diag(Tok, diag::err_expected) << tok::identifier;
1860 StmtResult Parser::ParseContinueStatement() {
1862 return Actions.ActOnContinueStmt(ContinueLoc,
getCurScope());
1873 return Actions.ActOnBreakStmt(BreakLoc,
getCurScope());
1883 assert((
Tok.
is(tok::kw_return) ||
Tok.
is(tok::kw_co_return)) &&
1884 "Not a return stmt!");
1885 bool IsCoreturn =
Tok.
is(tok::kw_co_return);
1891 if (
Tok.
is(tok::code_completion) && !IsCoreturn) {
1898 R = ParseInitializer();
1901 diag::warn_cxx98_compat_generalized_initializer_lists :
1902 diag::ext_generalized_initializer_lists)
1903 << R.
get()->getSourceRange();
1912 return Actions.ActOnCoreturnStmt(
getCurScope(), ReturnLoc, R.
get());
1913 return Actions.ActOnReturnStmt(ReturnLoc, R.
get(),
getCurScope());
1916 StmtResult Parser::ParsePragmaLoopHint(StmtVector &Stmts,
1917 AllowedConstructsKind Allowed,
1919 ParsedAttributesWithRange &Attrs) {
1921 ParsedAttributesWithRange TempAttrs(AttrFactory);
1924 while (
Tok.
is(tok::annot_pragma_loop_hint)) {
1926 if (!HandlePragmaLoopHint(Hint))
1937 MaybeParseCXX11Attributes(Attrs);
1939 StmtResult S = ParseStatementOrDeclarationAfterAttributes(
1940 Stmts, Allowed, TrailingElseLoc, Attrs);
1942 Attrs.takeAllFrom(TempAttrs);
1946 Decl *Parser::ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope) {
1947 assert(
Tok.
is(tok::l_brace));
1951 "parsing function body");
1955 getLangOpts().CPlusPlus && Decl && isa<CXXMethodDecl>(Decl);
1957 PragmaStackSentinel(Actions,
"InternalPragmaState", IsCXXMethod);
1962 StmtResult FnBody(ParseCompoundStatementBody());
1965 if (FnBody.isInvalid()) {
1967 FnBody = Actions.ActOnCompoundStmt(LBraceLoc, LBraceLoc,
None,
false);
1971 return Actions.ActOnFinishFunctionBody(Decl, FnBody.get());
1979 Decl *Parser::ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope) {
1980 assert(
Tok.
is(tok::kw_try) &&
"Expected 'try'");
1984 "parsing function try block");
1987 if (
Tok.
is(tok::colon))
1988 ParseConstructorInitializer(Decl);
1990 Actions.ActOnDefaultCtorInitializers(Decl);
1994 getLangOpts().CPlusPlus && Decl && isa<CXXMethodDecl>(Decl);
1996 PragmaStackSentinel(Actions,
"InternalPragmaState", IsCXXMethod);
1999 StmtResult FnBody(ParseCXXTryBlockCommon(TryLoc,
true));
2002 if (FnBody.isInvalid()) {
2004 FnBody = Actions.ActOnCompoundStmt(LBraceLoc, LBraceLoc,
None,
false);
2008 return Actions.ActOnFinishFunctionBody(Decl, FnBody.get());
2011 bool Parser::trySkippingFunctionBody() {
2012 assert(SkipFunctionBodies &&
2013 "Should only be called when SkipFunctionBodies is enabled");
2014 if (!PP.isCodeCompletionEnabled()) {
2021 TentativeParsingAction PA(*
this);
2022 bool IsTryCatch =
Tok.
is(tok::kw_try);
2024 bool ErrorInPrologue = ConsumeAndStoreFunctionPrologue(Toks);
2025 if (llvm::any_of(Toks, [](
const Token &Tok) {
2026 return Tok.
is(tok::code_completion);
2031 if (ErrorInPrologue) {
2040 while (IsTryCatch && Tok.
is(tok::kw_catch)) {
2057 assert(Tok.
is(tok::kw_try) &&
"Expected 'try'");
2060 return ParseCXXTryBlockCommon(TryLoc);
2080 if (Tok.
isNot(tok::l_brace))
2081 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
2087 if (TryBlock.isInvalid())
2092 if ((Tok.
is(tok::identifier) &&
2094 Tok.
is(tok::kw___finally)) {
2099 Handler = ParseSEHExceptBlock(Loc);
2103 Handler = ParseSEHFinallyBlock(Loc);
2105 if(Handler.isInvalid())
2108 return Actions.ActOnSEHTryBlock(
true ,
2114 StmtVector Handlers;
2118 DiagnoseAndSkipCXX11Attributes();
2120 if (Tok.
isNot(tok::kw_catch))
2122 while (Tok.
is(tok::kw_catch)) {
2123 StmtResult Handler(ParseCXXCatchBlock(FnTry));
2124 if (!Handler.isInvalid())
2125 Handlers.push_back(Handler.get());
2129 if (Handlers.empty())
2132 return Actions.ActOnCXXTryBlock(TryLoc, TryBlock.get(), Handlers);
2146 StmtResult Parser::ParseCXXCatchBlock(
bool FnCatch) {
2147 assert(Tok.
is(tok::kw_catch) &&
"Expected 'catch'");
2152 if (T.expectAndConsume())
2163 Decl *ExceptionDecl =
nullptr;
2164 if (Tok.
isNot(tok::ellipsis)) {
2165 ParsedAttributesWithRange Attributes(AttrFactory);
2166 MaybeParseCXX11Attributes(Attributes);
2169 DS.takeAttributesFrom(Attributes);
2171 if (ParseCXXTypeSpecifierSeq(DS))
2175 ParseDeclarator(ExDecl);
2176 ExceptionDecl = Actions.ActOnExceptionDeclarator(
getCurScope(), ExDecl);
2181 if (T.getCloseLocation().isInvalid())
2184 if (Tok.
isNot(tok::l_brace))
2185 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
2189 if (Block.isInvalid())
2192 return Actions.ActOnCXXCatchBlock(CatchLoc, ExceptionDecl, Block.get());
2195 void Parser::ParseMicrosoftIfExistsStatement(StmtVector &Stmts) {
2196 IfExistsCondition
Result;
2197 if (ParseMicrosoftIfExistsCondition(Result))
2204 if (Result.Behavior == IEB_Dependent) {
2205 if (!Tok.
is(tok::l_brace)) {
2206 Diag(Tok, diag::err_expected) << tok::l_brace;
2210 StmtResult Compound = ParseCompoundStatement();
2211 if (Compound.isInvalid())
2214 StmtResult DepResult = Actions.ActOnMSDependentExistsStmt(Result.KeywordLoc,
2219 if (DepResult.isUsable())
2220 Stmts.push_back(DepResult.get());
2225 if (Braces.consumeOpen()) {
2226 Diag(Tok, diag::err_expected) << tok::l_brace;
2230 switch (Result.Behavior) {
2236 llvm_unreachable(
"Dependent case handled above");
2244 while (Tok.
isNot(tok::r_brace)) {
2245 StmtResult R = ParseStatementOrDeclaration(Stmts, ACK_Any);
2247 Stmts.push_back(R.get());
2249 Braces.consumeClose();
2253 MaybeParseGNUAttributes(Attrs);
2258 if (Attrs.
begin()->getKind() != ParsedAttr::AT_OpenCLUnrollHint)
2261 if (!(Tok.
is(tok::kw_for) || Tok.
is(tok::kw_while) || Tok.
is(tok::kw_do))) {
2262 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.
llvm::PointerUnion< Expr *, IdentifierLoc * > ArgsUnion
A union of the various pointer types that can be passed to an ParsedAttr as an argument.
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...
Represent a C++ namespace.
RAII object that enters a new expression evaluation context.
Represents a variable declaration or definition.
ActionResult< Stmt * > StmtResult
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...
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.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
Represents a member of a struct/union/class.
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.
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.
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
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.
ExprResult ParseCaseExpression(SourceLocation CaseLoc)
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)
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.
StmtResult ProcessStmtAttributes(Stmt *Stmt, const ParsedAttributesView &Attrs, SourceRange Range)
Stmt attributes - this routine is the top level dispatcher.
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.
Stop skipping at specified token, but don't skip the token itself.