29#include "llvm/ADT/STLExtras.h"
41 ParsedStmtContext StmtCtx) {
48 Res = ParseStatementOrDeclaration(Stmts, StmtCtx, TrailingElseLoc);
104Parser::ParseStatementOrDeclaration(StmtVector &Stmts,
105 ParsedStmtContext StmtCtx,
116 MaybeParseCXX11Attributes(CXX11Attrs,
true);
119 MaybeParseGNUAttributes(GNUOrMSAttrs);
122 MaybeParseMicrosoftAttributes(GNUOrMSAttrs);
124 StmtResult Res = ParseStatementOrDeclarationAfterAttributes(
125 Stmts, StmtCtx, TrailingElseLoc, CXX11Attrs, GNUOrMSAttrs);
126 MaybeDestroyTemplateIds();
134 "attributes on empty statement");
145 StatementFilterCCC(
Token nextTok) : NextToken(nextTok) {
146 WantTypeSpecifiers = nextTok.
isOneOf(tok::l_paren, tok::less, tok::l_square,
147 tok::identifier, tok::star, tok::amp);
148 WantExpressionKeywords =
149 nextTok.
isOneOf(tok::l_paren, tok::identifier, tok::arrow, tok::period);
150 WantRemainingKeywords =
151 nextTok.
isOneOf(tok::l_paren, tok::semi, tok::identifier, tok::l_brace);
152 WantCXXNamedCasts =
false;
155 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
158 if (NextToken.is(tok::equal))
160 if (NextToken.is(tok::period) &&
166 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
167 return std::make_unique<StatementFilterCCC>(*
this);
175StmtResult Parser::ParseStatementOrDeclarationAfterAttributes(
176 StmtVector &Stmts, ParsedStmtContext StmtCtx,
179 const char *SemiError =
nullptr;
193 return ParseObjCAtStatement(AtLoc, StmtCtx);
196 case tok::code_completion:
202 case tok::identifier:
205 if (Next.is(tok::colon)) {
213 return ParseLabeledStatement(Attrs, StmtCtx);
218 if (Next.isNot(tok::coloncolon)) {
221 StatementFilterCCC CCC(Next);
222 if (TryAnnotateName(&CCC) == ANK_Error) {
226 if (Tok.
is(tok::semi))
232 if (Tok.
isNot(tok::identifier))
241 bool HaveAttrs = !CXX11Attrs.
empty() || !GNUAttrs.
empty();
243 bool AllAttrsAreStmtAttrs = llvm::all_of(CXX11Attrs, IsStmtAttr) &&
244 llvm::all_of(GNUAttrs, IsStmtAttr);
251 (StmtCtx & ParsedStmtContext::AllowDeclarationsInC) !=
252 ParsedStmtContext()) &&
253 ((GNUAttributeLoc.
isValid() && !(HaveAttrs && AllAttrsAreStmtAttrs)) ||
254 isDeclarationStatement())) {
257 if (GNUAttributeLoc.
isValid()) {
258 DeclStart = GNUAttributeLoc;
260 GNUAttrs, &GNUAttributeLoc);
276 if (Tok.
is(tok::r_brace)) {
277 Diag(Tok, diag::err_expected_statement);
282#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
283#include "clang/Basic/TransformTypeTraits.def"
286 Diag(Tok, diag::ext_keyword_as_ident)
288 goto ParseIdentifier;
292 return ParseExprStatement(StmtCtx);
296 case tok::kw___attribute: {
298 ParseGNUAttributes(GNUAttrs);
302 case tok::kw_template: {
307 getAccessSpecifierIfPresent());
312 return ParseCaseStatement(StmtCtx);
313 case tok::kw_default:
314 return ParseDefaultStatement(StmtCtx);
317 return ParseCompoundStatement();
324 return ParseIfStatement(TrailingElseLoc);
326 return ParseSwitchStatement(TrailingElseLoc);
329 return ParseWhileStatement(TrailingElseLoc);
331 Res = ParseDoStatement();
332 SemiError =
"do/while";
335 return ParseForStatement(TrailingElseLoc);
338 Res = ParseGotoStatement();
341 case tok::kw_continue:
342 Res = ParseContinueStatement();
343 SemiError =
"continue";
346 Res = ParseBreakStatement();
350 Res = ParseReturnStatement();
351 SemiError =
"return";
353 case tok::kw_co_return:
354 Res = ParseReturnStatement();
355 SemiError =
"co_return";
362 (AL.isRegularKeywordAttribute()
363 ?
Diag(AL.getRange().getBegin(), diag::err_keyword_not_allowed)
364 :
Diag(AL.
getRange().getBegin(), diag::warn_attribute_ignored))
368 ProhibitAttributes(GNUAttrs);
370 Res = ParseAsmStatement(msAsm);
371 if (msAsm)
return Res;
376 case tok::kw___if_exists:
377 case tok::kw___if_not_exists:
378 ProhibitAttributes(CXX11Attrs);
379 ProhibitAttributes(GNUAttrs);
380 ParseMicrosoftIfExistsStatement(Stmts);
386 return ParseCXXTryBlock();
389 ProhibitAttributes(CXX11Attrs);
390 ProhibitAttributes(GNUAttrs);
391 return ParseSEHTryBlock();
393 case tok::kw___leave:
394 Res = ParseSEHLeaveStatement();
395 SemiError =
"__leave";
398 case tok::annot_pragma_vis:
399 ProhibitAttributes(CXX11Attrs);
400 ProhibitAttributes(GNUAttrs);
401 HandlePragmaVisibility();
404 case tok::annot_pragma_pack:
405 ProhibitAttributes(CXX11Attrs);
406 ProhibitAttributes(GNUAttrs);
410 case tok::annot_pragma_msstruct:
411 ProhibitAttributes(CXX11Attrs);
412 ProhibitAttributes(GNUAttrs);
413 HandlePragmaMSStruct();
416 case tok::annot_pragma_align:
417 ProhibitAttributes(CXX11Attrs);
418 ProhibitAttributes(GNUAttrs);
422 case tok::annot_pragma_weak:
423 ProhibitAttributes(CXX11Attrs);
424 ProhibitAttributes(GNUAttrs);
428 case tok::annot_pragma_weakalias:
429 ProhibitAttributes(CXX11Attrs);
430 ProhibitAttributes(GNUAttrs);
431 HandlePragmaWeakAlias();
434 case tok::annot_pragma_redefine_extname:
435 ProhibitAttributes(CXX11Attrs);
436 ProhibitAttributes(GNUAttrs);
437 HandlePragmaRedefineExtname();
440 case tok::annot_pragma_fp_contract:
441 ProhibitAttributes(CXX11Attrs);
442 ProhibitAttributes(GNUAttrs);
443 Diag(Tok, diag::err_pragma_file_or_compound_scope) <<
"fp_contract";
444 ConsumeAnnotationToken();
447 case tok::annot_pragma_fp:
448 ProhibitAttributes(CXX11Attrs);
449 ProhibitAttributes(GNUAttrs);
450 Diag(Tok, diag::err_pragma_file_or_compound_scope) <<
"clang fp";
451 ConsumeAnnotationToken();
454 case tok::annot_pragma_fenv_access:
455 case tok::annot_pragma_fenv_access_ms:
456 ProhibitAttributes(CXX11Attrs);
457 ProhibitAttributes(GNUAttrs);
458 Diag(Tok, diag::err_pragma_file_or_compound_scope)
459 << (
Kind == tok::annot_pragma_fenv_access ?
"STDC FENV_ACCESS"
461 ConsumeAnnotationToken();
464 case tok::annot_pragma_fenv_round:
465 ProhibitAttributes(CXX11Attrs);
466 ProhibitAttributes(GNUAttrs);
467 Diag(Tok, diag::err_pragma_file_or_compound_scope) <<
"STDC FENV_ROUND";
468 ConsumeAnnotationToken();
471 case tok::annot_pragma_cx_limited_range:
472 ProhibitAttributes(CXX11Attrs);
473 ProhibitAttributes(GNUAttrs);
474 Diag(Tok, diag::err_pragma_file_or_compound_scope)
475 <<
"STDC CX_LIMITED_RANGE";
476 ConsumeAnnotationToken();
479 case tok::annot_pragma_float_control:
480 ProhibitAttributes(CXX11Attrs);
481 ProhibitAttributes(GNUAttrs);
482 Diag(Tok, diag::err_pragma_file_or_compound_scope) <<
"float_control";
483 ConsumeAnnotationToken();
486 case tok::annot_pragma_opencl_extension:
487 ProhibitAttributes(CXX11Attrs);
488 ProhibitAttributes(GNUAttrs);
489 HandlePragmaOpenCLExtension();
492 case tok::annot_pragma_captured:
493 ProhibitAttributes(CXX11Attrs);
494 ProhibitAttributes(GNUAttrs);
495 return HandlePragmaCaptured();
497 case tok::annot_pragma_openmp:
500 ProhibitAttributes(CXX11Attrs);
501 ProhibitAttributes(GNUAttrs);
503 case tok::annot_attr_openmp:
505 return ParseOpenMPDeclarativeOrExecutableDirective(StmtCtx);
507 case tok::annot_pragma_openacc:
510 case tok::annot_pragma_ms_pointers_to_members:
511 ProhibitAttributes(CXX11Attrs);
512 ProhibitAttributes(GNUAttrs);
513 HandlePragmaMSPointersToMembers();
516 case tok::annot_pragma_ms_pragma:
517 ProhibitAttributes(CXX11Attrs);
518 ProhibitAttributes(GNUAttrs);
519 HandlePragmaMSPragma();
522 case tok::annot_pragma_ms_vtordisp:
523 ProhibitAttributes(CXX11Attrs);
524 ProhibitAttributes(GNUAttrs);
525 HandlePragmaMSVtorDisp();
528 case tok::annot_pragma_loop_hint:
529 ProhibitAttributes(CXX11Attrs);
530 ProhibitAttributes(GNUAttrs);
531 return ParsePragmaLoopHint(Stmts, StmtCtx, TrailingElseLoc, CXX11Attrs);
533 case tok::annot_pragma_dump:
537 case tok::annot_pragma_attribute:
538 HandlePragmaAttribute();
547 ExpectAndConsume(tok::semi, diag::err_expected_semi_after_stmt, SemiError);
556StmtResult Parser::ParseExprStatement(ParsedStmtContext StmtCtx) {
558 Token OldToken = Tok;
564 if (
Expr.isInvalid()) {
569 if (Tok.
is(tok::semi))
578 Diag(OldToken, diag::err_expected_case_before_expression)
582 return ParseCaseStatement(StmtCtx,
true,
Expr);
585 Token *CurTok =
nullptr;
587 if (Tok.
is(tok::annot_repl_input_end))
591 ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
610 assert(Tok.
is(tok::kw___try) &&
"Expected '__try'");
613 if (Tok.
isNot(tok::l_brace))
614 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
619 if (TryBlock.isInvalid())
623 if (Tok.
is(tok::identifier) &&
626 Handler = ParseSEHExceptBlock(
Loc);
627 }
else if (Tok.
is(tok::kw___finally)) {
629 Handler = ParseSEHFinallyBlock(
Loc);
650 raii2(Ident___exception_code,
false),
651 raii3(Ident_GetExceptionCode,
false);
653 if (ExpectAndConsume(tok::l_paren))
667 ParseScopeFlags FilterScope(
this,
getCurScope()->getFlags() |
681 if (ExpectAndConsume(tok::r_paren))
684 if (Tok.
isNot(tok::l_brace))
685 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
689 if(
Block.isInvalid())
702 raii2(Ident___abnormal_termination,
false),
703 raii3(Ident_AbnormalTermination,
false);
705 if (Tok.
isNot(tok::l_brace))
706 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
708 ParseScope FinallyScope(
this, 0);
712 if(
Block.isInvalid()) {
733 if (!
P.getLangOpts().CPlusPlus && !
P.getLangOpts().MicrosoftExt &&
734 isa<DeclStmt>(SubStmt)) {
737 ? diag::warn_c23_compat_label_followed_by_declaration
738 : diag::ext_c_label_followed_by_declaration);
752 ParsedStmtContext StmtCtx) {
754 "Not an identifier!");
759 StmtCtx &= ~ParsedStmtContext::AllowStandaloneOpenMPDirectives;
761 Token IdentTok = Tok;
764 assert(Tok.
is(tok::colon) &&
"Not a label!");
771 if (Tok.
is(tok::kw___attribute)) {
773 ParseGNUAttributes(TempAttrs);
787 SubStmt = ParseStatementOrDeclarationAfterAttributes(
788 Stmts, StmtCtx,
nullptr, EmptyCXX11Attrs, TempAttrs);
789 if (!TempAttrs.empty() && !SubStmt.
isInvalid())
795 if (SubStmt.
isUnset() && Tok.
is(tok::r_brace)) {
796 DiagnoseLabelAtEndOfCompoundStatement();
802 SubStmt = ParseStatement(
nullptr, StmtCtx);
824StmtResult Parser::ParseCaseStatement(ParsedStmtContext StmtCtx,
826 assert((MissingCase || Tok.
is(tok::kw_case)) &&
"Not a case stmt!");
831 StmtCtx &= ~ParsedStmtContext::AllowStandaloneOpenMPDirectives;
854 Stmt *DeepestParsedCaseStmt =
nullptr;
863 if (Tok.
is(tok::code_completion)) {
892 Diag(DotDotDotLoc, diag::ext_gnu_case_range);
900 ColonProtection.restore();
906 Diag(ColonLoc, diag::err_expected_after)
907 <<
"'case'" << tok::colon
911 Diag(ExpectedLoc, diag::err_expected_after)
912 <<
"'case'" << tok::colon
914 ColonLoc = ExpectedLoc;
918 Actions.
ActOnCaseStmt(CaseLoc, LHS, DotDotDotLoc, RHS, ColonLoc);
923 if (TopLevelCase.isInvalid())
924 return ParseStatement(
nullptr, StmtCtx);
929 Stmt *NextDeepest = Case.
get();
930 if (TopLevelCase.isInvalid())
934 DeepestParsedCaseStmt = NextDeepest;
938 }
while (Tok.
is(tok::kw_case));
943 if (Tok.
is(tok::r_brace)) {
946 DiagnoseLabelAtEndOfCompoundStatement();
949 SubStmt = ParseStatement(
nullptr, StmtCtx);
953 if (DeepestParsedCaseStmt) {
970StmtResult Parser::ParseDefaultStatement(ParsedStmtContext StmtCtx) {
971 assert(Tok.
is(tok::kw_default) &&
"Not a default stmt!");
976 StmtCtx &= ~ParsedStmtContext::AllowStandaloneOpenMPDirectives;
984 Diag(ColonLoc, diag::err_expected_after)
985 <<
"'default'" << tok::colon
989 Diag(ExpectedLoc, diag::err_expected_after)
990 <<
"'default'" << tok::colon
992 ColonLoc = ExpectedLoc;
997 if (Tok.
is(tok::r_brace)) {
1000 DiagnoseLabelAtEndOfCompoundStatement();
1003 SubStmt = ParseStatement(
nullptr, StmtCtx);
1015StmtResult Parser::ParseCompoundStatement(
bool isStmtExpr) {
1016 return ParseCompoundStatement(isStmtExpr,
1042StmtResult Parser::ParseCompoundStatement(
bool isStmtExpr,
1043 unsigned ScopeFlags) {
1044 assert(Tok.
is(tok::l_brace) &&
"Not a compound stmt!");
1048 ParseScope CompoundScope(
this, ScopeFlags);
1051 return ParseCompoundStatementBody(isStmtExpr);
1057void Parser::ParseCompoundStatementLeadingPragmas() {
1058 bool checkForPragmas =
true;
1059 while (checkForPragmas) {
1061 case tok::annot_pragma_vis:
1062 HandlePragmaVisibility();
1064 case tok::annot_pragma_pack:
1067 case tok::annot_pragma_msstruct:
1068 HandlePragmaMSStruct();
1070 case tok::annot_pragma_align:
1071 HandlePragmaAlign();
1073 case tok::annot_pragma_weak:
1076 case tok::annot_pragma_weakalias:
1077 HandlePragmaWeakAlias();
1079 case tok::annot_pragma_redefine_extname:
1080 HandlePragmaRedefineExtname();
1082 case tok::annot_pragma_opencl_extension:
1083 HandlePragmaOpenCLExtension();
1085 case tok::annot_pragma_fp_contract:
1086 HandlePragmaFPContract();
1088 case tok::annot_pragma_fp:
1091 case tok::annot_pragma_fenv_access:
1092 case tok::annot_pragma_fenv_access_ms:
1093 HandlePragmaFEnvAccess();
1095 case tok::annot_pragma_fenv_round:
1096 HandlePragmaFEnvRound();
1098 case tok::annot_pragma_cx_limited_range:
1099 HandlePragmaCXLimitedRange();
1101 case tok::annot_pragma_float_control:
1102 HandlePragmaFloatControl();
1104 case tok::annot_pragma_ms_pointers_to_members:
1105 HandlePragmaMSPointersToMembers();
1107 case tok::annot_pragma_ms_pragma:
1108 HandlePragmaMSPragma();
1110 case tok::annot_pragma_ms_vtordisp:
1111 HandlePragmaMSVtorDisp();
1113 case tok::annot_pragma_dump:
1117 checkForPragmas =
false;
1124void Parser::DiagnoseLabelAtEndOfCompoundStatement() {
1127 ? diag::warn_cxx20_compat_label_end_of_compound_statement
1128 : diag::ext_cxx_label_end_of_compound_statement);
1131 ? diag::warn_c23_compat_label_end_of_compound_statement
1132 : diag::ext_c_label_end_of_compound_statement);
1138bool Parser::ConsumeNullStmt(StmtVector &Stmts) {
1139 if (!Tok.
is(tok::semi))
1151 ParseStatementOrDeclaration(Stmts, ParsedStmtContext::SubStmt);
1153 Stmts.push_back(R.
get());
1160 Diag(StartLoc, diag::warn_null_statement)
1166 bool IsStmtExprResult =
false;
1167 if ((StmtCtx & ParsedStmtContext::InStmtExpr) != ParsedStmtContext()) {
1169 unsigned LookAhead = 0;
1170 while (GetLookAheadToken(LookAhead).is(tok::semi)) {
1176 IsStmtExprResult = GetLookAheadToken(LookAhead).
is(tok::r_brace) &&
1177 GetLookAheadToken(LookAhead + 1).
is(tok::r_paren);
1180 if (IsStmtExprResult)
1189StmtResult Parser::ParseCompoundStatementBody(
bool isStmtExpr) {
1192 "in compound statement ('{}')");
1200 if (
T.consumeOpen())
1206 ParseCompoundStatementLeadingPragmas();
1213 while (Tok.
is(tok::kw___label__)) {
1218 if (Tok.
isNot(tok::identifier)) {
1219 Diag(Tok, diag::err_expected) << tok::identifier;
1236 ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
1238 Stmts.push_back(R.
get());
1241 ParsedStmtContext SubStmtCtx =
1242 ParsedStmtContext::Compound |
1243 (isStmtExpr ? ParsedStmtContext::InStmtExpr : ParsedStmtContext());
1245 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
1246 Tok.
isNot(tok::eof)) {
1247 if (Tok.
is(tok::annot_pragma_unused)) {
1248 HandlePragmaUnused();
1252 if (ConsumeNullStmt(Stmts))
1256 if (Tok.
isNot(tok::kw___extension__)) {
1257 R = ParseStatementOrDeclaration(Stmts, SubStmtCtx);
1264 while (Tok.
is(tok::kw___extension__))
1268 MaybeParseCXX11Attributes(attrs,
true);
1271 if (isDeclarationStatement()) {
1279 attrs, DeclSpecAttrs);
1283 ExprResult Res(ParseExpressionWithLeadingExtension(ExtLoc));
1285 if (Res.isInvalid()) {
1292 ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
1293 R = handleExprStmt(Res, SubStmtCtx);
1300 Stmts.push_back(R.
get());
1311 diag::warn_no_support_for_eval_method_source_on_m32);
1316 if (!
T.consumeClose()) {
1319 if (isStmtExpr && Tok.
is(tok::r_paren))
1320 checkCompoundToken(CloseLoc, tok::r_brace, CompoundToken::StmtExprEnd);
1326 if (
T.getCloseLocation().isValid())
1327 CloseLoc =
T.getCloseLocation();
1347bool Parser::ParseParenExprOrCondition(
StmtResult *InitStmt,
1358 Cond = ParseCXXCondition(InitStmt,
Loc, CK,
false);
1377 if (Tok.
isNot(tok::r_paren))
1383 Start, Tok.
getLocation() == Start ? Start : PrevTokLocation, {},
1392 LParenLoc =
T.getOpenLocation();
1393 RParenLoc =
T.getCloseLocation();
1398 while (Tok.
is(tok::r_paren)) {
1399 Diag(Tok, diag::err_extraneous_rparen_in_condition)
1409enum MisleadingStatementKind { MSK_if, MSK_else, MSK_for, MSK_while };
1411struct MisleadingIndentationChecker {
1415 unsigned NumDirectives;
1416 MisleadingStatementKind
Kind;
1418 MisleadingIndentationChecker(
Parser &
P, MisleadingStatementKind K,
1420 :
P(
P), StmtLoc(SL), PrevLoc(
P.getCurToken().getLocation()),
1421 NumDirectives(
P.getPreprocessor().getNumDirectives()),
Kind(K),
1422 ShouldSkip(
P.getCurToken().is(tok::l_brace)) {
1423 if (!
P.MisleadingIndentationElseLoc.isInvalid()) {
1424 StmtLoc =
P.MisleadingIndentationElseLoc;
1427 if (
Kind == MSK_else && !ShouldSkip)
1428 P.MisleadingIndentationElseLoc = SL;
1434 unsigned TabStop =
SM.getDiagnostics().getDiagnosticOptions().TabStop;
1436 unsigned ColNo =
SM.getSpellingColumnNumber(
Loc);
1437 if (ColNo == 0 || TabStop == 1)
1440 std::pair<FileID, unsigned> FIDAndOffset =
SM.getDecomposedLoc(
Loc);
1443 StringRef BufData =
SM.getBufferData(FIDAndOffset.first, &
Invalid);
1447 const char *EndPos = BufData.data() + FIDAndOffset.second;
1449 assert(FIDAndOffset.second + 1 >= ColNo &&
1450 "Column number smaller than file offset?");
1452 unsigned VisualColumn = 0;
1455 for (
const char *CurPos = EndPos - (ColNo - 1); CurPos != EndPos;
1457 if (*CurPos ==
'\t')
1459 VisualColumn += (TabStop - VisualColumn % TabStop);
1463 return VisualColumn + 1;
1467 Token Tok =
P.getCurToken();
1468 if (
P.getActions().getDiagnostics().isIgnored(
1469 diag::warn_misleading_indentation, Tok.
getLocation()) ||
1470 ShouldSkip || NumDirectives !=
P.getPreprocessor().getNumDirectives() ||
1474 (
Kind == MSK_else &&
P.MisleadingIndentationElseLoc.isInvalid())) {
1478 if (
Kind == MSK_else)
1482 unsigned PrevColNum = getVisualIndentation(
SM, PrevLoc);
1483 unsigned CurColNum = getVisualIndentation(
SM, Tok.
getLocation());
1484 unsigned StmtColNum = getVisualIndentation(
SM, StmtLoc);
1486 if (PrevColNum != 0 && CurColNum != 0 && StmtColNum != 0 &&
1487 ((PrevColNum > StmtColNum && PrevColNum == CurColNum) ||
1489 SM.getPresumedLineNumber(StmtLoc) !=
1491 (Tok.
isNot(tok::identifier) ||
1492 P.getPreprocessor().LookAhead(0).isNot(tok::colon))) {
1494 P.Diag(StmtLoc, diag::note_previous_statement);
1511 assert(Tok.
is(tok::kw_if) &&
"Not an if stmt!");
1514 bool IsConstexpr =
false;
1515 bool IsConsteval =
false;
1519 if (Tok.
is(tok::kw_constexpr)) {
1521 : diag::ext_constexpr_if);
1525 if (Tok.
is(tok::exclaim)) {
1529 if (Tok.
is(tok::kw_consteval)) {
1531 : diag::ext_consteval_if);
1536 if (!IsConsteval && (NotLocation.
isValid() || Tok.
isNot(tok::l_paren))) {
1537 Diag(Tok, diag::err_expected_lparen_after) <<
"if";
1563 std::optional<bool> ConstexprCondition;
1566 if (ParseParenExprOrCondition(&InitStmt, Cond, IfLoc,
1576 bool IsBracedThen = Tok.
is(tok::l_brace);
1598 MisleadingIndentationChecker MIChecker(*
this, MSK_if, IfLoc);
1606 bool ShouldEnter = ConstexprCondition && !*ConstexprCondition;
1609 if (NotLocation.
isInvalid() && IsConsteval) {
1615 Actions, Context,
nullptr,
1617 ThenStmt = ParseStatement(&InnerStatementTrailingElseLoc);
1620 if (Tok.
isNot(tok::kw_else))
1631 if (Tok.
is(tok::kw_else)) {
1632 if (TrailingElseLoc)
1648 Tok.
is(tok::l_brace));
1650 MisleadingIndentationChecker MIChecker(*
this, MSK_else, ElseLoc);
1651 bool ShouldEnter = ConstexprCondition && *ConstexprCondition;
1654 if (NotLocation.
isValid() && IsConsteval) {
1660 Actions, Context,
nullptr,
1662 ElseStmt = ParseStatement();
1669 }
else if (Tok.
is(tok::code_completion)) {
1673 }
else if (InnerStatementTrailingElseLoc.
isValid()) {
1674 Diag(InnerStatementTrailingElseLoc, diag::warn_dangling_else);
1690 auto IsCompoundStatement = [](
const Stmt *S) {
1691 if (
const auto *Outer = dyn_cast_if_present<AttributedStmt>(S))
1692 S = Outer->getSubStmt();
1693 return isa_and_nonnull<clang::CompoundStmt>(S);
1696 if (!IsCompoundStatement(ThenStmt.
get())) {
1697 Diag(ConstevalLoc, diag::err_expected_after) <<
"consteval"
1701 if (!ElseStmt.
isUnset() && !IsCompoundStatement(ElseStmt.
get())) {
1702 Diag(ElseLoc, diag::err_expected_after) <<
"else"
1717 else if (IsConsteval)
1721 return Actions.
ActOnIfStmt(IfLoc, Kind, LParen, InitStmt.
get(), Cond, RParen,
1722 ThenStmt.
get(), ElseLoc, ElseStmt.
get());
1730 assert(Tok.
is(tok::kw_switch) &&
"Not a switch stmt!");
1733 if (Tok.
isNot(tok::l_paren)) {
1734 Diag(Tok, diag::err_expected_lparen_after) <<
"switch";
1756 ParseScope SwitchScope(
this, ScopeFlags);
1763 if (ParseParenExprOrCondition(&InitStmt, Cond, SwitchLoc,
1768 SwitchLoc, LParen, InitStmt.
get(), Cond, RParen);
1770 if (
Switch.isInvalid()) {
1775 if (Tok.
is(tok::l_brace)) {
1803 StmtResult Body(ParseStatement(TrailingElseLoc));
1817 assert(Tok.
is(tok::kw_while) &&
"Not a while stmt!");
1821 if (Tok.
isNot(tok::l_paren)) {
1822 Diag(Tok, diag::err_expected_lparen_after) <<
"while";
1841 unsigned ScopeFlags;
1847 ParseScope WhileScope(
this, ScopeFlags);
1853 if (ParseParenExprOrCondition(
nullptr, Cond, WhileLoc,
1870 MisleadingIndentationChecker MIChecker(*
this, MSK_while, WhileLoc);
1873 StmtResult Body(ParseStatement(TrailingElseLoc));
1875 if (Body.isUsable())
1881 if (Cond.
isInvalid() || Body.isInvalid())
1884 return Actions.
ActOnWhileStmt(WhileLoc, LParen, Cond, RParen, Body.get());
1892 assert(Tok.
is(tok::kw_do) &&
"Not a do stmt!");
1897 unsigned ScopeFlags;
1903 ParseScope DoScope(
this, ScopeFlags);
1922 if (Tok.
isNot(tok::kw_while)) {
1923 if (!Body.isInvalid()) {
1924 Diag(Tok, diag::err_expected_while);
1925 Diag(DoLoc, diag::note_matching) <<
"'do'";
1932 if (Tok.
isNot(tok::l_paren)) {
1933 Diag(Tok, diag::err_expected_lparen_after) <<
"do/while";
1943 DiagnoseAndSkipCXX11Attributes();
1952 if (!Tok.
isOneOf(tok::r_paren, tok::r_square, tok::r_brace))
1955 Start, Start == Tok.
getLocation() ? Start : PrevTokLocation, {},
1961 if (Cond.
isInvalid() || Body.isInvalid())
1964 return Actions.
ActOnDoStmt(DoLoc, Body.get(), WhileLoc,
T.getOpenLocation(),
1965 Cond.
get(),
T.getCloseLocation());
1968bool Parser::isForRangeIdentifier() {
1969 assert(Tok.
is(tok::identifier));
1972 if (Next.is(tok::colon))
1975 if (Next.isOneOf(tok::l_square, tok::kw_alignas)) {
1976 TentativeParsingAction PA(*
this);
1978 SkipCXX11Attributes();
2011 assert(Tok.
is(tok::kw_for) &&
"Not a for stmt!");
2015 if (Tok.
is(tok::kw_co_await))
2018 if (Tok.
isNot(tok::l_paren)) {
2019 Diag(Tok, diag::err_expected_lparen_after) <<
"for";
2042 unsigned ScopeFlags = 0;
2046 ParseScope ForScope(
this, ScopeFlags);
2053 bool ForEach =
false;
2057 ForRangeInfo ForRangeInfo;
2060 if (Tok.
is(tok::code_completion)) {
2069 MaybeParseCXX11Attributes(attrs);
2074 if (Tok.
is(tok::semi)) {
2075 ProhibitAttributes(attrs);
2079 EmptyInitStmtSemiLoc = SemiLoc;
2082 isForRangeIdentifier()) {
2083 ProhibitAttributes(attrs);
2086 MaybeParseCXX11Attributes(attrs);
2089 if (Tok.
is(tok::l_brace))
2090 ForRangeInfo.RangeExpr = ParseBraceInitializer();
2094 Diag(
Loc, diag::err_for_range_identifier)
2099 ForRangeInfo.LoopVar =
2101 }
else if (isForInitDeclaration()) {
2105 if (!C99orCXXorObjC) {
2106 Diag(Tok, diag::ext_c99_variable_decl_in_for_loop);
2107 Diag(Tok, diag::warn_gcc_variable_decl_in_for_loop);
2111 if (Tok.
is(tok::kw_using)) {
2117 bool MightBeForRangeStmt =
getLangOpts().CPlusPlus;
2120 DG = ParseSimpleDeclaration(
2122 MightBeForRangeStmt ? &ForRangeInfo :
nullptr);
2124 if (ForRangeInfo.ParsedForRangeDecl()) {
2126 ? diag::warn_cxx98_compat_for_range
2127 : diag::ext_for_range);
2128 ForRangeInfo.LoopVar = FirstPart;
2130 }
else if (Tok.
is(tok::semi)) {
2132 }
else if ((ForEach = isTokIdentifier_in())) {
2137 if (Tok.
is(tok::code_completion)) {
2145 Diag(Tok, diag::err_expected_semi_for);
2149 ProhibitAttributes(attrs);
2152 ForEach = isTokIdentifier_in();
2155 if (!
Value.isInvalid()) {
2164 bool IsRangeBasedFor =
2165 getLangOpts().CPlusPlus11 && !ForEach && Tok.
is(tok::colon);
2170 if (Tok.
is(tok::semi)) {
2172 }
else if (ForEach) {
2175 if (Tok.
is(tok::code_completion)) {
2185 Diag(Tok, diag::err_for_range_expected_decl)
2190 if (!
Value.isInvalid()) {
2191 Diag(Tok, diag::err_expected_semi_for);
2195 if (Tok.
is(tok::semi))
2202 if (!ForEach && !ForRangeInfo.ParsedForRangeDecl() &&
2205 if (Tok.
is(tok::semi)) {
2207 }
else if (Tok.
is(tok::r_paren)) {
2213 bool MightBeForRangeStmt = !ForRangeInfo.ParsedForRangeDecl();
2217 SecondPart = ParseCXXCondition(
2218 nullptr, ForLoc, CK,
2220 true, MightBeForRangeStmt ? &ForRangeInfo :
nullptr,
2223 if (ForRangeInfo.ParsedForRangeDecl()) {
2225 : ForRangeInfo.ColonLoc,
2227 ? diag::warn_cxx17_compat_for_range_init_stmt
2228 : diag::ext_for_range_init_stmt)
2231 if (EmptyInitStmtSemiLoc.
isValid()) {
2232 Diag(EmptyInitStmtSemiLoc, diag::warn_empty_init_statement)
2241 Tok.
getLocation() == SecondPartStart ? SecondPartStart
2271 if (!ForEach && !ForRangeInfo.ParsedForRangeDecl()) {
2272 if (Tok.
isNot(tok::semi)) {
2274 Diag(Tok, diag::err_expected_semi_for);
2278 if (Tok.
is(tok::semi)) {
2282 if (Tok.
isNot(tok::r_paren)) {
2294 if (CoawaitLoc.
isValid() && !ForRangeInfo.ParsedForRangeDecl()) {
2295 Diag(CoawaitLoc, diag::err_for_co_await_not_range_for);
2300 Diag(CoawaitLoc, diag::warn_deprecated_for_co_await);
2308 if (ForRangeInfo.ParsedForRangeDecl()) {
2313 ForRangeInfo.LoopVar.get(), ForRangeInfo.ColonLoc, CorrectedRange.
get(),
2315 ForRangeInfo.LifetimeExtendTemps);
2316 }
else if (ForEach) {
2320 ForLoc, FirstPart.
get(), Collection.
get(),
T.getCloseLocation());
2341 Tok.
is(tok::l_brace));
2350 MisleadingIndentationChecker MIChecker(*
this, MSK_for, ForLoc);
2353 StmtResult Body(ParseStatement(TrailingElseLoc));
2355 if (Body.isUsable())
2364 if (Body.isInvalid())
2371 if (ForRangeInfo.ParsedForRangeDecl())
2375 SecondPart, ThirdPart,
T.getCloseLocation(),
2387 assert(Tok.
is(tok::kw_goto) &&
"Not a goto stmt!");
2391 if (Tok.
is(tok::identifier)) {
2396 }
else if (Tok.
is(tok::star)) {
2398 Diag(Tok, diag::ext_gnu_indirect_goto);
2407 Diag(Tok, diag::err_expected) << tok::identifier;
2443 assert((Tok.
is(tok::kw_return) || Tok.
is(tok::kw_co_return)) &&
2444 "Not a return stmt!");
2445 bool IsCoreturn = Tok.
is(tok::kw_co_return);
2449 if (Tok.
isNot(tok::semi)) {
2453 if (Tok.
is(tok::code_completion) && !IsCoreturn) {
2461 R = ParseInitializer();
2465 ? diag::warn_cxx98_compat_generalized_initializer_lists
2466 : diag::ext_generalized_initializer_lists)
2480StmtResult Parser::ParsePragmaLoopHint(StmtVector &Stmts,
2481 ParsedStmtContext StmtCtx,
2490 while (Tok.
is(tok::annot_pragma_loop_hint)) {
2492 if (!HandlePragmaLoopHint(Hint))
2499 ParsedAttr::Form::Pragma());
2503 MaybeParseCXX11Attributes(Attrs);
2506 StmtResult S = ParseStatementOrDeclarationAfterAttributes(
2507 Stmts, StmtCtx, TrailingElseLoc, Attrs, EmptyDeclSpecAttrs);
2519Decl *Parser::ParseFunctionStatementBody(
Decl *
Decl, ParseScope &BodyScope) {
2520 assert(Tok.
is(tok::l_brace));
2524 "parsing function body");
2530 PragmaStackSentinel(Actions,
"InternalPragmaState", IsCXXMethod);
2535 StmtResult FnBody(ParseCompoundStatementBody());
2538 if (FnBody.isInvalid()) {
2553Decl *Parser::ParseFunctionTryBlock(
Decl *
Decl, ParseScope &BodyScope) {
2554 assert(Tok.
is(tok::kw_try) &&
"Expected 'try'");
2558 "parsing function try block");
2561 if (Tok.
is(tok::colon))
2562 ParseConstructorInitializer(
Decl);
2570 PragmaStackSentinel(Actions,
"InternalPragmaState", IsCXXMethod);
2573 StmtResult FnBody(ParseCXXTryBlockCommon(TryLoc,
true));
2576 if (FnBody.isInvalid()) {
2586bool Parser::trySkippingFunctionBody() {
2587 assert(SkipFunctionBodies &&
2588 "Should only be called when SkipFunctionBodies is enabled");
2596 TentativeParsingAction PA(*
this);
2597 bool IsTryCatch = Tok.
is(tok::kw_try);
2599 bool ErrorInPrologue = ConsumeAndStoreFunctionPrologue(Toks);
2600 if (llvm::any_of(Toks, [](
const Token &Tok) {
2601 return Tok.
is(tok::code_completion);
2606 if (ErrorInPrologue) {
2615 while (IsTryCatch && Tok.
is(tok::kw_catch)) {
2632 assert(Tok.
is(tok::kw_try) &&
"Expected 'try'");
2635 return ParseCXXTryBlockCommon(TryLoc);
2655 if (Tok.
isNot(tok::l_brace))
2656 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
2662 if (TryBlock.isInvalid())
2667 if ((Tok.
is(tok::identifier) &&
2669 Tok.
is(tok::kw___finally)) {
2674 Handler = ParseSEHExceptBlock(
Loc);
2678 Handler = ParseSEHFinallyBlock(
Loc);
2693 DiagnoseAndSkipCXX11Attributes();
2695 if (Tok.
isNot(tok::kw_catch))
2697 while (Tok.
is(tok::kw_catch)) {
2698 StmtResult Handler(ParseCXXCatchBlock(FnTry));
2700 Handlers.push_back(Handler.
get());
2704 if (Handlers.empty())
2721StmtResult Parser::ParseCXXCatchBlock(
bool FnCatch) {
2722 assert(Tok.
is(tok::kw_catch) &&
"Expected 'catch'");
2727 if (
T.expectAndConsume())
2739 Decl *ExceptionDecl =
nullptr;
2740 if (Tok.
isNot(tok::ellipsis)) {
2742 MaybeParseCXX11Attributes(Attributes);
2746 if (ParseCXXTypeSpecifierSeq(DS))
2750 ParseDeclarator(ExDecl);
2756 if (
T.getCloseLocation().isInvalid())
2759 if (Tok.
isNot(tok::l_brace))
2760 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
2764 if (
Block.isInvalid())
2770void Parser::ParseMicrosoftIfExistsStatement(StmtVector &Stmts) {
2771 IfExistsCondition
Result;
2772 if (ParseMicrosoftIfExistsCondition(
Result))
2779 if (
Result.Behavior == IEB_Dependent) {
2780 if (!Tok.
is(tok::l_brace)) {
2781 Diag(Tok, diag::err_expected) << tok::l_brace;
2785 StmtResult Compound = ParseCompoundStatement();
2795 Stmts.push_back(DepResult.
get());
2800 if (
Braces.consumeOpen()) {
2801 Diag(Tok, diag::err_expected) << tok::l_brace;
2805 switch (
Result.Behavior) {
2811 llvm_unreachable(
"Dependent case handled above");
2819 while (Tok.
isNot(tok::r_brace)) {
2821 ParseStatementOrDeclaration(Stmts, ParsedStmtContext::Compound);
2823 Stmts.push_back(R.
get());
enum clang::sema::@1655::IndirectLocalPathEntry::EntryKind Kind
static void DiagnoseLabelFollowedByDecl(Parser &P, const Stmt *SubStmt)
Defines the PrettyStackTraceEntry class, which is used to make crashes give more contextual informati...
This file declares facilities that support code completion.
This file declares semantic analysis for Objective-C.
This file declares semantic analysis for OpenMP constructs and clauses.
static CharSourceRange getRange(const CharSourceRange &EditRange, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeMacroExpansion)
Defines the clang::TokenKind enum and support functions.
Attr - This represents one attribute.
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ....
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
virtual bool ValidateCandidate(const TypoCorrection &candidate)
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
Captures information about "declaration specifiers".
Decl - This represents one declaration (or definition), e.g.
Information about one declarator, including the parsed type information and the identifier.
RAII object that enters a new expression evaluation context.
This represents one expression.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
ExtensionRAIIObject - This saves the state of extension warnings when constructed and disables them.
Represents a member of a struct/union/class.
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
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.
One of these records is kept for each identifier that is lexed.
void setIsPoisoned(bool Value=true)
setIsPoisoned - Mark this identifier as poisoned.
StringRef getName() const
Return the actual identifier string.
Represents the declaration of a label.
@ FEM_Source
Use the declared type for fp arithmetic.
Represent a C++ namespace.
RAII object that makes sure paren/bracket/brace count is correct after declaration/statement parsing,...
ParsedAttr - Represents a syntactic attribute.
ParsedAttributes - A collection of parsed attributes.
void takeAllFrom(ParsedAttributes &Other)
Parser - This implements a parser for the C family of languages.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Sema::FullExprArg FullExprArg
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
ExprResult ParseCaseExpression(SourceLocation CaseLoc)
StmtResult ParseOpenACCDirectiveStmt()
bool TryConsumeToken(tok::TokenKind Expected)
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
Scope * getCurScope() const
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
void SkipMalformedDecl()
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a s...
const LangOptions & getLangOpts() const
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
SmallVector< Stmt *, 32 > StmtVector
A SmallVector of statements.
@ StopBeforeMatch
Stop skipping at specified token, but don't skip the token itself.
@ StopAtCodeCompletion
Stop at code completion.
@ StopAtSemi
Stop skipping at semicolon.
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
An RAII object for [un]poisoning an identifier within a scope.
void enterReturn(Sema &S, SourceLocation Tok)
QualType get(SourceLocation Tok) const
Get the expected type associated with this location, if any.
SourceLocation getLastFPEvalPragmaLocation() const
LangOptions::FPEvalMethodKind getCurrentFPEvalMethod() const
SourceManager & getSourceManager() const
const TargetInfo & getTargetInfo() const
bool isCodeCompletionEnabled() const
Determine if we are performing code completion.
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
PrettyDeclStackTraceEntry - If a crash occurs in the parser while parsing something related to a decl...
If a crash happens while one of these objects are live, the message is printed out along with the spe...
void AddFlags(unsigned Flags)
Sets up the specified scope flags and adjusts the scope state variables accordingly.
void decrementMSManglingNumber()
@ SEHTryScope
This scope corresponds to an SEH try.
@ ContinueScope
This is a while, do, for, which can have continue statements embedded into it.
@ ControlScope
The controlling scope in a if/switch/while/for statement.
@ SEHFilterScope
We are currently in the filter expression of an SEH except block.
@ SwitchScope
This is a scope that corresponds to a switch statement.
@ BreakScope
This is a while, do, switch, for, etc that can have break statements embedded into it.
@ CatchScope
This is the scope of a C++ catch statement.
@ CompoundStmtScope
This is a compound statement scope.
@ FnTryCatchScope
This is the scope for a function-level C++ try or catch scope.
@ SEHExceptScope
This scope corresponds to an SEH except.
@ TryScope
This is the scope of a C++ try statement.
@ DeclScope
This is a scope that can contain a declaration.
@ PCC_ForInit
Code completion occurs at the beginning of the initialization statement (or expression) in a for loop...
@ PCC_Expression
Code completion occurs within an expression.
@ PCC_Statement
Code completion occurs within a statement, which may also be an expression or a declaration.
void CodeCompleteCase(Scope *S)
void CodeCompleteExpression(Scope *S, const CodeCompleteExpressionData &Data)
Perform code-completion in an expression context when we know what type we're looking for.
void CodeCompleteAfterIf(Scope *S, bool IsBracedThen)
void CodeCompleteOrdinaryName(Scope *S, ParserCompletionContext CompletionContext)
void CodeCompleteObjCForCollection(Scope *S, DeclGroupPtrTy IterationVar)
StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, Stmt *First, Expr *collection, SourceLocation RParenLoc)
StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body)
FinishObjCForCollectionStmt - Attach the body to a objective-C foreach statement.
void ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init)
Check if the current region is an OpenMP loop region and if it is, mark loop control variable,...
A RAII object to enter scope of a compound statement.
std::optional< bool > getKnownValue() const
Records and restores the CurFPFeatures state on entry/exit of compound statements.
StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc, IdentifierInfo *Ident, ParsedAttributes &Attrs)
StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope)
StmtResult ActOnForEachLValueExpr(Expr *E)
In an Objective C collection iteration statement: for (x in y) x can be an arbitrary l-value expressi...
void ActOnForEachDeclStmt(DeclGroupPtrTy Decl)
@ Boolean
A boolean condition, from 'if', 'while', 'for', or 'do'.
@ Switch
An integral condition for a 'switch' statement.
@ ConstexprIf
A constant boolean condition from 'if constexpr'.
StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *TheDecl)
StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, Scope *CurScope)
StmtResult ActOnExprStmt(ExprResult Arg, bool DiscardedValue=true)
bool CheckCaseExpression(Expr *E)
ASTContext & getASTContext() const
StmtResult ActOnSEHTryBlock(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
ConditionResult ActOnCondition(Scope *S, SourceLocation Loc, Expr *SubExpr, ConditionKind CK, bool MissingOK=false)
StmtResult ActOnCoreturnStmt(Scope *S, SourceLocation KwLoc, Expr *E)
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
SemaCodeCompletion & CodeCompletion()
void ProcessDeclAttributeList(Scope *S, Decl *D, const ParsedAttributesView &AttrList, const ProcessDeclAttributeOptions &Options=ProcessDeclAttributeOptions())
ProcessDeclAttributeList - Apply all the decl attributes in the specified attribute list to the speci...
StmtResult ActOnExprStmtError()
StmtResult ActOnNullStmt(SourceLocation SemiLoc, bool HasLeadingEmptyMacro=false)
StmtResult ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *First, ConditionResult Second, FullExprArg Third, SourceLocation RParenLoc, Stmt *Body)
StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *DestExp)
Decl * ActOnExceptionDeclarator(Scope *S, Declarator &D)
ActOnExceptionDeclarator - Parsed the exception-declarator in a C++ catch handler.
LabelDecl * LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, SourceLocation GnuLabelLoc=SourceLocation())
LookupOrCreateLabel - Do a name lookup of a label with the specified name.
Decl * ActOnFinishFunctionBody(Decl *Decl, Stmt *Body)
StmtResult ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *InitStmt, Stmt *LoopVar, SourceLocation ColonLoc, Expr *Collection, SourceLocation RParenLoc, BuildForRangeKind Kind, ArrayRef< MaterializeTemporaryExpr * > LifetimeExtendTemps={})
ActOnCXXForRangeStmt - Check and build a C++11 for-range statement.
void ActOnDefaultCtorInitializers(Decl *CDtorDecl)
DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, ArrayRef< Decl * > Group)
StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block)
StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope)
StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation CondLParen, Expr *Cond, SourceLocation CondRParen)
StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc)
StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, CXXScopeSpec &SS, UnqualifiedId &Name, Stmt *Nested)
ExpressionEvaluationContext
Describes how the expressions currently being parsed are evaluated at run-time, if at all.
@ DiscardedStatement
The current expression occurs within a discarded statement.
@ ImmediateFunctionContext
In addition of being constant evaluated, the current expression occurs in an immediate function conte...
StmtResult ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
void ActOnAfterCompoundStatementLeadingPragmas()
StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, SourceLocation EndLoc)
StmtResult ActOnAttributedStmt(const ParsedAttributes &AttrList, Stmt *SubStmt)
StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope)
FullExprArg MakeFullDiscardedValueExpr(Expr *Arg)
void ActOnStartSEHFinallyBlock()
void ActOnAbortSEHFinallyBlock()
@ BFRK_Build
Initial building of a for-range statement.
StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, Decl *ExDecl, Stmt *HandlerBlock)
ActOnCXXCatchBlock - Takes an exception declaration and a handler block and creates a proper catch ha...
void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt)
ActOnCaseStmtBody - This installs a statement as the body of a case.
ExprResult ActOnStmtExprResult(ExprResult E)
ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, ArrayRef< Expr * > SubExprs, QualType T=QualType())
Attempts to produce a RecoveryExpr after some AST node cannot be created.
StmtResult ActOnIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc, Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal)
QualType PreferredConditionType(ConditionKind K) const
static ConditionResult ConditionError()
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt * > Elts, bool isStmtExpr)
StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, SourceLocation ColonLoc, Stmt *SubStmt)
StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, ArrayRef< Stmt * > Handlers)
ActOnCXXTryBlock - Takes a try compound-statement and a number of handlers and creates a try statemen...
StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt, Scope *CurScope)
StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, SourceLocation DotDotDotLoc, ExprResult RHS, SourceLocation ColonLoc)
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
FinishCXXForRangeStmt - Attach the body to a C++0x for-range statement.
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, bool RecoverUncorrectedTypos=false, llvm::function_ref< ExprResult(Expr *)> Filter=[](Expr *E) -> ExprResult { return E;})
Process any TypoExprs in the given Expr and its children, generating diagnostics as appropriate and r...
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
void setBegin(SourceLocation b)
SourceLocation getBegin() const
Stmt - This represents one statement.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
virtual bool supportSourceEvalMethod() const
Token - This structure provides full information about a lexed token.
IdentifierInfo * getIdentifierInfo() const
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
void setKind(tok::TokenKind K)
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)) {....
tok::TokenKind getKind() const
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
bool hasLeadingEmptyMacro() const
Return true if this token has an empty macro before it.
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
bool isNot(tok::TokenKind K) const
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
void setAnnotationValue(void *val)
Simple class containing the result of Sema::CorrectTypo.
DeclClass * getCorrectionDeclAs() const
NestedNameSpecifier * getCorrectionSpecifier() const
Gets the NestedNameSpecifier needed to use the typo correction.
Represents a variable declaration or definition.
Defines the clang::TargetInfo interface.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
The JSON file list parser is used to communicate input to InstallAPI.
IfStatementKind
In an if statement, this denotes whether the statement is a constexpr or consteval if statement.
llvm::PointerUnion< Expr *, IdentifierLoc * > ArgsUnion
A union of the various pointer types that can be passed to an ParsedAttr as an argument.
void takeAndConcatenateAttrs(ParsedAttributes &First, ParsedAttributes &Second, ParsedAttributes &Result)
Consumes the attributes from First and Second and concatenates them into Result.
@ Result
The result type of a method or function.
ActionResult< Stmt * > StmtResult
const FunctionProtoType * T
@ Braces
New-expression has a C++11 list-initializer.
Loop optimization hint for loop and unroll pragmas.
IdentifierLoc * OptionLoc
IdentifierLoc * PragmaNameLoc