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())
125 StatementFilterCCC(
Token nextTok) : NextToken(nextTok) {
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 {
138 if (NextToken.is(tok::equal))
140 if (NextToken.is(tok::period) &&
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))
201 if (Tok.
isNot(tok::identifier))
211 Allowed == ACK_Any) &&
212 isDeclarationStatement()) {
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();
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);
279 if (msAsm)
return Res;
284 case tok::kw___if_exists:
285 case tok::kw___if_not_exists:
286 ProhibitAttributes(Attrs);
287 ParseMicrosoftIfExistsStatement(Stmts);
293 return ParseCXXTryBlock();
296 ProhibitAttributes(Attrs);
297 return ParseSEHTryBlock();
299 case tok::kw___leave:
300 Res = ParseSEHLeaveStatement();
301 SemiError =
"__leave";
304 case tok::annot_pragma_vis:
305 ProhibitAttributes(Attrs);
306 HandlePragmaVisibility();
309 case tok::annot_pragma_pack:
310 ProhibitAttributes(Attrs);
314 case tok::annot_pragma_msstruct:
315 ProhibitAttributes(Attrs);
316 HandlePragmaMSStruct();
319 case tok::annot_pragma_align:
320 ProhibitAttributes(Attrs);
324 case tok::annot_pragma_weak:
325 ProhibitAttributes(Attrs);
329 case tok::annot_pragma_weakalias:
330 ProhibitAttributes(Attrs);
331 HandlePragmaWeakAlias();
334 case tok::annot_pragma_redefine_extname:
335 ProhibitAttributes(Attrs);
336 HandlePragmaRedefineExtname();
339 case tok::annot_pragma_fp_contract:
340 ProhibitAttributes(Attrs);
341 Diag(Tok, diag::err_pragma_fp_contract_scope);
342 ConsumeAnnotationToken();
345 case tok::annot_pragma_fp:
346 ProhibitAttributes(Attrs);
347 Diag(Tok, diag::err_pragma_fp_scope);
348 ConsumeAnnotationToken();
351 case tok::annot_pragma_opencl_extension:
352 ProhibitAttributes(Attrs);
353 HandlePragmaOpenCLExtension();
356 case tok::annot_pragma_captured:
357 ProhibitAttributes(Attrs);
358 return HandlePragmaCaptured();
360 case tok::annot_pragma_openmp:
361 ProhibitAttributes(Attrs);
362 return ParseOpenMPDeclarativeOrExecutableDirective(Allowed);
364 case tok::annot_pragma_ms_pointers_to_members:
365 ProhibitAttributes(Attrs);
366 HandlePragmaMSPointersToMembers();
369 case tok::annot_pragma_ms_pragma:
370 ProhibitAttributes(Attrs);
371 HandlePragmaMSPragma();
374 case tok::annot_pragma_ms_vtordisp:
375 ProhibitAttributes(Attrs);
376 HandlePragmaMSVtorDisp();
379 case tok::annot_pragma_loop_hint:
380 ProhibitAttributes(Attrs);
381 return ParsePragmaLoopHint(Stmts, Allowed, TrailingElseLoc, Attrs);
383 case tok::annot_pragma_dump:
387 case tok::annot_pragma_attribute:
388 HandlePragmaAttribute();
397 ExpectAndConsume(tok::semi, diag::err_expected_semi_after_stmt, SemiError);
408 Token OldToken = Tok;
414 if (
Expr.isInvalid()) {
419 if (Tok.
is(tok::semi))
428 Diag(OldToken, diag::err_expected_case_before_expression)
432 return ParseCaseStatement(
true,
Expr);
436 ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
450 assert(Tok.
is(tok::kw___try) &&
"Expected '__try'");
453 if (Tok.
isNot(tok::l_brace))
454 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
456 StmtResult TryBlock(ParseCompoundStatement(
false,
458 if(TryBlock.isInvalid())
462 if (Tok.
is(tok::identifier) &&
465 Handler = ParseSEHExceptBlock(Loc);
466 }
else if (Tok.
is(tok::kw___finally)) {
468 Handler = ParseSEHFinallyBlock(Loc);
473 if(Handler.isInvalid())
489 raii2(Ident___exception_code,
false),
490 raii3(Ident_GetExceptionCode,
false);
492 if (ExpectAndConsume(tok::l_paren))
506 ParseScopeFlags FilterScope(
this,
getCurScope()->getFlags() |
520 if (ExpectAndConsume(tok::r_paren))
523 if (Tok.
isNot(tok::l_brace))
524 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
528 if(Block.isInvalid())
541 raii2(Ident___abnormal_termination,
false),
542 raii3(Ident_AbnormalTermination,
false);
544 if (Tok.
isNot(tok::l_brace))
545 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
547 ParseScope FinallyScope(
this, 0);
551 if(Block.isInvalid()) {
575 StmtResult Parser::ParseLabeledStatement(ParsedAttributesWithRange &attrs) {
577 "Not an identifier!");
579 Token IdentTok = Tok;
582 assert(Tok.
is(tok::colon) &&
"Not a label!");
589 if (Tok.
is(tok::kw___attribute)) {
590 ParsedAttributesWithRange TempAttrs(AttrFactory);
591 ParseGNUAttributes(TempAttrs);
601 attrs.takeAllFrom(TempAttrs);
602 else if (isDeclarationStatement()) {
608 SubStmt = ParseStatementOrDeclarationAfterAttributes(
609 Stmts, ACK_StatementsOpenMPNonStandalone,
nullptr,
611 if (!TempAttrs.empty() && !SubStmt.isInvalid())
613 SubStmt.get(), TempAttrs.getList(), TempAttrs.Range);
615 Diag(Tok, diag::err_expected_after) <<
"__attribute__" << tok::semi;
620 if (!SubStmt.isInvalid() && !SubStmt.isUsable())
621 SubStmt = ParseStatement();
624 if (SubStmt.isInvalid())
628 IdentTok.getLocation());
644 assert((MissingCase || Tok.
is(tok::kw_case)) &&
"Not a case stmt!");
667 Stmt *DeepestParsedCaseStmt =
nullptr;
676 if (Tok.
is(tok::code_completion)) {
713 Diag(DotDotDotLoc, diag::ext_gnu_case_range);
724 ColonProtection.restore();
730 Diag(ColonLoc, diag::err_expected_after)
731 <<
"'case'" << tok::colon
735 Diag(ExpectedLoc, diag::err_expected_after)
736 <<
"'case'" << tok::colon
738 ColonLoc = ExpectedLoc;
747 if (Case.isInvalid()) {
748 if (TopLevelCase.isInvalid())
749 return ParseStatement(
nullptr,
755 Stmt *NextDeepest = Case.get();
756 if (TopLevelCase.isInvalid())
760 DeepestParsedCaseStmt = NextDeepest;
764 }
while (Tok.
is(tok::kw_case));
769 if (Tok.
isNot(tok::r_brace)) {
770 SubStmt = ParseStatement(
nullptr,
778 Diag(AfterColonLoc, diag::err_label_end_of_compound_statement)
785 if (DeepestParsedCaseStmt) {
787 if (SubStmt.isInvalid())
802 assert(Tok.
is(tok::kw_default) &&
"Not a default stmt!");
809 Diag(ColonLoc, diag::err_expected_after)
810 <<
"'default'" << tok::colon
814 Diag(ExpectedLoc, diag::err_expected_after)
815 <<
"'default'" << tok::colon
817 ColonLoc = ExpectedLoc;
822 if (Tok.
isNot(tok::r_brace)) {
823 SubStmt = ParseStatement(
nullptr,
829 Diag(AfterColonLoc, diag::err_label_end_of_compound_statement)
835 if (SubStmt.isInvalid())
842 StmtResult Parser::ParseCompoundStatement(
bool isStmtExpr) {
868 StmtResult Parser::ParseCompoundStatement(
bool isStmtExpr,
869 unsigned ScopeFlags) {
870 assert(Tok.
is(tok::l_brace) &&
"Not a compount stmt!");
874 ParseScope CompoundScope(
this, ScopeFlags);
877 return ParseCompoundStatementBody(isStmtExpr);
883 void Parser::ParseCompoundStatementLeadingPragmas() {
884 bool checkForPragmas =
true;
885 while (checkForPragmas) {
887 case tok::annot_pragma_vis:
888 HandlePragmaVisibility();
890 case tok::annot_pragma_pack:
893 case tok::annot_pragma_msstruct:
894 HandlePragmaMSStruct();
896 case tok::annot_pragma_align:
899 case tok::annot_pragma_weak:
902 case tok::annot_pragma_weakalias:
903 HandlePragmaWeakAlias();
905 case tok::annot_pragma_redefine_extname:
906 HandlePragmaRedefineExtname();
908 case tok::annot_pragma_opencl_extension:
909 HandlePragmaOpenCLExtension();
911 case tok::annot_pragma_fp_contract:
912 HandlePragmaFPContract();
914 case tok::annot_pragma_fp:
917 case tok::annot_pragma_ms_pointers_to_members:
918 HandlePragmaMSPointersToMembers();
920 case tok::annot_pragma_ms_pragma:
921 HandlePragmaMSPragma();
923 case tok::annot_pragma_ms_vtordisp:
924 HandlePragmaMSVtorDisp();
926 case tok::annot_pragma_dump:
930 checkForPragmas =
false;
941 StmtResult Parser::ParseCompoundStatementBody(
bool isStmtExpr) {
944 "in compound statement ('{}')");
958 ParseCompoundStatementLeadingPragmas();
964 while (Tok.
is(tok::kw___label__)) {
969 if (Tok.
isNot(tok::identifier)) {
970 Diag(Tok, diag::err_expected) << tok::identifier;
987 ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
989 Stmts.push_back(R.get());
992 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
994 if (Tok.
is(tok::annot_pragma_unused)) {
995 HandlePragmaUnused();
1000 if (Tok.
isNot(tok::kw___extension__)) {
1001 R = ParseStatementOrDeclaration(Stmts, ACK_Any);
1008 while (Tok.
is(tok::kw___extension__))
1011 ParsedAttributesWithRange attrs(AttrFactory);
1012 MaybeParseCXX11Attributes(attrs,
nullptr,
1016 if (isDeclarationStatement()) {
1027 ExprResult Res(ParseExpressionWithLeadingExtension(ExtLoc));
1029 if (Res.isInvalid()) {
1037 ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
1043 Stmts.push_back(R.get());
1049 if (!T.consumeClose())
1052 CloseLoc = T.getCloseLocation();
1070 bool Parser::ParseParenExprOrCondition(
StmtResult *InitStmt,
1078 Cond = ParseCXXCondition(InitStmt, Loc, CK);
1096 if (Tok.
isNot(tok::r_paren))
1106 while (Tok.
is(tok::r_paren)) {
1107 Diag(Tok, diag::err_extraneous_rparen_in_condition)
1124 assert(Tok.
is(tok::kw_if) &&
"Not an if stmt!");
1127 bool IsConstexpr =
false;
1128 if (Tok.
is(tok::kw_constexpr)) {
1130 : diag::ext_constexpr_if);
1135 if (Tok.
isNot(tok::l_paren)) {
1136 Diag(Tok, diag::err_expected_lparen_after) <<
"if";
1160 if (ParseParenExprOrCondition(&InitStmt, Cond, IfLoc,
1198 ConstexprCondition && !*ConstexprCondition);
1199 ThenStmt = ParseStatement(&InnerStatementTrailingElseLoc);
1210 if (Tok.
is(tok::kw_else)) {
1211 if (TrailingElseLoc)
1227 Tok.
is(tok::l_brace));
1232 ConstexprCondition && *ConstexprCondition);
1233 ElseStmt = ParseStatement();
1237 }
else if (Tok.
is(tok::code_completion)) {
1241 }
else if (InnerStatementTrailingElseLoc.
isValid()) {
1242 Diag(InnerStatementTrailingElseLoc, diag::warn_dangling_else);
1250 if ((ThenStmt.isInvalid() && ElseStmt.isInvalid()) ||
1251 (ThenStmt.isInvalid() && ElseStmt.get() ==
nullptr) ||
1252 (ThenStmt.get() ==
nullptr && ElseStmt.isInvalid())) {
1258 if (ThenStmt.isInvalid())
1260 if (ElseStmt.isInvalid())
1263 return Actions.
ActOnIfStmt(IfLoc, IsConstexpr, InitStmt.get(), Cond,
1264 ThenStmt.
get(), ElseLoc, ElseStmt.get());
1272 assert(Tok.
is(tok::kw_switch) &&
"Not a switch stmt!");
1275 if (Tok.
isNot(tok::l_paren)) {
1276 Diag(Tok, diag::err_expected_lparen_after) <<
"switch";
1298 ParseScope SwitchScope(
this, ScopeFlags);
1303 if (ParseParenExprOrCondition(&InitStmt, Cond, SwitchLoc,
1310 if (Switch.isInvalid()) {
1315 if (Tok.
is(tok::l_brace)) {
1343 StmtResult Body(ParseStatement(TrailingElseLoc));
1357 assert(Tok.
is(tok::kw_while) &&
"Not a while stmt!");
1361 if (Tok.
isNot(tok::l_paren)) {
1362 Diag(Tok, diag::err_expected_lparen_after) <<
"while";
1381 unsigned ScopeFlags;
1387 ParseScope WhileScope(
this, ScopeFlags);
1391 if (ParseParenExprOrCondition(
nullptr, Cond, WhileLoc,
1392 Sema::ConditionKind::Boolean))
1409 StmtResult Body(ParseStatement(TrailingElseLoc));
1415 if (Cond.
isInvalid() || Body.isInvalid())
1426 assert(Tok.
is(tok::kw_do) &&
"Not a do stmt!");
1431 unsigned ScopeFlags;
1437 ParseScope DoScope(
this, ScopeFlags);
1456 if (Tok.
isNot(tok::kw_while)) {
1457 if (!Body.isInvalid()) {
1458 Diag(Tok, diag::err_expected_while);
1459 Diag(DoLoc, diag::note_matching) <<
"'do'";
1466 if (Tok.
isNot(tok::l_paren)) {
1467 Diag(Tok, diag::err_expected_lparen_after) <<
"do/while";
1477 DiagnoseAndSkipCXX11Attributes();
1483 if (Cond.
isInvalid() || Body.isInvalid())
1486 return Actions.
ActOnDoStmt(DoLoc, Body.get(), WhileLoc, T.getOpenLocation(),
1487 Cond.
get(), T.getCloseLocation());
1490 bool Parser::isForRangeIdentifier() {
1491 assert(Tok.
is(tok::identifier));
1494 if (Next.is(tok::colon))
1497 if (Next.isOneOf(tok::l_square, tok::kw_alignas)) {
1498 TentativeParsingAction PA(*
this);
1500 SkipCXX11Attributes();
1532 assert(Tok.
is(tok::kw_for) &&
"Not a for stmt!");
1536 if (Tok.
is(tok::kw_co_await))
1539 if (Tok.
isNot(tok::l_paren)) {
1540 Diag(Tok, diag::err_expected_lparen_after) <<
"for";
1563 unsigned ScopeFlags = 0;
1567 ParseScope ForScope(
this, ScopeFlags);
1574 bool ForEach =
false, ForRange =
false;
1578 ForRangeInit ForRangeInit;
1581 if (Tok.
is(tok::code_completion)) {
1589 ParsedAttributesWithRange attrs(AttrFactory);
1590 MaybeParseCXX11Attributes(attrs);
1593 if (Tok.
is(tok::semi)) {
1594 ProhibitAttributes(attrs);
1598 isForRangeIdentifier()) {
1599 ProhibitAttributes(attrs);
1602 MaybeParseCXX11Attributes(attrs);
1605 if (Tok.
is(tok::l_brace))
1606 ForRangeInit.RangeExpr = ParseBraceInitializer();
1610 Diag(Loc, diag::err_for_range_identifier)
1616 attrs, attrs.Range.getEnd());
1618 }
else if (isForInitDeclaration()) {
1620 if (!C99orCXXorObjC)
1621 Diag(Tok, diag::ext_c99_variable_decl_in_for_loop);
1624 bool MightBeForRangeStmt =
getLangOpts().CPlusPlus;
1630 MightBeForRangeStmt ? &ForRangeInit :
nullptr);
1632 if (ForRangeInit.ParsedForRangeDecl()) {
1634 diag::warn_cxx98_compat_for_range : diag::ext_for_range);
1637 }
else if (Tok.
is(tok::semi)) {
1639 }
else if ((ForEach = isTokIdentifier_in())) {
1644 if (Tok.
is(tok::code_completion)) {
1651 Diag(Tok, diag::err_expected_semi_for);
1654 ProhibitAttributes(attrs);
1657 ForEach = isTokIdentifier_in();
1667 if (Tok.
is(tok::semi)) {
1669 }
else if (ForEach) {
1672 if (Tok.
is(tok::code_completion)) {
1681 Diag(Tok, diag::err_for_range_expected_decl)
1682 << FirstPart.get()->getSourceRange();
1687 Diag(Tok, diag::err_expected_semi_for);
1691 if (Tok.
is(tok::semi))
1699 if (!ForEach && !ForRange && !SecondPart.
isInvalid()) {
1701 if (Tok.
is(tok::semi)) {
1703 }
else if (Tok.
is(tok::r_paren)) {
1708 ParseCXXCondition(
nullptr, ForLoc, Sema::ConditionKind::Boolean);
1720 if (Tok.
isNot(tok::semi)) {
1722 Diag(Tok, diag::err_expected_semi_for);
1728 if (Tok.
is(tok::semi)) {
1733 if (Tok.
isNot(tok::r_paren)) {
1745 if (CoawaitLoc.
isValid() && !ForRange) {
1746 Diag(CoawaitLoc, diag::err_for_co_await_not_range_for);
1760 getCurScope(), ForLoc, CoawaitLoc, FirstPart.get(),
1761 ForRangeInit.ColonLoc, CorrectedRange.
get(),
1766 }
else if (ForEach) {
1770 T.getCloseLocation());
1774 if (
getLangOpts().OpenMP && FirstPart.isUsable()) {
1791 Tok.
is(tok::l_brace));
1801 StmtResult Body(ParseStatement(TrailingElseLoc));
1809 if (Body.isInvalid())
1819 return Actions.
ActOnForStmt(ForLoc, T.getOpenLocation(), FirstPart.get(),
1820 SecondPart, ThirdPart, T.getCloseLocation(),
1832 assert(Tok.
is(tok::kw_goto) &&
"Not a goto stmt!");
1836 if (Tok.
is(tok::identifier)) {
1841 }
else if (Tok.
is(tok::star)) {
1843 Diag(Tok, diag::ext_gnu_indirect_goto);
1846 if (R.isInvalid()) {
1852 Diag(Tok, diag::err_expected) << tok::identifier;
1865 StmtResult Parser::ParseContinueStatement() {
1888 assert((Tok.
is(tok::kw_return) || Tok.
is(tok::kw_co_return)) &&
1889 "Not a return stmt!");
1890 bool IsCoreturn = Tok.
is(tok::kw_co_return);
1894 if (Tok.
isNot(tok::semi)) {
1896 if (Tok.
is(tok::code_completion) && !IsCoreturn) {
1903 R = ParseInitializer();
1906 diag::warn_cxx98_compat_generalized_initializer_lists :
1907 diag::ext_generalized_initializer_lists)
1921 StmtResult Parser::ParsePragmaLoopHint(StmtVector &Stmts,
1922 AllowedConstructsKind Allowed,
1924 ParsedAttributesWithRange &Attrs) {
1926 ParsedAttributesWithRange TempAttrs(AttrFactory);
1929 while (Tok.
is(tok::annot_pragma_loop_hint)) {
1931 if (!HandlePragmaLoopHint(Hint))
1942 MaybeParseCXX11Attributes(Attrs);
1944 StmtResult S = ParseStatementOrDeclarationAfterAttributes(
1945 Stmts, Allowed, TrailingElseLoc, Attrs);
1947 Attrs.takeAllFrom(TempAttrs);
1951 Decl *Parser::ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope) {
1952 assert(Tok.
is(tok::l_brace));
1956 "parsing function body");
1960 getLangOpts().CPlusPlus && Decl && isa<CXXMethodDecl>(Decl);
1962 PragmaStackSentinel(Actions,
"InternalPragmaState", IsCXXMethod);
1967 StmtResult FnBody(ParseCompoundStatementBody());
1970 if (FnBody.isInvalid()) {
1984 Decl *Parser::ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope) {
1985 assert(Tok.
is(tok::kw_try) &&
"Expected 'try'");
1989 "parsing function try block");
1992 if (Tok.
is(tok::colon))
1993 ParseConstructorInitializer(Decl);
1999 getLangOpts().CPlusPlus && Decl && isa<CXXMethodDecl>(Decl);
2001 PragmaStackSentinel(Actions,
"InternalPragmaState", IsCXXMethod);
2004 StmtResult FnBody(ParseCXXTryBlockCommon(TryLoc,
true));
2007 if (FnBody.isInvalid()) {
2016 bool Parser::trySkippingFunctionBody() {
2017 assert(SkipFunctionBodies &&
2018 "Should only be called when SkipFunctionBodies is enabled");
2026 TentativeParsingAction PA(*
this);
2027 bool IsTryCatch = Tok.
is(tok::kw_try);
2029 bool ErrorInPrologue = ConsumeAndStoreFunctionPrologue(Toks);
2030 if (llvm::any_of(Toks, [](
const Token &Tok) {
2031 return Tok.
is(tok::code_completion);
2036 if (ErrorInPrologue) {
2045 while (IsTryCatch && Tok.
is(tok::kw_catch)) {
2062 assert(Tok.
is(tok::kw_try) &&
"Expected 'try'");
2065 return ParseCXXTryBlockCommon(TryLoc);
2085 if (Tok.
isNot(tok::l_brace))
2086 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
2088 StmtResult TryBlock(ParseCompoundStatement(
false,
2091 if (TryBlock.isInvalid())
2096 if ((Tok.
is(tok::identifier) &&
2098 Tok.
is(tok::kw___finally)) {
2103 Handler = ParseSEHExceptBlock(Loc);
2107 Handler = ParseSEHFinallyBlock(Loc);
2109 if(Handler.isInvalid())
2118 StmtVector Handlers;
2122 DiagnoseAndSkipCXX11Attributes();
2124 if (Tok.
isNot(tok::kw_catch))
2126 while (Tok.
is(tok::kw_catch)) {
2127 StmtResult Handler(ParseCXXCatchBlock(FnTry));
2128 if (!Handler.isInvalid())
2129 Handlers.push_back(Handler.get());
2133 if (Handlers.empty())
2150 StmtResult Parser::ParseCXXCatchBlock(
bool FnCatch) {
2151 assert(Tok.
is(tok::kw_catch) &&
"Expected 'catch'");
2156 if (T.expectAndConsume())
2167 Decl *ExceptionDecl =
nullptr;
2168 if (Tok.
isNot(tok::ellipsis)) {
2169 ParsedAttributesWithRange Attributes(AttrFactory);
2170 MaybeParseCXX11Attributes(Attributes);
2173 DS.takeAttributesFrom(Attributes);
2175 if (ParseCXXTypeSpecifierSeq(DS))
2179 ParseDeclarator(ExDecl);
2185 if (T.getCloseLocation().isInvalid())
2188 if (Tok.
isNot(tok::l_brace))
2189 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
2193 if (Block.isInvalid())
2199 void Parser::ParseMicrosoftIfExistsStatement(StmtVector &Stmts) {
2200 IfExistsCondition
Result;
2201 if (ParseMicrosoftIfExistsCondition(Result))
2208 if (Result.Behavior == IEB_Dependent) {
2209 if (!Tok.
is(tok::l_brace)) {
2210 Diag(Tok, diag::err_expected) << tok::l_brace;
2214 StmtResult Compound = ParseCompoundStatement();
2215 if (Compound.isInvalid())
2223 if (DepResult.isUsable())
2224 Stmts.push_back(DepResult.get());
2229 if (Braces.consumeOpen()) {
2230 Diag(Tok, diag::err_expected) << tok::l_brace;
2234 switch (Result.Behavior) {
2240 llvm_unreachable(
"Dependent case handled above");
2248 while (Tok.
isNot(tok::r_brace)) {
2249 StmtResult R = ParseStatementOrDeclaration(Stmts, ACK_Any);
2251 Stmts.push_back(R.get());
2253 Braces.consumeClose();
2257 MaybeParseGNUAttributes(Attrs);
2262 if (Attrs.
getList()->
getKind() != AttributeList::AT_OpenCLUnrollHint)
2265 if (!(Tok.
is(tok::kw_for) || Tok.
is(tok::kw_while) || Tok.
is(tok::kw_do))) {
2266 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.
SourceManager & getSourceManager() const
IdentifierLoc * PragmaNameLoc
This is the scope of a C++ try statement.
ConditionResult ActOnCondition(Scope *S, SourceLocation Loc, Expr *SubExpr, ConditionKind CK)
Sema::FullExprArg FullExprArg
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
Simple class containing the result of Sema::CorrectTypo.
StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, Decl *ExDecl, Stmt *HandlerBlock)
ActOnCXXCatchBlock - Takes an exception declaration and a handler block and creates a proper catch ha...
const LangOptions & getLangOpts() const
static ConditionResult ConditionError()
Stmt - This represents one statement.
StmtResult ActOnExprStmt(ExprResult Arg)
StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, Stmt *First, Expr *collection, SourceLocation RParenLoc)
StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, Stmt *InitStmt, ConditionResult Cond)
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt * > Elts, bool isStmtExpr)
Decl - This represents one declaration (or definition), e.g.
Defines the PrettyStackTraceEntry class, which is used to make crashes give more contextual informati...
This is a while, do, switch, for, etc that can have break statements embedded into it...
NamespaceDecl - Represent a C++ namespace.
StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope)
StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation CondLParen, Expr *Cond, SourceLocation CondRParen)
void ActOnDefaultCtorInitializers(Decl *CDtorDecl)
RAII object that enters a new expression evaluation context.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Information about one declarator, including the parsed type information and the identifier.
void ActOnForEachDeclStmt(DeclGroupPtrTy Decl)
IdentifierLoc * OptionLoc
Records and restores the FP_CONTRACT state on entry/exit of compound statements.
RAII object that makes sure paren/bracket/brace count is correct after declaration/statement parsing...
StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body)
FinishObjCForCollectionStmt - Attach the body to a objective-C foreach statement. ...
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 ...
void CodeCompleteOrdinaryName(Scope *S, ParserCompletionContext CompletionContext)
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
bool TryConsumeToken(tok::TokenKind Expected)
One of these records is kept for each identifier that is lexed.
AttributeList * getList() const
llvm::PointerUnion< Expr *, IdentifierLoc * > ArgsUnion
A union of the various pointer types that can be passed to an AttributeList as an argument...
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
void decrementMSManglingNumber()
Token - This structure provides full information about a lexed token.
void CodeCompleteCase(Scope *S)
llvm::Optional< bool > getKnownValue() const
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ...
void ActOnAbortSEHFinallyBlock()
The controlling scope in a if/switch/while/for statement.
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...
This is a scope that corresponds to a switch statement.
void ActOnStartSEHFinallyBlock()
This is a while, do, for, which can have continue statements embedded into it.
Code completion occurs within an expression.
StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope)
StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *TheDecl)
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.
LabelDecl * LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, SourceLocation GnuLabelLoc=SourceLocation())
LookupOrCreateLabel - Do a name lookup of a label with the specified name.
tok::TokenKind getKind() const
StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block)
StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope)
Decl * ActOnFinishFunctionBody(Decl *Decl, Stmt *Body)
void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL, bool IncludeCXX11Attributes=true)
ProcessDeclAttributeList - Apply all the decl attributes in the specified attribute list to the speci...
StmtResult ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *LoopVar, SourceLocation ColonLoc, Expr *Collection, SourceLocation RParenLoc, BuildForRangeKind Kind)
ActOnCXXForRangeStmt - Check and build a C++11 for-range statement.
StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, SourceLocation EndLoc)
A RAII object to enter scope of a compound statement.
StmtResult ActOnCoreturnStmt(Scope *S, SourceLocation KwLoc, Expr *E)
virtual bool ValidateCandidate(const TypoCorrection &candidate)
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
Expr - This represents one expression.
NestedNameSpecifier * getCorrectionSpecifier() const
Gets the NestedNameSpecifier needed to use the typo correction.
StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt, Scope *CurScope)
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.
ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, VerifyICEDiagnoser &Diagnoser, bool AllowFold=true)
VerifyIntegerConstantExpression - Verifies that an expression is an ICE, and reports the appropriate ...
void setIsPoisoned(bool Value=true)
setIsPoisoned - Mark this identifier as poisoned.
Initial building of a for-range statement.
Code completion occurs within a statement, which may also be an expression or a declaration.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
bool isNot(tok::TokenKind K) const
StmtResult ActOnNullStmt(SourceLocation SemiLoc, bool HasLeadingEmptyMacro=false)
A boolean condition, from 'if', 'while', 'for', or 'do'.
The result type of a method or function.
StmtResult ProcessStmtAttributes(Stmt *Stmt, AttributeList *Attrs, SourceRange Range)
Stmt attributes - this routine is the top level dispatcher.
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
PrettyDeclStackTraceEntry - If a crash occurs in the parser while parsing something related to a decl...
bool isSwitchScope() const
isSwitchScope - Return true if this scope is a switch scope.
Stop skipping at semicolon.
bool CheckCaseExpression(Expr *E)
void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt)
ActOnCaseStmtBody - This installs a statement as the body of a case.
std::pair< VarDecl *, Expr * > get() const
Encodes a location in the source.
StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, Scope *CurScope)
bool isValid() const
Return true if this is a valid SourceLocation object.
StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, SourceLocation ColonLoc, Stmt *SubStmt)
StmtResult ActOnForEachLValueExpr(Expr *E)
In an Objective C collection iteration statement: for (x in y) x can be an arbitrary l-value expressi...
LabelDecl - Represents the declaration of a label.
Scope * getCurScope() const
void CodeCompleteReturn(Scope *S)
ExtensionRAIIObject - This saves the state of extension warnings when constructed and disables them...
StmtResult ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
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)) {...
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ConditionResult Cond, Stmt *Body)
We are currently in the filter expression of an SEH except block.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Decl * ActOnExceptionDeclarator(Scope *S, Declarator &D)
ActOnExceptionDeclarator - Parsed the exception-declarator in a C++ catch handler.
StmtResult ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *First, ConditionResult Second, FullExprArg Third, SourceLocation RParenLoc, Stmt *Body)
StmtResult ActOnExprStmtError()
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
A constant boolean condition from 'if constexpr'.
StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *DestExp)
detail::InMemoryDirectory::const_iterator E
DeclClass * getCorrectionDeclAs() const
StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, CXXScopeSpec &SS, UnqualifiedId &Name, Stmt *Nested)
StmtResult ActOnFinishFullStmt(Stmt *Stmt)
StmtResult ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal, SourceLocation DotDotDotLoc, Expr *RHSVal, SourceLocation ColonLoc)
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)
void CodeCompleteObjCForCollection(Scope *S, DeclGroupPtrTy IterationVar)
ActionResult< Stmt * > StmtResult
bool hasLeadingEmptyMacro() const
Return true if this token has an empty macro before it.
DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, ArrayRef< Decl * > Group)
bool isCodeCompletionEnabled() const
Determine if we are performing code completion.
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.
StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc, IdentifierInfo *Ident, ParsedAttributes &Attrs, SourceLocation AttrEnd)
This is a scope that can contain a declaration.
ExprResult ParseConstantExpression(TypeCastState isTypeCast=NotTypeCast)
An integral condition for a 'switch' statement.
Captures information about "declaration specifiers".
Code completion occurs at the beginning of the initialization statement (or expression) in a for loop...
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, 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...
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
FinishCXXForRangeStmt - Attach the body to a C++0x for-range 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...
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.
FullExprArg MakeFullDiscardedValueExpr(Expr *Arg)
SourceLocation getLocStart() const LLVM_READONLY
void CodeCompleteAfterIf(Scope *S)
ParsedAttributes - A collection of parsed attributes.
StmtResult ActOnIfStmt(SourceLocation IfLoc, bool IsConstexpr, Stmt *InitStmt, ConditionResult Cond, Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal)
SourceLocation ColonLoc
Location of ':'.
An RAII object for [un]poisoning an identifier within a scope.
StmtResult ActOnSEHTryBlock(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
AttributeList - Represents a syntactic attribute.
Stop skipping at specified token, but don't skip the token itself.
IdentifierInfo * getIdentifierInfo() const