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,
608 if (D.SS.isInvalid())
623 Tok.
is(tok::identifier) &&
627 !D.SS.getScopeRep()->getAsNamespace() &&
628 !D.SS.getScopeRep()->getAsNamespaceAlias()) {
632 D.Name.setConstructorName(Type, IdLoc, IdLoc);
637 !(Tok.
is(tok::identifier) &&
640 nullptr,
nullptr, D.Name))
646 diag::warn_cxx17_compat_using_declaration_pack :
647 diag::ext_using_declaration_pack);
670 const ParsedTemplateInfo &TemplateInfo,
675 ParsedAttributesWithRange MisplacedAttrs(AttrFactory);
676 MaybeParseCXX11Attributes(MisplacedAttrs);
679 bool InvalidDeclarator = ParseUsingDeclarator(Context, D);
681 ParsedAttributesWithRange Attrs(AttrFactory);
682 MaybeParseGNUAttributes(Attrs);
683 MaybeParseCXX11Attributes(Attrs);
686 if (Tok.
is(tok::equal)) {
687 if (InvalidDeclarator) {
694 if (MisplacedAttrs.Range.isValid()) {
695 Diag(MisplacedAttrs.Range.getBegin(), diag::err_attributes_not_allowed)
700 Attrs.takeAllFrom(MisplacedAttrs);
703 Decl *DeclFromDeclSpec =
nullptr;
704 Decl *AD = ParseAliasDeclarationAfterDeclarator(
705 TemplateInfo, UsingLoc, D, DeclEnd, AS, Attrs, &DeclFromDeclSpec);
711 ProhibitAttributes(MisplacedAttrs);
712 ProhibitAttributes(Attrs);
717 if (TemplateInfo.Kind) {
719 Diag(UsingLoc, diag::err_templated_using_directive_declaration)
731 MaybeParseGNUAttributes(Attrs);
733 if (InvalidDeclarator)
738 if (D.TypenameLoc.isValid() &&
740 Diag(D.Name.getSourceRange().getBegin(),
741 diag::err_typename_identifiers_only)
748 D.TypenameLoc, D.SS, D.Name,
749 D.EllipsisLoc, Attrs);
751 DeclsInGroup.push_back(UD);
759 InvalidDeclarator = ParseUsingDeclarator(Context, D);
762 if (DeclsInGroup.size() > 1)
764 diag::warn_cxx17_compat_multi_using_declaration :
765 diag::ext_multi_using_declaration);
769 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
770 !Attrs.empty() ?
"attributes list" 771 :
"using declaration"))
777 Decl *Parser::ParseAliasDeclarationAfterDeclarator(
781 if (ExpectAndConsume(tok::equal)) {
787 diag::warn_cxx98_compat_alias_declaration :
788 diag::ext_alias_declaration);
792 if (TemplateInfo.Kind == ParsedTemplateInfo::Template &&
795 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization)
797 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation)
799 if (SpecKind != -1) {
803 D.Name.TemplateId->RAngleLoc);
805 Range = TemplateInfo.getSourceRange();
806 Diag(Range.
getBegin(), diag::err_alias_declaration_specialization)
807 << SpecKind << Range;
814 Diag(D.Name.StartLocation, diag::err_alias_declaration_not_identifier);
818 }
else if (D.TypenameLoc.isValid())
819 Diag(D.TypenameLoc, diag::err_alias_declaration_not_identifier)
822 D.SS.isNotEmpty() ? D.SS.getEndLoc() : D.TypenameLoc));
823 else if (D.SS.isNotEmpty())
824 Diag(D.SS.getBeginLoc(), diag::err_alias_declaration_not_identifier)
826 if (D.EllipsisLoc.isValid())
827 Diag(D.EllipsisLoc, diag::err_alias_declaration_pack_expansion)
830 Decl *DeclFromDeclSpec =
nullptr;
835 AS, &DeclFromDeclSpec, &Attrs);
837 *OwnedType = DeclFromDeclSpec;
841 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
842 !Attrs.
empty() ?
"attributes list" 843 :
"alias declaration"))
848 TemplateParams ? TemplateParams->data() :
nullptr,
849 TemplateParams ? TemplateParams->size() : 0);
851 UsingLoc, D.Name, Attrs, TypeAlias,
864 assert(Tok.
isOneOf(tok::kw_static_assert, tok::kw__Static_assert) &&
865 "Not a static_assert declaration");
869 if (Tok.
is(tok::kw_static_assert))
870 Diag(Tok, diag::warn_cxx98_compat_static_assert);
875 if (T.consumeOpen()) {
876 Diag(Tok, diag::err_expected) << tok::l_paren;
884 if (AssertExpr.isInvalid()) {
890 if (Tok.
is(tok::r_paren)) {
892 ? diag::warn_cxx14_compat_static_assert_no_message
893 : diag::ext_static_assert_no_message)
896 :
FixItHint::CreateInsertion(Tok.getLocation(),
", \"\""));
898 if (ExpectAndConsume(tok::comma)) {
903 if (!isTokenStringLiteral()) {
904 Diag(Tok, diag::err_expected_string_literal)
910 AssertMessage = ParseStringLiteralExpression();
920 ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert);
925 T.getCloseLocation());
934 assert(Tok.
isOneOf(tok::kw_decltype, tok::annot_decltype)
935 &&
"Not a decltype specifier");
941 if (Tok.
is(tok::annot_decltype)) {
942 Result = getExprAnnotation(Tok);
944 ConsumeAnnotationToken();
945 if (Result.isInvalid()) {
951 Diag(Tok, diag::warn_cxx98_compat_decltype);
956 if (T.expectAndConsume(diag::err_expected_lparen_after,
957 "decltype", tok::r_paren)) {
960 StartLoc : T.getOpenLocation();
964 if (Tok.
is(tok::kw_auto)) {
970 ? diag::warn_cxx11_compat_decltype_auto_type_specifier
971 : diag::ext_decltype_auto_type_specifier);
985 if (Result.isInvalid()) {
988 EndLoc = ConsumeParen();
995 assert(Tok.
is(tok::semi));
1008 if (T.getCloseLocation().isInvalid()) {
1012 return T.getCloseLocation();
1015 if (Result.isInvalid()) {
1017 return T.getCloseLocation();
1020 EndLoc = T.getCloseLocation();
1022 assert(!Result.isInvalid());
1024 const char *PrevSpec =
nullptr;
1030 DiagID, Result.get(), Policy)
1033 Diag(StartLoc, DiagID) << PrevSpec;
1039 void Parser::AnnotateExistingDecltypeSpecifier(
const DeclSpec& DS,
1048 Tok.
setKind(tok::annot_decltype);
1049 setExprAnnotation(Tok,
1058 void Parser::ParseUnderlyingTypeSpecifier(
DeclSpec &DS) {
1059 assert(Tok.
is(tok::kw___underlying_type) &&
1060 "Not an underlying type specifier");
1064 if (T.expectAndConsume(diag::err_expected_lparen_after,
1065 "__underlying_type", tok::r_paren)) {
1077 if (T.getCloseLocation().isInvalid())
1080 const char *PrevSpec =
nullptr;
1083 DiagID, Result.
get(),
1085 Diag(StartLoc, DiagID) << PrevSpec;
1110 if (Tok.
is(tok::kw_typename)) {
1111 Diag(Tok, diag::err_expected_class_name_not_template)
1118 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
false))
1126 if (Tok.
isOneOf(tok::kw_decltype, tok::annot_decltype)) {
1133 EndLocation = ParseDecltypeSpecifier(DS);
1140 if (Tok.
is(tok::annot_template_id)) {
1145 AnnotateTemplateIdTokenAsType(SS,
true);
1147 assert(Tok.
is(tok::annot_typename) &&
"template-id -> type failed");
1150 ConsumeAnnotationToken();
1160 if (Tok.
isNot(tok::identifier)) {
1161 Diag(Tok, diag::err_expected_class_name);
1168 if (Tok.
is(tok::less)) {
1174 &SS, Template, TNK)) {
1175 Diag(IdLoc, diag::err_unknown_template_name)
1180 TemplateArgList TemplateArgs;
1182 ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs,
1196 AnnotateTemplateIdTokenAsType(SS,
true);
1200 if (Tok.
isNot(tok::annot_typename))
1207 ConsumeAnnotationToken();
1214 *Id, IdLoc,
getCurScope(), &SS,
true,
false,
nullptr,
1217 false, &CorrectedII);
1219 Diag(IdLoc, diag::err_expected_class_name);
1224 EndLocation = IdLoc;
1232 const char *PrevSpec =
nullptr;
1241 void Parser::ParseMicrosoftInheritanceClassAttributes(
ParsedAttributes &attrs) {
1242 while (Tok.
isOneOf(tok::kw___single_inheritance,
1243 tok::kw___multiple_inheritance,
1244 tok::kw___virtual_inheritance)) {
1247 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1255 bool Parser::isValidAfterTypeSpecifier(
bool CouldBeBitfield) {
1263 case tok::identifier:
1265 case tok::coloncolon:
1266 case tok::annot_cxxscope:
1267 case tok::annot_typename:
1268 case tok::annot_template_id:
1269 case tok::kw_decltype:
1272 case tok::kw_operator:
1273 case tok::kw___declspec:
1278 case tok::kw___attribute:
1279 case tok::annot_pragma_pack:
1281 case tok::annot_pragma_ms_pragma:
1283 case tok::annot_pragma_ms_vtordisp:
1285 case tok::annot_pragma_ms_pointers_to_members:
1288 return CouldBeBitfield;
1290 case tok::kw___cdecl:
1291 case tok::kw___fastcall:
1292 case tok::kw___stdcall:
1293 case tok::kw___thiscall:
1294 case tok::kw___vectorcall:
1300 case tok::kw_volatile:
1301 case tok::kw_restrict:
1302 case tok::kw__Atomic:
1303 case tok::kw___unaligned:
1307 case tok::kw_inline:
1308 case tok::kw_virtual:
1309 case tok::kw_friend:
1311 case tok::kw_static:
1312 case tok::kw_extern:
1313 case tok::kw_typedef:
1314 case tok::kw_register:
1316 case tok::kw_mutable:
1317 case tok::kw_thread_local:
1318 case tok::kw_constexpr:
1319 case tok::kw_consteval:
1320 case tok::kw_constinit:
1336 if (!isKnownToBeTypeSpecifier(
NextToken()))
1393 const ParsedTemplateInfo &TemplateInfo,
1395 bool EnteringContext, DeclSpecContext DSC,
1396 ParsedAttributesWithRange &Attributes) {
1398 if (TagTokKind == tok::kw_struct)
1400 else if (TagTokKind == tok::kw___interface)
1402 else if (TagTokKind == tok::kw_class)
1405 assert(TagTokKind == tok::kw_union &&
"Not a class specifier");
1409 if (Tok.
is(tok::code_completion)) {
1412 return cutOffParsing();
1425 bool shouldDelayDiagsInTag =
1426 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
1427 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
1430 ParsedAttributesWithRange attrs(AttrFactory);
1432 MaybeParseGNUAttributes(attrs);
1433 MaybeParseMicrosoftDeclSpecs(attrs);
1436 if (Tok.
isOneOf(tok::kw___single_inheritance,
1437 tok::kw___multiple_inheritance,
1438 tok::kw___virtual_inheritance))
1439 ParseMicrosoftInheritanceClassAttributes(attrs);
1444 MaybeParseCXX11Attributes(attrs);
1451 Tok.
isNot(tok::identifier) &&
1454 Tok.
isOneOf(tok::kw___is_abstract,
1455 tok::kw___is_aggregate,
1456 tok::kw___is_arithmetic,
1458 tok::kw___is_assignable,
1459 tok::kw___is_base_of,
1461 tok::kw___is_complete_type,
1462 tok::kw___is_compound,
1464 tok::kw___is_constructible,
1465 tok::kw___is_convertible,
1466 tok::kw___is_convertible_to,
1467 tok::kw___is_destructible,
1470 tok::kw___is_floating_point,
1472 tok::kw___is_function,
1473 tok::kw___is_fundamental,
1474 tok::kw___is_integral,
1475 tok::kw___is_interface_class,
1476 tok::kw___is_literal,
1477 tok::kw___is_lvalue_expr,
1478 tok::kw___is_lvalue_reference,
1479 tok::kw___is_member_function_pointer,
1480 tok::kw___is_member_object_pointer,
1481 tok::kw___is_member_pointer,
1482 tok::kw___is_nothrow_assignable,
1483 tok::kw___is_nothrow_constructible,
1484 tok::kw___is_nothrow_destructible,
1485 tok::kw___is_object,
1487 tok::kw___is_pointer,
1488 tok::kw___is_polymorphic,
1489 tok::kw___is_reference,
1490 tok::kw___is_rvalue_expr,
1491 tok::kw___is_rvalue_reference,
1493 tok::kw___is_scalar,
1494 tok::kw___is_sealed,
1495 tok::kw___is_signed,
1496 tok::kw___is_standard_layout,
1497 tok::kw___is_trivial,
1498 tok::kw___is_trivially_assignable,
1499 tok::kw___is_trivially_constructible,
1500 tok::kw___is_trivially_copyable,
1502 tok::kw___is_unsigned,
1504 tok::kw___is_volatile))
1510 TryKeywordIdentFallback(
true);
1512 struct PreserveAtomicIdentifierInfoRAII {
1513 PreserveAtomicIdentifierInfoRAII(
Token &Tok,
bool Enabled)
1514 : AtomicII(nullptr) {
1517 assert(Tok.
is(tok::kw__Atomic));
1522 ~PreserveAtomicIdentifierInfoRAII() {
1525 AtomicII->revertIdentifierToTokenID(tok::kw__Atomic);
1535 bool ShouldChangeAtomicToIdentifier =
getLangOpts().MSVCCompat &&
1536 Tok.
is(tok::kw__Atomic) &&
1538 PreserveAtomicIdentifierInfoRAII AtomicTokenGuard(
1539 Tok, ShouldChangeAtomicToIdentifier);
1549 bool HasValidSpec =
true;
1550 if (ParseOptionalCXXScopeSpecifier(Spec,
nullptr, EnteringContext)) {
1552 HasValidSpec =
false;
1555 if (Tok.
isNot(tok::identifier) && Tok.
isNot(tok::annot_template_id)) {
1556 Diag(Tok, diag::err_expected) << tok::identifier;
1557 HasValidSpec =
false;
1565 auto RecoverFromUndeclaredTemplateName = [&](
IdentifierInfo *Name,
1568 bool KnownUndeclared) {
1569 Diag(NameLoc, diag::err_explicit_spec_non_template)
1570 << (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation)
1571 << TagTokKind << Name << TemplateArgRange << KnownUndeclared;
1575 if (TemplateParams && TemplateInfo.LastParameterListWasEmpty) {
1576 if (TemplateParams->size() > 1) {
1577 TemplateParams->pop_back();
1579 TemplateParams =
nullptr;
1580 const_cast<ParsedTemplateInfo &
>(TemplateInfo).
Kind =
1581 ParsedTemplateInfo::NonTemplate;
1583 }
else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
1585 TemplateParams =
nullptr;
1586 const_cast<ParsedTemplateInfo &
>(TemplateInfo).
Kind =
1587 ParsedTemplateInfo::NonTemplate;
1588 const_cast<ParsedTemplateInfo &
>(TemplateInfo).TemplateLoc =
1590 const_cast<ParsedTemplateInfo &
>(TemplateInfo).ExternLoc =
1599 if (Tok.
is(tok::identifier)) {
1607 TemplateArgList TemplateArgs;
1609 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs,
1615 RecoverFromUndeclaredTemplateName(
1616 Name, NameLoc,
SourceRange(LAngleLoc, RAngleLoc),
false);
1618 }
else if (Tok.
is(tok::annot_template_id)) {
1619 TemplateId = takeTemplateIdAnnotation(Tok);
1620 NameLoc = ConsumeAnnotationToken();
1625 TemplateId->
Kind, NameLoc, Name);
1627 RecoverFromUndeclaredTemplateName(
1630 TemplateId =
nullptr;
1644 Diag(TemplateId->
LAngleLoc, diag::err_template_spec_syntax_non_template)
1645 << TemplateId->
Name <<
static_cast<int>(TemplateId->
Kind) << Range;
1680 MaybeParseCXX11Attributes(Attributes);
1682 const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy();
1684 if (DSC == DeclSpecContext::DSC_trailing)
1686 else if (Tok.
is(tok::l_brace) ||
1688 (isCXX11FinalKeyword() &&
1704 }
else if (isCXX11FinalKeyword() && (
NextToken().is(tok::l_square) ||
1708 TentativeParsingAction PA(*
this);
1715 if (Tok.
is(tok::l_square) &&
NextToken().
is(tok::l_square)) {
1719 }
else if (Tok.
is(tok::kw_alignas) &&
NextToken().
is(tok::l_paren)) {
1729 if (Tok.
isOneOf(tok::l_brace, tok::colon))
1735 }
else if (!isTypeSpecifier(DSC) &&
1736 (Tok.
is(tok::semi) ||
1739 if (Tok.
isNot(tok::semi)) {
1740 const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy();
1742 ExpectAndConsume(tok::semi, diag::err_expected_after,
1744 PP.EnterToken(Tok,
true);
1760 Diag(AttrRange.
getBegin(), diag::err_attributes_not_allowed)
1774 if (shouldDelayDiagsInTag) {
1775 diagsFromTag.done();
1777 diagsFromTag.redelay();
1784 Diag(StartLoc, diag::err_anon_type_definition)
1809 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation &&
1812 ProhibitAttributes(attrs);
1814 TagOrTempResult = Actions.ActOnExplicitInstantiation(
1815 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc,
1816 TagType, StartLoc, SS, TemplateId->
Template,
1826 TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate)) {
1827 ProhibitAttributes(attrs);
1828 TypeResult = Actions.ActOnTagTemplateIdType(TUK, TagType, StartLoc,
1840 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
1853 "Expected a definition here");
1857 TemplateParams =
nullptr;
1860 PP.getLocForEndOfToken(TemplateInfo.TemplateLoc);
1862 diag::err_explicit_instantiation_with_definition)
1869 FakedParamLists.push_back(Actions.ActOnTemplateParameterList(
1871 LAngleLoc,
nullptr));
1872 TemplateParams = &FakedParamLists;
1877 TagOrTempResult = Actions.ActOnClassTemplateSpecialization(
1879 SS, *TemplateId, attrs,
1882 TemplateParams ? TemplateParams->size() : 0),
1885 }
else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation &&
1892 ProhibitAttributes(attrs);
1894 TagOrTempResult = Actions.ActOnExplicitInstantiation(
1895 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc,
1896 TagType, StartLoc, SS, Name, NameLoc, attrs);
1898 TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) {
1899 ProhibitAttributes(attrs);
1901 TagOrTempResult = Actions.ActOnTemplatedFriendTag(
1905 TemplateParams ? TemplateParams->size() : 0));
1908 ProhibitAttributes(attrs);
1911 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
1914 Diag(Tok, diag::err_template_defn_explicit_instantiation)
1916 TemplateParams =
nullptr;
1919 bool IsDependent =
false;
1929 stripTypeAttributesOffDeclSpec(attrs, DS, TUK);
1932 TagOrTempResult = Actions.ActOnTag(
1933 getCurScope(), TagType, TUK, StartLoc, SS, Name, NameLoc, attrs, AS,
1936 DSC == DeclSpecContext::DSC_type_specifier,
1937 DSC == DeclSpecContext::DSC_template_param ||
1938 DSC == DeclSpecContext::DSC_template_type_arg,
1945 TypeResult = Actions.ActOnDependentTag(
getCurScope(), TagType, TUK,
1946 SS, Name, StartLoc, NameLoc);
1952 assert(Tok.
is(tok::l_brace) ||
1954 isCXX11FinalKeyword());
1956 SkipCXXMemberSpecification(StartLoc, AttrFixitLoc, TagType,
1957 TagOrTempResult.
get());
1959 ParseCXXMemberSpecification(StartLoc, AttrFixitLoc, attrs, TagType,
1960 TagOrTempResult.
get());
1965 ParseStructUnionBody(StartLoc, TagType, D);
1967 !Actions.ActOnDuplicateDefinition(DS, TagOrTempResult.
get(),
1977 Actions.ProcessDeclAttributeDelayed(TagOrTempResult.
get(), attrs);
1979 const char *PrevSpec =
nullptr;
1984 NameLoc.isValid() ? NameLoc : StartLoc,
1985 PrevSpec, DiagID, TypeResult.
get(), Policy);
1986 }
else if (!TagOrTempResult.
isInvalid()) {
1988 NameLoc.isValid() ? NameLoc : StartLoc,
1989 PrevSpec, DiagID, TagOrTempResult.
get(), Owned,
1997 Diag(StartLoc, DiagID) << PrevSpec;
2013 (TemplateInfo.Kind || !isValidAfterTypeSpecifier(
false))) {
2014 if (Tok.
isNot(tok::semi)) {
2015 const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy();
2016 ExpectAndConsume(tok::semi, diag::err_expected_after,
2021 PP.EnterToken(Tok,
true);
2034 void Parser::ParseBaseClause(
Decl *ClassDecl) {
2035 assert(Tok.
is(tok::colon) &&
"Not a base clause");
2043 BaseResult Result = ParseBaseSpecifier(ClassDecl);
2050 BaseInfo.push_back(Result.
get());
2060 Actions.ActOnBaseSpecifiers(ClassDecl, BaseInfo);
2075 bool IsVirtual =
false;
2078 ParsedAttributesWithRange Attributes(AttrFactory);
2079 MaybeParseCXX11Attributes(Attributes);
2085 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2092 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2096 if (Tok.
is(tok::kw_virtual)) {
2100 Diag(VirtualLoc, diag::err_dup_virtual)
2107 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2121 TypeResult BaseType = ParseBaseTypeSpecifier(BaseLoc, EndLocation);
2136 return Actions.ActOnBaseSpecifier(ClassDecl, Range, Attributes, IsVirtual,
2137 Access, BaseType.
get(), BaseLoc,
2161 void Parser::HandleMemberFunctionDeclDelays(
Declarator& DeclaratorInfo,
2169 if (!NeedLateParse) {
2173 if (Param->hasUnparsedDefaultArg()) {
2174 NeedLateParse =
true;
2180 if (NeedLateParse) {
2183 auto LateMethod =
new LateParsedMethodDeclaration(
this, ThisDecl);
2184 getCurrentClass().LateParsedDeclarations.push_back(LateMethod);
2193 LateMethod->DefaultArgs.reserve(FTI.
NumParams);
2195 LateMethod->DefaultArgs.push_back(LateParsedDefaultArgument(
2216 Ident_final = &PP.getIdentifierTable().get(
"final");
2218 Ident_GNU_final = &PP.getIdentifierTable().get(
"__final");
2220 Ident_sealed = &PP.getIdentifierTable().get(
"sealed");
2221 Ident_override = &PP.getIdentifierTable().get(
"override");
2224 if (II == Ident_override)
2227 if (II == Ident_sealed)
2230 if (II == Ident_final)
2233 if (II == Ident_GNU_final)
2244 void Parser::ParseOptionalCXX11VirtSpecifierSeq(
VirtSpecifiers &VS,
2263 const char *PrevSpec =
nullptr;
2280 ? diag::warn_cxx98_compat_override_control_keyword
2281 : diag::ext_override_control_keyword)
2290 bool Parser::isCXX11FinalKeyword()
const {
2299 bool Parser::ParseCXXMemberDeclaratorBeforeInitializer(
2301 LateParsedAttrList &LateParsedAttrs) {
2307 if (Tok.
isNot(tok::colon))
2308 ParseDeclarator(DeclaratorInfo);
2314 "don't know where identifier would go yet?");
2316 if (BitfieldSize.isInvalid())
2318 }
else if (Tok.
is(tok::kw_requires)) {
2319 ParseTrailingRequiresClause(DeclaratorInfo);
2321 ParseOptionalCXX11VirtSpecifierSeq(
2322 VS, getCurrentClass().IsInterface,
2325 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo, VS);
2329 if (Tok.
is(tok::kw_asm)) {
2331 ExprResult AsmLabel(ParseSimpleAsm(
true, &Loc));
2332 if (AsmLabel.isInvalid())
2340 MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs);
2344 if (BitfieldSize.isUnset() && VS.
isUnset()) {
2345 ParseOptionalCXX11VirtSpecifierSeq(
2346 VS, getCurrentClass().IsInterface,
2352 if (AL.isKnownToGCC() && !AL.isCXX11Attribute())
2353 Diag(AL.getLoc(), diag::warn_gcc_attribute_location);
2355 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo, VS);
2361 if (!DeclaratorInfo.
hasName() && BitfieldSize.isUnset()) {
2371 void Parser::MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(
2378 ParseTypeQualifierListOpt(
2379 DS, AR_NoAttributesParsed,
false,
2380 false, llvm::function_ref<
void()>([&]() {
2381 Actions.CodeCompleteFunctionQualifiers(DS, D, &VS);
2388 auto DeclSpecCheck = [&](
DeclSpec::TQ TypeQual, StringRef FixItName,
2391 auto &MQ =
Function.getOrCreateMethodQualifiers();
2392 if (!(MQ.getTypeQualifiers() & TypeQual)) {
2393 std::string Name(FixItName.data());
2396 MQ.SetTypeQual(TypeQual, SpecLoc);
2398 Diag(SpecLoc, diag::err_declspec_after_virtspec)
2407 bool RefQualifierIsLValueRef =
true;
2409 if (ParseRefQualifier(RefQualifierIsLValueRef, RefQualifierLoc)) {
2410 const char *Name = (RefQualifierIsLValueRef ?
"& " :
"&& ");
2412 Function.RefQualifierIsLValueRef = RefQualifierIsLValueRef;
2415 Diag(RefQualifierLoc, diag::err_declspec_after_virtspec)
2416 << (RefQualifierIsLValueRef ?
"&" :
"&&")
2465 const ParsedTemplateInfo &TemplateInfo,
2467 if (Tok.
is(tok::at)) {
2469 Diag(Tok, diag::err_at_defs_cxx);
2471 Diag(Tok, diag::err_at_in_class);
2487 bool MalformedTypeSpec =
false;
2488 if (!TemplateInfo.Kind &&
2489 Tok.
isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) {
2491 MalformedTypeSpec =
true;
2494 if (Tok.
isNot(tok::annot_cxxscope))
2495 isAccessDecl =
false;
2497 isAccessDecl = GetLookAheadToken(2).is(tok::semi);
2504 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
2516 &TemplateKWLoc, Name)) {
2522 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
2523 "access declaration")) {
2539 if (!TemplateInfo.Kind &&
2540 Tok.
isOneOf(tok::kw_static_assert, tok::kw__Static_assert)) {
2546 if (Tok.
is(tok::kw_template)) {
2547 assert(!TemplateInfo.TemplateParams &&
2548 "Nested template improperly parsed?");
2557 if (Tok.
is(tok::kw___extension__)) {
2561 return ParseCXXClassMemberDeclaration(AS, AccessAttrs,
2562 TemplateInfo, TemplateDiags);
2565 ParsedAttributesWithRange attrs(AttrFactory);
2566 ParsedAttributesViewWithRange FnAttrs;
2568 MaybeParseCXX11Attributes(attrs);
2571 FnAttrs.addAll(attrs.begin(), attrs.end());
2572 FnAttrs.Range = attrs.Range;
2574 MaybeParseMicrosoftAttributes(attrs);
2576 if (Tok.
is(tok::kw_using)) {
2577 ProhibitAttributes(attrs);
2583 while (Tok.
is(tok::kw_template)) {
2585 Diag(TemplateLoc, diag::err_unexpected_template_after_using)
2589 if (Tok.
is(tok::kw_namespace)) {
2590 Diag(UsingLoc, diag::err_using_namespace_in_class);
2597 UsingLoc, DeclEnd, AS);
2601 LateParsedAttrList CommonLateParsedAttrs;
2607 if (MalformedTypeSpec)
2610 ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DeclSpecContext::DSC_class,
2611 &CommonLateParsedAttrs);
2619 TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate &&
2620 DiagnoseMissingSemiAfterTagDefinition(DS, AS, DeclSpecContext::DSC_class,
2621 &CommonLateParsedAttrs))
2625 TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->data()
2627 TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->size() : 0);
2631 ProhibitAttributes(FnAttrs);
2634 Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(
2635 getCurScope(), AS, DS, TemplateParams,
false, AnonRecord);
2636 DS.complete(TheDecl);
2638 Decl* decls[] = {AnonRecord, TheDecl};
2639 return Actions.BuildDeclaratorGroup(decls);
2641 return Actions.ConvertDeclToDeclGroup(TheDecl);
2645 if (TemplateInfo.TemplateParams)
2650 LateParsedAttrList LateParsedAttrs;
2655 auto TryConsumePureSpecifier = [&] (
bool AllowDefinition) {
2656 if (Tok.
isNot(tok::equal))
2661 if (
Zero.isNot(tok::numeric_constant) ||
Zero.getLength() != 1 ||
2662 PP.getSpelling(
Zero, Buffer) !=
"0")
2665 auto &
After = GetLookAheadToken(2);
2666 if (!
After.isOneOf(tok::semi, tok::comma) &&
2667 !(AllowDefinition &&
2668 After.isOneOf(tok::l_brace, tok::colon, tok::kw_try)))
2677 ExprResult BitfieldSize;
2678 ExprResult TrailingRequiresClause;
2679 bool ExpectSemi =
true;
2682 if (ParseCXXMemberDeclaratorBeforeInitializer(
2683 DeclaratorInfo, VS, BitfieldSize, LateParsedAttrs)) {
2693 TryConsumePureSpecifier(
true);
2704 if (Tok.
isOneOf(tok::l_brace, tok::colon, tok::kw_try)) {
2706 }
else if (Tok.
is(tok::equal)) {
2708 if (KW.
is(tok::kw_default))
2710 else if (KW.
is(tok::kw_delete))
2722 ProhibitAttributes(FnAttrs);
2739 diag::err_function_declared_typedef);
2746 ParseCXXInlineMethodDef(AS, AccessAttrs, DeclaratorInfo, TemplateInfo,
2750 for (
unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i) {
2751 CommonLateParsedAttrs[i]->addDecl(FunDecl);
2753 for (
unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i) {
2754 LateParsedAttrs[i]->addDecl(FunDecl);
2757 LateParsedAttrs.clear();
2760 if (Tok.
is(tok::semi))
2761 ConsumeExtraSemi(AfterMemberFunctionDefinition);
2773 bool HasStaticInitializer =
false;
2777 if (!TryConsumePureSpecifier(
false))
2779 HasStaticInitializer =
true;
2786 if (BitfieldSize.
get())
2788 ? diag::warn_cxx17_compat_bitfield_member_init
2789 : diag::ext_bitfield_member_init);
2792 HasStaticInitializer =
true;
2810 E = Ranges.end(); I != E; ++I)
2811 Diag((*I).getBegin(), diag::err_attributes_not_allowed) << *I;
2813 ThisDecl = Actions.ActOnFriendFunctionDecl(
getCurScope(), DeclaratorInfo,
2816 ThisDecl = Actions.ActOnCXXMemberDeclarator(
getCurScope(), AS,
2820 VS, HasInClassInit);
2823 ThisDecl ? dyn_cast<VarTemplateDecl>(ThisDecl) :
nullptr)
2826 ThisDecl = VT->getTemplatedDecl();
2829 Actions.ProcessDeclAttributeList(
getCurScope(), ThisDecl, AccessAttrs);
2838 HasStaticInitializer =
true;
2841 if (ThisDecl && PureSpecLoc.
isValid())
2842 Actions.ActOnPureSpecifier(ThisDecl, PureSpecLoc);
2848 ? diag::warn_cxx98_compat_nonstatic_member_init
2849 : diag::ext_nonstatic_member_init);
2857 Diag(Tok, diag::err_incomplete_array_member_init);
2864 ParseCXXNonStaticMemberInitializer(ThisDecl);
2865 }
else if (HasStaticInitializer) {
2867 ExprResult Init = ParseCXXMemberInitializer(
2873 Actions.AddInitializerToDecl(ThisDecl, Init.
get(), EqualLoc.
isInvalid());
2876 Actions.ActOnUninitializedDecl(ThisDecl);
2881 for (
unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i)
2882 CommonLateParsedAttrs[i]->addDecl(ThisDecl);
2884 for (
unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i)
2885 LateParsedAttrs[i]->addDecl(ThisDecl);
2887 Actions.FinalizeDeclaration(ThisDecl);
2888 DeclsInGroup.push_back(ThisDecl);
2893 HandleMemberFunctionDeclDelays(DeclaratorInfo, ThisDecl);
2895 LateParsedAttrs.clear();
2897 DeclaratorInfo.complete(ThisDecl);
2910 Diag(CommaLoc, diag::err_expected_semi_declaration)
2917 DeclaratorInfo.
clear();
2924 MaybeParseGNUAttributes(DeclaratorInfo);
2926 if (ParseCXXMemberDeclaratorBeforeInitializer(
2927 DeclaratorInfo, VS, BitfieldSize, LateParsedAttrs))
2932 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list)) {
2940 return Actions.FinalizeDeclaratorGroup(
getCurScope(), DS, DeclsInGroup);
2963 ExprResult Parser::ParseCXXMemberInitializer(
Decl *D,
bool IsFunction,
2965 assert(Tok.
isOneOf(tok::equal, tok::l_brace)
2966 &&
"Data member initializer not starting with '=' or '{'");
2971 if (Tok.
is(tok::kw_delete)) {
2986 }
else if (Tok.
is(tok::kw_default)) {
2988 Diag(Tok, diag::err_default_delete_in_multiple_declaration)
2996 if (
const auto *PD = dyn_cast_or_null<MSPropertyDecl>(D)) {
2997 Diag(Tok, diag::err_ms_property_initializer) << PD;
3000 return ParseInitializer();
3003 void Parser::SkipCXXMemberSpecification(
SourceLocation RecordLoc,
3008 assert(isCXX11FinalKeyword() &&
"not a class definition");
3013 ParsedAttributesWithRange Attrs(AttrFactory);
3014 CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc);
3019 if (Tok.
isNot(tok::colon) && Tok.
isNot(tok::l_brace))
3026 if (Tok.
is(tok::colon)) {
3029 ParsingClassDefinition ParsingDef(*
this, TagDecl,
true,
3032 Actions.ActOnTagStartSkippedDefinition(
getCurScope(), TagDecl);
3035 ParseBaseClause(
nullptr);
3037 Actions.ActOnTagFinishSkippedDefinition(OldContext);
3039 if (!Tok.
is(tok::l_brace)) {
3040 Diag(PP.getLocForEndOfToken(PrevTokLocation),
3041 diag::err_expected_lbrace_after_base_specifiers);
3047 assert(Tok.
is(tok::l_brace));
3054 if (Tok.
is(tok::kw___attribute))
3055 MaybeParseGNUAttributes(Attrs);
3064 case tok::kw___if_exists:
3065 case tok::kw___if_not_exists:
3066 ParseMicrosoftIfExistsClassDeclaration(TagType, AccessAttrs, AS);
3071 ConsumeExtraSemi(InsideStruct, TagType);
3075 case tok::annot_pragma_vis:
3076 HandlePragmaVisibility();
3078 case tok::annot_pragma_pack:
3081 case tok::annot_pragma_align:
3082 HandlePragmaAlign();
3084 case tok::annot_pragma_ms_pointers_to_members:
3085 HandlePragmaMSPointersToMembers();
3087 case tok::annot_pragma_ms_pragma:
3088 HandlePragmaMSPragma();
3090 case tok::annot_pragma_ms_vtordisp:
3091 HandlePragmaMSVtorDisp();
3093 case tok::annot_pragma_dump:
3097 case tok::kw_namespace:
3099 DiagnoseUnexpectedNamespace(cast<NamedDecl>(TagDecl));
3102 case tok::kw_private:
3106 return ParseCXXClassMemberDeclaration(AS, AccessAttrs);
3108 case tok::kw_public:
3109 case tok::kw_protected: {
3117 AccessAttrs.clear();
3118 MaybeParseGNUAttributes(AccessAttrs);
3123 Diag(EndLoc, diag::err_expected)
3127 Diag(EndLoc, diag::err_expected)
3137 if (Actions.ActOnAccessSpecifier(NewAS, ASLoc, EndLoc, AccessAttrs)) {
3139 AccessAttrs.clear();
3145 case tok::annot_pragma_openmp:
3146 return ParseOpenMPDeclarativeDirectiveWithExtDecl(
3147 AS, AccessAttrs,
true, TagType, TagDecl);
3153 Actions.getASTContext().getPrintingPolicy());
3154 ConsumeAnnotationToken();
3157 return ParseCXXClassMemberDeclaration(AS, AccessAttrs);
3167 void Parser::ParseCXXMemberSpecification(
SourceLocation RecordLoc,
3169 ParsedAttributesWithRange &Attrs,
3170 unsigned TagType,
Decl *TagDecl) {
3176 llvm::TimeTraceScope TimeScope(
"ParseClass", [&]() {
3177 if (
auto *TD = dyn_cast_or_null<NamedDecl>(TagDecl))
3178 return TD->getQualifiedNameAsString();
3179 return std::string(
"<anonymous>");
3183 "parsing struct/union/class body");
3187 bool NonNestedClass =
true;
3188 if (!ClassStack.empty()) {
3190 if (S->isClassScope()) {
3192 NonNestedClass =
false;
3195 if (getCurrentClass().IsInterface) {
3196 Diag(RecordLoc, diag::err_invalid_member_in_interface)
3198 << (isa<NamedDecl>(TagDecl)
3199 ? cast<NamedDecl>(TagDecl)->getQualifiedNameAsString()
3216 ParsingClassDefinition ParsingDef(*
this, TagDecl, NonNestedClass,
3220 Actions.ActOnTagStartDefinition(
getCurScope(), TagDecl);
3223 bool IsFinalSpelledSealed =
false;
3231 "not a class definition");
3236 Diag(FinalLoc, diag::err_override_control_interface)
3240 ? diag::warn_cxx98_compat_override_control_keyword
3241 : diag::ext_override_control_keyword)
3244 Diag(FinalLoc, diag::ext_ms_sealed_keyword);
3246 Diag(FinalLoc, diag::ext_warn_gnu_final);
3252 CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc);
3261 if (!Tok.
is(tok::colon) && !Tok.
is(tok::l_brace)) {
3263 Actions.ActOnTagDefinitionError(
getCurScope(), TagDecl);
3268 if (Tok.
is(tok::colon)) {
3269 ParseScope InheritanceScope(
this,
getCurScope()->getFlags() |
3272 ParseBaseClause(TagDecl);
3273 if (!Tok.
is(tok::l_brace)) {
3274 bool SuggestFixIt =
false;
3275 SourceLocation BraceLoc = PP.getLocForEndOfToken(PrevTokLocation);
3278 case tok::kw_private:
3279 case tok::kw_protected:
3280 case tok::kw_public:
3283 case tok::kw_static_assert:
3287 case tok::kw_template:
3288 SuggestFixIt =
true;
3290 case tok::identifier:
3291 SuggestFixIt = isConstructorDeclarator(
true);
3294 SuggestFixIt = isCXXSimpleDeclaration(
false);
3299 Diag(BraceLoc, diag::err_expected_lbrace_after_base_specifiers);
3303 PP.EnterToken(Tok,
true);
3307 Actions.ActOnTagDefinitionError(
getCurScope(), TagDecl);
3313 assert(Tok.
is(tok::l_brace));
3318 Actions.ActOnStartCXXMemberDeclarations(
getCurScope(), TagDecl, FinalLoc,
3319 IsFinalSpelledSealed,
3320 T.getOpenLocation());
3330 ParsedAttributesWithRange AccessAttrs(AttrFactory);
3334 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
3337 ParseCXXClassMemberDeclarationWithPragmas(
3338 CurAS, AccessAttrs, static_cast<DeclSpec::TST>(TagType), TagDecl);
3347 MaybeParseGNUAttributes(attrs);
3350 Actions.ActOnFinishCXXMemberSpecification(
getCurScope(), RecordLoc, TagDecl,
3351 T.getOpenLocation(),
3352 T.getCloseLocation(), attrs);
3359 if (TagDecl && NonNestedClass) {
3365 ParseLexedPragmas(getCurrentClass());
3366 ParseLexedAttributes(getCurrentClass());
3367 ParseLexedMethodDeclarations(getCurrentClass());
3370 Actions.ActOnFinishCXXMemberDecls();
3372 ParseLexedMemberInitializers(getCurrentClass());
3373 ParseLexedMethodDefs(getCurrentClass());
3374 PrevTokLocation = SavedPrevTokLocation;
3378 Actions.ActOnFinishCXXNonNestedClass();
3382 Actions.ActOnTagFinishDefinition(
getCurScope(), TagDecl, T.getRange());
3389 void Parser::DiagnoseUnexpectedNamespace(
NamedDecl *D) {
3390 assert(Tok.
is(tok::kw_namespace));
3395 diag::err_missing_end_of_definition) << D;
3397 diag::note_missing_end_of_definition_before) << D;
3400 PP.EnterToken(Tok,
true);
3403 Tok.
setLocation(PP.getLocForEndOfToken(PrevTokLocation));
3405 PP.EnterToken(Tok,
true);
3431 void Parser::ParseConstructorInitializer(
Decl *ConstructorDecl) {
3432 assert(Tok.
is(tok::colon) &&
3433 "Constructor initializer always starts with ':'");
3441 bool AnyErrors =
false;
3444 if (Tok.
is(tok::code_completion)) {
3445 Actions.CodeCompleteConstructorInitializer(ConstructorDecl,
3447 return cutOffParsing();
3450 MemInitResult MemInit = ParseMemInitializer(ConstructorDecl);
3452 MemInitializers.push_back(MemInit.
get());
3456 if (Tok.
is(tok::comma))
3458 else if (Tok.
is(tok::l_brace))
3463 Tok.
isOneOf(tok::identifier, tok::coloncolon)) {
3465 Diag(Loc, diag::err_ctor_init_missing_comma)
3477 Actions.ActOnMemInitializers(ConstructorDecl, ColonLoc, MemInitializers,
3496 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
false))
3507 if (Tok.
is(tok::identifier)) {
3512 }
else if (Tok.
is(tok::annot_decltype)) {
3517 ParseDecltypeSpecifier(DS);
3520 ? takeTemplateIdAnnotation(Tok)
3525 AnnotateTemplateIdTokenAsType(SS,
true);
3526 assert(Tok.
is(tok::annot_typename) &&
"template-id -> type failed");
3528 ConsumeAnnotationToken();
3529 if (!TemplateTypeTy)
3532 Diag(Tok, diag::err_expected_member_or_base_name);
3539 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
3542 ExprResult InitList = ParseBraceInitializer();
3549 return Actions.ActOnMemInitializer(ConstructorDecl,
getCurScope(), SS, II,
3550 TemplateTypeTy, DS, IdLoc,
3551 InitList.
get(), EllipsisLoc);
3552 }
else if(Tok.
is(tok::l_paren)) {
3557 ExprVector ArgExprs;
3558 CommaLocsTy CommaLocs;
3559 auto RunSignatureHelp = [&] {
3560 QualType PreferredType = Actions.ProduceCtorInitMemberSignatureHelp(
3561 getCurScope(), ConstructorDecl, SS, TemplateTypeTy, ArgExprs, II,
3562 T.getOpenLocation());
3563 CalledSignatureHelp =
true;
3564 return PreferredType;
3566 if (Tok.
isNot(tok::r_paren) &&
3567 ParseExpressionList(ArgExprs, CommaLocs, [&] {
3568 PreferredType.enterFunctionArgument(Tok.
getLocation(),
3571 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
3582 return Actions.ActOnMemInitializer(ConstructorDecl,
getCurScope(), SS, II,
3583 TemplateTypeTy, DS, IdLoc,
3584 T.getOpenLocation(), ArgExprs,
3585 T.getCloseLocation(), EllipsisLoc);
3589 return Diag(Tok, diag::err_expected_either) << tok::l_paren << tok::l_brace;
3591 return Diag(Tok, diag::err_expected) << tok::l_paren;
3604 Parser::tryParseExceptionSpecification(
bool Delayed,
3608 ExprResult &NoexceptExpr,
3611 ExceptionSpecTokens =
nullptr;
3615 if (Tok.
isNot(tok::kw_throw) && Tok.
isNot(tok::kw_noexcept))
3619 bool IsNoexcept = Tok.
is(tok::kw_noexcept);
3620 Token StartTok = Tok;
3624 if (!Tok.
is(tok::l_paren)) {
3627 Diag(Tok, diag::warn_cxx98_compat_noexcept_decl);
3628 NoexceptExpr =
nullptr;
3632 Diag(Tok, diag::err_expected_lparen_after) <<
"throw";
3638 ExceptionSpecTokens->push_back(StartTok);
3639 ExceptionSpecTokens->push_back(Tok);
3640 SpecificationRange.
setEnd(ConsumeParen());
3642 ConsumeAndStoreUntil(tok::r_paren, *ExceptionSpecTokens,
3645 SpecificationRange.
setEnd(ExceptionSpecTokens->back().getLocation());
3651 if (Tok.
is(tok::kw_throw)) {
3652 Result = ParseDynamicExceptionSpecification(SpecificationRange,
3654 DynamicExceptionRanges);
3655 assert(DynamicExceptions.size() == DynamicExceptionRanges.size() &&
3656 "Produced different number of exception types and ranges.");
3660 if (Tok.
isNot(tok::kw_noexcept))
3663 Diag(Tok, diag::warn_cxx98_compat_noexcept_decl);
3671 if (Tok.
is(tok::l_paren)) {
3678 NoexceptExpr = Actions.ActOnNoexceptSpec(KeywordLoc, NoexceptExpr.
get(),
3680 NoexceptRange =
SourceRange(KeywordLoc, T.getCloseLocation());
3687 NoexceptRange =
SourceRange(KeywordLoc, KeywordLoc);
3691 SpecificationRange = NoexceptRange;
3692 Result = NoexceptType;
3696 if (Tok.
is(tok::kw_throw)) {
3697 Diag(Tok.
getLocation(), diag::err_dynamic_and_noexcept_specification);
3698 ParseDynamicExceptionSpecification(NoexceptRange, DynamicExceptions,
3699 DynamicExceptionRanges);
3702 Diag(Tok.
getLocation(), diag::err_dynamic_and_noexcept_specification);
3711 const char *Replacement = IsNoexcept ?
"noexcept" :
"noexcept(false)";
3714 ? diag::ext_dynamic_exception_spec
3715 : diag::warn_exception_spec_deprecated)
3717 P.
Diag(Range.
getBegin(), diag::note_exception_spec_deprecated)
3737 assert(Tok.
is(tok::kw_throw) &&
"expected throw");
3742 Diag(Tok, diag::err_expected_lparen_after) <<
"throw";
3749 if (Tok.
is(tok::ellipsis)) {
3752 Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec);
3761 while (Tok.
isNot(tok::r_paren)) {
3764 if (Tok.
is(tok::ellipsis)) {
3771 Res = Actions.ActOnPackExpansion(Res.
get(), Ellipsis);
3775 Exceptions.push_back(Res.
get());
3776 Ranges.push_back(Range);
3786 Exceptions.empty());
3792 TypeResult Parser::ParseTrailingReturnType(
SourceRange &Range,
3793 bool MayBeFollowedByDirectInit) {
3794 assert(Tok.
is(tok::arrow) &&
"expected arrow");
3804 void Parser::ParseTrailingRequiresClause(
Declarator &D) {
3805 assert(Tok.
is(tok::kw_requires) &&
"expected requires");
3809 ExprResult TrailingRequiresClause;
3810 ParseScope ParamScope(
this,
3815 Actions.ActOnStartTrailingRequiresClause(
getCurScope(), D);
3818 InitCXXThisScopeForDeclaratorIfRelevant(D, D.
getDeclSpec(), ThisScope);
3820 TrailingRequiresClause =
3823 TrailingRequiresClause =
3824 Actions.ActOnFinishTrailingRequiresClause(TrailingRequiresClause);
3828 diag::err_requires_clause_on_declarator_not_declaring_a_function);
3832 if (TrailingRequiresClause.isInvalid())
3833 SkipUntil({tok::l_brace, tok::arrow, tok::kw_try, tok::comma, tok::colon},
3843 TypeResult TrailingReturnType =
3844 ParseTrailingReturnType(Range,
false);
3848 diag::err_requires_clause_must_appear_after_trailing_return)
3852 FunctionChunk.TrailingReturnType = TrailingReturnType.
get();
3854 SkipUntil({tok::equal, tok::l_brace, tok::arrow, tok::kw_try, tok::comma},
3863 Parser::PushParsingClass(
Decl *ClassDecl,
bool NonNestedClass,
3865 assert((NonNestedClass || !ClassStack.empty()) &&
3866 "Nested class without outer class");
3867 ClassStack.push(
new ParsingClass(ClassDecl, NonNestedClass, IsInterface));
3868 return Actions.PushParsingClass();
3873 void Parser::DeallocateParsedClasses(Parser::ParsingClass *Class) {
3874 for (
unsigned I = 0, N = Class->LateParsedDeclarations.size(); I != N; ++I)
3875 delete Class->LateParsedDeclarations[I];
3886 assert(!ClassStack.empty() &&
"Mismatched push/pop for class parsing");
3888 Actions.PopParsingClass(state);
3890 ParsingClass *Victim = ClassStack.top();
3892 if (Victim->TopLevelClass) {
3895 DeallocateParsedClasses(Victim);
3898 assert(!ClassStack.empty() &&
"Missing top-level class?");
3900 if (Victim->LateParsedDeclarations.empty()) {
3905 DeallocateParsedClasses(Victim);
3912 assert(
getCurScope()->isClassScope() &&
"Nested class outside of class scope?");
3913 ClassStack.top()->LateParsedDeclarations.push_back(
new LateParsedClass(
this, Victim));
3938 case tok::numeric_constant: {
3945 PP.getSourceManager().getExpansionLoc(Tok.
getLocation());
3946 StringRef Spelling = PP.getSpelling(ExpansionLoc, ExpansionBuf);
3947 if (Spelling ==
"__clang__") {
3950 PP.getSourceManager().getExpansionLoc(Tok.
getEndLoc()));
3951 Diag(Tok, diag::warn_wrong_clang_attr_namespace)
3954 return &PP.getIdentifierTable().get(
"_Clang");
3967 case tok::pipeequal:
3968 case tok::caretequal:
3970 case tok::exclaimequal:
3975 PP.getSourceManager().getSpellingLoc(Tok.
getLocation());
3976 StringRef Spelling = PP.getSpelling(SpellingLoc, SpellingBuf);
3979 return &PP.getIdentifierTable().get(Spelling);
3989 case ParsedAttr::AT_CarriesDependency:
3990 case ParsedAttr::AT_Deprecated:
3991 case ParsedAttr::AT_FallThrough:
3992 case ParsedAttr::AT_CXX11NoReturn:
3993 case ParsedAttr::AT_NoUniqueAddress:
3995 case ParsedAttr::AT_WarnUnusedResult:
3996 return !ScopeName && AttrName->
getName().equals(
"nodiscard");
3997 case ParsedAttr::AT_Unused:
3998 return !ScopeName && AttrName->
getName().equals(
"maybe_unused");
4024 assert(Tok.
is(tok::l_paren) &&
"Not a C++11 attribute argument list");
4040 if (ScopeName && (ScopeName->
isStr(
"gnu") || ScopeName->
isStr(
"__gnu__"))) {
4043 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
4044 ScopeLoc, Syntax,
nullptr);
4050 if (ScopeName && (ScopeName->
isStr(
"clang") || ScopeName->
isStr(
"_Clang")))
4051 NumArgs = ParseClangAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc,
4052 ScopeName, ScopeLoc, Syntax);
4055 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
4056 ScopeName, ScopeLoc, Syntax);
4058 if (!Attrs.
empty() &&
4068 Diag(LParenLoc, diag::err_attribute_requires_arguments) << AttrName;
4074 Diag(LParenLoc, diag::err_cxx11_attribute_forbids_arguments)
4109 if (Tok.
is(tok::kw_alignas)) {
4111 ParseAlignmentSpecifier(attrs, endLoc);
4115 assert(Tok.
is(tok::l_square) &&
NextToken().
is(tok::l_square) &&
4116 "Not a double square bracket attribute list");
4125 if (Tok.
is(tok::kw_using)) {
4127 ? diag::warn_cxx14_compat_using_attribute_ns
4128 : diag::ext_using_attribute_ns);
4131 CommonScopeName = TryParseCXX11AttributeIdentifier(CommonScopeLoc);
4132 if (!CommonScopeName) {
4140 llvm::SmallDenseMap<IdentifierInfo*, SourceLocation, 4> SeenAttrs;
4142 while (Tok.
isNot(tok::r_square)) {
4150 AttrName = TryParseCXX11AttributeIdentifier(AttrLoc);
4157 ScopeName = AttrName;
4160 AttrName = TryParseCXX11AttributeIdentifier(AttrLoc);
4168 if (CommonScopeName) {
4170 Diag(ScopeLoc, diag::err_using_attribute_ns_conflict)
4173 ScopeName = CommonScopeName;
4174 ScopeLoc = CommonScopeLoc;
4179 bool AttrParsed =
false;
4182 !SeenAttrs.insert(std::make_pair(AttrName, AttrLoc)).second)
4183 Diag(AttrLoc, diag::err_cxx11_attribute_repeated)
4187 if (Tok.
is(tok::l_paren))
4188 AttrParsed = ParseCXX11AttributeArgs(AttrName, AttrLoc, attrs, endLoc,
4189 ScopeName, ScopeLoc);
4194 SourceRange(ScopeLoc.
isValid() ? ScopeLoc : AttrLoc, AttrLoc),
4195 ScopeName, ScopeLoc,
nullptr, 0,
4199 Diag(Tok, diag::err_cxx11_attribute_forbids_ellipsis)
4203 if (ExpectAndConsume(tok::r_square))
4207 if (ExpectAndConsume(tok::r_square))
4215 void Parser::ParseCXX11Attributes(ParsedAttributesWithRange &attrs,
4217 assert(standardAttributesAllowed());
4224 ParseCXX11AttributeSpecifier(attrs, endLoc);
4225 }
while (isCXX11AttributeSpecifier());
4230 void Parser::DiagnoseAndSkipCXX11Attributes() {
4237 Diag(StartLoc, diag::err_attributes_not_allowed)
4245 if (!isCXX11AttributeSpecifier())
4249 if (Tok.
is(tok::l_square)) {
4255 assert(Tok.
is(tok::kw_alignas) &&
"not an attribute specifier");
4262 }
while (isCXX11AttributeSpecifier());
4269 assert(Tok.
is(tok::identifier) &&
"Not a Microsoft attribute list");
4271 assert(UuidIdent->getName() ==
"uuid" &&
"Not a Microsoft attribute list");
4279 Diag(Tok, diag::err_expected) << tok::l_paren;
4284 if (Tok.
is(tok::string_literal)) {
4286 ExprResult StringResult = ParseStringLiteralExpression();
4289 ArgExprs.push_back(StringResult.
get());
4306 while (Tok.
isNot(tok::r_paren)) {
4308 Diag(Tok, diag::err_attribute_uuid_malformed_guid);
4313 SpellingBuffer.resize(Tok.
getLength() + 1);
4314 bool Invalid =
false;
4315 StringRef TokSpelling = PP.getSpelling(Tok, SpellingBuffer, &Invalid);
4320 StrBuffer += TokSpelling;
4326 Diag(Tok, diag::err_attribute_uuid_malformed_guid);
4336 Toks[0].
setKind(tok::string_literal);
4341 cast<StringLiteral>(Actions.ActOnStringLiteral(Toks,
nullptr).get());
4342 ArgExprs.push_back(UuidString);
4362 assert(Tok.
is(tok::l_square) &&
"Not a Microsoft attribute list");
4372 if (Tok.
isNot(tok::identifier))
4375 ParseMicrosoftUuidAttributeArgs(attrs);
4383 }
while (Tok.
is(tok::l_square));
4386 void Parser::ParseMicrosoftIfExistsClassDeclaration(
4389 IfExistsCondition
Result;
4390 if (ParseMicrosoftIfExistsCondition(Result))
4395 Diag(Tok, diag::err_expected) << tok::l_brace;
4399 switch (Result.Behavior) {
4405 Diag(Result.KeywordLoc, diag::warn_microsoft_dependent_exists)
4406 << Result.IsIfExists;
4415 while (Tok.
isNot(tok::r_brace) && !isEofOrEom()) {
4417 if (Tok.
isOneOf(tok::kw___if_exists, tok::kw___if_not_exists)) {
4418 ParseMicrosoftIfExistsClassDeclaration(TagType,
4419 AccessAttrs, CurAS);
4424 if (Tok.
is(tok::semi)) {
4425 ConsumeExtraSemi(InsideStruct, TagType);
4435 if (Tok.
is(tok::colon))
4436 Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.
getLocation(),
4439 Diag(Tok, diag::err_expected) << tok::colon;
4445 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.
This is a scope that corresponds to the parameters within a function prototype.
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.
Syntax
The style used to specify an attribute.
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 ...
void setTrailingRequiresClause(Expr *TRC)
Sets a trailing requires clause for this declarator.
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)
bool Zero(InterpState &S, CodePtr OpPC)
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
void setTemplateParameterLists(ArrayRef< TemplateParameterList *> TPLs)
Sets the template parameter lists that preceded the declarator.
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...
__ptr16, alignas(...), etc.
const clang::PrintingPolicy & getPrintingPolicy() const
void takeAllFrom(ParsedAttributes &attrs)
ParsedTemplateArgument * getTemplateArgs()
Retrieves a pointer to the template arguments.
MutableArrayRef< TemplateParameterList * > MultiTemplateParamsArg
unsigned HasTrailingReturnType
HasTrailingReturnType - If this is true, a trailing return type was specified.
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
const char * getName() const
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
This is a scope that corresponds to the parameters within a function prototype for a function declara...
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)
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)
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 isPragmaAnnotation(TokenKind K)
Return true if this is an annotation token representing a pragma.
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...
Kind getParsedKind() const
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
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)
ExprResult ParseConstraintLogicalOrExpression(bool IsTrailingRequiresClause)
Parse a constraint-logical-or-expression.
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