27 #include "llvm/ADT/Optional.h"
28 #include "llvm/ADT/SmallSet.h"
29 #include "llvm/ADT/SmallString.h"
30 #include "llvm/ADT/StringSwitch.h"
32 using namespace clang;
46 DeclSpecContext DSC = getDeclSpecContextFromDeclaratorContext(Context);
47 if (DSC == DeclSpecContext::DSC_normal)
48 DSC = DeclSpecContext::DSC_type_specifier;
54 ParseSpecifierQualifierList(DS, AS, DSC);
60 ParseDeclarator(DeclaratorInfo);
72 if (Name.size() >= 4 && Name.startswith(
"__") && Name.endswith(
"__"))
73 return Name.drop_front(2).drop_back(2);
80 #define CLANG_ATTR_LATE_PARSED_LIST
82 #include "clang/Parse/AttrParserStringSwitches.inc"
84 #undef CLANG_ATTR_LATE_PARSED_LIST
94 if (
SM.getFileID(StartLoc) !=
SM.getFileID(EndLoc))
97 bool AttrStartIsInMacro =
99 bool AttrEndIsInMacro =
101 return AttrStartIsInMacro && AttrEndIsInMacro;
104 void Parser::ParseAttributes(
unsigned WhichAttrKinds,
ParsedAttributes &Attrs,
105 LateParsedAttrList *LateAttrs) {
111 if (WhichAttrKinds & PAKM_CXX11)
112 MoreToParse |= MaybeParseCXX11Attributes(Attrs);
113 if (WhichAttrKinds & PAKM_GNU)
114 MoreToParse |= MaybeParseGNUAttributes(Attrs, LateAttrs);
115 if (WhichAttrKinds & PAKM_Declspec)
116 MoreToParse |= MaybeParseMicrosoftDeclSpecs(Attrs);
117 }
while (MoreToParse);
162 LateParsedAttrList *LateAttrs,
Declarator *D) {
163 assert(Tok.
is(tok::kw___attribute) &&
"Not a GNU attribute list!");
168 while (Tok.
is(tok::kw___attribute)) {
170 unsigned OldNumAttrs = Attrs.
size();
171 unsigned OldNumLateAttrs = LateAttrs ? LateAttrs->size() : 0;
173 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
178 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
"(")) {
191 if (Tok.
is(tok::code_completion)) {
202 if (Tok.
isNot(tok::l_paren)) {
203 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
210 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, &EndLoc,
nullptr,
216 LateParsedAttribute *LA =
217 new LateParsedAttribute(
this, *AttrName, AttrNameLoc);
218 LateAttrs->push_back(LA);
222 if (!ClassStack.empty() && !LateAttrs->parseSoon())
223 getCurrentClass().LateParsedDeclarations.push_back(LA);
227 LA->Toks.push_back(Tok);
230 ConsumeAndStoreUntil(tok::r_paren, LA->Toks,
true);
235 LA->Toks.push_back(Eof);
236 }
while (Tok.
is(tok::comma));
238 if (ExpectAndConsume(tok::r_paren))
241 if (ExpectAndConsume(tok::r_paren))
248 if (!
SM.isWrittenInBuiltinFile(
SM.getSpellingLoc(AttrTokLoc)) &&
251 StringRef FoundName =
255 for (
unsigned i = OldNumAttrs; i < Attrs.
size(); ++i)
256 Attrs[i].setMacroIdentifier(MacroII, ExpansionRange.
getBegin());
259 for (
unsigned i = OldNumLateAttrs; i < LateAttrs->size(); ++i)
260 (*LateAttrs)[i]->MacroII = MacroII;
270 #define CLANG_ATTR_IDENTIFIER_ARG_LIST
272 #include "clang/Parse/AttrParserStringSwitches.inc"
274 #undef CLANG_ATTR_IDENTIFIER_ARG_LIST
279 #define CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST
281 #include "clang/Parse/AttrParserStringSwitches.inc"
283 #undef CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST
288 #define CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST
290 #include "clang/Parse/AttrParserStringSwitches.inc"
292 #undef CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST
297 #define CLANG_ATTR_ACCEPTS_EXPR_PACK
299 #include "clang/Parse/AttrParserStringSwitches.inc"
301 #undef CLANG_ATTR_ACCEPTS_EXPR_PACK
306 #define CLANG_ATTR_TYPE_ARG_LIST
308 #include "clang/Parse/AttrParserStringSwitches.inc"
310 #undef CLANG_ATTR_TYPE_ARG_LIST
316 #define CLANG_ATTR_ARG_CONTEXT_LIST
318 #include "clang/Parse/AttrParserStringSwitches.inc"
320 #undef CLANG_ATTR_ARG_CONTEXT_LIST
324 assert(Tok.
is(tok::identifier) &&
"expected an identifier");
339 Parens.consumeOpen();
342 if (Tok.
isNot(tok::r_paren))
345 if (Parens.consumeClose())
353 SourceRange(AttrNameLoc, Parens.getCloseLocation()),
354 ScopeName, ScopeLoc, T.
get(), Syntax);
357 ScopeName, ScopeLoc,
nullptr, 0, Syntax);
360 unsigned Parser::ParseAttributeArgsCommon(
369 bool AttributeHasVariadicIdentifierArg =
373 if (ChangeKWThisToIdent && Tok.
is(tok::kw_this))
377 if (Tok.
is(tok::identifier)) {
379 bool IsIdentifierArg = AttributeHasVariadicIdentifierArg ||
389 IsIdentifierArg = Next.isOneOf(tok::r_paren, tok::comma);
393 ArgExprs.push_back(ParseIdentifierLoc());
397 if (!ArgExprs.empty() ? Tok.
is(tok::comma) : Tok.
isNot(tok::r_paren)) {
399 if (!ArgExprs.empty())
402 if (AttributeIsTypeArgAttr) {
410 TheParsedType = T.
get();
411 }
else if (AttributeHasVariadicIdentifierArg) {
419 if (ChangeKWThisToIdent && Tok.
is(tok::kw_this))
423 if (Tok.
is(tok::identifier)) {
424 ArgExprs.push_back(ParseIdentifierLoc());
439 ArgExprs.push_back(ArgExpr.
get());
451 CommaLocsTy CommaLocs;
452 ExprVector ParsedExprs;
453 if (ParseExpressionList(ParsedExprs, CommaLocs,
454 llvm::function_ref<
void()>(),
462 for (
size_t I = 0; I < ParsedExprs.size(); ++I) {
463 if (!isa<PackExpansionExpr>(ParsedExprs[I]))
468 diag::err_attribute_argument_parm_pack_not_supported)
475 ArgExprs.insert(ArgExprs.end(), ParsedExprs.begin(), ParsedExprs.end());
480 if (!ExpectAndConsume(tok::r_paren)) {
483 if (AttributeIsTypeArgAttr && !TheParsedType.
get().
isNull()) {
485 ScopeName, ScopeLoc, TheParsedType, Syntax);
488 ArgExprs.data(), ArgExprs.size(), Syntax);
495 return static_cast<unsigned>(ArgExprs.size() + !TheParsedType.
get().
isNull());
500 void Parser::ParseGNUAttributeArgs(
505 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
510 if (AttrKind == ParsedAttr::AT_Availability) {
511 ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
514 }
else if (AttrKind == ParsedAttr::AT_ExternalSourceSymbol) {
515 ParseExternalSourceSymbolAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
516 ScopeName, ScopeLoc, Syntax);
518 }
else if (AttrKind == ParsedAttr::AT_ObjCBridgeRelated) {
519 ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
520 ScopeName, ScopeLoc, Syntax);
522 }
else if (AttrKind == ParsedAttr::AT_SwiftNewType) {
523 ParseSwiftNewTypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
526 }
else if (AttrKind == ParsedAttr::AT_TypeTagForDatatype) {
527 ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
528 ScopeName, ScopeLoc, Syntax);
531 ParseAttributeWithTypeArg(*AttrName, AttrNameLoc, Attrs, ScopeName,
545 for (
unsigned i = 0; i != FTI.
NumParams; ++i) {
551 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
555 unsigned Parser::ParseClangAttributeArgs(
559 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
566 return ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
567 ScopeName, ScopeLoc, Syntax);
568 case ParsedAttr::AT_ExternalSourceSymbol:
569 ParseExternalSourceSymbolAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
570 ScopeName, ScopeLoc, Syntax);
572 case ParsedAttr::AT_Availability:
573 ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
576 case ParsedAttr::AT_ObjCBridgeRelated:
577 ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
578 ScopeName, ScopeLoc, Syntax);
580 case ParsedAttr::AT_SwiftNewType:
581 ParseSwiftNewTypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
584 case ParsedAttr::AT_TypeTagForDatatype:
585 ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
586 ScopeName, ScopeLoc, Syntax);
589 return !Attrs.
empty() ? Attrs.
begin()->getNumArgs() : 0;
595 unsigned ExistingAttrs = Attrs.
size();
609 if (AttrName->
getName() ==
"property") {
615 T.expectAndConsume(diag::err_expected_lparen_after,
624 bool HasInvalidAccessor =
false;
629 if (!Tok.
is(tok::identifier)) {
631 if (Tok.
is(tok::r_paren) && !HasInvalidAccessor &&
632 AccessorNames[AK_Put] ==
nullptr &&
633 AccessorNames[AK_Get] ==
nullptr) {
634 Diag(AttrNameLoc, diag::err_ms_property_no_getter_or_putter);
645 if (KindStr ==
"get") {
647 }
else if (KindStr ==
"put") {
651 }
else if (KindStr ==
"set") {
652 Diag(KindLoc, diag::err_ms_property_has_set_accessor)
659 Diag(KindLoc, diag::err_ms_property_missing_accessor_kind);
661 HasInvalidAccessor =
true;
662 goto next_property_accessor;
666 Diag(KindLoc, diag::err_ms_property_unknown_accessor);
667 HasInvalidAccessor =
true;
686 if (!Tok.
is(tok::identifier)) {
691 if (
Kind == AK_Invalid) {
693 }
else if (AccessorNames[
Kind] !=
nullptr) {
695 Diag(KindLoc, diag::err_ms_property_duplicate_accessor) << KindStr;
701 next_property_accessor:
707 if (Tok.
is(tok::r_paren))
710 Diag(Tok.
getLocation(), diag::err_ms_property_expected_comma_or_rparen);
715 if (!HasInvalidAccessor)
717 AccessorNames[AK_Get], AccessorNames[AK_Put],
720 return !HasInvalidAccessor;
724 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs,
nullptr,
nullptr,
730 Diag(OpenParenLoc, diag::err_attribute_requires_arguments) << AttrName;
743 assert(
getLangOpts().DeclSpecKeyword &&
"__declspec keyword is not enabled");
744 assert(Tok.
is(tok::kw___declspec) &&
"Not a declspec!");
749 while (Tok.
is(tok::kw___declspec)) {
752 if (T.expectAndConsume(diag::err_expected_lparen_after,
"__declspec",
758 while (Tok.
isNot(tok::r_paren)) {
763 if (Tok.
is(tok::code_completion)) {
771 bool IsString = Tok.
getKind() == tok::string_literal;
772 if (!IsString && Tok.
getKind() != tok::identifier &&
773 Tok.
getKind() != tok::kw_restrict) {
774 Diag(Tok, diag::err_ms_declspec_type);
784 StringRef Str = PP.
getSpelling(Tok, StrBuffer, &Invalid);
790 AttrNameLoc = ConsumeStringToken();
796 bool AttrHandled =
false;
799 if (Tok.
is(tok::l_paren))
800 AttrHandled = ParseMicrosoftDeclSpecArgs(AttrName, AttrNameLoc, Attrs);
801 else if (AttrName->
getName() ==
"property")
807 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
811 EndLoc = T.getCloseLocation();
821 case tok::kw___fastcall:
822 case tok::kw___stdcall:
823 case tok::kw___thiscall:
824 case tok::kw___regcall:
825 case tok::kw___cdecl:
826 case tok::kw___vectorcall:
827 case tok::kw___ptr64:
829 case tok::kw___ptr32:
831 case tok::kw___uptr: {
834 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
844 void Parser::DiagnoseAndSkipExtendedMicrosoftTypeAttributes() {
850 Diag(StartLoc, diag::warn_microsoft_qualifiers_ignored) <<
Range;
860 case tok::kw_volatile:
861 case tok::kw___fastcall:
862 case tok::kw___stdcall:
863 case tok::kw___thiscall:
864 case tok::kw___cdecl:
865 case tok::kw___vectorcall:
866 case tok::kw___ptr32:
867 case tok::kw___ptr64:
869 case tok::kw___unaligned:
882 while (Tok.
is(tok::kw___pascal)) {
885 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
892 while (Tok.
is(tok::kw___kernel)) {
895 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
901 while (Tok.
is(tok::kw___noinline__)) {
904 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
912 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
920 case tok::kw__Nonnull:
921 case tok::kw__Nullable:
922 case tok::kw__Nullable_result:
923 case tok::kw__Null_unspecified: {
927 Diag(AttrNameLoc, diag::ext_nullability)
929 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
940 return (Separator ==
'.' || Separator ==
'_');
951 VersionTuple Parser::ParseVersionTuple(
SourceRange &Range) {
954 if (!Tok.
is(tok::numeric_constant)) {
955 Diag(Tok, diag::err_expected_version);
958 return VersionTuple();
967 const char *ThisTokBegin = &Buffer[0];
971 unsigned ActualLength = PP.
getSpelling(Tok, ThisTokBegin, &Invalid);
973 return VersionTuple();
976 unsigned AfterMajor = 0;
978 while (AfterMajor < ActualLength &&
isDigit(ThisTokBegin[AfterMajor])) {
979 Major = Major * 10 + ThisTokBegin[AfterMajor] -
'0';
983 if (AfterMajor == 0) {
984 Diag(Tok, diag::err_expected_version);
987 return VersionTuple();
990 if (AfterMajor == ActualLength) {
995 Diag(Tok, diag::err_zero_version);
996 return VersionTuple();
999 return VersionTuple(Major);
1002 const char AfterMajorSeparator = ThisTokBegin[AfterMajor];
1004 || (AfterMajor + 1 == ActualLength)) {
1005 Diag(Tok, diag::err_expected_version);
1008 return VersionTuple();
1012 unsigned AfterMinor = AfterMajor + 1;
1014 while (AfterMinor < ActualLength &&
isDigit(ThisTokBegin[AfterMinor])) {
1015 Minor = Minor * 10 + ThisTokBegin[AfterMinor] -
'0';
1019 if (AfterMinor == ActualLength) {
1023 if (Major == 0 && Minor == 0) {
1024 Diag(Tok, diag::err_zero_version);
1025 return VersionTuple();
1028 return VersionTuple(Major, Minor);
1031 const char AfterMinorSeparator = ThisTokBegin[AfterMinor];
1034 Diag(Tok, diag::err_expected_version);
1037 return VersionTuple();
1041 if (AfterMajorSeparator != AfterMinorSeparator)
1042 Diag(Tok, diag::warn_expected_consistent_version_separator);
1045 unsigned AfterSubminor = AfterMinor + 1;
1046 unsigned Subminor = 0;
1047 while (AfterSubminor < ActualLength &&
isDigit(ThisTokBegin[AfterSubminor])) {
1048 Subminor = Subminor * 10 + ThisTokBegin[AfterSubminor] -
'0';
1052 if (AfterSubminor != ActualLength) {
1053 Diag(Tok, diag::err_expected_version);
1056 return VersionTuple();
1059 return VersionTuple(Major, Minor, Subminor);
1087 void Parser::ParseAvailabilityAttribute(
IdentifierInfo &Availability,
1094 enum { Introduced, Deprecated, Obsoleted,
Unknown };
1100 if (T.consumeOpen()) {
1101 Diag(Tok, diag::err_expected) << tok::l_paren;
1106 if (Tok.
isNot(tok::identifier)) {
1107 Diag(Tok, diag::err_availability_expected_platform);
1114 if (Ident->getName() ==
"macosx")
1118 else if (Ident->getName() ==
"macosx_app_extension")
1122 AvailabilityAttr::canonicalizePlatformName(Ident->getName()));
1126 if (ExpectAndConsume(tok::comma)) {
1133 if (!Ident_introduced) {
1147 if (Tok.
isNot(tok::identifier)) {
1148 Diag(Tok, diag::err_availability_expected_change);
1155 if (Keyword == Ident_strict) {
1157 Diag(KeywordLoc, diag::err_availability_redundant)
1160 StrictLoc = KeywordLoc;
1164 if (Keyword == Ident_unavailable) {
1165 if (UnavailableLoc.
isValid()) {
1166 Diag(KeywordLoc, diag::err_availability_redundant)
1169 UnavailableLoc = KeywordLoc;
1173 if (Keyword == Ident_deprecated && Platform->
Ident &&
1176 if (Changes[Deprecated].KeywordLoc.
isValid()) {
1177 Diag(KeywordLoc, diag::err_availability_redundant)
1184 Changes[Deprecated].
Version = VersionTuple(1);
1188 if (Tok.
isNot(tok::equal)) {
1189 Diag(Tok, diag::err_expected_after) << Keyword << tok::equal;
1194 if (Keyword == Ident_message || Keyword == Ident_replacement) {
1195 if (Tok.
isNot(tok::string_literal)) {
1196 Diag(Tok, diag::err_expected_string_literal)
1201 if (Keyword == Ident_message)
1207 cast_or_null<StringLiteral>(MessageExpr.
get())) {
1208 if (!MessageStringLiteral->isAscii()) {
1209 Diag(MessageStringLiteral->getSourceRange().getBegin(),
1210 diag::err_expected_string_literal)
1216 if (Keyword == Ident_message)
1224 if ((Keyword == Ident_introduced || Keyword == Ident_deprecated) &&
1225 Tok.
is(tok::identifier)) {
1229 if (Keyword == Ident_introduced)
1230 UnavailableLoc = KeywordLoc;
1236 VersionTuple Version = ParseVersionTuple(VersionRange);
1238 if (Version.empty()) {
1244 if (Keyword == Ident_introduced)
1246 else if (Keyword == Ident_deprecated)
1248 else if (Keyword == Ident_obsoleted)
1253 if (Index < Unknown) {
1254 if (!Changes[Index].KeywordLoc.
isInvalid()) {
1255 Diag(KeywordLoc, diag::err_availability_redundant)
1258 Changes[Index].VersionRange.
getEnd());
1262 Changes[Index].
Version = Version;
1265 Diag(KeywordLoc, diag::err_availability_unknown_change)
1266 << Keyword << VersionRange;
1272 if (T.consumeClose())
1276 *endLoc = T.getCloseLocation();
1280 if (UnavailableLoc.
isValid()) {
1281 bool Complained =
false;
1282 for (
unsigned Index = Introduced; Index !=
Unknown; ++Index) {
1283 if (Changes[Index].KeywordLoc.
isValid()) {
1285 Diag(UnavailableLoc, diag::warn_availability_and_unavailable)
1287 Changes[Index].VersionRange.
getEnd());
1298 attrs.
addNew(&Availability,
1299 SourceRange(AvailabilityLoc, T.getCloseLocation()),
1300 ScopeName, ScopeLoc,
1302 Changes[Introduced],
1303 Changes[Deprecated],
1305 UnavailableLoc, MessageExpr.
get(),
1306 Syntax, StrictLoc, ReplacementExpr.
get());
1322 void Parser::ParseExternalSourceSymbolAttribute(
1328 if (T.expectAndConsume())
1332 if (!Ident_language) {
1339 bool HasLanguage =
false;
1341 bool HasDefinedIn =
false;
1346 if (Tok.
isNot(tok::identifier)) {
1347 Diag(Tok, diag::err_external_source_symbol_expected_keyword);
1354 if (Keyword == Ident_generated_declaration) {
1355 if (GeneratedDeclaration) {
1356 Diag(Tok, diag::err_external_source_symbol_duplicate_clause) << Keyword;
1360 GeneratedDeclaration = ParseIdentifierLoc();
1364 if (Keyword != Ident_language && Keyword != Ident_defined_in) {
1365 Diag(Tok, diag::err_external_source_symbol_expected_keyword);
1371 if (ExpectAndConsume(tok::equal, diag::err_expected_after,
1377 bool HadLanguage = HasLanguage, HadDefinedIn = HasDefinedIn;
1378 if (Keyword == Ident_language)
1381 HasDefinedIn =
true;
1383 if (Tok.
isNot(tok::string_literal)) {
1384 Diag(Tok, diag::err_expected_string_literal)
1386 << (Keyword != Ident_language);
1390 if (Keyword == Ident_language) {
1392 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
1399 assert(Keyword == Ident_defined_in &&
"Invalid clause keyword!");
1401 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
1411 if (T.consumeClose())
1414 *EndLoc = T.getCloseLocation();
1417 GeneratedDeclaration};
1419 ScopeName, ScopeLoc, Args, llvm::array_lengthof(Args), Syntax);
1433 void Parser::ParseObjCBridgeRelatedAttribute(
1439 if (T.consumeOpen()) {
1440 Diag(Tok, diag::err_expected) << tok::l_paren;
1445 if (Tok.
isNot(tok::identifier)) {
1446 Diag(Tok, diag::err_objcbridge_related_expected_related_class);
1451 if (ExpectAndConsume(tok::comma)) {
1460 if (Tok.
is(tok::identifier)) {
1463 Diag(Tok, diag::err_objcbridge_related_selector_name);
1469 if (Tok.
is(tok::colon))
1470 Diag(Tok, diag::err_objcbridge_related_selector_name);
1472 Diag(Tok, diag::err_expected) << tok::comma;
1480 if (Tok.
is(tok::identifier))
1482 else if (Tok.
isNot(tok::r_paren)) {
1483 Diag(Tok, diag::err_expected) << tok::r_paren;
1489 if (T.consumeClose())
1493 *EndLoc = T.getCloseLocation();
1496 Attrs.
addNew(&ObjCBridgeRelated,
1497 SourceRange(ObjCBridgeRelatedLoc, T.getCloseLocation()),
1498 ScopeName, ScopeLoc, RelatedClass, ClassMethod, InstanceMethod,
1502 void Parser::ParseSwiftNewTypeAttribute(
1509 if (T.consumeOpen()) {
1510 Diag(Tok, diag::err_expected) << tok::l_paren;
1514 if (Tok.
is(tok::r_paren)) {
1519 if (Tok.
isNot(tok::kw_struct) && Tok.
isNot(tok::kw_enum)) {
1520 Diag(Tok, diag::warn_attribute_type_not_supported)
1522 if (!isTokenSpecial())
1533 if (T.consumeClose())
1536 *EndLoc = T.getCloseLocation();
1540 ScopeName, ScopeLoc, Args, llvm::array_lengthof(Args), Syntax);
1543 void Parser::ParseTypeTagForDatatypeAttribute(
IdentifierInfo &AttrName,
1550 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
1555 if (Tok.
isNot(tok::identifier)) {
1556 Diag(Tok, diag::err_expected) << tok::identifier;
1562 if (ExpectAndConsume(tok::comma)) {
1574 bool LayoutCompatible =
false;
1575 bool MustBeNull =
false;
1577 if (Tok.
isNot(tok::identifier)) {
1578 Diag(Tok, diag::err_expected) << tok::identifier;
1583 if (Flag->
isStr(
"layout_compatible"))
1584 LayoutCompatible =
true;
1585 else if (Flag->
isStr(
"must_be_null"))
1588 Diag(Tok, diag::err_type_safety_unknown_flag) << Flag;
1595 if (!T.consumeClose()) {
1597 ArgumentKind, MatchingCType.
get(),
1598 LayoutCompatible, MustBeNull, Syntax);
1602 *EndLoc = T.getCloseLocation();
1613 bool Parser::DiagnoseProhibitedCXX11Attribute() {
1614 assert(Tok.
is(tok::l_square) &&
NextToken().is(tok::l_square));
1616 switch (isCXX11AttributeSpecifier(
true)) {
1617 case CAK_NotAttributeSpecifier:
1621 case CAK_InvalidAttributeSpecifier:
1625 case CAK_AttributeSpecifier:
1630 assert(Tok.
is(tok::r_square) &&
"isCXX11AttributeSpecifier lied");
1632 Diag(BeginLoc, diag::err_attributes_not_allowed)
1636 llvm_unreachable(
"All cases handled above.");
1645 assert((Tok.
is(tok::l_square) &&
NextToken().is(tok::l_square)) ||
1646 Tok.
is(tok::kw_alignas));
1650 ParseCXX11Attributes(Attrs);
1653 Diag(Loc, diag::err_attributes_not_allowed)
1658 void Parser::DiagnoseProhibitedAttributes(
1660 if (CorrectLocation.
isValid()) {
1662 Diag(CorrectLocation, diag::err_attributes_misplaced)
1666 Diag(
Range.getBegin(), diag::err_attributes_not_allowed) <<
Range;
1669 void Parser::ProhibitCXX11Attributes(
ParsedAttributes &Attrs,
unsigned DiagID,
1670 bool DiagnoseEmptyAttrs,
1671 bool WarnOnUnknownAttrs) {
1681 if (FirstLSquare.
is(tok::l_square)) {
1685 if (SecondLSquare && SecondLSquare->is(tok::l_square)) {
1696 if (!AL.isCXX11Attribute() && !AL.isC2xAttribute())
1699 if (WarnOnUnknownAttrs)
1700 Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
1701 << AL << AL.getRange();
1703 Diag(AL.getLoc(), DiagID) << AL;
1711 if (PA.isCXX11Attribute() || PA.isC2xAttribute())
1712 Diag(PA.getLoc(), diag::ext_cxx11_attr_placement) << PA << PA.getRange();
1732 if ((AL.getKind() == ParsedAttr::AT_Aligned &&
1733 AL.isDeclspecAttribute()) ||
1734 AL.isMicrosoftAttribute())
1735 ToBeMoved.push_back(&AL);
1769 Decl *SingleDecl =
nullptr;
1771 case tok::kw_template:
1772 case tok::kw_export:
1773 ProhibitAttributes(Attrs);
1774 SingleDecl = ParseDeclarationStartingWithTemplate(Context, DeclEnd, Attrs);
1776 case tok::kw_inline:
1779 ProhibitAttributes(Attrs);
1781 return ParseNamespace(Context, DeclEnd, InlineLoc);
1783 return ParseSimpleDeclaration(Context, DeclEnd, Attrs,
true,
nullptr,
1785 case tok::kw_namespace:
1786 ProhibitAttributes(Attrs);
1787 return ParseNamespace(Context, DeclEnd);
1789 return ParseUsingDirectiveOrDeclaration(Context, ParsedTemplateInfo(),
1791 case tok::kw_static_assert:
1792 case tok::kw__Static_assert:
1793 ProhibitAttributes(Attrs);
1794 SingleDecl = ParseStaticAssertDeclaration(DeclEnd);
1797 return ParseSimpleDeclaration(Context, DeclEnd, Attrs,
true,
nullptr,
1829 bool RequireSemi, ForRangeInit *FRI,
SourceLocation *DeclSpecStart) {
1833 DeclSpecContext DSContext = getDeclSpecContextFromDeclaratorContext(Context);
1834 ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(),
AS_none, DSContext);
1839 DiagnoseMissingSemiAfterTagDefinition(DS,
AS_none, DSContext))
1844 if (Tok.
is(tok::semi)) {
1845 ProhibitAttributes(Attrs);
1851 DS.complete(TheDecl);
1853 Decl* decls[] = {AnonRecord, TheDecl};
1863 return ParseDeclGroup(DS, Context, &DeclEnd, FRI);
1870 case tok::annot_cxxscope:
1871 case tok::annot_template_id:
1873 case tok::code_completion:
1874 case tok::coloncolon:
1876 case tok::kw___attribute:
1877 case tok::kw_operator:
1893 case tok::identifier:
1895 case tok::code_completion:
1896 case tok::coloncolon:
1899 case tok::equalequal:
1900 case tok::kw_alignas:
1902 case tok::kw___attribute:
1920 case tok::identifier:
1943 if (Tok.
isOneOf(tok::comma, tok::l_brace, tok::kw_try)) {
1967 case tok::kw_inline:
1972 (!ParsingInObjCContainer || CurParsedObjCImpl))
1976 case tok::kw_namespace:
1981 (!ParsingInObjCContainer || CurParsedObjCImpl))
1987 if (
NextToken().isObjCAtKeyword(tok::objc_end) &&
1988 ParsingInObjCContainer)
2000 case tok::annot_module_begin:
2001 case tok::annot_module_end:
2002 case tok::annot_module_include:
2019 ForRangeInit *FRI) {
2030 if (Tok.
is(tok::kw_requires))
2031 ParseTrailingRequiresClause(D);
2036 LateParsedAttrList LateParsedAttrs(
true);
2038 MaybeParseGNUAttributes(D, &LateParsedAttrs);
2043 if (Tok.
is(tok::kw__Noreturn)) {
2045 const char *PrevSpec;
2051 MaybeParseGNUAttributes(D, &LateParsedAttrs);
2052 Fixit &= Tok.
isOneOf(tok::semi, tok::l_brace, tok::kw_try);
2054 Diag(Loc, diag::err_c11_noreturn_misplaced)
2056 << (Fixit ?
FixItHint::CreateInsertion(D.getBeginLoc(),
"_Noreturn ")
2063 if (Tok.
is(tok::equal) &&
NextToken().is(tok::code_completion)) {
2074 while (
auto Specifier = isCXX11VirtSpecifier()) {
2075 Diag(Tok, diag::err_virt_specifier_outside_class)
2083 if (!isDeclarationAfterDeclarator()) {
2089 if (isStartOfFunctionDefinition(D)) {
2091 Diag(Tok, diag::err_function_declared_typedef);
2097 Decl *TheDecl = ParseFunctionDefinition(D, ParsedTemplateInfo(),
2102 if (isDeclarationSpecifier()) {
2110 Diag(Tok, diag::err_expected_fn_body);
2115 if (Tok.
is(tok::l_brace)) {
2116 Diag(Tok, diag::err_function_definition_not_allowed);
2124 if (ParseAsmAttributesAfterDeclarator(D))
2133 if (FRI && (Tok.
is(tok::colon) || isTokIdentifier_in())) {
2134 bool IsForRangeLoop =
false;
2136 IsForRangeLoop =
true;
2139 if (Tok.
is(tok::l_brace))
2140 FRI->RangeExpr = ParseBraceInitializer();
2146 if (IsForRangeLoop) {
2150 if (
auto *VD = dyn_cast_or_null<VarDecl>(ThisDecl))
2151 VD->setObjCForDecl(
true);
2154 D.complete(ThisDecl);
2159 Decl *FirstDecl = ParseDeclarationAfterDeclaratorAndAttributes(
2160 D, ParsedTemplateInfo(), FRI);
2161 if (LateParsedAttrs.size() > 0)
2162 ParseLexedAttributeList(LateParsedAttrs, FirstDecl,
true,
false);
2163 D.complete(FirstDecl);
2165 DeclsInGroup.push_back(FirstDecl);
2173 if (Tok.
isAtStartOfLine() && ExpectSemi && !MightBeDeclarator(Context)) {
2177 Diag(CommaLoc, diag::err_expected_semi_declaration)
2194 MaybeParseGNUAttributes(D);
2198 DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2206 if (Tok.
is(tok::kw_requires))
2207 ParseTrailingRequiresClause(D);
2208 Decl *ThisDecl = ParseDeclarationAfterDeclarator(D);
2209 D.complete(ThisDecl);
2211 DeclsInGroup.push_back(ThisDecl);
2218 if (ExpectSemi && ExpectAndConsumeSemi(
2220 ? diag::err_invalid_token_after_toplevel_declarator
2221 : diag::err_expected_semi_declaration)) {
2225 if (!isDeclarationSpecifier()) {
2236 bool Parser::ParseAsmAttributesAfterDeclarator(
Declarator &D) {
2238 if (Tok.
is(tok::kw_asm)) {
2240 ExprResult AsmLabel(ParseSimpleAsm(
true, &Loc));
2241 if (AsmLabel.isInvalid()) {
2250 MaybeParseGNUAttributes(D);
2276 Decl *Parser::ParseDeclarationAfterDeclarator(
2277 Declarator &D,
const ParsedTemplateInfo &TemplateInfo) {
2278 if (ParseAsmAttributesAfterDeclarator(D))
2281 return ParseDeclarationAfterDeclaratorAndAttributes(D, TemplateInfo);
2284 Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
2285 Declarator &D,
const ParsedTemplateInfo &TemplateInfo, ForRangeInit *FRI) {
2287 struct InitializerScopeRAII {
2293 :
P(
P), D(D), ThisDecl(ThisDecl) {
2294 if (ThisDecl &&
P.getLangOpts().CPlusPlus) {
2298 S =
P.getCurScope();
2300 P.Actions.ActOnCXXEnterDeclInitializer(S, ThisDecl);
2303 ~InitializerScopeRAII() { pop(); }
2305 if (ThisDecl &&
P.getLangOpts().CPlusPlus) {
2308 S =
P.getCurScope();
2309 P.Actions.ActOnCXXExitDeclInitializer(S, ThisDecl);
2318 InitKind TheInitKind;
2320 if (isTokenEqualOrEqualTypo())
2321 TheInitKind = InitKind::Equal;
2322 else if (Tok.
is(tok::l_paren))
2323 TheInitKind = InitKind::CXXDirect;
2326 TheInitKind = InitKind::CXXBraced;
2333 Decl *ThisDecl =
nullptr;
2334 Decl *OuterDecl =
nullptr;
2335 switch (TemplateInfo.Kind) {
2336 case ParsedTemplateInfo::NonTemplate:
2340 case ParsedTemplateInfo::Template:
2341 case ParsedTemplateInfo::ExplicitSpecialization: {
2343 *TemplateInfo.TemplateParams,
2345 if (
VarTemplateDecl *VT = dyn_cast_or_null<VarTemplateDecl>(ThisDecl)) {
2348 ThisDecl = VT->getTemplatedDecl();
2353 case ParsedTemplateInfo::ExplicitInstantiation: {
2354 if (Tok.
is(tok::semi)) {
2356 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc, D);
2361 ThisDecl = ThisRes.
get();
2369 Diag(Tok, diag::err_template_defn_explicit_instantiation)
2376 diag::err_explicit_instantiation_with_definition)
2384 LAngleLoc,
nullptr));
2394 switch (TheInitKind) {
2396 case InitKind::Equal: {
2399 if (Tok.
is(tok::kw_delete)) {
2405 }
else if (Tok.
is(tok::kw_default)) {
2413 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2415 if (Tok.
is(tok::code_completion)) {
2428 Diag(EqualLoc, diag::err_single_decl_assign_in_for_range)
2432 FRI->ColonLoc = EqualLoc;
2434 FRI->RangeExpr = Init;
2439 if (Init.isInvalid()) {
2441 StopTokens.push_back(tok::comma);
2444 StopTokens.push_back(tok::r_paren);
2453 case InitKind::CXXDirect: {
2459 CommaLocsTy CommaLocs;
2461 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2463 auto ThisVarDecl = dyn_cast_or_null<VarDecl>(ThisDecl);
2464 auto RunSignatureHelp = [&]() {
2466 ThisVarDecl->getType()->getCanonicalTypeInternal(),
2467 ThisDecl->
getLocation(), Exprs, T.getOpenLocation(),
2469 CalledSignatureHelp =
true;
2470 return PreferredType;
2472 auto SetPreferredType = [&] {
2473 PreferredType.enterFunctionArgument(Tok.
getLocation(), RunSignatureHelp);
2476 llvm::function_ref<void()> ExpressionStarts;
2482 ExpressionStarts = SetPreferredType;
2484 if (ParseExpressionList(Exprs, CommaLocs, ExpressionStarts)) {
2487 ThisVarDecl->getType()->getCanonicalTypeInternal(),
2488 ThisDecl->
getLocation(), Exprs, T.getOpenLocation(),
2490 CalledSignatureHelp =
true;
2498 assert(!Exprs.empty() && Exprs.size()-1 == CommaLocs.size() &&
2499 "Unexpected number of commas!");
2504 T.getCloseLocation(),
2511 case InitKind::CXXBraced: {
2513 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
2515 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2517 PreferredType.enterVariableInit(Tok.
getLocation(), ThisDecl);
2522 if (Init.isInvalid()) {
2535 return OuterDecl ? OuterDecl : ThisDecl;
2545 DeclSpecContext DSC) {
2549 ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS, DSC);
2554 Diag(Tok, diag::err_expected_type);
2557 Diag(Tok, diag::err_typename_requires_specqual);
2568 diag::err_typename_invalid_storageclass);
2610 return T.
isOneOf(tok::l_square, tok::l_paren, tok::r_paren, tok::semi,
2611 tok::comma, tok::equal, tok::kw_asm, tok::l_brace,
2625 const ParsedTemplateInfo &TemplateInfo,
2628 assert(Tok.
is(tok::identifier) &&
"should have identifier");
2650 if (!isTypeSpecifier(DSC) &&
getLangOpts().isImplicitIntAllowed() &&
2668 AnnotateScopeToken(*SS,
false);
2679 DSC == DeclSpecContext::DSC_template_type_arg)) {
2680 const char *PrevSpec;
2696 if (SS ==
nullptr) {
2697 const char *TagName =
nullptr, *FixitTagName =
nullptr;
2703 TagName=
"enum" ; FixitTagName =
"enum " ; TagKind=tok::kw_enum ;
break;
2705 TagName=
"union" ; FixitTagName =
"union " ;TagKind=tok::kw_union ;
break;
2707 TagName=
"struct"; FixitTagName =
"struct ";TagKind=tok::kw_struct;
break;
2709 TagName=
"__interface"; FixitTagName =
"__interface ";
2710 TagKind=tok::kw___interface;
break;
2712 TagName=
"class" ; FixitTagName =
"class " ;TagKind=tok::kw_class ;
break;
2720 Diag(Loc, diag::err_use_of_tag_name_without_tag)
2721 << TokenName << TagName <<
getLangOpts().CPlusPlus
2727 Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
2728 << TokenName << TagName;
2732 if (TagKind == tok::kw_enum)
2733 ParseEnumSpecifier(Loc, DS, TemplateInfo, AS,
2734 DeclSpecContext::DSC_normal);
2736 ParseClassSpecifier(TagKind, Loc, DS, TemplateInfo, AS,
2738 DeclSpecContext::DSC_normal, Attrs);
2745 if (!isTypeSpecifier(DSC) && (!SS || DSC == DeclSpecContext::DSC_top_level ||
2746 DSC == DeclSpecContext::DSC_class)) {
2750 case tok::l_paren: {
2757 TentativeParsingAction PA(*
this);
2759 TPResult TPR = TryParseDeclarator(
false);
2762 if (TPR != TPResult::False) {
2770 if (DSC == DeclSpecContext::DSC_class ||
2771 (DSC == DeclSpecContext::DSC_top_level && SS)) {
2774 Diag(Loc, diag::err_constructor_bad_name)
2795 AnnotateScopeToken(*SS,
false);
2817 const char *PrevSpec;
2838 if (IsTemplateName) {
2840 TemplateArgList Args;
2841 ParseTemplateIdAfterTemplateName(
true, LAngle, Args, RAngle);
2855 Parser::DeclSpecContext
2858 return DeclSpecContext::DSC_class;
2860 return DeclSpecContext::DSC_top_level;
2862 return DeclSpecContext::DSC_template_param;
2865 return DeclSpecContext::DSC_template_type_arg;
2868 return DeclSpecContext::DSC_trailing;
2871 return DeclSpecContext::DSC_alias_declaration;
2872 return DeclSpecContext::DSC_normal;
2887 if (isTypeIdInParens()) {
2912 assert(Tok.
isOneOf(tok::kw_alignas, tok::kw__Alignas) &&
2913 "Not an alignment-specifier!");
2919 if (T.expectAndConsume())
2923 ExprResult ArgExpr = ParseAlignArgument(T.getOpenLocation(), EllipsisLoc);
2931 *EndLoc = T.getCloseLocation();
2934 ArgExprs.push_back(ArgExpr.
get());
2935 Attrs.
addNew(KWName, KWLoc,
nullptr, KWLoc, ArgExprs.data(), 1,
2939 ExprResult Parser::ParseExtIntegerArgument() {
2940 assert(Tok.
isOneOf(tok::kw__ExtInt, tok::kw__BitInt) &&
2941 "Not an extended int type");
2945 if (T.expectAndConsume())
2954 if(T.consumeClose())
2968 DeclSpecContext DSContext,
2969 LateParsedAttrList *LateAttrs) {
2972 bool EnteringContext = (DSContext == DeclSpecContext::DSC_class ||
2973 DSContext == DeclSpecContext::DSC_top_level);
2976 Tok.
isOneOf(tok::identifier, tok::coloncolon, tok::kw_decltype,
2977 tok::annot_template_id) &&
2983 bool HasScope = Tok.
is(tok::annot_cxxscope);
2989 bool MightBeDeclarator =
true;
2990 if (Tok.
isOneOf(tok::kw_typename, tok::annot_typename)) {
2992 MightBeDeclarator =
false;
2993 }
else if (AfterScope.
is(tok::annot_template_id)) {
2999 MightBeDeclarator =
false;
3000 }
else if (AfterScope.
is(tok::identifier)) {
3001 const Token &Next = HasScope ? GetLookAheadToken(2) :
NextToken();
3005 if (Next.isOneOf(tok::star, tok::amp, tok::ampamp, tok::identifier,
3006 tok::annot_cxxscope, tok::coloncolon)) {
3008 MightBeDeclarator =
false;
3009 }
else if (HasScope) {
3020 switch (Classification.
getKind()) {
3026 llvm_unreachable(
"typo correction is not possible here");
3033 MightBeDeclarator =
false;
3049 if (MightBeDeclarator)
3054 diag::err_expected_after)
3065 ParsedTemplateInfo NotATemplate;
3066 ParseDeclarationSpecifiers(DS, NotATemplate, AS, DSContext, LateAttrs);
3073 const char *&PrevSpec,
unsigned &DiagID,
3075 assert(!LangOpts.FixedPoint);
3076 DiagID = diag::err_fixed_point_not_enabled;
3108 void Parser::ParseDeclarationSpecifiers(
DeclSpec &DS,
3109 const ParsedTemplateInfo &TemplateInfo,
3111 DeclSpecContext DSContext,
3112 LateParsedAttrList *LateAttrs) {
3121 bool EnteringContext = (DSContext == DeclSpecContext::DSC_class ||
3122 DSContext == DeclSpecContext::DSC_top_level);
3123 bool AttrsLastTime =
false;
3129 bool isStorageClass =
false;
3130 const char *PrevSpec =
nullptr;
3131 unsigned DiagID = 0;
3152 auto handleOpenCLImageKW = [&] (StringRef Ext,
TypeSpecifierType ImageTypeSpec) {
3166 bool IsTemplateSpecOrInst =
3167 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
3168 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
3174 ProhibitAttributes(attrs);
3179 ProhibitCXX11Attributes(attrs, diag::err_attribute_not_type_attr);
3186 DS.
Finish(Actions, Policy);
3190 case tok::kw_alignas:
3191 if (!standardAttributesAllowed() || !isCXX11AttributeSpecifier())
3192 goto DoneWithDeclSpec;
3194 ProhibitAttributes(attrs);
3201 ParseCXX11Attributes(attrs);
3202 AttrsLastTime =
true;
3205 case tok::code_completion: {
3208 bool AllowNonIdentifiers
3214 bool AllowNestedNameSpecifiers
3215 = DSContext == DeclSpecContext::DSC_top_level ||
3220 AllowNonIdentifiers,
3221 AllowNestedNameSpecifiers);
3227 else if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate)
3230 else if (DSContext == DeclSpecContext::DSC_class)
3232 else if (CurParsedObjCImpl)
3240 case tok::coloncolon:
3245 goto DoneWithDeclSpec;
3247 if (Tok.
is(tok::coloncolon))
3248 goto DoneWithDeclSpec;
3251 case tok::annot_cxxscope: {
3253 goto DoneWithDeclSpec;
3264 ? takeTemplateIdAnnotation(Next)
3270 ConsumeAnnotationToken();
3284 if ((DSContext == DeclSpecContext::DSC_top_level ||
3285 DSContext == DeclSpecContext::DSC_class) &&
3288 isConstructorDeclarator(
false)) {
3293 goto DoneWithDeclSpec;
3297 ConsumeAnnotationToken();
3298 assert(Tok.
is(tok::annot_template_id) &&
3299 "ParseOptionalCXXScopeSpecifier not working");
3300 AnnotateTemplateIdTokenAsType(SS);
3305 GetLookAheadToken(2).
isOneOf(tok::kw_auto, tok::kw_decltype)) {
3310 ConsumeAnnotationToken();
3314 if (Next.is(tok::annot_typename)) {
3316 ConsumeAnnotationToken();
3320 PrevSpec, DiagID, T, Policy);
3324 ConsumeAnnotationToken();
3327 if (Next.isNot(tok::identifier))
3328 goto DoneWithDeclSpec;
3333 if ((DSContext == DeclSpecContext::DSC_top_level ||
3334 DSContext == DeclSpecContext::DSC_class) &&
3337 isConstructorDeclarator(
false))
3338 goto DoneWithDeclSpec;
3347 Actions.
getTypeName(*Next.getIdentifierInfo(), Next.getLocation(),
3351 isClassTemplateDeductionContext(DSContext));
3353 if (IsTemplateSpecOrInst)
3361 if (TryAnnotateTypeConstraint())
3362 goto DoneWithDeclSpec;
3363 if (Tok.
isNot(tok::annot_cxxscope) ||
3367 ConsumeAnnotationToken();
3369 if (ParseImplicitInt(DS, &SS, TemplateInfo, AS, DSContext, Attrs)) {
3370 if (!Attrs.
empty()) {
3371 AttrsLastTime =
true;
3376 goto DoneWithDeclSpec;
3380 ConsumeAnnotationToken();
3383 DiagID, TypeRep, Policy);
3393 case tok::annot_typename: {
3397 goto DoneWithDeclSpec;
3406 ConsumeAnnotationToken();
3411 case tok::kw___is_signed:
3422 TryKeywordIdentFallback(
true);
3425 goto DoneWithDeclSpec;
3428 case tok::kw___super:
3429 case tok::kw_decltype:
3430 case tok::identifier: {
3435 goto DoneWithDeclSpec;
3441 if (!
getLangOpts().DeclSpecKeyword && Tok.
is(tok::identifier) &&
3443 Diag(Loc, diag::err_ms_attributes_not_enabled);
3453 if (T.consumeOpen()) {
3454 assert(
false &&
"Not a left paren?");
3473 if (IsTemplateSpecOrInst)
3477 if (IsTemplateSpecOrInst)
3480 goto DoneWithDeclSpec;
3483 if (!Tok.
is(tok::identifier))
3488 if (TryAltiVecToken(DS, Loc, PrevSpec, DiagID,
isInvalid))
3494 goto DoneWithDeclSpec;
3496 if (DSContext == DeclSpecContext::DSC_objc_method_result &&
3497 isObjCInstancetype()) {
3501 DiagID, TypeRep, Policy);
3514 isConstructorDeclarator(
true))
3515 goto DoneWithDeclSpec;
3519 false,
false,
nullptr,
false,
false,
3520 isClassTemplateDeductionContext(DSContext));
3525 if (TryAnnotateTypeConstraint())
3526 goto DoneWithDeclSpec;
3527 if (Tok.
isNot(tok::identifier))
3530 if (ParseImplicitInt(DS,
nullptr, TemplateInfo, AS, DSContext, Attrs)) {
3531 if (!Attrs.
empty()) {
3532 AttrsLastTime =
true;
3537 goto DoneWithDeclSpec;
3543 (DSContext == DeclSpecContext::DSC_class ||
3544 DSContext == DeclSpecContext::DSC_top_level) &&
3547 isConstructorDeclarator(
true,
3549 goto DoneWithDeclSpec;
3552 DiagID, TypeRep, Policy);
3564 TypeResult NewTypeRep = parseObjCTypeArgsAndProtocolQualifiers(
3579 case tok::annot_template_id: {
3591 TemplateId =
nullptr;
3594 Diag(Loc, diag::err_placeholder_expected_auto_or_decltype_auto)
3598 TemplateId, Policy);
3602 goto DoneWithDeclSpec;
3603 ConsumeAnnotationToken();
3607 if (Tracker.consumeOpen()) {
3609 Diag(Tok, diag::err_expected) << tok::l_paren;
3613 Tracker.skipToEnd();
3614 Diag(Tok, diag::err_placeholder_expected_auto_or_decltype_auto)
3619 Tracker.consumeClose();
3627 DiagID, TemplateId, Policy);
3630 TemplateId, Policy);
3639 goto DoneWithDeclSpec;
3647 isConstructorDeclarator(
true))
3648 goto DoneWithDeclSpec;
3653 AnnotateTemplateIdTokenAsType(SS);
3658 case tok::kw___attribute:
3659 case tok::kw___declspec:
3660 ParseAttributes(PAKM_GNU | PAKM_Declspec, DS.
getAttributes(), LateAttrs);
3664 case tok::kw___forceinline: {
3673 case tok::kw___unaligned:
3678 case tok::kw___sptr:
3679 case tok::kw___uptr:
3680 case tok::kw___ptr64:
3681 case tok::kw___ptr32:
3683 case tok::kw___cdecl:
3684 case tok::kw___stdcall:
3685 case tok::kw___fastcall:
3686 case tok::kw___thiscall:
3687 case tok::kw___regcall:
3688 case tok::kw___vectorcall:
3693 case tok::kw___pascal:
3698 case tok::kw___kernel:
3703 case tok::kw___noinline__:
3708 case tok::kw__Nonnull:
3709 case tok::kw__Nullable:
3710 case tok::kw__Nullable_result:
3711 case tok::kw__Null_unspecified:
3716 case tok::kw___kindof:
3723 case tok::kw_typedef:
3725 PrevSpec, DiagID, Policy);
3726 isStorageClass =
true;
3728 case tok::kw_extern:
3730 Diag(Tok, diag::ext_thread_before) <<
"extern";
3732 PrevSpec, DiagID, Policy);
3733 isStorageClass =
true;
3735 case tok::kw___private_extern__:
3737 Loc, PrevSpec, DiagID, Policy);
3738 isStorageClass =
true;
3740 case tok::kw_static:
3742 Diag(Tok, diag::ext_thread_before) <<
"static";
3744 PrevSpec, DiagID, Policy);
3745 isStorageClass =
true;
3749 if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) {
3751 PrevSpec, DiagID, Policy);
3753 Diag(Tok, diag::ext_auto_storage_class)
3760 PrevSpec, DiagID, Policy);
3761 isStorageClass =
true;
3763 case tok::kw___auto_type:
3764 Diag(Tok, diag::ext_auto_type);
3768 case tok::kw_register:
3770 PrevSpec, DiagID, Policy);
3771 isStorageClass =
true;
3773 case tok::kw_mutable:
3775 PrevSpec, DiagID, Policy);
3776 isStorageClass =
true;
3778 case tok::kw___thread:
3781 isStorageClass =
true;
3783 case tok::kw_thread_local:
3786 isStorageClass =
true;
3788 case tok::kw__Thread_local:
3790 Diag(Tok, diag::ext_c11_feature) << Tok.
getName();
3792 Loc, PrevSpec, DiagID);
3793 isStorageClass =
true;
3797 case tok::kw_inline:
3800 case tok::kw_virtual:
3804 !
getActions().getOpenCLOptions().isAvailableOption(
3806 DiagID = diag::err_openclcxx_virtual_function;
3813 case tok::kw_explicit: {
3817 ConsumedEnd = ExplicitLoc;
3819 if (Tok.
is(tok::l_paren)) {
3822 ? diag::warn_cxx17_compat_explicit_bool
3823 : diag::ext_explicit_bool);
3827 Tracker.consumeOpen();
3830 if (ExplicitExpr.isUsable()) {
3832 Tracker.consumeClose();
3836 Tracker.skipToEnd();
3842 ExplicitSpec, CloseParenLoc);
3845 case tok::kw__Noreturn:
3847 Diag(Tok, diag::ext_c11_feature) << Tok.
getName();
3852 case tok::kw__Alignas:
3854 Diag(Tok, diag::ext_c11_feature) << Tok.
getName();
3859 case tok::kw_friend:
3860 if (DSContext == DeclSpecContext::DSC_class)
3864 DiagID = diag::err_friend_invalid_in_context;
3870 case tok::kw___module_private__:
3875 case tok::kw_constexpr:
3879 case tok::kw_consteval:
3883 case tok::kw_constinit:
3899 PrevSpec, DiagID, Policy);
3901 case tok::kw___int64:
3903 PrevSpec, DiagID, Policy);
3905 case tok::kw_signed:
3909 case tok::kw_unsigned:
3913 case tok::kw__Complex:
3915 Diag(Tok, diag::ext_c99_feature) << Tok.
getName();
3919 case tok::kw__Imaginary:
3921 Diag(Tok, diag::ext_c99_feature) << Tok.
getName();
3937 case tok::kw__ExtInt:
3938 case tok::kw__BitInt: {
3939 DiagnoseBitIntUse(Tok);
3944 ConsumedEnd = PrevTokLocation;
3947 case tok::kw___int128:
3955 case tok::kw___bf16:
3963 case tok::kw_double:
3967 case tok::kw__Float16:
3971 case tok::kw__Accum:
3979 case tok::kw__Fract:
3994 case tok::kw___float128:
3998 case tok::kw___ibm128:
4002 case tok::kw_wchar_t:
4006 case tok::kw_char8_t:
4010 case tok::kw_char16_t:
4014 case tok::kw_char32_t:
4021 Diag(Tok, diag::ext_c99_feature) << Tok.
getName();
4023 if (Tok.
is(tok::kw_bool) &&
4027 DiagID = diag::err_bool_redeclaration;
4036 case tok::kw__Decimal32:
4040 case tok::kw__Decimal64:
4044 case tok::kw__Decimal128:
4048 case tok::kw___vector:
4051 case tok::kw___pixel:
4054 case tok::kw___bool:
4059 getLangOpts().getOpenCLCompatibleVersion() < 200) {
4064 goto DoneWithDeclSpec;
4066 DiagID = diag::err_opencl_unknown_type_specifier;
4073 #define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
4074 #define IMAGE_WRITE_TYPE(Type, Id, Ext)
4075 #define IMAGE_READ_TYPE(ImgType, Id, Ext) \
4076 case tok::kw_##ImgType##_t: \
4077 if (!handleOpenCLImageKW(Ext, DeclSpec::TST_##ImgType##_t)) \
4078 goto DoneWithDeclSpec; \
4080 #include "clang/Basic/OpenCLImageTypes.def"
4081 case tok::kw___unknown_anytype:
4083 PrevSpec, DiagID, Policy);
4088 case tok::kw_struct:
4089 case tok::kw___interface:
4090 case tok::kw_union: {
4098 ParseClassSpecifier(
Kind, Loc, DS, TemplateInfo, AS,
4099 EnteringContext, DSContext, Attributes);
4103 if (!Attributes.empty()) {
4104 AttrsLastTime =
true;
4113 ParseEnumSpecifier(Loc, DS, TemplateInfo, AS, DSContext);
4121 case tok::kw_volatile:
4125 case tok::kw_restrict:
4131 case tok::kw_typename:
4134 goto DoneWithDeclSpec;
4136 if (!Tok.
is(tok::kw_typename))
4141 case tok::kw_typeof:
4142 ParseTypeofSpecifier(DS);
4145 case tok::annot_decltype:
4146 ParseDecltypeSpecifier(DS);
4149 case tok::annot_pragma_pack:
4153 case tok::annot_pragma_ms_pragma:
4154 HandlePragmaMSPragma();
4157 case tok::annot_pragma_ms_vtordisp:
4158 HandlePragmaMSVtorDisp();
4161 case tok::annot_pragma_ms_pointers_to_members:
4162 HandlePragmaMSPointersToMembers();
4165 case tok::kw___underlying_type:
4166 ParseUnderlyingTypeSpecifier(DS);
4169 case tok::kw__Atomic:
4175 Diag(Tok, diag::ext_c11_feature) << Tok.
getName();
4178 ParseAtomicSpecifier(DS);
4186 case tok::kw___generic:
4191 if (!Actions.
getLangOpts().OpenCLGenericAddressSpace) {
4192 DiagID = diag::err_opencl_unknown_type_specifier;
4198 case tok::kw_private:
4202 goto DoneWithDeclSpec;
4204 case tok::kw___private:
4205 case tok::kw___global:
4206 case tok::kw___local:
4207 case tok::kw___constant:
4209 case tok::kw___read_only:
4210 case tok::kw___write_only:
4211 case tok::kw___read_write:
4220 goto DoneWithDeclSpec;
4225 if (
Type.isUsable()) {
4227 PrevSpec, DiagID,
Type.get(),
4229 Diag(StartLoc, DiagID) << PrevSpec;
4245 assert(PrevSpec &&
"Method did not return previous specifier!");
4248 if (DiagID == diag::ext_duplicate_declspec ||
4249 DiagID == diag::ext_warn_duplicate_declspec ||
4250 DiagID == diag::err_duplicate_declspec)
4251 Diag(Loc, DiagID) << PrevSpec
4254 else if (DiagID == diag::err_opencl_unknown_type_specifier) {
4258 Diag(Loc, DiagID) << PrevSpec;
4261 if (DiagID != diag::err_bool_redeclaration && ConsumedEnd.
isInvalid())
4265 AttrsLastTime =
false;
4290 void Parser::ParseStructDeclaration(
4294 if (Tok.
is(tok::kw___extension__)) {
4298 return ParseStructDeclaration(DS, FieldsCallback);
4303 MaybeParseCXX11Attributes(Attrs);
4307 ParseSpecifierQualifierList(DS);
4311 if (Tok.
is(tok::semi)) {
4315 assert(!AnonRecord &&
"Did not expect anonymous struct or union here");
4321 bool FirstDeclarator =
true;
4325 DeclaratorInfo.D.setCommaLoc(CommaLoc);
4328 if (!FirstDeclarator) {
4331 DiagnoseAndSkipCXX11Attributes();
4332 MaybeParseGNUAttributes(DeclaratorInfo.D);
4333 DiagnoseAndSkipCXX11Attributes();
4338 if (Tok.
isNot(tok::colon)) {
4341 ParseDeclarator(DeclaratorInfo.D);
4343 DeclaratorInfo.D.SetIdentifier(
nullptr, Tok.
getLocation());
4347 if (Res.isInvalid())
4350 DeclaratorInfo.BitfieldSize = Res.get();
4354 MaybeParseGNUAttributes(DeclaratorInfo.D);
4357 FieldsCallback(DeclaratorInfo);
4364 FirstDeclarator =
false;
4381 "parsing struct/union body");
4385 if (T.consumeOpen())
4392 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
4397 if (Tok.
is(tok::semi)) {
4398 ConsumeExtraSemi(InsideStruct,
TagType);
4403 if (Tok.
isOneOf(tok::kw__Static_assert, tok::kw_static_assert)) {
4405 ParseStaticAssertDeclaration(DeclEnd);
4409 if (Tok.
is(tok::annot_pragma_pack)) {
4414 if (Tok.
is(tok::annot_pragma_align)) {
4415 HandlePragmaAlign();
4419 if (Tok.
isOneOf(tok::annot_pragma_openmp, tok::annot_attr_openmp)) {
4423 (void)ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs);
4431 ConsumeAnnotationToken();
4435 if (!Tok.
is(tok::at)) {
4441 FD.D, FD.BitfieldSize);
4447 ParseStructDeclaration(DS, CFieldCallback);
4451 Diag(Tok, diag::err_unexpected_at);
4456 ExpectAndConsume(tok::l_paren);
4457 if (!Tok.
is(tok::identifier)) {
4458 Diag(Tok, diag::err_expected) << tok::identifier;
4466 ExpectAndConsume(tok::r_paren);
4472 if (Tok.
is(tok::r_brace)) {
4473 ExpectAndConsume(tok::semi, diag::ext_expected_semi_decl_list);
4477 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list);
4488 MaybeParseGNUAttributes(attrs);
4494 T.getOpenLocation(), T.getCloseLocation(), attrs);
4530 const ParsedTemplateInfo &TemplateInfo,
4533 if (Tok.
is(tok::code_completion)) {
4542 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec | PAKM_CXX11, attrs);
4545 bool IsScopedUsingClassTag =
false;
4550 : diag::ext_scoped_enum);
4551 IsScopedUsingClassTag = Tok.
is(tok::kw_class);
4556 ProhibitAttributes(attrs);
4559 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec | PAKM_CXX11, attrs);
4568 bool shouldDelayDiagsInTag =
4569 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
4570 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
4574 AllowDefiningTypeSpec AllowEnumSpecifier =
4575 isDefiningTypeSpecifierContext(DSC);
4576 bool CanBeOpaqueEnumDeclaration =
4577 DS.
isEmpty() && isOpaqueEnumDeclarationContext(DSC);
4580 (AllowEnumSpecifier == AllowDefiningTypeSpec::Yes ||
4581 CanBeOpaqueEnumDeclaration);
4589 if (ParseOptionalCXXScopeSpecifier(Spec,
nullptr,
4594 if (Spec.
isSet() && Tok.
isNot(tok::identifier)) {
4595 Diag(Tok, diag::err_expected) << tok::identifier;
4596 if (Tok.
isNot(tok::l_brace)) {
4608 if (Tok.
isNot(tok::identifier) && Tok.
isNot(tok::l_brace) &&
4609 Tok.
isNot(tok::colon)) {
4610 Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace;
4620 if (Tok.
is(tok::identifier)) {
4625 if (!Name && ScopedEnumKWLoc.
isValid()) {
4628 Diag(Tok, diag::err_scoped_enum_missing_identifier);
4630 IsScopedUsingClassTag =
false;
4635 if (shouldDelayDiagsInTag)
4636 diagsFromTag.done();
4641 bool CanBeBitfield =
4645 if (Tok.
is(tok::colon)) {
4670 if (CanBeBitfield && !isEnumBase(CanBeOpaqueEnumDeclaration)) {
4675 }
else if (CanHaveEnumBase || !ColonIsSacred) {
4683 ParseSpecifierQualifierList(DS, AS, DeclSpecContext::DSC_type_specifier);
4687 BaseRange =
SourceRange(ColonLoc, DeclaratorInfo.getSourceRange().getEnd());
4691 Diag(ColonLoc, diag::warn_cxx98_compat_enum_fixed_underlying_type)
4694 Diag(ColonLoc, diag::ext_cxx11_enum_fixed_underlying_type)
4697 Diag(ColonLoc, diag::ext_ms_c_enum_fixed_underlying_type)
4700 Diag(ColonLoc, diag::ext_clang_c_enum_fixed_underlying_type)
4717 if (AllowEnumSpecifier == AllowDefiningTypeSpec::No)
4719 else if (Tok.
is(tok::l_brace)) {
4728 IsScopedUsingClassTag =
false;
4734 }
else if (!isTypeSpecifier(DSC) &&
4735 (Tok.
is(tok::semi) ||
4737 !isValidAfterTypeSpecifier(CanBeBitfield)))) {
4742 if (Tok.
isNot(tok::semi)) {
4744 ExpectAndConsume(tok::semi, diag::err_expected_after,
"enum");
4752 bool IsElaboratedTypeSpecifier =
4758 diagsFromTag.redelay();
4762 if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
4766 Diag(Tok, diag::err_enum_template);
4771 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
4774 Diag(StartLoc, diag::err_explicit_instantiation_enum);
4778 assert(TemplateInfo.TemplateParams &&
"no template parameters");
4780 TemplateInfo.TemplateParams->size());
4784 Diag(Tok, diag::err_enumerator_unnamed_no_def);
4799 if (IsElaboratedTypeSpecifier && !
getLangOpts().MicrosoftExt &&
4801 ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
4804 Diag(BaseRange.
getBegin(), diag::ext_enum_base_in_type_specifier)
4805 << (AllowEnumSpecifier == AllowDefiningTypeSpec::Yes) << BaseRange;
4806 else if (ScopedEnumKWLoc.
isValid())
4807 Diag(ScopedEnumKWLoc, diag::ext_elaborated_enum_class)
4811 stripTypeAttributesOffDeclSpec(attrs, DS, TUK);
4821 bool IsDependent =
false;
4822 const char *PrevSpec =
nullptr;
4827 ScopedEnumKWLoc, IsScopedUsingClassTag, BaseType,
4828 DSC == DeclSpecContext::DSC_type_specifier,
4829 DSC == DeclSpecContext::DSC_template_param ||
4830 DSC == DeclSpecContext::DSC_template_type_arg,
4841 NameLoc.
isValid() ? NameLoc : StartLoc,
4842 PrevSpec, DiagID,
TagDecl, Owned,
4844 Diag(StartLoc, DiagID) << PrevSpec;
4853 Diag(Tok, diag::err_expected_type_name_after_typename);
4859 if (
Type.isInvalid()) {
4865 NameLoc.
isValid() ? NameLoc : StartLoc,
4866 PrevSpec, DiagID,
Type.get(),
4868 Diag(StartLoc, DiagID) << PrevSpec;
4887 ParseEnumBody(StartLoc, D);
4896 NameLoc.
isValid() ? NameLoc : StartLoc,
4897 PrevSpec, DiagID,
TagDecl, Owned,
4899 Diag(StartLoc, DiagID) << PrevSpec;
4922 Diag(Tok, diag::err_empty_enum);
4927 Decl *LastEnumConstDecl =
nullptr;
4930 while (Tok.
isNot(tok::r_brace)) {
4933 if (Tok.
isNot(tok::identifier)) {
4945 MaybeParseGNUAttributes(attrs);
4946 if (standardAttributesAllowed() && isCXX11AttributeSpecifier()) {
4949 ? diag::warn_cxx14_compat_ns_enum_attribute
4950 : diag::ext_ns_enum_attribute)
4952 ParseCXX11Attributes(attrs);
4957 EnumAvailabilityDiags.emplace_back(*
this);
4970 EqualLoc, AssignedVal.
get());
4971 EnumAvailabilityDiags.back().done();
4973 EnumConstantDecls.push_back(EnumConstDecl);
4974 LastEnumConstDecl = EnumConstDecl;
4976 if (Tok.
is(tok::identifier)) {
4979 Diag(Loc, diag::err_enumerator_list_missing_comma)
5002 if (Tok.
is(tok::r_brace) && CommaLoc.
isValid()) {
5005 diag::ext_enumerator_list_comma_cxx :
5006 diag::ext_enumerator_list_comma_c)
5009 Diag(CommaLoc, diag::warn_cxx98_compat_enumerator_list_comma)
5020 MaybeParseGNUAttributes(attrs);
5026 assert(EnumConstantDecls.size() == EnumAvailabilityDiags.size());
5027 for (
size_t i = 0, e = EnumConstantDecls.size(); i != e; ++i) {
5029 EnumAvailabilityDiags[i].redelay();
5030 PD.complete(EnumConstantDecls[i]);
5039 if (!isValidAfterTypeSpecifier(CanBeBitfield)) {
5040 ExpectAndConsume(tok::semi, diag::err_expected_after,
"enum");
5052 bool Parser::isKnownToBeTypeSpecifier(
const Token &Tok)
const {
5054 default:
return false;
5058 case tok::kw___int64:
5059 case tok::kw___int128:
5060 case tok::kw_signed:
5061 case tok::kw_unsigned:
5062 case tok::kw__Complex:
5063 case tok::kw__Imaginary:
5066 case tok::kw_wchar_t:
5067 case tok::kw_char8_t:
5068 case tok::kw_char16_t:
5069 case tok::kw_char32_t:
5071 case tok::kw__ExtInt:
5072 case tok::kw__BitInt:
5073 case tok::kw___bf16:
5076 case tok::kw_double:
5077 case tok::kw__Accum:
5078 case tok::kw__Fract:
5079 case tok::kw__Float16:
5080 case tok::kw___float128:
5081 case tok::kw___ibm128:
5084 case tok::kw__Decimal32:
5085 case tok::kw__Decimal64:
5086 case tok::kw__Decimal128:
5087 case tok::kw___vector:
5088 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
5089 #include "clang/Basic/OpenCLImageTypes.def"
5093 case tok::kw_struct:
5094 case tok::kw___interface:
5100 case tok::annot_typename:
5107 bool Parser::isTypeSpecifierQualifier() {
5109 default:
return false;
5111 case tok::identifier:
5112 if (TryAltiVecVectorToken())
5115 case tok::kw_typename:
5120 if (Tok.
is(tok::identifier))
5122 return isTypeSpecifierQualifier();
5124 case tok::coloncolon:
5131 return isTypeSpecifierQualifier();
5134 case tok::kw___attribute:
5136 case tok::kw_typeof:
5141 case tok::kw___int64:
5142 case tok::kw___int128:
5143 case tok::kw_signed:
5144 case tok::kw_unsigned:
5145 case tok::kw__Complex:
5146 case tok::kw__Imaginary:
5149 case tok::kw_wchar_t:
5150 case tok::kw_char8_t:
5151 case tok::kw_char16_t:
5152 case tok::kw_char32_t:
5154 case tok::kw__ExtInt:
5155 case tok::kw__BitInt:
5157 case tok::kw___bf16:
5159 case tok::kw_double:
5160 case tok::kw__Accum:
5161 case tok::kw__Fract:
5162 case tok::kw__Float16:
5163 case tok::kw___float128:
5164 case tok::kw___ibm128:
5167 case tok::kw__Decimal32:
5168 case tok::kw__Decimal64:
5169 case tok::kw__Decimal128:
5170 case tok::kw___vector:
5171 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
5172 #include "clang/Basic/OpenCLImageTypes.def"
5176 case tok::kw_struct:
5177 case tok::kw___interface:
5184 case tok::kw_volatile:
5185 case tok::kw_restrict:
5189 case tok::kw___unknown_anytype:
5192 case tok::annot_typename:
5199 case tok::kw___cdecl:
5200 case tok::kw___stdcall:
5201 case tok::kw___fastcall:
5202 case tok::kw___thiscall:
5203 case tok::kw___regcall:
5204 case tok::kw___vectorcall:
5206 case tok::kw___ptr64:
5207 case tok::kw___ptr32:
5208 case tok::kw___pascal:
5209 case tok::kw___unaligned:
5211 case tok::kw__Nonnull:
5212 case tok::kw__Nullable:
5213 case tok::kw__Nullable_result:
5214 case tok::kw__Null_unspecified:
5216 case tok::kw___kindof:
5218 case tok::kw___private:
5219 case tok::kw___local:
5220 case tok::kw___global:
5221 case tok::kw___constant:
5222 case tok::kw___generic:
5223 case tok::kw___read_only:
5224 case tok::kw___read_write:
5225 case tok::kw___write_only:
5228 case tok::kw_private:
5232 case tok::kw__Atomic:
5242 bool Parser::isDeclarationSpecifier(
bool DisambiguatingWithExpression) {
5244 default:
return false;
5251 case tok::identifier:
5255 if (TryAltiVecVectorToken())
5258 case tok::kw_decltype:
5259 case tok::kw_typename:
5264 if (TryAnnotateTypeConstraint())
5266 if (Tok.
is(tok::identifier))
5274 if (DisambiguatingWithExpression &&
5275 isStartOfObjCClassMessageMissingOpenBracket())
5278 return isDeclarationSpecifier();
5280 case tok::coloncolon:
5289 return isDeclarationSpecifier();
5292 case tok::kw_typedef:
5293 case tok::kw_extern:
5294 case tok::kw___private_extern__:
5295 case tok::kw_static:
5297 case tok::kw___auto_type:
5298 case tok::kw_register:
5299 case tok::kw___thread:
5300 case tok::kw_thread_local:
5301 case tok::kw__Thread_local:
5304 case tok::kw___module_private__:
5307 case tok::kw___unknown_anytype:
5312 case tok::kw___int64:
5313 case tok::kw___int128:
5314 case tok::kw_signed:
5315 case tok::kw_unsigned:
5316 case tok::kw__Complex:
5317 case tok::kw__Imaginary:
5320 case tok::kw_wchar_t:
5321 case tok::kw_char8_t:
5322 case tok::kw_char16_t:
5323 case tok::kw_char32_t:
5326 case tok::kw__ExtInt:
5327 case tok::kw__BitInt:
5329 case tok::kw___bf16:
5331 case tok::kw_double:
5332 case tok::kw__Accum:
5333 case tok::kw__Fract:
5334 case tok::kw__Float16:
5335 case tok::kw___float128:
5336 case tok::kw___ibm128:
5339 case tok::kw__Decimal32:
5340 case tok::kw__Decimal64:
5341 case tok::kw__Decimal128:
5342 case tok::kw___vector:
5346 case tok::kw_struct:
5348 case tok::kw___interface:
5354 case tok::kw_volatile:
5355 case tok::kw_restrict:
5359 case tok::kw_inline:
5360 case tok::kw_virtual:
5361 case tok::kw_explicit:
5362 case tok::kw__Noreturn:
5365 case tok::kw__Alignas:
5368 case tok::kw_friend:
5371 case tok::kw_static_assert:
5372 case tok::kw__Static_assert:
5375 case tok::kw_typeof:
5378 case tok::kw___attribute:
5381 case tok::annot_decltype:
5382 case tok::kw_constexpr:
5385 case tok::kw_consteval:
5386 case tok::kw_constinit:
5389 case tok::kw__Atomic:
5397 case tok::annot_typename:
5398 return !DisambiguatingWithExpression ||
5399 !isStartOfObjCClassMessageMissingOpenBracket();
5402 case tok::annot_template_id: {
5408 return isTypeConstraintAnnotation() &&
5412 case tok::annot_cxxscope: {
5421 if (
NextToken().is(tok::identifier) && TryAnnotateTypeConstraint())
5423 return isTypeConstraintAnnotation() &&
5424 GetLookAheadToken(2).isOneOf(tok::kw_auto, tok::kw_decltype);
5427 case tok::kw___declspec:
5428 case tok::kw___cdecl:
5429 case tok::kw___stdcall:
5430 case tok::kw___fastcall:
5431 case tok::kw___thiscall:
5432 case tok::kw___regcall:
5433 case tok::kw___vectorcall:
5435 case tok::kw___sptr:
5436 case tok::kw___uptr:
5437 case tok::kw___ptr64:
5438 case tok::kw___ptr32:
5439 case tok::kw___forceinline:
5440 case tok::kw___pascal:
5441 case tok::kw___unaligned:
5443 case tok::kw__Nonnull:
5444 case tok::kw__Nullable:
5445 case tok::kw__Nullable_result:
5446 case tok::kw__Null_unspecified:
5448 case tok::kw___kindof:
5450 case tok::kw___private:
5451 case tok::kw___local:
5452 case tok::kw___global:
5453 case tok::kw___constant:
5454 case tok::kw___generic:
5455 case tok::kw___read_only:
5456 case tok::kw___read_write:
5457 case tok::kw___write_only:
5458 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
5459 #include "clang/Basic/OpenCLImageTypes.def"
5463 case tok::kw_private:
5468 bool Parser::isConstructorDeclarator(
bool IsUnqualified,
bool DeductionGuide) {
5469 TentativeParsingAction TPA(*
this);
5473 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
5481 if (Tok.
is(tok::identifier)) {
5485 }
else if (Tok.
is(tok::annot_template_id)) {
5486 ConsumeAnnotationToken();
5494 SkipCXX11Attributes();
5497 if (Tok.
isNot(tok::l_paren)) {
5505 if (Tok.
is(tok::r_paren) ||
5506 (Tok.
is(tok::ellipsis) &&
NextToken().is(tok::r_paren))) {
5514 isCXX11AttributeSpecifier(
false,
5521 DeclaratorScopeObj DeclScopeObj(*
this, SS);
5523 DeclScopeObj.EnterDeclaratorScope();
5527 MaybeParseMicrosoftAttributes(Attrs);
5532 bool IsConstructor =
false;
5533 if (isDeclarationSpecifier())
5534 IsConstructor =
true;
5535 else if (Tok.
is(tok::identifier) ||
5536 (Tok.
is(tok::annot_cxxscope) &&
NextToken().is(tok::identifier))) {
5541 if (Tok.
is(tok::annot_cxxscope))
5542 ConsumeAnnotationToken();
5554 case tok::coloncolon:
5567 SkipCXX11Attributes();
5569 if (DeductionGuide) {
5571 IsConstructor = Tok.
is(tok::arrow);
5574 if (Tok.
is(tok::colon) || Tok.
is(tok::kw_try)) {
5578 IsConstructor =
true;
5580 if (Tok.
is(tok::semi) || Tok.
is(tok::l_brace)) {
5593 IsConstructor = IsUnqualified;
5598 IsConstructor =
true;
5604 return IsConstructor;
5619 void Parser::ParseTypeQualifierListOpt(
5620 DeclSpec &DS,
unsigned AttrReqs,
bool AtomicAllowed,
5621 bool IdentifierRequired,
5623 if (standardAttributesAllowed() && (AttrReqs & AR_CXX11AttributesParsed) &&
5624 isCXX11AttributeSpecifier()) {
5626 ParseCXX11Attributes(Attrs);
5634 const char *PrevSpec =
nullptr;
5635 unsigned DiagID = 0;
5639 case tok::code_completion:
5642 (*CodeCompletionHandler)();
5651 case tok::kw_volatile:
5655 case tok::kw_restrict:
5659 case tok::kw__Atomic:
5661 goto DoneWithTypeQuals;
5663 Diag(Tok, diag::ext_c11_feature) << Tok.
getName();
5669 case tok::kw_private:
5671 goto DoneWithTypeQuals;
5673 case tok::kw___private:
5674 case tok::kw___global:
5675 case tok::kw___local:
5676 case tok::kw___constant:
5677 case tok::kw___generic:
5678 case tok::kw___read_only:
5679 case tok::kw___write_only:
5680 case tok::kw___read_write:
5684 case tok::kw___unaligned:
5688 case tok::kw___uptr:
5693 if (TryKeywordIdentFallback(
false))
5697 case tok::kw___sptr:
5699 case tok::kw___ptr64:
5700 case tok::kw___ptr32:
5701 case tok::kw___cdecl:
5702 case tok::kw___stdcall:
5703 case tok::kw___fastcall:
5704 case tok::kw___thiscall:
5705 case tok::kw___regcall:
5706 case tok::kw___vectorcall:
5707 if (AttrReqs & AR_DeclspecAttributesParsed) {
5711 goto DoneWithTypeQuals;
5712 case tok::kw___pascal:
5713 if (AttrReqs & AR_VendorAttributesParsed) {
5717 goto DoneWithTypeQuals;
5720 case tok::kw__Nonnull:
5721 case tok::kw__Nullable:
5722 case tok::kw__Nullable_result:
5723 case tok::kw__Null_unspecified:
5728 case tok::kw___kindof:
5734 case tok::kw___attribute:
5735 if (AttrReqs & AR_GNUAttributesParsedAndRejected)
5737 Diag(Tok, diag::err_attributes_not_allowed);
5741 if (AttrReqs & AR_GNUAttributesParsed ||
5742 AttrReqs & AR_GNUAttributesParsedAndRejected) {
5760 assert(PrevSpec &&
"Method did not return previous specifier!");
5761 Diag(Tok, DiagID) << PrevSpec;
5768 void Parser::ParseDeclarator(
Declarator &D) {
5772 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
5778 if (
Kind == tok::star ||
Kind == tok::caret)
5782 if (
Kind == tok::kw_pipe && Lang.OpenCL &&
5786 if (!Lang.CPlusPlus)
5789 if (
Kind == tok::amp)
5797 if (
Kind == tok::ampamp)
5808 for (
unsigned Idx = 0; Idx != NumTypes; ++Idx)
5840 void Parser::ParseDeclaratorInternal(
Declarator &D,
5841 DirectDeclParseFunction DirectDeclParser) {
5849 (Tok.
is(tok::coloncolon) || Tok.
is(tok::kw_decltype) ||
5850 (Tok.
is(tok::identifier) &&
5852 Tok.
is(tok::annot_cxxscope))) {
5856 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
5857 false, EnteringContext);
5860 if (Tok.
isNot(tok::star)) {
5865 AnnotateScopeToken(SS,
true);
5867 if (DirectDeclParser)
5868 (this->*DirectDeclParser)(D);
5873 checkCompoundToken(SS.
getEndLoc(), tok::coloncolon,
5874 CompoundToken::MemberPtr);
5880 ParseTypeQualifierListOpt(DS);
5885 ParseDeclaratorInternal(D, DirectDeclParser);