26 #include "llvm/ADT/SmallString.h"
27 using namespace clang;
36 bool AllowOpenMPStandalone) {
43 Res = ParseStatementOrDeclaration(
44 Stmts, AllowOpenMPStandalone ? ACK_StatementsOpenMPAnyExecutable
45 : ACK_StatementsOpenMPNonStandalone,
47 }
while (!Res.isInvalid() && !Res.get());
102 Parser::ParseStatementOrDeclaration(StmtVector &Stmts,
103 AllowedContsructsKind Allowed,
108 ParsedAttributesWithRange Attrs(AttrFactory);
109 MaybeParseCXX11Attributes(Attrs,
nullptr,
true);
111 StmtResult Res = ParseStatementOrDeclarationAfterAttributes(
112 Stmts, Allowed, TrailingElseLoc, Attrs);
114 assert((Attrs.empty() || Res.isInvalid() || Res.isUsable()) &&
115 "attributes on empty statement");
117 if (Attrs.empty() || Res.isInvalid())
126 StatementFilterCCC(
Token nextTok) : NextToken(nextTok) {
127 WantTypeSpecifiers = nextTok.
isOneOf(tok::l_paren, tok::less, tok::l_square,
128 tok::identifier, tok::star, tok::amp);
129 WantExpressionKeywords =
130 nextTok.
isOneOf(tok::l_paren, tok::identifier, tok::arrow, tok::period);
131 WantRemainingKeywords =
132 nextTok.
isOneOf(tok::l_paren, tok::semi, tok::identifier, tok::l_brace);
133 WantCXXNamedCasts =
false;
136 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
139 if (NextToken.is(tok::equal))
141 if (NextToken.is(tok::period) &&
153 Parser::ParseStatementOrDeclarationAfterAttributes(StmtVector &Stmts,
155 ParsedAttributesWithRange &Attrs) {
156 const char *SemiError =
nullptr;
168 ProhibitAttributes(Attrs);
170 return ParseObjCAtStatement(AtLoc);
173 case tok::code_completion:
178 case tok::identifier: {
180 if (Next.
is(tok::colon)) {
182 return ParseLabeledStatement(Attrs);
187 if (Next.
isNot(tok::coloncolon)) {
190 if (TryAnnotateName(
false,
191 llvm::make_unique<StatementFilterCCC>(Next)) ==
196 if (Tok.
is(tok::semi))
202 if (Tok.
isNot(tok::identifier))
211 isDeclarationStatement()) {
218 if (Tok.
is(tok::r_brace)) {
219 Diag(Tok, diag::err_expected_statement);
223 return ParseExprStatement();
227 return ParseCaseStatement();
228 case tok::kw_default:
229 return ParseDefaultStatement();
232 return ParseCompoundStatement();
239 return ParseIfStatement(TrailingElseLoc);
241 return ParseSwitchStatement(TrailingElseLoc);
244 return ParseWhileStatement(TrailingElseLoc);
246 Res = ParseDoStatement();
247 SemiError =
"do/while";
250 return ParseForStatement(TrailingElseLoc);
253 Res = ParseGotoStatement();
256 case tok::kw_continue:
257 Res = ParseContinueStatement();
258 SemiError =
"continue";
261 Res = ParseBreakStatement();
265 Res = ParseReturnStatement();
266 SemiError =
"return";
268 case tok::kw_co_return:
269 Res = ParseReturnStatement();
270 SemiError =
"co_return";
274 ProhibitAttributes(Attrs);
276 Res = ParseAsmStatement(msAsm);
278 if (msAsm)
return Res;
283 case tok::kw___if_exists:
284 case tok::kw___if_not_exists:
285 ProhibitAttributes(Attrs);
286 ParseMicrosoftIfExistsStatement(Stmts);
292 return ParseCXXTryBlock();
295 ProhibitAttributes(Attrs);
296 return ParseSEHTryBlock();
298 case tok::kw___leave:
299 Res = ParseSEHLeaveStatement();
300 SemiError =
"__leave";
303 case tok::annot_pragma_vis:
304 ProhibitAttributes(Attrs);
305 HandlePragmaVisibility();
308 case tok::annot_pragma_pack:
309 ProhibitAttributes(Attrs);
313 case tok::annot_pragma_msstruct:
314 ProhibitAttributes(Attrs);
315 HandlePragmaMSStruct();
318 case tok::annot_pragma_align:
319 ProhibitAttributes(Attrs);
323 case tok::annot_pragma_weak:
324 ProhibitAttributes(Attrs);
328 case tok::annot_pragma_weakalias:
329 ProhibitAttributes(Attrs);
330 HandlePragmaWeakAlias();
333 case tok::annot_pragma_redefine_extname:
334 ProhibitAttributes(Attrs);
335 HandlePragmaRedefineExtname();
338 case tok::annot_pragma_fp_contract:
339 ProhibitAttributes(Attrs);
340 Diag(Tok, diag::err_pragma_fp_contract_scope);
344 case tok::annot_pragma_opencl_extension:
345 ProhibitAttributes(Attrs);
346 HandlePragmaOpenCLExtension();
349 case tok::annot_pragma_captured:
350 ProhibitAttributes(Attrs);
351 return HandlePragmaCaptured();
353 case tok::annot_pragma_openmp:
354 ProhibitAttributes(Attrs);
355 return ParseOpenMPDeclarativeOrExecutableDirective(Allowed);
357 case tok::annot_pragma_ms_pointers_to_members:
358 ProhibitAttributes(Attrs);
359 HandlePragmaMSPointersToMembers();
362 case tok::annot_pragma_ms_pragma:
363 ProhibitAttributes(Attrs);
364 HandlePragmaMSPragma();
367 case tok::annot_pragma_ms_vtordisp:
368 ProhibitAttributes(Attrs);
369 HandlePragmaMSVtorDisp();
372 case tok::annot_pragma_loop_hint:
373 ProhibitAttributes(Attrs);
374 return ParsePragmaLoopHint(Stmts, Allowed, TrailingElseLoc, Attrs);
376 case tok::annot_pragma_dump:
386 ExpectAndConsume(tok::semi, diag::err_expected_semi_after_stmt, SemiError);
397 Token OldToken = Tok;
401 if (
Expr.isInvalid()) {
406 if (Tok.
is(tok::semi))
415 Diag(OldToken, diag::err_expected_case_before_expression)
419 return ParseCaseStatement(
true,
Expr);
423 ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
437 assert(Tok.
is(tok::kw___try) &&
"Expected '__try'");
440 if (Tok.
isNot(tok::l_brace))
441 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
443 StmtResult TryBlock(ParseCompoundStatement(
false,
445 if(TryBlock.isInvalid())
449 if (Tok.
is(tok::identifier) &&
452 Handler = ParseSEHExceptBlock(Loc);
453 }
else if (Tok.
is(tok::kw___finally)) {
455 Handler = ParseSEHFinallyBlock(Loc);
460 if(Handler.isInvalid())
476 raii2(Ident___exception_code,
false),
477 raii3(Ident_GetExceptionCode,
false);
479 if (ExpectAndConsume(tok::l_paren))
493 ParseScopeFlags FilterScope(
this,
getCurScope()->getFlags() |
507 if (ExpectAndConsume(tok::r_paren))
510 if (Tok.
isNot(tok::l_brace))
511 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
515 if(Block.isInvalid())
528 raii2(Ident___abnormal_termination,
false),
529 raii3(Ident_AbnormalTermination,
false);
531 if (Tok.
isNot(tok::l_brace))
532 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
534 ParseScope FinallyScope(
this, 0);
538 if(Block.isInvalid()) {
562 StmtResult Parser::ParseLabeledStatement(ParsedAttributesWithRange &attrs) {
564 "Not an identifier!");
566 Token IdentTok = Tok;
569 assert(Tok.
is(tok::colon) &&
"Not a label!");
576 if (Tok.
is(tok::kw___attribute)) {
577 ParsedAttributesWithRange TempAttrs(AttrFactory);
578 ParseGNUAttributes(TempAttrs);
588 attrs.takeAllFrom(TempAttrs);
589 else if (isDeclarationStatement()) {
595 SubStmt = ParseStatementOrDeclarationAfterAttributes(
596 Stmts, ACK_StatementsOpenMPNonStandalone,
nullptr,
598 if (!TempAttrs.empty() && !SubStmt.isInvalid())
600 SubStmt.get(), TempAttrs.getList(), TempAttrs.Range);
602 Diag(Tok, diag::err_expected_after) <<
"__attribute__" << tok::semi;
607 if (!SubStmt.isInvalid() && !SubStmt.isUsable())
608 SubStmt = ParseStatement();
611 if (SubStmt.isInvalid())
615 IdentTok.getLocation());
631 assert((MissingCase || Tok.
is(tok::kw_case)) &&
"Not a case stmt!");
654 Stmt *DeepestParsedCaseStmt =
nullptr;
663 if (Tok.
is(tok::code_completion)) {
700 Diag(DotDotDotLoc, diag::ext_gnu_case_range);
711 ColonProtection.restore();
717 Diag(ColonLoc, diag::err_expected_after)
718 <<
"'case'" << tok::colon
722 Diag(ExpectedLoc, diag::err_expected_after)
723 <<
"'case'" << tok::colon
725 ColonLoc = ExpectedLoc;
734 if (Case.isInvalid()) {
735 if (TopLevelCase.isInvalid())
736 return ParseStatement(
nullptr,
742 Stmt *NextDeepest = Case.get();
743 if (TopLevelCase.isInvalid())
747 DeepestParsedCaseStmt = NextDeepest;
751 }
while (Tok.
is(tok::kw_case));
756 if (Tok.
isNot(tok::r_brace)) {
757 SubStmt = ParseStatement(
nullptr,
765 Diag(AfterColonLoc, diag::err_label_end_of_compound_statement)
772 if (DeepestParsedCaseStmt) {
774 if (SubStmt.isInvalid())
789 assert(Tok.
is(tok::kw_default) &&
"Not a default stmt!");
796 Diag(ColonLoc, diag::err_expected_after)
797 <<
"'default'" << tok::colon
801 Diag(ExpectedLoc, diag::err_expected_after)
802 <<
"'default'" << tok::colon
804 ColonLoc = ExpectedLoc;
809 if (Tok.
isNot(tok::r_brace)) {
810 SubStmt = ParseStatement(
nullptr,
816 Diag(AfterColonLoc, diag::err_label_end_of_compound_statement)
822 if (SubStmt.isInvalid())
829 StmtResult Parser::ParseCompoundStatement(
bool isStmtExpr) {
855 StmtResult Parser::ParseCompoundStatement(
bool isStmtExpr,
856 unsigned ScopeFlags) {
857 assert(Tok.
is(tok::l_brace) &&
"Not a compount stmt!");
861 ParseScope CompoundScope(
this, ScopeFlags);
864 return ParseCompoundStatementBody(isStmtExpr);
870 void Parser::ParseCompoundStatementLeadingPragmas() {
871 bool checkForPragmas =
true;
872 while (checkForPragmas) {
874 case tok::annot_pragma_vis:
875 HandlePragmaVisibility();
877 case tok::annot_pragma_pack:
880 case tok::annot_pragma_msstruct:
881 HandlePragmaMSStruct();
883 case tok::annot_pragma_align:
886 case tok::annot_pragma_weak:
889 case tok::annot_pragma_weakalias:
890 HandlePragmaWeakAlias();
892 case tok::annot_pragma_redefine_extname:
893 HandlePragmaRedefineExtname();
895 case tok::annot_pragma_opencl_extension:
896 HandlePragmaOpenCLExtension();
898 case tok::annot_pragma_fp_contract:
899 HandlePragmaFPContract();
901 case tok::annot_pragma_ms_pointers_to_members:
902 HandlePragmaMSPointersToMembers();
904 case tok::annot_pragma_ms_pragma:
905 HandlePragmaMSPragma();
907 case tok::annot_pragma_ms_vtordisp:
908 HandlePragmaMSVtorDisp();
910 case tok::annot_pragma_dump:
914 checkForPragmas =
false;
925 StmtResult Parser::ParseCompoundStatementBody(
bool isStmtExpr) {
928 "in compound statement ('{}')");
942 ParseCompoundStatementLeadingPragmas();
948 while (Tok.
is(tok::kw___label__)) {
953 if (Tok.
isNot(tok::identifier)) {
954 Diag(Tok, diag::err_expected) << tok::identifier;
971 ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
973 Stmts.push_back(R.get());
976 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
978 if (Tok.
is(tok::annot_pragma_unused)) {
979 HandlePragmaUnused();
984 if (Tok.
isNot(tok::kw___extension__)) {
985 R = ParseStatementOrDeclaration(Stmts, ACK_Any);
992 while (Tok.
is(tok::kw___extension__))
995 ParsedAttributesWithRange attrs(AttrFactory);
996 MaybeParseCXX11Attributes(attrs,
nullptr,
1000 if (isDeclarationStatement()) {
1011 ExprResult Res(ParseExpressionWithLeadingExtension(ExtLoc));
1013 if (Res.isInvalid()) {
1021 ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
1027 Stmts.push_back(R.get());
1033 if (!T.consumeClose())
1036 CloseLoc = T.getCloseLocation();
1056 bool ConvertToBoolean) {
1061 ParseCXXCondition(ExprResult, DeclResult, Loc, ConvertToBoolean);
1064 DeclResult =
nullptr;
1067 if (!ExprResult.
isInvalid() && ConvertToBoolean)
1075 if (ExprResult.
isInvalid() && !DeclResult && Tok.
isNot(tok::r_paren)) {
1079 if (Tok.
isNot(tok::r_paren))
1089 while (Tok.
is(tok::r_paren)) {
1090 Diag(Tok, diag::err_extraneous_rparen_in_condition)
1107 assert(Tok.
is(tok::kw_if) &&
"Not an if stmt!");
1110 if (Tok.
isNot(tok::l_paren)) {
1111 Diag(Tok, diag::err_expected_lparen_after) <<
"if";
1134 Decl *CondVar =
nullptr;
1135 if (ParseParenExprOrCondition(CondExp, CondVar, IfLoc,
true))
1164 StmtResult ThenStmt(ParseStatement(&InnerStatementTrailingElseLoc));
1174 if (Tok.
is(tok::kw_else)) {
1175 if (TrailingElseLoc)
1192 ElseStmt = ParseStatement();
1196 }
else if (Tok.
is(tok::code_completion)) {
1200 }
else if (InnerStatementTrailingElseLoc.
isValid()) {
1201 Diag(InnerStatementTrailingElseLoc, diag::warn_dangling_else);
1209 if ((ThenStmt.isInvalid() && ElseStmt.isInvalid()) ||
1210 (ThenStmt.isInvalid() && ElseStmt.get() ==
nullptr) ||
1211 (ThenStmt.get() ==
nullptr && ElseStmt.isInvalid())) {
1217 if (ThenStmt.isInvalid())
1219 if (ElseStmt.isInvalid())
1222 return Actions.
ActOnIfStmt(IfLoc, FullCondExp, CondVar, ThenStmt.get(),
1223 ElseLoc, ElseStmt.get());
1231 assert(Tok.
is(tok::kw_switch) &&
"Not a switch stmt!");
1234 if (Tok.
isNot(tok::l_paren)) {
1235 Diag(Tok, diag::err_expected_lparen_after) <<
"switch";
1257 ParseScope SwitchScope(
this, ScopeFlags);
1261 Decl *CondVar =
nullptr;
1262 if (ParseParenExprOrCondition(Cond, CondVar, SwitchLoc,
false))
1268 if (Switch.isInvalid()) {
1273 if (Tok.
is(tok::l_brace)) {
1301 StmtResult Body(ParseStatement(TrailingElseLoc));
1315 assert(Tok.
is(tok::kw_while) &&
"Not a while stmt!");
1319 if (Tok.
isNot(tok::l_paren)) {
1320 Diag(Tok, diag::err_expected_lparen_after) <<
"while";
1339 unsigned ScopeFlags;
1345 ParseScope WhileScope(
this, ScopeFlags);
1349 Decl *CondVar =
nullptr;
1350 if (ParseParenExprOrCondition(Cond, CondVar, WhileLoc,
true))
1369 StmtResult Body(ParseStatement(TrailingElseLoc));
1375 if ((Cond.
isInvalid() && !CondVar) || Body.isInvalid())
1378 return Actions.
ActOnWhileStmt(WhileLoc, FullCond, CondVar, Body.get());
1386 assert(Tok.
is(tok::kw_do) &&
"Not a do stmt!");
1391 unsigned ScopeFlags;
1397 ParseScope DoScope(
this, ScopeFlags);
1416 if (Tok.
isNot(tok::kw_while)) {
1417 if (!Body.isInvalid()) {
1418 Diag(Tok, diag::err_expected_while);
1419 Diag(DoLoc, diag::note_matching) <<
"'do'";
1426 if (Tok.
isNot(tok::l_paren)) {
1427 Diag(Tok, diag::err_expected_lparen_after) <<
"do/while";
1437 DiagnoseAndSkipCXX11Attributes();
1443 if (Cond.
isInvalid() || Body.isInvalid())
1446 return Actions.
ActOnDoStmt(DoLoc, Body.get(), WhileLoc, T.getOpenLocation(),
1447 Cond.
get(), T.getCloseLocation());
1450 bool Parser::isForRangeIdentifier() {
1451 assert(Tok.
is(tok::identifier));
1454 if (Next.is(tok::colon))
1457 if (Next.isOneOf(tok::l_square, tok::kw_alignas)) {
1458 TentativeParsingAction PA(*
this);
1460 SkipCXX11Attributes();
1492 assert(Tok.
is(tok::kw_for) &&
"Not a for stmt!");
1496 if (Tok.
is(tok::kw_co_await))
1499 if (Tok.
isNot(tok::l_paren)) {
1500 Diag(Tok, diag::err_expected_lparen_after) <<
"for";
1523 unsigned ScopeFlags = 0;
1527 ParseScope ForScope(
this, ScopeFlags);
1534 bool ForEach =
false, ForRange =
false;
1536 bool SecondPartIsInvalid =
false;
1538 ExprResult Collection;
1539 ForRangeInit ForRangeInit;
1541 Decl *SecondVar =
nullptr;
1543 if (Tok.
is(tok::code_completion)) {
1551 ParsedAttributesWithRange attrs(AttrFactory);
1552 MaybeParseCXX11Attributes(attrs);
1555 if (Tok.
is(tok::semi)) {
1556 ProhibitAttributes(attrs);
1560 isForRangeIdentifier()) {
1561 ProhibitAttributes(attrs);
1564 MaybeParseCXX11Attributes(attrs);
1567 if (Tok.
is(tok::l_brace))
1568 ForRangeInit.RangeExpr = ParseBraceInitializer();
1572 Diag(Loc, diag::err_for_range_identifier)
1578 attrs, attrs.Range.getEnd());
1580 }
else if (isForInitDeclaration()) {
1582 if (!C99orCXXorObjC)
1583 Diag(Tok, diag::ext_c99_variable_decl_in_for_loop);
1586 bool MightBeForRangeStmt =
getLangOpts().CPlusPlus;
1592 MightBeForRangeStmt ? &ForRangeInit :
nullptr);
1594 if (ForRangeInit.ParsedForRangeDecl()) {
1596 diag::warn_cxx98_compat_for_range : diag::ext_for_range);
1599 }
else if (Tok.
is(tok::semi)) {
1601 }
else if ((ForEach = isTokIdentifier_in())) {
1606 if (Tok.
is(tok::code_completion)) {
1613 Diag(Tok, diag::err_expected_semi_for);
1616 ProhibitAttributes(attrs);
1619 ForEach = isTokIdentifier_in();
1629 if (Tok.
is(tok::semi)) {
1631 }
else if (ForEach) {
1634 if (Tok.
is(tok::code_completion)) {
1643 Diag(Tok, diag::err_for_range_expected_decl)
1644 << FirstPart.get()->getSourceRange();
1646 SecondPartIsInvalid =
true;
1649 Diag(Tok, diag::err_expected_semi_for);
1653 if (Tok.
is(tok::semi))
1661 if (!ForEach && !ForRange) {
1662 assert(!SecondPart.get() &&
"Shouldn't have a second expression yet.");
1664 if (Tok.
is(tok::semi)) {
1666 }
else if (Tok.
is(tok::r_paren)) {
1671 ParseCXXCondition(Second, SecondVar, ForLoc,
true);
1678 SecondPartIsInvalid = Second.
isInvalid();
1682 if (Tok.
isNot(tok::semi)) {
1683 if (!SecondPartIsInvalid || SecondVar)
1684 Diag(Tok, diag::err_expected_semi_for);
1690 if (Tok.
is(tok::semi)) {
1695 if (Tok.
isNot(tok::r_paren)) {
1707 if (CoawaitLoc.
isValid() && !ForRange) {
1708 Diag(CoawaitLoc, diag::err_for_co_await_not_range_for);
1720 getCurScope(), ForLoc, CoawaitLoc, FirstPart.get(),
1721 ForRangeInit.ColonLoc, ForRangeInit.RangeExpr.get(),
1726 }
else if (ForEach) {
1730 T.getCloseLocation());
1734 if (
getLangOpts().OpenMP && FirstPart.isUsable()) {
1751 Tok.
is(tok::l_brace));
1761 StmtResult Body(ParseStatement(TrailingElseLoc));
1769 if (Body.isInvalid())
1779 return Actions.
ActOnForStmt(ForLoc, T.getOpenLocation(), FirstPart.get(),
1780 SecondPart, SecondVar, ThirdPart,
1781 T.getCloseLocation(), Body.get());
1792 assert(Tok.
is(tok::kw_goto) &&
"Not a goto stmt!");
1796 if (Tok.
is(tok::identifier)) {
1801 }
else if (Tok.
is(tok::star)) {
1803 Diag(Tok, diag::ext_gnu_indirect_goto);
1806 if (R.isInvalid()) {
1812 Diag(Tok, diag::err_expected) << tok::identifier;
1825 StmtResult Parser::ParseContinueStatement() {
1848 assert((Tok.
is(tok::kw_return) || Tok.
is(tok::kw_co_return)) &&
1849 "Not a return stmt!");
1850 bool IsCoreturn = Tok.
is(tok::kw_co_return);
1854 if (Tok.
isNot(tok::semi)) {
1856 if (Tok.
is(tok::code_completion) && !IsCoreturn) {
1863 R = ParseInitializer();
1866 diag::warn_cxx98_compat_generalized_initializer_lists :
1867 diag::ext_generalized_initializer_lists)
1868 << R.
get()->getSourceRange();
1881 StmtResult Parser::ParsePragmaLoopHint(StmtVector &Stmts,
1882 AllowedContsructsKind Allowed,
1884 ParsedAttributesWithRange &Attrs) {
1886 ParsedAttributesWithRange TempAttrs(AttrFactory);
1889 while (Tok.
is(tok::annot_pragma_loop_hint)) {
1891 if (!HandlePragmaLoopHint(Hint))
1902 MaybeParseCXX11Attributes(Attrs);
1904 StmtResult S = ParseStatementOrDeclarationAfterAttributes(
1905 Stmts, Allowed, TrailingElseLoc, Attrs);
1907 Attrs.takeAllFrom(TempAttrs);
1911 Decl *Parser::ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope) {
1912 assert(Tok.
is(tok::l_brace));
1916 trySkippingFunctionBody()) {
1922 "parsing function body");
1926 getLangOpts().CPlusPlus && Decl && isa<CXXMethodDecl>(Decl);
1932 StmtResult FnBody(ParseCompoundStatementBody());
1935 if (FnBody.isInvalid()) {
1949 Decl *Parser::ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope) {
1950 assert(Tok.
is(tok::kw_try) &&
"Expected 'try'");
1954 "parsing function try block");
1957 if (Tok.
is(tok::colon))
1958 ParseConstructorInitializer(Decl);
1963 trySkippingFunctionBody()) {
1970 getLangOpts().CPlusPlus && Decl && isa<CXXMethodDecl>(Decl);
1974 StmtResult FnBody(ParseCXXTryBlockCommon(TryLoc,
true));
1977 if (FnBody.isInvalid()) {
1986 bool Parser::trySkippingFunctionBody() {
1987 assert(Tok.
is(tok::l_brace));
1988 assert(SkipFunctionBodies &&
1989 "Should only be called when SkipFunctionBodies is enabled");
1999 TentativeParsingAction PA(*
this);
2016 assert(Tok.
is(tok::kw_try) &&
"Expected 'try'");
2019 return ParseCXXTryBlockCommon(TryLoc);
2039 if (Tok.
isNot(tok::l_brace))
2040 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
2042 StmtResult TryBlock(ParseCompoundStatement(
false,
2045 if (TryBlock.isInvalid())
2050 if ((Tok.
is(tok::identifier) &&
2052 Tok.
is(tok::kw___finally)) {
2057 Handler = ParseSEHExceptBlock(Loc);
2061 Handler = ParseSEHFinallyBlock(Loc);
2063 if(Handler.isInvalid())
2072 StmtVector Handlers;
2076 DiagnoseAndSkipCXX11Attributes();
2078 if (Tok.
isNot(tok::kw_catch))
2080 while (Tok.
is(tok::kw_catch)) {
2081 StmtResult Handler(ParseCXXCatchBlock(FnTry));
2082 if (!Handler.isInvalid())
2083 Handlers.push_back(Handler.get());
2087 if (Handlers.empty())
2104 StmtResult Parser::ParseCXXCatchBlock(
bool FnCatch) {
2105 assert(Tok.
is(tok::kw_catch) &&
"Expected 'catch'");
2110 if (T.expectAndConsume())
2121 Decl *ExceptionDecl =
nullptr;
2122 if (Tok.
isNot(tok::ellipsis)) {
2123 ParsedAttributesWithRange Attributes(AttrFactory);
2124 MaybeParseCXX11Attributes(Attributes);
2127 DS.takeAttributesFrom(Attributes);
2129 if (ParseCXXTypeSpecifierSeq(DS))
2133 ParseDeclarator(ExDecl);
2139 if (T.getCloseLocation().isInvalid())
2142 if (Tok.
isNot(tok::l_brace))
2143 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
2147 if (Block.isInvalid())
2153 void Parser::ParseMicrosoftIfExistsStatement(StmtVector &Stmts) {
2154 IfExistsCondition
Result;
2155 if (ParseMicrosoftIfExistsCondition(Result))
2162 if (Result.Behavior == IEB_Dependent) {
2163 if (!Tok.
is(tok::l_brace)) {
2164 Diag(Tok, diag::err_expected) << tok::l_brace;
2168 StmtResult Compound = ParseCompoundStatement();
2169 if (Compound.isInvalid())
2177 if (DepResult.isUsable())
2178 Stmts.push_back(DepResult.get());
2183 if (Braces.consumeOpen()) {
2184 Diag(Tok, diag::err_expected) << tok::l_brace;
2188 switch (Result.Behavior) {
2194 llvm_unreachable(
"Dependent case handled above");
2202 while (Tok.
isNot(tok::r_brace)) {
2203 StmtResult R = ParseStatementOrDeclaration(Stmts, ACK_Any);
2205 Stmts.push_back(R.get());
2207 Braces.consumeClose();
void AddFlags(unsigned Flags)
Sets up the specified scope flags and adjusts the scope state variables accordingly.
SourceManager & getSourceManager() const
Defines the clang::ASTContext interface.
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.
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
FullExprArg MakeFullExpr(Expr *Arg)
StmtResult ActOnExprStmt(ExprResult Arg)
StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, Stmt *First, Expr *collection, SourceLocation RParenLoc)
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...
Records and restores the vtordisp state on entry/exit of C++ method body.
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)
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.
StmtResult ActOnCoreturnStmt(SourceLocation KwLoc, Expr *E)
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. ...
bool canSkipFunctionBody(Decl *D)
Determine whether we can skip parsing the body of a function definition, assuming we don't care about...
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.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
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...
StmtResult ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *First, FullExprArg Second, Decl *SecondVar, FullExprArg Third, SourceLocation RParenLoc, Stmt *Body)
void decrementMSManglingNumber()
Token - This structure provides full information about a lexed token.
void CodeCompleteCase(Scope *S)
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.
ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc, Expr *SubExpr)
A location where the result (returned value) of evaluating a statement should be stored.
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...
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 ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, Decl *CondVar, Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal)
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...
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. ...
StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, Expr *Cond, Decl *CondVar)
bool isNot(tok::TokenKind K) const
StmtResult ActOnNullStmt(SourceLocation SemiLoc, bool HasLeadingEmptyMacro=false)
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...
Decl * ActOnSkippedFunctionBody(Decl *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.
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)) {...
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 ActOnExprStmtError()
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *DestExp)
detail::InMemoryDirectory::const_iterator E
DeclClass * getCorrectionDeclAs() const
Defines the Diagnostic-related interfaces.
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)
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)
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...
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)
void CodeCompleteAfterIf(Scope *S)
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.
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, FullExprArg Cond, Decl *CondVar, Stmt *Body)
IdentifierInfo * getIdentifierInfo() const