28#include "llvm/ADT/SmallSet.h"
29#include "llvm/ADT/SmallString.h"
30#include "llvm/ADT/StringSwitch.h"
47 DeclSpecContext DSC = getDeclSpecContextFromDeclaratorContext(Context);
48 if (DSC == DeclSpecContext::DSC_normal)
49 DSC = DeclSpecContext::DSC_type_specifier;
55 ParseSpecifierQualifierList(DS, AS, DSC);
63 if (AL.isDeclspecAttribute())
64 ToBeMoved.push_back(&AL);
73 ParseDeclarator(DeclaratorInfo);
85 if (Name.size() >= 4 && Name.startswith(
"__") && Name.endswith(
"__"))
86 return Name.drop_front(2).drop_back(2);
93#define CLANG_ATTR_LATE_PARSED_LIST
95#include "clang/Parse/AttrParserStringSwitches.inc"
97#undef CLANG_ATTR_LATE_PARSED_LIST
107 if (
SM.getFileID(StartLoc) !=
SM.getFileID(EndLoc))
110 bool AttrStartIsInMacro =
112 bool AttrEndIsInMacro =
114 return AttrStartIsInMacro && AttrEndIsInMacro;
117void Parser::ParseAttributes(
unsigned WhichAttrKinds,
ParsedAttributes &Attrs,
118 LateParsedAttrList *LateAttrs) {
124 if (WhichAttrKinds & PAKM_CXX11)
125 MoreToParse |= MaybeParseCXX11Attributes(Attrs);
126 if (WhichAttrKinds & PAKM_GNU)
127 MoreToParse |= MaybeParseGNUAttributes(Attrs, LateAttrs);
128 if (WhichAttrKinds & PAKM_Declspec)
129 MoreToParse |= MaybeParseMicrosoftDeclSpecs(Attrs);
130 }
while (MoreToParse);
175 LateParsedAttrList *LateAttrs,
Declarator *D) {
176 assert(Tok.
is(tok::kw___attribute) &&
"Not a GNU attribute list!");
181 while (Tok.
is(tok::kw___attribute)) {
183 unsigned OldNumAttrs = Attrs.
size();
184 unsigned OldNumLateAttrs = LateAttrs ? LateAttrs->size() : 0;
186 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
191 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
"(")) {
204 if (Tok.
is(tok::code_completion)) {
215 if (Tok.
isNot(tok::l_paren)) {
216 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
223 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, &EndLoc,
nullptr,
229 LateParsedAttribute *LA =
230 new LateParsedAttribute(
this, *AttrName, AttrNameLoc);
231 LateAttrs->push_back(LA);
235 if (!ClassStack.empty() && !LateAttrs->parseSoon())
236 getCurrentClass().LateParsedDeclarations.push_back(LA);
240 LA->Toks.push_back(Tok);
243 ConsumeAndStoreUntil(tok::r_paren, LA->Toks,
true);
248 LA->Toks.push_back(Eof);
249 }
while (Tok.
is(tok::comma));
251 if (ExpectAndConsume(tok::r_paren))
254 if (ExpectAndConsume(tok::r_paren))
261 if (!
SM.isWrittenInBuiltinFile(
SM.getSpellingLoc(AttrTokLoc)) &&
264 StringRef FoundName =
268 for (
unsigned i = OldNumAttrs; i < Attrs.
size(); ++i)
269 Attrs[i].setMacroIdentifier(MacroII, ExpansionRange.
getBegin());
272 for (
unsigned i = OldNumLateAttrs; i < LateAttrs->size(); ++i)
273 (*LateAttrs)[i]->MacroII = MacroII;
283#define CLANG_ATTR_IDENTIFIER_ARG_LIST
285#include "clang/Parse/AttrParserStringSwitches.inc"
287#undef CLANG_ATTR_IDENTIFIER_ARG_LIST
292#define CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST
294#include "clang/Parse/AttrParserStringSwitches.inc"
296#undef CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST
301#define CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST
303#include "clang/Parse/AttrParserStringSwitches.inc"
305#undef CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST
310#define CLANG_ATTR_ACCEPTS_EXPR_PACK
312#include "clang/Parse/AttrParserStringSwitches.inc"
314#undef CLANG_ATTR_ACCEPTS_EXPR_PACK
319#define CLANG_ATTR_TYPE_ARG_LIST
321#include "clang/Parse/AttrParserStringSwitches.inc"
323#undef CLANG_ATTR_TYPE_ARG_LIST
329#define CLANG_ATTR_ARG_CONTEXT_LIST
331#include "clang/Parse/AttrParserStringSwitches.inc"
333#undef CLANG_ATTR_ARG_CONTEXT_LIST
337 assert(Tok.
is(tok::identifier) &&
"expected an identifier");
352 Parens.consumeOpen();
355 if (Tok.
isNot(tok::r_paren))
358 if (Parens.consumeClose())
366 SourceRange(AttrNameLoc, Parens.getCloseLocation()),
367 ScopeName, ScopeLoc, T.
get(), Syntax);
370 ScopeName, ScopeLoc,
nullptr, 0, Syntax);
373unsigned Parser::ParseAttributeArgsCommon(
382 bool AttributeHasVariadicIdentifierArg =
386 if (ChangeKWThisToIdent && Tok.
is(tok::kw_this))
390 if (Tok.
is(tok::identifier)) {
392 bool IsIdentifierArg = AttributeHasVariadicIdentifierArg ||
402 IsIdentifierArg = Next.isOneOf(tok::r_paren, tok::comma);
406 ArgExprs.push_back(ParseIdentifierLoc());
410 if (!ArgExprs.empty() ? Tok.
is(tok::comma) : Tok.
isNot(tok::r_paren)) {
412 if (!ArgExprs.empty())
415 if (AttributeIsTypeArgAttr) {
423 TheParsedType = T.
get();
424 }
else if (AttributeHasVariadicIdentifierArg) {
432 if (ChangeKWThisToIdent && Tok.
is(tok::kw_this))
436 if (Tok.
is(tok::identifier)) {
437 ArgExprs.push_back(ParseIdentifierLoc());
452 ArgExprs.push_back(ArgExpr.
get());
464 ExprVector ParsedExprs;
465 if (ParseExpressionList(ParsedExprs, llvm::function_ref<
void()>(),
473 for (
size_t I = 0; I < ParsedExprs.size(); ++I) {
474 if (!isa<PackExpansionExpr>(ParsedExprs[I]))
479 diag::err_attribute_argument_parm_pack_not_supported)
486 ArgExprs.insert(ArgExprs.end(), ParsedExprs.begin(), ParsedExprs.end());
491 if (!ExpectAndConsume(tok::r_paren)) {
494 if (AttributeIsTypeArgAttr && !TheParsedType.
get().
isNull()) {
496 ScopeName, ScopeLoc, TheParsedType, Syntax);
499 ArgExprs.data(), ArgExprs.size(), Syntax);
506 return static_cast<unsigned>(ArgExprs.size() + !TheParsedType.
get().
isNull());
511void Parser::ParseGNUAttributeArgs(
516 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
521 if (AttrKind == ParsedAttr::AT_Availability) {
522 ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
525 }
else if (AttrKind == ParsedAttr::AT_ExternalSourceSymbol) {
526 ParseExternalSourceSymbolAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
527 ScopeName, ScopeLoc, Syntax);
529 }
else if (AttrKind == ParsedAttr::AT_ObjCBridgeRelated) {
530 ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
531 ScopeName, ScopeLoc, Syntax);
533 }
else if (AttrKind == ParsedAttr::AT_SwiftNewType) {
534 ParseSwiftNewTypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
537 }
else if (AttrKind == ParsedAttr::AT_TypeTagForDatatype) {
538 ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
539 ScopeName, ScopeLoc, Syntax);
542 ParseAttributeWithTypeArg(*AttrName, AttrNameLoc, Attrs, ScopeName,
549 std::optional<ParseScope> PrototypeScope;
556 for (
unsigned i = 0; i != FTI.
NumParams; ++i) {
562 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
566unsigned Parser::ParseClangAttributeArgs(
570 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
577 return ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
578 ScopeName, ScopeLoc, Syntax);
579 case ParsedAttr::AT_ExternalSourceSymbol:
580 ParseExternalSourceSymbolAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
581 ScopeName, ScopeLoc, Syntax);
583 case ParsedAttr::AT_Availability:
584 ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
587 case ParsedAttr::AT_ObjCBridgeRelated:
588 ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
589 ScopeName, ScopeLoc, Syntax);
591 case ParsedAttr::AT_SwiftNewType:
592 ParseSwiftNewTypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
595 case ParsedAttr::AT_TypeTagForDatatype:
596 ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
597 ScopeName, ScopeLoc, Syntax);
600 return !Attrs.
empty() ? Attrs.
begin()->getNumArgs() : 0;
606 unsigned ExistingAttrs = Attrs.
size();
620 if (AttrName->
getName() ==
"property") {
626 T.expectAndConsume(diag::err_expected_lparen_after,
635 bool HasInvalidAccessor =
false;
640 if (!Tok.
is(tok::identifier)) {
642 if (Tok.
is(tok::r_paren) && !HasInvalidAccessor &&
643 AccessorNames[AK_Put] ==
nullptr &&
644 AccessorNames[AK_Get] ==
nullptr) {
645 Diag(AttrNameLoc, diag::err_ms_property_no_getter_or_putter);
656 if (KindStr ==
"get") {
658 }
else if (KindStr ==
"put") {
662 }
else if (KindStr ==
"set") {
663 Diag(KindLoc, diag::err_ms_property_has_set_accessor)
670 Diag(KindLoc, diag::err_ms_property_missing_accessor_kind);
672 HasInvalidAccessor =
true;
673 goto next_property_accessor;
677 Diag(KindLoc, diag::err_ms_property_unknown_accessor);
678 HasInvalidAccessor =
true;
697 if (!Tok.
is(tok::identifier)) {
702 if (Kind == AK_Invalid) {
704 }
else if (AccessorNames[Kind] !=
nullptr) {
706 Diag(KindLoc, diag::err_ms_property_duplicate_accessor) << KindStr;
712 next_property_accessor:
718 if (Tok.
is(tok::r_paren))
721 Diag(Tok.
getLocation(), diag::err_ms_property_expected_comma_or_rparen);
726 if (!HasInvalidAccessor)
728 AccessorNames[AK_Get], AccessorNames[AK_Put],
731 return !HasInvalidAccessor;
735 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs,
nullptr,
nullptr,
741 Diag(OpenParenLoc, diag::err_attribute_requires_arguments) << AttrName;
754 assert(
getLangOpts().DeclSpecKeyword &&
"__declspec keyword is not enabled");
755 assert(Tok.
is(tok::kw___declspec) &&
"Not a declspec!");
760 while (Tok.
is(tok::kw___declspec)) {
763 if (T.expectAndConsume(diag::err_expected_lparen_after,
"__declspec",
769 while (Tok.
isNot(tok::r_paren)) {
774 if (Tok.
is(tok::code_completion)) {
782 bool IsString = Tok.
getKind() == tok::string_literal;
783 if (!IsString && Tok.
getKind() != tok::identifier &&
784 Tok.
getKind() != tok::kw_restrict) {
785 Diag(Tok, diag::err_ms_declspec_type);
795 StringRef Str = PP.
getSpelling(Tok, StrBuffer, &Invalid);
801 AttrNameLoc = ConsumeStringToken();
807 bool AttrHandled =
false;
810 if (Tok.
is(tok::l_paren))
811 AttrHandled = ParseMicrosoftDeclSpecArgs(AttrName, AttrNameLoc, Attrs);
812 else if (AttrName->
getName() ==
"property")
818 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
822 EndLoc = T.getCloseLocation();
832 case tok::kw___fastcall:
833 case tok::kw___stdcall:
834 case tok::kw___thiscall:
835 case tok::kw___regcall:
836 case tok::kw___cdecl:
837 case tok::kw___vectorcall:
838 case tok::kw___ptr64:
840 case tok::kw___ptr32:
842 case tok::kw___uptr: {
845 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
856 assert(Tok.
is(tok::kw___funcref));
860 Diag(StartLoc, diag::err_wasm_funcref_not_wasm);
866 attrs.
addNew(AttrName, AttrNameLoc,
nullptr,
871void Parser::DiagnoseAndSkipExtendedMicrosoftTypeAttributes() {
877 Diag(StartLoc, diag::warn_microsoft_qualifiers_ignored) <<
Range;
887 case tok::kw_volatile:
888 case tok::kw___fastcall:
889 case tok::kw___stdcall:
890 case tok::kw___thiscall:
891 case tok::kw___cdecl:
892 case tok::kw___vectorcall:
893 case tok::kw___ptr32:
894 case tok::kw___ptr64:
896 case tok::kw___unaligned:
909 while (Tok.
is(tok::kw___pascal)) {
912 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
919 while (Tok.
is(tok::kw___kernel)) {
922 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
928 while (Tok.
is(tok::kw___noinline__)) {
931 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
939 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
943bool Parser::isHLSLQualifier(
const Token &Tok)
const {
944 return Tok.
is(tok::kw_groupshared);
950 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
958 case tok::kw__Nonnull:
959 case tok::kw__Nullable:
960 case tok::kw__Nullable_result:
961 case tok::kw__Null_unspecified: {
965 Diag(AttrNameLoc, diag::ext_nullability)
967 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
978 return (Separator ==
'.' || Separator ==
'_');
989VersionTuple Parser::ParseVersionTuple(
SourceRange &Range) {
992 if (!Tok.
is(tok::numeric_constant)) {
993 Diag(Tok, diag::err_expected_version);
996 return VersionTuple();
1005 const char *ThisTokBegin = &Buffer[0];
1009 unsigned ActualLength = PP.
getSpelling(Tok, ThisTokBegin, &Invalid);
1011 return VersionTuple();
1014 unsigned AfterMajor = 0;
1016 while (AfterMajor < ActualLength &&
isDigit(ThisTokBegin[AfterMajor])) {
1017 Major = Major * 10 + ThisTokBegin[AfterMajor] -
'0';
1021 if (AfterMajor == 0) {
1022 Diag(Tok, diag::err_expected_version);
1025 return VersionTuple();
1028 if (AfterMajor == ActualLength) {
1033 Diag(Tok, diag::err_zero_version);
1034 return VersionTuple();
1037 return VersionTuple(Major);
1040 const char AfterMajorSeparator = ThisTokBegin[AfterMajor];
1042 || (AfterMajor + 1 == ActualLength)) {
1043 Diag(Tok, diag::err_expected_version);
1046 return VersionTuple();
1050 unsigned AfterMinor = AfterMajor + 1;
1052 while (AfterMinor < ActualLength &&
isDigit(ThisTokBegin[AfterMinor])) {
1053 Minor = Minor * 10 + ThisTokBegin[AfterMinor] -
'0';
1057 if (AfterMinor == ActualLength) {
1061 if (Major == 0 && Minor == 0) {
1062 Diag(Tok, diag::err_zero_version);
1063 return VersionTuple();
1066 return VersionTuple(Major, Minor);
1069 const char AfterMinorSeparator = ThisTokBegin[AfterMinor];
1072 Diag(Tok, diag::err_expected_version);
1075 return VersionTuple();
1079 if (AfterMajorSeparator != AfterMinorSeparator)
1080 Diag(Tok, diag::warn_expected_consistent_version_separator);
1083 unsigned AfterSubminor = AfterMinor + 1;
1084 unsigned Subminor = 0;
1085 while (AfterSubminor < ActualLength &&
isDigit(ThisTokBegin[AfterSubminor])) {
1086 Subminor = Subminor * 10 + ThisTokBegin[AfterSubminor] -
'0';
1090 if (AfterSubminor != ActualLength) {
1091 Diag(Tok, diag::err_expected_version);
1094 return VersionTuple();
1097 return VersionTuple(Major, Minor, Subminor);
1125void Parser::ParseAvailabilityAttribute(
IdentifierInfo &Availability,
1132 enum { Introduced, Deprecated, Obsoleted,
Unknown };
1138 if (T.consumeOpen()) {
1139 Diag(Tok, diag::err_expected) << tok::l_paren;
1144 if (Tok.
isNot(tok::identifier)) {
1145 Diag(Tok, diag::err_availability_expected_platform);
1152 if (Ident->getName() ==
"macosx")
1156 else if (Ident->getName() ==
"macosx_app_extension")
1160 AvailabilityAttr::canonicalizePlatformName(Ident->getName()));
1164 if (ExpectAndConsume(tok::comma)) {
1171 if (!Ident_introduced) {
1185 if (Tok.
isNot(tok::identifier)) {
1186 Diag(Tok, diag::err_availability_expected_change);
1193 if (Keyword == Ident_strict) {
1195 Diag(KeywordLoc, diag::err_availability_redundant)
1198 StrictLoc = KeywordLoc;
1202 if (Keyword == Ident_unavailable) {
1203 if (UnavailableLoc.
isValid()) {
1204 Diag(KeywordLoc, diag::err_availability_redundant)
1207 UnavailableLoc = KeywordLoc;
1211 if (Keyword == Ident_deprecated && Platform->
Ident &&
1214 if (Changes[Deprecated].KeywordLoc.
isValid()) {
1215 Diag(KeywordLoc, diag::err_availability_redundant)
1222 Changes[Deprecated].
Version = VersionTuple(1);
1226 if (Tok.
isNot(tok::equal)) {
1227 Diag(Tok, diag::err_expected_after) << Keyword << tok::equal;
1232 if (Keyword == Ident_message || Keyword == Ident_replacement) {
1233 if (Tok.
isNot(tok::string_literal)) {
1234 Diag(Tok, diag::err_expected_string_literal)
1239 if (Keyword == Ident_message)
1245 cast_or_null<StringLiteral>(MessageExpr.
get())) {
1246 if (!MessageStringLiteral->isOrdinary()) {
1247 Diag(MessageStringLiteral->getSourceRange().getBegin(),
1248 diag::err_expected_string_literal)
1254 if (Keyword == Ident_message)
1262 if ((Keyword == Ident_introduced || Keyword == Ident_deprecated) &&
1263 Tok.
is(tok::identifier)) {
1267 if (Keyword == Ident_introduced)
1268 UnavailableLoc = KeywordLoc;
1274 VersionTuple Version = ParseVersionTuple(VersionRange);
1276 if (Version.empty()) {
1282 if (Keyword == Ident_introduced)
1284 else if (Keyword == Ident_deprecated)
1286 else if (Keyword == Ident_obsoleted)
1292 if (!Changes[Index].KeywordLoc.
isInvalid()) {
1293 Diag(KeywordLoc, diag::err_availability_redundant)
1296 Changes[Index].VersionRange.
getEnd());
1300 Changes[Index].
Version = Version;
1303 Diag(KeywordLoc, diag::err_availability_unknown_change)
1304 << Keyword << VersionRange;
1310 if (T.consumeClose())
1314 *endLoc = T.getCloseLocation();
1318 if (UnavailableLoc.
isValid()) {
1319 bool Complained =
false;
1320 for (
unsigned Index = Introduced; Index !=
Unknown; ++Index) {
1321 if (Changes[Index].KeywordLoc.
isValid()) {
1323 Diag(UnavailableLoc, diag::warn_availability_and_unavailable)
1325 Changes[Index].VersionRange.
getEnd());
1336 attrs.
addNew(&Availability,
1337 SourceRange(AvailabilityLoc, T.getCloseLocation()),
1338 ScopeName, ScopeLoc,
1340 Changes[Introduced],
1341 Changes[Deprecated],
1343 UnavailableLoc, MessageExpr.
get(),
1344 Syntax, StrictLoc, ReplacementExpr.
get());
1361void Parser::ParseExternalSourceSymbolAttribute(
1367 if (T.expectAndConsume())
1371 if (!Ident_language) {
1379 bool HasLanguage =
false;
1381 bool HasDefinedIn =
false;
1384 bool HasUSR =
false;
1388 if (Tok.
isNot(tok::identifier)) {
1389 Diag(Tok, diag::err_external_source_symbol_expected_keyword);
1396 if (Keyword == Ident_generated_declaration) {
1397 if (GeneratedDeclaration) {
1398 Diag(Tok, diag::err_external_source_symbol_duplicate_clause) << Keyword;
1402 GeneratedDeclaration = ParseIdentifierLoc();
1406 if (Keyword != Ident_language && Keyword != Ident_defined_in &&
1407 Keyword != Ident_USR) {
1408 Diag(Tok, diag::err_external_source_symbol_expected_keyword);
1414 if (ExpectAndConsume(tok::equal, diag::err_expected_after,
1420 bool HadLanguage = HasLanguage, HadDefinedIn = HasDefinedIn,
1422 if (Keyword == Ident_language)
1424 else if (Keyword == Ident_USR)
1427 HasDefinedIn =
true;
1429 if (Tok.
isNot(tok::string_literal)) {
1430 Diag(Tok, diag::err_expected_string_literal)
1433 Keyword == Ident_language
1435 : (Keyword == Ident_defined_in ? 1 : 2));
1439 if (Keyword == Ident_language) {
1441 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
1447 }
else if (Keyword == Ident_USR) {
1449 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
1456 assert(Keyword == Ident_defined_in &&
"Invalid clause keyword!");
1458 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
1468 if (T.consumeClose())
1471 *EndLoc = T.getCloseLocation();
1476 ScopeName, ScopeLoc, Args, std::size(Args), Syntax);
1490void Parser::ParseObjCBridgeRelatedAttribute(
1496 if (T.consumeOpen()) {
1497 Diag(Tok, diag::err_expected) << tok::l_paren;
1502 if (Tok.
isNot(tok::identifier)) {
1503 Diag(Tok, diag::err_objcbridge_related_expected_related_class);
1508 if (ExpectAndConsume(tok::comma)) {
1517 if (Tok.
is(tok::identifier)) {
1520 Diag(Tok, diag::err_objcbridge_related_selector_name);
1526 if (Tok.
is(tok::colon))
1527 Diag(Tok, diag::err_objcbridge_related_selector_name);
1529 Diag(Tok, diag::err_expected) << tok::comma;
1537 if (Tok.
is(tok::identifier))
1539 else if (Tok.
isNot(tok::r_paren)) {
1540 Diag(Tok, diag::err_expected) << tok::r_paren;
1546 if (T.consumeClose())
1550 *EndLoc = T.getCloseLocation();
1553 Attrs.
addNew(&ObjCBridgeRelated,
1554 SourceRange(ObjCBridgeRelatedLoc, T.getCloseLocation()),
1555 ScopeName, ScopeLoc, RelatedClass, ClassMethod, InstanceMethod,
1559void Parser::ParseSwiftNewTypeAttribute(
1566 if (T.consumeOpen()) {
1567 Diag(Tok, diag::err_expected) << tok::l_paren;
1571 if (Tok.
is(tok::r_paren)) {
1576 if (Tok.
isNot(tok::kw_struct) && Tok.
isNot(tok::kw_enum)) {
1577 Diag(Tok, diag::warn_attribute_type_not_supported)
1579 if (!isTokenSpecial())
1590 if (T.consumeClose())
1593 *EndLoc = T.getCloseLocation();
1597 ScopeName, ScopeLoc, Args, std::size(Args), Syntax);
1600void Parser::ParseTypeTagForDatatypeAttribute(
IdentifierInfo &AttrName,
1607 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
1612 if (Tok.
isNot(tok::identifier)) {
1613 Diag(Tok, diag::err_expected) << tok::identifier;
1619 if (ExpectAndConsume(tok::comma)) {
1631 bool LayoutCompatible =
false;
1632 bool MustBeNull =
false;
1634 if (Tok.
isNot(tok::identifier)) {
1635 Diag(Tok, diag::err_expected) << tok::identifier;
1640 if (Flag->
isStr(
"layout_compatible"))
1641 LayoutCompatible =
true;
1642 else if (Flag->
isStr(
"must_be_null"))
1645 Diag(Tok, diag::err_type_safety_unknown_flag) << Flag;
1652 if (!T.consumeClose()) {
1654 ArgumentKind, MatchingCType.
get(),
1655 LayoutCompatible, MustBeNull, Syntax);
1659 *EndLoc = T.getCloseLocation();
1670bool Parser::DiagnoseProhibitedCXX11Attribute() {
1671 assert(Tok.
is(tok::l_square) &&
NextToken().is(tok::l_square));
1673 switch (isCXX11AttributeSpecifier(
true)) {
1674 case CAK_NotAttributeSpecifier:
1678 case CAK_InvalidAttributeSpecifier:
1682 case CAK_AttributeSpecifier:
1687 assert(Tok.
is(tok::r_square) &&
"isCXX11AttributeSpecifier lied");
1689 Diag(BeginLoc, diag::err_attributes_not_allowed)
1693 llvm_unreachable(
"All cases handled above.");
1702 assert((Tok.
is(tok::l_square) &&
NextToken().is(tok::l_square)) ||
1703 Tok.
is(tok::kw_alignas));
1707 ParseCXX11Attributes(Attrs);
1710 Diag(Loc, diag::err_attributes_not_allowed)
1715void Parser::DiagnoseProhibitedAttributes(
1717 if (CorrectLocation.
isValid()) {
1719 Diag(CorrectLocation, diag::err_attributes_misplaced)
1723 Diag(
Range.getBegin(), diag::err_attributes_not_allowed) <<
Range;
1726void Parser::ProhibitCXX11Attributes(
ParsedAttributes &Attrs,
unsigned DiagID,
1727 bool DiagnoseEmptyAttrs,
1728 bool WarnOnUnknownAttrs) {
1738 if (FirstLSquare.
is(tok::l_square)) {
1739 std::optional<Token> SecondLSquare =
1742 if (SecondLSquare && SecondLSquare->is(tok::l_square)) {
1753 if (!AL.isCXX11Attribute() && !AL.isC2xAttribute())
1756 if (WarnOnUnknownAttrs)
1757 Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
1758 << AL << AL.getRange();
1760 Diag(AL.getLoc(), DiagID) << AL;
1768 if (PA.isCXX11Attribute() || PA.isC2xAttribute())
1769 Diag(PA.getLoc(), diag::ext_cxx11_attr_placement) << PA << PA.getRange();
1789 if ((AL.getKind() == ParsedAttr::AT_Aligned &&
1790 AL.isDeclspecAttribute()) ||
1791 AL.isMicrosoftAttribute())
1792 ToBeMoved.push_back(&AL);
1827 Decl *SingleDecl =
nullptr;
1829 case tok::kw_template:
1830 case tok::kw_export:
1831 ProhibitAttributes(DeclAttrs);
1832 ProhibitAttributes(DeclSpecAttrs);
1834 ParseDeclarationStartingWithTemplate(Context, DeclEnd, DeclAttrs);
1836 case tok::kw_inline:
1839 ProhibitAttributes(DeclAttrs);
1840 ProhibitAttributes(DeclSpecAttrs);
1842 return ParseNamespace(Context, DeclEnd, InlineLoc);
1844 return ParseSimpleDeclaration(Context, DeclEnd, DeclAttrs, DeclSpecAttrs,
1845 true,
nullptr, DeclSpecStart);
1847 case tok::kw_cbuffer:
1848 case tok::kw_tbuffer:
1849 SingleDecl = ParseHLSLBuffer(DeclEnd);
1851 case tok::kw_namespace:
1852 ProhibitAttributes(DeclAttrs);
1853 ProhibitAttributes(DeclSpecAttrs);
1854 return ParseNamespace(Context, DeclEnd);
1855 case tok::kw_using: {
1858 return ParseUsingDirectiveOrDeclaration(Context, ParsedTemplateInfo(),
1861 case tok::kw_static_assert:
1862 case tok::kw__Static_assert:
1863 ProhibitAttributes(DeclAttrs);
1864 ProhibitAttributes(DeclSpecAttrs);
1865 SingleDecl = ParseStaticAssertDeclaration(DeclEnd);
1868 return ParseSimpleDeclaration(Context, DeclEnd, DeclAttrs, DeclSpecAttrs,
1869 true,
nullptr, DeclSpecStart);
1901 bool RequireSemi, ForRangeInit *FRI,
SourceLocation *DeclSpecStart) {
1904 OriginalDeclSpecAttrs.
addAll(DeclSpecAttrs.
begin(), DeclSpecAttrs.
end());
1905 OriginalDeclSpecAttrs.
Range = DeclSpecAttrs.
Range;
1911 DeclSpecContext DSContext = getDeclSpecContextFromDeclaratorContext(Context);
1912 ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(),
AS_none, DSContext);
1917 DiagnoseMissingSemiAfterTagDefinition(DS,
AS_none, DSContext))
1922 if (Tok.
is(tok::semi)) {
1923 ProhibitAttributes(DeclAttrs);
1929 DS.complete(TheDecl);
1931 Decl* decls[] = {AnonRecord, TheDecl};
1940 return ParseDeclGroup(DS, Context, DeclAttrs, &DeclEnd, FRI);
1947 case tok::annot_cxxscope:
1948 case tok::annot_template_id:
1950 case tok::code_completion:
1951 case tok::coloncolon:
1953 case tok::kw___attribute:
1954 case tok::kw_operator:
1970 case tok::identifier:
1972 case tok::code_completion:
1973 case tok::coloncolon:
1976 case tok::equalequal:
1977 case tok::kw_alignas:
1979 case tok::kw___attribute:
1997 case tok::identifier:
2020 if (Tok.
isOneOf(tok::comma, tok::l_brace, tok::kw_try)) {
2044 case tok::kw_inline:
2049 (!ParsingInObjCContainer || CurParsedObjCImpl))
2053 case tok::kw_namespace:
2058 (!ParsingInObjCContainer || CurParsedObjCImpl))
2064 if (
NextToken().isObjCAtKeyword(tok::objc_end) &&
2065 ParsingInObjCContainer)
2077 case tok::annot_module_begin:
2078 case tok::annot_module_end:
2079 case tok::annot_module_include:
2097 ForRangeInit *FRI) {
2103 LocalAttrs.takeAllFrom(Attrs);
2114 MaybeParseHLSLSemantics(D);
2116 if (Tok.
is(tok::kw_requires))
2117 ParseTrailingRequiresClause(D);
2122 LateParsedAttrList LateParsedAttrs(
true);
2124 MaybeParseGNUAttributes(D, &LateParsedAttrs);
2129 if (Tok.
is(tok::kw__Noreturn)) {
2131 const char *PrevSpec;
2137 MaybeParseGNUAttributes(D, &LateParsedAttrs);
2138 Fixit &= Tok.
isOneOf(tok::semi, tok::l_brace, tok::kw_try);
2140 Diag(Loc, diag::err_c11_noreturn_misplaced)
2142 << (Fixit ?
FixItHint::CreateInsertion(D.getBeginLoc(),
"_Noreturn ")
2147 if (Tok.
is(tok::equal) &&
NextToken().is(tok::code_completion)) {
2158 while (
auto Specifier = isCXX11VirtSpecifier()) {
2159 Diag(Tok, diag::err_virt_specifier_outside_class)
2167 if (!isDeclarationAfterDeclarator()) {
2173 if (isStartOfFunctionDefinition(D)) {
2175 Diag(Tok, diag::err_function_declared_typedef);
2181 Decl *TheDecl = ParseFunctionDefinition(D, ParsedTemplateInfo(),
2194 Diag(Tok, diag::err_expected_fn_body);
2199 if (Tok.
is(tok::l_brace)) {
2200 Diag(Tok, diag::err_function_definition_not_allowed);
2208 if (ParseAsmAttributesAfterDeclarator(D))
2217 if (FRI && (Tok.
is(tok::colon) || isTokIdentifier_in())) {
2218 bool IsForRangeLoop =
false;
2220 IsForRangeLoop =
true;
2223 if (Tok.
is(tok::l_brace))
2224 FRI->RangeExpr = ParseBraceInitializer();
2230 if (IsForRangeLoop) {
2234 if (
auto *VD = dyn_cast_or_null<VarDecl>(ThisDecl))
2235 VD->setObjCForDecl(
true);
2238 D.complete(ThisDecl);
2243 Decl *FirstDecl = ParseDeclarationAfterDeclaratorAndAttributes(
2244 D, ParsedTemplateInfo(), FRI);
2245 if (LateParsedAttrs.size() > 0)
2246 ParseLexedAttributeList(LateParsedAttrs, FirstDecl,
true,
false);
2247 D.complete(FirstDecl);
2249 DeclsInGroup.push_back(FirstDecl);
2257 if (Tok.
isAtStartOfLine() && ExpectSemi && !MightBeDeclarator(Context)) {
2261 Diag(CommaLoc, diag::err_expected_semi_declaration)
2278 MaybeParseGNUAttributes(D);
2282 DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2287 MaybeParseHLSLSemantics(D);
2294 if (Tok.
is(tok::kw_requires))
2295 ParseTrailingRequiresClause(D);
2296 Decl *ThisDecl = ParseDeclarationAfterDeclarator(D);
2297 D.complete(ThisDecl);
2299 DeclsInGroup.push_back(ThisDecl);
2306 if (ExpectSemi && ExpectAndConsumeSemi(
2308 ? diag::err_invalid_token_after_toplevel_declarator
2309 : diag::err_expected_semi_declaration)) {
2324bool Parser::ParseAsmAttributesAfterDeclarator(
Declarator &D) {
2326 if (Tok.
is(tok::kw_asm)) {
2328 ExprResult AsmLabel(ParseSimpleAsm(
true, &Loc));
2329 if (AsmLabel.isInvalid()) {
2338 MaybeParseGNUAttributes(D);
2364Decl *Parser::ParseDeclarationAfterDeclarator(
2365 Declarator &D,
const ParsedTemplateInfo &TemplateInfo) {
2366 if (ParseAsmAttributesAfterDeclarator(D))
2369 return ParseDeclarationAfterDeclaratorAndAttributes(D, TemplateInfo);
2372Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
2373 Declarator &D,
const ParsedTemplateInfo &TemplateInfo, ForRangeInit *FRI) {
2375 struct InitializerScopeRAII {
2381 :
P(
P), D(D), ThisDecl(ThisDecl) {
2382 if (ThisDecl &&
P.getLangOpts().CPlusPlus) {
2386 S =
P.getCurScope();
2388 P.Actions.ActOnCXXEnterDeclInitializer(S, ThisDecl);
2391 ~InitializerScopeRAII() { pop(); }
2393 if (ThisDecl &&
P.getLangOpts().CPlusPlus) {
2396 S =
P.getCurScope();
2397 P.Actions.ActOnCXXExitDeclInitializer(S, ThisDecl);
2406 InitKind TheInitKind;
2408 if (isTokenEqualOrEqualTypo())
2409 TheInitKind = InitKind::Equal;
2410 else if (Tok.
is(tok::l_paren))
2411 TheInitKind = InitKind::CXXDirect;
2414 TheInitKind = InitKind::CXXBraced;
2416 TheInitKind = InitKind::Uninitialized;
2417 if (TheInitKind != InitKind::Uninitialized)
2421 Decl *ThisDecl =
nullptr;
2422 Decl *OuterDecl =
nullptr;
2423 switch (TemplateInfo.Kind) {
2424 case ParsedTemplateInfo::NonTemplate:
2428 case ParsedTemplateInfo::Template:
2429 case ParsedTemplateInfo::ExplicitSpecialization: {
2431 *TemplateInfo.TemplateParams,
2433 if (
VarTemplateDecl *VT = dyn_cast_or_null<VarTemplateDecl>(ThisDecl)) {
2436 ThisDecl = VT->getTemplatedDecl();
2441 case ParsedTemplateInfo::ExplicitInstantiation: {
2442 if (Tok.
is(tok::semi)) {
2444 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc, D);
2449 ThisDecl = ThisRes.
get();
2457 Diag(Tok, diag::err_template_defn_explicit_instantiation)
2464 diag::err_explicit_instantiation_with_definition)
2472 std::nullopt, LAngleLoc,
nullptr));
2482 switch (TheInitKind) {
2484 case InitKind::Equal: {
2487 if (Tok.
is(tok::kw_delete)) {
2493 }
else if (Tok.
is(tok::kw_default)) {
2501 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2503 if (Tok.
is(tok::code_completion)) {
2516 Diag(EqualLoc, diag::err_single_decl_assign_in_for_range)
2520 FRI->ColonLoc = EqualLoc;
2522 FRI->RangeExpr = Init;
2527 if (Init.isInvalid()) {
2529 StopTokens.push_back(tok::comma);
2532 StopTokens.push_back(tok::r_paren);
2541 case InitKind::CXXDirect: {
2548 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2550 auto ThisVarDecl = dyn_cast_or_null<VarDecl>(ThisDecl);
2551 auto RunSignatureHelp = [&]() {
2553 ThisVarDecl->getType()->getCanonicalTypeInternal(),
2554 ThisDecl->
getLocation(), Exprs, T.getOpenLocation(),
2556 CalledSignatureHelp =
true;
2557 return PreferredType;
2559 auto SetPreferredType = [&] {
2560 PreferredType.enterFunctionArgument(Tok.
getLocation(), RunSignatureHelp);
2563 llvm::function_ref<void()> ExpressionStarts;
2569 ExpressionStarts = SetPreferredType;
2571 if (ParseExpressionList(Exprs, ExpressionStarts)) {
2574 ThisVarDecl->getType()->getCanonicalTypeInternal(),
2575 ThisDecl->
getLocation(), Exprs, T.getOpenLocation(),
2577 CalledSignatureHelp =
true;
2587 T.getCloseLocation(),
2594 case InitKind::CXXBraced: {
2596 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
2598 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2600 PreferredType.enterVariableInit(Tok.
getLocation(), ThisDecl);
2605 if (Init.isInvalid()) {
2611 case InitKind::Uninitialized: {
2618 return OuterDecl ? OuterDecl : ThisDecl;
2627void Parser::ParseSpecifierQualifierList(
2633 ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS, DSC,
nullptr,
2634 AllowImplicitTypename);
2639 Diag(Tok, diag::err_expected_type);
2642 Diag(Tok, diag::err_typename_requires_specqual);
2653 diag::err_typename_invalid_storageclass);
2697 return T.
isOneOf(tok::l_square, tok::l_paren, tok::r_paren, tok::semi,
2698 tok::comma, tok::equal, tok::kw_asm, tok::l_brace,
2712 const ParsedTemplateInfo &TemplateInfo,
2715 assert(Tok.
is(tok::identifier) &&
"should have identifier");
2737 if (!isTypeSpecifier(DSC) &&
getLangOpts().isImplicitIntAllowed() &&
2755 AnnotateScopeToken(*SS,
false);
2766 DSC == DeclSpecContext::DSC_template_type_arg)) {
2767 const char *PrevSpec;
2783 if (SS ==
nullptr) {
2784 const char *TagName =
nullptr, *FixitTagName =
nullptr;
2790 TagName=
"enum" ; FixitTagName =
"enum " ; TagKind=tok::kw_enum ;
break;
2792 TagName=
"union" ; FixitTagName =
"union " ;TagKind=tok::kw_union ;
break;
2794 TagName=
"struct"; FixitTagName =
"struct ";TagKind=tok::kw_struct;
break;
2796 TagName=
"__interface"; FixitTagName =
"__interface ";
2797 TagKind=tok::kw___interface;
break;
2799 TagName=
"class" ; FixitTagName =
"class " ;TagKind=tok::kw_class ;
break;
2807 Diag(Loc, diag::err_use_of_tag_name_without_tag)
2808 << TokenName << TagName <<
getLangOpts().CPlusPlus
2814 Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
2815 << TokenName << TagName;
2819 if (TagKind == tok::kw_enum)
2820 ParseEnumSpecifier(Loc, DS, TemplateInfo, AS,
2821 DeclSpecContext::DSC_normal);
2823 ParseClassSpecifier(TagKind, Loc, DS, TemplateInfo, AS,
2825 DeclSpecContext::DSC_normal, Attrs);
2832 if (!isTypeSpecifier(DSC) && (!SS || DSC == DeclSpecContext::DSC_top_level ||
2833 DSC == DeclSpecContext::DSC_class)) {
2837 case tok::l_paren: {
2844 TentativeParsingAction PA(*
this);
2846 TPResult TPR = TryParseDeclarator(
false);
2849 if (TPR != TPResult::False) {
2857 if (DSC == DeclSpecContext::DSC_class ||
2858 (DSC == DeclSpecContext::DSC_top_level && SS)) {
2861 Diag(Loc, diag::err_constructor_bad_name)
2882 AnnotateScopeToken(*SS,
false);
2904 const char *PrevSpec;
2925 if (IsTemplateName) {
2927 TemplateArgList Args;
2928 ParseTemplateIdAfterTemplateName(
true, LAngle, Args, RAngle);
2942Parser::DeclSpecContext
2946 return DeclSpecContext::DSC_class;
2948 return DeclSpecContext::DSC_top_level;
2950 return DeclSpecContext::DSC_template_param;
2952 return DeclSpecContext::DSC_template_arg;
2954 return DeclSpecContext::DSC_template_type_arg;
2957 return DeclSpecContext::DSC_trailing;
2960 return DeclSpecContext::DSC_alias_declaration;
2962 return DeclSpecContext::DSC_association;
2964 return DeclSpecContext::DSC_type_specifier;
2966 return DeclSpecContext::DSC_condition;
2968 return DeclSpecContext::DSC_conv_operator;
2984 return DeclSpecContext::DSC_normal;
2987 llvm_unreachable(
"Missing DeclaratorContext case");
3002 if (isTypeIdInParens()) {
3027 assert(Tok.
isOneOf(tok::kw_alignas, tok::kw__Alignas) &&
3028 "Not an alignment-specifier!");
3034 if (T.expectAndConsume())
3038 ExprResult ArgExpr = ParseAlignArgument(T.getOpenLocation(), EllipsisLoc);
3046 *EndLoc = T.getCloseLocation();
3049 ArgExprs.push_back(ArgExpr.
get());
3050 Attrs.
addNew(KWName, KWLoc,
nullptr, KWLoc, ArgExprs.data(), 1,
3054ExprResult Parser::ParseExtIntegerArgument() {
3055 assert(Tok.
isOneOf(tok::kw__ExtInt, tok::kw__BitInt) &&
3056 "Not an extended int type");
3060 if (T.expectAndConsume())
3069 if(T.consumeClose())
3083 DeclSpecContext DSContext,
3084 LateParsedAttrList *LateAttrs) {
3087 bool EnteringContext = (DSContext == DeclSpecContext::DSC_class ||
3088 DSContext == DeclSpecContext::DSC_top_level);
3091 Tok.
isOneOf(tok::identifier, tok::coloncolon, tok::kw_decltype,
3092 tok::annot_template_id) &&
3098 bool HasScope = Tok.
is(tok::annot_cxxscope);
3104 bool MightBeDeclarator =
true;
3105 if (Tok.
isOneOf(tok::kw_typename, tok::annot_typename)) {
3107 MightBeDeclarator =
false;
3108 }
else if (AfterScope.
is(tok::annot_template_id)) {
3114 MightBeDeclarator =
false;
3115 }
else if (AfterScope.
is(tok::identifier)) {
3116 const Token &Next = HasScope ? GetLookAheadToken(2) :
NextToken();
3120 if (Next.isOneOf(tok::star, tok::amp, tok::ampamp, tok::identifier,
3121 tok::annot_cxxscope, tok::coloncolon)) {
3123 MightBeDeclarator =
false;
3124 }
else if (HasScope) {
3135 switch (Classification.
getKind()) {
3141 llvm_unreachable(
"typo correction is not possible here");
3148 MightBeDeclarator =
false;
3164 if (MightBeDeclarator)
3169 diag::err_expected_after)
3180 ParsedTemplateInfo NotATemplate;
3181 ParseDeclarationSpecifiers(DS, NotATemplate, AS, DSContext, LateAttrs);
3188 const char *&PrevSpec,
unsigned &DiagID,
3190 assert(!LangOpts.FixedPoint);
3191 DiagID = diag::err_fixed_point_not_enabled;
3223void Parser::ParseDeclarationSpecifiers(
3225 DeclSpecContext DSContext, LateParsedAttrList *LateAttrs,
3237 if (DSContext == DeclSpecContext::DSC_conv_operator) {
3240 DSContext = DeclSpecContext::DSC_type_specifier;
3243 bool EnteringContext = (DSContext == DeclSpecContext::DSC_class ||
3244 DSContext == DeclSpecContext::DSC_top_level);
3245 bool AttrsLastTime =
false;
3251 bool isStorageClass =
false;
3252 const char *PrevSpec =
nullptr;
3253 unsigned DiagID = 0;
3274 auto handleOpenCLImageKW = [&] (StringRef Ext,
TypeSpecifierType ImageTypeSpec) {
3288 bool IsTemplateSpecOrInst =
3289 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
3290 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
3296 ProhibitAttributes(attrs);
3300 if (!PA.isCXX11Attribute() && !PA.isC2xAttribute())
3308 if (PA.getKind() == ParsedAttr::AT_VectorSize) {
3309 Diag(PA.getLoc(), diag::warn_attribute_ignored) << PA;
3316 if (PA.isTypeAttr() && PA.getKind() != ParsedAttr::AT_LifetimeBound &&
3317 PA.getKind() != ParsedAttr::AT_AnyX86NoCfCheck)
3319 Diag(PA.getLoc(), diag::err_attribute_not_type_attr) << PA;
3328 DS.
Finish(Actions, Policy);
3332 case tok::kw_alignas:
3333 if (!standardAttributesAllowed() || !isCXX11AttributeSpecifier())
3334 goto DoneWithDeclSpec;
3336 ProhibitAttributes(attrs);
3343 ParseCXX11Attributes(attrs);
3344 AttrsLastTime =
true;
3347 case tok::code_completion: {
3350 bool AllowNonIdentifiers
3356 bool AllowNestedNameSpecifiers
3357 = DSContext == DeclSpecContext::DSC_top_level ||
3362 AllowNonIdentifiers,
3363 AllowNestedNameSpecifiers);
3368 if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate)
3371 else if (DSContext == DeclSpecContext::DSC_class)
3375 else if (CurParsedObjCImpl)
3383 case tok::coloncolon:
3388 goto DoneWithDeclSpec;
3390 if (Tok.
is(tok::coloncolon))
3391 goto DoneWithDeclSpec;
3394 case tok::annot_cxxscope: {
3396 goto DoneWithDeclSpec;
3399 if (TemplateInfo.TemplateParams)
3409 ? takeTemplateIdAnnotation(Next)
3415 ConsumeAnnotationToken();
3429 if ((DSContext == DeclSpecContext::DSC_top_level ||
3430 DSContext == DeclSpecContext::DSC_class) &&
3433 isConstructorDeclarator(
false,
3440 goto DoneWithDeclSpec;
3444 ConsumeAnnotationToken();
3445 assert(Tok.
is(tok::annot_template_id) &&
3446 "ParseOptionalCXXScopeSpecifier not working");
3447 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
3452 GetLookAheadToken(2).
isOneOf(tok::kw_auto, tok::kw_decltype)) {
3457 ConsumeAnnotationToken();
3461 if (Next.is(tok::annot_typename)) {
3463 ConsumeAnnotationToken();
3467 PrevSpec, DiagID, T, Policy);
3471 ConsumeAnnotationToken();
3475 Next.is(tok::annot_template_id) &&
3479 ConsumeAnnotationToken();
3480 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
3484 if (Next.isNot(tok::identifier))
3485 goto DoneWithDeclSpec;
3490 if ((DSContext == DeclSpecContext::DSC_top_level ||
3491 DSContext == DeclSpecContext::DSC_class) &&
3494 isConstructorDeclarator(
false,
3498 goto DoneWithDeclSpec;
3507 *Next.getIdentifierInfo(), Next.getLocation(),
getCurScope(), &SS,
3508 false,
false,
nullptr,
3511 isClassTemplateDeductionContext(DSContext), AllowImplicitTypename);
3513 if (IsTemplateSpecOrInst)
3521 if (TryAnnotateTypeConstraint())
3522 goto DoneWithDeclSpec;
3523 if (Tok.
isNot(tok::annot_cxxscope) ||
3527 ConsumeAnnotationToken();
3529 if (ParseImplicitInt(DS, &SS, TemplateInfo, AS, DSContext, Attrs)) {
3530 if (!Attrs.
empty()) {
3531 AttrsLastTime =
true;
3532 attrs.takeAllFrom(Attrs);
3536 goto DoneWithDeclSpec;
3540 ConsumeAnnotationToken();
3543 DiagID, TypeRep, Policy);
3553 case tok::annot_typename: {
3557 goto DoneWithDeclSpec;
3566 ConsumeAnnotationToken();
3571 case tok::kw___is_signed:
3582 TryKeywordIdentFallback(
true);
3585 goto DoneWithDeclSpec;
3588 case tok::kw___super:
3589 case tok::kw_decltype:
3590 case tok::identifier:
3596 goto DoneWithDeclSpec;
3602 if (!
getLangOpts().DeclSpecKeyword && Tok.
is(tok::identifier) &&
3604 Diag(Loc, diag::err_ms_attributes_not_enabled);
3614 if (T.consumeOpen()) {
3615 assert(
false &&
"Not a left paren?");
3634 if (IsTemplateSpecOrInst)
3638 if (IsTemplateSpecOrInst)
3641 goto DoneWithDeclSpec;
3644 if (!Tok.
is(tok::identifier))
3649 if (TryAltiVecToken(DS, Loc, PrevSpec, DiagID,
isInvalid))
3655 goto DoneWithDeclSpec;
3657 if (DSContext == DeclSpecContext::DSC_objc_method_result &&
3658 isObjCInstancetype()) {
3662 DiagID, TypeRep, Policy);
3675 isConstructorDeclarator(
true,
3678 goto DoneWithDeclSpec;
3682 false,
false,
nullptr,
false,
false,
3683 isClassTemplateDeductionContext(DSContext));
3688 if (TryAnnotateTypeConstraint())
3689 goto DoneWithDeclSpec;
3690 if (Tok.
isNot(tok::identifier))
3693 if (ParseImplicitInt(DS,
nullptr, TemplateInfo, AS, DSContext, Attrs)) {
3694 if (!Attrs.
empty()) {
3695 AttrsLastTime =
true;
3696 attrs.takeAllFrom(Attrs);
3700 goto DoneWithDeclSpec;
3706 (DSContext == DeclSpecContext::DSC_class ||
3707 DSContext == DeclSpecContext::DSC_top_level) &&
3710 isConstructorDeclarator(
true,
3712 goto DoneWithDeclSpec;
3715 DiagID, TypeRep, Policy);
3727 TypeResult NewTypeRep = parseObjCTypeArgsAndProtocolQualifiers(
3742 case tok::annot_template_id: {
3754 TemplateId =
nullptr;
3762 tok::kw_volatile, tok::kw_restrict, tok::amp,
3764 Diag(Loc, diag::err_placeholder_expected_auto_or_decltype_auto)
3768 TemplateId, Policy);
3772 goto DoneWithDeclSpec;
3773 ConsumeAnnotationToken();
3777 if (Tracker.consumeOpen()) {
3779 Diag(Tok, diag::err_expected) << tok::l_paren;
3783 Tracker.skipToEnd();
3784 Diag(Tok, diag::err_placeholder_expected_auto_or_decltype_auto)
3789 Tracker.consumeClose();
3797 DiagID, TemplateId, Policy);
3800 TemplateId, Policy);
3809 goto DoneWithDeclSpec;
3817 isConstructorDeclarator(
true,
3820 goto DoneWithDeclSpec;
3825 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
3830 case tok::kw___attribute:
3831 case tok::kw___declspec:
3832 ParseAttributes(PAKM_GNU | PAKM_Declspec, DS.
getAttributes(), LateAttrs);
3836 case tok::kw___forceinline: {
3845 case tok::kw___unaligned:
3850 case tok::kw___sptr:
3851 case tok::kw___uptr:
3852 case tok::kw___ptr64:
3853 case tok::kw___ptr32:
3855 case tok::kw___cdecl:
3856 case tok::kw___stdcall:
3857 case tok::kw___fastcall:
3858 case tok::kw___thiscall:
3859 case tok::kw___regcall:
3860 case tok::kw___vectorcall:
3864 case tok::kw___funcref:
3869 case tok::kw___pascal:
3874 case tok::kw___kernel:
3879 case tok::kw___noinline__:
3884 case tok::kw__Nonnull:
3885 case tok::kw__Nullable:
3886 case tok::kw__Nullable_result:
3887 case tok::kw__Null_unspecified:
3892 case tok::kw___kindof:
3899 case tok::kw_typedef:
3901 PrevSpec, DiagID, Policy);
3902 isStorageClass =
true;
3904 case tok::kw_extern:
3906 Diag(Tok, diag::ext_thread_before) <<
"extern";
3908 PrevSpec, DiagID, Policy);
3909 isStorageClass =
true;
3911 case tok::kw___private_extern__:
3913 Loc, PrevSpec, DiagID, Policy);
3914 isStorageClass =
true;
3916 case tok::kw_static:
3918 Diag(Tok, diag::ext_thread_before) <<
"static";
3920 PrevSpec, DiagID, Policy);
3921 isStorageClass =
true;
3925 if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) {
3927 PrevSpec, DiagID, Policy);
3929 Diag(Tok, diag::ext_auto_storage_class)
3936 PrevSpec, DiagID, Policy);
3937 isStorageClass =
true;
3939 case tok::kw___auto_type:
3940 Diag(Tok, diag::ext_auto_type);
3944 case tok::kw_register:
3946 PrevSpec, DiagID, Policy);
3947 isStorageClass =
true;
3949 case tok::kw_mutable:
3951 PrevSpec, DiagID, Policy);
3952 isStorageClass =
true;
3954 case tok::kw___thread:
3957 isStorageClass =
true;
3959 case tok::kw_thread_local:
3961 Diag(Tok, diag::warn_c2x_compat_keyword) << Tok.
getName();
3964 isStorageClass =
true;
3966 case tok::kw__Thread_local:
3968 Diag(Tok, diag::ext_c11_feature) << Tok.
getName();
3970 Loc, PrevSpec, DiagID);
3971 isStorageClass =
true;
3975 case tok::kw_inline:
3978 case tok::kw_virtual:
3982 !
getActions().getOpenCLOptions().isAvailableOption(
3984 DiagID = diag::err_openclcxx_virtual_function;
3991 case tok::kw_explicit: {
3995 ConsumedEnd = ExplicitLoc;
3997 if (Tok.
is(tok::l_paren)) {
4000 ? diag::warn_cxx17_compat_explicit_bool
4001 : diag::ext_explicit_bool);
4005 Tracker.consumeOpen();
4008 if (ExplicitExpr.isUsable()) {
4010 Tracker.consumeClose();
4014 Tracker.skipToEnd();
4020 ExplicitSpec, CloseParenLoc);
4023 case tok::kw__Noreturn:
4025 Diag(Tok, diag::ext_c11_feature) << Tok.
getName();
4030 case tok::kw__Alignas:
4032 Diag(Tok, diag::ext_c11_feature) << Tok.
getName();
4037 case tok::kw_friend:
4038 if (DSContext == DeclSpecContext::DSC_class)
4042 DiagID = diag::err_friend_invalid_in_context;
4048 case tok::kw___module_private__:
4053 case tok::kw_constexpr:
4057 case tok::kw_consteval:
4061 case tok::kw_constinit:
4077 PrevSpec, DiagID, Policy);
4079 case tok::kw___int64:
4081 PrevSpec, DiagID, Policy);
4083 case tok::kw_signed:
4087 case tok::kw_unsigned:
4091 case tok::kw__Complex:
4093 Diag(Tok, diag::ext_c99_feature) << Tok.
getName();
4097 case tok::kw__Imaginary:
4099 Diag(Tok, diag::ext_c99_feature) << Tok.
getName();
4115 case tok::kw__ExtInt:
4116 case tok::kw__BitInt: {
4117 DiagnoseBitIntUse(Tok);
4122 ConsumedEnd = PrevTokLocation;
4125 case tok::kw___int128:
4133 case tok::kw___bf16:
4141 case tok::kw_double:
4145 case tok::kw__Float16:
4149 case tok::kw__Accum:
4157 case tok::kw__Fract:
4172 case tok::kw___float128:
4176 case tok::kw___ibm128:
4180 case tok::kw_wchar_t:
4184 case tok::kw_char8_t:
4188 case tok::kw_char16_t:
4192 case tok::kw_char32_t:
4198 Diag(Tok, diag::warn_c2x_compat_keyword) << Tok.
getName();
4202 Diag(Tok, diag::ext_c99_feature) << Tok.
getName();
4204 if (Tok.
is(tok::kw_bool) &&
4208 DiagID = diag::err_bool_redeclaration;
4217 case tok::kw__Decimal32:
4221 case tok::kw__Decimal64:
4225 case tok::kw__Decimal128:
4229 case tok::kw___vector:
4232 case tok::kw___pixel:
4235 case tok::kw___bool:
4240 getLangOpts().getOpenCLCompatibleVersion() < 200) {
4245 goto DoneWithDeclSpec;
4247 DiagID = diag::err_opencl_unknown_type_specifier;
4254#define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
4255#define IMAGE_WRITE_TYPE(Type, Id, Ext)
4256#define IMAGE_READ_TYPE(ImgType, Id, Ext) \
4257 case tok::kw_##ImgType##_t: \
4258 if (!handleOpenCLImageKW(Ext, DeclSpec::TST_##ImgType##_t)) \
4259 goto DoneWithDeclSpec; \
4261#include "clang/Basic/OpenCLImageTypes.def"
4262 case tok::kw___unknown_anytype:
4264 PrevSpec, DiagID, Policy);
4269 case tok::kw_struct:
4270 case tok::kw___interface:
4271 case tok::kw_union: {
4279 ParseClassSpecifier(Kind, Loc, DS, TemplateInfo, AS,
4280 EnteringContext, DSContext, Attributes);
4284 if (!Attributes.empty()) {
4285 AttrsLastTime =
true;
4286 attrs.takeAllFrom(Attributes);
4294 ParseEnumSpecifier(Loc, DS, TemplateInfo, AS, DSContext);
4302 case tok::kw_volatile:
4306 case tok::kw_restrict:
4312 case tok::kw_typename:
4315 goto DoneWithDeclSpec;
4317 if (!Tok.
is(tok::kw_typename))
4322 case tok::kw_typeof:
4323 case tok::kw_typeof_unqual:
4324 ParseTypeofSpecifier(DS);
4327 case tok::annot_decltype:
4328 ParseDecltypeSpecifier(DS);
4331 case tok::annot_pragma_pack:
4335 case tok::annot_pragma_ms_pragma:
4336 HandlePragmaMSPragma();
4339 case tok::annot_pragma_ms_vtordisp:
4340 HandlePragmaMSVtorDisp();
4343 case tok::annot_pragma_ms_pointers_to_members:
4344 HandlePragmaMSPointersToMembers();
4347#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
4348#include "clang/Basic/TransformTypeTraits.def"
4352 if (!MaybeParseTypeTransformTypeSpecifier(DS))
4353 goto ParseIdentifier;
4356 case tok::kw__Atomic:
4362 Diag(Tok, diag::ext_c11_feature) << Tok.
getName();
4365 ParseAtomicSpecifier(DS);
4373 case tok::kw___generic:
4378 if (!Actions.
getLangOpts().OpenCLGenericAddressSpace) {
4379 DiagID = diag::err_opencl_unknown_type_specifier;
4385 case tok::kw_private:
4389 goto DoneWithDeclSpec;
4391 case tok::kw___private:
4392 case tok::kw___global:
4393 case tok::kw___local:
4394 case tok::kw___constant:
4396 case tok::kw___read_only:
4397 case tok::kw___write_only:
4398 case tok::kw___read_write:
4402 case tok::kw_groupshared:
4412 goto DoneWithDeclSpec;
4417 if (
Type.isUsable()) {
4419 PrevSpec, DiagID,
Type.get(),
4421 Diag(StartLoc, DiagID) << PrevSpec;
4437 assert(PrevSpec &&
"Method did not return previous specifier!");
4440 if (DiagID == diag::ext_duplicate_declspec ||
4441 DiagID == diag::ext_warn_duplicate_declspec ||
4442 DiagID == diag::err_duplicate_declspec)
4443 Diag(Loc, DiagID) << PrevSpec
4446 else if (DiagID == diag::err_opencl_unknown_type_specifier) {
4450 Diag(Loc, DiagID) << PrevSpec;
4453 if (DiagID != diag::err_bool_redeclaration && ConsumedEnd.
isInvalid())
4457 AttrsLastTime =
false;
4482void Parser::ParseStructDeclaration(
4486 if (Tok.
is(tok::kw___extension__)) {
4490 return ParseStructDeclaration(DS, FieldsCallback);
4495 MaybeParseCXX11Attributes(Attrs);
4498 ParseSpecifierQualifierList(DS);
4502 if (Tok.
is(tok::semi)) {
4507 ProhibitAttributes(Attrs);
4511 assert(!AnonRecord &&
"Did not expect anonymous struct or union here");
4517 bool FirstDeclarator =
true;
4521 DeclaratorInfo.D.setCommaLoc(CommaLoc);
4524 if (!FirstDeclarator) {
4527 DiagnoseAndSkipCXX11Attributes();
4528 MaybeParseGNUAttributes(DeclaratorInfo.D);
4529 DiagnoseAndSkipCXX11Attributes();
4534 if (Tok.
isNot(tok::colon)) {
4537 ParseDeclarator(DeclaratorInfo.D);
4539 DeclaratorInfo.D.SetIdentifier(
nullptr, Tok.
getLocation());
4543 if (Res.isInvalid())
4546 DeclaratorInfo.BitfieldSize = Res.get();
4550 MaybeParseGNUAttributes(DeclaratorInfo.D);
4553 FieldsCallback(DeclaratorInfo);
4560 FirstDeclarator =
false;
4577 "parsing struct/union body");
4581 if (T.consumeOpen())
4588 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
4589 Tok.
isNot(tok::eof)) {
4593 if (Tok.
is(tok::semi)) {
4594 ConsumeExtraSemi(InsideStruct,
TagType);
4599 if (Tok.
isOneOf(tok::kw__Static_assert, tok::kw_static_assert)) {
4601 ParseStaticAssertDeclaration(DeclEnd);
4605 if (Tok.
is(tok::annot_pragma_pack)) {
4610 if (Tok.
is(tok::annot_pragma_align)) {
4611 HandlePragmaAlign();
4615 if (Tok.
isOneOf(tok::annot_pragma_openmp, tok::annot_attr_openmp)) {
4619 (void)ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs);
4627 ConsumeAnnotationToken();
4631 if (!Tok.
is(tok::at)) {
4637 FD.D, FD.BitfieldSize);
4643 ParseStructDeclaration(DS, CFieldCallback);
4647 Diag(Tok, diag::err_unexpected_at);
4652 ExpectAndConsume(tok::l_paren);
4653 if (!Tok.
is(tok::identifier)) {
4654 Diag(Tok, diag::err_expected) << tok::identifier;
4662 ExpectAndConsume(tok::r_paren);
4668 if (Tok.
is(tok::r_brace)) {
4669 ExpectAndConsume(tok::semi, diag::ext_expected_semi_decl_list);
4673 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list);
4684 MaybeParseGNUAttributes(attrs);
4689 T.getOpenLocation(), T.getCloseLocation(), attrs);
4725 const ParsedTemplateInfo &TemplateInfo,
4728 if (Tok.
is(tok::code_completion)) {
4738 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec | PAKM_CXX11, attrs);
4741 bool IsScopedUsingClassTag =
false;
4746 : diag::ext_scoped_enum);
4747 IsScopedUsingClassTag = Tok.
is(tok::kw_class);
4752 ProhibitAttributes(attrs);
4755 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec | PAKM_CXX11, attrs);
4764 bool shouldDelayDiagsInTag =
4765 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
4766 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
4770 AllowDefiningTypeSpec AllowEnumSpecifier =
4772 bool CanBeOpaqueEnumDeclaration =
4773 DS.
isEmpty() && isOpaqueEnumDeclarationContext(DSC);
4776 (AllowEnumSpecifier == AllowDefiningTypeSpec::Yes ||
4777 CanBeOpaqueEnumDeclaration);
4785 if (ParseOptionalCXXScopeSpecifier(Spec,
nullptr,
4790 if (Spec.
isSet() && Tok.
isNot(tok::identifier)) {
4791 Diag(Tok, diag::err_expected) << tok::identifier;
4793 if (Tok.
isNot(tok::l_brace)) {
4805 if (Tok.
isNot(tok::identifier) && Tok.
isNot(tok::l_brace) &&
4806 Tok.
isNot(tok::colon)) {
4807 Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace;
4818 if (Tok.
is(tok::identifier)) {
4823 if (!Name && ScopedEnumKWLoc.
isValid()) {
4826 Diag(Tok, diag::err_scoped_enum_missing_identifier);
4828 IsScopedUsingClassTag =
false;
4833 if (shouldDelayDiagsInTag)
4834 diagsFromTag.done();
4839 bool CanBeBitfield =
4843 if (Tok.
is(tok::colon)) {
4868 if (CanBeBitfield && !isEnumBase(CanBeOpaqueEnumDeclaration)) {
4873 }
else if (CanHaveEnumBase || !ColonIsSacred) {
4884 DeclSpecContext::DSC_type_specifier);
4889 BaseRange =
SourceRange(ColonLoc, DeclaratorInfo.getSourceRange().getEnd());
4893 Diag(ColonLoc, diag::warn_cxx98_compat_enum_fixed_underlying_type)
4896 Diag(ColonLoc, diag::ext_cxx11_enum_fixed_underlying_type)
4899 Diag(ColonLoc, diag::ext_ms_c_enum_fixed_underlying_type)
4902 Diag(ColonLoc, diag::ext_clang_c_enum_fixed_underlying_type)
4919 if (AllowEnumSpecifier == AllowDefiningTypeSpec::No)
4921 else if (Tok.
is(tok::l_brace)) {
4930 IsScopedUsingClassTag =
false;
4936 }
else if (!isTypeSpecifier(DSC) &&
4937 (Tok.
is(tok::semi) ||
4939 !isValidAfterTypeSpecifier(CanBeBitfield)))) {
4944 if (Tok.
isNot(tok::semi)) {
4946 ExpectAndConsume(tok::semi, diag::err_expected_after,
"enum");
4954 bool IsElaboratedTypeSpecifier =
4960 diagsFromTag.redelay();
4964 if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
4968 Diag(Tok, diag::err_enum_template);
4973 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
4976 Diag(StartLoc, diag::err_explicit_instantiation_enum);
4980 assert(TemplateInfo.TemplateParams &&
"no template parameters");
4982 TemplateInfo.TemplateParams->size());
4987 Diag(Tok, diag::err_enumerator_unnamed_no_def);
5003 if (IsElaboratedTypeSpecifier && !
getLangOpts().MicrosoftExt &&
5005 ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
5008 Diag(BaseRange.
getBegin(), diag::ext_enum_base_in_type_specifier)
5009 << (AllowEnumSpecifier == AllowDefiningTypeSpec::Yes) << BaseRange;
5010 else if (ScopedEnumKWLoc.
isValid())
5011 Diag(ScopedEnumKWLoc, diag::ext_elaborated_enum_class)
5015 stripTypeAttributesOffDeclSpec(attrs, DS, TUK);
5025 bool IsDependent =
false;
5026 const char *PrevSpec =
nullptr;
5031 TParams, Owned, IsDependent, ScopedEnumKWLoc,
5032 IsScopedUsingClassTag,
5033 BaseType, DSC == DeclSpecContext::DSC_type_specifier,
5034 DSC == DeclSpecContext::DSC_template_param ||
5035 DSC == DeclSpecContext::DSC_template_type_arg,
5036 OffsetOfState, &SkipBody).
get();
5046 NameLoc.
isValid() ? NameLoc : StartLoc,
5047 PrevSpec, DiagID,
TagDecl, Owned,
5049 Diag(StartLoc, DiagID) << PrevSpec;
5058 Diag(Tok, diag::err_expected_type_name_after_typename);
5064 if (
Type.isInvalid()) {
5070 NameLoc.
isValid() ? NameLoc : StartLoc,
5071 PrevSpec, DiagID,
Type.get(),
5073 Diag(StartLoc, DiagID) << PrevSpec;
5092 ParseEnumBody(StartLoc, D);
5101 NameLoc.
isValid() ? NameLoc : StartLoc,
5102 PrevSpec, DiagID,
TagDecl, Owned,
5104 Diag(StartLoc, DiagID) << PrevSpec;
5127 Diag(Tok, diag::err_empty_enum);
5132 Decl *LastEnumConstDecl =
nullptr;
5135 while (Tok.
isNot(tok::r_brace)) {
5138 if (Tok.
isNot(tok::identifier)) {
5150 MaybeParseGNUAttributes(attrs);
5151 if (standardAttributesAllowed() && isCXX11AttributeSpecifier()) {
5154 ? diag::warn_cxx14_compat_ns_enum_attribute
5155 : diag::ext_ns_enum_attribute)
5157 ParseCXX11Attributes(attrs);
5162 EnumAvailabilityDiags.emplace_back(*
this);
5175 EqualLoc, AssignedVal.
get());
5176 EnumAvailabilityDiags.back().done();
5178 EnumConstantDecls.push_back(EnumConstDecl);
5179 LastEnumConstDecl = EnumConstDecl;
5181 if (Tok.
is(tok::identifier)) {
5184 Diag(Loc, diag::err_enumerator_list_missing_comma)
5207 if (Tok.
is(tok::r_brace) && CommaLoc.
isValid()) {
5210 diag::ext_enumerator_list_comma_cxx :
5211 diag::ext_enumerator_list_comma_c)
5214 Diag(CommaLoc, diag::warn_cxx98_compat_enumerator_list_comma)
5225 MaybeParseGNUAttributes(attrs);
5231 assert(EnumConstantDecls.size() == EnumAvailabilityDiags.size());
5232 for (
size_t i = 0, e = EnumConstantDecls.size(); i != e; ++i) {
5234 EnumAvailabilityDiags[i].redelay();
5235 PD.complete(EnumConstantDecls[i]);
5244 if (!isValidAfterTypeSpecifier(CanBeBitfield)) {
5245 ExpectAndConsume(tok::semi, diag::err_expected_after,
"enum");
5257bool Parser::isKnownToBeTypeSpecifier(
const Token &Tok)
const {
5259 default:
return false;
5263 case tok::kw___int64:
5264 case tok::kw___int128:
5265 case tok::kw_signed:
5266 case tok::kw_unsigned:
5267 case tok::kw__Complex:
5268 case tok::kw__Imaginary:
5271 case tok::kw_wchar_t:
5272 case tok::kw_char8_t:
5273 case tok::kw_char16_t:
5274 case tok::kw_char32_t:
5276 case tok::kw__ExtInt:
5277 case tok::kw__BitInt:
5278 case tok::kw___bf16:
5281 case tok::kw_double:
5282 case tok::kw__Accum:
5283 case tok::kw__Fract:
5284 case tok::kw__Float16:
5285 case tok::kw___float128:
5286 case tok::kw___ibm128:
5289 case tok::kw__Decimal32:
5290 case tok::kw__Decimal64:
5291 case tok::kw__Decimal128:
5292 case tok::kw___vector:
5293#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
5294#include "clang/Basic/OpenCLImageTypes.def"
5298 case tok::kw_struct:
5299 case tok::kw___interface:
5305 case tok::annot_typename:
5312bool Parser::isTypeSpecifierQualifier() {
5314 default:
return false;
5316 case tok::identifier:
5317 if (TryAltiVecVectorToken())
5320 case tok::kw_typename:
5325 if (Tok.
is(tok::identifier))
5327 return isTypeSpecifierQualifier();
5329 case tok::coloncolon:
5336 return isTypeSpecifierQualifier();
5339 case tok::kw___attribute:
5341 case tok::kw_typeof:
5342 case tok::kw_typeof_unqual:
5347 case tok::kw___int64:
5348 case tok::kw___int128:
5349 case tok::kw_signed:
5350 case tok::kw_unsigned:
5351 case tok::kw__Complex:
5352 case tok::kw__Imaginary:
5355 case tok::kw_wchar_t:
5356 case tok::kw_char8_t:
5357 case tok::kw_char16_t:
5358 case tok::kw_char32_t:
5360 case tok::kw__ExtInt:
5361 case tok::kw__BitInt:
5363 case tok::kw___bf16:
5365 case tok::kw_double:
5366 case tok::kw__Accum:
5367 case tok::kw__Fract:
5368 case tok::kw__Float16:
5369 case tok::kw___float128:
5370 case tok::kw___ibm128:
5373 case tok::kw__Decimal32:
5374 case tok::kw__Decimal64:
5375 case tok::kw__Decimal128:
5376 case tok::kw___vector:
5377#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
5378#include "clang/Basic/OpenCLImageTypes.def"
5382 case tok::kw_struct:
5383 case tok::kw___interface:
5390 case tok::kw_volatile:
5391 case tok::kw_restrict:
5395 case tok::kw___unknown_anytype:
5398 case tok::annot_typename:
5405 case tok::kw___cdecl:
5406 case tok::kw___stdcall:
5407 case tok::kw___fastcall:
5408 case tok::kw___thiscall:
5409 case tok::kw___regcall:
5410 case tok::kw___vectorcall:
5412 case tok::kw___ptr64:
5413 case tok::kw___ptr32:
5414 case tok::kw___pascal:
5415 case tok::kw___unaligned:
5417 case tok::kw__Nonnull:
5418 case tok::kw__Nullable:
5419 case tok::kw__Nullable_result:
5420 case tok::kw__Null_unspecified:
5422 case tok::kw___kindof:
5424 case tok::kw___private:
5425 case tok::kw___local:
5426 case tok::kw___global:
5427 case tok::kw___constant:
5428 case tok::kw___generic:
5429 case tok::kw___read_only:
5430 case tok::kw___read_write:
5431 case tok::kw___write_only:
5432 case tok::kw___funcref:
5433 case tok::kw_groupshared:
5436 case tok::kw_private:
5440 case tok::kw__Atomic:
5450 ParsedStmtContext SubStmtCtx = ParsedStmtContext();
5452 StmtResult R = ParseStatementOrDeclaration(Stmts, SubStmtCtx);
5460 for (
Stmt *S : Stmts)
5473bool Parser::isDeclarationSpecifier(
5475 bool DisambiguatingWithExpression) {
5477 default:
return false;