27 #include "llvm/ADT/Optional.h" 28 #include "llvm/ADT/SmallSet.h" 29 #include "llvm/ADT/SmallString.h" 30 #include "llvm/ADT/StringSwitch.h" 32 using namespace clang;
48 DeclSpecContext DSC = getDeclSpecContextFromDeclaratorContext(Context);
49 if (DSC == DeclSpecContext::DSC_normal)
50 DSC = DeclSpecContext::DSC_type_specifier;
56 ParseSpecifierQualifierList(DS, AS, DSC);
62 ParseDeclarator(DeclaratorInfo);
74 if (Name.size() >= 4 && Name.startswith(
"__") && Name.endswith(
"__"))
75 return Name.drop_front(2).drop_back(2);
82 #define CLANG_ATTR_LATE_PARSED_LIST 84 #include "clang/Parse/AttrParserStringSwitches.inc" 86 #undef CLANG_ATTR_LATE_PARSED_LIST 132 LateParsedAttrList *LateAttrs,
134 assert(Tok.
is(tok::kw___attribute) &&
"Not a GNU attribute list!");
136 while (Tok.
is(tok::kw___attribute)) {
138 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
143 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
"(")) {
162 if (Tok.
isNot(tok::l_paren)) {
163 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
170 ParseGNUAttributeArgs(AttrName, AttrNameLoc, attrs, endLoc,
nullptr,
176 LateParsedAttribute *LA =
177 new LateParsedAttribute(
this, *AttrName, AttrNameLoc);
178 LateAttrs->push_back(LA);
182 if (!ClassStack.empty() && !LateAttrs->parseSoon())
183 getCurrentClass().LateParsedDeclarations.push_back(LA);
187 LA->Toks.push_back(Tok);
190 ConsumeAndStoreUntil(tok::r_paren, LA->Toks,
true);
195 LA->Toks.push_back(Eof);
198 if (ExpectAndConsume(tok::r_paren))
201 if (ExpectAndConsume(tok::r_paren))
210 #define CLANG_ATTR_IDENTIFIER_ARG_LIST 212 #include "clang/Parse/AttrParserStringSwitches.inc" 214 #undef CLANG_ATTR_IDENTIFIER_ARG_LIST 219 #define CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST 221 #include "clang/Parse/AttrParserStringSwitches.inc" 223 #undef CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST 228 #define CLANG_ATTR_TYPE_ARG_LIST 230 #include "clang/Parse/AttrParserStringSwitches.inc" 232 #undef CLANG_ATTR_TYPE_ARG_LIST 238 #define CLANG_ATTR_ARG_CONTEXT_LIST 240 #include "clang/Parse/AttrParserStringSwitches.inc" 242 #undef CLANG_ATTR_ARG_CONTEXT_LIST 246 assert(Tok.
is(tok::identifier) &&
"expected an identifier");
265 if (Tok.
isNot(tok::r_paren))
277 ScopeName, ScopeLoc, T.
get(), Syntax);
280 ScopeName, ScopeLoc,
nullptr, 0, Syntax);
283 unsigned Parser::ParseAttributeArgsCommon(
291 if (Tok.
is(tok::identifier)) {
303 IsIdentifierArg = Next.
isOneOf(tok::r_paren, tok::comma);
307 ArgExprs.push_back(ParseIdentifierLoc());
310 if (!ArgExprs.empty() ? Tok.
is(tok::comma) : Tok.
isNot(tok::r_paren)) {
312 if (!ArgExprs.empty())
318 if (Tok.
is(tok::identifier) &&
320 ArgExprs.push_back(ParseIdentifierLoc());
334 ArgExprs.push_back(ArgExpr.
get());
341 if (!ExpectAndConsume(tok::r_paren)) {
344 ArgExprs.data(), ArgExprs.size(), Syntax);
350 return static_cast<unsigned>(ArgExprs.size());
364 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
369 if (AttrKind == ParsedAttr::AT_Availability) {
370 ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
373 }
else if (AttrKind == ParsedAttr::AT_ExternalSourceSymbol) {
374 ParseExternalSourceSymbolAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
375 ScopeName, ScopeLoc, Syntax);
377 }
else if (AttrKind == ParsedAttr::AT_ObjCBridgeRelated) {
378 ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
379 ScopeName, ScopeLoc, Syntax);
381 }
else if (AttrKind == ParsedAttr::AT_TypeTagForDatatype) {
382 ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
383 ScopeName, ScopeLoc, Syntax);
386 ParseAttributeWithTypeArg(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
400 for (
unsigned i = 0; i != FTI.
NumParams; ++i) {
406 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
410 unsigned Parser::ParseClangAttributeArgs(
414 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
421 return ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
422 ScopeName, ScopeLoc, Syntax);
423 case ParsedAttr::AT_ExternalSourceSymbol:
424 ParseExternalSourceSymbolAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
425 ScopeName, ScopeLoc, Syntax);
427 case ParsedAttr::AT_Availability:
428 ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
431 case ParsedAttr::AT_ObjCBridgeRelated:
432 ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
433 ScopeName, ScopeLoc, Syntax);
435 case ParsedAttr::AT_TypeTagForDatatype:
436 ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
437 ScopeName, ScopeLoc, Syntax);
440 return !Attrs.
empty() ? Attrs.
begin()->getNumArgs() : 0;
458 if (AttrName->
getName() ==
"property") {
473 bool HasInvalidAccessor =
false;
478 if (!Tok.
is(tok::identifier)) {
480 if (Tok.
is(tok::r_paren) && !HasInvalidAccessor &&
481 AccessorNames[AK_Put] ==
nullptr &&
482 AccessorNames[AK_Get] ==
nullptr) {
483 Diag(AttrNameLoc, diag::err_ms_property_no_getter_or_putter);
494 if (KindStr ==
"get") {
496 }
else if (KindStr ==
"put") {
500 }
else if (KindStr ==
"set") {
501 Diag(KindLoc, diag::err_ms_property_has_set_accessor)
508 Diag(KindLoc, diag::err_ms_property_missing_accessor_kind);
510 HasInvalidAccessor =
true;
511 goto next_property_accessor;
515 Diag(KindLoc, diag::err_ms_property_unknown_accessor);
516 HasInvalidAccessor =
true;
535 if (!Tok.
is(tok::identifier)) {
540 if (Kind == AK_Invalid) {
542 }
else if (AccessorNames[Kind] !=
nullptr) {
544 Diag(KindLoc, diag::err_ms_property_duplicate_accessor) << KindStr;
550 next_property_accessor:
556 if (Tok.
is(tok::r_paren))
559 Diag(Tok.
getLocation(), diag::err_ms_property_expected_comma_or_rparen);
564 if (!HasInvalidAccessor)
566 AccessorNames[AK_Get], AccessorNames[AK_Put],
569 return !HasInvalidAccessor;
573 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs,
nullptr,
nullptr,
578 if (!Attrs.
empty() && Attrs.
begin()->getMaxArgs() && !NumArgs) {
579 Diag(OpenParenLoc, diag::err_attribute_requires_arguments) << AttrName;
593 assert(
getLangOpts().DeclSpecKeyword &&
"__declspec keyword is not enabled");
594 assert(Tok.
is(tok::kw___declspec) &&
"Not a declspec!");
596 while (Tok.
is(tok::kw___declspec)) {
605 while (Tok.
isNot(tok::r_paren)) {
612 bool IsString = Tok.
getKind() == tok::string_literal;
613 if (!IsString && Tok.
getKind() != tok::identifier &&
614 Tok.
getKind() != tok::kw_restrict) {
615 Diag(Tok, diag::err_ms_declspec_type);
624 bool Invalid =
false;
625 StringRef Str = PP.
getSpelling(Tok, StrBuffer, &Invalid);
631 AttrNameLoc = ConsumeStringToken();
637 bool AttrHandled =
false;
640 if (Tok.
is(tok::l_paren))
641 AttrHandled = ParseMicrosoftDeclSpecArgs(AttrName, AttrNameLoc, Attrs);
642 else if (AttrName->
getName() ==
"property")
648 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
661 case tok::kw___fastcall:
662 case tok::kw___stdcall:
663 case tok::kw___thiscall:
664 case tok::kw___regcall:
665 case tok::kw___cdecl:
666 case tok::kw___vectorcall:
667 case tok::kw___ptr64:
669 case tok::kw___ptr32:
671 case tok::kw___uptr: {
674 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
684 void Parser::DiagnoseAndSkipExtendedMicrosoftTypeAttributes() {
690 Diag(StartLoc, diag::warn_microsoft_qualifiers_ignored) << Range;
700 case tok::kw_volatile:
701 case tok::kw___fastcall:
702 case tok::kw___stdcall:
703 case tok::kw___thiscall:
704 case tok::kw___cdecl:
705 case tok::kw___vectorcall:
706 case tok::kw___ptr32:
707 case tok::kw___ptr64:
709 case tok::kw___unaligned:
722 while (Tok.
is(tok::kw___pascal)) {
725 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
732 while (Tok.
is(tok::kw___kernel)) {
735 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
743 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
751 case tok::kw__Nonnull:
752 case tok::kw__Nullable:
753 case tok::kw__Null_unspecified: {
757 Diag(AttrNameLoc, diag::ext_nullability)
759 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
770 return (Separator ==
'.' || Separator ==
'_');
781 VersionTuple Parser::ParseVersionTuple(
SourceRange &Range) {
784 if (!Tok.
is(tok::numeric_constant)) {
785 Diag(Tok, diag::err_expected_version);
788 return VersionTuple();
797 const char *ThisTokBegin = &Buffer[0];
800 bool Invalid =
false;
801 unsigned ActualLength = PP.
getSpelling(Tok, ThisTokBegin, &Invalid);
803 return VersionTuple();
806 unsigned AfterMajor = 0;
808 while (AfterMajor < ActualLength &&
isDigit(ThisTokBegin[AfterMajor])) {
809 Major = Major * 10 + ThisTokBegin[AfterMajor] -
'0';
813 if (AfterMajor == 0) {
814 Diag(Tok, diag::err_expected_version);
817 return VersionTuple();
820 if (AfterMajor == ActualLength) {
825 Diag(Tok, diag::err_zero_version);
826 return VersionTuple();
829 return VersionTuple(Major);
832 const char AfterMajorSeparator = ThisTokBegin[AfterMajor];
834 || (AfterMajor + 1 == ActualLength)) {
835 Diag(Tok, diag::err_expected_version);
838 return VersionTuple();
842 unsigned AfterMinor = AfterMajor + 1;
844 while (AfterMinor < ActualLength &&
isDigit(ThisTokBegin[AfterMinor])) {
845 Minor = Minor * 10 + ThisTokBegin[AfterMinor] -
'0';
849 if (AfterMinor == ActualLength) {
853 if (Major == 0 && Minor == 0) {
854 Diag(Tok, diag::err_zero_version);
855 return VersionTuple();
858 return VersionTuple(Major, Minor);
861 const char AfterMinorSeparator = ThisTokBegin[AfterMinor];
864 Diag(Tok, diag::err_expected_version);
867 return VersionTuple();
871 if (AfterMajorSeparator != AfterMinorSeparator)
872 Diag(Tok, diag::warn_expected_consistent_version_separator);
875 unsigned AfterSubminor = AfterMinor + 1;
876 unsigned Subminor = 0;
877 while (AfterSubminor < ActualLength &&
isDigit(ThisTokBegin[AfterSubminor])) {
878 Subminor = Subminor * 10 + ThisTokBegin[AfterSubminor] -
'0';
882 if (AfterSubminor != ActualLength) {
883 Diag(Tok, diag::err_expected_version);
886 return VersionTuple();
889 return VersionTuple(Major, Minor, Subminor);
917 void Parser::ParseAvailabilityAttribute(
IdentifierInfo &Availability,
924 enum { Introduced, Deprecated, Obsoleted, Unknown };
931 Diag(Tok, diag::err_expected) << tok::l_paren;
936 if (Tok.
isNot(tok::identifier)) {
937 Diag(Tok, diag::err_availability_expected_platform);
944 if (Ident->getName() ==
"macosx")
948 else if (Ident->getName() ==
"macosx_app_extension")
952 AvailabilityAttr::canonicalizePlatformName(Ident->getName()));
956 if (ExpectAndConsume(tok::comma)) {
963 if (!Ident_introduced) {
977 if (Tok.
isNot(tok::identifier)) {
978 Diag(Tok, diag::err_availability_expected_change);
985 if (Keyword == Ident_strict) {
987 Diag(KeywordLoc, diag::err_availability_redundant)
990 StrictLoc = KeywordLoc;
994 if (Keyword == Ident_unavailable) {
995 if (UnavailableLoc.
isValid()) {
996 Diag(KeywordLoc, diag::err_availability_redundant)
999 UnavailableLoc = KeywordLoc;
1003 if (Keyword == Ident_deprecated && Platform->
Ident &&
1006 if (Changes[Deprecated].KeywordLoc.
isValid()) {
1007 Diag(KeywordLoc, diag::err_availability_redundant)
1014 Changes[Deprecated].
Version = VersionTuple(1);
1018 if (Tok.
isNot(tok::equal)) {
1019 Diag(Tok, diag::err_expected_after) << Keyword << tok::equal;
1024 if (Keyword == Ident_message || Keyword == Ident_replacement) {
1025 if (Tok.
isNot(tok::string_literal)) {
1026 Diag(Tok, diag::err_expected_string_literal)
1031 if (Keyword == Ident_message)
1032 MessageExpr = ParseStringLiteralExpression();
1034 ReplacementExpr = ParseStringLiteralExpression();
1037 cast_or_null<StringLiteral>(MessageExpr.
get())) {
1038 if (MessageStringLiteral->getCharByteWidth() != 1) {
1039 Diag(MessageStringLiteral->getSourceRange().getBegin(),
1040 diag::err_expected_string_literal)
1046 if (Keyword == Ident_message)
1054 if ((Keyword == Ident_introduced || Keyword == Ident_deprecated) &&
1055 Tok.
is(tok::identifier)) {
1059 if (Keyword == Ident_introduced)
1060 UnavailableLoc = KeywordLoc;
1066 VersionTuple Version = ParseVersionTuple(VersionRange);
1068 if (Version.empty()) {
1074 if (Keyword == Ident_introduced)
1076 else if (Keyword == Ident_deprecated)
1078 else if (Keyword == Ident_obsoleted)
1083 if (Index < Unknown) {
1084 if (!Changes[Index].KeywordLoc.
isInvalid()) {
1085 Diag(KeywordLoc, diag::err_availability_redundant)
1088 Changes[Index].VersionRange.
getEnd());
1092 Changes[Index].
Version = Version;
1095 Diag(KeywordLoc, diag::err_availability_unknown_change)
1096 << Keyword << VersionRange;
1110 if (UnavailableLoc.
isValid()) {
1111 bool Complained =
false;
1112 for (
unsigned Index = Introduced; Index != Unknown; ++Index) {
1113 if (Changes[Index].KeywordLoc.
isValid()) {
1115 Diag(UnavailableLoc, diag::warn_availability_and_unavailable)
1117 Changes[Index].VersionRange.getEnd());
1128 attrs.
addNew(&Availability,
1130 ScopeName, ScopeLoc,
1132 Changes[Introduced],
1133 Changes[Deprecated],
1135 UnavailableLoc, MessageExpr.
get(),
1136 Syntax, StrictLoc, ReplacementExpr.
get());
1152 void Parser::ParseExternalSourceSymbolAttribute(
1162 if (!Ident_language) {
1169 bool HasLanguage =
false;
1171 bool HasDefinedIn =
false;
1176 if (Tok.
isNot(tok::identifier)) {
1177 Diag(Tok, diag::err_external_source_symbol_expected_keyword);
1184 if (Keyword == Ident_generated_declaration) {
1185 if (GeneratedDeclaration) {
1186 Diag(Tok, diag::err_external_source_symbol_duplicate_clause) << Keyword;
1190 GeneratedDeclaration = ParseIdentifierLoc();
1194 if (Keyword != Ident_language && Keyword != Ident_defined_in) {
1195 Diag(Tok, diag::err_external_source_symbol_expected_keyword);
1201 if (ExpectAndConsume(tok::equal, diag::err_expected_after,
1207 bool HadLanguage = HasLanguage, HadDefinedIn = HasDefinedIn;
1208 if (Keyword == Ident_language)
1211 HasDefinedIn =
true;
1213 if (Tok.
isNot(tok::string_literal)) {
1214 Diag(Tok, diag::err_expected_string_literal)
1216 << (Keyword != Ident_language);
1220 if (Keyword == Ident_language) {
1222 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
1224 ParseStringLiteralExpression();
1227 Language = ParseStringLiteralExpression();
1229 assert(Keyword == Ident_defined_in &&
"Invalid clause keyword!");
1231 Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause)
1233 ParseStringLiteralExpression();
1236 DefinedInExpr = ParseStringLiteralExpression();
1247 GeneratedDeclaration};
1249 ScopeName, ScopeLoc, Args, llvm::array_lengthof(Args), Syntax);
1263 void Parser::ParseObjCBridgeRelatedAttribute(
IdentifierInfo &ObjCBridgeRelated,
1273 Diag(Tok, diag::err_expected) << tok::l_paren;
1278 if (Tok.
isNot(tok::identifier)) {
1279 Diag(Tok, diag::err_objcbridge_related_expected_related_class);
1284 if (ExpectAndConsume(tok::comma)) {
1293 if (Tok.
is(tok::identifier)) {
1294 ClassMethod = ParseIdentifierLoc();
1296 Diag(Tok, diag::err_objcbridge_related_selector_name);
1302 if (Tok.
is(tok::colon))
1303 Diag(Tok, diag::err_objcbridge_related_selector_name);
1305 Diag(Tok, diag::err_expected) << tok::comma;
1313 if (Tok.
is(tok::identifier))
1314 InstanceMethod = ParseIdentifierLoc();
1315 else if (Tok.
isNot(tok::r_paren)) {
1316 Diag(Tok, diag::err_expected) << tok::r_paren;
1329 attrs.
addNew(&ObjCBridgeRelated,
1331 ScopeName, ScopeLoc,
1341 void Parser::LateParsedDeclaration::ParseLexedAttributes() {}
1343 void Parser::LateParsedClass::ParseLexedAttributes() {
1344 Self->ParseLexedAttributes(*Class);
1347 void Parser::LateParsedAttribute::ParseLexedAttributes() {
1348 Self->ParseLexedAttribute(*
this,
true,
false);
1353 void Parser::ParseLexedAttributes(ParsingClass &Class) {
1356 bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope;
1359 if (HasTemplateScope)
1363 bool AlreadyHasClassScope = Class.TopLevelClass;
1365 ParseScope ClassScope(
this, ScopeFlags, !AlreadyHasClassScope);
1366 ParseScopeFlags ClassScopeFlags(
this, ScopeFlags, AlreadyHasClassScope);
1369 if (!AlreadyHasClassScope)
1371 Class.TagOrTemplate);
1372 if (!Class.LateParsedDeclarations.empty()) {
1373 for (
unsigned i = 0, ni = Class.LateParsedDeclarations.size(); i < ni; ++i){
1374 Class.LateParsedDeclarations[i]->ParseLexedAttributes();
1378 if (!AlreadyHasClassScope)
1380 Class.TagOrTemplate);
1384 void Parser::ParseLexedAttributeList(LateParsedAttrList &LAs,
Decl *D,
1386 assert(LAs.parseSoon() &&
1387 "Attribute list should be marked for immediate parsing.");
1388 for (
unsigned i = 0, ni = LAs.size(); i < ni; ++i) {
1391 ParseLexedAttribute(*LAs[i],
EnterScope, OnDefinition);
1402 void Parser::ParseLexedAttribute(LateParsedAttribute &LA,
1411 LA.Toks.push_back(AttrEnd);
1415 LA.Toks.push_back(Tok);
1416 PP.EnterTokenStream(LA.Toks,
true);
1423 if (LA.Decls.size() > 0) {
1424 Decl *D = LA.Decls[0];
1432 if (LA.Decls.size() == 1) {
1436 if (HasTemplateScope)
1447 ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, &endLoc,
1455 if (HasTemplateScope) {
1461 ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, &endLoc,
1466 Diag(Tok, diag::warn_attribute_no_decl) << LA.AttrName.getName();
1469 if (OnDefinition && !Attrs.
empty() && !Attrs.
begin()->isCXX11Attribute() &&
1470 Attrs.
begin()->isKnownToGCC())
1471 Diag(Tok, diag::warn_attribute_on_function_definition)
1474 for (
unsigned i = 0, ni = LA.Decls.size(); i < ni; ++i)
1486 void Parser::ParseTypeTagForDatatypeAttribute(
IdentifierInfo &AttrName,
1493 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
1498 if (Tok.
isNot(tok::identifier)) {
1499 Diag(Tok, diag::err_expected) << tok::identifier;
1505 if (ExpectAndConsume(tok::comma)) {
1517 bool LayoutCompatible =
false;
1518 bool MustBeNull =
false;
1520 if (Tok.
isNot(tok::identifier)) {
1521 Diag(Tok, diag::err_expected) << tok::identifier;
1526 if (Flag->
isStr(
"layout_compatible"))
1527 LayoutCompatible =
true;
1528 else if (Flag->
isStr(
"must_be_null"))
1531 Diag(Tok, diag::err_type_safety_unknown_flag) << Flag;
1538 if (!T.consumeClose()) {
1540 ArgumentKind, MatchingCType.
get(),
1541 LayoutCompatible, MustBeNull, Syntax);
1545 *EndLoc = T.getCloseLocation();
1556 bool Parser::DiagnoseProhibitedCXX11Attribute() {
1557 assert(Tok.
is(tok::l_square) &&
NextToken().
is(tok::l_square));
1559 switch (isCXX11AttributeSpecifier(
true)) {
1560 case CAK_NotAttributeSpecifier:
1564 case CAK_InvalidAttributeSpecifier:
1568 case CAK_AttributeSpecifier:
1573 assert(Tok.
is(tok::r_square) &&
"isCXX11AttributeSpecifier lied");
1575 Diag(BeginLoc, diag::err_attributes_not_allowed)
1579 llvm_unreachable(
"All cases handled above.");
1586 void Parser::DiagnoseMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs,
1588 assert((Tok.
is(tok::l_square) &&
NextToken().
is(tok::l_square)) ||
1589 Tok.
is(tok::kw_alignas));
1593 ParseCXX11Attributes(Attrs);
1596 Diag(Loc, diag::err_attributes_not_allowed)
1601 void Parser::DiagnoseProhibitedAttributes(
1603 if (CorrectLocation.
isValid()) {
1605 Diag(CorrectLocation, diag::err_attributes_misplaced)
1609 Diag(Range.
getBegin(), diag::err_attributes_not_allowed) << Range;
1612 void Parser::ProhibitCXX11Attributes(ParsedAttributesWithRange &Attrs,
1615 if (!AL.isCXX11Attribute() && !AL.isC2xAttribute())
1618 Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored) << AL.getName();
1620 Diag(AL.getLoc(), DiagID) << AL.getName();
1633 void Parser::stripTypeAttributesOffDeclSpec(ParsedAttributesWithRange &Attrs,
1642 if ((AL.getKind() == ParsedAttr::AT_Aligned &&
1643 AL.isDeclspecAttribute()) ||
1644 AL.isMicrosoftAttribute())
1645 ToBeMoved.push_back(&AL);
1672 ParsedAttributesWithRange &attrs) {
1678 Decl *SingleDecl =
nullptr;
1680 case tok::kw_template:
1681 case tok::kw_export:
1682 ProhibitAttributes(attrs);
1683 SingleDecl = ParseDeclarationStartingWithTemplate(Context, DeclEnd, attrs);
1685 case tok::kw_inline:
1688 ProhibitAttributes(attrs);
1690 return ParseNamespace(Context, DeclEnd, InlineLoc);
1692 return ParseSimpleDeclaration(Context, DeclEnd, attrs,
1694 case tok::kw_namespace:
1695 ProhibitAttributes(attrs);
1696 return ParseNamespace(Context, DeclEnd);
1698 return ParseUsingDirectiveOrDeclaration(Context, ParsedTemplateInfo(),
1700 case tok::kw_static_assert:
1701 case tok::kw__Static_assert:
1702 ProhibitAttributes(attrs);
1703 SingleDecl = ParseStaticAssertDeclaration(DeclEnd);
1706 return ParseSimpleDeclaration(Context, DeclEnd, attrs,
true);
1733 ParsedAttributesWithRange &Attrs,
1734 bool RequireSemi, ForRangeInit *FRI) {
1738 DeclSpecContext DSContext = getDeclSpecContextFromDeclaratorContext(Context);
1739 ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(),
AS_none, DSContext);
1744 DiagnoseMissingSemiAfterTagDefinition(DS,
AS_none, DSContext))
1749 if (Tok.
is(tok::semi)) {
1750 ProhibitAttributes(Attrs);
1758 Decl* decls[] = {AnonRecord, TheDecl};
1765 return ParseDeclGroup(DS, Context, &DeclEnd, FRI);
1772 case tok::annot_cxxscope:
1773 case tok::annot_template_id:
1775 case tok::code_completion:
1776 case tok::coloncolon:
1778 case tok::kw___attribute:
1779 case tok::kw_operator:
1796 case tok::identifier:
1798 case tok::code_completion:
1799 case tok::coloncolon:
1802 case tok::equalequal:
1803 case tok::kw_alignas:
1805 case tok::kw___attribute:
1824 case tok::identifier:
1847 if (Tok.
isOneOf(tok::comma, tok::l_brace, tok::kw_try)) {
1871 case tok::kw_inline:
1876 (!ParsingInObjCContainer || CurParsedObjCImpl))
1880 case tok::kw_namespace:
1885 (!ParsingInObjCContainer || CurParsedObjCImpl))
1892 ParsingInObjCContainer)
1904 case tok::annot_module_begin:
1905 case tok::annot_module_end:
1906 case tok::annot_module_include:
1923 ForRangeInit *FRI) {
1937 LateParsedAttrList LateParsedAttrs(
true);
1939 MaybeParseGNUAttributes(D, &LateParsedAttrs);
1944 if (Tok.
is(tok::kw__Noreturn)) {
1946 const char *PrevSpec;
1952 MaybeParseGNUAttributes(D, &LateParsedAttrs);
1953 Fixit &= Tok.
isOneOf(tok::semi, tok::l_brace, tok::kw_try);
1955 Diag(Loc, diag::err_c11_noreturn_misplaced)
1967 !isDeclarationAfterDeclarator()) {
1973 if (isStartOfFunctionDefinition(D)) {
1975 Diag(Tok, diag::err_function_declared_typedef);
1982 ParseFunctionDefinition(D, ParsedTemplateInfo(), &LateParsedAttrs);
1986 if (isDeclarationSpecifier()) {
1994 Diag(Tok, diag::err_expected_fn_body);
1999 if (Tok.
is(tok::l_brace)) {
2000 Diag(Tok, diag::err_function_definition_not_allowed);
2007 if (ParseAsmAttributesAfterDeclarator(D))
2016 if (FRI && (Tok.
is(tok::colon) || isTokIdentifier_in())) {
2017 bool IsForRangeLoop =
false;
2019 IsForRangeLoop =
true;
2020 if (Tok.
is(tok::l_brace))
2021 FRI->RangeExpr = ParseBraceInitializer();
2027 if (IsForRangeLoop) {
2031 if (
auto *VD = dyn_cast_or_null<VarDecl>(ThisDecl))
2032 VD->setObjCForDecl(
true);
2040 Decl *FirstDecl = ParseDeclarationAfterDeclaratorAndAttributes(
2041 D, ParsedTemplateInfo(), FRI);
2042 if (LateParsedAttrs.size() > 0)
2043 ParseLexedAttributeList(LateParsedAttrs, FirstDecl,
true,
false);
2046 DeclsInGroup.push_back(FirstDecl);
2054 if (Tok.
isAtStartOfLine() && ExpectSemi && !MightBeDeclarator(Context)) {
2058 Diag(CommaLoc, diag::err_expected_semi_declaration)
2075 MaybeParseGNUAttributes(D);
2079 DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
2083 Decl *ThisDecl = ParseDeclarationAfterDeclarator(D);
2086 DeclsInGroup.push_back(ThisDecl);
2095 ? diag::err_invalid_token_after_toplevel_declarator
2096 : diag::err_expected_semi_declaration)) {
2100 if (!isDeclarationSpecifier()) {
2111 bool Parser::ParseAsmAttributesAfterDeclarator(
Declarator &D) {
2113 if (Tok.
is(tok::kw_asm)) {
2125 MaybeParseGNUAttributes(D);
2151 Decl *Parser::ParseDeclarationAfterDeclarator(
2152 Declarator &D,
const ParsedTemplateInfo &TemplateInfo) {
2153 if (ParseAsmAttributesAfterDeclarator(D))
2156 return ParseDeclarationAfterDeclaratorAndAttributes(D, TemplateInfo);
2159 Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
2160 Declarator &D,
const ParsedTemplateInfo &TemplateInfo, ForRangeInit *FRI) {
2162 struct InitializerScopeRAII {
2168 :
P(P), D(D), ThisDecl(ThisDecl) {
2178 ~InitializerScopeRAII() { pop(); }
2193 Decl *ThisDecl =
nullptr;
2194 switch (TemplateInfo.Kind) {
2195 case ParsedTemplateInfo::NonTemplate:
2196 ThisDecl = Actions.ActOnDeclarator(
getCurScope(), D);
2199 case ParsedTemplateInfo::Template:
2200 case ParsedTemplateInfo::ExplicitSpecialization: {
2201 ThisDecl = Actions.ActOnTemplateDeclarator(
getCurScope(),
2202 *TemplateInfo.TemplateParams,
2204 if (
VarTemplateDecl *VT = dyn_cast_or_null<VarTemplateDecl>(ThisDecl))
2207 ThisDecl = VT->getTemplatedDecl();
2210 case ParsedTemplateInfo::ExplicitInstantiation: {
2211 if (Tok.
is(tok::semi)) {
2212 DeclResult ThisRes = Actions.ActOnExplicitInstantiation(
2213 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc, D);
2218 ThisDecl = ThisRes.
get();
2226 Diag(Tok, diag::err_template_defn_explicit_instantiation)
2228 ThisDecl = Actions.ActOnDeclarator(
getCurScope(), D);
2231 PP.getLocForEndOfToken(TemplateInfo.TemplateLoc);
2233 diag::err_explicit_instantiation_with_definition)
2239 FakedParamLists.push_back(Actions.ActOnTemplateParameterList(
2241 LAngleLoc,
nullptr));
2244 Actions.ActOnTemplateDeclarator(
getCurScope(), FakedParamLists, D);
2253 if (isTokenEqualOrEqualTypo()) {
2256 if (Tok.
is(tok::kw_delete)) {
2262 }
else if (Tok.
is(tok::kw_default)) {
2269 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2271 if (Tok.
is(tok::code_completion)) {
2272 Actions.CodeCompleteInitializer(
getCurScope(), ThisDecl);
2273 Actions.FinalizeDeclaration(ThisDecl);
2283 Diag(EqualLoc, diag::err_single_decl_assign_in_for_range)
2287 FRI->ColonLoc = EqualLoc;
2289 FRI->RangeExpr = Init;
2296 StopTokens.push_back(tok::comma);
2299 StopTokens.push_back(tok::r_paren);
2301 Actions.ActOnInitializerError(ThisDecl);
2303 Actions.AddInitializerToDecl(ThisDecl, Init.
get(),
2306 }
else if (Tok.
is(tok::l_paren)) {
2314 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2316 llvm::function_ref<void()> ExprListCompleter;
2317 auto ThisVarDecl = dyn_cast_or_null<VarDecl>(ThisDecl);
2318 auto ConstructorCompleter = [&, ThisVarDecl] {
2319 QualType PreferredType = Actions.ProduceConstructorSignatureHelp(
2320 getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(),
2322 CalledSignatureHelp =
true;
2323 Actions.CodeCompleteExpression(
getCurScope(), PreferredType);
2331 ExprListCompleter = ConstructorCompleter;
2334 if (ParseExpressionList(Exprs, CommaLocs, ExprListCompleter)) {
2335 if (ThisVarDecl && PP.isCodeCompletionReached() && !CalledSignatureHelp) {
2336 Actions.ProduceConstructorSignatureHelp(
2337 getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(),
2339 CalledSignatureHelp =
true;
2341 Actions.ActOnInitializerError(ThisDecl);
2347 assert(!Exprs.empty() && Exprs.size()-1 == CommaLocs.size() &&
2348 "Unexpected number of commas!");
2355 Actions.AddInitializerToDecl(ThisDecl, Initializer.
get(),
2358 }
else if (
getLangOpts().CPlusPlus11 && Tok.
is(tok::l_brace) &&
2361 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
2363 InitializerScopeRAII InitScope(*
this, D, ThisDecl);
2370 Actions.ActOnInitializerError(ThisDecl);
2372 Actions.AddInitializerToDecl(ThisDecl, Init.
get(),
true);
2375 Actions.ActOnUninitializedDecl(ThisDecl);
2378 Actions.FinalizeDeclaration(ThisDecl);
2390 DeclSpecContext DSC) {
2394 ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS, DSC);
2399 Diag(Tok, diag::err_expected_type);
2402 Diag(Tok, diag::err_typename_requires_specqual);
2413 diag::err_typename_invalid_storageclass);
2454 return T.
isOneOf(tok::l_square, tok::l_paren, tok::r_paren, tok::semi,
2455 tok::comma, tok::equal, tok::kw_asm, tok::l_brace,
2469 const ParsedTemplateInfo &TemplateInfo,
2471 ParsedAttributesWithRange &Attrs) {
2472 assert(Tok.
is(tok::identifier) &&
"should have identifier");
2494 if (!isTypeSpecifier(DSC) && !
getLangOpts().CPlusPlus &&
2507 AnnotateScopeToken(*SS,
false);
2516 if (
ParsedType T = Actions.ActOnMSVCUnknownTypeName(
2517 *Tok.getIdentifierInfo(), Tok.getLocation(),
2518 DSC == DeclSpecContext::DSC_template_type_arg)) {
2519 const char *PrevSpec;
2522 Actions.getASTContext().getPrintingPolicy());
2535 if (SS ==
nullptr) {
2536 const char *TagName =
nullptr, *FixitTagName =
nullptr;
2539 switch (Actions.isTagName(*Tok.getIdentifierInfo(),
getCurScope())) {
2542 TagName=
"enum" ; FixitTagName =
"enum " ; TagKind=tok::kw_enum ;
break;
2544 TagName=
"union" ; FixitTagName =
"union " ;TagKind=tok::kw_union ;
break;
2546 TagName=
"struct"; FixitTagName =
"struct ";TagKind=tok::kw_struct;
break;
2548 TagName=
"__interface"; FixitTagName =
"__interface ";
2549 TagKind=tok::kw___interface;
break;
2551 TagName=
"class" ; FixitTagName =
"class " ;TagKind=tok::kw_class ;
break;
2559 Diag(Loc, diag::err_use_of_tag_name_without_tag)
2560 << TokenName << TagName <<
getLangOpts().CPlusPlus
2563 if (Actions.LookupParsedName(R,
getCurScope(), SS)) {
2566 Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
2567 << TokenName << TagName;
2571 if (TagKind == tok::kw_enum)
2572 ParseEnumSpecifier(Loc, DS, TemplateInfo, AS,
2573 DeclSpecContext::DSC_normal);
2575 ParseClassSpecifier(TagKind, Loc, DS, TemplateInfo, AS,
2577 DeclSpecContext::DSC_normal, Attrs);
2584 if (!isTypeSpecifier(DSC) && (!SS || DSC == DeclSpecContext::DSC_top_level ||
2585 DSC == DeclSpecContext::DSC_class)) {
2589 case tok::l_paren: {
2596 TentativeParsingAction PA(*
this);
2598 TPResult TPR = TryParseDeclarator(
false);
2601 if (TPR != TPResult::False) {
2609 if (DSC == DeclSpecContext::DSC_class ||
2610 (DSC == DeclSpecContext::DSC_top_level && SS)) {
2612 if (Actions.isCurrentClassNameTypo(II, SS)) {
2613 Diag(Loc, diag::err_constructor_bad_name)
2614 << Tok.getIdentifierInfo() << II
2616 Tok.setIdentifierInfo(II);
2631 AnnotateScopeToken(*SS,
false);
2647 Actions.DiagnoseUnknownTypeName(II, Loc,
getCurScope(), SS, T,
2653 const char *PrevSpec;
2656 Actions.getASTContext().getPrintingPolicy());
2661 }
else if (II != Tok.getIdentifierInfo()) {
2674 if (IsTemplateName) {
2676 TemplateArgList Args;
2677 ParseTemplateIdAfterTemplateName(
true, LAngle, Args, RAngle);
2691 Parser::DeclSpecContext
2694 return DeclSpecContext::DSC_class;
2696 return DeclSpecContext::DSC_top_level;
2698 return DeclSpecContext::DSC_template_param;
2701 return DeclSpecContext::DSC_template_type_arg;
2704 return DeclSpecContext::DSC_trailing;
2707 return DeclSpecContext::DSC_alias_declaration;
2708 return DeclSpecContext::DSC_normal;
2723 if (isTypeIdInParens()) {
2727 ER = Actions.ActOnUnaryExprOrTypeTraitExpr(TypeLoc,
UETT_AlignOf,
true,
2748 assert(Tok.
isOneOf(tok::kw_alignas, tok::kw__Alignas) &&
2749 "Not an alignment-specifier!");
2770 ArgExprs.push_back(ArgExpr.
get());
2771 Attrs.
addNew(KWName, KWLoc,
nullptr, KWLoc, ArgExprs.data(), 1,
2784 DeclSpecContext DSContext,
2785 LateParsedAttrList *LateAttrs) {
2788 bool EnteringContext = (DSContext == DeclSpecContext::DSC_class ||
2789 DSContext == DeclSpecContext::DSC_top_level);
2792 Tok.
isOneOf(tok::identifier, tok::coloncolon, tok::kw_decltype,
2793 tok::annot_template_id) &&
2799 bool HasScope = Tok.
is(tok::annot_cxxscope);
2805 bool MightBeDeclarator =
true;
2806 if (Tok.
isOneOf(tok::kw_typename, tok::annot_typename)) {
2808 MightBeDeclarator =
false;
2809 }
else if (AfterScope.
is(tok::annot_template_id)) {
2815 MightBeDeclarator =
false;
2816 }
else if (AfterScope.
is(tok::identifier)) {
2817 const Token &Next = HasScope ? GetLookAheadToken(2) :
NextToken();
2821 if (Next.
isOneOf(tok::star, tok::amp, tok::ampamp, tok::identifier,
2822 tok::annot_cxxscope, tok::coloncolon)) {
2824 MightBeDeclarator =
false;
2825 }
else if (HasScope) {
2830 Actions.RestoreNestedNameSpecifierAnnotation(
2831 Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS);
2836 switch (Classification.
getKind()) {
2843 llvm_unreachable(
"typo correction and nested name specifiers not " 2849 MightBeDeclarator =
false;
2862 if (MightBeDeclarator)
2865 const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy();
2867 diag::err_expected_after)
2878 ParsedTemplateInfo NotATemplate;
2879 ParseDeclarationSpecifiers(DS, NotATemplate, AS, DSContext, LateAttrs);
2886 const char *&PrevSpec,
unsigned &DiagID,
2888 assert(!LangOpts.FixedPoint);
2889 DiagID = diag::err_fixed_point_not_enabled;
2921 void Parser::ParseDeclarationSpecifiers(
DeclSpec &DS,
2922 const ParsedTemplateInfo &TemplateInfo,
2924 DeclSpecContext DSContext,
2925 LateParsedAttrList *LateAttrs) {
2934 bool EnteringContext = (DSContext == DeclSpecContext::DSC_class ||
2935 DSContext == DeclSpecContext::DSC_top_level);
2936 bool AttrsLastTime =
false;
2937 ParsedAttributesWithRange attrs(AttrFactory);
2942 bool isStorageClass =
false;
2943 const char *PrevSpec =
nullptr;
2944 unsigned DiagID = 0;
2956 Tok.setKind(tok::identifier);
2960 switch (Tok.getKind()) {
2964 ProhibitAttributes(attrs);
2969 ProhibitCXX11Attributes(attrs, diag::err_attribute_not_type_attr);
2976 DS.
Finish(Actions, Policy);
2980 case tok::kw_alignas:
2981 if (!standardAttributesAllowed() || !isCXX11AttributeSpecifier())
2982 goto DoneWithDeclSpec;
2984 ProhibitAttributes(attrs);
2991 ParseCXX11Attributes(attrs);
2992 AttrsLastTime =
true;
2995 case tok::code_completion: {
2998 bool AllowNonIdentifiers
3004 bool AllowNestedNameSpecifiers
3005 = DSContext == DeclSpecContext::DSC_top_level ||
3009 AllowNonIdentifiers,
3010 AllowNestedNameSpecifiers);
3011 return cutOffParsing();
3016 else if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate)
3019 else if (DSContext == DeclSpecContext::DSC_class)
3021 else if (CurParsedObjCImpl)
3024 Actions.CodeCompleteOrdinaryName(
getCurScope(), CCC);
3025 return cutOffParsing();
3028 case tok::coloncolon:
3033 goto DoneWithDeclSpec;
3035 if (Tok.
is(tok::coloncolon))
3036 goto DoneWithDeclSpec;
3039 case tok::annot_cxxscope: {
3041 goto DoneWithDeclSpec;
3044 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
3045 Tok.getAnnotationRange(),
3050 if (Next.
is(tok::annot_template_id) &&
3063 if ((DSContext == DeclSpecContext::DSC_top_level ||
3064 DSContext == DeclSpecContext::DSC_class) &&
3067 isConstructorDeclarator(
false)) {
3072 goto DoneWithDeclSpec;
3076 ConsumeAnnotationToken();
3077 assert(Tok.
is(tok::annot_template_id) &&
3078 "ParseOptionalCXXScopeSpecifier not working");
3079 AnnotateTemplateIdTokenAsType();
3083 if (Next.
is(tok::annot_typename)) {
3085 ConsumeAnnotationToken();
3086 if (Tok.getAnnotationValue()) {
3089 Tok.getAnnotationEndLoc(),
3090 PrevSpec, DiagID, T, Policy);
3097 ConsumeAnnotationToken();
3100 if (Next.
isNot(tok::identifier))
3101 goto DoneWithDeclSpec;
3106 if ((DSContext == DeclSpecContext::DSC_top_level ||
3107 DSContext == DeclSpecContext::DSC_class) &&
3110 isConstructorDeclarator(
false))
3111 goto DoneWithDeclSpec;
3118 isClassTemplateDeductionContext(DSContext));
3126 ConsumeAnnotationToken();
3127 ParsedAttributesWithRange Attrs(AttrFactory);
3128 if (ParseImplicitInt(DS, &SS, TemplateInfo, AS, DSContext, Attrs)) {
3129 if (!Attrs.empty()) {
3130 AttrsLastTime =
true;
3131 attrs.takeAllFrom(Attrs);
3135 goto DoneWithDeclSpec;
3139 ConsumeAnnotationToken();
3142 DiagID, TypeRep, Policy);
3152 case tok::annot_typename: {
3156 goto DoneWithDeclSpec;
3158 if (Tok.getAnnotationValue()) {
3169 ConsumeAnnotationToken();
3174 case tok::kw___is_signed:
3185 TryKeywordIdentFallback(
true);
3188 goto DoneWithDeclSpec;
3191 case tok::kw___super:
3192 case tok::kw_decltype:
3193 case tok::identifier: {
3198 goto DoneWithDeclSpec;
3204 if (!
getLangOpts().DeclSpecKeyword && Tok.
is(tok::identifier) &&
3205 Tok.getIdentifierInfo()->getName().equals(
"__declspec")) {
3206 Diag(Loc, diag::err_ms_attributes_not_enabled);
3217 assert(
false &&
"Not a left paren?");
3230 goto DoneWithDeclSpec;
3232 if (!Tok.
is(tok::identifier))
3237 if (TryAltiVecToken(DS, Loc, PrevSpec, DiagID, isInvalid))
3243 goto DoneWithDeclSpec;
3245 if (DSContext == DeclSpecContext::DSC_objc_method_result &&
3246 isObjCInstancetype()) {
3247 ParsedType TypeRep = Actions.ActOnObjCInstanceType(Loc);
3250 DiagID, TypeRep, Policy);
3262 Actions.isCurrentClassName(*Tok.getIdentifierInfo(),
getCurScope()) &&
3263 isConstructorDeclarator(
true))
3264 goto DoneWithDeclSpec;
3267 *Tok.getIdentifierInfo(), Tok.getLocation(),
getCurScope(),
nullptr,
3268 false,
false,
nullptr,
false,
false,
3269 isClassTemplateDeductionContext(DSContext));
3274 ParsedAttributesWithRange Attrs(AttrFactory);
3275 if (ParseImplicitInt(DS,
nullptr, TemplateInfo, AS, DSContext, Attrs)) {
3276 if (!Attrs.empty()) {
3277 AttrsLastTime =
true;
3278 attrs.takeAllFrom(Attrs);
3282 goto DoneWithDeclSpec;
3288 (DSContext == DeclSpecContext::DSC_class ||
3289 DSContext == DeclSpecContext::DSC_top_level) &&
3290 Actions.isDeductionGuideName(
getCurScope(), *Tok.getIdentifierInfo(),
3291 Tok.getLocation()) &&
3292 isConstructorDeclarator(
true,
3294 goto DoneWithDeclSpec;
3297 DiagID, TypeRep, Policy);
3309 TypeResult NewTypeRep = parseObjCTypeArgsAndProtocolQualifiers(
3324 case tok::annot_template_id: {
3329 goto DoneWithDeclSpec;
3337 isConstructorDeclarator(TemplateId->
SS.
isEmpty()))
3338 goto DoneWithDeclSpec;
3342 AnnotateTemplateIdTokenAsType();
3347 case tok::kw___attribute:
3352 case tok::kw___declspec:
3357 case tok::kw___forceinline: {
3366 case tok::kw___unaligned:
3371 case tok::kw___sptr:
3372 case tok::kw___uptr:
3373 case tok::kw___ptr64:
3374 case tok::kw___ptr32:
3376 case tok::kw___cdecl:
3377 case tok::kw___stdcall:
3378 case tok::kw___fastcall:
3379 case tok::kw___thiscall:
3380 case tok::kw___regcall:
3381 case tok::kw___vectorcall:
3386 case tok::kw___pascal:
3391 case tok::kw___kernel:
3396 case tok::kw__Nonnull:
3397 case tok::kw__Nullable:
3398 case tok::kw__Null_unspecified:
3403 case tok::kw___kindof:
3410 case tok::kw_typedef:
3412 PrevSpec, DiagID, Policy);
3413 isStorageClass =
true;
3415 case tok::kw_extern:
3417 Diag(Tok, diag::ext_thread_before) <<
"extern";
3419 PrevSpec, DiagID, Policy);
3420 isStorageClass =
true;
3422 case tok::kw___private_extern__:
3424 Loc, PrevSpec, DiagID, Policy);
3425 isStorageClass =
true;
3427 case tok::kw_static:
3429 Diag(Tok, diag::ext_thread_before) <<
"static";
3431 PrevSpec, DiagID, Policy);
3432 isStorageClass =
true;
3436 if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) {
3438 PrevSpec, DiagID, Policy);
3440 Diag(Tok, diag::ext_auto_storage_class)
3447 PrevSpec, DiagID, Policy);
3448 isStorageClass =
true;
3450 case tok::kw___auto_type:
3451 Diag(Tok, diag::ext_auto_type);
3455 case tok::kw_register:
3457 PrevSpec, DiagID, Policy);
3458 isStorageClass =
true;
3460 case tok::kw_mutable:
3462 PrevSpec, DiagID, Policy);
3463 isStorageClass =
true;
3465 case tok::kw___thread:
3468 isStorageClass =
true;
3470 case tok::kw_thread_local:
3473 isStorageClass =
true;
3475 case tok::kw__Thread_local:
3477 Loc, PrevSpec, DiagID);
3478 isStorageClass =
true;
3482 case tok::kw_inline:
3485 case tok::kw_virtual:
3488 DiagID = diag::err_openclcxx_virtual_function;
3489 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
3496 case tok::kw_explicit:
3499 case tok::kw__Noreturn:
3501 Diag(Loc, diag::ext_c11_noreturn);
3506 case tok::kw__Alignas:
3508 Diag(Tok, diag::ext_c11_alignment) << Tok.getName();
3513 case tok::kw_friend:
3514 if (DSContext == DeclSpecContext::DSC_class)
3518 DiagID = diag::err_friend_invalid_in_context;
3524 case tok::kw___module_private__:
3529 case tok::kw_constexpr:
3546 case tok::kw___int64:
3550 case tok::kw_signed:
3554 case tok::kw_unsigned:
3558 case tok::kw__Complex:
3562 case tok::kw__Imaginary:
3578 case tok::kw___int128:
3590 case tok::kw_double:
3594 case tok::kw__Float16:
3598 case tok::kw__Accum:
3606 case tok::kw__Fract:
3621 case tok::kw___float128:
3625 case tok::kw_wchar_t:
3629 case tok::kw_char8_t:
3633 case tok::kw_char16_t:
3637 case tok::kw_char32_t:
3643 if (Tok.
is(tok::kw_bool) &&
3647 DiagID = diag::err_bool_redeclaration;
3649 Tok.setKind(tok::identifier);
3656 case tok::kw__Decimal32:
3660 case tok::kw__Decimal64:
3664 case tok::kw__Decimal128:
3668 case tok::kw___vector:
3671 case tok::kw___pixel:
3674 case tok::kw___bool:
3681 Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
3682 goto DoneWithDeclSpec;
3684 isInvalid = DS.
SetTypePipe(
true, Loc, PrevSpec, DiagID, Policy);
3686 #define GENERIC_IMAGE_TYPE(ImgType, Id) \ 3687 case tok::kw_##ImgType##_t: \ 3688 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, \ 3691 #include "clang/Basic/OpenCLImageTypes.def" 3692 case tok::kw___unknown_anytype:
3694 PrevSpec, DiagID, Policy);
3699 case tok::kw_struct:
3700 case tok::kw___interface:
3701 case tok::kw_union: {
3708 ParsedAttributesWithRange Attributes(AttrFactory);
3709 ParseClassSpecifier(Kind, Loc, DS, TemplateInfo, AS,
3710 EnteringContext, DSContext, Attributes);
3714 if (!Attributes.empty()) {
3715 AttrsLastTime =
true;
3716 attrs.takeAllFrom(Attributes);
3724 ParseEnumSpecifier(Loc, DS, TemplateInfo, AS, DSContext);
3732 case tok::kw_volatile:
3736 case tok::kw_restrict:
3742 case tok::kw_typename:
3745 goto DoneWithDeclSpec;
3747 if (!Tok.
is(tok::kw_typename))
3752 case tok::kw_typeof:
3753 ParseTypeofSpecifier(DS);
3756 case tok::annot_decltype:
3757 ParseDecltypeSpecifier(DS);
3760 case tok::annot_pragma_pack:
3764 case tok::annot_pragma_ms_pragma:
3765 HandlePragmaMSPragma();
3768 case tok::annot_pragma_ms_vtordisp:
3769 HandlePragmaMSVtorDisp();
3772 case tok::annot_pragma_ms_pointers_to_members:
3773 HandlePragmaMSPointersToMembers();
3776 case tok::kw___underlying_type:
3777 ParseUnderlyingTypeSpecifier(DS);
3780 case tok::kw__Atomic:
3786 ParseAtomicSpecifier(DS);
3794 case tok::kw___read_only:
3795 case tok::kw___write_only:
3796 case tok::kw___read_write:
3798 if (Actions.getLangOpts().OpenCLCPlusPlus) {
3799 DiagID = diag::err_openclcxx_reserved;
3800 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
3807 case tok::kw___generic:
3810 if (Actions.getLangOpts().OpenCLVersion < 200 &&
3811 !Actions.getLangOpts().OpenCLCPlusPlus) {
3812 DiagID = diag::err_opencl_unknown_type_specifier;
3813 PrevSpec = Tok.getIdentifierInfo()->getNameStart();
3818 case tok::kw___private:
3819 case tok::kw___global:
3820 case tok::kw___local:
3821 case tok::kw___constant:
3830 goto DoneWithDeclSpec;
3837 PrevSpec, DiagID, Type.
get(),
3838 Actions.getASTContext().getPrintingPolicy()))
3839 Diag(StartLoc, DiagID) << PrevSpec;
3852 assert(PrevSpec &&
"Method did not return previous specifier!");
3855 if (DiagID == diag::ext_duplicate_declspec ||
3856 DiagID == diag::ext_warn_duplicate_declspec)
3859 else if (DiagID == diag::err_opencl_unknown_type_specifier) {
3862 << PrevSpec << isStorageClass;
3864 Diag(Tok, DiagID) << PrevSpec;
3868 if (DiagID != diag::err_bool_redeclaration)
3872 AttrsLastTime =
false;
3894 void Parser::ParseStructDeclaration(
3898 if (Tok.
is(tok::kw___extension__)) {
3902 return ParseStructDeclaration(DS, FieldsCallback);
3906 ParsedAttributesWithRange Attrs(AttrFactory);
3907 MaybeParseCXX11Attributes(Attrs);
3911 ParseSpecifierQualifierList(DS);
3915 if (Tok.
is(tok::semi)) {
3919 assert(!AnonRecord &&
"Did not expect anonymous struct or union here");
3925 bool FirstDeclarator =
true;
3932 if (!FirstDeclarator)
3933 MaybeParseGNUAttributes(DeclaratorInfo.
D);
3937 if (Tok.
isNot(tok::colon)) {
3940 ParseDeclarator(DeclaratorInfo.
D);
3953 MaybeParseGNUAttributes(DeclaratorInfo.
D);
3956 FieldsCallback(DeclaratorInfo);
3963 FirstDeclarator =
false;
3980 "parsing struct/union body");
3988 Actions.ActOnTagStartDefinition(
getCurScope(), TagDecl);
3993 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
3998 if (Tok.
is(tok::semi)) {
3999 ConsumeExtraSemi(InsideStruct,
TagType);
4004 if (Tok.
is(tok::kw__Static_assert)) {
4006 ParseStaticAssertDeclaration(DeclEnd);
4010 if (Tok.
is(tok::annot_pragma_pack)) {
4015 if (Tok.
is(tok::annot_pragma_align)) {
4016 HandlePragmaAlign();
4020 if (Tok.
is(tok::annot_pragma_openmp)) {
4023 ParsedAttributesWithRange Attrs(AttrFactory);
4024 (void)ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs);
4028 if (!Tok.
is(tok::at)) {
4034 FD.D, FD.BitfieldSize);
4035 FieldDecls.push_back(Field);
4041 ParseStructDeclaration(DS, CFieldCallback);
4045 Diag(Tok, diag::err_unexpected_at);
4050 ExpectAndConsume(tok::l_paren);
4051 if (!Tok.
is(tok::identifier)) {
4052 Diag(Tok, diag::err_expected) << tok::identifier;
4057 Actions.ActOnDefs(
getCurScope(), TagDecl, Tok.getLocation(),
4058 Tok.getIdentifierInfo(), Fields);
4059 FieldDecls.insert(FieldDecls.end(), Fields.begin(), Fields.end());
4061 ExpectAndConsume(tok::r_paren);
4067 if (Tok.
is(tok::r_brace)) {
4068 ExpectAndConsume(tok::semi, diag::ext_expected_semi_decl_list);
4072 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list);
4083 MaybeParseGNUAttributes(attrs);
4085 Actions.ActOnFields(
getCurScope(), RecordLoc, TagDecl, FieldDecls,
4122 const ParsedTemplateInfo &TemplateInfo,
4125 if (Tok.
is(tok::code_completion)) {
4128 return cutOffParsing();
4132 ParsedAttributesWithRange attrs(AttrFactory);
4133 MaybeParseGNUAttributes(attrs);
4134 MaybeParseCXX11Attributes(attrs);
4135 MaybeParseMicrosoftDeclSpecs(attrs);
4138 bool IsScopedUsingClassTag =
false;
4141 if (Tok.
isOneOf(tok::kw_class, tok::kw_struct)) {
4143 : diag::ext_scoped_enum);
4144 IsScopedUsingClassTag = Tok.
is(tok::kw_class);
4149 ProhibitAttributes(attrs);
4152 MaybeParseGNUAttributes(attrs);
4153 MaybeParseCXX11Attributes(attrs);
4154 MaybeParseMicrosoftDeclSpecs(attrs);
4163 bool shouldDelayDiagsInTag =
4164 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
4165 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
4169 bool AllowDeclaration = DSC != DeclSpecContext::DSC_trailing;
4178 if (ParseOptionalCXXScopeSpecifier(Spec,
nullptr,
4182 if (Spec.
isSet() && Tok.
isNot(tok::identifier)) {
4183 Diag(Tok, diag::err_expected) << tok::identifier;
4184 if (Tok.
isNot(tok::l_brace)) {
4196 if (Tok.
isNot(tok::identifier) && Tok.
isNot(tok::l_brace) &&
4197 !(AllowDeclaration && Tok.
is(tok::colon))) {
4198 Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace;
4208 if (Tok.
is(tok::identifier)) {
4209 Name = Tok.getIdentifierInfo();
4213 if (!Name && ScopedEnumKWLoc.
isValid()) {
4216 Diag(Tok, diag::err_scoped_enum_missing_identifier);
4218 IsScopedUsingClassTag =
false;
4223 if (shouldDelayDiagsInTag)
4224 diagsFromTag.
done();
4230 if (AllowDeclaration && Tok.
is(tok::colon)) {
4231 bool PossibleBitfield =
false;
4232 if (CanBeBitfield) {
4245 if (TPR == TPResult::True)
4246 PossibleBitfield =
true;
4251 else if (TPR == TPResult::False &&
4252 GetLookAheadToken(2).
getKind() == tok::semi) {
4259 TentativeParsingAction TPA(*
this);
4271 isCXXDeclarationSpecifier(TPResult::True) != TPResult::True) ||
4274 PossibleBitfield =
true;
4286 if (!PossibleBitfield) {
4292 Diag(StartLoc, diag::warn_cxx98_compat_enum_fixed_underlying_type);
4294 Diag(StartLoc, diag::ext_cxx11_enum_fixed_underlying_type);
4296 Diag(StartLoc, diag::ext_ms_c_enum_fixed_underlying_type);
4298 Diag(StartLoc, diag::ext_clang_c_enum_fixed_underlying_type);
4314 if (!AllowDeclaration) {
4316 }
else if (Tok.
is(tok::l_brace)) {
4318 Diag(Tok.getLocation(), diag::err_friend_decl_defines_type)
4326 }
else if (!isTypeSpecifier(DSC) &&
4327 (Tok.
is(tok::semi) ||
4328 (Tok.isAtStartOfLine() &&
4329 !isValidAfterTypeSpecifier(CanBeBitfield)))) {
4331 if (Tok.
isNot(tok::semi)) {
4333 ExpectAndConsume(tok::semi, diag::err_expected_after,
"enum");
4335 Tok.setKind(tok::semi);
4348 if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
4352 Diag(Tok, diag::err_enum_template);
4357 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
4360 Diag(StartLoc, diag::err_explicit_instantiation_enum);
4364 assert(TemplateInfo.TemplateParams &&
"no template parameters");
4366 TemplateInfo.TemplateParams->size());
4370 ProhibitAttributes(attrs);
4373 Diag(Tok, diag::err_enumerator_unnamed_no_def);
4380 stripTypeAttributesOffDeclSpec(attrs, DS, TUK);
4385 SkipBody = Actions.shouldSkipAnonEnumBody(
getCurScope(),
4390 bool IsDependent =
false;
4391 const char *PrevSpec =
nullptr;
4393 Decl *TagDecl = Actions.ActOnTag(
4396 ScopedEnumKWLoc, IsScopedUsingClassTag, BaseType,
4397 DSC == DeclSpecContext::DSC_type_specifier,
4398 DSC == DeclSpecContext::DSC_template_param ||
4399 DSC == DeclSpecContext::DSC_template_type_arg,
4410 NameLoc.
isValid() ? NameLoc : StartLoc,
4411 PrevSpec, DiagID, TagDecl, Owned,
4413 Diag(StartLoc, DiagID) << PrevSpec;
4422 Diag(Tok, diag::err_expected_type_name_after_typename);
4434 NameLoc.
isValid() ? NameLoc : StartLoc,
4435 PrevSpec, DiagID, Type.
get(),
4436 Actions.getASTContext().getPrintingPolicy()))
4437 Diag(StartLoc, DiagID) << PrevSpec;
4456 ParseEnumBody(StartLoc, D);
4458 !Actions.ActOnDuplicateDefinition(DS, TagDecl, SkipBody)) {
4465 NameLoc.
isValid() ? NameLoc : StartLoc,
4466 PrevSpec, DiagID, TagDecl, Owned,
4468 Diag(StartLoc, DiagID) << PrevSpec;
4484 Actions.ActOnTagStartDefinition(
getCurScope(), EnumDecl);
4491 Diag(Tok, diag::err_empty_enum);
4496 Decl *LastEnumConstDecl =
nullptr;
4499 while (Tok.
isNot(tok::r_brace)) {
4502 if (Tok.
isNot(tok::identifier)) {
4503 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
4513 ParsedAttributesWithRange attrs(AttrFactory);
4514 MaybeParseGNUAttributes(attrs);
4515 ProhibitAttributes(attrs);
4516 if (standardAttributesAllowed() && isCXX11AttributeSpecifier()) {
4519 ? diag::warn_cxx14_compat_ns_enum_attribute
4520 : diag::ext_ns_enum_attribute)
4522 ParseCXX11Attributes(attrs);
4527 EnumAvailabilityDiags.emplace_back(*
this);
4536 Decl *EnumConstDecl = Actions.ActOnEnumConstant(
4537 getCurScope(), EnumDecl, LastEnumConstDecl, IdentLoc, Ident, attrs,
4538 EqualLoc, AssignedVal.
get());
4539 EnumAvailabilityDiags.back().done();
4541 EnumConstantDecls.push_back(EnumConstDecl);
4542 LastEnumConstDecl = EnumConstDecl;
4544 if (Tok.
is(tok::identifier)) {
4547 Diag(Loc, diag::err_enumerator_list_missing_comma)
4557 Diag(Tok.getLocation(), diag::err_expected_either) << tok::r_brace
4560 Diag(Tok.getLocation(), diag::err_expected_end_of_enumerator);
4570 if (Tok.
is(tok::r_brace) && CommaLoc.
isValid()) {
4573 diag::ext_enumerator_list_comma_cxx :
4574 diag::ext_enumerator_list_comma_c)
4577 Diag(CommaLoc, diag::warn_cxx98_compat_enumerator_list_comma)
4588 MaybeParseGNUAttributes(attrs);
4590 Actions.ActOnEnumBody(StartLoc, T.
getRange(), EnumDecl, EnumConstantDecls,
4594 assert(EnumConstantDecls.size() == EnumAvailabilityDiags.size());
4595 for (
size_t i = 0, e = EnumConstantDecls.size(); i != e; ++i) {
4597 EnumAvailabilityDiags[i].redelay();
4607 if (!isValidAfterTypeSpecifier(CanBeBitfield)) {
4608 ExpectAndConsume(tok::semi, diag::err_expected_after,
"enum");
4613 Tok.setKind(tok::semi);
4620 bool Parser::isKnownToBeTypeSpecifier(
const Token &Tok)
const {
4622 default:
return false;
4626 case tok::kw___int64:
4627 case tok::kw___int128:
4628 case tok::kw_signed:
4629 case tok::kw_unsigned:
4630 case tok::kw__Complex:
4631 case tok::kw__Imaginary:
4634 case tok::kw_wchar_t:
4635 case tok::kw_char8_t:
4636 case tok::kw_char16_t:
4637 case tok::kw_char32_t:
4641 case tok::kw_double:
4642 case tok::kw__Accum:
4643 case tok::kw__Fract:
4644 case tok::kw__Float16:
4645 case tok::kw___float128:
4648 case tok::kw__Decimal32:
4649 case tok::kw__Decimal64:
4650 case tok::kw__Decimal128:
4651 case tok::kw___vector:
4652 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: 4653 #include "clang/Basic/OpenCLImageTypes.def" 4657 case tok::kw_struct:
4658 case tok::kw___interface:
4664 case tok::annot_typename:
4671 bool Parser::isTypeSpecifierQualifier() {
4673 default:
return false;
4675 case tok::identifier:
4676 if (TryAltiVecVectorToken())
4679 case tok::kw_typename:
4684 if (Tok.
is(tok::identifier))
4686 return isTypeSpecifierQualifier();
4688 case tok::coloncolon:
4695 return isTypeSpecifierQualifier();
4698 case tok::kw___attribute:
4700 case tok::kw_typeof:
4705 case tok::kw___int64:
4706 case tok::kw___int128:
4707 case tok::kw_signed:
4708 case tok::kw_unsigned:
4709 case tok::kw__Complex:
4710 case tok::kw__Imaginary:
4713 case tok::kw_wchar_t:
4714 case tok::kw_char8_t:
4715 case tok::kw_char16_t:
4716 case tok::kw_char32_t:
4720 case tok::kw_double:
4721 case tok::kw__Accum:
4722 case tok::kw__Fract:
4723 case tok::kw__Float16:
4724 case tok::kw___float128:
4727 case tok::kw__Decimal32:
4728 case tok::kw__Decimal64:
4729 case tok::kw__Decimal128:
4730 case tok::kw___vector:
4731 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: 4732 #include "clang/Basic/OpenCLImageTypes.def" 4736 case tok::kw_struct:
4737 case tok::kw___interface:
4744 case tok::kw_volatile:
4745 case tok::kw_restrict:
4749 case tok::kw___unknown_anytype:
4752 case tok::annot_typename:
4759 case tok::kw___cdecl:
4760 case tok::kw___stdcall:
4761 case tok::kw___fastcall:
4762 case tok::kw___thiscall:
4763 case tok::kw___regcall:
4764 case tok::kw___vectorcall:
4766 case tok::kw___ptr64:
4767 case tok::kw___ptr32:
4768 case tok::kw___pascal:
4769 case tok::kw___unaligned:
4771 case tok::kw__Nonnull:
4772 case tok::kw__Nullable:
4773 case tok::kw__Null_unspecified:
4775 case tok::kw___kindof:
4777 case tok::kw___private:
4778 case tok::kw___local:
4779 case tok::kw___global:
4780 case tok::kw___constant:
4781 case tok::kw___generic:
4782 case tok::kw___read_only:
4783 case tok::kw___read_write:
4784 case tok::kw___write_only:
4789 case tok::kw__Atomic:
4799 bool Parser::isDeclarationSpecifier(
bool DisambiguatingWithExpression) {
4801 default:
return false;
4806 case tok::identifier:
4810 if (TryAltiVecVectorToken())
4813 case tok::kw_decltype:
4814 case tok::kw_typename:
4819 if (Tok.
is(tok::identifier))
4827 if (DisambiguatingWithExpression &&
4828 isStartOfObjCClassMessageMissingOpenBracket())
4831 return isDeclarationSpecifier();
4833 case tok::coloncolon:
4842 return isDeclarationSpecifier();
4845 case tok::kw_typedef:
4846 case tok::kw_extern:
4847 case tok::kw___private_extern__:
4848 case tok::kw_static:
4850 case tok::kw___auto_type:
4851 case tok::kw_register:
4852 case tok::kw___thread:
4853 case tok::kw_thread_local:
4854 case tok::kw__Thread_local:
4857 case tok::kw___module_private__:
4860 case tok::kw___unknown_anytype:
4865 case tok::kw___int64:
4866 case tok::kw___int128:
4867 case tok::kw_signed:
4868 case tok::kw_unsigned:
4869 case tok::kw__Complex:
4870 case tok::kw__Imaginary:
4873 case tok::kw_wchar_t:
4874 case tok::kw_char8_t:
4875 case tok::kw_char16_t:
4876 case tok::kw_char32_t:
4881 case tok::kw_double:
4882 case tok::kw__Accum:
4883 case tok::kw__Fract:
4884 case tok::kw__Float16:
4885 case tok::kw___float128:
4888 case tok::kw__Decimal32:
4889 case tok::kw__Decimal64:
4890 case tok::kw__Decimal128:
4891 case tok::kw___vector:
4895 case tok::kw_struct:
4897 case tok::kw___interface:
4903 case tok::kw_volatile:
4904 case tok::kw_restrict:
4908 case tok::kw_inline:
4909 case tok::kw_virtual:
4910 case tok::kw_explicit:
4911 case tok::kw__Noreturn:
4914 case tok::kw__Alignas:
4917 case tok::kw_friend:
4920 case tok::kw__Static_assert:
4923 case tok::kw_typeof:
4926 case tok::kw___attribute:
4929 case tok::annot_decltype:
4930 case tok::kw_constexpr:
4933 case tok::kw__Atomic:
4941 case tok::annot_typename:
4942 return !DisambiguatingWithExpression ||
4943 !isStartOfObjCClassMessageMissingOpenBracket();
4945 case tok::kw___declspec:
4946 case tok::kw___cdecl:
4947 case tok::kw___stdcall:
4948 case tok::kw___fastcall:
4949 case tok::kw___thiscall:
4950 case tok::kw___regcall:
4951 case tok::kw___vectorcall:
4953 case tok::kw___sptr:
4954 case tok::kw___uptr:
4955 case tok::kw___ptr64:
4956 case tok::kw___ptr32:
4957 case tok::kw___forceinline:
4958 case tok::kw___pascal:
4959 case tok::kw___unaligned:
4961 case tok::kw__Nonnull:
4962 case tok::kw__Nullable:
4963 case tok::kw__Null_unspecified:
4965 case tok::kw___kindof:
4967 case tok::kw___private:
4968 case tok::kw___local:
4969 case tok::kw___global:
4970 case tok::kw___constant:
4971 case tok::kw___generic:
4972 case tok::kw___read_only:
4973 case tok::kw___read_write:
4974 case tok::kw___write_only:
4975 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: 4976 #include "clang/Basic/OpenCLImageTypes.def" 4982 bool Parser::isConstructorDeclarator(
bool IsUnqualified,
bool DeductionGuide) {
4983 TentativeParsingAction TPA(*
this);
4987 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
4994 if (Tok.
is(tok::identifier)) {
4998 }
else if (Tok.
is(tok::annot_template_id)) {
4999 ConsumeAnnotationToken();
5007 SkipCXX11Attributes();
5010 if (Tok.
isNot(tok::l_paren)) {
5018 if (Tok.
is(tok::r_paren) ||
5027 isCXX11AttributeSpecifier(
false,
5034 DeclaratorScopeObj DeclScopeObj(*
this, SS);
5036 DeclScopeObj.EnterDeclaratorScope();
5040 MaybeParseMicrosoftAttributes(Attrs);
5045 bool IsConstructor =
false;
5046 if (isDeclarationSpecifier())
5047 IsConstructor =
true;
5048 else if (Tok.
is(tok::identifier) ||
5049 (Tok.
is(tok::annot_cxxscope) &&
NextToken().
is(tok::identifier))) {
5054 if (Tok.
is(tok::annot_cxxscope))
5055 ConsumeAnnotationToken();
5067 case tok::coloncolon:
5080 SkipCXX11Attributes();
5082 if (DeductionGuide) {
5084 IsConstructor = Tok.
is(tok::arrow);
5087 if (Tok.
is(tok::colon) || Tok.
is(tok::kw_try)) {
5091 IsConstructor =
true;
5093 if (Tok.
is(tok::semi) || Tok.
is(tok::l_brace)) {
5106 IsConstructor = IsUnqualified;
5111 IsConstructor =
true;
5117 return IsConstructor;
5132 void Parser::ParseTypeQualifierListOpt(
5133 DeclSpec &DS,
unsigned AttrReqs,
bool AtomicAllowed,
5134 bool IdentifierRequired,
5136 if (standardAttributesAllowed() && (AttrReqs & AR_CXX11AttributesParsed) &&
5137 isCXX11AttributeSpecifier()) {
5138 ParsedAttributesWithRange attrs(AttrFactory);
5139 ParseCXX11Attributes(attrs);
5147 const char *PrevSpec =
nullptr;
5148 unsigned DiagID = 0;
5152 case tok::code_completion:
5154 (*CodeCompletionHandler)();
5156 Actions.CodeCompleteTypeQualifiers(DS);
5157 return cutOffParsing();
5163 case tok::kw_volatile:
5167 case tok::kw_restrict:
5171 case tok::kw__Atomic:
5173 goto DoneWithTypeQuals;
5179 case tok::kw___private:
5180 case tok::kw___global:
5181 case tok::kw___local:
5182 case tok::kw___constant:
5183 case tok::kw___generic:
5184 case tok::kw___read_only:
5185 case tok::kw___write_only:
5186 case tok::kw___read_write:
5190 case tok::kw___unaligned:
5194 case tok::kw___uptr:
5199 if (TryKeywordIdentFallback(
false))
5203 case tok::kw___sptr:
5205 case tok::kw___ptr64:
5206 case tok::kw___ptr32:
5207 case tok::kw___cdecl:
5208 case tok::kw___stdcall:
5209 case tok::kw___fastcall:
5210 case tok::kw___thiscall:
5211 case tok::kw___regcall:
5212 case tok::kw___vectorcall:
5213 if (AttrReqs & AR_DeclspecAttributesParsed) {
5217 goto DoneWithTypeQuals;
5218 case tok::kw___pascal:
5219 if (AttrReqs & AR_VendorAttributesParsed) {
5223 goto DoneWithTypeQuals;
5226 case tok::kw__Nonnull:
5227 case tok::kw__Nullable:
5228 case tok::kw__Null_unspecified:
5233 case tok::kw___kindof:
5239 case tok::kw___attribute:
5240 if (AttrReqs & AR_GNUAttributesParsedAndRejected)
5242 Diag(Tok, diag::err_attributes_not_allowed);
5246 if (AttrReqs & AR_GNUAttributesParsed ||
5247 AttrReqs & AR_GNUAttributesParsedAndRejected) {
5257 DS.
Finish(Actions, Actions.getASTContext().getPrintingPolicy());
5265 assert(PrevSpec &&
"Method did not return previous specifier!");
5266 Diag(Tok, DiagID) << PrevSpec;
5274 void Parser::ParseDeclarator(
Declarator &D) {
5277 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
5282 if (Kind == tok::star || Kind == tok::caret)
5285 if ((Kind == tok::kw_pipe) && Lang.OpenCL && (Lang.OpenCLVersion >= 200))
5288 if (!Lang.CPlusPlus)
5291 if (Kind == tok::amp)
5299 if (Kind == tok::ampamp)
5300 return Lang.CPlusPlus11 ||
5311 for (
unsigned Idx = 0; Idx != NumTypes; ++Idx)
5343 void Parser::ParseDeclaratorInternal(
Declarator &D,
5344 DirectDeclParseFunction DirectDeclParser) {
5345 if (Diags.hasAllExtensionsSilenced())
5352 (Tok.
is(tok::coloncolon) || Tok.
is(tok::kw_decltype) ||
5353 (Tok.
is(tok::identifier) &&
5355 Tok.
is(tok::annot_cxxscope))) {
5356 bool EnteringContext =
5360 ParseOptionalCXXScopeSpecifier(SS,
nullptr, EnteringContext);
5363 if (Tok.
isNot(tok::star)) {
5368 AnnotateScopeToken(SS,
true);
5370 if (DirectDeclParser)
5371 (this->*DirectDeclParser)(D);
5378 ParseTypeQualifierListOpt(DS);
5382 ParseDeclaratorInternal(D, DirectDeclParser);
5398 ParseTypeQualifierListOpt(DS);
5407 if (DirectDeclParser)
5408 (this->*DirectDeclParser)(D);
5417 if (Kind == tok::star || Kind == tok::caret) {
5423 unsigned Reqs = AR_CXX11AttributesParsed | AR_DeclspecAttributesParsed |
5425 ? AR_GNUAttributesParsed
5426 : AR_GNUAttributesParsedAndRejected);
5431 ParseDeclaratorInternal(D, DirectDeclParser);
5432 if (Kind == tok::star)
5450 if (Kind == tok::ampamp)
5452 diag::warn_cxx98_compat_rvalue_reference :
5453 diag::ext_rvalue_reference);
5456 ParseTypeQualifierListOpt(DS);
5465 diag::err_invalid_reference_qualifier_application) <<
"const";
5468 diag::err_invalid_reference_qualifier_application) <<
"volatile";
5472 diag::err_invalid_reference_qualifier_application) <<
"_Atomic";
5476 ParseDeclaratorInternal(D, DirectDeclParser);
5483 Diag(InnerChunk.
Loc, diag::err_illegal_decl_reference_to_reference)
5486 Diag(InnerChunk.
Loc, diag::err_illegal_decl_reference_to_reference)
5561 void Parser::ParseDirectDeclarator(
Declarator &D) {
5568 return ParseDecompositionDeclarator(D);
5580 bool EnteringContext =
5588 if (Actions.ShouldEnterDeclaratorScope(
getCurScope(),
5592 DeclScopeObj.EnterDeclaratorScope();
5599 goto PastIdentifier;
5616 !Actions.containsUnexpandedParameterPacks(D) &&
5624 DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, D);
5634 if (Tok.
isOneOf(tok::identifier, tok::kw_operator, tok::annot_template_id,
5638 bool AllowConstructorName;
5639 bool AllowDeductionGuide;
5641 AllowConstructorName =
false;
5642 AllowDeductionGuide =
false;
5644 AllowConstructorName =
5647 AllowDeductionGuide =
false;
5649 AllowConstructorName =
5651 AllowDeductionGuide =
5659 true, AllowConstructorName,
5660 AllowDeductionGuide,
nullptr,
nullptr,
5673 DeclScopeObj.EnterDeclaratorScope();
5680 goto PastIdentifier;
5686 diag::err_expected_unqualified_id)
5689 goto PastIdentifier;
5693 "There's a C++-specific check for tok::identifier above");
5698 goto PastIdentifier;
5703 bool DiagnoseIdentifier =
false;
5707 DiagnoseIdentifier =
true;
5710 DiagnoseIdentifier =
5718 !isCXX11VirtSpecifier(Tok))
5720 tok::comma, tok::semi, tok::equal, tok::l_brace, tok::kw_try);
5721 if (DiagnoseIdentifier) {
5726 goto PastIdentifier;
5730 if (Tok.
is(tok::l_paren)) {
5735 RevertingTentativeParsingAction PA(*
this);
5739 goto PastIdentifier;
5746 ParseParenDeclarator(D);
5759 DeclScopeObj.EnterDeclaratorScope();
5770 diag::ext_abstract_pack_declarator_parens);
5772 if (Tok.
getKind() == tok::annot_pragma_parser_crash)
5774 if (Tok.
is(tok::l_square))
5775 return ParseMisplacedBracketDeclarator(D);
5783 diag::err_expected_member_name_or_semi_objcxx_keyword)
5790 goto PastIdentifier;
5793 diag::err_expected_member_name_or_semi)
5797 if (Tok.
isOneOf(tok::period, tok::arrow))
5798 Diag(Tok, diag::err_invalid_operator_on_type) << Tok.
is(tok::arrow);
5802 Diag(PP.getLocForEndOfToken(Loc), diag::err_expected_unqualified_id)
5806 diag::err_expected_unqualified_id)
5811 diag::err_expected_either)
5812 << tok::identifier << tok::l_paren;
5820 "Haven't past the location of the identifier yet?");
5824 MaybeParseCXX11Attributes(D);
5827 if (Tok.
is(tok::l_paren)) {
5830 ParseScope PrototypeScope(
this,
5838 bool IsAmbiguous =
false;
5842 TentativelyDeclaredIdentifiers.push_back(D.
getIdentifier());
5843 bool IsFunctionDecl = isCXXFunctionDeclarator(&IsAmbiguous);
5844 TentativelyDeclaredIdentifiers.pop_back();
5845 if (!IsFunctionDecl)
5851 ParseFunctionDeclarator(D, attrs, T, IsAmbiguous);
5852 PrototypeScope.Exit();
5853 }
else if (Tok.
is(tok::l_square)) {
5854 ParseBracketDeclarator(D);
5861 void Parser::ParseDecompositionDeclarator(
Declarator &D) {
5862 assert(Tok.
is(tok::l_square));
5868 if (!(
NextToken().is(tok::identifier) &&
5869 GetLookAheadToken(2).
isOneOf(tok::comma, tok::r_square)) &&
5871 GetLookAheadToken(2).isOneOf(tok::equal, tok::l_brace)))
5872 return ParseMisplacedBracketDeclarator(D);
5878 while (Tok.
isNot(tok::r_square)) {
5879 if (!Bindings.empty()) {
5880 if (Tok.
is(tok::comma))
5883 if (Tok.
is(tok::identifier)) {
5885 Diag(EndLoc, diag::err_expected)
5888 Diag(Tok, diag::err_expected_comma_or_rsquare);
5891 SkipUntil(tok::r_square, tok::comma, tok::identifier,
5893 if (Tok.
is(tok::comma))
5895 else if (Tok.
isNot(tok::identifier))
5900 if (Tok.
isNot(tok::identifier)) {
5901 Diag(Tok, diag::err_expected) << tok::identifier;
5909 if (Tok.
isNot(tok::r_square))
5915 if (Bindings.empty())
5938 void Parser::ParseParenDeclarator(
Declarator &D) {
5942 assert(!D.
isPastIdentifier() &&
"Should be called before passing identifier");
5955 bool RequiresArg =
false;
5956 if (Tok.
is(tok::kw___attribute)) {
5957 ParseGNUAttributes(attrs);
5965 ParseMicrosoftTypeAttributes(attrs);
5968 if (Tok.
is(tok::kw___pascal))
5969 ParseBorlandTypeAttributes(attrs);
5981 }
else if (Tok.
is(tok::r_paren) ||
5984 isDeclarationSpecifier() ||
5985 isCXX11AttributeSpecifier()) {
6003 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
6014 DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, D);
6027 ParseScope PrototypeScope(
this,
6031 ParseFunctionDeclarator(D, attrs, T,
false, RequiresArg);
6032 PrototypeScope.Exit();
6054 void Parser::ParseFunctionDeclarator(
Declarator &D,
6059 assert(
getCurScope()->isFunctionPrototypeScope() &&
6060 "Should call from a Function scope");
6066 bool HasProto =
false;
6073 bool RefQualifierIsLValueRef =
true;
6081 ParsedAttributesWithRange FnAttrs(AttrFactory);
6090 StartLoc = LParenLoc;
6092 if (isFunctionDeclaratorIdentifierList()) {
6094 Diag(Tok, diag::err_argument_required_after_attribute);
6096 ParseFunctionDeclaratorIdentifierList(D, ParamInfo);
6100 LocalEndLoc = RParenLoc;
6105 MaybeParseCXX11Attributes(FnAttrs);
6106 ProhibitAttributes(FnAttrs);
6108 if (Tok.
isNot(tok::r_paren))
6109 ParseParameterDeclarationClause(D, FirstArgAttrs, ParamInfo,
6111 else if (RequiresArg)
6112 Diag(Tok, diag::err_argument_required_after_attribute);
6114 HasProto = ParamInfo.size() ||
getLangOpts().CPlusPlus
6120 LocalEndLoc = RParenLoc;
6129 ParseTypeQualifierListOpt(DS, AR_NoAttributesParsed,
6132 llvm::function_ref<
void()>([&]() {
6133 Actions.CodeCompleteFunctionQualifiers(DS, D);
6140 if (ParseRefQualifier(RefQualifierIsLValueRef, RefQualifierLoc))
6141 EndLoc = RefQualifierLoc;
6150 bool IsCXX11MemberFunction =
6157 Actions.CurContext->isRecord());
6164 Actions, dyn_cast<CXXRecordDecl>(Actions.CurContext), Q,
6165 IsCXX11MemberFunction);
6170 if (Delayed && Actions.isLibstdcxxEagerExceptionSpecHack(D) &&
6171 GetLookAheadToken(0).is(tok::kw_noexcept) &&
6172 GetLookAheadToken(1).is(tok::l_paren) &&
6173 GetLookAheadToken(2).is(tok::kw_noexcept) &&
6174 GetLookAheadToken(3).is(tok::l_paren) &&
6175 GetLookAheadToken(4).is(tok::identifier) &&
6176 GetLookAheadToken(4).getIdentifierInfo()->isStr(
"swap")) {
6187 ESpecType = tryParseExceptionSpecification(Delayed,
6190 DynamicExceptionRanges,
6192 ExceptionSpecTokens);
6194 EndLoc = ESpecRange.
getEnd();
6198 MaybeParseCXX11Attributes(FnAttrs);
6201 LocalEndLoc = EndLoc;
6203 Diag(Tok, diag::warn_cxx98_compat_trailing_return_type);
6208 TrailingReturnType =
6212 }
else if (standardAttributesAllowed()) {
6213 MaybeParseCXX11Attributes(FnAttrs);
6226 if (!ND || isa<ParmVarDecl>(ND))
6228 DeclsInPrototype.push_back(ND);
6234 HasProto, IsAmbiguous, LParenLoc, ParamInfo.data(),
6235 ParamInfo.size(), EllipsisLoc, RParenLoc,
6236 RefQualifierIsLValueRef, RefQualifierLoc,
6238 ESpecType, ESpecRange, DynamicExceptions.data(),
6239 DynamicExceptionRanges.data(), DynamicExceptions.size(),
6240 NoexceptExpr.
isUsable() ? NoexceptExpr.
get() :
nullptr,
6241 ExceptionSpecTokens, DeclsInPrototype, StartLoc,
6242 LocalEndLoc, D, TrailingReturnType, &DS),
6243 std::move(FnAttrs), EndLoc);
6248 bool Parser::ParseRefQualifier(
bool &RefQualifierIsLValueRef,
6250 if (Tok.
isOneOf(tok::amp, tok::ampamp)) {
6252 diag::warn_cxx98_compat_ref_qualifier :
6253 diag::ext_ref_qualifier);
6255 RefQualifierIsLValueRef = Tok.
is(tok::amp);
6267 bool Parser::isFunctionDeclaratorIdentifierList() {
6269 && Tok.
is(tok::identifier)
6270 && !TryAltiVecVectorToken()
6299 void Parser::ParseFunctionDeclaratorIdentifierList(
6307 Diag(Tok, diag::ext_ident_list_in_param);
6310 llvm::SmallSet<const IdentifierInfo*, 16> ParamsSoFar;
6314 if (Tok.
isNot(tok::identifier)) {
6315 Diag(Tok, diag::err_expected) << tok::identifier;
6326 Diag(Tok, diag::err_unexpected_typedef_ident) << ParmII;
6329 if (!ParamsSoFar.insert(ParmII).second) {
6330 Diag(Tok, diag::err_param_redefinition) << ParmII;
6375 void Parser::ParseParameterDeclarationClause(
6405 ParseDeclarationSpecifiers(DS);
6415 ParseDeclarator(ParmDeclarator);
6418 MaybeParseGNUAttributes(ParmDeclarator);
6425 std::unique_ptr<CachedTokens> DefArgToks;
6429 if (DS.
isEmpty() && ParmDeclarator.getIdentifier() ==
nullptr &&
6430 ParmDeclarator.getNumTypeObjects() == 0) {
6432 Diag(DSStart, diag::err_missing_param);
6439 if (Tok.
is(tok::ellipsis) &&
6441 (!ParmDeclarator.getEllipsisLoc().isValid() &&
6442 !Actions.isUnexpandedParameterPackPermitted())) &&
6443 Actions.containsUnexpandedParameterPacks(ParmDeclarator))
6444 DiagnoseMisplacedEllipsisInDeclarator(
ConsumeToken(), ParmDeclarator);
6448 Decl *Param = Actions.ActOnParamDeclarator(
getCurScope(), ParmDeclarator);
6453 if (Tok.
is(tok::equal)) {
6464 if (!ConsumeAndStoreInitializer(*DefArgToks, CIK_DefaultArgument)) {
6466 Actions.ActOnParamDefaultArgumentError(Param, EqualLoc);
6468 Actions.ActOnParamUnparsedDefaultArgument(Param, EqualLoc,
6484 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
6485 DefArgResult = ParseBraceInitializer();
6488 DefArgResult = Actions.CorrectDelayedTyposInExpr(DefArgResult);
6490 Actions.ActOnParamDefaultArgumentError(Param, EqualLoc);
6494 Actions.ActOnParamDefaultArgument(Param, EqualLoc,
6495 DefArgResult.
get());
6501 ParmDeclarator.getIdentifierLoc(),
6502 Param, std::move(DefArgToks)));
6509 Diag(EllipsisLoc, diag::err_missing_comma_before_ellipsis)
6511 }
else if (ParmDeclarator.getEllipsisLoc().isValid() ||
6512 Actions.containsUnexpandedParameterPacks(ParmDeclarator)) {
6516 Diag(EllipsisLoc, diag::warn_misplaced_ellipsis_vararg)
6517 << ParmEllipsis.
isValid() << ParmEllipsis;
6520 diag::note_misplaced_ellipsis_vararg_existing_ellipsis);
6522 Diag(ParmDeclarator.getIdentifierLoc(),
6523 diag::note_misplaced_ellipsis_vararg_add_ellipsis)
6526 << !ParmDeclarator.hasName();
6528 Diag(EllipsisLoc, diag::note_misplaced_ellipsis_vararg_add_comma)
6547 void Parser::ParseBracketDeclarator(
Declarator &D) {
6548 if (CheckProhibitedCXX11Attribute())
6556 if (Tok.
getKind() == tok::r_square) {
6559 MaybeParseCXX11Attributes(attrs);
6567 }
else if (Tok.
getKind() == tok::numeric_constant &&
6568 GetLookAheadToken(1).is(tok::r_square)) {
6575 MaybeParseCXX11Attributes(attrs);
6583 }
else if (Tok.
getKind() == tok::code_completion) {
6584 Actions.CodeCompleteBracketDeclarator(
getCurScope());
6585 return cutOffParsing();
6595 ParseTypeQualifierListOpt(DS, AR_CXX11AttributesParsed);
6603 bool isStar =
false;
6610 if (Tok.
is(tok::star) && GetLookAheadToken(1).is(tok::r_square)) {
6614 Diag(StaticLoc, diag::err_unspecified_vla_size_with_static);
6618 }
else if (Tok.
isNot(tok::r_square)) {
6636 Diag(StaticLoc, diag::err_unspecified_size_with_static);
6662 void Parser::ParseMisplacedBracketDeclarator(
Declarator &D) {
6663 assert(Tok.
is(tok::l_square) &&
"Missing opening bracket");
6669 while (Tok.
is(tok::l_square)) {
6670 ParseBracketDeclarator(TempDeclarator);
6676 if (Tok.
is(tok::semi))
6682 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
6687 if (TempDeclarator.getNumTypeObjects() == 0)
6691 bool NeedParens =
false;
6716 for (
unsigned i = 0, e = TempDeclarator.getNumTypeObjects(); i < e; ++i) {
6729 SourceRange BracketRange(StartBracketLoc, EndBracketLoc);
6733 Diag(EndLoc, diag::err_brackets_go_after_unqualified_id)
6741 Diag(EndLoc, diag::err_brackets_go_after_unqualified_id)
6754 void Parser::ParseTypeofSpecifier(
DeclSpec &DS) {
6755 assert(Tok.
is(tok::kw_typeof) &&
"Not a typeof specifier");
6759 const bool hasParens = Tok.
is(tok::l_paren);
6768 ExprResult Operand = Actions.CorrectDelayedTyposInExpr(
6769 ParseExprAfterUnaryExprOrTypeTrait(OpTok, isCastExpr, CastTy, CastRange));
6785 const char *PrevSpec =
nullptr;
6790 Actions.getASTContext().getPrintingPolicy()))
6791 Diag(StartLoc, DiagID) << PrevSpec;
6802 Operand = Actions.HandleExprEvaluationContextForTypeof(Operand.
get());
6808 const char *PrevSpec =
nullptr;
6812 DiagID, Operand.
get(),
6813 Actions.getASTContext().getPrintingPolicy()))
6814 Diag(StartLoc, DiagID) << PrevSpec;
6820 void Parser::ParseAtomicSpecifier(
DeclSpec &DS) {
6821 assert(Tok.
is(tok::kw__Atomic) &&
NextToken().
is(tok::l_paren) &&
6822 "Not an atomic specifier");
6844 const char *PrevSpec =
nullptr;
6847 DiagID, Result.
get(),
6848 Actions.getASTContext().getPrintingPolicy()))
6849 Diag(StartLoc, DiagID) << PrevSpec;
6854 bool Parser::TryAltiVecVectorTokenOutOfLine() {
6857 default:
return false;
6860 case tok::kw_signed:
6861 case tok::kw_unsigned:
6866 case tok::kw_double:
6868 case tok::kw___bool:
6869 case tok::kw___pixel:
6870 Tok.
setKind(tok::kw___vector);
6872 case tok::identifier:
6874 Tok.
setKind(tok::kw___vector);
6878 Tok.
setKind(tok::kw___vector);
6886 const char *&PrevSpec,
unsigned &DiagID,
6888 const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy();
6894 case tok::kw_signed:
6895 case tok::kw_unsigned:
6900 case tok::kw_double:
6902 case tok::kw___bool:
6903 case tok::kw___pixel:
6906 case tok::identifier:
void ClearFunctionSpecs()
Defines the clang::ASTContext interface.
static bool isAttributeLateParsed(const IdentifierInfo &II)
isAttributeLateParsed - Return true if the attribute has arguments that require late parsing...
static Qualifiers fromCVRUMask(unsigned CVRU)
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
no exception specification
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
A (possibly-)qualified type.
This is a scope that corresponds to the parameters within a function prototype.
SourceLocation getEndOfPreviousToken()
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
SourceRange getSourceRange() const LLVM_READONLY
Return the source range that covers this unqualified-id.
static const TSS TSS_unsigned
SourceLocation StartLocation
The location of the first token that describes this unqualified-id, which will be the location of the...
Code completion occurs within a class, struct, or union.
const DeclaratorChunk & getTypeObject(unsigned i) const
Return the specified TypeInfo from this declarator.
bool SetTypeQual(TQ T, SourceLocation Loc)
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc...
IdentifierInfo * Name
FIXME: Temporarily stores the name of a specialization.
static const TST TST_wchar
llvm::PointerUnion< Expr *, IdentifierLoc * > ArgsUnion
A union of the various pointer types that can be passed to an ParsedAttr as an argument.
static bool attributeHasVariadicIdentifierArg(const IdentifierInfo &II)
Determine whether the given attribute has a variadic identifier argument.
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)) {...
bool isEmpty() const
No scope specifier.
static const TST TST_typeofExpr
static const TST TST_char16
Decl - This represents one declaration (or definition), e.g.
RAII object used to inform the actions that we're currently parsing a declaration.
bool SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Is the identifier known as a __declspec-style attribute?
A RAII object used to temporarily suppress access-like checking.
Defines the C++ template declaration subclasses.
The base class of the type hierarchy.
bool TryAnnotateCXXScopeToken(bool EnteringContext=false)
TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only annotates C++ scope specifiers and ...
SourceLocation getCloseLocation() const
This indicates that the scope corresponds to a function, which means that labels are set here...
SourceLocation getBeginLoc() const LLVM_READONLY
One instance of this struct is used for each type in a declarator that is parsed. ...
Declaration of a variable template.
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
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 const char * getSpecifierName(DeclSpec::TST T, const PrintingPolicy &Policy)
Turn a type-specifier-type into a string like "_Bool" or "union".
SourceLocation getEndLoc() const LLVM_READONLY
SourceLocation getEndLoc() const LLVM_READONLY
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
TemplateNameKind Kind
The kind of template that Template refers to.
void ActOnExitFunctionContext()
Wrapper for void* pointer.
Parser - This implements a parser for the C family of languages.
bool SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
TSCS getThreadStorageClassSpec() const
void SetIdentifier(IdentifierInfo *Id, SourceLocation IdLoc)
Set the name of this declarator to be the given identifier.
static IdentifierLoc * create(ASTContext &Ctx, SourceLocation Loc, IdentifierInfo *Ident)
SourceLocation getEndLoc() const
NameClassificationKind getKind() const
RAII object that enters a new expression evaluation context.
void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record)
Information about one declarator, including the parsed type information and the identifier.
bool setFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
void setTypeofParensRange(SourceRange range)
unsigned getParsedSpecifiers() const
Return a bitmask of which flavors of specifiers this DeclSpec includes.
static const TST TST_interface
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
static const TST TST_char
bool hasTypeSpecifier() const
Return true if any type-specifier has been found.
Describes how types, statements, expressions, and declarations should be printed. ...
Code completion occurs within an Objective-C implementation or category implementation.
RAII object that makes sure paren/bracket/brace count is correct after declaration/statement parsing...
friend class ObjCDeclContextSwitch
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
Represents a parameter to a function.
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed...
tok::TokenKind getKind() 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 ...
bool mayOmitIdentifier() const
mayOmitIdentifier - Return true if the identifier is either optional or not allowed.
The collection of all-type qualifiers we support.
Information about a template-id annotation token.
Base wrapper for a particular "section" of type source info.
SourceLocation getFriendSpecLoc() const
Represents a struct/union/class.
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
bool TryConsumeToken(tok::TokenKind Expected)
One of these records is kept for each identifier that is lexed.
static const TST TST_decimal32
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
static bool attributeHasIdentifierArg(const IdentifierInfo &II)
Determine whether the given attribute has an identifier argument.
static const TST TST_char8
SourceLocation getTypeSpecTypeLoc() const
static const TST TST_class
DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType=nullptr)
static const TST TST_double
Code completion occurs following one or more template headers within a class.
bool setFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
The iterator over UnresolvedSets.
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Token - This structure provides full information about a lexed token.
static const TST TST_enum
void setKind(tok::TokenKind K)
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ...
void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs)
ActOnFinishDelayedAttribute - Invoked when we have finished parsing an attribute for which parsing is...
bool hasTagDefinition() const
void ClearStorageClassSpecs()
static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc, SourceLocation ConstQualLoc, SourceLocation VolatileQualLoc, SourceLocation RestrictQualLoc, SourceLocation AtomicQualLoc, SourceLocation UnalignedQualLoc)
Return a DeclaratorChunk for a pointer.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
void * getAsOpaquePtr() const
static const TST TST_accum
bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
bool isInvalidType() const
Code completion occurs at top-level or namespace context.
The controlling scope in a if/switch/while/for statement.
bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const
Return true if we have an ObjC keyword identifier.
This is a scope that corresponds to a block/closure object.
bool isFunctionDeclaratorAFunctionDeclaration() const
Return true if a function declarator at this position would be a function declaration.
static ParsedType getTypeAnnotation(const Token &Tok)
getTypeAnnotation - Read a parsed type out of an annotation token.
Represents the results of name lookup.
void setExtension(bool Val=true)
This scope corresponds to an enum.
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
Return the 'spelling' of the token at the given location; does not go up to the spelling location or ...
tok::TokenKind getTokenID() const
If this is a source-language token (e.g.
static StringRef normalizeAttrName(StringRef Name)
Normalizes an attribute name by dropping prefixed and suffixed __.
void SetRangeBegin(SourceLocation Loc)
SetRangeBegin - Set the start of the source range to Loc, unless it's invalid.
Code completion occurs following one or more template headers.
bool isTypeSpecPipe() const
bool setFunctionSpecForceInline(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef< Decl *> Group)
BuildDeclaratorGroup - convert a list of declarations into a declaration group, performing any necess...
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, llvm::function_ref< ExprResult(Expr *)> Filter=[](Expr *E) -> ExprResult { return E;})
Process any TypoExprs in the given Expr and its children, generating diagnostics as appropriate and r...
SourceRange getRange() const
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
const clang::PrintingPolicy & getPrintingPolicy() const
MutableArrayRef< TemplateParameterList * > MultiTemplateParamsArg
bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
bool hasAttributes() const
Scope - A scope is a transient data structure that is used while parsing the program.
Represents information about a change in availability for an entity, which is part of the encoding of...
Represents a C++ nested-name-specifier or a global scope specifier.
int hasAttribute(AttrSyntax Syntax, const IdentifierInfo *Scope, const IdentifierInfo *Attr, const TargetInfo &Target, const LangOptions &LangOpts)
Return the version number associated with the attribute if we recognize and implement the attribute s...
bool SetTypePipe(bool isPipe, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
bool setFunctionSpecNoreturn(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type...
SourceLocation getConstSpecLoc() const
const CXXScopeSpec & getCXXScopeSpec() const
getCXXScopeSpec - Return the C++ scope specifier (global scope or nested-name-specifier) that is part...
bool isCPlusPlusKeyword(const LangOptions &LangOpts) const
Return true if this token is a C++ keyword in the specified language.
void addAtEnd(ParsedAttr *newAttr)
static bool VersionNumberSeparator(const char Separator)
SourceRange getSourceRange() const LLVM_READONLY
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
VersionTuple getOpenCLVersionTuple() const
Return the OpenCL C or C++ version as a VersionTuple.
VersionTuple Version
The version number at which the change occurred.
IdentifierInfo * getIdentifier() const
static const TST TST_float
Code completion occurs within a sequence of declaration specifiers within a function, method, or block.
void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl)
ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an initializer for the declaratio...
unsigned getFlags() const
getFlags - Return the flags for this scope.
Provides definitions for the various language-specific address spaces.
static const TSW TSW_long
enum clang::DeclaratorChunk::@215 Kind
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(), DeclSpec *MethodQualifiers=nullptr)
DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
SourceLocation getUnalignedSpecLoc() const
ParsedAttr * addNewTypeTagForDatatype(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *argumentKind, ParsedType matchingCType, bool layoutCompatible, bool mustBeNull, ParsedAttr::Syntax syntax)
Add type_tag_for_datatype attribute.
void ClearConstexprSpec()
bool mayBeFollowedByCXXDirectInit() const
mayBeFollowedByCXXDirectInit - Return true if the declarator can be followed by a C++ direct initiali...
A class for parsing a declarator.
bool isPastIdentifier() const
isPastIdentifier - Return true if we have parsed beyond the point where the name would appear...
void SetRangeStart(SourceLocation Loc)
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
void ActOnReenterCXXMethodParameter(Scope *S, ParmVarDecl *Param)
This is used to implement the constant expression evaluation part of the attribute enable_if extensio...
TST getTypeSpecType() const
The current expression is potentially evaluated, but any declarations referenced inside that expressi...
ParsedAttr * addNewPropertyAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierInfo *getterId, IdentifierInfo *setterId, ParsedAttr::Syntax syntaxUsed)
Add microsoft __delspec(property) attribute.
Decl * ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, RecordDecl *&AnonRecord)
ParsedFreeStandingDeclSpec - This method is invoked when a declspec with no declarator (e...
void setDecompositionBindings(SourceLocation LSquareLoc, ArrayRef< DecompositionDeclarator::Binding > Bindings, SourceLocation RSquareLoc)
Set the decomposition bindings for this declarator.
Represents a character-granular source range.
bool isExplicitSpecified() const
void SkipMalformedDecl()
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a s...
bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, ParsedType ObjectType, SourceLocation *TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
static DeclaratorChunk getPipe(unsigned TypeQuals, SourceLocation Loc)
Return a DeclaratorChunk for a block.
TypeResult ActOnTypeName(Scope *S, Declarator &D)
bool isTypeAltiVecVector() const
void setEofData(const void *D)
static bool isPipeDeclerator(const Declarator &D)
SourceLocation getVolatileSpecLoc() const
SourceLocation getThreadStorageClassSpecLoc() const
static constexpr bool isOneOf()
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
void setAsmLabel(Expr *E)
DeclContext * getDeclContext()
bool isConstexprSpecified() const
static const TST TST_decimal64
This is a compound statement scope.
SourceLocation getStorageClassSpecLoc() const
UnqualifiedIdKind getKind() const
Determine what kind of name we have.
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7)...
void UpdateTypeRep(ParsedType Rep)
SourceLocation KeywordLoc
The location of the keyword indicating the kind of change.
A class for parsing a field declarator.
bool isValid() const
Determine whether this availability change is valid.
SourceLocation Loc
Loc - The place where this type was defined.
static SourceLocation getMissingDeclaratorIdLoc(Declarator &D, SourceLocation Loc)
void setEllipsisLoc(SourceLocation EL)
SourceLocation getEnd() const
bool SetTypeSpecSign(TSS S, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
SourceLocation getOpenLocation() const
static const TST TST_half
bool isFriendSpecified() const
Wraps an identifier and optional source location for the identifier.
void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl)
ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an initializer for the declaration ...
The result type of a method or function.
SourceRange VersionRange
The source range covering the version number.
static const TSW TSW_short
PrettyDeclStackTraceEntry - If a crash occurs in the parser while parsing something related to a decl...
bool isFirstDeclarator() const
const LangOptions & getLangOpts() const
bool SetTypeSpecWidth(TSW 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 ...
This is a scope that corresponds to the parameters within a function prototype for a function declara...
bool hasGroupingParens() const
static const TST TST_char32
static const TST TST_fract
A class for parsing a DeclSpec.
bool isTemplateDecl() const
returns true if this declaration is a template
static DeclaratorChunk getParen(SourceLocation LParenLoc, SourceLocation RParenLoc)
Return a DeclaratorChunk for a paren.
Stop skipping at semicolon.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc, bool lvalue)
Return a DeclaratorChunk for a reference.
SCS getStorageClassSpec() const
static const TST TST_float16
bool hasName() const
hasName - Whether this declarator has a name, which might be an identifier (accessible via getIdentif...
Encodes a location in the source.
void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record)
bool isTypeSpecOwned() const
static const TST TST_auto_type
bool TryAnnotateTypeOrScopeToken()
TryAnnotateTypeOrScopeToken - If the current token position is on a typename (possibly qualified in C...
UnqualifiedId & getName()
Retrieve the name specified by this declarator.
void FinalizeDeclaration(Decl *D)
FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform any semantic actions neces...
static void SetupFixedPointError(const LangOptions &LangOpts, const char *&PrevSpec, unsigned &DiagID, bool &isInvalid)
Syntax
The style used to specify an attribute.
Represents the declaration of a struct/union/class/enum.
void ExitScope()
ExitScope - Pop a scope off the scope stack.
This is a scope that corresponds to the Objective-C @catch statement.
ASTContext & getASTContext() const LLVM_READONLY
SourceLocation getEndLoc() const LLVM_READONLY
static const TST TST_union
IdentifierInfo * getIdentifierInfo() const
ParsedAttr - Represents a syntactic attribute.
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 TSS TSS_signed
ExtensionRAIIObject - This saves the state of extension warnings when constructed and disables them...
void setGroupingParens(bool flag)
ParsedAttr * addNew(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ArgsUnion *args, unsigned numArgs, ParsedAttr::Syntax syntax, SourceLocation ellipsisLoc=SourceLocation())
Add attribute with expression arguments.
void EnterScope(unsigned ScopeFlags)
EnterScope - Start a new scope.
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
const void * getEofData() const
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
static bool isPtrOperatorToken(tok::TokenKind Kind, const LangOptions &Lang, DeclaratorContext TheContext)
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
void remove(ParsedAttr *ToBeRemoved)
Decl * getRepAsDecl() const
static const TST TST_typeofType
Used for C's _Alignof and C++'s alignof.
Scope * getCurScope() const
bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
SourceLocation getInlineSpecLoc() const
static DeclaratorChunk getArray(unsigned TypeQuals, bool isStatic, bool isStar, Expr *NumElts, SourceLocation LBLoc, SourceLocation RBLoc)
Return a DeclaratorChunk for an array.
bool isInvalid() const
An error occurred during parsing of the scope specifier.
SourceLocation getModulePrivateSpecLoc() const
StringRef getName() const
Return the actual identifier string.
The scope of a struct/union/class definition.
SourceRange getSourceRange() const LLVM_READONLY
Get the source range that spans this declarator.
bool isNot(tok::TokenKind K) const
void ActOnReenterFunctionContext(Scope *S, Decl *D)
Push the parameters of D, which must be a function, into scope.
TSW getTypeSpecWidth() const
ParserCompletionContext
Describes the context in which code completion occurs.
bool setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
static bool isInvalid(LocType Loc, bool *Invalid)
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
bool expectAndConsume(unsigned DiagID=diag::err_expected, const char *Msg="", tok::TokenKind SkipToTok=tok::unknown)
static const TST TST_auto
static const TST TST_void
CXXScopeSpec SS
The nested-name-specifier that precedes the template name.
bool isFunctionOrFunctionTemplate() const
Whether this declaration is a function or function template.
static const TST TST_int128
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
SourceLocation getPipeLoc() const
This is a scope that corresponds to the template parameters of a C++ template.
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
The name refers to a template whose specialization produces a type.
static const TST TST_unspecified
unsigned getLength() const
bool isValid() const
A scope specifier is present, and it refers to a real scope.
LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
const TargetInfo & getTargetInfo() const
static const TST TST_decimal128
unsigned getTypeQualifiers() const
getTypeQualifiers - Return a set of TQs.
void takeAttributesFrom(ParsedAttributes &attrs)
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
static const TSCS TSCS___thread
SourceLocation getVirtualSpecLoc() const
bool SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
static const TST TST_typename
void SetRangeEnd(SourceLocation Loc)
SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.
ExprResult ParseAssignmentExpression(TypeCastState isTypeCast=NotTypeCast)
Parse an expr that doesn't include (top-level) commas.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
void ActOnCXXForRangeDecl(Decl *D)
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.
void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc)
AddTypeInfo - Add a chunk to this declarator.
CXXScopeSpec & getTypeSpecScope()
This is a scope that can contain a declaration.
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
SourceLocation getIdentifierLoc() const
bool isSet() const
Deprecated.
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
ParsedAttr * addNewTypeAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ParsedType typeArg, ParsedAttr::Syntax syntaxUsed)
Add an attribute with a single type argument.
void setInvalidType(bool Val=true)
ExprResult ParseConstantExpression(TypeCastState isTypeCast=NotTypeCast)
static DeclaratorChunk getBlockPointer(unsigned TypeQuals, SourceLocation Loc)
Return a DeclaratorChunk for a block.
static bool attributeParsedArgsUnevaluated(const IdentifierInfo &II)
Determine whether the given attribute requires parsing its arguments in an unevaluated context or not...
Captures information about "declaration specifiers".
SourceLocation getRestrictSpecLoc() const
static bool isValidAfterIdentifierInDeclarator(const Token &T)
isValidAfterIdentifierInDeclaratorAfterDeclSpec - Return true if the specified token is valid after t...
DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, ArrayRef< Decl *> Group)
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
static const TSCS TSCS_thread_local
SourceLocation getEllipsisLoc() const
bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
bool mayHaveIdentifier() const
mayHaveIdentifier - Return true if the identifier is either optional or required. ...
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
static const TST TST_float128
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
static const TST TST_bool
bool isVirtualSpecified() const
Decl * getObjCDeclContext() const
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
A template-id, e.g., f<int>.
void Finish(Sema &S, const PrintingPolicy &Policy)
Finish - This does final analysis of the declspec, issuing diagnostics for things like "_Imaginary" (...
StringLiteral - This represents a string literal expression, e.g.
Defines the clang::TargetInfo interface.
bool isInlineSpecified() const
void ExtendWithDeclSpec(const DeclSpec &DS)
ExtendWithDeclSpec - Extend the declarator source range to include the given declspec, unless its location is invalid.
SourceLocation getAtomicSpecLoc() const
static const TSW TSW_longlong
static Decl::Kind getKind(const Decl *D)
SourceLocation getExplicitSpecLoc() const
SourceLocation getConstexprSpecLoc() const
static bool attributeIsTypeArgAttr(const IdentifierInfo &II)
Determine whether the given attribute parses a type argument.
static const TST TST_atomic
bool isEmpty() const
isEmpty - Return true if this declaration specifier is completely empty: no tokens were parsed in the...
static const TST TST_struct
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
ParamInfo - An array of paraminfo objects is allocated whenever a function declarator is parsed...
DeclaratorContext getContext() const
void setLocation(SourceLocation L)
A trivial tuple used to represent a source range.
bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
This represents a decl that may have a name.
__ptr16, alignas(...), etc.
SourceLocation EndLocation
The location of the last token that describes this unqualified-id.
static const TSCS TSCS__Thread_local
Callback handler that receives notifications when performing code completion within the preprocessor...
void * getAnnotationValue() const
bool isFirstDeclarationOfMember()
Returns true if this declares a real member and not a friend.
void SetRangeEnd(SourceLocation Loc)
void addAttributes(ParsedAttributesView &AL)
Concatenates two attribute lists.
SourceLocation getBegin() const
ParsedAttributes - A collection of parsed attributes.
void setCommaLoc(SourceLocation CL)
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeNameContext, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName type-name: [C99 6.7.6] specifier-qualifier-list abstract-declarator[opt].
ParsedAttributes & getAttributes()
SourceLocation getLocation() const
void startToken()
Reset all flags to cleared.
Decl * ActOnDeclarator(Scope *S, Declarator &D)
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
static DeclaratorChunk getMemberPointer(const CXXScopeSpec &SS, unsigned TypeQuals, SourceLocation Loc)
bool setFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Stop skipping at specified token, but don't skip the token itself.
unsigned ActOnReenterTemplateScope(Scope *S, Decl *Template)
SourceLocation getEndLoc() const