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);
110 if (!MaybeParseOpenCLUnrollHintAttribute(Attrs))
113 StmtResult Res = ParseStatementOrDeclarationAfterAttributes(
114 Stmts, Allowed, TrailingElseLoc, Attrs);
116 assert((Attrs.empty() || Res.isInvalid() || Res.isUsable()) &&
117 "attributes on empty statement");
119 if (Attrs.empty() || Res.isInvalid())
128 StatementFilterCCC(
Token nextTok) : NextToken(nextTok) {
129 WantTypeSpecifiers = nextTok.
isOneOf(tok::l_paren, tok::less, tok::l_square,
130 tok::identifier, tok::star, tok::amp);
131 WantExpressionKeywords =
132 nextTok.
isOneOf(tok::l_paren, tok::identifier, tok::arrow, tok::period);
133 WantRemainingKeywords =
134 nextTok.
isOneOf(tok::l_paren, tok::semi, tok::identifier, tok::l_brace);
135 WantCXXNamedCasts =
false;
138 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
141 if (NextToken.is(tok::equal))
143 if (NextToken.is(tok::period) &&
155 Parser::ParseStatementOrDeclarationAfterAttributes(StmtVector &Stmts,
157 ParsedAttributesWithRange &Attrs) {
158 const char *SemiError =
nullptr;
170 ProhibitAttributes(Attrs);
172 return ParseObjCAtStatement(AtLoc);
175 case tok::code_completion:
180 case tok::identifier: {
182 if (Next.
is(tok::colon)) {
184 return ParseLabeledStatement(Attrs);
189 if (Next.
isNot(tok::coloncolon)) {
192 if (TryAnnotateName(
false,
193 llvm::make_unique<StatementFilterCCC>(Next)) ==
198 if (Tok.
is(tok::semi))
204 if (Tok.
isNot(tok::identifier))
213 isDeclarationStatement()) {
220 if (Tok.
is(tok::r_brace)) {
221 Diag(Tok, diag::err_expected_statement);
225 return ParseExprStatement();
229 return ParseCaseStatement();
230 case tok::kw_default:
231 return ParseDefaultStatement();
234 return ParseCompoundStatement();
241 return ParseIfStatement(TrailingElseLoc);
243 return ParseSwitchStatement(TrailingElseLoc);
246 return ParseWhileStatement(TrailingElseLoc);
248 Res = ParseDoStatement();
249 SemiError =
"do/while";
252 return ParseForStatement(TrailingElseLoc);
255 Res = ParseGotoStatement();
258 case tok::kw_continue:
259 Res = ParseContinueStatement();
260 SemiError =
"continue";
263 Res = ParseBreakStatement();
267 Res = ParseReturnStatement();
268 SemiError =
"return";
270 case tok::kw_co_return:
271 Res = ParseReturnStatement();
272 SemiError =
"co_return";
276 ProhibitAttributes(Attrs);
278 Res = ParseAsmStatement(msAsm);
280 if (msAsm)
return Res;
285 case tok::kw___if_exists:
286 case tok::kw___if_not_exists:
287 ProhibitAttributes(Attrs);
288 ParseMicrosoftIfExistsStatement(Stmts);
294 return ParseCXXTryBlock();
297 ProhibitAttributes(Attrs);
298 return ParseSEHTryBlock();
300 case tok::kw___leave:
301 Res = ParseSEHLeaveStatement();
302 SemiError =
"__leave";
305 case tok::annot_pragma_vis:
306 ProhibitAttributes(Attrs);
307 HandlePragmaVisibility();
310 case tok::annot_pragma_pack:
311 ProhibitAttributes(Attrs);
315 case tok::annot_pragma_msstruct:
316 ProhibitAttributes(Attrs);
317 HandlePragmaMSStruct();
320 case tok::annot_pragma_align:
321 ProhibitAttributes(Attrs);
325 case tok::annot_pragma_weak:
326 ProhibitAttributes(Attrs);
330 case tok::annot_pragma_weakalias:
331 ProhibitAttributes(Attrs);
332 HandlePragmaWeakAlias();
335 case tok::annot_pragma_redefine_extname:
336 ProhibitAttributes(Attrs);
337 HandlePragmaRedefineExtname();
340 case tok::annot_pragma_fp_contract:
341 ProhibitAttributes(Attrs);
342 Diag(Tok, diag::err_pragma_fp_contract_scope);
346 case tok::annot_pragma_opencl_extension:
347 ProhibitAttributes(Attrs);
348 HandlePragmaOpenCLExtension();
351 case tok::annot_pragma_captured:
352 ProhibitAttributes(Attrs);
353 return HandlePragmaCaptured();
355 case tok::annot_pragma_openmp:
356 ProhibitAttributes(Attrs);
357 return ParseOpenMPDeclarativeOrExecutableDirective(Allowed);
359 case tok::annot_pragma_ms_pointers_to_members:
360 ProhibitAttributes(Attrs);
361 HandlePragmaMSPointersToMembers();
364 case tok::annot_pragma_ms_pragma:
365 ProhibitAttributes(Attrs);
366 HandlePragmaMSPragma();
369 case tok::annot_pragma_ms_vtordisp:
370 ProhibitAttributes(Attrs);
371 HandlePragmaMSVtorDisp();
374 case tok::annot_pragma_loop_hint:
375 ProhibitAttributes(Attrs);
376 return ParsePragmaLoopHint(Stmts, Allowed, TrailingElseLoc, Attrs);
378 case tok::annot_pragma_dump:
388 ExpectAndConsume(tok::semi, diag::err_expected_semi_after_stmt, SemiError);
399 Token OldToken = Tok;
403 if (
Expr.isInvalid()) {
408 if (Tok.
is(tok::semi))
417 Diag(OldToken, diag::err_expected_case_before_expression)
421 return ParseCaseStatement(
true,
Expr);
425 ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
439 assert(Tok.
is(tok::kw___try) &&
"Expected '__try'");
442 if (Tok.
isNot(tok::l_brace))
443 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
445 StmtResult TryBlock(ParseCompoundStatement(
false,
447 if(TryBlock.isInvalid())
451 if (Tok.
is(tok::identifier) &&
454 Handler = ParseSEHExceptBlock(Loc);
455 }
else if (Tok.
is(tok::kw___finally)) {
457 Handler = ParseSEHFinallyBlock(Loc);
462 if(Handler.isInvalid())
478 raii2(Ident___exception_code,
false),
479 raii3(Ident_GetExceptionCode,
false);
481 if (ExpectAndConsume(tok::l_paren))
495 ParseScopeFlags FilterScope(
this,
getCurScope()->getFlags() |
509 if (ExpectAndConsume(tok::r_paren))
512 if (Tok.
isNot(tok::l_brace))
513 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
517 if(Block.isInvalid())
530 raii2(Ident___abnormal_termination,
false),
531 raii3(Ident_AbnormalTermination,
false);
533 if (Tok.
isNot(tok::l_brace))
534 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
536 ParseScope FinallyScope(
this, 0);
540 if(Block.isInvalid()) {
564 StmtResult Parser::ParseLabeledStatement(ParsedAttributesWithRange &attrs) {
566 "Not an identifier!");
568 Token IdentTok = Tok;
571 assert(Tok.
is(tok::colon) &&
"Not a label!");
578 if (Tok.
is(tok::kw___attribute)) {
579 ParsedAttributesWithRange TempAttrs(AttrFactory);
580 ParseGNUAttributes(TempAttrs);
590 attrs.takeAllFrom(TempAttrs);
591 else if (isDeclarationStatement()) {
597 SubStmt = ParseStatementOrDeclarationAfterAttributes(
598 Stmts, ACK_StatementsOpenMPNonStandalone,
nullptr,
600 if (!TempAttrs.empty() && !SubStmt.isInvalid())
602 SubStmt.get(), TempAttrs.getList(), TempAttrs.Range);
604 Diag(Tok, diag::err_expected_after) <<
"__attribute__" << tok::semi;
609 if (!SubStmt.isInvalid() && !SubStmt.isUsable())
610 SubStmt = ParseStatement();
613 if (SubStmt.isInvalid())
617 IdentTok.getLocation());
633 assert((MissingCase || Tok.
is(tok::kw_case)) &&
"Not a case stmt!");
656 Stmt *DeepestParsedCaseStmt =
nullptr;
665 if (Tok.
is(tok::code_completion)) {
702 Diag(DotDotDotLoc, diag::ext_gnu_case_range);
713 ColonProtection.restore();
719 Diag(ColonLoc, diag::err_expected_after)
720 <<
"'case'" << tok::colon
724 Diag(ExpectedLoc, diag::err_expected_after)
725 <<
"'case'" << tok::colon
727 ColonLoc = ExpectedLoc;
736 if (Case.isInvalid()) {
737 if (TopLevelCase.isInvalid())
738 return ParseStatement(
nullptr,
744 Stmt *NextDeepest = Case.get();
745 if (TopLevelCase.isInvalid())
749 DeepestParsedCaseStmt = NextDeepest;
753 }
while (Tok.
is(tok::kw_case));
758 if (Tok.
isNot(tok::r_brace)) {
759 SubStmt = ParseStatement(
nullptr,
767 Diag(AfterColonLoc, diag::err_label_end_of_compound_statement)
774 if (DeepestParsedCaseStmt) {
776 if (SubStmt.isInvalid())
791 assert(Tok.
is(tok::kw_default) &&
"Not a default stmt!");
798 Diag(ColonLoc, diag::err_expected_after)
799 <<
"'default'" << tok::colon
803 Diag(ExpectedLoc, diag::err_expected_after)
804 <<
"'default'" << tok::colon
806 ColonLoc = ExpectedLoc;
811 if (Tok.
isNot(tok::r_brace)) {
812 SubStmt = ParseStatement(
nullptr,
818 Diag(AfterColonLoc, diag::err_label_end_of_compound_statement)
824 if (SubStmt.isInvalid())
831 StmtResult Parser::ParseCompoundStatement(
bool isStmtExpr) {
857 StmtResult Parser::ParseCompoundStatement(
bool isStmtExpr,
858 unsigned ScopeFlags) {
859 assert(Tok.
is(tok::l_brace) &&
"Not a compount stmt!");
863 ParseScope CompoundScope(
this, ScopeFlags);
866 return ParseCompoundStatementBody(isStmtExpr);
872 void Parser::ParseCompoundStatementLeadingPragmas() {
873 bool checkForPragmas =
true;
874 while (checkForPragmas) {
876 case tok::annot_pragma_vis:
877 HandlePragmaVisibility();
879 case tok::annot_pragma_pack:
882 case tok::annot_pragma_msstruct:
883 HandlePragmaMSStruct();
885 case tok::annot_pragma_align:
888 case tok::annot_pragma_weak:
891 case tok::annot_pragma_weakalias:
892 HandlePragmaWeakAlias();
894 case tok::annot_pragma_redefine_extname:
895 HandlePragmaRedefineExtname();
897 case tok::annot_pragma_opencl_extension:
898 HandlePragmaOpenCLExtension();
900 case tok::annot_pragma_fp_contract:
901 HandlePragmaFPContract();
903 case tok::annot_pragma_ms_pointers_to_members:
904 HandlePragmaMSPointersToMembers();
906 case tok::annot_pragma_ms_pragma:
907 HandlePragmaMSPragma();
909 case tok::annot_pragma_ms_vtordisp:
910 HandlePragmaMSVtorDisp();
912 case tok::annot_pragma_dump:
916 checkForPragmas =
false;
927 StmtResult Parser::ParseCompoundStatementBody(
bool isStmtExpr) {
930 "in compound statement ('{}')");
944 ParseCompoundStatementLeadingPragmas();
950 while (Tok.
is(tok::kw___label__)) {
955 if (Tok.
isNot(tok::identifier)) {
956 Diag(Tok, diag::err_expected) << tok::identifier;
973 ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
975 Stmts.push_back(R.get());
978 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
980 if (Tok.
is(tok::annot_pragma_unused)) {
981 HandlePragmaUnused();
986 if (Tok.
isNot(tok::kw___extension__)) {
987 R = ParseStatementOrDeclaration(Stmts, ACK_Any);
994 while (Tok.
is(tok::kw___extension__))
997 ParsedAttributesWithRange attrs(AttrFactory);
998 MaybeParseCXX11Attributes(attrs,
nullptr,
1002 if (isDeclarationStatement()) {
1013 ExprResult Res(ParseExpressionWithLeadingExtension(ExtLoc));
1015 if (Res.isInvalid()) {
1023 ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
1029 Stmts.push_back(R.get());
1035 if (!T.consumeClose())
1038 CloseLoc = T.getCloseLocation();
1056 bool Parser::ParseParenExprOrCondition(
StmtResult *InitStmt,
1064 Cond = ParseCXXCondition(InitStmt, Loc, CK);
1082 if (Tok.
isNot(tok::r_paren))
1092 while (Tok.
is(tok::r_paren)) {
1093 Diag(Tok, diag::err_extraneous_rparen_in_condition)
1110 assert(Tok.
is(tok::kw_if) &&
"Not an if stmt!");
1113 bool IsConstexpr =
false;
1114 if (Tok.
is(tok::kw_constexpr)) {
1116 : diag::ext_constexpr_if);
1121 if (Tok.
isNot(tok::l_paren)) {
1122 Diag(Tok, diag::err_expected_lparen_after) <<
"if";
1146 if (ParseParenExprOrCondition(&InitStmt, Cond, IfLoc,
1183 ConstexprCondition && !*ConstexprCondition);
1184 ThenStmt = ParseStatement(&InnerStatementTrailingElseLoc);
1195 if (Tok.
is(tok::kw_else)) {
1196 if (TrailingElseLoc)
1212 Tok.
is(tok::l_brace));
1216 ConstexprCondition && *ConstexprCondition);
1217 ElseStmt = ParseStatement();
1221 }
else if (Tok.
is(tok::code_completion)) {
1225 }
else if (InnerStatementTrailingElseLoc.
isValid()) {
1226 Diag(InnerStatementTrailingElseLoc, diag::warn_dangling_else);
1234 if ((ThenStmt.isInvalid() && ElseStmt.isInvalid()) ||
1235 (ThenStmt.isInvalid() && ElseStmt.get() ==
nullptr) ||
1236 (ThenStmt.get() ==
nullptr && ElseStmt.isInvalid())) {
1242 if (ThenStmt.isInvalid())
1244 if (ElseStmt.isInvalid())
1247 return Actions.
ActOnIfStmt(IfLoc, IsConstexpr, InitStmt.get(), Cond,
1248 ThenStmt.
get(), ElseLoc, ElseStmt.get());
1256 assert(Tok.
is(tok::kw_switch) &&
"Not a switch stmt!");
1259 if (Tok.
isNot(tok::l_paren)) {
1260 Diag(Tok, diag::err_expected_lparen_after) <<
"switch";
1282 ParseScope SwitchScope(
this, ScopeFlags);
1287 if (ParseParenExprOrCondition(&InitStmt, Cond, SwitchLoc,
1294 if (Switch.isInvalid()) {
1299 if (Tok.
is(tok::l_brace)) {
1327 StmtResult Body(ParseStatement(TrailingElseLoc));
1341 assert(Tok.
is(tok::kw_while) &&
"Not a while stmt!");
1345 if (Tok.
isNot(tok::l_paren)) {
1346 Diag(Tok, diag::err_expected_lparen_after) <<
"while";
1365 unsigned ScopeFlags;
1371 ParseScope WhileScope(
this, ScopeFlags);
1375 if (ParseParenExprOrCondition(
nullptr, Cond, WhileLoc,
1376 Sema::ConditionKind::Boolean))
1393 StmtResult Body(ParseStatement(TrailingElseLoc));
1399 if (Cond.
isInvalid() || Body.isInvalid())
1410 assert(Tok.
is(tok::kw_do) &&
"Not a do stmt!");
1415 unsigned ScopeFlags;
1421 ParseScope DoScope(
this, ScopeFlags);
1440 if (Tok.
isNot(tok::kw_while)) {
1441 if (!Body.isInvalid()) {
1442 Diag(Tok, diag::err_expected_while);
1443 Diag(DoLoc, diag::note_matching) <<
"'do'";
1450 if (Tok.
isNot(tok::l_paren)) {
1451 Diag(Tok, diag::err_expected_lparen_after) <<
"do/while";
1461 DiagnoseAndSkipCXX11Attributes();
1467 if (Cond.
isInvalid() || Body.isInvalid())
1470 return Actions.
ActOnDoStmt(DoLoc, Body.get(), WhileLoc, T.getOpenLocation(),
1471 Cond.
get(), T.getCloseLocation());
1474 bool Parser::isForRangeIdentifier() {
1475 assert(Tok.
is(tok::identifier));
1478 if (Next.is(tok::colon))
1481 if (Next.isOneOf(tok::l_square, tok::kw_alignas)) {
1482 TentativeParsingAction PA(*
this);
1484 SkipCXX11Attributes();
1516 assert(Tok.
is(tok::kw_for) &&
"Not a for stmt!");
1520 if (Tok.
is(tok::kw_co_await))
1523 if (Tok.
isNot(tok::l_paren)) {
1524 Diag(Tok, diag::err_expected_lparen_after) <<
"for";
1547 unsigned ScopeFlags = 0;
1551 ParseScope ForScope(
this, ScopeFlags);
1558 bool ForEach =
false, ForRange =
false;
1562 ForRangeInit ForRangeInit;
1565 if (Tok.
is(tok::code_completion)) {
1573 ParsedAttributesWithRange attrs(AttrFactory);
1574 MaybeParseCXX11Attributes(attrs);
1577 if (Tok.
is(tok::semi)) {
1578 ProhibitAttributes(attrs);
1582 isForRangeIdentifier()) {
1583 ProhibitAttributes(attrs);
1586 MaybeParseCXX11Attributes(attrs);
1589 if (Tok.
is(tok::l_brace))
1590 ForRangeInit.RangeExpr = ParseBraceInitializer();
1594 Diag(Loc, diag::err_for_range_identifier)
1600 attrs, attrs.Range.getEnd());
1602 }
else if (isForInitDeclaration()) {
1604 if (!C99orCXXorObjC)
1605 Diag(Tok, diag::ext_c99_variable_decl_in_for_loop);
1608 bool MightBeForRangeStmt =
getLangOpts().CPlusPlus;
1614 MightBeForRangeStmt ? &ForRangeInit :
nullptr);
1616 if (ForRangeInit.ParsedForRangeDecl()) {
1618 diag::warn_cxx98_compat_for_range : diag::ext_for_range);
1621 }
else if (Tok.
is(tok::semi)) {
1623 }
else if ((ForEach = isTokIdentifier_in())) {
1628 if (Tok.
is(tok::code_completion)) {
1635 Diag(Tok, diag::err_expected_semi_for);
1638 ProhibitAttributes(attrs);
1641 ForEach = isTokIdentifier_in();
1651 if (Tok.
is(tok::semi)) {
1653 }
else if (ForEach) {
1656 if (Tok.
is(tok::code_completion)) {
1665 Diag(Tok, diag::err_for_range_expected_decl)
1666 << FirstPart.get()->getSourceRange();
1671 Diag(Tok, diag::err_expected_semi_for);
1675 if (Tok.
is(tok::semi))
1683 if (!ForEach && !ForRange && !SecondPart.
isInvalid()) {
1685 if (Tok.
is(tok::semi)) {
1687 }
else if (Tok.
is(tok::r_paren)) {
1692 ParseCXXCondition(
nullptr, ForLoc, Sema::ConditionKind::Boolean);
1704 if (Tok.
isNot(tok::semi)) {
1706 Diag(Tok, diag::err_expected_semi_for);
1712 if (Tok.
is(tok::semi)) {
1717 if (Tok.
isNot(tok::r_paren)) {
1729 if (CoawaitLoc.
isValid() && !ForRange) {
1730 Diag(CoawaitLoc, diag::err_for_co_await_not_range_for);
1744 getCurScope(), ForLoc, CoawaitLoc, FirstPart.get(),
1745 ForRangeInit.ColonLoc, CorrectedRange.
get(),
1750 }
else if (ForEach) {
1754 T.getCloseLocation());
1758 if (
getLangOpts().OpenMP && FirstPart.isUsable()) {
1775 Tok.
is(tok::l_brace));
1785 StmtResult Body(ParseStatement(TrailingElseLoc));
1793 if (Body.isInvalid())
1803 return Actions.
ActOnForStmt(ForLoc, T.getOpenLocation(), FirstPart.get(),
1804 SecondPart, ThirdPart, T.getCloseLocation(),
1816 assert(Tok.
is(tok::kw_goto) &&
"Not a goto stmt!");
1820 if (Tok.
is(tok::identifier)) {
1825 }
else if (Tok.
is(tok::star)) {
1827 Diag(Tok, diag::ext_gnu_indirect_goto);
1830 if (R.isInvalid()) {
1836 Diag(Tok, diag::err_expected) << tok::identifier;
1849 StmtResult Parser::ParseContinueStatement() {
1872 assert((Tok.
is(tok::kw_return) || Tok.
is(tok::kw_co_return)) &&
1873 "Not a return stmt!");
1874 bool IsCoreturn = Tok.
is(tok::kw_co_return);
1878 if (Tok.
isNot(tok::semi)) {
1880 if (Tok.
is(tok::code_completion) && !IsCoreturn) {
1887 R = ParseInitializer();
1890 diag::warn_cxx98_compat_generalized_initializer_lists :
1891 diag::ext_generalized_initializer_lists)
1892 << R.
get()->getSourceRange();
1905 StmtResult Parser::ParsePragmaLoopHint(StmtVector &Stmts,
1906 AllowedContsructsKind Allowed,
1908 ParsedAttributesWithRange &Attrs) {
1910 ParsedAttributesWithRange TempAttrs(AttrFactory);
1913 while (Tok.
is(tok::annot_pragma_loop_hint)) {
1915 if (!HandlePragmaLoopHint(Hint))
1926 MaybeParseCXX11Attributes(Attrs);
1928 StmtResult S = ParseStatementOrDeclarationAfterAttributes(
1929 Stmts, Allowed, TrailingElseLoc, Attrs);
1931 Attrs.takeAllFrom(TempAttrs);
1935 Decl *Parser::ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope) {
1936 assert(Tok.
is(tok::l_brace));
1940 "parsing function body");
1944 getLangOpts().CPlusPlus && Decl && isa<CXXMethodDecl>(Decl);
1946 PragmaStackSentinel(Actions,
"InternalPragmaState", IsCXXMethod);
1951 StmtResult FnBody(ParseCompoundStatementBody());
1954 if (FnBody.isInvalid()) {
1968 Decl *Parser::ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope) {
1969 assert(Tok.
is(tok::kw_try) &&
"Expected 'try'");
1973 "parsing function try block");
1976 if (Tok.
is(tok::colon))
1977 ParseConstructorInitializer(Decl);
1983 getLangOpts().CPlusPlus && Decl && isa<CXXMethodDecl>(Decl);
1985 PragmaStackSentinel(Actions,
"InternalPragmaState", IsCXXMethod);
1988 StmtResult FnBody(ParseCXXTryBlockCommon(TryLoc,
true));
1991 if (FnBody.isInvalid()) {
2000 bool Parser::trySkippingFunctionBody() {
2001 assert(SkipFunctionBodies &&
2002 "Should only be called when SkipFunctionBodies is enabled");
2010 TentativeParsingAction PA(*
this);
2011 bool IsTryCatch = Tok.
is(tok::kw_try);
2013 bool ErrorInPrologue = ConsumeAndStoreFunctionPrologue(Toks);
2014 if (llvm::any_of(Toks, [](
const Token &Tok) {
2015 return Tok.
is(tok::code_completion);
2020 if (ErrorInPrologue) {
2029 while (IsTryCatch && Tok.
is(tok::kw_catch)) {
2046 assert(Tok.
is(tok::kw_try) &&
"Expected 'try'");
2049 return ParseCXXTryBlockCommon(TryLoc);
2069 if (Tok.
isNot(tok::l_brace))
2070 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
2072 StmtResult TryBlock(ParseCompoundStatement(
false,
2075 if (TryBlock.isInvalid())
2080 if ((Tok.
is(tok::identifier) &&
2082 Tok.
is(tok::kw___finally)) {
2087 Handler = ParseSEHExceptBlock(Loc);
2091 Handler = ParseSEHFinallyBlock(Loc);
2093 if(Handler.isInvalid())
2102 StmtVector Handlers;
2106 DiagnoseAndSkipCXX11Attributes();
2108 if (Tok.
isNot(tok::kw_catch))
2110 while (Tok.
is(tok::kw_catch)) {
2111 StmtResult Handler(ParseCXXCatchBlock(FnTry));
2112 if (!Handler.isInvalid())
2113 Handlers.push_back(Handler.get());
2117 if (Handlers.empty())
2134 StmtResult Parser::ParseCXXCatchBlock(
bool FnCatch) {
2135 assert(Tok.
is(tok::kw_catch) &&
"Expected 'catch'");
2140 if (T.expectAndConsume())
2151 Decl *ExceptionDecl =
nullptr;
2152 if (Tok.
isNot(tok::ellipsis)) {
2153 ParsedAttributesWithRange Attributes(AttrFactory);
2154 MaybeParseCXX11Attributes(Attributes);
2157 DS.takeAttributesFrom(Attributes);
2159 if (ParseCXXTypeSpecifierSeq(DS))
2163 ParseDeclarator(ExDecl);
2169 if (T.getCloseLocation().isInvalid())
2172 if (Tok.
isNot(tok::l_brace))
2173 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
2177 if (Block.isInvalid())
2183 void Parser::ParseMicrosoftIfExistsStatement(StmtVector &Stmts) {
2184 IfExistsCondition
Result;
2185 if (ParseMicrosoftIfExistsCondition(Result))
2192 if (Result.Behavior == IEB_Dependent) {
2193 if (!Tok.
is(tok::l_brace)) {
2194 Diag(Tok, diag::err_expected) << tok::l_brace;
2198 StmtResult Compound = ParseCompoundStatement();
2199 if (Compound.isInvalid())
2207 if (DepResult.isUsable())
2208 Stmts.push_back(DepResult.get());
2213 if (Braces.consumeOpen()) {
2214 Diag(Tok, diag::err_expected) << tok::l_brace;
2218 switch (Result.Behavior) {
2224 llvm_unreachable(
"Dependent case handled above");
2232 while (Tok.
isNot(tok::r_brace)) {
2233 StmtResult R = ParseStatementOrDeclaration(Stmts, ACK_Any);
2235 Stmts.push_back(R.get());
2237 Braces.consumeClose();
2241 MaybeParseGNUAttributes(Attrs);
2246 if (Attrs.
getList()->
getKind() != AttributeList::AT_OpenCLUnrollHint)
2249 if (!(Tok.
is(tok::kw_for) || Tok.
is(tok::kw_while) || Tok.
is(tok::kw_do))) {
2250 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
Defines the clang::ASTContext interface.
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()
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)
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.
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. ...
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. ...
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...
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.
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
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)
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.
The current expression occurs within a discarded statement.
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)
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