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_fenv_access:
352 ProhibitAttributes(Attrs);
353 HandlePragmaFEnvAccess();
356 case tok::annot_pragma_opencl_extension:
357 ProhibitAttributes(Attrs);
358 HandlePragmaOpenCLExtension();
361 case tok::annot_pragma_captured:
362 ProhibitAttributes(Attrs);
363 return HandlePragmaCaptured();
365 case tok::annot_pragma_openmp:
366 ProhibitAttributes(Attrs);
367 return ParseOpenMPDeclarativeOrExecutableDirective(Allowed);
369 case tok::annot_pragma_ms_pointers_to_members:
370 ProhibitAttributes(Attrs);
371 HandlePragmaMSPointersToMembers();
374 case tok::annot_pragma_ms_pragma:
375 ProhibitAttributes(Attrs);
376 HandlePragmaMSPragma();
379 case tok::annot_pragma_ms_vtordisp:
380 ProhibitAttributes(Attrs);
381 HandlePragmaMSVtorDisp();
384 case tok::annot_pragma_loop_hint:
385 ProhibitAttributes(Attrs);
386 return ParsePragmaLoopHint(Stmts, Allowed, TrailingElseLoc, Attrs);
388 case tok::annot_pragma_dump:
392 case tok::annot_pragma_attribute:
393 HandlePragmaAttribute();
402 ExpectAndConsume(tok::semi, diag::err_expected_semi_after_stmt, SemiError);
415 ExprStatementTokLoc =
Tok.getLocation();
419 if (
Expr.isInvalid()) {
424 if (
Tok.
is(tok::semi))
426 return Actions.ActOnExprStmtError();
430 Actions.CheckCaseExpression(
Expr.get())) {
433 Diag(OldToken, diag::err_expected_case_before_expression)
437 return ParseCaseStatement(
true,
Expr);
441 ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
442 return Actions.ActOnExprStmt(
Expr, isExprValueDiscarded());
455 assert(
Tok.
is(tok::kw___try) &&
"Expected '__try'");
459 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
464 if (TryBlock.isInvalid())
468 if (
Tok.
is(tok::identifier) &&
469 Tok.getIdentifierInfo() == getSEHExceptKeyword()) {
471 Handler = ParseSEHExceptBlock(Loc);
472 }
else if (
Tok.
is(tok::kw___finally)) {
474 Handler = ParseSEHFinallyBlock(Loc);
479 if(Handler.isInvalid())
482 return Actions.ActOnSEHTryBlock(
false ,
495 raii2(Ident___exception_code,
false),
496 raii3(Ident_GetExceptionCode,
false);
498 if (ExpectAndConsume(tok::l_paren))
505 Ident__exception_info->setIsPoisoned(
false);
506 Ident___exception_info->setIsPoisoned(
false);
507 Ident_GetExceptionInfo->setIsPoisoned(
false);
512 ParseScopeFlags FilterScope(
this,
getCurScope()->getFlags() |
518 Ident__exception_info->setIsPoisoned(
true);
519 Ident___exception_info->setIsPoisoned(
true);
520 Ident_GetExceptionInfo->setIsPoisoned(
true);
526 if (ExpectAndConsume(tok::r_paren))
530 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
534 if(Block.isInvalid())
537 return Actions.ActOnSEHExceptBlock(ExceptLoc, FilterExpr.
get(), Block.get());
547 raii2(Ident___abnormal_termination,
false),
548 raii3(Ident_AbnormalTermination,
false);
551 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
553 ParseScope FinallyScope(
this, 0);
554 Actions.ActOnStartSEHFinallyBlock();
557 if(Block.isInvalid()) {
558 Actions.ActOnAbortSEHFinallyBlock();
562 return Actions.ActOnFinishSEHFinallyBlock(FinallyLoc, Block.get());
572 return Actions.ActOnSEHLeaveStmt(LeaveLoc,
getCurScope());
581 StmtResult Parser::ParseLabeledStatement(ParsedAttributesWithRange &attrs) {
582 assert(
Tok.
is(tok::identifier) &&
Tok.getIdentifierInfo() &&
583 "Not an identifier!");
588 assert(
Tok.
is(tok::colon) &&
"Not a label!");
595 if (
Tok.
is(tok::kw___attribute)) {
596 ParsedAttributesWithRange TempAttrs(AttrFactory);
597 ParseGNUAttributes(TempAttrs);
607 attrs.takeAllFrom(TempAttrs);
608 else if (isDeclarationStatement()) {
614 SubStmt = ParseStatementOrDeclarationAfterAttributes(
615 Stmts, ACK_StatementsOpenMPNonStandalone,
nullptr,
617 if (!TempAttrs.empty() && !SubStmt.isInvalid())
618 SubStmt = Actions.ProcessStmtAttributes(SubStmt.get(), TempAttrs,
621 Diag(Tok, diag::err_expected_after) <<
"__attribute__" << tok::semi;
626 if (!SubStmt.isInvalid() && !SubStmt.isUsable())
627 SubStmt = ParseStatement();
630 if (SubStmt.isInvalid())
631 SubStmt = Actions.ActOnNullStmt(ColonLoc);
633 LabelDecl *LD = Actions.LookupOrCreateLabel(IdentTok.getIdentifierInfo(),
634 IdentTok.getLocation());
635 Actions.ProcessDeclAttributeList(Actions.CurScope, LD, attrs);
638 return Actions.ActOnLabelStmt(IdentTok.getLocation(), LD,
ColonLoc,
648 assert((MissingCase ||
Tok.
is(tok::kw_case)) &&
"Not a case stmt!");
671 Stmt *DeepestParsedCaseStmt =
nullptr;
680 if (
Tok.
is(tok::code_completion)) {
709 Diag(DotDotDotLoc, diag::ext_gnu_case_range);
717 ColonProtection.restore();
723 Diag(ColonLoc, diag::err_expected_after)
724 <<
"'case'" << tok::colon
727 SourceLocation ExpectedLoc = PP.getLocForEndOfToken(PrevTokLocation);
728 Diag(ExpectedLoc, diag::err_expected_after)
729 <<
"'case'" << tok::colon
731 ColonLoc = ExpectedLoc;
735 Actions.ActOnCaseStmt(CaseLoc, LHS, DotDotDotLoc, RHS, ColonLoc);
739 if (Case.isInvalid()) {
740 if (TopLevelCase.isInvalid())
741 return ParseStatement(
nullptr,
747 Stmt *NextDeepest = Case.get();
748 if (TopLevelCase.isInvalid())
751 Actions.ActOnCaseStmtBody(DeepestParsedCaseStmt, Case.get());
752 DeepestParsedCaseStmt = NextDeepest;
756 }
while (
Tok.
is(tok::kw_case));
762 SubStmt = ParseStatement(
nullptr,
770 Diag(AfterColonLoc, diag::err_label_end_of_compound_statement)
777 if (DeepestParsedCaseStmt) {
779 if (SubStmt.isInvalid())
781 Actions.ActOnCaseStmtBody(DeepestParsedCaseStmt, SubStmt.get());
794 assert(
Tok.
is(tok::kw_default) &&
"Not a default stmt!");
801 Diag(ColonLoc, diag::err_expected_after)
802 <<
"'default'" << tok::colon
805 SourceLocation ExpectedLoc = PP.getLocForEndOfToken(PrevTokLocation);
806 Diag(ExpectedLoc, diag::err_expected_after)
807 <<
"'default'" << tok::colon
809 ColonLoc = ExpectedLoc;
815 SubStmt = ParseStatement(
nullptr,
821 Diag(AfterColonLoc, diag::err_label_end_of_compound_statement)
827 if (SubStmt.isInvalid())
828 SubStmt = Actions.ActOnNullStmt(ColonLoc);
830 return Actions.ActOnDefaultStmt(DefaultLoc, ColonLoc,
834 StmtResult Parser::ParseCompoundStatement(
bool isStmtExpr) {
835 return ParseCompoundStatement(isStmtExpr,
861 StmtResult Parser::ParseCompoundStatement(
bool isStmtExpr,
862 unsigned ScopeFlags) {
863 assert(
Tok.
is(tok::l_brace) &&
"Not a compount stmt!");
867 ParseScope CompoundScope(
this, ScopeFlags);
870 return ParseCompoundStatementBody(isStmtExpr);
876 void Parser::ParseCompoundStatementLeadingPragmas() {
877 bool checkForPragmas =
true;
878 while (checkForPragmas) {
879 switch (
Tok.getKind()) {
880 case tok::annot_pragma_vis:
881 HandlePragmaVisibility();
883 case tok::annot_pragma_pack:
886 case tok::annot_pragma_msstruct:
887 HandlePragmaMSStruct();
889 case tok::annot_pragma_align:
892 case tok::annot_pragma_weak:
895 case tok::annot_pragma_weakalias:
896 HandlePragmaWeakAlias();
898 case tok::annot_pragma_redefine_extname:
899 HandlePragmaRedefineExtname();
901 case tok::annot_pragma_opencl_extension:
902 HandlePragmaOpenCLExtension();
904 case tok::annot_pragma_fp_contract:
905 HandlePragmaFPContract();
907 case tok::annot_pragma_fp:
910 case tok::annot_pragma_fenv_access:
911 HandlePragmaFEnvAccess();
913 case tok::annot_pragma_ms_pointers_to_members:
914 HandlePragmaMSPointersToMembers();
916 case tok::annot_pragma_ms_pragma:
917 HandlePragmaMSPragma();
919 case tok::annot_pragma_ms_vtordisp:
920 HandlePragmaMSVtorDisp();
922 case tok::annot_pragma_dump:
926 checkForPragmas =
false;
935 bool Parser::ConsumeNullStmt(StmtVector &Stmts) {
936 if (!
Tok.
is(tok::semi))
942 while (
Tok.
is(tok::semi) && !
Tok.hasLeadingEmptyMacro() &&
943 Tok.getLocation().isValid() && !
Tok.getLocation().isMacroID()) {
944 EndLoc =
Tok.getLocation();
947 StmtResult R = ParseStatementOrDeclaration(Stmts, ACK_Any);
949 Stmts.push_back(R.get());
956 Diag(StartLoc, diag::warn_null_statement)
961 bool Parser::isExprValueDiscarded() {
962 if (Actions.isCurCompoundStmtAStmtExpr()) {
975 StmtResult Parser::ParseCompoundStatementBody(
bool isStmtExpr) {
978 "in compound statement ('{}')");
992 ParseCompoundStatementLeadingPragmas();
998 while (
Tok.
is(tok::kw___label__)) {
1004 Diag(Tok, diag::err_expected) << tok::identifier;
1010 DeclsInGroup.push_back(Actions.LookupOrCreateLabel(II, IdLoc, LabelLoc));
1018 Actions.FinalizeDeclaratorGroup(
getCurScope(), DS, DeclsInGroup);
1019 StmtResult R = Actions.ActOnDeclStmt(Res, LabelLoc,
Tok.getLocation());
1021 ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
1023 Stmts.push_back(R.get());
1026 while (!tryParseMisplacedModuleImport() &&
Tok.
isNot(tok::r_brace) &&
1028 if (
Tok.
is(tok::annot_pragma_unused)) {
1029 HandlePragmaUnused();
1033 if (ConsumeNullStmt(Stmts))
1037 if (
Tok.
isNot(tok::kw___extension__)) {
1038 R = ParseStatementOrDeclaration(Stmts, ACK_Any);
1045 while (
Tok.
is(tok::kw___extension__))
1048 ParsedAttributesWithRange attrs(AttrFactory);
1049 MaybeParseCXX11Attributes(attrs,
nullptr,
1053 if (isDeclarationStatement()) {
1061 R = Actions.ActOnDeclStmt(Res, DeclStart, DeclEnd);
1064 ExprResult Res(ParseExpressionWithLeadingExtension(ExtLoc));
1066 if (Res.isInvalid()) {
1074 ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
1075 R = Actions.ActOnExprStmt(Res, isExprValueDiscarded());
1080 Stmts.push_back(R.get());
1086 if (!T.consumeClose())
1089 CloseLoc = T.getCloseLocation();
1091 return Actions.ActOnCompoundStmt(T.getOpenLocation(), CloseLoc,
1107 bool Parser::ParseParenExprOrCondition(
StmtResult *InitStmt,
1115 Cond = ParseCXXCondition(InitStmt, Loc, CK);
1123 Cond = Actions.ActOnCondition(
getCurScope(), Loc, CondExpr.
get(), CK);
1143 while (
Tok.
is(tok::r_paren)) {
1144 Diag(Tok, diag::err_extraneous_rparen_in_condition)
1161 assert(
Tok.
is(tok::kw_if) &&
"Not an if stmt!");
1164 bool IsConstexpr =
false;
1165 if (
Tok.
is(tok::kw_constexpr)) {
1167 : diag::ext_constexpr_if);
1173 Diag(Tok, diag::err_expected_lparen_after) <<
"if";
1197 if (ParseParenExprOrCondition(&InitStmt, Cond, IfLoc,
1235 ConstexprCondition && !*ConstexprCondition);
1236 ThenStmt = ParseStatement(&InnerStatementTrailingElseLoc);
1247 if (
Tok.
is(tok::kw_else)) {
1248 if (TrailingElseLoc)
1249 *TrailingElseLoc =
Tok.getLocation();
1252 ElseStmtLoc =
Tok.getLocation();
1264 Tok.
is(tok::l_brace));
1269 ConstexprCondition && *ConstexprCondition);
1270 ElseStmt = ParseStatement();
1274 }
else if (
Tok.
is(tok::code_completion)) {
1278 }
else if (InnerStatementTrailingElseLoc.
isValid()) {
1279 Diag(InnerStatementTrailingElseLoc, diag::warn_dangling_else);
1287 if ((ThenStmt.isInvalid() && ElseStmt.isInvalid()) ||
1288 (ThenStmt.isInvalid() && ElseStmt.get() ==
nullptr) ||
1289 (ThenStmt.get() ==
nullptr && ElseStmt.isInvalid())) {
1295 if (ThenStmt.isInvalid())
1296 ThenStmt = Actions.ActOnNullStmt(ThenStmtLoc);
1297 if (ElseStmt.isInvalid())
1298 ElseStmt = Actions.ActOnNullStmt(ElseStmtLoc);
1300 return Actions.ActOnIfStmt(IfLoc, IsConstexpr, InitStmt.get(), Cond,
1301 ThenStmt.
get(), ElseLoc, ElseStmt.get());
1309 assert(
Tok.
is(tok::kw_switch) &&
"Not a switch stmt!");
1313 Diag(Tok, diag::err_expected_lparen_after) <<
"switch";
1335 ParseScope SwitchScope(
this, ScopeFlags);
1340 if (ParseParenExprOrCondition(&InitStmt, Cond, SwitchLoc,
1345 Actions.ActOnStartOfSwitchStmt(SwitchLoc, InitStmt.get(), Cond);
1347 if (Switch.isInvalid()) {
1352 if (
Tok.
is(tok::l_brace)) {
1380 StmtResult Body(ParseStatement(TrailingElseLoc));
1386 return Actions.ActOnFinishSwitchStmt(SwitchLoc, Switch.get(), Body.get());
1394 assert(
Tok.
is(tok::kw_while) &&
"Not a while stmt!");
1399 Diag(Tok, diag::err_expected_lparen_after) <<
"while";
1418 unsigned ScopeFlags;
1424 ParseScope WhileScope(
this, ScopeFlags);
1428 if (ParseParenExprOrCondition(
nullptr, Cond, WhileLoc,
1429 Sema::ConditionKind::Boolean))
1446 StmtResult Body(ParseStatement(TrailingElseLoc));
1452 if (Cond.
isInvalid() || Body.isInvalid())
1455 return Actions.ActOnWhileStmt(WhileLoc, Cond, Body.
get());
1463 assert(
Tok.
is(tok::kw_do) &&
"Not a do stmt!");
1468 unsigned ScopeFlags;
1474 ParseScope DoScope(
this, ScopeFlags);
1494 if (!Body.isInvalid()) {
1495 Diag(Tok, diag::err_expected_while);
1496 Diag(DoLoc, diag::note_matching) <<
"'do'";
1504 Diag(Tok, diag::err_expected_lparen_after) <<
"do/while";
1514 DiagnoseAndSkipCXX11Attributes();
1519 Cond = Actions.CorrectDelayedTyposInExpr(Cond);
1523 if (Cond.
isInvalid() || Body.isInvalid())
1526 return Actions.ActOnDoStmt(DoLoc, Body.get(), WhileLoc, T.getOpenLocation(),
1527 Cond.
get(), T.getCloseLocation());
1530 bool Parser::isForRangeIdentifier() {
1531 assert(
Tok.
is(tok::identifier));
1534 if (Next.is(tok::colon))
1537 if (Next.isOneOf(tok::l_square, tok::kw_alignas)) {
1538 TentativeParsingAction PA(*
this);
1540 SkipCXX11Attributes();
1572 assert(
Tok.
is(tok::kw_for) &&
"Not a for stmt!");
1576 if (
Tok.
is(tok::kw_co_await))
1580 Diag(Tok, diag::err_expected_lparen_after) <<
"for";
1603 unsigned ScopeFlags = 0;
1607 ParseScope ForScope(
this, ScopeFlags);
1614 bool ForEach =
false;
1618 ForRangeInfo ForRangeInfo;
1621 if (
Tok.
is(tok::code_completion)) {
1629 ParsedAttributesWithRange attrs(AttrFactory);
1630 MaybeParseCXX11Attributes(attrs);
1635 if (
Tok.
is(tok::semi)) {
1636 ProhibitAttributes(attrs);
1639 if (!
Tok.hasLeadingEmptyMacro() && !SemiLoc.
isMacroID())
1640 EmptyInitStmtSemiLoc = SemiLoc;
1643 isForRangeIdentifier()) {
1644 ProhibitAttributes(attrs);
1647 MaybeParseCXX11Attributes(attrs);
1650 if (
Tok.
is(tok::l_brace))
1651 ForRangeInfo.RangeExpr = ParseBraceInitializer();
1655 Diag(Loc, diag::err_for_range_identifier)
1660 ForRangeInfo.LoopVar = Actions.ActOnCXXForRangeIdentifier(
1661 getCurScope(), Loc, Name, attrs, attrs.Range.getEnd());
1662 }
else if (isForInitDeclaration()) {
1666 if (!C99orCXXorObjC) {
1667 Diag(Tok, diag::ext_c99_variable_decl_in_for_loop);
1668 Diag(Tok, diag::warn_gcc_variable_decl_in_for_loop);
1672 bool MightBeForRangeStmt =
getLangOpts().CPlusPlus;
1678 MightBeForRangeStmt ? &ForRangeInfo :
nullptr);
1679 FirstPart = Actions.ActOnDeclStmt(DG, DeclStart,
Tok.getLocation());
1680 if (ForRangeInfo.ParsedForRangeDecl()) {
1682 diag::warn_cxx98_compat_for_range : diag::ext_for_range);
1683 ForRangeInfo.LoopVar = FirstPart;
1685 }
else if (
Tok.
is(tok::semi)) {
1687 }
else if ((ForEach = isTokIdentifier_in())) {
1688 Actions.ActOnForEachDeclStmt(DG);
1692 if (
Tok.
is(tok::code_completion)) {
1693 Actions.CodeCompleteObjCForCollection(
getCurScope(), DG);
1699 Diag(Tok, diag::err_expected_semi_for);
1702 ProhibitAttributes(attrs);
1705 ForEach = isTokIdentifier_in();
1710 FirstPart = Actions.ActOnForEachLValueExpr(Value.
get());
1717 bool IsRangeBasedFor =
1719 FirstPart = Actions.ActOnExprStmt(Value, !IsRangeBasedFor);
1723 if (
Tok.
is(tok::semi)) {
1725 }
else if (ForEach) {
1728 if (
Tok.
is(tok::code_completion)) {
1729 Actions.CodeCompleteObjCForCollection(
getCurScope(),
nullptr);
1737 Diag(Tok, diag::err_for_range_expected_decl)
1738 << FirstPart.get()->getSourceRange();
1743 Diag(Tok, diag::err_expected_semi_for);
1747 if (
Tok.
is(tok::semi))
1755 if (!ForEach && !ForRangeInfo.ParsedForRangeDecl() &&
1758 if (
Tok.
is(tok::semi)) {
1760 }
else if (
Tok.
is(tok::r_paren)) {
1766 bool MightBeForRangeStmt = !ForRangeInfo.ParsedForRangeDecl();
1769 ParseCXXCondition(
nullptr, ForLoc, Sema::ConditionKind::Boolean,
1770 MightBeForRangeStmt ? &ForRangeInfo :
nullptr);
1772 if (ForRangeInfo.ParsedForRangeDecl()) {
1773 Diag(FirstPart.get() ? FirstPart.get()->getBeginLoc()
1774 : ForRangeInfo.ColonLoc,
1776 ? diag::warn_cxx17_compat_for_range_init_stmt
1777 : diag::ext_for_range_init_stmt)
1778 << (FirstPart.get() ? FirstPart.get()->getSourceRange()
1780 if (EmptyInitStmtSemiLoc.
isValid()) {
1781 Diag(EmptyInitStmtSemiLoc, diag::warn_empty_init_statement)
1799 if (!ForEach && !ForRangeInfo.ParsedForRangeDecl()) {
1802 Diag(Tok, diag::err_expected_semi_for);
1808 if (
Tok.
is(tok::semi)) {
1816 ThirdPart = Actions.MakeFullDiscardedValueExpr(Third.
get());
1824 if (CoawaitLoc.
isValid() && !ForRangeInfo.ParsedForRangeDecl()) {
1825 Diag(CoawaitLoc, diag::err_for_co_await_not_range_for);
1835 if (ForRangeInfo.ParsedForRangeDecl()) {
1837 Actions.CorrectDelayedTyposInExpr(ForRangeInfo.RangeExpr.get());
1838 ForRangeStmt = Actions.ActOnCXXForRangeStmt(
1839 getCurScope(), ForLoc, CoawaitLoc, FirstPart.get(),
1840 ForRangeInfo.LoopVar.get(), ForRangeInfo.ColonLoc, CorrectedRange.
get(),
1845 }
else if (ForEach) {
1846 ForEachStmt = Actions.ActOnObjCForCollectionStmt(ForLoc,
1849 T.getCloseLocation());
1853 if (
getLangOpts().OpenMP && FirstPart.isUsable()) {
1854 Actions.ActOnOpenMPLoopInitialization(ForLoc, FirstPart.get());
1870 Tok.
is(tok::l_brace));
1880 StmtResult Body(ParseStatement(TrailingElseLoc));
1888 if (Body.isInvalid())
1892 return Actions.FinishObjCForCollectionStmt(ForEachStmt.get(),
1895 if (ForRangeInfo.ParsedForRangeDecl())
1896 return Actions.FinishCXXForRangeStmt(ForRangeStmt.get(), Body.get());
1898 return Actions.ActOnForStmt(ForLoc, T.getOpenLocation(), FirstPart.get(),
1899 SecondPart, ThirdPart, T.getCloseLocation(),
1911 assert(
Tok.
is(tok::kw_goto) &&
"Not a goto stmt!");
1915 if (
Tok.
is(tok::identifier)) {
1916 LabelDecl *LD = Actions.LookupOrCreateLabel(
Tok.getIdentifierInfo(),
1918 Res = Actions.ActOnGotoStmt(GotoLoc,
Tok.getLocation(), LD);
1920 }
else if (
Tok.
is(tok::star)) {
1922 Diag(Tok, diag::ext_gnu_indirect_goto);
1925 if (R.isInvalid()) {
1929 Res = Actions.ActOnIndirectGotoStmt(GotoLoc, StarLoc, R.get());
1931 Diag(Tok, diag::err_expected) << tok::identifier;
1944 StmtResult Parser::ParseContinueStatement() {
1946 return Actions.ActOnContinueStmt(ContinueLoc,
getCurScope());
1957 return Actions.ActOnBreakStmt(BreakLoc,
getCurScope());
1967 assert((
Tok.
is(tok::kw_return) ||
Tok.
is(tok::kw_co_return)) &&
1968 "Not a return stmt!");
1969 bool IsCoreturn =
Tok.
is(tok::kw_co_return);
1975 if (
Tok.
is(tok::code_completion) && !IsCoreturn) {
1982 R = ParseInitializer();
1986 ? diag::warn_cxx98_compat_generalized_initializer_lists
1987 : diag::ext_generalized_initializer_lists)
1988 << R.
get()->getSourceRange();
1997 return Actions.ActOnCoreturnStmt(
getCurScope(), ReturnLoc, R.
get());
1998 return Actions.ActOnReturnStmt(ReturnLoc, R.
get(),
getCurScope());
2001 StmtResult Parser::ParsePragmaLoopHint(StmtVector &Stmts,
2002 AllowedConstructsKind Allowed,
2004 ParsedAttributesWithRange &Attrs) {
2006 ParsedAttributesWithRange TempAttrs(AttrFactory);
2009 while (
Tok.
is(tok::annot_pragma_loop_hint)) {
2011 if (!HandlePragmaLoopHint(Hint))
2022 MaybeParseCXX11Attributes(Attrs);
2024 StmtResult S = ParseStatementOrDeclarationAfterAttributes(
2025 Stmts, Allowed, TrailingElseLoc, Attrs);
2027 Attrs.takeAllFrom(TempAttrs);
2031 Decl *Parser::ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope) {
2032 assert(
Tok.
is(tok::l_brace));
2036 "parsing function body");
2040 getLangOpts().CPlusPlus && Decl && isa<CXXMethodDecl>(Decl);
2042 PragmaStackSentinel(Actions,
"InternalPragmaState", IsCXXMethod);
2047 StmtResult FnBody(ParseCompoundStatementBody());
2050 if (FnBody.isInvalid()) {
2052 FnBody = Actions.ActOnCompoundStmt(LBraceLoc, LBraceLoc,
None,
false);
2056 return Actions.ActOnFinishFunctionBody(Decl, FnBody.get());
2064 Decl *Parser::ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope) {
2065 assert(
Tok.
is(tok::kw_try) &&
"Expected 'try'");
2069 "parsing function try block");
2072 if (
Tok.
is(tok::colon))
2073 ParseConstructorInitializer(Decl);
2075 Actions.ActOnDefaultCtorInitializers(Decl);
2079 getLangOpts().CPlusPlus && Decl && isa<CXXMethodDecl>(Decl);
2081 PragmaStackSentinel(Actions,
"InternalPragmaState", IsCXXMethod);
2084 StmtResult FnBody(ParseCXXTryBlockCommon(TryLoc,
true));
2087 if (FnBody.isInvalid()) {
2089 FnBody = Actions.ActOnCompoundStmt(LBraceLoc, LBraceLoc,
None,
false);
2093 return Actions.ActOnFinishFunctionBody(Decl, FnBody.get());
2096 bool Parser::trySkippingFunctionBody() {
2097 assert(SkipFunctionBodies &&
2098 "Should only be called when SkipFunctionBodies is enabled");
2099 if (!PP.isCodeCompletionEnabled()) {
2106 TentativeParsingAction PA(*
this);
2107 bool IsTryCatch =
Tok.
is(tok::kw_try);
2109 bool ErrorInPrologue = ConsumeAndStoreFunctionPrologue(Toks);
2110 if (llvm::any_of(Toks, [](
const Token &Tok) {
2111 return Tok.
is(tok::code_completion);
2116 if (ErrorInPrologue) {
2125 while (IsTryCatch && Tok.
is(tok::kw_catch)) {
2142 assert(Tok.
is(tok::kw_try) &&
"Expected 'try'");
2145 return ParseCXXTryBlockCommon(TryLoc);
2165 if (Tok.
isNot(tok::l_brace))
2166 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
2172 if (TryBlock.isInvalid())
2177 if ((Tok.
is(tok::identifier) &&
2179 Tok.
is(tok::kw___finally)) {
2184 Handler = ParseSEHExceptBlock(Loc);
2188 Handler = ParseSEHFinallyBlock(Loc);
2190 if(Handler.isInvalid())
2193 return Actions.ActOnSEHTryBlock(
true ,
2199 StmtVector Handlers;
2203 DiagnoseAndSkipCXX11Attributes();
2205 if (Tok.
isNot(tok::kw_catch))
2207 while (Tok.
is(tok::kw_catch)) {
2208 StmtResult Handler(ParseCXXCatchBlock(FnTry));
2209 if (!Handler.isInvalid())
2210 Handlers.push_back(Handler.get());
2214 if (Handlers.empty())
2217 return Actions.ActOnCXXTryBlock(TryLoc, TryBlock.get(), Handlers);
2231 StmtResult Parser::ParseCXXCatchBlock(
bool FnCatch) {
2232 assert(Tok.
is(tok::kw_catch) &&
"Expected 'catch'");
2237 if (T.expectAndConsume())
2248 Decl *ExceptionDecl =
nullptr;
2249 if (Tok.
isNot(tok::ellipsis)) {
2250 ParsedAttributesWithRange Attributes(AttrFactory);
2251 MaybeParseCXX11Attributes(Attributes);
2254 DS.takeAttributesFrom(Attributes);
2256 if (ParseCXXTypeSpecifierSeq(DS))
2260 ParseDeclarator(ExDecl);
2261 ExceptionDecl = Actions.ActOnExceptionDeclarator(
getCurScope(), ExDecl);
2266 if (T.getCloseLocation().isInvalid())
2269 if (Tok.
isNot(tok::l_brace))
2270 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
2274 if (Block.isInvalid())
2277 return Actions.ActOnCXXCatchBlock(CatchLoc, ExceptionDecl, Block.get());
2280 void Parser::ParseMicrosoftIfExistsStatement(StmtVector &Stmts) {
2281 IfExistsCondition
Result;
2282 if (ParseMicrosoftIfExistsCondition(Result))
2289 if (Result.Behavior == IEB_Dependent) {
2290 if (!Tok.
is(tok::l_brace)) {
2291 Diag(Tok, diag::err_expected) << tok::l_brace;
2295 StmtResult Compound = ParseCompoundStatement();
2296 if (Compound.isInvalid())
2299 StmtResult DepResult = Actions.ActOnMSDependentExistsStmt(Result.KeywordLoc,
2304 if (DepResult.isUsable())
2305 Stmts.push_back(DepResult.get());
2310 if (Braces.consumeOpen()) {
2311 Diag(Tok, diag::err_expected) << tok::l_brace;
2315 switch (Result.Behavior) {
2321 llvm_unreachable(
"Dependent case handled above");
2329 while (Tok.
isNot(tok::r_brace)) {
2330 StmtResult R = ParseStatementOrDeclaration(Stmts, ACK_Any);
2332 Stmts.push_back(R.get());
2334 Braces.consumeClose();
2338 MaybeParseGNUAttributes(Attrs);
2343 if (Attrs.
begin()->getKind() != ParsedAttr::AT_OpenCLUnrollHint)
2346 if (!(Tok.
is(tok::kw_for) || Tok.
is(tok::kw_while) || Tok.
is(tok::kw_do))) {
2347 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...
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.
A trivial tuple used to represent a source range.
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.