17 using namespace clang;
49 bool Parser::isCXXDeclarationStatement() {
54 case tok::kw_namespace:
59 case tok::kw_static_assert:
60 case tok::kw__Static_assert:
64 return isCXXSimpleDeclaration(
false);
88 bool Parser::isCXXSimpleDeclaration(
bool AllowForRangeDecl) {
113 bool InvalidAsDeclaration =
false;
114 TPResult TPR = isCXXDeclarationSpecifier(TPResult::False,
115 &InvalidAsDeclaration);
116 if (TPR != TPResult::Ambiguous)
117 return TPR != TPResult::False;
125 if (InvalidAsDeclaration)
136 RevertingTentativeParsingAction PA(*
this);
137 TPR = TryParseSimpleDeclaration(AllowForRangeDecl);
141 if (TPR == TPResult::Error)
145 if (TPR == TPResult::Ambiguous)
146 TPR = TPResult::True;
148 assert(TPR == TPResult::True || TPR == TPResult::False);
149 return TPR == TPResult::True;
154 Parser::TPResult Parser::TryConsumeDeclarationSpecifier() {
156 case tok::kw__Atomic:
163 case tok::kw___attribute:
164 case tok::kw___underlying_type: {
166 if (Tok.
isNot(tok::l_paren))
167 return TPResult::Error;
170 return TPResult::Error;
177 case tok::kw___interface:
189 if (!TrySkipAttributes())
190 return TPResult::Error;
193 return TPResult::Error;
194 if (Tok.
is(tok::annot_cxxscope))
195 ConsumeAnnotationToken();
196 if (Tok.
is(tok::identifier))
198 else if (Tok.
is(tok::annot_template_id))
199 ConsumeAnnotationToken();
201 return TPResult::Error;
204 case tok::annot_cxxscope:
205 ConsumeAnnotationToken();
211 return TryParseProtocolQualifiers();
215 return TPResult::Ambiguous;
226 Parser::TPResult Parser::TryParseSimpleDeclaration(
bool AllowForRangeDecl) {
227 if (TryConsumeDeclarationSpecifier() == TPResult::Error)
228 return TPResult::Error;
233 if (Tok.
isNot(tok::l_paren)) {
234 TPResult TPR = isCXXDeclarationSpecifier();
235 if (TPR == TPResult::Ambiguous)
236 return TPResult::True;
237 if (TPR == TPResult::True || TPR == TPResult::Error)
239 assert(TPR == TPResult::False);
242 TPResult TPR = TryParseInitDeclaratorList();
243 if (TPR != TPResult::Ambiguous)
246 if (Tok.
isNot(tok::semi) && (!AllowForRangeDecl || Tok.
isNot(tok::colon)))
247 return TPResult::False;
249 return TPResult::Ambiguous;
279 Parser::TPResult Parser::TryParseInitDeclaratorList() {
282 TPResult TPR = TryParseDeclarator(
false);
283 if (TPR != TPResult::Ambiguous)
287 if (Tok.
isOneOf(tok::kw_asm, tok::kw___attribute))
288 return TPResult::True;
291 if (Tok.
is(tok::l_paren)) {
295 return TPResult::Error;
296 }
else if (Tok.
is(tok::l_brace)) {
299 return TPResult::True;
300 }
else if (Tok.
is(tok::equal) || isTokIdentifier_in()) {
317 return TPResult::True;
324 return TPResult::Ambiguous;
352 RevertingTentativeParsingAction PA(
P);
356 unsigned QuestionColonDepth = 0;
358 P.
SkipUntil({tok::r_paren, tok::semi, tok::question, tok::colon},
360 if (
P.Tok.
is(tok::question))
361 ++QuestionColonDepth;
362 else if (
P.Tok.
is(tok::colon)) {
363 if (QuestionColonDepth)
364 --QuestionColonDepth;
379 if (
P.Tok.
isNot(tok::r_paren))
381 if (
P.Tok.
isNot(tok::semi))
400 assert(
resolved() &&
"can't continue after tentative parsing bails out");
402 case TPResult::False:
405 case TPResult::Ambiguous:
407 case TPResult::Error:
415 ConditionOrInitStatement
result()
const {
418 "result called but not yet resolved");
420 return ConditionOrInitStatement::Expression;
422 return ConditionOrInitStatement::ConditionDecl;
424 return ConditionOrInitStatement::InitStmtDecl;
426 return ConditionOrInitStatement::ForRangeDecl;
427 return ConditionOrInitStatement::Error;
431 bool Parser::isEnumBase(
bool AllowSemi) {
432 assert(Tok.
is(tok::colon) &&
"should be looking at the ':'");
434 RevertingTentativeParsingAction PA(*
this);
439 bool InvalidAsDeclSpec =
false;
443 TPResult R = isCXXDeclarationSpecifier( TPResult::True,
445 if (R == TPResult::Ambiguous) {
448 if (TryConsumeDeclarationSpecifier() == TPResult::Error)
453 if (Tok.
is(tok::l_brace) || (AllowSemi && Tok.
is(tok::semi)))
457 R = isCXXDeclarationSpecifier(TPResult::True, &InvalidAsDeclSpec);
460 return R != TPResult::False;
480 Parser::ConditionOrInitStatement
481 Parser::isCXXConditionDeclarationOrInitStatement(
bool CanBeInitStatement,
482 bool CanBeForRangeDecl) {
483 ConditionDeclarationOrInitStatementState
State(*
this, CanBeInitStatement,
486 if (CanBeInitStatement && Tok.
is(tok::kw_using))
487 return ConditionOrInitStatement::InitStmtDecl;
488 if (
State.update(isCXXDeclarationSpecifier()))
489 return State.result();
492 RevertingTentativeParsingAction PA(*
this);
495 if (
State.update(TryConsumeDeclarationSpecifier()))
496 return State.result();
497 assert(Tok.
is(tok::l_paren) &&
"Expected '('");
501 if (
State.update(TryParseDeclarator(
false)))
502 return State.result();
507 if (Tok.
isOneOf(tok::equal, tok::kw_asm, tok::kw___attribute) ||
509 State.markNotExpression();
510 return State.result();
514 if (
State.CanBeForRangeDecl && Tok.
is(tok::colon))
515 return ConditionOrInitStatement::ForRangeDecl;
519 if (
State.markNotCondition())
520 return State.result();
523 if (
State.markNotForRangeDecl())
524 return State.result();
528 if (Tok.
is(tok::l_paren)) {
538 if (
State.CanBeCondition && Tok.
is(tok::r_paren))
539 return ConditionOrInitStatement::ConditionDecl;
540 else if (
State.CanBeInitStatement && Tok.
is(tok::semi))
541 return ConditionOrInitStatement::InitStmtDecl;
543 return ConditionOrInitStatement::Expression;
563 bool Parser::isCXXTypeId(TentativeCXXTypeIdContext Context,
bool &isAmbiguous) {
574 TPResult TPR = isCXXDeclarationSpecifier();
575 if (TPR != TPResult::Ambiguous)
576 return TPR != TPResult::False;
585 RevertingTentativeParsingAction PA(*
this);
588 TryConsumeDeclarationSpecifier();
589 assert(Tok.
is(tok::l_paren) &&
"Expected '('");
592 TPR = TryParseDeclarator(
true,
false);
595 if (TPR == TPResult::Error)
596 TPR = TPResult::True;
598 if (TPR == TPResult::Ambiguous) {
601 if (Context == TypeIdInParens && Tok.
is(tok::r_paren)) {
602 TPR = TPResult::True;
609 }
else if (Context == TypeIdAsTemplateArgument &&
610 (Tok.
isOneOf(tok::greater, tok::comma) ||
612 (Tok.
isOneOf(tok::greatergreater,
613 tok::greatergreatergreater) ||
614 (Tok.
is(tok::ellipsis) &&
616 tok::greatergreatergreater,
618 TPR = TPResult::True;
622 TPR = TPResult::False;
625 assert(TPR == TPResult::True || TPR == TPResult::False);
626 return TPR == TPResult::True;
662 Parser::CXX11AttributeKind
663 Parser::isCXX11AttributeSpecifier(
bool Disambiguate,
664 bool OuterMightBeMessageSend) {
665 if (Tok.
is(tok::kw_alignas))
666 return CAK_AttributeSpecifier;
669 return CAK_NotAttributeSpecifier;
673 return CAK_AttributeSpecifier;
676 if (GetLookAheadToken(2).is(tok::kw_using))
677 return CAK_AttributeSpecifier;
679 RevertingTentativeParsingAction PA(*
this);
687 bool IsAttribute =
SkipUntil(tok::r_square);
688 IsAttribute &= Tok.
is(tok::r_square);
690 return IsAttribute ? CAK_AttributeSpecifier : CAK_InvalidAttributeSpecifier;
706 RevertingTentativeParsingAction LambdaTPA(*
this);
708 LambdaIntroducerTentativeParse Tentative;
709 if (ParseLambdaIntroducer(Intro, &Tentative)) {
713 return CAK_NotAttributeSpecifier;
717 case LambdaIntroducerTentativeParse::MessageSend:
720 return CAK_NotAttributeSpecifier;
722 case LambdaIntroducerTentativeParse::Success:
723 case LambdaIntroducerTentativeParse::Incomplete:
725 if (Tok.
is(tok::r_square))
727 return CAK_AttributeSpecifier;
729 if (OuterMightBeMessageSend)
731 return CAK_NotAttributeSpecifier;
734 return CAK_InvalidAttributeSpecifier;
736 case LambdaIntroducerTentativeParse::Invalid:
747 bool IsAttribute =
true;
748 while (Tok.
isNot(tok::r_square)) {
749 if (Tok.
is(tok::comma)) {
751 return CAK_AttributeSpecifier;
760 if (!TryParseCXX11AttributeIdentifier(Loc)) {
764 if (Tok.
is(tok::coloncolon)) {
766 if (!TryParseCXX11AttributeIdentifier(Loc)) {
773 if (Tok.
is(tok::l_paren)) {
789 if (Tok.
is(tok::r_square)) {
791 IsAttribute = Tok.
is(tok::r_square);
799 return CAK_AttributeSpecifier;
802 return CAK_NotAttributeSpecifier;
805 bool Parser::TrySkipAttributes() {
806 while (Tok.
isOneOf(tok::l_square, tok::kw___attribute, tok::kw___declspec,
808 if (Tok.
is(tok::l_square)) {
810 if (Tok.
isNot(tok::l_square))
820 if (Tok.
isNot(tok::l_paren))
831 Parser::TPResult Parser::TryParsePtrOperatorSeq() {
834 return TPResult::Error;
836 if (Tok.
isOneOf(tok::star, tok::amp, tok::caret, tok::ampamp) ||
837 (Tok.
is(tok::annot_cxxscope) &&
NextToken().is(tok::star))) {
842 if (!TrySkipAttributes())
843 return TPResult::Error;
845 while (Tok.
isOneOf(tok::kw_const, tok::kw_volatile, tok::kw_restrict,
846 tok::kw__Nonnull, tok::kw__Nullable,
847 tok::kw__Nullable_result, tok::kw__Null_unspecified,
851 return TPResult::True;
874 Parser::TPResult Parser::TryParseOperatorId() {
875 assert(Tok.
is(tok::kw_operator));
880 case tok::kw_new:
case tok::kw_delete:
882 if (Tok.
is(tok::l_square) &&
NextToken().is(tok::r_square)) {
886 return TPResult::True;
888 #define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemOnly) \
890 #define OVERLOADED_OPERATOR_MULTI(Name, Spelling, Unary, Binary, MemOnly)
891 #include "clang/Basic/OperatorKinds.def"
893 return TPResult::True;
899 return TPResult::True;
907 return TPResult::True;
917 bool FoundUDSuffix =
false;
920 ConsumeStringToken();
921 }
while (isTokenStringLiteral());
923 if (!FoundUDSuffix) {
924 if (Tok.
is(tok::identifier))
927 return TPResult::Error;
929 return TPResult::True;
933 bool AnyDeclSpecifiers =
false;
935 TPResult TPR = isCXXDeclarationSpecifier();
936 if (TPR == TPResult::Error)
938 if (TPR == TPResult::False) {
939 if (!AnyDeclSpecifiers)
940 return TPResult::Error;
943 if (TryConsumeDeclarationSpecifier() == TPResult::Error)
944 return TPResult::Error;
945 AnyDeclSpecifiers =
true;
947 return TryParsePtrOperatorSeq();
1003 Parser::TPResult Parser::TryParseDeclarator(
bool mayBeAbstract,
1004 bool mayHaveIdentifier,
1005 bool mayHaveDirectInit) {
1009 if (TryParsePtrOperatorSeq() == TPResult::Error)
1010 return TPResult::Error;
1014 if (Tok.
is(tok::ellipsis))
1017 if ((Tok.
isOneOf(tok::identifier, tok::kw_operator) ||
1018 (Tok.
is(tok::annot_cxxscope) && (
NextToken().is(tok::identifier) ||
1020 mayHaveIdentifier) {
1022 if (Tok.
is(tok::annot_cxxscope)) {
1027 return TPResult::Error;
1028 ConsumeAnnotationToken();
1029 }
else if (Tok.
is(tok::identifier)) {
1032 if (Tok.
is(tok::kw_operator)) {
1033 if (TryParseOperatorId() == TPResult::Error)
1034 return TPResult::Error;
1037 }
else if (Tok.
is(tok::l_paren)) {
1039 if (mayBeAbstract &&
1040 (Tok.
is(tok::r_paren) ||
1042 (Tok.
is(tok::ellipsis) &&
NextToken().is(tok::r_paren)) ||
1043 isDeclarationSpecifier())) {
1046 TPResult TPR = TryParseFunctionDeclarator();
1047 if (TPR != TPResult::Ambiguous)
1053 if (Tok.
isOneOf(tok::kw___attribute, tok::kw___declspec, tok::kw___cdecl,
1054 tok::kw___stdcall, tok::kw___fastcall, tok::kw___thiscall,
1055 tok::kw___regcall, tok::kw___vectorcall))
1056 return TPResult::True;
1057 TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier);
1058 if (TPR != TPResult::Ambiguous)
1060 if (Tok.
isNot(tok::r_paren))
1061 return TPResult::False;
1064 }
else if (!mayBeAbstract) {
1065 return TPResult::False;
1068 if (mayHaveDirectInit)
1069 return TPResult::Ambiguous;
1072 TPResult TPR(TPResult::Ambiguous);
1074 if (Tok.
is(tok::l_paren)) {
1079 if (!mayBeAbstract && !isCXXFunctionDeclarator())
1085 TPR = TryParseFunctionDeclarator();
1086 }
else if (Tok.
is(tok::l_square)) {
1089 TPR = TryParseBracketDeclarator();
1090 }
else if (Tok.
is(tok::kw_requires)) {
1093 TPR = TPResult::True;
1098 if (TPR != TPResult::Ambiguous)
1102 return TPResult::Ambiguous;
1106 return llvm::is_contained(TentativelyDeclaredIdentifiers, II);
1112 TentativeParseCCC(
const Token &Next) {
1113 WantRemainingKeywords =
false;
1114 WantTypeSpecifiers =
1115 Next.isOneOf(tok::l_paren, tok::r_paren, tok::greater, tok::l_brace,
1116 tok::identifier, tok::comma);
1119 bool ValidateCandidate(
const TypoCorrection &Candidate)
override {
1123 llvm::all_of(Candidate,
1124 [](
NamedDecl *ND) { return ND->isCXXInstanceMember(); }))
1130 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
1131 return std::make_unique<TentativeParseCCC>(*
this);
1248 Parser::isCXXDeclarationSpecifier(Parser::TPResult BracedCastResult,
1249 bool *InvalidAsDeclSpec) {
1255 GetLookAheadToken(Lookahead + 1).
isOneOf(tok::kw_auto, tok::kw_decltype,
1263 case tok::identifier: {
1266 if (TryAltiVecVectorToken())
1267 return TPResult::True;
1271 if (!
getLangOpts().ObjC && Next.is(tok::identifier))
1272 return TPResult::True;
1274 if (Next.isNot(tok::coloncolon) && Next.isNot(tok::less)) {
1279 TentativeParseCCC CCC(Next);
1280 switch (TryAnnotateName(&CCC)) {
1282 return TPResult::Error;
1283 case ANK_TentativeDecl:
1284 return TPResult::False;
1285 case ANK_TemplateName:
1292 return TPResult::Error;
1293 if (Tok.
isNot(tok::identifier))
1299 return GreaterThanIsOperator ? TPResult::True : TPResult::False;
1300 case ANK_Unresolved:
1301 return InvalidAsDeclSpec ? TPResult::Ambiguous : TPResult::False;
1305 assert(Tok.
isNot(tok::identifier) &&
1306 "TryAnnotateName succeeded without producing an annotation");
1313 return TPResult::Error;
1317 if (Tok.
is(tok::identifier))
1318 return TPResult::False;
1322 return isCXXDeclarationSpecifier(BracedCastResult, InvalidAsDeclSpec);
1325 case tok::kw_typename:
1329 return TPResult::Error;
1330 return isCXXDeclarationSpecifier(BracedCastResult, InvalidAsDeclSpec);
1332 case tok::coloncolon: {
1334 if (Next.isOneOf(tok::kw_new,
1336 return TPResult::False;
1339 case tok::kw___super:
1340 case tok::kw_decltype:
1344 return TPResult::Error;
1345 return isCXXDeclarationSpecifier(BracedCastResult, InvalidAsDeclSpec);
1354 case tok::kw_friend:
1355 case tok::kw_typedef:
1356 case tok::kw_constexpr:
1357 case tok::kw_consteval:
1358 case tok::kw_constinit:
1360 case tok::kw_register:
1361 case tok::kw_static:
1362 case tok::kw_extern:
1363 case tok::kw_mutable:
1365 case tok::kw___thread:
1366 case tok::kw_thread_local:
1367 case tok::kw__Thread_local:
1369 case tok::kw_inline:
1370 case tok::kw_virtual:
1371 case tok::kw_explicit:
1374 case tok::kw___module_private__:
1377 case tok::kw___unknown_anytype:
1390 case tok::kw_struct:
1392 case tok::kw___interface:
1397 case tok::kw_volatile:
1398 return TPResult::True;
1401 case tok::kw_private:
1403 return TPResult::False;
1405 case tok::kw___private:
1406 case tok::kw___local:
1407 case tok::kw___global:
1408 case tok::kw___constant:
1409 case tok::kw___generic:
1411 case tok::kw___read_only:
1412 case tok::kw___write_only:
1413 case tok::kw___read_write:
1418 case tok::kw_restrict:
1419 case tok::kw__Complex:
1420 case tok::kw___attribute:
1421 case tok::kw___auto_type:
1422 return TPResult::True;
1425 case tok::kw___declspec:
1426 case tok::kw___cdecl:
1427 case tok::kw___stdcall:
1428 case tok::kw___fastcall:
1429 case tok::kw___thiscall:
1430 case tok::kw___regcall:
1431 case tok::kw___vectorcall:
1433 case tok::kw___sptr:
1434 case tok::kw___uptr:
1435 case tok::kw___ptr64:
1436 case tok::kw___ptr32:
1437 case tok::kw___forceinline:
1438 case tok::kw___unaligned:
1439 case tok::kw__Nonnull:
1440 case tok::kw__Nullable:
1441 case tok::kw__Nullable_result:
1442 case tok::kw__Null_unspecified:
1443 case tok::kw___kindof:
1444 return TPResult::True;
1447 case tok::kw___pascal:
1448 return TPResult::True;
1451 case tok::kw___vector:
1452 return TPResult::True;
1454 case tok::annot_template_id: {
1460 InvalidAsDeclSpec) {
1465 *InvalidAsDeclSpec =
NextToken().
is(tok::l_paren);
1466 return TPResult::Ambiguous;
1469 return TPResult::Error;
1470 if (IsPlaceholderSpecifier(TemplateId, 0))
1471 return TPResult::True;
1473 return TPResult::False;
1475 AnnotateTemplateIdTokenAsType(SS);
1476 assert(Tok.
is(tok::annot_typename));
1480 case tok::annot_cxxscope:
1483 return TPResult::Error;
1484 if (!Tok.
is(tok::annot_typename)) {
1485 if (Tok.
is(tok::annot_cxxscope) &&
1486 NextToken().is(tok::annot_template_id)) {
1490 if (InvalidAsDeclSpec) {
1491 *InvalidAsDeclSpec =
NextToken().
is(tok::l_paren);
1492 return TPResult::Ambiguous;
1494 return TPResult::Error;
1496 if (IsPlaceholderSpecifier(TemplateId, 1))
1497 return TPResult::True;
1501 if (Tok.
is(tok::annot_cxxscope) &&
NextToken().is(tok::identifier)) {
1507 RevertingTentativeParsingAction PA(*
this);
1508 ConsumeAnnotationToken();
1510 bool isIdentifier = Tok.
is(tok::identifier);
1511 TPResult TPR = TPResult::False;
1513 TPR = isCXXDeclarationSpecifier(BracedCastResult,
1517 TPR == TPResult::True || TPR == TPResult::Error)
1518 return TPResult::Error;
1520 if (InvalidAsDeclSpec) {
1523 *InvalidAsDeclSpec =
true;
1524 return TPResult::Ambiguous;
1530 if (((Tok.
is(tok::amp) || Tok.
is(tok::star)) &&
1533 (Tok.
is(tok::ampamp) &&
NextToken().is(tok::greater)))
1534 return TPResult::True;
1540 switch (TryAnnotateName()) {
1542 return TPResult::Error;
1543 case ANK_TentativeDecl:
1544 return TPResult::False;
1545 case ANK_TemplateName:
1550 return TPResult::Error;
1551 if (Tok.
isNot(tok::identifier))
1561 case ANK_Unresolved:
1562 return InvalidAsDeclSpec ? TPResult::Ambiguous : TPResult::False;
1568 assert(Tok.
isNot(tok::annot_cxxscope) ||
1570 return isCXXDeclarationSpecifier(BracedCastResult, InvalidAsDeclSpec);
1573 return TPResult::False;
1596 case tok::annot_typename:
1601 RevertingTentativeParsingAction PA(*
this);
1604 TPResult TPR = TryParseProtocolQualifiers();
1605 bool isFollowedByParen = Tok.
is(tok::l_paren);
1606 bool isFollowedByBrace = Tok.
is(tok::l_brace);
1608 if (TPR == TPResult::Error)
1609 return TPResult::Error;
1611 if (isFollowedByParen)
1612 return TPResult::Ambiguous;
1615 return BracedCastResult;
1617 return TPResult::True;
1622 case tok::kw_wchar_t:
1623 case tok::kw_char8_t:
1624 case tok::kw_char16_t:
1625 case tok::kw_char32_t:
1630 case tok::kw___int64:
1631 case tok::kw___int128:
1632 case tok::kw_signed:
1633 case tok::kw_unsigned:
1636 case tok::kw_double:
1637 case tok::kw___bf16:
1638 case tok::kw__Float16:
1639 case tok::kw___float128:
1640 case tok::kw___ibm128:
1642 case tok::annot_decltype:
1643 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
1644 #include "clang/Basic/OpenCLImageTypes.def"
1646 return TPResult::Ambiguous;
1655 return BracedCastResult;
1657 if (isStartOfObjCClassMessageMissingOpenBracket())
1658 return TPResult::False;
1660 return TPResult::True;
1663 case tok::kw_typeof: {
1665 return TPResult::True;
1667 RevertingTentativeParsingAction PA(*
this);
1669 TPResult TPR = TryParseTypeofSpecifier();
1670 bool isFollowedByParen = Tok.
is(tok::l_paren);
1671 bool isFollowedByBrace = Tok.
is(tok::l_brace);
1673 if (TPR == TPResult::Error)
1674 return TPResult::Error;
1676 if (isFollowedByParen)
1677 return TPResult::Ambiguous;
1680 return BracedCastResult;
1682 return TPResult::True;
1686 case tok::kw___underlying_type:
1687 return TPResult::True;
1690 case tok::kw__Atomic:
1691 return TPResult::True;
1693 case tok::kw__BitInt:
1694 case tok::kw__ExtInt: {
1696 return TPResult::Error;
1697 RevertingTentativeParsingAction PA(*
this);
1702 return TPResult::Error;
1704 if (Tok.
is(tok::l_paren))
1705 return TPResult::Ambiguous;
1708 return BracedCastResult;
1710 return TPResult::True;
1713 return TPResult::False;
1717 bool Parser::isCXXDeclarationSpecifierAType() {
1720 case tok::annot_decltype:
1721 case tok::annot_template_id:
1722 case tok::annot_typename:
1723 case tok::kw_typeof:
1724 case tok::kw___underlying_type:
1729 case tok::kw_struct:
1731 case tok::kw___interface:
1737 case tok::kw_wchar_t:
1738 case tok::kw_char8_t:
1739 case tok::kw_char16_t:
1740 case tok::kw_char32_t:
1744 case tok::kw__ExtInt:
1745 case tok::kw__BitInt:
1747 case tok::kw___int64:
1748 case tok::kw___int128:
1749 case tok::kw_signed:
1750 case tok::kw_unsigned:
1753 case tok::kw_double:
1754 case tok::kw___bf16:
1755 case tok::kw__Float16:
1756 case tok::kw___float128:
1757 case tok::kw___ibm128:
1759 case tok::kw___unknown_anytype:
1760 case tok::kw___auto_type:
1761 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
1762 #include "clang/Basic/OpenCLImageTypes.def"
1768 case tok::kw__Atomic:
1781 Parser::TPResult Parser::TryParseTypeofSpecifier() {
1782 assert(Tok.
is(tok::kw_typeof) &&
"Expected 'typeof'!");
1785 assert(Tok.
is(tok::l_paren) &&
"Expected '('");
1789 return TPResult::Error;
1791 return TPResult::Ambiguous;
1796 Parser::TPResult Parser::TryParseProtocolQualifiers() {
1797 assert(Tok.
is(tok::less) &&
"Expected '<' for qualifier list");
1800 if (Tok.
isNot(tok::identifier))
1801 return TPResult::Error;
1804 if (Tok.
is(tok::comma)) {
1809 if (Tok.
is(tok::greater)) {
1811 return TPResult::Ambiguous;
1815 return TPResult::Error;
1828 bool Parser::isCXXFunctionDeclarator(
bool *IsAmbiguous) {
1839 RevertingTentativeParsingAction PA(*
this);
1842 bool InvalidAsDeclaration =
false;
1843 TPResult TPR = TryParseParameterDeclarationClause(&InvalidAsDeclaration);
1844 if (TPR == TPResult::Ambiguous) {
1845 if (Tok.
isNot(tok::r_paren))
1846 TPR = TPResult::False;
1849 if (Next.isOneOf(tok::amp, tok::ampamp, tok::kw_const, tok::kw_volatile,
1850 tok::kw_throw, tok::kw_noexcept, tok::l_square,
1851 tok::l_brace, tok::kw_try, tok::equal, tok::arrow) ||
1852 isCXX11VirtSpecifier(Next))
1856 TPR = TPResult::True;
1857 else if (InvalidAsDeclaration)
1859 TPR = TPResult::False;
1863 if (IsAmbiguous && TPR == TPResult::Ambiguous)
1864 *IsAmbiguous =
true;
1867 return TPR != TPResult::False;
1888 Parser::TryParseParameterDeclarationClause(
bool *InvalidAsDeclaration,
1889 bool VersusTemplateArgument) {
1891 if (Tok.
is(tok::r_paren))
1892 return TPResult::Ambiguous;
1903 if (Tok.
is(tok::ellipsis)) {
1905 if (Tok.
is(tok::r_paren))
1906 return TPResult::True;
1908 return TPResult::False;
1912 if (isCXX11AttributeSpecifier(
false,
1914 return TPResult::True;
1917 MaybeParseMicrosoftAttributes(attrs);
1922 TPResult TPR = isCXXDeclarationSpecifier(TPResult::False,
1923 InvalidAsDeclaration);
1926 if (TPR != TPResult::Ambiguous &&
1927 !(VersusTemplateArgument && TPR == TPResult::True))
1930 bool SeenType =
false;
1932 SeenType |= isCXXDeclarationSpecifierAType();
1933 if (TryConsumeDeclarationSpecifier() == TPResult::Error)
1934 return TPResult::Error;
1937 if (SeenType && Tok.
is(tok::identifier))
1938 return TPResult::True;
1940 TPR = isCXXDeclarationSpecifier(TPResult::False,
1941 InvalidAsDeclaration);
1942 if (TPR == TPResult::Error)
1946 if (TPR == TPResult::True && !VersusTemplateArgument)
1948 }
while (TPR != TPResult::False);
1952 TPR = TryParseDeclarator(
true);
1953 if (TPR != TPResult::Ambiguous)
1957 if (Tok.
is(tok::kw___attribute))
1958 return TPResult::True;
1969 if (VersusTemplateArgument)
1970 return Tok.
is(tok::equal) ? TPResult::True : TPResult::False;
1972 if (Tok.
is(tok::equal)) {
1976 return TPResult::Error;
1979 if (Tok.
is(tok::ellipsis)) {
1981 if (Tok.
is(tok::r_paren))
1982 return TPResult::True;
1984 return TPResult::False;
1991 return TPResult::Ambiguous;
2006 Parser::TPResult Parser::TryParseFunctionDeclarator() {
2009 TPResult TPR = TryParseParameterDeclarationClause();
2010 if (TPR == TPResult::Ambiguous && Tok.
isNot(tok::r_paren))
2011 TPR = TPResult::False;
2013 if (TPR == TPResult::False || TPR == TPResult::Error)
2018 return TPResult::Error;
2021 while (Tok.
isOneOf(tok::kw_const, tok::kw_volatile, tok::kw___unaligned,
2026 if (Tok.
isOneOf(tok::amp, tok::ampamp))
2030 if (Tok.
is(tok::kw_throw)) {
2032 if (Tok.
isNot(tok::l_paren))
2033 return TPResult::Error;
2038 return TPResult::Error;
2040 if (Tok.
is(tok::kw_noexcept)) {
2043 if (Tok.
is(tok::l_paren)) {
2047 return TPResult::Error;
2051 return TPResult::Ambiguous;
2056 Parser::TPResult Parser::TryParseBracketDeclarator() {
2061 if (Tok.
is(tok::l_brace))
2062 return TPResult::False;
2065 return TPResult::Error;
2069 if (Tok.
isNot(tok::r_square))
2070 return TPResult::False;
2073 return TPResult::Ambiguous;
2080 Parser::TPResult Parser::isTemplateArgumentList(
unsigned TokensToSkip) {
2081 if (!TokensToSkip) {
2082 if (Tok.
isNot(tok::less))
2083 return TPResult::False;
2085 return TPResult::True;
2088 RevertingTentativeParsingAction PA(*
this);
2090 while (TokensToSkip) {
2096 return TPResult::False;
2101 bool InvalidAsTemplateArgumentList =
false;
2102 if (isCXXDeclarationSpecifier(TPResult::False,
2103 &InvalidAsTemplateArgumentList) ==
2105 return TPResult::True;
2106 if (InvalidAsTemplateArgumentList)
2107 return TPResult::False;
2121 if (
SkipUntil({tok::greater, tok::greatergreater, tok::greatergreatergreater},
2123 return TPResult::Ambiguous;
2124 return TPResult::False;
2129 Parser::TPResult Parser::isExplicitBool() {
2130 assert(Tok.
is(tok::l_paren) &&
"expected to be looking at a '(' token");
2132 RevertingTentativeParsingAction PA(*
this);
2140 while (Tok.
is(tok::l_paren))
2144 return TPResult::Error;
2149 if (Tok.
is(tok::annot_cxxscope)) {
2153 ConsumeAnnotationToken();
2158 if (Tok.
is(tok::kw_operator))
2159 return TPResult::Ambiguous;
2162 if (Tok.
isNot(tok::identifier) && Tok.
isNot(tok::annot_template_id))
2163 return TPResult::True;
2166 : *takeTemplateIdAnnotation(Tok)->Name,
2168 return TPResult::True;
2174 !isConstructorDeclarator(SS.
isEmpty(),
2176 return TPResult::True;
2179 return TPResult::Ambiguous;