26 #include "llvm/ADT/SmallString.h" 27 #include "llvm/Support/TimeProfiler.h" 29 using namespace clang;
61 assert(Tok.
is(tok::kw_namespace) &&
"Not a namespace!");
65 if (Tok.
is(tok::code_completion)) {
73 InnerNamespaceInfoList ExtraNSs;
76 ParsedAttributesWithRange attrs(AttrFactory);
80 ? diag::warn_cxx14_compat_ns_enum_attribute
81 : diag::ext_ns_enum_attribute)
84 ParseCXX11Attributes(attrs);
87 if (Tok.
is(tok::identifier)) {
90 while (Tok.
is(tok::coloncolon) &&
93 GetLookAheadToken(2).
is(tok::identifier)))) {
95 InnerNamespaceInfo Info;
98 if (Tok.
is(tok::kw_inline)) {
101 FirstNestedInlineLoc = Info.InlineLoc;
107 ExtraNSs.push_back(Info);
112 if (!ExtraNSs.empty() && attrLoc.isValid())
113 Diag(attrLoc, diag::err_unexpected_nested_namespace_attribute);
116 if (Tok.
is(tok::kw___attribute)) {
118 ParseGNUAttributes(attrs);
121 if (Tok.
is(tok::equal)) {
123 Diag(Tok, diag::err_expected) << tok::identifier;
128 if (attrLoc.isValid())
129 Diag(attrLoc, diag::err_unexpected_namespace_attributes_alias);
131 Diag(InlineLoc, diag::err_inline_namespace_alias)
133 Decl *NSAlias = ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd);
138 if (T.consumeOpen()) {
140 Diag(Tok, diag::err_expected) << tok::l_brace;
142 Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace;
149 Diag(T.getOpenLocation(), diag::err_namespace_nonnamespace_scope);
154 if (ExtraNSs.empty()) {
156 }
else if (InlineLoc.
isValid()) {
157 Diag(InlineLoc, diag::err_inline_nested_namespace_definition);
159 Diag(ExtraNSs[0].NamespaceLoc,
160 diag::warn_cxx14_compat_nested_namespace_definition);
161 if (FirstNestedInlineLoc.
isValid())
162 Diag(FirstNestedInlineLoc,
163 diag::warn_cxx17_compat_inline_nested_namespace_definition);
165 Diag(ExtraNSs[0].NamespaceLoc,
166 diag::warn_cxx14_compat_nested_namespace_definition);
167 if (FirstNestedInlineLoc.
isValid())
168 Diag(FirstNestedInlineLoc, diag::ext_inline_nested_namespace_definition);
170 TentativeParsingAction TPA(*
this);
172 Token rBraceToken = Tok;
175 if (!rBraceToken.
is(tok::r_brace)) {
176 Diag(ExtraNSs[0].NamespaceLoc, diag::ext_nested_namespace_definition)
178 ExtraNSs.back().IdentLoc);
180 std::string NamespaceFix;
181 for (
const auto &ExtraNS : ExtraNSs) {
182 NamespaceFix +=
" { ";
183 if (ExtraNS.InlineLoc.isValid())
184 NamespaceFix +=
"inline ";
185 NamespaceFix +=
"namespace ";
186 NamespaceFix += ExtraNS.Ident->getName();
190 for (
unsigned i = 0, e = ExtraNSs.size();
i != e; ++
i)
193 Diag(ExtraNSs[0].NamespaceLoc, diag::ext_nested_namespace_definition)
196 ExtraNSs.back().IdentLoc),
202 if (FirstNestedInlineLoc.
isValid())
203 Diag(FirstNestedInlineLoc, diag::ext_inline_nested_namespace_definition);
209 diag::warn_cxx98_compat_inline_namespace : diag::ext_inline_namespace);
216 getCurScope(), InlineLoc, NamespaceLoc, IdentLoc, Ident,
217 T.getOpenLocation(), attrs, ImplicitUsingDirectiveDecl);
220 NamespaceLoc,
"parsing namespace");
224 ParseInnerNamespace(ExtraNSs, 0, InlineLoc, attrs, T);
227 NamespaceScope.Exit();
229 DeclEnd = T.getCloseLocation();
233 ImplicitUsingDirectiveDecl);
237 void Parser::ParseInnerNamespace(
const InnerNamespaceInfoList &InnerNSs,
241 if (index == InnerNSs.size()) {
242 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
244 ParsedAttributesWithRange attrs(AttrFactory);
245 MaybeParseCXX11Attributes(attrs);
246 ParseExternalDeclaration(attrs);
262 getCurScope(), InnerNSs[index].InlineLoc, InnerNSs[index].NamespaceLoc,
263 InnerNSs[index].IdentLoc, InnerNSs[index].Ident,
265 assert(!ImplicitUsingDirectiveDecl &&
266 "nested namespace definition cannot define anonymous namespace");
268 ParseInnerNamespace(InnerNSs, ++index, InlineLoc, attrs, Tracker);
270 NamespaceScope.Exit();
281 assert(Tok.
is(tok::equal) &&
"Not equal token");
285 if (Tok.
is(tok::code_completion)) {
293 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
false,
299 if (Tok.
isNot(tok::identifier)) {
300 Diag(Tok, diag::err_expected_namespace_name);
319 if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after_namespace_name))
323 Alias, SS, IdentLoc, Ident);
334 assert(isTokenStringLiteral() &&
"Not a string literal!");
335 ExprResult Lang = ParseStringLiteralExpression(
false);
345 ParsedAttributesWithRange attrs(AttrFactory);
346 MaybeParseCXX11Attributes(attrs);
348 if (Tok.
isNot(tok::l_brace)) {
355 ParseExternalDeclaration(attrs, &DS);
363 ProhibitAttributes(attrs);
368 unsigned NestedModules = 0;
371 case tok::annot_module_begin:
376 case tok::annot_module_end:
383 case tok::annot_module_include:
395 ParsedAttributesWithRange attrs(AttrFactory);
396 MaybeParseCXX11Attributes(attrs);
397 ParseExternalDeclaration(attrs);
416 Decl *Parser::ParseExportDeclaration() {
417 assert(Tok.
is(tok::kw_export));
425 if (Tok.
isNot(tok::l_brace)) {
427 ParsedAttributesWithRange Attrs(AttrFactory);
428 MaybeParseCXX11Attributes(Attrs);
429 MaybeParseMicrosoftAttributes(Attrs);
430 ParseExternalDeclaration(Attrs);
441 Diag(ExportLoc, diag::err_export_empty)
445 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
447 ParsedAttributesWithRange Attrs(AttrFactory);
448 MaybeParseCXX11Attributes(Attrs);
449 MaybeParseMicrosoftAttributes(Attrs);
450 ParseExternalDeclaration(Attrs);
455 T.getCloseLocation());
462 const ParsedTemplateInfo &TemplateInfo,
464 ParsedAttributesWithRange &attrs) {
465 assert(Tok.
is(tok::kw_using) &&
"Not using token");
471 if (Tok.
is(tok::code_completion)) {
478 while (Tok.
is(tok::kw_template)) {
480 Diag(TemplateLoc, diag::err_unexpected_template_after_using)
485 if (Tok.
is(tok::kw_namespace)) {
487 if (TemplateInfo.Kind) {
489 Diag(UsingLoc, diag::err_templated_using_directive_declaration)
493 Decl *UsingDir = ParseUsingDirective(Context, UsingLoc, DeclEnd, attrs);
500 ProhibitAttributes(attrs);
502 return ParseUsingDeclaration(Context, TemplateInfo, UsingLoc, DeclEnd,
520 assert(Tok.
is(tok::kw_namespace) &&
"Not 'namespace' token");
525 if (Tok.
is(tok::code_completion)) {
533 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
false,
543 if (Tok.
isNot(tok::identifier)) {
544 Diag(Tok, diag::err_expected_namespace_name);
563 bool GNUAttr =
false;
564 if (Tok.
is(tok::kw___attribute)) {
566 ParseGNUAttributes(attrs);
571 if (ExpectAndConsume(tok::semi,
572 GNUAttr ? diag::err_expected_semi_after_attribute_list
573 : diag::err_expected_semi_after_namespace_name))
577 IdentLoc, NamespcName, attrs);
586 UsingDeclarator &D) {
593 if (Tok.
is(tok::kw___super)) {
600 if (ParseOptionalCXXScopeSpecifier(D.SS,
nullptr,
false,
605 if (D.SS.isInvalid())
620 Tok.
is(tok::identifier) &&
624 !D.SS.getScopeRep()->getAsNamespace() &&
625 !D.SS.getScopeRep()->getAsNamespaceAlias()) {
629 D.Name.setConstructorName(Type, IdLoc, IdLoc);
634 !(Tok.
is(tok::identifier) &&
637 nullptr,
nullptr, D.Name))
643 diag::warn_cxx17_compat_using_declaration_pack :
644 diag::ext_using_declaration_pack);
667 const ParsedTemplateInfo &TemplateInfo,
672 ParsedAttributesWithRange MisplacedAttrs(AttrFactory);
673 MaybeParseCXX11Attributes(MisplacedAttrs);
676 bool InvalidDeclarator = ParseUsingDeclarator(Context, D);
678 ParsedAttributesWithRange Attrs(AttrFactory);
679 MaybeParseGNUAttributes(Attrs);
680 MaybeParseCXX11Attributes(Attrs);
683 if (Tok.
is(tok::equal)) {
684 if (InvalidDeclarator) {
691 if (MisplacedAttrs.Range.isValid()) {
692 Diag(MisplacedAttrs.Range.getBegin(), diag::err_attributes_not_allowed)
697 Attrs.takeAllFrom(MisplacedAttrs);
700 Decl *DeclFromDeclSpec =
nullptr;
701 Decl *AD = ParseAliasDeclarationAfterDeclarator(
702 TemplateInfo, UsingLoc, D, DeclEnd, AS, Attrs, &DeclFromDeclSpec);
708 ProhibitAttributes(MisplacedAttrs);
709 ProhibitAttributes(Attrs);
714 if (TemplateInfo.Kind) {
716 Diag(UsingLoc, diag::err_templated_using_directive_declaration)
728 MaybeParseGNUAttributes(Attrs);
730 if (InvalidDeclarator)
735 if (D.TypenameLoc.isValid() &&
737 Diag(D.Name.getSourceRange().getBegin(),
738 diag::err_typename_identifiers_only)
745 D.TypenameLoc, D.SS, D.Name,
746 D.EllipsisLoc, Attrs);
748 DeclsInGroup.push_back(UD);
756 InvalidDeclarator = ParseUsingDeclarator(Context, D);
759 if (DeclsInGroup.size() > 1)
761 diag::warn_cxx17_compat_multi_using_declaration :
762 diag::ext_multi_using_declaration);
766 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
767 !Attrs.empty() ?
"attributes list" 768 :
"using declaration"))
774 Decl *Parser::ParseAliasDeclarationAfterDeclarator(
778 if (ExpectAndConsume(tok::equal)) {
784 diag::warn_cxx98_compat_alias_declaration :
785 diag::ext_alias_declaration);
789 if (TemplateInfo.Kind == ParsedTemplateInfo::Template &&
792 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization)
794 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation)
796 if (SpecKind != -1) {
800 D.Name.TemplateId->RAngleLoc);
802 Range = TemplateInfo.getSourceRange();
803 Diag(Range.
getBegin(), diag::err_alias_declaration_specialization)
804 << SpecKind << Range;
811 Diag(D.Name.StartLocation, diag::err_alias_declaration_not_identifier);
815 }
else if (D.TypenameLoc.isValid())
816 Diag(D.TypenameLoc, diag::err_alias_declaration_not_identifier)
819 D.SS.isNotEmpty() ? D.SS.getEndLoc() : D.TypenameLoc));
820 else if (D.SS.isNotEmpty())
821 Diag(D.SS.getBeginLoc(), diag::err_alias_declaration_not_identifier)
823 if (D.EllipsisLoc.isValid())
824 Diag(D.EllipsisLoc, diag::err_alias_declaration_pack_expansion)
827 Decl *DeclFromDeclSpec =
nullptr;
832 AS, &DeclFromDeclSpec, &Attrs);
834 *OwnedType = DeclFromDeclSpec;
838 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
839 !Attrs.
empty() ?
"attributes list" 840 :
"alias declaration"))
845 TemplateParams ? TemplateParams->data() :
nullptr,
846 TemplateParams ? TemplateParams->size() : 0);
848 UsingLoc, D.Name, Attrs, TypeAlias,
861 assert(Tok.
isOneOf(tok::kw_static_assert, tok::kw__Static_assert) &&
862 "Not a static_assert declaration");
865 Diag(Tok, diag::ext_c11_static_assert);
866 if (Tok.
is(tok::kw_static_assert))
867 Diag(Tok, diag::warn_cxx98_compat_static_assert);
872 if (T.consumeOpen()) {
873 Diag(Tok, diag::err_expected) << tok::l_paren;
881 if (AssertExpr.isInvalid()) {
887 if (Tok.
is(tok::r_paren)) {
889 ? diag::warn_cxx14_compat_static_assert_no_message
890 : diag::ext_static_assert_no_message)
893 :
FixItHint::CreateInsertion(Tok.getLocation(),
", \"\""));
895 if (ExpectAndConsume(tok::comma)) {
900 if (!isTokenStringLiteral()) {
901 Diag(Tok, diag::err_expected_string_literal)
907 AssertMessage = ParseStringLiteralExpression();
917 ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert);
922 T.getCloseLocation());
931 assert(Tok.
isOneOf(tok::kw_decltype, tok::annot_decltype)
932 &&
"Not a decltype specifier");
938 if (Tok.
is(tok::annot_decltype)) {
939 Result = getExprAnnotation(Tok);
941 ConsumeAnnotationToken();
942 if (Result.isInvalid()) {
948 Diag(Tok, diag::warn_cxx98_compat_decltype);
953 if (T.expectAndConsume(diag::err_expected_lparen_after,
954 "decltype", tok::r_paren)) {
957 StartLoc : T.getOpenLocation();
961 if (Tok.
is(tok::kw_auto)) {
967 ? diag::warn_cxx11_compat_decltype_auto_type_specifier
968 : diag::ext_decltype_auto_type_specifier);
982 if (Result.isInvalid()) {
985 EndLoc = ConsumeParen();
992 assert(Tok.
is(tok::semi));
1005 if (T.getCloseLocation().isInvalid()) {
1009 return T.getCloseLocation();
1012 if (Result.isInvalid()) {
1014 return T.getCloseLocation();
1017 EndLoc = T.getCloseLocation();
1019 assert(!Result.isInvalid());
1021 const char *PrevSpec =
nullptr;
1027 DiagID, Result.get(), Policy)
1030 Diag(StartLoc, DiagID) << PrevSpec;
1036 void Parser::AnnotateExistingDecltypeSpecifier(
const DeclSpec& DS,
1045 Tok.
setKind(tok::annot_decltype);
1046 setExprAnnotation(Tok,
1055 void Parser::ParseUnderlyingTypeSpecifier(
DeclSpec &DS) {
1056 assert(Tok.
is(tok::kw___underlying_type) &&
1057 "Not an underlying type specifier");
1061 if (T.expectAndConsume(diag::err_expected_lparen_after,
1062 "__underlying_type", tok::r_paren)) {
1074 if (T.getCloseLocation().isInvalid())
1077 const char *PrevSpec =
nullptr;
1080 DiagID, Result.
get(),
1082 Diag(StartLoc, DiagID) << PrevSpec;
1107 if (Tok.
is(tok::kw_typename)) {
1108 Diag(Tok, diag::err_expected_class_name_not_template)
1115 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
false))
1123 if (Tok.
isOneOf(tok::kw_decltype, tok::annot_decltype)) {
1130 EndLocation = ParseDecltypeSpecifier(DS);
1137 if (Tok.
is(tok::annot_template_id)) {
1142 AnnotateTemplateIdTokenAsType(
true);
1144 assert(Tok.
is(tok::annot_typename) &&
"template-id -> type failed");
1147 ConsumeAnnotationToken();
1157 if (Tok.
isNot(tok::identifier)) {
1158 Diag(Tok, diag::err_expected_class_name);
1165 if (Tok.
is(tok::less)) {
1171 &SS, Template, TNK)) {
1172 Diag(IdLoc, diag::err_unknown_template_name)
1177 TemplateArgList TemplateArgs;
1179 ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs,
1193 AnnotateTemplateIdTokenAsType(
true);
1197 if (Tok.
isNot(tok::annot_typename))
1204 ConsumeAnnotationToken();
1211 *Id, IdLoc,
getCurScope(), &SS,
true,
false,
nullptr,
1214 false, &CorrectedII);
1216 Diag(IdLoc, diag::err_expected_class_name);
1221 EndLocation = IdLoc;
1229 const char *PrevSpec =
nullptr;
1238 void Parser::ParseMicrosoftInheritanceClassAttributes(
ParsedAttributes &attrs) {
1239 while (Tok.
isOneOf(tok::kw___single_inheritance,
1240 tok::kw___multiple_inheritance,
1241 tok::kw___virtual_inheritance)) {
1244 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1252 bool Parser::isValidAfterTypeSpecifier(
bool CouldBeBitfield) {
1260 case tok::identifier:
1262 case tok::coloncolon:
1263 case tok::annot_cxxscope:
1264 case tok::annot_typename:
1265 case tok::annot_template_id:
1266 case tok::kw_decltype:
1269 case tok::kw_operator:
1270 case tok::kw___declspec:
1275 case tok::kw___attribute:
1276 case tok::annot_pragma_pack:
1278 case tok::annot_pragma_ms_pragma:
1280 case tok::annot_pragma_ms_vtordisp:
1282 case tok::annot_pragma_ms_pointers_to_members:
1285 return CouldBeBitfield;
1287 case tok::kw___cdecl:
1288 case tok::kw___fastcall:
1289 case tok::kw___stdcall:
1290 case tok::kw___thiscall:
1291 case tok::kw___vectorcall:
1297 case tok::kw_volatile:
1298 case tok::kw_restrict:
1299 case tok::kw__Atomic:
1300 case tok::kw___unaligned:
1304 case tok::kw_inline:
1305 case tok::kw_virtual:
1306 case tok::kw_friend:
1308 case tok::kw_static:
1309 case tok::kw_extern:
1310 case tok::kw_typedef:
1311 case tok::kw_register:
1313 case tok::kw_mutable:
1314 case tok::kw_thread_local:
1315 case tok::kw_constexpr:
1331 if (!isKnownToBeTypeSpecifier(
NextToken()))
1388 const ParsedTemplateInfo &TemplateInfo,
1390 bool EnteringContext, DeclSpecContext DSC,
1391 ParsedAttributesWithRange &Attributes) {
1393 if (TagTokKind == tok::kw_struct)
1395 else if (TagTokKind == tok::kw___interface)
1397 else if (TagTokKind == tok::kw_class)
1400 assert(TagTokKind == tok::kw_union &&
"Not a class specifier");
1404 if (Tok.
is(tok::code_completion)) {
1407 return cutOffParsing();
1420 bool shouldDelayDiagsInTag =
1421 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
1422 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
1425 ParsedAttributesWithRange attrs(AttrFactory);
1427 MaybeParseGNUAttributes(attrs);
1428 MaybeParseMicrosoftDeclSpecs(attrs);
1431 if (Tok.
isOneOf(tok::kw___single_inheritance,
1432 tok::kw___multiple_inheritance,
1433 tok::kw___virtual_inheritance))
1434 ParseMicrosoftInheritanceClassAttributes(attrs);
1439 MaybeParseCXX11Attributes(attrs);
1446 Tok.
isNot(tok::identifier) &&
1449 Tok.
isOneOf(tok::kw___is_abstract,
1450 tok::kw___is_aggregate,
1451 tok::kw___is_arithmetic,
1453 tok::kw___is_assignable,
1454 tok::kw___is_base_of,
1456 tok::kw___is_complete_type,
1457 tok::kw___is_compound,
1459 tok::kw___is_constructible,
1460 tok::kw___is_convertible,
1461 tok::kw___is_convertible_to,
1462 tok::kw___is_destructible,
1465 tok::kw___is_floating_point,
1467 tok::kw___is_function,
1468 tok::kw___is_fundamental,
1469 tok::kw___is_integral,
1470 tok::kw___is_interface_class,
1471 tok::kw___is_literal,
1472 tok::kw___is_lvalue_expr,
1473 tok::kw___is_lvalue_reference,
1474 tok::kw___is_member_function_pointer,
1475 tok::kw___is_member_object_pointer,
1476 tok::kw___is_member_pointer,
1477 tok::kw___is_nothrow_assignable,
1478 tok::kw___is_nothrow_constructible,
1479 tok::kw___is_nothrow_destructible,
1480 tok::kw___is_object,
1482 tok::kw___is_pointer,
1483 tok::kw___is_polymorphic,
1484 tok::kw___is_reference,
1485 tok::kw___is_rvalue_expr,
1486 tok::kw___is_rvalue_reference,
1488 tok::kw___is_scalar,
1489 tok::kw___is_sealed,
1490 tok::kw___is_signed,
1491 tok::kw___is_standard_layout,
1492 tok::kw___is_trivial,
1493 tok::kw___is_trivially_assignable,
1494 tok::kw___is_trivially_constructible,
1495 tok::kw___is_trivially_copyable,
1497 tok::kw___is_unsigned,
1499 tok::kw___is_volatile))
1505 TryKeywordIdentFallback(
true);
1507 struct PreserveAtomicIdentifierInfoRAII {
1508 PreserveAtomicIdentifierInfoRAII(
Token &Tok,
bool Enabled)
1509 : AtomicII(nullptr) {
1512 assert(Tok.
is(tok::kw__Atomic));
1517 ~PreserveAtomicIdentifierInfoRAII() {
1520 AtomicII->revertIdentifierToTokenID(tok::kw__Atomic);
1530 bool ShouldChangeAtomicToIdentifier =
getLangOpts().MSVCCompat &&
1531 Tok.
is(tok::kw__Atomic) &&
1533 PreserveAtomicIdentifierInfoRAII AtomicTokenGuard(
1534 Tok, ShouldChangeAtomicToIdentifier);
1544 bool HasValidSpec =
true;
1545 if (ParseOptionalCXXScopeSpecifier(Spec,
nullptr, EnteringContext)) {
1547 HasValidSpec =
false;
1550 if (Tok.
isNot(tok::identifier) && Tok.
isNot(tok::annot_template_id)) {
1551 Diag(Tok, diag::err_expected) << tok::identifier;
1552 HasValidSpec =
false;
1560 auto RecoverFromUndeclaredTemplateName = [&](
IdentifierInfo *Name,
1563 bool KnownUndeclared) {
1564 Diag(NameLoc, diag::err_explicit_spec_non_template)
1565 << (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation)
1566 << TagTokKind << Name << TemplateArgRange << KnownUndeclared;
1570 if (TemplateParams && TemplateInfo.LastParameterListWasEmpty) {
1571 if (TemplateParams->size() > 1) {
1572 TemplateParams->pop_back();
1574 TemplateParams =
nullptr;
1575 const_cast<ParsedTemplateInfo &
>(TemplateInfo).
Kind =
1576 ParsedTemplateInfo::NonTemplate;
1578 }
else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
1580 TemplateParams =
nullptr;
1581 const_cast<ParsedTemplateInfo &
>(TemplateInfo).
Kind =
1582 ParsedTemplateInfo::NonTemplate;
1583 const_cast<ParsedTemplateInfo &
>(TemplateInfo).TemplateLoc =
1585 const_cast<ParsedTemplateInfo &
>(TemplateInfo).ExternLoc =
1594 if (Tok.
is(tok::identifier)) {
1602 TemplateArgList TemplateArgs;
1604 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs,
1610 RecoverFromUndeclaredTemplateName(
1611 Name, NameLoc,
SourceRange(LAngleLoc, RAngleLoc),
false);
1613 }
else if (Tok.
is(tok::annot_template_id)) {
1614 TemplateId = takeTemplateIdAnnotation(Tok);
1615 NameLoc = ConsumeAnnotationToken();
1620 TemplateId->
Kind, NameLoc, Name);
1622 RecoverFromUndeclaredTemplateName(
1625 TemplateId =
nullptr;
1639 Diag(TemplateId->
LAngleLoc, diag::err_template_spec_syntax_non_template)
1640 << TemplateId->
Name <<
static_cast<int>(TemplateId->
Kind) << Range;
1675 MaybeParseCXX11Attributes(Attributes);
1677 const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy();
1679 if (DSC == DeclSpecContext::DSC_trailing)
1681 else if (Tok.
is(tok::l_brace) ||
1683 (isCXX11FinalKeyword() &&
1699 }
else if (isCXX11FinalKeyword() && (
NextToken().is(tok::l_square) ||
1703 TentativeParsingAction PA(*
this);
1710 if (Tok.
is(tok::l_square) &&
NextToken().
is(tok::l_square)) {
1714 }
else if (Tok.
is(tok::kw_alignas) &&
NextToken().
is(tok::l_paren)) {
1724 if (Tok.
isOneOf(tok::l_brace, tok::colon))
1730 }
else if (!isTypeSpecifier(DSC) &&
1731 (Tok.
is(tok::semi) ||
1734 if (Tok.
isNot(tok::semi)) {
1735 const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy();
1737 ExpectAndConsume(tok::semi, diag::err_expected_after,
1739 PP.EnterToken(Tok,
true);
1755 Diag(AttrRange.
getBegin(), diag::err_attributes_not_allowed)
1769 if (shouldDelayDiagsInTag) {
1770 diagsFromTag.done();
1772 diagsFromTag.redelay();
1779 Diag(StartLoc, diag::err_anon_type_definition)
1804 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation &&
1807 ProhibitAttributes(attrs);
1809 TagOrTempResult = Actions.ActOnExplicitInstantiation(
1810 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc,
1811 TagType, StartLoc, SS, TemplateId->
Template,
1821 TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate)) {
1822 ProhibitAttributes(attrs);
1823 TypeResult = Actions.ActOnTagTemplateIdType(TUK, TagType, StartLoc,
1835 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
1848 "Expected a definition here");
1852 TemplateParams =
nullptr;
1855 PP.getLocForEndOfToken(TemplateInfo.TemplateLoc);
1857 diag::err_explicit_instantiation_with_definition)
1864 FakedParamLists.push_back(Actions.ActOnTemplateParameterList(
1866 LAngleLoc,
nullptr));
1867 TemplateParams = &FakedParamLists;
1872 TagOrTempResult = Actions.ActOnClassTemplateSpecialization(
1877 TemplateParams ? TemplateParams->size() : 0),
1880 }
else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation &&
1887 ProhibitAttributes(attrs);
1889 TagOrTempResult = Actions.ActOnExplicitInstantiation(
1890 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc,
1891 TagType, StartLoc, SS, Name, NameLoc, attrs);
1893 TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) {
1894 ProhibitAttributes(attrs);
1896 TagOrTempResult = Actions.ActOnTemplatedFriendTag(
1900 TemplateParams ? TemplateParams->size() : 0));
1903 ProhibitAttributes(attrs);
1906 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
1909 Diag(Tok, diag::err_template_defn_explicit_instantiation)
1911 TemplateParams =
nullptr;
1914 bool IsDependent =
false;
1924 stripTypeAttributesOffDeclSpec(attrs, DS, TUK);
1927 TagOrTempResult = Actions.ActOnTag(
1928 getCurScope(), TagType, TUK, StartLoc, SS, Name, NameLoc, attrs, AS,
1931 DSC == DeclSpecContext::DSC_type_specifier,
1932 DSC == DeclSpecContext::DSC_template_param ||
1933 DSC == DeclSpecContext::DSC_template_type_arg,
1940 TypeResult = Actions.ActOnDependentTag(
getCurScope(), TagType, TUK,
1941 SS, Name, StartLoc, NameLoc);
1947 assert(Tok.
is(tok::l_brace) ||
1949 isCXX11FinalKeyword());
1951 SkipCXXMemberSpecification(StartLoc, AttrFixitLoc, TagType,
1952 TagOrTempResult.
get());
1954 ParseCXXMemberSpecification(StartLoc, AttrFixitLoc, attrs, TagType,
1955 TagOrTempResult.
get());
1960 ParseStructUnionBody(StartLoc, TagType, D);
1962 !Actions.ActOnDuplicateDefinition(DS, TagOrTempResult.
get(),
1972 Actions.ProcessDeclAttributeDelayed(TagOrTempResult.
get(), attrs);
1974 const char *PrevSpec =
nullptr;
1979 NameLoc.isValid() ? NameLoc : StartLoc,
1980 PrevSpec, DiagID, TypeResult.
get(), Policy);
1981 }
else if (!TagOrTempResult.
isInvalid()) {
1983 NameLoc.isValid() ? NameLoc : StartLoc,
1984 PrevSpec, DiagID, TagOrTempResult.
get(), Owned,
1992 Diag(StartLoc, DiagID) << PrevSpec;
2008 (TemplateInfo.Kind || !isValidAfterTypeSpecifier(
false))) {
2009 if (Tok.
isNot(tok::semi)) {
2010 const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy();
2011 ExpectAndConsume(tok::semi, diag::err_expected_after,
2016 PP.EnterToken(Tok,
true);
2029 void Parser::ParseBaseClause(
Decl *ClassDecl) {
2030 assert(Tok.
is(tok::colon) &&
"Not a base clause");
2038 BaseResult Result = ParseBaseSpecifier(ClassDecl);
2045 BaseInfo.push_back(Result.
get());
2055 Actions.ActOnBaseSpecifiers(ClassDecl, BaseInfo);
2070 bool IsVirtual =
false;
2073 ParsedAttributesWithRange Attributes(AttrFactory);
2074 MaybeParseCXX11Attributes(Attributes);
2080 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2087 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2091 if (Tok.
is(tok::kw_virtual)) {
2095 Diag(VirtualLoc, diag::err_dup_virtual)
2102 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2116 TypeResult BaseType = ParseBaseTypeSpecifier(BaseLoc, EndLocation);
2131 return Actions.ActOnBaseSpecifier(ClassDecl, Range, Attributes, IsVirtual,
2132 Access, BaseType.
get(), BaseLoc,
2156 void Parser::HandleMemberFunctionDeclDelays(
Declarator& DeclaratorInfo,
2164 if (!NeedLateParse) {
2168 if (Param->hasUnparsedDefaultArg()) {
2169 NeedLateParse =
true;
2175 if (NeedLateParse) {
2178 auto LateMethod =
new LateParsedMethodDeclaration(
this, ThisDecl);
2179 getCurrentClass().LateParsedDeclarations.push_back(LateMethod);
2188 LateMethod->DefaultArgs.reserve(FTI.
NumParams);
2190 LateMethod->DefaultArgs.push_back(LateParsedDefaultArgument(
2211 Ident_final = &PP.getIdentifierTable().get(
"final");
2213 Ident_GNU_final = &PP.getIdentifierTable().get(
"__final");
2215 Ident_sealed = &PP.getIdentifierTable().get(
"sealed");
2216 Ident_override = &PP.getIdentifierTable().get(
"override");
2219 if (II == Ident_override)
2222 if (II == Ident_sealed)
2225 if (II == Ident_final)
2228 if (II == Ident_GNU_final)
2239 void Parser::ParseOptionalCXX11VirtSpecifierSeq(
VirtSpecifiers &VS,
2258 const char *PrevSpec =
nullptr;
2275 ? diag::warn_cxx98_compat_override_control_keyword
2276 : diag::ext_override_control_keyword)
2285 bool Parser::isCXX11FinalKeyword()
const {
2294 bool Parser::ParseCXXMemberDeclaratorBeforeInitializer(
2296 LateParsedAttrList &LateParsedAttrs) {
2301 if (Tok.
isNot(tok::colon))
2302 ParseDeclarator(DeclaratorInfo);
2308 "don't know where identifier would go yet?");
2310 if (BitfieldSize.isInvalid())
2313 ParseOptionalCXX11VirtSpecifierSeq(
2314 VS, getCurrentClass().IsInterface,
2317 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo, VS);
2321 if (Tok.
is(tok::kw_asm)) {
2323 ExprResult AsmLabel(ParseSimpleAsm(&Loc));
2324 if (AsmLabel.isInvalid())
2332 MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs);
2336 if (BitfieldSize.isUnset() && VS.
isUnset()) {
2337 ParseOptionalCXX11VirtSpecifierSeq(
2338 VS, getCurrentClass().IsInterface,
2344 if (AL.isKnownToGCC() && !AL.isCXX11Attribute())
2345 Diag(AL.getLoc(), diag::warn_gcc_attribute_location);
2347 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo, VS);
2353 if (!DeclaratorInfo.
hasName() && BitfieldSize.isUnset()) {
2363 void Parser::MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(
2370 ParseTypeQualifierListOpt(
2371 DS, AR_NoAttributesParsed,
false,
2372 false, llvm::function_ref<
void()>([&]() {
2373 Actions.CodeCompleteFunctionQualifiers(DS, D, &VS);
2380 auto DeclSpecCheck = [&](
DeclSpec::TQ TypeQual, StringRef FixItName,
2383 auto &MQ =
Function.getOrCreateMethodQualifiers();
2384 if (!(MQ.getTypeQualifiers() & TypeQual)) {
2385 std::string Name(FixItName.data());
2388 MQ.SetTypeQual(TypeQual, SpecLoc);
2390 Diag(SpecLoc, diag::err_declspec_after_virtspec)
2399 bool RefQualifierIsLValueRef =
true;
2401 if (ParseRefQualifier(RefQualifierIsLValueRef, RefQualifierLoc)) {
2402 const char *Name = (RefQualifierIsLValueRef ?
"& " :
"&& ");
2404 Function.RefQualifierIsLValueRef = RefQualifierIsLValueRef;
2407 Diag(RefQualifierLoc, diag::err_declspec_after_virtspec)
2408 << (RefQualifierIsLValueRef ?
"&" :
"&&")
2456 const ParsedTemplateInfo &TemplateInfo,
2458 if (Tok.
is(tok::at)) {
2460 Diag(Tok, diag::err_at_defs_cxx);
2462 Diag(Tok, diag::err_at_in_class);
2478 bool MalformedTypeSpec =
false;
2479 if (!TemplateInfo.Kind &&
2480 Tok.
isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) {
2482 MalformedTypeSpec =
true;
2485 if (Tok.
isNot(tok::annot_cxxscope))
2486 isAccessDecl =
false;
2488 isAccessDecl = GetLookAheadToken(2).is(tok::semi);
2495 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
2507 &TemplateKWLoc, Name)) {
2513 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
2514 "access declaration")) {
2530 if (!TemplateInfo.Kind &&
2531 Tok.
isOneOf(tok::kw_static_assert, tok::kw__Static_assert)) {
2537 if (Tok.
is(tok::kw_template)) {
2538 assert(!TemplateInfo.TemplateParams &&
2539 "Nested template improperly parsed?");
2548 if (Tok.
is(tok::kw___extension__)) {
2552 return ParseCXXClassMemberDeclaration(AS, AccessAttrs,
2553 TemplateInfo, TemplateDiags);
2556 ParsedAttributesWithRange attrs(AttrFactory);
2557 ParsedAttributesViewWithRange FnAttrs;
2559 MaybeParseCXX11Attributes(attrs);
2562 FnAttrs.addAll(attrs.begin(), attrs.end());
2563 FnAttrs.Range = attrs.Range;
2565 MaybeParseMicrosoftAttributes(attrs);
2567 if (Tok.
is(tok::kw_using)) {
2568 ProhibitAttributes(attrs);
2574 while (Tok.
is(tok::kw_template)) {
2576 Diag(TemplateLoc, diag::err_unexpected_template_after_using)
2580 if (Tok.
is(tok::kw_namespace)) {
2581 Diag(UsingLoc, diag::err_using_namespace_in_class);
2588 UsingLoc, DeclEnd, AS);
2592 LateParsedAttrList CommonLateParsedAttrs;
2598 if (MalformedTypeSpec)
2601 ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DeclSpecContext::DSC_class,
2602 &CommonLateParsedAttrs);
2610 TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate &&
2611 DiagnoseMissingSemiAfterTagDefinition(DS, AS, DeclSpecContext::DSC_class,
2612 &CommonLateParsedAttrs))
2616 TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->data()
2618 TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->size() : 0);
2622 ProhibitAttributes(FnAttrs);
2625 Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(
2626 getCurScope(), AS, DS, TemplateParams,
false, AnonRecord);
2627 DS.complete(TheDecl);
2629 Decl* decls[] = {AnonRecord, TheDecl};
2630 return Actions.BuildDeclaratorGroup(decls);
2632 return Actions.ConvertDeclToDeclGroup(TheDecl);
2639 LateParsedAttrList LateParsedAttrs;
2644 auto TryConsumePureSpecifier = [&] (
bool AllowDefinition) {
2645 if (Tok.
isNot(tok::equal))
2650 if (Zero.isNot(tok::numeric_constant) || Zero.getLength() != 1 ||
2651 PP.getSpelling(Zero, Buffer) !=
"0")
2654 auto &
After = GetLookAheadToken(2);
2655 if (!
After.isOneOf(tok::semi, tok::comma) &&
2656 !(AllowDefinition &&
2657 After.isOneOf(tok::l_brace, tok::colon, tok::kw_try)))
2666 ExprResult BitfieldSize;
2667 bool ExpectSemi =
true;
2670 if (ParseCXXMemberDeclaratorBeforeInitializer(
2671 DeclaratorInfo, VS, BitfieldSize, LateParsedAttrs)) {
2681 TryConsumePureSpecifier(
true);
2692 if (Tok.
isOneOf(tok::l_brace, tok::colon, tok::kw_try)) {
2694 }
else if (Tok.
is(tok::equal)) {
2696 if (KW.
is(tok::kw_default))
2698 else if (KW.
is(tok::kw_delete))
2710 ProhibitAttributes(FnAttrs);
2727 diag::err_function_declared_typedef);
2734 ParseCXXInlineMethodDef(AS, AccessAttrs, DeclaratorInfo, TemplateInfo,
2738 for (
unsigned i = 0, ni = CommonLateParsedAttrs.size();
i < ni; ++
i) {
2739 CommonLateParsedAttrs[
i]->addDecl(FunDecl);
2741 for (
unsigned i = 0, ni = LateParsedAttrs.size();
i < ni; ++
i) {
2742 LateParsedAttrs[
i]->addDecl(FunDecl);
2745 LateParsedAttrs.clear();
2748 if (Tok.
is(tok::semi))
2749 ConsumeExtraSemi(AfterMemberFunctionDefinition);
2761 bool HasStaticInitializer =
false;
2765 if (!TryConsumePureSpecifier(
false))
2767 HasStaticInitializer =
true;
2774 if (BitfieldSize.
get())
2776 ? diag::warn_cxx17_compat_bitfield_member_init
2777 : diag::ext_bitfield_member_init);
2780 HasStaticInitializer =
true;
2798 E = Ranges.end(); I != E; ++I)
2799 Diag((*I).getBegin(), diag::err_attributes_not_allowed) << *I;
2801 ThisDecl = Actions.ActOnFriendFunctionDecl(
getCurScope(), DeclaratorInfo,
2804 ThisDecl = Actions.ActOnCXXMemberDeclarator(
getCurScope(), AS,
2808 VS, HasInClassInit);
2811 ThisDecl ? dyn_cast<VarTemplateDecl>(ThisDecl) :
nullptr)
2814 ThisDecl = VT->getTemplatedDecl();
2817 Actions.ProcessDeclAttributeList(
getCurScope(), ThisDecl, AccessAttrs);
2826 HasStaticInitializer =
true;
2829 if (ThisDecl && PureSpecLoc.
isValid())
2830 Actions.ActOnPureSpecifier(ThisDecl, PureSpecLoc);
2836 ? diag::warn_cxx98_compat_nonstatic_member_init
2837 : diag::ext_nonstatic_member_init);
2845 Diag(Tok, diag::err_incomplete_array_member_init);
2852 ParseCXXNonStaticMemberInitializer(ThisDecl);
2853 }
else if (HasStaticInitializer) {
2855 ExprResult Init = ParseCXXMemberInitializer(
2861 Actions.AddInitializerToDecl(ThisDecl, Init.
get(), EqualLoc.
isInvalid());
2864 Actions.ActOnUninitializedDecl(ThisDecl);
2869 for (
unsigned i = 0, ni = CommonLateParsedAttrs.size();
i < ni; ++
i)
2870 CommonLateParsedAttrs[
i]->addDecl(ThisDecl);
2872 for (
unsigned i = 0, ni = LateParsedAttrs.size();
i < ni; ++
i)
2873 LateParsedAttrs[
i]->addDecl(ThisDecl);
2875 Actions.FinalizeDeclaration(ThisDecl);
2876 DeclsInGroup.push_back(ThisDecl);
2881 HandleMemberFunctionDeclDelays(DeclaratorInfo, ThisDecl);
2883 LateParsedAttrs.clear();
2885 DeclaratorInfo.complete(ThisDecl);
2898 Diag(CommaLoc, diag::err_expected_semi_declaration)
2905 DeclaratorInfo.
clear();
2912 MaybeParseGNUAttributes(DeclaratorInfo);
2914 if (ParseCXXMemberDeclaratorBeforeInitializer(
2915 DeclaratorInfo, VS, BitfieldSize, LateParsedAttrs))
2920 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list)) {
2928 return Actions.FinalizeDeclaratorGroup(
getCurScope(), DS, DeclsInGroup);
2951 ExprResult Parser::ParseCXXMemberInitializer(
Decl *D,
bool IsFunction,
2953 assert(Tok.
isOneOf(tok::equal, tok::l_brace)
2954 &&
"Data member initializer not starting with '=' or '{'");
2959 if (Tok.
is(tok::kw_delete)) {
2974 }
else if (Tok.
is(tok::kw_default)) {
2976 Diag(Tok, diag::err_default_delete_in_multiple_declaration)
2983 if (
const auto *PD = dyn_cast_or_null<MSPropertyDecl>(D)) {
2984 Diag(Tok, diag::err_ms_property_initializer) << PD;
2987 return ParseInitializer();
2990 void Parser::SkipCXXMemberSpecification(
SourceLocation RecordLoc,
2995 assert(isCXX11FinalKeyword() &&
"not a class definition");
3000 ParsedAttributesWithRange Attrs(AttrFactory);
3001 CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc);
3006 if (Tok.
isNot(tok::colon) && Tok.
isNot(tok::l_brace))
3013 if (Tok.
is(tok::colon)) {
3016 ParsingClassDefinition ParsingDef(*
this, TagDecl,
true,
3019 Actions.ActOnTagStartSkippedDefinition(
getCurScope(), TagDecl);
3022 ParseBaseClause(
nullptr);
3024 Actions.ActOnTagFinishSkippedDefinition(OldContext);
3026 if (!Tok.
is(tok::l_brace)) {
3027 Diag(PP.getLocForEndOfToken(PrevTokLocation),
3028 diag::err_expected_lbrace_after_base_specifiers);
3034 assert(Tok.
is(tok::l_brace));
3041 if (Tok.
is(tok::kw___attribute))
3042 MaybeParseGNUAttributes(Attrs);
3051 case tok::kw___if_exists:
3052 case tok::kw___if_not_exists:
3053 ParseMicrosoftIfExistsClassDeclaration(TagType, AccessAttrs, AS);
3058 ConsumeExtraSemi(InsideStruct, TagType);
3062 case tok::annot_pragma_vis:
3063 HandlePragmaVisibility();
3065 case tok::annot_pragma_pack:
3068 case tok::annot_pragma_align:
3069 HandlePragmaAlign();
3071 case tok::annot_pragma_ms_pointers_to_members:
3072 HandlePragmaMSPointersToMembers();
3074 case tok::annot_pragma_ms_pragma:
3075 HandlePragmaMSPragma();
3077 case tok::annot_pragma_ms_vtordisp:
3078 HandlePragmaMSVtorDisp();
3080 case tok::annot_pragma_dump:
3084 case tok::kw_namespace:
3086 DiagnoseUnexpectedNamespace(cast<NamedDecl>(TagDecl));
3089 case tok::kw_private:
3093 return ParseCXXClassMemberDeclaration(AS, AccessAttrs);
3095 case tok::kw_public:
3096 case tok::kw_protected: {
3104 AccessAttrs.clear();
3105 MaybeParseGNUAttributes(AccessAttrs);
3110 Diag(EndLoc, diag::err_expected)
3114 Diag(EndLoc, diag::err_expected)
3124 if (Actions.ActOnAccessSpecifier(NewAS, ASLoc, EndLoc, AccessAttrs)) {
3126 AccessAttrs.clear();
3132 case tok::annot_pragma_openmp:
3133 return ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, AccessAttrs, TagType,
3137 return ParseCXXClassMemberDeclaration(AS, AccessAttrs);
3147 void Parser::ParseCXXMemberSpecification(
SourceLocation RecordLoc,
3149 ParsedAttributesWithRange &Attrs,
3150 unsigned TagType,
Decl *TagDecl) {
3156 llvm::TimeTraceScope TimeScope(
"ParseClass", [&]() {
3157 if (
auto *TD = dyn_cast_or_null<NamedDecl>(TagDecl))
3158 return TD->getQualifiedNameAsString();
3159 return std::string(
"<anonymous>");
3163 "parsing struct/union/class body");
3167 bool NonNestedClass =
true;
3168 if (!ClassStack.empty()) {
3170 if (S->isClassScope()) {
3172 NonNestedClass =
false;
3175 if (getCurrentClass().IsInterface) {
3176 Diag(RecordLoc, diag::err_invalid_member_in_interface)
3178 << (isa<NamedDecl>(TagDecl)
3179 ? cast<NamedDecl>(TagDecl)->getQualifiedNameAsString()
3196 ParsingClassDefinition ParsingDef(*
this, TagDecl, NonNestedClass,
3200 Actions.ActOnTagStartDefinition(
getCurScope(), TagDecl);
3203 bool IsFinalSpelledSealed =
false;
3211 "not a class definition");
3216 Diag(FinalLoc, diag::err_override_control_interface)
3220 ? diag::warn_cxx98_compat_override_control_keyword
3221 : diag::ext_override_control_keyword)
3224 Diag(FinalLoc, diag::ext_ms_sealed_keyword);
3226 Diag(FinalLoc, diag::ext_warn_gnu_final);
3232 CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc);
3241 if (!Tok.
is(tok::colon) && !Tok.
is(tok::l_brace)) {
3243 Actions.ActOnTagDefinitionError(
getCurScope(), TagDecl);
3248 if (Tok.
is(tok::colon)) {
3249 ParseScope InheritanceScope(
this,
getCurScope()->getFlags() |
3252 ParseBaseClause(TagDecl);
3253 if (!Tok.
is(tok::l_brace)) {
3254 bool SuggestFixIt =
false;
3255 SourceLocation BraceLoc = PP.getLocForEndOfToken(PrevTokLocation);
3258 case tok::kw_private:
3259 case tok::kw_protected:
3260 case tok::kw_public:
3263 case tok::kw_static_assert:
3267 case tok::kw_template:
3268 SuggestFixIt =
true;
3270 case tok::identifier:
3271 SuggestFixIt = isConstructorDeclarator(
true);
3274 SuggestFixIt = isCXXSimpleDeclaration(
false);
3279 Diag(BraceLoc, diag::err_expected_lbrace_after_base_specifiers);
3283 PP.EnterToken(Tok,
true);
3287 Actions.ActOnTagDefinitionError(
getCurScope(), TagDecl);
3293 assert(Tok.
is(tok::l_brace));
3298 Actions.ActOnStartCXXMemberDeclarations(
getCurScope(), TagDecl, FinalLoc,
3299 IsFinalSpelledSealed,
3300 T.getOpenLocation());
3310 ParsedAttributesWithRange AccessAttrs(AttrFactory);
3314 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
3317 ParseCXXClassMemberDeclarationWithPragmas(
3318 CurAS, AccessAttrs, static_cast<DeclSpec::TST>(TagType), TagDecl);
3327 MaybeParseGNUAttributes(attrs);
3330 Actions.ActOnFinishCXXMemberSpecification(
getCurScope(), RecordLoc, TagDecl,
3331 T.getOpenLocation(),
3332 T.getCloseLocation(), attrs);
3339 if (TagDecl && NonNestedClass) {
3345 ParseLexedAttributes(getCurrentClass());
3346 ParseLexedMethodDeclarations(getCurrentClass());
3349 Actions.ActOnFinishCXXMemberDecls();
3351 ParseLexedMemberInitializers(getCurrentClass());
3352 ParseLexedMethodDefs(getCurrentClass());
3353 PrevTokLocation = SavedPrevTokLocation;
3357 Actions.ActOnFinishCXXNonNestedClass(TagDecl);
3361 Actions.ActOnTagFinishDefinition(
getCurScope(), TagDecl, T.getRange());
3368 void Parser::DiagnoseUnexpectedNamespace(
NamedDecl *D) {
3369 assert(Tok.
is(tok::kw_namespace));
3374 diag::err_missing_end_of_definition) << D;
3376 diag::note_missing_end_of_definition_before) << D;
3379 PP.EnterToken(Tok,
true);
3382 Tok.
setLocation(PP.getLocForEndOfToken(PrevTokLocation));
3384 PP.EnterToken(Tok,
true);
3410 void Parser::ParseConstructorInitializer(
Decl *ConstructorDecl) {
3411 assert(Tok.
is(tok::colon) &&
3412 "Constructor initializer always starts with ':'");
3420 bool AnyErrors =
false;
3423 if (Tok.
is(tok::code_completion)) {
3424 Actions.CodeCompleteConstructorInitializer(ConstructorDecl,
3426 return cutOffParsing();
3429 MemInitResult MemInit = ParseMemInitializer(ConstructorDecl);
3431 MemInitializers.push_back(MemInit.
get());
3435 if (Tok.
is(tok::comma))
3437 else if (Tok.
is(tok::l_brace))
3442 Tok.
isOneOf(tok::identifier, tok::coloncolon)) {
3444 Diag(Loc, diag::err_ctor_init_missing_comma)
3456 Actions.ActOnMemInitializers(ConstructorDecl, ColonLoc, MemInitializers,
3475 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
false))
3486 if (Tok.
is(tok::identifier)) {
3491 }
else if (Tok.
is(tok::annot_decltype)) {
3496 ParseDecltypeSpecifier(DS);
3499 ? takeTemplateIdAnnotation(Tok)
3504 AnnotateTemplateIdTokenAsType(
true);
3505 assert(Tok.
is(tok::annot_typename) &&
"template-id -> type failed");
3507 ConsumeAnnotationToken();
3508 if (!TemplateTypeTy)
3511 Diag(Tok, diag::err_expected_member_or_base_name);
3518 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
3521 ExprResult InitList = ParseBraceInitializer();
3528 return Actions.ActOnMemInitializer(ConstructorDecl,
getCurScope(), SS, II,
3529 TemplateTypeTy, DS, IdLoc,
3530 InitList.
get(), EllipsisLoc);
3531 }
else if(Tok.
is(tok::l_paren)) {
3536 ExprVector ArgExprs;
3537 CommaLocsTy CommaLocs;
3538 auto RunSignatureHelp = [&] {
3539 QualType PreferredType = Actions.ProduceCtorInitMemberSignatureHelp(
3540 getCurScope(), ConstructorDecl, SS, TemplateTypeTy, ArgExprs, II,
3541 T.getOpenLocation());
3542 CalledSignatureHelp =
true;
3543 return PreferredType;
3545 if (Tok.
isNot(tok::r_paren) &&
3546 ParseExpressionList(ArgExprs, CommaLocs, [&] {
3547 PreferredType.enterFunctionArgument(Tok.
getLocation(),
3550 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
3561 return Actions.ActOnMemInitializer(ConstructorDecl,
getCurScope(), SS, II,
3562 TemplateTypeTy, DS, IdLoc,
3563 T.getOpenLocation(), ArgExprs,
3564 T.getCloseLocation(), EllipsisLoc);
3568 return Diag(Tok, diag::err_expected_either) << tok::l_paren << tok::l_brace;
3570 return Diag(Tok, diag::err_expected) << tok::l_paren;
3583 Parser::tryParseExceptionSpecification(
bool Delayed,
3587 ExprResult &NoexceptExpr,
3590 ExceptionSpecTokens =
nullptr;
3594 if (Tok.
isNot(tok::kw_throw) && Tok.
isNot(tok::kw_noexcept))
3598 bool IsNoexcept = Tok.
is(tok::kw_noexcept);
3599 Token StartTok = Tok;
3603 if (!Tok.
is(tok::l_paren)) {
3606 Diag(Tok, diag::warn_cxx98_compat_noexcept_decl);
3607 NoexceptExpr =
nullptr;
3611 Diag(Tok, diag::err_expected_lparen_after) <<
"throw";
3617 ExceptionSpecTokens->push_back(StartTok);
3618 ExceptionSpecTokens->push_back(Tok);
3619 SpecificationRange.
setEnd(ConsumeParen());
3621 ConsumeAndStoreUntil(tok::r_paren, *ExceptionSpecTokens,
3624 SpecificationRange.
setEnd(ExceptionSpecTokens->back().getLocation());
3630 if (Tok.
is(tok::kw_throw)) {
3631 Result = ParseDynamicExceptionSpecification(SpecificationRange,
3633 DynamicExceptionRanges);
3634 assert(DynamicExceptions.size() == DynamicExceptionRanges.size() &&
3635 "Produced different number of exception types and ranges.");
3639 if (Tok.
isNot(tok::kw_noexcept))
3642 Diag(Tok, diag::warn_cxx98_compat_noexcept_decl);
3650 if (Tok.
is(tok::l_paren)) {
3657 NoexceptExpr = Actions.ActOnNoexceptSpec(KeywordLoc, NoexceptExpr.
get(),
3659 NoexceptRange =
SourceRange(KeywordLoc, T.getCloseLocation());
3666 NoexceptRange =
SourceRange(KeywordLoc, KeywordLoc);
3670 SpecificationRange = NoexceptRange;
3671 Result = NoexceptType;
3675 if (Tok.
is(tok::kw_throw)) {
3676 Diag(Tok.
getLocation(), diag::err_dynamic_and_noexcept_specification);
3677 ParseDynamicExceptionSpecification(NoexceptRange, DynamicExceptions,
3678 DynamicExceptionRanges);
3681 Diag(Tok.
getLocation(), diag::err_dynamic_and_noexcept_specification);
3690 const char *Replacement = IsNoexcept ?
"noexcept" :
"noexcept(false)";
3693 ? diag::ext_dynamic_exception_spec
3694 : diag::warn_exception_spec_deprecated)
3696 P.
Diag(Range.
getBegin(), diag::note_exception_spec_deprecated)
3716 assert(Tok.
is(tok::kw_throw) &&
"expected throw");
3721 Diag(Tok, diag::err_expected_lparen_after) <<
"throw";
3728 if (Tok.
is(tok::ellipsis)) {
3731 Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec);
3740 while (Tok.
isNot(tok::r_paren)) {
3743 if (Tok.
is(tok::ellipsis)) {
3750 Res = Actions.ActOnPackExpansion(Res.
get(), Ellipsis);
3754 Exceptions.push_back(Res.
get());
3755 Ranges.push_back(Range);
3765 Exceptions.empty());
3771 TypeResult Parser::ParseTrailingReturnType(
SourceRange &Range,
3772 bool MayBeFollowedByDirectInit) {
3773 assert(Tok.
is(tok::arrow) &&
"expected arrow");
3786 Parser::PushParsingClass(
Decl *ClassDecl,
bool NonNestedClass,
3788 assert((NonNestedClass || !ClassStack.empty()) &&
3789 "Nested class without outer class");
3790 ClassStack.push(
new ParsingClass(ClassDecl, NonNestedClass, IsInterface));
3791 return Actions.PushParsingClass();
3796 void Parser::DeallocateParsedClasses(Parser::ParsingClass *Class) {
3797 for (
unsigned I = 0, N = Class->LateParsedDeclarations.size(); I != N; ++I)
3798 delete Class->LateParsedDeclarations[I];
3809 assert(!ClassStack.empty() &&
"Mismatched push/pop for class parsing");
3811 Actions.PopParsingClass(state);
3813 ParsingClass *Victim = ClassStack.top();
3815 if (Victim->TopLevelClass) {
3818 DeallocateParsedClasses(Victim);
3821 assert(!ClassStack.empty() &&
"Missing top-level class?");
3823 if (Victim->LateParsedDeclarations.empty()) {
3828 DeallocateParsedClasses(Victim);
3835 assert(
getCurScope()->isClassScope() &&
"Nested class outside of class scope?");
3836 ClassStack.top()->LateParsedDeclarations.push_back(
new LateParsedClass(
this, Victim));
3861 case tok::numeric_constant: {
3868 PP.getSourceManager().getExpansionLoc(Tok.
getLocation());
3869 StringRef Spelling = PP.getSpelling(ExpansionLoc, ExpansionBuf);
3870 if (Spelling ==
"__clang__") {
3873 PP.getSourceManager().getExpansionLoc(Tok.
getEndLoc()));
3874 Diag(Tok, diag::warn_wrong_clang_attr_namespace)
3877 return &PP.getIdentifierTable().get(
"_Clang");
3890 case tok::pipeequal:
3891 case tok::caretequal:
3893 case tok::exclaimequal:
3898 PP.getSourceManager().getSpellingLoc(Tok.
getLocation());
3899 StringRef Spelling = PP.getSpelling(SpellingLoc, SpellingBuf);
3902 return &PP.getIdentifierTable().get(Spelling);
3911 case ParsedAttr::AT_CarriesDependency:
3912 case ParsedAttr::AT_Deprecated:
3913 case ParsedAttr::AT_FallThrough:
3914 case ParsedAttr::AT_CXX11NoReturn:
3915 case ParsedAttr::AT_NoUniqueAddress:
3917 case ParsedAttr::AT_WarnUnusedResult:
3918 return !ScopeName && AttrName->
getName().equals(
"nodiscard");
3919 case ParsedAttr::AT_Unused:
3920 return !ScopeName && AttrName->
getName().equals(
"maybe_unused");
3946 assert(Tok.
is(tok::l_paren) &&
"Not a C++11 attribute argument list");
3962 if (ScopeName && (ScopeName->
isStr(
"gnu") || ScopeName->
isStr(
"__gnu__"))) {
3965 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
3966 ScopeLoc, Syntax,
nullptr);
3972 if (ScopeName && (ScopeName->
isStr(
"clang") || ScopeName->
isStr(
"_Clang")))
3973 NumArgs = ParseClangAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc,
3974 ScopeName, ScopeLoc, Syntax);
3977 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
3978 ScopeName, ScopeLoc, Syntax);
3980 if (!Attrs.
empty() &&
3990 Diag(LParenLoc, diag::err_attribute_requires_arguments) << AttrName;
3996 Diag(LParenLoc, diag::err_cxx11_attribute_forbids_arguments)
4031 if (Tok.
is(tok::kw_alignas)) {
4033 ParseAlignmentSpecifier(attrs, endLoc);
4037 assert(Tok.
is(tok::l_square) &&
NextToken().
is(tok::l_square) &&
4038 "Not a double square bracket attribute list");
4047 if (Tok.
is(tok::kw_using)) {
4049 ? diag::warn_cxx14_compat_using_attribute_ns
4050 : diag::ext_using_attribute_ns);
4053 CommonScopeName = TryParseCXX11AttributeIdentifier(CommonScopeLoc);
4054 if (!CommonScopeName) {
4062 llvm::SmallDenseMap<IdentifierInfo*, SourceLocation, 4> SeenAttrs;
4064 while (Tok.
isNot(tok::r_square)) {
4072 AttrName = TryParseCXX11AttributeIdentifier(AttrLoc);
4079 ScopeName = AttrName;
4082 AttrName = TryParseCXX11AttributeIdentifier(AttrLoc);
4090 if (CommonScopeName) {
4092 Diag(ScopeLoc, diag::err_using_attribute_ns_conflict)
4095 ScopeName = CommonScopeName;
4096 ScopeLoc = CommonScopeLoc;
4101 bool AttrParsed =
false;
4104 !SeenAttrs.insert(std::make_pair(AttrName, AttrLoc)).second)
4105 Diag(AttrLoc, diag::err_cxx11_attribute_repeated)
4109 if (Tok.
is(tok::l_paren))
4110 AttrParsed = ParseCXX11AttributeArgs(AttrName, AttrLoc, attrs, endLoc,
4111 ScopeName, ScopeLoc);
4116 SourceRange(ScopeLoc.
isValid() ? ScopeLoc : AttrLoc, AttrLoc),
4117 ScopeName, ScopeLoc,
nullptr, 0,
4121 Diag(Tok, diag::err_cxx11_attribute_forbids_ellipsis)
4125 if (ExpectAndConsume(tok::r_square))
4129 if (ExpectAndConsume(tok::r_square))
4137 void Parser::ParseCXX11Attributes(ParsedAttributesWithRange &attrs,
4139 assert(standardAttributesAllowed());
4146 ParseCXX11AttributeSpecifier(attrs, endLoc);
4147 }
while (isCXX11AttributeSpecifier());
4152 void Parser::DiagnoseAndSkipCXX11Attributes() {
4159 Diag(StartLoc, diag::err_attributes_not_allowed)
4167 if (!isCXX11AttributeSpecifier())
4171 if (Tok.
is(tok::l_square)) {
4177 assert(Tok.
is(tok::kw_alignas) &&
"not an attribute specifier");
4184 }
while (isCXX11AttributeSpecifier());
4191 assert(Tok.
is(tok::identifier) &&
"Not a Microsoft attribute list");
4193 assert(UuidIdent->getName() ==
"uuid" &&
"Not a Microsoft attribute list");
4201 Diag(Tok, diag::err_expected) << tok::l_paren;
4206 if (Tok.
is(tok::string_literal)) {
4208 ExprResult StringResult = ParseStringLiteralExpression();
4211 ArgExprs.push_back(StringResult.
get());
4228 while (Tok.
isNot(tok::r_paren)) {
4230 Diag(Tok, diag::err_attribute_uuid_malformed_guid);
4235 SpellingBuffer.resize(Tok.
getLength() + 1);
4236 bool Invalid =
false;
4237 StringRef TokSpelling = PP.getSpelling(Tok, SpellingBuffer, &Invalid);
4242 StrBuffer += TokSpelling;
4248 Diag(Tok, diag::err_attribute_uuid_malformed_guid);
4258 Toks[0].
setKind(tok::string_literal);
4263 cast<StringLiteral>(Actions.ActOnStringLiteral(Toks,
nullptr).get());
4264 ArgExprs.push_back(UuidString);
4284 assert(Tok.
is(tok::l_square) &&
"Not a Microsoft attribute list");
4294 if (Tok.
isNot(tok::identifier))
4297 ParseMicrosoftUuidAttributeArgs(attrs);
4305 }
while (Tok.
is(tok::l_square));
4308 void Parser::ParseMicrosoftIfExistsClassDeclaration(
4311 IfExistsCondition
Result;
4312 if (ParseMicrosoftIfExistsCondition(Result))
4317 Diag(Tok, diag::err_expected) << tok::l_brace;
4321 switch (Result.Behavior) {
4327 Diag(Result.KeywordLoc, diag::warn_microsoft_dependent_exists)
4328 << Result.IsIfExists;
4337 while (Tok.
isNot(tok::r_brace) && !isEofOrEom()) {
4339 if (Tok.
isOneOf(tok::kw___if_exists, tok::kw___if_not_exists)) {
4340 ParseMicrosoftIfExistsClassDeclaration((
DeclSpec::TST)TagType,
4341 AccessAttrs, CurAS);
4346 if (Tok.
is(tok::semi)) {
4347 ConsumeExtraSemi(InsideStruct, TagType);
4357 if (Tok.
is(tok::colon))
4358 Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.
getLocation(),
4361 Diag(Tok, diag::err_expected) << tok::colon;
4367 ParseCXXClassMemberDeclaration(CurAS, AccessAttrs);
Defines the clang::ASTContext interface.
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
no exception specification
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
A (possibly-)qualified type.
void clear()
Reset the contents of this Declarator.
void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace)
ActOnFinishNamespaceDef - This callback is called after a namespace is exited.
IdentifierInfo * Name
FIXME: Temporarily stores the name of a specialization.
SourceLocation TemplateNameLoc
TemplateNameLoc - The location of the template name within the source.
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
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)) {...
static CharSourceRange getTokenRange(SourceRange R)
The name refers to a dependent template name:
Decl * ActOnUsingDirective(Scope *CurScope, SourceLocation UsingLoc, SourceLocation NamespcLoc, CXXScopeSpec &SS, SourceLocation IdentLoc, IdentifierInfo *NamespcName, const ParsedAttributesView &AttrList)
Decl - This represents one declaration (or definition), e.g.
RAII object used to inform the actions that we're currently parsing a declaration.
void CodeCompleteUsing(Scope *S)
A RAII object used to temporarily suppress access-like checking.
Defines the C++ template declaration subclasses.
bool isTemplateParamScope() const
isTemplateParamScope - Return true if this scope is a C++ template parameter scope.
The base class of the type hierarchy.
bool TryAnnotateCXXScopeToken(bool EnteringContext=false)
TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only annotates C++ scope specifiers and ...
SourceLocation getCloseLocation() const
This indicates that the scope corresponds to a function, which means that labels are set here...
Declaration of a variable template.
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
static FixItHint CreateInsertionFromRange(SourceLocation InsertionLoc, CharSourceRange FromRange, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code from FromRange at a specific location...
static const char * getSpecifierName(DeclSpec::TST T, const PrintingPolicy &Policy)
Turn a type-specifier-type into a string like "_Bool" or "union".
std::unique_ptr< CachedTokens > DefaultArgTokens
DefaultArgTokens - When the parameter's default argument cannot be parsed immediately (because it occ...
static const char * getSpecifierName(Specifier VS)
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.
const NestedNameSpecifier * Specifier
Wrapper for void* pointer.
Parser - This implements a parser for the C family of languages.
constexpr XRayInstrMask Function
void SetIdentifier(IdentifierInfo *Id, SourceLocation IdLoc)
Set the name of this declarator to be the given identifier.
const ParsedAttributes & getAttributes() const
RAII object that enters a new expression evaluation context.
static const TST TST_underlyingType
Information about one declarator, including the parsed type information and the identifier.
void setTypeofParensRange(SourceRange range)
TypeSpecifierType
Specifies the kind of type.
static const TST TST_interface
bool isInvalidDecl() const
Like System, but searched after the system directories.
void setBegin(SourceLocation b)
Describes how types, statements, expressions, and declarations should be printed. ...
RAII object that makes sure paren/bracket/brace count is correct after declaration/statement parsing...
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, bool IsClassTemplateDeductionContext=true, IdentifierInfo **CorrectedII=nullptr)
If the identifier refers to a type name within this scope, return the declaration of that type...
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
friend class ObjCDeclContextSwitch
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed...
tok::TokenKind getKind() const
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
Information about a template-id annotation token.
SourceLocation getFriendSpecLoc() const
Represents a struct/union/class.
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
bool TryConsumeToken(tok::TokenKind Expected)
One of these records is kept for each identifier that is lexed.
Decl * ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc, SourceLocation NamespaceLoc, SourceLocation IdentLoc, IdentifierInfo *Ident, SourceLocation LBrace, const ParsedAttributesView &AttrList, UsingDirectiveDecl *&UsingDecl)
ActOnStartNamespaceDef - This is called at the start of a namespace definition.
Decl * ActOnNamespaceAliasDef(Scope *CurScope, SourceLocation NamespaceLoc, SourceLocation AliasLoc, IdentifierInfo *Alias, CXXScopeSpec &SS, SourceLocation IdentLoc, IdentifierInfo *Ident)
SourceLocation getAnnotationEndLoc() const
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
Lookup for the name failed, but we're assuming it was a template name anyway.
LLVM_READONLY bool isLetter(unsigned char c)
Return true if this character is an ASCII letter: [a-zA-Z].
static const TST TST_class
The current expression is potentially evaluated at run time, which means that code may be generated t...
DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType=nullptr)
static const TST TST_error
Token - This structure provides full information about a lexed token.
void setKind(tok::TokenKind K)
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ...
bool DiagnoseUnknownTemplateName(const IdentifierInfo &II, SourceLocation IILoc, Scope *S, const CXXScopeSpec *SS, TemplateTy &SuggestedTemplate, TemplateNameKind &SuggestedKind)
bool hasTagDefinition() const
void ClearStorageClassSpecs()
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param Data Additional data for task generation like final * state
bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const
Return true if we have an ObjC keyword identifier.
void setExternInLinkageSpec(bool Value)
Represents a C++ unqualified-id that has been parsed.
static ParsedType getTypeAnnotation(const Token &Tok)
getTypeAnnotation - Read a parsed type out of an annotation token.
Microsoft throw(...) extension.
DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef< Decl *> Group)
BuildDeclaratorGroup - convert a list of declarations into a declaration group, performing any necess...
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, llvm::function_ref< ExprResult(Expr *)> Filter=[](Expr *E) -> ExprResult { return E;})
Process any TypoExprs in the given Expr and its children, generating diagnostics as appropriate and r...
const clang::PrintingPolicy & getPrintingPolicy() const
void takeAllFrom(ParsedAttributes &attrs)
ParsedTemplateArgument * getTemplateArgs()
Retrieves a pointer to the template arguments.
MutableArrayRef< TemplateParameterList * > MultiTemplateParamsArg
ActionResult< ParsedType > TypeResult
Scope - A scope is a transient data structure that is used while parsing the program.
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...
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type...
Decl * ActOnStartLinkageSpecification(Scope *S, SourceLocation ExternLoc, Expr *LangStr, SourceLocation LBraceLoc)
ActOnStartLinkageSpecification - Parsed the beginning of a C++ linkage specification, including the language and (if present) the '{'.
SourceRange getSourceRange() const LLVM_READONLY
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
SourceLocation TemplateKWLoc
TemplateKWLoc - The location of the template keyword.
void setInvalid(bool b=true) const
SourceLocation LAngleLoc
The location of the '<' before the template argument list.
A little helper class used to produce diagnostics.
A class for parsing a declarator.
bool isDeclarationOfFunction() const
Determine whether the declaration that will be produced from this declaration will be a function...
bool isPastIdentifier() const
isPastIdentifier - Return true if we have parsed beyond the point where the name would appear...
void SetRangeStart(SourceLocation Loc)
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
SourceRange getRange() const
TST getTypeSpecType() const
Decl * ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, Expr *AssertExpr, Expr *AssertMessageExpr, SourceLocation RParenLoc)
A single parameter index whose accessors require each use to make explicit the parameter index encodi...
This represents one expression.
static bool IsBuiltInOrStandardCXX11Attribute(IdentifierInfo *AttrName, IdentifierInfo *ScopeName)
Represents a character-granular source range.
void AnnotateCachedTokens(const Token &Tok)
We notify the Preprocessor that if it is caching tokens (because backtrack is enabled) it should repl...
This file defines the classes used to store parsed information about declaration-specifiers and decla...
void SkipMalformedDecl()
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a s...
bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, ParsedType ObjectType, SourceLocation *TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
Specifier getLastSpecifier() const
TypeResult ActOnTypeName(Scope *S, Declarator &D)
void RevertCachedTokens(unsigned N)
When backtracking is enabled and tokens are cached, this allows to revert a specific number of tokens...
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
OpaquePtr< TemplateName > TemplateTy
Defines an enumeration for C++ overloaded operators.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
void setAsmLabel(Expr *E)
SourceLocation getBeginLoc() const
Decl * ActOnFinishExportDecl(Scope *S, Decl *ExportDecl, SourceLocation RBraceLoc)
Complete the definition of an export declaration.
Represents a C++ template name within the type system.
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7)...
CachedTokens * ExceptionSpecTokens
Pointer to the cached tokens for an exception-specification that has not yet been parsed...
TemplateNameKind
Specifies the kind of template name that an identifier refers to.
InClassInitStyle
In-class initialization styles for non-static data members.
SourceLocation getOpenLocation() const
ParsedType getInheritingConstructorName(CXXScopeSpec &SS, SourceLocation NameLoc, IdentifierInfo &Name)
Handle the result of the special case name lookup for inheriting constructor declarations.
bool isFriendSpecified() const
The result type of a method or function.
void CodeCompleteNamespaceDecl(Scope *S)
PrettyDeclStackTraceEntry - If a crash occurs in the parser while parsing something related to a decl...
const LangOptions & getLangOpts() const
A class for parsing a DeclSpec.
Represents a C++ Modules TS module export declaration.
ExprResult ActOnDecltypeExpression(Expr *E)
Process the expression contained within a decltype.
bool isArrayOfUnknownBound() const
isArrayOfUnknownBound - This method returns true if the declarator is a declarator for an array of un...
Stop skipping at semicolon.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
SCS getStorageClassSpec() const
ASTContext & getASTContext() const
bool hasName() const
hasName - Whether this declarator has a name, which might be an identifier (accessible via getIdentif...
Encodes a location in the source.
Decl * ActOnFinishLinkageSpecification(Scope *S, Decl *LinkageSpec, SourceLocation RBraceLoc)
ActOnFinishLinkageSpecification - Complete the definition of the C++ linkage specification LinkageSpe...
void setLength(unsigned Len)
Syntax
The style used to specify an attribute.
Represents the declaration of a struct/union/class/enum.
static const TST TST_union
IdentifierInfo * getIdentifierInfo() const
void setAnnotationEndLoc(SourceLocation L)
ParsedAttr - Represents a syntactic attribute.
ExtensionRAIIObject - This saves the state of extension warnings when constructed and disables them...
ParsedAttr * addNew(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ArgsUnion *args, unsigned numArgs, ParsedAttr::Syntax syntax, SourceLocation ellipsisLoc=SourceLocation())
Add attribute with expression arguments.
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Direct list-initialization.
Represents a C++11 virt-specifier-seq.
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
Decl * ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc, SourceLocation LBraceLoc)
We have parsed the start of an export declaration, including the '{' (if present).
FunctionDefinitionKind
Described the kind of function definition (if any) provided for a function.
Scope * getCurScope() const
ExprResult ParseConstantExpressionInExprEvalContext(TypeCastState isTypeCast=NotTypeCast)
bool isInvalid() const
An error occurred during parsing of the scope specifier.
void setFunctionDefinitionKind(FunctionDefinitionKind Val)
SourceLocation getModulePrivateSpecLoc() const
StringRef getName() const
Return the actual identifier string.
The scope of a struct/union/class definition.
bool isNot(tok::TokenKind K) const
bool isBacktrackEnabled() const
True if EnableBacktrackAtThisPos() was called and caching of tokens is on.
static const TST TST_decltype_auto
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
SmallVector< Token, 4 > CachedTokens
A set of tokens that has been cached for later parsing.
static const TST TST_decltype
const Scope * getParent() const
getParent - Return the scope that this is nested in.
static void diagnoseDynamicExceptionSpecification(Parser &P, SourceRange Range, bool IsNoexcept)
CXXScopeSpec SS
The nested-name-specifier that precedes the template name.
SourceLocation RAngleLoc
The location of the '>' after the template argument list.
void CodeCompleteTag(Scope *S, unsigned TagSpec)
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
The name refers to a template whose specialization produces a type.
unsigned getLength() const
void CodeCompleteNamespaceAliasDecl(Scope *S)
void forEachQualifier(llvm::function_ref< void(TQ, StringRef, SourceLocation)> Handle)
This method calls the passed in handler on each qual being set.
void setLiteralData(const char *Ptr)
void CodeCompleteUsingDirective(Scope *S)
const TargetInfo & getTargetInfo() const
bool SetSpecifier(Specifier VS, SourceLocation Loc, const char *&PrevSpec)
unsigned getTypeQualifiers() const
getTypeQualifiers - Return a set of TQs.
void takeAttributesFrom(ParsedAttributes &attrs)
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
static const TST TST_typename
void SetRangeEnd(SourceLocation Loc)
SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
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.
We are between inheritance colon and the real class/struct definition scope.
ExceptionSpecificationType getExceptionSpecType() const
Get the type of exception specification this function has.
SmallVector< TemplateParameterList *, 4 > TemplateParameterLists
CXXScopeSpec & getTypeSpecScope()
This is a scope that can contain a declaration.
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
SourceLocation getIdentifierLoc() const
bool isSet() const
Deprecated.
unsigned getMaxArgs() const
void getCXX11AttributeRanges(SmallVectorImpl< SourceRange > &Ranges)
Return a source range list of C++11 attributes associated with the declarator.
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
ExprResult ParseConstantExpression(TypeCastState isTypeCast=NotTypeCast)
Captures information about "declaration specifiers".
ActionResult< Expr * > ExprResult
void setEnd(SourceLocation e)
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
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.
A template-id, e.g., f<int>.
SourceLocation getFirstLocation() const
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 OpaquePtr make(PtrTy P)
static const TST TST_struct
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
void setLocation(SourceLocation L)
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
Expr * getRepAsExpr() const
__ptr16, alignas(...), etc.
Represents C++ using-directive.
unsigned NumArgs
NumArgs - The number of template arguments.
void SetRangeEnd(SourceLocation Loc)
Decl * ActOnAliasDeclaration(Scope *CurScope, AccessSpecifier AS, MultiTemplateParamsArg TemplateParams, SourceLocation UsingLoc, UnqualifiedId &Name, const ParsedAttributesView &AttrList, TypeResult Type, Decl *DeclFromDeclSpec)
SourceLocation getBegin() const
ParsedAttributes - A collection of parsed attributes.
SourceLocation ColonLoc
Location of ':'.
void setCommaLoc(SourceLocation CL)
bool hasLeadingSpace() const
Return true if this token has whitespace before it.
Decl * ActOnUsingDeclaration(Scope *CurScope, AccessSpecifier AS, SourceLocation UsingLoc, SourceLocation TypenameLoc, CXXScopeSpec &SS, UnqualifiedId &Name, SourceLocation EllipsisLoc, const ParsedAttributesView &AttrList)
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeNameContext, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName type-name: [C99 6.7.6] specifier-qualifier-list abstract-declarator[opt].
Attr - This represents one attribute.
SourceLocation getLocation() const
void startToken()
Reset all flags to cleared.
ParsedTemplateTy Template
The declaration of the template corresponding to the template-name.
Stop skipping at specified token, but don't skip the token itself.
SourceLocation getEndLoc() const