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 =
2196 if (IsTemplateSpecOrInst)
2206 while (MaybeParseHLSLAnnotations(D))
2209 if (
Tok.is(tok::kw_requires)) {
2210 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
2214 ++CurTemplateDepthTracker;
2215 ParseTrailingRequiresClauseWithScope(D);
2219 MaybeParseGNUAttributes(D, &LateParsedAttrs);
2224 if (Tok.is(tok::kw__Noreturn)) {
2226 const char *PrevSpec;
2232 MaybeParseGNUAttributes(D, &LateParsedAttrs);
2233 Fixit &= Tok.isOneOf(tok::semi, tok::l_brace, tok::kw_try);
2235 Diag(Loc, diag::err_c11_noreturn_misplaced)
2237 << (Fixit ? FixItHint::CreateInsertion(D.getBeginLoc(),
"_Noreturn ")
2242 if (Tok.is(tok::equal) &&
NextToken().
is(tok::code_completion)) {
2244 Actions.CodeCompletion().CodeCompleteAfterFunctionEquals(D);
2253 while (
auto Specifier = isCXX11VirtSpecifier()) {
2254 Diag(Tok, diag::err_virt_specifier_outside_class)
2262 if (!isDeclarationAfterDeclarator()) {
2268 if (isStartOfFunctionDefinition(D)) {
2278 diag::err_function_declared_typedef)
2282 Decl *TheDecl =
nullptr;
2288 Diag(Tok, diag::err_template_defn_explicit_instantiation) << 0;
2289 TheDecl = ParseFunctionDefinition(D, ParsedTemplateInfo(),
2292 SourceLocation LAngleLoc =
2293 PP.getLocForEndOfToken(TemplateInfo.TemplateLoc);
2295 diag::err_explicit_instantiation_with_definition)
2296 << SourceRange(TemplateInfo.TemplateLoc)
2301 FakedParamLists.push_back(Actions.ActOnTemplateParameterList(
2302 0, SourceLocation(), TemplateInfo.TemplateLoc, LAngleLoc, {},
2303 LAngleLoc,
nullptr));
2305 TheDecl = ParseFunctionDefinition(
2307 ParsedTemplateInfo(&FakedParamLists,
2314 ParseFunctionDefinition(D, TemplateInfo, &LateParsedAttrs);
2317 return Actions.ConvertDeclToDeclGroup(TheDecl);
2321 Tok.is(tok::kw_namespace)) {
2331 Diag(Tok, diag::err_expected_fn_body);
2336 if (Tok.is(tok::l_brace)) {
2337 Diag(Tok, diag::err_function_definition_not_allowed);
2345 if (ParseAsmAttributesAfterDeclarator(D))
2354 if (FRI && (Tok.is(tok::colon) || isTokIdentifier_in())) {
2367 bool EnterContext = FRI->ExpansionStmt &&
2368 Actions.CurContext == FRI->ExpansionStmt->getParent();
2370 Actions.PushDeclContext(
nullptr, FRI->ExpansionStmt);
2371 llvm::scope_exit RestoreDeclContext{[&] {
2373 Actions.PopDeclContext();
2376 bool IsForRangeLoopOrExpansionStmt =
false;
2378 IsForRangeLoopOrExpansionStmt =
true;
2380 Actions.OpenMP().startOpenMPCXXRangeFor();
2382 ParseForRangeInitializerAfterColon(*FRI, &DS);
2386 if (IsForRangeLoopOrExpansionStmt) {
2387 Actions.ActOnCXXForRangeDecl(ThisDecl, FRI->ExpansionStmt);
2390 if (
auto *VD = dyn_cast_or_null<VarDecl>(ThisDecl))
2391 VD->setObjCForDecl(
true);
2393 Actions.FinalizeDeclaration(ThisDecl);
2394 D.complete(ThisDecl);
2395 return Actions.FinalizeDeclaratorGroup(
getCurScope(), DS, ThisDecl);
2398 SmallVector<Decl *, 8> DeclsInGroup;
2400 ParseDeclarationAfterDeclaratorAndAttributes(D, TemplateInfo, FRI);
2401 if (LateParsedAttrs.size() > 0)
2402 ParseLexedAttributeList(LateParsedAttrs, FirstDecl,
true,
false);
2403 D.complete(FirstDecl);
2405 DeclsInGroup.push_back(FirstDecl);
2411 SourceLocation CommaLoc;
2413 if (Tok.isAtStartOfLine() && ExpectSemi && !MightBeDeclarator(Context)) {
2417 Diag(CommaLoc, diag::err_expected_semi_declaration)
2429 Diag(CommaLoc, diag::err_multiple_template_declarators)
2430 << TemplateInfo.Kind;
2444 MaybeParseGNUAttributes(D);
2448 DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2456 MaybeParseHLSLAnnotations(D);
2459 Decl *ThisDecl =
nullptr;
2465 if (Tok.is(tok::kw_requires))
2466 ParseTrailingRequiresClauseWithScope(D);
2467 ThisDecl = ParseDeclarationAfterDeclarator(D, TemplateInfo);
2469 if (LateParsedAttrs.size() > 0)
2470 ParseLexedAttributeList(LateParsedAttrs, ThisDecl,
true,
false);
2472 D.complete(ThisDecl);
2474 DeclsInGroup.push_back(ThisDecl);
2479 *DeclEnd = Tok.getLocation();
2481 if (ExpectSemi && ExpectAndConsumeSemi(
2483 ? diag::err_invalid_token_after_toplevel_declarator
2484 : diag::err_expected_semi_declaration)) {
2492 return Actions.FinalizeDeclaratorGroup(
getCurScope(), DS, DeclsInGroup);
2495bool Parser::ParseAsmAttributesAfterDeclarator(
Declarator &D) {
2497 if (Tok.is(tok::kw_asm)) {
2499 ExprResult AsmLabel(ParseSimpleAsm(
true, &Loc));
2500 if (AsmLabel.isInvalid()) {
2509 MaybeParseGNUAttributes(D);
2513Decl *Parser::ParseDeclarationAfterDeclarator(
2514 Declarator &D,
const ParsedTemplateInfo &TemplateInfo) {
2515 if (ParseAsmAttributesAfterDeclarator(D))
2518 return ParseDeclarationAfterDeclaratorAndAttributes(D, TemplateInfo);
2521Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
2522 Declarator &D,
const ParsedTemplateInfo &TemplateInfo, ForRangeInit *FRI) {
2524 struct InitializerScopeRAII {
2530 InitializerScopeRAII(Parser &P, Declarator &D, Decl *ThisDecl)
2531 : P(P), D(D), ThisDecl(ThisDecl), Entered(
false) {
2534 if (D.getCXXScopeSpec().isSet()) {
2536 S = P.getCurScope();
2539 P.Actions.ActOnCXXEnterDeclInitializer(S, ThisDecl);
2544 ~InitializerScopeRAII() {
2560 InitKind TheInitKind;
2562 if (isTokenEqualOrEqualTypo())
2563 TheInitKind = InitKind::Equal;
2565 TheInitKind = InitKind::CXXDirect;
2568 TheInitKind = InitKind::CXXBraced;
2570 TheInitKind = InitKind::Uninitialized;
2571 if (TheInitKind != InitKind::Uninitialized)
2575 Decl *ThisDecl =
nullptr;
2576 Decl *OuterDecl =
nullptr;
2577 switch (TemplateInfo.Kind) {
2579 ThisDecl = Actions.ActOnDeclarator(getCurScope(), D);
2584 ThisDecl = Actions.ActOnTemplateDeclarator(getCurScope(),
2585 *TemplateInfo.TemplateParams,
2587 if (
VarTemplateDecl *VT = dyn_cast_or_null<VarTemplateDecl>(ThisDecl)) {
2590 ThisDecl = VT->getTemplatedDecl();
2596 if (
Tok.
is(tok::semi)) {
2597 DeclResult ThisRes = Actions.ActOnExplicitInstantiation(
2598 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc, D);
2600 SkipUntil(tok::semi, StopBeforeMatch);
2603 ThisDecl = ThisRes.
get();
2611 Diag(
Tok, diag::err_template_defn_explicit_instantiation)
2613 ThisDecl = Actions.ActOnDeclarator(getCurScope(), D);
2616 PP.getLocForEndOfToken(TemplateInfo.TemplateLoc);
2618 diag::err_explicit_instantiation_with_definition)
2623 TemplateParameterLists FakedParamLists;
2624 FakedParamLists.push_back(Actions.ActOnTemplateParameterList(
2626 LAngleLoc,
nullptr));
2629 Actions.ActOnTemplateDeclarator(getCurScope(), FakedParamLists, D);
2638 switch (TheInitKind) {
2640 case InitKind::Equal: {
2643 if (
Tok.
is(tok::kw_delete)) {
2645 Diag(ConsumeToken(), diag::err_default_delete_in_multiple_declaration)
2648 Diag(ConsumeToken(), diag::err_deleted_non_function);
2649 SkipDeletedFunctionBody();
2650 }
else if (
Tok.
is(tok::kw_default)) {
2652 Diag(ConsumeToken(), diag::err_default_delete_in_multiple_declaration)
2655 Diag(ConsumeToken(), diag::err_default_special_members)
2656 << (getLangOpts().CPlusPlus29
2657 ? diag::DefaultableFunctionKinds::Cxx29
2658 : getLangOpts().CPlusPlus20
2659 ? diag::DefaultableFunctionKinds::Cxx20
2660 : diag::DefaultableFunctionKinds::Default);
2662 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2664 if (
Tok.
is(tok::code_completion)) {
2666 Actions.CodeCompletion().CodeCompleteInitializer(getCurScope(),
2668 Actions.FinalizeDeclaration(ThisDecl);
2678 Diag(EqualLoc, diag::err_single_decl_assign_in_for_range)
2682 FRI->ColonLoc = EqualLoc;
2684 FRI->RangeExpr =
Init;
2687 if (
Init.isInvalid()) {
2689 StopTokens.push_back(tok::comma);
2692 StopTokens.push_back(tok::r_paren);
2693 SkipUntil(StopTokens, StopAtSemi | StopBeforeMatch);
2694 Actions.ActOnInitializerError(ThisDecl);
2696 Actions.AddInitializerToDecl(ThisDecl,
Init.get(),
2701 case InitKind::CXXDirect: {
2708 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2710 auto ThisVarDecl = dyn_cast_or_null<VarDecl>(ThisDecl);
2711 auto RunSignatureHelp = [&]() {
2713 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
2714 ThisVarDecl->getType()->getCanonicalTypeInternal(),
2717 CalledSignatureHelp =
true;
2718 return PreferredType;
2720 auto SetPreferredType = [&] {
2721 PreferredType.enterFunctionArgument(
Tok.
getLocation(), RunSignatureHelp);
2724 llvm::function_ref<void()> ExpressionStarts;
2730 ExpressionStarts = SetPreferredType;
2733 bool SawError = ParseExpressionList(Exprs, ExpressionStarts);
2736 if (ThisVarDecl && PP.isCodeCompletionReached() && !CalledSignatureHelp) {
2737 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
2738 ThisVarDecl->getType()->getCanonicalTypeInternal(),
2741 CalledSignatureHelp =
true;
2743 Actions.ActOnInitializerError(ThisDecl);
2744 SkipUntil(tok::r_paren, StopAtSemi);
2750 T.getCloseLocation(),
2752 Actions.AddInitializerToDecl(ThisDecl,
Initializer.get(),
2757 case InitKind::CXXBraced: {
2759 Diag(
Tok, diag::compat_cxx11_generalized_initializer_lists);
2761 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2766 if (
Init.isInvalid()) {
2767 Actions.ActOnInitializerError(ThisDecl);
2769 Actions.AddInitializerToDecl(ThisDecl,
Init.get(),
true);
2772 case InitKind::Uninitialized: {
2773 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2774 Actions.ActOnUninitializedDecl(ThisDecl);
2779 Actions.FinalizeDeclaration(ThisDecl);
2780 return OuterDecl ? OuterDecl : ThisDecl;
2783void Parser::ParseSpecifierQualifierList(
2786 ParsedTemplateInfo TemplateInfo;
2788 assert((!LateAttrs ||
2789 llvm::none_of(*LateAttrs, llvm::IsaPred<LateParsedTypeAttribute>)) &&
2790 "caller's late-attribute list must not hold type attributes yet");
2795 ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC, LateAttrs,
2796 AllowImplicitTypename);
2801 Diag(Tok, diag::err_expected_type);
2804 Diag(Tok, diag::err_typename_requires_specqual);
2815 diag::err_typename_invalid_storageclass);
2859 return T.isOneOf(tok::l_square, tok::l_paren, tok::r_paren, tok::semi,
2860 tok::comma, tok::equal, tok::kw_asm, tok::l_brace,
2865 ParsedTemplateInfo &TemplateInfo,
2868 assert(Tok.is(tok::identifier) &&
"should have identifier");
2870 SourceLocation Loc = Tok.getLocation();
2890 if (!isTypeSpecifier(DSC) &&
getLangOpts().isImplicitIntAllowed() &&
2908 AnnotateScopeToken(*SS,
false);
2917 if (
ParsedType T = Actions.ActOnMSVCUnknownTypeName(
2918 *Tok.getIdentifierInfo(), Tok.getLocation(),
2919 DSC == DeclSpecContext::DSC_template_type_arg)) {
2920 const char *PrevSpec;
2923 Actions.getASTContext().getPrintingPolicy());
2936 if (SS ==
nullptr) {
2937 const char *TagName =
nullptr, *FixitTagName =
nullptr;
2940 switch (Actions.isTagName(*Tok.getIdentifierInfo(),
getCurScope())) {
2943 TagName=
"enum" ; FixitTagName =
"enum " ; TagKind=tok::kw_enum ;
break;
2945 TagName=
"union" ; FixitTagName =
"union " ;TagKind=tok::kw_union ;
break;
2947 TagName=
"struct"; FixitTagName =
"struct ";TagKind=tok::kw_struct;
break;
2949 TagName=
"__interface"; FixitTagName =
"__interface ";
2950 TagKind=tok::kw___interface;
break;
2952 TagName=
"class" ; FixitTagName =
"class " ;TagKind=tok::kw_class ;
break;
2956 IdentifierInfo *TokenName = Tok.getIdentifierInfo();
2957 LookupResult
R(Actions, TokenName, SourceLocation(),
2960 Diag(Loc, diag::err_use_of_tag_name_without_tag)
2961 << TokenName << TagName <<
getLangOpts().CPlusPlus
2967 Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
2968 << TokenName << TagName;
2972 if (TagKind == tok::kw_enum)
2973 ParseEnumSpecifier(Loc, DS, TemplateInfo, AS,
2974 DeclSpecContext::DSC_normal);
2976 ParseClassSpecifier(TagKind, Loc, DS, TemplateInfo, AS,
2978 DeclSpecContext::DSC_normal, Attrs);
2985 if (!isTypeSpecifier(DSC) && (!SS || DSC == DeclSpecContext::DSC_top_level ||
2986 DSC == DeclSpecContext::DSC_class)) {
2990 case tok::l_paren: {
2997 TentativeParsingAction PA(*
this);
2999 TPResult TPR = TryParseDeclarator(
false);
3002 if (TPR != TPResult::False) {
3010 if (DSC == DeclSpecContext::DSC_class ||
3011 (DSC == DeclSpecContext::DSC_top_level && SS)) {
3012 IdentifierInfo *II = Tok.getIdentifierInfo();
3013 if (Actions.isCurrentClassNameTypo(II, SS)) {
3014 Diag(Loc, diag::err_constructor_bad_name)
3015 << Tok.getIdentifierInfo() << II
3017 Tok.setIdentifierInfo(II);
3035 AnnotateScopeToken(*SS,
false);
3049 IdentifierInfo *II = Tok.getIdentifierInfo();
3051 Actions.DiagnoseUnknownTypeName(II, Loc,
getCurScope(), SS,
T,
3057 const char *PrevSpec;
3060 Actions.getASTContext().getPrintingPolicy());
3065 }
else if (II != Tok.getIdentifierInfo()) {
3078 if (IsTemplateName) {
3079 SourceLocation LAngle, RAngle;
3080 TemplateArgList Args;
3081 ParseTemplateIdAfterTemplateName(
true, LAngle, Args, RAngle);
3090Parser::DeclSpecContext
3094 return DeclSpecContext::DSC_class;
3096 return DeclSpecContext::DSC_top_level;
3098 return DeclSpecContext::DSC_template_param;
3100 return DeclSpecContext::DSC_template_arg;
3102 return DeclSpecContext::DSC_template_type_arg;
3105 return DeclSpecContext::DSC_trailing;
3108 return DeclSpecContext::DSC_alias_declaration;
3110 return DeclSpecContext::DSC_association;
3112 return DeclSpecContext::DSC_type_specifier;
3114 return DeclSpecContext::DSC_condition;
3116 return DeclSpecContext::DSC_conv_operator;
3118 return DeclSpecContext::DSC_new;
3133 return DeclSpecContext::DSC_normal;
3136 llvm_unreachable(
"Missing DeclaratorContext case");
3143 if (isTypeIdInParens()) {
3144 SourceLocation TypeLoc = Tok.getLocation();
3146 SourceRange TypeRange(Start, Tok.getLocation());
3147 if (Actions.ActOnAlignasTypeArgument(KWName, Ty, TypeLoc, TypeRange))
3164 assert(Tok.isOneOf(tok::kw_alignas, tok::kw__Alignas) &&
3165 "Not an alignment-specifier!");
3172 if (
T.expectAndConsume())
3177 SourceLocation EllipsisLoc;
3179 ParseAlignArgument(PP.getSpelling(KWTok),
T.getOpenLocation(),
3188 *EndLoc =
T.getCloseLocation();
3195 ArgExprs.push_back(ArgExpr.
get());
3196 Attrs.
addNew(KWName, KWLoc, AttributeScopeInfo(), ArgExprs.data(), 1, Kind,
3201void Parser::DistributeCLateParsedAttrs(
Decl *Dcl,
3207 for (
auto *LateAttr : *LateAttrs) {
3208 if (LateAttr->Decls.empty())
3209 LateAttr->addDecl(Dcl);
3215 assert(Tok.is(tok::kw___ptrauth));
3217 IdentifierInfo *KwName = Tok.getIdentifierInfo();
3221 if (
T.expectAndConsume())
3231 ArgExprs.push_back(ER.
get());
3235 SourceLocation EndLoc =
T.getCloseLocation();
3237 if (ArgExprs.empty() || ArgExprs.size() > 3) {
3238 Diag(KwLoc, diag::err_ptrauth_qualifier_bad_arg_count);
3242 Attrs.
addNew(KwName, SourceRange(KwLoc, EndLoc), AttributeScopeInfo(),
3243 ArgExprs.data(), ArgExprs.size(),
3244 ParsedAttr::Form::Keyword(
false,
3254 assert(Tok.is(tok::l_paren) &&
"Attribute arg list not starting with '('");
3259 if (Tok.is(tok::r_paren)) {
3260 Diag(Tok.getLocation(), diag::err_argument_required_after_attribute);
3267 using ExpressionKind =
3269 EnterExpressionEvaluationContext EC(
3271 ExpressionKind::EK_AttrArgument);
3279 ArgExprs.push_back(ArgExpr.
get());
3282 ASTContext &Ctx = Actions.getASTContext();
3288 Attrs.
addNew(&AttrName, SourceRange(AttrNameLoc,
Parens.getCloseLocation()),
3289 AttributeScopeInfo(), ArgExprs.data(), ArgExprs.size(), Form);
3292ExprResult Parser::ParseExtIntegerArgument() {
3293 assert(Tok.isOneOf(tok::kw__ExtInt, tok::kw__BitInt) &&
3294 "Not an extended int type");
3298 if (
T.expectAndConsume())
3307 if(
T.consumeClose())
3314 DeclSpecContext DSContext,
3318 bool EnteringContext = (DSContext == DeclSpecContext::DSC_class ||
3319 DSContext == DeclSpecContext::DSC_top_level);
3322 (Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw_decltype) ||
3323 (Tok.is(tok::annot_template_id) &&
NextToken().
is(tok::coloncolon))) &&
3329 bool HasScope = Tok.is(tok::annot_cxxscope);
3331 Token AfterScope = HasScope ?
NextToken() : Tok;
3335 bool MightBeDeclarator =
true;
3336 if (Tok.isOneOf(tok::kw_typename, tok::annot_typename)) {
3338 MightBeDeclarator =
false;
3339 }
else if (AfterScope.
is(tok::annot_template_id)) {
3342 TemplateIdAnnotation *Annot =
3345 MightBeDeclarator =
false;
3346 }
else if (AfterScope.
is(tok::identifier)) {
3351 if (
Next.isOneOf(tok::star, tok::amp, tok::ampamp, tok::identifier,
3352 tok::annot_cxxscope, tok::coloncolon)) {
3354 MightBeDeclarator = false;
3355 }
else if (HasScope) {
3360 Actions.RestoreNestedNameSpecifierAnnotation(
3361 Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS);
3363 Sema::NameClassification Classification = Actions.ClassifyName(
3366 switch (Classification.
getKind()) {
3372 llvm_unreachable(
"typo correction is not possible here");
3380 MightBeDeclarator =
false;
3395 if (MightBeDeclarator)
3398 const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy();
3400 diag::err_expected_after)
3411 ParsedTemplateInfo NotATemplate;
3412 ParseDeclarationSpecifiers(DS, NotATemplate, AS, DSContext, LateAttrs);
3416void Parser::ParseDeclarationSpecifiers(
3430 if (DSContext == DeclSpecContext::DSC_conv_operator)
3431 DSContext = DeclSpecContext::DSC_type_specifier;
3433 bool EnteringContext = (DSContext == DeclSpecContext::DSC_class ||
3434 DSContext == DeclSpecContext::DSC_top_level);
3435 bool AttrsLastTime =
false;
3436 ParsedAttributes attrs(AttrFactory);
3438 PrintingPolicy Policy = Actions.getPrintingPolicy();
3441 bool isStorageClass =
false;
3442 const char *PrevSpec =
nullptr;
3443 unsigned DiagID = 0;
3447 SourceLocation ConsumedEnd;
3456 if (
getLangOpts().MSVCCompat && Tok.is(tok::kw__Atomic) &&
3459 Tok.setKind(tok::identifier);
3461 SourceLocation Loc = Tok.getLocation();
3464 auto handleOpenCLImageKW = [&] (StringRef Ext,
TypeSpecifierType ImageTypeSpec) {
3468 Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
3469 Tok.setKind(tok::identifier);
3478 bool IsTemplateSpecOrInst =
3482 switch (Tok.getKind()) {
3484 if (Tok.isRegularKeywordAttribute())
3489 ProhibitAttributes(attrs);
3492 for (
const ParsedAttr &PA : attrs) {
3493 if (!PA.isCXX11Attribute() && !PA.isC23Attribute() &&
3494 !PA.isRegularKeywordAttribute())
3502 if (PA.getKind() == ParsedAttr::AT_VectorSize) {
3503 Diag(PA.getLoc(), diag::warn_attribute_ignored) << PA;
3510 if (PA.isTypeAttr() && PA.getKind() != ParsedAttr::AT_LifetimeBound &&
3511 PA.getKind() != ParsedAttr::AT_AnyX86NoCfCheck)
3514 if (PA.getKind() == ParsedAttr::AT_LifetimeBound)
3515 Diag(PA.getLoc(), diag::err_attribute_wrong_decl_type)
3516 << PA << PA.isRegularKeywordAttribute()
3519 Diag(PA.getLoc(), diag::err_attribute_not_type_attr)
3520 << PA << PA.isRegularKeywordAttribute();
3529 DS.
Finish(Actions, Policy);
3533 case tok::kw__Alignas:
3534 diagnoseUseOfC11Keyword(Tok);
3536 case tok::kw_alignas:
3542 if (Tok.getKind() == tok::kw_alignas)
3543 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName();
3549 if (!isAllowedCXX11AttributeSpecifier())
3550 goto DoneWithDeclSpec;
3553 ProhibitAttributes(attrs);
3558 attrs.Range = SourceRange();
3560 ParseCXX11Attributes(attrs);
3561 AttrsLastTime =
true;
3564 case tok::code_completion: {
3568 bool AllowNonIdentifiers
3574 bool AllowNestedNameSpecifiers
3575 = DSContext == DeclSpecContext::DSC_top_level ||
3579 Actions.CodeCompletion().CodeCompleteDeclSpec(
3580 getCurScope(), DS, AllowNonIdentifiers, AllowNestedNameSpecifiers);
3586 CCC = DSContext == DeclSpecContext::DSC_class
3589 else if (DSContext == DeclSpecContext::DSC_class)
3593 else if (CurParsedObjCImpl)
3597 Actions.CodeCompletion().CodeCompleteOrdinaryName(
getCurScope(), CCC);
3601 case tok::coloncolon:
3607 goto DoneWithDeclSpec;
3609 if (Tok.is(tok::coloncolon))
3610 goto DoneWithDeclSpec;
3613 case tok::annot_cxxscope: {
3615 goto DoneWithDeclSpec;
3618 if (TemplateInfo.TemplateParams)
3620 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
3621 Tok.getAnnotationRange(),
3627 TemplateIdAnnotation *TemplateId =
Next.is(tok::annot_template_id)
3628 ? takeTemplateIdAnnotation(
Next)
3634 ConsumeAnnotationToken();
3648 if ((DSContext == DeclSpecContext::DSC_top_level ||
3649 DSContext == DeclSpecContext::DSC_class) &&
3652 isConstructorDeclarator(
false,
3659 goto DoneWithDeclSpec;
3663 ConsumeAnnotationToken();
3664 assert(Tok.is(tok::annot_template_id) &&
3665 "ParseOptionalCXXScopeSpecifier not working");
3666 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
3676 ConsumeAnnotationToken();
3680 if (
Next.is(tok::annot_typename)) {
3682 ConsumeAnnotationToken();
3685 Tok.getAnnotationEndLoc(),
3686 PrevSpec, DiagID,
T, Policy);
3690 ConsumeAnnotationToken();
3694 Next.is(tok::annot_template_id) &&
3695 static_cast<TemplateIdAnnotation *
>(
Next.getAnnotationValue())
3698 ConsumeAnnotationToken();
3699 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
3703 if (
Next.isNot(tok::identifier))
3704 goto DoneWithDeclSpec;
3709 if ((DSContext == DeclSpecContext::DSC_top_level ||
3710 DSContext == DeclSpecContext::DSC_class) &&
3713 isConstructorDeclarator(
false,
3717 goto DoneWithDeclSpec;
3723 SuppressAccessChecks SAC(*
this, IsTemplateSpecOrInst);
3727 false,
false,
nullptr,
3730 isClassTemplateDeductionContext(DSContext), AllowImplicitTypename);
3732 if (IsTemplateSpecOrInst)
3740 if (TryAnnotateTypeConstraint())
3741 goto DoneWithDeclSpec;
3742 if (Tok.isNot(tok::annot_cxxscope) ||
3746 ConsumeAnnotationToken();
3747 ParsedAttributes Attrs(AttrFactory);
3748 if (ParseImplicitInt(DS, &SS, TemplateInfo, AS, DSContext, Attrs)) {
3749 if (!Attrs.
empty()) {
3750 AttrsLastTime =
true;
3751 attrs.takeAllAppendingFrom(Attrs);
3755 goto DoneWithDeclSpec;
3759 ConsumeAnnotationToken();
3762 DiagID, TypeRep, Policy);
3772 case tok::annot_typename: {
3776 goto DoneWithDeclSpec;
3785 ConsumeAnnotationToken();
3790 case tok::kw___is_signed:
3802 TryKeywordIdentFallback(
true);
3805 goto DoneWithDeclSpec;
3808 case tok::kw___super:
3809 case tok::kw_decltype:
3810 case tok::identifier:
3816 goto DoneWithDeclSpec;
3822 if (!
getLangOpts().DeclSpecKeyword && Tok.is(tok::identifier) &&
3823 Tok.getIdentifierInfo()->getName() ==
"__declspec") {
3824 Diag(Loc, diag::err_ms_attributes_not_enabled);
3834 if (
T.consumeOpen()) {
3835 assert(
false &&
"Not a left paren?");
3850 SuppressAccessChecks SAC(*
this, IsTemplateSpecOrInst);
3854 if (IsTemplateSpecOrInst)
3858 if (IsTemplateSpecOrInst)
3861 goto DoneWithDeclSpec;
3864 if (!Tok.is(tok::identifier))
3869 if (TryAltiVecToken(DS, Loc, PrevSpec, DiagID,
isInvalid))
3875 goto DoneWithDeclSpec;
3877 if (DSContext == DeclSpecContext::DSC_objc_method_result &&
3878 isObjCInstancetype()) {
3879 ParsedType TypeRep = Actions.ObjC().ActOnObjCInstanceType(Loc);
3882 DiagID, TypeRep, Policy);
3894 Actions.isCurrentClassName(*Tok.getIdentifierInfo(),
getCurScope()) &&
3895 isConstructorDeclarator(
true,
3898 goto DoneWithDeclSpec;
3901 *Tok.getIdentifierInfo(), Tok.getLocation(),
getCurScope(),
nullptr,
3902 false,
false,
nullptr,
false,
false,
3903 isClassTemplateDeductionContext(DSContext));
3908 if (TryAnnotateTypeConstraint())
3909 goto DoneWithDeclSpec;
3910 if (Tok.isNot(tok::identifier))
3912 ParsedAttributes Attrs(AttrFactory);
3913 if (ParseImplicitInt(DS,
nullptr, TemplateInfo, AS, DSContext, Attrs)) {
3914 if (!Attrs.
empty()) {
3915 AttrsLastTime =
true;
3916 attrs.takeAllAppendingFrom(Attrs);
3920 goto DoneWithDeclSpec;
3927 (DSContext == DeclSpecContext::DSC_class ||
3928 DSContext == DeclSpecContext::DSC_top_level) &&
3929 Actions.isDeductionGuideName(
getCurScope(), *Tok.getIdentifierInfo(),
3930 Tok.getLocation(), SS) &&
3931 isConstructorDeclarator(
true,
3933 goto DoneWithDeclSpec;
3936 DiagID, TypeRep, Policy);
3947 SourceLocation NewEndLoc;
3948 TypeResult NewTypeRep = parseObjCTypeArgsAndProtocolQualifiers(
3963 case tok::annot_template_id: {
3964 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
3975 TemplateId =
nullptr;
3983 tok::kw_volatile, tok::kw_restrict, tok::amp,
3985 Diag(Loc, diag::err_placeholder_expected_auto_or_decltype_auto)
3989 TemplateId, Policy);
3993 goto DoneWithDeclSpec;
3995 if (TemplateId && !
isInvalid && Actions.CheckTypeConstraint(TemplateId))
3996 TemplateId =
nullptr;
3998 ConsumeAnnotationToken();
3999 SourceLocation AutoLoc = Tok.getLocation();
4002 if (Tracker.consumeOpen()) {
4004 Diag(Tok, diag::err_expected) << tok::l_paren;
4008 Tracker.skipToEnd();
4009 Diag(Tok, diag::err_placeholder_expected_auto_or_decltype_auto)
4014 Tracker.consumeClose();
4017 ConsumedEnd = Tok.getLocation();
4022 DiagID, TemplateId, Policy);
4025 TemplateId, Policy);
4034 goto DoneWithDeclSpec;
4042 isConstructorDeclarator(
true,
4045 goto DoneWithDeclSpec;
4050 AnnotateTemplateIdTokenAsType(SS, AllowImplicitTypename);
4055 case tok::kw___attribute:
4056 case tok::kw___declspec:
4057 ParseAttributes(PAKM_GNU | PAKM_Declspec, DS.
getAttributes(), LateAttrs);
4061 case tok::kw___forceinline: {
4063 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
4064 SourceLocation AttrNameLoc = Tok.getLocation();
4066 nullptr, 0, tok::kw___forceinline);
4070 case tok::kw___unaligned:
4076 case tok::kw___ptrauth:
4080 case tok::kw___sptr:
4081 case tok::kw___uptr:
4082 case tok::kw___ptr64:
4083 case tok::kw___ptr32:
4085 case tok::kw___cdecl:
4086 case tok::kw___stdcall:
4087 case tok::kw___fastcall:
4088 case tok::kw___thiscall:
4089 case tok::kw___regcall:
4090 case tok::kw___vectorcall:
4094 case tok::kw___funcref:
4099 case tok::kw___pascal:
4104 case tok::kw___kernel:
4109 case tok::kw___noinline__:
4114 case tok::kw__Nonnull:
4115 case tok::kw__Nullable:
4116 case tok::kw__Nullable_result:
4117 case tok::kw__Null_unspecified:
4122 case tok::kw___kindof:
4124 AttributeScopeInfo(),
nullptr, 0,
4130 case tok::kw_typedef:
4132 PrevSpec, DiagID, Policy);
4133 isStorageClass =
true;
4135 case tok::kw_extern:
4137 Diag(Tok, diag::ext_thread_before) <<
"extern";
4139 PrevSpec, DiagID, Policy);
4140 isStorageClass =
true;
4142 case tok::kw___private_extern__:
4144 Loc, PrevSpec, DiagID, Policy);
4145 isStorageClass =
true;
4147 case tok::kw_static:
4149 Diag(Tok, diag::ext_thread_before) <<
"static";
4151 PrevSpec, DiagID, Policy);
4152 isStorageClass =
true;
4156 auto IsTypedefName = [&](
const Token &
T) {
4157 if (!
T.is(tok::identifier))
4159 IdentifierInfo *II =
T.getIdentifierInfo();
4163 LookupResult
R(Actions, II,
T.getLocation(),
4167 R.suppressDiagnostics();
4170 auto MayBeTypeSpecifier = [&]() {
4181 if (isKnownToBeTypeSpecifier(
T))
4200 if (MayBeTypeSpecifier()) {
4202 PrevSpec, DiagID, Policy);
4204 Diag(Tok, diag::ext_auto_storage_class)
4211 PrevSpec, DiagID, Policy);
4212 isStorageClass =
true;
4214 case tok::kw___auto_type:
4215 Diag(Tok, diag::ext_auto_type);
4219 case tok::kw_register:
4221 PrevSpec, DiagID, Policy);
4222 isStorageClass =
true;
4224 case tok::kw_mutable:
4226 PrevSpec, DiagID, Policy);
4227 isStorageClass =
true;
4229 case tok::kw___thread:
4232 isStorageClass =
true;
4234 case tok::kw_thread_local:
4236 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName();
4245 Loc, PrevSpec, DiagID);
4246 isStorageClass =
true;
4248 case tok::kw__Thread_local:
4249 diagnoseUseOfC11Keyword(Tok);
4251 Loc, PrevSpec, DiagID);
4252 isStorageClass =
true;
4256 case tok::kw_inline:
4259 case tok::kw_virtual:
4263 !
getActions().getOpenCLOptions().isAvailableOption(
4265 DiagID = diag::err_openclcxx_virtual_function;
4266 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
4269 DiagID = diag::err_hlsl_virtual_function;
4270 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
4276 case tok::kw_explicit: {
4277 SourceLocation ExplicitLoc = Loc;
4278 SourceLocation CloseParenLoc;
4280 ConsumedEnd = ExplicitLoc;
4282 if (Tok.is(tok::l_paren)) {
4284 DiagCompat(Tok.getLocation(), diag_compat::explicit_bool);
4286 ExprResult ExplicitExpr(
static_cast<Expr *
>(
nullptr));
4288 Tracker.consumeOpen();
4290 EnterExpressionEvaluationContext ConstantEvaluated(
4294 ConsumedEnd = Tok.getLocation();
4295 if (ExplicitExpr.isUsable()) {
4296 CloseParenLoc = Tok.getLocation();
4297 Tracker.consumeClose();
4299 Actions.ActOnExplicitBoolSpecifier(ExplicitExpr.get());
4301 Tracker.skipToEnd();
4303 Diag(Tok.getLocation(), diag::warn_cxx20_compat_explicit_bool);
4307 ExplicitSpec, CloseParenLoc);
4310 case tok::kw__Noreturn:
4311 diagnoseUseOfC11Keyword(Tok);
4316 case tok::kw_friend:
4317 if (DSContext == DeclSpecContext::DSC_class) {
4324 DiagID = diag::err_friend_invalid_in_context;
4330 case tok::kw___module_private__:
4335 case tok::kw_constexpr:
4337 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName();
4341 case tok::kw_consteval:
4345 case tok::kw_constinit:
4353 Diag(Tok, diag::err_unknown_typename) << Tok.getName();
4357 goto DoneWithDeclSpec;
4368 PrevSpec, DiagID, Policy);
4370 case tok::kw___int64:
4372 PrevSpec, DiagID, Policy);
4374 case tok::kw_signed:
4378 case tok::kw_unsigned:
4382 case tok::kw__Complex:
4384 Diag(Tok, diag::ext_c99_feature) << Tok.getName();
4388 case tok::kw__Imaginary:
4390 Diag(Tok, diag::ext_c99_feature) << Tok.getName();
4406 case tok::kw__ExtInt:
4407 case tok::kw__BitInt: {
4408 DiagnoseBitIntUse(Tok);
4413 ConsumedEnd = PrevTokLocation;
4416 case tok::kw___int128:
4424 case tok::kw___bf16:
4432 case tok::kw_double:
4436 case tok::kw__Float16:
4440 case tok::kw__Accum:
4442 "This keyword is only used when fixed point types are enabled "
4443 "with `-ffixed-point`");
4447 case tok::kw__Fract:
4449 "This keyword is only used when fixed point types are enabled "
4450 "with `-ffixed-point`");
4456 "This keyword is only used when fixed point types are enabled "
4457 "with `-ffixed-point`");
4460 case tok::kw___float128:
4464 case tok::kw___ibm128:
4468 case tok::kw_wchar_t:
4472 case tok::kw_char8_t:
4476 case tok::kw_char16_t:
4480 case tok::kw_char32_t:
4486 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName();
4490 Diag(Tok, diag::ext_c99_feature) << Tok.getName();
4492 if (Tok.is(tok::kw_bool) &&
4496 DiagID = diag::err_bool_redeclaration;
4498 Tok.setKind(tok::identifier);
4505 case tok::kw__Decimal32:
4509 case tok::kw__Decimal64:
4513 case tok::kw__Decimal128:
4517 case tok::kw___vector:
4520 case tok::kw___pixel:
4523 case tok::kw___bool:
4528 getLangOpts().getOpenCLCompatibleVersion() < 200) {
4531 Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
4532 Tok.setKind(tok::identifier);
4533 goto DoneWithDeclSpec;
4535 DiagID = diag::err_opencl_unknown_type_specifier;
4536 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
4542#define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
4543#define IMAGE_WRITE_TYPE(Type, Id, Ext)
4544#define IMAGE_READ_TYPE(ImgType, Id, Ext) \
4545 case tok::kw_##ImgType##_t: \
4546 if (!handleOpenCLImageKW(Ext, DeclSpec::TST_##ImgType##_t)) \
4547 goto DoneWithDeclSpec; \
4549#include "clang/Basic/OpenCLImageTypes.def"
4550 case tok::kw___unknown_anytype:
4552 PrevSpec, DiagID, Policy);
4557 case tok::kw_struct:
4558 case tok::kw___interface:
4559 case tok::kw_union: {
4566 ParsedAttributes Attributes(AttrFactory);
4567 ParseClassSpecifier(Kind, Loc, DS, TemplateInfo, AS,
4568 EnteringContext, DSContext, Attributes);
4572 if (!Attributes.empty()) {
4573 AttrsLastTime =
true;
4574 attrs.takeAllAppendingFrom(Attributes);
4582 ParseEnumSpecifier(Loc, DS, TemplateInfo, AS, DSContext);
4590 case tok::kw_volatile:
4594 case tok::kw_restrict:
4598 case tok::kw___ob_wrap:
4600 Diag(Loc, diag::warn_overflow_behavior_keyword_disabled)
4605 OverflowBehaviorType::OverflowBehaviorKind::Wrap, Loc, PrevSpec,
4608 case tok::kw___ob_trap:
4610 Diag(Loc, diag::warn_overflow_behavior_keyword_disabled)
4615 OverflowBehaviorType::OverflowBehaviorKind::Trap, Loc, PrevSpec,
4620 case tok::kw_typename:
4623 goto DoneWithDeclSpec;
4625 if (!Tok.is(tok::kw_typename))
4630 case tok::kw_typeof:
4631 case tok::kw_typeof_unqual:
4632 ParseTypeofSpecifier(DS);
4635 case tok::annot_decltype:
4636 ParseDecltypeSpecifier(DS);
4639 case tok::annot_pack_indexing_type:
4640 ParsePackIndexingType(DS);
4643 case tok::annot_pragma_pack:
4647 case tok::annot_pragma_ms_pragma:
4648 HandlePragmaMSPragma();
4651 case tok::annot_pragma_ms_vtordisp:
4652 HandlePragmaMSVtorDisp();
4655 case tok::annot_pragma_ms_pointers_to_members:
4656 HandlePragmaMSPointersToMembers();
4659 case tok::annot_pragma_export:
4660 HandlePragmaExport();
4663#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
4664#include "clang/Basic/BuiltinTraits.inc"
4668 if (!MaybeParseTypeTransformTypeSpecifier(DS))
4669 goto ParseIdentifier;
4672 case tok::kw__Atomic:
4677 diagnoseUseOfC11Keyword(Tok);
4679 ParseAtomicSpecifier(DS);
4687 case tok::kw___generic:
4692 if (!Actions.getLangOpts().OpenCLGenericAddressSpace) {
4693 DiagID = diag::err_opencl_unknown_type_specifier;
4694 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
4699 case tok::kw_private:
4703 goto DoneWithDeclSpec;
4705 case tok::kw___private:
4706 case tok::kw___global:
4707 case tok::kw___local:
4708 case tok::kw___constant:
4710 case tok::kw___read_only:
4711 case tok::kw___write_only:
4712 case tok::kw___read_write:
4715 case tok::kw_row_major:
4716 case tok::kw_column_major:
4717 case tok::kw_nointerpolation:
4718 case tok::kw_linear:
4719 case tok::kw_centroid:
4720 case tok::kw_noperspective:
4721 case tok::kw_sample:
4722 case tok::kw_center:
4723 case tok::kw_groupshared:
4731#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
4732 case tok::kw_##Name: \
4733 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, \
4736#include "clang/Basic/HLSLIntangibleTypes.def"
4738#define HLSL_PACKED_TYPE(Name, Id, SingletonId) \
4739 case tok::kw_##Name: \
4740 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, \
4743#include "clang/Basic/HLSLPackedTypes.def"
4750 goto DoneWithDeclSpec;
4752 SourceLocation StartLoc = Tok.getLocation();
4753 SourceLocation EndLoc;
4755 if (
Type.isUsable()) {
4757 PrevSpec, DiagID,
Type.get(),
4758 Actions.getASTContext().getPrintingPolicy()))
4759 Diag(StartLoc, DiagID) << PrevSpec;
4775 assert(PrevSpec &&
"Method did not return previous specifier!");
4778 if (DiagID == diag::ext_duplicate_declspec ||
4779 DiagID == diag::ext_warn_duplicate_declspec ||
4780 DiagID == diag::err_duplicate_declspec)
4781 Diag(Loc, DiagID) << PrevSpec
4784 else if (DiagID == diag::err_opencl_unknown_type_specifier) {
4788 Diag(Loc, DiagID) << PrevSpec;
4791 if (DiagID != diag::err_bool_redeclaration && ConsumedEnd.
isInvalid())
4795 AttrsLastTime =
false;
4807 if (!RD || !RD->getName().empty() || RD->isAnonymousStructOrUnion())
4810 for (
auto *I : RD->decls()) {
4811 auto *VD = dyn_cast<ValueDecl>(I);
4819 for (
const auto &DD : CAT->dependent_decls()) {
4820 if (!RD->containsDecl(DD.getDecl())) {
4821 P.
Diag(VD->getBeginLoc(), diag::err_count_attr_param_not_in_same_struct)
4822 << DD.getDecl() << CAT->getKind() << CAT->isArrayType();
4823 P.
Diag(DD.getDecl()->getBeginLoc(),
4824 diag::note_flexible_array_counted_by_attr_field)
4831void Parser::ParseStructDeclaration(
4836 if (Tok.is(tok::kw___extension__)) {
4838 ExtensionRAIIObject O(Diags);
4840 return ParseStructDeclaration(DS, FieldsCallback, LateFieldAttrs);
4844 ParsedAttributes Attrs(AttrFactory);
4845 MaybeParseCXX11Attributes(Attrs);
4848 ParseSpecifierQualifierList(DS);
4852 if (Tok.is(tok::semi)) {
4857 ProhibitAttributes(Attrs);
4858 RecordDecl *AnonRecord =
nullptr;
4859 Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(
4861 assert(!AnonRecord &&
"Did not expect anonymous struct or union here");
4867 bool FirstDeclarator =
true;
4868 SourceLocation CommaLoc;
4870 ParsingFieldDeclarator DeclaratorInfo(*
this, DS, Attrs);
4871 DeclaratorInfo.D.setCommaLoc(CommaLoc);
4874 if (!FirstDeclarator) {
4877 DiagnoseAndSkipCXX11Attributes();
4878 MaybeParseGNUAttributes(DeclaratorInfo.D);
4879 DiagnoseAndSkipCXX11Attributes();
4884 if (Tok.isNot(tok::colon)) {
4887 ParseDeclarator(DeclaratorInfo.D);
4889 DeclaratorInfo.D.SetIdentifier(
nullptr, Tok.getLocation());
4901 DeclaratorInfo.BitfieldSize = Res.
get();
4905 MaybeParseGNUAttributes(DeclaratorInfo.D, LateFieldAttrs);
4908 Decl *
Field = FieldsCallback(DeclaratorInfo);
4910 DistributeCLateParsedAttrs(Field, LateFieldAttrs);
4917 FirstDeclarator =
false;
4925 LPA.
Toks.push_back(AttrEnd);
4929 LPA.
Toks.push_back(Tok);
4930 PP.EnterTokenStream(LPA.
Toks,
true,
4937 ParsedAttributes Attrs(AttrFactory);
4941 SourceLocation(), ParsedAttr::Form::GNU(),
4946 while (Tok.isNot(tok::eof))
4950 if (Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData())
4958 assert(LA.
Decls.size() <= 1 &&
4959 "late field attribute expects to have at most one declaration.");
4961 ParsedAttributes Attrs = ParseLexedAttributeTokens(LA);
4965void Parser::CompleteLateParsedTypeAttributes(
4968 std::unique_ptr<LateParsedTypeAttribute> LTA(RawLTA);
4970 BoundsAttributedType *BATy = LTA->Info.TypeToComplete;
4971 if (!BATy || Actions.isLateParsedBoundsTypeRejected(BATy))
4974 ArrayRef<Decl *> Fields = LTA->Decls;
4976 AttributeFactory AF;
4977 ParsedAttributes Attrs(AF);
4978 ParseLexedTypeAttribute(*LTA, Attrs);
4983 assert(Attrs.
size() == 1);
4985 Expr *Arg = Attrs[0].getArgAsExpr(0);
4989 assert(!Fields.empty());
4990 for (Decl *FD : Fields)
4991 Valid &= Actions.ActOnLateParsedTypeAttrArgument(
4995 Attrs[0].setUsedAsTypeAttr();
4997 Attrs[0].setInvalid();
4999 LateTypeAttrs.clear();
5004 Self->ParseLexedTypeAttribute(*
this, OutAttrs);
5009 LateParsedAttrList::iterator It =
5011 if (
auto *LTA = dyn_cast<LateParsedTypeAttribute>(LA)) {
5012 To.push_back(<A->Info);
5017 From.erase(It, From.end());
5022 PrettyDeclStackTraceEntry CrashInfo(Actions.Context, TagDecl,
RecordLoc,
5023 "parsing struct/union body");
5027 if (
T.consumeOpen())
5031 Actions.ActOnTagStartDefinition(
getCurScope(), TagDecl);
5035 LateParsedAttrList LateFieldAttrs(
true,
5039 while (!tryParseMisplacedModuleImport() && Tok.isNot(tok::r_brace) &&
5040 Tok.isNot(tok::eof)) {
5044 if (Tok.is(tok::semi)) {
5050 if (Tok.isOneOf(tok::kw__Static_assert, tok::kw_static_assert)) {
5051 SourceLocation DeclEnd;
5052 ParseStaticAssertDeclaration(DeclEnd);
5056 if (Tok.is(tok::annot_pragma_pack)) {
5061 if (Tok.is(tok::annot_pragma_align)) {
5062 HandlePragmaAlign();
5066 if (Tok.isOneOf(tok::annot_pragma_openmp, tok::annot_attr_openmp)) {
5069 ParsedAttributes Attrs(AttrFactory);
5070 (void)ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs);
5074 if (Tok.is(tok::annot_pragma_openacc)) {
5076 ParsedAttributes Attrs(AttrFactory);
5082 Diag(Tok.getLocation(), diag::err_pragma_misplaced_in_decl)
5084 TagType, Actions.getASTContext().getPrintingPolicy());
5085 ConsumeAnnotationToken();
5089 if (!Tok.is(tok::at)) {
5090 auto CFieldCallback = [&](ParsingFieldDeclarator &FD) -> Decl * {
5094 FD.D.getDeclSpec().getSourceRange().getBegin(),
5095 FD.D, FD.BitfieldSize);
5101 ParsingDeclSpec DS(*
this);
5102 ParseStructDeclaration(DS, CFieldCallback, &LateFieldAttrs);
5105 if (!Tok.isObjCAtKeyword(tok::objc_defs)) {
5106 Diag(Tok, diag::err_unexpected_at);
5111 ExpectAndConsume(tok::l_paren);
5112 if (!Tok.is(tok::identifier)) {
5113 Diag(Tok, diag::err_expected) << tok::identifier;
5117 SmallVector<Decl *, 16> Fields;
5118 Actions.ObjC().ActOnDefs(
getCurScope(), TagDecl, Tok.getLocation(),
5119 Tok.getIdentifierInfo(), Fields);
5121 ExpectAndConsume(tok::r_paren);
5127 if (Tok.is(tok::r_brace)) {
5128 ExpectAndConsume(tok::semi, diag::ext_expected_semi_decl_list);
5132 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list);
5141 ParsedAttributes attrs(AttrFactory);
5143 MaybeParseGNUAttributes(attrs, &LateFieldAttrs);
5145 SmallVector<Decl *, 32> FieldDecls(TagDecl->
fields());
5148 T.getOpenLocation(),
T.getCloseLocation(), attrs);
5151 ParseLexedAttributeList(LateFieldAttrs,
nullptr,
false,
5154 Actions.ActOnTagFinishDefinition(
getCurScope(), TagDecl,
T.getRange());
5158 const ParsedTemplateInfo &TemplateInfo,
5161 if (Tok.is(tok::code_completion)) {
5170 ParsedAttributes attrs(AttrFactory);
5171 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec | PAKM_CXX11, attrs);
5173 SourceLocation ScopedEnumKWLoc;
5174 bool IsScopedUsingClassTag =
false;
5179 IsScopedUsingClassTag = Tok.is(tok::kw_class);
5184 ProhibitAttributes(attrs);
5187 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec | PAKM_CXX11, attrs);
5196 bool shouldDelayDiagsInTag =
5199 SuppressAccessChecks diagsFromTag(*
this, shouldDelayDiagsInTag);
5202 AllowDefiningTypeSpec AllowEnumSpecifier =
5204 bool CanBeOpaqueEnumDeclaration =
5205 DS.
isEmpty() && isOpaqueEnumDeclarationContext(DSC);
5208 (AllowEnumSpecifier == AllowDefiningTypeSpec::Yes ||
5209 CanBeOpaqueEnumDeclaration);
5213 CXXScopeSpec InvalidDeclScope;
5221 if (ParseOptionalCXXScopeSpecifier(Spec,
nullptr,
5226 if (Spec.
isSet() && Tok.isNot(tok::identifier)) {
5227 Diag(Tok, diag::err_expected) << tok::identifier;
5229 if (Tok.isNot(tok::l_brace)) {
5237 SS = std::move(Spec);
5241 if (Tok.isNot(tok::identifier) && Tok.isNot(tok::l_brace) &&
5242 Tok.isNot(tok::colon)) {
5243 Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace;
5252 IdentifierInfo *Name =
nullptr;
5253 SourceLocation NameLoc;
5254 if (Tok.is(tok::identifier)) {
5255 Name = Tok.getIdentifierInfo();
5259 if (!Name && ScopedEnumKWLoc.
isValid()) {
5262 Diag(Tok, diag::err_scoped_enum_missing_identifier);
5263 ScopedEnumKWLoc = SourceLocation();
5264 IsScopedUsingClassTag =
false;
5269 if (shouldDelayDiagsInTag)
5270 diagsFromTag.done();
5273 SourceRange BaseRange;
5275 bool CanBeBitfield =
5278 auto IsCXXTypeAhead = [
this]() {
5279 RevertingTentativeParsingAction PA(*
this);
5285 if (Tok.is(tok::colon) &&
5286 (!ParsingGenericAssociationType || IsCXXTypeAhead())) {
5311 if (CanBeBitfield && !isEnumBase(CanBeOpaqueEnumDeclaration)) {
5315 Diag(Tok.getLocation(), diag::err_anonymous_enum_bitfield);
5316 }
else if (CanHaveEnumBase || !ColonIsSacred) {
5323 DeclSpec DS(AttrFactory);
5327 DeclSpecContext::DSC_type_specifier);
5330 BaseType = Actions.ActOnTypeName(DeclaratorInfo);
5332 BaseRange = SourceRange(ColonLoc, DeclaratorInfo.getSourceRange().getEnd());
5336 DiagCompat(ColonLoc, diag_compat::cxx_enum_fixed_underlying_type)
5339 Diag(ColonLoc, diag::ext_ms_c_enum_fixed_underlying_type)
5342 DiagCompat(ColonLoc, diag_compat::c_enum_fixed_underlying_type)
5359 if (AllowEnumSpecifier == AllowDefiningTypeSpec::No)
5361 else if (Tok.is(tok::l_brace)) {
5363 Diag(Tok.getLocation(), diag::err_friend_decl_defines_type)
5369 ScopedEnumKWLoc = SourceLocation();
5370 IsScopedUsingClassTag =
false;
5376 }
else if (!isTypeSpecifier(DSC) &&
5377 (Tok.is(tok::semi) ||
5378 (Tok.isAtStartOfLine() &&
5379 !isValidAfterTypeSpecifier(CanBeBitfield)))) {
5384 if (Tok.isNot(tok::semi)) {
5386 ExpectAndConsume(tok::semi, diag::err_expected_after,
"enum");
5387 PP.EnterToken(Tok,
true);
5388 Tok.setKind(tok::semi);
5394 bool IsElaboratedTypeSpecifier =
5400 diagsFromTag.redelay();
5408 Diag(Tok, diag::err_enum_template);
5416 Diag(StartLoc, diag::err_explicit_instantiation_enum);
5420 assert(TemplateInfo.TemplateParams &&
"no template parameters");
5422 TemplateInfo.TemplateParams->size());
5427 Diag(Tok, diag::err_enumerator_unnamed_no_def);
5443 if (IsElaboratedTypeSpecifier && !
getLangOpts().MicrosoftExt &&
5445 ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
5446 diag::err_keyword_not_allowed,
5449 Diag(BaseRange.
getBegin(), diag::ext_enum_base_in_type_specifier)
5450 << (AllowEnumSpecifier == AllowDefiningTypeSpec::Yes) << BaseRange;
5451 else if (ScopedEnumKWLoc.
isValid())
5452 Diag(ScopedEnumKWLoc, diag::ext_elaborated_enum_class)
5456 stripTypeAttributesOffDeclSpec(attrs, DS, TUK);
5458 SkipBodyInfo SkipBody;
5461 SkipBody = Actions.shouldSkipAnonEnumBody(
getCurScope(),
5466 bool IsDependent =
false;
5467 const char *PrevSpec =
nullptr;
5472 TParams, Owned, IsDependent, ScopedEnumKWLoc,
5473 IsScopedUsingClassTag,
5474 BaseType, DSC == DeclSpecContext::DSC_type_specifier,
5475 DSC == DeclSpecContext::DSC_template_param ||
5476 DSC == DeclSpecContext::DSC_template_type_arg,
5477 OffsetOfState, &SkipBody).get();
5487 NameLoc.
isValid() ? NameLoc : StartLoc,
5488 PrevSpec, DiagID, TagDecl, Owned,
5489 Actions.getASTContext().getPrintingPolicy()))
5490 Diag(StartLoc, DiagID) << PrevSpec;
5499 Diag(Tok, diag::err_expected_type_name_after_typename);
5505 if (
Type.isInvalid()) {
5511 NameLoc.
isValid() ? NameLoc : StartLoc,
5512 PrevSpec, DiagID,
Type.get(),
5513 Actions.getASTContext().getPrintingPolicy()))
5514 Diag(StartLoc, DiagID) << PrevSpec;
5533 ParseEnumBody(StartLoc, D, &SkipBody);
5535 !Actions.ActOnDuplicateDefinition(
getCurScope(), TagDecl, SkipBody)) {
5542 NameLoc.
isValid() ? NameLoc : StartLoc,
5543 PrevSpec, DiagID, TagDecl, Owned,
5544 Actions.getASTContext().getPrintingPolicy()))
5545 Diag(StartLoc, DiagID) << PrevSpec;
5552 Actions.ActOnTagStartDefinition(
getCurScope(), EnumDecl);
5560 Diag(
T.getOpenLocation(), diag::ext_ms_c_empty_enum_type)
5561 << SourceRange(
T.getOpenLocation(), Tok.getLocation());
5563 Diag(Tok, diag::err_empty_enum);
5566 SmallVector<Decl *, 32> EnumConstantDecls;
5567 SmallVector<SuppressAccessChecks, 32> EnumAvailabilityDiags;
5569 Decl *LastEnumConstDecl =
nullptr;
5572 while (Tok.isNot(tok::r_brace)) {
5575 if (Tok.isNot(tok::identifier)) {
5576 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
5582 IdentifierInfo *Ident = Tok.getIdentifierInfo();
5586 ParsedAttributes attrs(AttrFactory);
5587 MaybeParseGNUAttributes(attrs);
5588 if (isAllowedCXX11AttributeSpecifier()) {
5590 DiagCompat(Tok.getLocation(), diag_compat::ns_enum_attribute)
5592 ParseCXX11Attributes(attrs);
5595 SourceLocation EqualLoc;
5597 EnumAvailabilityDiags.emplace_back(*
this);
5599 EnterExpressionEvaluationContext ConstantEvaluated(
5608 Decl *EnumConstDecl = Actions.ActOnEnumConstant(
5609 getCurScope(), EnumDecl, LastEnumConstDecl, IdentLoc, Ident, attrs,
5610 EqualLoc, AssignedVal.
get(), SkipBody);
5611 EnumAvailabilityDiags.back().done();
5613 EnumConstantDecls.push_back(EnumConstDecl);
5614 LastEnumConstDecl = EnumConstDecl;
5616 if (Tok.is(tok::identifier)) {
5619 Diag(Loc, diag::err_enumerator_list_missing_comma)
5626 SourceLocation CommaLoc;
5627 if (Tok.isNot(tok::r_brace) && !
TryConsumeToken(tok::comma, CommaLoc)) {
5629 Diag(Tok.getLocation(), diag::err_expected_either) << tok::r_brace
5632 Diag(Tok.getLocation(), diag::err_expected_end_of_enumerator);
5642 if (Tok.is(tok::r_brace) && CommaLoc.
isValid()) {
5644 DiagCompat(CommaLoc, diag_compat::cxx_enumerator_list_comma)
5647 Diag(CommaLoc, diag::ext_enumerator_list_comma_c)
5657 ParsedAttributes attrs(AttrFactory);
5658 MaybeParseGNUAttributes(attrs);
5660 Actions.ActOnEnumBody(StartLoc,
T.getRange(), EnumDecl, EnumConstantDecls,
5664 assert(EnumConstantDecls.size() == EnumAvailabilityDiags.size());
5665 for (
size_t i = 0, e = EnumConstantDecls.size(); i != e; ++i) {
5667 EnumAvailabilityDiags[i].redelay();
5668 PD.complete(EnumConstantDecls[i]);
5672 Actions.ActOnTagFinishDefinition(
getCurScope(), EnumDecl,
T.getRange());
5677 if (!isValidAfterTypeSpecifier(CanBeBitfield)) {
5678 ExpectAndConsume(tok::semi, diag::err_expected_after,
"enum");
5682 PP.EnterToken(Tok,
true);
5683 Tok.setKind(tok::semi);
5687bool Parser::isKnownToBeTypeSpecifier(
const Token &
Tok)
const {
5688 switch (Tok.getKind()) {
5689 default:
return false;
5693 case tok::kw___int64:
5694 case tok::kw___int128:
5695 case tok::kw_signed:
5696 case tok::kw_unsigned:
5697 case tok::kw__Complex:
5698 case tok::kw__Imaginary:
5701 case tok::kw_wchar_t:
5702 case tok::kw_char8_t:
5703 case tok::kw_char16_t:
5704 case tok::kw_char32_t:
5706 case tok::kw__ExtInt:
5707 case tok::kw__BitInt:
5708 case tok::kw___bf16:
5711 case tok::kw_double:
5712 case tok::kw__Accum:
5713 case tok::kw__Fract:
5714 case tok::kw__Float16:
5715 case tok::kw___float128:
5716 case tok::kw___ibm128:
5719 case tok::kw__Decimal32:
5720 case tok::kw__Decimal64:
5721 case tok::kw__Decimal128:
5722 case tok::kw___vector:
5723#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
5724#include "clang/Basic/OpenCLImageTypes.def"
5725#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
5726#include "clang/Basic/HLSLIntangibleTypes.def"
5727#define HLSL_PACKED_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
5728#include "clang/Basic/HLSLPackedTypes.def"
5732 case tok::kw_struct:
5733 case tok::kw___interface:
5738 case tok::kw_typeof:
5739 case tok::kw_typeof_unqual:
5742 case tok::kw__Atomic:
5745 case tok::annot_typename:
5750bool Parser::isTypeSpecifierQualifier(
const Token &
Tok) {
5751 switch (Tok.getKind()) {
5752 default:
return false;
5754 case tok::identifier:
5755 if (TryAltiVecVectorToken())
5758 case tok::kw_typename:
5767 case tok::coloncolon:
5777 case tok::kw___attribute:
5779 case tok::kw_typeof:
5780 case tok::kw_typeof_unqual:
5785 case tok::kw___int64:
5786 case tok::kw___int128:
5787 case tok::kw_signed:
5788 case tok::kw_unsigned:
5789 case tok::kw__Complex:
5790 case tok::kw__Imaginary:
5793 case tok::kw_wchar_t:
5794 case tok::kw_char8_t:
5795 case tok::kw_char16_t:
5796 case tok::kw_char32_t:
5798 case tok::kw__ExtInt:
5799 case tok::kw__BitInt:
5801 case tok::kw___bf16:
5803 case tok::kw_double:
5804 case tok::kw__Accum:
5805 case tok::kw__Fract:
5806 case tok::kw__Float16:
5807 case tok::kw___float128:
5808 case tok::kw___ibm128:
5811 case tok::kw__Decimal32:
5812 case tok::kw__Decimal64:
5813 case tok::kw__Decimal128:
5814 case tok::kw___vector:
5815#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
5816#include "clang/Basic/OpenCLImageTypes.def"
5817#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
5818#include "clang/Basic/HLSLIntangibleTypes.def"
5819#define HLSL_PACKED_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
5820#include "clang/Basic/HLSLPackedTypes.def"
5824 case tok::kw_struct:
5825 case tok::kw___interface:
5832 case tok::kw_volatile:
5833 case tok::kw_restrict:
5834 case tok::kw___ob_wrap:
5835 case tok::kw___ob_trap:
5839 case tok::kw___unknown_anytype:
5842 case tok::annot_typename:
5849 case tok::kw___cdecl:
5850 case tok::kw___stdcall:
5851 case tok::kw___fastcall:
5852 case tok::kw___thiscall:
5853 case tok::kw___regcall:
5854 case tok::kw___vectorcall:
5856 case tok::kw___ptr64:
5857 case tok::kw___ptr32:
5858 case tok::kw___pascal:
5859 case tok::kw___unaligned:
5860 case tok::kw___ptrauth:
5862 case tok::kw__Nonnull:
5863 case tok::kw__Nullable:
5864 case tok::kw__Nullable_result:
5865 case tok::kw__Null_unspecified:
5867 case tok::kw___kindof:
5869 case tok::kw___private:
5870 case tok::kw___local:
5871 case tok::kw___global:
5872 case tok::kw___constant:
5873 case tok::kw___generic:
5874 case tok::kw___read_only:
5875 case tok::kw___read_write:
5876 case tok::kw___write_only:
5877 case tok::kw___funcref:
5880 case tok::kw_private:
5884 case tok::kw__Atomic:
5888 case tok::kw_nointerpolation:
5889 case tok::kw_linear:
5890 case tok::kw_centroid:
5891 case tok::kw_noperspective:
5892 case tok::kw_sample:
5893 case tok::kw_center:
5894 case tok::kw_groupshared:
5898 case tok::kw_row_major:
5899 case tok::kw_column_major:
5905 assert(PP.isIncrementalProcessingEnabled() &&
"Not in incremental mode");
5909 ParsedStmtContext SubStmtCtx = ParsedStmtContext();
5912 TopLevelStmtDecl *TLSD = Actions.ActOnStartTopLevelStmtDecl(
getCurScope());
5913 StmtResult R = ParseStatementOrDeclaration(Stmts, SubStmtCtx);
5914 Actions.ActOnFinishTopLevelStmtDecl(TLSD,
R.get());
5915 if (!
R.isUsable()) {
5916 R = Actions.ActOnNullStmt(Tok.getLocation());
5920 if (Tok.is(tok::eof) && Tok.getEofData()) {
5925 SmallVector<Decl *, 2> DeclsInGroup;
5926 DeclsInGroup.push_back(TLSD);
5929 for (Stmt *S : Stmts) {
5932 TopLevelStmtDecl *D = Actions.ActOnStartTopLevelStmtDecl(
getCurScope());
5933 Actions.ActOnFinishTopLevelStmtDecl(D, S);
5934 DeclsInGroup.push_back(D);
5937 return Actions.BuildDeclaratorGroup(DeclsInGroup);
5940bool Parser::isDeclarationSpecifier(
5942 bool DisambiguatingWithExpression) {
5943 switch (Tok.getKind()) {
5944 default:
return false;
5951 case tok::identifier:
5955 if (TryAltiVecVectorToken())
5958 case tok::kw_decltype:
5959 case tok::kw_typename:
5964 if (TryAnnotateTypeConstraint())
5966 if (Tok.is(tok::identifier))
5974 if (DisambiguatingWithExpression &&
5975 isStartOfObjCClassMessageMissingOpenBracket())
5978 return isDeclarationSpecifier(AllowImplicitTypename);
5980 case tok::coloncolon:
5994 case tok::kw_typedef:
5995 case tok::kw_extern:
5996 case tok::kw___private_extern__:
5997 case tok::kw_static:
5999 case tok::kw___auto_type:
6000 case tok::kw_register:
6001 case tok::kw___thread:
6002 case tok::kw_thread_local:
6003 case tok::kw__Thread_local:
6006 case tok::kw___module_private__:
6009 case tok::kw___unknown_anytype:
6014 case tok::kw___int64:
6015 case tok::kw___int128:
6016 case tok::kw_signed:
6017 case tok::kw_unsigned:
6018 case tok::kw__Complex:
6019 case tok::kw__Imaginary:
6022 case tok::kw_wchar_t:
6023 case tok::kw_char8_t:
6024 case tok::kw_char16_t:
6025 case tok::kw_char32_t:
6028 case tok::kw__ExtInt:
6029 case tok::kw__BitInt:
6031 case tok::kw___bf16:
6033 case tok::kw_double:
6034 case tok::kw__Accum:
6035 case tok::kw__Fract:
6036 case tok::kw__Float16:
6037 case tok::kw___float128:
6038 case tok::kw___ibm128:
6041 case tok::kw__Decimal32:
6042 case tok::kw__Decimal64:
6043 case tok::kw__Decimal128:
6044 case tok::kw___vector:
6048 case tok::kw_struct:
6050 case tok::kw___interface:
6056 case tok::kw_volatile:
6057 case tok::kw_restrict:
6058 case tok::kw___ob_wrap:
6059 case tok::kw___ob_trap:
6063 case tok::kw_inline:
6064 case tok::kw_virtual:
6065 case tok::kw_explicit:
6066 case tok::kw__Noreturn:
6069 case tok::kw__Alignas:
6072 case tok::kw_friend:
6075 case tok::kw_static_assert:
6076 case tok::kw__Static_assert:
6079 case tok::kw_typeof:
6080 case tok::kw_typeof_unqual:
6083 case tok::kw___attribute:
6086 case tok::annot_decltype:
6087 case tok::annot_pack_indexing_type:
6088 case tok::kw_constexpr:
6091 case tok::kw_consteval:
6092 case tok::kw_constinit:
6095 case tok::kw__Atomic:
6098 case tok::kw_alignas:
6108 case tok::annot_typename:
6109 return !DisambiguatingWithExpression ||
6110 !isStartOfObjCClassMessageMissingOpenBracket();
6113 case tok::annot_template_id: {
6114 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
6119 return isTypeConstraintAnnotation() &&
6123 case tok::annot_cxxscope: {
6124 TemplateIdAnnotation *TemplateId =
6132 if (
NextToken().
is(tok::identifier) && TryAnnotateTypeConstraint())
6134 return isTypeConstraintAnnotation() &&
6138 case tok::kw___declspec:
6139 case tok::kw___cdecl:
6140 case tok::kw___stdcall:
6141 case tok::kw___fastcall:
6142 case tok::kw___thiscall:
6143 case tok::kw___regcall:
6144 case tok::kw___vectorcall:
6146 case tok::kw___sptr:
6147 case tok::kw___uptr:
6148 case tok::kw___ptr64:
6149 case tok::kw___ptr32:
6150 case tok::kw___forceinline:
6151 case tok::kw___pascal:
6152 case tok::kw___unaligned:
6153 case tok::kw___ptrauth:
6155 case tok::kw__Nonnull:
6156 case tok::kw__Nullable:
6157 case tok::kw__Nullable_result:
6158 case tok::kw__Null_unspecified:
6160 case tok::kw___kindof:
6162 case tok::kw___private:
6163 case tok::kw___local:
6164 case tok::kw___global:
6165 case tok::kw___constant:
6166 case tok::kw___generic:
6167 case tok::kw___read_only:
6168 case tok::kw___read_write:
6169 case tok::kw___write_only:
6170#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
6171#include "clang/Basic/OpenCLImageTypes.def"
6172#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
6173#include "clang/Basic/HLSLIntangibleTypes.def"
6174#define HLSL_PACKED_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
6175#include "clang/Basic/HLSLPackedTypes.def"
6177 case tok::kw___funcref:
6178 case tok::kw_groupshared:
6181 case tok::kw_nointerpolation:
6182 case tok::kw_linear:
6183 case tok::kw_centroid:
6184 case tok::kw_noperspective:
6185 case tok::kw_sample:
6186 case tok::kw_center:
6187 case tok::kw_row_major:
6188 case tok::kw_column_major:
6191 case tok::kw_private:
6196bool Parser::isConstructorDeclarator(
bool IsUnqualified,
bool DeductionGuide,
6198 const ParsedTemplateInfo *TemplateInfo) {
6199 RevertingTentativeParsingAction TPA(*
this);
6202 if (TemplateInfo && TemplateInfo->TemplateParams)
6205 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
6212 if (Tok.is(tok::identifier)) {
6216 }
else if (Tok.is(tok::annot_template_id)) {
6217 ConsumeAnnotationToken();
6224 SkipCXX11Attributes();
6227 if (Tok.isNot(tok::l_paren)) {
6234 if (Tok.is(tok::r_paren) ||
6235 (Tok.is(tok::ellipsis) &&
NextToken().
is(tok::r_paren))) {
6241 if (isCXX11AttributeSpecifier(
false,
6248 DeclaratorScopeObj DeclScopeObj(*
this, SS);
6250 DeclScopeObj.EnterDeclaratorScope();
6253 ParsedAttributes Attrs(AttrFactory);
6254 MaybeParseMicrosoftAttributes(Attrs);
6263 bool IsConstructor =
false;
6269 if (Tok.is(tok::kw_this)) {
6271 return isDeclarationSpecifier(ITC);
6274 if (isDeclarationSpecifier(ITC))
6275 IsConstructor =
true;
6276 else if (Tok.is(tok::identifier) ||
6277 (Tok.is(tok::annot_cxxscope) &&
NextToken().
is(tok::identifier))) {
6282 if (Tok.is(tok::annot_cxxscope))
6283 ConsumeAnnotationToken();
6289 switch (Tok.getKind()) {
6295 case tok::coloncolon:
6308 SkipCXX11Attributes();
6310 if (DeductionGuide) {
6312 IsConstructor = Tok.is(tok::arrow);
6315 if (Tok.is(tok::colon) || Tok.is(tok::kw_try)) {
6319 IsConstructor =
true;
6321 if (Tok.is(tok::semi) || Tok.is(tok::l_brace)) {
6334 IsConstructor = IsUnqualified;
6339 IsConstructor =
true;
6343 return IsConstructor;
6346void Parser::ParseTypeQualifierListOpt(
6347 DeclSpec &DS,
unsigned AttrReqs,
bool AtomicOrPtrauthAllowed,
6350 if ((AttrReqs & AR_CXX11AttributesParsed) &&
6351 isAllowedCXX11AttributeSpecifier()) {
6352 ParsedAttributes Attrs(AttrFactory);
6353 ParseCXX11Attributes(Attrs);
6357 SourceLocation EndLoc;
6361 const char *PrevSpec =
nullptr;
6362 unsigned DiagID = 0;
6363 SourceLocation Loc = Tok.getLocation();
6365 switch (Tok.getKind()) {
6366 case tok::code_completion:
6368 if (CodeCompletionHandler)
6369 CodeCompletionHandler();
6371 Actions.CodeCompletion().CodeCompleteTypeQualifiers(DS);
6378 case tok::kw_volatile:
6382 case tok::kw_restrict:
6386 case tok::kw___ob_wrap:
6388 Diag(Loc, diag::warn_overflow_behavior_keyword_disabled)
6393 OverflowBehaviorType::OverflowBehaviorKind::Wrap, Loc, PrevSpec,
6396 case tok::kw___ob_trap:
6398 Diag(Loc, diag::warn_overflow_behavior_keyword_disabled)
6403 OverflowBehaviorType::OverflowBehaviorKind::Trap, Loc, PrevSpec,
6406 case tok::kw__Atomic:
6407 if (!AtomicOrPtrauthAllowed)
6408 goto DoneWithTypeQuals;
6409 diagnoseUseOfC11Keyword(Tok);
6415 case tok::kw_private:
6417 goto DoneWithTypeQuals;
6419 case tok::kw___private:
6420 case tok::kw___global:
6421 case tok::kw___local:
6422 case tok::kw___constant:
6423 case tok::kw___generic:
6424 case tok::kw___read_only:
6425 case tok::kw___write_only:
6426 case tok::kw___read_write:
6430 case tok::kw_groupshared:
6434 case tok::kw_nointerpolation:
6435 case tok::kw_linear:
6436 case tok::kw_centroid:
6437 case tok::kw_noperspective:
6438 case tok::kw_sample:
6439 case tok::kw_center:
6445 case tok::kw___ptrauth:
6446 if (!AtomicOrPtrauthAllowed)
6447 goto DoneWithTypeQuals;
6449 EndLoc = PrevTokLocation;
6452 case tok::kw___unaligned:
6456 case tok::kw___uptr:
6461 if (TryKeywordIdentFallback(
false))
6465 case tok::kw___sptr:
6467 case tok::kw___ptr64:
6468 case tok::kw___ptr32:
6469 case tok::kw___cdecl:
6470 case tok::kw___stdcall:
6471 case tok::kw___fastcall:
6472 case tok::kw___thiscall:
6473 case tok::kw___regcall:
6474 case tok::kw___vectorcall:
6475 if (AttrReqs & AR_DeclspecAttributesParsed) {
6479 goto DoneWithTypeQuals;
6481 case tok::kw___funcref:
6485 case tok::kw___pascal:
6486 if (AttrReqs & AR_VendorAttributesParsed) {
6490 goto DoneWithTypeQuals;
6493 case tok::kw__Nonnull:
6494 case tok::kw__Nullable:
6495 case tok::kw__Nullable_result:
6496 case tok::kw__Null_unspecified:
6501 case tok::kw___kindof:
6503 AttributeScopeInfo(),
nullptr, 0,
6508 case tok::kw___attribute:
6509 if (AttrReqs & AR_GNUAttributesParsedAndRejected)
6511 Diag(Tok, diag::err_attributes_not_allowed);
6515 if (AttrReqs & AR_GNUAttributesParsed ||
6516 AttrReqs & AR_GNUAttributesParsedAndRejected) {
6526 DS.
Finish(Actions, Actions.getASTContext().getPrintingPolicy());
6534 assert(PrevSpec &&
"Method did not return previous specifier!");
6535 Diag(Tok, DiagID) << PrevSpec;
6544 Actions.runWithSufficientStackSpace(D.
getBeginLoc(), [&] {
6545 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
6551 if (Kind == tok::star || Kind == tok::caret)
6555 if (Kind == tok::kw_pipe && Lang.OpenCL &&
6556 Lang.getOpenCLCompatibleVersion() >= 200)
6559 if (!Lang.CPlusPlus)
6562 if (Kind == tok::amp)
6570 if (Kind == tok::ampamp)
6581 for (
unsigned Idx = 0; Idx != NumTypes; ++Idx)
6588void Parser::ParseDeclaratorInternal(
Declarator &D,
6589 DirectDeclParseFunction DirectDeclParser) {
6590 if (Diags.hasAllExtensionsSilenced())
6600 (Tok.is(tok::coloncolon) ||
6601 (Tok.is(tok::kw_decltype) &&
NextToken().
is(tok::l_paren)) ||
6602 (Tok.is(tok::identifier) &&
6604 Tok.is(tok::annot_cxxscope))) {
6605 TentativeParsingAction TPA(*
this,
true);
6611 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
6623 Tok.is(tok::star)) {
6627 checkCompoundToken(SS.
getEndLoc(), tok::coloncolon,
6628 CompoundToken::MemberPtr);
6633 DeclSpec DS(AttrFactory);
6634 ParseTypeQualifierListOpt(DS);
6638 Actions.runWithSufficientStackSpace(D.
getBeginLoc(), [&] {
6639 ParseDeclaratorInternal(D, DirectDeclParser);
6653 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
6663 AnnotateScopeToken(SS,
true);
6665 if (DirectDeclParser)
6666 (this->*DirectDeclParser)(D);
6674 DeclSpec DS(AttrFactory);
6675 ParseTypeQualifierListOpt(DS);
6684 if (DirectDeclParser)
6685 (this->*DirectDeclParser)(D);
6694 if (Kind == tok::star || Kind == tok::caret) {
6696 DeclSpec DS(AttrFactory);
6700 unsigned Reqs = AR_CXX11AttributesParsed | AR_DeclspecAttributesParsed |
6702 ? AR_GNUAttributesParsed
6703 : AR_GNUAttributesParsedAndRejected);
6704 ParseTypeQualifierListOpt(DS, Reqs,
true,
6709 Actions.runWithSufficientStackSpace(
6710 D.
getBeginLoc(), [&] { ParseDeclaratorInternal(D, DirectDeclParser); });
6711 if (Kind == tok::star)
6726 DeclSpec DS(AttrFactory);
6730 if (Kind == tok::ampamp)
6731 DiagCompat(Loc, diag_compat::rvalue_reference);
6734 ParseTypeQualifierListOpt(DS);
6743 diag::err_invalid_reference_qualifier_application) <<
"const";
6746 diag::err_invalid_reference_qualifier_application) <<
"volatile";
6750 diag::err_invalid_reference_qualifier_application) <<
"_Atomic";
6754 Actions.runWithSufficientStackSpace(
6755 D.
getBeginLoc(), [&] { ParseDeclaratorInternal(D, DirectDeclParser); });
6762 Diag(InnerChunk.
Loc, diag::err_illegal_decl_reference_to_reference)
6765 Diag(InnerChunk.
Loc, diag::err_illegal_decl_reference_to_reference)
6794void Parser::ParseDirectDeclarator(
Declarator &D) {
6801 return ParseDecompositionDeclarator(D);
6815 ParseOptionalCXXScopeSpecifier(
6817 false, EnteringContext);
6832 if (Actions.ShouldEnterDeclaratorScope(
getCurScope(),
6836 DeclScopeObj.EnterDeclaratorScope();
6843 goto PastIdentifier;
6859 !Actions.containsUnexpandedParameterPacks(D) &&
6867 DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, D);
6877 if (Tok.isOneOf(tok::identifier, tok::kw_operator, tok::annot_template_id,
6881 bool AllowConstructorName;
6882 bool AllowDeductionGuide;
6884 AllowConstructorName =
false;
6885 AllowDeductionGuide =
false;
6889 AllowDeductionGuide =
false;
6897 SourceLocation TemplateKWLoc;
6902 true, AllowConstructorName,
6903 AllowDeductionGuide, &TemplateKWLoc,
6916 DeclScopeObj.EnterDeclaratorScope();
6923 goto PastIdentifier;
6929 diag::err_expected_unqualified_id)
6932 goto PastIdentifier;
6936 "There's a C++-specific check for tok::identifier above");
6937 assert(Tok.getIdentifierInfo() &&
"Not an identifier?");
6938 D.
SetIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
6941 goto PastIdentifier;
6946 bool DiagnoseIdentifier =
false;
6950 DiagnoseIdentifier =
true;
6953 DiagnoseIdentifier =
6961 !isCXX11VirtSpecifier(Tok))
6963 tok::comma, tok::semi, tok::equal, tok::l_brace, tok::kw_try);
6964 if (DiagnoseIdentifier) {
6965 Diag(Tok.getLocation(), diag::err_unexpected_unqualified_id)
6969 goto PastIdentifier;
6973 if (Tok.is(tok::l_paren)) {
6978 RevertingTentativeParsingAction PA(*
this);
6983 goto PastIdentifier;
6990 ParseParenDeclarator(D);
7008 DeclScopeObj.EnterDeclaratorScope();
7019 diag::ext_abstract_pack_declarator_parens);
7021 if (Tok.getKind() == tok::annot_pragma_parser_crash)
7023 if (Tok.is(tok::l_square))
7024 return ParseMisplacedBracketDeclarator(D);
7029 !Tok.isAnnotation() && Tok.getIdentifierInfo() &&
7030 Tok.getIdentifierInfo()->isCPlusPlusKeyword(
getLangOpts())) {
7032 diag::err_expected_member_name_or_semi_objcxx_keyword)
7033 << Tok.getIdentifierInfo()
7036 D.
SetIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
7039 goto PastIdentifier;
7042 diag::err_expected_member_name_or_semi)
7046 if (Tok.getKind() == tok::TokenKind::kw_while) {
7047 Diag(Tok, diag::err_while_loop_outside_of_a_function);
7049 if (Tok.isOneOf(tok::period, tok::arrow))
7050 Diag(Tok, diag::err_invalid_operator_on_type) << Tok.is(tok::arrow);
7053 if (Tok.isAtStartOfLine() && Loc.
isValid())
7054 Diag(PP.getLocForEndOfToken(Loc), diag::err_expected_unqualified_id)
7058 diag::err_expected_unqualified_id)
7063 diag::err_expected_either)
7064 << tok::identifier << tok::l_paren;
7073 "Haven't past the location of the identifier yet?");
7077 MaybeParseCXX11Attributes(D);
7080 if (Tok.is(tok::l_paren)) {
7092 bool IsAmbiguous =
false;
7104 AllowImplicitTypename =
7112 TentativelyDeclaredIdentifiers.push_back(D.
getIdentifier());
7113 bool IsFunctionDecl =
7114 isCXXFunctionDeclarator(&IsAmbiguous, AllowImplicitTypename);
7115 TentativelyDeclaredIdentifiers.pop_back();
7116 if (!IsFunctionDecl)
7119 ParsedAttributes attrs(AttrFactory);
7122 if (IsFunctionDeclaration)
7123 Actions.ActOnStartFunctionDeclarationDeclarator(D,
7124 TemplateParameterDepth);
7125 ParseFunctionDeclarator(D, attrs,
T, IsAmbiguous);
7126 if (IsFunctionDeclaration)
7127 Actions.ActOnFinishFunctionDeclarationDeclarator(D);
7128 PrototypeScope.Exit();
7129 }
else if (Tok.is(tok::l_square)) {
7130 ParseBracketDeclarator(D);
7131 }
else if (Tok.isRegularKeywordAttribute()) {
7133 Diag(Tok, diag::err_keyword_not_allowed) << Tok.getIdentifierInfo();
7138 if (!
T.consumeOpen())
7149 Diag(Tok, diag::err_requires_clause_inside_parens);
7163void Parser::ParseDecompositionDeclarator(
Declarator &D) {
7164 assert(Tok.is(tok::l_square));
7166 TentativeParsingAction PA(*
this);
7171 DiagnoseAndSkipCXX11Attributes();
7175 if (!(Tok.isOneOf(tok::identifier, tok::ellipsis) &&
7177 tok::identifier, tok::l_square, tok::ellipsis)) &&
7178 !(Tok.is(tok::r_square) &&
7181 return ParseMisplacedBracketDeclarator(D);
7184 SourceLocation PrevEllipsisLoc;
7185 SmallVector<DecompositionDeclarator::Binding, 32>
Bindings;
7186 while (Tok.isNot(tok::r_square)) {
7188 if (Tok.is(tok::comma))
7191 if (Tok.is(tok::identifier)) {
7193 Diag(EndLoc, diag::err_expected)
7196 Diag(Tok, diag::err_expected_comma_or_rsquare);
7199 SkipUntil({tok::r_square, tok::comma, tok::identifier, tok::ellipsis},
7201 if (Tok.is(tok::comma))
7203 else if (Tok.is(tok::r_square))
7208 if (isCXX11AttributeSpecifier() !=
7210 DiagnoseAndSkipCXX11Attributes();
7212 SourceLocation EllipsisLoc;
7214 if (Tok.is(tok::ellipsis)) {
7216 if (PrevEllipsisLoc.
isValid()) {
7217 Diag(Tok, diag::err_binding_multiple_ellipses);
7218 Diag(PrevEllipsisLoc, diag::note_previous_ellipsis);
7221 EllipsisLoc = Tok.getLocation();
7222 PrevEllipsisLoc = EllipsisLoc;
7226 if (Tok.isNot(tok::identifier)) {
7227 Diag(Tok, diag::err_expected) << tok::identifier;
7231 IdentifierInfo *II = Tok.getIdentifierInfo();
7232 SourceLocation Loc = Tok.getLocation();
7235 if (Tok.is(tok::ellipsis) && !PrevEllipsisLoc.
isValid()) {
7236 DiagnoseMisplacedEllipsis(Tok.getLocation(), Loc, EllipsisLoc.
isValid(),
7238 EllipsisLoc = Tok.getLocation();
7242 ParsedAttributes Attrs(AttrFactory);
7243 if (isCXX11AttributeSpecifier() !=
7245 DiagCompat(Tok, diag_compat::attrs_on_binding);
7246 MaybeParseCXX11Attributes(Attrs);
7249 Bindings.push_back({II, Loc, std::move(Attrs), EllipsisLoc});
7252 if (Tok.isNot(tok::r_square))
7259 Diag(Tok.getLocation(), diag::ext_decomp_decl_empty);
7267 T.getCloseLocation());
7270void Parser::ParseParenDeclarator(
Declarator &D) {
7274 assert(!D.
isPastIdentifier() &&
"Should be called before passing identifier");
7286 ParsedAttributes attrs(AttrFactory);
7287 bool RequiresArg =
false;
7288 if (Tok.is(tok::kw___attribute)) {
7289 ParseGNUAttributes(attrs);
7297 ParseMicrosoftTypeAttributes(attrs);
7300 if (Tok.is(tok::kw___pascal))
7301 ParseBorlandTypeAttributes(attrs);
7313 }
else if (Tok.is(tok::r_paren) ||
7315 Tok.is(tok::ellipsis) &&
7317 isDeclarationSpecifier(
7319 isCXX11AttributeSpecifier() !=
7339 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
7344 std::move(attrs),
T.getCloseLocation());
7350 DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, D);
7368 ParseFunctionDeclarator(D, attrs,
T,
false, RequiresArg);
7369 PrototypeScope.Exit();
7372void Parser::InitCXXThisScopeForDeclaratorIfRelevant(
7374 std::optional<Sema::CXXThisScopeRAII> &ThisScope) {
7382 bool IsCXX11MemberFunction =
7389 Actions.CurContext->isRecord());
7390 if (!IsCXX11MemberFunction)
7410 ThisScope.emplace(Actions, dyn_cast<CXXRecordDecl>(Actions.CurContext), Q,
7411 IsCXX11MemberFunction);
7414void Parser::ParseFunctionDeclarator(
Declarator &D,
7419 assert(
getCurScope()->isFunctionPrototypeScope() &&
7420 "Should call from a Function scope");
7426 bool HasProto =
false;
7428 SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
7430 SourceLocation EllipsisLoc;
7432 DeclSpec DS(AttrFactory);
7433 bool RefQualifierIsLValueRef =
true;
7434 SourceLocation RefQualifierLoc;
7436 SourceRange ESpecRange;
7437 SmallVector<ParsedType, 2> DynamicExceptions;
7438 SmallVector<SourceRange, 2> DynamicExceptionRanges;
7441 ParsedAttributes FnAttrs(AttrFactory);
7443 SourceLocation TrailingReturnTypeLoc;
7448 SourceLocation StartLoc, LocalEndLoc, EndLoc;
7449 SourceLocation LParenLoc, RParenLoc;
7451 StartLoc = LParenLoc;
7453 if (isFunctionDeclaratorIdentifierList()) {
7455 Diag(Tok, diag::err_argument_required_after_attribute);
7457 ParseFunctionDeclaratorIdentifierList(D, ParamInfo);
7461 LocalEndLoc = RParenLoc;
7466 MaybeParseCXX11Attributes(FnAttrs);
7467 ProhibitAttributes(FnAttrs);
7469 if (Tok.isNot(tok::r_paren)) {
7476 LateParsedAttrList *FnLateAttrs =
nullptr;
7481 ParseParameterDeclarationClause(D, FirstArgAttrs, ParamInfo, EllipsisLoc,
7483 }
else if (RequiresArg)
7484 Diag(Tok, diag::err_argument_required_after_attribute);
7495 LocalEndLoc = RParenLoc;
7504 ParseTypeQualifierListOpt(
7505 DS, AR_NoAttributesParsed,
7508 Actions.CodeCompletion().CodeCompleteFunctionQualifiers(DS, D);
7515 if (ParseRefQualifier(RefQualifierIsLValueRef, RefQualifierLoc))
7516 EndLoc = RefQualifierLoc;
7518 std::optional<Sema::CXXThisScopeRAII> ThisScope;
7519 InitCXXThisScopeForDeclaratorIfRelevant(D, DS, ThisScope);
7536 if (Delayed && Actions.isLibstdcxxEagerExceptionSpecHack(D) &&
7553 ESpecType = tryParseExceptionSpecification(Delayed,
7556 DynamicExceptionRanges,
7558 ExceptionSpecTokens);
7560 EndLoc = ESpecRange.
getEnd();
7564 MaybeParseCXX11Attributes(FnAttrs);
7567 LocalEndLoc = EndLoc;
7569 Diag(Tok, diag::warn_cxx98_compat_trailing_return_type);
7572 LocalEndLoc = Tok.getLocation();
7576 TrailingReturnTypeLoc =
Range.getBegin();
7577 EndLoc =
Range.getEnd();
7580 MaybeParseCXX11Attributes(FnAttrs);
7588 SmallVector<NamedDecl *, 0> DeclsInPrototype;
7591 NamedDecl *ND = dyn_cast<NamedDecl>(D);
7594 DeclsInPrototype.push_back(ND);
7601 llvm::sort(DeclsInPrototype, [](Decl *D1, Decl *D2) {
7609 HasProto, IsAmbiguous, LParenLoc, ParamInfo.data(),
7610 ParamInfo.size(), EllipsisLoc, RParenLoc,
7611 RefQualifierIsLValueRef, RefQualifierLoc,
7613 ESpecType, ESpecRange, DynamicExceptions.data(),
7614 DynamicExceptionRanges.data(), DynamicExceptions.size(),
7615 NoexceptExpr.
isUsable() ? NoexceptExpr.
get() :
nullptr,
7616 ExceptionSpecTokens, DeclsInPrototype, StartLoc,
7617 LocalEndLoc, D, TrailingReturnType, TrailingReturnTypeLoc,
7619 std::move(FnAttrs), EndLoc);
7622bool Parser::ParseRefQualifier(
bool &RefQualifierIsLValueRef,
7624 if (Tok.isOneOf(tok::amp, tok::ampamp)) {
7626 RefQualifierIsLValueRef = Tok.is(tok::amp);
7633bool Parser::isFunctionDeclaratorIdentifierList() {
7635 && Tok.is(tok::identifier)
7636 && !TryAltiVecVectorToken()
7652 && (!Tok.is(tok::eof) &&
7656void Parser::ParseFunctionDeclaratorIdentifierList(
7660 assert(!
getLangOpts().requiresStrictPrototypes() &&
7661 "Cannot parse an identifier list in C23 or C++");
7668 Diag(Tok, diag::ext_ident_list_in_param);
7671 llvm::SmallPtrSet<const IdentifierInfo *, 16> ParamsSoFar;
7675 if (Tok.isNot(tok::identifier)) {
7676 Diag(Tok, diag::err_expected) << tok::identifier;
7683 IdentifierInfo *ParmII = Tok.getIdentifierInfo();
7686 if (Actions.getTypeName(*ParmII, Tok.getLocation(),
getCurScope()))
7687 Diag(Tok, diag::err_unexpected_typedef_ident) << ParmII;
7690 if (!ParamsSoFar.insert(ParmII).second) {
7691 Diag(Tok, diag::err_param_redefinition) << ParmII;
7694 ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII,
7705void Parser::ParseParameterDeclarationClause(
7715 if (
getCurScope()->getFunctionPrototypeDepth() - 1 >
7717 Diag(Tok.getLocation(), diag::err_function_scope_depth_exceeded)
7736 IsACXXFunctionDeclaration) {
7747 LateParsedAttrList LateParamAttrs(
7749 !OuterLateParamAttrs);
7759 DeclSpec DS(AttrFactory);
7761 ParsedAttributes ArgDeclAttrs(AttrFactory);
7762 ParsedAttributes ArgDeclSpecAttrs(AttrFactory);
7769 ArgDeclSpecAttrs.takeAllPrependingFrom(FirstArgAttrs);
7772 MaybeParseCXX11Attributes(ArgDeclAttrs);
7775 MaybeParseMicrosoftAttributes(ArgDeclSpecAttrs);
7778 SourceLocation DSStart = Tok.getLocation();
7782 SourceLocation ThisLoc;
7786 ParsedTemplateInfo TemplateInfo;
7787 ParseDeclarationSpecifiers(DS, TemplateInfo,
AS_none,
7788 DeclSpecContext::DSC_normal,
7789 nullptr, AllowImplicitTypename);
7802 ParseDeclarator(ParmDeclarator);
7805 ParmDeclarator.SetRangeBegin(ThisLoc);
7808 MaybeParseGNUAttributes(ParmDeclarator, &LateParamAttrs);
7812 if (Tok.is(tok::kw_requires)) {
7817 diag::err_requires_clause_on_declarator_not_declaring_a_function);
7823 const IdentifierInfo *ParmII = ParmDeclarator.getIdentifier();
7827 std::unique_ptr<CachedTokens> DefArgToks;
7831 if (DS.
isEmpty() && ParmDeclarator.getIdentifier() ==
nullptr &&
7832 ParmDeclarator.getNumTypeObjects() == 0) {
7834 Diag(DSStart, diag::err_missing_param);
7841 if (Tok.is(tok::ellipsis) &&
7843 (!ParmDeclarator.getEllipsisLoc().isValid() &&
7844 !Actions.isUnexpandedParameterPackPermitted())) &&
7845 Actions.containsUnexpandedParameterPacks(ParmDeclarator))
7846 DiagnoseMisplacedEllipsisInDeclarator(
ConsumeToken(), ParmDeclarator);
7865 if (!ParmDeclarator.isInvalidType() && !ParmDeclarator.hasName() &&
7866 Tok.isNot(tok::raw_identifier) && !Tok.isAnnotation() &&
7867 Tok.getIdentifierInfo() &&
7868 Tok.getIdentifierInfo()->isKeyword(
getLangOpts())) {
7869 Diag(Tok, diag::err_keyword_as_parameter) << PP.getSpelling(Tok);
7878 Diag(ParmDeclarator.getBeginLoc(),
7879 diag::err_function_parameter_limit_exceeded);
7887 Actions.ActOnParamDeclarator(
getCurScope(), ParmDeclarator, ThisLoc);
7889 DistributeCLateParsedAttrs(Param, &LateParamAttrs);
7894 if (Tok.is(tok::equal)) {
7895 SourceLocation EqualLoc = Tok.getLocation();
7905 ConsumeAndStoreInitializer(*DefArgToks,
7907 Actions.ActOnParamUnparsedDefaultArgument(Param, EqualLoc,
7918 DelayTemplateIdDestructionRAII DontDestructTemplateIds(
7923 EnterExpressionEvaluationContext Eval(
7930 Diag(Tok, diag::compat_cxx11_generalized_initializer_lists);
7931 DefArgResult = ParseBraceInitializer();
7933 if (Tok.is(tok::l_paren) &&
NextToken().
is(tok::l_brace)) {
7934 Diag(Tok, diag::err_stmt_expr_in_default_arg) << 0;
7935 Actions.ActOnParamDefaultArgumentError(Param, EqualLoc,
7945 Actions.ActOnParamDefaultArgumentError(Param, EqualLoc,
7950 Actions.ActOnParamDefaultArgument(Param, EqualLoc,
7951 DefArgResult.
get());
7956 ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII,
7957 ParmDeclarator.getIdentifierLoc(),
7958 Param, std::move(DefArgToks)));
7966 Diag(EllipsisLoc, diag::warn_deprecated_missing_comma_before_ellipsis)
7973 Diag(EllipsisLoc, diag::err_missing_comma_before_ellipsis)
7975 }
else if (ParmDeclarator.getEllipsisLoc().isValid() ||
7976 Actions.containsUnexpandedParameterPacks(ParmDeclarator)) {
7979 SourceLocation ParmEllipsis = ParmDeclarator.getEllipsisLoc();
7980 Diag(EllipsisLoc, diag::warn_misplaced_ellipsis_vararg)
7981 << ParmEllipsis.
isValid() << ParmEllipsis;
7984 diag::note_misplaced_ellipsis_vararg_existing_ellipsis);
7986 Diag(ParmDeclarator.getIdentifierLoc(),
7987 diag::note_misplaced_ellipsis_vararg_add_ellipsis)
7990 << !ParmDeclarator.hasName();
7992 Diag(EllipsisLoc, diag::note_misplaced_ellipsis_vararg_add_comma)
8006 if (OuterLateParamAttrs) {
8009 if (LA->
Decls.empty()) {
8010 LateParamAttrs[Kept++] = LA;
8013 OuterLateParamAttrs->push_back(LA);
8016 if (!ClassStack.empty() && !OuterLateParamAttrs->
parseSoon())
8017 getCurrentClass().LateParsedDeclarations.push_back(LA);
8019 LateParamAttrs.resize(Kept);
8025 if (!LateParamAttrs.empty())
8026 ParseLexedAttributeList(LateParamAttrs,
nullptr,
false,
8030void Parser::ParseBracketDeclarator(
Declarator &D) {
8031 if (CheckProhibitedCXX11Attribute())
8039 if (Tok.getKind() == tok::r_square) {
8041 ParsedAttributes attrs(AttrFactory);
8042 MaybeParseCXX11Attributes(attrs);
8046 T.getOpenLocation(),
8047 T.getCloseLocation()),
8048 std::move(attrs),
T.getCloseLocation());
8050 }
else if (Tok.getKind() == tok::numeric_constant &&
8057 ParsedAttributes attrs(AttrFactory);
8058 MaybeParseCXX11Attributes(attrs);
8062 T.getOpenLocation(),
8063 T.getCloseLocation()),
8064 std::move(attrs),
T.getCloseLocation());
8066 }
else if (Tok.getKind() == tok::code_completion) {
8068 Actions.CodeCompletion().CodeCompleteBracketDeclarator(
getCurScope());
8073 SourceLocation StaticLoc;
8078 DeclSpec DS(AttrFactory);
8079 ParseTypeQualifierListOpt(DS, AR_CXX11AttributesParsed);
8087 bool isStar =
false;
8098 Diag(StaticLoc, diag::err_unspecified_vla_size_with_static);
8099 StaticLoc = SourceLocation();
8102 }
else if (Tok.isNot(tok::r_square)) {
8119 Diag(StaticLoc, diag::err_unspecified_size_with_static);
8120 StaticLoc = SourceLocation();
8139 isStar, NumElements.
get(),
T.getOpenLocation(),
8140 T.getCloseLocation()),
8144void Parser::ParseMisplacedBracketDeclarator(
Declarator &D) {
8145 assert(Tok.is(tok::l_square) &&
"Missing opening bracket");
8148 SourceLocation StartBracketLoc = Tok.getLocation();
8152 while (Tok.is(tok::l_square)) {
8153 ParseBracketDeclarator(TempDeclarator);
8159 if (Tok.is(tok::semi))
8162 SourceLocation SuggestParenLoc = Tok.getLocation();
8165 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
8170 if (TempDeclarator.getNumTypeObjects() == 0)
8174 bool NeedParens =
false;
8193 SourceLocation EndLoc = PP.getLocForEndOfToken(D.
getEndLoc());
8199 for (
unsigned i = 0, e = TempDeclarator.getNumTypeObjects(); i < e; ++i) {
8200 const DeclaratorChunk &Chunk = TempDeclarator.getTypeObject(i);
8201 D.
AddTypeInfo(Chunk, TempDeclarator.getAttributePool(), SourceLocation());
8206 if (!D.
hasName() && !NeedParens)
8209 SourceLocation EndBracketLoc = TempDeclarator.getEndLoc();
8212 SourceRange BracketRange(StartBracketLoc, EndBracketLoc);
8213 SourceLocation EndLoc = PP.getLocForEndOfToken(D.
getEndLoc());
8216 Diag(EndLoc, diag::err_brackets_go_after_unqualified_id)
8221 EndLoc, CharSourceRange(BracketRange,
true))
8224 Diag(EndLoc, diag::err_brackets_go_after_unqualified_id)
8227 EndLoc, CharSourceRange(BracketRange,
true))
8232void Parser::ParseTypeofSpecifier(
DeclSpec &DS) {
8233 assert(Tok.isOneOf(tok::kw_typeof, tok::kw_typeof_unqual) &&
8234 "Not a typeof specifier");
8236 bool IsUnqual = Tok.is(tok::kw_typeof_unqual);
8237 const IdentifierInfo *II = Tok.getIdentifierInfo();
8239 Diag(Tok.getLocation(), diag::warn_c23_compat_keyword) << Tok.getName();
8243 bool HasParens = Tok.is(tok::l_paren);
8251 SourceRange CastRange;
8253 ParseExprAfterUnaryExprOrTypeTrait(OpTok, isCastExpr, CastTy, CastRange);
8269 const char *PrevSpec =
nullptr;
8276 Actions.getASTContext().getPrintingPolicy()))
8277 Diag(StartLoc, DiagID) << PrevSpec;
8288 Operand = Actions.HandleExprEvaluationContextForTypeof(
Operand.get());
8294 const char *PrevSpec =
nullptr;
8301 Actions.getASTContext().getPrintingPolicy()))
8302 Diag(StartLoc, DiagID) << PrevSpec;
8305void Parser::ParseAtomicSpecifier(
DeclSpec &DS) {
8306 assert(Tok.is(tok::kw__Atomic) &&
NextToken().
is(tok::l_paren) &&
8307 "Not an atomic specifier");
8311 if (
T.consumeOpen())
8315 if (
Result.isInvalid()) {
8323 if (
T.getCloseLocation().isInvalid())
8329 const char *PrevSpec =
nullptr;
8333 Actions.getASTContext().getPrintingPolicy()))
8334 Diag(StartLoc, DiagID) << PrevSpec;
8337bool Parser::TryAltiVecVectorTokenOutOfLine() {
8339 switch (
Next.getKind()) {
8340 default:
return false;
8343 case tok::kw_signed:
8344 case tok::kw_unsigned:
8349 case tok::kw_double:
8352 case tok::kw___bool:
8353 case tok::kw___pixel:
8354 Tok.setKind(tok::kw___vector);
8356 case tok::identifier:
8357 if (
Next.getIdentifierInfo() == Ident_pixel) {
8358 Tok.setKind(tok::kw___vector);
8361 if (
Next.getIdentifierInfo() == Ident_bool ||
8362 Next.getIdentifierInfo() == Ident_Bool) {
8363 Tok.setKind(tok::kw___vector);
8371 const char *&PrevSpec,
unsigned &DiagID,
8373 const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy();
8374 if (Tok.getIdentifierInfo() == Ident_vector) {
8376 switch (
Next.getKind()) {
8379 case tok::kw_signed:
8380 case tok::kw_unsigned:
8385 case tok::kw_double:
8388 case tok::kw___bool:
8389 case tok::kw___pixel:
8392 case tok::identifier:
8393 if (
Next.getIdentifierInfo() == Ident_pixel) {
8397 if (
Next.getIdentifierInfo() == Ident_bool ||
8398 Next.getIdentifierInfo() == Ident_Bool) {
8407 }
else if ((Tok.getIdentifierInfo() == Ident_pixel) &&
8411 }
else if ((Tok.getIdentifierInfo() == Ident_bool) &&
8419TypeResult Parser::ParseTypeFromString(StringRef TypeStr, StringRef Context,
8422 SmallVector<Token, 4> Tokens;
8425 auto &SourceMgr = PP.getSourceManager();
8426 FileID FID = SourceMgr.createFileID(
8427 llvm::MemoryBuffer::getMemBufferCopy(TypeStr, Context),
SrcMgr::C_User,
8431 Lexer L(FID, SourceMgr.getBufferOrFake(FID), PP);
8432 L.setParsingPreprocessorDirective(
true);
8438 Tokens.push_back(Tok);
8439 }
while (Tok.isNot(tok::eod));
8444 Token &EndToken = Tokens.back();
8448 Tokens.push_back(Tok);
8451 PP.EnterTokenStream(Tokens,
false,
8466 (Tok.isNot(tok::eof) || Tok.getEofData() != TypeStr.data())) {
8467 Diag(Tok.getLocation(), diag::err_type_unparsed);
8472 while (Tok.isNot(tok::eof))
8476 if (Tok.is(tok::eof) && Tok.getEofData() == TypeStr.data())
8481void Parser::DiagnoseBitIntUse(
const Token &
Tok) {
8485 assert(Tok.isOneOf(tok::kw__ExtInt, tok::kw__BitInt) &&
8486 "expected either an _ExtInt or _BitInt token!");
8488 SourceLocation Loc = Tok.getLocation();
8489 if (Tok.is(tok::kw__ExtInt)) {
8490 Diag(Loc, diag::warn_ext_int_deprecated)
8496 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.
void setDeclarationLateAttrs(LateParsedAttrList *L)
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)
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
void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc, const LateParsedTypeAttrInfoList &LateAttrs={})
AddTypeInfo - Add a chunk to this declarator.
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)
LateParsedAttrList * getDeclarationLateAttrs() const
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.
SmallVector< LateParsedTypeAttrInfo *, 0 > LateParsedTypeAttrInfoList
The late-parsed type attributes of a declaration specifier, declarator or declarator chunk,...
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