34#include "llvm/ADT/ScopeExit.h"
35#include "llvm/ADT/SmallSet.h"
36#include "llvm/ADT/StringSwitch.h"
48 DeclSpecContext DSC = getDeclSpecContextFromDeclaratorContext(Context);
49 if (DSC == DeclSpecContext::DSC_normal)
50 DSC = DeclSpecContext::DSC_type_specifier;
56 ParseSpecifierQualifierList(DS, AS, DSC);
64 if (AL.isDeclspecAttribute())
65 ToBeMoved.push_back(&AL);
74 ParseDeclarator(DeclaratorInfo);
81 return Actions.ActOnTypeName(DeclaratorInfo);
86 if (Name.size() >= 4 && Name.starts_with(
"__") && Name.ends_with(
"__"))
87 return Name.drop_front(2).drop_back(2);
94#define CLANG_ATTR_LATE_PARSED_EXPERIMENTAL_EXT_LIST
96#include "clang/Parse/AttrParserStringSwitches.inc"
98#undef CLANG_ATTR_LATE_PARSED_EXPERIMENTAL_EXT_LIST
104#define CLANG_ATTR_LATE_PARSED_LIST
106#include "clang/Parse/AttrParserStringSwitches.inc"
108#undef CLANG_ATTR_LATE_PARSED_LIST
114#define CLANG_ATTR_PARSE_ARGS_IN_FUNCTION_SCOPE_LIST
116#include "clang/Parse/AttrParserStringSwitches.inc"
118#undef CLANG_ATTR_PARSE_ARGS_IN_FUNCTION_SCOPE_LIST
131 bool AttrStartIsInMacro =
133 bool AttrEndIsInMacro =
135 return AttrStartIsInMacro && AttrEndIsInMacro;
138void Parser::ParseAttributes(
unsigned WhichAttrKinds,
ParsedAttributes &Attrs,
145 if (WhichAttrKinds & PAKM_CXX11)
146 MoreToParse |= MaybeParseCXX11Attributes(Attrs);
147 if (WhichAttrKinds & PAKM_GNU)
148 MoreToParse |= MaybeParseGNUAttributes(Attrs, LateAttrs);
149 if (WhichAttrKinds & PAKM_Declspec)
150 MoreToParse |= MaybeParseMicrosoftDeclSpecs(Attrs);
151 }
while (MoreToParse);
158 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
164 if (Tok.isNot(tok::l_paren)) {
165 Attrs.
addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
nullptr, 0,
166 ParsedAttr::Form::GNU());
170 bool LateParse =
false;
177 LateParse =
getLangOpts().ExperimentalLateParseAttributes &&
190 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, &EndLoc,
nullptr,
191 SourceLocation(), ParsedAttr::Form::GNU(), D);
210 const DeclaratorChunk::FunctionTypeInfo &FTI = Chunk.
Fun;
211 for (
unsigned P = 0, NumParams = FTI.
NumParams; P != NumParams; ++P)
212 if (
auto *Param = dyn_cast_or_null<ParmVarDecl>(FTI.
Params[P].
Param);
213 Param && Param->getIdentifier())
219 LateAttrs->push_back(LA);
223 if (!ClassStack.empty() && !LateAttrs->
parseSoon())
224 getCurrentClass().LateParsedDeclarations.push_back(LA);
228 LA->
Toks.push_back(Tok);
231 ConsumeAndStoreUntil(tok::r_paren, LA->
Toks,
true);
236 LA->
Toks.push_back(Eof);
243 assert(Tok.is(tok::kw___attribute) &&
"Not a GNU attribute list!");
245 SourceLocation StartLoc = Tok.getLocation();
246 SourceLocation EndLoc = StartLoc;
248 while (Tok.is(tok::kw___attribute)) {
250 unsigned OldNumAttrs = Attrs.
size();
251 unsigned OldNumLateAttrs = LateAttrs ? LateAttrs->size() : 0;
253 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
258 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
"(")) {
269 if (Tok.isAnnotation())
271 if (Tok.is(tok::code_completion)) {
273 Actions.CodeCompletion().CodeCompleteAttribute(
278 if (ParseSingleGNUAttribute(Attrs, EndLoc, LateAttrs, D))
280 }
while (Tok.is(tok::comma));
282 if (ExpectAndConsume(tok::r_paren))
284 SourceLocation Loc = Tok.getLocation();
285 if (ExpectAndConsume(tok::r_paren))
291 auto &SM = PP.getSourceManager();
292 if (!SM.isWrittenInBuiltinFile(SM.getSpellingLoc(AttrTokLoc)) &&
294 CharSourceRange ExpansionRange = SM.getExpansionRange(AttrTokLoc);
295 StringRef FoundName =
297 IdentifierInfo *MacroII = PP.getIdentifierInfo(FoundName);
299 for (
unsigned i = OldNumAttrs; i < Attrs.
size(); ++i)
300 Attrs[i].setMacroIdentifier(MacroII, ExpansionRange.
getBegin());
303 for (
unsigned i = OldNumLateAttrs; i < LateAttrs->size(); ++i)
304 (*LateAttrs)[i]->MacroII = MacroII;
309 Attrs.
Range = SourceRange(StartLoc, EndLoc);
317#define CLANG_ATTR_IDENTIFIER_ARG_LIST
319#include "clang/Parse/AttrParserStringSwitches.inc"
321#undef CLANG_ATTR_IDENTIFIER_ARG_LIST
329#define CLANG_ATTR_STRING_LITERAL_ARG_LIST
331#include "clang/Parse/AttrParserStringSwitches.inc"
333#undef CLANG_ATTR_STRING_LITERAL_ARG_LIST
340#define CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST
342#include "clang/Parse/AttrParserStringSwitches.inc"
344#undef CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST
351#define CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST
353#include "clang/Parse/AttrParserStringSwitches.inc"
355#undef CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST
362#define CLANG_ATTR_ACCEPTS_EXPR_PACK
364#include "clang/Parse/AttrParserStringSwitches.inc"
366#undef CLANG_ATTR_ACCEPTS_EXPR_PACK
373#define CLANG_ATTR_TYPE_ARG_LIST
375#include "clang/Parse/AttrParserStringSwitches.inc"
377#undef CLANG_ATTR_TYPE_ARG_LIST
384#define CLANG_ATTR_STRICT_IDENTIFIER_ARG_LIST
386#include "clang/Parse/AttrParserStringSwitches.inc"
388#undef CLANG_ATTR_STRICT_IDENTIFIER_ARG_LIST
396#define CLANG_ATTR_ARG_CONTEXT_LIST
398#include "clang/Parse/AttrParserStringSwitches.inc"
400#undef CLANG_ATTR_ARG_CONTEXT_LIST
404 assert(Tok.is(tok::identifier) &&
"expected an identifier");
405 IdentifierLoc *IL =
new (Actions.Context)
406 IdentifierLoc(Tok.getLocation(), Tok.getIdentifierInfo());
421 if (Tok.isNot(tok::r_paren))
424 if (
Parens.consumeClose())
432 &AttrName, SourceRange(AttrNameLoc,
Parens.getCloseLocation()),
433 AttributeScopeInfo(ScopeName, ScopeLoc),
T.get(), Form);
435 Attrs.
addNew(&AttrName, SourceRange(AttrNameLoc,
Parens.getCloseLocation()),
436 AttributeScopeInfo(ScopeName, ScopeLoc),
nullptr, 0, Form);
440Parser::ParseUnevaluatedStringInAttribute(
const IdentifierInfo &AttrName) {
441 if (Tok.is(tok::l_paren)) {
444 ExprResult Res = ParseUnevaluatedStringInAttribute(AttrName);
445 Paren.consumeClose();
448 if (!isTokenStringLiteral()) {
449 Diag(Tok.getLocation(), diag::err_expected_string_literal)
456bool Parser::ParseAttributeArgumentList(
459 bool SawError =
false;
463 Expr = ParseUnevaluatedStringInAttribute(AttrName);
465 Diag(Tok, diag::compat_cxx11_generalized_initializer_lists);
466 Expr = ParseBraceInitializer();
471 if (Tok.is(tok::ellipsis))
473 else if (Tok.is(tok::code_completion)) {
489 if (Actions.DiagnoseUnexpandedParameterPack(Expr.
get())) {
494 Exprs.push_back(Expr.
get());
496 if (Tok.isNot(tok::comma))
501 checkPotentialAngleBracketDelimiter(Comma);
508unsigned Parser::ParseAttributeArgsCommon(
517 bool AttributeIsTypeArgAttr =
519 bool AttributeHasVariadicIdentifierArg =
523 if (ChangeKWThisToIdent && Tok.is(tok::kw_this))
524 Tok.setKind(tok::identifier);
527 if (Tok.is(tok::identifier)) {
529 bool IsIdentifierArg =
530 AttributeHasVariadicIdentifierArg ||
541 IsIdentifierArg =
Next.isOneOf(tok::r_paren, tok::comma);
545 ArgExprs.push_back(ParseIdentifierLoc());
549 if (!ArgExprs.empty() ? Tok.is(tok::comma) : Tok.isNot(tok::r_paren)) {
551 if (!ArgExprs.empty())
554 if (AttributeIsTypeArgAttr) {
562 TheParsedType =
T.get();
563 }
else if (AttributeHasVariadicIdentifierArg ||
573 if (ChangeKWThisToIdent && Tok.is(tok::kw_this))
574 Tok.setKind(tok::identifier);
577 if (Tok.is(tok::identifier)) {
578 ArgExprs.push_back(ParseIdentifierLoc());
594 ArgExprs.push_back(ArgExpr.
get());
610 ExprVector ParsedExprs;
611 ParsedAttributeArgumentsProperties ArgProperties =
614 if (ParseAttributeArgumentList(*AttrName, ParsedExprs, ArgProperties,
621 for (
size_t I = 0; I < ParsedExprs.size(); ++I) {
626 Diag(Tok.getLocation(),
627 diag::err_attribute_argument_parm_pack_not_supported)
634 llvm::append_range(ArgExprs, ParsedExprs);
638 SourceLocation RParen = Tok.getLocation();
639 if (!ExpectAndConsume(tok::r_paren)) {
640 SourceLocation AttrLoc = ScopeLoc.
isValid() ? ScopeLoc : AttrNameLoc;
642 if (AttributeIsTypeArgAttr && !TheParsedType.
get().
isNull()) {
644 AttributeScopeInfo(ScopeName, ScopeLoc),
645 TheParsedType, Form);
647 Attrs.
addNew(AttrName, SourceRange(AttrLoc, RParen),
648 AttributeScopeInfo(ScopeName, ScopeLoc), ArgExprs.data(),
649 ArgExprs.size(), Form);
656 return static_cast<unsigned>(ArgExprs.size() + !TheParsedType.
get().
isNull());
659void Parser::ParseGNUAttributeArgs(
664 assert(Tok.is(tok::l_paren) &&
"Attribute arg list not starting with '('");
669 if (AttrKind == ParsedAttr::AT_Availability) {
670 ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
673 }
else if (AttrKind == ParsedAttr::AT_ExternalSourceSymbol) {
674 ParseExternalSourceSymbolAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
675 ScopeName, ScopeLoc, Form);
677 }
else if (AttrKind == ParsedAttr::AT_ObjCBridgeRelated) {
678 ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
679 ScopeName, ScopeLoc, Form);
681 }
else if (AttrKind == ParsedAttr::AT_SwiftNewType) {
682 ParseSwiftNewTypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
685 }
else if (AttrKind == ParsedAttr::AT_TypeTagForDatatype) {
686 ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
687 ScopeName, ScopeLoc, Form);
690 ParseAttributeWithTypeArg(*AttrName, AttrNameLoc, Attrs, ScopeName,
693 }
else if (AttrKind == ParsedAttr::AT_CountedBy ||
694 AttrKind == ParsedAttr::AT_CountedByOrNull ||
695 AttrKind == ParsedAttr::AT_SizedBy ||
696 AttrKind == ParsedAttr::AT_SizedByOrNull) {
697 ParseBoundsAttribute(*AttrName, AttrNameLoc, Attrs, ScopeName, ScopeLoc,
700 }
else if (AttrKind == ParsedAttr::AT_CXXAssume) {
701 ParseCXXAssumeAttributeArg(Attrs, AttrName, AttrNameLoc, ScopeName,
702 ScopeLoc, EndLoc, Form);
708 std::optional<ParseScope> PrototypeScope;
713 const DeclaratorChunk::FunctionTypeInfo *FTI =
nullptr;
725 PrototypeScope.emplace(
729 for (
unsigned i = 0; i < FTI->
NumParams; ++i)
730 Actions.ActOnReenterCXXMethodParameter(
735 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
739unsigned Parser::ParseClangAttributeArgs(
743 assert(Tok.is(tok::l_paren) &&
"Attribute arg list not starting with '('");
750 return ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
751 ScopeName, ScopeLoc, Form);
752 case ParsedAttr::AT_ExternalSourceSymbol:
753 ParseExternalSourceSymbolAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
754 ScopeName, ScopeLoc, Form);
756 case ParsedAttr::AT_Availability:
757 ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
760 case ParsedAttr::AT_ObjCBridgeRelated:
761 ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
762 ScopeName, ScopeLoc, Form);
764 case ParsedAttr::AT_SwiftNewType:
765 ParseSwiftNewTypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
768 case ParsedAttr::AT_TypeTagForDatatype:
769 ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
770 ScopeName, ScopeLoc, Form);
773 case ParsedAttr::AT_CXXAssume:
774 ParseCXXAssumeAttributeArg(Attrs, AttrName, AttrNameLoc, ScopeName,
775 ScopeLoc, EndLoc, Form);
778 return !Attrs.
empty() ? Attrs.
begin()->getNumArgs() : 0;
784 unsigned ExistingAttrs = Attrs.
size();
796 SourceLocation OpenParenLoc = Tok.getLocation();
798 if (
AttrName->getName() ==
"property") {
804 T.expectAndConsume(diag::err_expected_lparen_after,
805 AttrName->getNameStart(), tok::r_paren);
812 IdentifierInfo *AccessorNames[] = {
nullptr,
nullptr};
813 bool HasInvalidAccessor =
false;
818 if (!Tok.is(tok::identifier)) {
820 if (Tok.is(tok::r_paren) && !HasInvalidAccessor &&
821 AccessorNames[AK_Put] ==
nullptr &&
822 AccessorNames[AK_Get] ==
nullptr) {
823 Diag(AttrNameLoc, diag::err_ms_property_no_getter_or_putter);
827 Diag(Tok.getLocation(), diag::err_ms_property_unknown_accessor);
832 SourceLocation KindLoc = Tok.getLocation();
833 StringRef KindStr = Tok.getIdentifierInfo()->getName();
834 if (KindStr ==
"get") {
836 }
else if (KindStr ==
"put") {
840 }
else if (KindStr ==
"set") {
841 Diag(KindLoc, diag::err_ms_property_has_set_accessor)
848 Diag(KindLoc, diag::err_ms_property_missing_accessor_kind);
850 HasInvalidAccessor =
true;
851 goto next_property_accessor;
855 Diag(KindLoc, diag::err_ms_property_unknown_accessor);
856 HasInvalidAccessor =
true;
869 Diag(Tok.getLocation(), diag::err_ms_property_expected_equal)
875 if (!Tok.is(tok::identifier)) {
876 Diag(Tok.getLocation(), diag::err_ms_property_expected_accessor_name);
880 if (Kind == AK_Invalid) {
882 }
else if (AccessorNames[Kind] !=
nullptr) {
884 Diag(KindLoc, diag::err_ms_property_duplicate_accessor) << KindStr;
886 AccessorNames[
Kind] = Tok.getIdentifierInfo();
890 next_property_accessor:
896 if (Tok.is(tok::r_paren))
899 Diag(Tok.getLocation(), diag::err_ms_property_expected_comma_or_rparen);
904 if (!HasInvalidAccessor)
906 AccessorNames[AK_Get], AccessorNames[AK_Put],
907 ParsedAttr::Form::Declspec());
909 return !HasInvalidAccessor;
913 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs,
nullptr,
nullptr,
914 SourceLocation(), ParsedAttr::Form::Declspec());
919 Diag(OpenParenLoc, diag::err_attribute_requires_arguments) <<
AttrName;
926 assert(
getLangOpts().DeclSpecKeyword &&
"__declspec keyword is not enabled");
927 assert(Tok.is(tok::kw___declspec) &&
"Not a declspec!");
929 SourceLocation StartLoc = Tok.getLocation();
930 SourceLocation EndLoc = StartLoc;
932 while (Tok.is(tok::kw___declspec)) {
935 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"__declspec",
941 while (Tok.isNot(tok::r_paren)) {
946 if (Tok.is(tok::code_completion)) {
948 Actions.CodeCompletion().CodeCompleteAttribute(
955 bool IsString = Tok.getKind() == tok::string_literal;
956 if (!IsString && Tok.getKind() != tok::identifier &&
957 Tok.getKind() != tok::kw_restrict) {
958 Diag(Tok, diag::err_ms_declspec_type);
964 SourceLocation AttrNameLoc;
966 SmallString<8> StrBuffer;
967 bool Invalid =
false;
968 StringRef Str = PP.getSpelling(Tok, StrBuffer, &Invalid);
973 AttrName = PP.getIdentifierInfo(Str);
974 AttrNameLoc = ConsumeStringToken();
980 bool AttrHandled =
false;
983 if (Tok.is(tok::l_paren))
984 AttrHandled = ParseMicrosoftDeclSpecArgs(AttrName, AttrNameLoc, Attrs);
985 else if (
AttrName->getName() ==
"property")
987 Diag(Tok.getLocation(), diag::err_expected_lparen_after)
991 Attrs.
addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
nullptr, 0,
992 ParsedAttr::Form::Declspec());
995 EndLoc =
T.getCloseLocation();
998 Attrs.
Range = SourceRange(StartLoc, EndLoc);
1004 auto Kind = Tok.getKind();
1006 case tok::kw___fastcall:
1007 case tok::kw___stdcall:
1008 case tok::kw___thiscall:
1009 case tok::kw___regcall:
1010 case tok::kw___cdecl:
1011 case tok::kw___vectorcall:
1012 case tok::kw___ptr64:
1014 case tok::kw___ptr32:
1015 case tok::kw___sptr:
1016 case tok::kw___uptr: {
1017 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1019 attrs.
addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
nullptr, 0,
1029void Parser::ParseWebAssemblyFuncrefTypeAttribute(
ParsedAttributes &attrs) {
1030 assert(Tok.is(tok::kw___funcref));
1031 SourceLocation StartLoc = Tok.getLocation();
1034 Diag(StartLoc, diag::err_wasm_funcref_not_wasm);
1038 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1040 attrs.
addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
nullptr,
1041 0, tok::kw___funcref);
1044void Parser::DiagnoseAndSkipExtendedMicrosoftTypeAttributes() {
1045 SourceLocation StartLoc = Tok.getLocation();
1046 SourceLocation EndLoc = SkipExtendedMicrosoftTypeAttributes();
1049 SourceRange
Range(StartLoc, EndLoc);
1050 Diag(StartLoc, diag::warn_microsoft_qualifiers_ignored) <<
Range;
1055 SourceLocation EndLoc;
1058 switch (Tok.getKind()) {
1060 case tok::kw_volatile:
1061 case tok::kw___fastcall:
1062 case tok::kw___stdcall:
1063 case tok::kw___thiscall:
1064 case tok::kw___cdecl:
1065 case tok::kw___vectorcall:
1066 case tok::kw___ptr32:
1067 case tok::kw___ptr64:
1069 case tok::kw___unaligned:
1070 case tok::kw___sptr:
1071 case tok::kw___uptr:
1082 while (Tok.is(tok::kw___pascal)) {
1083 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1085 attrs.
addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
nullptr, 0,
1092 while (Tok.is(tok::kw___kernel)) {
1093 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1095 attrs.
addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
nullptr, 0,
1101 while (Tok.is(tok::kw___noinline__)) {
1102 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1104 attrs.
addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
nullptr, 0,
1105 tok::kw___noinline__);
1110 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1111 SourceLocation AttrNameLoc = Tok.getLocation();
1112 Attrs.
addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
nullptr, 0,
1117 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1118 auto Kind = Tok.getKind();
1120 Attrs.
addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
nullptr, 0, Kind);
1126 auto Kind = Tok.getKind();
1128 case tok::kw__Nonnull:
1129 case tok::kw__Nullable:
1130 case tok::kw__Nullable_result:
1131 case tok::kw__Null_unspecified: {
1132 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1135 Diag(AttrNameLoc, diag::ext_nullability)
1137 attrs.
addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
nullptr, 0,
1148 return (Separator ==
'.' || Separator ==
'_');
1151VersionTuple Parser::ParseVersionTuple(
SourceRange &Range) {
1152 Range = SourceRange(Tok.getLocation(), Tok.getEndLoc());
1154 if (!Tok.is(tok::numeric_constant)) {
1155 Diag(Tok, diag::err_expected_version);
1158 return VersionTuple();
1165 SmallString<512> Buffer;
1166 Buffer.resize(Tok.getLength()+1);
1167 const char *ThisTokBegin = &Buffer[0];
1170 bool Invalid =
false;
1171 unsigned ActualLength = PP.getSpelling(Tok, ThisTokBegin, &Invalid);
1173 return VersionTuple();
1176 unsigned AfterMajor = 0;
1178 while (AfterMajor < ActualLength &&
isDigit(ThisTokBegin[AfterMajor])) {
1179 Major = Major * 10 + ThisTokBegin[AfterMajor] -
'0';
1183 if (AfterMajor == 0) {
1184 Diag(Tok, diag::err_expected_version);
1187 return VersionTuple();
1190 if (AfterMajor == ActualLength) {
1195 Diag(Tok, diag::err_zero_version);
1196 return VersionTuple();
1199 return VersionTuple(Major);
1202 const char AfterMajorSeparator = ThisTokBegin[AfterMajor];
1204 || (AfterMajor + 1 == ActualLength)) {
1205 Diag(Tok, diag::err_expected_version);
1208 return VersionTuple();
1212 unsigned AfterMinor = AfterMajor + 1;
1214 while (AfterMinor < ActualLength &&
isDigit(ThisTokBegin[AfterMinor])) {
1215 Minor = Minor * 10 + ThisTokBegin[AfterMinor] -
'0';
1219 if (AfterMinor == ActualLength) {
1223 if (Major == 0 && Minor == 0) {
1224 Diag(Tok, diag::err_zero_version);
1225 return VersionTuple();
1228 return VersionTuple(Major, Minor);
1231 const char AfterMinorSeparator = ThisTokBegin[AfterMinor];
1234 Diag(Tok, diag::err_expected_version);
1237 return VersionTuple();
1241 if (AfterMajorSeparator != AfterMinorSeparator)
1242 Diag(Tok, diag::warn_expected_consistent_version_separator);
1245 unsigned AfterSubminor = AfterMinor + 1;
1246 unsigned Subminor = 0;
1247 while (AfterSubminor < ActualLength &&
isDigit(ThisTokBegin[AfterSubminor])) {
1248 Subminor = Subminor * 10 + ThisTokBegin[AfterSubminor] -
'0';
1252 if (AfterSubminor != ActualLength) {
1253 Diag(Tok, diag::err_expected_version);
1256 return VersionTuple();
1259 return VersionTuple(Major, Minor, Subminor);
1262void Parser::ParseAvailabilityAttribute(
1266 enum { Introduced, Deprecated, Obsoleted,
Unknown };
1267 AvailabilityChange Changes[
Unknown];
1269 IdentifierLoc *EnvironmentLoc =
nullptr;
1273 if (
T.consumeOpen()) {
1274 Diag(Tok, diag::err_expected) << tok::l_paren;
1279 if (Tok.isNot(tok::identifier)) {
1280 Diag(Tok, diag::err_availability_expected_platform);
1284 IdentifierLoc *Platform = ParseIdentifierLoc();
1287 if (Ident->getName().contains(
"xrOS") || Ident->getName().contains(
"xros"))
1288 Diag(Platform->
getLoc(), diag::warn_availability_unknown_platform)
1291 else if (Ident->getName() ==
"macosx")
1295 else if (Ident->getName() ==
"macosx_app_extension")
1299 AvailabilityAttr::canonicalizePlatformName(Ident->getName())));
1303 if (ExpectAndConsume(tok::comma)) {
1310 if (!Ident_introduced) {
1311 Ident_introduced = PP.getIdentifierInfo(
"introduced");
1312 Ident_deprecated = PP.getIdentifierInfo(
"deprecated");
1313 Ident_obsoleted = PP.getIdentifierInfo(
"obsoleted");
1314 Ident_unavailable = PP.getIdentifierInfo(
"unavailable");
1315 Ident_message = PP.getIdentifierInfo(
"message");
1316 Ident_strict = PP.getIdentifierInfo(
"strict");
1317 Ident_replacement = PP.getIdentifierInfo(
"replacement");
1318 Ident_environment = PP.getIdentifierInfo(
"environment");
1323 SourceLocation UnavailableLoc, StrictLoc;
1325 if (Tok.isNot(tok::identifier)) {
1326 Diag(Tok, diag::err_availability_expected_change);
1330 IdentifierInfo *
Keyword = Tok.getIdentifierInfo();
1333 if (
Keyword == Ident_strict) {
1335 Diag(KeywordLoc, diag::err_availability_redundant)
1336 <<
Keyword << SourceRange(StrictLoc);
1338 StrictLoc = KeywordLoc;
1342 if (
Keyword == Ident_unavailable) {
1343 if (UnavailableLoc.
isValid()) {
1344 Diag(KeywordLoc, diag::err_availability_redundant)
1345 <<
Keyword << SourceRange(UnavailableLoc);
1347 UnavailableLoc = KeywordLoc;
1354 if (Changes[Deprecated].KeywordLoc.
isValid()) {
1355 Diag(KeywordLoc, diag::err_availability_redundant)
1357 << SourceRange(Changes[Deprecated].KeywordLoc);
1362 Changes[Deprecated].
Version = VersionTuple(1);
1366 if (
Keyword == Ident_environment) {
1367 if (EnvironmentLoc !=
nullptr) {
1368 Diag(KeywordLoc, diag::err_availability_redundant)
1373 if (Tok.isNot(tok::equal)) {
1374 Diag(Tok, diag::err_expected_after) <<
Keyword << tok::equal;
1380 if (!isTokenStringLiteral()) {
1381 Diag(Tok, diag::err_expected_string_literal)
1386 if (
Keyword == Ident_message) {
1394 if (
Keyword == Ident_environment) {
1395 if (Tok.isNot(tok::identifier)) {
1396 Diag(Tok, diag::err_availability_expected_environment);
1400 EnvironmentLoc = ParseIdentifierLoc();
1406 if ((
Keyword == Ident_introduced ||
Keyword == Ident_deprecated) &&
1407 Tok.is(tok::identifier)) {
1408 IdentifierInfo *NA = Tok.getIdentifierInfo();
1411 if (
Keyword == Ident_introduced)
1412 UnavailableLoc = KeywordLoc;
1417 SourceRange VersionRange;
1418 VersionTuple Version = ParseVersionTuple(VersionRange);
1420 if (Version.empty()) {
1426 if (
Keyword == Ident_introduced)
1428 else if (
Keyword == Ident_deprecated)
1430 else if (
Keyword == Ident_obsoleted)
1436 if (!Changes[Index].KeywordLoc.
isInvalid()) {
1437 Diag(KeywordLoc, diag::err_availability_redundant)
1439 << SourceRange(Changes[Index].KeywordLoc,
1440 Changes[Index].VersionRange.
getEnd());
1444 Changes[Index].
Version = Version;
1447 Diag(KeywordLoc, diag::err_availability_unknown_change)
1454 if (
T.consumeClose())
1458 *endLoc =
T.getCloseLocation();
1462 if (UnavailableLoc.
isValid()) {
1463 bool Complained =
false;
1464 for (
unsigned Index = Introduced; Index !=
Unknown; ++Index) {
1465 if (Changes[Index].KeywordLoc.
isValid()) {
1467 Diag(UnavailableLoc, diag::warn_availability_and_unavailable)
1468 << SourceRange(Changes[Index].KeywordLoc,
1469 Changes[Index].VersionRange.
getEnd());
1474 Changes[Index] = AvailabilityChange();
1480 attrs.
addNew(&Availability,
1481 SourceRange(AvailabilityLoc,
T.getCloseLocation()),
1482 AttributeScopeInfo(ScopeName, ScopeLoc), Platform,
1483 Changes[Introduced], Changes[Deprecated], Changes[Obsoleted],
1484 UnavailableLoc, MessageExpr.
get(), Form, StrictLoc,
1485 ReplacementExpr.
get(), EnvironmentLoc);
1488void Parser::ParseExternalSourceSymbolAttribute(
1494 if (
T.expectAndConsume())
1498 if (!Ident_language) {
1499 Ident_language = PP.getIdentifierInfo(
"language");
1500 Ident_defined_in = PP.getIdentifierInfo(
"defined_in");
1501 Ident_generated_declaration = PP.getIdentifierInfo(
"generated_declaration");
1502 Ident_USR = PP.getIdentifierInfo(
"USR");
1506 bool HasLanguage =
false;
1508 bool HasDefinedIn =
false;
1509 IdentifierLoc *GeneratedDeclaration =
nullptr;
1511 bool HasUSR =
false;
1515 if (Tok.isNot(tok::identifier)) {
1516 Diag(Tok, diag::err_external_source_symbol_expected_keyword);
1521 SourceLocation KeywordLoc = Tok.getLocation();
1522 IdentifierInfo *
Keyword = Tok.getIdentifierInfo();
1523 if (
Keyword == Ident_generated_declaration) {
1524 if (GeneratedDeclaration) {
1525 Diag(Tok, diag::err_external_source_symbol_duplicate_clause) <<
Keyword;
1529 GeneratedDeclaration = ParseIdentifierLoc();
1535 Diag(Tok, diag::err_external_source_symbol_expected_keyword);
1541 if (ExpectAndConsume(tok::equal, diag::err_expected_after,
1547 bool HadLanguage = HasLanguage, HadDefinedIn = HasDefinedIn,
1549 if (
Keyword == Ident_language)
1551 else if (
Keyword == Ident_USR)
1554 HasDefinedIn =
true;
1556 if (!isTokenStringLiteral()) {
1557 Diag(Tok, diag::err_expected_string_literal)
1562 : (
Keyword == Ident_defined_in ? 1 : 2));
1566 if (
Keyword == Ident_language) {
1568 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
1574 }
else if (
Keyword == Ident_USR) {
1576 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
1583 assert(
Keyword == Ident_defined_in &&
"Invalid clause keyword!");
1585 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
1595 if (
T.consumeClose())
1598 *EndLoc =
T.getCloseLocation();
1602 Attrs.
addNew(&ExternalSourceSymbol, SourceRange(Loc,
T.getCloseLocation()),
1603 AttributeScopeInfo(ScopeName, ScopeLoc), Args, std::size(Args),
1607void Parser::ParseObjCBridgeRelatedAttribute(
1613 if (
T.consumeOpen()) {
1614 Diag(Tok, diag::err_expected) << tok::l_paren;
1619 if (Tok.isNot(tok::identifier)) {
1620 Diag(Tok, diag::err_objcbridge_related_expected_related_class);
1624 IdentifierLoc *RelatedClass = ParseIdentifierLoc();
1625 if (ExpectAndConsume(tok::comma)) {
1634 if (Tok.is(tok::identifier)) {
1637 Diag(Tok, diag::err_objcbridge_related_selector_name);
1643 if (Tok.is(tok::colon))
1644 Diag(Tok, diag::err_objcbridge_related_selector_name);
1646 Diag(Tok, diag::err_expected) << tok::comma;
1654 if (Tok.is(tok::identifier))
1656 else if (Tok.isNot(tok::r_paren)) {
1657 Diag(Tok, diag::err_expected) << tok::r_paren;
1663 if (
T.consumeClose())
1667 *EndLoc =
T.getCloseLocation();
1670 Attrs.
addNew(&ObjCBridgeRelated,
1671 SourceRange(ObjCBridgeRelatedLoc,
T.getCloseLocation()),
1672 AttributeScopeInfo(ScopeName, ScopeLoc), RelatedClass,
1673 ClassMethod, InstanceMethod, Form);
1676void Parser::ParseSwiftNewTypeAttribute(
1683 if (
T.consumeOpen()) {
1684 Diag(Tok, diag::err_expected) << tok::l_paren;
1688 if (Tok.is(tok::r_paren)) {
1689 Diag(Tok.getLocation(), diag::err_argument_required_after_attribute);
1693 if (Tok.isNot(tok::kw_struct) && Tok.isNot(tok::kw_enum)) {
1694 Diag(Tok, diag::warn_attribute_type_not_supported)
1695 << &
AttrName << Tok.getIdentifierInfo();
1696 if (!isTokenSpecial())
1702 auto *SwiftType =
new (Actions.Context)
1703 IdentifierLoc(Tok.getLocation(), Tok.getIdentifierInfo());
1707 if (
T.consumeClose())
1710 *EndLoc =
T.getCloseLocation();
1713 Attrs.
addNew(&AttrName, SourceRange(AttrNameLoc,
T.getCloseLocation()),
1714 AttributeScopeInfo(ScopeName, ScopeLoc), Args, std::size(Args),
1718void Parser::ParseTypeTagForDatatypeAttribute(
1722 assert(Tok.is(tok::l_paren) &&
"Attribute arg list not starting with '('");
1727 if (Tok.isNot(tok::identifier)) {
1728 Diag(Tok, diag::err_expected) << tok::identifier;
1732 IdentifierLoc *ArgumentKind = ParseIdentifierLoc();
1734 if (ExpectAndConsume(tok::comma)) {
1739 SourceRange MatchingCTypeRange;
1746 bool LayoutCompatible =
false;
1747 bool MustBeNull =
false;
1749 if (Tok.isNot(tok::identifier)) {
1750 Diag(Tok, diag::err_expected) << tok::identifier;
1754 IdentifierInfo *Flag = Tok.getIdentifierInfo();
1755 if (Flag->
isStr(
"layout_compatible"))
1756 LayoutCompatible =
true;
1757 else if (Flag->
isStr(
"must_be_null"))
1760 Diag(Tok, diag::err_type_safety_unknown_flag) << Flag;
1767 if (!
T.consumeClose()) {
1769 &AttrName, AttrNameLoc, AttributeScopeInfo(ScopeName, ScopeLoc),
1770 ArgumentKind, MatchingCType.
get(), LayoutCompatible, MustBeNull, Form);
1774 *EndLoc =
T.getCloseLocation();
1777bool Parser::DiagnoseProhibitedCXX11Attribute() {
1778 assert(Tok.is(tok::l_square) &&
NextToken().
is(tok::l_square));
1780 switch (isCXX11AttributeSpecifier(
true)) {
1786 Diag(Tok.getLocation(), diag::err_l_square_l_square_not_attribute);
1791 SourceLocation BeginLoc = ConsumeBracket();
1794 assert(Tok.is(tok::r_square) &&
"isCXX11AttributeSpecifier lied");
1795 SourceLocation EndLoc = ConsumeBracket();
1796 Diag(BeginLoc, diag::err_attributes_not_allowed)
1797 << SourceRange(BeginLoc, EndLoc);
1800 llvm_unreachable(
"All cases handled above.");
1805 assert((Tok.is(tok::l_square) &&
NextToken().
is(tok::l_square)) ||
1806 Tok.is(tok::kw_alignas) || Tok.isRegularKeywordAttribute());
1810 Tok.isRegularKeywordAttribute() ? Tok.getIdentifierInfo() :
nullptr;
1811 SourceLocation Loc = Tok.getLocation();
1812 ParseCXX11Attributes(Attrs);
1813 CharSourceRange AttrRange(SourceRange(Loc, Attrs.
Range.
getEnd()),
true);
1816 :
Diag(Loc, diag::err_attributes_not_allowed))
1821void Parser::DiagnoseProhibitedAttributes(
1824 if (CorrectLocation.
isValid()) {
1825 CharSourceRange AttrRange(Attrs.
Range,
true);
1826 (FirstAttr && FirstAttr->isRegularKeywordAttribute()
1827 ?
Diag(CorrectLocation, diag::err_keyword_misplaced) << FirstAttr
1828 :
Diag(CorrectLocation, diag::err_attributes_misplaced))
1833 (FirstAttr && FirstAttr->isRegularKeywordAttribute()
1834 ?
Diag(
Range.getBegin(), diag::err_keyword_not_allowed) << FirstAttr
1835 :
Diag(
Range.getBegin(), diag::err_attributes_not_allowed))
1841 unsigned AttrDiagID,
1842 unsigned KeywordDiagID,
1843 bool DiagnoseEmptyAttrs,
1844 bool WarnOnUnknownAttrs) {
1850 auto &SM = PP.getSourceManager();
1854 if (FirstLSquare.
is(tok::l_square)) {
1855 std::optional<Token> SecondLSquare =
1858 if (SecondLSquare && SecondLSquare->is(tok::l_square)) {
1868 for (
const ParsedAttr &AL : Attrs) {
1869 if (AL.isRegularKeywordAttribute()) {
1870 Diag(AL.getLoc(), KeywordDiagID) << AL;
1874 if (!AL.isStandardAttributeSyntax())
1877 if (WarnOnUnknownAttrs) {
1878 Actions.DiagnoseUnknownAttribute(AL);
1882 Diag(AL.getLoc(), AttrDiagID) << AL;
1889 for (
const ParsedAttr &PA : Attrs) {
1890 if (PA.isStandardAttributeSyntax() || PA.isRegularKeywordAttribute())
1891 Diag(PA.getLoc(), diag::ext_cxx11_attr_placement)
1892 << PA << PA.isRegularKeywordAttribute() << PA.getRange();
1901 llvm::SmallVector<ParsedAttr *, 1> ToBeMoved;
1904 if ((AL.getKind() == ParsedAttr::AT_Aligned &&
1905 AL.isDeclspecAttribute()) ||
1906 AL.isMicrosoftAttribute())
1907 ToBeMoved.push_back(&AL);
1910 for (ParsedAttr *AL : ToBeMoved) {
1924 ObjCDeclContextSwitch ObjCDC(*
this);
1926 Decl *SingleDecl =
nullptr;
1927 switch (Tok.getKind()) {
1928 case tok::kw_template:
1929 case tok::kw_export:
1930 ProhibitAttributes(DeclAttrs);
1931 ProhibitAttributes(DeclSpecAttrs);
1932 return ParseDeclarationStartingWithTemplate(Context, DeclEnd, DeclAttrs);
1933 case tok::kw_inline:
1936 ProhibitAttributes(DeclAttrs);
1937 ProhibitAttributes(DeclSpecAttrs);
1939 return ParseNamespace(Context, DeclEnd, InlineLoc);
1941 return ParseSimpleDeclaration(Context, DeclEnd, DeclAttrs, DeclSpecAttrs,
1942 true,
nullptr, DeclSpecStart);
1944 case tok::kw_cbuffer:
1945 case tok::kw_tbuffer:
1946 SingleDecl = ParseHLSLBuffer(DeclEnd, DeclAttrs);
1948 case tok::kw_namespace:
1949 ProhibitAttributes(DeclAttrs);
1950 ProhibitAttributes(DeclSpecAttrs);
1951 return ParseNamespace(Context, DeclEnd);
1952 case tok::kw_using: {
1954 return ParseUsingDirectiveOrDeclaration(Context, ParsedTemplateInfo(),
1955 DeclEnd, DeclAttrs);
1957 case tok::kw_static_assert:
1958 case tok::kw__Static_assert:
1959 ProhibitAttributes(DeclAttrs);
1960 ProhibitAttributes(DeclSpecAttrs);
1961 SingleDecl = ParseStaticAssertDeclaration(DeclEnd);
1964 return ParseSimpleDeclaration(Context, DeclEnd, DeclAttrs, DeclSpecAttrs,
1965 true,
nullptr, DeclSpecStart);
1970 return Actions.ConvertDeclToDeclGroup(SingleDecl);
1976 bool RequireSemi, ForRangeInit *FRI,
SourceLocation *DeclSpecStart) {
1978 ParsedAttributesView OriginalDeclSpecAttrs;
1979 OriginalDeclSpecAttrs.
prepend(DeclSpecAttrs.
begin(), DeclSpecAttrs.
end());
1980 OriginalDeclSpecAttrs.
Range = DeclSpecAttrs.
Range;
1983 ParsingDeclSpec DS(*
this);
1986 ParsedTemplateInfo TemplateInfo;
1987 DeclSpecContext DSContext = getDeclSpecContextFromDeclaratorContext(Context);
1988 ParseDeclarationSpecifiers(DS, TemplateInfo,
AS_none, DSContext);
1993 DiagnoseMissingSemiAfterTagDefinition(DS,
AS_none, DSContext))
1998 if (Tok.is(tok::semi)) {
1999 ProhibitAttributes(DeclAttrs);
2000 DeclEnd = Tok.getLocation();
2002 RecordDecl *AnonRecord =
nullptr;
2003 Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(
2005 Actions.ActOnDefinedDeclarationSpecifier(TheDecl);
2006 DS.complete(TheDecl);
2008 Decl* decls[] = {AnonRecord, TheDecl};
2009 return Actions.BuildDeclaratorGroup(decls);
2011 return Actions.ConvertDeclToDeclGroup(TheDecl);
2015 Actions.ActOnDefinedDeclarationSpecifier(DS.
getRepAsDecl());
2020 return ParseDeclGroup(DS, Context, DeclAttrs, TemplateInfo, &DeclEnd, FRI);
2024 switch (Tok.getKind()) {
2025 case tok::annot_cxxscope:
2026 case tok::annot_template_id:
2028 case tok::code_completion:
2029 case tok::coloncolon:
2031 case tok::kw___attribute:
2032 case tok::kw_operator:
2048 case tok::identifier:
2050 case tok::code_completion:
2051 case tok::coloncolon:
2054 case tok::equalequal:
2055 case tok::kw_alignas:
2057 case tok::kw___attribute:
2075 case tok::identifier:
2079 return Tok.isRegularKeywordAttribute();
2083 return Tok.isRegularKeywordAttribute();
2089 switch (Tok.getKind()) {
2095 if (Tok.isOneOf(tok::comma, tok::l_brace, tok::kw_try)) {
2119 case tok::kw_inline:
2123 if (Tok.isAtStartOfLine() &&
NextToken().
is(tok::kw_namespace) &&
2124 (!ParsingInObjCContainer || CurParsedObjCImpl))
2128 case tok::kw_extern:
2131 case tok::kw_namespace:
2135 if (Tok.isAtStartOfLine() &&
2136 (!ParsingInObjCContainer || CurParsedObjCImpl))
2142 if (
NextToken().isObjCAtKeyword(tok::objc_end) &&
2143 ParsingInObjCContainer)
2150 if (Tok.isAtStartOfLine() && ParsingInObjCContainer)
2155 case tok::annot_module_begin:
2156 case tok::annot_module_end:
2157 case tok::annot_module_include:
2171 ParsedTemplateInfo &TemplateInfo,
2173 ForRangeInit *FRI) {
2179 LocalAttrs.takeAllPrependingFrom(Attrs);
2181 if (TemplateInfo.TemplateParams)
2184 bool IsTemplateSpecOrInst =
2191 if (IsTemplateSpecOrInst)
2201 while (MaybeParseHLSLAnnotations(D))
2204 if (
Tok.is(tok::kw_requires)) {
2205 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
2209 ++CurTemplateDepthTracker;
2210 ParseTrailingRequiresClauseWithScope(D);
2216 LateParsedAttrList LateParsedAttrs(
true);
2218 MaybeParseGNUAttributes(D, &LateParsedAttrs);
2223 if (Tok.is(tok::kw__Noreturn)) {
2225 const char *PrevSpec;
2231 MaybeParseGNUAttributes(D, &LateParsedAttrs);
2232 Fixit &= Tok.isOneOf(tok::semi, tok::l_brace, tok::kw_try);
2234 Diag(Loc, diag::err_c11_noreturn_misplaced)
2236 << (Fixit ? FixItHint::CreateInsertion(D.getBeginLoc(),
"_Noreturn ")
2241 if (Tok.is(tok::equal) &&
NextToken().
is(tok::code_completion)) {
2243 Actions.CodeCompletion().CodeCompleteAfterFunctionEquals(D);
2252 while (
auto Specifier = isCXX11VirtSpecifier()) {
2253 Diag(Tok, diag::err_virt_specifier_outside_class)
2261 if (!isDeclarationAfterDeclarator()) {
2267 if (isStartOfFunctionDefinition(D)) {
2277 diag::err_function_declared_typedef)
2281 Decl *TheDecl =
nullptr;
2287 Diag(Tok, diag::err_template_defn_explicit_instantiation) << 0;
2288 TheDecl = ParseFunctionDefinition(D, ParsedTemplateInfo(),
2291 SourceLocation LAngleLoc =
2292 PP.getLocForEndOfToken(TemplateInfo.TemplateLoc);
2294 diag::err_explicit_instantiation_with_definition)
2295 << SourceRange(TemplateInfo.TemplateLoc)
2300 FakedParamLists.push_back(Actions.ActOnTemplateParameterList(
2301 0, SourceLocation(), TemplateInfo.TemplateLoc, LAngleLoc, {},
2302 LAngleLoc,
nullptr));
2304 TheDecl = ParseFunctionDefinition(
2306 ParsedTemplateInfo(&FakedParamLists,
2313 ParseFunctionDefinition(D, TemplateInfo, &LateParsedAttrs);
2316 return Actions.ConvertDeclToDeclGroup(TheDecl);
2320 Tok.is(tok::kw_namespace)) {
2330 Diag(Tok, diag::err_expected_fn_body);
2335 if (Tok.is(tok::l_brace)) {
2336 Diag(Tok, diag::err_function_definition_not_allowed);
2344 if (ParseAsmAttributesAfterDeclarator(D))
2353 if (FRI && (Tok.is(tok::colon) || isTokIdentifier_in())) {
2366 bool EnterContext = FRI->ExpansionStmt &&
2367 Actions.CurContext == FRI->ExpansionStmt->getParent();
2369 Actions.PushDeclContext(
nullptr, FRI->ExpansionStmt);
2370 llvm::scope_exit RestoreDeclContext{[&] {
2372 Actions.PopDeclContext();
2375 bool IsForRangeLoopOrExpansionStmt =
false;
2377 IsForRangeLoopOrExpansionStmt =
true;
2379 Actions.OpenMP().startOpenMPCXXRangeFor();
2381 ParseForRangeInitializerAfterColon(*FRI, &DS);
2385 if (IsForRangeLoopOrExpansionStmt) {
2386 Actions.ActOnCXXForRangeDecl(ThisDecl, FRI->ExpansionStmt);
2389 if (
auto *VD = dyn_cast_or_null<VarDecl>(ThisDecl))
2390 VD->setObjCForDecl(
true);
2392 Actions.FinalizeDeclaration(ThisDecl);
2393 D.complete(ThisDecl);
2394 return Actions.FinalizeDeclaratorGroup(
getCurScope(), DS, ThisDecl);
2397 SmallVector<Decl *, 8> DeclsInGroup;
2399 ParseDeclarationAfterDeclaratorAndAttributes(D, TemplateInfo, FRI);
2400 if (LateParsedAttrs.size() > 0)
2401 ParseLexedAttributeList(LateParsedAttrs, FirstDecl,
true,
false);
2402 D.complete(FirstDecl);
2404 DeclsInGroup.push_back(FirstDecl);
2410 SourceLocation CommaLoc;
2412 if (Tok.isAtStartOfLine() && ExpectSemi && !MightBeDeclarator(Context)) {
2416 Diag(CommaLoc, diag::err_expected_semi_declaration)
2428 Diag(CommaLoc, diag::err_multiple_template_declarators)
2429 << TemplateInfo.Kind;
2443 MaybeParseGNUAttributes(D);
2447 DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2452 MaybeParseHLSLAnnotations(D);
2459 if (Tok.is(tok::kw_requires))
2460 ParseTrailingRequiresClauseWithScope(D);
2461 Decl *ThisDecl = ParseDeclarationAfterDeclarator(D, TemplateInfo);
2462 D.complete(ThisDecl);
2464 DeclsInGroup.push_back(ThisDecl);
2469 *DeclEnd = Tok.getLocation();
2471 if (ExpectSemi && ExpectAndConsumeSemi(
2473 ? diag::err_invalid_token_after_toplevel_declarator
2474 : diag::err_expected_semi_declaration)) {
2482 return Actions.FinalizeDeclaratorGroup(
getCurScope(), DS, DeclsInGroup);
2485bool Parser::ParseAsmAttributesAfterDeclarator(
Declarator &D) {
2487 if (Tok.is(tok::kw_asm)) {
2489 ExprResult AsmLabel(ParseSimpleAsm(
true, &Loc));
2490 if (AsmLabel.isInvalid()) {
2499 MaybeParseGNUAttributes(D);
2503Decl *Parser::ParseDeclarationAfterDeclarator(
2504 Declarator &D,
const ParsedTemplateInfo &TemplateInfo) {
2505 if (ParseAsmAttributesAfterDeclarator(D))
2508 return ParseDeclarationAfterDeclaratorAndAttributes(D, TemplateInfo);
2511Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
2512 Declarator &D,
const ParsedTemplateInfo &TemplateInfo, ForRangeInit *FRI) {
2514 struct InitializerScopeRAII {
2520 InitializerScopeRAII(Parser &P, Declarator &D, Decl *ThisDecl)
2521 : P(P), D(D), ThisDecl(ThisDecl), Entered(
false) {
2524 if (D.getCXXScopeSpec().isSet()) {
2526 S = P.getCurScope();
2529 P.Actions.ActOnCXXEnterDeclInitializer(S, ThisDecl);
2534 ~InitializerScopeRAII() {
2550 InitKind TheInitKind;
2552 if (isTokenEqualOrEqualTypo())
2553 TheInitKind = InitKind::Equal;
2555 TheInitKind = InitKind::CXXDirect;
2558 TheInitKind = InitKind::CXXBraced;
2560 TheInitKind = InitKind::Uninitialized;
2561 if (TheInitKind != InitKind::Uninitialized)
2565 Decl *ThisDecl =
nullptr;
2566 Decl *OuterDecl =
nullptr;
2567 switch (TemplateInfo.Kind) {
2569 ThisDecl = Actions.ActOnDeclarator(getCurScope(), D);
2574 ThisDecl = Actions.ActOnTemplateDeclarator(getCurScope(),
2575 *TemplateInfo.TemplateParams,
2577 if (
VarTemplateDecl *VT = dyn_cast_or_null<VarTemplateDecl>(ThisDecl)) {
2580 ThisDecl = VT->getTemplatedDecl();
2586 if (
Tok.
is(tok::semi)) {
2587 DeclResult ThisRes = Actions.ActOnExplicitInstantiation(
2588 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc, D);
2590 SkipUntil(tok::semi, StopBeforeMatch);
2593 ThisDecl = ThisRes.
get();
2601 Diag(
Tok, diag::err_template_defn_explicit_instantiation)
2603 ThisDecl = Actions.ActOnDeclarator(getCurScope(), D);
2606 PP.getLocForEndOfToken(TemplateInfo.TemplateLoc);
2608 diag::err_explicit_instantiation_with_definition)
2613 TemplateParameterLists FakedParamLists;
2614 FakedParamLists.push_back(Actions.ActOnTemplateParameterList(
2616 LAngleLoc,
nullptr));
2619 Actions.ActOnTemplateDeclarator(getCurScope(), FakedParamLists, D);
2628 switch (TheInitKind) {
2630 case InitKind::Equal: {
2633 if (
Tok.
is(tok::kw_delete)) {
2635 Diag(ConsumeToken(), diag::err_default_delete_in_multiple_declaration)
2638 Diag(ConsumeToken(), diag::err_deleted_non_function);
2639 SkipDeletedFunctionBody();
2640 }
else if (
Tok.
is(tok::kw_default)) {
2642 Diag(ConsumeToken(), diag::err_default_delete_in_multiple_declaration)
2645 Diag(ConsumeToken(), diag::err_default_special_members)
2646 << getLangOpts().CPlusPlus20;
2648 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2650 if (
Tok.
is(tok::code_completion)) {
2652 Actions.CodeCompletion().CodeCompleteInitializer(getCurScope(),
2654 Actions.FinalizeDeclaration(ThisDecl);
2664 Diag(EqualLoc, diag::err_single_decl_assign_in_for_range)
2668 FRI->ColonLoc = EqualLoc;
2670 FRI->RangeExpr =
Init;
2673 if (
Init.isInvalid()) {
2675 StopTokens.push_back(tok::comma);
2678 StopTokens.push_back(tok::r_paren);
2679 SkipUntil(StopTokens, StopAtSemi | StopBeforeMatch);
2680 Actions.ActOnInitializerError(ThisDecl);
2682 Actions.AddInitializerToDecl(ThisDecl,
Init.get(),
2687 case InitKind::CXXDirect: {
2694 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2696 auto ThisVarDecl = dyn_cast_or_null<VarDecl>(ThisDecl);
2697 auto RunSignatureHelp = [&]() {
2699 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
2700 ThisVarDecl->getType()->getCanonicalTypeInternal(),
2703 CalledSignatureHelp =
true;
2704 return PreferredType;
2706 auto SetPreferredType = [&] {
2707 PreferredType.enterFunctionArgument(
Tok.
getLocation(), RunSignatureHelp);
2710 llvm::function_ref<void()> ExpressionStarts;
2716 ExpressionStarts = SetPreferredType;
2719 bool SawError = ParseExpressionList(Exprs, ExpressionStarts);
2722 if (ThisVarDecl && PP.isCodeCompletionReached() && !CalledSignatureHelp) {
2723 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
2724 ThisVarDecl->getType()->getCanonicalTypeInternal(),
2727 CalledSignatureHelp =
true;
2729 Actions.ActOnInitializerError(ThisDecl);
2730 SkipUntil(tok::r_paren, StopAtSemi);
2736 T.getCloseLocation(),
2738 Actions.AddInitializerToDecl(ThisDecl,
Initializer.get(),
2743 case InitKind::CXXBraced: {
2745 Diag(
Tok, diag::compat_cxx11_generalized_initializer_lists);
2747 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2752 if (
Init.isInvalid()) {
2753 Actions.ActOnInitializerError(ThisDecl);
2755 Actions.AddInitializerToDecl(ThisDecl,
Init.get(),
true);
2758 case InitKind::Uninitialized: {
2759 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2760 Actions.ActOnUninitializedDecl(ThisDecl);
2765 Actions.FinalizeDeclaration(ThisDecl);
2766 return OuterDecl ? OuterDecl : ThisDecl;
2769void Parser::ParseSpecifierQualifierList(
2772 ParsedTemplateInfo TemplateInfo;
2774 assert((!LateAttrs ||
2775 llvm::none_of(*LateAttrs, llvm::IsaPred<LateParsedTypeAttribute>)) &&
2776 "caller's late-attribute list must not hold type attributes yet");
2781 ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC, LateAttrs,
2782 AllowImplicitTypename);
2787 Diag(Tok, diag::err_expected_type);
2790 Diag(Tok, diag::err_typename_requires_specqual);
2801 diag::err_typename_invalid_storageclass);
2845 return T.isOneOf(tok::l_square, tok::l_paren, tok::r_paren, tok::semi,
2846 tok::comma, tok::equal, tok::kw_asm, tok::l_brace,
2851 ParsedTemplateInfo &TemplateInfo,
2854 assert(Tok.is(tok::identifier) &&
"should have identifier");
2856 SourceLocation Loc = Tok.getLocation();
2876 if (!isTypeSpecifier(DSC) &&
getLangOpts().isImplicitIntAllowed() &&
2894 AnnotateScopeToken(*SS,
false);
2903 if (
ParsedType T = Actions.ActOnMSVCUnknownTypeName(
2904 *Tok.getIdentifierInfo(), Tok.getLocation(),
2905 DSC == DeclSpecContext::DSC_template_type_arg)) {
2906 const char *PrevSpec;
2909 Actions.getASTContext().getPrintingPolicy());
2922 if (SS ==
nullptr) {
2923 const char *TagName =
nullptr, *FixitTagName =
nullptr;
2926 switch (Actions.isTagName(*Tok.getIdentifierInfo(),
getCurScope())) {
2929 TagName=
"enum" ; FixitTagName =
"enum " ; TagKind=tok::kw_enum ;
break;
2931 TagName=
"union" ; FixitTagName =
"union " ;TagKind=tok::kw_union ;
break;
2933 TagName=
"struct"; FixitTagName =
"struct ";TagKind=tok::kw_struct;
break;
2935 TagName=
"__interface"; FixitTagName =
"__interface ";
2936 TagKind=tok::kw___interface;
break;
2938 TagName=
"class" ; FixitTagName =
"class " ;TagKind=tok::kw_class ;
break;
2942 IdentifierInfo *TokenName = Tok.getIdentifierInfo();
2943 LookupResult
R(Actions, TokenName, SourceLocation(),
2946 Diag(Loc, diag::err_use_of_tag_name_without_tag)
2947 << TokenName << TagName <<
getLangOpts().CPlusPlus
2953 Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
2954 << TokenName << TagName;
2958 if (TagKind == tok::kw_enum)
2959 ParseEnumSpecifier(Loc, DS, TemplateInfo, AS,
2960 DeclSpecContext::DSC_normal);
2962 ParseClassSpecifier(TagKind, Loc, DS, TemplateInfo, AS,
2964 DeclSpecContext::DSC_normal, Attrs);
2971 if (!isTypeSpecifier(DSC) && (!SS || DSC == DeclSpecContext::DSC_top_level ||
2972 DSC == DeclSpecContext::DSC_class)) {
2976 case tok::l_paren: {
2983 TentativeParsingAction PA(*
this);
2985 TPResult TPR = TryParseDeclarator(
false);
2988 if (TPR != TPResult::False) {
2996 if (DSC == DeclSpecContext::DSC_class ||
2997 (DSC == DeclSpecContext::DSC_top_level && SS)) {
2998 IdentifierInfo *II = Tok.getIdentifierInfo();
2999 if (Actions.isCurrentClassNameTypo(II, SS)) {
3000 Diag(Loc, diag::err_constructor_bad_name)
3001 << Tok.getIdentifierInfo() << II
3003 Tok.setIdentifierInfo(II);
3021 AnnotateScopeToken(*SS,
false);
3035 IdentifierInfo *II = Tok.getIdentifierInfo();
3037 Actions.DiagnoseUnknownTypeName(II, Loc,
getCurScope(), SS,
T,
3043 const char *PrevSpec;
3046 Actions.getASTContext().getPrintingPolicy());
3051 }
else if (II != Tok.getIdentifierInfo()) {
3064 if (IsTemplateName) {
3065 SourceLocation LAngle, RAngle;
3066 TemplateArgList Args;
3067 ParseTemplateIdAfterTemplateName(
true, LAngle, Args, RAngle);
3076Parser::DeclSpecContext
3080 return DeclSpecContext::DSC_class;
3082 return DeclSpecContext::DSC_top_level;
3084 return DeclSpecContext::DSC_template_param;
3086 return DeclSpecContext::DSC_template_arg;
3088 return DeclSpecContext::DSC_template_type_arg;
3091 return DeclSpecContext::DSC_trailing;
3094 return DeclSpecContext::DSC_alias_declaration;
3096 return DeclSpecContext::DSC_association;
3098 return DeclSpecContext::DSC_type_specifier;
3100 return DeclSpecContext::DSC_condition;
3102 return DeclSpecContext::DSC_conv_operator;
3104 return DeclSpecContext::DSC_new;
3119 return DeclSpecContext::DSC_normal;
3122 llvm_unreachable(
"Missing DeclaratorContext case");
3129 if (isTypeIdInParens()) {
3130 SourceLocation TypeLoc = Tok.getLocation();
3132 SourceRange TypeRange(Start, Tok.getLocation());
3133 if (Actions.ActOnAlignasTypeArgument(KWName, Ty, TypeLoc, TypeRange))
3150 assert(Tok.isOneOf(tok::kw_alignas, tok::kw__Alignas) &&
3151 "Not an alignment-specifier!");
3158 if (
T.expectAndConsume())
3163 SourceLocation EllipsisLoc;
3165 ParseAlignArgument(PP.getSpelling(KWTok),
T.getOpenLocation(),
3174 *EndLoc =
T.getCloseLocation();
3181 ArgExprs.push_back(ArgExpr.
get());
3182 Attrs.
addNew(KWName, KWLoc, AttributeScopeInfo(), ArgExprs.data(), 1, Kind,
3187void Parser::DistributeCLateParsedAttrs(
Decl *Dcl,
3193 for (
auto *LateAttr : *LateAttrs) {
3194 if (LateAttr->Decls.empty())
3195 LateAttr->addDecl(Dcl);
3201 assert(Tok.is(tok::kw___ptrauth));
3203 IdentifierInfo *KwName = Tok.getIdentifierInfo();
3207 if (
T.expectAndConsume())
3217 ArgExprs.push_back(ER.
get());
3221 SourceLocation EndLoc =
T.getCloseLocation();
3223 if (ArgExprs.empty() || ArgExprs.size() > 3) {
3224 Diag(KwLoc, diag::err_ptrauth_qualifier_bad_arg_count);
3228 Attrs.
addNew(KwName, SourceRange(KwLoc, EndLoc), AttributeScopeInfo(),
3229 ArgExprs.data(), ArgExprs.size(),
3230 ParsedAttr::Form::Keyword(
false,
3240 assert(Tok.is(tok::l_paren) &&
"Attribute arg list not starting with '('");
3245 if (Tok.is(tok::r_paren)) {
3246 Diag(Tok.getLocation(), diag::err_argument_required_after_attribute);
3253 using ExpressionKind =
3255 EnterExpressionEvaluationContext EC(
3257 ExpressionKind::EK_AttrArgument);
3265 ArgExprs.push_back(ArgExpr.
get());
3268 ASTContext &Ctx = Actions.getASTContext();
3274 Attrs.
addNew(&AttrName, SourceRange(AttrNameLoc,
Parens.getCloseLocation()),
3275 AttributeScopeInfo(), ArgExprs.data(), ArgExprs.size(), Form);
3278ExprResult Parser::ParseExtIntegerArgument() {
3279 assert(Tok.isOneOf(tok::kw__ExtInt, tok::kw__BitInt) &&
3280 "Not an extended int type");
3284 if (
T.expectAndConsume())
3293 if(
T.consumeClose())
3300 DeclSpecContext DSContext,
3304 bool EnteringContext = (DSContext == DeclSpecContext::DSC_class ||
3305 DSContext == DeclSpecContext::DSC_top_level);
3308 (Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw_decltype) ||
3309 (Tok.is(tok::annot_template_id) &&
NextToken().
is(tok::coloncolon))) &&
3315 bool HasScope = Tok.is(tok::annot_cxxscope);
3317 Token AfterScope = HasScope ?
NextToken() : Tok;
3321 bool MightBeDeclarator =
true;
3322 if (Tok.isOneOf(tok::kw_typename, tok::annot_typename)) {
3324 MightBeDeclarator =
false;
3325 }
else if (AfterScope.
is(tok::annot_template_id)) {
3328 TemplateIdAnnotation *Annot =
3331 MightBeDeclarator =
false;
3332 }
else if (AfterScope.
is(tok::identifier)) {
3337 if (
Next.isOneOf(tok::star, tok::amp, tok::ampamp, tok::identifier,
3338 tok::annot_cxxscope, tok::coloncolon)) {
3340 MightBeDeclarator = false;
3341 }
else if (HasScope) {
3346 Actions.RestoreNestedNameSpecifierAnnotation(
3347 Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS);
3349 Sema::NameClassification Classification = Actions.ClassifyName(
3352 switch (Classification.
getKind()) {
3358 llvm_unreachable(
"typo correction is not possible here");
3366 MightBeDeclarator =
false;
3381 if (MightBeDeclarator)
3384 const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy();
3386 diag::err_expected_after)
3397 ParsedTemplateInfo NotATemplate;
3398 ParseDeclarationSpecifiers(DS, NotATemplate, AS, DSContext, LateAttrs);
3402void Parser::ParseDeclarationSpecifiers(
3416 if (DSContext == DeclSpecContext::DSC_conv_operator)
3417 DSContext = DeclSpecContext::DSC_type_specifier;
3419 bool EnteringContext = (DSContext == DeclSpecContext::DSC_class ||
3420 DSContext == DeclSpecContext::DSC_top_level);
3421 bool AttrsLastTime =
false;
3422 ParsedAttributes attrs(AttrFactory);
3424 PrintingPolicy Policy = Actions.getPrintingPolicy();
3427 bool isStorageClass =
false;
3428 const char *PrevSpec =
nullptr;
3429 unsigned DiagID = 0;
3433 SourceLocation ConsumedEnd;
3442 if (
getLangOpts().MSVCCompat && Tok.is(tok::kw__Atomic) &&
3445 Tok.setKind(tok::identifier);
3447 SourceLocation Loc = Tok.getLocation();
3450 auto handleOpenCLImageKW = [&] (StringRef Ext,
TypeSpecifierType ImageTypeSpec) {
3454 Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
3455 Tok.setKind(tok::identifier);
3464 bool IsTemplateSpecOrInst =
3468 switch (Tok.getKind()) {
3470 if (Tok.isRegularKeywordAttribute())
3475 ProhibitAttributes(attrs);
3478 for (
const ParsedAttr &PA : attrs) {
3479 if (!PA.isCXX11Attribute() && !PA.isC23Attribute() &&
3480 !PA.isRegularKeywordAttribute())
3488 if (PA.getKind() == ParsedAttr::AT_VectorSize) {
3489 Diag(PA.getLoc(), diag::warn_attribute_ignored) << PA;
3496 if (PA.isTypeAttr() && PA.getKind() != ParsedAttr::AT_LifetimeBound &&
3497 PA.getKind() != ParsedAttr::AT_AnyX86NoCfCheck)
3500 if (PA.getKind() == ParsedAttr::AT_LifetimeBound)
3501 Diag(PA.getLoc(), diag::err_attribute_wrong_decl_type)
3502 << PA << PA.isRegularKeywordAttribute()
3505 Diag(PA.getLoc(), diag::err_attribute_not_type_attr)
3506 << PA << PA.isRegularKeywordAttribute();
3515 DS.
Finish(Actions, Policy);
3519 case tok::kw__Alignas:
3520 diagnoseUseOfC11Keyword(Tok);
3522 case tok::kw_alignas:
3528 if (Tok.getKind() == tok::kw_alignas)
3529 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName();
3535 if (!isAllowedCXX11AttributeSpecifier())
3536 goto DoneWithDeclSpec;
3539 ProhibitAttributes(attrs);
3544 attrs.Range = SourceRange();
3546 ParseCXX11Attributes(attrs);
3547 AttrsLastTime =
true;
3550 case tok::code_completion: {
3554 bool AllowNonIdentifiers
3560 bool AllowNestedNameSpecifiers
3561 = DSContext == DeclSpecContext::DSC_top_level ||
3565 Actions.CodeCompletion().CodeCompleteDeclSpec(
3566 getCurScope(), DS, AllowNonIdentifiers, AllowNestedNameSpecifiers);
3572 CCC = DSContext == DeclSpecContext::DSC_class
3575 else if (DSContext == DeclSpecContext::DSC_class)
3579 else if (CurParsedObjCImpl)
3583 Actions.CodeCompletion().CodeCompleteOrdinaryName(
getCurScope(), CCC);
3587 case tok::coloncolon:
3593 goto DoneWithDeclSpec;
3595 if (Tok.is(tok::coloncolon))
3596 goto DoneWithDeclSpec;
3599 case tok::annot_cxxscope: {
3601 goto DoneWithDeclSpec;
3604 if (TemplateInfo.TemplateParams)
3606 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
3607 Tok.getAnnotationRange(),
3613 TemplateIdAnnotation *TemplateId =
Next.is(tok::annot_template_id)
3614 ? takeTemplateIdAnnotation(
Next)
3620 ConsumeAnnotationToken();
3634 if ((DSContext == DeclSpecContext::DSC_top_level ||
3635 DSContext == DeclSpecContext::DSC_class) &&
3638 isConstructorDeclarator(
false,
3645 goto DoneWithDeclSpec;
3649 ConsumeAnnotationToken();
3650 assert(Tok.is(tok::annot_template_id) &&
3651 "ParseOptionalCXXScopeSpecifier not working");
3652 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
3662 ConsumeAnnotationToken();
3666 if (
Next.is(tok::annot_typename)) {
3668 ConsumeAnnotationToken();
3671 Tok.getAnnotationEndLoc(),
3672 PrevSpec, DiagID,
T, Policy);
3676 ConsumeAnnotationToken();
3680 Next.is(tok::annot_template_id) &&
3681 static_cast<TemplateIdAnnotation *
>(
Next.getAnnotationValue())
3684 ConsumeAnnotationToken();
3685 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
3689 if (
Next.isNot(tok::identifier))
3690 goto DoneWithDeclSpec;
3695 if ((DSContext == DeclSpecContext::DSC_top_level ||
3696 DSContext == DeclSpecContext::DSC_class) &&
3699 isConstructorDeclarator(
false,
3703 goto DoneWithDeclSpec;
3709 SuppressAccessChecks SAC(*
this, IsTemplateSpecOrInst);
3713 false,
false,
nullptr,
3716 isClassTemplateDeductionContext(DSContext), AllowImplicitTypename);
3718 if (IsTemplateSpecOrInst)
3726 if (TryAnnotateTypeConstraint())
3727 goto DoneWithDeclSpec;
3728 if (Tok.isNot(tok::annot_cxxscope) ||
3732 ConsumeAnnotationToken();
3733 ParsedAttributes Attrs(AttrFactory);
3734 if (ParseImplicitInt(DS, &SS, TemplateInfo, AS, DSContext, Attrs)) {
3735 if (!Attrs.
empty()) {
3736 AttrsLastTime =
true;
3737 attrs.takeAllAppendingFrom(Attrs);
3741 goto DoneWithDeclSpec;
3745 ConsumeAnnotationToken();
3748 DiagID, TypeRep, Policy);
3758 case tok::annot_typename: {
3762 goto DoneWithDeclSpec;
3771 ConsumeAnnotationToken();
3776 case tok::kw___is_signed:
3788 TryKeywordIdentFallback(
true);
3791 goto DoneWithDeclSpec;
3794 case tok::kw___super:
3795 case tok::kw_decltype:
3796 case tok::identifier:
3802 goto DoneWithDeclSpec;
3808 if (!
getLangOpts().DeclSpecKeyword && Tok.is(tok::identifier) &&
3809 Tok.getIdentifierInfo()->getName() ==
"__declspec") {
3810 Diag(Loc, diag::err_ms_attributes_not_enabled);
3820 if (
T.consumeOpen()) {
3821 assert(
false &&
"Not a left paren?");
3836 SuppressAccessChecks SAC(*
this, IsTemplateSpecOrInst);
3840 if (IsTemplateSpecOrInst)
3844 if (IsTemplateSpecOrInst)
3847 goto DoneWithDeclSpec;
3850 if (!Tok.is(tok::identifier))
3855 if (TryAltiVecToken(DS, Loc, PrevSpec, DiagID,
isInvalid))
3861 goto DoneWithDeclSpec;
3863 if (DSContext == DeclSpecContext::DSC_objc_method_result &&
3864 isObjCInstancetype()) {
3865 ParsedType TypeRep = Actions.ObjC().ActOnObjCInstanceType(Loc);
3868 DiagID, TypeRep, Policy);
3880 Actions.isCurrentClassName(*Tok.getIdentifierInfo(),
getCurScope()) &&
3881 isConstructorDeclarator(
true,
3884 goto DoneWithDeclSpec;
3887 *Tok.getIdentifierInfo(), Tok.getLocation(),
getCurScope(),
nullptr,
3888 false,
false,
nullptr,
false,
false,
3889 isClassTemplateDeductionContext(DSContext));
3894 if (TryAnnotateTypeConstraint())
3895 goto DoneWithDeclSpec;
3896 if (Tok.isNot(tok::identifier))
3898 ParsedAttributes Attrs(AttrFactory);
3899 if (ParseImplicitInt(DS,
nullptr, TemplateInfo, AS, DSContext, Attrs)) {
3900 if (!Attrs.
empty()) {
3901 AttrsLastTime =
true;
3902 attrs.takeAllAppendingFrom(Attrs);
3906 goto DoneWithDeclSpec;
3913 (DSContext == DeclSpecContext::DSC_class ||
3914 DSContext == DeclSpecContext::DSC_top_level) &&
3915 Actions.isDeductionGuideName(
getCurScope(), *Tok.getIdentifierInfo(),
3916 Tok.getLocation(), SS) &&
3917 isConstructorDeclarator(
true,
3919 goto DoneWithDeclSpec;
3922 DiagID, TypeRep, Policy);
3933 SourceLocation NewEndLoc;
3934 TypeResult NewTypeRep = parseObjCTypeArgsAndProtocolQualifiers(
3949 case tok::annot_template_id: {
3950 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
3961 TemplateId =
nullptr;
3969 tok::kw_volatile, tok::kw_restrict, tok::amp,
3971 Diag(Loc, diag::err_placeholder_expected_auto_or_decltype_auto)
3975 TemplateId, Policy);
3979 goto DoneWithDeclSpec;
3981 if (TemplateId && !
isInvalid && Actions.CheckTypeConstraint(TemplateId))
3982 TemplateId =
nullptr;
3984 ConsumeAnnotationToken();
3985 SourceLocation AutoLoc = Tok.getLocation();
3988 if (Tracker.consumeOpen()) {
3990 Diag(Tok, diag::err_expected) << tok::l_paren;
3994 Tracker.skipToEnd();
3995 Diag(Tok, diag::err_placeholder_expected_auto_or_decltype_auto)
4000 Tracker.consumeClose();
4003 ConsumedEnd = Tok.getLocation();
4008 DiagID, TemplateId, Policy);
4011 TemplateId, Policy);
4020 goto DoneWithDeclSpec;
4028 isConstructorDeclarator(
true,
4031 goto DoneWithDeclSpec;
4036 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
4041 case tok::kw___attribute:
4042 case tok::kw___declspec:
4043 ParseAttributes(PAKM_GNU | PAKM_Declspec, DS.
getAttributes(), LateAttrs);
4047 case tok::kw___forceinline: {
4049 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
4050 SourceLocation AttrNameLoc = Tok.getLocation();
4052 nullptr, 0, tok::kw___forceinline);
4056 case tok::kw___unaligned:
4062 case tok::kw___ptrauth:
4066 case tok::kw___sptr:
4067 case tok::kw___uptr:
4068 case tok::kw___ptr64:
4069 case tok::kw___ptr32:
4071 case tok::kw___cdecl:
4072 case tok::kw___stdcall:
4073 case tok::kw___fastcall:
4074 case tok::kw___thiscall:
4075 case tok::kw___regcall:
4076 case tok::kw___vectorcall:
4080 case tok::kw___funcref:
4085 case tok::kw___pascal:
4090 case tok::kw___kernel:
4095 case tok::kw___noinline__:
4100 case tok::kw__Nonnull:
4101 case tok::kw__Nullable:
4102 case tok::kw__Nullable_result:
4103 case tok::kw__Null_unspecified:
4108 case tok::kw___kindof:
4110 AttributeScopeInfo(),
nullptr, 0,
4116 case tok::kw_typedef:
4118 PrevSpec, DiagID, Policy);
4119 isStorageClass =
true;
4121 case tok::kw_extern:
4123 Diag(Tok, diag::ext_thread_before) <<
"extern";
4125 PrevSpec, DiagID, Policy);
4126 isStorageClass =
true;
4128 case tok::kw___private_extern__:
4130 Loc, PrevSpec, DiagID, Policy);
4131 isStorageClass =
true;
4133 case tok::kw_static:
4135 Diag(Tok, diag::ext_thread_before) <<
"static";
4137 PrevSpec, DiagID, Policy);
4138 isStorageClass =
true;
4142 auto IsTypedefName = [&](
const Token &
T) {
4143 if (!
T.is(tok::identifier))
4145 IdentifierInfo *II =
T.getIdentifierInfo();
4149 LookupResult
R(Actions, II,
T.getLocation(),
4153 R.suppressDiagnostics();
4156 auto MayBeTypeSpecifier = [&]() {
4167 if (isKnownToBeTypeSpecifier(
T))
4186 if (MayBeTypeSpecifier()) {
4188 PrevSpec, DiagID, Policy);
4190 Diag(Tok, diag::ext_auto_storage_class)
4197 PrevSpec, DiagID, Policy);
4198 isStorageClass =
true;
4200 case tok::kw___auto_type:
4201 Diag(Tok, diag::ext_auto_type);
4205 case tok::kw_register:
4207 PrevSpec, DiagID, Policy);
4208 isStorageClass =
true;
4210 case tok::kw_mutable:
4212 PrevSpec, DiagID, Policy);
4213 isStorageClass =
true;
4215 case tok::kw___thread:
4218 isStorageClass =
true;
4220 case tok::kw_thread_local:
4222 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName();
4231 Loc, PrevSpec, DiagID);
4232 isStorageClass =
true;
4234 case tok::kw__Thread_local:
4235 diagnoseUseOfC11Keyword(Tok);
4237 Loc, PrevSpec, DiagID);
4238 isStorageClass =
true;
4242 case tok::kw_inline:
4245 case tok::kw_virtual:
4249 !
getActions().getOpenCLOptions().isAvailableOption(
4251 DiagID = diag::err_openclcxx_virtual_function;
4252 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
4255 DiagID = diag::err_hlsl_virtual_function;
4256 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
4262 case tok::kw_explicit: {
4263 SourceLocation ExplicitLoc = Loc;
4264 SourceLocation CloseParenLoc;
4266 ConsumedEnd = ExplicitLoc;
4268 if (Tok.is(tok::l_paren)) {
4270 DiagCompat(Tok.getLocation(), diag_compat::explicit_bool);
4272 ExprResult ExplicitExpr(
static_cast<Expr *
>(
nullptr));
4274 Tracker.consumeOpen();
4276 EnterExpressionEvaluationContext ConstantEvaluated(
4280 ConsumedEnd = Tok.getLocation();
4281 if (ExplicitExpr.isUsable()) {
4282 CloseParenLoc = Tok.getLocation();
4283 Tracker.consumeClose();
4285 Actions.ActOnExplicitBoolSpecifier(ExplicitExpr.get());
4287 Tracker.skipToEnd();
4289 Diag(Tok.getLocation(), diag::warn_cxx20_compat_explicit_bool);
4293 ExplicitSpec, CloseParenLoc);
4296 case tok::kw__Noreturn:
4297 diagnoseUseOfC11Keyword(Tok);
4302 case tok::kw_friend:
4303 if (DSContext == DeclSpecContext::DSC_class) {
4310 DiagID = diag::err_friend_invalid_in_context;
4316 case tok::kw___module_private__:
4321 case tok::kw_constexpr:
4323 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName();
4327 case tok::kw_consteval:
4331 case tok::kw_constinit:
4339 Diag(Tok, diag::err_unknown_typename) << Tok.getName();
4343 goto DoneWithDeclSpec;
4354 PrevSpec, DiagID, Policy);
4356 case tok::kw___int64:
4358 PrevSpec, DiagID, Policy);
4360 case tok::kw_signed:
4364 case tok::kw_unsigned:
4368 case tok::kw__Complex:
4370 Diag(Tok, diag::ext_c99_feature) << Tok.getName();
4374 case tok::kw__Imaginary:
4376 Diag(Tok, diag::ext_c99_feature) << Tok.getName();
4392 case tok::kw__ExtInt:
4393 case tok::kw__BitInt: {
4394 DiagnoseBitIntUse(Tok);
4399 ConsumedEnd = PrevTokLocation;
4402 case tok::kw___int128:
4410 case tok::kw___bf16:
4418 case tok::kw_double:
4422 case tok::kw__Float16:
4426 case tok::kw__Accum:
4428 "This keyword is only used when fixed point types are enabled "
4429 "with `-ffixed-point`");
4433 case tok::kw__Fract:
4435 "This keyword is only used when fixed point types are enabled "
4436 "with `-ffixed-point`");
4442 "This keyword is only used when fixed point types are enabled "
4443 "with `-ffixed-point`");
4446 case tok::kw___float128:
4450 case tok::kw___ibm128:
4454 case tok::kw_wchar_t:
4458 case tok::kw_char8_t:
4462 case tok::kw_char16_t:
4466 case tok::kw_char32_t:
4472 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName();
4476 Diag(Tok, diag::ext_c99_feature) << Tok.getName();
4478 if (Tok.is(tok::kw_bool) &&
4482 DiagID = diag::err_bool_redeclaration;
4484 Tok.setKind(tok::identifier);
4491 case tok::kw__Decimal32:
4495 case tok::kw__Decimal64:
4499 case tok::kw__Decimal128:
4503 case tok::kw___vector:
4506 case tok::kw___pixel:
4509 case tok::kw___bool:
4514 getLangOpts().getOpenCLCompatibleVersion() < 200) {
4517 Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
4518 Tok.setKind(tok::identifier);
4519 goto DoneWithDeclSpec;
4521 DiagID = diag::err_opencl_unknown_type_specifier;
4522 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
4528#define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
4529#define IMAGE_WRITE_TYPE(Type, Id, Ext)
4530#define IMAGE_READ_TYPE(ImgType, Id, Ext) \
4531 case tok::kw_##ImgType##_t: \
4532 if (!handleOpenCLImageKW(Ext, DeclSpec::TST_##ImgType##_t)) \
4533 goto DoneWithDeclSpec; \
4535#include "clang/Basic/OpenCLImageTypes.def"
4536 case tok::kw___unknown_anytype:
4538 PrevSpec, DiagID, Policy);
4543 case tok::kw_struct:
4544 case tok::kw___interface:
4545 case tok::kw_union: {
4552 ParsedAttributes Attributes(AttrFactory);
4553 ParseClassSpecifier(Kind, Loc, DS, TemplateInfo, AS,
4554 EnteringContext, DSContext, Attributes);
4558 if (!Attributes.empty()) {
4559 AttrsLastTime =
true;
4560 attrs.takeAllAppendingFrom(Attributes);
4568 ParseEnumSpecifier(Loc, DS, TemplateInfo, AS, DSContext);
4576 case tok::kw_volatile:
4580 case tok::kw_restrict:
4584 case tok::kw___ob_wrap:
4586 Diag(Loc, diag::warn_overflow_behavior_keyword_disabled)
4591 OverflowBehaviorType::OverflowBehaviorKind::Wrap, Loc, PrevSpec,
4594 case tok::kw___ob_trap:
4596 Diag(Loc, diag::warn_overflow_behavior_keyword_disabled)
4601 OverflowBehaviorType::OverflowBehaviorKind::Trap, Loc, PrevSpec,
4606 case tok::kw_typename:
4609 goto DoneWithDeclSpec;
4611 if (!Tok.is(tok::kw_typename))
4616 case tok::kw_typeof:
4617 case tok::kw_typeof_unqual:
4618 ParseTypeofSpecifier(DS);
4621 case tok::annot_decltype:
4622 ParseDecltypeSpecifier(DS);
4625 case tok::annot_pack_indexing_type:
4626 ParsePackIndexingType(DS);
4629 case tok::annot_pragma_pack:
4633 case tok::annot_pragma_ms_pragma:
4634 HandlePragmaMSPragma();
4637 case tok::annot_pragma_ms_vtordisp:
4638 HandlePragmaMSVtorDisp();
4641 case tok::annot_pragma_ms_pointers_to_members:
4642 HandlePragmaMSPointersToMembers();
4645 case tok::annot_pragma_export:
4646 HandlePragmaExport();
4649#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
4650#include "clang/Basic/BuiltinTraits.inc"
4654 if (!MaybeParseTypeTransformTypeSpecifier(DS))
4655 goto ParseIdentifier;
4658 case tok::kw__Atomic:
4663 diagnoseUseOfC11Keyword(Tok);
4665 ParseAtomicSpecifier(DS);
4673 case tok::kw___generic:
4678 if (!Actions.getLangOpts().OpenCLGenericAddressSpace) {
4679 DiagID = diag::err_opencl_unknown_type_specifier;
4680 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
4685 case tok::kw_private:
4689 goto DoneWithDeclSpec;
4691 case tok::kw___private:
4692 case tok::kw___global:
4693 case tok::kw___local:
4694 case tok::kw___constant:
4696 case tok::kw___read_only:
4697 case tok::kw___write_only:
4698 case tok::kw___read_write:
4701 case tok::kw_row_major:
4702 case tok::kw_column_major:
4703 case tok::kw_nointerpolation:
4704 case tok::kw_linear:
4705 case tok::kw_centroid:
4706 case tok::kw_noperspective:
4707 case tok::kw_sample:
4708 case tok::kw_center:
4709 case tok::kw_groupshared:
4717#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
4718 case tok::kw_##Name: \
4719 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, \
4722#include "clang/Basic/HLSLIntangibleTypes.def"
4724#define HLSL_PACKED_TYPE(Name, Id, SingletonId) \
4725 case tok::kw_##Name: \
4726 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, \
4729#include "clang/Basic/HLSLPackedTypes.def"
4736 goto DoneWithDeclSpec;
4738 SourceLocation StartLoc = Tok.getLocation();
4739 SourceLocation EndLoc;
4741 if (
Type.isUsable()) {
4743 PrevSpec, DiagID,
Type.get(),
4744 Actions.getASTContext().getPrintingPolicy()))
4745 Diag(StartLoc, DiagID) << PrevSpec;
4761 assert(PrevSpec &&
"Method did not return previous specifier!");
4764 if (DiagID == diag::ext_duplicate_declspec ||
4765 DiagID == diag::ext_warn_duplicate_declspec ||
4766 DiagID == diag::err_duplicate_declspec)
4767 Diag(Loc, DiagID) << PrevSpec
4770 else if (DiagID == diag::err_opencl_unknown_type_specifier) {
4774 Diag(Loc, DiagID) << PrevSpec;
4777 if (DiagID != diag::err_bool_redeclaration && ConsumedEnd.
isInvalid())
4781 AttrsLastTime =
false;
4793 if (!RD || !RD->getName().empty() || RD->isAnonymousStructOrUnion())
4796 for (
auto *I : RD->decls()) {
4797 auto *VD = dyn_cast<ValueDecl>(I);
4805 for (
const auto &DD : CAT->dependent_decls()) {
4806 if (!RD->containsDecl(DD.getDecl())) {
4807 P.
Diag(VD->getBeginLoc(), diag::err_count_attr_param_not_in_same_struct)
4808 << DD.getDecl() << CAT->getKind() << CAT->isArrayType();
4809 P.
Diag(DD.getDecl()->getBeginLoc(),
4810 diag::note_flexible_array_counted_by_attr_field)
4817void Parser::ParseStructDeclaration(
4822 if (Tok.is(tok::kw___extension__)) {
4824 ExtensionRAIIObject O(Diags);
4826 return ParseStructDeclaration(DS, FieldsCallback, LateFieldAttrs);
4830 ParsedAttributes Attrs(AttrFactory);
4831 MaybeParseCXX11Attributes(Attrs);
4834 ParseSpecifierQualifierList(DS);
4838 if (Tok.is(tok::semi)) {
4843 ProhibitAttributes(Attrs);
4844 RecordDecl *AnonRecord =
nullptr;
4845 Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(
4847 assert(!AnonRecord &&
"Did not expect anonymous struct or union here");
4853 bool FirstDeclarator =
true;
4854 SourceLocation CommaLoc;
4856 ParsingFieldDeclarator DeclaratorInfo(*
this, DS, Attrs);
4857 DeclaratorInfo.D.setCommaLoc(CommaLoc);
4860 if (!FirstDeclarator) {
4863 DiagnoseAndSkipCXX11Attributes();
4864 MaybeParseGNUAttributes(DeclaratorInfo.D);
4865 DiagnoseAndSkipCXX11Attributes();
4870 if (Tok.isNot(tok::colon)) {
4873 ParseDeclarator(DeclaratorInfo.D);
4875 DeclaratorInfo.D.SetIdentifier(
nullptr, Tok.getLocation());
4887 DeclaratorInfo.BitfieldSize = Res.
get();
4891 MaybeParseGNUAttributes(DeclaratorInfo.D, LateFieldAttrs);
4894 Decl *
Field = FieldsCallback(DeclaratorInfo);
4896 DistributeCLateParsedAttrs(Field, LateFieldAttrs);
4903 FirstDeclarator =
false;
4911 LPA.
Toks.push_back(AttrEnd);
4915 LPA.
Toks.push_back(Tok);
4916 PP.EnterTokenStream(LPA.
Toks,
true,
4923 ParsedAttributes Attrs(AttrFactory);
4927 SourceLocation(), ParsedAttr::Form::GNU(),
4932 while (Tok.isNot(tok::eof))
4936 if (Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData())
4944 assert(LA.
Decls.size() <= 1 &&
4945 "late field attribute expects to have at most one declaration.");
4947 ParsedAttributes Attrs = ParseLexedAttributeTokens(LA);
4951void Parser::CompleteLateParsedTypeAttributes(
4954 std::unique_ptr<LateParsedTypeAttribute> LTA(RawLTA);
4956 BoundsAttributedType *BATy = LTA->Info.TypeToComplete;
4957 if (!BATy || Actions.isLateParsedBoundsTypeRejected(BATy))
4960 ArrayRef<Decl *> Fields = LTA->Decls;
4962 AttributeFactory AF;
4963 ParsedAttributes Attrs(AF);
4964 ParseLexedTypeAttribute(*LTA, Attrs);
4969 assert(Attrs.
size() == 1);
4971 Expr *Arg = Attrs[0].getArgAsExpr(0);
4975 assert(!Fields.empty());
4976 for (Decl *FD : Fields)
4977 Valid &= Actions.ActOnLateParsedTypeAttrArgument(
4981 Attrs[0].setUsedAsTypeAttr();
4983 Attrs[0].setInvalid();
4985 LateTypeAttrs.clear();
4990 Self->ParseLexedTypeAttribute(*
this, OutAttrs);
4995 LateParsedAttrList::iterator It =
5003 From.erase(It, From.end());
5008 PrettyDeclStackTraceEntry CrashInfo(Actions.Context, TagDecl,
RecordLoc,
5009 "parsing struct/union body");
5013 if (
T.consumeOpen())
5017 Actions.ActOnTagStartDefinition(
getCurScope(), TagDecl);
5021 LateParsedAttrList LateFieldAttrs(
true,
5025 while (!tryParseMisplacedModuleImport() && Tok.isNot(tok::r_brace) &&
5026 Tok.isNot(tok::eof)) {
5030 if (Tok.is(tok::semi)) {
5036 if (Tok.isOneOf(tok::kw__Static_assert, tok::kw_static_assert)) {
5037 SourceLocation DeclEnd;
5038 ParseStaticAssertDeclaration(DeclEnd);
5042 if (Tok.is(tok::annot_pragma_pack)) {
5047 if (Tok.is(tok::annot_pragma_align)) {
5048 HandlePragmaAlign();
5052 if (Tok.isOneOf(tok::annot_pragma_openmp, tok::annot_attr_openmp)) {
5055 ParsedAttributes Attrs(AttrFactory);
5056 (void)ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs);
5060 if (Tok.is(tok::annot_pragma_openacc)) {
5062 ParsedAttributes Attrs(AttrFactory);
5068 Diag(Tok.getLocation(), diag::err_pragma_misplaced_in_decl)
5070 TagType, Actions.getASTContext().getPrintingPolicy());
5071 ConsumeAnnotationToken();
5075 if (!Tok.is(tok::at)) {
5076 auto CFieldCallback = [&](ParsingFieldDeclarator &FD) -> Decl * {
5080 FD.D.getDeclSpec().getSourceRange().getBegin(),
5081 FD.D, FD.BitfieldSize);
5087 ParsingDeclSpec DS(*
this);
5088 ParseStructDeclaration(DS, CFieldCallback, &LateFieldAttrs);
5091 if (!Tok.isObjCAtKeyword(tok::objc_defs)) {
5092 Diag(Tok, diag::err_unexpected_at);
5097 ExpectAndConsume(tok::l_paren);
5098 if (!Tok.is(tok::identifier)) {
5099 Diag(Tok, diag::err_expected) << tok::identifier;
5103 SmallVector<Decl *, 16> Fields;
5104 Actions.ObjC().ActOnDefs(
getCurScope(), TagDecl, Tok.getLocation(),
5105 Tok.getIdentifierInfo(), Fields);
5107 ExpectAndConsume(tok::r_paren);
5113 if (Tok.is(tok::r_brace)) {
5114 ExpectAndConsume(tok::semi, diag::ext_expected_semi_decl_list);
5118 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list);
5127 ParsedAttributes attrs(AttrFactory);
5129 MaybeParseGNUAttributes(attrs, &LateFieldAttrs);
5131 SmallVector<Decl *, 32> FieldDecls(TagDecl->
fields());
5134 T.getOpenLocation(),
T.getCloseLocation(), attrs);
5137 ParseLexedAttributeList(LateFieldAttrs,
nullptr,
false,
5140 Actions.ActOnTagFinishDefinition(
getCurScope(), TagDecl,
T.getRange());
5144 const ParsedTemplateInfo &TemplateInfo,
5147 if (Tok.is(tok::code_completion)) {
5156 ParsedAttributes attrs(AttrFactory);
5157 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec | PAKM_CXX11, attrs);
5159 SourceLocation ScopedEnumKWLoc;
5160 bool IsScopedUsingClassTag =
false;
5165 IsScopedUsingClassTag = Tok.is(tok::kw_class);
5170 ProhibitAttributes(attrs);
5173 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec | PAKM_CXX11, attrs);
5182 bool shouldDelayDiagsInTag =
5185 SuppressAccessChecks diagsFromTag(*
this, shouldDelayDiagsInTag);
5188 AllowDefiningTypeSpec AllowEnumSpecifier =
5190 bool CanBeOpaqueEnumDeclaration =
5191 DS.
isEmpty() && isOpaqueEnumDeclarationContext(DSC);
5194 (AllowEnumSpecifier == AllowDefiningTypeSpec::Yes ||
5195 CanBeOpaqueEnumDeclaration);
5199 CXXScopeSpec InvalidDeclScope;
5207 if (ParseOptionalCXXScopeSpecifier(Spec,
nullptr,
5212 if (Spec.
isSet() && Tok.isNot(tok::identifier)) {
5213 Diag(Tok, diag::err_expected) << tok::identifier;
5215 if (Tok.isNot(tok::l_brace)) {
5223 SS = std::move(Spec);
5227 if (Tok.isNot(tok::identifier) && Tok.isNot(tok::l_brace) &&
5228 Tok.isNot(tok::colon)) {
5229 Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace;
5238 IdentifierInfo *Name =
nullptr;
5239 SourceLocation NameLoc;
5240 if (Tok.is(tok::identifier)) {
5241 Name = Tok.getIdentifierInfo();
5245 if (!Name && ScopedEnumKWLoc.
isValid()) {
5248 Diag(Tok, diag::err_scoped_enum_missing_identifier);
5249 ScopedEnumKWLoc = SourceLocation();
5250 IsScopedUsingClassTag =
false;
5255 if (shouldDelayDiagsInTag)
5256 diagsFromTag.done();
5259 SourceRange BaseRange;
5261 bool CanBeBitfield =
5264 auto IsCXXTypeAhead = [
this]() {
5265 RevertingTentativeParsingAction PA(*
this);
5271 if (Tok.is(tok::colon) &&
5272 (!ParsingGenericAssociationType || IsCXXTypeAhead())) {
5297 if (CanBeBitfield && !isEnumBase(CanBeOpaqueEnumDeclaration)) {
5301 Diag(Tok.getLocation(), diag::err_anonymous_enum_bitfield);
5302 }
else if (CanHaveEnumBase || !ColonIsSacred) {
5309 DeclSpec DS(AttrFactory);
5313 DeclSpecContext::DSC_type_specifier);
5316 BaseType = Actions.ActOnTypeName(DeclaratorInfo);
5318 BaseRange = SourceRange(ColonLoc, DeclaratorInfo.getSourceRange().getEnd());
5322 DiagCompat(ColonLoc, diag_compat::cxx_enum_fixed_underlying_type)
5325 Diag(ColonLoc, diag::ext_ms_c_enum_fixed_underlying_type)
5328 DiagCompat(ColonLoc, diag_compat::c_enum_fixed_underlying_type)
5345 if (AllowEnumSpecifier == AllowDefiningTypeSpec::No)
5347 else if (Tok.is(tok::l_brace)) {
5349 Diag(Tok.getLocation(), diag::err_friend_decl_defines_type)
5355 ScopedEnumKWLoc = SourceLocation();
5356 IsScopedUsingClassTag =
false;
5362 }
else if (!isTypeSpecifier(DSC) &&
5363 (Tok.is(tok::semi) ||
5364 (Tok.isAtStartOfLine() &&
5365 !isValidAfterTypeSpecifier(CanBeBitfield)))) {
5370 if (Tok.isNot(tok::semi)) {
5372 ExpectAndConsume(tok::semi, diag::err_expected_after,
"enum");
5373 PP.EnterToken(Tok,
true);
5374 Tok.setKind(tok::semi);
5380 bool IsElaboratedTypeSpecifier =
5386 diagsFromTag.redelay();
5394 Diag(Tok, diag::err_enum_template);
5402 Diag(StartLoc, diag::err_explicit_instantiation_enum);
5406 assert(TemplateInfo.TemplateParams &&
"no template parameters");
5408 TemplateInfo.TemplateParams->size());
5413 Diag(Tok, diag::err_enumerator_unnamed_no_def);
5429 if (IsElaboratedTypeSpecifier && !
getLangOpts().MicrosoftExt &&
5431 ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
5432 diag::err_keyword_not_allowed,
5435 Diag(BaseRange.
getBegin(), diag::ext_enum_base_in_type_specifier)
5436 << (AllowEnumSpecifier == AllowDefiningTypeSpec::Yes) << BaseRange;
5437 else if (ScopedEnumKWLoc.
isValid())
5438 Diag(ScopedEnumKWLoc, diag::ext_elaborated_enum_class)
5442 stripTypeAttributesOffDeclSpec(attrs, DS, TUK);
5444 SkipBodyInfo SkipBody;
5447 SkipBody = Actions.shouldSkipAnonEnumBody(
getCurScope(),
5452 bool IsDependent =
false;
5453 const char *PrevSpec =
nullptr;
5458 TParams, Owned, IsDependent, ScopedEnumKWLoc,
5459 IsScopedUsingClassTag,
5460 BaseType, DSC == DeclSpecContext::DSC_type_specifier,
5461 DSC == DeclSpecContext::DSC_template_param ||
5462 DSC == DeclSpecContext::DSC_template_type_arg,
5463 OffsetOfState, &SkipBody).get();
5473 NameLoc.
isValid() ? NameLoc : StartLoc,
5474 PrevSpec, DiagID, TagDecl, Owned,
5475 Actions.getASTContext().getPrintingPolicy()))
5476 Diag(StartLoc, DiagID) << PrevSpec;
5485 Diag(Tok, diag::err_expected_type_name_after_typename);
5491 if (
Type.isInvalid()) {
5497 NameLoc.
isValid() ? NameLoc : StartLoc,
5498 PrevSpec, DiagID,
Type.get(),
5499 Actions.getASTContext().getPrintingPolicy()))
5500 Diag(StartLoc, DiagID) << PrevSpec;
5519 ParseEnumBody(StartLoc, D, &SkipBody);
5521 !Actions.ActOnDuplicateDefinition(
getCurScope(), TagDecl, SkipBody)) {
5528 NameLoc.
isValid() ? NameLoc : StartLoc,
5529 PrevSpec, DiagID, TagDecl, Owned,
5530 Actions.getASTContext().getPrintingPolicy()))
5531 Diag(StartLoc, DiagID) << PrevSpec;
5538 Actions.ActOnTagStartDefinition(
getCurScope(), EnumDecl);
5546 Diag(
T.getOpenLocation(), diag::ext_ms_c_empty_enum_type)
5547 << SourceRange(
T.getOpenLocation(), Tok.getLocation());
5549 Diag(Tok, diag::err_empty_enum);
5552 SmallVector<Decl *, 32> EnumConstantDecls;
5553 SmallVector<SuppressAccessChecks, 32> EnumAvailabilityDiags;
5555 Decl *LastEnumConstDecl =
nullptr;
5558 while (Tok.isNot(tok::r_brace)) {
5561 if (Tok.isNot(tok::identifier)) {
5562 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
5568 IdentifierInfo *Ident = Tok.getIdentifierInfo();
5572 ParsedAttributes attrs(AttrFactory);
5573 MaybeParseGNUAttributes(attrs);
5574 if (isAllowedCXX11AttributeSpecifier()) {
5576 DiagCompat(Tok.getLocation(), diag_compat::ns_enum_attribute)
5578 ParseCXX11Attributes(attrs);
5581 SourceLocation EqualLoc;
5583 EnumAvailabilityDiags.emplace_back(*
this);
5585 EnterExpressionEvaluationContext ConstantEvaluated(
5594 Decl *EnumConstDecl = Actions.ActOnEnumConstant(
5595 getCurScope(), EnumDecl, LastEnumConstDecl, IdentLoc, Ident, attrs,
5596 EqualLoc, AssignedVal.
get(), SkipBody);
5597 EnumAvailabilityDiags.back().done();
5599 EnumConstantDecls.push_back(EnumConstDecl);
5600 LastEnumConstDecl = EnumConstDecl;
5602 if (Tok.is(tok::identifier)) {
5605 Diag(Loc, diag::err_enumerator_list_missing_comma)
5612 SourceLocation CommaLoc;
5613 if (Tok.isNot(tok::r_brace) && !
TryConsumeToken(tok::comma, CommaLoc)) {
5615 Diag(Tok.getLocation(), diag::err_expected_either) << tok::r_brace
5618 Diag(Tok.getLocation(), diag::err_expected_end_of_enumerator);
5628 if (Tok.is(tok::r_brace) && CommaLoc.
isValid()) {
5630 DiagCompat(CommaLoc, diag_compat::cxx_enumerator_list_comma)
5633 Diag(CommaLoc, diag::ext_enumerator_list_comma_c)
5643 ParsedAttributes attrs(AttrFactory);
5644 MaybeParseGNUAttributes(attrs);
5646 Actions.ActOnEnumBody(StartLoc,
T.getRange(), EnumDecl, EnumConstantDecls,
5650 assert(EnumConstantDecls.size() == EnumAvailabilityDiags.size());
5651 for (
size_t i = 0, e = EnumConstantDecls.size(); i != e; ++i) {
5653 EnumAvailabilityDiags[i].redelay();
5654 PD.complete(EnumConstantDecls[i]);
5658 Actions.ActOnTagFinishDefinition(
getCurScope(), EnumDecl,
T.getRange());
5663 if (!isValidAfterTypeSpecifier(CanBeBitfield)) {
5664 ExpectAndConsume(tok::semi, diag::err_expected_after,
"enum");
5668 PP.EnterToken(Tok,
true);
5669 Tok.setKind(tok::semi);
5673bool Parser::isKnownToBeTypeSpecifier(
const Token &
Tok)
const {
5674 switch (Tok.getKind()) {
5675 default:
return false;
5679 case tok::kw___int64:
5680 case tok::kw___int128:
5681 case tok::kw_signed:
5682 case tok::kw_unsigned:
5683 case tok::kw__Complex:
5684 case tok::kw__Imaginary:
5687 case tok::kw_wchar_t:
5688 case tok::kw_char8_t:
5689 case tok::kw_char16_t:
5690 case tok::kw_char32_t:
5692 case tok::kw__ExtInt:
5693 case tok::kw__BitInt:
5694 case tok::kw___bf16:
5697 case tok::kw_double:
5698 case tok::kw__Accum:
5699 case tok::kw__Fract:
5700 case tok::kw__Float16:
5701 case tok::kw___float128:
5702 case tok::kw___ibm128:
5705 case tok::kw__Decimal32:
5706 case tok::kw__Decimal64:
5707 case tok::kw__Decimal128:
5708 case tok::kw___vector:
5709#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
5710#include "clang/Basic/OpenCLImageTypes.def"
5711#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
5712#include "clang/Basic/HLSLIntangibleTypes.def"
5713#define HLSL_PACKED_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
5714#include "clang/Basic/HLSLPackedTypes.def"
5718 case tok::kw_struct:
5719 case tok::kw___interface:
5724 case tok::kw_typeof:
5725 case tok::kw_typeof_unqual:
5728 case tok::kw__Atomic:
5731 case tok::annot_typename:
5736bool Parser::isTypeSpecifierQualifier(
const Token &
Tok) {
5737 switch (Tok.getKind()) {
5738 default:
return false;
5740 case tok::identifier:
5741 if (TryAltiVecVectorToken())
5744 case tok::kw_typename:
5753 case tok::coloncolon:
5763 case tok::kw___attribute:
5765 case tok::kw_typeof:
5766 case tok::kw_typeof_unqual:
5771 case tok::kw___int64:
5772 case tok::kw___int128:
5773 case tok::kw_signed:
5774 case tok::kw_unsigned:
5775 case tok::kw__Complex:
5776 case tok::kw__Imaginary:
5779 case tok::kw_wchar_t:
5780 case tok::kw_char8_t:
5781 case tok::kw_char16_t:
5782 case tok::kw_char32_t:
5784 case tok::kw__ExtInt:
5785 case tok::kw__BitInt:
5787 case tok::kw___bf16:
5789 case tok::kw_double:
5790 case tok::kw__Accum:
5791 case tok::kw__Fract:
5792 case tok::kw__Float16:
5793 case tok::kw___float128:
5794 case tok::kw___ibm128:
5797 case tok::kw__Decimal32:
5798 case tok::kw__Decimal64:
5799 case tok::kw__Decimal128:
5800 case tok::kw___vector:
5801#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
5802#include "clang/Basic/OpenCLImageTypes.def"
5803#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
5804#include "clang/Basic/HLSLIntangibleTypes.def"
5805#define HLSL_PACKED_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
5806#include "clang/Basic/HLSLPackedTypes.def"
5810 case tok::kw_struct:
5811 case tok::kw___interface:
5818 case tok::kw_volatile:
5819 case tok::kw_restrict:
5820 case tok::kw___ob_wrap:
5821 case tok::kw___ob_trap:
5825 case tok::kw___unknown_anytype:
5828 case tok::annot_typename:
5835 case tok::kw___cdecl:
5836 case tok::kw___stdcall:
5837 case tok::kw___fastcall:
5838 case tok::kw___thiscall:
5839 case tok::kw___regcall:
5840 case tok::kw___vectorcall:
5842 case tok::kw___ptr64:
5843 case tok::kw___ptr32:
5844 case tok::kw___pascal:
5845 case tok::kw___unaligned:
5846 case tok::kw___ptrauth:
5848 case tok::kw__Nonnull:
5849 case tok::kw__Nullable:
5850 case tok::kw__Nullable_result:
5851 case tok::kw__Null_unspecified:
5853 case tok::kw___kindof:
5855 case tok::kw___private:
5856 case tok::kw___local:
5857 case tok::kw___global:
5858 case tok::kw___constant:
5859 case tok::kw___generic:
5860 case tok::kw___read_only:
5861 case tok::kw___read_write:
5862 case tok::kw___write_only:
5863 case tok::kw___funcref:
5866 case tok::kw_private:
5870 case tok::kw__Atomic:
5874 case tok::kw_nointerpolation:
5875 case tok::kw_linear:
5876 case tok::kw_centroid:
5877 case tok::kw_noperspective:
5878 case tok::kw_sample:
5879 case tok::kw_center:
5880 case tok::kw_groupshared:
5884 case tok::kw_row_major:
5885 case tok::kw_column_major:
5891 assert(PP.isIncrementalProcessingEnabled() &&
"Not in incremental mode");
5895 ParsedStmtContext SubStmtCtx = ParsedStmtContext();
5898 TopLevelStmtDecl *TLSD = Actions.ActOnStartTopLevelStmtDecl(
getCurScope());
5899 StmtResult R = ParseStatementOrDeclaration(Stmts, SubStmtCtx);
5900 Actions.ActOnFinishTopLevelStmtDecl(TLSD,
R.get());
5901 if (!
R.isUsable()) {
5902 R = Actions.ActOnNullStmt(Tok.getLocation());
5906 if (Tok.is(tok::eof) && Tok.getEofData()) {
5911 SmallVector<Decl *, 2> DeclsInGroup;
5912 DeclsInGroup.push_back(TLSD);
5915 for (Stmt *S : Stmts) {
5918 TopLevelStmtDecl *D = Actions.ActOnStartTopLevelStmtDecl(
getCurScope());
5919 Actions.ActOnFinishTopLevelStmtDecl(D, S);
5920 DeclsInGroup.push_back(D);
5923 return Actions.BuildDeclaratorGroup(DeclsInGroup);
5926bool Parser::isDeclarationSpecifier(
5928 bool DisambiguatingWithExpression) {
5929 switch (Tok.getKind()) {
5930 default:
return false;
5937 case tok::identifier:
5941 if (TryAltiVecVectorToken())
5944 case tok::kw_decltype:
5945 case tok::kw_typename:
5950 if (TryAnnotateTypeConstraint())
5952 if (Tok.is(tok::identifier))
5960 if (DisambiguatingWithExpression &&
5961 isStartOfObjCClassMessageMissingOpenBracket())
5964 return isDeclarationSpecifier(AllowImplicitTypename);
5966 case tok::coloncolon:
5980 case tok::kw_typedef:
5981 case tok::kw_extern:
5982 case tok::kw___private_extern__:
5983 case tok::kw_static:
5985 case tok::kw___auto_type:
5986 case tok::kw_register:
5987 case tok::kw___thread:
5988 case tok::kw_thread_local:
5989 case tok::kw__Thread_local:
5992 case tok::kw___module_private__:
5995 case tok::kw___unknown_anytype:
6000 case tok::kw___int64:
6001 case tok::kw___int128:
6002 case tok::kw_signed:
6003 case tok::kw_unsigned:
6004 case tok::kw__Complex:
6005 case tok::kw__Imaginary:
6008 case tok::kw_wchar_t:
6009 case tok::kw_char8_t:
6010 case tok::kw_char16_t:
6011 case tok::kw_char32_t:
6014 case tok::kw__ExtInt:
6015 case tok::kw__BitInt:
6017 case tok::kw___bf16:
6019 case tok::kw_double:
6020 case tok::kw__Accum:
6021 case tok::kw__Fract:
6022 case tok::kw__Float16:
6023 case tok::kw___float128:
6024 case tok::kw___ibm128:
6027 case tok::kw__Decimal32:
6028 case tok::kw__Decimal64:
6029 case tok::kw__Decimal128:
6030 case tok::kw___vector:
6034 case tok::kw_struct:
6036 case tok::kw___interface:
6042 case tok::kw_volatile:
6043 case tok::kw_restrict:
6044 case tok::kw___ob_wrap:
6045 case tok::kw___ob_trap:
6049 case tok::kw_inline:
6050 case tok::kw_virtual:
6051 case tok::kw_explicit:
6052 case tok::kw__Noreturn:
6055 case tok::kw__Alignas:
6058 case tok::kw_friend:
6061 case tok::kw_static_assert:
6062 case tok::kw__Static_assert:
6065 case tok::kw_typeof:
6066 case tok::kw_typeof_unqual:
6069 case tok::kw___attribute:
6072 case tok::annot_decltype:
6073 case tok::annot_pack_indexing_type:
6074 case tok::kw_constexpr:
6077 case tok::kw_consteval:
6078 case tok::kw_constinit:
6081 case tok::kw__Atomic:
6084 case tok::kw_alignas:
6094 case tok::annot_typename:
6095 return !DisambiguatingWithExpression ||
6096 !isStartOfObjCClassMessageMissingOpenBracket();
6099 case tok::annot_template_id: {
6100 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
6105 return isTypeConstraintAnnotation() &&
6109 case tok::annot_cxxscope: {
6110 TemplateIdAnnotation *TemplateId =
6118 if (
NextToken().
is(tok::identifier) && TryAnnotateTypeConstraint())
6120 return isTypeConstraintAnnotation() &&
6124 case tok::kw___declspec:
6125 case tok::kw___cdecl:
6126 case tok::kw___stdcall:
6127 case tok::kw___fastcall:
6128 case tok::kw___thiscall:
6129 case tok::kw___regcall:
6130 case tok::kw___vectorcall:
6132 case tok::kw___sptr:
6133 case tok::kw___uptr:
6134 case tok::kw___ptr64:
6135 case tok::kw___ptr32:
6136 case tok::kw___forceinline:
6137 case tok::kw___pascal:
6138 case tok::kw___unaligned:
6139 case tok::kw___ptrauth:
6141 case tok::kw__Nonnull:
6142 case tok::kw__Nullable:
6143 case tok::kw__Nullable_result:
6144 case tok::kw__Null_unspecified:
6146 case tok::kw___kindof:
6148 case tok::kw___private:
6149 case tok::kw___local:
6150 case tok::kw___global:
6151 case tok::kw___constant:
6152 case tok::kw___generic:
6153 case tok::kw___read_only:
6154 case tok::kw___read_write:
6155 case tok::kw___write_only:
6156#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
6157#include "clang/Basic/OpenCLImageTypes.def"
6158#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
6159#include "clang/Basic/HLSLIntangibleTypes.def"
6160#define HLSL_PACKED_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
6161#include "clang/Basic/HLSLPackedTypes.def"
6163 case tok::kw___funcref:
6164 case tok::kw_groupshared:
6167 case tok::kw_nointerpolation:
6168 case tok::kw_linear:
6169 case tok::kw_centroid:
6170 case tok::kw_noperspective:
6171 case tok::kw_sample:
6172 case tok::kw_center:
6173 case tok::kw_row_major:
6174 case tok::kw_column_major:
6177 case tok::kw_private:
6182bool Parser::isConstructorDeclarator(
bool IsUnqualified,
bool DeductionGuide,
6184 const ParsedTemplateInfo *TemplateInfo) {
6185 RevertingTentativeParsingAction TPA(*
this);
6188 if (TemplateInfo && TemplateInfo->TemplateParams)
6191 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
6198 if (Tok.is(tok::identifier)) {
6202 }
else if (Tok.is(tok::annot_template_id)) {
6203 ConsumeAnnotationToken();
6210 SkipCXX11Attributes();
6213 if (Tok.isNot(tok::l_paren)) {
6220 if (Tok.is(tok::r_paren) ||
6221 (Tok.is(tok::ellipsis) &&
NextToken().
is(tok::r_paren))) {
6227 if (isCXX11AttributeSpecifier(
false,
6234 DeclaratorScopeObj DeclScopeObj(*
this, SS);
6236 DeclScopeObj.EnterDeclaratorScope();
6239 ParsedAttributes Attrs(AttrFactory);
6240 MaybeParseMicrosoftAttributes(Attrs);
6249 bool IsConstructor =
false;
6255 if (Tok.is(tok::kw_this)) {
6257 return isDeclarationSpecifier(ITC);
6260 if (isDeclarationSpecifier(ITC))
6261 IsConstructor =
true;
6262 else if (Tok.is(tok::identifier) ||
6263 (Tok.is(tok::annot_cxxscope) &&
NextToken().
is(tok::identifier))) {
6268 if (Tok.is(tok::annot_cxxscope))
6269 ConsumeAnnotationToken();
6275 switch (Tok.getKind()) {
6281 case tok::coloncolon:
6294 SkipCXX11Attributes();
6296 if (DeductionGuide) {
6298 IsConstructor = Tok.is(tok::arrow);
6301 if (Tok.is(tok::colon) || Tok.is(tok::kw_try)) {
6305 IsConstructor =
true;
6307 if (Tok.is(tok::semi) || Tok.is(tok::l_brace)) {
6320 IsConstructor = IsUnqualified;
6325 IsConstructor =
true;
6329 return IsConstructor;
6332void Parser::ParseTypeQualifierListOpt(
6333 DeclSpec &DS,
unsigned AttrReqs,
bool AtomicOrPtrauthAllowed,
6336 if ((AttrReqs & AR_CXX11AttributesParsed) &&
6337 isAllowedCXX11AttributeSpecifier()) {
6338 ParsedAttributes Attrs(AttrFactory);
6339 ParseCXX11Attributes(Attrs);
6343 SourceLocation EndLoc;
6347 const char *PrevSpec =
nullptr;
6348 unsigned DiagID = 0;
6349 SourceLocation Loc = Tok.getLocation();
6351 switch (Tok.getKind()) {
6352 case tok::code_completion:
6354 if (CodeCompletionHandler)
6355 CodeCompletionHandler();
6357 Actions.CodeCompletion().CodeCompleteTypeQualifiers(DS);
6364 case tok::kw_volatile:
6368 case tok::kw_restrict:
6372 case tok::kw___ob_wrap:
6374 Diag(Loc, diag::warn_overflow_behavior_keyword_disabled)
6379 OverflowBehaviorType::OverflowBehaviorKind::Wrap, Loc, PrevSpec,
6382 case tok::kw___ob_trap:
6384 Diag(Loc, diag::warn_overflow_behavior_keyword_disabled)
6389 OverflowBehaviorType::OverflowBehaviorKind::Trap, Loc, PrevSpec,
6392 case tok::kw__Atomic:
6393 if (!AtomicOrPtrauthAllowed)
6394 goto DoneWithTypeQuals;
6395 diagnoseUseOfC11Keyword(Tok);
6401 case tok::kw_private:
6403 goto DoneWithTypeQuals;
6405 case tok::kw___private:
6406 case tok::kw___global:
6407 case tok::kw___local:
6408 case tok::kw___constant:
6409 case tok::kw___generic:
6410 case tok::kw___read_only:
6411 case tok::kw___write_only:
6412 case tok::kw___read_write:
6416 case tok::kw_groupshared:
6420 case tok::kw_nointerpolation:
6421 case tok::kw_linear:
6422 case tok::kw_centroid:
6423 case tok::kw_noperspective:
6424 case tok::kw_sample:
6425 case tok::kw_center:
6431 case tok::kw___ptrauth:
6432 if (!AtomicOrPtrauthAllowed)
6433 goto DoneWithTypeQuals;
6435 EndLoc = PrevTokLocation;
6438 case tok::kw___unaligned:
6442 case tok::kw___uptr:
6447 if (TryKeywordIdentFallback(
false))
6451 case tok::kw___sptr:
6453 case tok::kw___ptr64:
6454 case tok::kw___ptr32:
6455 case tok::kw___cdecl:
6456 case tok::kw___stdcall:
6457 case tok::kw___fastcall:
6458 case tok::kw___thiscall:
6459 case tok::kw___regcall:
6460 case tok::kw___vectorcall:
6461 if (AttrReqs & AR_DeclspecAttributesParsed) {
6465 goto DoneWithTypeQuals;
6467 case tok::kw___funcref:
6471 case tok::kw___pascal:
6472 if (AttrReqs & AR_VendorAttributesParsed) {
6476 goto DoneWithTypeQuals;
6479 case tok::kw__Nonnull:
6480 case tok::kw__Nullable:
6481 case tok::kw__Nullable_result:
6482 case tok::kw__Null_unspecified:
6487 case tok::kw___kindof:
6489 AttributeScopeInfo(),
nullptr, 0,
6494 case tok::kw___attribute:
6495 if (AttrReqs & AR_GNUAttributesParsedAndRejected)
6497 Diag(Tok, diag::err_attributes_not_allowed);
6501 if (AttrReqs & AR_GNUAttributesParsed ||
6502 AttrReqs & AR_GNUAttributesParsedAndRejected) {
6512 DS.
Finish(Actions, Actions.getASTContext().getPrintingPolicy());
6520 assert(PrevSpec &&
"Method did not return previous specifier!");
6521 Diag(Tok, DiagID) << PrevSpec;
6530 Actions.runWithSufficientStackSpace(D.
getBeginLoc(), [&] {
6531 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
6537 if (Kind == tok::star || Kind == tok::caret)
6541 if (Kind == tok::kw_pipe && Lang.OpenCL &&
6542 Lang.getOpenCLCompatibleVersion() >= 200)
6545 if (!Lang.CPlusPlus)
6548 if (Kind == tok::amp)
6556 if (Kind == tok::ampamp)
6567 for (
unsigned Idx = 0; Idx != NumTypes; ++Idx)
6574void Parser::ParseDeclaratorInternal(
Declarator &D,
6575 DirectDeclParseFunction DirectDeclParser) {
6576 if (Diags.hasAllExtensionsSilenced())
6586 (Tok.is(tok::coloncolon) ||
6587 (Tok.is(tok::kw_decltype) &&
NextToken().
is(tok::l_paren)) ||
6588 (Tok.is(tok::identifier) &&
6590 Tok.is(tok::annot_cxxscope))) {
6591 TentativeParsingAction TPA(*
this,
true);
6597 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
6609 Tok.is(tok::star)) {
6613 checkCompoundToken(SS.
getEndLoc(), tok::coloncolon,
6614 CompoundToken::MemberPtr);
6619 DeclSpec DS(AttrFactory);
6620 ParseTypeQualifierListOpt(DS);
6624 Actions.runWithSufficientStackSpace(D.
getBeginLoc(), [&] {
6625 ParseDeclaratorInternal(D, DirectDeclParser);
6639 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
6649 AnnotateScopeToken(SS,
true);
6651 if (DirectDeclParser)
6652 (this->*DirectDeclParser)(D);
6660 DeclSpec DS(AttrFactory);
6661 ParseTypeQualifierListOpt(DS);
6670 if (DirectDeclParser)
6671 (this->*DirectDeclParser)(D);
6680 if (Kind == tok::star || Kind == tok::caret) {
6682 DeclSpec DS(AttrFactory);
6686 unsigned Reqs = AR_CXX11AttributesParsed | AR_DeclspecAttributesParsed |
6688 ? AR_GNUAttributesParsed
6689 : AR_GNUAttributesParsedAndRejected);
6690 ParseTypeQualifierListOpt(DS, Reqs,
true,
6695 Actions.runWithSufficientStackSpace(
6696 D.
getBeginLoc(), [&] { ParseDeclaratorInternal(D, DirectDeclParser); });
6697 if (Kind == tok::star)
6712 DeclSpec DS(AttrFactory);
6716 if (Kind == tok::ampamp)
6717 DiagCompat(Loc, diag_compat::rvalue_reference);
6720 ParseTypeQualifierListOpt(DS);
6729 diag::err_invalid_reference_qualifier_application) <<
"const";
6732 diag::err_invalid_reference_qualifier_application) <<
"volatile";
6736 diag::err_invalid_reference_qualifier_application) <<
"_Atomic";
6740 Actions.runWithSufficientStackSpace(
6741 D.
getBeginLoc(), [&] { ParseDeclaratorInternal(D, DirectDeclParser); });
6748 Diag(InnerChunk.
Loc, diag::err_illegal_decl_reference_to_reference)
6751 Diag(InnerChunk.
Loc, diag::err_illegal_decl_reference_to_reference)
6780void Parser::ParseDirectDeclarator(
Declarator &D) {
6787 return ParseDecompositionDeclarator(D);
6801 ParseOptionalCXXScopeSpecifier(
6803 false, EnteringContext);
6818 if (Actions.ShouldEnterDeclaratorScope(
getCurScope(),
6822 DeclScopeObj.EnterDeclaratorScope();
6829 goto PastIdentifier;
6845 !Actions.containsUnexpandedParameterPacks(D) &&
6853 DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, D);
6863 if (Tok.isOneOf(tok::identifier, tok::kw_operator, tok::annot_template_id,
6867 bool AllowConstructorName;
6868 bool AllowDeductionGuide;
6870 AllowConstructorName =
false;
6871 AllowDeductionGuide =
false;
6875 AllowDeductionGuide =
false;
6883 SourceLocation TemplateKWLoc;
6888 true, AllowConstructorName,
6889 AllowDeductionGuide, &TemplateKWLoc,
6902 DeclScopeObj.EnterDeclaratorScope();
6909 goto PastIdentifier;
6915 diag::err_expected_unqualified_id)
6918 goto PastIdentifier;
6922 "There's a C++-specific check for tok::identifier above");
6923 assert(Tok.getIdentifierInfo() &&
"Not an identifier?");
6924 D.
SetIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
6927 goto PastIdentifier;
6932 bool DiagnoseIdentifier =
false;
6936 DiagnoseIdentifier =
true;
6939 DiagnoseIdentifier =
6947 !isCXX11VirtSpecifier(Tok))
6949 tok::comma, tok::semi, tok::equal, tok::l_brace, tok::kw_try);
6950 if (DiagnoseIdentifier) {
6951 Diag(Tok.getLocation(), diag::err_unexpected_unqualified_id)
6955 goto PastIdentifier;
6959 if (Tok.is(tok::l_paren)) {
6964 RevertingTentativeParsingAction PA(*
this);
6969 goto PastIdentifier;
6976 ParseParenDeclarator(D);
6994 DeclScopeObj.EnterDeclaratorScope();
7005 diag::ext_abstract_pack_declarator_parens);
7007 if (Tok.getKind() == tok::annot_pragma_parser_crash)
7009 if (Tok.is(tok::l_square))
7010 return ParseMisplacedBracketDeclarator(D);
7015 !Tok.isAnnotation() && Tok.getIdentifierInfo() &&
7016 Tok.getIdentifierInfo()->isCPlusPlusKeyword(
getLangOpts())) {
7018 diag::err_expected_member_name_or_semi_objcxx_keyword)
7019 << Tok.getIdentifierInfo()
7022 D.
SetIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
7025 goto PastIdentifier;
7028 diag::err_expected_member_name_or_semi)
7032 if (Tok.getKind() == tok::TokenKind::kw_while) {
7033 Diag(Tok, diag::err_while_loop_outside_of_a_function);
7035 if (Tok.isOneOf(tok::period, tok::arrow))
7036 Diag(Tok, diag::err_invalid_operator_on_type) << Tok.is(tok::arrow);
7039 if (Tok.isAtStartOfLine() && Loc.
isValid())
7040 Diag(PP.getLocForEndOfToken(Loc), diag::err_expected_unqualified_id)
7044 diag::err_expected_unqualified_id)
7049 diag::err_expected_either)
7050 << tok::identifier << tok::l_paren;
7059 "Haven't past the location of the identifier yet?");
7063 MaybeParseCXX11Attributes(D);
7066 if (Tok.is(tok::l_paren)) {
7078 bool IsAmbiguous =
false;
7090 AllowImplicitTypename =
7098 TentativelyDeclaredIdentifiers.push_back(D.
getIdentifier());
7099 bool IsFunctionDecl =
7100 isCXXFunctionDeclarator(&IsAmbiguous, AllowImplicitTypename);
7101 TentativelyDeclaredIdentifiers.pop_back();
7102 if (!IsFunctionDecl)
7105 ParsedAttributes attrs(AttrFactory);
7108 if (IsFunctionDeclaration)
7109 Actions.ActOnStartFunctionDeclarationDeclarator(D,
7110 TemplateParameterDepth);
7111 ParseFunctionDeclarator(D, attrs,
T, IsAmbiguous);
7112 if (IsFunctionDeclaration)
7113 Actions.ActOnFinishFunctionDeclarationDeclarator(D);
7114 PrototypeScope.Exit();
7115 }
else if (Tok.is(tok::l_square)) {
7116 ParseBracketDeclarator(D);
7117 }
else if (Tok.isRegularKeywordAttribute()) {
7119 Diag(Tok, diag::err_keyword_not_allowed) << Tok.getIdentifierInfo();
7124 if (!
T.consumeOpen())
7135 Diag(Tok, diag::err_requires_clause_inside_parens);
7149void Parser::ParseDecompositionDeclarator(
Declarator &D) {
7150 assert(Tok.is(tok::l_square));
7152 TentativeParsingAction PA(*
this);
7157 DiagnoseAndSkipCXX11Attributes();
7161 if (!(Tok.isOneOf(tok::identifier, tok::ellipsis) &&
7163 tok::identifier, tok::l_square, tok::ellipsis)) &&
7164 !(Tok.is(tok::r_square) &&
7167 return ParseMisplacedBracketDeclarator(D);
7170 SourceLocation PrevEllipsisLoc;
7171 SmallVector<DecompositionDeclarator::Binding, 32>
Bindings;
7172 while (Tok.isNot(tok::r_square)) {
7174 if (Tok.is(tok::comma))
7177 if (Tok.is(tok::identifier)) {
7179 Diag(EndLoc, diag::err_expected)
7182 Diag(Tok, diag::err_expected_comma_or_rsquare);
7185 SkipUntil({tok::r_square, tok::comma, tok::identifier, tok::ellipsis},
7187 if (Tok.is(tok::comma))
7189 else if (Tok.is(tok::r_square))
7194 if (isCXX11AttributeSpecifier() !=
7196 DiagnoseAndSkipCXX11Attributes();
7198 SourceLocation EllipsisLoc;
7200 if (Tok.is(tok::ellipsis)) {
7202 if (PrevEllipsisLoc.
isValid()) {
7203 Diag(Tok, diag::err_binding_multiple_ellipses);
7204 Diag(PrevEllipsisLoc, diag::note_previous_ellipsis);
7207 EllipsisLoc = Tok.getLocation();
7208 PrevEllipsisLoc = EllipsisLoc;
7212 if (Tok.isNot(tok::identifier)) {
7213 Diag(Tok, diag::err_expected) << tok::identifier;
7217 IdentifierInfo *II = Tok.getIdentifierInfo();
7218 SourceLocation Loc = Tok.getLocation();
7221 if (Tok.is(tok::ellipsis) && !PrevEllipsisLoc.
isValid()) {
7222 DiagnoseMisplacedEllipsis(Tok.getLocation(), Loc, EllipsisLoc.
isValid(),
7224 EllipsisLoc = Tok.getLocation();
7228 ParsedAttributes Attrs(AttrFactory);
7229 if (isCXX11AttributeSpecifier() !=
7231 DiagCompat(Tok, diag_compat::attrs_on_binding);
7232 MaybeParseCXX11Attributes(Attrs);
7235 Bindings.push_back({II, Loc, std::move(Attrs), EllipsisLoc});
7238 if (Tok.isNot(tok::r_square))
7245 Diag(Tok.getLocation(), diag::ext_decomp_decl_empty);
7253 T.getCloseLocation());
7256void Parser::ParseParenDeclarator(
Declarator &D) {
7260 assert(!D.
isPastIdentifier() &&
"Should be called before passing identifier");
7272 ParsedAttributes attrs(AttrFactory);
7273 bool RequiresArg =
false;
7274 if (Tok.is(tok::kw___attribute)) {
7275 ParseGNUAttributes(attrs);
7283 ParseMicrosoftTypeAttributes(attrs);
7286 if (Tok.is(tok::kw___pascal))
7287 ParseBorlandTypeAttributes(attrs);
7299 }
else if (Tok.is(tok::r_paren) ||
7301 Tok.is(tok::ellipsis) &&
7303 isDeclarationSpecifier(
7305 isCXX11AttributeSpecifier() !=
7325 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
7330 std::move(attrs),
T.getCloseLocation());
7336 DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, D);
7354 ParseFunctionDeclarator(D, attrs,
T,
false, RequiresArg);
7355 PrototypeScope.Exit();
7358void Parser::InitCXXThisScopeForDeclaratorIfRelevant(
7360 std::optional<Sema::CXXThisScopeRAII> &ThisScope) {
7368 bool IsCXX11MemberFunction =
7375 Actions.CurContext->isRecord());
7376 if (!IsCXX11MemberFunction)
7396 ThisScope.emplace(Actions, dyn_cast<CXXRecordDecl>(Actions.CurContext), Q,
7397 IsCXX11MemberFunction);
7400void Parser::ParseFunctionDeclarator(
Declarator &D,
7405 assert(
getCurScope()->isFunctionPrototypeScope() &&
7406 "Should call from a Function scope");
7412 bool HasProto =
false;
7414 SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
7416 SourceLocation EllipsisLoc;
7418 DeclSpec DS(AttrFactory);
7419 bool RefQualifierIsLValueRef =
true;
7420 SourceLocation RefQualifierLoc;
7422 SourceRange ESpecRange;
7423 SmallVector<ParsedType, 2> DynamicExceptions;
7424 SmallVector<SourceRange, 2> DynamicExceptionRanges;
7427 ParsedAttributes FnAttrs(AttrFactory);
7429 SourceLocation TrailingReturnTypeLoc;
7434 SourceLocation StartLoc, LocalEndLoc, EndLoc;
7435 SourceLocation LParenLoc, RParenLoc;
7437 StartLoc = LParenLoc;
7439 if (isFunctionDeclaratorIdentifierList()) {
7441 Diag(Tok, diag::err_argument_required_after_attribute);
7443 ParseFunctionDeclaratorIdentifierList(D, ParamInfo);
7447 LocalEndLoc = RParenLoc;
7452 MaybeParseCXX11Attributes(FnAttrs);
7453 ProhibitAttributes(FnAttrs);
7455 if (Tok.isNot(tok::r_paren))
7456 ParseParameterDeclarationClause(D, FirstArgAttrs, ParamInfo, EllipsisLoc);
7457 else if (RequiresArg)
7458 Diag(Tok, diag::err_argument_required_after_attribute);
7469 LocalEndLoc = RParenLoc;
7478 ParseTypeQualifierListOpt(
7479 DS, AR_NoAttributesParsed,
7482 Actions.CodeCompletion().CodeCompleteFunctionQualifiers(DS, D);
7489 if (ParseRefQualifier(RefQualifierIsLValueRef, RefQualifierLoc))
7490 EndLoc = RefQualifierLoc;
7492 std::optional<Sema::CXXThisScopeRAII> ThisScope;
7493 InitCXXThisScopeForDeclaratorIfRelevant(D, DS, ThisScope);
7510 if (Delayed && Actions.isLibstdcxxEagerExceptionSpecHack(D) &&
7527 ESpecType = tryParseExceptionSpecification(Delayed,
7530 DynamicExceptionRanges,
7532 ExceptionSpecTokens);
7534 EndLoc = ESpecRange.
getEnd();
7538 MaybeParseCXX11Attributes(FnAttrs);
7541 LocalEndLoc = EndLoc;
7543 Diag(Tok, diag::warn_cxx98_compat_trailing_return_type);
7546 LocalEndLoc = Tok.getLocation();
7550 TrailingReturnTypeLoc =
Range.getBegin();
7551 EndLoc =
Range.getEnd();
7554 MaybeParseCXX11Attributes(FnAttrs);
7562 SmallVector<NamedDecl *, 0> DeclsInPrototype;
7565 NamedDecl *ND = dyn_cast<NamedDecl>(D);
7568 DeclsInPrototype.push_back(ND);
7575 llvm::sort(DeclsInPrototype, [](Decl *D1, Decl *D2) {
7583 HasProto, IsAmbiguous, LParenLoc, ParamInfo.data(),
7584 ParamInfo.size(), EllipsisLoc, RParenLoc,
7585 RefQualifierIsLValueRef, RefQualifierLoc,
7587 ESpecType, ESpecRange, DynamicExceptions.data(),
7588 DynamicExceptionRanges.data(), DynamicExceptions.size(),
7589 NoexceptExpr.
isUsable() ? NoexceptExpr.
get() :
nullptr,
7590 ExceptionSpecTokens, DeclsInPrototype, StartLoc,
7591 LocalEndLoc, D, TrailingReturnType, TrailingReturnTypeLoc,
7593 std::move(FnAttrs), EndLoc);
7596bool Parser::ParseRefQualifier(
bool &RefQualifierIsLValueRef,
7598 if (Tok.isOneOf(tok::amp, tok::ampamp)) {
7600 RefQualifierIsLValueRef = Tok.is(tok::amp);
7607bool Parser::isFunctionDeclaratorIdentifierList() {
7609 && Tok.is(tok::identifier)
7610 && !TryAltiVecVectorToken()
7626 && (!Tok.is(tok::eof) &&
7630void Parser::ParseFunctionDeclaratorIdentifierList(
7634 assert(!
getLangOpts().requiresStrictPrototypes() &&
7635 "Cannot parse an identifier list in C23 or C++");
7642 Diag(Tok, diag::ext_ident_list_in_param);
7645 llvm::SmallPtrSet<const IdentifierInfo *, 16> ParamsSoFar;
7649 if (Tok.isNot(tok::identifier)) {
7650 Diag(Tok, diag::err_expected) << tok::identifier;
7657 IdentifierInfo *ParmII = Tok.getIdentifierInfo();
7660 if (Actions.getTypeName(*ParmII, Tok.getLocation(),
getCurScope()))
7661 Diag(Tok, diag::err_unexpected_typedef_ident) << ParmII;
7664 if (!ParamsSoFar.insert(ParmII).second) {
7665 Diag(Tok, diag::err_param_redefinition) << ParmII;
7668 ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII,
7679void Parser::ParseParameterDeclarationClause(
7688 if (
getCurScope()->getFunctionPrototypeDepth() - 1 >
7690 Diag(Tok.getLocation(), diag::err_function_scope_depth_exceeded)
7709 IsACXXFunctionDeclaration) {
7718 LateParsedAttrList LateParamAttrs(
true,
7729 DeclSpec DS(AttrFactory);
7731 ParsedAttributes ArgDeclAttrs(AttrFactory);
7732 ParsedAttributes ArgDeclSpecAttrs(AttrFactory);
7739 ArgDeclSpecAttrs.takeAllPrependingFrom(FirstArgAttrs);
7742 MaybeParseCXX11Attributes(ArgDeclAttrs);
7745 MaybeParseMicrosoftAttributes(ArgDeclSpecAttrs);
7748 SourceLocation DSStart = Tok.getLocation();
7752 SourceLocation ThisLoc;
7756 ParsedTemplateInfo TemplateInfo;
7757 ParseDeclarationSpecifiers(DS, TemplateInfo,
AS_none,
7758 DeclSpecContext::DSC_normal,
7759 nullptr, AllowImplicitTypename);
7772 ParseDeclarator(ParmDeclarator);
7775 ParmDeclarator.SetRangeBegin(ThisLoc);
7778 MaybeParseGNUAttributes(ParmDeclarator, &LateParamAttrs);
7782 if (Tok.is(tok::kw_requires)) {
7787 diag::err_requires_clause_on_declarator_not_declaring_a_function);
7793 const IdentifierInfo *ParmII = ParmDeclarator.getIdentifier();
7797 std::unique_ptr<CachedTokens> DefArgToks;
7801 if (DS.
isEmpty() && ParmDeclarator.getIdentifier() ==
nullptr &&
7802 ParmDeclarator.getNumTypeObjects() == 0) {
7804 Diag(DSStart, diag::err_missing_param);
7811 if (Tok.is(tok::ellipsis) &&
7813 (!ParmDeclarator.getEllipsisLoc().isValid() &&
7814 !Actions.isUnexpandedParameterPackPermitted())) &&
7815 Actions.containsUnexpandedParameterPacks(ParmDeclarator))
7816 DiagnoseMisplacedEllipsisInDeclarator(
ConsumeToken(), ParmDeclarator);
7835 if (!ParmDeclarator.isInvalidType() && !ParmDeclarator.hasName() &&
7836 Tok.isNot(tok::raw_identifier) && !Tok.isAnnotation() &&
7837 Tok.getIdentifierInfo() &&
7838 Tok.getIdentifierInfo()->isKeyword(
getLangOpts())) {
7839 Diag(Tok, diag::err_keyword_as_parameter) << PP.getSpelling(Tok);
7848 Diag(ParmDeclarator.getBeginLoc(),
7849 diag::err_function_parameter_limit_exceeded);
7857 Actions.ActOnParamDeclarator(
getCurScope(), ParmDeclarator, ThisLoc);
7859 DistributeCLateParsedAttrs(Param, &LateParamAttrs);
7864 if (Tok.is(tok::equal)) {
7865 SourceLocation EqualLoc = Tok.getLocation();
7875 ConsumeAndStoreInitializer(*DefArgToks,
7877 Actions.ActOnParamUnparsedDefaultArgument(Param, EqualLoc,
7888 DelayTemplateIdDestructionRAII DontDestructTemplateIds(
7893 EnterExpressionEvaluationContext Eval(
7900 Diag(Tok, diag::compat_cxx11_generalized_initializer_lists);
7901 DefArgResult = ParseBraceInitializer();
7903 if (Tok.is(tok::l_paren) &&
NextToken().
is(tok::l_brace)) {
7904 Diag(Tok, diag::err_stmt_expr_in_default_arg) << 0;
7905 Actions.ActOnParamDefaultArgumentError(Param, EqualLoc,
7915 Actions.ActOnParamDefaultArgumentError(Param, EqualLoc,
7920 Actions.ActOnParamDefaultArgument(Param, EqualLoc,
7921 DefArgResult.
get());
7926 ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII,
7927 ParmDeclarator.getIdentifierLoc(),
7928 Param, std::move(DefArgToks)));
7936 Diag(EllipsisLoc, diag::warn_deprecated_missing_comma_before_ellipsis)
7943 Diag(EllipsisLoc, diag::err_missing_comma_before_ellipsis)
7945 }
else if (ParmDeclarator.getEllipsisLoc().isValid() ||
7946 Actions.containsUnexpandedParameterPacks(ParmDeclarator)) {
7949 SourceLocation ParmEllipsis = ParmDeclarator.getEllipsisLoc();
7950 Diag(EllipsisLoc, diag::warn_misplaced_ellipsis_vararg)
7951 << ParmEllipsis.
isValid() << ParmEllipsis;
7954 diag::note_misplaced_ellipsis_vararg_existing_ellipsis);
7956 Diag(ParmDeclarator.getIdentifierLoc(),
7957 diag::note_misplaced_ellipsis_vararg_add_ellipsis)
7960 << !ParmDeclarator.hasName();
7962 Diag(EllipsisLoc, diag::note_misplaced_ellipsis_vararg_add_comma)
7975 if (!LateParamAttrs.empty())
7976 ParseLexedAttributeList(LateParamAttrs,
nullptr,
false,
7980void Parser::ParseBracketDeclarator(
Declarator &D) {
7981 if (CheckProhibitedCXX11Attribute())
7989 if (Tok.getKind() == tok::r_square) {
7991 ParsedAttributes attrs(AttrFactory);
7992 MaybeParseCXX11Attributes(attrs);
7996 T.getOpenLocation(),
7997 T.getCloseLocation()),
7998 std::move(attrs),
T.getCloseLocation());
8000 }
else if (Tok.getKind() == tok::numeric_constant &&
8007 ParsedAttributes attrs(AttrFactory);
8008 MaybeParseCXX11Attributes(attrs);
8012 T.getOpenLocation(),
8013 T.getCloseLocation()),
8014 std::move(attrs),
T.getCloseLocation());
8016 }
else if (Tok.getKind() == tok::code_completion) {
8018 Actions.CodeCompletion().CodeCompleteBracketDeclarator(
getCurScope());
8023 SourceLocation StaticLoc;
8028 DeclSpec DS(AttrFactory);
8029 ParseTypeQualifierListOpt(DS, AR_CXX11AttributesParsed);
8037 bool isStar =
false;
8048 Diag(StaticLoc, diag::err_unspecified_vla_size_with_static);
8049 StaticLoc = SourceLocation();
8052 }
else if (Tok.isNot(tok::r_square)) {
8069 Diag(StaticLoc, diag::err_unspecified_size_with_static);
8070 StaticLoc = SourceLocation();
8089 isStar, NumElements.
get(),
T.getOpenLocation(),
8090 T.getCloseLocation()),
8094void Parser::ParseMisplacedBracketDeclarator(
Declarator &D) {
8095 assert(Tok.is(tok::l_square) &&
"Missing opening bracket");
8098 SourceLocation StartBracketLoc = Tok.getLocation();
8102 while (Tok.is(tok::l_square)) {
8103 ParseBracketDeclarator(TempDeclarator);
8109 if (Tok.is(tok::semi))
8112 SourceLocation SuggestParenLoc = Tok.getLocation();
8115 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
8120 if (TempDeclarator.getNumTypeObjects() == 0)
8124 bool NeedParens =
false;
8143 SourceLocation EndLoc = PP.getLocForEndOfToken(D.
getEndLoc());
8149 for (
unsigned i = 0, e = TempDeclarator.getNumTypeObjects(); i < e; ++i) {
8150 const DeclaratorChunk &Chunk = TempDeclarator.getTypeObject(i);
8151 D.
AddTypeInfo(Chunk, TempDeclarator.getAttributePool(), SourceLocation());
8156 if (!D.
hasName() && !NeedParens)
8159 SourceLocation EndBracketLoc = TempDeclarator.getEndLoc();
8162 SourceRange BracketRange(StartBracketLoc, EndBracketLoc);
8163 SourceLocation EndLoc = PP.getLocForEndOfToken(D.
getEndLoc());
8166 Diag(EndLoc, diag::err_brackets_go_after_unqualified_id)
8171 EndLoc, CharSourceRange(BracketRange,
true))
8174 Diag(EndLoc, diag::err_brackets_go_after_unqualified_id)
8177 EndLoc, CharSourceRange(BracketRange,
true))
8182void Parser::ParseTypeofSpecifier(
DeclSpec &DS) {
8183 assert(Tok.isOneOf(tok::kw_typeof, tok::kw_typeof_unqual) &&
8184 "Not a typeof specifier");
8186 bool IsUnqual = Tok.is(tok::kw_typeof_unqual);
8187 const IdentifierInfo *II = Tok.getIdentifierInfo();
8189 Diag(Tok.getLocation(), diag::warn_c23_compat_keyword) << Tok.getName();
8193 bool HasParens = Tok.is(tok::l_paren);
8201 SourceRange CastRange;
8203 ParseExprAfterUnaryExprOrTypeTrait(OpTok, isCastExpr, CastTy, CastRange);
8219 const char *PrevSpec =
nullptr;
8226 Actions.getASTContext().getPrintingPolicy()))
8227 Diag(StartLoc, DiagID) << PrevSpec;
8238 Operand = Actions.HandleExprEvaluationContextForTypeof(
Operand.get());
8244 const char *PrevSpec =
nullptr;
8251 Actions.getASTContext().getPrintingPolicy()))
8252 Diag(StartLoc, DiagID) << PrevSpec;
8255void Parser::ParseAtomicSpecifier(
DeclSpec &DS) {
8256 assert(Tok.is(tok::kw__Atomic) &&
NextToken().
is(tok::l_paren) &&
8257 "Not an atomic specifier");
8261 if (
T.consumeOpen())
8265 if (
Result.isInvalid()) {
8273 if (
T.getCloseLocation().isInvalid())
8279 const char *PrevSpec =
nullptr;
8283 Actions.getASTContext().getPrintingPolicy()))
8284 Diag(StartLoc, DiagID) << PrevSpec;
8287bool Parser::TryAltiVecVectorTokenOutOfLine() {
8289 switch (
Next.getKind()) {
8290 default:
return false;
8293 case tok::kw_signed:
8294 case tok::kw_unsigned:
8299 case tok::kw_double:
8302 case tok::kw___bool:
8303 case tok::kw___pixel:
8304 Tok.setKind(tok::kw___vector);
8306 case tok::identifier:
8307 if (
Next.getIdentifierInfo() == Ident_pixel) {
8308 Tok.setKind(tok::kw___vector);
8311 if (
Next.getIdentifierInfo() == Ident_bool ||
8312 Next.getIdentifierInfo() == Ident_Bool) {
8313 Tok.setKind(tok::kw___vector);
8321 const char *&PrevSpec,
unsigned &DiagID,
8323 const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy();
8324 if (Tok.getIdentifierInfo() == Ident_vector) {
8326 switch (
Next.getKind()) {
8329 case tok::kw_signed:
8330 case tok::kw_unsigned:
8335 case tok::kw_double:
8338 case tok::kw___bool:
8339 case tok::kw___pixel:
8342 case tok::identifier:
8343 if (
Next.getIdentifierInfo() == Ident_pixel) {
8347 if (
Next.getIdentifierInfo() == Ident_bool ||
8348 Next.getIdentifierInfo() == Ident_Bool) {
8357 }
else if ((Tok.getIdentifierInfo() == Ident_pixel) &&
8361 }
else if ((Tok.getIdentifierInfo() == Ident_bool) &&
8369TypeResult Parser::ParseTypeFromString(StringRef TypeStr, StringRef Context,
8372 SmallVector<Token, 4> Tokens;
8375 auto &SourceMgr = PP.getSourceManager();
8376 FileID FID = SourceMgr.createFileID(
8377 llvm::MemoryBuffer::getMemBufferCopy(TypeStr, Context),
SrcMgr::C_User,
8381 Lexer L(FID, SourceMgr.getBufferOrFake(FID), PP);
8382 L.setParsingPreprocessorDirective(
true);
8388 Tokens.push_back(Tok);
8389 }
while (Tok.isNot(tok::eod));
8394 Token &EndToken = Tokens.back();
8398 Tokens.push_back(Tok);
8401 PP.EnterTokenStream(Tokens,
false,
8416 (Tok.isNot(tok::eof) || Tok.getEofData() != TypeStr.data())) {
8417 Diag(Tok.getLocation(), diag::err_type_unparsed);
8422 while (Tok.isNot(tok::eof))
8426 if (Tok.is(tok::eof) && Tok.getEofData() == TypeStr.data())
8431void Parser::DiagnoseBitIntUse(
const Token &
Tok) {
8435 assert(Tok.isOneOf(tok::kw__ExtInt, tok::kw__BitInt) &&
8436 "expected either an _ExtInt or _BitInt token!");
8438 SourceLocation Loc = Tok.getLocation();
8439 if (Tok.is(tok::kw__ExtInt)) {
8440 Diag(Loc, diag::warn_ext_int_deprecated)
8446 Diag(Loc, diag::warn_c23_compat_keyword) << Tok.getName();
Defines the clang::ASTContext interface.
Provides definitions for the various language-specific address spaces.
static StringRef normalizeAttrName(StringRef AttrName, StringRef NormalizedScopeName, AttributeCommonInfo::Syntax SyntaxUsed)
static Decl::Kind getKind(const Decl *D)
Defines the C++ template declaration subclasses.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
llvm::MachO::RecordLoc RecordLoc
static StringRef getTriple(const Command &Job)
static bool IsAttributeLateParsedExperimentalExt(const IdentifierInfo &II)
returns true iff attribute is annotated with LateAttrParseExperimentalExt in Attr....
static bool FindLocsWithCommonFileID(Preprocessor &PP, SourceLocation StartLoc, SourceLocation EndLoc)
Check if the a start and end source location expand to the same macro.
static bool IsAttributeArgsParsedInFunctionScope(const IdentifierInfo &II)
Such attributes need their arguments parsed inside a function prototype scope so the arguments can re...
static bool IsAttributeLateParsedStandard(const IdentifierInfo &II)
returns true iff attribute is annotated with LateAttrParseStandard in Attr.td.
static ParsedAttributeArgumentsProperties attributeStringLiteralListArg(const llvm::Triple &T, const IdentifierInfo &II, ParsedAttr::Syntax Syntax, IdentifierInfo *ScopeName)
Determine whether the given attribute has string arguments.
static bool attributeHasStrictIdentifierArgs(const IdentifierInfo &II, ParsedAttr::Syntax Syntax, IdentifierInfo *ScopeName)
Determine whether the given attribute takes a strict identifier argument.
static bool attributeIsTypeArgAttr(const IdentifierInfo &II, ParsedAttr::Syntax Syntax, IdentifierInfo *ScopeName)
Determine whether the given attribute parses a type argument.
static bool attributeTreatsKeywordThisAsIdentifier(const IdentifierInfo &II, ParsedAttr::Syntax Syntax, IdentifierInfo *ScopeName)
Determine whether the given attribute treats kw_this as an identifier.
static bool attributeParsedArgsUnevaluated(const IdentifierInfo &II, ParsedAttr::Syntax Syntax, IdentifierInfo *ScopeName)
Determine whether the given attribute requires parsing its arguments in an unevaluated context or not...
static bool attributeHasIdentifierArg(const llvm::Triple &T, const IdentifierInfo &II, ParsedAttr::Syntax Syntax, IdentifierInfo *ScopeName)
Determine whether the given attribute has an identifier argument.
static bool isValidAfterIdentifierInDeclarator(const Token &T)
isValidAfterIdentifierInDeclaratorAfterDeclSpec - Return true if the specified token is valid after t...
static bool attributeHasVariadicIdentifierArg(const IdentifierInfo &II, ParsedAttr::Syntax Syntax, IdentifierInfo *ScopeName)
Determine whether the given attribute has a variadic identifier argument.
static bool isPipeDeclarator(const Declarator &D)
static SourceLocation getMissingDeclaratorIdLoc(Declarator &D, SourceLocation Loc)
static bool attributeAcceptsExprPack(const IdentifierInfo &II, ParsedAttr::Syntax Syntax, IdentifierInfo *ScopeName)
Determine if an attribute accepts parameter packs.
static void DiagnoseCountAttributedTypeInUnnamedAnon(ParsingDeclSpec &DS, Parser &P)
static bool VersionNumberSeparator(const char Separator)
static bool isPtrOperatorToken(tok::TokenKind Kind, const LangOptions &Lang, DeclaratorContext TheContext)
llvm::SmallVector< std::pair< const MemRegion *, SVal >, 4 > Bindings
static constexpr bool isOneOf()
This file declares semantic analysis for CUDA constructs.
This file declares facilities that support code completion.
This file declares semantic analysis for Objective-C.
This file declares semantic analysis for OpenMP constructs and clauses.
static bool isInvalid(LocType Loc, bool *Invalid)
Defines the clang::TokenKind enum and support functions.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
QualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
Syntax
The style used to specify an attribute.
@ AS_Declspec
__declspec(...)
Kind getParsedKind() const
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ....
SourceLocation getOpenLocation() const
SourceLocation getCloseLocation() const
Represents a C++ nested-name-specifier or a global scope specifier.
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
bool isValid() const
A scope specifier is present, and it refers to a real scope.
SourceLocation getEndLoc() const
bool isSet() const
Deprecated.
bool isInvalid() const
An error occurred during parsing of the scope specifier.
void setTemplateParamLists(ArrayRef< TemplateParameterList * > L)
bool isEmpty() const
No scope specifier.
SourceLocation getBegin() const
Callback handler that receives notifications when performing code completion within the preprocessor.
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
Captures information about "declaration specifiers".
bool isVirtualSpecified() const
bool setFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, ExplicitSpecifier ExplicitSpec, SourceLocation CloseParenLoc)
bool isTypeSpecPipe() const
static const TSCS TSCS___thread
static const TST TST_typeof_unqualType
void setTypeArgumentRange(SourceRange range)
bool SetTypePipe(bool isPipe, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
SourceLocation getPipeLoc() const
static const TST TST_typename
SourceLocation getEndLoc() const LLVM_READONLY
bool hasTypeSpecifier() const
Return true if any type-specifier has been found.
bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec and return false if there was no error.
static const TST TST_char8
static const TST TST_BFloat16
void ClearStorageClassSpecs()
bool SetConstexprSpec(ConstexprSpecKind ConstexprKind, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
static const TSCS TSCS__Thread_local
bool SetTypeSpecWidth(TypeSpecifierWidth W, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec, but return true and ignore the request if ...
bool isNoreturnSpecified() const
TST getTypeSpecType() const
SourceLocation getStorageClassSpecLoc() const
SCS getStorageClassSpec() const
bool setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
SourceLocation getOverflowBehaviorLoc() const
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
SourceRange getSourceRange() const LLVM_READONLY
bool SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
void SetRangeEnd(SourceLocation Loc)
bool SetBitIntType(SourceLocation KWLoc, Expr *BitWidth, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
static const TST TST_auto_type
static const TST TST_interface
static const TST TST_double
static const TST TST_typeofExpr
unsigned getTypeQualifiers() const
getTypeQualifiers - Return a set of TQs.
void SetRangeStart(SourceLocation Loc)
bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
SourceLocation getNoreturnSpecLoc() const
static const TST TST_union
static const TST TST_char
static const TST TST_bool
static const TST TST_char16
SourceLocation getExplicitSpecLoc() const
SourceLocation getFriendSpecLoc() const
SourceLocation getModulePrivateSpecLoc() const
bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
void UpdateTypeRep(ParsedType Rep)
TSCS getThreadStorageClassSpec() const
bool setFunctionSpecNoreturn(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
bool hasAttributes() const
static const TST TST_accum
static const TST TST_half
ParsedAttributes & getAttributes()
bool SetOverflowBehavior(OverflowBehaviorType::OverflowBehaviorKind Kind, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
SourceLocation getConstSpecLoc() const
static const TST TST_ibm128
void addAttributes(const ParsedAttributesView &AL)
Concatenates two attribute lists.
static const TST TST_enum
bool SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
bool isWrapSpecified() const
static const TST TST_float128
void takeAttributesAppendingingFrom(ParsedAttributes &attrs)
void Finish(Sema &S, const PrintingPolicy &Policy)
Finish - This does final analysis of the declspec, issuing diagnostics for things like "_Complex" (la...
bool isInlineSpecified() const
SourceLocation getRestrictSpecLoc() const
static const TST TST_typeof_unqualExpr
static const TST TST_class
bool hasTagDefinition() const
static const TST TST_decimal64
unsigned getParsedSpecifiers() const
Return a bitmask of which flavors of specifiers this DeclSpec includes.
void ClearFunctionSpecs()
bool SetTypeQual(TQ T, SourceLocation Loc)
static const TST TST_wchar
static const TST TST_void
bool isTypeAltiVecVector() const
void ClearConstexprSpec()
static const char * getSpecifierName(DeclSpec::TST T, const PrintingPolicy &Policy)
Turn a type-specifier-type into a string like "_Bool" or "union".
static const TST TST_float
static const TST TST_atomic
static const TST TST_fract
SourceLocation getThreadStorageClassSpecLoc() const
Decl * getRepAsDecl() const
static const TST TST_float16
static const TST TST_unspecified
SourceLocation getAtomicSpecLoc() const
SourceLocation getVirtualSpecLoc() const
SourceLocation getConstexprSpecLoc() const
CXXScopeSpec & getTypeSpecScope()
bool isEmpty() const
isEmpty - Return true if this declaration specifier is completely empty: no tokens were parsed in the...
SourceLocation getTypeSpecTypeLoc() const
static const TSCS TSCS_thread_local
bool setFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
static const TST TST_decimal32
bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
TypeSpecifierWidth getTypeSpecWidth() const
static const TST TST_char32
bool setFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
static const TST TST_decimal128
bool isTypeSpecOwned() const
SourceLocation getInlineSpecLoc() const
SourceLocation getUnalignedSpecLoc() const
static const TST TST_int128
SourceLocation getVolatileSpecLoc() const
FriendSpecified isFriendSpecified() const
bool hasExplicitSpecifier() const
bool setFunctionSpecForceInline(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
bool hasConstexprSpecifier() const
static const TST TST_typeofType
bool SetTypeSpecSign(TypeSpecifierSign S, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
static const TST TST_auto
@ PQ_StorageClassSpecifier
ConstexprSpecKind getConstexprSpecifier() const
static const TST TST_struct
Decl - This represents one declaration (or definition), e.g.
SourceLocation getEndLoc() const LLVM_READONLY
bool isInvalidDecl() const
SourceLocation getLocation() const
Information about one declarator, including the parsed type information and the identifier.
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
bool isPastIdentifier() const
isPastIdentifier - Return true if we have parsed beyond the point where the name would appear.
void SetRangeBegin(SourceLocation Loc)
SetRangeBegin - Set the start of the source range to Loc, unless it's invalid.
const DeclaratorChunk & getTypeObject(unsigned i) const
Return the specified TypeInfo from this declarator.
void setCommaLoc(SourceLocation CL)
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
SourceLocation getIdentifierLoc() const
void SetIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Set the name of this declarator to be the given identifier.
bool mayOmitIdentifier() const
mayOmitIdentifier - Return true if the identifier is either optional or not allowed.
SourceLocation getEndLoc() const LLVM_READONLY
bool mayBeFollowedByCXXDirectInit() const
mayBeFollowedByCXXDirectInit - Return true if the declarator can be followed by a C++ direct initiali...
bool hasGroupingParens() const
void setDecompositionBindings(SourceLocation LSquareLoc, MutableArrayRef< DecompositionDeclarator::Binding > Bindings, SourceLocation RSquareLoc)
Set the decomposition bindings for this declarator.
void setInvalidType(bool Val=true)
void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc, const LateParsedAttrList &LateAttrs={})
AddTypeInfo - Add a chunk to this declarator.
TemplateParameterList * getInventedTemplateParameterList() const
The template parameter list generated from the explicit template parameters along with any invented t...
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
bool mayHaveIdentifier() const
mayHaveIdentifier - Return true if the identifier is either optional or required.
void setGroupingParens(bool flag)
SourceLocation getEllipsisLoc() const
DeclaratorContext getContext() const
SourceLocation getBeginLoc() const LLVM_READONLY
void setTrailingRequiresClause(Expr *TRC)
Sets a trailing requires clause for this declarator.
void setHasInitializer(bool Val=true)
UnqualifiedId & getName()
Retrieve the name specified by this declarator.
void setTemplateParameterLists(ArrayRef< TemplateParameterList * > TPLs)
Sets the template parameter lists that preceded the declarator.
bool isFirstDeclarator() const
bool hasTrailingRequiresClause() const
Determine whether a trailing requires clause was written in this declarator.
const CXXScopeSpec & getCXXScopeSpec() const
getCXXScopeSpec - Return the C++ scope specifier (global scope or nested-name-specifier) that is part...
bool hasName() const
hasName - Whether this declarator has a name, which might be an identifier (accessible via getIdentif...
ArrayRef< TemplateParameterList * > getTemplateParameterLists() const
The template parameter lists that preceded the declarator.
bool isFunctionDeclaratorAFunctionDeclaration() const
Return true if a function declarator at this position would be a function declaration.
void clear()
Reset the contents of this Declarator.
void setAsmLabel(Expr *E)
void ExtendWithDeclSpec(const DeclSpec &DS)
ExtendWithDeclSpec - Extend the declarator source range to include the given declspec,...
void SetRangeEnd(SourceLocation Loc)
SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.
void setExtension(bool Val=true)
bool isInvalidType() const
SourceRange getSourceRange() const LLVM_READONLY
Get the source range that spans this declarator.
bool isDecompositionDeclarator() const
Return whether this declarator is a decomposition declarator.
bool isPrototypeContext() const
void setEllipsisLoc(SourceLocation EL)
const IdentifierInfo * getIdentifier() const
static FixItHint CreateInsertionFromRange(SourceLocation InsertionLoc, CharSourceRange FromRange, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code from FromRange at a specific location.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
One of these records is kept for each identifier that is lexed.
tok::TokenKind getTokenID() const
If this is a source-language token (e.g.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
StringRef getName() const
Return the actual identifier string.
A simple pair of identifier info and location.
SourceLocation getLoc() const
void setIdentifierInfo(IdentifierInfo *Ident)
IdentifierInfo * getIdentifierInfo() const
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool requiresStrictPrototypes() const
Returns true if functions without prototypes or functions with an identifier list (aka K&R C function...
std::string getOpenCLVersionString() const
Return the OpenCL C or C++ for OpenCL language name and version as a string.
unsigned getOpenCLCompatibleVersion() const
Return the OpenCL version that kernel language is compatible with.
bool lateAttrParseExperimentalExtOnly() const
returns true iff the attribute to be parsed should only be late parsed if it is annotated with LateAt...
static StringRef getSourceText(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts, bool *Invalid=nullptr)
Returns a string for the source that the range encompasses.
static bool isAtStartOfMacroExpansion(SourceLocation loc, const SourceManager &SM, const LangOptions &LangOpts, SourceLocation *MacroBegin=nullptr)
Returns true if the given MacroID location points at the first token of the macro expansion.
static bool isAtEndOfMacroExpansion(SourceLocation loc, const SourceManager &SM, const LangOptions &LangOpts, SourceLocation *MacroEnd=nullptr)
Returns true if the given MacroID location points at the last token of the macro expansion.
static std::optional< Token > findNextToken(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeComments=false)
Finds the token that comes right after the given location.
static bool getRawToken(SourceLocation Loc, Token &Result, const SourceManager &SM, const LangOptions &LangOpts, bool IgnoreWhiteSpace=false)
Relex the token at the specified location.
UnresolvedSetImpl::iterator iterator
static constexpr unsigned getMaxFunctionScopeDepth()
ParsedAttr - Represents a syntactic attribute.
unsigned getMaxArgs() const
static const ParsedAttributesView & none()
void prepend(iterator B, iterator E)
void addAtEnd(ParsedAttr *newAttr)
void remove(ParsedAttr *ToBeRemoved)
ParsedAttributes - A collection of parsed attributes.
void takeOneFrom(ParsedAttributes &Other, ParsedAttr *PA)
ParsedAttr * addNewPropertyAttr(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, IdentifierInfo *getterId, IdentifierInfo *setterId, ParsedAttr::Form formUsed)
Add microsoft __delspec(property) attribute.
ParsedAttr * addNewTypeAttr(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, ParsedType typeArg, ParsedAttr::Form formUsed, SourceLocation ellipsisLoc=SourceLocation())
Add an attribute with a single type argument.
ParsedAttr * addNewTypeTagForDatatype(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, IdentifierLoc *argumentKind, ParsedType matchingCType, bool layoutCompatible, bool mustBeNull, ParsedAttr::Form form)
Add type_tag_for_datatype attribute.
void takeAllAppendingFrom(ParsedAttributes &Other)
ParsedAttr * addNew(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form, SourceLocation ellipsisLoc=SourceLocation())
Add attribute with expression arguments.
ParseScope - Introduces a new scope for parsing.
Parser - This implements a parser for the C family of languages.
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeName, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName.
bool TryAnnotateTypeOrScopeToken(ImplicitTypenameContext AllowImplicitTypename=ImplicitTypenameContext::No, bool IsAddressOfOperand=false)
TryAnnotateTypeOrScopeToken - If the current token position is on a typename (possibly qualified in C...
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
SourceLocation getEndOfPreviousToken() const
DiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagId)
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
Sema & getActions() const
static TypeResult getTypeAnnotation(const Token &Tok)
getTypeAnnotation - Read a parsed type out of an annotation token.
ExprResult ParseConstraintLogicalOrExpression(bool IsTrailingRequiresClause)
Parse a constraint-logical-or-expression.
ExprResult ParseConstantExpressionInExprEvalContext(TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
SmallVector< Stmt *, 24 > StmtVector
A SmallVector of statements.
bool ParseUnqualifiedId(CXXScopeSpec &SS, ParsedType ObjectType, bool ObjectHadErrors, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, SourceLocation *TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
friend class ColonProtectionRAIIObject
DeclGroupPtrTy ParseOpenACCDirectiveDecl(AccessSpecifier &AS, ParsedAttributes &Attrs, DeclSpec::TST TagType, Decl *TagDecl)
Parse OpenACC directive on a declaration.
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type.
friend struct LateParsedTypeAttribute
const Token & GetLookAheadToken(unsigned N)
GetLookAheadToken - This peeks ahead N tokens and returns that token without consuming any tokens.
ExprResult ParseConstantExpression()
bool TryConsumeToken(tok::TokenKind Expected)
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
Scope * getCurScope() const
ExprResult ParseArrayBoundExpression()
friend struct LateParsedAttribute
const TargetInfo & getTargetInfo() const
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
void SkipMalformedDecl()
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a s...
const Token & getCurToken() const
void ExitScope()
ExitScope - Pop a scope off the scope stack.
const LangOptions & getLangOpts() const
friend class ParenBraceBracketBalancer
@ StopBeforeMatch
Stop skipping at specified token, but don't skip the token itself.
@ StopAtCodeCompletion
Stop at code completion.
@ StopAtSemi
Stop skipping at semicolon.
ExprResult ParseUnevaluatedStringLiteralExpression()
ObjCContainerDecl * getObjCDeclContext() const
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
ExprResult ParseAssignmentExpression(TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
Parse an expr that doesn't include (top-level) commas.
friend class BalancedDelimiterTracker
SmallVector< TemplateParameterList *, 4 > TemplateParameterLists
bool TryAnnotateCXXScopeToken(bool EnteringContext=false)
TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only annotates C++ scope specifiers and ...
A class for parsing a DeclSpec.
A class for parsing a declarator.
A class for parsing a field declarator.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
SourceManager & getSourceManager() const
const LangOptions & getLangOpts() const
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
void addAddressSpace(LangAS space)
static Qualifiers fromCVRUMask(unsigned CVRU)
Represents a struct/union/class.
field_range fields() const
bool isClassScope() const
isClassScope - Return true if this scope is a class/struct/union scope.
unsigned getFlags() const
getFlags - Return the flags for this scope.
@ FunctionPrototypeScope
This is a scope that corresponds to the parameters within a function prototype.
@ BlockScope
This is a scope that corresponds to a block/closure object.
@ FriendScope
This is a scope of friend declaration.
@ ControlScope
The controlling scope in a if/switch/while/for statement.
@ AtCatchScope
This is a scope that corresponds to the Objective-C @catch statement.
@ TemplateParamScope
This is a scope that corresponds to the template parameters of a C++ template.
@ CompoundStmtScope
This is a compound statement scope.
@ ClassScope
The scope of a struct/union/class definition.
@ FunctionDeclarationScope
This is a scope that corresponds to the parameters within a function prototype for a function declara...
@ FnScope
This indicates that the scope corresponds to a function, which means that labels are set here.
@ EnumScope
This scope corresponds to an enum.
@ DeclScope
This is a scope that can contain a declaration.
@ CTCK_InitGlobalVar
Unknown context.
ParserCompletionContext
Describes the context in which code completion occurs.
@ PCC_LocalDeclarationSpecifiers
Code completion occurs within a sequence of declaration specifiers within a function,...
@ PCC_MemberTemplate
Code completion occurs following one or more template headers within a class.
@ PCC_Class
Code completion occurs within a class, struct, or union.
@ PCC_ObjCImplementation
Code completion occurs within an Objective-C implementation or category implementation.
@ PCC_Namespace
Code completion occurs at top-level or namespace context.
@ PCC_Template
Code completion occurs following one or more template headers.
NameClassificationKind getKind() const
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
@ ConstantEvaluated
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
@ PotentiallyEvaluatedIfUsed
The current expression is potentially evaluated, but any declarations referenced inside that expressi...
void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl)
ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an initializer for the declaratio...
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
UIntTy getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it.
This class handles loading and caching of source files into memory.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
A RAII object used to temporarily suppress access-like checking.
Represents the declaration of a struct/union/class/enum.
Token - This structure provides full information about a lexed token.
IdentifierInfo * getIdentifierInfo() const
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
static Token createEof(SourceLocation Loc=SourceLocation(), const void *Data=nullptr)
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
void * getAnnotationValue() const
tok::TokenKind getKind() const
bool isOneOf(Ts... Ks) const
void setLocation(SourceLocation L)
void startToken()
Reset all flags to cleared.
void setSemiMissing(bool Missing=true)
static constexpr int FunctionTypeNumParamsLimit
SourceLocation EndLocation
The location of the last token that describes this unqualified-id.
SourceRange getSourceRange() const LLVM_READONLY
Return the source range that covers this unqualified-id.
SourceLocation StartLocation
The location of the first token that describes this unqualified-id, which will be the location of the...
UnqualifiedIdKind getKind() const
Determine what kind of name we have.
Declaration of a variable template.
static const char * getSpecifierName(Specifier VS)
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Attr > attr
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
const char * getKeywordSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple keyword and contextual keyword tokens like 'int' and 'dynamic_cast'...
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
bool isPragmaAnnotation(TokenKind K)
Return true if this is an annotation token representing a pragma.
Top level wrappers for InstallAPI frontend operations.
TypeSpecifierType
Specifies the kind of type.
bool doesKeywordAttributeTakeArgs(tok::TokenKind Kind)
bool isa(CodeGen::Address addr)
@ NotAttributeSpecifier
This is not an attribute specifier.
@ AttributeSpecifier
This should be treated as an attribute-specifier.
@ InvalidAttributeSpecifier
The next tokens are '[[', but this is not an attribute-specifier.
@ ExpectedParameterOrImplicitObjectParameter
MutableArrayRef< TemplateParameterList * > MultiTemplateParamsArg
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
int hasAttribute(AttributeCommonInfo::Syntax Syntax, llvm::StringRef ScopeName, llvm::StringRef AttrName, const TargetInfo &Target, const LangOptions &LangOpts, bool CheckPlugins)
Return the version number associated with the attribute if we recognize and implement the attribute s...
llvm::PointerUnion< Expr *, IdentifierLoc * > ArgsUnion
A union of the various pointer types that can be passed to an ParsedAttr as an argument.
@ IK_TemplateId
A template-id, e.g., f<int>.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
ActionResult< Decl * > DeclResult
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
llvm::SmallVector< ArgsUnion, 12U > ArgsVector
Language
The language for the input, used to select and validate the language standard and possible actions.
@ Result
The result type of a method or function.
ActionResult< ParsedType > TypeResult
const FunctionProtoType * T
@ Template
We are parsing a template declaration.
@ ExplicitSpecialization
We are parsing an explicit specialization.
@ ExplicitInstantiation
We are parsing an explicit instantiation.
@ NonTemplate
We are not parsing a template at all.
LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
@ FunctionTemplate
The name was classified as a function template name.
@ Keyword
The name has been typo-corrected to a keyword.
@ DependentNonType
The name denotes a member of a dependent type that could not be resolved.
@ UndeclaredTemplate
The name was classified as an ADL-only function template name.
@ NonType
The name was classified as a specific non-type, non-template declaration.
@ Unknown
This name is not a type or template in this context, but might be something else.
@ Error
Classification failed; an error has been produced.
@ Type
The name was classified as a type.
@ TypeTemplate
The name was classified as a template whose specializations are types.
@ Concept
The name was classified as a concept name.
@ OverloadSet
The name was classified as an overload set, and an expression representing that overload set has been...
@ UndeclaredNonType
The name was classified as an ADL-only function name.
@ VarTemplate
The name was classified as a variable template name.
LangAS
Defines the address space values used by the address space qualifier of QualType.
@ TNK_Type_template
The name refers to a template whose specialization produces a type.
@ TNK_Dependent_template_name
The name refers to a dependent template name:
@ TNK_Concept_template
The name refers to a concept.
@ TNK_Undeclared_template
Lookup for the name failed, but we're assuming it was a template name anyway.
void takeAndConcatenateAttrs(ParsedAttributes &First, ParsedAttributes &&Second)
Consumes the attributes from Second and concatenates them at the end of First.
U cast(CodeGen::Address addr)
SmallVector< Token, 4 > CachedTokens
A set of tokens that has been cached for later parsing.
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
ActionResult< Expr * > ExprResult
@ Parens
New-expression has a C++98 paren-delimited initializer.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_None
no exception specification
ActionResult< Stmt * > StmtResult
VersionTuple Version
The version number at which the change occurred.
SourceLocation KeywordLoc
The location of the keyword indicating the kind of change.
SourceRange VersionRange
The source range covering the version number.
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc, SourceLocation ConstQualLoc, SourceLocation VolatileQualLoc, SourceLocation RestrictQualLoc, SourceLocation AtomicQualLoc, SourceLocation UnalignedQualLoc, SourceLocation OverflowBehaviorLoc={}, bool OverflowBehaviorIsWrap=false)
Return a DeclaratorChunk for a pointer.
static DeclaratorChunk getBlockPointer(unsigned TypeQuals, SourceLocation Loc)
Return a DeclaratorChunk for a block.
static DeclaratorChunk getFunction(bool HasProto, bool IsAmbiguous, SourceLocation LParenLoc, ParamInfo *Params, unsigned NumParams, SourceLocation EllipsisLoc, SourceLocation RParenLoc, bool RefQualifierIsLvalueRef, SourceLocation RefQualifierLoc, SourceLocation MutableLoc, ExceptionSpecificationType ESpecType, SourceRange ESpecRange, ParsedType *Exceptions, SourceRange *ExceptionRanges, unsigned NumExceptions, Expr *NoexceptExpr, CachedTokens *ExceptionSpecTokens, ArrayRef< NamedDecl * > DeclsInPrototype, SourceLocation LocalRangeBegin, SourceLocation LocalRangeEnd, Declarator &TheDeclarator, TypeResult TrailingReturnType=TypeResult(), SourceLocation TrailingReturnTypeLoc=SourceLocation(), DeclSpec *MethodQualifiers=nullptr)
DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
static DeclaratorChunk getPipe(unsigned TypeQuals, SourceLocation Loc)
Return a DeclaratorChunk for a block.
static DeclaratorChunk getArray(unsigned TypeQuals, bool isStatic, bool isStar, Expr *NumElts, SourceLocation LBLoc, SourceLocation RBLoc)
Return a DeclaratorChunk for an array.
SourceLocation Loc
Loc - The place where this type was defined.
static DeclaratorChunk getMemberPointer(const CXXScopeSpec &SS, unsigned TypeQuals, SourceLocation StarLoc, SourceLocation EndLoc)
enum clang::DeclaratorChunk::@340323374315200305336204205154073066142310370142 Kind
static DeclaratorChunk getParen(SourceLocation LParenLoc, SourceLocation RParenLoc)
Return a DeclaratorChunk for a paren.
static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc, bool lvalue)
Return a DeclaratorChunk for a reference.
Contains the lexed tokens of an attribute with arguments that may reference member variables and so n...
SmallVector< ParmVarDecl *, 4 > ProtoParams
Parameters of the prototype the attribute was written on, kept because late parsing runs after their ...
IdentifierInfo & AttrName
SourceLocation AttrNameLoc
SmallVector< Decl *, 2 > Decls
A late-parsed attribute that will be applied as a type attribute.
void ParseInto(ParsedAttributes &OutAttrs)
Parse this late-parsed type attribute and store results in OutAttrs.
bool isStringLiteralArg(unsigned I) const
ExpressionKind
Describes whether we are in an expression constext which we have to handle differently.
bool hasInvalidName() const
const IdentifierInfo * Name
FIXME: Temporarily stores the name of a specialization.
TemplateNameKind Kind
The kind of template that Template refers to.
bool hasInvalidArgs() const