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);
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)
965 StmtResult Parser::ParseCompoundStatementBody(
bool isStmtExpr) {
968 "in compound statement ('{}')");
982 ParseCompoundStatementLeadingPragmas();
988 while (
Tok.
is(tok::kw___label__)) {
994 Diag(Tok, diag::err_expected) << tok::identifier;
1000 DeclsInGroup.push_back(Actions.LookupOrCreateLabel(II, IdLoc, LabelLoc));
1008 Actions.FinalizeDeclaratorGroup(
getCurScope(), DS, DeclsInGroup);
1009 StmtResult R = Actions.ActOnDeclStmt(Res, LabelLoc,
Tok.getLocation());
1011 ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
1013 Stmts.push_back(R.get());
1016 while (!tryParseMisplacedModuleImport() &&
Tok.
isNot(tok::r_brace) &&
1018 if (
Tok.
is(tok::annot_pragma_unused)) {
1019 HandlePragmaUnused();
1023 if (ConsumeNullStmt(Stmts))
1027 if (
Tok.
isNot(tok::kw___extension__)) {
1028 R = ParseStatementOrDeclaration(Stmts, ACK_Any);
1035 while (
Tok.
is(tok::kw___extension__))
1038 ParsedAttributesWithRange attrs(AttrFactory);
1039 MaybeParseCXX11Attributes(attrs,
nullptr,
1043 if (isDeclarationStatement()) {
1051 R = Actions.ActOnDeclStmt(Res, DeclStart, DeclEnd);
1054 ExprResult Res(ParseExpressionWithLeadingExtension(ExtLoc));
1056 if (Res.isInvalid()) {
1064 ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
1065 R = Actions.ActOnExprStmt(Res);
1070 Stmts.push_back(R.get());
1076 if (!T.consumeClose())
1079 CloseLoc = T.getCloseLocation();
1081 return Actions.ActOnCompoundStmt(T.getOpenLocation(), CloseLoc,
1097 bool Parser::ParseParenExprOrCondition(
StmtResult *InitStmt,
1105 Cond = ParseCXXCondition(InitStmt, Loc, CK);
1113 Cond = Actions.ActOnCondition(
getCurScope(), Loc, CondExpr.
get(), CK);
1133 while (
Tok.
is(tok::r_paren)) {
1134 Diag(Tok, diag::err_extraneous_rparen_in_condition)
1151 assert(
Tok.
is(tok::kw_if) &&
"Not an if stmt!");
1154 bool IsConstexpr =
false;
1155 if (
Tok.
is(tok::kw_constexpr)) {
1157 : diag::ext_constexpr_if);
1163 Diag(Tok, diag::err_expected_lparen_after) <<
"if";
1187 if (ParseParenExprOrCondition(&InitStmt, Cond, IfLoc,
1225 ConstexprCondition && !*ConstexprCondition);
1226 ThenStmt = ParseStatement(&InnerStatementTrailingElseLoc);
1237 if (
Tok.
is(tok::kw_else)) {
1238 if (TrailingElseLoc)
1239 *TrailingElseLoc =
Tok.getLocation();
1242 ElseStmtLoc =
Tok.getLocation();
1254 Tok.
is(tok::l_brace));
1259 ConstexprCondition && *ConstexprCondition);
1260 ElseStmt = ParseStatement();
1264 }
else if (
Tok.
is(tok::code_completion)) {
1268 }
else if (InnerStatementTrailingElseLoc.
isValid()) {
1269 Diag(InnerStatementTrailingElseLoc, diag::warn_dangling_else);
1277 if ((ThenStmt.isInvalid() && ElseStmt.isInvalid()) ||
1278 (ThenStmt.isInvalid() && ElseStmt.get() ==
nullptr) ||
1279 (ThenStmt.get() ==
nullptr && ElseStmt.isInvalid())) {
1285 if (ThenStmt.isInvalid())
1286 ThenStmt = Actions.ActOnNullStmt(ThenStmtLoc);
1287 if (ElseStmt.isInvalid())
1288 ElseStmt = Actions.ActOnNullStmt(ElseStmtLoc);
1290 return Actions.ActOnIfStmt(IfLoc, IsConstexpr, InitStmt.get(), Cond,
1291 ThenStmt.
get(), ElseLoc, ElseStmt.get());
1299 assert(
Tok.
is(tok::kw_switch) &&
"Not a switch stmt!");
1303 Diag(Tok, diag::err_expected_lparen_after) <<
"switch";
1325 ParseScope SwitchScope(
this, ScopeFlags);
1330 if (ParseParenExprOrCondition(&InitStmt, Cond, SwitchLoc,
1335 Actions.ActOnStartOfSwitchStmt(SwitchLoc, InitStmt.get(), Cond);
1337 if (Switch.isInvalid()) {
1342 if (
Tok.
is(tok::l_brace)) {
1370 StmtResult Body(ParseStatement(TrailingElseLoc));
1376 return Actions.ActOnFinishSwitchStmt(SwitchLoc, Switch.get(), Body.get());
1384 assert(
Tok.
is(tok::kw_while) &&
"Not a while stmt!");
1389 Diag(Tok, diag::err_expected_lparen_after) <<
"while";
1408 unsigned ScopeFlags;
1414 ParseScope WhileScope(
this, ScopeFlags);
1418 if (ParseParenExprOrCondition(
nullptr, Cond, WhileLoc,
1419 Sema::ConditionKind::Boolean))
1436 StmtResult Body(ParseStatement(TrailingElseLoc));
1442 if (Cond.
isInvalid() || Body.isInvalid())
1445 return Actions.ActOnWhileStmt(WhileLoc, Cond, Body.
get());
1453 assert(
Tok.
is(tok::kw_do) &&
"Not a do stmt!");
1458 unsigned ScopeFlags;
1464 ParseScope DoScope(
this, ScopeFlags);
1484 if (!Body.isInvalid()) {
1485 Diag(Tok, diag::err_expected_while);
1486 Diag(DoLoc, diag::note_matching) <<
"'do'";
1494 Diag(Tok, diag::err_expected_lparen_after) <<
"do/while";
1504 DiagnoseAndSkipCXX11Attributes();
1509 Cond = Actions.CorrectDelayedTyposInExpr(Cond);
1513 if (Cond.
isInvalid() || Body.isInvalid())
1516 return Actions.ActOnDoStmt(DoLoc, Body.get(), WhileLoc, T.getOpenLocation(),
1517 Cond.
get(), T.getCloseLocation());
1520 bool Parser::isForRangeIdentifier() {
1521 assert(
Tok.
is(tok::identifier));
1524 if (Next.is(tok::colon))
1527 if (Next.isOneOf(tok::l_square, tok::kw_alignas)) {
1528 TentativeParsingAction PA(*
this);
1530 SkipCXX11Attributes();
1562 assert(
Tok.
is(tok::kw_for) &&
"Not a for stmt!");
1566 if (
Tok.
is(tok::kw_co_await))
1570 Diag(Tok, diag::err_expected_lparen_after) <<
"for";
1593 unsigned ScopeFlags = 0;
1597 ParseScope ForScope(
this, ScopeFlags);
1604 bool ForEach =
false;
1608 ForRangeInfo ForRangeInfo;
1611 if (
Tok.
is(tok::code_completion)) {
1619 ParsedAttributesWithRange attrs(AttrFactory);
1620 MaybeParseCXX11Attributes(attrs);
1625 if (
Tok.
is(tok::semi)) {
1626 ProhibitAttributes(attrs);
1629 if (!
Tok.hasLeadingEmptyMacro() && !SemiLoc.
isMacroID())
1630 EmptyInitStmtSemiLoc = SemiLoc;
1633 isForRangeIdentifier()) {
1634 ProhibitAttributes(attrs);
1637 MaybeParseCXX11Attributes(attrs);
1640 if (
Tok.
is(tok::l_brace))
1641 ForRangeInfo.RangeExpr = ParseBraceInitializer();
1645 Diag(Loc, diag::err_for_range_identifier)
1650 ForRangeInfo.LoopVar = Actions.ActOnCXXForRangeIdentifier(
1651 getCurScope(), Loc, Name, attrs, attrs.Range.getEnd());
1652 }
else if (isForInitDeclaration()) {
1656 if (!C99orCXXorObjC) {
1657 Diag(Tok, diag::ext_c99_variable_decl_in_for_loop);
1658 Diag(Tok, diag::warn_gcc_variable_decl_in_for_loop);
1662 bool MightBeForRangeStmt =
getLangOpts().CPlusPlus;
1668 MightBeForRangeStmt ? &ForRangeInfo :
nullptr);
1669 FirstPart = Actions.ActOnDeclStmt(DG, DeclStart,
Tok.getLocation());
1670 if (ForRangeInfo.ParsedForRangeDecl()) {
1672 diag::warn_cxx98_compat_for_range : diag::ext_for_range);
1673 ForRangeInfo.LoopVar = FirstPart;
1675 }
else if (
Tok.
is(tok::semi)) {
1677 }
else if ((ForEach = isTokIdentifier_in())) {
1678 Actions.ActOnForEachDeclStmt(DG);
1682 if (
Tok.
is(tok::code_completion)) {
1683 Actions.CodeCompleteObjCForCollection(
getCurScope(), DG);
1689 Diag(Tok, diag::err_expected_semi_for);
1692 ProhibitAttributes(attrs);
1695 ForEach = isTokIdentifier_in();
1700 FirstPart = Actions.ActOnForEachLValueExpr(Value.
get());
1702 FirstPart = Actions.ActOnExprStmt(Value);
1705 if (
Tok.
is(tok::semi)) {
1707 }
else if (ForEach) {
1710 if (
Tok.
is(tok::code_completion)) {
1711 Actions.CodeCompleteObjCForCollection(
getCurScope(),
nullptr);
1719 Diag(Tok, diag::err_for_range_expected_decl)
1720 << FirstPart.get()->getSourceRange();
1725 Diag(Tok, diag::err_expected_semi_for);
1729 if (
Tok.
is(tok::semi))
1737 if (!ForEach && !ForRangeInfo.ParsedForRangeDecl() &&
1740 if (
Tok.
is(tok::semi)) {
1742 }
else if (
Tok.
is(tok::r_paren)) {
1748 bool MightBeForRangeStmt = !ForRangeInfo.ParsedForRangeDecl();
1751 ParseCXXCondition(
nullptr, ForLoc, Sema::ConditionKind::Boolean,
1752 MightBeForRangeStmt ? &ForRangeInfo :
nullptr);
1754 if (ForRangeInfo.ParsedForRangeDecl()) {
1755 Diag(FirstPart.get() ? FirstPart.get()->getBeginLoc()
1756 : ForRangeInfo.ColonLoc,
1758 ? diag::warn_cxx17_compat_for_range_init_stmt
1759 : diag::ext_for_range_init_stmt)
1760 << (FirstPart.get() ? FirstPart.get()->getSourceRange()
1762 if (EmptyInitStmtSemiLoc.
isValid()) {
1763 Diag(EmptyInitStmtSemiLoc, diag::warn_empty_init_statement)
1781 if (!ForEach && !ForRangeInfo.ParsedForRangeDecl()) {
1784 Diag(Tok, diag::err_expected_semi_for);
1790 if (
Tok.
is(tok::semi)) {
1798 ThirdPart = Actions.MakeFullDiscardedValueExpr(Third.
get());
1806 if (CoawaitLoc.
isValid() && !ForRangeInfo.ParsedForRangeDecl()) {
1807 Diag(CoawaitLoc, diag::err_for_co_await_not_range_for);
1817 if (ForRangeInfo.ParsedForRangeDecl()) {
1819 Actions.CorrectDelayedTyposInExpr(ForRangeInfo.RangeExpr.get());
1820 ForRangeStmt = Actions.ActOnCXXForRangeStmt(
1821 getCurScope(), ForLoc, CoawaitLoc, FirstPart.get(),
1822 ForRangeInfo.LoopVar.get(), ForRangeInfo.ColonLoc, CorrectedRange.
get(),
1827 }
else if (ForEach) {
1828 ForEachStmt = Actions.ActOnObjCForCollectionStmt(ForLoc,
1831 T.getCloseLocation());
1835 if (
getLangOpts().OpenMP && FirstPart.isUsable()) {
1836 Actions.ActOnOpenMPLoopInitialization(ForLoc, FirstPart.get());
1852 Tok.
is(tok::l_brace));
1862 StmtResult Body(ParseStatement(TrailingElseLoc));
1870 if (Body.isInvalid())
1874 return Actions.FinishObjCForCollectionStmt(ForEachStmt.get(),
1877 if (ForRangeInfo.ParsedForRangeDecl())
1878 return Actions.FinishCXXForRangeStmt(ForRangeStmt.get(), Body.get());
1880 return Actions.ActOnForStmt(ForLoc, T.getOpenLocation(), FirstPart.get(),
1881 SecondPart, ThirdPart, T.getCloseLocation(),
1893 assert(
Tok.
is(tok::kw_goto) &&
"Not a goto stmt!");
1897 if (
Tok.
is(tok::identifier)) {
1898 LabelDecl *LD = Actions.LookupOrCreateLabel(
Tok.getIdentifierInfo(),
1900 Res = Actions.ActOnGotoStmt(GotoLoc,
Tok.getLocation(), LD);
1902 }
else if (
Tok.
is(tok::star)) {
1904 Diag(Tok, diag::ext_gnu_indirect_goto);
1907 if (R.isInvalid()) {
1911 Res = Actions.ActOnIndirectGotoStmt(GotoLoc, StarLoc, R.get());
1913 Diag(Tok, diag::err_expected) << tok::identifier;
1926 StmtResult Parser::ParseContinueStatement() {
1928 return Actions.ActOnContinueStmt(ContinueLoc,
getCurScope());
1939 return Actions.ActOnBreakStmt(BreakLoc,
getCurScope());
1949 assert((
Tok.
is(tok::kw_return) ||
Tok.
is(tok::kw_co_return)) &&
1950 "Not a return stmt!");
1951 bool IsCoreturn =
Tok.
is(tok::kw_co_return);
1957 if (
Tok.
is(tok::code_completion) && !IsCoreturn) {
1964 R = ParseInitializer();
1968 ? diag::warn_cxx98_compat_generalized_initializer_lists
1969 : diag::ext_generalized_initializer_lists)
1970 << R.
get()->getSourceRange();
1979 return Actions.ActOnCoreturnStmt(
getCurScope(), ReturnLoc, R.
get());
1980 return Actions.ActOnReturnStmt(ReturnLoc, R.
get(),
getCurScope());
1983 StmtResult Parser::ParsePragmaLoopHint(StmtVector &Stmts,
1984 AllowedConstructsKind Allowed,
1986 ParsedAttributesWithRange &Attrs) {
1988 ParsedAttributesWithRange TempAttrs(AttrFactory);
1991 while (
Tok.
is(tok::annot_pragma_loop_hint)) {
1993 if (!HandlePragmaLoopHint(Hint))
2004 MaybeParseCXX11Attributes(Attrs);
2006 StmtResult S = ParseStatementOrDeclarationAfterAttributes(
2007 Stmts, Allowed, TrailingElseLoc, Attrs);
2009 Attrs.takeAllFrom(TempAttrs);
2013 Decl *Parser::ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope) {
2014 assert(
Tok.
is(tok::l_brace));
2018 "parsing function body");
2022 getLangOpts().CPlusPlus && Decl && isa<CXXMethodDecl>(Decl);
2024 PragmaStackSentinel(Actions,
"InternalPragmaState", IsCXXMethod);
2029 StmtResult FnBody(ParseCompoundStatementBody());
2032 if (FnBody.isInvalid()) {
2034 FnBody = Actions.ActOnCompoundStmt(LBraceLoc, LBraceLoc,
None,
false);
2038 return Actions.ActOnFinishFunctionBody(Decl, FnBody.get());
2046 Decl *Parser::ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope) {
2047 assert(
Tok.
is(tok::kw_try) &&
"Expected 'try'");
2051 "parsing function try block");
2054 if (
Tok.
is(tok::colon))
2055 ParseConstructorInitializer(Decl);
2057 Actions.ActOnDefaultCtorInitializers(Decl);
2061 getLangOpts().CPlusPlus && Decl && isa<CXXMethodDecl>(Decl);
2063 PragmaStackSentinel(Actions,
"InternalPragmaState", IsCXXMethod);
2066 StmtResult FnBody(ParseCXXTryBlockCommon(TryLoc,
true));
2069 if (FnBody.isInvalid()) {
2071 FnBody = Actions.ActOnCompoundStmt(LBraceLoc, LBraceLoc,
None,
false);
2075 return Actions.ActOnFinishFunctionBody(Decl, FnBody.get());
2078 bool Parser::trySkippingFunctionBody() {
2079 assert(SkipFunctionBodies &&
2080 "Should only be called when SkipFunctionBodies is enabled");
2081 if (!PP.isCodeCompletionEnabled()) {
2088 TentativeParsingAction PA(*
this);
2089 bool IsTryCatch =
Tok.
is(tok::kw_try);
2091 bool ErrorInPrologue = ConsumeAndStoreFunctionPrologue(Toks);
2092 if (llvm::any_of(Toks, [](
const Token &Tok) {
2093 return Tok.
is(tok::code_completion);
2098 if (ErrorInPrologue) {
2107 while (IsTryCatch && Tok.
is(tok::kw_catch)) {
2124 assert(Tok.
is(tok::kw_try) &&
"Expected 'try'");
2127 return ParseCXXTryBlockCommon(TryLoc);
2147 if (Tok.
isNot(tok::l_brace))
2148 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
2154 if (TryBlock.isInvalid())
2159 if ((Tok.
is(tok::identifier) &&
2161 Tok.
is(tok::kw___finally)) {
2166 Handler = ParseSEHExceptBlock(Loc);
2170 Handler = ParseSEHFinallyBlock(Loc);
2172 if(Handler.isInvalid())
2175 return Actions.ActOnSEHTryBlock(
true ,
2181 StmtVector Handlers;
2185 DiagnoseAndSkipCXX11Attributes();
2187 if (Tok.
isNot(tok::kw_catch))
2189 while (Tok.
is(tok::kw_catch)) {
2190 StmtResult Handler(ParseCXXCatchBlock(FnTry));
2191 if (!Handler.isInvalid())
2192 Handlers.push_back(Handler.get());
2196 if (Handlers.empty())
2199 return Actions.ActOnCXXTryBlock(TryLoc, TryBlock.get(), Handlers);
2213 StmtResult Parser::ParseCXXCatchBlock(
bool FnCatch) {
2214 assert(Tok.
is(tok::kw_catch) &&
"Expected 'catch'");
2219 if (T.expectAndConsume())
2230 Decl *ExceptionDecl =
nullptr;
2231 if (Tok.
isNot(tok::ellipsis)) {
2232 ParsedAttributesWithRange Attributes(AttrFactory);
2233 MaybeParseCXX11Attributes(Attributes);
2236 DS.takeAttributesFrom(Attributes);
2238 if (ParseCXXTypeSpecifierSeq(DS))
2242 ParseDeclarator(ExDecl);
2243 ExceptionDecl = Actions.ActOnExceptionDeclarator(
getCurScope(), ExDecl);
2248 if (T.getCloseLocation().isInvalid())
2251 if (Tok.
isNot(tok::l_brace))
2252 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
2256 if (Block.isInvalid())
2259 return Actions.ActOnCXXCatchBlock(CatchLoc, ExceptionDecl, Block.get());
2262 void Parser::ParseMicrosoftIfExistsStatement(StmtVector &Stmts) {
2263 IfExistsCondition
Result;
2264 if (ParseMicrosoftIfExistsCondition(Result))
2271 if (Result.Behavior == IEB_Dependent) {
2272 if (!Tok.
is(tok::l_brace)) {
2273 Diag(Tok, diag::err_expected) << tok::l_brace;
2277 StmtResult Compound = ParseCompoundStatement();
2278 if (Compound.isInvalid())
2281 StmtResult DepResult = Actions.ActOnMSDependentExistsStmt(Result.KeywordLoc,
2286 if (DepResult.isUsable())
2287 Stmts.push_back(DepResult.get());
2292 if (Braces.consumeOpen()) {
2293 Diag(Tok, diag::err_expected) << tok::l_brace;
2297 switch (Result.Behavior) {
2303 llvm_unreachable(
"Dependent case handled above");
2311 while (Tok.
isNot(tok::r_brace)) {
2312 StmtResult R = ParseStatementOrDeclaration(Stmts, ACK_Any);
2314 Stmts.push_back(R.get());
2316 Braces.consumeClose();
2320 MaybeParseGNUAttributes(Attrs);
2325 if (Attrs.
begin()->getKind() != ParsedAttr::AT_OpenCLUnrollHint)
2328 if (!(Tok.
is(tok::kw_for) || Tok.
is(tok::kw_while) || Tok.
is(tok::kw_do))) {
2329 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.