26 #include "llvm/ADT/SmallString.h"
27 using namespace clang;
42 Res = ParseStatementOrDeclaration(Stmts,
true, TrailingElseLoc);
98 Parser::ParseStatementOrDeclaration(StmtVector &Stmts,
bool OnlyStatement,
103 ParsedAttributesWithRange Attrs(AttrFactory);
104 MaybeParseCXX11Attributes(Attrs,
nullptr,
true);
106 StmtResult Res = ParseStatementOrDeclarationAfterAttributes(Stmts,
107 OnlyStatement, TrailingElseLoc, Attrs);
110 "attributes on empty statement");
121 StatementFilterCCC(
Token nextTok) : NextToken(nextTok) {
122 WantTypeSpecifiers = nextTok.
isOneOf(tok::l_paren, tok::less, tok::l_square,
123 tok::identifier, tok::star, tok::amp);
124 WantExpressionKeywords =
125 nextTok.
isOneOf(tok::l_paren, tok::identifier, tok::arrow, tok::period);
126 WantRemainingKeywords =
127 nextTok.
isOneOf(tok::l_paren, tok::semi, tok::identifier, tok::l_brace);
128 WantCXXNamedCasts =
false;
131 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
134 if (NextToken.is(tok::equal))
136 if (NextToken.is(tok::period) &&
148 Parser::ParseStatementOrDeclarationAfterAttributes(StmtVector &Stmts,
150 ParsedAttributesWithRange &Attrs) {
151 const char *SemiError =
nullptr;
163 ProhibitAttributes(Attrs);
165 return ParseObjCAtStatement(AtLoc);
168 case tok::code_completion:
173 case tok::identifier: {
175 if (Next.
is(tok::colon)) {
177 return ParseLabeledStatement(Attrs);
182 if (Next.
isNot(tok::coloncolon)) {
185 if (TryAnnotateName(
false,
186 llvm::make_unique<StatementFilterCCC>(Next)) ==
191 if (Tok.
is(tok::semi))
197 if (Tok.
isNot(tok::identifier))
212 if (Tok.
is(tok::r_brace)) {
213 Diag(Tok, diag::err_expected_statement);
217 return ParseExprStatement();
221 return ParseCaseStatement();
222 case tok::kw_default:
223 return ParseDefaultStatement();
226 return ParseCompoundStatement();
233 return ParseIfStatement(TrailingElseLoc);
235 return ParseSwitchStatement(TrailingElseLoc);
238 return ParseWhileStatement(TrailingElseLoc);
240 Res = ParseDoStatement();
241 SemiError =
"do/while";
244 return ParseForStatement(TrailingElseLoc);
247 Res = ParseGotoStatement();
250 case tok::kw_continue:
251 Res = ParseContinueStatement();
252 SemiError =
"continue";
255 Res = ParseBreakStatement();
259 Res = ParseReturnStatement();
260 SemiError =
"return";
264 ProhibitAttributes(Attrs);
266 Res = ParseAsmStatement(msAsm);
268 if (msAsm)
return Res;
273 case tok::kw___if_exists:
274 case tok::kw___if_not_exists:
275 ProhibitAttributes(Attrs);
276 ParseMicrosoftIfExistsStatement(Stmts);
282 return ParseCXXTryBlock();
285 ProhibitAttributes(Attrs);
286 return ParseSEHTryBlock();
288 case tok::kw___leave:
289 Res = ParseSEHLeaveStatement();
290 SemiError =
"__leave";
293 case tok::annot_pragma_vis:
294 ProhibitAttributes(Attrs);
295 HandlePragmaVisibility();
298 case tok::annot_pragma_pack:
299 ProhibitAttributes(Attrs);
303 case tok::annot_pragma_msstruct:
304 ProhibitAttributes(Attrs);
305 HandlePragmaMSStruct();
308 case tok::annot_pragma_align:
309 ProhibitAttributes(Attrs);
313 case tok::annot_pragma_weak:
314 ProhibitAttributes(Attrs);
318 case tok::annot_pragma_weakalias:
319 ProhibitAttributes(Attrs);
320 HandlePragmaWeakAlias();
323 case tok::annot_pragma_redefine_extname:
324 ProhibitAttributes(Attrs);
325 HandlePragmaRedefineExtname();
328 case tok::annot_pragma_fp_contract:
329 ProhibitAttributes(Attrs);
330 Diag(Tok, diag::err_pragma_fp_contract_scope);
334 case tok::annot_pragma_opencl_extension:
335 ProhibitAttributes(Attrs);
336 HandlePragmaOpenCLExtension();
339 case tok::annot_pragma_captured:
340 ProhibitAttributes(Attrs);
341 return HandlePragmaCaptured();
343 case tok::annot_pragma_openmp:
344 ProhibitAttributes(Attrs);
345 return ParseOpenMPDeclarativeOrExecutableDirective(!OnlyStatement);
347 case tok::annot_pragma_ms_pointers_to_members:
348 ProhibitAttributes(Attrs);
349 HandlePragmaMSPointersToMembers();
352 case tok::annot_pragma_ms_pragma:
353 ProhibitAttributes(Attrs);
354 HandlePragmaMSPragma();
357 case tok::annot_pragma_loop_hint:
358 ProhibitAttributes(Attrs);
359 return ParsePragmaLoopHint(Stmts, OnlyStatement, TrailingElseLoc, Attrs);
367 ExpectAndConsume(tok::semi, diag::err_expected_semi_after_stmt, SemiError);
378 Token OldToken = Tok;
382 if (
Expr.isInvalid()) {
387 if (Tok.
is(tok::semi))
396 Diag(OldToken, diag::err_expected_case_before_expression)
400 return ParseCaseStatement(
true,
Expr);
404 ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
418 assert(Tok.
is(tok::kw___try) &&
"Expected '__try'");
421 if (Tok.
isNot(tok::l_brace))
422 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
424 StmtResult TryBlock(ParseCompoundStatement(
false,
426 if(TryBlock.isInvalid())
430 if (Tok.
is(tok::identifier) &&
433 Handler = ParseSEHExceptBlock(Loc);
434 }
else if (Tok.
is(tok::kw___finally)) {
436 Handler = ParseSEHFinallyBlock(Loc);
457 raii2(Ident___exception_code,
false),
458 raii3(Ident_GetExceptionCode,
false);
460 if (ExpectAndConsume(tok::l_paren))
474 ParseScopeFlags FilterScope(
this,
getCurScope()->getFlags() |
488 if (ExpectAndConsume(tok::r_paren))
491 if (Tok.
isNot(tok::l_brace))
492 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
496 if(Block.isInvalid())
509 raii2(Ident___abnormal_termination,
false),
510 raii3(Ident_AbnormalTermination,
false);
512 if (Tok.
isNot(tok::l_brace))
513 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
515 ParseScope FinallyScope(
this, 0);
519 if(Block.isInvalid()) {
543 StmtResult Parser::ParseLabeledStatement(ParsedAttributesWithRange &attrs) {
545 "Not an identifier!");
547 Token IdentTok = Tok;
550 assert(Tok.
is(tok::colon) &&
"Not a label!");
557 if (Tok.
is(tok::kw___attribute)) {
558 ParsedAttributesWithRange TempAttrs(AttrFactory);
559 ParseGNUAttributes(TempAttrs);
569 attrs.takeAllFrom(TempAttrs);
570 else if (isDeclarationStatement()) {
576 SubStmt = ParseStatementOrDeclarationAfterAttributes(
577 Stmts,
true,
nullptr, TempAttrs);
578 if (!TempAttrs.empty() && !SubStmt.
isInvalid())
580 SubStmt.
get(), TempAttrs.getList(), TempAttrs.Range);
582 Diag(Tok, diag::err_expected_after) <<
"__attribute__" << tok::semi;
588 SubStmt = ParseStatement();
595 IdentTok.getLocation());
611 assert((MissingCase || Tok.
is(tok::kw_case)) &&
"Not a case stmt!");
634 Stmt *DeepestParsedCaseStmt =
nullptr;
643 if (Tok.
is(tok::code_completion)) {
680 Diag(DotDotDotLoc, diag::ext_gnu_case_range);
691 ColonProtection.restore();
697 Diag(ColonLoc, diag::err_expected_after)
698 <<
"'case'" << tok::colon
702 Diag(ExpectedLoc, diag::err_expected_after)
703 <<
"'case'" << tok::colon
705 ColonLoc = ExpectedLoc;
715 if (TopLevelCase.isInvalid())
716 return ParseStatement();
721 Stmt *NextDeepest = Case.
get();
722 if (TopLevelCase.isInvalid())
726 DeepestParsedCaseStmt = NextDeepest;
730 }
while (Tok.
is(tok::kw_case));
735 if (Tok.
isNot(tok::r_brace)) {
736 SubStmt = ParseStatement();
743 Diag(AfterColonLoc, diag::err_label_end_of_compound_statement)
750 if (DeepestParsedCaseStmt) {
767 assert(Tok.
is(tok::kw_default) &&
"Not a default stmt!");
774 Diag(ColonLoc, diag::err_expected_after)
775 <<
"'default'" << tok::colon
779 Diag(ExpectedLoc, diag::err_expected_after)
780 <<
"'default'" << tok::colon
782 ColonLoc = ExpectedLoc;
787 if (Tok.
isNot(tok::r_brace)) {
788 SubStmt = ParseStatement();
793 Diag(AfterColonLoc, diag::err_label_end_of_compound_statement)
806 StmtResult Parser::ParseCompoundStatement(
bool isStmtExpr) {
832 StmtResult Parser::ParseCompoundStatement(
bool isStmtExpr,
833 unsigned ScopeFlags) {
834 assert(Tok.
is(tok::l_brace) &&
"Not a compount stmt!");
838 ParseScope CompoundScope(
this, ScopeFlags);
841 return ParseCompoundStatementBody(isStmtExpr);
847 void Parser::ParseCompoundStatementLeadingPragmas() {
848 bool checkForPragmas =
true;
849 while (checkForPragmas) {
851 case tok::annot_pragma_vis:
852 HandlePragmaVisibility();
854 case tok::annot_pragma_pack:
857 case tok::annot_pragma_msstruct:
858 HandlePragmaMSStruct();
860 case tok::annot_pragma_align:
863 case tok::annot_pragma_weak:
866 case tok::annot_pragma_weakalias:
867 HandlePragmaWeakAlias();
869 case tok::annot_pragma_redefine_extname:
870 HandlePragmaRedefineExtname();
872 case tok::annot_pragma_opencl_extension:
873 HandlePragmaOpenCLExtension();
875 case tok::annot_pragma_fp_contract:
876 HandlePragmaFPContract();
878 case tok::annot_pragma_ms_pointers_to_members:
879 HandlePragmaMSPointersToMembers();
881 case tok::annot_pragma_ms_pragma:
882 HandlePragmaMSPragma();
885 checkForPragmas =
false;
896 StmtResult Parser::ParseCompoundStatementBody(
bool isStmtExpr) {
899 "in compound statement ('{}')");
913 ParseCompoundStatementLeadingPragmas();
919 while (Tok.
is(tok::kw___label__)) {
924 if (Tok.
isNot(tok::identifier)) {
925 Diag(Tok, diag::err_expected) << tok::identifier;
942 ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
944 Stmts.push_back(R.
get());
947 while (Tok.
isNot(tok::r_brace) && !isEofOrEom()) {
948 if (Tok.
is(tok::annot_pragma_unused)) {
949 HandlePragmaUnused();
954 if (Tok.
isNot(tok::kw___extension__)) {
955 R = ParseStatementOrDeclaration(Stmts,
false);
962 while (Tok.
is(tok::kw___extension__))
965 ParsedAttributesWithRange attrs(AttrFactory);
966 MaybeParseCXX11Attributes(attrs,
nullptr,
970 if (isDeclarationStatement()) {
981 ExprResult Res(ParseExpressionWithLeadingExtension(ExtLoc));
983 if (Res.isInvalid()) {
991 ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
997 Stmts.push_back(R.
get());
1003 if (!T.consumeClose())
1006 CloseLoc = T.getCloseLocation();
1026 bool ConvertToBoolean) {
1031 ParseCXXCondition(ExprResult, DeclResult, Loc, ConvertToBoolean);
1034 DeclResult =
nullptr;
1037 if (!ExprResult.
isInvalid() && ConvertToBoolean)
1045 if (ExprResult.
isInvalid() && !DeclResult && Tok.
isNot(tok::r_paren)) {
1049 if (Tok.
isNot(tok::r_paren))
1059 while (Tok.
is(tok::r_paren)) {
1060 Diag(Tok, diag::err_extraneous_rparen_in_condition)
1077 assert(Tok.
is(tok::kw_if) &&
"Not an if stmt!");
1080 if (Tok.
isNot(tok::l_paren)) {
1081 Diag(Tok, diag::err_expected_lparen_after) <<
"if";
1104 Decl *CondVar =
nullptr;
1105 if (ParseParenExprOrCondition(CondExp, CondVar, IfLoc,
true))
1134 StmtResult ThenStmt(ParseStatement(&InnerStatementTrailingElseLoc));
1144 if (Tok.
is(tok::kw_else)) {
1145 if (TrailingElseLoc)
1162 ElseStmt = ParseStatement();
1166 }
else if (Tok.
is(tok::code_completion)) {
1170 }
else if (InnerStatementTrailingElseLoc.
isValid()) {
1171 Diag(InnerStatementTrailingElseLoc, diag::warn_dangling_else);
1179 if ((ThenStmt.isInvalid() && ElseStmt.isInvalid()) ||
1180 (ThenStmt.isInvalid() && ElseStmt.get() ==
nullptr) ||
1181 (ThenStmt.get() ==
nullptr && ElseStmt.isInvalid())) {
1187 if (ThenStmt.isInvalid())
1189 if (ElseStmt.isInvalid())
1192 return Actions.
ActOnIfStmt(IfLoc, FullCondExp, CondVar, ThenStmt.get(),
1193 ElseLoc, ElseStmt.get());
1201 assert(Tok.
is(tok::kw_switch) &&
"Not a switch stmt!");
1204 if (Tok.
isNot(tok::l_paren)) {
1205 Diag(Tok, diag::err_expected_lparen_after) <<
"switch";
1227 ParseScope SwitchScope(
this, ScopeFlags);
1231 Decl *CondVar =
nullptr;
1232 if (ParseParenExprOrCondition(Cond, CondVar, SwitchLoc,
false))
1243 if (Tok.
is(tok::l_brace)) {
1271 StmtResult Body(ParseStatement(TrailingElseLoc));
1285 assert(Tok.
is(tok::kw_while) &&
"Not a while stmt!");
1289 if (Tok.
isNot(tok::l_paren)) {
1290 Diag(Tok, diag::err_expected_lparen_after) <<
"while";
1309 unsigned ScopeFlags;
1315 ParseScope WhileScope(
this, ScopeFlags);
1319 Decl *CondVar =
nullptr;
1320 if (ParseParenExprOrCondition(Cond, CondVar, WhileLoc,
true))
1339 StmtResult Body(ParseStatement(TrailingElseLoc));
1345 if ((Cond.
isInvalid() && !CondVar) || Body.isInvalid())
1348 return Actions.
ActOnWhileStmt(WhileLoc, FullCond, CondVar, Body.get());
1356 assert(Tok.
is(tok::kw_do) &&
"Not a do stmt!");
1361 unsigned ScopeFlags;
1367 ParseScope DoScope(
this, ScopeFlags);
1386 if (Tok.
isNot(tok::kw_while)) {
1387 if (!Body.isInvalid()) {
1388 Diag(Tok, diag::err_expected_while);
1389 Diag(DoLoc, diag::note_matching) <<
"'do'";
1396 if (Tok.
isNot(tok::l_paren)) {
1397 Diag(Tok, diag::err_expected_lparen_after) <<
"do/while";
1407 DiagnoseAndSkipCXX11Attributes();
1413 if (Cond.
isInvalid() || Body.isInvalid())
1416 return Actions.
ActOnDoStmt(DoLoc, Body.get(), WhileLoc, T.getOpenLocation(),
1417 Cond.
get(), T.getCloseLocation());
1420 bool Parser::isForRangeIdentifier() {
1421 assert(Tok.
is(tok::identifier));
1424 if (Next.is(tok::colon))
1427 if (Next.isOneOf(tok::l_square, tok::kw_alignas)) {
1428 TentativeParsingAction PA(*
this);
1430 SkipCXX11Attributes();
1459 assert(Tok.
is(tok::kw_for) &&
"Not a for stmt!");
1462 if (Tok.
isNot(tok::l_paren)) {
1463 Diag(Tok, diag::err_expected_lparen_after) <<
"for";
1486 unsigned ScopeFlags = 0;
1490 ParseScope ForScope(
this, ScopeFlags);
1497 bool ForEach =
false, ForRange =
false;
1499 bool SecondPartIsInvalid =
false;
1501 ExprResult Collection;
1502 ForRangeInit ForRangeInit;
1504 Decl *SecondVar =
nullptr;
1506 if (Tok.
is(tok::code_completion)) {
1514 ParsedAttributesWithRange attrs(AttrFactory);
1515 MaybeParseCXX11Attributes(attrs);
1518 if (Tok.
is(tok::semi)) {
1519 ProhibitAttributes(attrs);
1523 isForRangeIdentifier()) {
1524 ProhibitAttributes(attrs);
1527 MaybeParseCXX11Attributes(attrs);
1530 if (Tok.
is(tok::l_brace))
1531 ForRangeInit.RangeExpr = ParseBraceInitializer();
1535 Diag(Loc, diag::err_for_range_identifier)
1541 attrs, attrs.Range.getEnd());
1543 }
else if (isForInitDeclaration()) {
1545 if (!C99orCXXorObjC)
1546 Diag(Tok, diag::ext_c99_variable_decl_in_for_loop);
1549 bool MightBeForRangeStmt =
getLangOpts().CPlusPlus;
1555 MightBeForRangeStmt ? &ForRangeInit :
nullptr);
1557 if (ForRangeInit.ParsedForRangeDecl()) {
1559 diag::warn_cxx98_compat_for_range : diag::ext_for_range);
1562 }
else if (Tok.
is(tok::semi)) {
1564 }
else if ((ForEach = isTokIdentifier_in())) {
1569 if (Tok.
is(tok::code_completion)) {
1576 Diag(Tok, diag::err_expected_semi_for);
1579 ProhibitAttributes(attrs);
1582 ForEach = isTokIdentifier_in();
1592 if (Tok.
is(tok::semi)) {
1594 }
else if (ForEach) {
1597 if (Tok.
is(tok::code_completion)) {
1606 Diag(Tok, diag::err_for_range_expected_decl)
1607 << FirstPart.
get()->getSourceRange();
1609 SecondPartIsInvalid =
true;
1612 Diag(Tok, diag::err_expected_semi_for);
1616 if (Tok.
is(tok::semi))
1624 if (!ForEach && !ForRange) {
1625 assert(!SecondPart.get() &&
"Shouldn't have a second expression yet.");
1627 if (Tok.
is(tok::semi)) {
1629 }
else if (Tok.
is(tok::r_paren)) {
1634 ParseCXXCondition(Second, SecondVar, ForLoc,
true);
1641 SecondPartIsInvalid = Second.
isInvalid();
1645 if (Tok.
isNot(tok::semi)) {
1646 if (!SecondPartIsInvalid || SecondVar)
1647 Diag(Tok, diag::err_expected_semi_for);
1653 if (Tok.
is(tok::semi)) {
1658 if (Tok.
isNot(tok::r_paren)) {
1676 ForRangeInit.ColonLoc,
1677 ForRangeInit.RangeExpr.get(),
1678 T.getCloseLocation(),
1684 }
else if (ForEach) {
1688 T.getCloseLocation());
1709 Tok.
is(tok::l_brace));
1719 StmtResult Body(ParseStatement(TrailingElseLoc));
1727 if (Body.isInvalid())
1737 return Actions.
ActOnForStmt(ForLoc, T.getOpenLocation(), FirstPart.
get(),
1738 SecondPart, SecondVar, ThirdPart,
1739 T.getCloseLocation(), Body.get());
1750 assert(Tok.
is(tok::kw_goto) &&
"Not a goto stmt!");
1754 if (Tok.
is(tok::identifier)) {
1759 }
else if (Tok.
is(tok::star)) {
1761 Diag(Tok, diag::ext_gnu_indirect_goto);
1770 Diag(Tok, diag::err_expected) << tok::identifier;
1783 StmtResult Parser::ParseContinueStatement() {
1803 assert(Tok.
is(tok::kw_return) &&
"Not a return stmt!");
1807 if (Tok.
isNot(tok::semi)) {
1808 if (Tok.
is(tok::code_completion)) {
1815 R = ParseInitializer();
1818 diag::warn_cxx98_compat_generalized_initializer_lists :
1819 diag::ext_generalized_initializer_lists)
1820 << R.
get()->getSourceRange();
1831 StmtResult Parser::ParsePragmaLoopHint(StmtVector &Stmts,
bool OnlyStatement,
1833 ParsedAttributesWithRange &Attrs) {
1835 ParsedAttributesWithRange TempAttrs(AttrFactory);
1838 while (Tok.
is(tok::annot_pragma_loop_hint)) {
1840 if (!HandlePragmaLoopHint(Hint))
1851 MaybeParseCXX11Attributes(Attrs);
1853 StmtResult S = ParseStatementOrDeclarationAfterAttributes(
1854 Stmts, OnlyStatement, TrailingElseLoc, Attrs);
1856 Attrs.takeAllFrom(TempAttrs);
1860 Decl *Parser::ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope) {
1861 assert(Tok.
is(tok::l_brace));
1865 trySkippingFunctionBody()) {
1871 "parsing function body");
1876 StmtResult FnBody(ParseCompoundStatementBody());
1879 if (FnBody.isInvalid()) {
1893 Decl *Parser::ParseFunctionTryBlock(Decl *Decl, ParseScope &BodyScope) {
1894 assert(Tok.
is(tok::kw_try) &&
"Expected 'try'");
1898 "parsing function try block");
1901 if (Tok.
is(tok::colon))
1902 ParseConstructorInitializer(Decl);
1907 trySkippingFunctionBody()) {
1913 StmtResult FnBody(ParseCXXTryBlockCommon(TryLoc,
true));
1916 if (FnBody.isInvalid()) {
1925 bool Parser::trySkippingFunctionBody() {
1926 assert(Tok.
is(tok::l_brace));
1927 assert(SkipFunctionBodies &&
1928 "Should only be called when SkipFunctionBodies is enabled");
1938 TentativeParsingAction PA(*
this);
1955 assert(Tok.
is(tok::kw_try) &&
"Expected 'try'");
1958 return ParseCXXTryBlockCommon(TryLoc);
1978 if (Tok.
isNot(tok::l_brace))
1979 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
1981 StmtResult TryBlock(ParseCompoundStatement(
false,
1984 if (TryBlock.isInvalid())
1989 if ((Tok.
is(tok::identifier) &&
1991 Tok.
is(tok::kw___finally)) {
1996 Handler = ParseSEHExceptBlock(Loc);
2000 Handler = ParseSEHFinallyBlock(Loc);
2011 StmtVector Handlers;
2015 DiagnoseAndSkipCXX11Attributes();
2017 if (Tok.
isNot(tok::kw_catch))
2019 while (Tok.
is(tok::kw_catch)) {
2020 StmtResult Handler(ParseCXXCatchBlock(FnTry));
2022 Handlers.push_back(Handler.
get());
2026 if (Handlers.empty())
2043 StmtResult Parser::ParseCXXCatchBlock(
bool FnCatch) {
2044 assert(Tok.
is(tok::kw_catch) &&
"Expected 'catch'");
2049 if (T.expectAndConsume())
2060 Decl *ExceptionDecl =
nullptr;
2061 if (Tok.
isNot(tok::ellipsis)) {
2062 ParsedAttributesWithRange Attributes(AttrFactory);
2063 MaybeParseCXX11Attributes(Attributes);
2066 DS.takeAttributesFrom(Attributes);
2068 if (ParseCXXTypeSpecifierSeq(DS))
2072 ParseDeclarator(ExDecl);
2078 if (T.getCloseLocation().isInvalid())
2081 if (Tok.
isNot(tok::l_brace))
2082 return StmtError(
Diag(Tok, diag::err_expected) << tok::l_brace);
2086 if (Block.isInvalid())
2092 void Parser::ParseMicrosoftIfExistsStatement(StmtVector &Stmts) {
2093 IfExistsCondition
Result;
2094 if (ParseMicrosoftIfExistsCondition(Result))
2101 if (Result.Behavior == IEB_Dependent) {
2102 if (!Tok.
is(tok::l_brace)) {
2103 Diag(Tok, diag::err_expected) << tok::l_brace;
2107 StmtResult Compound = ParseCompoundStatement();
2117 Stmts.push_back(DepResult.
get());
2122 if (Braces.consumeOpen()) {
2123 Diag(Tok, diag::err_expected) << tok::l_brace;
2127 switch (Result.Behavior) {
2133 llvm_unreachable(
"Dependent case handled above");
2141 while (Tok.
isNot(tok::r_brace)) {
2142 StmtResult R = ParseStatementOrDeclaration(Stmts,
false);
2144 Stmts.push_back(R.
get());
2146 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)
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)
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)
Information about one declarator, including the parsed type information and the identifier.
void ActOnForEachDeclStmt(DeclGroupPtrTy Decl)
IdentifierLoc * OptionLoc
RAII object that makes sure paren/bracket/brace count is correct after declaration/statement parsing...
StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body)
bool canSkipFunctionBody(Decl *D)
Determine whether we can skip parsing the body of a function definition, assuming we don't care about...
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
void CodeCompleteOrdinaryName(Scope *S, ParserCompletionContext CompletionContext)
const Token & NextToken()
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)
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...
StmtResult ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *First, FullExprArg Second, Decl *SecondVar, FullExprArg Third, SourceLocation RParenLoc, Stmt *Body)
void decrementMSManglingNumber()
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)
StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, ArrayRef< Stmt * > Handlers)
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)
LabelDecl * LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, SourceLocation GnuLabelLoc=SourceLocation())
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)
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...
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)
void setIsPoisoned(bool Value=true)
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
Decl * ActOnSkippedFunctionBody(Decl *Decl)
bool isSwitchScope() const
isSwitchScope - Return true if this scope is a switch scope.
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. The SourceManager can decode this to get at the full include stack...
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)
Scope * getCurScope() const
void CodeCompleteReturn(Scope *S)
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
We are currently in the filter expression of an SEH except block.
SourceLocation getExprLoc() const LLVM_READONLY
Decl * ActOnExceptionDeclarator(Scope *S, Declarator &D)
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)
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. Some scopes just contain loop constructs but don't co...
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()
StmtResult ActOnCXXForRangeStmt(SourceLocation ForLoc, Stmt *LoopVar, SourceLocation ColonLoc, Expr *Collection, SourceLocation RParenLoc, BuildForRangeKind Kind)
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)
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)
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