27 #include "llvm/ADT/SmallSet.h"
28 #include "llvm/ADT/SmallString.h"
29 #include "llvm/ADT/StringSwitch.h"
30 using namespace clang;
46 DeclSpecContext DSC = getDeclSpecContextFromDeclaratorContext(Context);
47 if (DSC == DSC_normal)
48 DSC = DSC_type_specifier;
54 ParseSpecifierQualifierList(DS, AS, DSC);
60 ParseDeclarator(DeclaratorInfo);
74 #define CLANG_ATTR_LATE_PARSED_LIST
75 return llvm::StringSwitch<bool>(II.
getName())
76 #include
"clang/Parse/AttrParserStringSwitches.inc"
78 #undef CLANG_ATTR_LATE_PARSED_LIST
124 LateParsedAttrList *LateAttrs,
126 assert(Tok.
is(tok::kw___attribute) &&
"Not a GNU attribute list!");
128 while (Tok.
is(tok::kw___attribute)) {
130 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
135 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
"(")) {
154 if (Tok.
isNot(tok::l_paren)) {
155 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
162 ParseGNUAttributeArgs(AttrName, AttrNameLoc, attrs, endLoc,
nullptr,
168 LateParsedAttribute *LA =
169 new LateParsedAttribute(
this, *AttrName, AttrNameLoc);
170 LateAttrs->push_back(LA);
174 if (!ClassStack.empty() && !LateAttrs->parseSoon())
175 getCurrentClass().LateParsedDeclarations.push_back(LA);
178 ConsumeAndStoreUntil(tok::r_paren, LA->Toks,
true,
false);
183 LA->Toks.push_back(Eof);
186 if (ExpectAndConsume(tok::r_paren))
189 if (ExpectAndConsume(tok::r_paren))
198 if (Name.size() >= 4 && Name.startswith(
"__") && Name.endswith(
"__"))
199 Name = Name.drop_front(2).drop_back(2);
205 #define CLANG_ATTR_IDENTIFIER_ARG_LIST
207 #include "clang/Parse/AttrParserStringSwitches.inc"
209 #undef CLANG_ATTR_IDENTIFIER_ARG_LIST
214 #define CLANG_ATTR_TYPE_ARG_LIST
216 #include "clang/Parse/AttrParserStringSwitches.inc"
218 #undef CLANG_ATTR_TYPE_ARG_LIST
224 #define CLANG_ATTR_ARG_CONTEXT_LIST
226 #include "clang/Parse/AttrParserStringSwitches.inc"
228 #undef CLANG_ATTR_ARG_CONTEXT_LIST
232 assert(Tok.
is(tok::identifier) &&
"expected an identifier");
248 Parens.consumeOpen();
251 if (Tok.
isNot(tok::r_paren))
254 if (Parens.consumeClose())
262 SourceRange(AttrNameLoc, Parens.getCloseLocation()),
263 ScopeName, ScopeLoc, T.
get(), Syntax);
266 ScopeName, ScopeLoc,
nullptr, 0, Syntax);
269 unsigned Parser::ParseAttributeArgsCommon(
277 if (Tok.
is(tok::identifier)) {
288 IsIdentifierArg = Next.
isOneOf(tok::r_paren, tok::comma);
292 ArgExprs.push_back(ParseIdentifierLoc());
295 if (!ArgExprs.empty() ? Tok.
is(tok::comma) : Tok.
isNot(tok::r_paren)) {
297 if (!ArgExprs.empty())
302 std::unique_ptr<EnterExpressionEvaluationContext> Unevaluated;
309 if (ArgExpr.isInvalid()) {
313 ArgExprs.push_back(ArgExpr.get());
319 if (!ExpectAndConsume(tok::r_paren)) {
322 ArgExprs.data(), ArgExprs.size(), Syntax);
328 return static_cast<unsigned>(ArgExprs.size());
342 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
347 if (AttrKind == AttributeList::AT_Availability) {
348 ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
351 }
else if (AttrKind == AttributeList::AT_ObjCBridgeRelated) {
352 ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
353 ScopeName, ScopeLoc, Syntax);
355 }
else if (AttrKind == AttributeList::AT_TypeTagForDatatype) {
356 ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
357 ScopeName, ScopeLoc, Syntax);
360 ParseAttributeWithTypeArg(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
367 std::unique_ptr<ParseScope> PrototypeScope;
374 for (
unsigned i = 0; i != FTI.
NumParams; ++i) {
380 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
399 if (AttrName->
getName() ==
"property") {
405 T.expectAndConsume(diag::err_expected_lparen_after,
414 bool HasInvalidAccessor =
false;
419 if (!Tok.
is(tok::identifier)) {
421 if (Tok.
is(tok::r_paren) && !HasInvalidAccessor &&
422 AccessorNames[AK_Put] ==
nullptr &&
423 AccessorNames[AK_Get] ==
nullptr) {
424 Diag(AttrNameLoc, diag::err_ms_property_no_getter_or_putter);
435 if (KindStr ==
"get") {
437 }
else if (KindStr ==
"put") {
441 }
else if (KindStr ==
"set") {
442 Diag(KindLoc, diag::err_ms_property_has_set_accessor)
449 Diag(KindLoc, diag::err_ms_property_missing_accessor_kind);
451 HasInvalidAccessor =
true;
452 goto next_property_accessor;
456 Diag(KindLoc, diag::err_ms_property_unknown_accessor);
457 HasInvalidAccessor =
true;
476 if (!Tok.
is(tok::identifier)) {
481 if (Kind == AK_Invalid) {
483 }
else if (AccessorNames[Kind] !=
nullptr) {
485 Diag(KindLoc, diag::err_ms_property_duplicate_accessor) << KindStr;
491 next_property_accessor:
497 if (Tok.
is(tok::r_paren))
500 Diag(Tok.
getLocation(), diag::err_ms_property_expected_comma_or_rparen);
505 if (!HasInvalidAccessor)
507 AccessorNames[AK_Get], AccessorNames[AK_Put],
510 return !HasInvalidAccessor;
514 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs,
nullptr,
nullptr,
521 Diag(OpenParenLoc, diag::err_attribute_requires_arguments) << AttrName;
537 "Incorrect language options for parsing __declspec");
538 assert(Tok.
is(tok::kw___declspec) &&
"Not a declspec!");
540 while (Tok.
is(tok::kw___declspec)) {
543 if (T.expectAndConsume(diag::err_expected_lparen_after,
"__declspec",
549 while (Tok.
isNot(tok::r_paren)) {
556 bool IsString = Tok.
getKind() == tok::string_literal;
557 if (!IsString && Tok.
getKind() != tok::identifier &&
558 Tok.
getKind() != tok::kw_restrict) {
559 Diag(Tok, diag::err_ms_declspec_type);
568 bool Invalid =
false;
569 StringRef Str = PP.
getSpelling(Tok, StrBuffer, &Invalid);
575 AttrNameLoc = ConsumeStringToken();
581 bool AttrHandled =
false;
584 if (Tok.
is(tok::l_paren))
585 AttrHandled = ParseMicrosoftDeclSpecArgs(AttrName, AttrNameLoc, Attrs);
586 else if (AttrName->
getName() ==
"property")
592 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
597 *End = T.getCloseLocation();
605 case tok::kw___fastcall:
606 case tok::kw___stdcall:
607 case tok::kw___thiscall:
608 case tok::kw___cdecl:
609 case tok::kw___vectorcall:
610 case tok::kw___ptr64:
612 case tok::kw___ptr32:
613 case tok::kw___unaligned:
615 case tok::kw___uptr: {
618 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
628 void Parser::DiagnoseAndSkipExtendedMicrosoftTypeAttributes() {
634 Diag(StartLoc, diag::warn_microsoft_qualifiers_ignored) << Range;
644 case tok::kw_volatile:
645 case tok::kw___fastcall:
646 case tok::kw___stdcall:
647 case tok::kw___thiscall:
648 case tok::kw___cdecl:
649 case tok::kw___vectorcall:
650 case tok::kw___ptr32:
651 case tok::kw___ptr64:
653 case tok::kw___unaligned:
666 while (Tok.
is(tok::kw___pascal)) {
669 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
676 while (Tok.
is(tok::kw___kernel)) {
679 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
687 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
695 case tok::kw__Nonnull:
696 case tok::kw__Nullable:
697 case tok::kw__Null_unspecified: {
701 Diag(AttrNameLoc, diag::ext_nullability)
703 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
714 return (Separator ==
'.' || Separator ==
'_');
726 if (!Tok.
is(tok::numeric_constant)) {
727 Diag(Tok, diag::err_expected_version);
739 const char *ThisTokBegin = &Buffer[0];
742 bool Invalid =
false;
743 unsigned ActualLength = PP.
getSpelling(Tok, ThisTokBegin, &Invalid);
748 unsigned AfterMajor = 0;
750 while (AfterMajor < ActualLength &&
isDigit(ThisTokBegin[AfterMajor])) {
751 Major = Major * 10 + ThisTokBegin[AfterMajor] -
'0';
755 if (AfterMajor == 0) {
756 Diag(Tok, diag::err_expected_version);
762 if (AfterMajor == ActualLength) {
767 Diag(Tok, diag::err_zero_version);
774 const char AfterMajorSeparator = ThisTokBegin[AfterMajor];
776 || (AfterMajor + 1 == ActualLength)) {
777 Diag(Tok, diag::err_expected_version);
784 unsigned AfterMinor = AfterMajor + 1;
786 while (AfterMinor < ActualLength &&
isDigit(ThisTokBegin[AfterMinor])) {
787 Minor = Minor * 10 + ThisTokBegin[AfterMinor] -
'0';
791 if (AfterMinor == ActualLength) {
795 if (Major == 0 && Minor == 0) {
796 Diag(Tok, diag::err_zero_version);
800 return VersionTuple(Major, Minor, (AfterMajorSeparator ==
'_'));
803 const char AfterMinorSeparator = ThisTokBegin[AfterMinor];
806 Diag(Tok, diag::err_expected_version);
813 if (AfterMajorSeparator != AfterMinorSeparator)
814 Diag(Tok, diag::warn_expected_consistent_version_separator);
817 unsigned AfterSubminor = AfterMinor + 1;
818 unsigned Subminor = 0;
819 while (AfterSubminor < ActualLength &&
isDigit(ThisTokBegin[AfterSubminor])) {
820 Subminor = Subminor * 10 + ThisTokBegin[AfterSubminor] -
'0';
824 if (AfterSubminor != ActualLength) {
825 Diag(Tok, diag::err_expected_version);
831 return VersionTuple(Major, Minor, Subminor, (AfterMajorSeparator ==
'_'));
853 void Parser::ParseAvailabilityAttribute(
IdentifierInfo &Availability,
860 enum { Introduced, Deprecated, Obsoleted,
Unknown };
866 if (T.consumeOpen()) {
867 Diag(Tok, diag::err_expected) << tok::l_paren;
872 if (Tok.
isNot(tok::identifier)) {
873 Diag(Tok, diag::err_availability_expected_platform);
880 if (ExpectAndConsume(tok::comma)) {
887 if (!Ident_introduced) {
898 if (Tok.
isNot(tok::identifier)) {
899 Diag(Tok, diag::err_availability_expected_change);
906 if (Keyword == Ident_unavailable) {
907 if (UnavailableLoc.
isValid()) {
908 Diag(KeywordLoc, diag::err_availability_redundant)
911 UnavailableLoc = KeywordLoc;
915 if (Tok.
isNot(tok::equal)) {
916 Diag(Tok, diag::err_expected_after) << Keyword << tok::equal;
921 if (Keyword == Ident_message) {
922 if (Tok.
isNot(tok::string_literal)) {
923 Diag(Tok, diag::err_expected_string_literal)
928 MessageExpr = ParseStringLiteralExpression();
931 cast_or_null<StringLiteral>(MessageExpr.
get())) {
932 if (MessageStringLiteral->getCharByteWidth() != 1) {
933 Diag(MessageStringLiteral->getSourceRange().getBegin(),
934 diag::err_expected_string_literal)
945 if ((Keyword == Ident_introduced || Keyword == Ident_deprecated) &&
946 Tok.
is(tok::identifier)) {
950 if (Keyword == Ident_introduced)
951 UnavailableLoc = KeywordLoc;
959 if (Version.
empty()) {
965 if (Keyword == Ident_introduced)
967 else if (Keyword == Ident_deprecated)
969 else if (Keyword == Ident_obsoleted)
975 if (!Changes[Index].KeywordLoc.
isInvalid()) {
976 Diag(KeywordLoc, diag::err_availability_redundant)
979 Changes[Index].VersionRange.
getEnd());
983 Changes[Index].
Version = Version;
986 Diag(KeywordLoc, diag::err_availability_unknown_change)
987 << Keyword << VersionRange;
993 if (T.consumeClose())
997 *endLoc = T.getCloseLocation();
1001 if (UnavailableLoc.
isValid()) {
1002 bool Complained =
false;
1003 for (
unsigned Index = Introduced; Index !=
Unknown; ++Index) {
1004 if (Changes[Index].KeywordLoc.
isValid()) {
1006 Diag(UnavailableLoc, diag::warn_availability_and_unavailable)
1008 Changes[Index].VersionRange.
getEnd());
1019 attrs.
addNew(&Availability,
1020 SourceRange(AvailabilityLoc, T.getCloseLocation()),
1021 ScopeName, ScopeLoc,
1023 Changes[Introduced],
1024 Changes[Deprecated],
1026 UnavailableLoc, MessageExpr.
get(),
1041 void Parser::ParseObjCBridgeRelatedAttribute(
IdentifierInfo &ObjCBridgeRelated,
1050 if (T.consumeOpen()) {
1051 Diag(Tok, diag::err_expected) << tok::l_paren;
1056 if (Tok.
isNot(tok::identifier)) {
1057 Diag(Tok, diag::err_objcbridge_related_expected_related_class);
1062 if (ExpectAndConsume(tok::comma)) {
1069 if (Tok.
is(tok::identifier)) {
1070 ClassMethod = ParseIdentifierLoc();
1072 Diag(Tok, diag::err_objcbridge_related_selector_name);
1078 if (Tok.
is(tok::colon))
1079 Diag(Tok, diag::err_objcbridge_related_selector_name);
1081 Diag(Tok, diag::err_expected) << tok::comma;
1088 if (Tok.
is(tok::identifier))
1089 InstanceMethod = ParseIdentifierLoc();
1090 else if (Tok.
isNot(tok::r_paren)) {
1091 Diag(Tok, diag::err_expected) << tok::r_paren;
1097 if (T.consumeClose())
1101 *endLoc = T.getCloseLocation();
1104 attrs.
addNew(&ObjCBridgeRelated,
1105 SourceRange(ObjCBridgeRelatedLoc, T.getCloseLocation()),
1106 ScopeName, ScopeLoc,
1116 void Parser::LateParsedDeclaration::ParseLexedAttributes() {}
1118 void Parser::LateParsedClass::ParseLexedAttributes() {
1119 Self->ParseLexedAttributes(*Class);
1122 void Parser::LateParsedAttribute::ParseLexedAttributes() {
1123 Self->ParseLexedAttribute(*
this,
true,
false);
1128 void Parser::ParseLexedAttributes(ParsingClass &Class) {
1131 bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope;
1134 if (HasTemplateScope)
1138 bool AlreadyHasClassScope = Class.TopLevelClass;
1140 ParseScope ClassScope(
this, ScopeFlags, !AlreadyHasClassScope);
1141 ParseScopeFlags ClassScopeFlags(
this, ScopeFlags, AlreadyHasClassScope);
1144 if (!AlreadyHasClassScope)
1146 Class.TagOrTemplate);
1147 if (!Class.LateParsedDeclarations.empty()) {
1148 for (
unsigned i = 0, ni = Class.LateParsedDeclarations.size(); i < ni; ++i){
1149 Class.LateParsedDeclarations[i]->ParseLexedAttributes();
1153 if (!AlreadyHasClassScope)
1155 Class.TagOrTemplate);
1160 void Parser::ParseLexedAttributeList(LateParsedAttrList &LAs,
Decl *D,
1161 bool EnterScope,
bool OnDefinition) {
1162 assert(LAs.parseSoon() &&
1163 "Attribute list should be marked for immediate parsing.");
1164 for (
unsigned i = 0, ni = LAs.size(); i < ni; ++i) {
1167 ParseLexedAttribute(*LAs[i], EnterScope, OnDefinition);
1179 void Parser::ParseLexedAttribute(LateParsedAttribute &LA,
1180 bool EnterScope,
bool OnDefinition) {
1188 LA.Toks.push_back(AttrEnd);
1192 LA.Toks.push_back(Tok);
1195 ConsumeAnyToken(
true);
1200 if (LA.Decls.size() > 0) {
1201 Decl *D = LA.Decls[0];
1209 if (LA.Decls.size() == 1) {
1213 if (HasTemplateScope)
1222 ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, &endLoc,
1230 if (HasTemplateScope) {
1236 ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, &endLoc,
1241 Diag(Tok, diag::warn_attribute_no_decl) << LA.AttrName.getName();
1247 Diag(Tok, diag::warn_attribute_on_function_definition)
1250 for (
unsigned i = 0, ni = LA.Decls.size(); i < ni; ++i)
1262 void Parser::ParseTypeTagForDatatypeAttribute(
IdentifierInfo &AttrName,
1269 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
1274 if (Tok.
isNot(tok::identifier)) {
1275 Diag(Tok, diag::err_expected) << tok::identifier;
1281 if (ExpectAndConsume(tok::comma)) {
1293 bool LayoutCompatible =
false;
1294 bool MustBeNull =
false;
1296 if (Tok.
isNot(tok::identifier)) {
1297 Diag(Tok, diag::err_expected) << tok::identifier;
1302 if (Flag->
isStr(
"layout_compatible"))
1303 LayoutCompatible =
true;
1304 else if (Flag->
isStr(
"must_be_null"))
1307 Diag(Tok, diag::err_type_safety_unknown_flag) << Flag;
1314 if (!T.consumeClose()) {
1316 ArgumentKind, MatchingCType.
get(),
1317 LayoutCompatible, MustBeNull, Syntax);
1321 *EndLoc = T.getCloseLocation();
1332 bool Parser::DiagnoseProhibitedCXX11Attribute() {
1333 assert(Tok.
is(tok::l_square) &&
NextToken().
is(tok::l_square));
1335 switch (isCXX11AttributeSpecifier(
true)) {
1336 case CAK_NotAttributeSpecifier:
1340 case CAK_InvalidAttributeSpecifier:
1344 case CAK_AttributeSpecifier:
1349 assert(Tok.
is(tok::r_square) &&
"isCXX11AttributeSpecifier lied");
1351 Diag(BeginLoc, diag::err_attributes_not_allowed)
1355 llvm_unreachable(
"All cases handled above.");
1362 void Parser::DiagnoseMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs,
1364 assert((Tok.
is(tok::l_square) &&
NextToken().
is(tok::l_square)) ||
1365 Tok.
is(tok::kw_alignas));
1369 ParseCXX11Attributes(Attrs);
1372 Diag(Loc, diag::err_attributes_not_allowed)
1377 void Parser::DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs) {
1378 Diag(attrs.Range.getBegin(), diag::err_attributes_not_allowed)
1382 void Parser::ProhibitCXX11Attributes(ParsedAttributesWithRange &attrs) {
1386 Diag(AttrList->
getLoc(), diag::err_attribute_not_type_attr)
1390 AttrList = AttrList->
getNext();
1396 void Parser::handleDeclspecAlignBeforeClassKey(ParsedAttributesWithRange &Attrs,
1410 if (AL->
getKind() == AttributeList::AT_Aligned &&
1452 ParsedAttributesWithRange &attrs) {
1458 Decl *SingleDecl =
nullptr;
1459 Decl *OwnedType =
nullptr;
1461 case tok::kw_template:
1462 case tok::kw_export:
1463 ProhibitAttributes(attrs);
1464 SingleDecl = ParseDeclarationStartingWithTemplate(Context, DeclEnd);
1466 case tok::kw_inline:
1469 ProhibitAttributes(attrs);
1471 SingleDecl = ParseNamespace(Context, DeclEnd, InlineLoc);
1474 return ParseSimpleDeclaration(Context, DeclEnd, attrs,
1476 case tok::kw_namespace:
1477 ProhibitAttributes(attrs);
1478 SingleDecl = ParseNamespace(Context, DeclEnd);
1481 SingleDecl = ParseUsingDirectiveOrDeclaration(Context, ParsedTemplateInfo(),
1482 DeclEnd, attrs, &OwnedType);
1484 case tok::kw_static_assert:
1485 case tok::kw__Static_assert:
1486 ProhibitAttributes(attrs);
1487 SingleDecl = ParseStaticAssertDeclaration(DeclEnd);
1490 return ParseSimpleDeclaration(Context, DeclEnd, attrs,
true);
1516 Parser::ParseSimpleDeclaration(
unsigned Context,
1518 ParsedAttributesWithRange &Attrs,
1519 bool RequireSemi, ForRangeInit *FRI) {
1523 DeclSpecContext DSContext = getDeclSpecContextFromDeclaratorContext(Context);
1524 ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(),
AS_none, DSContext);
1529 DiagnoseMissingSemiAfterTagDefinition(DS,
AS_none, DSContext))
1534 if (Tok.
is(tok::semi)) {
1535 ProhibitAttributes(Attrs);
1540 DS.complete(TheDecl);
1545 return ParseDeclGroup(DS, Context, &DeclEnd, FRI);
1550 bool Parser::MightBeDeclarator(
unsigned Context) {
1552 case tok::annot_cxxscope:
1553 case tok::annot_template_id:
1555 case tok::code_completion:
1556 case tok::coloncolon:
1558 case tok::kw___attribute:
1559 case tok::kw_operator:
1575 case tok::identifier:
1577 case tok::code_completion:
1578 case tok::coloncolon:
1581 case tok::equalequal:
1582 case tok::kw_alignas:
1584 case tok::kw___attribute:
1602 case tok::identifier:
1625 if (Tok.
isOneOf(tok::comma, tok::l_brace, tok::kw_try)) {
1649 case tok::kw_inline:
1654 (!ParsingInObjCContainer || CurParsedObjCImpl))
1658 case tok::kw_namespace:
1663 (!ParsingInObjCContainer || CurParsedObjCImpl))
1670 ParsingInObjCContainer)
1682 case tok::annot_module_begin:
1683 case tok::annot_module_end:
1684 case tok::annot_module_include:
1701 ForRangeInit *FRI) {
1707 if (!D.hasName() && !D.mayOmitIdentifier()) {
1715 LateParsedAttrList LateParsedAttrs(
true);
1716 if (D.isFunctionDeclarator()) {
1717 MaybeParseGNUAttributes(D, &LateParsedAttrs);
1722 if (Tok.
is(tok::kw__Noreturn)) {
1724 const char *PrevSpec;
1730 MaybeParseGNUAttributes(D, &LateParsedAttrs);
1731 Fixit &= Tok.
isOneOf(tok::semi, tok::l_brace, tok::kw_try);
1733 Diag(Loc, diag::err_c11_noreturn_misplaced)
1735 << (Fixit ?
FixItHint::CreateInsertion(D.getLocStart(),
"_Noreturn ")
1741 if (D.isFunctionDeclarator() &&
1745 !isDeclarationAfterDeclarator()) {
1751 if (isStartOfFunctionDefinition(D)) {
1753 Diag(Tok, diag::err_function_declared_typedef);
1760 ParseFunctionDefinition(D, ParsedTemplateInfo(), &LateParsedAttrs);
1764 if (isDeclarationSpecifier()) {
1772 Diag(Tok, diag::err_expected_fn_body);
1777 if (Tok.
is(tok::l_brace)) {
1778 Diag(Tok, diag::err_function_definition_not_allowed);
1785 if (ParseAsmAttributesAfterDeclarator(D))
1794 if (FRI && (Tok.
is(tok::colon) || isTokIdentifier_in())) {
1795 bool IsForRangeLoop =
false;
1797 IsForRangeLoop =
true;
1798 if (Tok.
is(tok::l_brace))
1799 FRI->RangeExpr = ParseBraceInitializer();
1808 D.complete(ThisDecl);
1813 Decl *FirstDecl = ParseDeclarationAfterDeclaratorAndAttributes(
1814 D, ParsedTemplateInfo(), FRI);
1815 if (LateParsedAttrs.size() > 0)
1816 ParseLexedAttributeList(LateParsedAttrs, FirstDecl,
true,
false);
1817 D.complete(FirstDecl);
1819 DeclsInGroup.push_back(FirstDecl);
1827 if (Tok.
isAtStartOfLine() && ExpectSemi && !MightBeDeclarator(Context)) {
1831 Diag(CommaLoc, diag::err_expected_semi_declaration)
1839 D.setCommaLoc(CommaLoc);
1848 MaybeParseGNUAttributes(D);
1852 DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
1855 if (!D.isInvalidType()) {
1856 Decl *ThisDecl = ParseDeclarationAfterDeclarator(D);
1857 D.complete(ThisDecl);
1859 DeclsInGroup.push_back(ThisDecl);
1868 ? diag::err_invalid_token_after_toplevel_declarator
1869 : diag::err_expected_semi_declaration)) {
1873 if (!isDeclarationSpecifier()) {
1884 bool Parser::ParseAsmAttributesAfterDeclarator(
Declarator &D) {
1886 if (Tok.
is(tok::kw_asm)) {
1889 if (AsmLabel.isInvalid()) {
1898 MaybeParseGNUAttributes(D);
1924 Decl *Parser::ParseDeclarationAfterDeclarator(
1925 Declarator &D,
const ParsedTemplateInfo &TemplateInfo) {
1926 if (ParseAsmAttributesAfterDeclarator(D))
1929 return ParseDeclarationAfterDeclaratorAndAttributes(D, TemplateInfo);
1932 Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
1933 Declarator &D,
const ParsedTemplateInfo &TemplateInfo, ForRangeInit *FRI) {
1935 Decl *ThisDecl =
nullptr;
1936 switch (TemplateInfo.Kind) {
1937 case ParsedTemplateInfo::NonTemplate:
1941 case ParsedTemplateInfo::Template:
1942 case ParsedTemplateInfo::ExplicitSpecialization: {
1944 *TemplateInfo.TemplateParams,
1946 if (
VarTemplateDecl *VT = dyn_cast_or_null<VarTemplateDecl>(ThisDecl))
1949 ThisDecl = VT->getTemplatedDecl();
1952 case ParsedTemplateInfo::ExplicitInstantiation: {
1953 if (Tok.
is(tok::semi)) {
1955 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc, D);
1960 ThisDecl = ThisRes.
get();
1968 Diag(Tok, diag::err_template_defn_explicit_instantiation)
1975 diag::err_explicit_instantiation_with_definition)
1982 0,
SourceLocation(), TemplateInfo.TemplateLoc, LAngleLoc,
nullptr,
1997 if (isTokenEqualOrEqualTypo()) {
2000 if (Tok.
is(tok::kw_delete)) {
2006 }
else if (Tok.
is(tok::kw_default)) {
2018 if (Tok.
is(tok::code_completion)) {
2030 Diag(EqualLoc, diag::err_single_decl_assign_in_for_range)
2034 FRI->ColonLoc = EqualLoc;
2036 FRI->RangeExpr = Init;
2044 if (Init.isInvalid()) {
2046 StopTokens.push_back(tok::comma);
2048 StopTokens.push_back(tok::r_paren);
2053 false, TypeContainsAuto);
2055 }
else if (Tok.
is(tok::l_paren)) {
2061 CommaLocsTy CommaLocs;
2068 if (ParseExpressionList(Exprs, CommaLocs, [&] {
2070 cast<VarDecl>(ThisDecl)->getType()->getCanonicalTypeInternal(),
2084 assert(!Exprs.empty() && Exprs.size()-1 == CommaLocs.size() &&
2085 "Unexpected number of commas!");
2093 T.getCloseLocation(),
2096 true, TypeContainsAuto);
2098 }
else if (
getLangOpts().CPlusPlus11 && Tok.
is(tok::l_brace) &&
2101 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
2115 if (Init.isInvalid()) {
2119 true, TypeContainsAuto);
2137 DeclSpecContext DSC) {
2141 ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS, DSC);
2146 Diag(Tok, diag::err_expected_type);
2149 Diag(Tok, diag::err_typename_requires_specqual);
2160 diag::err_typename_invalid_storageclass);
2201 return T.
isOneOf(tok::l_square, tok::l_paren, tok::r_paren, tok::semi,
2202 tok::comma, tok::equal, tok::kw_asm, tok::l_brace,
2217 const ParsedTemplateInfo &TemplateInfo,
2219 ParsedAttributesWithRange &Attrs) {
2220 assert(Tok.
is(tok::identifier) &&
"should have identifier");
2242 if (!isTypeSpecifier(DSC) && !
getLangOpts().CPlusPlus &&
2255 AnnotateScopeToken(*SS,
false);
2265 if (SS ==
nullptr) {
2266 const char *TagName =
nullptr, *FixitTagName =
nullptr;
2272 TagName=
"enum" ; FixitTagName =
"enum " ; TagKind=tok::kw_enum ;
break;
2274 TagName=
"union" ; FixitTagName =
"union " ;TagKind=tok::kw_union ;
break;
2276 TagName=
"struct"; FixitTagName =
"struct ";TagKind=tok::kw_struct;
break;
2278 TagName=
"__interface"; FixitTagName =
"__interface ";
2279 TagKind=tok::kw___interface;
break;
2281 TagName=
"class" ; FixitTagName =
"class " ;TagKind=tok::kw_class ;
break;
2289 Diag(Loc, diag::err_use_of_tag_name_without_tag)
2290 << TokenName << TagName <<
getLangOpts().CPlusPlus
2296 Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
2297 << TokenName << TagName;
2301 if (TagKind == tok::kw_enum)
2302 ParseEnumSpecifier(Loc, DS, TemplateInfo, AS, DSC_normal);
2304 ParseClassSpecifier(TagKind, Loc, DS, TemplateInfo, AS,
2305 false, DSC_normal, Attrs);
2312 if (!isTypeSpecifier(DSC) &&
2313 (!SS || DSC == DSC_top_level || DSC == DSC_class)) {
2317 case tok::l_paren: {
2324 TentativeParsingAction PA(*
this);
2326 TPResult TPR = TryParseDeclarator(
false);
2337 if (DSC == DSC_class || (DSC == DSC_top_level && SS)) {
2340 Diag(Loc, diag::err_constructor_bad_name)
2357 AnnotateScopeToken(*SS,
false);
2379 const char *PrevSpec;
2410 Parser::DeclSpecContext
2411 Parser::getDeclSpecContextFromDeclaratorContext(
unsigned Context) {
2415 return DSC_top_level;
2417 return DSC_template_type_arg;
2419 return DSC_trailing;
2422 return DSC_alias_declaration;
2438 if (isTypeIdInParens()) {
2463 assert(Tok.
isOneOf(tok::kw_alignas, tok::kw__Alignas) &&
2464 "Not an alignment-specifier!");
2470 if (T.expectAndConsume())
2474 ExprResult ArgExpr = ParseAlignArgument(T.getOpenLocation(), EllipsisLoc);
2482 *EndLoc = T.getCloseLocation();
2485 ArgExprs.push_back(ArgExpr.
get());
2486 Attrs.
addNew(KWName, KWLoc,
nullptr, KWLoc, ArgExprs.data(), 1,
2499 DeclSpecContext DSContext,
2500 LateParsedAttrList *LateAttrs) {
2503 bool EnteringContext = (DSContext == DSC_class || DSContext == DSC_top_level);
2506 Tok.
isOneOf(tok::identifier, tok::coloncolon, tok::kw_decltype,
2507 tok::annot_template_id) &&
2513 bool HasScope = Tok.
is(tok::annot_cxxscope);
2519 bool MightBeDeclarator =
true;
2520 if (Tok.
isOneOf(tok::kw_typename, tok::annot_typename)) {
2522 MightBeDeclarator =
false;
2523 }
else if (AfterScope.
is(tok::annot_template_id)) {
2529 MightBeDeclarator =
false;
2530 }
else if (AfterScope.
is(tok::identifier)) {
2531 const Token &Next = HasScope ? GetLookAheadToken(2) : NextToken();
2535 if (Next.
isOneOf(tok::star, tok::amp, tok::ampamp, tok::identifier,
2536 tok::annot_cxxscope, tok::coloncolon)) {
2538 MightBeDeclarator =
false;
2539 }
else if (HasScope) {
2550 switch (Classification.
getKind()) {
2557 llvm_unreachable(
"typo correction and nested name specifiers not "
2563 MightBeDeclarator =
false;
2576 if (MightBeDeclarator)
2581 diag::err_expected_after)
2592 ParsedTemplateInfo NotATemplate;
2593 ParseDeclarationSpecifiers(DS, NotATemplate, AS, DSContext, LateAttrs);
2626 void Parser::ParseDeclarationSpecifiers(
DeclSpec &DS,
2627 const ParsedTemplateInfo &TemplateInfo,
2629 DeclSpecContext DSContext,
2630 LateParsedAttrList *LateAttrs) {
2639 bool EnteringContext = (DSContext == DSC_class || DSContext == DSC_top_level);
2640 bool AttrsLastTime =
false;
2641 ParsedAttributesWithRange attrs(AttrFactory);
2646 bool isStorageClass =
false;
2647 const char *PrevSpec =
nullptr;
2648 unsigned DiagID = 0;
2656 ProhibitAttributes(attrs);
2661 ProhibitCXX11Attributes(attrs);
2668 DS.
Finish(Diags, PP, Policy);
2672 case tok::kw_alignas:
2674 goto DoneWithDeclSpec;
2676 ProhibitAttributes(attrs);
2683 ParseCXX11Attributes(attrs);
2684 AttrsLastTime =
true;
2687 case tok::code_completion: {
2690 bool AllowNonIdentifiers
2696 bool AllowNestedNameSpecifiers
2697 = DSContext == DSC_top_level ||
2701 AllowNonIdentifiers,
2702 AllowNestedNameSpecifiers);
2703 return cutOffParsing();
2708 else if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate)
2711 else if (DSContext == DSC_class)
2713 else if (CurParsedObjCImpl)
2717 return cutOffParsing();
2720 case tok::coloncolon:
2725 goto DoneWithDeclSpec;
2727 if (Tok.
is(tok::coloncolon))
2728 goto DoneWithDeclSpec;
2731 case tok::annot_cxxscope: {
2733 goto DoneWithDeclSpec;
2742 if (Next.
is(tok::annot_template_id) &&
2767 if ((DSContext == DSC_top_level || DSContext == DSC_class) &&
2770 if (isConstructorDeclarator(
false)) {
2775 goto DoneWithDeclSpec;
2783 diag::err_out_of_line_template_id_names_constructor)
2784 << TemplateId->
Name;
2789 assert(Tok.
is(tok::annot_template_id) &&
2790 "ParseOptionalCXXScopeSpecifier not working");
2791 AnnotateTemplateIdTokenAsType();
2795 if (Next.
is(tok::annot_typename)) {
2802 PrevSpec, DiagID, T, Policy);
2812 if (Next.
isNot(tok::identifier))
2813 goto DoneWithDeclSpec;
2817 if ((DSContext == DSC_top_level || DSContext == DSC_class) &&
2820 if (isConstructorDeclarator(
false))
2821 goto DoneWithDeclSpec;
2829 Diag(Next.
getLocation(), diag::err_out_of_line_type_names_constructor)
2846 ParsedAttributesWithRange Attrs(AttrFactory);
2847 if (ParseImplicitInt(DS, &SS, TemplateInfo, AS, DSContext, Attrs)) {
2848 if (!Attrs.
empty()) {
2849 AttrsLastTime =
true;
2850 attrs.takeAllFrom(Attrs);
2854 goto DoneWithDeclSpec;
2861 DiagID, TypeRep, Policy);
2871 case tok::annot_typename: {
2875 goto DoneWithDeclSpec;
2893 case tok::kw___is_signed:
2904 TryKeywordIdentFallback(
true);
2907 goto DoneWithDeclSpec;
2910 case tok::kw___super:
2911 case tok::kw_decltype:
2912 case tok::identifier: {
2917 goto DoneWithDeclSpec;
2924 goto DoneWithDeclSpec;
2926 if (!Tok.
is(tok::identifier))
2931 if (TryAltiVecToken(DS, Loc, PrevSpec, DiagID, isInvalid))
2937 goto DoneWithDeclSpec;
2939 if (DSContext == DSC_objc_method_result && isObjCInstancetype()) {
2943 DiagID, TypeRep, Policy);
2960 if (!TypeRep && DSContext == DSC_template_type_arg &&
2969 ParsedAttributesWithRange Attrs(AttrFactory);
2970 if (ParseImplicitInt(DS,
nullptr, TemplateInfo, AS, DSContext, Attrs)) {
2971 if (!Attrs.
empty()) {
2972 AttrsLastTime =
true;
2973 attrs.takeAllFrom(Attrs);
2977 goto DoneWithDeclSpec;
2984 isConstructorDeclarator(
true))
2985 goto DoneWithDeclSpec;
2988 DiagID, TypeRep, Policy);
3000 TypeResult NewTypeRep = parseObjCTypeArgsAndProtocolQualifiers(
3015 case tok::annot_template_id: {
3020 goto DoneWithDeclSpec;
3028 isConstructorDeclarator(TemplateId->
SS.
isEmpty()))
3029 goto DoneWithDeclSpec;
3033 AnnotateTemplateIdTokenAsType();
3038 case tok::kw___attribute:
3043 case tok::kw___declspec:
3048 case tok::kw___forceinline: {
3057 case tok::kw___sptr:
3058 case tok::kw___uptr:
3059 case tok::kw___ptr64:
3060 case tok::kw___ptr32:
3062 case tok::kw___cdecl:
3063 case tok::kw___stdcall:
3064 case tok::kw___fastcall:
3065 case tok::kw___thiscall:
3066 case tok::kw___vectorcall:
3067 case tok::kw___unaligned:
3072 case tok::kw___pascal:
3077 case tok::kw___kernel:
3082 case tok::kw__Nonnull:
3083 case tok::kw__Nullable:
3084 case tok::kw__Null_unspecified:
3089 case tok::kw___kindof:
3096 case tok::kw_typedef:
3098 PrevSpec, DiagID, Policy);
3099 isStorageClass =
true;
3101 case tok::kw_extern:
3103 Diag(Tok, diag::ext_thread_before) <<
"extern";
3105 PrevSpec, DiagID, Policy);
3106 isStorageClass =
true;
3108 case tok::kw___private_extern__:
3110 Loc, PrevSpec, DiagID, Policy);
3111 isStorageClass =
true;
3113 case tok::kw_static:
3115 Diag(Tok, diag::ext_thread_before) <<
"static";
3117 PrevSpec, DiagID, Policy);
3118 isStorageClass =
true;
3122 if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) {
3124 PrevSpec, DiagID, Policy);
3126 Diag(Tok, diag::ext_auto_storage_class)
3133 PrevSpec, DiagID, Policy);
3134 isStorageClass =
true;
3136 case tok::kw_register:
3138 PrevSpec, DiagID, Policy);
3139 isStorageClass =
true;
3141 case tok::kw_mutable:
3143 PrevSpec, DiagID, Policy);
3144 isStorageClass =
true;
3146 case tok::kw___thread:
3149 isStorageClass =
true;
3151 case tok::kw_thread_local:
3155 case tok::kw__Thread_local:
3157 Loc, PrevSpec, DiagID);
3158 isStorageClass =
true;
3162 case tok::kw_inline:
3165 case tok::kw_virtual:
3168 case tok::kw_explicit:
3171 case tok::kw__Noreturn:
3173 Diag(Loc, diag::ext_c11_noreturn);
3178 case tok::kw__Alignas:
3180 Diag(Tok, diag::ext_c11_alignment) << Tok.
getName();
3185 case tok::kw_friend:
3186 if (DSContext == DSC_class)
3190 DiagID = diag::err_friend_invalid_in_context;
3196 case tok::kw___module_private__:
3201 case tok::kw_constexpr:
3206 case tok::kw_concept:
3223 case tok::kw___int64:
3227 case tok::kw_signed:
3231 case tok::kw_unsigned:
3235 case tok::kw__Complex:
3239 case tok::kw__Imaginary:
3255 case tok::kw___int128:
3267 case tok::kw_double:
3271 case tok::kw_wchar_t:
3275 case tok::kw_char16_t:
3279 case tok::kw_char32_t:
3285 if (Tok.
is(tok::kw_bool) &&
3289 DiagID = diag::err_bool_redeclaration;
3298 case tok::kw__Decimal32:
3302 case tok::kw__Decimal64:
3306 case tok::kw__Decimal128:
3310 case tok::kw___vector:
3313 case tok::kw___pixel:
3316 case tok::kw___bool:
3319 case tok::kw___unknown_anytype:
3321 PrevSpec, DiagID, Policy);
3326 case tok::kw_struct:
3327 case tok::kw___interface:
3328 case tok::kw_union: {
3335 ParsedAttributesWithRange Attributes(AttrFactory);
3336 ParseClassSpecifier(Kind, Loc, DS, TemplateInfo, AS,
3337 EnteringContext, DSContext, Attributes);
3341 if (!Attributes.empty()) {
3342 AttrsLastTime =
true;
3343 attrs.takeAllFrom(Attributes);
3351 ParseEnumSpecifier(Loc, DS, TemplateInfo, AS, DSContext);
3359 case tok::kw_volatile:
3363 case tok::kw_restrict:
3369 case tok::kw_typename:
3372 goto DoneWithDeclSpec;
3374 if (!Tok.
is(tok::kw_typename))
3379 case tok::kw_typeof:
3380 ParseTypeofSpecifier(DS);
3383 case tok::annot_decltype:
3384 ParseDecltypeSpecifier(DS);
3387 case tok::kw___underlying_type:
3388 ParseUnderlyingTypeSpecifier(DS);
3391 case tok::kw__Atomic:
3397 ParseAtomicSpecifier(DS);
3405 case tok::kw___generic:
3409 DiagID = diag::err_opencl_unknown_type_specifier;
3414 case tok::kw___private:
3415 case tok::kw___global:
3416 case tok::kw___local:
3417 case tok::kw___constant:
3418 case tok::kw___read_only:
3419 case tok::kw___write_only:
3420 case tok::kw___read_write:
3429 goto DoneWithDeclSpec;
3436 PrevSpec, DiagID, Type.
get(),
3438 Diag(StartLoc, DiagID) << PrevSpec;
3451 assert(PrevSpec &&
"Method did not return previous specifier!");
3454 if (DiagID == diag::ext_duplicate_declspec)
3457 else if (DiagID == diag::err_opencl_unknown_type_specifier)
3458 Diag(Tok, DiagID) << PrevSpec << isStorageClass;
3460 Diag(Tok, DiagID) << PrevSpec;
3464 if (DiagID != diag::err_bool_redeclaration)
3467 AttrsLastTime =
false;
3488 void Parser::ParseStructDeclaration(
3492 if (Tok.
is(tok::kw___extension__)) {
3496 return ParseStructDeclaration(DS, FieldsCallback);
3500 ParseSpecifierQualifierList(DS);
3504 if (Tok.
is(tok::semi)) {
3512 bool FirstDeclarator =
true;
3516 DeclaratorInfo.D.setCommaLoc(CommaLoc);
3519 if (!FirstDeclarator)
3520 MaybeParseGNUAttributes(DeclaratorInfo.D);
3524 if (Tok.
isNot(tok::colon)) {
3527 ParseDeclarator(DeclaratorInfo.D);
3529 DeclaratorInfo.D.SetIdentifier(
nullptr, Tok.
getLocation());
3533 if (Res.isInvalid())
3536 DeclaratorInfo.BitfieldSize = Res.get();
3540 MaybeParseGNUAttributes(DeclaratorInfo.D);
3543 FieldsCallback(DeclaratorInfo);
3550 FirstDeclarator =
false;
3567 "parsing struct/union body");
3571 if (T.consumeOpen())
3580 while (Tok.
isNot(tok::r_brace) && !isEofOrEom()) {
3584 if (Tok.
is(tok::semi)) {
3585 ConsumeExtraSemi(InsideStruct, TagType);
3590 if (Tok.
is(tok::kw__Static_assert)) {
3592 ParseStaticAssertDeclaration(DeclEnd);
3596 if (Tok.
is(tok::annot_pragma_pack)) {
3601 if (Tok.
is(tok::annot_pragma_align)) {
3602 HandlePragmaAlign();
3606 if (Tok.
is(tok::annot_pragma_openmp)) {
3608 auto Res = ParseOpenMPDeclarativeDirective();
3614 if (!Tok.
is(tok::at)) {
3620 FD.D, FD.BitfieldSize);
3621 FieldDecls.push_back(Field);
3627 ParseStructDeclaration(DS, CFieldCallback);
3631 Diag(Tok, diag::err_unexpected_at);
3636 ExpectAndConsume(tok::l_paren);
3637 if (!Tok.
is(tok::identifier)) {
3638 Diag(Tok, diag::err_expected) << tok::identifier;
3645 FieldDecls.insert(FieldDecls.end(), Fields.begin(), Fields.end());
3647 ExpectAndConsume(tok::r_paren);
3653 if (Tok.
is(tok::r_brace)) {
3654 ExpectAndConsume(tok::semi, diag::ext_expected_semi_decl_list);
3658 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list);
3669 MaybeParseGNUAttributes(attrs);
3672 RecordLoc, TagDecl, FieldDecls,
3673 T.getOpenLocation(), T.getCloseLocation(),
3677 T.getCloseLocation());
3711 const ParsedTemplateInfo &TemplateInfo,
3714 if (Tok.
is(tok::code_completion)) {
3717 return cutOffParsing();
3721 ParsedAttributesWithRange attrs(AttrFactory);
3722 MaybeParseGNUAttributes(attrs);
3723 MaybeParseCXX11Attributes(attrs);
3724 MaybeParseMicrosoftDeclSpecs(attrs);
3727 bool IsScopedUsingClassTag =
false;
3730 if (Tok.
isOneOf(tok::kw_class, tok::kw_struct)) {
3732 : diag::ext_scoped_enum);
3733 IsScopedUsingClassTag = Tok.
is(tok::kw_class);
3738 ProhibitAttributes(attrs);
3741 MaybeParseGNUAttributes(attrs);
3742 MaybeParseCXX11Attributes(attrs);
3743 MaybeParseMicrosoftDeclSpecs(attrs);
3752 bool shouldDelayDiagsInTag =
3753 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
3754 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
3758 bool AllowDeclaration = DSC != DSC_trailing;
3760 bool AllowFixedUnderlyingType = AllowDeclaration &&
3771 if (ParseOptionalCXXScopeSpecifier(Spec,
ParsedType(),
3775 if (Spec.
isSet() && Tok.
isNot(tok::identifier)) {
3776 Diag(Tok, diag::err_expected) << tok::identifier;
3777 if (Tok.
isNot(tok::l_brace)) {
3789 if (Tok.
isNot(tok::identifier) && Tok.
isNot(tok::l_brace) &&
3790 !(AllowFixedUnderlyingType && Tok.
is(tok::colon))) {
3791 Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace;
3801 if (Tok.
is(tok::identifier)) {
3806 if (!Name && ScopedEnumKWLoc.
isValid()) {
3809 Diag(Tok, diag::err_scoped_enum_missing_identifier);
3811 IsScopedUsingClassTag =
false;
3816 if (shouldDelayDiagsInTag)
3817 diagsFromTag.done();
3823 if (AllowFixedUnderlyingType && Tok.
is(tok::colon)) {
3824 bool PossibleBitfield =
false;
3825 if (CanBeBitfield) {
3839 PossibleBitfield =
true;
3845 GetLookAheadToken(2).
getKind() == tok::semi) {
3852 TentativeParsingAction TPA(*
this);
3867 PossibleBitfield =
true;
3879 if (!PossibleBitfield) {
3884 Diag(StartLoc, diag::warn_cxx98_compat_enum_fixed_underlying_type);
3887 Diag(StartLoc, diag::ext_cxx11_enum_fixed_underlying_type) << Range;
3889 Diag(StartLoc, diag::ext_c_enum_fixed_underlying_type) << Range;
3905 if (!AllowDeclaration) {
3907 }
else if (Tok.
is(tok::l_brace)) {
3917 }
else if (!isTypeSpecifier(DSC) &&
3918 (Tok.
is(tok::semi) ||
3920 !isValidAfterTypeSpecifier(CanBeBitfield)))) {
3922 if (Tok.
isNot(tok::semi)) {
3924 ExpectAndConsume(tok::semi, diag::err_expected_after,
"enum");
3935 diagsFromTag.redelay();
3939 if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
3943 Diag(Tok, diag::err_enum_template);
3948 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
3951 Diag(StartLoc, diag::err_explicit_instantiation_enum);
3955 assert(TemplateInfo.TemplateParams &&
"no template parameters");
3957 TemplateInfo.TemplateParams->size());
3961 ProhibitAttributes(attrs);
3964 Diag(Tok, diag::err_enumerator_unnamed_no_def);
3971 handleDeclspecAlignBeforeClassKey(attrs, DS, TUK);
3981 bool IsDependent =
false;
3982 const char *PrevSpec =
nullptr;
3985 StartLoc, SS, Name, NameLoc, attrs.getList(),
3987 Owned, IsDependent, ScopedEnumKWLoc,
3988 IsScopedUsingClassTag, BaseType,
3989 DSC == DSC_type_specifier, &SkipBody);
3999 NameLoc.
isValid() ? NameLoc : StartLoc,
4000 PrevSpec, DiagID, TagDecl, Owned,
4002 Diag(StartLoc, DiagID) << PrevSpec;
4011 Diag(Tok, diag::err_expected_type_name_after_typename);
4023 NameLoc.
isValid() ? NameLoc : StartLoc,
4024 PrevSpec, DiagID, Type.
get(),
4026 Diag(StartLoc, DiagID) << PrevSpec;
4044 ParseEnumBody(StartLoc, TagDecl);
4047 NameLoc.
isValid() ? NameLoc : StartLoc,
4048 PrevSpec, DiagID, TagDecl, Owned,
4050 Diag(StartLoc, DiagID) << PrevSpec;
4073 Diag(Tok, diag::error_empty_enum);
4078 Decl *LastEnumConstDecl =
nullptr;
4081 while (Tok.
isNot(tok::r_brace)) {
4084 if (Tok.
isNot(tok::identifier)) {
4095 ParsedAttributesWithRange attrs(AttrFactory);
4096 MaybeParseGNUAttributes(attrs);
4097 ProhibitAttributes(attrs);
4102 ParseCXX11Attributes(attrs);
4107 EnumAvailabilityDiags.emplace_back(*
this);
4119 attrs.getList(), EqualLoc,
4121 EnumAvailabilityDiags.back().done();
4123 EnumConstantDecls.push_back(EnumConstDecl);
4124 LastEnumConstDecl = EnumConstDecl;
4126 if (Tok.
is(tok::identifier)) {
4129 Diag(Loc, diag::err_enumerator_list_missing_comma)
4152 if (Tok.
is(tok::r_brace) && CommaLoc.
isValid()) {
4155 diag::ext_enumerator_list_comma_cxx :
4156 diag::ext_enumerator_list_comma_c)
4159 Diag(CommaLoc, diag::warn_cxx98_compat_enumerator_list_comma)
4170 MaybeParseGNUAttributes(attrs);
4172 Actions.
ActOnEnumBody(StartLoc, T.getOpenLocation(), T.getCloseLocation(),
4173 EnumDecl, EnumConstantDecls,
4178 assert(EnumConstantDecls.size() == EnumAvailabilityDiags.size());
4179 for (
size_t i = 0, e = EnumConstantDecls.size(); i != e; ++i) {
4181 EnumAvailabilityDiags[i].redelay();
4182 PD.complete(EnumConstantDecls[i]);
4187 T.getCloseLocation());
4192 if (!isValidAfterTypeSpecifier(CanBeBitfield)) {
4193 ExpectAndConsume(tok::semi, diag::err_expected_after,
"enum");
4204 bool Parser::isTypeQualifier()
const {
4206 default:
return false;
4209 case tok::kw_volatile:
4210 case tok::kw_restrict:
4211 case tok::kw___private:
4212 case tok::kw___local:
4213 case tok::kw___global:
4214 case tok::kw___constant:
4215 case tok::kw___generic:
4216 case tok::kw___read_only:
4217 case tok::kw___read_write:
4218 case tok::kw___write_only:
4226 bool Parser::isKnownToBeTypeSpecifier(
const Token &Tok)
const {
4228 default:
return false;
4232 case tok::kw___int64:
4233 case tok::kw___int128:
4234 case tok::kw_signed:
4235 case tok::kw_unsigned:
4236 case tok::kw__Complex:
4237 case tok::kw__Imaginary:
4240 case tok::kw_wchar_t:
4241 case tok::kw_char16_t:
4242 case tok::kw_char32_t:
4246 case tok::kw_double:
4249 case tok::kw__Decimal32:
4250 case tok::kw__Decimal64:
4251 case tok::kw__Decimal128:
4252 case tok::kw___vector:
4256 case tok::kw_struct:
4257 case tok::kw___interface:
4263 case tok::annot_typename:
4270 bool Parser::isTypeSpecifierQualifier() {
4272 default:
return false;
4274 case tok::identifier:
4275 if (TryAltiVecVectorToken())
4278 case tok::kw_typename:
4283 if (Tok.
is(tok::identifier))
4285 return isTypeSpecifierQualifier();
4287 case tok::coloncolon:
4294 return isTypeSpecifierQualifier();
4297 case tok::kw___attribute:
4299 case tok::kw_typeof:
4304 case tok::kw___int64:
4305 case tok::kw___int128:
4306 case tok::kw_signed:
4307 case tok::kw_unsigned:
4308 case tok::kw__Complex:
4309 case tok::kw__Imaginary:
4312 case tok::kw_wchar_t:
4313 case tok::kw_char16_t:
4314 case tok::kw_char32_t:
4318 case tok::kw_double:
4321 case tok::kw__Decimal32:
4322 case tok::kw__Decimal64:
4323 case tok::kw__Decimal128:
4324 case tok::kw___vector:
4328 case tok::kw_struct:
4329 case tok::kw___interface:
4336 case tok::kw_volatile:
4337 case tok::kw_restrict:
4340 case tok::kw___unknown_anytype:
4343 case tok::annot_typename:
4350 case tok::kw___cdecl:
4351 case tok::kw___stdcall:
4352 case tok::kw___fastcall:
4353 case tok::kw___thiscall:
4354 case tok::kw___vectorcall:
4356 case tok::kw___ptr64:
4357 case tok::kw___ptr32:
4358 case tok::kw___pascal:
4359 case tok::kw___unaligned:
4361 case tok::kw__Nonnull:
4362 case tok::kw__Nullable:
4363 case tok::kw__Null_unspecified:
4365 case tok::kw___kindof:
4367 case tok::kw___private:
4368 case tok::kw___local:
4369 case tok::kw___global:
4370 case tok::kw___constant:
4371 case tok::kw___generic:
4372 case tok::kw___read_only:
4373 case tok::kw___read_write:
4374 case tok::kw___write_only:
4379 case tok::kw__Atomic:
4389 bool Parser::isDeclarationSpecifier(
bool DisambiguatingWithExpression) {
4391 default:
return false;
4393 case tok::identifier:
4397 if (TryAltiVecVectorToken())
4400 case tok::kw_decltype:
4401 case tok::kw_typename:
4406 if (Tok.
is(tok::identifier))
4414 if (DisambiguatingWithExpression &&
4415 isStartOfObjCClassMessageMissingOpenBracket())
4418 return isDeclarationSpecifier();
4420 case tok::coloncolon:
4429 return isDeclarationSpecifier();
4432 case tok::kw_typedef:
4433 case tok::kw_extern:
4434 case tok::kw___private_extern__:
4435 case tok::kw_static:
4437 case tok::kw_register:
4438 case tok::kw___thread:
4439 case tok::kw_thread_local:
4440 case tok::kw__Thread_local:
4443 case tok::kw___module_private__:
4446 case tok::kw___unknown_anytype:
4451 case tok::kw___int64:
4452 case tok::kw___int128:
4453 case tok::kw_signed:
4454 case tok::kw_unsigned:
4455 case tok::kw__Complex:
4456 case tok::kw__Imaginary:
4459 case tok::kw_wchar_t:
4460 case tok::kw_char16_t:
4461 case tok::kw_char32_t:
4466 case tok::kw_double:
4469 case tok::kw__Decimal32:
4470 case tok::kw__Decimal64:
4471 case tok::kw__Decimal128:
4472 case tok::kw___vector:
4476 case tok::kw_struct:
4478 case tok::kw___interface:
4484 case tok::kw_volatile:
4485 case tok::kw_restrict:
4488 case tok::kw_inline:
4489 case tok::kw_virtual:
4490 case tok::kw_explicit:
4491 case tok::kw__Noreturn:
4494 case tok::kw__Alignas:
4497 case tok::kw_friend:
4500 case tok::kw__Static_assert:
4503 case tok::kw_typeof:
4506 case tok::kw___attribute:
4509 case tok::annot_decltype:
4510 case tok::kw_constexpr:
4513 case tok::kw_concept:
4516 case tok::kw__Atomic:
4524 case tok::annot_typename:
4525 return !DisambiguatingWithExpression ||
4526 !isStartOfObjCClassMessageMissingOpenBracket();
4528 case tok::kw___declspec:
4529 case tok::kw___cdecl:
4530 case tok::kw___stdcall:
4531 case tok::kw___fastcall:
4532 case tok::kw___thiscall:
4533 case tok::kw___vectorcall:
4535 case tok::kw___sptr:
4536 case tok::kw___uptr:
4537 case tok::kw___ptr64:
4538 case tok::kw___ptr32:
4539 case tok::kw___forceinline:
4540 case tok::kw___pascal:
4541 case tok::kw___unaligned:
4543 case tok::kw__Nonnull:
4544 case tok::kw__Nullable:
4545 case tok::kw__Null_unspecified:
4547 case tok::kw___kindof:
4549 case tok::kw___private:
4550 case tok::kw___local:
4551 case tok::kw___global:
4552 case tok::kw___constant:
4553 case tok::kw___generic:
4554 case tok::kw___read_only:
4555 case tok::kw___read_write:
4556 case tok::kw___write_only:
4562 bool Parser::isConstructorDeclarator(
bool IsUnqualified) {
4563 TentativeParsingAction TPA(*
this);
4567 if (ParseOptionalCXXScopeSpecifier(SS,
ParsedType(),
4574 if (Tok.
isOneOf(tok::identifier, tok::annot_template_id)) {
4584 if (Tok.
isNot(tok::l_paren)) {
4592 if (Tok.
is(tok::r_paren) ||
4601 isCXX11AttributeSpecifier(
false,
4608 DeclaratorScopeObj DeclScopeObj(*
this, SS);
4610 DeclScopeObj.EnterDeclaratorScope();
4614 MaybeParseMicrosoftAttributes(Attrs);
4619 bool IsConstructor =
false;
4620 if (isDeclarationSpecifier())
4621 IsConstructor =
true;
4622 else if (Tok.
is(tok::identifier) ||
4623 (Tok.
is(tok::annot_cxxscope) &&
NextToken().
is(tok::identifier))) {
4628 if (Tok.
is(tok::annot_cxxscope))
4641 case tok::coloncolon:
4654 IsConstructor =
true;
4669 IsConstructor = IsUnqualified;
4674 IsConstructor =
true;
4680 return IsConstructor;
4695 void Parser::ParseTypeQualifierListOpt(
DeclSpec &DS,
unsigned AttrReqs,
4697 bool IdentifierRequired) {
4699 isCXX11AttributeSpecifier()) {
4700 ParsedAttributesWithRange attrs(AttrFactory);
4701 ParseCXX11Attributes(attrs);
4708 bool isInvalid =
false;
4709 const char *PrevSpec =
nullptr;
4710 unsigned DiagID = 0;
4714 case tok::code_completion:
4716 return cutOffParsing();
4722 case tok::kw_volatile:
4726 case tok::kw_restrict:
4730 case tok::kw__Atomic:
4732 goto DoneWithTypeQuals;
4738 case tok::kw___private:
4739 case tok::kw___global:
4740 case tok::kw___local:
4741 case tok::kw___constant:
4742 case tok::kw___generic:
4743 case tok::kw___read_only:
4744 case tok::kw___write_only:
4745 case tok::kw___read_write:
4749 case tok::kw___uptr:
4752 if ((AttrReqs & AR_DeclspecAttributesParsed) && !
getLangOpts().CPlusPlus &&
4754 if (TryKeywordIdentFallback(
false))
4757 case tok::kw___sptr:
4759 case tok::kw___ptr64:
4760 case tok::kw___ptr32:
4761 case tok::kw___cdecl:
4762 case tok::kw___stdcall:
4763 case tok::kw___fastcall:
4764 case tok::kw___thiscall:
4765 case tok::kw___vectorcall:
4766 case tok::kw___unaligned:
4767 if (AttrReqs & AR_DeclspecAttributesParsed) {
4771 goto DoneWithTypeQuals;
4772 case tok::kw___pascal:
4773 if (AttrReqs & AR_VendorAttributesParsed) {
4777 goto DoneWithTypeQuals;
4780 case tok::kw__Nonnull:
4781 case tok::kw__Nullable:
4782 case tok::kw__Null_unspecified:
4787 case tok::kw___kindof:
4793 case tok::kw___attribute:
4794 if (AttrReqs & AR_GNUAttributesParsedAndRejected)
4796 Diag(Tok, diag::err_attributes_not_allowed);
4800 if (AttrReqs & AR_GNUAttributesParsed ||
4801 AttrReqs & AR_GNUAttributesParsedAndRejected) {
4818 assert(PrevSpec &&
"Method did not return previous specifier!");
4819 Diag(Tok, DiagID) << PrevSpec;
4828 void Parser::ParseDeclarator(
Declarator &D) {
4831 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
4835 unsigned TheContext) {
4836 if (Kind == tok::star || Kind == tok::caret)
4839 if (!Lang.CPlusPlus)
4842 if (Kind == tok::amp)
4850 if (Kind == tok::ampamp)
4882 void Parser::ParseDeclaratorInternal(
Declarator &D,
4883 DirectDeclParseFunction DirectDeclParser) {
4891 (Tok.
is(tok::coloncolon) ||
4892 (Tok.
is(tok::identifier) &&
4894 Tok.
is(tok::annot_cxxscope))) {
4898 ParseOptionalCXXScopeSpecifier(SS,
ParsedType(), EnteringContext);
4901 if (Tok.
isNot(tok::star)) {
4906 AnnotateScopeToken(SS,
true);
4908 if (DirectDeclParser)
4909 (this->*DirectDeclParser)(D);
4916 ParseTypeQualifierListOpt(DS);
4920 ParseDeclaratorInternal(D, DirectDeclParser);
4935 if (DirectDeclParser)
4936 (this->*DirectDeclParser)(D);
4945 if (Kind == tok::star || Kind == tok::caret) {
4951 unsigned Reqs = AR_CXX11AttributesParsed | AR_DeclspecAttributesParsed |
4953 ? AR_GNUAttributesParsed
4954 : AR_GNUAttributesParsedAndRejected);
4959 ParseDeclaratorInternal(D, DirectDeclParser);
4960 if (Kind == tok::star)
4981 if (Kind == tok::ampamp)
4983 diag::warn_cxx98_compat_rvalue_reference :
4984 diag::ext_rvalue_reference);
4987 ParseTypeQualifierListOpt(DS);
4996 diag::err_invalid_reference_qualifier_application) <<
"const";
4999 diag::err_invalid_reference_qualifier_application) <<
"volatile";
5003 diag::err_invalid_reference_qualifier_application) <<
"_Atomic";
5007 ParseDeclaratorInternal(D, DirectDeclParser);
5014 Diag(InnerChunk.
Loc, diag::err_illegal_decl_reference_to_reference)
5017 Diag(InnerChunk.
Loc, diag::err_illegal_decl_reference_to_reference)
5088 void Parser::ParseDirectDeclarator(
Declarator &D) {
5113 DeclScopeObj.EnterDeclaratorScope();
5137 DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, D);
5147 if (Tok.
isOneOf(tok::identifier, tok::kw_operator, tok::annot_template_id,
5151 bool AllowConstructorName;
5153 AllowConstructorName =
false;
5155 AllowConstructorName =
5166 AllowConstructorName,
5181 DeclScopeObj.EnterDeclaratorScope();
5188 goto PastIdentifier;
5192 "There's a C++-specific check for tok::identifier above");
5197 goto PastIdentifier;
5202 !isCXX11VirtSpecifier(Tok)) {
5207 goto PastIdentifier;
5211 if (Tok.
is(tok::l_paren)) {
5215 ParseParenDeclarator(D);
5228 DeclScopeObj.EnterDeclaratorScope();
5239 diag::ext_abstract_pack_declarator_parens);
5241 if (Tok.
getKind() == tok::annot_pragma_parser_crash)
5243 if (Tok.
is(tok::l_square))
5244 return ParseMisplacedBracketDeclarator(D);
5247 diag::err_expected_member_name_or_semi)
5249 : D.getDeclSpec().getSourceRange());
5251 if (Tok.
isOneOf(tok::period, tok::arrow))
5252 Diag(Tok, diag::err_invalid_operator_on_type) << Tok.
is(tok::arrow);
5260 diag::err_expected_unqualified_id)
5265 diag::err_expected_either)
5266 << tok::identifier << tok::l_paren;
5274 "Haven't past the location of the identifier yet?");
5278 MaybeParseCXX11Attributes(D);
5281 if (Tok.
is(tok::l_paren)) {
5284 ParseScope PrototypeScope(
this,
5292 bool IsAmbiguous =
false;
5296 TentativelyDeclaredIdentifiers.push_back(D.
getIdentifier());
5297 bool IsFunctionDecl = isCXXFunctionDeclarator(&IsAmbiguous);
5298 TentativelyDeclaredIdentifiers.pop_back();
5299 if (!IsFunctionDecl)
5305 ParseFunctionDeclarator(D, attrs, T, IsAmbiguous);
5306 PrototypeScope.Exit();
5307 }
else if (Tok.
is(tok::l_square)) {
5308 ParseBracketDeclarator(D);
5328 void Parser::ParseParenDeclarator(
Declarator &D) {
5332 assert(!D.
isPastIdentifier() &&
"Should be called before passing identifier");
5345 bool RequiresArg =
false;
5346 if (Tok.
is(tok::kw___attribute)) {
5347 ParseGNUAttributes(attrs);
5355 ParseMicrosoftTypeAttributes(attrs);
5358 if (Tok.
is(tok::kw___pascal))
5359 ParseBorlandTypeAttributes(attrs);
5371 }
else if (Tok.
is(tok::r_paren) ||
5374 isDeclarationSpecifier() ||
5375 isCXX11AttributeSpecifier()) {
5393 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
5397 T.getCloseLocation()),
5398 attrs, T.getCloseLocation());
5404 DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, D);
5417 ParseScope PrototypeScope(
this,
5421 ParseFunctionDeclarator(D, attrs, T,
false, RequiresArg);
5422 PrototypeScope.Exit();
5444 void Parser::ParseFunctionDeclarator(
Declarator &D,
5449 assert(
getCurScope()->isFunctionPrototypeScope() &&
5450 "Should call from a Function scope");
5456 bool HasProto =
false;
5463 bool RefQualifierIsLValueRef =
true;
5483 StartLoc = LParenLoc;
5485 if (isFunctionDeclaratorIdentifierList()) {
5487 Diag(Tok, diag::err_argument_required_after_attribute);
5489 ParseFunctionDeclaratorIdentifierList(D, ParamInfo);
5493 LocalEndLoc = RParenLoc;
5496 if (Tok.
isNot(tok::r_paren))
5497 ParseParameterDeclarationClause(D, FirstArgAttrs, ParamInfo,
5499 else if (RequiresArg)
5500 Diag(Tok, diag::err_argument_required_after_attribute);
5502 HasProto = ParamInfo.size() ||
getLangOpts().CPlusPlus;
5507 LocalEndLoc = RParenLoc;
5516 ParseTypeQualifierListOpt(DS, AR_NoAttributesParsed,
5526 if (ParseRefQualifier(RefQualifierIsLValueRef, RefQualifierLoc))
5527 EndLoc = RefQualifierLoc;
5536 bool IsCXX11MemberFunction =
5550 IsCXX11MemberFunction);
5556 GetLookAheadToken(0).is(tok::kw_noexcept) &&
5557 GetLookAheadToken(1).is(tok::l_paren) &&
5558 GetLookAheadToken(2).is(tok::kw_noexcept) &&
5559 GetLookAheadToken(3).is(tok::l_paren) &&
5560 GetLookAheadToken(4).is(tok::identifier) &&
5561 GetLookAheadToken(4).getIdentifierInfo()->isStr(
"swap")) {
5572 ESpecType = tryParseExceptionSpecification(Delayed,
5575 DynamicExceptionRanges,
5577 ExceptionSpecTokens);
5579 EndLoc = ESpecRange.
getEnd();
5583 MaybeParseCXX11Attributes(FnAttrs);
5586 LocalEndLoc = EndLoc;
5588 Diag(Tok, diag::warn_cxx98_compat_trailing_return_type);
5593 TrailingReturnType = ParseTrailingReturnType(Range);
5603 ParamInfo.data(), ParamInfo.size(),
5604 EllipsisLoc, RParenLoc,
5606 RefQualifierIsLValueRef,
5607 RefQualifierLoc, ConstQualifierLoc,
5608 VolatileQualifierLoc,
5609 RestrictQualifierLoc,
5612 DynamicExceptions.data(),
5613 DynamicExceptionRanges.data(),
5614 DynamicExceptions.size(),
5616 NoexceptExpr.
get() :
nullptr,
5617 ExceptionSpecTokens,
5618 StartLoc, LocalEndLoc, D,
5619 TrailingReturnType),
5625 bool Parser::ParseRefQualifier(
bool &RefQualifierIsLValueRef,
5627 if (Tok.
isOneOf(tok::amp, tok::ampamp)) {
5629 diag::warn_cxx98_compat_ref_qualifier :
5630 diag::ext_ref_qualifier);
5632 RefQualifierIsLValueRef = Tok.
is(tok::amp);
5644 bool Parser::isFunctionDeclaratorIdentifierList() {
5646 && Tok.
is(tok::identifier)
5647 && !TryAltiVecVectorToken()
5675 void Parser::ParseFunctionDeclaratorIdentifierList(
5683 Diag(Tok, diag::ext_ident_list_in_param);
5686 llvm::SmallSet<const IdentifierInfo*, 16> ParamsSoFar;
5690 if (Tok.
isNot(tok::identifier)) {
5691 Diag(Tok, diag::err_expected) << tok::identifier;
5702 Diag(Tok, diag::err_unexpected_typedef_ident) << ParmII;
5705 if (!ParamsSoFar.insert(ParmII).second) {
5706 Diag(Tok, diag::err_param_redefinition) << ParmII;
5751 void Parser::ParseParameterDeclarationClause(
5781 ParseDeclarationSpecifiers(DS);
5791 ParseDeclarator(ParmDeclarator);
5794 MaybeParseGNUAttributes(ParmDeclarator);
5805 if (DS.
isEmpty() && ParmDeclarator.getIdentifier() ==
nullptr &&
5806 ParmDeclarator.getNumTypeObjects() == 0) {
5808 Diag(DSStart, diag::err_missing_param);
5815 if (Tok.
is(tok::ellipsis) &&
5817 (!ParmDeclarator.getEllipsisLoc().isValid() &&
5820 DiagnoseMisplacedEllipsisInDeclarator(
ConsumeToken(), ParmDeclarator);
5829 if (Tok.
is(tok::equal)) {
5841 if (!ConsumeAndStoreInitializer(*DefArgToks, CIK_DefaultArgument)) {
5843 DefArgToks =
nullptr;
5861 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
5862 DefArgResult = ParseBraceInitializer();
5872 DefArgResult.
get());
5878 ParmDeclarator.getIdentifierLoc(),
5879 Param, DefArgToks));
5886 Diag(EllipsisLoc, diag::err_missing_comma_before_ellipsis)
5888 }
else if (ParmDeclarator.getEllipsisLoc().isValid() ||
5893 Diag(EllipsisLoc, diag::warn_misplaced_ellipsis_vararg)
5894 << ParmEllipsis.
isValid() << ParmEllipsis;
5897 diag::note_misplaced_ellipsis_vararg_existing_ellipsis);
5899 Diag(ParmDeclarator.getIdentifierLoc(),
5900 diag::note_misplaced_ellipsis_vararg_add_ellipsis)
5903 << !ParmDeclarator.hasName();
5905 Diag(EllipsisLoc, diag::note_misplaced_ellipsis_vararg_add_comma)
5924 void Parser::ParseBracketDeclarator(
Declarator &D) {
5925 if (CheckProhibitedCXX11Attribute())
5933 if (Tok.
getKind() == tok::r_square) {
5936 MaybeParseCXX11Attributes(attrs);
5940 T.getOpenLocation(),
5941 T.getCloseLocation()),
5942 attrs, T.getCloseLocation());
5944 }
else if (Tok.
getKind() == tok::numeric_constant &&
5945 GetLookAheadToken(1).is(tok::r_square)) {
5952 MaybeParseCXX11Attributes(attrs);
5957 T.getOpenLocation(),
5958 T.getCloseLocation()),
5959 attrs, T.getCloseLocation());
5970 ParseTypeQualifierListOpt(DS, AR_CXX11AttributesParsed);
5978 bool isStar =
false;
5985 if (Tok.
is(tok::star) && GetLookAheadToken(1).is(tok::r_square)) {
5989 Diag(StaticLoc, diag::err_unspecified_vla_size_with_static);
5993 }
else if (Tok.
isNot(tok::r_square)) {
6011 Diag(StaticLoc, diag::err_unspecified_size_with_static);
6027 MaybeParseCXX11Attributes(attrs);
6033 T.getOpenLocation(),
6034 T.getCloseLocation()),
6035 attrs, T.getCloseLocation());
6039 void Parser::ParseMisplacedBracketDeclarator(
Declarator &D) {
6040 assert(Tok.
is(tok::l_square) &&
"Missing opening bracket");
6046 while (Tok.
is(tok::l_square)) {
6047 ParseBracketDeclarator(TempDeclarator);
6053 if (Tok.
is(tok::semi))
6059 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
6064 if (TempDeclarator.getNumTypeObjects() == 0)
6068 bool NeedParens =
false;
6093 for (
unsigned i = 0, e = TempDeclarator.getNumTypeObjects(); i < e; ++i) {
6108 SourceRange BracketRange(StartBracketLoc, EndBracketLoc);
6112 Diag(EndLoc, diag::err_brackets_go_after_unqualified_id)
6120 Diag(EndLoc, diag::err_brackets_go_after_unqualified_id)
6133 void Parser::ParseTypeofSpecifier(
DeclSpec &DS) {
6134 assert(Tok.
is(tok::kw_typeof) &&
"Not a typeof specifier");
6138 const bool hasParens = Tok.
is(tok::l_paren);
6147 ParseExprAfterUnaryExprOrTypeTrait(OpTok, isCastExpr, CastTy, CastRange));
6163 const char *PrevSpec =
nullptr;
6169 Diag(StartLoc, DiagID) << PrevSpec;
6186 const char *PrevSpec =
nullptr;
6190 DiagID, Operand.
get(),
6192 Diag(StartLoc, DiagID) << PrevSpec;
6198 void Parser::ParseAtomicSpecifier(
DeclSpec &DS) {
6199 assert(Tok.
is(tok::kw__Atomic) &&
NextToken().
is(tok::l_paren) &&
6200 "Not an atomic specifier");
6204 if (T.consumeOpen())
6216 if (T.getCloseLocation().isInvalid())
6222 const char *PrevSpec =
nullptr;
6225 DiagID, Result.
get(),
6227 Diag(StartLoc, DiagID) << PrevSpec;
6233 bool Parser::TryAltiVecVectorTokenOutOfLine() {
6236 default:
return false;
6239 case tok::kw_signed:
6240 case tok::kw_unsigned:
6245 case tok::kw_double:
6247 case tok::kw___bool:
6248 case tok::kw___pixel:
6249 Tok.
setKind(tok::kw___vector);
6251 case tok::identifier:
6253 Tok.
setKind(tok::kw___vector);
6257 Tok.
setKind(tok::kw___vector);
6265 const char *&PrevSpec,
unsigned &DiagID,
6273 case tok::kw_signed:
6274 case tok::kw_unsigned:
6279 case tok::kw_double:
6281 case tok::kw___bool:
6282 case tok::kw___pixel:
6285 case tok::identifier:
void ClearFunctionSpecs()
MutableArrayRef< TemplateParameterList * > MultiTemplateParamsArg
unsigned getFlags() const
bool isAtStartOfLine() const
SourceLocation getThreadStorageClassSpecLoc() const
SourceLocation getCloseLocation() const
Defines the clang::ASTContext interface.
static bool isAttributeLateParsed(const IdentifierInfo &II)
SourceLocation getEnd() const
AttributeList * addNewPropertyAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierInfo *getterId, IdentifierInfo *setterId, AttributeList::Syntax syntaxUsed)
Add microsoft __delspec(property) attribute.
IdKind getKind() const
Determine what kind of name we have.
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
TypeResult ActOnDependentTag(Scope *S, unsigned TagSpec, TagUseKind TUK, const CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation TagLoc, SourceLocation NameLoc)
static LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
no exception specification
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
SourceLocation getRestrictSpecLoc() const
This is a scope that corresponds to the parameters within a function prototype.
Represents a version number in the form major[.minor[.subminor[.build]]].
SourceLocation getConstSpecLoc() const
SourceLocation getExplicitSpecLoc() const
TSW getTypeSpecWidth() const
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.
TheContext getContext() const
IdentifierInfo * Name
FIXME: Temporarily stores the name of a specialization.
const LangOptions & getLangOpts() const
static const TST TST_wchar
ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val)
Decl * getRepAsDecl() const
const LangOptions & getLangOpts() const
SourceLocation TemplateNameLoc
IdentifierInfo * getIdentifierInfo(StringRef Name) const
static const TST TST_typeofExpr
static const TST TST_char16
static bool isPtrOperatorToken(tok::TokenKind Kind, const LangOptions &Lang, unsigned TheContext)
RAII object used to inform the actions that we're currently parsing a declaration. This is active when parsing a variable's initializer, but not when parsing the body of a class or function definition.
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. Access-like checks are those associa...
Defines the C++ template declaration subclasses.
bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, bool AllowBuiltinCreation=false, bool EnteringContext=false)
Performs name lookup for a name that was parsed in the source code, and may contain a C++ scope speci...
SCS getStorageClassSpec() const
const char * getName() const
bool TryAnnotateCXXScopeToken(bool EnteringContext=false)
This indicates that the scope corresponds to a function, which means that labels are set here...
One instance of this struct is used for each type in a declarator that is parsed. ...
Declaration of a variable template.
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 getInlineSpecLoc() const
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.
bool SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
void SetIdentifier(IdentifierInfo *Id, SourceLocation IdLoc)
Set the name of this declarator to be the given identifier.
SourceLocation getLocEnd() const LLVM_READONLY
static IdentifierLoc * create(ASTContext &Ctx, SourceLocation Loc, IdentifierInfo *Ident)
void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, bool AllowNonIdentifiers, bool AllowNestedNameSpecifiers)
RAII object that enters a new expression evaluation context.
void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record)
void EnterToken(const Token &Tok)
Enters a token in the token stream to be lexed next.
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)
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
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...
Decl * ActOnParamDeclarator(Scope *S, Declarator &D)
void Finish(DiagnosticsEngine &D, Preprocessor &PP, const PrintingPolicy &Policy)
TemplateParameterList * ActOnTemplateParameterList(unsigned Depth, SourceLocation ExportLoc, SourceLocation TemplateLoc, SourceLocation LAngleLoc, Decl **Params, unsigned NumParams, SourceLocation RAngleLoc)
friend class ObjCDeclContextSwitch
ParmVarDecl - Represents a parameter to a function.
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
bool isEmpty() const
No scope specifier.
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
void ActOnUninitializedDecl(Decl *dcl, bool TypeMayContainAuto)
Information about a template-id annotation token.
Base wrapper for a particular "section" of type source info.
void CodeCompleteOrdinaryName(Scope *S, ParserCompletionContext CompletionContext)
void CodeCompleteConstructor(Scope *S, QualType Type, SourceLocation Loc, ArrayRef< Expr * > Args)
const Token & NextToken()
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
bool TryConsumeToken(tok::TokenKind Expected)
__ptr16, alignas(...), etc.
void set(AttributeList *newList)
OpaquePtr< QualType > ParsedType
static const TST TST_decimal32
AttributeList * getList() const
static bool attributeHasIdentifierArg(const IdentifierInfo &II)
Determine whether the given attribute has an identifier argument.
void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &attrs, SourceLocation EndLoc)
void ActOnTagStartDefinition(Scope *S, Decl *TagDecl)
const CXXScopeSpec & getCXXScopeSpec() const
static const TST TST_class
int hasAttribute(AttrSyntax Syntax, const IdentifierInfo *Scope, const IdentifierInfo *Attr, const llvm::Triple &T, const LangOptions &LangOpts)
Return the version number associated with the attribute if we recognize and implement the attribute s...
bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS)
DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType=nullptr)
AttributeList * addNewTypeAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ParsedType typeArg, AttributeList::Syntax syntaxUsed)
Add an attribute with a single type argument.
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)
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
ParsedType ActOnObjCInstanceType(SourceLocation Loc)
The parser has parsed the context-sensitive type 'instancetype' in an Objective-C message declaration...
SkipBodyInfo shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II, SourceLocation IILoc)
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 { ...
SourceLocation getTypeSpecTypeLoc() const
Decl * ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, SourceLocation IdLoc, IdentifierInfo *Id, AttributeList *Attrs, SourceLocation EqualLoc, Expr *Val)
void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs)
void ClearStorageClassSpecs()
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool mayBeFollowedByCXXDirectInit() const
Decl * ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc, AttributeList *Attr, AccessSpecifier AS, SourceLocation ModulePrivateLoc, MultiTemplateParamsArg TemplateParameterLists, bool &OwnedDecl, bool &IsDependent, SourceLocation ScopedEnumKWLoc, bool ScopedEnumUsesClassTag, TypeResult UnderlyingType, bool IsTypeSpecifier, SkipBodyInfo *SkipBody=nullptr)
This is invoked when we see 'struct foo' or 'struct {'. In the former case, Name will be non-null...
bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
Code completion occurs at top-level or namespace context.
The controlling scope in a if/switch/while/for statement.
const TargetInfo & getTargetInfo() const
void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart, IdentifierInfo *ClassName, SmallVectorImpl< Decl * > &Decls)
This is a scope that corresponds to a block/closure object. Blocks serve as top-level scopes for some...
The current expression is potentially evaluated, but any declarations referenced inside that expressi...
void addAttributes(AttributeList *AL)
Concatenates two attribute lists.
Represents the results of name lookup.
bool hasGroupingParens() const
void setExtension(bool Val=true)
This scope corresponds to an enum.
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec *SS=nullptr, bool isClassName=false, bool HasTrailingDot=false, ParsedType ObjectType=ParsedType(), bool IsCtorOrDtorName=false, bool WantNontrivialTypeSourceInfo=false, IdentifierInfo **CorrectedII=nullptr)
If the identifier refers to a type name within this scope, return the declaration of that type...
static StringRef normalizeAttrName(StringRef Name)
Normalizes an attribute name by dropping prefixed and suffixed __.
void SetRangeBegin(SourceLocation Loc)
Code completion occurs following one or more template headers.
void ActOnInitializerError(Decl *Dcl)
bool setFunctionSpecForceInline(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
bool isCurrentClassNameTypo(IdentifierInfo *&II, const CXXScopeSpec *SS)
Determine whether the identifier II is a typo for the name of the class type currently being defined...
tok::TokenKind getTokenID() const
bool hasAllExtensionsSilenced()
bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
ExprResult ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, bool IsType, void *TyOrEx, const SourceRange &ArgRange)
SourceLocation getEndLoc() const
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.
bool setFunctionSpecNoreturn(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
tok::TokenKind getKind() const
Decl * ActOnTemplateDeclarator(Scope *S, MultiTemplateParamsArg TemplateParameterLists, Declarator &D)
ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope=nullptr)
bool isFunctionDeclaratorAFunctionDeclaration() const
Return true if a function declarator at this position would be a function declaration.
const SourceRange & getSourceRange() const LLVM_READONLY
static bool VersionNumberSeparator(const char Separator)
void setInvalid(bool b=true) const
VersionTuple Version
The version number at which the change occurred.
void DiagnoseUnknownTypeName(IdentifierInfo *&II, SourceLocation IILoc, Scope *S, CXXScopeSpec *SS, ParsedType &SuggestedType, bool AllowClassTemplates=false)
bool isFunctionOrFunctionTemplate() const
Whether this declaration is a function or function template.
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)
Provides definitions for the various language-specific address spaces.
void * getAnnotationValue() const
static const TSW TSW_long
bool isFunctionDeclarator(unsigned &idx) const
TST getTypeSpecType() const
void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit, bool TypeMayContainAuto)
void ClearConstexprSpec()
const void * getEofData() const
SourceLocation getModulePrivateSpecLoc() const
A class for parsing a declarator.
TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S)
void SetRangeStart(SourceLocation Loc)
NameClassificationKind getKind() const
SourceLocation getFriendSpecLoc() const
TypeResult ParseTypeName(SourceRange *Range=nullptr, Declarator::TheContext Context=Declarator::TypeNameContext, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
bool mayOmitIdentifier() const
void ActOnReenterCXXMethodParameter(Scope *S, ParmVarDecl *Param)
unsigned getTypeQualifiers() const
getTypeQualifiers - Return a set of TQs.
SourceRange getAnnotationRange() const
SourceRange of the group of tokens that this annotation token represents.
bool containsUnexpandedParameterPacks(Declarator &D)
Determine whether the given declarator contains any unexpanded parameter packs.
StringRef getName() const
Return the actual identifier string.
Represents a character-granular source range.
SourceLocation getAtomicSpecLoc() const
bool isTemplateDecl() const
returns true if this declaration is a template
TypeResult ActOnTypeName(Scope *S, Declarator &D)
void setEofData(const void *D)
void setAsmLabel(Expr *E)
SourceLocation getVolatileSpecLoc() const
DeclContext * getDeclContext()
static const TST TST_decimal64
bool isPastIdentifier() const
Decl * ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart, Declarator &D, Expr *BitfieldWidth)
void UpdateTypeRep(ParsedType Rep)
SourceLocation KeywordLoc
The location of the keyword indicating the kind of change.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
bool isConstexprSpecified() const
A class for parsing a field declarator.
bool isNot(tok::TokenKind K) const
bool hasTypeSpecifier() const
Return true if any type-specifier has been found.
SourceLocation Loc
Loc - The place where this type was defined.
static SourceLocation getMissingDeclaratorIdLoc(Declarator &D, SourceLocation Loc)
void setEllipsisLoc(SourceLocation EL)
bool SetTypeSpecSign(TSS S, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
static const TST TST_half
Wraps an identifier and optional source location for the identifier.
void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl)
The result type of a method or function.
SourceLocation getStorageClassSpecLoc() const
SourceRange VersionRange
The source range covering the version number.
SourceLocation getAnnotationEndLoc() const
static const TSW TSW_short
bool isVirtualSpecified() const
void CodeCompleteInitializer(Scope *S, Decl *D)
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
const clang::PrintingPolicy & getPrintingPolicy() const
bool SetTypeSpecWidth(TSW W, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
NameClassification ClassifyName(Scope *S, CXXScopeSpec &SS, IdentifierInfo *&Name, SourceLocation NameLoc, const Token &NextToken, bool IsAddressOfOperand, std::unique_ptr< CorrectionCandidateCallback > CCC=nullptr)
Perform name lookup on the given name, classifying it based on the results of name lookup and the fol...
This is a scope that corresponds to the parameters within a function prototype for a function declara...
void CodeCompleteTypeQualifiers(DeclSpec &DS)
static const TST TST_char32
A class for parsing a DeclSpec.
static DeclaratorChunk getParen(SourceLocation LParenLoc, SourceLocation RParenLoc)
Return a DeclaratorChunk for a paren.
bool SetConceptSpec(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc, bool lvalue)
Return a DeclaratorChunk for a reference.
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record)
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
UnqualifiedId & getName()
Retrieve the name specified by this declarator.
void FinalizeDeclaration(Decl *D)
bool isValid() const
Return true if this is a valid SourceLocation object.
TagDecl - 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
static const TST TST_union
bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
Scope * getCurScope() const
void EnterTokenStream(const Token *Toks, unsigned NumToks, bool DisableMacroExpansion, bool OwnsTokens)
Add a "macro" context to the top of the include stack, which will cause the lexer to start returning ...
static const TSS TSS_signed
bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const
Return true if we have an ObjC keyword identifier.
void setIdentifierInfo(IdentifierInfo *II)
void setGroupingParens(bool flag)
void EnterScope(unsigned ScopeFlags)
EnterScope - Start a new scope.
bool isInvalid() const
An error occurred during parsing of the scope specifier.
SourceLocation getConstexprSpecLoc() const
bool isTemplateParamScope() const
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
static DeclaratorChunk getFunction(bool HasProto, bool IsAmbiguous, SourceLocation LParenLoc, ParamInfo *Params, unsigned NumParams, SourceLocation EllipsisLoc, SourceLocation RParenLoc, unsigned TypeQuals, bool RefQualifierIsLvalueRef, SourceLocation RefQualifierLoc, SourceLocation ConstQualifierLoc, SourceLocation VolatileQualifierLoc, SourceLocation RestrictQualifierLoc, SourceLocation MutableLoc, ExceptionSpecificationType ESpecType, SourceLocation ESpecLoc, ParsedType *Exceptions, SourceRange *ExceptionRanges, unsigned NumExceptions, Expr *NoexceptExpr, CachedTokens *ExceptionSpecTokens, SourceLocation LocalRangeBegin, SourceLocation LocalRangeEnd, Declarator &TheDeclarator, TypeResult TrailingReturnType=TypeResult())
SourceLocation getVirtualSpecLoc() const
static const TST TST_typeofType
SourceLocation getBegin() const
const SourceRange & getSourceRange() const LLVM_READONLY
Get the source range that spans this declarator.
bool isLibstdcxxEagerExceptionSpecHack(const Declarator &D)
Determine if we're in a case where we need to (incorrectly) eagerly parse an exception specification ...
bool hasAttributes() const
bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const LangOptions &Lang)
bool is(tok::TokenKind K) const
bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
static DeclaratorChunk getArray(unsigned TypeQuals, bool isStatic, bool isStar, Expr *NumElts, SourceLocation LBLoc, SourceLocation RBLoc)
Return a DeclaratorChunk for an array.
bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, ParsedType ObjectType, SourceLocation &TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, ArrayRef< Decl * > Fields, SourceLocation LBrac, SourceLocation RBrac, AttributeList *AttrList)
ExprResult HandleExprEvaluationContextForTypeof(Expr *E)
bool containsPlaceholderType() const
SourceLocation getOpenLocation() const
The scope of a struct/union/class definition.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
void ActOnReenterFunctionContext(Scope *S, Decl *D)
Push the parameters of D, which must be a function, into scope.
ParserCompletionContext
Describes the context in which code completion occurs.
ParsedType ActOnDelayedDefaultTemplateArg(const IdentifierInfo &II, SourceLocation NameLoc)
For compatibility with MSVC, we delay parsing of some default template type arguments until instantia...
bool setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
TSCS getThreadStorageClassSpec() const
SmallVector< Token, 4 > CachedTokens
A set of tokens that has been cached for later parsing.
static const TST TST_auto
bool isFriendSpecified() const
static const TST TST_void
bool empty() const
Determine whether this version information is empty (e.g., all version components are zero)...
void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, SourceLocation RBraceLoc, Decl *EnumDecl, ArrayRef< Decl * > Elements, Scope *S, AttributeList *Attr)
CXXScopeSpec SS
The nested-name-specifier that precedes the template name.
static const TST TST_int128
void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, SourceLocation RBraceLoc)
void CodeCompleteTag(Scope *S, unsigned TagSpec)
void ActOnParamDefaultArgument(Decl *param, SourceLocation EqualLoc, Expr *defarg)
bool hasTagDefinition() const
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
This is a scope that corresponds to the template parameters of a C++ template. Template parameter sco...
SourceLocation getLocEnd() const LLVM_READONLY
static const TST TST_unspecified
enum clang::DeclaratorChunk::@184 Kind
bool isFirstDeclarator() const
Syntax
The style used to specify an attribute.
bool isCurrentClassName(const IdentifierInfo &II, Scope *S, const CXXScopeSpec *SS=nullptr)
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
IdentifierInfo * getName() const
static const TST TST_decimal128
PrintingPolicy getPrintingPolicy() const
Retrieve a suitable printing policy.
void takeAttributesFrom(ParsedAttributes &attrs)
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
static const TSCS TSCS___thread
void RestoreNestedNameSpecifierAnnotation(void *Annotation, SourceRange AnnotationRange, CXXScopeSpec &SS)
Given an annotation pointer for a nested-name-specifier, restore the nested-name-specifier structure...
bool mayHaveIdentifier() const
bool isKnownToGCC() const
void setNext(AttributeList *N)
unsigned getMaxArgs() const
bool SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
static const TST TST_typename
void * getAsOpaquePtr() const
void SetRangeEnd(SourceLocation Loc)
SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.
DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, ArrayRef< Decl * > Group)
DeclResult ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc, SourceLocation TemplateLoc, unsigned TagSpec, SourceLocation KWLoc, const CXXScopeSpec &SS, TemplateTy Template, SourceLocation TemplateNameLoc, SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc, AttributeList *Attr)
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)
SourceLocation getLoc() const
static bool isInvalid(SourceLocation Loc, bool *Invalid)
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.
bool isInlineSpecified() const
A template-id, e.g., f<int>.
SmallVector< TemplateParameterList *, 4 > TemplateParameterLists
CXXScopeSpec & getTypeSpecScope()
AttributeList * addNew(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ArgsUnion *args, unsigned numArgs, AttributeList::Syntax syntax, SourceLocation ellipsisLoc=SourceLocation())
Add attribute with expression arguments.
bool isUnexpandedParameterPackPermitted()
Determine whether it's possible for an unexpanded parameter pack to be valid in this location...
This is a scope that can contain a declaration. Some scopes just contain loop constructs but don't co...
IdentifierInfo * getIdentifier() const
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
static ParsedType getTypeAnnotation(Token &Tok)
getTypeAnnotation - Read a parsed type out of an annotation token.
Decl * ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS)
bool isCXX11Attribute() const
void setInvalidType(bool Val=true)
ExprResult ParseConstantExpression(TypeCastState isTypeCast=NotTypeCast)
void ActOnParamDefaultArgumentError(Decl *param, SourceLocation EqualLoc)
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".
bool isExplicitSpecified() const
SourceLocation getIdentifierLoc() const
static bool isValidAfterIdentifierInDeclarator(const Token &T)
SourceLocation ConsumeToken()
static const TSCS TSCS_thread_local
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
void ActOnParamUnparsedDefaultArgument(Decl *param, SourceLocation EqualLoc, SourceLocation ArgLoc)
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...
bool TryAnnotateTypeOrScopeToken(bool EnteringContext=false, bool NeedType=false)
static const TST TST_bool
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
bool diagnoseIdentifier() const
bool isTypeSpecOwned() const
static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc, SourceLocation ConstQualLoc, SourceLocation VolatileQualLoc, SourceLocation RestrictQualLoc, SourceLocation AtomicQualLoc)
Return a DeclaratorChunk for a pointer.
Defines the clang::TargetInfo interface.
void ExtendWithDeclSpec(const DeclSpec &DS)
static const TSW TSW_longlong
static Decl::Kind getKind(const Decl *D)
bool isTypeAltiVecVector() const
unsigned getParsedSpecifiers() const
Return a bitmask of which flavors of specifiers this DeclSpec includes.
bool isValid() const
A scope specifier is present, and it refers to a real scope.
unsigned getLength() const
static bool attributeIsTypeArgAttr(const IdentifierInfo &II)
Determine whether the given attribute parses a type argument.
static const TST TST_atomic
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7)...
bool isDeclspecAttribute() const
static const TST TST_struct
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
const DeclaratorChunk & getTypeObject(unsigned i) const
void setLocation(SourceLocation L)
AttributeList * getNext() const
A trivial tuple used to represent a source range.
SourceLocation getLocation() const
bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
bool isInvalidType() const
SourceLocation EndLocation
The location of the last token that describes this unqualified-id.
static const TSCS TSCS__Thread_local
bool isFirstDeclarationOfMember()
Returns true if this declares a real member and not a friend.
SourceLocation getLocEnd() const LLVM_READONLY
void SetRangeEnd(SourceLocation Loc)
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
Attr - This represents one attribute.
ParsedAttributes & getAttributes()
void startToken()
Reset all flags to cleared.
AttributeList * addNewTypeTagForDatatype(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *argumentKind, ParsedType matchingCType, bool layoutCompatible, bool mustBeNull, AttributeList::Syntax syntax)
Add type_tag_for_datatype attribute.
const DeclSpec & getDeclSpec() const
Decl * ActOnDeclarator(Scope *S, Declarator &D)
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.
SourceLocation getEllipsisLoc() const
unsigned ActOnReenterTemplateScope(Scope *S, Decl *Template)
IdentifierInfo * getIdentifierInfo() const