28 #include "llvm/ADT/SmallString.h" 30 using namespace clang;
61 assert(Tok.
is(tok::kw_namespace) &&
"Not a namespace!");
65 if (Tok.
is(tok::code_completion)) {
73 std::vector<SourceLocation> ExtraIdentLoc;
74 std::vector<IdentifierInfo*> ExtraIdent;
75 std::vector<SourceLocation> ExtraNamespaceLoc;
77 ParsedAttributesWithRange attrs(AttrFactory);
81 ? diag::warn_cxx14_compat_ns_enum_attribute
82 : diag::ext_ns_enum_attribute)
85 ParseCXX11Attributes(attrs);
88 if (Tok.
is(tok::identifier)) {
91 while (Tok.
is(tok::coloncolon) &&
NextToken().
is(tok::identifier)) {
99 if (!ExtraNamespaceLoc.empty() && attrLoc.isValid())
100 Diag(attrLoc, diag::err_unexpected_nested_namespace_attribute);
103 if (Tok.
is(tok::kw___attribute)) {
105 ParseGNUAttributes(attrs);
108 if (Tok.
is(tok::equal)) {
110 Diag(Tok, diag::err_expected) << tok::identifier;
115 if (attrLoc.isValid())
116 Diag(attrLoc, diag::err_unexpected_namespace_attributes_alias);
118 Diag(InlineLoc, diag::err_inline_namespace_alias)
120 Decl *NSAlias = ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd);
125 if (T.consumeOpen()) {
127 Diag(Tok, diag::err_expected) << tok::l_brace;
129 Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace;
136 Diag(T.getOpenLocation(), diag::err_namespace_nonnamespace_scope);
141 if (ExtraIdent.empty()) {
143 }
else if (InlineLoc.
isValid()) {
144 Diag(InlineLoc, diag::err_inline_nested_namespace_definition);
146 Diag(ExtraNamespaceLoc[0],
147 diag::warn_cxx14_compat_nested_namespace_definition);
149 TentativeParsingAction TPA(*
this);
151 Token rBraceToken = Tok;
154 if (!rBraceToken.
is(tok::r_brace)) {
155 Diag(ExtraNamespaceLoc[0], diag::ext_nested_namespace_definition)
156 <<
SourceRange(ExtraNamespaceLoc.front(), ExtraIdentLoc.back());
158 std::string NamespaceFix;
159 for (std::vector<IdentifierInfo*>::iterator I = ExtraIdent.begin(),
160 E = ExtraIdent.end(); I != E; ++I) {
161 NamespaceFix +=
" { namespace ";
162 NamespaceFix += (*I)->getName();
166 for (
unsigned i = 0, e = ExtraIdent.size(); i != e; ++i)
169 Diag(ExtraNamespaceLoc[0], diag::ext_nested_namespace_definition)
171 ExtraIdentLoc.back()),
180 diag::warn_cxx98_compat_inline_namespace : diag::ext_inline_namespace);
187 getCurScope(), InlineLoc, NamespaceLoc, IdentLoc, Ident,
188 T.getOpenLocation(), attrs, ImplicitUsingDirectiveDecl);
191 NamespaceLoc,
"parsing namespace");
195 ParseInnerNamespace(ExtraIdentLoc, ExtraIdent, ExtraNamespaceLoc, 0,
196 InlineLoc, attrs, T);
199 NamespaceScope.Exit();
201 DeclEnd = T.getCloseLocation();
205 ImplicitUsingDirectiveDecl);
209 void Parser::ParseInnerNamespace(std::vector<SourceLocation> &IdentLoc,
210 std::vector<IdentifierInfo *> &Ident,
211 std::vector<SourceLocation> &NamespaceLoc,
215 if (index == Ident.size()) {
216 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
218 ParsedAttributesWithRange attrs(AttrFactory);
219 MaybeParseCXX11Attributes(attrs);
220 ParseExternalDeclaration(attrs);
238 ImplicitUsingDirectiveDecl);
239 assert(!ImplicitUsingDirectiveDecl &&
240 "nested namespace definition cannot define anonymous namespace");
242 ParseInnerNamespace(IdentLoc, Ident, NamespaceLoc, ++index, InlineLoc,
245 NamespaceScope.Exit();
256 assert(Tok.
is(tok::equal) &&
"Not equal token");
260 if (Tok.
is(tok::code_completion)) {
268 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
false,
274 if (Tok.
isNot(tok::identifier)) {
275 Diag(Tok, diag::err_expected_namespace_name);
294 if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after_namespace_name))
298 Alias, SS, IdentLoc, Ident);
309 assert(isTokenStringLiteral() &&
"Not a string literal!");
310 ExprResult Lang = ParseStringLiteralExpression(
false);
320 ParsedAttributesWithRange attrs(AttrFactory);
321 MaybeParseCXX11Attributes(attrs);
323 if (Tok.
isNot(tok::l_brace)) {
330 ParseExternalDeclaration(attrs, &DS);
338 ProhibitAttributes(attrs);
343 unsigned NestedModules = 0;
346 case tok::annot_module_begin:
351 case tok::annot_module_end:
358 case tok::annot_module_include:
370 ParsedAttributesWithRange attrs(AttrFactory);
371 MaybeParseCXX11Attributes(attrs);
372 ParseExternalDeclaration(attrs);
391 Decl *Parser::ParseExportDeclaration() {
392 assert(Tok.
is(tok::kw_export));
400 if (Tok.
isNot(tok::l_brace)) {
402 ParsedAttributesWithRange Attrs(AttrFactory);
403 MaybeParseCXX11Attributes(Attrs);
404 MaybeParseMicrosoftAttributes(Attrs);
405 ParseExternalDeclaration(Attrs);
415 if (Tok.
is(tok::r_brace))
416 Diag(ExportLoc, diag::err_export_empty)
419 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
421 ParsedAttributesWithRange Attrs(AttrFactory);
422 MaybeParseCXX11Attributes(Attrs);
423 MaybeParseMicrosoftAttributes(Attrs);
424 ParseExternalDeclaration(Attrs);
429 T.getCloseLocation());
436 const ParsedTemplateInfo &TemplateInfo,
438 ParsedAttributesWithRange &attrs) {
439 assert(Tok.
is(tok::kw_using) &&
"Not using token");
445 if (Tok.
is(tok::code_completion)) {
452 if (Tok.
is(tok::kw_namespace)) {
454 if (TemplateInfo.Kind) {
456 Diag(UsingLoc, diag::err_templated_using_directive_declaration)
460 Decl *UsingDir = ParseUsingDirective(Context, UsingLoc, DeclEnd, attrs);
467 ProhibitAttributes(attrs);
469 return ParseUsingDeclaration(Context, TemplateInfo, UsingLoc, DeclEnd,
487 assert(Tok.
is(tok::kw_namespace) &&
"Not 'namespace' token");
492 if (Tok.
is(tok::code_completion)) {
500 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
false,
510 if (Tok.
isNot(tok::identifier)) {
511 Diag(Tok, diag::err_expected_namespace_name);
530 bool GNUAttr =
false;
531 if (Tok.
is(tok::kw___attribute)) {
533 ParseGNUAttributes(attrs);
538 if (ExpectAndConsume(tok::semi,
539 GNUAttr ? diag::err_expected_semi_after_attribute_list
540 : diag::err_expected_semi_after_namespace_name))
544 IdentLoc, NamespcName, attrs);
553 UsingDeclarator &D) {
560 if (Tok.
is(tok::kw___super)) {
567 ParseOptionalCXXScopeSpecifier(D.SS,
nullptr,
false,
571 if (D.SS.isInvalid())
586 Tok.
is(tok::identifier) &&
590 !D.SS.getScopeRep()->getAsNamespace() &&
591 !D.SS.getScopeRep()->getAsNamespaceAlias()) {
595 D.Name.setConstructorName(Type, IdLoc, IdLoc);
600 !(Tok.
is(tok::identifier) &&
603 nullptr,
nullptr, D.Name))
609 diag::warn_cxx17_compat_using_declaration_pack :
610 diag::ext_using_declaration_pack);
633 const ParsedTemplateInfo &TemplateInfo,
638 ParsedAttributesWithRange MisplacedAttrs(AttrFactory);
639 MaybeParseCXX11Attributes(MisplacedAttrs);
642 bool InvalidDeclarator = ParseUsingDeclarator(Context, D);
644 ParsedAttributesWithRange Attrs(AttrFactory);
645 MaybeParseGNUAttributes(Attrs);
646 MaybeParseCXX11Attributes(Attrs);
649 if (Tok.
is(tok::equal)) {
650 if (InvalidDeclarator) {
657 if (MisplacedAttrs.Range.isValid()) {
658 Diag(MisplacedAttrs.Range.getBegin(), diag::err_attributes_not_allowed)
663 Attrs.takeAllFrom(MisplacedAttrs);
666 Decl *DeclFromDeclSpec =
nullptr;
667 Decl *AD = ParseAliasDeclarationAfterDeclarator(
668 TemplateInfo, UsingLoc, D, DeclEnd, AS, Attrs, &DeclFromDeclSpec);
674 ProhibitAttributes(MisplacedAttrs);
675 ProhibitAttributes(Attrs);
680 if (TemplateInfo.Kind) {
682 Diag(UsingLoc, diag::err_templated_using_directive_declaration)
694 MaybeParseGNUAttributes(Attrs);
696 if (InvalidDeclarator)
701 if (D.TypenameLoc.isValid() &&
703 Diag(D.Name.getSourceRange().getBegin(),
704 diag::err_typename_identifiers_only)
711 D.TypenameLoc, D.SS, D.Name,
712 D.EllipsisLoc, Attrs);
714 DeclsInGroup.push_back(UD);
722 InvalidDeclarator = ParseUsingDeclarator(Context, D);
725 if (DeclsInGroup.size() > 1)
727 diag::warn_cxx17_compat_multi_using_declaration :
728 diag::ext_multi_using_declaration);
732 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
733 !Attrs.empty() ?
"attributes list" 734 :
"using declaration"))
740 Decl *Parser::ParseAliasDeclarationAfterDeclarator(
744 if (ExpectAndConsume(tok::equal)) {
750 diag::warn_cxx98_compat_alias_declaration :
751 diag::ext_alias_declaration);
755 if (TemplateInfo.Kind == ParsedTemplateInfo::Template &&
758 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization)
760 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation)
762 if (SpecKind != -1) {
766 D.Name.TemplateId->RAngleLoc);
768 Range = TemplateInfo.getSourceRange();
769 Diag(Range.
getBegin(), diag::err_alias_declaration_specialization)
770 << SpecKind << Range;
777 Diag(D.Name.StartLocation, diag::err_alias_declaration_not_identifier);
781 }
else if (D.TypenameLoc.isValid())
782 Diag(D.TypenameLoc, diag::err_alias_declaration_not_identifier)
785 D.SS.isNotEmpty() ? D.SS.getEndLoc() : D.TypenameLoc));
786 else if (D.SS.isNotEmpty())
787 Diag(D.SS.getBeginLoc(), diag::err_alias_declaration_not_identifier)
789 if (D.EllipsisLoc.isValid())
790 Diag(D.EllipsisLoc, diag::err_alias_declaration_pack_expansion)
793 Decl *DeclFromDeclSpec =
nullptr;
798 AS, &DeclFromDeclSpec, &Attrs);
800 *OwnedType = DeclFromDeclSpec;
804 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
805 !Attrs.
empty() ?
"attributes list" 806 :
"alias declaration"))
811 TemplateParams ? TemplateParams->data() :
nullptr,
812 TemplateParams ? TemplateParams->size() : 0);
814 UsingLoc, D.Name, Attrs, TypeAlias,
827 assert(Tok.
isOneOf(tok::kw_static_assert, tok::kw__Static_assert) &&
828 "Not a static_assert declaration");
831 Diag(Tok, diag::ext_c11_static_assert);
832 if (Tok.
is(tok::kw_static_assert))
833 Diag(Tok, diag::warn_cxx98_compat_static_assert);
838 if (T.consumeOpen()) {
839 Diag(Tok, diag::err_expected) << tok::l_paren;
847 if (AssertExpr.isInvalid()) {
853 if (Tok.
is(tok::r_paren)) {
855 ? diag::warn_cxx14_compat_static_assert_no_message
856 : diag::ext_static_assert_no_message)
859 :
FixItHint::CreateInsertion(Tok.getLocation(),
", \"\""));
861 if (ExpectAndConsume(tok::comma)) {
866 if (!isTokenStringLiteral()) {
867 Diag(Tok, diag::err_expected_string_literal)
873 AssertMessage = ParseStringLiteralExpression();
883 ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert);
888 T.getCloseLocation());
897 assert(Tok.
isOneOf(tok::kw_decltype, tok::annot_decltype)
898 &&
"Not a decltype specifier");
904 if (Tok.
is(tok::annot_decltype)) {
905 Result = getExprAnnotation(Tok);
907 ConsumeAnnotationToken();
908 if (Result.isInvalid()) {
914 Diag(Tok, diag::warn_cxx98_compat_decltype);
919 if (T.expectAndConsume(diag::err_expected_lparen_after,
920 "decltype", tok::r_paren)) {
923 StartLoc : T.getOpenLocation();
927 if (Tok.
is(tok::kw_auto)) {
933 ? diag::warn_cxx11_compat_decltype_auto_type_specifier
934 : diag::ext_decltype_auto_type_specifier);
948 if (Result.isInvalid()) {
951 EndLoc = ConsumeParen();
958 assert(Tok.
is(tok::semi));
971 if (T.getCloseLocation().isInvalid()) {
975 return T.getCloseLocation();
978 if (Result.isInvalid()) {
980 return T.getCloseLocation();
983 EndLoc = T.getCloseLocation();
985 assert(!Result.isInvalid());
987 const char *PrevSpec =
nullptr;
993 DiagID, Result.get(), Policy)
996 Diag(StartLoc, DiagID) << PrevSpec;
1002 void Parser::AnnotateExistingDecltypeSpecifier(
const DeclSpec& DS,
1011 Tok.
setKind(tok::annot_decltype);
1012 setExprAnnotation(Tok,
1021 void Parser::ParseUnderlyingTypeSpecifier(
DeclSpec &DS) {
1022 assert(Tok.
is(tok::kw___underlying_type) &&
1023 "Not an underlying type specifier");
1027 if (T.expectAndConsume(diag::err_expected_lparen_after,
1028 "__underlying_type", tok::r_paren)) {
1040 if (T.getCloseLocation().isInvalid())
1043 const char *PrevSpec =
nullptr;
1046 DiagID, Result.
get(),
1048 Diag(StartLoc, DiagID) << PrevSpec;
1073 if (Tok.
is(tok::kw_typename)) {
1074 Diag(Tok, diag::err_expected_class_name_not_template)
1081 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
false);
1088 if (Tok.
isOneOf(tok::kw_decltype, tok::annot_decltype)) {
1095 EndLocation = ParseDecltypeSpecifier(DS);
1102 if (Tok.
is(tok::annot_template_id)) {
1106 AnnotateTemplateIdTokenAsType(
true);
1108 assert(Tok.
is(tok::annot_typename) &&
"template-id -> type failed");
1111 ConsumeAnnotationToken();
1121 if (Tok.
isNot(tok::identifier)) {
1122 Diag(Tok, diag::err_expected_class_name);
1129 if (Tok.
is(tok::less)) {
1135 &SS, Template, TNK)) {
1136 Diag(IdLoc, diag::err_unknown_template_name)
1141 TemplateArgList TemplateArgs;
1143 ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs,
1157 AnnotateTemplateIdTokenAsType(
true);
1161 if (Tok.
isNot(tok::annot_typename))
1168 ConsumeAnnotationToken();
1175 *Id, IdLoc,
getCurScope(), &SS,
true,
false,
nullptr,
1178 false, &CorrectedII);
1180 Diag(IdLoc, diag::err_expected_class_name);
1185 EndLocation = IdLoc;
1193 const char *PrevSpec =
nullptr;
1202 void Parser::ParseMicrosoftInheritanceClassAttributes(
ParsedAttributes &attrs) {
1203 while (Tok.
isOneOf(tok::kw___single_inheritance,
1204 tok::kw___multiple_inheritance,
1205 tok::kw___virtual_inheritance)) {
1208 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1216 bool Parser::isValidAfterTypeSpecifier(
bool CouldBeBitfield) {
1224 case tok::identifier:
1226 case tok::annot_cxxscope:
1227 case tok::annot_typename:
1228 case tok::annot_template_id:
1231 case tok::kw_operator:
1232 case tok::kw___declspec:
1237 case tok::kw___attribute:
1238 case tok::annot_pragma_pack:
1240 case tok::annot_pragma_ms_pragma:
1242 case tok::annot_pragma_ms_vtordisp:
1244 case tok::annot_pragma_ms_pointers_to_members:
1247 return CouldBeBitfield;
1249 case tok::kw___cdecl:
1250 case tok::kw___fastcall:
1251 case tok::kw___stdcall:
1252 case tok::kw___thiscall:
1253 case tok::kw___vectorcall:
1259 case tok::kw_volatile:
1260 case tok::kw_restrict:
1261 case tok::kw__Atomic:
1262 case tok::kw___unaligned:
1266 case tok::kw_inline:
1267 case tok::kw_virtual:
1268 case tok::kw_friend:
1270 case tok::kw_static:
1271 case tok::kw_extern:
1272 case tok::kw_typedef:
1273 case tok::kw_register:
1275 case tok::kw_mutable:
1276 case tok::kw_thread_local:
1277 case tok::kw_constexpr:
1293 if (!isKnownToBeTypeSpecifier(
NextToken()))
1350 const ParsedTemplateInfo &TemplateInfo,
1352 bool EnteringContext, DeclSpecContext DSC,
1353 ParsedAttributesWithRange &Attributes) {
1355 if (TagTokKind == tok::kw_struct)
1357 else if (TagTokKind == tok::kw___interface)
1359 else if (TagTokKind == tok::kw_class)
1362 assert(TagTokKind == tok::kw_union &&
"Not a class specifier");
1366 if (Tok.
is(tok::code_completion)) {
1369 return cutOffParsing();
1382 bool shouldDelayDiagsInTag =
1383 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
1384 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
1387 ParsedAttributesWithRange attrs(AttrFactory);
1389 MaybeParseGNUAttributes(attrs);
1390 MaybeParseMicrosoftDeclSpecs(attrs);
1393 if (Tok.
isOneOf(tok::kw___single_inheritance,
1394 tok::kw___multiple_inheritance,
1395 tok::kw___virtual_inheritance))
1396 ParseMicrosoftInheritanceClassAttributes(attrs);
1401 MaybeParseCXX11Attributes(attrs);
1408 Tok.
isNot(tok::identifier) &&
1411 Tok.
isOneOf(tok::kw___is_abstract,
1412 tok::kw___is_aggregate,
1413 tok::kw___is_arithmetic,
1415 tok::kw___is_assignable,
1416 tok::kw___is_base_of,
1418 tok::kw___is_complete_type,
1419 tok::kw___is_compound,
1421 tok::kw___is_constructible,
1422 tok::kw___is_convertible,
1423 tok::kw___is_convertible_to,
1424 tok::kw___is_destructible,
1427 tok::kw___is_floating_point,
1429 tok::kw___is_function,
1430 tok::kw___is_fundamental,
1431 tok::kw___is_integral,
1432 tok::kw___is_interface_class,
1433 tok::kw___is_literal,
1434 tok::kw___is_lvalue_expr,
1435 tok::kw___is_lvalue_reference,
1436 tok::kw___is_member_function_pointer,
1437 tok::kw___is_member_object_pointer,
1438 tok::kw___is_member_pointer,
1439 tok::kw___is_nothrow_assignable,
1440 tok::kw___is_nothrow_constructible,
1441 tok::kw___is_nothrow_destructible,
1442 tok::kw___is_object,
1444 tok::kw___is_pointer,
1445 tok::kw___is_polymorphic,
1446 tok::kw___is_reference,
1447 tok::kw___is_rvalue_expr,
1448 tok::kw___is_rvalue_reference,
1450 tok::kw___is_scalar,
1451 tok::kw___is_sealed,
1452 tok::kw___is_signed,
1453 tok::kw___is_standard_layout,
1454 tok::kw___is_trivial,
1455 tok::kw___is_trivially_assignable,
1456 tok::kw___is_trivially_constructible,
1457 tok::kw___is_trivially_copyable,
1459 tok::kw___is_unsigned,
1461 tok::kw___is_volatile))
1467 TryKeywordIdentFallback(
true);
1469 struct PreserveAtomicIdentifierInfoRAII {
1470 PreserveAtomicIdentifierInfoRAII(
Token &Tok,
bool Enabled)
1471 : AtomicII(nullptr) {
1474 assert(Tok.
is(tok::kw__Atomic));
1479 ~PreserveAtomicIdentifierInfoRAII() {
1482 AtomicII->revertIdentifierToTokenID(tok::kw__Atomic);
1492 bool ShouldChangeAtomicToIdentifier =
getLangOpts().MSVCCompat &&
1493 Tok.
is(tok::kw__Atomic) &&
1495 PreserveAtomicIdentifierInfoRAII AtomicTokenGuard(
1496 Tok, ShouldChangeAtomicToIdentifier);
1506 bool HasValidSpec =
true;
1507 if (ParseOptionalCXXScopeSpecifier(Spec,
nullptr, EnteringContext)) {
1509 HasValidSpec =
false;
1512 if (Tok.
isNot(tok::identifier) && Tok.
isNot(tok::annot_template_id)) {
1513 Diag(Tok, diag::err_expected) << tok::identifier;
1514 HasValidSpec =
false;
1526 if (Tok.
is(tok::identifier)) {
1534 TemplateArgList TemplateArgs;
1536 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs,
1543 Diag(NameLoc, diag::err_explicit_spec_non_template)
1544 << (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation)
1545 << TagTokKind << Name <<
SourceRange(LAngleLoc, RAngleLoc);
1549 if (TemplateParams && TemplateInfo.LastParameterListWasEmpty) {
1550 if (TemplateParams->size() > 1) {
1551 TemplateParams->pop_back();
1553 TemplateParams =
nullptr;
1554 const_cast<ParsedTemplateInfo&
>(TemplateInfo).
Kind 1555 = ParsedTemplateInfo::NonTemplate;
1557 }
else if (TemplateInfo.Kind
1558 == ParsedTemplateInfo::ExplicitInstantiation) {
1560 TemplateParams =
nullptr;
1561 const_cast<ParsedTemplateInfo&
>(TemplateInfo).
Kind 1562 = ParsedTemplateInfo::NonTemplate;
1563 const_cast<ParsedTemplateInfo&
>(TemplateInfo).TemplateLoc
1565 const_cast<ParsedTemplateInfo&
>(TemplateInfo).ExternLoc
1569 }
else if (Tok.
is(tok::annot_template_id)) {
1570 TemplateId = takeTemplateIdAnnotation(Tok);
1571 NameLoc = ConsumeAnnotationToken();
1583 Diag(TemplateId->
LAngleLoc, diag::err_template_spec_syntax_non_template)
1584 << TemplateId->
Name <<
static_cast<int>(TemplateId->
Kind) << Range;
1619 MaybeParseCXX11Attributes(Attributes);
1621 const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy();
1623 if (DSC == DeclSpecContext::DSC_trailing)
1625 else if (Tok.
is(tok::l_brace) ||
1627 (isCXX11FinalKeyword() &&
1643 }
else if (isCXX11FinalKeyword() && (
NextToken().is(tok::l_square) ||
1647 TentativeParsingAction PA(*
this);
1654 if (Tok.
is(tok::l_square) &&
NextToken().
is(tok::l_square)) {
1658 }
else if (Tok.
is(tok::kw_alignas) &&
NextToken().
is(tok::l_paren)) {
1668 if (Tok.
isOneOf(tok::l_brace, tok::colon))
1674 }
else if (!isTypeSpecifier(DSC) &&
1675 (Tok.
is(tok::semi) ||
1678 if (Tok.
isNot(tok::semi)) {
1679 const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy();
1681 ExpectAndConsume(tok::semi, diag::err_expected_after,
1699 Diag(AttrRange.
getBegin(), diag::err_attributes_not_allowed)
1713 if (shouldDelayDiagsInTag) {
1714 diagsFromTag.done();
1716 diagsFromTag.redelay();
1723 Diag(StartLoc, diag::err_anon_type_definition)
1748 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation &&
1751 ProhibitAttributes(attrs);
1753 TagOrTempResult = Actions.ActOnExplicitInstantiation(
1754 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc,
1755 TagType, StartLoc, SS, TemplateId->
Template,
1765 TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate)) {
1766 ProhibitAttributes(attrs);
1767 TypeResult = Actions.ActOnTagTemplateIdType(TUK, TagType, StartLoc,
1779 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
1792 "Expected a definition here");
1796 TemplateParams =
nullptr;
1799 PP.getLocForEndOfToken(TemplateInfo.TemplateLoc);
1801 diag::err_explicit_instantiation_with_definition)
1808 FakedParamLists.push_back(Actions.ActOnTemplateParameterList(
1810 LAngleLoc,
nullptr));
1811 TemplateParams = &FakedParamLists;
1816 TagOrTempResult = Actions.ActOnClassTemplateSpecialization(
1821 TemplateParams ? TemplateParams->size() : 0),
1824 }
else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation &&
1831 ProhibitAttributes(attrs);
1833 TagOrTempResult = Actions.ActOnExplicitInstantiation(
1834 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc,
1835 TagType, StartLoc, SS, Name, NameLoc, attrs);
1837 TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) {
1838 ProhibitAttributes(attrs);
1840 TagOrTempResult = Actions.ActOnTemplatedFriendTag(
1844 TemplateParams ? TemplateParams->size() : 0));
1847 ProhibitAttributes(attrs);
1850 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
1853 Diag(Tok, diag::err_template_defn_explicit_instantiation)
1855 TemplateParams =
nullptr;
1858 bool IsDependent =
false;
1868 stripTypeAttributesOffDeclSpec(attrs, DS, TUK);
1871 TagOrTempResult = Actions.ActOnTag(
1872 getCurScope(), TagType, TUK, StartLoc, SS, Name, NameLoc, attrs, AS,
1875 DSC == DeclSpecContext::DSC_type_specifier,
1876 DSC == DeclSpecContext::DSC_template_param ||
1877 DSC == DeclSpecContext::DSC_template_type_arg,
1884 TypeResult = Actions.ActOnDependentTag(
getCurScope(), TagType, TUK,
1885 SS, Name, StartLoc, NameLoc);
1891 assert(Tok.
is(tok::l_brace) ||
1893 isCXX11FinalKeyword());
1895 SkipCXXMemberSpecification(StartLoc, AttrFixitLoc, TagType,
1896 TagOrTempResult.
get());
1898 ParseCXXMemberSpecification(StartLoc, AttrFixitLoc, attrs, TagType,
1899 TagOrTempResult.
get());
1904 ParseStructUnionBody(StartLoc, TagType, D);
1906 !Actions.ActOnDuplicateDefinition(DS, TagOrTempResult.
get(),
1916 Actions.ProcessDeclAttributeDelayed(TagOrTempResult.
get(), attrs);
1918 const char *PrevSpec =
nullptr;
1923 NameLoc.isValid() ? NameLoc : StartLoc,
1924 PrevSpec, DiagID, TypeResult.
get(), Policy);
1925 }
else if (!TagOrTempResult.
isInvalid()) {
1927 NameLoc.isValid() ? NameLoc : StartLoc,
1928 PrevSpec, DiagID, TagOrTempResult.
get(), Owned,
1936 Diag(StartLoc, DiagID) << PrevSpec;
1952 (TemplateInfo.Kind || !isValidAfterTypeSpecifier(
false))) {
1953 if (Tok.
isNot(tok::semi)) {
1954 const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy();
1955 ExpectAndConsume(tok::semi, diag::err_expected_after,
1973 void Parser::ParseBaseClause(
Decl *ClassDecl) {
1974 assert(Tok.
is(tok::colon) &&
"Not a base clause");
1982 BaseResult Result = ParseBaseSpecifier(ClassDecl);
1989 BaseInfo.push_back(Result.
get());
1999 Actions.ActOnBaseSpecifiers(ClassDecl, BaseInfo);
2014 bool IsVirtual =
false;
2017 ParsedAttributesWithRange Attributes(AttrFactory);
2018 MaybeParseCXX11Attributes(Attributes);
2024 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2031 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2035 if (Tok.
is(tok::kw_virtual)) {
2039 Diag(VirtualLoc, diag::err_dup_virtual)
2046 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2060 TypeResult BaseType = ParseBaseTypeSpecifier(BaseLoc, EndLocation);
2075 return Actions.ActOnBaseSpecifier(ClassDecl, Range, Attributes, IsVirtual,
2076 Access, BaseType.
get(), BaseLoc,
2100 void Parser::HandleMemberFunctionDeclDelays(
Declarator& DeclaratorInfo,
2108 if (!NeedLateParse) {
2112 if (Param->hasUnparsedDefaultArg()) {
2113 NeedLateParse =
true;
2119 if (NeedLateParse) {
2122 auto LateMethod =
new LateParsedMethodDeclaration(
this, ThisDecl);
2123 getCurrentClass().LateParsedDeclarations.push_back(LateMethod);
2132 LateMethod->DefaultArgs.reserve(FTI.
NumParams);
2134 LateMethod->DefaultArgs.push_back(LateParsedDefaultArgument(
2155 Ident_final = &PP.getIdentifierTable().get(
"final");
2157 Ident_GNU_final = &PP.getIdentifierTable().get(
"__final");
2159 Ident_sealed = &PP.getIdentifierTable().get(
"sealed");
2160 Ident_override = &PP.getIdentifierTable().get(
"override");
2163 if (II == Ident_override)
2166 if (II == Ident_sealed)
2169 if (II == Ident_final)
2172 if (II == Ident_GNU_final)
2183 void Parser::ParseOptionalCXX11VirtSpecifierSeq(
VirtSpecifiers &VS,
2202 const char *PrevSpec =
nullptr;
2219 ? diag::warn_cxx98_compat_override_control_keyword
2220 : diag::ext_override_control_keyword)
2229 bool Parser::isCXX11FinalKeyword()
const {
2238 bool Parser::ParseCXXMemberDeclaratorBeforeInitializer(
2240 LateParsedAttrList &LateParsedAttrs) {
2245 if (Tok.
isNot(tok::colon))
2246 ParseDeclarator(DeclaratorInfo);
2252 "don't know where identifier would go yet?");
2254 if (BitfieldSize.isInvalid())
2257 ParseOptionalCXX11VirtSpecifierSeq(
2258 VS, getCurrentClass().IsInterface,
2261 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo, VS);
2265 if (Tok.
is(tok::kw_asm)) {
2267 ExprResult AsmLabel(ParseSimpleAsm(&Loc));
2268 if (AsmLabel.isInvalid())
2276 MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs);
2280 if (BitfieldSize.isUnset() && VS.
isUnset()) {
2281 ParseOptionalCXX11VirtSpecifierSeq(
2282 VS, getCurrentClass().IsInterface,
2288 if (AL.isKnownToGCC() && !AL.isCXX11Attribute())
2289 Diag(AL.getLoc(), diag::warn_gcc_attribute_location);
2291 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo, VS);
2297 if (!DeclaratorInfo.
hasName() && BitfieldSize.isUnset()) {
2307 void Parser::MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(
2314 ParseTypeQualifierListOpt(
2315 DS, AR_NoAttributesParsed,
false,
2316 false, llvm::function_ref<
void()>([&]() {
2317 Actions.CodeCompleteFunctionQualifiers(DS, D, &VS);
2325 const char *FixItName,
2327 unsigned* QualifierLoc) {
2330 if (!(
Function.TypeQuals & TypeQual)) {
2331 std::string Name(FixItName);
2335 *QualifierLoc = SpecLoc.getRawEncoding();
2337 Diag(SpecLoc, diag::err_declspec_after_virtspec)
2353 bool RefQualifierIsLValueRef =
true;
2355 if (ParseRefQualifier(RefQualifierIsLValueRef, RefQualifierLoc)) {
2356 const char *Name = (RefQualifierIsLValueRef ?
"& " :
"&& ");
2358 Function.RefQualifierIsLValueRef = RefQualifierIsLValueRef;
2361 Diag(RefQualifierLoc, diag::err_declspec_after_virtspec)
2362 << (RefQualifierIsLValueRef ?
"&" :
"&&")
2410 const ParsedTemplateInfo &TemplateInfo,
2412 if (Tok.
is(tok::at)) {
2414 Diag(Tok, diag::err_at_defs_cxx);
2416 Diag(Tok, diag::err_at_in_class);
2432 bool MalformedTypeSpec =
false;
2433 if (!TemplateInfo.Kind &&
2434 Tok.
isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) {
2436 MalformedTypeSpec =
true;
2439 if (Tok.
isNot(tok::annot_cxxscope))
2440 isAccessDecl =
false;
2442 isAccessDecl = GetLookAheadToken(2).is(tok::semi);
2449 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
2461 &TemplateKWLoc, Name)) {
2467 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
2468 "access declaration")) {
2484 if (!TemplateInfo.Kind &&
2485 Tok.
isOneOf(tok::kw_static_assert, tok::kw__Static_assert)) {
2491 if (Tok.
is(tok::kw_template)) {
2492 assert(!TemplateInfo.TemplateParams &&
2493 "Nested template improperly parsed?");
2502 if (Tok.
is(tok::kw___extension__)) {
2506 return ParseCXXClassMemberDeclaration(AS, AccessAttrs,
2507 TemplateInfo, TemplateDiags);
2510 ParsedAttributesWithRange attrs(AttrFactory);
2511 ParsedAttributesViewWithRange FnAttrs;
2513 MaybeParseCXX11Attributes(attrs);
2516 FnAttrs.addAll(attrs.begin(), attrs.end());
2517 FnAttrs.Range = attrs.Range;
2519 MaybeParseMicrosoftAttributes(attrs);
2521 if (Tok.
is(tok::kw_using)) {
2522 ProhibitAttributes(attrs);
2527 if (Tok.
is(tok::kw_namespace)) {
2528 Diag(UsingLoc, diag::err_using_namespace_in_class);
2535 UsingLoc, DeclEnd, AS);
2539 LateParsedAttrList CommonLateParsedAttrs;
2545 if (MalformedTypeSpec)
2548 ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DeclSpecContext::DSC_class,
2549 &CommonLateParsedAttrs);
2557 TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate &&
2558 DiagnoseMissingSemiAfterTagDefinition(DS, AS, DeclSpecContext::DSC_class,
2559 &CommonLateParsedAttrs))
2563 TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->data()
2565 TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->size() : 0);
2569 ProhibitAttributes(FnAttrs);
2572 Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(
2573 getCurScope(), AS, DS, TemplateParams,
false, AnonRecord);
2574 DS.complete(TheDecl);
2576 Decl* decls[] = {AnonRecord, TheDecl};
2577 return Actions.BuildDeclaratorGroup(decls);
2579 return Actions.ConvertDeclToDeclGroup(TheDecl);
2586 LateParsedAttrList LateParsedAttrs;
2591 auto TryConsumePureSpecifier = [&] (
bool AllowDefinition) {
2592 if (Tok.
isNot(tok::equal))
2597 if (Zero.isNot(tok::numeric_constant) || Zero.getLength() != 1 ||
2598 PP.getSpelling(Zero, Buffer) !=
"0")
2601 auto &
After = GetLookAheadToken(2);
2602 if (!
After.isOneOf(tok::semi, tok::comma) &&
2603 !(AllowDefinition &&
2604 After.isOneOf(tok::l_brace, tok::colon, tok::kw_try)))
2613 ExprResult BitfieldSize;
2614 bool ExpectSemi =
true;
2617 if (ParseCXXMemberDeclaratorBeforeInitializer(
2618 DeclaratorInfo, VS, BitfieldSize, LateParsedAttrs)) {
2628 TryConsumePureSpecifier(
true);
2639 if (Tok.
isOneOf(tok::l_brace, tok::colon, tok::kw_try)) {
2641 }
else if (Tok.
is(tok::equal)) {
2643 if (KW.
is(tok::kw_default))
2645 else if (KW.
is(tok::kw_delete))
2657 ProhibitAttributes(FnAttrs);
2674 diag::err_function_declared_typedef);
2681 ParseCXXInlineMethodDef(AS, AccessAttrs, DeclaratorInfo, TemplateInfo,
2685 for (
unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i) {
2686 CommonLateParsedAttrs[i]->addDecl(FunDecl);
2688 for (
unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i) {
2689 LateParsedAttrs[i]->addDecl(FunDecl);
2692 LateParsedAttrs.clear();
2695 if (Tok.
is(tok::semi))
2696 ConsumeExtraSemi(AfterMemberFunctionDefinition);
2708 bool HasStaticInitializer =
false;
2712 if (!TryConsumePureSpecifier(
false))
2714 HasStaticInitializer =
true;
2721 if (BitfieldSize.
get())
2723 ? diag::warn_cxx17_compat_bitfield_member_init
2724 : diag::ext_bitfield_member_init);
2727 HasStaticInitializer =
true;
2745 E = Ranges.end(); I != E; ++I)
2746 Diag((*I).getBegin(), diag::err_attributes_not_allowed) << *I;
2748 ThisDecl = Actions.ActOnFriendFunctionDecl(
getCurScope(), DeclaratorInfo,
2751 ThisDecl = Actions.ActOnCXXMemberDeclarator(
getCurScope(), AS,
2755 VS, HasInClassInit);
2758 ThisDecl ? dyn_cast<VarTemplateDecl>(ThisDecl) :
nullptr)
2761 ThisDecl = VT->getTemplatedDecl();
2764 Actions.ProcessDeclAttributeList(
getCurScope(), ThisDecl, AccessAttrs);
2773 HasStaticInitializer =
true;
2776 if (ThisDecl && PureSpecLoc.
isValid())
2777 Actions.ActOnPureSpecifier(ThisDecl, PureSpecLoc);
2783 ? diag::warn_cxx98_compat_nonstatic_member_init
2784 : diag::ext_nonstatic_member_init);
2792 Diag(Tok, diag::err_incomplete_array_member_init);
2799 ParseCXXNonStaticMemberInitializer(ThisDecl);
2800 }
else if (HasStaticInitializer) {
2802 ExprResult Init = ParseCXXMemberInitializer(
2808 Actions.AddInitializerToDecl(ThisDecl, Init.
get(), EqualLoc.
isInvalid());
2811 Actions.ActOnUninitializedDecl(ThisDecl);
2816 for (
unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i)
2817 CommonLateParsedAttrs[i]->addDecl(ThisDecl);
2819 for (
unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i)
2820 LateParsedAttrs[i]->addDecl(ThisDecl);
2822 Actions.FinalizeDeclaration(ThisDecl);
2823 DeclsInGroup.push_back(ThisDecl);
2828 HandleMemberFunctionDeclDelays(DeclaratorInfo, ThisDecl);
2830 LateParsedAttrs.clear();
2832 DeclaratorInfo.complete(ThisDecl);
2845 Diag(CommaLoc, diag::err_expected_semi_declaration)
2852 DeclaratorInfo.
clear();
2859 MaybeParseGNUAttributes(DeclaratorInfo);
2861 if (ParseCXXMemberDeclaratorBeforeInitializer(
2862 DeclaratorInfo, VS, BitfieldSize, LateParsedAttrs))
2867 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list)) {
2875 return Actions.FinalizeDeclaratorGroup(
getCurScope(), DS, DeclsInGroup);
2898 ExprResult Parser::ParseCXXMemberInitializer(
Decl *D,
bool IsFunction,
2900 assert(Tok.
isOneOf(tok::equal, tok::l_brace)
2901 &&
"Data member initializer not starting with '=' or '{'");
2906 if (Tok.
is(tok::kw_delete)) {
2921 }
else if (Tok.
is(tok::kw_default)) {
2923 Diag(Tok, diag::err_default_delete_in_multiple_declaration)
2930 if (
const auto *PD = dyn_cast_or_null<MSPropertyDecl>(D)) {
2931 Diag(Tok, diag::err_ms_property_initializer) << PD;
2934 return ParseInitializer();
2937 void Parser::SkipCXXMemberSpecification(
SourceLocation RecordLoc,
2942 assert(isCXX11FinalKeyword() &&
"not a class definition");
2947 ParsedAttributesWithRange Attrs(AttrFactory);
2948 CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc);
2953 if (Tok.
isNot(tok::colon) && Tok.
isNot(tok::l_brace))
2960 if (Tok.
is(tok::colon)) {
2963 ParsingClassDefinition ParsingDef(*
this, TagDecl,
true,
2966 Actions.ActOnTagStartSkippedDefinition(
getCurScope(), TagDecl);
2969 ParseBaseClause(
nullptr);
2971 Actions.ActOnTagFinishSkippedDefinition(OldContext);
2973 if (!Tok.
is(tok::l_brace)) {
2974 Diag(PP.getLocForEndOfToken(PrevTokLocation),
2975 diag::err_expected_lbrace_after_base_specifiers);
2981 assert(Tok.
is(tok::l_brace));
2988 if (Tok.
is(tok::kw___attribute))
2989 MaybeParseGNUAttributes(Attrs);
2998 case tok::kw___if_exists:
2999 case tok::kw___if_not_exists:
3000 ParseMicrosoftIfExistsClassDeclaration(TagType, AccessAttrs, AS);
3005 ConsumeExtraSemi(InsideStruct, TagType);
3009 case tok::annot_pragma_vis:
3010 HandlePragmaVisibility();
3012 case tok::annot_pragma_pack:
3015 case tok::annot_pragma_align:
3016 HandlePragmaAlign();
3018 case tok::annot_pragma_ms_pointers_to_members:
3019 HandlePragmaMSPointersToMembers();
3021 case tok::annot_pragma_ms_pragma:
3022 HandlePragmaMSPragma();
3024 case tok::annot_pragma_ms_vtordisp:
3025 HandlePragmaMSVtorDisp();
3027 case tok::annot_pragma_dump:
3031 case tok::kw_namespace:
3033 DiagnoseUnexpectedNamespace(cast<NamedDecl>(TagDecl));
3036 case tok::kw_public:
3037 case tok::kw_protected:
3038 case tok::kw_private: {
3046 AccessAttrs.clear();
3047 MaybeParseGNUAttributes(AccessAttrs);
3052 Diag(EndLoc, diag::err_expected)
3056 Diag(EndLoc, diag::err_expected)
3066 if (Actions.ActOnAccessSpecifier(NewAS, ASLoc, EndLoc, AccessAttrs)) {
3068 AccessAttrs.clear();
3074 case tok::annot_pragma_openmp:
3075 return ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, AccessAttrs, TagType,
3079 return ParseCXXClassMemberDeclaration(AS, AccessAttrs);
3089 void Parser::ParseCXXMemberSpecification(
SourceLocation RecordLoc,
3091 ParsedAttributesWithRange &Attrs,
3092 unsigned TagType,
Decl *TagDecl) {
3099 "parsing struct/union/class body");
3103 bool NonNestedClass =
true;
3104 if (!ClassStack.empty()) {
3106 if (S->isClassScope()) {
3108 NonNestedClass =
false;
3111 if (getCurrentClass().IsInterface) {
3112 Diag(RecordLoc, diag::err_invalid_member_in_interface)
3114 << (isa<NamedDecl>(TagDecl)
3115 ? cast<NamedDecl>(TagDecl)->getQualifiedNameAsString()
3132 ParsingClassDefinition ParsingDef(*
this, TagDecl, NonNestedClass,
3136 Actions.ActOnTagStartDefinition(
getCurScope(), TagDecl);
3139 bool IsFinalSpelledSealed =
false;
3147 "not a class definition");
3152 Diag(FinalLoc, diag::err_override_control_interface)
3156 ? diag::warn_cxx98_compat_override_control_keyword
3157 : diag::ext_override_control_keyword)
3160 Diag(FinalLoc, diag::ext_ms_sealed_keyword);
3162 Diag(FinalLoc, diag::ext_warn_gnu_final);
3168 CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc);
3177 if (!Tok.
is(tok::colon) && !Tok.
is(tok::l_brace)) {
3179 Actions.ActOnTagDefinitionError(
getCurScope(), TagDecl);
3184 if (Tok.
is(tok::colon)) {
3185 ParseScope InheritanceScope(
this,
getCurScope()->getFlags() |
3188 ParseBaseClause(TagDecl);
3189 if (!Tok.
is(tok::l_brace)) {
3190 bool SuggestFixIt =
false;
3191 SourceLocation BraceLoc = PP.getLocForEndOfToken(PrevTokLocation);
3194 case tok::kw_private:
3195 case tok::kw_protected:
3196 case tok::kw_public:
3199 case tok::kw_static_assert:
3203 case tok::kw_template:
3204 SuggestFixIt =
true;
3206 case tok::identifier:
3207 SuggestFixIt = isConstructorDeclarator(
true);
3210 SuggestFixIt = isCXXSimpleDeclaration(
false);
3215 Diag(BraceLoc, diag::err_expected_lbrace_after_base_specifiers);
3223 Actions.ActOnTagDefinitionError(
getCurScope(), TagDecl);
3229 assert(Tok.
is(tok::l_brace));
3234 Actions.ActOnStartCXXMemberDeclarations(
getCurScope(), TagDecl, FinalLoc,
3235 IsFinalSpelledSealed,
3236 T.getOpenLocation());
3246 ParsedAttributesWithRange AccessAttrs(AttrFactory);
3250 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
3253 ParseCXXClassMemberDeclarationWithPragmas(
3254 CurAS, AccessAttrs, static_cast<DeclSpec::TST>(TagType), TagDecl);
3263 MaybeParseGNUAttributes(attrs);
3266 Actions.ActOnFinishCXXMemberSpecification(
getCurScope(), RecordLoc, TagDecl,
3267 T.getOpenLocation(),
3268 T.getCloseLocation(), attrs);
3275 if (TagDecl && NonNestedClass) {
3281 ParseLexedAttributes(getCurrentClass());
3282 ParseLexedMethodDeclarations(getCurrentClass());
3285 Actions.ActOnFinishCXXMemberDecls();
3287 ParseLexedMemberInitializers(getCurrentClass());
3288 ParseLexedMethodDefs(getCurrentClass());
3289 PrevTokLocation = SavedPrevTokLocation;
3293 Actions.ActOnFinishCXXNonNestedClass(TagDecl);
3297 Actions.ActOnTagFinishDefinition(
getCurScope(), TagDecl, T.getRange());
3304 void Parser::DiagnoseUnexpectedNamespace(
NamedDecl *D) {
3305 assert(Tok.
is(tok::kw_namespace));
3310 diag::err_missing_end_of_definition) << D;
3312 diag::note_missing_end_of_definition_before) << D;
3318 Tok.
setLocation(PP.getLocForEndOfToken(PrevTokLocation));
3346 void Parser::ParseConstructorInitializer(
Decl *ConstructorDecl) {
3347 assert(Tok.
is(tok::colon) &&
3348 "Constructor initializer always starts with ':'");
3356 bool AnyErrors =
false;
3359 if (Tok.
is(tok::code_completion)) {
3360 Actions.CodeCompleteConstructorInitializer(ConstructorDecl,
3362 return cutOffParsing();
3365 MemInitResult MemInit = ParseMemInitializer(ConstructorDecl);
3367 MemInitializers.push_back(MemInit.
get());
3371 if (Tok.
is(tok::comma))
3373 else if (Tok.
is(tok::l_brace))
3378 Tok.
isOneOf(tok::identifier, tok::coloncolon)) {
3380 Diag(Loc, diag::err_ctor_init_missing_comma)
3392 Actions.ActOnMemInitializers(ConstructorDecl, ColonLoc, MemInitializers,
3411 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
false);
3421 if (Tok.
is(tok::identifier)) {
3426 }
else if (Tok.
is(tok::annot_decltype)) {
3431 ParseDecltypeSpecifier(DS);
3434 ? takeTemplateIdAnnotation(Tok)
3438 AnnotateTemplateIdTokenAsType(
true);
3439 assert(Tok.
is(tok::annot_typename) &&
"template-id -> type failed");
3441 ConsumeAnnotationToken();
3443 Diag(Tok, diag::err_expected_member_or_base_name);
3450 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
3452 ExprResult InitList = ParseBraceInitializer();
3459 return Actions.ActOnMemInitializer(ConstructorDecl,
getCurScope(), SS, II,
3460 TemplateTypeTy, DS, IdLoc,
3461 InitList.
get(), EllipsisLoc);
3462 }
else if(Tok.
is(tok::l_paren)) {
3467 ExprVector ArgExprs;
3468 CommaLocsTy CommaLocs;
3469 if (Tok.
isNot(tok::r_paren) && ParseExpressionList(ArgExprs, CommaLocs)) {
3479 return Actions.ActOnMemInitializer(ConstructorDecl,
getCurScope(), SS, II,
3480 TemplateTypeTy, DS, IdLoc,
3481 T.getOpenLocation(), ArgExprs,
3482 T.getCloseLocation(), EllipsisLoc);
3486 return Diag(Tok, diag::err_expected_either) << tok::l_paren << tok::l_brace;
3488 return Diag(Tok, diag::err_expected) << tok::l_paren;
3501 Parser::tryParseExceptionSpecification(
bool Delayed,
3505 ExprResult &NoexceptExpr,
3508 ExceptionSpecTokens =
nullptr;
3512 if (Tok.
isNot(tok::kw_throw) && Tok.
isNot(tok::kw_noexcept))
3516 bool IsNoexcept = Tok.
is(tok::kw_noexcept);
3517 Token StartTok = Tok;
3521 if (!Tok.
is(tok::l_paren)) {
3524 Diag(Tok, diag::warn_cxx98_compat_noexcept_decl);
3525 NoexceptExpr =
nullptr;
3529 Diag(Tok, diag::err_expected_lparen_after) <<
"throw";
3535 ExceptionSpecTokens->push_back(StartTok);
3536 ExceptionSpecTokens->push_back(Tok);
3537 SpecificationRange.
setEnd(ConsumeParen());
3539 ConsumeAndStoreUntil(tok::r_paren, *ExceptionSpecTokens,
3542 SpecificationRange.
setEnd(ExceptionSpecTokens->back().getLocation());
3548 if (Tok.
is(tok::kw_throw)) {
3549 Result = ParseDynamicExceptionSpecification(SpecificationRange,
3551 DynamicExceptionRanges);
3552 assert(DynamicExceptions.size() == DynamicExceptionRanges.size() &&
3553 "Produced different number of exception types and ranges.");
3557 if (Tok.
isNot(tok::kw_noexcept))
3560 Diag(Tok, diag::warn_cxx98_compat_noexcept_decl);
3568 if (Tok.
is(tok::l_paren)) {
3575 NoexceptExpr = Actions.ActOnNoexceptSpec(KeywordLoc, NoexceptExpr.
get(),
3577 NoexceptRange =
SourceRange(KeywordLoc, T.getCloseLocation());
3584 NoexceptRange =
SourceRange(KeywordLoc, KeywordLoc);
3588 SpecificationRange = NoexceptRange;
3589 Result = NoexceptType;
3593 if (Tok.
is(tok::kw_throw)) {
3594 Diag(Tok.
getLocation(), diag::err_dynamic_and_noexcept_specification);
3595 ParseDynamicExceptionSpecification(NoexceptRange, DynamicExceptions,
3596 DynamicExceptionRanges);
3599 Diag(Tok.
getLocation(), diag::err_dynamic_and_noexcept_specification);
3608 const char *
Replacement = IsNoexcept ?
"noexcept" :
"noexcept(false)";
3611 ? diag::ext_dynamic_exception_spec
3612 : diag::warn_exception_spec_deprecated)
3614 P.
Diag(Range.
getBegin(), diag::note_exception_spec_deprecated)
3634 assert(Tok.
is(tok::kw_throw) &&
"expected throw");
3639 Diag(Tok, diag::err_expected_lparen_after) <<
"throw";
3646 if (Tok.
is(tok::ellipsis)) {
3649 Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec);
3658 while (Tok.
isNot(tok::r_paren)) {
3661 if (Tok.
is(tok::ellipsis)) {
3668 Res = Actions.ActOnPackExpansion(Res.
get(), Ellipsis);
3672 Exceptions.push_back(Res.
get());
3673 Ranges.push_back(Range);
3683 Exceptions.empty());
3689 TypeResult Parser::ParseTrailingReturnType(
SourceRange &Range,
3690 bool MayBeFollowedByDirectInit) {
3691 assert(Tok.
is(tok::arrow) &&
"expected arrow");
3704 Parser::PushParsingClass(
Decl *ClassDecl,
bool NonNestedClass,
3706 assert((NonNestedClass || !ClassStack.empty()) &&
3707 "Nested class without outer class");
3708 ClassStack.push(
new ParsingClass(ClassDecl, NonNestedClass, IsInterface));
3709 return Actions.PushParsingClass();
3714 void Parser::DeallocateParsedClasses(Parser::ParsingClass *Class) {
3715 for (
unsigned I = 0, N = Class->LateParsedDeclarations.size(); I != N; ++I)
3716 delete Class->LateParsedDeclarations[I];
3727 assert(!ClassStack.empty() &&
"Mismatched push/pop for class parsing");
3729 Actions.PopParsingClass(state);
3731 ParsingClass *Victim = ClassStack.top();
3733 if (Victim->TopLevelClass) {
3736 DeallocateParsedClasses(Victim);
3739 assert(!ClassStack.empty() &&
"Missing top-level class?");
3741 if (Victim->LateParsedDeclarations.empty()) {
3746 DeallocateParsedClasses(Victim);
3753 assert(
getCurScope()->isClassScope() &&
"Nested class outside of class scope?");
3754 ClassStack.top()->LateParsedDeclarations.push_back(
new LateParsedClass(
this, Victim));
3786 case tok::pipeequal:
3787 case tok::caretequal:
3789 case tok::exclaimequal:
3794 PP.getSourceManager().getSpellingLoc(Tok.
getLocation());
3795 StringRef Spelling = PP.getSpelling(SpellingLoc, SpellingBuf);
3798 return &PP.getIdentifierTable().get(Spelling);
3807 case ParsedAttr::AT_CarriesDependency:
3808 case ParsedAttr::AT_Deprecated:
3809 case ParsedAttr::AT_FallThrough:
3810 case ParsedAttr::AT_CXX11NoReturn:
3812 case ParsedAttr::AT_WarnUnusedResult:
3813 return !ScopeName && AttrName->
getName().equals(
"nodiscard");
3814 case ParsedAttr::AT_Unused:
3815 return !ScopeName && AttrName->
getName().equals(
"maybe_unused");
3841 assert(Tok.
is(tok::l_paren) &&
"Not a C++11 attribute argument list");
3857 if (ScopeName && ScopeName->
getName() ==
"gnu") {
3860 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
3861 ScopeLoc, Syntax,
nullptr);
3867 if (ScopeName && ScopeName->
getName() ==
"clang")
3869 ParseClangAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
3873 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
3874 ScopeName, ScopeLoc, Syntax);
3876 if (!Attrs.
empty() &&
3886 Diag(LParenLoc, diag::err_attribute_requires_arguments) << AttrName;
3892 Diag(LParenLoc, diag::err_cxx11_attribute_forbids_arguments)
3927 if (Tok.
is(tok::kw_alignas)) {
3929 ParseAlignmentSpecifier(attrs, endLoc);
3933 assert(Tok.
is(tok::l_square) &&
NextToken().
is(tok::l_square) &&
3934 "Not a double square bracket attribute list");
3943 if (Tok.
is(tok::kw_using)) {
3945 ? diag::warn_cxx14_compat_using_attribute_ns
3946 : diag::ext_using_attribute_ns);
3949 CommonScopeName = TryParseCXX11AttributeIdentifier(CommonScopeLoc);
3950 if (!CommonScopeName) {
3958 llvm::SmallDenseMap<IdentifierInfo*, SourceLocation, 4> SeenAttrs;
3960 while (Tok.
isNot(tok::r_square)) {
3968 AttrName = TryParseCXX11AttributeIdentifier(AttrLoc);
3975 ScopeName = AttrName;
3978 AttrName = TryParseCXX11AttributeIdentifier(AttrLoc);
3986 if (CommonScopeName) {
3988 Diag(ScopeLoc, diag::err_using_attribute_ns_conflict)
3991 ScopeName = CommonScopeName;
3992 ScopeLoc = CommonScopeLoc;
3997 bool AttrParsed =
false;
4000 !SeenAttrs.insert(std::make_pair(AttrName, AttrLoc)).second)
4001 Diag(AttrLoc, diag::err_cxx11_attribute_repeated)
4005 if (Tok.
is(tok::l_paren))
4006 AttrParsed = ParseCXX11AttributeArgs(AttrName, AttrLoc, attrs, endLoc,
4007 ScopeName, ScopeLoc);
4012 SourceRange(ScopeLoc.
isValid() ? ScopeLoc : AttrLoc, AttrLoc),
4013 ScopeName, ScopeLoc,
nullptr, 0,
4017 Diag(Tok, diag::err_cxx11_attribute_forbids_ellipsis)
4021 if (ExpectAndConsume(tok::r_square))
4025 if (ExpectAndConsume(tok::r_square))
4033 void Parser::ParseCXX11Attributes(ParsedAttributesWithRange &attrs,
4035 assert(standardAttributesAllowed());
4042 ParseCXX11AttributeSpecifier(attrs, endLoc);
4043 }
while (isCXX11AttributeSpecifier());
4048 void Parser::DiagnoseAndSkipCXX11Attributes() {
4055 Diag(StartLoc, diag::err_attributes_not_allowed)
4063 if (!isCXX11AttributeSpecifier())
4067 if (Tok.
is(tok::l_square)) {
4073 assert(Tok.
is(tok::kw_alignas) &&
"not an attribute specifier");
4080 }
while (isCXX11AttributeSpecifier());
4087 assert(Tok.
is(tok::identifier) &&
"Not a Microsoft attribute list");
4089 assert(UuidIdent->getName() ==
"uuid" &&
"Not a Microsoft attribute list");
4097 Diag(Tok, diag::err_expected) << tok::l_paren;
4102 if (Tok.
is(tok::string_literal)) {
4104 ExprResult StringResult = ParseStringLiteralExpression();
4107 ArgExprs.push_back(StringResult.
get());
4124 while (Tok.
isNot(tok::r_paren)) {
4126 Diag(Tok, diag::err_attribute_uuid_malformed_guid);
4131 SpellingBuffer.resize(Tok.
getLength() + 1);
4132 bool Invalid =
false;
4133 StringRef TokSpelling = PP.getSpelling(Tok, SpellingBuffer, &Invalid);
4138 StrBuffer += TokSpelling;
4144 Diag(Tok, diag::err_attribute_uuid_malformed_guid);
4154 Toks[0].
setKind(tok::string_literal);
4159 cast<StringLiteral>(Actions.ActOnStringLiteral(Toks,
nullptr).get());
4160 ArgExprs.push_back(UuidString);
4180 assert(Tok.
is(tok::l_square) &&
"Not a Microsoft attribute list");
4190 if (Tok.
isNot(tok::identifier))
4193 ParseMicrosoftUuidAttributeArgs(attrs);
4201 }
while (Tok.
is(tok::l_square));
4204 void Parser::ParseMicrosoftIfExistsClassDeclaration(
4207 IfExistsCondition
Result;
4208 if (ParseMicrosoftIfExistsCondition(Result))
4213 Diag(Tok, diag::err_expected) << tok::l_brace;
4217 switch (Result.Behavior) {
4223 Diag(Result.KeywordLoc, diag::warn_microsoft_dependent_exists)
4224 << Result.IsIfExists;
4233 while (Tok.
isNot(tok::r_brace) && !isEofOrEom()) {
4235 if (Tok.
isOneOf(tok::kw___if_exists, tok::kw___if_not_exists)) {
4236 ParseMicrosoftIfExistsClassDeclaration((
DeclSpec::TST)TagType,
4237 AccessAttrs, CurAS);
4242 if (Tok.
is(tok::semi)) {
4243 ConsumeExtraSemi(InsideStruct, TagType);
4253 if (Tok.
is(tok::colon))
4254 Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.
getLocation(),
4257 Diag(Tok, diag::err_expected) << tok::colon;
4263 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...
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.
void EnterToken(const Token &Tok)
Enters a token in the token stream to be lexed next.
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.
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...
SourceLocation getConstSpecLoc() const
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...
Expr - 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.
SourceLocation getVolatileSpecLoc() const
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.
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 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
SourceLocation getRestrictSpecLoc() const
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.