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().CPlusPlus29
2647 ? diag::DefaultableFunctionKinds::Cxx29
2648 : getLangOpts().CPlusPlus20
2649 ? diag::DefaultableFunctionKinds::Cxx20
2650 : diag::DefaultableFunctionKinds::Default);
2652 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2654 if (
Tok.
is(tok::code_completion)) {
2656 Actions.CodeCompletion().CodeCompleteInitializer(getCurScope(),
2658 Actions.FinalizeDeclaration(ThisDecl);
2668 Diag(EqualLoc, diag::err_single_decl_assign_in_for_range)
2672 FRI->ColonLoc = EqualLoc;
2674 FRI->RangeExpr =
Init;
2677 if (
Init.isInvalid()) {
2679 StopTokens.push_back(tok::comma);
2682 StopTokens.push_back(tok::r_paren);
2683 SkipUntil(StopTokens, StopAtSemi | StopBeforeMatch);
2684 Actions.ActOnInitializerError(ThisDecl);
2686 Actions.AddInitializerToDecl(ThisDecl,
Init.get(),
2691 case InitKind::CXXDirect: {
2698 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2700 auto ThisVarDecl = dyn_cast_or_null<VarDecl>(ThisDecl);
2701 auto RunSignatureHelp = [&]() {
2703 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
2704 ThisVarDecl->getType()->getCanonicalTypeInternal(),
2707 CalledSignatureHelp =
true;
2708 return PreferredType;
2710 auto SetPreferredType = [&] {
2711 PreferredType.enterFunctionArgument(
Tok.
getLocation(), RunSignatureHelp);
2714 llvm::function_ref<void()> ExpressionStarts;
2720 ExpressionStarts = SetPreferredType;
2723 bool SawError = ParseExpressionList(Exprs, ExpressionStarts);
2726 if (ThisVarDecl && PP.isCodeCompletionReached() && !CalledSignatureHelp) {
2727 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
2728 ThisVarDecl->getType()->getCanonicalTypeInternal(),
2731 CalledSignatureHelp =
true;
2733 Actions.ActOnInitializerError(ThisDecl);
2734 SkipUntil(tok::r_paren, StopAtSemi);
2740 T.getCloseLocation(),
2742 Actions.AddInitializerToDecl(ThisDecl,
Initializer.get(),
2747 case InitKind::CXXBraced: {
2749 Diag(
Tok, diag::compat_cxx11_generalized_initializer_lists);
2751 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2756 if (
Init.isInvalid()) {
2757 Actions.ActOnInitializerError(ThisDecl);
2759 Actions.AddInitializerToDecl(ThisDecl,
Init.get(),
true);
2762 case InitKind::Uninitialized: {
2763 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2764 Actions.ActOnUninitializedDecl(ThisDecl);
2769 Actions.FinalizeDeclaration(ThisDecl);
2770 return OuterDecl ? OuterDecl : ThisDecl;
2773void Parser::ParseSpecifierQualifierList(
2776 ParsedTemplateInfo TemplateInfo;
2778 assert((!LateAttrs ||
2779 llvm::none_of(*LateAttrs, llvm::IsaPred<LateParsedTypeAttribute>)) &&
2780 "caller's late-attribute list must not hold type attributes yet");
2785 ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC, LateAttrs,
2786 AllowImplicitTypename);
2791 Diag(Tok, diag::err_expected_type);
2794 Diag(Tok, diag::err_typename_requires_specqual);
2805 diag::err_typename_invalid_storageclass);
2849 return T.isOneOf(tok::l_square, tok::l_paren, tok::r_paren, tok::semi,
2850 tok::comma, tok::equal, tok::kw_asm, tok::l_brace,
2855 ParsedTemplateInfo &TemplateInfo,
2858 assert(Tok.is(tok::identifier) &&
"should have identifier");
2860 SourceLocation Loc = Tok.getLocation();
2880 if (!isTypeSpecifier(DSC) &&
getLangOpts().isImplicitIntAllowed() &&
2898 AnnotateScopeToken(*SS,
false);
2907 if (
ParsedType T = Actions.ActOnMSVCUnknownTypeName(
2908 *Tok.getIdentifierInfo(), Tok.getLocation(),
2909 DSC == DeclSpecContext::DSC_template_type_arg)) {
2910 const char *PrevSpec;
2913 Actions.getASTContext().getPrintingPolicy());
2926 if (SS ==
nullptr) {
2927 const char *TagName =
nullptr, *FixitTagName =
nullptr;
2930 switch (Actions.isTagName(*Tok.getIdentifierInfo(),
getCurScope())) {
2933 TagName=
"enum" ; FixitTagName =
"enum " ; TagKind=tok::kw_enum ;
break;
2935 TagName=
"union" ; FixitTagName =
"union " ;TagKind=tok::kw_union ;
break;
2937 TagName=
"struct"; FixitTagName =
"struct ";TagKind=tok::kw_struct;
break;
2939 TagName=
"__interface"; FixitTagName =
"__interface ";
2940 TagKind=tok::kw___interface;
break;
2942 TagName=
"class" ; FixitTagName =
"class " ;TagKind=tok::kw_class ;
break;
2946 IdentifierInfo *TokenName = Tok.getIdentifierInfo();
2947 LookupResult
R(Actions, TokenName, SourceLocation(),
2950 Diag(Loc, diag::err_use_of_tag_name_without_tag)
2951 << TokenName << TagName <<
getLangOpts().CPlusPlus
2957 Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
2958 << TokenName << TagName;
2962 if (TagKind == tok::kw_enum)
2963 ParseEnumSpecifier(Loc, DS, TemplateInfo, AS,
2964 DeclSpecContext::DSC_normal);
2966 ParseClassSpecifier(TagKind, Loc, DS, TemplateInfo, AS,
2968 DeclSpecContext::DSC_normal, Attrs);
2975 if (!isTypeSpecifier(DSC) && (!SS || DSC == DeclSpecContext::DSC_top_level ||
2976 DSC == DeclSpecContext::DSC_class)) {
2980 case tok::l_paren: {
2987 TentativeParsingAction PA(*
this);
2989 TPResult TPR = TryParseDeclarator(
false);
2992 if (TPR != TPResult::False) {
3000 if (DSC == DeclSpecContext::DSC_class ||
3001 (DSC == DeclSpecContext::DSC_top_level && SS)) {
3002 IdentifierInfo *II = Tok.getIdentifierInfo();
3003 if (Actions.isCurrentClassNameTypo(II, SS)) {
3004 Diag(Loc, diag::err_constructor_bad_name)
3005 << Tok.getIdentifierInfo() << II
3007 Tok.setIdentifierInfo(II);
3025 AnnotateScopeToken(*SS,
false);
3039 IdentifierInfo *II = Tok.getIdentifierInfo();
3041 Actions.DiagnoseUnknownTypeName(II, Loc,
getCurScope(), SS,
T,
3047 const char *PrevSpec;
3050 Actions.getASTContext().getPrintingPolicy());
3055 }
else if (II != Tok.getIdentifierInfo()) {
3068 if (IsTemplateName) {
3069 SourceLocation LAngle, RAngle;
3070 TemplateArgList Args;
3071 ParseTemplateIdAfterTemplateName(
true, LAngle, Args, RAngle);
3080Parser::DeclSpecContext
3084 return DeclSpecContext::DSC_class;
3086 return DeclSpecContext::DSC_top_level;
3088 return DeclSpecContext::DSC_template_param;
3090 return DeclSpecContext::DSC_template_arg;
3092 return DeclSpecContext::DSC_template_type_arg;
3095 return DeclSpecContext::DSC_trailing;
3098 return DeclSpecContext::DSC_alias_declaration;
3100 return DeclSpecContext::DSC_association;
3102 return DeclSpecContext::DSC_type_specifier;
3104 return DeclSpecContext::DSC_condition;
3106 return DeclSpecContext::DSC_conv_operator;
3108 return DeclSpecContext::DSC_new;
3123 return DeclSpecContext::DSC_normal;
3126 llvm_unreachable(
"Missing DeclaratorContext case");
3133 if (isTypeIdInParens()) {
3134 SourceLocation TypeLoc = Tok.getLocation();
3136 SourceRange TypeRange(Start, Tok.getLocation());
3137 if (Actions.ActOnAlignasTypeArgument(KWName, Ty, TypeLoc, TypeRange))
3154 assert(Tok.isOneOf(tok::kw_alignas, tok::kw__Alignas) &&
3155 "Not an alignment-specifier!");
3162 if (
T.expectAndConsume())
3167 SourceLocation EllipsisLoc;
3169 ParseAlignArgument(PP.getSpelling(KWTok),
T.getOpenLocation(),
3178 *EndLoc =
T.getCloseLocation();
3185 ArgExprs.push_back(ArgExpr.
get());
3186 Attrs.
addNew(KWName, KWLoc, AttributeScopeInfo(), ArgExprs.data(), 1, Kind,
3191void Parser::DistributeCLateParsedAttrs(
Decl *Dcl,
3197 for (
auto *LateAttr : *LateAttrs) {
3198 if (LateAttr->Decls.empty())
3199 LateAttr->addDecl(Dcl);
3205 assert(Tok.is(tok::kw___ptrauth));
3207 IdentifierInfo *KwName = Tok.getIdentifierInfo();
3211 if (
T.expectAndConsume())
3221 ArgExprs.push_back(ER.
get());
3225 SourceLocation EndLoc =
T.getCloseLocation();
3227 if (ArgExprs.empty() || ArgExprs.size() > 3) {
3228 Diag(KwLoc, diag::err_ptrauth_qualifier_bad_arg_count);
3232 Attrs.
addNew(KwName, SourceRange(KwLoc, EndLoc), AttributeScopeInfo(),
3233 ArgExprs.data(), ArgExprs.size(),
3234 ParsedAttr::Form::Keyword(
false,
3244 assert(Tok.is(tok::l_paren) &&
"Attribute arg list not starting with '('");
3249 if (Tok.is(tok::r_paren)) {
3250 Diag(Tok.getLocation(), diag::err_argument_required_after_attribute);
3257 using ExpressionKind =
3259 EnterExpressionEvaluationContext EC(
3261 ExpressionKind::EK_AttrArgument);
3269 ArgExprs.push_back(ArgExpr.
get());
3272 ASTContext &Ctx = Actions.getASTContext();
3278 Attrs.
addNew(&AttrName, SourceRange(AttrNameLoc,
Parens.getCloseLocation()),
3279 AttributeScopeInfo(), ArgExprs.data(), ArgExprs.size(), Form);
3282ExprResult Parser::ParseExtIntegerArgument() {
3283 assert(Tok.isOneOf(tok::kw__ExtInt, tok::kw__BitInt) &&
3284 "Not an extended int type");
3288 if (
T.expectAndConsume())
3297 if(
T.consumeClose())
3304 DeclSpecContext DSContext,
3308 bool EnteringContext = (DSContext == DeclSpecContext::DSC_class ||
3309 DSContext == DeclSpecContext::DSC_top_level);
3312 (Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw_decltype) ||
3313 (Tok.is(tok::annot_template_id) &&
NextToken().
is(tok::coloncolon))) &&
3319 bool HasScope = Tok.is(tok::annot_cxxscope);
3321 Token AfterScope = HasScope ?
NextToken() : Tok;
3325 bool MightBeDeclarator =
true;
3326 if (Tok.isOneOf(tok::kw_typename, tok::annot_typename)) {
3328 MightBeDeclarator =
false;
3329 }
else if (AfterScope.
is(tok::annot_template_id)) {
3332 TemplateIdAnnotation *Annot =
3335 MightBeDeclarator =
false;
3336 }
else if (AfterScope.
is(tok::identifier)) {
3341 if (
Next.isOneOf(tok::star, tok::amp, tok::ampamp, tok::identifier,
3342 tok::annot_cxxscope, tok::coloncolon)) {
3344 MightBeDeclarator = false;
3345 }
else if (HasScope) {
3350 Actions.RestoreNestedNameSpecifierAnnotation(
3351 Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS);
3353 Sema::NameClassification Classification = Actions.ClassifyName(
3356 switch (Classification.
getKind()) {
3362 llvm_unreachable(
"typo correction is not possible here");
3370 MightBeDeclarator =
false;
3385 if (MightBeDeclarator)
3388 const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy();
3390 diag::err_expected_after)
3401 ParsedTemplateInfo NotATemplate;
3402 ParseDeclarationSpecifiers(DS, NotATemplate, AS, DSContext, LateAttrs);
3406void Parser::ParseDeclarationSpecifiers(
3420 if (DSContext == DeclSpecContext::DSC_conv_operator)
3421 DSContext = DeclSpecContext::DSC_type_specifier;
3423 bool EnteringContext = (DSContext == DeclSpecContext::DSC_class ||
3424 DSContext == DeclSpecContext::DSC_top_level);
3425 bool AttrsLastTime =
false;
3426 ParsedAttributes attrs(AttrFactory);
3428 PrintingPolicy Policy = Actions.getPrintingPolicy();
3431 bool isStorageClass =
false;
3432 const char *PrevSpec =
nullptr;
3433 unsigned DiagID = 0;
3437 SourceLocation ConsumedEnd;
3446 if (
getLangOpts().MSVCCompat && Tok.is(tok::kw__Atomic) &&
3449 Tok.setKind(tok::identifier);
3451 SourceLocation Loc = Tok.getLocation();
3454 auto handleOpenCLImageKW = [&] (StringRef Ext,
TypeSpecifierType ImageTypeSpec) {
3458 Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
3459 Tok.setKind(tok::identifier);
3468 bool IsTemplateSpecOrInst =
3472 switch (Tok.getKind()) {
3474 if (Tok.isRegularKeywordAttribute())
3479 ProhibitAttributes(attrs);
3482 for (
const ParsedAttr &PA : attrs) {
3483 if (!PA.isCXX11Attribute() && !PA.isC23Attribute() &&
3484 !PA.isRegularKeywordAttribute())
3492 if (PA.getKind() == ParsedAttr::AT_VectorSize) {
3493 Diag(PA.getLoc(), diag::warn_attribute_ignored) << PA;
3500 if (PA.isTypeAttr() && PA.getKind() != ParsedAttr::AT_LifetimeBound &&
3501 PA.getKind() != ParsedAttr::AT_AnyX86NoCfCheck)
3504 if (PA.getKind() == ParsedAttr::AT_LifetimeBound)
3505 Diag(PA.getLoc(), diag::err_attribute_wrong_decl_type)
3506 << PA << PA.isRegularKeywordAttribute()
3509 Diag(PA.getLoc(), diag::err_attribute_not_type_attr)
3510 << PA << PA.isRegularKeywordAttribute();
3519 DS.
Finish(Actions, Policy);
3523 case tok::kw__Alignas:
3524 diagnoseUseOfC11Keyword(Tok);
3526 case tok::kw_alignas:
3532 if (Tok.getKind() == tok::kw_alignas)
3533 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName();
3539 if (!isAllowedCXX11AttributeSpecifier())
3540 goto DoneWithDeclSpec;
3543 ProhibitAttributes(attrs);
3548 attrs.Range = SourceRange();
3550 ParseCXX11Attributes(attrs);
3551 AttrsLastTime =
true;
3554 case tok::code_completion: {
3558 bool AllowNonIdentifiers
3564 bool AllowNestedNameSpecifiers
3565 = DSContext == DeclSpecContext::DSC_top_level ||
3569 Actions.CodeCompletion().CodeCompleteDeclSpec(
3570 getCurScope(), DS, AllowNonIdentifiers, AllowNestedNameSpecifiers);
3576 CCC = DSContext == DeclSpecContext::DSC_class
3579 else if (DSContext == DeclSpecContext::DSC_class)
3583 else if (CurParsedObjCImpl)
3587 Actions.CodeCompletion().CodeCompleteOrdinaryName(
getCurScope(), CCC);
3591 case tok::coloncolon:
3597 goto DoneWithDeclSpec;
3599 if (Tok.is(tok::coloncolon))
3600 goto DoneWithDeclSpec;
3603 case tok::annot_cxxscope: {
3605 goto DoneWithDeclSpec;
3608 if (TemplateInfo.TemplateParams)
3610 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
3611 Tok.getAnnotationRange(),
3617 TemplateIdAnnotation *TemplateId =
Next.is(tok::annot_template_id)
3618 ? takeTemplateIdAnnotation(
Next)
3624 ConsumeAnnotationToken();
3638 if ((DSContext == DeclSpecContext::DSC_top_level ||
3639 DSContext == DeclSpecContext::DSC_class) &&
3642 isConstructorDeclarator(
false,
3649 goto DoneWithDeclSpec;
3653 ConsumeAnnotationToken();
3654 assert(Tok.is(tok::annot_template_id) &&
3655 "ParseOptionalCXXScopeSpecifier not working");
3656 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
3666 ConsumeAnnotationToken();
3670 if (
Next.is(tok::annot_typename)) {
3672 ConsumeAnnotationToken();
3675 Tok.getAnnotationEndLoc(),
3676 PrevSpec, DiagID,
T, Policy);
3680 ConsumeAnnotationToken();
3684 Next.is(tok::annot_template_id) &&
3685 static_cast<TemplateIdAnnotation *
>(
Next.getAnnotationValue())
3688 ConsumeAnnotationToken();
3689 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
3693 if (
Next.isNot(tok::identifier))
3694 goto DoneWithDeclSpec;
3699 if ((DSContext == DeclSpecContext::DSC_top_level ||
3700 DSContext == DeclSpecContext::DSC_class) &&
3703 isConstructorDeclarator(
false,
3707 goto DoneWithDeclSpec;
3713 SuppressAccessChecks SAC(*
this, IsTemplateSpecOrInst);
3717 false,
false,
nullptr,
3720 isClassTemplateDeductionContext(DSContext), AllowImplicitTypename);
3722 if (IsTemplateSpecOrInst)
3730 if (TryAnnotateTypeConstraint())
3731 goto DoneWithDeclSpec;
3732 if (Tok.isNot(tok::annot_cxxscope) ||
3736 ConsumeAnnotationToken();
3737 ParsedAttributes Attrs(AttrFactory);
3738 if (ParseImplicitInt(DS, &SS, TemplateInfo, AS, DSContext, Attrs)) {
3739 if (!Attrs.
empty()) {
3740 AttrsLastTime =
true;
3741 attrs.takeAllAppendingFrom(Attrs);
3745 goto DoneWithDeclSpec;
3749 ConsumeAnnotationToken();
3752 DiagID, TypeRep, Policy);
3762 case tok::annot_typename: {
3766 goto DoneWithDeclSpec;
3775 ConsumeAnnotationToken();
3780 case tok::kw___is_signed:
3792 TryKeywordIdentFallback(
true);
3795 goto DoneWithDeclSpec;
3798 case tok::kw___super:
3799 case tok::kw_decltype:
3800 case tok::identifier:
3806 goto DoneWithDeclSpec;
3812 if (!
getLangOpts().DeclSpecKeyword && Tok.is(tok::identifier) &&
3813 Tok.getIdentifierInfo()->getName() ==
"__declspec") {
3814 Diag(Loc, diag::err_ms_attributes_not_enabled);
3824 if (
T.consumeOpen()) {
3825 assert(
false &&
"Not a left paren?");
3840 SuppressAccessChecks SAC(*
this, IsTemplateSpecOrInst);
3844 if (IsTemplateSpecOrInst)
3848 if (IsTemplateSpecOrInst)
3851 goto DoneWithDeclSpec;
3854 if (!Tok.is(tok::identifier))
3859 if (TryAltiVecToken(DS, Loc, PrevSpec, DiagID,
isInvalid))
3865 goto DoneWithDeclSpec;
3867 if (DSContext == DeclSpecContext::DSC_objc_method_result &&
3868 isObjCInstancetype()) {
3869 ParsedType TypeRep = Actions.ObjC().ActOnObjCInstanceType(Loc);
3872 DiagID, TypeRep, Policy);
3884 Actions.isCurrentClassName(*Tok.getIdentifierInfo(),
getCurScope()) &&
3885 isConstructorDeclarator(
true,
3888 goto DoneWithDeclSpec;
3891 *Tok.getIdentifierInfo(), Tok.getLocation(),
getCurScope(),
nullptr,
3892 false,
false,
nullptr,
false,
false,
3893 isClassTemplateDeductionContext(DSContext));
3898 if (TryAnnotateTypeConstraint())
3899 goto DoneWithDeclSpec;
3900 if (Tok.isNot(tok::identifier))
3902 ParsedAttributes Attrs(AttrFactory);
3903 if (ParseImplicitInt(DS,
nullptr, TemplateInfo, AS, DSContext, Attrs)) {
3904 if (!Attrs.
empty()) {
3905 AttrsLastTime =
true;
3906 attrs.takeAllAppendingFrom(Attrs);
3910 goto DoneWithDeclSpec;
3917 (DSContext == DeclSpecContext::DSC_class ||
3918 DSContext == DeclSpecContext::DSC_top_level) &&
3919 Actions.isDeductionGuideName(
getCurScope(), *Tok.getIdentifierInfo(),
3920 Tok.getLocation(), SS) &&
3921 isConstructorDeclarator(
true,
3923 goto DoneWithDeclSpec;
3926 DiagID, TypeRep, Policy);
3937 SourceLocation NewEndLoc;
3938 TypeResult NewTypeRep = parseObjCTypeArgsAndProtocolQualifiers(
3953 case tok::annot_template_id: {
3954 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
3965 TemplateId =
nullptr;
3973 tok::kw_volatile, tok::kw_restrict, tok::amp,
3975 Diag(Loc, diag::err_placeholder_expected_auto_or_decltype_auto)
3979 TemplateId, Policy);
3983 goto DoneWithDeclSpec;
3985 if (TemplateId && !
isInvalid && Actions.CheckTypeConstraint(TemplateId))
3986 TemplateId =
nullptr;
3988 ConsumeAnnotationToken();
3989 SourceLocation AutoLoc = Tok.getLocation();
3992 if (Tracker.consumeOpen()) {
3994 Diag(Tok, diag::err_expected) << tok::l_paren;
3998 Tracker.skipToEnd();
3999 Diag(Tok, diag::err_placeholder_expected_auto_or_decltype_auto)
4004 Tracker.consumeClose();
4007 ConsumedEnd = Tok.getLocation();
4012 DiagID, TemplateId, Policy);
4015 TemplateId, Policy);
4024 goto DoneWithDeclSpec;
4032 isConstructorDeclarator(
true,
4035 goto DoneWithDeclSpec;
4040 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
4045 case tok::kw___attribute:
4046 case tok::kw___declspec:
4047 ParseAttributes(PAKM_GNU | PAKM_Declspec, DS.
getAttributes(), LateAttrs);
4051 case tok::kw___forceinline: {
4053 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
4054 SourceLocation AttrNameLoc = Tok.getLocation();
4056 nullptr, 0, tok::kw___forceinline);
4060 case tok::kw___unaligned:
4066 case tok::kw___ptrauth:
4070 case tok::kw___sptr:
4071 case tok::kw___uptr:
4072 case tok::kw___ptr64:
4073 case tok::kw___ptr32:
4075 case tok::kw___cdecl:
4076 case tok::kw___stdcall:
4077 case tok::kw___fastcall:
4078 case tok::kw___thiscall:
4079 case tok::kw___regcall:
4080 case tok::kw___vectorcall:
4084 case tok::kw___funcref:
4089 case tok::kw___pascal:
4094 case tok::kw___kernel:
4099 case tok::kw___noinline__:
4104 case tok::kw__Nonnull:
4105 case tok::kw__Nullable:
4106 case tok::kw__Nullable_result:
4107 case tok::kw__Null_unspecified:
4112 case tok::kw___kindof:
4114 AttributeScopeInfo(),
nullptr, 0,
4120 case tok::kw_typedef:
4122 PrevSpec, DiagID, Policy);
4123 isStorageClass =
true;
4125 case tok::kw_extern:
4127 Diag(Tok, diag::ext_thread_before) <<
"extern";
4129 PrevSpec, DiagID, Policy);
4130 isStorageClass =
true;
4132 case tok::kw___private_extern__:
4134 Loc, PrevSpec, DiagID, Policy);
4135 isStorageClass =
true;
4137 case tok::kw_static:
4139 Diag(Tok, diag::ext_thread_before) <<
"static";
4141 PrevSpec, DiagID, Policy);
4142 isStorageClass =
true;
4146 auto IsTypedefName = [&](
const Token &
T) {
4147 if (!
T.is(tok::identifier))
4149 IdentifierInfo *II =
T.getIdentifierInfo();
4153 LookupResult
R(Actions, II,
T.getLocation(),
4157 R.suppressDiagnostics();
4160 auto MayBeTypeSpecifier = [&]() {
4171 if (isKnownToBeTypeSpecifier(
T))
4190 if (MayBeTypeSpecifier()) {
4192 PrevSpec, DiagID, Policy);
4194 Diag(Tok, diag::ext_auto_storage_class)
4201 PrevSpec, DiagID, Policy);
4202 isStorageClass =
true;
4204 case tok::kw___auto_type:
4205 Diag(Tok, diag::ext_auto_type);
4209 case tok::kw_register:
4211 PrevSpec, DiagID, Policy);
4212 isStorageClass =
true;
4214 case tok::kw_mutable:
4216 PrevSpec, DiagID, Policy);
4217 isStorageClass =
true;
4219 case tok::kw___thread:
4222 isStorageClass =
true;
4224 case tok::kw_thread_local:
4226 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName();
4235 Loc, PrevSpec, DiagID);
4236 isStorageClass =
true;
4238 case tok::kw__Thread_local:
4239 diagnoseUseOfC11Keyword(Tok);
4241 Loc, PrevSpec, DiagID);
4242 isStorageClass =
true;
4246 case tok::kw_inline:
4249 case tok::kw_virtual:
4253 !
getActions().getOpenCLOptions().isAvailableOption(
4255 DiagID = diag::err_openclcxx_virtual_function;
4256 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
4259 DiagID = diag::err_hlsl_virtual_function;
4260 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
4266 case tok::kw_explicit: {
4267 SourceLocation ExplicitLoc = Loc;
4268 SourceLocation CloseParenLoc;
4270 ConsumedEnd = ExplicitLoc;
4272 if (Tok.is(tok::l_paren)) {
4274 DiagCompat(Tok.getLocation(), diag_compat::explicit_bool);
4276 ExprResult ExplicitExpr(
static_cast<Expr *
>(
nullptr));
4278 Tracker.consumeOpen();
4280 EnterExpressionEvaluationContext ConstantEvaluated(
4284 ConsumedEnd = Tok.getLocation();
4285 if (ExplicitExpr.isUsable()) {
4286 CloseParenLoc = Tok.getLocation();
4287 Tracker.consumeClose();
4289 Actions.ActOnExplicitBoolSpecifier(ExplicitExpr.get());
4291 Tracker.skipToEnd();
4293 Diag(Tok.getLocation(), diag::warn_cxx20_compat_explicit_bool);
4297 ExplicitSpec, CloseParenLoc);
4300 case tok::kw__Noreturn:
4301 diagnoseUseOfC11Keyword(Tok);
4306 case tok::kw_friend:
4307 if (DSContext == DeclSpecContext::DSC_class) {
4314 DiagID = diag::err_friend_invalid_in_context;
4320 case tok::kw___module_private__:
4325 case tok::kw_constexpr:
4327 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName();
4331 case tok::kw_consteval:
4335 case tok::kw_constinit:
4343 Diag(Tok, diag::err_unknown_typename) << Tok.getName();
4347 goto DoneWithDeclSpec;
4358 PrevSpec, DiagID, Policy);
4360 case tok::kw___int64:
4362 PrevSpec, DiagID, Policy);
4364 case tok::kw_signed:
4368 case tok::kw_unsigned:
4372 case tok::kw__Complex:
4374 Diag(Tok, diag::ext_c99_feature) << Tok.getName();
4378 case tok::kw__Imaginary:
4380 Diag(Tok, diag::ext_c99_feature) << Tok.getName();
4396 case tok::kw__ExtInt:
4397 case tok::kw__BitInt: {
4398 DiagnoseBitIntUse(Tok);
4403 ConsumedEnd = PrevTokLocation;
4406 case tok::kw___int128:
4414 case tok::kw___bf16:
4422 case tok::kw_double:
4426 case tok::kw__Float16:
4430 case tok::kw__Accum:
4432 "This keyword is only used when fixed point types are enabled "
4433 "with `-ffixed-point`");
4437 case tok::kw__Fract:
4439 "This keyword is only used when fixed point types are enabled "
4440 "with `-ffixed-point`");
4446 "This keyword is only used when fixed point types are enabled "
4447 "with `-ffixed-point`");
4450 case tok::kw___float128:
4454 case tok::kw___ibm128:
4458 case tok::kw_wchar_t:
4462 case tok::kw_char8_t:
4466 case tok::kw_char16_t:
4470 case tok::kw_char32_t:
4476 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName();
4480 Diag(Tok, diag::ext_c99_feature) << Tok.getName();
4482 if (Tok.is(tok::kw_bool) &&
4486 DiagID = diag::err_bool_redeclaration;
4488 Tok.setKind(tok::identifier);
4495 case tok::kw__Decimal32:
4499 case tok::kw__Decimal64:
4503 case tok::kw__Decimal128:
4507 case tok::kw___vector:
4510 case tok::kw___pixel:
4513 case tok::kw___bool:
4518 getLangOpts().getOpenCLCompatibleVersion() < 200) {
4521 Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
4522 Tok.setKind(tok::identifier);
4523 goto DoneWithDeclSpec;
4525 DiagID = diag::err_opencl_unknown_type_specifier;
4526 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
4532#define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
4533#define IMAGE_WRITE_TYPE(Type, Id, Ext)
4534#define IMAGE_READ_TYPE(ImgType, Id, Ext) \
4535 case tok::kw_##ImgType##_t: \
4536 if (!handleOpenCLImageKW(Ext, DeclSpec::TST_##ImgType##_t)) \
4537 goto DoneWithDeclSpec; \
4539#include "clang/Basic/OpenCLImageTypes.def"
4540 case tok::kw___unknown_anytype:
4542 PrevSpec, DiagID, Policy);
4547 case tok::kw_struct:
4548 case tok::kw___interface:
4549 case tok::kw_union: {
4556 ParsedAttributes Attributes(AttrFactory);
4557 ParseClassSpecifier(Kind, Loc, DS, TemplateInfo, AS,
4558 EnteringContext, DSContext, Attributes);
4562 if (!Attributes.empty()) {
4563 AttrsLastTime =
true;
4564 attrs.takeAllAppendingFrom(Attributes);
4572 ParseEnumSpecifier(Loc, DS, TemplateInfo, AS, DSContext);
4580 case tok::kw_volatile:
4584 case tok::kw_restrict:
4588 case tok::kw___ob_wrap:
4590 Diag(Loc, diag::warn_overflow_behavior_keyword_disabled)
4595 OverflowBehaviorType::OverflowBehaviorKind::Wrap, Loc, PrevSpec,
4598 case tok::kw___ob_trap:
4600 Diag(Loc, diag::warn_overflow_behavior_keyword_disabled)
4605 OverflowBehaviorType::OverflowBehaviorKind::Trap, Loc, PrevSpec,
4610 case tok::kw_typename:
4613 goto DoneWithDeclSpec;
4615 if (!Tok.is(tok::kw_typename))
4620 case tok::kw_typeof:
4621 case tok::kw_typeof_unqual:
4622 ParseTypeofSpecifier(DS);
4625 case tok::annot_decltype:
4626 ParseDecltypeSpecifier(DS);
4629 case tok::annot_pack_indexing_type:
4630 ParsePackIndexingType(DS);
4633 case tok::annot_pragma_pack:
4637 case tok::annot_pragma_ms_pragma:
4638 HandlePragmaMSPragma();
4641 case tok::annot_pragma_ms_vtordisp:
4642 HandlePragmaMSVtorDisp();
4645 case tok::annot_pragma_ms_pointers_to_members:
4646 HandlePragmaMSPointersToMembers();
4649 case tok::annot_pragma_export:
4650 HandlePragmaExport();
4653#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
4654#include "clang/Basic/BuiltinTraits.inc"
4658 if (!MaybeParseTypeTransformTypeSpecifier(DS))
4659 goto ParseIdentifier;
4662 case tok::kw__Atomic:
4667 diagnoseUseOfC11Keyword(Tok);
4669 ParseAtomicSpecifier(DS);
4677 case tok::kw___generic:
4682 if (!Actions.getLangOpts().OpenCLGenericAddressSpace) {
4683 DiagID = diag::err_opencl_unknown_type_specifier;
4684 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
4689 case tok::kw_private:
4693 goto DoneWithDeclSpec;
4695 case tok::kw___private:
4696 case tok::kw___global:
4697 case tok::kw___local:
4698 case tok::kw___constant:
4700 case tok::kw___read_only:
4701 case tok::kw___write_only:
4702 case tok::kw___read_write:
4705 case tok::kw_row_major:
4706 case tok::kw_column_major:
4707 case tok::kw_nointerpolation:
4708 case tok::kw_linear:
4709 case tok::kw_centroid:
4710 case tok::kw_noperspective:
4711 case tok::kw_sample:
4712 case tok::kw_center:
4713 case tok::kw_groupshared:
4721#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
4722 case tok::kw_##Name: \
4723 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, \
4726#include "clang/Basic/HLSLIntangibleTypes.def"
4728#define HLSL_PACKED_TYPE(Name, Id, SingletonId) \
4729 case tok::kw_##Name: \
4730 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, \
4733#include "clang/Basic/HLSLPackedTypes.def"
4740 goto DoneWithDeclSpec;
4742 SourceLocation StartLoc = Tok.getLocation();
4743 SourceLocation EndLoc;
4745 if (
Type.isUsable()) {
4747 PrevSpec, DiagID,
Type.get(),
4748 Actions.getASTContext().getPrintingPolicy()))
4749 Diag(StartLoc, DiagID) << PrevSpec;
4765 assert(PrevSpec &&
"Method did not return previous specifier!");
4768 if (DiagID == diag::ext_duplicate_declspec ||
4769 DiagID == diag::ext_warn_duplicate_declspec ||
4770 DiagID == diag::err_duplicate_declspec)
4771 Diag(Loc, DiagID) << PrevSpec
4774 else if (DiagID == diag::err_opencl_unknown_type_specifier) {
4778 Diag(Loc, DiagID) << PrevSpec;
4781 if (DiagID != diag::err_bool_redeclaration && ConsumedEnd.
isInvalid())
4785 AttrsLastTime =
false;
4797 if (!RD || !RD->getName().empty() || RD->isAnonymousStructOrUnion())
4800 for (
auto *I : RD->decls()) {
4801 auto *VD = dyn_cast<ValueDecl>(I);
4809 for (
const auto &DD : CAT->dependent_decls()) {
4810 if (!RD->containsDecl(DD.getDecl())) {
4811 P.
Diag(VD->getBeginLoc(), diag::err_count_attr_param_not_in_same_struct)
4812 << DD.getDecl() << CAT->getKind() << CAT->isArrayType();
4813 P.
Diag(DD.getDecl()->getBeginLoc(),
4814 diag::note_flexible_array_counted_by_attr_field)
4821void Parser::ParseStructDeclaration(
4826 if (Tok.is(tok::kw___extension__)) {
4828 ExtensionRAIIObject O(Diags);
4830 return ParseStructDeclaration(DS, FieldsCallback, LateFieldAttrs);
4834 ParsedAttributes Attrs(AttrFactory);
4835 MaybeParseCXX11Attributes(Attrs);
4838 ParseSpecifierQualifierList(DS);
4842 if (Tok.is(tok::semi)) {
4847 ProhibitAttributes(Attrs);
4848 RecordDecl *AnonRecord =
nullptr;
4849 Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(
4851 assert(!AnonRecord &&
"Did not expect anonymous struct or union here");
4857 bool FirstDeclarator =
true;
4858 SourceLocation CommaLoc;
4860 ParsingFieldDeclarator DeclaratorInfo(*
this, DS, Attrs);
4861 DeclaratorInfo.D.setCommaLoc(CommaLoc);
4864 if (!FirstDeclarator) {
4867 DiagnoseAndSkipCXX11Attributes();
4868 MaybeParseGNUAttributes(DeclaratorInfo.D);
4869 DiagnoseAndSkipCXX11Attributes();
4874 if (Tok.isNot(tok::colon)) {
4877 ParseDeclarator(DeclaratorInfo.D);
4879 DeclaratorInfo.D.SetIdentifier(
nullptr, Tok.getLocation());
4891 DeclaratorInfo.BitfieldSize = Res.
get();
4895 MaybeParseGNUAttributes(DeclaratorInfo.D, LateFieldAttrs);
4898 Decl *
Field = FieldsCallback(DeclaratorInfo);
4900 DistributeCLateParsedAttrs(Field, LateFieldAttrs);
4907 FirstDeclarator =
false;
4915 LPA.
Toks.push_back(AttrEnd);
4919 LPA.
Toks.push_back(Tok);
4920 PP.EnterTokenStream(LPA.
Toks,
true,
4927 ParsedAttributes Attrs(AttrFactory);
4931 SourceLocation(), ParsedAttr::Form::GNU(),
4936 while (Tok.isNot(tok::eof))
4940 if (Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData())
4948 assert(LA.
Decls.size() <= 1 &&
4949 "late field attribute expects to have at most one declaration.");
4951 ParsedAttributes Attrs = ParseLexedAttributeTokens(LA);
4955void Parser::CompleteLateParsedTypeAttributes(
4958 std::unique_ptr<LateParsedTypeAttribute> LTA(RawLTA);
4960 BoundsAttributedType *BATy = LTA->Info.TypeToComplete;
4961 if (!BATy || Actions.isLateParsedBoundsTypeRejected(BATy))
4964 ArrayRef<Decl *> Fields = LTA->Decls;
4966 AttributeFactory AF;
4967 ParsedAttributes Attrs(AF);
4968 ParseLexedTypeAttribute(*LTA, Attrs);
4973 assert(Attrs.
size() == 1);
4975 Expr *Arg = Attrs[0].getArgAsExpr(0);
4979 assert(!Fields.empty());
4980 for (Decl *FD : Fields)
4981 Valid &= Actions.ActOnLateParsedTypeAttrArgument(
4985 Attrs[0].setUsedAsTypeAttr();
4987 Attrs[0].setInvalid();
4989 LateTypeAttrs.clear();
4994 Self->ParseLexedTypeAttribute(*
this, OutAttrs);
4999 LateParsedAttrList::iterator It =
5007 From.erase(It, From.end());
5012 PrettyDeclStackTraceEntry CrashInfo(Actions.Context, TagDecl,
RecordLoc,
5013 "parsing struct/union body");
5017 if (
T.consumeOpen())
5021 Actions.ActOnTagStartDefinition(
getCurScope(), TagDecl);
5025 LateParsedAttrList LateFieldAttrs(
true,
5029 while (!tryParseMisplacedModuleImport() && Tok.isNot(tok::r_brace) &&
5030 Tok.isNot(tok::eof)) {
5034 if (Tok.is(tok::semi)) {
5040 if (Tok.isOneOf(tok::kw__Static_assert, tok::kw_static_assert)) {
5041 SourceLocation DeclEnd;
5042 ParseStaticAssertDeclaration(DeclEnd);
5046 if (Tok.is(tok::annot_pragma_pack)) {
5051 if (Tok.is(tok::annot_pragma_align)) {
5052 HandlePragmaAlign();
5056 if (Tok.isOneOf(tok::annot_pragma_openmp, tok::annot_attr_openmp)) {
5059 ParsedAttributes Attrs(AttrFactory);
5060 (void)ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs);
5064 if (Tok.is(tok::annot_pragma_openacc)) {
5066 ParsedAttributes Attrs(AttrFactory);
5072 Diag(Tok.getLocation(), diag::err_pragma_misplaced_in_decl)
5074 TagType, Actions.getASTContext().getPrintingPolicy());
5075 ConsumeAnnotationToken();
5079 if (!Tok.is(tok::at)) {
5080 auto CFieldCallback = [&](ParsingFieldDeclarator &FD) -> Decl * {
5084 FD.D.getDeclSpec().getSourceRange().getBegin(),
5085 FD.D, FD.BitfieldSize);
5091 ParsingDeclSpec DS(*
this);
5092 ParseStructDeclaration(DS, CFieldCallback, &LateFieldAttrs);
5095 if (!Tok.isObjCAtKeyword(tok::objc_defs)) {
5096 Diag(Tok, diag::err_unexpected_at);
5101 ExpectAndConsume(tok::l_paren);
5102 if (!Tok.is(tok::identifier)) {
5103 Diag(Tok, diag::err_expected) << tok::identifier;
5107 SmallVector<Decl *, 16> Fields;
5108 Actions.ObjC().ActOnDefs(
getCurScope(), TagDecl, Tok.getLocation(),
5109 Tok.getIdentifierInfo(), Fields);
5111 ExpectAndConsume(tok::r_paren);
5117 if (Tok.is(tok::r_brace)) {
5118 ExpectAndConsume(tok::semi, diag::ext_expected_semi_decl_list);
5122 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list);
5131 ParsedAttributes attrs(AttrFactory);
5133 MaybeParseGNUAttributes(attrs, &LateFieldAttrs);
5135 SmallVector<Decl *, 32> FieldDecls(TagDecl->
fields());
5138 T.getOpenLocation(),
T.getCloseLocation(), attrs);
5141 ParseLexedAttributeList(LateFieldAttrs,
nullptr,
false,
5144 Actions.ActOnTagFinishDefinition(
getCurScope(), TagDecl,
T.getRange());
5148 const ParsedTemplateInfo &TemplateInfo,
5151 if (Tok.is(tok::code_completion)) {
5160 ParsedAttributes attrs(AttrFactory);
5161 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec | PAKM_CXX11, attrs);
5163 SourceLocation ScopedEnumKWLoc;
5164 bool IsScopedUsingClassTag =
false;
5169 IsScopedUsingClassTag = Tok.is(tok::kw_class);
5174 ProhibitAttributes(attrs);
5177 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec | PAKM_CXX11, attrs);
5186 bool shouldDelayDiagsInTag =
5189 SuppressAccessChecks diagsFromTag(*
this, shouldDelayDiagsInTag);
5192 AllowDefiningTypeSpec AllowEnumSpecifier =
5194 bool CanBeOpaqueEnumDeclaration =
5195 DS.
isEmpty() && isOpaqueEnumDeclarationContext(DSC);
5198 (AllowEnumSpecifier == AllowDefiningTypeSpec::Yes ||
5199 CanBeOpaqueEnumDeclaration);
5203 CXXScopeSpec InvalidDeclScope;
5211 if (ParseOptionalCXXScopeSpecifier(Spec,
nullptr,
5216 if (Spec.
isSet() && Tok.isNot(tok::identifier)) {
5217 Diag(Tok, diag::err_expected) << tok::identifier;
5219 if (Tok.isNot(tok::l_brace)) {
5227 SS = std::move(Spec);
5231 if (Tok.isNot(tok::identifier) && Tok.isNot(tok::l_brace) &&
5232 Tok.isNot(tok::colon)) {
5233 Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace;
5242 IdentifierInfo *Name =
nullptr;
5243 SourceLocation NameLoc;
5244 if (Tok.is(tok::identifier)) {
5245 Name = Tok.getIdentifierInfo();
5249 if (!Name && ScopedEnumKWLoc.
isValid()) {
5252 Diag(Tok, diag::err_scoped_enum_missing_identifier);
5253 ScopedEnumKWLoc = SourceLocation();
5254 IsScopedUsingClassTag =
false;
5259 if (shouldDelayDiagsInTag)
5260 diagsFromTag.done();
5263 SourceRange BaseRange;
5265 bool CanBeBitfield =
5268 auto IsCXXTypeAhead = [
this]() {
5269 RevertingTentativeParsingAction PA(*
this);
5275 if (Tok.is(tok::colon) &&
5276 (!ParsingGenericAssociationType || IsCXXTypeAhead())) {
5301 if (CanBeBitfield && !isEnumBase(CanBeOpaqueEnumDeclaration)) {
5305 Diag(Tok.getLocation(), diag::err_anonymous_enum_bitfield);
5306 }
else if (CanHaveEnumBase || !ColonIsSacred) {
5313 DeclSpec DS(AttrFactory);
5317 DeclSpecContext::DSC_type_specifier);
5320 BaseType = Actions.ActOnTypeName(DeclaratorInfo);
5322 BaseRange = SourceRange(ColonLoc, DeclaratorInfo.getSourceRange().getEnd());
5326 DiagCompat(ColonLoc, diag_compat::cxx_enum_fixed_underlying_type)
5329 Diag(ColonLoc, diag::ext_ms_c_enum_fixed_underlying_type)
5332 DiagCompat(ColonLoc, diag_compat::c_enum_fixed_underlying_type)
5349 if (AllowEnumSpecifier == AllowDefiningTypeSpec::No)
5351 else if (Tok.is(tok::l_brace)) {
5353 Diag(Tok.getLocation(), diag::err_friend_decl_defines_type)
5359 ScopedEnumKWLoc = SourceLocation();
5360 IsScopedUsingClassTag =
false;
5366 }
else if (!isTypeSpecifier(DSC) &&
5367 (Tok.is(tok::semi) ||
5368 (Tok.isAtStartOfLine() &&
5369 !isValidAfterTypeSpecifier(CanBeBitfield)))) {
5374 if (Tok.isNot(tok::semi)) {
5376 ExpectAndConsume(tok::semi, diag::err_expected_after,
"enum");
5377 PP.EnterToken(Tok,
true);
5378 Tok.setKind(tok::semi);
5384 bool IsElaboratedTypeSpecifier =
5390 diagsFromTag.redelay();
5398 Diag(Tok, diag::err_enum_template);
5406 Diag(StartLoc, diag::err_explicit_instantiation_enum);
5410 assert(TemplateInfo.TemplateParams &&
"no template parameters");
5412 TemplateInfo.TemplateParams->size());
5417 Diag(Tok, diag::err_enumerator_unnamed_no_def);
5433 if (IsElaboratedTypeSpecifier && !
getLangOpts().MicrosoftExt &&
5435 ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
5436 diag::err_keyword_not_allowed,
5439 Diag(BaseRange.
getBegin(), diag::ext_enum_base_in_type_specifier)
5440 << (AllowEnumSpecifier == AllowDefiningTypeSpec::Yes) << BaseRange;
5441 else if (ScopedEnumKWLoc.
isValid())
5442 Diag(ScopedEnumKWLoc, diag::ext_elaborated_enum_class)
5446 stripTypeAttributesOffDeclSpec(attrs, DS, TUK);
5448 SkipBodyInfo SkipBody;
5451 SkipBody = Actions.shouldSkipAnonEnumBody(
getCurScope(),
5456 bool IsDependent =
false;
5457 const char *PrevSpec =
nullptr;
5462 TParams, Owned, IsDependent, ScopedEnumKWLoc,
5463 IsScopedUsingClassTag,
5464 BaseType, DSC == DeclSpecContext::DSC_type_specifier,
5465 DSC == DeclSpecContext::DSC_template_param ||
5466 DSC == DeclSpecContext::DSC_template_type_arg,
5467 OffsetOfState, &SkipBody).get();
5477 NameLoc.
isValid() ? NameLoc : StartLoc,
5478 PrevSpec, DiagID, TagDecl, Owned,
5479 Actions.getASTContext().getPrintingPolicy()))
5480 Diag(StartLoc, DiagID) << PrevSpec;
5489 Diag(Tok, diag::err_expected_type_name_after_typename);
5495 if (
Type.isInvalid()) {
5501 NameLoc.
isValid() ? NameLoc : StartLoc,
5502 PrevSpec, DiagID,
Type.get(),
5503 Actions.getASTContext().getPrintingPolicy()))
5504 Diag(StartLoc, DiagID) << PrevSpec;
5523 ParseEnumBody(StartLoc, D, &SkipBody);
5525 !Actions.ActOnDuplicateDefinition(
getCurScope(), TagDecl, SkipBody)) {
5532 NameLoc.
isValid() ? NameLoc : StartLoc,
5533 PrevSpec, DiagID, TagDecl, Owned,
5534 Actions.getASTContext().getPrintingPolicy()))
5535 Diag(StartLoc, DiagID) << PrevSpec;
5542 Actions.ActOnTagStartDefinition(
getCurScope(), EnumDecl);
5550 Diag(
T.getOpenLocation(), diag::ext_ms_c_empty_enum_type)
5551 << SourceRange(
T.getOpenLocation(), Tok.getLocation());
5553 Diag(Tok, diag::err_empty_enum);
5556 SmallVector<Decl *, 32> EnumConstantDecls;
5557 SmallVector<SuppressAccessChecks, 32> EnumAvailabilityDiags;
5559 Decl *LastEnumConstDecl =
nullptr;
5562 while (Tok.isNot(tok::r_brace)) {
5565 if (Tok.isNot(tok::identifier)) {
5566 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
5572 IdentifierInfo *Ident = Tok.getIdentifierInfo();
5576 ParsedAttributes attrs(AttrFactory);
5577 MaybeParseGNUAttributes(attrs);
5578 if (isAllowedCXX11AttributeSpecifier()) {
5580 DiagCompat(Tok.getLocation(), diag_compat::ns_enum_attribute)
5582 ParseCXX11Attributes(attrs);
5585 SourceLocation EqualLoc;
5587 EnumAvailabilityDiags.emplace_back(*
this);
5589 EnterExpressionEvaluationContext ConstantEvaluated(
5598 Decl *EnumConstDecl = Actions.ActOnEnumConstant(
5599 getCurScope(), EnumDecl, LastEnumConstDecl, IdentLoc, Ident, attrs,
5600 EqualLoc, AssignedVal.
get(), SkipBody);
5601 EnumAvailabilityDiags.back().done();
5603 EnumConstantDecls.push_back(EnumConstDecl);
5604 LastEnumConstDecl = EnumConstDecl;
5606 if (Tok.is(tok::identifier)) {
5609 Diag(Loc, diag::err_enumerator_list_missing_comma)
5616 SourceLocation CommaLoc;
5617 if (Tok.isNot(tok::r_brace) && !
TryConsumeToken(tok::comma, CommaLoc)) {
5619 Diag(Tok.getLocation(), diag::err_expected_either) << tok::r_brace
5622 Diag(Tok.getLocation(), diag::err_expected_end_of_enumerator);
5632 if (Tok.is(tok::r_brace) && CommaLoc.
isValid()) {
5634 DiagCompat(CommaLoc, diag_compat::cxx_enumerator_list_comma)
5637 Diag(CommaLoc, diag::ext_enumerator_list_comma_c)
5647 ParsedAttributes attrs(AttrFactory);
5648 MaybeParseGNUAttributes(attrs);
5650 Actions.ActOnEnumBody(StartLoc,
T.getRange(), EnumDecl, EnumConstantDecls,
5654 assert(EnumConstantDecls.size() == EnumAvailabilityDiags.size());
5655 for (
size_t i = 0, e = EnumConstantDecls.size(); i != e; ++i) {
5657 EnumAvailabilityDiags[i].redelay();
5658 PD.complete(EnumConstantDecls[i]);
5662 Actions.ActOnTagFinishDefinition(
getCurScope(), EnumDecl,
T.getRange());
5667 if (!isValidAfterTypeSpecifier(CanBeBitfield)) {
5668 ExpectAndConsume(tok::semi, diag::err_expected_after,
"enum");
5672 PP.EnterToken(Tok,
true);
5673 Tok.setKind(tok::semi);
5677bool Parser::isKnownToBeTypeSpecifier(
const Token &
Tok)
const {
5678 switch (Tok.getKind()) {
5679 default:
return false;
5683 case tok::kw___int64:
5684 case tok::kw___int128:
5685 case tok::kw_signed:
5686 case tok::kw_unsigned:
5687 case tok::kw__Complex:
5688 case tok::kw__Imaginary:
5691 case tok::kw_wchar_t:
5692 case tok::kw_char8_t:
5693 case tok::kw_char16_t:
5694 case tok::kw_char32_t:
5696 case tok::kw__ExtInt:
5697 case tok::kw__BitInt:
5698 case tok::kw___bf16:
5701 case tok::kw_double:
5702 case tok::kw__Accum:
5703 case tok::kw__Fract:
5704 case tok::kw__Float16:
5705 case tok::kw___float128:
5706 case tok::kw___ibm128:
5709 case tok::kw__Decimal32:
5710 case tok::kw__Decimal64:
5711 case tok::kw__Decimal128:
5712 case tok::kw___vector:
5713#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
5714#include "clang/Basic/OpenCLImageTypes.def"
5715#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
5716#include "clang/Basic/HLSLIntangibleTypes.def"
5717#define HLSL_PACKED_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
5718#include "clang/Basic/HLSLPackedTypes.def"
5722 case tok::kw_struct:
5723 case tok::kw___interface:
5728 case tok::kw_typeof:
5729 case tok::kw_typeof_unqual:
5732 case tok::kw__Atomic:
5735 case tok::annot_typename:
5740bool Parser::isTypeSpecifierQualifier(
const Token &
Tok) {
5741 switch (Tok.getKind()) {
5742 default:
return false;
5744 case tok::identifier:
5745 if (TryAltiVecVectorToken())
5748 case tok::kw_typename:
5757 case tok::coloncolon:
5767 case tok::kw___attribute:
5769 case tok::kw_typeof:
5770 case tok::kw_typeof_unqual:
5775 case tok::kw___int64:
5776 case tok::kw___int128:
5777 case tok::kw_signed:
5778 case tok::kw_unsigned:
5779 case tok::kw__Complex:
5780 case tok::kw__Imaginary:
5783 case tok::kw_wchar_t:
5784 case tok::kw_char8_t:
5785 case tok::kw_char16_t:
5786 case tok::kw_char32_t:
5788 case tok::kw__ExtInt:
5789 case tok::kw__BitInt:
5791 case tok::kw___bf16:
5793 case tok::kw_double:
5794 case tok::kw__Accum:
5795 case tok::kw__Fract:
5796 case tok::kw__Float16:
5797 case tok::kw___float128:
5798 case tok::kw___ibm128:
5801 case tok::kw__Decimal32:
5802 case tok::kw__Decimal64:
5803 case tok::kw__Decimal128:
5804 case tok::kw___vector:
5805#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
5806#include "clang/Basic/OpenCLImageTypes.def"
5807#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
5808#include "clang/Basic/HLSLIntangibleTypes.def"
5809#define HLSL_PACKED_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
5810#include "clang/Basic/HLSLPackedTypes.def"
5814 case tok::kw_struct:
5815 case tok::kw___interface:
5822 case tok::kw_volatile:
5823 case tok::kw_restrict:
5824 case tok::kw___ob_wrap:
5825 case tok::kw___ob_trap:
5829 case tok::kw___unknown_anytype:
5832 case tok::annot_typename:
5839 case tok::kw___cdecl:
5840 case tok::kw___stdcall:
5841 case tok::kw___fastcall:
5842 case tok::kw___thiscall:
5843 case tok::kw___regcall:
5844 case tok::kw___vectorcall:
5846 case tok::kw___ptr64:
5847 case tok::kw___ptr32:
5848 case tok::kw___pascal:
5849 case tok::kw___unaligned:
5850 case tok::kw___ptrauth:
5852 case tok::kw__Nonnull:
5853 case tok::kw__Nullable:
5854 case tok::kw__Nullable_result:
5855 case tok::kw__Null_unspecified:
5857 case tok::kw___kindof:
5859 case tok::kw___private:
5860 case tok::kw___local:
5861 case tok::kw___global:
5862 case tok::kw___constant:
5863 case tok::kw___generic:
5864 case tok::kw___read_only:
5865 case tok::kw___read_write:
5866 case tok::kw___write_only:
5867 case tok::kw___funcref:
5870 case tok::kw_private:
5874 case tok::kw__Atomic:
5878 case tok::kw_nointerpolation:
5879 case tok::kw_linear:
5880 case tok::kw_centroid:
5881 case tok::kw_noperspective:
5882 case tok::kw_sample:
5883 case tok::kw_center:
5884 case tok::kw_groupshared:
5888 case tok::kw_row_major:
5889 case tok::kw_column_major:
5895 assert(PP.isIncrementalProcessingEnabled() &&
"Not in incremental mode");
5899 ParsedStmtContext SubStmtCtx = ParsedStmtContext();
5902 TopLevelStmtDecl *TLSD = Actions.ActOnStartTopLevelStmtDecl(
getCurScope());
5903 StmtResult R = ParseStatementOrDeclaration(Stmts, SubStmtCtx);
5904 Actions.ActOnFinishTopLevelStmtDecl(TLSD,
R.get());
5905 if (!
R.isUsable()) {
5906 R = Actions.ActOnNullStmt(Tok.getLocation());
5910 if (Tok.is(tok::eof) && Tok.getEofData()) {
5915 SmallVector<Decl *, 2> DeclsInGroup;
5916 DeclsInGroup.push_back(TLSD);
5919 for (Stmt *S : Stmts) {
5922 TopLevelStmtDecl *D = Actions.ActOnStartTopLevelStmtDecl(
getCurScope());
5923 Actions.ActOnFinishTopLevelStmtDecl(D, S);
5924 DeclsInGroup.push_back(D);
5927 return Actions.BuildDeclaratorGroup(DeclsInGroup);
5930bool Parser::isDeclarationSpecifier(
5932 bool DisambiguatingWithExpression) {
5933 switch (Tok.getKind()) {
5934 default:
return false;
5941 case tok::identifier:
5945 if (TryAltiVecVectorToken())
5948 case tok::kw_decltype:
5949 case tok::kw_typename:
5954 if (TryAnnotateTypeConstraint())
5956 if (Tok.is(tok::identifier))
5964 if (DisambiguatingWithExpression &&
5965 isStartOfObjCClassMessageMissingOpenBracket())
5968 return isDeclarationSpecifier(AllowImplicitTypename);
5970 case tok::coloncolon:
5984 case tok::kw_typedef:
5985 case tok::kw_extern:
5986 case tok::kw___private_extern__:
5987 case tok::kw_static:
5989 case tok::kw___auto_type:
5990 case tok::kw_register:
5991 case tok::kw___thread:
5992 case tok::kw_thread_local:
5993 case tok::kw__Thread_local:
5996 case tok::kw___module_private__:
5999 case tok::kw___unknown_anytype:
6004 case tok::kw___int64:
6005 case tok::kw___int128:
6006 case tok::kw_signed:
6007 case tok::kw_unsigned:
6008 case tok::kw__Complex:
6009 case tok::kw__Imaginary:
6012 case tok::kw_wchar_t:
6013 case tok::kw_char8_t:
6014 case tok::kw_char16_t:
6015 case tok::kw_char32_t:
6018 case tok::kw__ExtInt:
6019 case tok::kw__BitInt:
6021 case tok::kw___bf16:
6023 case tok::kw_double:
6024 case tok::kw__Accum:
6025 case tok::kw__Fract:
6026 case tok::kw__Float16:
6027 case tok::kw___float128:
6028 case tok::kw___ibm128:
6031 case tok::kw__Decimal32:
6032 case tok::kw__Decimal64:
6033 case tok::kw__Decimal128:
6034 case tok::kw___vector:
6038 case tok::kw_struct:
6040 case tok::kw___interface:
6046 case tok::kw_volatile:
6047 case tok::kw_restrict:
6048 case tok::kw___ob_wrap:
6049 case tok::kw___ob_trap:
6053 case tok::kw_inline:
6054 case tok::kw_virtual:
6055 case tok::kw_explicit:
6056 case tok::kw__Noreturn:
6059 case tok::kw__Alignas:
6062 case tok::kw_friend:
6065 case tok::kw_static_assert:
6066 case tok::kw__Static_assert:
6069 case tok::kw_typeof:
6070 case tok::kw_typeof_unqual:
6073 case tok::kw___attribute:
6076 case tok::annot_decltype:
6077 case tok::annot_pack_indexing_type:
6078 case tok::kw_constexpr:
6081 case tok::kw_consteval:
6082 case tok::kw_constinit:
6085 case tok::kw__Atomic:
6088 case tok::kw_alignas:
6098 case tok::annot_typename:
6099 return !DisambiguatingWithExpression ||
6100 !isStartOfObjCClassMessageMissingOpenBracket();
6103 case tok::annot_template_id: {
6104 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
6109 return isTypeConstraintAnnotation() &&
6113 case tok::annot_cxxscope: {
6114 TemplateIdAnnotation *TemplateId =
6122 if (
NextToken().
is(tok::identifier) && TryAnnotateTypeConstraint())
6124 return isTypeConstraintAnnotation() &&
6128 case tok::kw___declspec:
6129 case tok::kw___cdecl:
6130 case tok::kw___stdcall:
6131 case tok::kw___fastcall:
6132 case tok::kw___thiscall:
6133 case tok::kw___regcall:
6134 case tok::kw___vectorcall:
6136 case tok::kw___sptr:
6137 case tok::kw___uptr:
6138 case tok::kw___ptr64:
6139 case tok::kw___ptr32:
6140 case tok::kw___forceinline:
6141 case tok::kw___pascal:
6142 case tok::kw___unaligned:
6143 case tok::kw___ptrauth:
6145 case tok::kw__Nonnull:
6146 case tok::kw__Nullable:
6147 case tok::kw__Nullable_result:
6148 case tok::kw__Null_unspecified:
6150 case tok::kw___kindof:
6152 case tok::kw___private:
6153 case tok::kw___local:
6154 case tok::kw___global:
6155 case tok::kw___constant:
6156 case tok::kw___generic:
6157 case tok::kw___read_only:
6158 case tok::kw___read_write:
6159 case tok::kw___write_only:
6160#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
6161#include "clang/Basic/OpenCLImageTypes.def"
6162#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
6163#include "clang/Basic/HLSLIntangibleTypes.def"
6164#define HLSL_PACKED_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
6165#include "clang/Basic/HLSLPackedTypes.def"
6167 case tok::kw___funcref:
6168 case tok::kw_groupshared:
6171 case tok::kw_nointerpolation:
6172 case tok::kw_linear:
6173 case tok::kw_centroid:
6174 case tok::kw_noperspective:
6175 case tok::kw_sample:
6176 case tok::kw_center:
6177 case tok::kw_row_major:
6178 case tok::kw_column_major:
6181 case tok::kw_private:
6186bool Parser::isConstructorDeclarator(
bool IsUnqualified,
bool DeductionGuide,
6188 const ParsedTemplateInfo *TemplateInfo) {
6189 RevertingTentativeParsingAction TPA(*
this);
6192 if (TemplateInfo && TemplateInfo->TemplateParams)
6195 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
6202 if (Tok.is(tok::identifier)) {
6206 }
else if (Tok.is(tok::annot_template_id)) {
6207 ConsumeAnnotationToken();
6214 SkipCXX11Attributes();
6217 if (Tok.isNot(tok::l_paren)) {
6224 if (Tok.is(tok::r_paren) ||
6225 (Tok.is(tok::ellipsis) &&
NextToken().
is(tok::r_paren))) {
6231 if (isCXX11AttributeSpecifier(
false,
6238 DeclaratorScopeObj DeclScopeObj(*
this, SS);
6240 DeclScopeObj.EnterDeclaratorScope();
6243 ParsedAttributes Attrs(AttrFactory);
6244 MaybeParseMicrosoftAttributes(Attrs);
6253 bool IsConstructor =
false;
6259 if (Tok.is(tok::kw_this)) {
6261 return isDeclarationSpecifier(ITC);
6264 if (isDeclarationSpecifier(ITC))
6265 IsConstructor =
true;
6266 else if (Tok.is(tok::identifier) ||
6267 (Tok.is(tok::annot_cxxscope) &&
NextToken().
is(tok::identifier))) {
6272 if (Tok.is(tok::annot_cxxscope))
6273 ConsumeAnnotationToken();
6279 switch (Tok.getKind()) {
6285 case tok::coloncolon:
6298 SkipCXX11Attributes();
6300 if (DeductionGuide) {
6302 IsConstructor = Tok.is(tok::arrow);
6305 if (Tok.is(tok::colon) || Tok.is(tok::kw_try)) {
6309 IsConstructor =
true;
6311 if (Tok.is(tok::semi) || Tok.is(tok::l_brace)) {
6324 IsConstructor = IsUnqualified;
6329 IsConstructor =
true;
6333 return IsConstructor;
6336void Parser::ParseTypeQualifierListOpt(
6337 DeclSpec &DS,
unsigned AttrReqs,
bool AtomicOrPtrauthAllowed,
6340 if ((AttrReqs & AR_CXX11AttributesParsed) &&
6341 isAllowedCXX11AttributeSpecifier()) {
6342 ParsedAttributes Attrs(AttrFactory);
6343 ParseCXX11Attributes(Attrs);
6347 SourceLocation EndLoc;
6351 const char *PrevSpec =
nullptr;
6352 unsigned DiagID = 0;
6353 SourceLocation Loc = Tok.getLocation();
6355 switch (Tok.getKind()) {
6356 case tok::code_completion:
6358 if (CodeCompletionHandler)
6359 CodeCompletionHandler();
6361 Actions.CodeCompletion().CodeCompleteTypeQualifiers(DS);
6368 case tok::kw_volatile:
6372 case tok::kw_restrict:
6376 case tok::kw___ob_wrap:
6378 Diag(Loc, diag::warn_overflow_behavior_keyword_disabled)
6383 OverflowBehaviorType::OverflowBehaviorKind::Wrap, Loc, PrevSpec,
6386 case tok::kw___ob_trap:
6388 Diag(Loc, diag::warn_overflow_behavior_keyword_disabled)
6393 OverflowBehaviorType::OverflowBehaviorKind::Trap, Loc, PrevSpec,
6396 case tok::kw__Atomic:
6397 if (!AtomicOrPtrauthAllowed)
6398 goto DoneWithTypeQuals;
6399 diagnoseUseOfC11Keyword(Tok);
6405 case tok::kw_private:
6407 goto DoneWithTypeQuals;
6409 case tok::kw___private:
6410 case tok::kw___global:
6411 case tok::kw___local:
6412 case tok::kw___constant:
6413 case tok::kw___generic:
6414 case tok::kw___read_only:
6415 case tok::kw___write_only:
6416 case tok::kw___read_write:
6420 case tok::kw_groupshared:
6424 case tok::kw_nointerpolation:
6425 case tok::kw_linear:
6426 case tok::kw_centroid:
6427 case tok::kw_noperspective:
6428 case tok::kw_sample:
6429 case tok::kw_center:
6435 case tok::kw___ptrauth:
6436 if (!AtomicOrPtrauthAllowed)
6437 goto DoneWithTypeQuals;
6439 EndLoc = PrevTokLocation;
6442 case tok::kw___unaligned:
6446 case tok::kw___uptr:
6451 if (TryKeywordIdentFallback(
false))
6455 case tok::kw___sptr:
6457 case tok::kw___ptr64:
6458 case tok::kw___ptr32:
6459 case tok::kw___cdecl:
6460 case tok::kw___stdcall:
6461 case tok::kw___fastcall:
6462 case tok::kw___thiscall:
6463 case tok::kw___regcall:
6464 case tok::kw___vectorcall:
6465 if (AttrReqs & AR_DeclspecAttributesParsed) {
6469 goto DoneWithTypeQuals;
6471 case tok::kw___funcref:
6475 case tok::kw___pascal:
6476 if (AttrReqs & AR_VendorAttributesParsed) {
6480 goto DoneWithTypeQuals;
6483 case tok::kw__Nonnull:
6484 case tok::kw__Nullable:
6485 case tok::kw__Nullable_result:
6486 case tok::kw__Null_unspecified:
6491 case tok::kw___kindof:
6493 AttributeScopeInfo(),
nullptr, 0,
6498 case tok::kw___attribute:
6499 if (AttrReqs & AR_GNUAttributesParsedAndRejected)
6501 Diag(Tok, diag::err_attributes_not_allowed);
6505 if (AttrReqs & AR_GNUAttributesParsed ||
6506 AttrReqs & AR_GNUAttributesParsedAndRejected) {
6516 DS.
Finish(Actions, Actions.getASTContext().getPrintingPolicy());
6524 assert(PrevSpec &&
"Method did not return previous specifier!");
6525 Diag(Tok, DiagID) << PrevSpec;
6534 Actions.runWithSufficientStackSpace(D.
getBeginLoc(), [&] {
6535 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
6541 if (Kind == tok::star || Kind == tok::caret)
6545 if (Kind == tok::kw_pipe && Lang.OpenCL &&
6546 Lang.getOpenCLCompatibleVersion() >= 200)
6549 if (!Lang.CPlusPlus)
6552 if (Kind == tok::amp)
6560 if (Kind == tok::ampamp)
6571 for (
unsigned Idx = 0; Idx != NumTypes; ++Idx)
6578void Parser::ParseDeclaratorInternal(
Declarator &D,
6579 DirectDeclParseFunction DirectDeclParser) {
6580 if (Diags.hasAllExtensionsSilenced())
6590 (Tok.is(tok::coloncolon) ||
6591 (Tok.is(tok::kw_decltype) &&
NextToken().
is(tok::l_paren)) ||
6592 (Tok.is(tok::identifier) &&
6594 Tok.is(tok::annot_cxxscope))) {
6595 TentativeParsingAction TPA(*
this,
true);
6601 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
6613 Tok.is(tok::star)) {
6617 checkCompoundToken(SS.
getEndLoc(), tok::coloncolon,
6618 CompoundToken::MemberPtr);
6623 DeclSpec DS(AttrFactory);
6624 ParseTypeQualifierListOpt(DS);
6628 Actions.runWithSufficientStackSpace(D.
getBeginLoc(), [&] {
6629 ParseDeclaratorInternal(D, DirectDeclParser);
6643 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
6653 AnnotateScopeToken(SS,
true);
6655 if (DirectDeclParser)
6656 (this->*DirectDeclParser)(D);
6664 DeclSpec DS(AttrFactory);
6665 ParseTypeQualifierListOpt(DS);
6674 if (DirectDeclParser)
6675 (this->*DirectDeclParser)(D);
6684 if (Kind == tok::star || Kind == tok::caret) {
6686 DeclSpec DS(AttrFactory);
6690 unsigned Reqs = AR_CXX11AttributesParsed | AR_DeclspecAttributesParsed |
6692 ? AR_GNUAttributesParsed
6693 : AR_GNUAttributesParsedAndRejected);
6694 ParseTypeQualifierListOpt(DS, Reqs,
true,
6699 Actions.runWithSufficientStackSpace(
6700 D.
getBeginLoc(), [&] { ParseDeclaratorInternal(D, DirectDeclParser); });
6701 if (Kind == tok::star)
6716 DeclSpec DS(AttrFactory);
6720 if (Kind == tok::ampamp)
6721 DiagCompat(Loc, diag_compat::rvalue_reference);
6724 ParseTypeQualifierListOpt(DS);
6733 diag::err_invalid_reference_qualifier_application) <<
"const";
6736 diag::err_invalid_reference_qualifier_application) <<
"volatile";
6740 diag::err_invalid_reference_qualifier_application) <<
"_Atomic";
6744 Actions.runWithSufficientStackSpace(
6745 D.
getBeginLoc(), [&] { ParseDeclaratorInternal(D, DirectDeclParser); });
6752 Diag(InnerChunk.
Loc, diag::err_illegal_decl_reference_to_reference)
6755 Diag(InnerChunk.
Loc, diag::err_illegal_decl_reference_to_reference)
6784void Parser::ParseDirectDeclarator(
Declarator &D) {
6791 return ParseDecompositionDeclarator(D);
6805 ParseOptionalCXXScopeSpecifier(
6807 false, EnteringContext);
6822 if (Actions.ShouldEnterDeclaratorScope(
getCurScope(),
6826 DeclScopeObj.EnterDeclaratorScope();
6833 goto PastIdentifier;
6849 !Actions.containsUnexpandedParameterPacks(D) &&
6857 DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, D);
6867 if (Tok.isOneOf(tok::identifier, tok::kw_operator, tok::annot_template_id,
6871 bool AllowConstructorName;
6872 bool AllowDeductionGuide;
6874 AllowConstructorName =
false;
6875 AllowDeductionGuide =
false;
6879 AllowDeductionGuide =
false;
6887 SourceLocation TemplateKWLoc;
6892 true, AllowConstructorName,
6893 AllowDeductionGuide, &TemplateKWLoc,
6906 DeclScopeObj.EnterDeclaratorScope();
6913 goto PastIdentifier;
6919 diag::err_expected_unqualified_id)
6922 goto PastIdentifier;
6926 "There's a C++-specific check for tok::identifier above");
6927 assert(Tok.getIdentifierInfo() &&
"Not an identifier?");
6928 D.
SetIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
6931 goto PastIdentifier;
6936 bool DiagnoseIdentifier =
false;
6940 DiagnoseIdentifier =
true;
6943 DiagnoseIdentifier =
6951 !isCXX11VirtSpecifier(Tok))
6953 tok::comma, tok::semi, tok::equal, tok::l_brace, tok::kw_try);
6954 if (DiagnoseIdentifier) {
6955 Diag(Tok.getLocation(), diag::err_unexpected_unqualified_id)
6959 goto PastIdentifier;
6963 if (Tok.is(tok::l_paren)) {
6968 RevertingTentativeParsingAction PA(*
this);
6973 goto PastIdentifier;
6980 ParseParenDeclarator(D);
6998 DeclScopeObj.EnterDeclaratorScope();
7009 diag::ext_abstract_pack_declarator_parens);
7011 if (Tok.getKind() == tok::annot_pragma_parser_crash)
7013 if (Tok.is(tok::l_square))
7014 return ParseMisplacedBracketDeclarator(D);
7019 !Tok.isAnnotation() && Tok.getIdentifierInfo() &&
7020 Tok.getIdentifierInfo()->isCPlusPlusKeyword(
getLangOpts())) {
7022 diag::err_expected_member_name_or_semi_objcxx_keyword)
7023 << Tok.getIdentifierInfo()
7026 D.
SetIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
7029 goto PastIdentifier;
7032 diag::err_expected_member_name_or_semi)
7036 if (Tok.getKind() == tok::TokenKind::kw_while) {
7037 Diag(Tok, diag::err_while_loop_outside_of_a_function);
7039 if (Tok.isOneOf(tok::period, tok::arrow))
7040 Diag(Tok, diag::err_invalid_operator_on_type) << Tok.is(tok::arrow);
7043 if (Tok.isAtStartOfLine() && Loc.
isValid())
7044 Diag(PP.getLocForEndOfToken(Loc), diag::err_expected_unqualified_id)
7048 diag::err_expected_unqualified_id)
7053 diag::err_expected_either)
7054 << tok::identifier << tok::l_paren;
7063 "Haven't past the location of the identifier yet?");
7067 MaybeParseCXX11Attributes(D);
7070 if (Tok.is(tok::l_paren)) {
7082 bool IsAmbiguous =
false;
7094 AllowImplicitTypename =
7102 TentativelyDeclaredIdentifiers.push_back(D.
getIdentifier());
7103 bool IsFunctionDecl =
7104 isCXXFunctionDeclarator(&IsAmbiguous, AllowImplicitTypename);
7105 TentativelyDeclaredIdentifiers.pop_back();
7106 if (!IsFunctionDecl)
7109 ParsedAttributes attrs(AttrFactory);
7112 if (IsFunctionDeclaration)
7113 Actions.ActOnStartFunctionDeclarationDeclarator(D,
7114 TemplateParameterDepth);
7115 ParseFunctionDeclarator(D, attrs,
T, IsAmbiguous);
7116 if (IsFunctionDeclaration)
7117 Actions.ActOnFinishFunctionDeclarationDeclarator(D);
7118 PrototypeScope.Exit();
7119 }
else if (Tok.is(tok::l_square)) {
7120 ParseBracketDeclarator(D);
7121 }
else if (Tok.isRegularKeywordAttribute()) {
7123 Diag(Tok, diag::err_keyword_not_allowed) << Tok.getIdentifierInfo();
7128 if (!
T.consumeOpen())
7139 Diag(Tok, diag::err_requires_clause_inside_parens);
7153void Parser::ParseDecompositionDeclarator(
Declarator &D) {
7154 assert(Tok.is(tok::l_square));
7156 TentativeParsingAction PA(*
this);
7161 DiagnoseAndSkipCXX11Attributes();
7165 if (!(Tok.isOneOf(tok::identifier, tok::ellipsis) &&
7167 tok::identifier, tok::l_square, tok::ellipsis)) &&
7168 !(Tok.is(tok::r_square) &&
7171 return ParseMisplacedBracketDeclarator(D);
7174 SourceLocation PrevEllipsisLoc;
7175 SmallVector<DecompositionDeclarator::Binding, 32>
Bindings;
7176 while (Tok.isNot(tok::r_square)) {
7178 if (Tok.is(tok::comma))
7181 if (Tok.is(tok::identifier)) {
7183 Diag(EndLoc, diag::err_expected)
7186 Diag(Tok, diag::err_expected_comma_or_rsquare);
7189 SkipUntil({tok::r_square, tok::comma, tok::identifier, tok::ellipsis},
7191 if (Tok.is(tok::comma))
7193 else if (Tok.is(tok::r_square))
7198 if (isCXX11AttributeSpecifier() !=
7200 DiagnoseAndSkipCXX11Attributes();
7202 SourceLocation EllipsisLoc;
7204 if (Tok.is(tok::ellipsis)) {
7206 if (PrevEllipsisLoc.
isValid()) {
7207 Diag(Tok, diag::err_binding_multiple_ellipses);
7208 Diag(PrevEllipsisLoc, diag::note_previous_ellipsis);
7211 EllipsisLoc = Tok.getLocation();
7212 PrevEllipsisLoc = EllipsisLoc;
7216 if (Tok.isNot(tok::identifier)) {
7217 Diag(Tok, diag::err_expected) << tok::identifier;
7221 IdentifierInfo *II = Tok.getIdentifierInfo();
7222 SourceLocation Loc = Tok.getLocation();
7225 if (Tok.is(tok::ellipsis) && !PrevEllipsisLoc.
isValid()) {
7226 DiagnoseMisplacedEllipsis(Tok.getLocation(), Loc, EllipsisLoc.
isValid(),
7228 EllipsisLoc = Tok.getLocation();
7232 ParsedAttributes Attrs(AttrFactory);
7233 if (isCXX11AttributeSpecifier() !=
7235 DiagCompat(Tok, diag_compat::attrs_on_binding);
7236 MaybeParseCXX11Attributes(Attrs);
7239 Bindings.push_back({II, Loc, std::move(Attrs), EllipsisLoc});
7242 if (Tok.isNot(tok::r_square))
7249 Diag(Tok.getLocation(), diag::ext_decomp_decl_empty);
7257 T.getCloseLocation());
7260void Parser::ParseParenDeclarator(
Declarator &D) {
7264 assert(!D.
isPastIdentifier() &&
"Should be called before passing identifier");
7276 ParsedAttributes attrs(AttrFactory);
7277 bool RequiresArg =
false;
7278 if (Tok.is(tok::kw___attribute)) {
7279 ParseGNUAttributes(attrs);
7287 ParseMicrosoftTypeAttributes(attrs);
7290 if (Tok.is(tok::kw___pascal))
7291 ParseBorlandTypeAttributes(attrs);
7303 }
else if (Tok.is(tok::r_paren) ||
7305 Tok.is(tok::ellipsis) &&
7307 isDeclarationSpecifier(
7309 isCXX11AttributeSpecifier() !=
7329 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
7334 std::move(attrs),
T.getCloseLocation());
7340 DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, D);
7358 ParseFunctionDeclarator(D, attrs,
T,
false, RequiresArg);
7359 PrototypeScope.Exit();
7362void Parser::InitCXXThisScopeForDeclaratorIfRelevant(
7364 std::optional<Sema::CXXThisScopeRAII> &ThisScope) {
7372 bool IsCXX11MemberFunction =
7379 Actions.CurContext->isRecord());
7380 if (!IsCXX11MemberFunction)
7400 ThisScope.emplace(Actions, dyn_cast<CXXRecordDecl>(Actions.CurContext), Q,
7401 IsCXX11MemberFunction);
7404void Parser::ParseFunctionDeclarator(
Declarator &D,
7409 assert(
getCurScope()->isFunctionPrototypeScope() &&
7410 "Should call from a Function scope");
7416 bool HasProto =
false;
7418 SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
7420 SourceLocation EllipsisLoc;
7422 DeclSpec DS(AttrFactory);
7423 bool RefQualifierIsLValueRef =
true;
7424 SourceLocation RefQualifierLoc;
7426 SourceRange ESpecRange;
7427 SmallVector<ParsedType, 2> DynamicExceptions;
7428 SmallVector<SourceRange, 2> DynamicExceptionRanges;
7431 ParsedAttributes FnAttrs(AttrFactory);
7433 SourceLocation TrailingReturnTypeLoc;
7438 SourceLocation StartLoc, LocalEndLoc, EndLoc;
7439 SourceLocation LParenLoc, RParenLoc;
7441 StartLoc = LParenLoc;
7443 if (isFunctionDeclaratorIdentifierList()) {
7445 Diag(Tok, diag::err_argument_required_after_attribute);
7447 ParseFunctionDeclaratorIdentifierList(D, ParamInfo);
7451 LocalEndLoc = RParenLoc;
7456 MaybeParseCXX11Attributes(FnAttrs);
7457 ProhibitAttributes(FnAttrs);
7459 if (Tok.isNot(tok::r_paren))
7460 ParseParameterDeclarationClause(D, FirstArgAttrs, ParamInfo, EllipsisLoc);
7461 else if (RequiresArg)
7462 Diag(Tok, diag::err_argument_required_after_attribute);
7473 LocalEndLoc = RParenLoc;
7482 ParseTypeQualifierListOpt(
7483 DS, AR_NoAttributesParsed,
7486 Actions.CodeCompletion().CodeCompleteFunctionQualifiers(DS, D);
7493 if (ParseRefQualifier(RefQualifierIsLValueRef, RefQualifierLoc))
7494 EndLoc = RefQualifierLoc;
7496 std::optional<Sema::CXXThisScopeRAII> ThisScope;
7497 InitCXXThisScopeForDeclaratorIfRelevant(D, DS, ThisScope);
7514 if (Delayed && Actions.isLibstdcxxEagerExceptionSpecHack(D) &&
7531 ESpecType = tryParseExceptionSpecification(Delayed,
7534 DynamicExceptionRanges,
7536 ExceptionSpecTokens);
7538 EndLoc = ESpecRange.
getEnd();
7542 MaybeParseCXX11Attributes(FnAttrs);
7545 LocalEndLoc = EndLoc;
7547 Diag(Tok, diag::warn_cxx98_compat_trailing_return_type);
7550 LocalEndLoc = Tok.getLocation();
7554 TrailingReturnTypeLoc =
Range.getBegin();
7555 EndLoc =
Range.getEnd();
7558 MaybeParseCXX11Attributes(FnAttrs);
7566 SmallVector<NamedDecl *, 0> DeclsInPrototype;
7569 NamedDecl *ND = dyn_cast<NamedDecl>(D);
7572 DeclsInPrototype.push_back(ND);
7579 llvm::sort(DeclsInPrototype, [](Decl *D1, Decl *D2) {
7587 HasProto, IsAmbiguous, LParenLoc, ParamInfo.data(),
7588 ParamInfo.size(), EllipsisLoc, RParenLoc,
7589 RefQualifierIsLValueRef, RefQualifierLoc,
7591 ESpecType, ESpecRange, DynamicExceptions.data(),
7592 DynamicExceptionRanges.data(), DynamicExceptions.size(),
7593 NoexceptExpr.
isUsable() ? NoexceptExpr.
get() :
nullptr,
7594 ExceptionSpecTokens, DeclsInPrototype, StartLoc,
7595 LocalEndLoc, D, TrailingReturnType, TrailingReturnTypeLoc,
7597 std::move(FnAttrs), EndLoc);
7600bool Parser::ParseRefQualifier(
bool &RefQualifierIsLValueRef,
7602 if (Tok.isOneOf(tok::amp, tok::ampamp)) {
7604 RefQualifierIsLValueRef = Tok.is(tok::amp);
7611bool Parser::isFunctionDeclaratorIdentifierList() {
7613 && Tok.is(tok::identifier)
7614 && !TryAltiVecVectorToken()
7630 && (!Tok.is(tok::eof) &&
7634void Parser::ParseFunctionDeclaratorIdentifierList(
7638 assert(!
getLangOpts().requiresStrictPrototypes() &&
7639 "Cannot parse an identifier list in C23 or C++");
7646 Diag(Tok, diag::ext_ident_list_in_param);
7649 llvm::SmallPtrSet<const IdentifierInfo *, 16> ParamsSoFar;
7653 if (Tok.isNot(tok::identifier)) {
7654 Diag(Tok, diag::err_expected) << tok::identifier;
7661 IdentifierInfo *ParmII = Tok.getIdentifierInfo();
7664 if (Actions.getTypeName(*ParmII, Tok.getLocation(),
getCurScope()))
7665 Diag(Tok, diag::err_unexpected_typedef_ident) << ParmII;
7668 if (!ParamsSoFar.insert(ParmII).second) {
7669 Diag(Tok, diag::err_param_redefinition) << ParmII;
7672 ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII,
7683void Parser::ParseParameterDeclarationClause(
7692 if (
getCurScope()->getFunctionPrototypeDepth() - 1 >
7694 Diag(Tok.getLocation(), diag::err_function_scope_depth_exceeded)
7713 IsACXXFunctionDeclaration) {
7722 LateParsedAttrList LateParamAttrs(
true,
7733 DeclSpec DS(AttrFactory);
7735 ParsedAttributes ArgDeclAttrs(AttrFactory);
7736 ParsedAttributes ArgDeclSpecAttrs(AttrFactory);
7743 ArgDeclSpecAttrs.takeAllPrependingFrom(FirstArgAttrs);
7746 MaybeParseCXX11Attributes(ArgDeclAttrs);
7749 MaybeParseMicrosoftAttributes(ArgDeclSpecAttrs);
7752 SourceLocation DSStart = Tok.getLocation();
7756 SourceLocation ThisLoc;
7760 ParsedTemplateInfo TemplateInfo;
7761 ParseDeclarationSpecifiers(DS, TemplateInfo,
AS_none,
7762 DeclSpecContext::DSC_normal,
7763 nullptr, AllowImplicitTypename);
7776 ParseDeclarator(ParmDeclarator);
7779 ParmDeclarator.SetRangeBegin(ThisLoc);
7782 MaybeParseGNUAttributes(ParmDeclarator, &LateParamAttrs);
7786 if (Tok.is(tok::kw_requires)) {
7791 diag::err_requires_clause_on_declarator_not_declaring_a_function);
7797 const IdentifierInfo *ParmII = ParmDeclarator.getIdentifier();
7801 std::unique_ptr<CachedTokens> DefArgToks;
7805 if (DS.
isEmpty() && ParmDeclarator.getIdentifier() ==
nullptr &&
7806 ParmDeclarator.getNumTypeObjects() == 0) {
7808 Diag(DSStart, diag::err_missing_param);
7815 if (Tok.is(tok::ellipsis) &&
7817 (!ParmDeclarator.getEllipsisLoc().isValid() &&
7818 !Actions.isUnexpandedParameterPackPermitted())) &&
7819 Actions.containsUnexpandedParameterPacks(ParmDeclarator))
7820 DiagnoseMisplacedEllipsisInDeclarator(
ConsumeToken(), ParmDeclarator);
7839 if (!ParmDeclarator.isInvalidType() && !ParmDeclarator.hasName() &&
7840 Tok.isNot(tok::raw_identifier) && !Tok.isAnnotation() &&
7841 Tok.getIdentifierInfo() &&
7842 Tok.getIdentifierInfo()->isKeyword(
getLangOpts())) {
7843 Diag(Tok, diag::err_keyword_as_parameter) << PP.getSpelling(Tok);
7852 Diag(ParmDeclarator.getBeginLoc(),
7853 diag::err_function_parameter_limit_exceeded);
7861 Actions.ActOnParamDeclarator(
getCurScope(), ParmDeclarator, ThisLoc);
7863 DistributeCLateParsedAttrs(Param, &LateParamAttrs);
7868 if (Tok.is(tok::equal)) {
7869 SourceLocation EqualLoc = Tok.getLocation();
7879 ConsumeAndStoreInitializer(*DefArgToks,
7881 Actions.ActOnParamUnparsedDefaultArgument(Param, EqualLoc,
7892 DelayTemplateIdDestructionRAII DontDestructTemplateIds(
7897 EnterExpressionEvaluationContext Eval(
7904 Diag(Tok, diag::compat_cxx11_generalized_initializer_lists);
7905 DefArgResult = ParseBraceInitializer();
7907 if (Tok.is(tok::l_paren) &&
NextToken().
is(tok::l_brace)) {
7908 Diag(Tok, diag::err_stmt_expr_in_default_arg) << 0;
7909 Actions.ActOnParamDefaultArgumentError(Param, EqualLoc,
7919 Actions.ActOnParamDefaultArgumentError(Param, EqualLoc,
7924 Actions.ActOnParamDefaultArgument(Param, EqualLoc,
7925 DefArgResult.
get());
7930 ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII,
7931 ParmDeclarator.getIdentifierLoc(),
7932 Param, std::move(DefArgToks)));
7940 Diag(EllipsisLoc, diag::warn_deprecated_missing_comma_before_ellipsis)
7947 Diag(EllipsisLoc, diag::err_missing_comma_before_ellipsis)
7949 }
else if (ParmDeclarator.getEllipsisLoc().isValid() ||
7950 Actions.containsUnexpandedParameterPacks(ParmDeclarator)) {
7953 SourceLocation ParmEllipsis = ParmDeclarator.getEllipsisLoc();
7954 Diag(EllipsisLoc, diag::warn_misplaced_ellipsis_vararg)
7955 << ParmEllipsis.
isValid() << ParmEllipsis;
7958 diag::note_misplaced_ellipsis_vararg_existing_ellipsis);
7960 Diag(ParmDeclarator.getIdentifierLoc(),
7961 diag::note_misplaced_ellipsis_vararg_add_ellipsis)
7964 << !ParmDeclarator.hasName();
7966 Diag(EllipsisLoc, diag::note_misplaced_ellipsis_vararg_add_comma)
7979 if (!LateParamAttrs.empty())
7980 ParseLexedAttributeList(LateParamAttrs,
nullptr,
false,
7984void Parser::ParseBracketDeclarator(
Declarator &D) {
7985 if (CheckProhibitedCXX11Attribute())
7993 if (Tok.getKind() == tok::r_square) {
7995 ParsedAttributes attrs(AttrFactory);
7996 MaybeParseCXX11Attributes(attrs);
8000 T.getOpenLocation(),
8001 T.getCloseLocation()),
8002 std::move(attrs),
T.getCloseLocation());
8004 }
else if (Tok.getKind() == tok::numeric_constant &&
8011 ParsedAttributes attrs(AttrFactory);
8012 MaybeParseCXX11Attributes(attrs);
8016 T.getOpenLocation(),
8017 T.getCloseLocation()),
8018 std::move(attrs),
T.getCloseLocation());
8020 }
else if (Tok.getKind() == tok::code_completion) {
8022 Actions.CodeCompletion().CodeCompleteBracketDeclarator(
getCurScope());
8027 SourceLocation StaticLoc;
8032 DeclSpec DS(AttrFactory);
8033 ParseTypeQualifierListOpt(DS, AR_CXX11AttributesParsed);
8041 bool isStar =
false;
8052 Diag(StaticLoc, diag::err_unspecified_vla_size_with_static);
8053 StaticLoc = SourceLocation();
8056 }
else if (Tok.isNot(tok::r_square)) {
8073 Diag(StaticLoc, diag::err_unspecified_size_with_static);
8074 StaticLoc = SourceLocation();
8093 isStar, NumElements.
get(),
T.getOpenLocation(),
8094 T.getCloseLocation()),
8098void Parser::ParseMisplacedBracketDeclarator(
Declarator &D) {
8099 assert(Tok.is(tok::l_square) &&
"Missing opening bracket");
8102 SourceLocation StartBracketLoc = Tok.getLocation();
8106 while (Tok.is(tok::l_square)) {
8107 ParseBracketDeclarator(TempDeclarator);
8113 if (Tok.is(tok::semi))
8116 SourceLocation SuggestParenLoc = Tok.getLocation();
8119 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
8124 if (TempDeclarator.getNumTypeObjects() == 0)
8128 bool NeedParens =
false;
8147 SourceLocation EndLoc = PP.getLocForEndOfToken(D.
getEndLoc());
8153 for (
unsigned i = 0, e = TempDeclarator.getNumTypeObjects(); i < e; ++i) {
8154 const DeclaratorChunk &Chunk = TempDeclarator.getTypeObject(i);
8155 D.
AddTypeInfo(Chunk, TempDeclarator.getAttributePool(), SourceLocation());
8160 if (!D.
hasName() && !NeedParens)
8163 SourceLocation EndBracketLoc = TempDeclarator.getEndLoc();
8166 SourceRange BracketRange(StartBracketLoc, EndBracketLoc);
8167 SourceLocation EndLoc = PP.getLocForEndOfToken(D.
getEndLoc());
8170 Diag(EndLoc, diag::err_brackets_go_after_unqualified_id)
8175 EndLoc, CharSourceRange(BracketRange,
true))
8178 Diag(EndLoc, diag::err_brackets_go_after_unqualified_id)
8181 EndLoc, CharSourceRange(BracketRange,
true))
8186void Parser::ParseTypeofSpecifier(
DeclSpec &DS) {
8187 assert(Tok.isOneOf(tok::kw_typeof, tok::kw_typeof_unqual) &&
8188 "Not a typeof specifier");
8190 bool IsUnqual = Tok.is(tok::kw_typeof_unqual);
8191 const IdentifierInfo *II = Tok.getIdentifierInfo();
8193 Diag(Tok.getLocation(), diag::warn_c23_compat_keyword) << Tok.getName();
8197 bool HasParens = Tok.is(tok::l_paren);
8205 SourceRange CastRange;
8207 ParseExprAfterUnaryExprOrTypeTrait(OpTok, isCastExpr, CastTy, CastRange);
8223 const char *PrevSpec =
nullptr;
8230 Actions.getASTContext().getPrintingPolicy()))
8231 Diag(StartLoc, DiagID) << PrevSpec;
8242 Operand = Actions.HandleExprEvaluationContextForTypeof(
Operand.get());
8248 const char *PrevSpec =
nullptr;
8255 Actions.getASTContext().getPrintingPolicy()))
8256 Diag(StartLoc, DiagID) << PrevSpec;
8259void Parser::ParseAtomicSpecifier(
DeclSpec &DS) {
8260 assert(Tok.is(tok::kw__Atomic) &&
NextToken().
is(tok::l_paren) &&
8261 "Not an atomic specifier");
8265 if (
T.consumeOpen())
8269 if (
Result.isInvalid()) {
8277 if (
T.getCloseLocation().isInvalid())
8283 const char *PrevSpec =
nullptr;
8287 Actions.getASTContext().getPrintingPolicy()))
8288 Diag(StartLoc, DiagID) << PrevSpec;
8291bool Parser::TryAltiVecVectorTokenOutOfLine() {
8293 switch (
Next.getKind()) {
8294 default:
return false;
8297 case tok::kw_signed:
8298 case tok::kw_unsigned:
8303 case tok::kw_double:
8306 case tok::kw___bool:
8307 case tok::kw___pixel:
8308 Tok.setKind(tok::kw___vector);
8310 case tok::identifier:
8311 if (
Next.getIdentifierInfo() == Ident_pixel) {
8312 Tok.setKind(tok::kw___vector);
8315 if (
Next.getIdentifierInfo() == Ident_bool ||
8316 Next.getIdentifierInfo() == Ident_Bool) {
8317 Tok.setKind(tok::kw___vector);
8325 const char *&PrevSpec,
unsigned &DiagID,
8327 const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy();
8328 if (Tok.getIdentifierInfo() == Ident_vector) {
8330 switch (
Next.getKind()) {
8333 case tok::kw_signed:
8334 case tok::kw_unsigned:
8339 case tok::kw_double:
8342 case tok::kw___bool:
8343 case tok::kw___pixel:
8346 case tok::identifier:
8347 if (
Next.getIdentifierInfo() == Ident_pixel) {
8351 if (
Next.getIdentifierInfo() == Ident_bool ||
8352 Next.getIdentifierInfo() == Ident_Bool) {
8361 }
else if ((Tok.getIdentifierInfo() == Ident_pixel) &&
8365 }
else if ((Tok.getIdentifierInfo() == Ident_bool) &&
8373TypeResult Parser::ParseTypeFromString(StringRef TypeStr, StringRef Context,
8376 SmallVector<Token, 4> Tokens;
8379 auto &SourceMgr = PP.getSourceManager();
8380 FileID FID = SourceMgr.createFileID(
8381 llvm::MemoryBuffer::getMemBufferCopy(TypeStr, Context),
SrcMgr::C_User,
8385 Lexer L(FID, SourceMgr.getBufferOrFake(FID), PP);
8386 L.setParsingPreprocessorDirective(
true);
8392 Tokens.push_back(Tok);
8393 }
while (Tok.isNot(tok::eod));
8398 Token &EndToken = Tokens.back();
8402 Tokens.push_back(Tok);
8405 PP.EnterTokenStream(Tokens,
false,
8420 (Tok.isNot(tok::eof) || Tok.getEofData() != TypeStr.data())) {
8421 Diag(Tok.getLocation(), diag::err_type_unparsed);
8426 while (Tok.isNot(tok::eof))
8430 if (Tok.is(tok::eof) && Tok.getEofData() == TypeStr.data())
8435void Parser::DiagnoseBitIntUse(
const Token &
Tok) {
8439 assert(Tok.isOneOf(tok::kw__ExtInt, tok::kw__BitInt) &&
8440 "expected either an _ExtInt or _BitInt token!");
8442 SourceLocation Loc = Tok.getLocation();
8443 if (Tok.is(tok::kw__ExtInt)) {
8444 Diag(Loc, diag::warn_ext_int_deprecated)
8450 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