27 #include "llvm/ADT/SmallString.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);
440 if (Tok.
is(tok::r_brace))
441 Diag(ExportLoc, diag::err_export_empty)
444 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
446 ParsedAttributesWithRange Attrs(AttrFactory);
447 MaybeParseCXX11Attributes(Attrs);
448 MaybeParseMicrosoftAttributes(Attrs);
449 ParseExternalDeclaration(Attrs);
454 T.getCloseLocation());
461 const ParsedTemplateInfo &TemplateInfo,
463 ParsedAttributesWithRange &attrs) {
464 assert(Tok.
is(tok::kw_using) &&
"Not using token");
470 if (Tok.
is(tok::code_completion)) {
477 if (Tok.
is(tok::kw_namespace)) {
479 if (TemplateInfo.Kind) {
481 Diag(UsingLoc, diag::err_templated_using_directive_declaration)
485 Decl *UsingDir = ParseUsingDirective(Context, UsingLoc, DeclEnd, attrs);
492 ProhibitAttributes(attrs);
494 return ParseUsingDeclaration(Context, TemplateInfo, UsingLoc, DeclEnd,
512 assert(Tok.
is(tok::kw_namespace) &&
"Not 'namespace' token");
517 if (Tok.
is(tok::code_completion)) {
525 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
false,
535 if (Tok.
isNot(tok::identifier)) {
536 Diag(Tok, diag::err_expected_namespace_name);
555 bool GNUAttr =
false;
556 if (Tok.
is(tok::kw___attribute)) {
558 ParseGNUAttributes(attrs);
563 if (ExpectAndConsume(tok::semi,
564 GNUAttr ? diag::err_expected_semi_after_attribute_list
565 : diag::err_expected_semi_after_namespace_name))
569 IdentLoc, NamespcName, attrs);
578 UsingDeclarator &D) {
585 if (Tok.
is(tok::kw___super)) {
592 ParseOptionalCXXScopeSpecifier(D.SS,
nullptr,
false,
596 if (D.SS.isInvalid())
611 Tok.
is(tok::identifier) &&
615 !D.SS.getScopeRep()->getAsNamespace() &&
616 !D.SS.getScopeRep()->getAsNamespaceAlias()) {
620 D.Name.setConstructorName(Type, IdLoc, IdLoc);
625 !(Tok.
is(tok::identifier) &&
628 nullptr,
nullptr, D.Name))
634 diag::warn_cxx17_compat_using_declaration_pack :
635 diag::ext_using_declaration_pack);
658 const ParsedTemplateInfo &TemplateInfo,
663 ParsedAttributesWithRange MisplacedAttrs(AttrFactory);
664 MaybeParseCXX11Attributes(MisplacedAttrs);
667 bool InvalidDeclarator = ParseUsingDeclarator(Context, D);
669 ParsedAttributesWithRange Attrs(AttrFactory);
670 MaybeParseGNUAttributes(Attrs);
671 MaybeParseCXX11Attributes(Attrs);
674 if (Tok.
is(tok::equal)) {
675 if (InvalidDeclarator) {
682 if (MisplacedAttrs.Range.isValid()) {
683 Diag(MisplacedAttrs.Range.getBegin(), diag::err_attributes_not_allowed)
688 Attrs.takeAllFrom(MisplacedAttrs);
691 Decl *DeclFromDeclSpec =
nullptr;
692 Decl *AD = ParseAliasDeclarationAfterDeclarator(
693 TemplateInfo, UsingLoc, D, DeclEnd, AS, Attrs, &DeclFromDeclSpec);
699 ProhibitAttributes(MisplacedAttrs);
700 ProhibitAttributes(Attrs);
705 if (TemplateInfo.Kind) {
707 Diag(UsingLoc, diag::err_templated_using_directive_declaration)
719 MaybeParseGNUAttributes(Attrs);
721 if (InvalidDeclarator)
726 if (D.TypenameLoc.isValid() &&
728 Diag(D.Name.getSourceRange().getBegin(),
729 diag::err_typename_identifiers_only)
736 D.TypenameLoc, D.SS, D.Name,
737 D.EllipsisLoc, Attrs);
739 DeclsInGroup.push_back(UD);
747 InvalidDeclarator = ParseUsingDeclarator(Context, D);
750 if (DeclsInGroup.size() > 1)
752 diag::warn_cxx17_compat_multi_using_declaration :
753 diag::ext_multi_using_declaration);
757 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
758 !Attrs.empty() ?
"attributes list" 759 :
"using declaration"))
765 Decl *Parser::ParseAliasDeclarationAfterDeclarator(
769 if (ExpectAndConsume(tok::equal)) {
775 diag::warn_cxx98_compat_alias_declaration :
776 diag::ext_alias_declaration);
780 if (TemplateInfo.Kind == ParsedTemplateInfo::Template &&
783 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization)
785 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation)
787 if (SpecKind != -1) {
791 D.Name.TemplateId->RAngleLoc);
793 Range = TemplateInfo.getSourceRange();
794 Diag(Range.
getBegin(), diag::err_alias_declaration_specialization)
795 << SpecKind << Range;
802 Diag(D.Name.StartLocation, diag::err_alias_declaration_not_identifier);
806 }
else if (D.TypenameLoc.isValid())
807 Diag(D.TypenameLoc, diag::err_alias_declaration_not_identifier)
810 D.SS.isNotEmpty() ? D.SS.getEndLoc() : D.TypenameLoc));
811 else if (D.SS.isNotEmpty())
812 Diag(D.SS.getBeginLoc(), diag::err_alias_declaration_not_identifier)
814 if (D.EllipsisLoc.isValid())
815 Diag(D.EllipsisLoc, diag::err_alias_declaration_pack_expansion)
818 Decl *DeclFromDeclSpec =
nullptr;
823 AS, &DeclFromDeclSpec, &Attrs);
825 *OwnedType = DeclFromDeclSpec;
829 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
830 !Attrs.
empty() ?
"attributes list" 831 :
"alias declaration"))
836 TemplateParams ? TemplateParams->data() :
nullptr,
837 TemplateParams ? TemplateParams->size() : 0);
839 UsingLoc, D.Name, Attrs, TypeAlias,
852 assert(Tok.
isOneOf(tok::kw_static_assert, tok::kw__Static_assert) &&
853 "Not a static_assert declaration");
856 Diag(Tok, diag::ext_c11_static_assert);
857 if (Tok.
is(tok::kw_static_assert))
858 Diag(Tok, diag::warn_cxx98_compat_static_assert);
863 if (T.consumeOpen()) {
864 Diag(Tok, diag::err_expected) << tok::l_paren;
872 if (AssertExpr.isInvalid()) {
878 if (Tok.
is(tok::r_paren)) {
880 ? diag::warn_cxx14_compat_static_assert_no_message
881 : diag::ext_static_assert_no_message)
884 :
FixItHint::CreateInsertion(Tok.getLocation(),
", \"\""));
886 if (ExpectAndConsume(tok::comma)) {
891 if (!isTokenStringLiteral()) {
892 Diag(Tok, diag::err_expected_string_literal)
898 AssertMessage = ParseStringLiteralExpression();
908 ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert);
913 T.getCloseLocation());
922 assert(Tok.
isOneOf(tok::kw_decltype, tok::annot_decltype)
923 &&
"Not a decltype specifier");
929 if (Tok.
is(tok::annot_decltype)) {
930 Result = getExprAnnotation(Tok);
932 ConsumeAnnotationToken();
933 if (Result.isInvalid()) {
939 Diag(Tok, diag::warn_cxx98_compat_decltype);
944 if (T.expectAndConsume(diag::err_expected_lparen_after,
945 "decltype", tok::r_paren)) {
948 StartLoc : T.getOpenLocation();
952 if (Tok.
is(tok::kw_auto)) {
958 ? diag::warn_cxx11_compat_decltype_auto_type_specifier
959 : diag::ext_decltype_auto_type_specifier);
973 if (Result.isInvalid()) {
976 EndLoc = ConsumeParen();
983 assert(Tok.
is(tok::semi));
996 if (T.getCloseLocation().isInvalid()) {
1000 return T.getCloseLocation();
1003 if (Result.isInvalid()) {
1005 return T.getCloseLocation();
1008 EndLoc = T.getCloseLocation();
1010 assert(!Result.isInvalid());
1012 const char *PrevSpec =
nullptr;
1018 DiagID, Result.get(), Policy)
1021 Diag(StartLoc, DiagID) << PrevSpec;
1027 void Parser::AnnotateExistingDecltypeSpecifier(
const DeclSpec& DS,
1036 Tok.
setKind(tok::annot_decltype);
1037 setExprAnnotation(Tok,
1046 void Parser::ParseUnderlyingTypeSpecifier(
DeclSpec &DS) {
1047 assert(Tok.
is(tok::kw___underlying_type) &&
1048 "Not an underlying type specifier");
1052 if (T.expectAndConsume(diag::err_expected_lparen_after,
1053 "__underlying_type", tok::r_paren)) {
1065 if (T.getCloseLocation().isInvalid())
1068 const char *PrevSpec =
nullptr;
1071 DiagID, Result.
get(),
1073 Diag(StartLoc, DiagID) << PrevSpec;
1098 if (Tok.
is(tok::kw_typename)) {
1099 Diag(Tok, diag::err_expected_class_name_not_template)
1106 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
false);
1113 if (Tok.
isOneOf(tok::kw_decltype, tok::annot_decltype)) {
1120 EndLocation = ParseDecltypeSpecifier(DS);
1127 if (Tok.
is(tok::annot_template_id)) {
1131 AnnotateTemplateIdTokenAsType(
true);
1133 assert(Tok.
is(tok::annot_typename) &&
"template-id -> type failed");
1136 ConsumeAnnotationToken();
1146 if (Tok.
isNot(tok::identifier)) {
1147 Diag(Tok, diag::err_expected_class_name);
1154 if (Tok.
is(tok::less)) {
1160 &SS, Template, TNK)) {
1161 Diag(IdLoc, diag::err_unknown_template_name)
1166 TemplateArgList TemplateArgs;
1168 ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs,
1182 AnnotateTemplateIdTokenAsType(
true);
1186 if (Tok.
isNot(tok::annot_typename))
1193 ConsumeAnnotationToken();
1200 *Id, IdLoc,
getCurScope(), &SS,
true,
false,
nullptr,
1203 false, &CorrectedII);
1205 Diag(IdLoc, diag::err_expected_class_name);
1210 EndLocation = IdLoc;
1218 const char *PrevSpec =
nullptr;
1227 void Parser::ParseMicrosoftInheritanceClassAttributes(
ParsedAttributes &attrs) {
1228 while (Tok.
isOneOf(tok::kw___single_inheritance,
1229 tok::kw___multiple_inheritance,
1230 tok::kw___virtual_inheritance)) {
1233 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1241 bool Parser::isValidAfterTypeSpecifier(
bool CouldBeBitfield) {
1249 case tok::identifier:
1251 case tok::annot_cxxscope:
1252 case tok::annot_typename:
1253 case tok::annot_template_id:
1256 case tok::kw_operator:
1257 case tok::kw___declspec:
1262 case tok::kw___attribute:
1263 case tok::annot_pragma_pack:
1265 case tok::annot_pragma_ms_pragma:
1267 case tok::annot_pragma_ms_vtordisp:
1269 case tok::annot_pragma_ms_pointers_to_members:
1272 return CouldBeBitfield;
1274 case tok::kw___cdecl:
1275 case tok::kw___fastcall:
1276 case tok::kw___stdcall:
1277 case tok::kw___thiscall:
1278 case tok::kw___vectorcall:
1284 case tok::kw_volatile:
1285 case tok::kw_restrict:
1286 case tok::kw__Atomic:
1287 case tok::kw___unaligned:
1291 case tok::kw_inline:
1292 case tok::kw_virtual:
1293 case tok::kw_friend:
1295 case tok::kw_static:
1296 case tok::kw_extern:
1297 case tok::kw_typedef:
1298 case tok::kw_register:
1300 case tok::kw_mutable:
1301 case tok::kw_thread_local:
1302 case tok::kw_constexpr:
1318 if (!isKnownToBeTypeSpecifier(
NextToken()))
1375 const ParsedTemplateInfo &TemplateInfo,
1377 bool EnteringContext, DeclSpecContext DSC,
1378 ParsedAttributesWithRange &Attributes) {
1380 if (TagTokKind == tok::kw_struct)
1382 else if (TagTokKind == tok::kw___interface)
1384 else if (TagTokKind == tok::kw_class)
1387 assert(TagTokKind == tok::kw_union &&
"Not a class specifier");
1391 if (Tok.
is(tok::code_completion)) {
1394 return cutOffParsing();
1407 bool shouldDelayDiagsInTag =
1408 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
1409 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
1412 ParsedAttributesWithRange attrs(AttrFactory);
1414 MaybeParseGNUAttributes(attrs);
1415 MaybeParseMicrosoftDeclSpecs(attrs);
1418 if (Tok.
isOneOf(tok::kw___single_inheritance,
1419 tok::kw___multiple_inheritance,
1420 tok::kw___virtual_inheritance))
1421 ParseMicrosoftInheritanceClassAttributes(attrs);
1426 MaybeParseCXX11Attributes(attrs);
1433 Tok.
isNot(tok::identifier) &&
1436 Tok.
isOneOf(tok::kw___is_abstract,
1437 tok::kw___is_aggregate,
1438 tok::kw___is_arithmetic,
1440 tok::kw___is_assignable,
1441 tok::kw___is_base_of,
1443 tok::kw___is_complete_type,
1444 tok::kw___is_compound,
1446 tok::kw___is_constructible,
1447 tok::kw___is_convertible,
1448 tok::kw___is_convertible_to,
1449 tok::kw___is_destructible,
1452 tok::kw___is_floating_point,
1454 tok::kw___is_function,
1455 tok::kw___is_fundamental,
1456 tok::kw___is_integral,
1457 tok::kw___is_interface_class,
1458 tok::kw___is_literal,
1459 tok::kw___is_lvalue_expr,
1460 tok::kw___is_lvalue_reference,
1461 tok::kw___is_member_function_pointer,
1462 tok::kw___is_member_object_pointer,
1463 tok::kw___is_member_pointer,
1464 tok::kw___is_nothrow_assignable,
1465 tok::kw___is_nothrow_constructible,
1466 tok::kw___is_nothrow_destructible,
1467 tok::kw___is_object,
1469 tok::kw___is_pointer,
1470 tok::kw___is_polymorphic,
1471 tok::kw___is_reference,
1472 tok::kw___is_rvalue_expr,
1473 tok::kw___is_rvalue_reference,
1475 tok::kw___is_scalar,
1476 tok::kw___is_sealed,
1477 tok::kw___is_signed,
1478 tok::kw___is_standard_layout,
1479 tok::kw___is_trivial,
1480 tok::kw___is_trivially_assignable,
1481 tok::kw___is_trivially_constructible,
1482 tok::kw___is_trivially_copyable,
1484 tok::kw___is_unsigned,
1486 tok::kw___is_volatile))
1492 TryKeywordIdentFallback(
true);
1494 struct PreserveAtomicIdentifierInfoRAII {
1495 PreserveAtomicIdentifierInfoRAII(
Token &Tok,
bool Enabled)
1496 : AtomicII(nullptr) {
1499 assert(Tok.
is(tok::kw__Atomic));
1504 ~PreserveAtomicIdentifierInfoRAII() {
1507 AtomicII->revertIdentifierToTokenID(tok::kw__Atomic);
1517 bool ShouldChangeAtomicToIdentifier =
getLangOpts().MSVCCompat &&
1518 Tok.
is(tok::kw__Atomic) &&
1520 PreserveAtomicIdentifierInfoRAII AtomicTokenGuard(
1521 Tok, ShouldChangeAtomicToIdentifier);
1531 bool HasValidSpec =
true;
1532 if (ParseOptionalCXXScopeSpecifier(Spec,
nullptr, EnteringContext)) {
1534 HasValidSpec =
false;
1537 if (Tok.
isNot(tok::identifier) && Tok.
isNot(tok::annot_template_id)) {
1538 Diag(Tok, diag::err_expected) << tok::identifier;
1539 HasValidSpec =
false;
1551 if (Tok.
is(tok::identifier)) {
1559 TemplateArgList TemplateArgs;
1561 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs,
1568 Diag(NameLoc, diag::err_explicit_spec_non_template)
1569 << (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation)
1570 << TagTokKind << Name <<
SourceRange(LAngleLoc, RAngleLoc);
1574 if (TemplateParams && TemplateInfo.LastParameterListWasEmpty) {
1575 if (TemplateParams->size() > 1) {
1576 TemplateParams->pop_back();
1578 TemplateParams =
nullptr;
1579 const_cast<ParsedTemplateInfo&
>(TemplateInfo).
Kind 1580 = ParsedTemplateInfo::NonTemplate;
1582 }
else if (TemplateInfo.Kind
1583 == 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
1594 }
else if (Tok.
is(tok::annot_template_id)) {
1595 TemplateId = takeTemplateIdAnnotation(Tok);
1596 NameLoc = ConsumeAnnotationToken();
1608 Diag(TemplateId->
LAngleLoc, diag::err_template_spec_syntax_non_template)
1609 << TemplateId->
Name <<
static_cast<int>(TemplateId->
Kind) << Range;
1644 MaybeParseCXX11Attributes(Attributes);
1646 const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy();
1648 if (DSC == DeclSpecContext::DSC_trailing)
1650 else if (Tok.
is(tok::l_brace) ||
1652 (isCXX11FinalKeyword() &&
1668 }
else if (isCXX11FinalKeyword() && (
NextToken().is(tok::l_square) ||
1672 TentativeParsingAction PA(*
this);
1679 if (Tok.
is(tok::l_square) &&
NextToken().
is(tok::l_square)) {
1683 }
else if (Tok.
is(tok::kw_alignas) &&
NextToken().
is(tok::l_paren)) {
1693 if (Tok.
isOneOf(tok::l_brace, tok::colon))
1699 }
else if (!isTypeSpecifier(DSC) &&
1700 (Tok.
is(tok::semi) ||
1703 if (Tok.
isNot(tok::semi)) {
1704 const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy();
1706 ExpectAndConsume(tok::semi, diag::err_expected_after,
1724 Diag(AttrRange.
getBegin(), diag::err_attributes_not_allowed)
1738 if (shouldDelayDiagsInTag) {
1739 diagsFromTag.done();
1741 diagsFromTag.redelay();
1748 Diag(StartLoc, diag::err_anon_type_definition)
1773 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation &&
1776 ProhibitAttributes(attrs);
1778 TagOrTempResult = Actions.ActOnExplicitInstantiation(
1779 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc,
1780 TagType, StartLoc, SS, TemplateId->
Template,
1790 TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate)) {
1791 ProhibitAttributes(attrs);
1792 TypeResult = Actions.ActOnTagTemplateIdType(TUK, TagType, StartLoc,
1804 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
1817 "Expected a definition here");
1821 TemplateParams =
nullptr;
1824 PP.getLocForEndOfToken(TemplateInfo.TemplateLoc);
1826 diag::err_explicit_instantiation_with_definition)
1833 FakedParamLists.push_back(Actions.ActOnTemplateParameterList(
1835 LAngleLoc,
nullptr));
1836 TemplateParams = &FakedParamLists;
1841 TagOrTempResult = Actions.ActOnClassTemplateSpecialization(
1846 TemplateParams ? TemplateParams->size() : 0),
1849 }
else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation &&
1856 ProhibitAttributes(attrs);
1858 TagOrTempResult = Actions.ActOnExplicitInstantiation(
1859 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc,
1860 TagType, StartLoc, SS, Name, NameLoc, attrs);
1862 TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) {
1863 ProhibitAttributes(attrs);
1865 TagOrTempResult = Actions.ActOnTemplatedFriendTag(
1869 TemplateParams ? TemplateParams->size() : 0));
1872 ProhibitAttributes(attrs);
1875 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
1878 Diag(Tok, diag::err_template_defn_explicit_instantiation)
1880 TemplateParams =
nullptr;
1883 bool IsDependent =
false;
1893 stripTypeAttributesOffDeclSpec(attrs, DS, TUK);
1896 TagOrTempResult = Actions.ActOnTag(
1897 getCurScope(), TagType, TUK, StartLoc, SS, Name, NameLoc, attrs, AS,
1900 DSC == DeclSpecContext::DSC_type_specifier,
1901 DSC == DeclSpecContext::DSC_template_param ||
1902 DSC == DeclSpecContext::DSC_template_type_arg,
1909 TypeResult = Actions.ActOnDependentTag(
getCurScope(), TagType, TUK,
1910 SS, Name, StartLoc, NameLoc);
1916 assert(Tok.
is(tok::l_brace) ||
1918 isCXX11FinalKeyword());
1920 SkipCXXMemberSpecification(StartLoc, AttrFixitLoc, TagType,
1921 TagOrTempResult.
get());
1923 ParseCXXMemberSpecification(StartLoc, AttrFixitLoc, attrs, TagType,
1924 TagOrTempResult.
get());
1929 ParseStructUnionBody(StartLoc, TagType, D);
1931 !Actions.ActOnDuplicateDefinition(DS, TagOrTempResult.
get(),
1941 Actions.ProcessDeclAttributeDelayed(TagOrTempResult.
get(), attrs);
1943 const char *PrevSpec =
nullptr;
1948 NameLoc.isValid() ? NameLoc : StartLoc,
1949 PrevSpec, DiagID, TypeResult.
get(), Policy);
1950 }
else if (!TagOrTempResult.
isInvalid()) {
1952 NameLoc.isValid() ? NameLoc : StartLoc,
1953 PrevSpec, DiagID, TagOrTempResult.
get(), Owned,
1961 Diag(StartLoc, DiagID) << PrevSpec;
1977 (TemplateInfo.Kind || !isValidAfterTypeSpecifier(
false))) {
1978 if (Tok.
isNot(tok::semi)) {
1979 const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy();
1980 ExpectAndConsume(tok::semi, diag::err_expected_after,
1998 void Parser::ParseBaseClause(
Decl *ClassDecl) {
1999 assert(Tok.
is(tok::colon) &&
"Not a base clause");
2007 BaseResult Result = ParseBaseSpecifier(ClassDecl);
2014 BaseInfo.push_back(Result.
get());
2024 Actions.ActOnBaseSpecifiers(ClassDecl, BaseInfo);
2039 bool IsVirtual =
false;
2042 ParsedAttributesWithRange Attributes(AttrFactory);
2043 MaybeParseCXX11Attributes(Attributes);
2049 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2056 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2060 if (Tok.
is(tok::kw_virtual)) {
2064 Diag(VirtualLoc, diag::err_dup_virtual)
2071 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2085 TypeResult BaseType = ParseBaseTypeSpecifier(BaseLoc, EndLocation);
2100 return Actions.ActOnBaseSpecifier(ClassDecl, Range, Attributes, IsVirtual,
2101 Access, BaseType.
get(), BaseLoc,
2125 void Parser::HandleMemberFunctionDeclDelays(
Declarator& DeclaratorInfo,
2133 if (!NeedLateParse) {
2137 if (Param->hasUnparsedDefaultArg()) {
2138 NeedLateParse =
true;
2144 if (NeedLateParse) {
2147 auto LateMethod =
new LateParsedMethodDeclaration(
this, ThisDecl);
2148 getCurrentClass().LateParsedDeclarations.push_back(LateMethod);
2157 LateMethod->DefaultArgs.reserve(FTI.
NumParams);
2159 LateMethod->DefaultArgs.push_back(LateParsedDefaultArgument(
2180 Ident_final = &PP.getIdentifierTable().get(
"final");
2182 Ident_GNU_final = &PP.getIdentifierTable().get(
"__final");
2184 Ident_sealed = &PP.getIdentifierTable().get(
"sealed");
2185 Ident_override = &PP.getIdentifierTable().get(
"override");
2188 if (II == Ident_override)
2191 if (II == Ident_sealed)
2194 if (II == Ident_final)
2197 if (II == Ident_GNU_final)
2208 void Parser::ParseOptionalCXX11VirtSpecifierSeq(
VirtSpecifiers &VS,
2227 const char *PrevSpec =
nullptr;
2244 ? diag::warn_cxx98_compat_override_control_keyword
2245 : diag::ext_override_control_keyword)
2254 bool Parser::isCXX11FinalKeyword()
const {
2263 bool Parser::ParseCXXMemberDeclaratorBeforeInitializer(
2265 LateParsedAttrList &LateParsedAttrs) {
2270 if (Tok.
isNot(tok::colon))
2271 ParseDeclarator(DeclaratorInfo);
2277 "don't know where identifier would go yet?");
2279 if (BitfieldSize.isInvalid())
2282 ParseOptionalCXX11VirtSpecifierSeq(
2283 VS, getCurrentClass().IsInterface,
2286 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo, VS);
2290 if (Tok.
is(tok::kw_asm)) {
2292 ExprResult AsmLabel(ParseSimpleAsm(&Loc));
2293 if (AsmLabel.isInvalid())
2301 MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs);
2305 if (BitfieldSize.isUnset() && VS.
isUnset()) {
2306 ParseOptionalCXX11VirtSpecifierSeq(
2307 VS, getCurrentClass().IsInterface,
2313 if (AL.isKnownToGCC() && !AL.isCXX11Attribute())
2314 Diag(AL.getLoc(), diag::warn_gcc_attribute_location);
2316 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo, VS);
2322 if (!DeclaratorInfo.
hasName() && BitfieldSize.isUnset()) {
2332 void Parser::MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(
2339 ParseTypeQualifierListOpt(
2340 DS, AR_NoAttributesParsed,
false,
2341 false, llvm::function_ref<
void()>([&]() {
2342 Actions.CodeCompleteFunctionQualifiers(DS, D, &VS);
2349 auto DeclSpecCheck = [&](
DeclSpec::TQ TypeQual, StringRef FixItName,
2352 auto &MQ =
Function.getOrCreateMethodQualifiers();
2353 if (!(MQ.getTypeQualifiers() & TypeQual)) {
2354 std::string Name(FixItName.data());
2357 MQ.SetTypeQual(TypeQual, SpecLoc);
2359 Diag(SpecLoc, diag::err_declspec_after_virtspec)
2368 bool RefQualifierIsLValueRef =
true;
2370 if (ParseRefQualifier(RefQualifierIsLValueRef, RefQualifierLoc)) {
2371 const char *Name = (RefQualifierIsLValueRef ?
"& " :
"&& ");
2373 Function.RefQualifierIsLValueRef = RefQualifierIsLValueRef;
2376 Diag(RefQualifierLoc, diag::err_declspec_after_virtspec)
2377 << (RefQualifierIsLValueRef ?
"&" :
"&&")
2425 const ParsedTemplateInfo &TemplateInfo,
2427 if (Tok.
is(tok::at)) {
2429 Diag(Tok, diag::err_at_defs_cxx);
2431 Diag(Tok, diag::err_at_in_class);
2447 bool MalformedTypeSpec =
false;
2448 if (!TemplateInfo.Kind &&
2449 Tok.
isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) {
2451 MalformedTypeSpec =
true;
2454 if (Tok.
isNot(tok::annot_cxxscope))
2455 isAccessDecl =
false;
2457 isAccessDecl = GetLookAheadToken(2).is(tok::semi);
2464 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
2476 &TemplateKWLoc, Name)) {
2482 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
2483 "access declaration")) {
2499 if (!TemplateInfo.Kind &&
2500 Tok.
isOneOf(tok::kw_static_assert, tok::kw__Static_assert)) {
2506 if (Tok.
is(tok::kw_template)) {
2507 assert(!TemplateInfo.TemplateParams &&
2508 "Nested template improperly parsed?");
2517 if (Tok.
is(tok::kw___extension__)) {
2521 return ParseCXXClassMemberDeclaration(AS, AccessAttrs,
2522 TemplateInfo, TemplateDiags);
2525 ParsedAttributesWithRange attrs(AttrFactory);
2526 ParsedAttributesViewWithRange FnAttrs;
2528 MaybeParseCXX11Attributes(attrs);
2531 FnAttrs.addAll(attrs.begin(), attrs.end());
2532 FnAttrs.Range = attrs.Range;
2534 MaybeParseMicrosoftAttributes(attrs);
2536 if (Tok.
is(tok::kw_using)) {
2537 ProhibitAttributes(attrs);
2542 if (Tok.
is(tok::kw_namespace)) {
2543 Diag(UsingLoc, diag::err_using_namespace_in_class);
2550 UsingLoc, DeclEnd, AS);
2554 LateParsedAttrList CommonLateParsedAttrs;
2560 if (MalformedTypeSpec)
2563 ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DeclSpecContext::DSC_class,
2564 &CommonLateParsedAttrs);
2572 TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate &&
2573 DiagnoseMissingSemiAfterTagDefinition(DS, AS, DeclSpecContext::DSC_class,
2574 &CommonLateParsedAttrs))
2578 TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->data()
2580 TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->size() : 0);
2584 ProhibitAttributes(FnAttrs);
2587 Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(
2588 getCurScope(), AS, DS, TemplateParams,
false, AnonRecord);
2589 DS.complete(TheDecl);
2591 Decl* decls[] = {AnonRecord, TheDecl};
2592 return Actions.BuildDeclaratorGroup(decls);
2594 return Actions.ConvertDeclToDeclGroup(TheDecl);
2601 LateParsedAttrList LateParsedAttrs;
2606 auto TryConsumePureSpecifier = [&] (
bool AllowDefinition) {
2607 if (Tok.
isNot(tok::equal))
2612 if (Zero.isNot(tok::numeric_constant) || Zero.getLength() != 1 ||
2613 PP.getSpelling(Zero, Buffer) !=
"0")
2616 auto &
After = GetLookAheadToken(2);
2617 if (!
After.isOneOf(tok::semi, tok::comma) &&
2618 !(AllowDefinition &&
2619 After.isOneOf(tok::l_brace, tok::colon, tok::kw_try)))
2628 ExprResult BitfieldSize;
2629 bool ExpectSemi =
true;
2632 if (ParseCXXMemberDeclaratorBeforeInitializer(
2633 DeclaratorInfo, VS, BitfieldSize, LateParsedAttrs)) {
2643 TryConsumePureSpecifier(
true);
2654 if (Tok.
isOneOf(tok::l_brace, tok::colon, tok::kw_try)) {
2656 }
else if (Tok.
is(tok::equal)) {
2658 if (KW.
is(tok::kw_default))
2660 else if (KW.
is(tok::kw_delete))
2672 ProhibitAttributes(FnAttrs);
2689 diag::err_function_declared_typedef);
2696 ParseCXXInlineMethodDef(AS, AccessAttrs, DeclaratorInfo, TemplateInfo,
2700 for (
unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i) {
2701 CommonLateParsedAttrs[i]->addDecl(FunDecl);
2703 for (
unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i) {
2704 LateParsedAttrs[i]->addDecl(FunDecl);
2707 LateParsedAttrs.clear();
2710 if (Tok.
is(tok::semi))
2711 ConsumeExtraSemi(AfterMemberFunctionDefinition);
2723 bool HasStaticInitializer =
false;
2727 if (!TryConsumePureSpecifier(
false))
2729 HasStaticInitializer =
true;
2736 if (BitfieldSize.
get())
2738 ? diag::warn_cxx17_compat_bitfield_member_init
2739 : diag::ext_bitfield_member_init);
2742 HasStaticInitializer =
true;
2760 E = Ranges.end(); I != E; ++I)
2761 Diag((*I).getBegin(), diag::err_attributes_not_allowed) << *I;
2763 ThisDecl = Actions.ActOnFriendFunctionDecl(
getCurScope(), DeclaratorInfo,
2766 ThisDecl = Actions.ActOnCXXMemberDeclarator(
getCurScope(), AS,
2770 VS, HasInClassInit);
2773 ThisDecl ? dyn_cast<VarTemplateDecl>(ThisDecl) :
nullptr)
2776 ThisDecl = VT->getTemplatedDecl();
2779 Actions.ProcessDeclAttributeList(
getCurScope(), ThisDecl, AccessAttrs);
2788 HasStaticInitializer =
true;
2791 if (ThisDecl && PureSpecLoc.
isValid())
2792 Actions.ActOnPureSpecifier(ThisDecl, PureSpecLoc);
2798 ? diag::warn_cxx98_compat_nonstatic_member_init
2799 : diag::ext_nonstatic_member_init);
2807 Diag(Tok, diag::err_incomplete_array_member_init);
2814 ParseCXXNonStaticMemberInitializer(ThisDecl);
2815 }
else if (HasStaticInitializer) {
2817 ExprResult Init = ParseCXXMemberInitializer(
2823 Actions.AddInitializerToDecl(ThisDecl, Init.
get(), EqualLoc.
isInvalid());
2826 Actions.ActOnUninitializedDecl(ThisDecl);
2831 for (
unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i)
2832 CommonLateParsedAttrs[i]->addDecl(ThisDecl);
2834 for (
unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i)
2835 LateParsedAttrs[i]->addDecl(ThisDecl);
2837 Actions.FinalizeDeclaration(ThisDecl);
2838 DeclsInGroup.push_back(ThisDecl);
2843 HandleMemberFunctionDeclDelays(DeclaratorInfo, ThisDecl);
2845 LateParsedAttrs.clear();
2847 DeclaratorInfo.complete(ThisDecl);
2860 Diag(CommaLoc, diag::err_expected_semi_declaration)
2867 DeclaratorInfo.
clear();
2874 MaybeParseGNUAttributes(DeclaratorInfo);
2876 if (ParseCXXMemberDeclaratorBeforeInitializer(
2877 DeclaratorInfo, VS, BitfieldSize, LateParsedAttrs))
2882 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list)) {
2890 return Actions.FinalizeDeclaratorGroup(
getCurScope(), DS, DeclsInGroup);
2913 ExprResult Parser::ParseCXXMemberInitializer(
Decl *D,
bool IsFunction,
2915 assert(Tok.
isOneOf(tok::equal, tok::l_brace)
2916 &&
"Data member initializer not starting with '=' or '{'");
2921 if (Tok.
is(tok::kw_delete)) {
2936 }
else if (Tok.
is(tok::kw_default)) {
2938 Diag(Tok, diag::err_default_delete_in_multiple_declaration)
2945 if (
const auto *PD = dyn_cast_or_null<MSPropertyDecl>(D)) {
2946 Diag(Tok, diag::err_ms_property_initializer) << PD;
2949 return ParseInitializer();
2952 void Parser::SkipCXXMemberSpecification(
SourceLocation RecordLoc,
2957 assert(isCXX11FinalKeyword() &&
"not a class definition");
2962 ParsedAttributesWithRange Attrs(AttrFactory);
2963 CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc);
2968 if (Tok.
isNot(tok::colon) && Tok.
isNot(tok::l_brace))
2975 if (Tok.
is(tok::colon)) {
2978 ParsingClassDefinition ParsingDef(*
this, TagDecl,
true,
2981 Actions.ActOnTagStartSkippedDefinition(
getCurScope(), TagDecl);
2984 ParseBaseClause(
nullptr);
2986 Actions.ActOnTagFinishSkippedDefinition(OldContext);
2988 if (!Tok.
is(tok::l_brace)) {
2989 Diag(PP.getLocForEndOfToken(PrevTokLocation),
2990 diag::err_expected_lbrace_after_base_specifiers);
2996 assert(Tok.
is(tok::l_brace));
3003 if (Tok.
is(tok::kw___attribute))
3004 MaybeParseGNUAttributes(Attrs);
3013 case tok::kw___if_exists:
3014 case tok::kw___if_not_exists:
3015 ParseMicrosoftIfExistsClassDeclaration(TagType, AccessAttrs, AS);
3020 ConsumeExtraSemi(InsideStruct, TagType);
3024 case tok::annot_pragma_vis:
3025 HandlePragmaVisibility();
3027 case tok::annot_pragma_pack:
3030 case tok::annot_pragma_align:
3031 HandlePragmaAlign();
3033 case tok::annot_pragma_ms_pointers_to_members:
3034 HandlePragmaMSPointersToMembers();
3036 case tok::annot_pragma_ms_pragma:
3037 HandlePragmaMSPragma();
3039 case tok::annot_pragma_ms_vtordisp:
3040 HandlePragmaMSVtorDisp();
3042 case tok::annot_pragma_dump:
3046 case tok::kw_namespace:
3048 DiagnoseUnexpectedNamespace(cast<NamedDecl>(TagDecl));
3051 case tok::kw_public:
3052 case tok::kw_protected:
3053 case tok::kw_private: {
3061 AccessAttrs.clear();
3062 MaybeParseGNUAttributes(AccessAttrs);
3067 Diag(EndLoc, diag::err_expected)
3071 Diag(EndLoc, diag::err_expected)
3081 if (Actions.ActOnAccessSpecifier(NewAS, ASLoc, EndLoc, AccessAttrs)) {
3083 AccessAttrs.clear();
3089 case tok::annot_pragma_openmp:
3090 return ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, AccessAttrs, TagType,
3094 return ParseCXXClassMemberDeclaration(AS, AccessAttrs);
3104 void Parser::ParseCXXMemberSpecification(
SourceLocation RecordLoc,
3106 ParsedAttributesWithRange &Attrs,
3107 unsigned TagType,
Decl *TagDecl) {
3114 "parsing struct/union/class body");
3118 bool NonNestedClass =
true;
3119 if (!ClassStack.empty()) {
3121 if (S->isClassScope()) {
3123 NonNestedClass =
false;
3126 if (getCurrentClass().IsInterface) {
3127 Diag(RecordLoc, diag::err_invalid_member_in_interface)
3129 << (isa<NamedDecl>(TagDecl)
3130 ? cast<NamedDecl>(TagDecl)->getQualifiedNameAsString()
3147 ParsingClassDefinition ParsingDef(*
this, TagDecl, NonNestedClass,
3151 Actions.ActOnTagStartDefinition(
getCurScope(), TagDecl);
3154 bool IsFinalSpelledSealed =
false;
3162 "not a class definition");
3167 Diag(FinalLoc, diag::err_override_control_interface)
3171 ? diag::warn_cxx98_compat_override_control_keyword
3172 : diag::ext_override_control_keyword)
3175 Diag(FinalLoc, diag::ext_ms_sealed_keyword);
3177 Diag(FinalLoc, diag::ext_warn_gnu_final);
3183 CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc);
3192 if (!Tok.
is(tok::colon) && !Tok.
is(tok::l_brace)) {
3194 Actions.ActOnTagDefinitionError(
getCurScope(), TagDecl);
3199 if (Tok.
is(tok::colon)) {
3200 ParseScope InheritanceScope(
this,
getCurScope()->getFlags() |
3203 ParseBaseClause(TagDecl);
3204 if (!Tok.
is(tok::l_brace)) {
3205 bool SuggestFixIt =
false;
3206 SourceLocation BraceLoc = PP.getLocForEndOfToken(PrevTokLocation);
3209 case tok::kw_private:
3210 case tok::kw_protected:
3211 case tok::kw_public:
3214 case tok::kw_static_assert:
3218 case tok::kw_template:
3219 SuggestFixIt =
true;
3221 case tok::identifier:
3222 SuggestFixIt = isConstructorDeclarator(
true);
3225 SuggestFixIt = isCXXSimpleDeclaration(
false);
3230 Diag(BraceLoc, diag::err_expected_lbrace_after_base_specifiers);
3238 Actions.ActOnTagDefinitionError(
getCurScope(), TagDecl);
3244 assert(Tok.
is(tok::l_brace));
3249 Actions.ActOnStartCXXMemberDeclarations(
getCurScope(), TagDecl, FinalLoc,
3250 IsFinalSpelledSealed,
3251 T.getOpenLocation());
3261 ParsedAttributesWithRange AccessAttrs(AttrFactory);
3265 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
3268 ParseCXXClassMemberDeclarationWithPragmas(
3269 CurAS, AccessAttrs, static_cast<DeclSpec::TST>(TagType), TagDecl);
3278 MaybeParseGNUAttributes(attrs);
3281 Actions.ActOnFinishCXXMemberSpecification(
getCurScope(), RecordLoc, TagDecl,
3282 T.getOpenLocation(),
3283 T.getCloseLocation(), attrs);
3290 if (TagDecl && NonNestedClass) {
3296 ParseLexedAttributes(getCurrentClass());
3297 ParseLexedMethodDeclarations(getCurrentClass());
3300 Actions.ActOnFinishCXXMemberDecls();
3302 ParseLexedMemberInitializers(getCurrentClass());
3303 ParseLexedMethodDefs(getCurrentClass());
3304 PrevTokLocation = SavedPrevTokLocation;
3308 Actions.ActOnFinishCXXNonNestedClass(TagDecl);
3312 Actions.ActOnTagFinishDefinition(
getCurScope(), TagDecl, T.getRange());
3319 void Parser::DiagnoseUnexpectedNamespace(
NamedDecl *D) {
3320 assert(Tok.
is(tok::kw_namespace));
3325 diag::err_missing_end_of_definition) << D;
3327 diag::note_missing_end_of_definition_before) << D;
3333 Tok.
setLocation(PP.getLocForEndOfToken(PrevTokLocation));
3361 void Parser::ParseConstructorInitializer(
Decl *ConstructorDecl) {
3362 assert(Tok.
is(tok::colon) &&
3363 "Constructor initializer always starts with ':'");
3371 bool AnyErrors =
false;
3374 if (Tok.
is(tok::code_completion)) {
3375 Actions.CodeCompleteConstructorInitializer(ConstructorDecl,
3377 return cutOffParsing();
3380 MemInitResult MemInit = ParseMemInitializer(ConstructorDecl);
3382 MemInitializers.push_back(MemInit.
get());
3386 if (Tok.
is(tok::comma))
3388 else if (Tok.
is(tok::l_brace))
3393 Tok.
isOneOf(tok::identifier, tok::coloncolon)) {
3395 Diag(Loc, diag::err_ctor_init_missing_comma)
3407 Actions.ActOnMemInitializers(ConstructorDecl, ColonLoc, MemInitializers,
3426 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
false);
3436 if (Tok.
is(tok::identifier)) {
3441 }
else if (Tok.
is(tok::annot_decltype)) {
3446 ParseDecltypeSpecifier(DS);
3449 ? takeTemplateIdAnnotation(Tok)
3453 AnnotateTemplateIdTokenAsType(
true);
3454 assert(Tok.
is(tok::annot_typename) &&
"template-id -> type failed");
3456 ConsumeAnnotationToken();
3458 Diag(Tok, diag::err_expected_member_or_base_name);
3465 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
3468 ExprResult InitList = ParseBraceInitializer();
3475 return Actions.ActOnMemInitializer(ConstructorDecl,
getCurScope(), SS, II,
3476 TemplateTypeTy, DS, IdLoc,
3477 InitList.
get(), EllipsisLoc);
3478 }
else if(Tok.
is(tok::l_paren)) {
3483 ExprVector ArgExprs;
3484 CommaLocsTy CommaLocs;
3485 if (Tok.
isNot(tok::r_paren) &&
3486 ParseExpressionList(ArgExprs, CommaLocs, [&] {
3487 QualType PreferredType = Actions.ProduceCtorInitMemberSignatureHelp(
3488 getCurScope(), ConstructorDecl, SS, TemplateTypeTy, ArgExprs, II,
3489 T.getOpenLocation());
3490 CalledSignatureHelp =
true;
3491 Actions.CodeCompleteExpression(
getCurScope(), PreferredType);
3493 if (PP.isCodeCompletionReached() && !CalledSignatureHelp) {
3494 Actions.ProduceCtorInitMemberSignatureHelp(
3495 getCurScope(), ConstructorDecl, SS, TemplateTypeTy, ArgExprs, II,
3496 T.getOpenLocation());
3497 CalledSignatureHelp =
true;
3508 return Actions.ActOnMemInitializer(ConstructorDecl,
getCurScope(), SS, II,
3509 TemplateTypeTy, DS, IdLoc,
3510 T.getOpenLocation(), ArgExprs,
3511 T.getCloseLocation(), EllipsisLoc);
3515 return Diag(Tok, diag::err_expected_either) << tok::l_paren << tok::l_brace;
3517 return Diag(Tok, diag::err_expected) << tok::l_paren;
3530 Parser::tryParseExceptionSpecification(
bool Delayed,
3534 ExprResult &NoexceptExpr,
3537 ExceptionSpecTokens =
nullptr;
3541 if (Tok.
isNot(tok::kw_throw) && Tok.
isNot(tok::kw_noexcept))
3545 bool IsNoexcept = Tok.
is(tok::kw_noexcept);
3546 Token StartTok = Tok;
3550 if (!Tok.
is(tok::l_paren)) {
3553 Diag(Tok, diag::warn_cxx98_compat_noexcept_decl);
3554 NoexceptExpr =
nullptr;
3558 Diag(Tok, diag::err_expected_lparen_after) <<
"throw";
3564 ExceptionSpecTokens->push_back(StartTok);
3565 ExceptionSpecTokens->push_back(Tok);
3566 SpecificationRange.
setEnd(ConsumeParen());
3568 ConsumeAndStoreUntil(tok::r_paren, *ExceptionSpecTokens,
3571 SpecificationRange.
setEnd(ExceptionSpecTokens->back().getLocation());
3577 if (Tok.
is(tok::kw_throw)) {
3578 Result = ParseDynamicExceptionSpecification(SpecificationRange,
3580 DynamicExceptionRanges);
3581 assert(DynamicExceptions.size() == DynamicExceptionRanges.size() &&
3582 "Produced different number of exception types and ranges.");
3586 if (Tok.
isNot(tok::kw_noexcept))
3589 Diag(Tok, diag::warn_cxx98_compat_noexcept_decl);
3597 if (Tok.
is(tok::l_paren)) {
3604 NoexceptExpr = Actions.ActOnNoexceptSpec(KeywordLoc, NoexceptExpr.
get(),
3606 NoexceptRange =
SourceRange(KeywordLoc, T.getCloseLocation());
3613 NoexceptRange =
SourceRange(KeywordLoc, KeywordLoc);
3617 SpecificationRange = NoexceptRange;
3618 Result = NoexceptType;
3622 if (Tok.
is(tok::kw_throw)) {
3623 Diag(Tok.
getLocation(), diag::err_dynamic_and_noexcept_specification);
3624 ParseDynamicExceptionSpecification(NoexceptRange, DynamicExceptions,
3625 DynamicExceptionRanges);
3628 Diag(Tok.
getLocation(), diag::err_dynamic_and_noexcept_specification);
3637 const char *Replacement = IsNoexcept ?
"noexcept" :
"noexcept(false)";
3640 ? diag::ext_dynamic_exception_spec
3641 : diag::warn_exception_spec_deprecated)
3643 P.
Diag(Range.
getBegin(), diag::note_exception_spec_deprecated)
3663 assert(Tok.
is(tok::kw_throw) &&
"expected throw");
3668 Diag(Tok, diag::err_expected_lparen_after) <<
"throw";
3675 if (Tok.
is(tok::ellipsis)) {
3678 Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec);
3687 while (Tok.
isNot(tok::r_paren)) {
3690 if (Tok.
is(tok::ellipsis)) {
3697 Res = Actions.ActOnPackExpansion(Res.
get(), Ellipsis);
3701 Exceptions.push_back(Res.
get());
3702 Ranges.push_back(Range);
3712 Exceptions.empty());
3718 TypeResult Parser::ParseTrailingReturnType(
SourceRange &Range,
3719 bool MayBeFollowedByDirectInit) {
3720 assert(Tok.
is(tok::arrow) &&
"expected arrow");
3733 Parser::PushParsingClass(
Decl *ClassDecl,
bool NonNestedClass,
3735 assert((NonNestedClass || !ClassStack.empty()) &&
3736 "Nested class without outer class");
3737 ClassStack.push(
new ParsingClass(ClassDecl, NonNestedClass, IsInterface));
3738 return Actions.PushParsingClass();
3743 void Parser::DeallocateParsedClasses(Parser::ParsingClass *Class) {
3744 for (
unsigned I = 0, N = Class->LateParsedDeclarations.size(); I != N; ++I)
3745 delete Class->LateParsedDeclarations[I];
3756 assert(!ClassStack.empty() &&
"Mismatched push/pop for class parsing");
3758 Actions.PopParsingClass(state);
3760 ParsingClass *Victim = ClassStack.top();
3762 if (Victim->TopLevelClass) {
3765 DeallocateParsedClasses(Victim);
3768 assert(!ClassStack.empty() &&
"Missing top-level class?");
3770 if (Victim->LateParsedDeclarations.empty()) {
3775 DeallocateParsedClasses(Victim);
3782 assert(
getCurScope()->isClassScope() &&
"Nested class outside of class scope?");
3783 ClassStack.top()->LateParsedDeclarations.push_back(
new LateParsedClass(
this, Victim));
3808 case tok::numeric_constant: {
3815 PP.getSourceManager().getExpansionLoc(Tok.
getLocation());
3816 StringRef Spelling = PP.getSpelling(ExpansionLoc, ExpansionBuf);
3817 if (Spelling ==
"__clang__") {
3820 PP.getSourceManager().getExpansionLoc(Tok.
getEndLoc()));
3821 Diag(Tok, diag::warn_wrong_clang_attr_namespace)
3824 return &PP.getIdentifierTable().get(
"_Clang");
3837 case tok::pipeequal:
3838 case tok::caretequal:
3840 case tok::exclaimequal:
3845 PP.getSourceManager().getSpellingLoc(Tok.
getLocation());
3846 StringRef Spelling = PP.getSpelling(SpellingLoc, SpellingBuf);
3849 return &PP.getIdentifierTable().get(Spelling);
3858 case ParsedAttr::AT_CarriesDependency:
3859 case ParsedAttr::AT_Deprecated:
3860 case ParsedAttr::AT_FallThrough:
3861 case ParsedAttr::AT_CXX11NoReturn:
3863 case ParsedAttr::AT_WarnUnusedResult:
3864 return !ScopeName && AttrName->
getName().equals(
"nodiscard");
3865 case ParsedAttr::AT_Unused:
3866 return !ScopeName && AttrName->
getName().equals(
"maybe_unused");
3892 assert(Tok.
is(tok::l_paren) &&
"Not a C++11 attribute argument list");
3908 if (ScopeName && (ScopeName->
isStr(
"gnu") || ScopeName->
isStr(
"__gnu__"))) {
3911 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
3912 ScopeLoc, Syntax,
nullptr);
3918 if (ScopeName && (ScopeName->
isStr(
"clang") || ScopeName->
isStr(
"_Clang")))
3919 NumArgs = ParseClangAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc,
3920 ScopeName, ScopeLoc, Syntax);
3923 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
3924 ScopeName, ScopeLoc, Syntax);
3926 if (!Attrs.
empty() &&
3936 Diag(LParenLoc, diag::err_attribute_requires_arguments) << AttrName;
3942 Diag(LParenLoc, diag::err_cxx11_attribute_forbids_arguments)
3977 if (Tok.
is(tok::kw_alignas)) {
3979 ParseAlignmentSpecifier(attrs, endLoc);
3983 assert(Tok.
is(tok::l_square) &&
NextToken().
is(tok::l_square) &&
3984 "Not a double square bracket attribute list");
3993 if (Tok.
is(tok::kw_using)) {
3995 ? diag::warn_cxx14_compat_using_attribute_ns
3996 : diag::ext_using_attribute_ns);
3999 CommonScopeName = TryParseCXX11AttributeIdentifier(CommonScopeLoc);
4000 if (!CommonScopeName) {
4008 llvm::SmallDenseMap<IdentifierInfo*, SourceLocation, 4> SeenAttrs;
4010 while (Tok.
isNot(tok::r_square)) {
4018 AttrName = TryParseCXX11AttributeIdentifier(AttrLoc);
4025 ScopeName = AttrName;
4028 AttrName = TryParseCXX11AttributeIdentifier(AttrLoc);
4036 if (CommonScopeName) {
4038 Diag(ScopeLoc, diag::err_using_attribute_ns_conflict)
4041 ScopeName = CommonScopeName;
4042 ScopeLoc = CommonScopeLoc;
4047 bool AttrParsed =
false;
4050 !SeenAttrs.insert(std::make_pair(AttrName, AttrLoc)).second)
4051 Diag(AttrLoc, diag::err_cxx11_attribute_repeated)
4055 if (Tok.
is(tok::l_paren))
4056 AttrParsed = ParseCXX11AttributeArgs(AttrName, AttrLoc, attrs, endLoc,
4057 ScopeName, ScopeLoc);
4062 SourceRange(ScopeLoc.
isValid() ? ScopeLoc : AttrLoc, AttrLoc),
4063 ScopeName, ScopeLoc,
nullptr, 0,
4067 Diag(Tok, diag::err_cxx11_attribute_forbids_ellipsis)
4071 if (ExpectAndConsume(tok::r_square))
4075 if (ExpectAndConsume(tok::r_square))
4083 void Parser::ParseCXX11Attributes(ParsedAttributesWithRange &attrs,
4085 assert(standardAttributesAllowed());
4092 ParseCXX11AttributeSpecifier(attrs, endLoc);
4093 }
while (isCXX11AttributeSpecifier());
4098 void Parser::DiagnoseAndSkipCXX11Attributes() {
4105 Diag(StartLoc, diag::err_attributes_not_allowed)
4113 if (!isCXX11AttributeSpecifier())
4117 if (Tok.
is(tok::l_square)) {
4123 assert(Tok.
is(tok::kw_alignas) &&
"not an attribute specifier");
4130 }
while (isCXX11AttributeSpecifier());
4137 assert(Tok.
is(tok::identifier) &&
"Not a Microsoft attribute list");
4139 assert(UuidIdent->getName() ==
"uuid" &&
"Not a Microsoft attribute list");
4147 Diag(Tok, diag::err_expected) << tok::l_paren;
4152 if (Tok.
is(tok::string_literal)) {
4154 ExprResult StringResult = ParseStringLiteralExpression();
4157 ArgExprs.push_back(StringResult.
get());
4174 while (Tok.
isNot(tok::r_paren)) {
4176 Diag(Tok, diag::err_attribute_uuid_malformed_guid);
4181 SpellingBuffer.resize(Tok.
getLength() + 1);
4182 bool Invalid =
false;
4183 StringRef TokSpelling = PP.getSpelling(Tok, SpellingBuffer, &Invalid);
4188 StrBuffer += TokSpelling;
4194 Diag(Tok, diag::err_attribute_uuid_malformed_guid);
4204 Toks[0].
setKind(tok::string_literal);
4209 cast<StringLiteral>(Actions.ActOnStringLiteral(Toks,
nullptr).get());
4210 ArgExprs.push_back(UuidString);
4230 assert(Tok.
is(tok::l_square) &&
"Not a Microsoft attribute list");
4240 if (Tok.
isNot(tok::identifier))
4243 ParseMicrosoftUuidAttributeArgs(attrs);
4251 }
while (Tok.
is(tok::l_square));
4254 void Parser::ParseMicrosoftIfExistsClassDeclaration(
4257 IfExistsCondition
Result;
4258 if (ParseMicrosoftIfExistsCondition(Result))
4263 Diag(Tok, diag::err_expected) << tok::l_brace;
4267 switch (Result.Behavior) {
4273 Diag(Result.KeywordLoc, diag::warn_microsoft_dependent_exists)
4274 << Result.IsIfExists;
4283 while (Tok.
isNot(tok::r_brace) && !isEofOrEom()) {
4285 if (Tok.
isOneOf(tok::kw___if_exists, tok::kw___if_not_exists)) {
4286 ParseMicrosoftIfExistsClassDeclaration((
DeclSpec::TST)TagType,
4287 AccessAttrs, CurAS);
4292 if (Tok.
is(tok::semi)) {
4293 ConsumeExtraSemi(InsideStruct, TagType);
4303 if (Tok.
is(tok::colon))
4304 Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.
getLocation(),
4307 Diag(Tok, diag::err_expected) << tok::colon;
4313 ParseCXXClassMemberDeclaration(CurAS, AccessAttrs);
Defines the clang::ASTContext interface.
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
no exception specification
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
A (possibly-)qualified type.
void clear()
Reset the contents of this Declarator.
void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace)
ActOnFinishNamespaceDef - This callback is called after a namespace is exited.
IdentifierInfo * Name
FIXME: Temporarily stores the name of a specialization.
SourceLocation TemplateNameLoc
TemplateNameLoc - The location of the template name within the source.
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {...
static CharSourceRange getTokenRange(SourceRange R)
The name refers to a dependent template name:
Decl * ActOnUsingDirective(Scope *CurScope, SourceLocation UsingLoc, SourceLocation NamespcLoc, CXXScopeSpec &SS, SourceLocation IdentLoc, IdentifierInfo *NamespcName, const ParsedAttributesView &AttrList)
Decl - This represents one declaration (or definition), e.g.
RAII object used to inform the actions that we're currently parsing a declaration.
void CodeCompleteUsing(Scope *S)
A RAII object used to temporarily suppress access-like checking.
Defines the C++ template declaration subclasses.
bool isTemplateParamScope() const
isTemplateParamScope - Return true if this scope is a C++ template parameter scope.
The base class of the type hierarchy.
bool TryAnnotateCXXScopeToken(bool EnteringContext=false)
TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only annotates C++ scope specifiers and ...
SourceLocation getCloseLocation() const
This indicates that the scope corresponds to a function, which means that labels are set here...
Declaration of a variable template.
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
static FixItHint CreateInsertionFromRange(SourceLocation InsertionLoc, CharSourceRange FromRange, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code from FromRange at a specific location...
static const char * getSpecifierName(DeclSpec::TST T, const PrintingPolicy &Policy)
Turn a type-specifier-type into a string like "_Bool" or "union".
std::unique_ptr< CachedTokens > DefaultArgTokens
DefaultArgTokens - When the parameter's default argument cannot be parsed immediately (because it occ...
static const char * getSpecifierName(Specifier VS)
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
TemplateNameKind Kind
The kind of template that Template refers to.
const NestedNameSpecifier * Specifier
Wrapper for void* pointer.
Parser - This implements a parser for the C family of languages.
constexpr XRayInstrMask Function
void SetIdentifier(IdentifierInfo *Id, SourceLocation IdLoc)
Set the name of this declarator to be the given identifier.
const ParsedAttributes & getAttributes() const
RAII object that enters a new expression evaluation context.
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...
Decl * ActOnStartLinkageSpecification(Scope *S, SourceLocation ExternLoc, Expr *LangStr, SourceLocation LBraceLoc)
ActOnStartLinkageSpecification - Parsed the beginning of a C++ linkage specification, including the language and (if present) the '{'.
SourceRange getSourceRange() const LLVM_READONLY
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
SourceLocation TemplateKWLoc
TemplateKWLoc - The location of the template keyword.
void setInvalid(bool b=true) const
SourceLocation LAngleLoc
The location of the '<' before the template argument list.
A little helper class used to produce diagnostics.
A class for parsing a declarator.
bool isDeclarationOfFunction() const
Determine whether the declaration that will be produced from this declaration will be a function...
bool isPastIdentifier() const
isPastIdentifier - Return true if we have parsed beyond the point where the name would appear...
void SetRangeStart(SourceLocation Loc)
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
SourceRange getRange() const
TST getTypeSpecType() const
Decl * ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, Expr *AssertExpr, Expr *AssertMessageExpr, SourceLocation RParenLoc)
A single parameter index whose accessors require each use to make explicit the parameter index encodi...
This represents one expression.
static bool IsBuiltInOrStandardCXX11Attribute(IdentifierInfo *AttrName, IdentifierInfo *ScopeName)
Represents a character-granular source range.
void AnnotateCachedTokens(const Token &Tok)
We notify the Preprocessor that if it is caching tokens (because backtrack is enabled) it should repl...
This file defines the classes used to store parsed information about declaration-specifiers and decla...
void SkipMalformedDecl()
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a s...
bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, ParsedType ObjectType, SourceLocation *TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
Specifier getLastSpecifier() const
TypeResult ActOnTypeName(Scope *S, Declarator &D)
void RevertCachedTokens(unsigned N)
When backtracking is enabled and tokens are cached, this allows to revert a specific number of tokens...
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
OpaquePtr< TemplateName > TemplateTy
Defines an enumeration for C++ overloaded operators.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
void setAsmLabel(Expr *E)
SourceLocation getBeginLoc() const
Decl * ActOnFinishExportDecl(Scope *S, Decl *ExportDecl, SourceLocation RBraceLoc)
Complete the definition of an export declaration.
Represents a C++ template name within the type system.
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7)...
CachedTokens * ExceptionSpecTokens
Pointer to the cached tokens for an exception-specification that has not yet been parsed...
TemplateNameKind
Specifies the kind of template name that an identifier refers to.
InClassInitStyle
In-class initialization styles for non-static data members.
SourceLocation getOpenLocation() const
ParsedType getInheritingConstructorName(CXXScopeSpec &SS, SourceLocation NameLoc, IdentifierInfo &Name)
Handle the result of the special case name lookup for inheriting constructor declarations.
bool isFriendSpecified() const
The result type of a method or function.
void CodeCompleteNamespaceDecl(Scope *S)
PrettyDeclStackTraceEntry - If a crash occurs in the parser while parsing something related to a decl...
const LangOptions & getLangOpts() const
A class for parsing a DeclSpec.
Represents a C++ Modules TS module export declaration.
ExprResult ActOnDecltypeExpression(Expr *E)
Process the expression contained within a decltype.
bool isArrayOfUnknownBound() const
isArrayOfUnknownBound - This method returns true if the declarator is a declarator for an array of un...
Stop skipping at semicolon.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
SCS getStorageClassSpec() const
ASTContext & getASTContext() const
bool hasName() const
hasName - Whether this declarator has a name, which might be an identifier (accessible via getIdentif...
Encodes a location in the source.
Decl * ActOnFinishLinkageSpecification(Scope *S, Decl *LinkageSpec, SourceLocation RBraceLoc)
ActOnFinishLinkageSpecification - Complete the definition of the C++ linkage specification LinkageSpe...
void setLength(unsigned Len)
Syntax
The style used to specify an attribute.
Represents the declaration of a struct/union/class/enum.
static const TST TST_union
IdentifierInfo * getIdentifierInfo() const
void setAnnotationEndLoc(SourceLocation L)
ParsedAttr - Represents a syntactic attribute.
ExtensionRAIIObject - This saves the state of extension warnings when constructed and disables them...
ParsedAttr * addNew(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ArgsUnion *args, unsigned numArgs, ParsedAttr::Syntax syntax, SourceLocation ellipsisLoc=SourceLocation())
Add attribute with expression arguments.
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Direct list-initialization.
Represents a C++11 virt-specifier-seq.
Decl * ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc, SourceLocation LBraceLoc)
We have parsed the start of an export declaration, including the '{' (if present).
FunctionDefinitionKind
Described the kind of function definition (if any) provided for a function.
Scope * getCurScope() const
ExprResult ParseConstantExpressionInExprEvalContext(TypeCastState isTypeCast=NotTypeCast)
bool isInvalid() const
An error occurred during parsing of the scope specifier.
void setFunctionDefinitionKind(FunctionDefinitionKind Val)
SourceLocation getModulePrivateSpecLoc() const
StringRef getName() const
Return the actual identifier string.
The scope of a struct/union/class definition.
bool isNot(tok::TokenKind K) const
bool isBacktrackEnabled() const
True if EnableBacktrackAtThisPos() was called and caching of tokens is on.
static const TST TST_decltype_auto
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
SmallVector< Token, 4 > CachedTokens
A set of tokens that has been cached for later parsing.
static const TST TST_decltype
const Scope * getParent() const
getParent - Return the scope that this is nested in.
static void diagnoseDynamicExceptionSpecification(Parser &P, SourceRange Range, bool IsNoexcept)
CXXScopeSpec SS
The nested-name-specifier that precedes the template name.
SourceLocation RAngleLoc
The location of the '>' after the template argument list.
void CodeCompleteTag(Scope *S, unsigned TagSpec)
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
The name refers to a template whose specialization produces a type.
unsigned getLength() const
void CodeCompleteNamespaceAliasDecl(Scope *S)
void forEachQualifier(llvm::function_ref< void(TQ, StringRef, SourceLocation)> Handle)
This method calls the passed in handler on each qual being set.
void setLiteralData(const char *Ptr)
void CodeCompleteUsingDirective(Scope *S)
const TargetInfo & getTargetInfo() const
bool SetSpecifier(Specifier VS, SourceLocation Loc, const char *&PrevSpec)
unsigned getTypeQualifiers() const
getTypeQualifiers - Return a set of TQs.
void takeAttributesFrom(ParsedAttributes &attrs)
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
static const TST TST_typename
void SetRangeEnd(SourceLocation Loc)
SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
We are between inheritance colon and the real class/struct definition scope.
ExceptionSpecificationType getExceptionSpecType() const
Get the type of exception specification this function has.
SmallVector< TemplateParameterList *, 4 > TemplateParameterLists
CXXScopeSpec & getTypeSpecScope()
This is a scope that can contain a declaration.
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
SourceLocation getIdentifierLoc() const
bool isSet() const
Deprecated.
unsigned getMaxArgs() const
void getCXX11AttributeRanges(SmallVectorImpl< SourceRange > &Ranges)
Return a source range list of C++11 attributes associated with the declarator.
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
ExprResult ParseConstantExpression(TypeCastState isTypeCast=NotTypeCast)
Captures information about "declaration specifiers".
ActionResult< Expr * > ExprResult
void setEnd(SourceLocation e)
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
void revertTokenIDToIdentifier()
Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2 compatibility.
A template-id, e.g., f<int>.
SourceLocation getFirstLocation() const
StringLiteral - This represents a string literal expression, e.g.
Defines the clang::TargetInfo interface.
void ExtendWithDeclSpec(const DeclSpec &DS)
ExtendWithDeclSpec - Extend the declarator source range to include the given declspec, unless its location is invalid.
static OpaquePtr make(PtrTy P)
static const TST TST_struct
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
void setLocation(SourceLocation L)
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
Expr * getRepAsExpr() const
__ptr16, alignas(...), etc.
Represents C++ using-directive.
unsigned NumArgs
NumArgs - The number of template arguments.
void SetRangeEnd(SourceLocation Loc)
Decl * ActOnAliasDeclaration(Scope *CurScope, AccessSpecifier AS, MultiTemplateParamsArg TemplateParams, SourceLocation UsingLoc, UnqualifiedId &Name, const ParsedAttributesView &AttrList, TypeResult Type, Decl *DeclFromDeclSpec)
SourceLocation getBegin() const
ParsedAttributes - A collection of parsed attributes.
SourceLocation ColonLoc
Location of ':'.
void setCommaLoc(SourceLocation CL)
bool hasLeadingSpace() const
Return true if this token has whitespace before it.
Decl * ActOnUsingDeclaration(Scope *CurScope, AccessSpecifier AS, SourceLocation UsingLoc, SourceLocation TypenameLoc, CXXScopeSpec &SS, UnqualifiedId &Name, SourceLocation EllipsisLoc, const ParsedAttributesView &AttrList)
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeNameContext, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName type-name: [C99 6.7.6] specifier-qualifier-list abstract-declarator[opt].
Attr - This represents one attribute.
SourceLocation getLocation() const
void startToken()
Reset all flags to cleared.
ParsedTemplateTy Template
The declaration of the template corresponding to the template-name.
Stop skipping at specified token, but don't skip the token itself.
SourceLocation getEndLoc() const