28 #include "llvm/ADT/SmallSet.h"
29 #include "llvm/ADT/SmallString.h"
30 #include "llvm/ADT/StringSwitch.h"
31 #include "llvm/Support/ScopedPrinter.h"
33 using namespace clang;
49 DeclSpecContext DSC = getDeclSpecContextFromDeclaratorContext(Context);
50 if (DSC == DSC_normal)
51 DSC = DSC_type_specifier;
57 ParseSpecifierQualifierList(DS, AS, DSC);
63 ParseDeclarator(DeclaratorInfo);
76 #define CLANG_ATTR_LATE_PARSED_LIST
77 return llvm::StringSwitch<bool>(II.
getName())
78 #include
"clang/Parse/AttrParserStringSwitches.inc"
80 #undef CLANG_ATTR_LATE_PARSED_LIST
126 LateParsedAttrList *LateAttrs,
128 assert(Tok.
is(tok::kw___attribute) &&
"Not a GNU attribute list!");
130 while (Tok.
is(tok::kw___attribute)) {
132 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
137 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
"(")) {
156 if (Tok.
isNot(tok::l_paren)) {
157 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
164 ParseGNUAttributeArgs(AttrName, AttrNameLoc, attrs, endLoc,
nullptr,
170 LateParsedAttribute *LA =
171 new LateParsedAttribute(
this, *AttrName, AttrNameLoc);
172 LateAttrs->push_back(LA);
176 if (!ClassStack.empty() && !LateAttrs->parseSoon())
177 getCurrentClass().LateParsedDeclarations.push_back(LA);
180 ConsumeAndStoreUntil(tok::r_paren, LA->Toks,
true,
false);
185 LA->Toks.push_back(Eof);
188 if (ExpectAndConsume(tok::r_paren))
191 if (ExpectAndConsume(tok::r_paren))
200 if (Name.size() >= 4 && Name.startswith(
"__") && Name.endswith(
"__"))
201 Name = Name.drop_front(2).drop_back(2);
207 #define CLANG_ATTR_IDENTIFIER_ARG_LIST
209 #include "clang/Parse/AttrParserStringSwitches.inc"
211 #undef CLANG_ATTR_IDENTIFIER_ARG_LIST
216 #define CLANG_ATTR_TYPE_ARG_LIST
218 #include "clang/Parse/AttrParserStringSwitches.inc"
220 #undef CLANG_ATTR_TYPE_ARG_LIST
226 #define CLANG_ATTR_ARG_CONTEXT_LIST
228 #include "clang/Parse/AttrParserStringSwitches.inc"
230 #undef CLANG_ATTR_ARG_CONTEXT_LIST
234 assert(Tok.
is(tok::identifier) &&
"expected an identifier");
250 Parens.consumeOpen();
253 if (Tok.
isNot(tok::r_paren))
256 if (Parens.consumeClose())
264 SourceRange(AttrNameLoc, Parens.getCloseLocation()),
265 ScopeName, ScopeLoc, T.
get(), Syntax);
268 ScopeName, ScopeLoc,
nullptr, 0, Syntax);
271 unsigned Parser::ParseAttributeArgsCommon(
279 if (Tok.
is(tok::identifier)) {
290 IsIdentifierArg = Next.
isOneOf(tok::r_paren, tok::comma);
294 ArgExprs.push_back(ParseIdentifierLoc());
297 if (!ArgExprs.empty() ? Tok.
is(tok::comma) : Tok.
isNot(tok::r_paren)) {
299 if (!ArgExprs.empty())
304 std::unique_ptr<EnterExpressionEvaluationContext> Unevaluated;
311 if (ArgExpr.isInvalid()) {
315 ArgExprs.push_back(ArgExpr.get());
321 if (!ExpectAndConsume(tok::r_paren)) {
324 ArgExprs.data(), ArgExprs.size(), Syntax);
330 return static_cast<unsigned>(ArgExprs.size());
344 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
349 if (AttrKind == AttributeList::AT_Availability) {
350 ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
353 }
else if (AttrKind == AttributeList::AT_ObjCBridgeRelated) {
354 ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
355 ScopeName, ScopeLoc, Syntax);
357 }
else if (AttrKind == AttributeList::AT_TypeTagForDatatype) {
358 ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
359 ScopeName, ScopeLoc, Syntax);
362 ParseAttributeWithTypeArg(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
369 std::unique_ptr<ParseScope> PrototypeScope;
376 for (
unsigned i = 0; i != FTI.
NumParams; ++i) {
382 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
401 if (AttrName->
getName() ==
"property") {
407 T.expectAndConsume(diag::err_expected_lparen_after,
416 bool HasInvalidAccessor =
false;
421 if (!Tok.
is(tok::identifier)) {
423 if (Tok.
is(tok::r_paren) && !HasInvalidAccessor &&
424 AccessorNames[AK_Put] ==
nullptr &&
425 AccessorNames[AK_Get] ==
nullptr) {
426 Diag(AttrNameLoc, diag::err_ms_property_no_getter_or_putter);
437 if (KindStr ==
"get") {
439 }
else if (KindStr ==
"put") {
443 }
else if (KindStr ==
"set") {
444 Diag(KindLoc, diag::err_ms_property_has_set_accessor)
451 Diag(KindLoc, diag::err_ms_property_missing_accessor_kind);
453 HasInvalidAccessor =
true;
454 goto next_property_accessor;
458 Diag(KindLoc, diag::err_ms_property_unknown_accessor);
459 HasInvalidAccessor =
true;
478 if (!Tok.
is(tok::identifier)) {
483 if (Kind == AK_Invalid) {
485 }
else if (AccessorNames[Kind] !=
nullptr) {
487 Diag(KindLoc, diag::err_ms_property_duplicate_accessor) << KindStr;
493 next_property_accessor:
499 if (Tok.
is(tok::r_paren))
502 Diag(Tok.
getLocation(), diag::err_ms_property_expected_comma_or_rparen);
507 if (!HasInvalidAccessor)
509 AccessorNames[AK_Get], AccessorNames[AK_Put],
512 return !HasInvalidAccessor;
516 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs,
nullptr,
nullptr,
523 Diag(OpenParenLoc, diag::err_attribute_requires_arguments) << AttrName;
537 assert(
getLangOpts().DeclSpecKeyword &&
"__declspec keyword is not enabled");
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);
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:
614 case tok::kw___uptr: {
617 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
627 void Parser::DiagnoseAndSkipExtendedMicrosoftTypeAttributes() {
633 Diag(StartLoc, diag::warn_microsoft_qualifiers_ignored) << Range;
643 case tok::kw_volatile:
644 case tok::kw___fastcall:
645 case tok::kw___stdcall:
646 case tok::kw___thiscall:
647 case tok::kw___cdecl:
648 case tok::kw___vectorcall:
649 case tok::kw___ptr32:
650 case tok::kw___ptr64:
652 case tok::kw___unaligned:
665 while (Tok.
is(tok::kw___pascal)) {
668 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
675 while (Tok.
is(tok::kw___kernel)) {
678 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
686 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
694 case tok::kw__Nonnull:
695 case tok::kw__Nullable:
696 case tok::kw__Null_unspecified: {
700 Diag(AttrNameLoc, diag::ext_nullability)
702 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
713 return (Separator ==
'.' || Separator ==
'_');
725 if (!Tok.
is(tok::numeric_constant)) {
726 Diag(Tok, diag::err_expected_version);
738 const char *ThisTokBegin = &Buffer[0];
741 bool Invalid =
false;
742 unsigned ActualLength = PP.
getSpelling(Tok, ThisTokBegin, &Invalid);
747 unsigned AfterMajor = 0;
749 while (AfterMajor < ActualLength &&
isDigit(ThisTokBegin[AfterMajor])) {
750 Major = Major * 10 + ThisTokBegin[AfterMajor] -
'0';
754 if (AfterMajor == 0) {
755 Diag(Tok, diag::err_expected_version);
761 if (AfterMajor == ActualLength) {
766 Diag(Tok, diag::err_zero_version);
773 const char AfterMajorSeparator = ThisTokBegin[AfterMajor];
775 || (AfterMajor + 1 == ActualLength)) {
776 Diag(Tok, diag::err_expected_version);
783 unsigned AfterMinor = AfterMajor + 1;
785 while (AfterMinor < ActualLength &&
isDigit(ThisTokBegin[AfterMinor])) {
786 Minor = Minor * 10 + ThisTokBegin[AfterMinor] -
'0';
790 if (AfterMinor == ActualLength) {
794 if (Major == 0 && Minor == 0) {
795 Diag(Tok, diag::err_zero_version);
799 return VersionTuple(Major, Minor, (AfterMajorSeparator ==
'_'));
802 const char AfterMinorSeparator = ThisTokBegin[AfterMinor];
805 Diag(Tok, diag::err_expected_version);
812 if (AfterMajorSeparator != AfterMinorSeparator)
813 Diag(Tok, diag::warn_expected_consistent_version_separator);
816 unsigned AfterSubminor = AfterMinor + 1;
817 unsigned Subminor = 0;
818 while (AfterSubminor < ActualLength &&
isDigit(ThisTokBegin[AfterSubminor])) {
819 Subminor = Subminor * 10 + ThisTokBegin[AfterSubminor] -
'0';
823 if (AfterSubminor != ActualLength) {
824 Diag(Tok, diag::err_expected_version);
830 return VersionTuple(Major, Minor, Subminor, (AfterMajorSeparator ==
'_'));
858 void Parser::ParseAvailabilityAttribute(
IdentifierInfo &Availability,
865 enum { Introduced, Deprecated, Obsoleted,
Unknown };
871 if (T.consumeOpen()) {
872 Diag(Tok, diag::err_expected) << tok::l_paren;
877 if (Tok.
isNot(tok::identifier)) {
878 Diag(Tok, diag::err_availability_expected_platform);
892 if (ExpectAndConsume(tok::comma)) {
899 if (!Ident_introduced) {
913 if (Tok.
isNot(tok::identifier)) {
914 Diag(Tok, diag::err_availability_expected_change);
921 if (Keyword == Ident_strict) {
923 Diag(KeywordLoc, diag::err_availability_redundant)
926 StrictLoc = KeywordLoc;
930 if (Keyword == Ident_unavailable) {
931 if (UnavailableLoc.
isValid()) {
932 Diag(KeywordLoc, diag::err_availability_redundant)
935 UnavailableLoc = KeywordLoc;
939 if (Tok.
isNot(tok::equal)) {
940 Diag(Tok, diag::err_expected_after) << Keyword << tok::equal;
945 if (Keyword == Ident_message || Keyword == Ident_replacement) {
946 if (Tok.
isNot(tok::string_literal)) {
947 Diag(Tok, diag::err_expected_string_literal)
952 if (Keyword == Ident_message)
953 MessageExpr = ParseStringLiteralExpression();
955 ReplacementExpr = ParseStringLiteralExpression();
958 cast_or_null<StringLiteral>(MessageExpr.
get())) {
959 if (MessageStringLiteral->getCharByteWidth() != 1) {
960 Diag(MessageStringLiteral->getSourceRange().getBegin(),
961 diag::err_expected_string_literal)
967 if (Keyword == Ident_message)
975 if ((Keyword == Ident_introduced || Keyword == Ident_deprecated) &&
976 Tok.
is(tok::identifier)) {
980 if (Keyword == Ident_introduced)
981 UnavailableLoc = KeywordLoc;
989 if (Version.
empty()) {
995 if (Keyword == Ident_introduced)
997 else if (Keyword == Ident_deprecated)
999 else if (Keyword == Ident_obsoleted)
1004 if (Index < Unknown) {
1005 if (!Changes[Index].KeywordLoc.
isInvalid()) {
1006 Diag(KeywordLoc, diag::err_availability_redundant)
1009 Changes[Index].VersionRange.
getEnd());
1013 Changes[Index].
Version = Version;
1016 Diag(KeywordLoc, diag::err_availability_unknown_change)
1017 << Keyword << VersionRange;
1023 if (T.consumeClose())
1027 *endLoc = T.getCloseLocation();
1031 if (UnavailableLoc.
isValid()) {
1032 bool Complained =
false;
1033 for (
unsigned Index = Introduced; Index !=
Unknown; ++Index) {
1034 if (Changes[Index].KeywordLoc.
isValid()) {
1036 Diag(UnavailableLoc, diag::warn_availability_and_unavailable)
1038 Changes[Index].VersionRange.
getEnd());
1049 attrs.
addNew(&Availability,
1050 SourceRange(AvailabilityLoc, T.getCloseLocation()),
1051 ScopeName, ScopeLoc,
1053 Changes[Introduced],
1054 Changes[Deprecated],
1056 UnavailableLoc, MessageExpr.
get(),
1071 void Parser::ParseObjCBridgeRelatedAttribute(
IdentifierInfo &ObjCBridgeRelated,
1080 if (T.consumeOpen()) {
1081 Diag(Tok, diag::err_expected) << tok::l_paren;
1086 if (Tok.
isNot(tok::identifier)) {
1087 Diag(Tok, diag::err_objcbridge_related_expected_related_class);
1092 if (ExpectAndConsume(tok::comma)) {
1099 if (Tok.
is(tok::identifier)) {
1100 ClassMethod = ParseIdentifierLoc();
1102 Diag(Tok, diag::err_objcbridge_related_selector_name);
1108 if (Tok.
is(tok::colon))
1109 Diag(Tok, diag::err_objcbridge_related_selector_name);
1111 Diag(Tok, diag::err_expected) << tok::comma;
1118 if (Tok.
is(tok::identifier))
1119 InstanceMethod = ParseIdentifierLoc();
1120 else if (Tok.
isNot(tok::r_paren)) {
1121 Diag(Tok, diag::err_expected) << tok::r_paren;
1127 if (T.consumeClose())
1131 *endLoc = T.getCloseLocation();
1134 attrs.
addNew(&ObjCBridgeRelated,
1135 SourceRange(ObjCBridgeRelatedLoc, T.getCloseLocation()),
1136 ScopeName, ScopeLoc,
1146 void Parser::LateParsedDeclaration::ParseLexedAttributes() {}
1148 void Parser::LateParsedClass::ParseLexedAttributes() {
1149 Self->ParseLexedAttributes(*Class);
1152 void Parser::LateParsedAttribute::ParseLexedAttributes() {
1153 Self->ParseLexedAttribute(*
this,
true,
false);
1158 void Parser::ParseLexedAttributes(ParsingClass &Class) {
1161 bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope;
1164 if (HasTemplateScope)
1168 bool AlreadyHasClassScope = Class.TopLevelClass;
1170 ParseScope ClassScope(
this, ScopeFlags, !AlreadyHasClassScope);
1171 ParseScopeFlags ClassScopeFlags(
this, ScopeFlags, AlreadyHasClassScope);
1174 if (!AlreadyHasClassScope)
1176 Class.TagOrTemplate);
1177 if (!Class.LateParsedDeclarations.empty()) {
1178 for (
unsigned i = 0, ni = Class.LateParsedDeclarations.size(); i < ni; ++i){
1179 Class.LateParsedDeclarations[i]->ParseLexedAttributes();
1183 if (!AlreadyHasClassScope)
1185 Class.TagOrTemplate);
1189 void Parser::ParseLexedAttributeList(LateParsedAttrList &LAs,
Decl *D,
1190 bool EnterScope,
bool OnDefinition) {
1191 assert(LAs.parseSoon() &&
1192 "Attribute list should be marked for immediate parsing.");
1193 for (
unsigned i = 0, ni = LAs.size(); i < ni; ++i) {
1196 ParseLexedAttribute(*LAs[i], EnterScope, OnDefinition);
1207 void Parser::ParseLexedAttribute(LateParsedAttribute &LA,
1208 bool EnterScope,
bool OnDefinition) {
1216 LA.Toks.push_back(AttrEnd);
1220 LA.Toks.push_back(Tok);
1221 PP.EnterTokenStream(LA.Toks,
true);
1223 ConsumeAnyToken(
true);
1228 if (LA.Decls.size() > 0) {
1229 Decl *D = LA.Decls[0];
1231 RecordDecl *RD = dyn_cast_or_null<RecordDecl>(D->getDeclContext());
1237 if (LA.Decls.size() == 1) {
1239 bool HasTemplateScope = EnterScope && D->isTemplateDecl();
1241 if (HasTemplateScope)
1245 bool HasFunScope = EnterScope && D->isFunctionOrFunctionTemplate();
1250 ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, &endLoc,
1258 if (HasTemplateScope) {
1264 ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, &endLoc,
1269 Diag(Tok, diag::warn_attribute_no_decl) << LA.AttrName.getName();
1275 Diag(Tok, diag::warn_attribute_on_function_definition)
1278 for (
unsigned i = 0, ni = LA.Decls.size(); i < ni; ++i)
1290 void Parser::ParseTypeTagForDatatypeAttribute(
IdentifierInfo &AttrName,
1297 assert(Tok.
is(tok::l_paren) &&
"Attribute arg list not starting with '('");
1302 if (Tok.
isNot(tok::identifier)) {
1303 Diag(Tok, diag::err_expected) << tok::identifier;
1309 if (ExpectAndConsume(tok::comma)) {
1321 bool LayoutCompatible =
false;
1322 bool MustBeNull =
false;
1324 if (Tok.
isNot(tok::identifier)) {
1325 Diag(Tok, diag::err_expected) << tok::identifier;
1330 if (Flag->
isStr(
"layout_compatible"))
1331 LayoutCompatible =
true;
1332 else if (Flag->
isStr(
"must_be_null"))
1335 Diag(Tok, diag::err_type_safety_unknown_flag) << Flag;
1342 if (!T.consumeClose()) {
1344 ArgumentKind, MatchingCType.
get(),
1345 LayoutCompatible, MustBeNull, Syntax);
1349 *EndLoc = T.getCloseLocation();
1360 bool Parser::DiagnoseProhibitedCXX11Attribute() {
1361 assert(Tok.
is(tok::l_square) &&
NextToken().
is(tok::l_square));
1363 switch (isCXX11AttributeSpecifier(
true)) {
1364 case CAK_NotAttributeSpecifier:
1368 case CAK_InvalidAttributeSpecifier:
1372 case CAK_AttributeSpecifier:
1377 assert(Tok.
is(tok::r_square) &&
"isCXX11AttributeSpecifier lied");
1379 Diag(BeginLoc, diag::err_attributes_not_allowed)
1383 llvm_unreachable(
"All cases handled above.");
1390 void Parser::DiagnoseMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs,
1392 assert((Tok.
is(tok::l_square) &&
NextToken().
is(tok::l_square)) ||
1393 Tok.
is(tok::kw_alignas));
1397 ParseCXX11Attributes(Attrs);
1400 Diag(Loc, diag::err_attributes_not_allowed)
1405 void Parser::DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs) {
1406 Diag(attrs.Range.getBegin(), diag::err_attributes_not_allowed)
1410 void Parser::ProhibitCXX11Attributes(ParsedAttributesWithRange &attrs) {
1414 Diag(AttrList->
getLoc(), diag::err_attribute_not_type_attr)
1418 AttrList = AttrList->
getNext();
1424 void Parser::handleDeclspecAlignBeforeClassKey(ParsedAttributesWithRange &Attrs,
1438 if (AL->
getKind() == AttributeList::AT_Aligned &&
1480 ParsedAttributesWithRange &attrs) {
1486 Decl *SingleDecl =
nullptr;
1487 Decl *OwnedType =
nullptr;
1489 case tok::kw_template:
1490 case tok::kw_export:
1491 ProhibitAttributes(attrs);
1492 SingleDecl = ParseDeclarationStartingWithTemplate(Context, DeclEnd);
1494 case tok::kw_inline:
1497 ProhibitAttributes(attrs);
1499 return ParseNamespace(Context, DeclEnd, InlineLoc);
1501 return ParseSimpleDeclaration(Context, DeclEnd, attrs,
1503 case tok::kw_namespace:
1504 ProhibitAttributes(attrs);
1505 return ParseNamespace(Context, DeclEnd);
1507 SingleDecl = ParseUsingDirectiveOrDeclaration(Context, ParsedTemplateInfo(),
1508 DeclEnd, attrs, &OwnedType);
1510 case tok::kw_static_assert:
1511 case tok::kw__Static_assert:
1512 ProhibitAttributes(attrs);
1513 SingleDecl = ParseStaticAssertDeclaration(DeclEnd);
1516 return ParseSimpleDeclaration(Context, DeclEnd, attrs,
true);
1542 Parser::ParseSimpleDeclaration(
unsigned Context,
1544 ParsedAttributesWithRange &Attrs,
1545 bool RequireSemi, ForRangeInit *FRI) {
1549 DeclSpecContext DSContext = getDeclSpecContextFromDeclaratorContext(Context);
1550 ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(),
AS_none, DSContext);
1555 DiagnoseMissingSemiAfterTagDefinition(DS,
AS_none, DSContext))
1560 if (Tok.
is(tok::semi)) {
1561 ProhibitAttributes(Attrs);
1567 DS.complete(TheDecl);
1569 Decl* decls[] = {AnonRecord, TheDecl};
1576 return ParseDeclGroup(DS, Context, &DeclEnd, FRI);
1581 bool Parser::MightBeDeclarator(
unsigned Context) {
1583 case tok::annot_cxxscope:
1584 case tok::annot_template_id:
1586 case tok::code_completion:
1587 case tok::coloncolon:
1589 case tok::kw___attribute:
1590 case tok::kw_operator:
1606 case tok::identifier:
1608 case tok::code_completion:
1609 case tok::coloncolon:
1612 case tok::equalequal:
1613 case tok::kw_alignas:
1615 case tok::kw___attribute:
1633 case tok::identifier:
1656 if (Tok.
isOneOf(tok::comma, tok::l_brace, tok::kw_try)) {
1680 case tok::kw_inline:
1685 (!ParsingInObjCContainer || CurParsedObjCImpl))
1689 case tok::kw_namespace:
1694 (!ParsingInObjCContainer || CurParsedObjCImpl))
1701 ParsingInObjCContainer)
1713 case tok::annot_module_begin:
1714 case tok::annot_module_end:
1715 case tok::annot_module_include:
1732 ForRangeInit *FRI) {
1738 if (!D.hasName() && !D.mayOmitIdentifier()) {
1746 LateParsedAttrList LateParsedAttrs(
true);
1747 if (D.isFunctionDeclarator()) {
1748 MaybeParseGNUAttributes(D, &LateParsedAttrs);
1753 if (Tok.
is(tok::kw__Noreturn)) {
1755 const char *PrevSpec;
1761 MaybeParseGNUAttributes(D, &LateParsedAttrs);
1762 Fixit &= Tok.
isOneOf(tok::semi, tok::l_brace, tok::kw_try);
1764 Diag(Loc, diag::err_c11_noreturn_misplaced)
1766 << (Fixit ?
FixItHint::CreateInsertion(D.getLocStart(),
"_Noreturn ")
1772 if (D.isFunctionDeclarator() &&
1776 !isDeclarationAfterDeclarator()) {
1782 if (isStartOfFunctionDefinition(D)) {
1784 Diag(Tok, diag::err_function_declared_typedef);
1791 ParseFunctionDefinition(D, ParsedTemplateInfo(), &LateParsedAttrs);
1795 if (isDeclarationSpecifier()) {
1803 Diag(Tok, diag::err_expected_fn_body);
1808 if (Tok.
is(tok::l_brace)) {
1809 Diag(Tok, diag::err_function_definition_not_allowed);
1816 if (ParseAsmAttributesAfterDeclarator(D))
1825 if (FRI && (Tok.
is(tok::colon) || isTokIdentifier_in())) {
1826 bool IsForRangeLoop =
false;
1828 IsForRangeLoop =
true;
1829 if (Tok.
is(tok::l_brace))
1830 FRI->RangeExpr = ParseBraceInitializer();
1839 D.complete(ThisDecl);
1844 Decl *FirstDecl = ParseDeclarationAfterDeclaratorAndAttributes(
1845 D, ParsedTemplateInfo(), FRI);
1846 if (LateParsedAttrs.size() > 0)
1847 ParseLexedAttributeList(LateParsedAttrs, FirstDecl,
true,
false);
1848 D.complete(FirstDecl);
1850 DeclsInGroup.push_back(FirstDecl);
1858 if (Tok.
isAtStartOfLine() && ExpectSemi && !MightBeDeclarator(Context)) {
1862 Diag(CommaLoc, diag::err_expected_semi_declaration)
1870 D.setCommaLoc(CommaLoc);
1879 MaybeParseGNUAttributes(D);
1883 DiagnoseAndSkipExtendedMicrosoftTypeAttributes();
1886 if (!D.isInvalidType()) {
1887 Decl *ThisDecl = ParseDeclarationAfterDeclarator(D);
1888 D.complete(ThisDecl);
1890 DeclsInGroup.push_back(ThisDecl);
1899 ? diag::err_invalid_token_after_toplevel_declarator
1900 : diag::err_expected_semi_declaration)) {
1904 if (!isDeclarationSpecifier()) {
1915 bool Parser::ParseAsmAttributesAfterDeclarator(
Declarator &D) {
1917 if (Tok.
is(tok::kw_asm)) {
1920 if (AsmLabel.isInvalid()) {
1929 MaybeParseGNUAttributes(D);
1955 Decl *Parser::ParseDeclarationAfterDeclarator(
1956 Declarator &D,
const ParsedTemplateInfo &TemplateInfo) {
1957 if (ParseAsmAttributesAfterDeclarator(D))
1960 return ParseDeclarationAfterDeclaratorAndAttributes(D, TemplateInfo);
1963 Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
1964 Declarator &D,
const ParsedTemplateInfo &TemplateInfo, ForRangeInit *FRI) {
1966 Decl *ThisDecl =
nullptr;
1967 switch (TemplateInfo.Kind) {
1968 case ParsedTemplateInfo::NonTemplate:
1972 case ParsedTemplateInfo::Template:
1973 case ParsedTemplateInfo::ExplicitSpecialization: {
1975 *TemplateInfo.TemplateParams,
1977 if (
VarTemplateDecl *VT = dyn_cast_or_null<VarTemplateDecl>(ThisDecl))
1980 ThisDecl = VT->getTemplatedDecl();
1983 case ParsedTemplateInfo::ExplicitInstantiation: {
1984 if (Tok.
is(tok::semi)) {
1986 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc, D);
1991 ThisDecl = ThisRes.
get();
1999 Diag(Tok, diag::err_template_defn_explicit_instantiation)
2006 diag::err_explicit_instantiation_with_definition)
2014 LAngleLoc,
nullptr));
2028 if (isTokenEqualOrEqualTypo()) {
2031 if (Tok.
is(tok::kw_delete)) {
2037 }
else if (Tok.
is(tok::kw_default)) {
2049 if (Tok.
is(tok::code_completion)) {
2061 Diag(EqualLoc, diag::err_single_decl_assign_in_for_range)
2065 FRI->ColonLoc = EqualLoc;
2067 FRI->RangeExpr = Init;
2075 if (Init.isInvalid()) {
2077 StopTokens.push_back(tok::comma);
2080 StopTokens.push_back(tok::r_paren);
2085 false, TypeContainsAuto);
2087 }
else if (Tok.
is(tok::l_paren)) {
2093 CommaLocsTy CommaLocs;
2100 if (ParseExpressionList(Exprs, CommaLocs, [&] {
2102 cast<VarDecl>(ThisDecl)->getType()->getCanonicalTypeInternal(),
2103 ThisDecl->getLocation(), Exprs);
2116 assert(!Exprs.empty() && Exprs.size()-1 == CommaLocs.size() &&
2117 "Unexpected number of commas!");
2125 T.getCloseLocation(),
2128 true, TypeContainsAuto);
2130 }
else if (
getLangOpts().CPlusPlus11 && Tok.
is(tok::l_brace) &&
2133 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
2147 if (Init.isInvalid()) {
2151 true, TypeContainsAuto);
2169 DeclSpecContext DSC) {
2173 ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS, DSC);
2178 Diag(Tok, diag::err_expected_type);
2181 Diag(Tok, diag::err_typename_requires_specqual);
2192 diag::err_typename_invalid_storageclass);
2233 return T.
isOneOf(tok::l_square, tok::l_paren, tok::r_paren, tok::semi,
2234 tok::comma, tok::equal, tok::kw_asm, tok::l_brace,
2248 const ParsedTemplateInfo &TemplateInfo,
2250 ParsedAttributesWithRange &Attrs) {
2251 assert(Tok.
is(tok::identifier) &&
"should have identifier");
2273 if (!isTypeSpecifier(DSC) && !
getLangOpts().CPlusPlus &&
2286 AnnotateScopeToken(*SS,
false);
2297 DSC == DSC_template_type_arg)) {
2298 const char *PrevSpec;
2314 if (SS ==
nullptr) {
2315 const char *TagName =
nullptr, *FixitTagName =
nullptr;
2321 TagName=
"enum" ; FixitTagName =
"enum " ; TagKind=tok::kw_enum ;
break;
2323 TagName=
"union" ; FixitTagName =
"union " ;TagKind=tok::kw_union ;
break;
2325 TagName=
"struct"; FixitTagName =
"struct ";TagKind=tok::kw_struct;
break;
2327 TagName=
"__interface"; FixitTagName =
"__interface ";
2328 TagKind=tok::kw___interface;
break;
2330 TagName=
"class" ; FixitTagName =
"class " ;TagKind=tok::kw_class ;
break;
2338 Diag(Loc, diag::err_use_of_tag_name_without_tag)
2339 << TokenName << TagName <<
getLangOpts().CPlusPlus
2345 Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
2346 << TokenName << TagName;
2350 if (TagKind == tok::kw_enum)
2351 ParseEnumSpecifier(Loc, DS, TemplateInfo, AS, DSC_normal);
2353 ParseClassSpecifier(TagKind, Loc, DS, TemplateInfo, AS,
2354 false, DSC_normal, Attrs);
2361 if (!isTypeSpecifier(DSC) &&
2362 (!SS || DSC == DSC_top_level || DSC == DSC_class)) {
2366 case tok::l_paren: {
2373 TentativeParsingAction PA(*
this);
2375 TPResult TPR = TryParseDeclarator(
false);
2386 if (DSC == DSC_class || (DSC == DSC_top_level && SS)) {
2389 Diag(Loc, diag::err_constructor_bad_name)
2406 AnnotateScopeToken(*SS,
false);
2428 const char *PrevSpec;
2459 Parser::DeclSpecContext
2460 Parser::getDeclSpecContextFromDeclaratorContext(
unsigned Context) {
2464 return DSC_top_level;
2466 return DSC_template_type_arg;
2468 return DSC_trailing;
2471 return DSC_alias_declaration;
2487 if (isTypeIdInParens()) {
2512 assert(Tok.
isOneOf(tok::kw_alignas, tok::kw__Alignas) &&
2513 "Not an alignment-specifier!");
2519 if (T.expectAndConsume())
2523 ExprResult ArgExpr = ParseAlignArgument(T.getOpenLocation(), EllipsisLoc);
2531 *EndLoc = T.getCloseLocation();
2534 ArgExprs.push_back(ArgExpr.
get());
2535 Attrs.
addNew(KWName, KWLoc,
nullptr, KWLoc, ArgExprs.data(), 1,
2548 DeclSpecContext DSContext,
2549 LateParsedAttrList *LateAttrs) {
2552 bool EnteringContext = (DSContext == DSC_class || DSContext == DSC_top_level);
2555 Tok.
isOneOf(tok::identifier, tok::coloncolon, tok::kw_decltype,
2556 tok::annot_template_id) &&
2562 bool HasScope = Tok.
is(tok::annot_cxxscope);
2568 bool MightBeDeclarator =
true;
2569 if (Tok.
isOneOf(tok::kw_typename, tok::annot_typename)) {
2571 MightBeDeclarator =
false;
2572 }
else if (AfterScope.
is(tok::annot_template_id)) {
2578 MightBeDeclarator =
false;
2579 }
else if (AfterScope.
is(tok::identifier)) {
2580 const Token &Next = HasScope ? GetLookAheadToken(2) : NextToken();
2584 if (Next.
isOneOf(tok::star, tok::amp, tok::ampamp, tok::identifier,
2585 tok::annot_cxxscope, tok::coloncolon)) {
2587 MightBeDeclarator =
false;
2588 }
else if (HasScope) {
2599 switch (Classification.
getKind()) {
2606 llvm_unreachable(
"typo correction and nested name specifiers not "
2612 MightBeDeclarator =
false;
2625 if (MightBeDeclarator)
2630 diag::err_expected_after)
2641 ParsedTemplateInfo NotATemplate;
2642 ParseDeclarationSpecifiers(DS, NotATemplate, AS, DSContext, LateAttrs);
2673 void Parser::ParseDeclarationSpecifiers(
DeclSpec &DS,
2674 const ParsedTemplateInfo &TemplateInfo,
2676 DeclSpecContext DSContext,
2677 LateParsedAttrList *LateAttrs) {
2686 bool EnteringContext = (DSContext == DSC_class || DSContext == DSC_top_level);
2687 bool AttrsLastTime =
false;
2688 ParsedAttributesWithRange attrs(AttrFactory);
2693 bool isStorageClass =
false;
2694 const char *PrevSpec =
nullptr;
2695 unsigned DiagID = 0;
2715 ProhibitAttributes(attrs);
2720 ProhibitCXX11Attributes(attrs);
2727 DS.
Finish(Actions, Policy);
2731 case tok::kw_alignas:
2733 goto DoneWithDeclSpec;
2735 ProhibitAttributes(attrs);
2742 ParseCXX11Attributes(attrs);
2743 AttrsLastTime =
true;
2746 case tok::code_completion: {
2749 bool AllowNonIdentifiers
2755 bool AllowNestedNameSpecifiers
2756 = DSContext == DSC_top_level ||
2760 AllowNonIdentifiers,
2761 AllowNestedNameSpecifiers);
2762 return cutOffParsing();
2767 else if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate)
2770 else if (DSContext == DSC_class)
2772 else if (CurParsedObjCImpl)
2776 return cutOffParsing();
2779 case tok::coloncolon:
2784 goto DoneWithDeclSpec;
2786 if (Tok.
is(tok::coloncolon))
2787 goto DoneWithDeclSpec;
2790 case tok::annot_cxxscope: {
2792 goto DoneWithDeclSpec;
2801 if (Next.
is(tok::annot_template_id) &&
2826 if ((DSContext == DSC_top_level || DSContext == DSC_class) &&
2829 if (isConstructorDeclarator(
false)) {
2834 goto DoneWithDeclSpec;
2842 diag::err_out_of_line_template_id_type_names_constructor)
2843 << TemplateId->
Name << 0 ;
2848 assert(Tok.
is(tok::annot_template_id) &&
2849 "ParseOptionalCXXScopeSpecifier not working");
2850 AnnotateTemplateIdTokenAsType();
2854 if (Next.
is(tok::annot_typename)) {
2861 PrevSpec, DiagID, T, Policy);
2871 if (Next.
isNot(tok::identifier))
2872 goto DoneWithDeclSpec;
2876 if ((DSContext == DSC_top_level || DSContext == DSC_class) &&
2879 if (isConstructorDeclarator(
false))
2880 goto DoneWithDeclSpec;
2889 diag::err_out_of_line_template_id_type_names_constructor)
2905 ParsedAttributesWithRange Attrs(AttrFactory);
2906 if (ParseImplicitInt(DS, &SS, TemplateInfo, AS, DSContext, Attrs)) {
2907 if (!Attrs.
empty()) {
2908 AttrsLastTime =
true;
2909 attrs.takeAllFrom(Attrs);
2913 goto DoneWithDeclSpec;
2920 DiagID, TypeRep, Policy);
2930 case tok::annot_typename: {
2934 goto DoneWithDeclSpec;
2952 case tok::kw___is_signed:
2963 TryKeywordIdentFallback(
true);
2966 goto DoneWithDeclSpec;
2969 case tok::kw___super:
2970 case tok::kw_decltype:
2971 case tok::identifier: {
2976 goto DoneWithDeclSpec;
2983 goto DoneWithDeclSpec;
2985 if (!Tok.
is(tok::identifier))
2990 if (TryAltiVecToken(DS, Loc, PrevSpec, DiagID, isInvalid))
2996 goto DoneWithDeclSpec;
2998 if (DSContext == DSC_objc_method_result && isObjCInstancetype()) {
3002 DiagID, TypeRep, Policy);
3018 ParsedAttributesWithRange Attrs(AttrFactory);
3019 if (ParseImplicitInt(DS,
nullptr, TemplateInfo, AS, DSContext, Attrs)) {
3020 if (!Attrs.
empty()) {
3021 AttrsLastTime =
true;
3022 attrs.takeAllFrom(Attrs);
3026 goto DoneWithDeclSpec;
3033 isConstructorDeclarator(
true))
3034 goto DoneWithDeclSpec;
3037 DiagID, TypeRep, Policy);
3049 TypeResult NewTypeRep = parseObjCTypeArgsAndProtocolQualifiers(
3064 case tok::annot_template_id: {
3069 goto DoneWithDeclSpec;
3077 isConstructorDeclarator(TemplateId->
SS.
isEmpty()))
3078 goto DoneWithDeclSpec;
3082 AnnotateTemplateIdTokenAsType();
3087 case tok::kw___attribute:
3092 case tok::kw___declspec:
3097 case tok::kw___forceinline: {
3106 case tok::kw___unaligned:
3111 case tok::kw___sptr:
3112 case tok::kw___uptr:
3113 case tok::kw___ptr64:
3114 case tok::kw___ptr32:
3116 case tok::kw___cdecl:
3117 case tok::kw___stdcall:
3118 case tok::kw___fastcall:
3119 case tok::kw___thiscall:
3120 case tok::kw___vectorcall:
3125 case tok::kw___pascal:
3130 case tok::kw___kernel:
3135 case tok::kw__Nonnull:
3136 case tok::kw__Nullable:
3137 case tok::kw__Null_unspecified:
3142 case tok::kw___kindof:
3149 case tok::kw_typedef:
3151 PrevSpec, DiagID, Policy);
3152 isStorageClass =
true;
3154 case tok::kw_extern:
3156 Diag(Tok, diag::ext_thread_before) <<
"extern";
3158 PrevSpec, DiagID, Policy);
3159 isStorageClass =
true;
3161 case tok::kw___private_extern__:
3163 Loc, PrevSpec, DiagID, Policy);
3164 isStorageClass =
true;
3166 case tok::kw_static:
3168 Diag(Tok, diag::ext_thread_before) <<
"static";
3170 PrevSpec, DiagID, Policy);
3171 isStorageClass =
true;
3175 if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) {
3177 PrevSpec, DiagID, Policy);
3179 Diag(Tok, diag::ext_auto_storage_class)
3186 PrevSpec, DiagID, Policy);
3187 isStorageClass =
true;
3189 case tok::kw___auto_type:
3190 Diag(Tok, diag::ext_auto_type);
3194 case tok::kw_register:
3196 PrevSpec, DiagID, Policy);
3197 isStorageClass =
true;
3199 case tok::kw_mutable:
3201 PrevSpec, DiagID, Policy);
3202 isStorageClass =
true;
3204 case tok::kw___thread:
3207 isStorageClass =
true;
3209 case tok::kw_thread_local:
3213 case tok::kw__Thread_local:
3215 Loc, PrevSpec, DiagID);
3216 isStorageClass =
true;
3220 case tok::kw_inline:
3223 case tok::kw_virtual:
3226 case tok::kw_explicit:
3229 case tok::kw__Noreturn:
3231 Diag(Loc, diag::ext_c11_noreturn);
3236 case tok::kw__Alignas:
3238 Diag(Tok, diag::ext_c11_alignment) << Tok.
getName();
3243 case tok::kw_friend:
3244 if (DSContext == DSC_class)
3248 DiagID = diag::err_friend_invalid_in_context;
3254 case tok::kw___module_private__:
3259 case tok::kw_constexpr:
3264 case tok::kw_concept:
3281 case tok::kw___int64:
3285 case tok::kw_signed:
3289 case tok::kw_unsigned:
3293 case tok::kw__Complex:
3297 case tok::kw__Imaginary:
3313 case tok::kw___int128:
3325 case tok::kw_double:
3329 case tok::kw___float128:
3333 case tok::kw_wchar_t:
3337 case tok::kw_char16_t:
3341 case tok::kw_char32_t:
3347 if (Tok.
is(tok::kw_bool) &&
3351 DiagID = diag::err_bool_redeclaration;
3360 case tok::kw__Decimal32:
3364 case tok::kw__Decimal64:
3368 case tok::kw__Decimal128:
3372 case tok::kw___vector:
3375 case tok::kw___pixel:
3378 case tok::kw___bool:
3386 goto DoneWithDeclSpec;
3388 isInvalid = DS.
SetTypePipe(
true, Loc, PrevSpec, DiagID, Policy);
3390 #define GENERIC_IMAGE_TYPE(ImgType, Id) \
3391 case tok::kw_##ImgType##_t: \
3392 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, \
3395 #include "clang/Basic/OpenCLImageTypes.def"
3396 case tok::kw___unknown_anytype:
3398 PrevSpec, DiagID, Policy);
3403 case tok::kw_struct:
3404 case tok::kw___interface:
3405 case tok::kw_union: {
3412 ParsedAttributesWithRange Attributes(AttrFactory);
3413 ParseClassSpecifier(Kind, Loc, DS, TemplateInfo, AS,
3414 EnteringContext, DSContext, Attributes);
3418 if (!Attributes.empty()) {
3419 AttrsLastTime =
true;
3420 attrs.takeAllFrom(Attributes);
3428 ParseEnumSpecifier(Loc, DS, TemplateInfo, AS, DSContext);
3436 case tok::kw_volatile:
3440 case tok::kw_restrict:
3446 case tok::kw_typename:
3449 goto DoneWithDeclSpec;
3451 if (!Tok.
is(tok::kw_typename))
3456 case tok::kw_typeof:
3457 ParseTypeofSpecifier(DS);
3460 case tok::annot_decltype:
3461 ParseDecltypeSpecifier(DS);
3464 case tok::annot_pragma_pack:
3468 case tok::annot_pragma_ms_pragma:
3469 HandlePragmaMSPragma();
3472 case tok::annot_pragma_ms_vtordisp:
3473 HandlePragmaMSVtorDisp();
3476 case tok::annot_pragma_ms_pointers_to_members:
3477 HandlePragmaMSPointersToMembers();
3480 case tok::kw___underlying_type:
3481 ParseUnderlyingTypeSpecifier(DS);
3484 case tok::kw__Atomic:
3490 ParseAtomicSpecifier(DS);
3498 case tok::kw___generic:
3502 DiagID = diag::err_opencl_unknown_type_specifier;
3507 case tok::kw___private:
3508 case tok::kw___global:
3509 case tok::kw___local:
3510 case tok::kw___constant:
3511 case tok::kw___read_only:
3512 case tok::kw___write_only:
3513 case tok::kw___read_write:
3522 goto DoneWithDeclSpec;
3529 PrevSpec, DiagID, Type.
get(),
3531 Diag(StartLoc, DiagID) << PrevSpec;
3544 assert(PrevSpec &&
"Method did not return previous specifier!");
3547 if (DiagID == diag::ext_duplicate_declspec)
3550 else if (DiagID == diag::err_opencl_unknown_type_specifier) {
3551 const int OpenCLVer =
getLangOpts().OpenCLVersion;
3552 std::string VerSpec = llvm::to_string(OpenCLVer / 100) +
3554 llvm::to_string((OpenCLVer % 100) / 10);
3555 Diag(Tok, DiagID) << VerSpec << PrevSpec << isStorageClass;
3557 Diag(Tok, DiagID) << PrevSpec;
3561 if (DiagID != diag::err_bool_redeclaration)
3564 AttrsLastTime =
false;
3585 void Parser::ParseStructDeclaration(
3589 if (Tok.
is(tok::kw___extension__)) {
3593 return ParseStructDeclaration(DS, FieldsCallback);
3597 ParseSpecifierQualifierList(DS);
3601 if (Tok.
is(tok::semi)) {
3605 assert(!AnonRecord &&
"Did not expect anonymous struct or union here");
3611 bool FirstDeclarator =
true;
3615 DeclaratorInfo.D.setCommaLoc(CommaLoc);
3618 if (!FirstDeclarator)
3619 MaybeParseGNUAttributes(DeclaratorInfo.D);
3623 if (Tok.
isNot(tok::colon)) {
3626 ParseDeclarator(DeclaratorInfo.D);
3628 DeclaratorInfo.D.SetIdentifier(
nullptr, Tok.
getLocation());
3632 if (Res.isInvalid())
3635 DeclaratorInfo.BitfieldSize = Res.get();
3639 MaybeParseGNUAttributes(DeclaratorInfo.D);
3642 FieldsCallback(DeclaratorInfo);
3649 FirstDeclarator =
false;
3666 "parsing struct/union body");
3670 if (T.consumeOpen())
3679 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
3684 if (Tok.
is(tok::semi)) {
3685 ConsumeExtraSemi(InsideStruct, TagType);
3690 if (Tok.
is(tok::kw__Static_assert)) {
3692 ParseStaticAssertDeclaration(DeclEnd);
3696 if (Tok.
is(tok::annot_pragma_pack)) {
3701 if (Tok.
is(tok::annot_pragma_align)) {
3702 HandlePragmaAlign();
3706 if (Tok.
is(tok::annot_pragma_openmp)) {
3709 ParsedAttributesWithRange Attrs(AttrFactory);
3710 (void)ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs);
3714 if (!Tok.
is(tok::at)) {
3719 FD.D.getDeclSpec().getSourceRange().getBegin(),
3720 FD.D, FD.BitfieldSize);
3721 FieldDecls.push_back(Field);
3727 ParseStructDeclaration(DS, CFieldCallback);
3731 Diag(Tok, diag::err_unexpected_at);
3736 ExpectAndConsume(tok::l_paren);
3737 if (!Tok.
is(tok::identifier)) {
3738 Diag(Tok, diag::err_expected) << tok::identifier;
3745 FieldDecls.insert(FieldDecls.end(), Fields.begin(), Fields.end());
3747 ExpectAndConsume(tok::r_paren);
3753 if (Tok.
is(tok::r_brace)) {
3754 ExpectAndConsume(tok::semi, diag::ext_expected_semi_decl_list);
3758 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list);
3769 MaybeParseGNUAttributes(attrs);
3772 RecordLoc, TagDecl, FieldDecls,
3773 T.getOpenLocation(), T.getCloseLocation(),
3810 const ParsedTemplateInfo &TemplateInfo,
3813 if (Tok.
is(tok::code_completion)) {
3816 return cutOffParsing();
3820 ParsedAttributesWithRange attrs(AttrFactory);
3821 MaybeParseGNUAttributes(attrs);
3822 MaybeParseCXX11Attributes(attrs);
3823 MaybeParseMicrosoftDeclSpecs(attrs);
3826 bool IsScopedUsingClassTag =
false;
3829 if (Tok.
isOneOf(tok::kw_class, tok::kw_struct)) {
3831 : diag::ext_scoped_enum);
3832 IsScopedUsingClassTag = Tok.
is(tok::kw_class);
3837 ProhibitAttributes(attrs);
3840 MaybeParseGNUAttributes(attrs);
3841 MaybeParseCXX11Attributes(attrs);
3842 MaybeParseMicrosoftDeclSpecs(attrs);
3851 bool shouldDelayDiagsInTag =
3852 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
3853 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
3857 bool AllowDeclaration = DSC != DSC_trailing;
3859 bool AllowFixedUnderlyingType = AllowDeclaration &&
3870 if (ParseOptionalCXXScopeSpecifier(Spec,
nullptr,
3874 if (Spec.
isSet() && Tok.
isNot(tok::identifier)) {
3875 Diag(Tok, diag::err_expected) << tok::identifier;
3876 if (Tok.
isNot(tok::l_brace)) {
3888 if (Tok.
isNot(tok::identifier) && Tok.
isNot(tok::l_brace) &&
3889 !(AllowFixedUnderlyingType && Tok.
is(tok::colon))) {
3890 Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace;
3900 if (Tok.
is(tok::identifier)) {
3905 if (!Name && ScopedEnumKWLoc.
isValid()) {
3908 Diag(Tok, diag::err_scoped_enum_missing_identifier);
3910 IsScopedUsingClassTag =
false;
3915 if (shouldDelayDiagsInTag)
3916 diagsFromTag.done();
3922 if (AllowFixedUnderlyingType && Tok.
is(tok::colon)) {
3923 bool PossibleBitfield =
false;
3924 if (CanBeBitfield) {
3938 PossibleBitfield =
true;
3944 GetLookAheadToken(2).
getKind() == tok::semi) {
3951 TentativeParsingAction TPA(*
this);
3966 PossibleBitfield =
true;
3978 if (!PossibleBitfield) {
3983 Diag(StartLoc, diag::warn_cxx98_compat_enum_fixed_underlying_type);
3986 Diag(StartLoc, diag::ext_cxx11_enum_fixed_underlying_type) << Range;
3988 Diag(StartLoc, diag::ext_c_enum_fixed_underlying_type) << Range;
4004 if (!AllowDeclaration) {
4006 }
else if (Tok.
is(tok::l_brace)) {
4016 }
else if (!isTypeSpecifier(DSC) &&
4017 (Tok.
is(tok::semi) ||
4019 !isValidAfterTypeSpecifier(CanBeBitfield)))) {
4021 if (Tok.
isNot(tok::semi)) {
4023 ExpectAndConsume(tok::semi, diag::err_expected_after,
"enum");
4034 diagsFromTag.redelay();
4038 if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
4042 Diag(Tok, diag::err_enum_template);
4047 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
4050 Diag(StartLoc, diag::err_explicit_instantiation_enum);
4054 assert(TemplateInfo.TemplateParams &&
"no template parameters");
4056 TemplateInfo.TemplateParams->size());
4060 ProhibitAttributes(attrs);
4063 Diag(Tok, diag::err_enumerator_unnamed_no_def);
4070 handleDeclspecAlignBeforeClassKey(attrs, DS, TUK);
4080 bool IsDependent =
false;
4081 const char *PrevSpec =
nullptr;
4084 StartLoc, SS, Name, NameLoc, attrs.getList(),
4086 Owned, IsDependent, ScopedEnumKWLoc,
4087 IsScopedUsingClassTag, BaseType,
4088 DSC == DSC_type_specifier, &SkipBody);
4098 NameLoc.
isValid() ? NameLoc : StartLoc,
4099 PrevSpec, DiagID, TagDecl, Owned,
4101 Diag(StartLoc, DiagID) << PrevSpec;
4110 Diag(Tok, diag::err_expected_type_name_after_typename);
4122 NameLoc.
isValid() ? NameLoc : StartLoc,
4123 PrevSpec, DiagID, Type.
get(),
4125 Diag(StartLoc, DiagID) << PrevSpec;
4143 ParseEnumBody(StartLoc, TagDecl);
4146 NameLoc.
isValid() ? NameLoc : StartLoc,
4147 PrevSpec, DiagID, TagDecl, Owned,
4149 Diag(StartLoc, DiagID) << PrevSpec;
4172 Diag(Tok, diag::error_empty_enum);
4177 Decl *LastEnumConstDecl =
nullptr;
4180 while (Tok.
isNot(tok::r_brace)) {
4183 if (Tok.
isNot(tok::identifier)) {
4194 ParsedAttributesWithRange attrs(AttrFactory);
4195 MaybeParseGNUAttributes(attrs);
4196 ProhibitAttributes(attrs);
4201 ParseCXX11Attributes(attrs);
4206 EnumAvailabilityDiags.emplace_back(*
this);
4218 attrs.getList(), EqualLoc,
4220 EnumAvailabilityDiags.back().done();
4222 EnumConstantDecls.push_back(EnumConstDecl);
4223 LastEnumConstDecl = EnumConstDecl;
4225 if (Tok.
is(tok::identifier)) {
4228 Diag(Loc, diag::err_enumerator_list_missing_comma)
4251 if (Tok.
is(tok::r_brace) && CommaLoc.
isValid()) {
4254 diag::ext_enumerator_list_comma_cxx :
4255 diag::ext_enumerator_list_comma_c)
4258 Diag(CommaLoc, diag::warn_cxx98_compat_enumerator_list_comma)
4269 MaybeParseGNUAttributes(attrs);
4272 EnumDecl, EnumConstantDecls,
4277 assert(EnumConstantDecls.size() == EnumAvailabilityDiags.size());
4278 for (
size_t i = 0, e = EnumConstantDecls.size(); i != e; ++i) {
4280 EnumAvailabilityDiags[i].redelay();
4281 PD.complete(EnumConstantDecls[i]);
4290 if (!isValidAfterTypeSpecifier(CanBeBitfield)) {
4291 ExpectAndConsume(tok::semi, diag::err_expected_after,
"enum");
4303 bool Parser::isKnownToBeTypeSpecifier(
const Token &Tok)
const {
4305 default:
return false;
4309 case tok::kw___int64:
4310 case tok::kw___int128:
4311 case tok::kw_signed:
4312 case tok::kw_unsigned:
4313 case tok::kw__Complex:
4314 case tok::kw__Imaginary:
4317 case tok::kw_wchar_t:
4318 case tok::kw_char16_t:
4319 case tok::kw_char32_t:
4323 case tok::kw_double:
4324 case tok::kw___float128:
4327 case tok::kw__Decimal32:
4328 case tok::kw__Decimal64:
4329 case tok::kw__Decimal128:
4330 case tok::kw___vector:
4331 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
4332 #include "clang/Basic/OpenCLImageTypes.def"
4336 case tok::kw_struct:
4337 case tok::kw___interface:
4343 case tok::annot_typename:
4350 bool Parser::isTypeSpecifierQualifier() {
4352 default:
return false;
4354 case tok::identifier:
4355 if (TryAltiVecVectorToken())
4358 case tok::kw_typename:
4363 if (Tok.
is(tok::identifier))
4365 return isTypeSpecifierQualifier();
4367 case tok::coloncolon:
4374 return isTypeSpecifierQualifier();
4377 case tok::kw___attribute:
4379 case tok::kw_typeof:
4384 case tok::kw___int64:
4385 case tok::kw___int128:
4386 case tok::kw_signed:
4387 case tok::kw_unsigned:
4388 case tok::kw__Complex:
4389 case tok::kw__Imaginary:
4392 case tok::kw_wchar_t:
4393 case tok::kw_char16_t:
4394 case tok::kw_char32_t:
4398 case tok::kw_double:
4399 case tok::kw___float128:
4402 case tok::kw__Decimal32:
4403 case tok::kw__Decimal64:
4404 case tok::kw__Decimal128:
4405 case tok::kw___vector:
4406 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
4407 #include "clang/Basic/OpenCLImageTypes.def"
4411 case tok::kw_struct:
4412 case tok::kw___interface:
4419 case tok::kw_volatile:
4420 case tok::kw_restrict:
4423 case tok::kw___unknown_anytype:
4426 case tok::annot_typename:
4433 case tok::kw___cdecl:
4434 case tok::kw___stdcall:
4435 case tok::kw___fastcall:
4436 case tok::kw___thiscall:
4437 case tok::kw___vectorcall:
4439 case tok::kw___ptr64:
4440 case tok::kw___ptr32:
4441 case tok::kw___pascal:
4442 case tok::kw___unaligned:
4444 case tok::kw__Nonnull:
4445 case tok::kw__Nullable:
4446 case tok::kw__Null_unspecified:
4448 case tok::kw___kindof:
4450 case tok::kw___private:
4451 case tok::kw___local:
4452 case tok::kw___global:
4453 case tok::kw___constant:
4454 case tok::kw___generic:
4455 case tok::kw___read_only:
4456 case tok::kw___read_write:
4457 case tok::kw___write_only:
4462 case tok::kw__Atomic:
4472 bool Parser::isDeclarationSpecifier(
bool DisambiguatingWithExpression) {
4474 default:
return false;
4479 case tok::identifier:
4483 if (TryAltiVecVectorToken())
4486 case tok::kw_decltype:
4487 case tok::kw_typename:
4492 if (Tok.
is(tok::identifier))
4500 if (DisambiguatingWithExpression &&
4501 isStartOfObjCClassMessageMissingOpenBracket())
4504 return isDeclarationSpecifier();
4506 case tok::coloncolon:
4515 return isDeclarationSpecifier();
4518 case tok::kw_typedef:
4519 case tok::kw_extern:
4520 case tok::kw___private_extern__:
4521 case tok::kw_static:
4523 case tok::kw___auto_type:
4524 case tok::kw_register:
4525 case tok::kw___thread:
4526 case tok::kw_thread_local:
4527 case tok::kw__Thread_local:
4530 case tok::kw___module_private__:
4533 case tok::kw___unknown_anytype:
4538 case tok::kw___int64:
4539 case tok::kw___int128:
4540 case tok::kw_signed:
4541 case tok::kw_unsigned:
4542 case tok::kw__Complex:
4543 case tok::kw__Imaginary:
4546 case tok::kw_wchar_t:
4547 case tok::kw_char16_t:
4548 case tok::kw_char32_t:
4553 case tok::kw_double:
4554 case tok::kw___float128:
4557 case tok::kw__Decimal32:
4558 case tok::kw__Decimal64:
4559 case tok::kw__Decimal128:
4560 case tok::kw___vector:
4564 case tok::kw_struct:
4566 case tok::kw___interface:
4572 case tok::kw_volatile:
4573 case tok::kw_restrict:
4576 case tok::kw_inline:
4577 case tok::kw_virtual:
4578 case tok::kw_explicit:
4579 case tok::kw__Noreturn:
4582 case tok::kw__Alignas:
4585 case tok::kw_friend:
4588 case tok::kw__Static_assert:
4591 case tok::kw_typeof:
4594 case tok::kw___attribute:
4597 case tok::annot_decltype:
4598 case tok::kw_constexpr:
4601 case tok::kw_concept:
4604 case tok::kw__Atomic:
4612 case tok::annot_typename:
4613 return !DisambiguatingWithExpression ||
4614 !isStartOfObjCClassMessageMissingOpenBracket();
4616 case tok::kw___declspec:
4617 case tok::kw___cdecl:
4618 case tok::kw___stdcall:
4619 case tok::kw___fastcall:
4620 case tok::kw___thiscall:
4621 case tok::kw___vectorcall:
4623 case tok::kw___sptr:
4624 case tok::kw___uptr:
4625 case tok::kw___ptr64:
4626 case tok::kw___ptr32:
4627 case tok::kw___forceinline:
4628 case tok::kw___pascal:
4629 case tok::kw___unaligned:
4631 case tok::kw__Nonnull:
4632 case tok::kw__Nullable:
4633 case tok::kw__Null_unspecified:
4635 case tok::kw___kindof:
4637 case tok::kw___private:
4638 case tok::kw___local:
4639 case tok::kw___global:
4640 case tok::kw___constant:
4641 case tok::kw___generic:
4642 case tok::kw___read_only:
4643 case tok::kw___read_write:
4644 case tok::kw___write_only:
4645 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
4646 #include "clang/Basic/OpenCLImageTypes.def"
4652 bool Parser::isConstructorDeclarator(
bool IsUnqualified) {
4653 TentativeParsingAction TPA(*
this);
4657 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
4664 if (Tok.
isOneOf(tok::identifier, tok::annot_template_id)) {
4674 if (Tok.
isNot(tok::l_paren)) {
4682 if (Tok.
is(tok::r_paren) ||
4691 isCXX11AttributeSpecifier(
false,
4698 DeclaratorScopeObj DeclScopeObj(*
this, SS);
4700 DeclScopeObj.EnterDeclaratorScope();
4704 MaybeParseMicrosoftAttributes(Attrs);
4709 bool IsConstructor =
false;
4710 if (isDeclarationSpecifier())
4711 IsConstructor =
true;
4712 else if (Tok.
is(tok::identifier) ||
4713 (Tok.
is(tok::annot_cxxscope) &&
NextToken().
is(tok::identifier))) {
4718 if (Tok.
is(tok::annot_cxxscope))
4731 case tok::coloncolon:
4744 IsConstructor =
true;
4759 IsConstructor = IsUnqualified;
4764 IsConstructor =
true;
4770 return IsConstructor;
4785 void Parser::ParseTypeQualifierListOpt(
DeclSpec &DS,
unsigned AttrReqs,
4787 bool IdentifierRequired) {
4789 isCXX11AttributeSpecifier()) {
4790 ParsedAttributesWithRange attrs(AttrFactory);
4791 ParseCXX11Attributes(attrs);
4798 bool isInvalid =
false;
4799 const char *PrevSpec =
nullptr;
4800 unsigned DiagID = 0;
4804 case tok::code_completion:
4806 return cutOffParsing();
4812 case tok::kw_volatile:
4816 case tok::kw_restrict:
4820 case tok::kw__Atomic:
4822 goto DoneWithTypeQuals;
4828 case tok::kw___private:
4829 case tok::kw___global:
4830 case tok::kw___local:
4831 case tok::kw___constant:
4832 case tok::kw___generic:
4833 case tok::kw___read_only:
4834 case tok::kw___write_only:
4835 case tok::kw___read_write:
4839 case tok::kw___unaligned:
4843 case tok::kw___uptr:
4848 if (TryKeywordIdentFallback(
false))
4851 case tok::kw___sptr:
4853 case tok::kw___ptr64:
4854 case tok::kw___ptr32:
4855 case tok::kw___cdecl:
4856 case tok::kw___stdcall:
4857 case tok::kw___fastcall:
4858 case tok::kw___thiscall:
4859 case tok::kw___vectorcall:
4860 if (AttrReqs & AR_DeclspecAttributesParsed) {
4864 goto DoneWithTypeQuals;
4865 case tok::kw___pascal:
4866 if (AttrReqs & AR_VendorAttributesParsed) {
4870 goto DoneWithTypeQuals;
4873 case tok::kw__Nonnull:
4874 case tok::kw__Nullable:
4875 case tok::kw__Null_unspecified:
4880 case tok::kw___kindof:
4886 case tok::kw___attribute:
4887 if (AttrReqs & AR_GNUAttributesParsedAndRejected)
4889 Diag(Tok, diag::err_attributes_not_allowed);
4893 if (AttrReqs & AR_GNUAttributesParsed ||
4894 AttrReqs & AR_GNUAttributesParsedAndRejected) {
4911 assert(PrevSpec &&
"Method did not return previous specifier!");
4912 Diag(Tok, DiagID) << PrevSpec;
4920 void Parser::ParseDeclarator(
Declarator &D) {
4923 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
4927 unsigned TheContext) {
4928 if (Kind == tok::star || Kind == tok::caret)
4931 if ((Kind == tok::kw_pipe) && Lang.OpenCL && (Lang.OpenCLVersion >= 200))
4934 if (!Lang.CPlusPlus)
4937 if (Kind == tok::amp)
4945 if (Kind == tok::ampamp)
4956 for (
unsigned Idx = 0; Idx != NumTypes; ++Idx)
4988 void Parser::ParseDeclaratorInternal(
Declarator &D,
4989 DirectDeclParseFunction DirectDeclParser) {
4997 (Tok.
is(tok::coloncolon) || Tok.
is(tok::kw_decltype) ||
4998 (Tok.
is(tok::identifier) &&
5000 Tok.
is(tok::annot_cxxscope))) {
5004 ParseOptionalCXXScopeSpecifier(SS,
nullptr, EnteringContext);
5007 if (Tok.
isNot(tok::star)) {
5012 AnnotateScopeToken(SS,
true);
5014 if (DirectDeclParser)
5015 (this->*DirectDeclParser)(D);
5022 ParseTypeQualifierListOpt(DS);
5026 ParseDeclaratorInternal(D, DirectDeclParser);
5042 ParseTypeQualifierListOpt(DS);
5051 if (DirectDeclParser)
5052 (this->*DirectDeclParser)(D);
5061 if (Kind == tok::star || Kind == tok::caret) {
5067 unsigned Reqs = AR_CXX11AttributesParsed | AR_DeclspecAttributesParsed |
5069 ? AR_GNUAttributesParsed
5070 : AR_GNUAttributesParsedAndRejected);
5075 ParseDeclaratorInternal(D, DirectDeclParser);
5076 if (Kind == tok::star)
5098 if (Kind == tok::ampamp)
5100 diag::warn_cxx98_compat_rvalue_reference :
5101 diag::ext_rvalue_reference);
5104 ParseTypeQualifierListOpt(DS);
5113 diag::err_invalid_reference_qualifier_application) <<
"const";
5116 diag::err_invalid_reference_qualifier_application) <<
"volatile";
5120 diag::err_invalid_reference_qualifier_application) <<
"_Atomic";
5124 ParseDeclaratorInternal(D, DirectDeclParser);
5131 Diag(InnerChunk.
Loc, diag::err_illegal_decl_reference_to_reference)
5134 Diag(InnerChunk.
Loc, diag::err_illegal_decl_reference_to_reference)
5205 void Parser::ParseDirectDeclarator(
Declarator &D) {
5230 DeclScopeObj.EnterDeclaratorScope();
5254 DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, D);
5264 if (Tok.
isOneOf(tok::identifier, tok::kw_operator, tok::annot_template_id,
5268 bool AllowConstructorName;
5270 AllowConstructorName =
false;
5272 AllowConstructorName =
5282 true, AllowConstructorName,
5283 nullptr, TemplateKWLoc, D.
getName()) ||
5295 DeclScopeObj.EnterDeclaratorScope();
5302 goto PastIdentifier;
5308 diag::err_expected_unqualified_id)
5311 goto PastIdentifier;
5315 "There's a C++-specific check for tok::identifier above");
5320 goto PastIdentifier;
5325 !isCXX11VirtSpecifier(Tok)) {
5330 goto PastIdentifier;
5334 if (Tok.
is(tok::l_paren)) {
5338 ParseParenDeclarator(D);
5351 DeclScopeObj.EnterDeclaratorScope();
5362 diag::ext_abstract_pack_declarator_parens);
5364 if (Tok.
getKind() == tok::annot_pragma_parser_crash)
5366 if (Tok.
is(tok::l_square))
5367 return ParseMisplacedBracketDeclarator(D);
5370 diag::err_expected_member_name_or_semi)
5374 if (Tok.
isOneOf(tok::period, tok::arrow))
5375 Diag(Tok, diag::err_invalid_operator_on_type) << Tok.
is(tok::arrow);
5383 diag::err_expected_unqualified_id)
5388 diag::err_expected_either)
5389 << tok::identifier << tok::l_paren;
5397 "Haven't past the location of the identifier yet?");
5401 MaybeParseCXX11Attributes(D);
5404 if (Tok.
is(tok::l_paren)) {
5407 ParseScope PrototypeScope(
this,
5415 bool IsAmbiguous =
false;
5419 TentativelyDeclaredIdentifiers.push_back(D.
getIdentifier());
5420 bool IsFunctionDecl = isCXXFunctionDeclarator(&IsAmbiguous);
5421 TentativelyDeclaredIdentifiers.pop_back();
5422 if (!IsFunctionDecl)
5428 ParseFunctionDeclarator(D, attrs, T, IsAmbiguous);
5429 PrototypeScope.Exit();
5430 }
else if (Tok.
is(tok::l_square)) {
5431 ParseBracketDeclarator(D);
5451 void Parser::ParseParenDeclarator(
Declarator &D) {
5455 assert(!D.
isPastIdentifier() &&
"Should be called before passing identifier");
5468 bool RequiresArg =
false;
5469 if (Tok.
is(tok::kw___attribute)) {
5470 ParseGNUAttributes(attrs);
5478 ParseMicrosoftTypeAttributes(attrs);
5481 if (Tok.
is(tok::kw___pascal))
5482 ParseBorlandTypeAttributes(attrs);
5494 }
else if (Tok.
is(tok::r_paren) ||
5497 isDeclarationSpecifier() ||
5498 isCXX11AttributeSpecifier()) {
5516 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
5520 T.getCloseLocation()),
5521 attrs, T.getCloseLocation());
5527 DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, D);
5540 ParseScope PrototypeScope(
this,
5544 ParseFunctionDeclarator(D, attrs, T,
false, RequiresArg);
5545 PrototypeScope.Exit();
5567 void Parser::ParseFunctionDeclarator(
Declarator &D,
5572 assert(
getCurScope()->isFunctionPrototypeScope() &&
5573 "Should call from a Function scope");
5579 bool HasProto =
false;
5586 bool RefQualifierIsLValueRef =
true;
5606 StartLoc = LParenLoc;
5608 if (isFunctionDeclaratorIdentifierList()) {
5610 Diag(Tok, diag::err_argument_required_after_attribute);
5612 ParseFunctionDeclaratorIdentifierList(D, ParamInfo);
5616 LocalEndLoc = RParenLoc;
5619 if (Tok.
isNot(tok::r_paren))
5620 ParseParameterDeclarationClause(D, FirstArgAttrs, ParamInfo,
5622 else if (RequiresArg)
5623 Diag(Tok, diag::err_argument_required_after_attribute);
5625 HasProto = ParamInfo.size() ||
getLangOpts().CPlusPlus;
5630 LocalEndLoc = RParenLoc;
5639 ParseTypeQualifierListOpt(DS, AR_NoAttributesParsed,
5649 if (ParseRefQualifier(RefQualifierIsLValueRef, RefQualifierLoc))
5650 EndLoc = RefQualifierLoc;
5659 bool IsCXX11MemberFunction =
5673 IsCXX11MemberFunction);
5679 GetLookAheadToken(0).is(tok::kw_noexcept) &&
5680 GetLookAheadToken(1).is(tok::l_paren) &&
5681 GetLookAheadToken(2).is(tok::kw_noexcept) &&
5682 GetLookAheadToken(3).is(tok::l_paren) &&
5683 GetLookAheadToken(4).is(tok::identifier) &&
5684 GetLookAheadToken(4).getIdentifierInfo()->isStr(
"swap")) {
5695 ESpecType = tryParseExceptionSpecification(Delayed,
5698 DynamicExceptionRanges,
5700 ExceptionSpecTokens);
5702 EndLoc = ESpecRange.
getEnd();
5706 MaybeParseCXX11Attributes(FnAttrs);
5709 LocalEndLoc = EndLoc;
5711 Diag(Tok, diag::warn_cxx98_compat_trailing_return_type);
5716 TrailingReturnType = ParseTrailingReturnType(Range);
5726 ParamInfo.data(), ParamInfo.size(),
5727 EllipsisLoc, RParenLoc,
5729 RefQualifierIsLValueRef,
5730 RefQualifierLoc, ConstQualifierLoc,
5731 VolatileQualifierLoc,
5732 RestrictQualifierLoc,
5734 ESpecType, ESpecRange,
5735 DynamicExceptions.data(),
5736 DynamicExceptionRanges.data(),
5737 DynamicExceptions.size(),
5739 NoexceptExpr.
get() :
nullptr,
5740 ExceptionSpecTokens,
5741 StartLoc, LocalEndLoc, D,
5742 TrailingReturnType),
5748 bool Parser::ParseRefQualifier(
bool &RefQualifierIsLValueRef,
5750 if (Tok.
isOneOf(tok::amp, tok::ampamp)) {
5752 diag::warn_cxx98_compat_ref_qualifier :
5753 diag::ext_ref_qualifier);
5755 RefQualifierIsLValueRef = Tok.
is(tok::amp);
5767 bool Parser::isFunctionDeclaratorIdentifierList() {
5769 && Tok.
is(tok::identifier)
5770 && !TryAltiVecVectorToken()
5798 void Parser::ParseFunctionDeclaratorIdentifierList(
5806 Diag(Tok, diag::ext_ident_list_in_param);
5809 llvm::SmallSet<const IdentifierInfo*, 16> ParamsSoFar;
5813 if (Tok.
isNot(tok::identifier)) {
5814 Diag(Tok, diag::err_expected) << tok::identifier;
5825 Diag(Tok, diag::err_unexpected_typedef_ident) << ParmII;
5828 if (!ParamsSoFar.insert(ParmII).second) {
5829 Diag(Tok, diag::err_param_redefinition) << ParmII;
5874 void Parser::ParseParameterDeclarationClause(
5904 ParseDeclarationSpecifiers(DS);
5914 ParseDeclarator(ParmDeclarator);
5917 MaybeParseGNUAttributes(ParmDeclarator);
5928 if (DS.
isEmpty() && ParmDeclarator.getIdentifier() ==
nullptr &&
5929 ParmDeclarator.getNumTypeObjects() == 0) {
5931 Diag(DSStart, diag::err_missing_param);
5938 if (Tok.
is(tok::ellipsis) &&
5940 (!ParmDeclarator.getEllipsisLoc().isValid() &&
5943 DiagnoseMisplacedEllipsisInDeclarator(
ConsumeToken(), ParmDeclarator);
5952 if (Tok.
is(tok::equal)) {
5964 if (!ConsumeAndStoreInitializer(*DefArgToks, CIK_DefaultArgument)) {
5966 DefArgToks =
nullptr;
5984 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
5985 DefArgResult = ParseBraceInitializer();
5995 DefArgResult.
get());
6001 ParmDeclarator.getIdentifierLoc(),
6002 Param, DefArgToks));
6009 Diag(EllipsisLoc, diag::err_missing_comma_before_ellipsis)
6011 }
else if (ParmDeclarator.getEllipsisLoc().isValid() ||
6016 Diag(EllipsisLoc, diag::warn_misplaced_ellipsis_vararg)
6017 << ParmEllipsis.
isValid() << ParmEllipsis;
6020 diag::note_misplaced_ellipsis_vararg_existing_ellipsis);
6022 Diag(ParmDeclarator.getIdentifierLoc(),
6023 diag::note_misplaced_ellipsis_vararg_add_ellipsis)
6026 << !ParmDeclarator.hasName();
6028 Diag(EllipsisLoc, diag::note_misplaced_ellipsis_vararg_add_comma)
6047 void Parser::ParseBracketDeclarator(
Declarator &D) {
6048 if (CheckProhibitedCXX11Attribute())
6056 if (Tok.
getKind() == tok::r_square) {
6059 MaybeParseCXX11Attributes(attrs);
6063 T.getOpenLocation(),
6064 T.getCloseLocation()),
6065 attrs, T.getCloseLocation());
6067 }
else if (Tok.
getKind() == tok::numeric_constant &&
6068 GetLookAheadToken(1).is(tok::r_square)) {
6075 MaybeParseCXX11Attributes(attrs);
6080 T.getOpenLocation(),
6081 T.getCloseLocation()),
6082 attrs, T.getCloseLocation());
6084 }
else if (Tok.
getKind() == tok::code_completion) {
6086 return cutOffParsing();
6096 ParseTypeQualifierListOpt(DS, AR_CXX11AttributesParsed);
6104 bool isStar =
false;
6111 if (Tok.
is(tok::star) && GetLookAheadToken(1).is(tok::r_square)) {
6115 Diag(StaticLoc, diag::err_unspecified_vla_size_with_static);
6119 }
else if (Tok.
isNot(tok::r_square)) {
6137 Diag(StaticLoc, diag::err_unspecified_size_with_static);
6153 MaybeParseCXX11Attributes(attrs);
6159 T.getOpenLocation(),
6160 T.getCloseLocation()),
6161 attrs, T.getCloseLocation());
6165 void Parser::ParseMisplacedBracketDeclarator(
Declarator &D) {
6166 assert(Tok.
is(tok::l_square) &&
"Missing opening bracket");
6172 while (Tok.
is(tok::l_square)) {
6173 ParseBracketDeclarator(TempDeclarator);
6179 if (Tok.
is(tok::semi))
6185 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
6190 if (TempDeclarator.getNumTypeObjects() == 0)
6194 bool NeedParens =
false;
6220 for (
unsigned i = 0, e = TempDeclarator.getNumTypeObjects(); i < e; ++i) {
6235 SourceRange BracketRange(StartBracketLoc, EndBracketLoc);
6239 Diag(EndLoc, diag::err_brackets_go_after_unqualified_id)
6247 Diag(EndLoc, diag::err_brackets_go_after_unqualified_id)
6260 void Parser::ParseTypeofSpecifier(
DeclSpec &DS) {
6261 assert(Tok.
is(tok::kw_typeof) &&
"Not a typeof specifier");
6265 const bool hasParens = Tok.
is(tok::l_paren);
6274 ParseExprAfterUnaryExprOrTypeTrait(OpTok, isCastExpr, CastTy, CastRange));
6290 const char *PrevSpec =
nullptr;
6296 Diag(StartLoc, DiagID) << PrevSpec;
6313 const char *PrevSpec =
nullptr;
6317 DiagID, Operand.
get(),
6319 Diag(StartLoc, DiagID) << PrevSpec;
6325 void Parser::ParseAtomicSpecifier(
DeclSpec &DS) {
6326 assert(Tok.
is(tok::kw__Atomic) &&
NextToken().
is(tok::l_paren) &&
6327 "Not an atomic specifier");
6331 if (T.consumeOpen())
6343 if (T.getCloseLocation().isInvalid())
6349 const char *PrevSpec =
nullptr;
6352 DiagID, Result.
get(),
6354 Diag(StartLoc, DiagID) << PrevSpec;
6359 bool Parser::TryAltiVecVectorTokenOutOfLine() {
6362 default:
return false;
6365 case tok::kw_signed:
6366 case tok::kw_unsigned:
6371 case tok::kw_double:
6373 case tok::kw___bool:
6374 case tok::kw___pixel:
6375 Tok.
setKind(tok::kw___vector);
6377 case tok::identifier:
6379 Tok.
setKind(tok::kw___vector);
6383 Tok.
setKind(tok::kw___vector);
6391 const char *&PrevSpec,
unsigned &DiagID,
6399 case tok::kw_signed:
6400 case tok::kw_unsigned:
6405 case tok::kw_double:
6407 case tok::kw___bool:
6408 case tok::kw___pixel:
6411 case tok::identifier:
void ClearFunctionSpecs()
MutableArrayRef< TemplateParameterList * > MultiTemplateParamsArg
unsigned getFlags() const
getFlags - Return the flags for this scope.
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
SourceLocation getThreadStorageClassSpecLoc() const
SourceLocation getCloseLocation() const
Defines the clang::ASTContext interface.
static bool isAttributeLateParsed(const IdentifierInfo &II)
isAttributeLateParsed - Return true if the attribute has arguments that require late parsing...
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()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
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
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc...
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
TemplateNameLoc - The location of the template name within the source.
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
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.
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.
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
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, SourceRange ESpecRange, ParsedType *Exceptions, SourceRange *ExceptionRanges, unsigned NumExceptions, Expr *NoexceptExpr, CachedTokens *ExceptionSpecTokens, SourceLocation LocalRangeBegin, SourceLocation LocalRangeEnd, Declarator &TheDeclarator, TypeResult TrailingReturnType=TypeResult())
DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
The base class of the type hierarchy.
bool TryAnnotateCXXScopeToken(bool EnteringContext=false)
TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only annotates C++ scope specifiers and ...
This indicates that the scope corresponds to a function, which means that labels are set here...
std::unique_ptr< llvm::MemoryBuffer > Buffer
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.
static IdentifierLoc * create(ASTContext &Ctx, SourceLocation Loc, IdentifierInfo *Ident)
void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, bool AllowNonIdentifiers, bool AllowNestedNameSpecifiers)
DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef< Decl * > Group, bool TypeMayContainAuto=true)
BuildDeclaratorGroup - convert a list of declarations into a declaration group, performing any necess...
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)
ActOnParamDeclarator - Called from Parser::ParseFunctionDeclarator() to introduce parameters into fun...
friend class ObjCDeclContextSwitch
ParmVarDecl - Represents a parameter to a function.
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed...
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 ...
bool isEmpty() const
No scope specifier.
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
void 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)
RecordDecl - Represents a struct/union/class.
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
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.
One of these records is kept for each identifier that is lexed.
void set(AttributeList *newList)
static const TST TST_decimal32
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
AttributeList * getList() const
static bool attributeHasIdentifierArg(const IdentifierInfo &II)
Determine whether the given attribute has an identifier argument.
bool isTypeSpecPipe() const
void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &attrs, SourceLocation EndLoc)
AddTypeInfo - Add a chunk to this declarator.
void ActOnTagStartDefinition(Scope *S, Decl *TagDecl)
ActOnTagStartDefinition - Invoked when we have entered the scope of a tag's definition (e...
const CXXScopeSpec & getCXXScopeSpec() const
getCXXScopeSpec - Return the C++ scope specifier (global scope or nested-name-specifier) that is part...
static const TST TST_class
bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS)
DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType=nullptr)
void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange, Decl *EnumDecl, ArrayRef< Decl * > Elements, Scope *S, AttributeList *Attr)
AttributeList * addNewTypeAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ParsedType typeArg, AttributeList::Syntax syntaxUsed)
Add an attribute with a single type argument.
bool isEmpty() const
isEmpty - Return true if this declaration specifier is completely empty: no tokens were parsed in the...
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.
ParsedType ActOnObjCInstanceType(SourceLocation Loc)
The parser has parsed the context-sensitive type 'instancetype' in an Objective-C message declaration...
Token - This structure provides full information about a lexed token.
SkipBodyInfo shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II, SourceLocation IILoc)
Determine whether the body of an anonymous enumeration should be skipped.
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)
ActOnFinishDelayedAttribute - Invoked when we have finished parsing an attribute for which parsing is...
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...
bool mayBeFollowedByCXXDirectInit() const
mayBeFollowedByCXXDirectInit - Return true if the declarator can be followed by a C++ direct initiali...
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 {'.
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)
Called whenever @defs(ClassName) is encountered in the source.
This is a scope that corresponds to a block/closure object.
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.
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.
void CodeCompleteBracketDeclarator(Scope *S)
void ActOnInitializerError(Decl *Dcl)
ActOnInitializerError - Given that there was an error parsing an initializer for the given declaratio...
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
If this is a source-language token (e.g.
bool hasAllExtensionsSilenced()
bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
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.
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)
AvailabilityChange Changes[NumAvailabilitySlots]
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.
static bool VersionNumberSeparator(const char Separator)
SourceRange getSourceRange() const LLVM_READONLY
void setInvalid(bool b=true) const
detail::InMemoryDirectory::const_iterator I
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)
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...
Provides definitions for the various language-specific address spaces.
void * getAnnotationValue() const
static const TSW TSW_long
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
TemplateParameterList * ActOnTemplateParameterList(unsigned Depth, SourceLocation ExportLoc, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< Decl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
ActOnTemplateParameterList - Builds a TemplateParameterList, optionally constrained by RequiresClause...
TST getTypeSpecType() const
void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit, bool TypeMayContainAuto)
AddInitializerToDecl - Adds the initializer Init to the declaration dcl.
void ClearConstexprSpec()
const void * getEofData() const
SourceLocation getModulePrivateSpecLoc() const
A class for parsing a declarator.
TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S)
isTagName() - This method is called for error recovery purposes only to determine if the specified na...
void SetRangeStart(SourceLocation Loc)
NameClassificationKind getKind() const
SourceLocation getFriendSpecLoc() const
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
TypeResult ParseTypeName(SourceRange *Range=nullptr, Declarator::TheContext Context=Declarator::TypeNameContext, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName type-name: [C99 6.7.6] specifier-qualifier-list abstract-declarator[opt].
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
bool mayOmitIdentifier() const
mayOmitIdentifier - Return true if the identifier is either optional or not allowed.
void ActOnReenterCXXMethodParameter(Scope *S, ParmVarDecl *Param)
This is used to implement the constant expression evaluation part of the attribute enable_if extensio...
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.
Decl * ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, RecordDecl *&AnonRecord)
ParsedFreeStandingDeclSpec - This method is invoked when a declspec with no declarator (e...
Represents a character-granular source range.
SourceLocation getAtomicSpecLoc() const
ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec *SS=nullptr, bool isClassName=false, bool HasTrailingDot=false, ParsedType ObjectType=nullptr, 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...
void SkipMalformedDecl()
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a s...
static DeclaratorChunk getPipe(unsigned TypeQuals, SourceLocation Loc)
Return a DeclaratorChunk for a block.
TypeResult ActOnTypeName(Scope *S, Declarator &D)
void setEofData(const void *D)
static bool isPipeDeclerator(const Declarator &D)
void setAsmLabel(Expr *E)
SourceLocation getVolatileSpecLoc() const
enum clang::DeclaratorChunk::@185 Kind
static const TST TST_decimal64
bool isPastIdentifier() const
isPastIdentifier - Return true if we have parsed beyond the point where the
Decl * ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart, Declarator &D, Expr *BitfieldWidth)
ActOnField - Each field of a C struct/union is passed into this in order to create a FieldDecl object...
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
class LLVM_ALIGNAS(8) TemplateSpecializationType unsigned NumArgs
Represents a type template specialization; the template must be a class template, a type alias templa...
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.
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)
const clang::PrintingPolicy & getPrintingPolicy() const
PrettyDeclStackTraceEntry - If a crash occurs in the parser while parsing something related to a decl...
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 ...
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)
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.
Encodes a location in the source.
void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record)
static const TST TST_auto_type
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, SourceRange BraceRange)
ActOnTagFinishDefinition - Invoked once we have finished parsing the definition of a tag (enumeration...
SourceLocation getEndLoc() const
UnqualifiedId & getName()
Retrieve the name specified by this declarator.
void FinalizeDeclaration(Decl *D)
FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform any semantic actions neces...
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getPipeLoc() const
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)
These methods set the specified attribute of the DeclSpec and return false if there was no error...
Scope * getCurScope() const
static const TSS TSS_signed
bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const
Return true if we have an ObjC keyword identifier.
void setIdentifierInfo(IdentifierInfo *II)
ExtensionRAIIObject - This saves the state of extension warnings when constructed and disables them...
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
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
SourceLocation getVirtualSpecLoc() const
SourceLocation getUnalignedSpecLoc() const
static const TST TST_typeofType
SourceLocation getBegin() const
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
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {...
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.
SourceRange getSourceRange() const LLVM_READONLY
Get the source range that spans this declarator.
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.
bool setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
static bool isInvalid(LocType Loc, bool *Invalid)
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)...
CXXScopeSpec SS
The nested-name-specifier that precedes the template name.
static const TST TST_int128
void CodeCompleteTag(Scope *S, unsigned TagSpec)
void ActOnParamDefaultArgument(Decl *param, SourceLocation EqualLoc, Expr *defarg)
ActOnParamDefaultArgument - Check whether the default argument provided for a function parameter is w...
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.
SourceLocation getLocEnd() const LLVM_READONLY
EnumDecl - Represents an enum.
bool hasName() const
hasName - Whether this declarator has a name, which might be an identifier (accessible via getIdentif...
The name refers to a template whose specialization produces a type.
static const TST TST_unspecified
bool isFirstDeclarator() const
Syntax
The style used to specify an attribute.
bool isCurrentClassName(const IdentifierInfo &II, Scope *S, const CXXScopeSpec *SS=nullptr)
isCurrentClassName - Determine whether the identifier II is the name of the class type currently bein...
ExprResult ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, bool IsType, void *TyOrEx, SourceRange ArgRange)
ActOnUnaryExprOrTypeTraitExpr - Handle sizeof(type) and sizeof expr and the same for alignof and __al...
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
mayHaveIdentifier - Return true if the identifier is either optional or required. ...
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 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 an unexpanded parameter pack might be permitted in this location.
This is a scope that can contain a declaration.
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.
bool isCXX11Attribute() const
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
void setInvalidType(bool Val=true)
ExprResult ParseConstantExpression(TypeCastState isTypeCast=NotTypeCast)
void ActOnParamDefaultArgumentError(Decl *param, SourceLocation EqualLoc)
ActOnParamDefaultArgumentError - Parsing or semantic analysis of the default argument for the paramet...
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)
isValidAfterIdentifierInDeclaratorAfterDeclSpec - Return true if the specified token is valid after t...
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
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)
ActOnParamUnparsedDefaultArgument - We've seen a default argument for a function parameter, but we can't parse it yet because we're inside a class definition.
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...
static const TST TST_float128
bool TryAnnotateTypeOrScopeToken(bool EnteringContext=false, bool NeedType=false)
TryAnnotateTypeOrScopeToken - If the current token position is on a typename (possibly qualified in C...
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...
void revertTokenIDToIdentifier()
Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2 compatibility.
bool diagnoseIdentifier() const
diagnoseIdentifier - Return true if the identifier is prohibited and should be diagnosed (because it ...
bool isTypeSpecOwned() const
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.
void ExtendWithDeclSpec(const DeclSpec &DS)
ExtendWithDeclSpec - Extend the declarator source range to include the given declspec, unless its location is invalid.
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.
bool isSet() const
Deprecated.
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...
ParamInfo - An array of paraminfo objects is allocated whenever a function declarator is parsed...
const DeclaratorChunk & getTypeObject(unsigned i) const
Return the specified TypeInfo from this declarator.
void setLocation(SourceLocation L)
AttributeList * getNext() const
A trivial tuple used to represent a source range.
bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
NamedDecl - This represents a decl with a name.
bool isInvalidType() const
SourceLocation EndLocation
The location of the last token that describes this unqualified-id.
static const TSCS TSCS__Thread_local
ParsedType ActOnMSVCUnknownTypeName(const IdentifierInfo &II, SourceLocation NameLoc, bool IsTemplateTypeArg)
Attempt to behave like MSVC in situations where lookup of an unqualified type name has failed in a de...
bool isFirstDeclarationOfMember()
Returns true if this declares a real member and not a friend.
SourceLocation getLocEnd() const LLVM_READONLY
void SetRangeEnd(SourceLocation Loc)
ParsedAttributes - A collection of parsed attributes.
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...
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
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
Decl * ActOnDeclarator(Scope *S, Declarator &D)
AttributeList - Represents a syntactic attribute.
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