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);
84 ParseCXX11Attributes(attrs);
87 if (Tok.
is(tok::identifier)) {
90 while (Tok.
is(tok::coloncolon) &&
NextToken().
is(tok::identifier)) {
98 if (!ExtraNamespaceLoc.empty() && attrLoc.isValid())
99 Diag(attrLoc, diag::err_unexpected_nested_namespace_attribute);
102 if (Tok.
is(tok::kw___attribute)) {
104 ParseGNUAttributes(attrs);
107 if (Tok.
is(tok::equal)) {
109 Diag(Tok, diag::err_expected) << tok::identifier;
114 if (attrLoc.isValid())
115 Diag(attrLoc, diag::err_unexpected_namespace_attributes_alias);
117 Diag(InlineLoc, diag::err_inline_namespace_alias)
119 Decl *NSAlias = ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd);
124 if (T.consumeOpen()) {
126 Diag(Tok, diag::err_expected) << tok::l_brace;
128 Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace;
135 Diag(T.getOpenLocation(), diag::err_namespace_nonnamespace_scope);
140 if (ExtraIdent.empty()) {
142 }
else if (InlineLoc.
isValid()) {
143 Diag(InlineLoc, diag::err_inline_nested_namespace_definition);
145 Diag(ExtraNamespaceLoc[0],
146 diag::warn_cxx14_compat_nested_namespace_definition);
148 TentativeParsingAction TPA(*
this);
150 Token rBraceToken = Tok;
153 if (!rBraceToken.
is(tok::r_brace)) {
154 Diag(ExtraNamespaceLoc[0], diag::ext_nested_namespace_definition)
155 <<
SourceRange(ExtraNamespaceLoc.front(), ExtraIdentLoc.back());
157 std::string NamespaceFix;
158 for (std::vector<IdentifierInfo*>::iterator
I = ExtraIdent.begin(),
159 E = ExtraIdent.end();
I !=
E; ++
I) {
160 NamespaceFix +=
" { namespace ";
161 NamespaceFix += (*I)->getName();
165 for (
unsigned i = 0, e = ExtraIdent.size(); i != e; ++i)
168 Diag(ExtraNamespaceLoc[0], diag::ext_nested_namespace_definition)
170 ExtraIdentLoc.back()),
179 diag::warn_cxx98_compat_inline_namespace : diag::ext_inline_namespace);
187 IdentLoc, Ident, T.getOpenLocation(),
188 attrs.getList(), ImplicitUsingDirectiveDecl);
191 "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);
237 NamespaceLoc[index], IdentLoc[index],
239 attrs.
getList(), ImplicitUsingDirectiveDecl);
240 assert(!ImplicitUsingDirectiveDecl &&
241 "nested namespace definition cannot define anonymous namespace");
243 ParseInnerNamespace(IdentLoc, Ident, NamespaceLoc, ++index, InlineLoc,
246 NamespaceScope.Exit();
257 assert(Tok.
is(tok::equal) &&
"Not equal token");
261 if (Tok.
is(tok::code_completion)) {
269 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
false,
275 if (Tok.
isNot(tok::identifier)) {
276 Diag(Tok, diag::err_expected_namespace_name);
295 if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after_namespace_name))
299 Alias, SS, IdentLoc, Ident);
310 assert(isTokenStringLiteral() &&
"Not a string literal!");
311 ExprResult Lang = ParseStringLiteralExpression(
false);
321 ParsedAttributesWithRange attrs(AttrFactory);
322 MaybeParseCXX11Attributes(attrs);
324 if (Tok.
isNot(tok::l_brace)) {
331 ParseExternalDeclaration(attrs, &DS);
339 ProhibitAttributes(attrs);
344 unsigned NestedModules = 0;
347 case tok::annot_module_begin:
352 case tok::annot_module_end:
359 case tok::annot_module_include:
371 ParsedAttributesWithRange attrs(AttrFactory);
372 MaybeParseCXX11Attributes(attrs);
373 ParseExternalDeclaration(attrs);
392 Decl *Parser::ParseExportDeclaration() {
393 assert(Tok.
is(tok::kw_export));
401 if (Tok.
isNot(tok::l_brace)) {
403 ParsedAttributesWithRange Attrs(AttrFactory);
404 MaybeParseCXX11Attributes(Attrs);
405 MaybeParseMicrosoftAttributes(Attrs);
406 ParseExternalDeclaration(Attrs);
416 if (Tok.
is(tok::r_brace))
417 Diag(ExportLoc, diag::err_export_empty)
420 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
422 ParsedAttributesWithRange Attrs(AttrFactory);
423 MaybeParseCXX11Attributes(Attrs);
424 MaybeParseMicrosoftAttributes(Attrs);
425 ParseExternalDeclaration(Attrs);
430 T.getCloseLocation());
436 Parser::ParseUsingDirectiveOrDeclaration(
unsigned Context,
437 const ParsedTemplateInfo &TemplateInfo,
439 ParsedAttributesWithRange &attrs) {
440 assert(Tok.
is(tok::kw_using) &&
"Not using token");
446 if (Tok.
is(tok::code_completion)) {
453 if (Tok.
is(tok::kw_namespace)) {
455 if (TemplateInfo.Kind) {
457 Diag(UsingLoc, diag::err_templated_using_directive_declaration)
461 Decl *UsingDir = ParseUsingDirective(Context, UsingLoc, DeclEnd, attrs);
468 ProhibitAttributes(attrs);
470 return ParseUsingDeclaration(Context, TemplateInfo, UsingLoc, DeclEnd,
484 Decl *Parser::ParseUsingDirective(
unsigned Context,
488 assert(Tok.
is(tok::kw_namespace) &&
"Not 'namespace' token");
493 if (Tok.
is(tok::code_completion)) {
501 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
false,
511 if (Tok.
isNot(tok::identifier)) {
512 Diag(Tok, diag::err_expected_namespace_name);
531 bool GNUAttr =
false;
532 if (Tok.
is(tok::kw___attribute)) {
534 ParseGNUAttributes(attrs);
539 if (ExpectAndConsume(tok::semi,
540 GNUAttr ? diag::err_expected_semi_after_attribute_list
541 : diag::err_expected_semi_after_namespace_name))
545 IdentLoc, NamespcName, attrs.
getList());
553 bool Parser::ParseUsingDeclarator(
unsigned Context, UsingDeclarator &D) {
560 if (Tok.
is(tok::kw___super)) {
567 ParseOptionalCXXScopeSpecifier(D.SS,
nullptr,
false,
571 if (D.SS.isInvalid())
585 Tok.
is(tok::identifier) &&
589 !D.SS.getScopeRep()->getAsNamespace() &&
590 !D.SS.getScopeRep()->getAsNamespaceAlias()) {
594 D.Name.setConstructorName(Type, IdLoc, IdLoc);
599 !(Tok.
is(tok::identifier) &&
602 nullptr, D.TemplateKWLoc, D.Name))
608 diag::warn_cxx1z_compat_using_declaration_pack :
609 diag::ext_using_declaration_pack);
631 Parser::ParseUsingDeclaration(
unsigned Context,
632 const ParsedTemplateInfo &TemplateInfo,
637 ParsedAttributesWithRange MisplacedAttrs(AttrFactory);
638 MaybeParseCXX11Attributes(MisplacedAttrs);
641 bool InvalidDeclarator = ParseUsingDeclarator(Context, D);
643 ParsedAttributesWithRange Attrs(AttrFactory);
644 MaybeParseGNUAttributes(Attrs);
645 MaybeParseCXX11Attributes(Attrs);
648 if (Tok.
is(tok::equal)) {
649 if (InvalidDeclarator) {
656 if (MisplacedAttrs.Range.isValid()) {
657 Diag(MisplacedAttrs.Range.getBegin(), diag::err_attributes_not_allowed)
662 Attrs.takeAllFrom(MisplacedAttrs);
665 Decl *DeclFromDeclSpec =
nullptr;
666 Decl *AD = ParseAliasDeclarationAfterDeclarator(
667 TemplateInfo, UsingLoc, D, DeclEnd, AS, Attrs, &DeclFromDeclSpec);
673 ProhibitAttributes(MisplacedAttrs);
674 ProhibitAttributes(Attrs);
679 if (TemplateInfo.Kind) {
681 Diag(UsingLoc, diag::err_templated_using_directive_declaration)
693 MaybeParseGNUAttributes(Attrs);
695 if (InvalidDeclarator)
700 if (D.TypenameLoc.isValid() &&
702 Diag(D.Name.getSourceRange().getBegin(),
703 diag::err_typename_identifiers_only)
710 D.TypenameLoc, D.SS, D.Name,
711 D.EllipsisLoc, Attrs.getList());
713 DeclsInGroup.push_back(UD);
721 InvalidDeclarator = ParseUsingDeclarator(Context, D);
724 if (DeclsInGroup.size() > 1)
726 diag::warn_cxx1z_compat_multi_using_declaration :
727 diag::ext_multi_using_declaration);
731 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
732 !Attrs.empty() ?
"attributes list"
733 :
"using declaration"))
739 Decl *Parser::ParseAliasDeclarationAfterDeclarator(
743 if (ExpectAndConsume(tok::equal)) {
749 diag::warn_cxx98_compat_alias_declaration :
750 diag::ext_alias_declaration);
754 if (TemplateInfo.Kind == ParsedTemplateInfo::Template &&
757 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization)
759 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation)
761 if (SpecKind != -1) {
765 D.Name.TemplateId->RAngleLoc);
767 Range = TemplateInfo.getSourceRange();
768 Diag(Range.
getBegin(), diag::err_alias_declaration_specialization)
769 << SpecKind << Range;
776 Diag(D.Name.StartLocation, diag::err_alias_declaration_not_identifier);
780 }
else if (D.TypenameLoc.isValid())
781 Diag(D.TypenameLoc, diag::err_alias_declaration_not_identifier)
784 D.SS.isNotEmpty() ? D.SS.getEndLoc() : D.TypenameLoc));
785 else if (D.SS.isNotEmpty())
786 Diag(D.SS.getBeginLoc(), diag::err_alias_declaration_not_identifier)
788 if (D.EllipsisLoc.isValid())
789 Diag(D.EllipsisLoc, diag::err_alias_declaration_pack_expansion)
792 Decl *DeclFromDeclSpec =
nullptr;
797 AS, &DeclFromDeclSpec, &Attrs);
799 *OwnedType = DeclFromDeclSpec;
803 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
804 !Attrs.
empty() ?
"attributes list"
805 :
"alias declaration"))
810 TemplateParams ? TemplateParams->data() :
nullptr,
811 TemplateParams ? TemplateParams->size() : 0);
813 UsingLoc, D.Name, Attrs.
getList(),
814 TypeAlias, DeclFromDeclSpec);
826 assert(Tok.
isOneOf(tok::kw_static_assert, tok::kw__Static_assert) &&
827 "Not a static_assert declaration");
830 Diag(Tok, diag::ext_c11_static_assert);
831 if (Tok.
is(tok::kw_static_assert))
832 Diag(Tok, diag::warn_cxx98_compat_static_assert);
837 if (T.consumeOpen()) {
838 Diag(Tok, diag::err_expected) << tok::l_paren;
846 if (AssertExpr.isInvalid()) {
852 if (Tok.
is(tok::r_paren)) {
854 ? diag::warn_cxx14_compat_static_assert_no_message
855 : diag::ext_static_assert_no_message)
858 :
FixItHint::CreateInsertion(Tok.getLocation(),
", \"\""));
860 if (ExpectAndConsume(tok::comma)) {
865 if (!isTokenStringLiteral()) {
866 Diag(Tok, diag::err_expected_string_literal)
872 AssertMessage = ParseStringLiteralExpression();
882 ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert);
887 T.getCloseLocation());
896 assert(Tok.
isOneOf(tok::kw_decltype, tok::annot_decltype)
897 &&
"Not a decltype specifier");
903 if (Tok.
is(tok::annot_decltype)) {
904 Result = getExprAnnotation(Tok);
906 ConsumeAnnotationToken();
907 if (Result.isInvalid()) {
913 Diag(Tok, diag::warn_cxx98_compat_decltype);
918 if (T.expectAndConsume(diag::err_expected_lparen_after,
919 "decltype", tok::r_paren)) {
922 StartLoc : T.getOpenLocation();
926 if (Tok.
is(tok::kw_auto)) {
932 ? diag::warn_cxx11_compat_decltype_auto_type_specifier
933 : diag::ext_decltype_auto_type_specifier);
947 if (Result.isInvalid()) {
950 EndLoc = ConsumeParen();
956 EndLoc = ConsumeAnyToken();
957 assert(Tok.
is(tok::semi));
970 if (T.getCloseLocation().isInvalid()) {
974 return T.getCloseLocation();
977 if (Result.isInvalid()) {
979 return T.getCloseLocation();
982 EndLoc = T.getCloseLocation();
984 assert(!Result.isInvalid());
986 const char *PrevSpec =
nullptr;
992 DiagID, Result.get(), Policy)
995 Diag(StartLoc, DiagID) << PrevSpec;
1001 void Parser::AnnotateExistingDecltypeSpecifier(
const DeclSpec& DS,
1010 Tok.
setKind(tok::annot_decltype);
1011 setExprAnnotation(Tok,
1020 void Parser::ParseUnderlyingTypeSpecifier(
DeclSpec &DS) {
1021 assert(Tok.
is(tok::kw___underlying_type) &&
1022 "Not an underlying type specifier");
1026 if (T.expectAndConsume(diag::err_expected_lparen_after,
1027 "__underlying_type", tok::r_paren)) {
1039 if (T.getCloseLocation().isInvalid())
1042 const char *PrevSpec =
nullptr;
1045 DiagID, Result.
get(),
1047 Diag(StartLoc, DiagID) << PrevSpec;
1072 if (Tok.
is(tok::kw_typename)) {
1073 Diag(Tok, diag::err_expected_class_name_not_template)
1080 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
false);
1087 if (Tok.
isOneOf(tok::kw_decltype, tok::annot_decltype)) {
1094 EndLocation = ParseDecltypeSpecifier(DS);
1101 if (Tok.
is(tok::annot_template_id)) {
1105 AnnotateTemplateIdTokenAsType(
true);
1107 assert(Tok.
is(tok::annot_typename) &&
"template-id -> type failed");
1110 ConsumeAnnotationToken();
1120 if (Tok.
isNot(tok::identifier)) {
1121 Diag(Tok, diag::err_expected_class_name);
1128 if (Tok.
is(tok::less)) {
1134 &SS, Template, TNK)) {
1135 Diag(IdLoc, diag::err_unknown_template_name)
1140 TemplateArgList TemplateArgs;
1142 ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs,
1156 AnnotateTemplateIdTokenAsType(
true);
1160 if (Tok.
isNot(tok::annot_typename))
1167 ConsumeAnnotationToken();
1174 *Id, IdLoc,
getCurScope(), &SS,
true,
false,
nullptr,
1177 false, &CorrectedII);
1179 Diag(IdLoc, diag::err_expected_class_name);
1184 EndLocation = IdLoc;
1192 const char *PrevSpec =
nullptr;
1201 void Parser::ParseMicrosoftInheritanceClassAttributes(
ParsedAttributes &attrs) {
1202 while (Tok.
isOneOf(tok::kw___single_inheritance,
1203 tok::kw___multiple_inheritance,
1204 tok::kw___virtual_inheritance)) {
1207 attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1215 bool Parser::isValidAfterTypeSpecifier(
bool CouldBeBitfield) {
1223 case tok::identifier:
1225 case tok::annot_cxxscope:
1226 case tok::annot_typename:
1227 case tok::annot_template_id:
1230 case tok::kw_operator:
1231 case tok::kw___declspec:
1236 case tok::kw___attribute:
1237 case tok::annot_pragma_pack:
1239 case tok::annot_pragma_ms_pragma:
1241 case tok::annot_pragma_ms_vtordisp:
1243 case tok::annot_pragma_ms_pointers_to_members:
1246 return CouldBeBitfield;
1248 case tok::kw___cdecl:
1249 case tok::kw___fastcall:
1250 case tok::kw___stdcall:
1251 case tok::kw___thiscall:
1252 case tok::kw___vectorcall:
1258 case tok::kw_volatile:
1259 case tok::kw_restrict:
1260 case tok::kw__Atomic:
1261 case tok::kw___unaligned:
1265 case tok::kw_inline:
1266 case tok::kw_virtual:
1267 case tok::kw_friend:
1269 case tok::kw_static:
1270 case tok::kw_extern:
1271 case tok::kw_typedef:
1272 case tok::kw_register:
1274 case tok::kw_mutable:
1275 case tok::kw_thread_local:
1276 case tok::kw_constexpr:
1292 if (!isKnownToBeTypeSpecifier(
NextToken()))
1349 const ParsedTemplateInfo &TemplateInfo,
1351 bool EnteringContext, DeclSpecContext DSC,
1352 ParsedAttributesWithRange &Attributes) {
1354 if (TagTokKind == tok::kw_struct)
1356 else if (TagTokKind == tok::kw___interface)
1358 else if (TagTokKind == tok::kw_class)
1361 assert(TagTokKind == tok::kw_union &&
"Not a class specifier");
1365 if (Tok.
is(tok::code_completion)) {
1368 return cutOffParsing();
1381 bool shouldDelayDiagsInTag =
1382 (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
1383 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
1386 ParsedAttributesWithRange attrs(AttrFactory);
1388 MaybeParseGNUAttributes(attrs);
1389 MaybeParseMicrosoftDeclSpecs(attrs);
1392 if (Tok.
isOneOf(tok::kw___single_inheritance,
1393 tok::kw___multiple_inheritance,
1394 tok::kw___virtual_inheritance))
1395 ParseMicrosoftInheritanceClassAttributes(attrs);
1400 MaybeParseCXX11Attributes(attrs);
1407 Tok.
isNot(tok::identifier) &&
1410 Tok.
isOneOf(tok::kw___is_abstract,
1411 tok::kw___is_aggregate,
1412 tok::kw___is_arithmetic,
1414 tok::kw___is_assignable,
1415 tok::kw___is_base_of,
1417 tok::kw___is_complete_type,
1418 tok::kw___is_compound,
1420 tok::kw___is_constructible,
1421 tok::kw___is_convertible,
1422 tok::kw___is_convertible_to,
1423 tok::kw___is_destructible,
1426 tok::kw___is_floating_point,
1428 tok::kw___is_function,
1429 tok::kw___is_fundamental,
1430 tok::kw___is_integral,
1431 tok::kw___is_interface_class,
1432 tok::kw___is_literal,
1433 tok::kw___is_lvalue_expr,
1434 tok::kw___is_lvalue_reference,
1435 tok::kw___is_member_function_pointer,
1436 tok::kw___is_member_object_pointer,
1437 tok::kw___is_member_pointer,
1438 tok::kw___is_nothrow_assignable,
1439 tok::kw___is_nothrow_constructible,
1440 tok::kw___is_nothrow_destructible,
1441 tok::kw___is_object,
1443 tok::kw___is_pointer,
1444 tok::kw___is_polymorphic,
1445 tok::kw___is_reference,
1446 tok::kw___is_rvalue_expr,
1447 tok::kw___is_rvalue_reference,
1449 tok::kw___is_scalar,
1450 tok::kw___is_sealed,
1451 tok::kw___is_signed,
1452 tok::kw___is_standard_layout,
1453 tok::kw___is_trivial,
1454 tok::kw___is_trivially_assignable,
1455 tok::kw___is_trivially_constructible,
1456 tok::kw___is_trivially_copyable,
1458 tok::kw___is_unsigned,
1460 tok::kw___is_volatile))
1466 TryKeywordIdentFallback(
true);
1468 struct PreserveAtomicIdentifierInfoRAII {
1469 PreserveAtomicIdentifierInfoRAII(
Token &Tok,
bool Enabled)
1470 : AtomicII(nullptr) {
1473 assert(Tok.
is(tok::kw__Atomic));
1478 ~PreserveAtomicIdentifierInfoRAII() {
1481 AtomicII->revertIdentifierToTokenID(tok::kw__Atomic);
1491 bool ShouldChangeAtomicToIdentifier =
getLangOpts().MSVCCompat &&
1492 Tok.
is(tok::kw__Atomic) &&
1494 PreserveAtomicIdentifierInfoRAII AtomicTokenGuard(
1495 Tok, ShouldChangeAtomicToIdentifier);
1505 bool HasValidSpec =
true;
1506 if (ParseOptionalCXXScopeSpecifier(Spec,
nullptr, EnteringContext)) {
1508 HasValidSpec =
false;
1511 if (Tok.
isNot(tok::identifier) && Tok.
isNot(tok::annot_template_id)) {
1512 Diag(Tok, diag::err_expected) << tok::identifier;
1513 HasValidSpec =
false;
1525 if (Tok.
is(tok::identifier)) {
1533 TemplateArgList TemplateArgs;
1535 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs,
1542 Diag(NameLoc, diag::err_explicit_spec_non_template)
1543 << (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation)
1544 << TagTokKind << Name <<
SourceRange(LAngleLoc, RAngleLoc);
1548 if (TemplateParams && TemplateInfo.LastParameterListWasEmpty) {
1549 if (TemplateParams->size() > 1) {
1550 TemplateParams->pop_back();
1552 TemplateParams =
nullptr;
1553 const_cast<ParsedTemplateInfo&
>(TemplateInfo).
Kind
1554 = ParsedTemplateInfo::NonTemplate;
1556 }
else if (TemplateInfo.Kind
1557 == ParsedTemplateInfo::ExplicitInstantiation) {
1559 TemplateParams =
nullptr;
1560 const_cast<ParsedTemplateInfo&
>(TemplateInfo).
Kind
1561 = ParsedTemplateInfo::NonTemplate;
1562 const_cast<ParsedTemplateInfo&
>(TemplateInfo).TemplateLoc
1564 const_cast<ParsedTemplateInfo&
>(TemplateInfo).ExternLoc
1568 }
else if (Tok.
is(tok::annot_template_id)) {
1569 TemplateId = takeTemplateIdAnnotation(Tok);
1570 NameLoc = ConsumeAnnotationToken();
1582 Diag(TemplateId->
LAngleLoc, diag::err_template_spec_syntax_non_template)
1583 << TemplateId->
Name <<
static_cast<int>(TemplateId->
Kind) << Range;
1617 MaybeParseCXX11Attributes(Attributes);
1621 if (DSC == DSC_trailing)
1623 else if (Tok.
is(tok::l_brace) ||
1625 (isCXX11FinalKeyword() &&
1641 }
else if (isCXX11FinalKeyword() && (
NextToken().is(tok::l_square) ||
1645 TentativeParsingAction PA(*
this);
1652 if (Tok.
is(tok::l_square) &&
NextToken().
is(tok::l_square)) {
1656 }
else if (Tok.
is(tok::kw_alignas) &&
NextToken().
is(tok::l_paren)) {
1666 if (Tok.
isOneOf(tok::l_brace, tok::colon))
1672 }
else if (!isTypeSpecifier(DSC) &&
1673 (Tok.
is(tok::semi) ||
1676 if (Tok.
isNot(tok::semi)) {
1679 ExpectAndConsume(tok::semi, diag::err_expected_after,
1697 Diag(AttrRange.
getBegin(), diag::err_attributes_not_allowed)
1711 if (shouldDelayDiagsInTag) {
1712 diagsFromTag.done();
1714 diagsFromTag.redelay();
1721 Diag(StartLoc, diag::err_anon_type_definition)
1746 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation &&
1749 ProhibitAttributes(attrs);
1753 TemplateInfo.ExternLoc,
1754 TemplateInfo.TemplateLoc,
1771 TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate)) {
1772 ProhibitAttributes(attrs);
1785 if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
1798 "Expected a definition here");
1802 TemplateParams =
nullptr;
1807 diag::err_explicit_instantiation_with_definition)
1816 LAngleLoc,
nullptr));
1817 TemplateParams = &FakedParamLists;
1827 TemplateParams ? TemplateParams->size() : 0),
1830 }
else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation &&
1837 ProhibitAttributes(attrs);
1841 TemplateInfo.ExternLoc,
1842 TemplateInfo.TemplateLoc,
1843 TagType, StartLoc, SS, Name,
1846 TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) {
1847 ProhibitAttributes(attrs);
1851 TagType, StartLoc, SS,
1854 TemplateParams? &(*TemplateParams)[0]
1856 TemplateParams? TemplateParams->size() : 0));
1859 ProhibitAttributes(attrs);
1862 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
1865 Diag(Tok, diag::err_template_defn_explicit_instantiation)
1867 TemplateParams =
nullptr;
1870 bool IsDependent =
false;
1880 stripTypeAttributesOffDeclSpec(attrs, DS, TUK);
1884 SS, Name, NameLoc, attrs.
getList(), AS,
1886 TParams, Owned, IsDependent,
1889 DSC == DSC_type_specifier,
1890 DSC == DSC_template_param ||
1891 DSC == DSC_template_type_arg, &SkipBody);
1898 SS, Name, StartLoc, NameLoc);
1904 assert(Tok.
is(tok::l_brace) ||
1906 isCXX11FinalKeyword());
1908 SkipCXXMemberSpecification(StartLoc, AttrFixitLoc, TagType,
1909 TagOrTempResult.
get());
1911 ParseCXXMemberSpecification(StartLoc, AttrFixitLoc, attrs, TagType,
1912 TagOrTempResult.
get());
1917 ParseStructUnionBody(StartLoc, TagType, D);
1931 const char *PrevSpec =
nullptr;
1936 NameLoc.isValid() ? NameLoc : StartLoc,
1937 PrevSpec, DiagID, TypeResult.
get(), Policy);
1938 }
else if (!TagOrTempResult.
isInvalid()) {
1940 NameLoc.isValid() ? NameLoc : StartLoc,
1941 PrevSpec, DiagID, TagOrTempResult.
get(), Owned,
1949 Diag(StartLoc, DiagID) << PrevSpec;
1965 (TemplateInfo.Kind || !isValidAfterTypeSpecifier(
false))) {
1966 if (Tok.
isNot(tok::semi)) {
1968 ExpectAndConsume(tok::semi, diag::err_expected_after,
1986 void Parser::ParseBaseClause(
Decl *ClassDecl) {
1987 assert(Tok.
is(tok::colon) &&
"Not a base clause");
1995 BaseResult Result = ParseBaseSpecifier(ClassDecl);
2002 BaseInfo.push_back(Result.
get());
2027 bool IsVirtual =
false;
2030 ParsedAttributesWithRange Attributes(AttrFactory);
2031 MaybeParseCXX11Attributes(Attributes);
2037 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2044 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2048 if (Tok.
is(tok::kw_virtual)) {
2052 Diag(VirtualLoc, diag::err_dup_virtual)
2059 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2073 TypeResult BaseType = ParseBaseTypeSpecifier(BaseLoc, EndLocation);
2089 Access, BaseType.
get(), BaseLoc,
2113 void Parser::HandleMemberFunctionDeclDelays(
Declarator& DeclaratorInfo,
2121 if (!NeedLateParse) {
2123 for (
unsigned ParamIdx = 0; ParamIdx < FTI.
NumParams; ++ParamIdx) {
2124 auto Param = cast<ParmVarDecl>(FTI.
Params[ParamIdx].
Param);
2125 if (Param->hasUnparsedDefaultArg()) {
2126 NeedLateParse =
true;
2132 if (NeedLateParse) {
2135 auto LateMethod =
new LateParsedMethodDeclaration(
this, ThisDecl);
2136 getCurrentClass().LateParsedDeclarations.push_back(LateMethod);
2145 LateMethod->DefaultArgs.reserve(FTI.
NumParams);
2146 for (
unsigned ParamIdx = 0; ParamIdx < FTI.
NumParams; ++ParamIdx)
2147 LateMethod->DefaultArgs.push_back(LateParsedDefaultArgument(
2176 if (II == Ident_override)
2179 if (II == Ident_sealed)
2182 if (II == Ident_final)
2185 if (II == Ident_GNU_final)
2196 void Parser::ParseOptionalCXX11VirtSpecifierSeq(
VirtSpecifiers &VS,
2215 const char *PrevSpec =
nullptr;
2232 ? diag::warn_cxx98_compat_override_control_keyword
2233 : diag::ext_override_control_keyword)
2242 bool Parser::isCXX11FinalKeyword()
const {
2251 bool Parser::ParseCXXMemberDeclaratorBeforeInitializer(
2253 LateParsedAttrList &LateParsedAttrs) {
2258 if (Tok.
isNot(tok::colon))
2259 ParseDeclarator(DeclaratorInfo);
2265 "don't know where identifier would go yet?");
2267 if (BitfieldSize.isInvalid())
2270 ParseOptionalCXX11VirtSpecifierSeq(
2271 VS, getCurrentClass().IsInterface,
2274 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo, VS);
2278 if (Tok.
is(tok::kw_asm)) {
2280 ExprResult AsmLabel(ParseSimpleAsm(&Loc));
2281 if (AsmLabel.isInvalid())
2289 MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs);
2293 if (BitfieldSize.isUnset() && VS.
isUnset()) {
2294 ParseOptionalCXX11VirtSpecifierSeq(
2295 VS, getCurrentClass().IsInterface,
2303 Diag(Attr->
getLoc(), diag::warn_gcc_attribute_location);
2306 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo, VS);
2312 if (!DeclaratorInfo.
hasName() && BitfieldSize.isUnset()) {
2322 void Parser::MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(
2329 ParseTypeQualifierListOpt(
2330 DS, AR_NoAttributesParsed,
false,
2331 false, llvm::function_ref<
void()>([&]() {
2340 const char *FixItName,
2342 unsigned* QualifierLoc) {
2345 if (!(
Function.TypeQuals & TypeQual)) {
2346 std::string
Name(FixItName);
2350 *QualifierLoc = SpecLoc.getRawEncoding();
2352 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")) {
2497 if (!TemplateInfo.Kind &&
2498 Tok.
isOneOf(tok::kw_static_assert, tok::kw__Static_assert)) {
2504 if (Tok.
is(tok::kw_template)) {
2505 assert(!TemplateInfo.TemplateParams &&
2506 "Nested template improperly parsed?");
2515 if (Tok.
is(tok::kw___extension__)) {
2519 return ParseCXXClassMemberDeclaration(AS, AccessAttrs,
2520 TemplateInfo, TemplateDiags);
2523 ParsedAttributesWithRange attrs(AttrFactory);
2524 ParsedAttributesWithRange FnAttrs(AttrFactory);
2526 MaybeParseCXX11Attributes(attrs);
2529 FnAttrs.addAll(attrs.
getList());
2530 FnAttrs.Range = attrs.Range;
2532 MaybeParseMicrosoftAttributes(attrs);
2534 if (Tok.
is(tok::kw_using)) {
2535 ProhibitAttributes(attrs);
2540 if (Tok.
is(tok::kw_namespace)) {
2541 Diag(UsingLoc, diag::err_using_namespace_in_class);
2548 UsingLoc, DeclEnd, AS);
2552 LateParsedAttrList CommonLateParsedAttrs;
2558 if (MalformedTypeSpec)
2561 ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC_class,
2562 &CommonLateParsedAttrs);
2570 TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate &&
2571 DiagnoseMissingSemiAfterTagDefinition(DS, AS, DSC_class,
2572 &CommonLateParsedAttrs))
2576 TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->data()
2578 TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->size() : 0);
2582 ProhibitAttributes(FnAttrs);
2586 getCurScope(), AS, DS, TemplateParams,
false, AnonRecord);
2587 DS.complete(TheDecl);
2589 Decl* decls[] = {AnonRecord, TheDecl};
2599 LateParsedAttrList LateParsedAttrs;
2604 auto TryConsumePureSpecifier = [&] (
bool AllowDefinition) {
2605 if (Tok.
isNot(tok::equal))
2610 if (Zero.isNot(tok::numeric_constant) || Zero.getLength() != 1 ||
2614 auto &
After = GetLookAheadToken(2);
2615 if (!
After.isOneOf(tok::semi, tok::comma) &&
2616 !(AllowDefinition &&
2617 After.isOneOf(tok::l_brace, tok::colon, tok::kw_try)))
2626 ExprResult BitfieldSize;
2627 bool ExpectSemi =
true;
2630 if (ParseCXXMemberDeclaratorBeforeInitializer(
2631 DeclaratorInfo, VS, BitfieldSize, LateParsedAttrs)) {
2641 TryConsumePureSpecifier(
true);
2652 if (Tok.
isOneOf(tok::l_brace, tok::colon, tok::kw_try)) {
2654 }
else if (Tok.
is(tok::equal)) {
2656 if (KW.
is(tok::kw_default))
2658 else if (KW.
is(tok::kw_delete))
2670 ProhibitAttributes(FnAttrs);
2687 diag::err_function_declared_typedef);
2694 ParseCXXInlineMethodDef(AS, AccessAttrs, DeclaratorInfo, TemplateInfo,
2698 for (
unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i) {
2699 CommonLateParsedAttrs[i]->addDecl(FunDecl);
2701 for (
unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i) {
2702 LateParsedAttrs[i]->addDecl(FunDecl);
2705 LateParsedAttrs.clear();
2708 if (Tok.
is(tok::semi))
2709 ConsumeExtraSemi(AfterMemberFunctionDefinition);
2721 bool HasStaticInitializer =
false;
2723 if (BitfieldSize.
get()) {
2724 Diag(Tok, diag::err_bitfield_member_init);
2728 if (!TryConsumePureSpecifier(
false))
2730 HasStaticInitializer =
true;
2739 HasStaticInitializer =
true;
2757 E = Ranges.end();
I !=
E; ++
I)
2758 Diag((*I).getBegin(), diag::err_attributes_not_allowed) << *
I;
2767 VS, HasInClassInit);
2770 ThisDecl ? dyn_cast<VarTemplateDecl>(ThisDecl) :
nullptr)
2773 ThisDecl = VT->getTemplatedDecl();
2775 if (ThisDecl && AccessAttrs)
2785 HasStaticInitializer =
true;
2788 if (ThisDecl && PureSpecLoc.
isValid())
2795 ? diag::warn_cxx98_compat_nonstatic_member_init
2796 : diag::ext_nonstatic_member_init);
2804 Diag(Tok, diag::err_incomplete_array_member_init);
2811 ParseCXXNonStaticMemberInitializer(ThisDecl);
2812 }
else if (HasStaticInitializer) {
2814 ExprResult Init = ParseCXXMemberInitializer(
2828 for (
unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i)
2829 CommonLateParsedAttrs[i]->addDecl(ThisDecl);
2831 for (
unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i)
2832 LateParsedAttrs[i]->addDecl(ThisDecl);
2835 DeclsInGroup.push_back(ThisDecl);
2840 HandleMemberFunctionDeclDelays(DeclaratorInfo, ThisDecl);
2842 LateParsedAttrs.clear();
2844 DeclaratorInfo.complete(ThisDecl);
2857 Diag(CommaLoc, diag::err_expected_semi_declaration)
2864 DeclaratorInfo.
clear();
2871 MaybeParseGNUAttributes(DeclaratorInfo);
2873 if (ParseCXXMemberDeclaratorBeforeInitializer(
2874 DeclaratorInfo, VS, BitfieldSize, LateParsedAttrs))
2879 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list)) {
2910 ExprResult Parser::ParseCXXMemberInitializer(
Decl *D,
bool IsFunction,
2912 assert(Tok.
isOneOf(tok::equal, tok::l_brace)
2913 &&
"Data member initializer not starting with '=' or '{'");
2918 if (Tok.
is(tok::kw_delete)) {
2933 }
else if (Tok.
is(tok::kw_default)) {
2935 Diag(Tok, diag::err_default_delete_in_multiple_declaration)
2942 if (
const auto *PD = dyn_cast_or_null<MSPropertyDecl>(D)) {
2943 Diag(Tok, diag::err_ms_property_initializer) << PD;
2946 return ParseInitializer();
2949 void Parser::SkipCXXMemberSpecification(
SourceLocation RecordLoc,
2954 assert(isCXX11FinalKeyword() &&
"not a class definition");
2959 ParsedAttributesWithRange Attrs(AttrFactory);
2960 CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc);
2965 if (Tok.
isNot(tok::colon) && Tok.
isNot(tok::l_brace))
2972 if (Tok.
is(tok::colon)) {
2975 ParsingClassDefinition ParsingDef(*
this, TagDecl,
true,
2981 ParseBaseClause(
nullptr);
2985 if (!Tok.
is(tok::l_brace)) {
2987 diag::err_expected_lbrace_after_base_specifiers);
2993 assert(Tok.
is(tok::l_brace));
3000 if (Tok.
is(tok::kw___attribute))
3001 MaybeParseGNUAttributes(Attrs);
3008 case tok::kw___if_exists:
3009 case tok::kw___if_not_exists:
3010 ParseMicrosoftIfExistsClassDeclaration(TagType, AS);
3015 ConsumeExtraSemi(InsideStruct, TagType);
3019 case tok::annot_pragma_vis:
3020 HandlePragmaVisibility();
3022 case tok::annot_pragma_pack:
3025 case tok::annot_pragma_align:
3026 HandlePragmaAlign();
3028 case tok::annot_pragma_ms_pointers_to_members:
3029 HandlePragmaMSPointersToMembers();
3031 case tok::annot_pragma_ms_pragma:
3032 HandlePragmaMSPragma();
3034 case tok::annot_pragma_ms_vtordisp:
3035 HandlePragmaMSVtorDisp();
3037 case tok::annot_pragma_dump:
3041 case tok::kw_namespace:
3043 DiagnoseUnexpectedNamespace(cast<NamedDecl>(TagDecl));
3046 case tok::kw_public:
3047 case tok::kw_protected:
3048 case tok::kw_private: {
3056 AccessAttrs.clear();
3057 MaybeParseGNUAttributes(AccessAttrs);
3062 Diag(EndLoc, diag::err_expected)
3066 Diag(EndLoc, diag::err_expected)
3077 AccessAttrs.getList())) {
3079 AccessAttrs.clear();
3085 case tok::annot_pragma_openmp:
3086 return ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, AccessAttrs, TagType,
3090 return ParseCXXClassMemberDeclaration(AS, AccessAttrs.getList());
3100 void Parser::ParseCXXMemberSpecification(
SourceLocation RecordLoc,
3102 ParsedAttributesWithRange &Attrs,
3103 unsigned TagType,
Decl *TagDecl) {
3110 "parsing struct/union/class body");
3114 bool NonNestedClass =
true;
3115 if (!ClassStack.empty()) {
3117 if (
S->isClassScope()) {
3119 NonNestedClass =
false;
3122 if (getCurrentClass().IsInterface) {
3123 Diag(RecordLoc, diag::err_invalid_member_in_interface)
3125 << (isa<NamedDecl>(TagDecl)
3126 ? cast<NamedDecl>(TagDecl)->getQualifiedNameAsString()
3143 ParsingClassDefinition ParsingDef(*
this, TagDecl, NonNestedClass,
3150 bool IsFinalSpelledSealed =
false;
3158 "not a class definition");
3163 Diag(FinalLoc, diag::err_override_control_interface)
3167 ? diag::warn_cxx98_compat_override_control_keyword
3168 : diag::ext_override_control_keyword)
3171 Diag(FinalLoc, diag::ext_ms_sealed_keyword);
3173 Diag(FinalLoc, diag::ext_warn_gnu_final);
3179 CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc);
3188 if (!Tok.
is(tok::colon) && !Tok.
is(tok::l_brace)) {
3195 if (Tok.
is(tok::colon)) {
3196 ParseBaseClause(TagDecl);
3197 if (!Tok.
is(tok::l_brace)) {
3198 bool SuggestFixIt =
false;
3202 case tok::kw_private:
3203 case tok::kw_protected:
3204 case tok::kw_public:
3207 case tok::kw_static_assert:
3211 case tok::kw_template:
3212 SuggestFixIt =
true;
3214 case tok::identifier:
3215 SuggestFixIt = isConstructorDeclarator(
true);
3218 SuggestFixIt = isCXXSimpleDeclaration(
false);
3223 Diag(BraceLoc, diag::err_expected_lbrace_after_base_specifiers);
3237 assert(Tok.
is(tok::l_brace));
3243 IsFinalSpelledSealed,
3244 T.getOpenLocation());
3254 ParsedAttributesWithRange AccessAttrs(AttrFactory);
3258 while (!tryParseMisplacedModuleImport() && Tok.
isNot(tok::r_brace) &&
3261 ParseCXXClassMemberDeclarationWithPragmas(
3262 CurAS, AccessAttrs, static_cast<DeclSpec::TST>(TagType), TagDecl);
3271 MaybeParseGNUAttributes(attrs);
3275 T.getOpenLocation(),
3276 T.getCloseLocation(),
3284 if (TagDecl && NonNestedClass) {
3290 ParseLexedAttributes(getCurrentClass());
3291 ParseLexedMethodDeclarations(getCurrentClass());
3296 ParseLexedMemberInitializers(getCurrentClass());
3297 ParseLexedMethodDefs(getCurrentClass());
3298 PrevTokLocation = SavedPrevTokLocation;
3313 void Parser::DiagnoseUnexpectedNamespace(
NamedDecl *D) {
3314 assert(Tok.
is(tok::kw_namespace));
3319 diag::err_missing_end_of_definition) << D;
3321 diag::note_missing_end_of_definition_before) << D;
3355 void Parser::ParseConstructorInitializer(
Decl *ConstructorDecl) {
3356 assert(Tok.
is(tok::colon) &&
3357 "Constructor initializer always starts with ':'");
3365 bool AnyErrors =
false;
3368 if (Tok.
is(tok::code_completion)) {
3371 return cutOffParsing();
3374 MemInitResult MemInit = ParseMemInitializer(ConstructorDecl);
3376 MemInitializers.push_back(MemInit.
get());
3380 if (Tok.
is(tok::comma))
3382 else if (Tok.
is(tok::l_brace))
3387 Tok.
isOneOf(tok::identifier, tok::coloncolon)) {
3389 Diag(Loc, diag::err_ctor_init_missing_comma)
3420 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
false);
3430 if (Tok.
is(tok::identifier)) {
3435 }
else if (Tok.
is(tok::annot_decltype)) {
3440 ParseDecltypeSpecifier(DS);
3443 ? takeTemplateIdAnnotation(Tok)
3447 AnnotateTemplateIdTokenAsType(
true);
3448 assert(Tok.
is(tok::annot_typename) &&
"template-id -> type failed");
3450 ConsumeAnnotationToken();
3452 Diag(Tok, diag::err_expected_member_or_base_name);
3459 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
3461 ExprResult InitList = ParseBraceInitializer();
3469 TemplateTypeTy, DS, IdLoc,
3470 InitList.
get(), EllipsisLoc);
3471 }
else if(Tok.
is(tok::l_paren)) {
3476 ExprVector ArgExprs;
3477 CommaLocsTy CommaLocs;
3478 if (Tok.
isNot(tok::r_paren) && ParseExpressionList(ArgExprs, CommaLocs)) {
3489 TemplateTypeTy, DS, IdLoc,
3490 T.getOpenLocation(), ArgExprs,
3491 T.getCloseLocation(), EllipsisLoc);
3495 return Diag(Tok, diag::err_expected_either) << tok::l_paren << tok::l_brace;
3497 return Diag(Tok, diag::err_expected) << tok::l_paren;
3510 Parser::tryParseExceptionSpecification(
bool Delayed,
3514 ExprResult &NoexceptExpr,
3517 ExceptionSpecTokens =
nullptr;
3521 if (Tok.
isNot(tok::kw_throw) && Tok.
isNot(tok::kw_noexcept))
3525 bool IsNoexcept = Tok.
is(tok::kw_noexcept);
3526 Token StartTok = Tok;
3530 if (!Tok.
is(tok::l_paren)) {
3533 Diag(Tok, diag::warn_cxx98_compat_noexcept_decl);
3534 NoexceptExpr =
nullptr;
3538 Diag(Tok, diag::err_expected_lparen_after) <<
"throw";
3544 ExceptionSpecTokens->push_back(StartTok);
3545 ExceptionSpecTokens->push_back(Tok);
3546 SpecificationRange.
setEnd(ConsumeParen());
3548 ConsumeAndStoreUntil(tok::r_paren, *ExceptionSpecTokens,
3551 SpecificationRange.
setEnd(ExceptionSpecTokens->back().getLocation());
3557 if (Tok.
is(tok::kw_throw)) {
3558 Result = ParseDynamicExceptionSpecification(SpecificationRange,
3560 DynamicExceptionRanges);
3561 assert(DynamicExceptions.size() == DynamicExceptionRanges.size() &&
3562 "Produced different number of exception types and ranges.");
3566 if (Tok.
isNot(tok::kw_noexcept))
3569 Diag(Tok, diag::warn_cxx98_compat_noexcept_decl);
3577 if (Tok.
is(tok::l_paren)) {
3590 NoexceptRange =
SourceRange(KeywordLoc, T.getCloseLocation());
3597 NoexceptRange =
SourceRange(KeywordLoc, KeywordLoc);
3601 SpecificationRange = NoexceptRange;
3602 Result = NoexceptType;
3606 if (Tok.
is(tok::kw_throw)) {
3607 Diag(Tok.
getLocation(), diag::err_dynamic_and_noexcept_specification);
3608 ParseDynamicExceptionSpecification(NoexceptRange, DynamicExceptions,
3609 DynamicExceptionRanges);
3612 Diag(Tok.
getLocation(), diag::err_dynamic_and_noexcept_specification);
3621 const char *
Replacement = IsNoexcept ?
"noexcept" :
"noexcept(false)";
3624 ? diag::ext_dynamic_exception_spec
3625 : diag::warn_exception_spec_deprecated)
3627 P.
Diag(Range.
getBegin(), diag::note_exception_spec_deprecated)
3647 assert(Tok.
is(tok::kw_throw) &&
"expected throw");
3651 if (T.consumeOpen()) {
3652 Diag(Tok, diag::err_expected_lparen_after) <<
"throw";
3659 if (Tok.
is(tok::ellipsis)) {
3662 Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec);
3664 SpecificationRange.
setEnd(T.getCloseLocation());
3671 while (Tok.
isNot(tok::r_paren)) {
3674 if (Tok.
is(tok::ellipsis)) {
3680 if (!Res.isInvalid())
3684 if (!Res.isInvalid()) {
3685 Exceptions.push_back(Res.get());
3686 Ranges.push_back(Range);
3694 SpecificationRange.
setEnd(T.getCloseLocation());
3696 Exceptions.empty());
3702 TypeResult Parser::ParseTrailingReturnType(
SourceRange &Range) {
3703 assert(Tok.
is(tok::arrow) &&
"expected arrow");
3714 Parser::PushParsingClass(
Decl *ClassDecl,
bool NonNestedClass,
3716 assert((NonNestedClass || !ClassStack.empty()) &&
3717 "Nested class without outer class");
3718 ClassStack.push(
new ParsingClass(ClassDecl, NonNestedClass, IsInterface));
3724 void Parser::DeallocateParsedClasses(Parser::ParsingClass *Class) {
3725 for (
unsigned I = 0, N = Class->LateParsedDeclarations.size();
I != N; ++
I)
3726 delete Class->LateParsedDeclarations[
I];
3737 assert(!ClassStack.empty() &&
"Mismatched push/pop for class parsing");
3741 ParsingClass *Victim = ClassStack.top();
3743 if (Victim->TopLevelClass) {
3746 DeallocateParsedClasses(Victim);
3749 assert(!ClassStack.empty() &&
"Missing top-level class?");
3751 if (Victim->LateParsedDeclarations.empty()) {
3756 DeallocateParsedClasses(Victim);
3763 assert(
getCurScope()->isClassScope() &&
"Nested class outside of class scope?");
3764 ClassStack.top()->LateParsedDeclarations.push_back(
new LateParsedClass(
this, Victim));
3796 case tok::pipeequal:
3797 case tok::caretequal:
3799 case tok::exclaimequal:
3805 StringRef Spelling = PP.
getSpelling(SpellingLoc, SpellingBuf);
3818 case AttributeList::AT_CarriesDependency:
3819 case AttributeList::AT_Deprecated:
3820 case AttributeList::AT_FallThrough:
3821 case AttributeList::AT_CXX11NoReturn:
3823 case AttributeList::AT_WarnUnusedResult:
3824 return !ScopeName && AttrName->
getName().equals(
"nodiscard");
3825 case AttributeList::AT_Unused:
3826 return !ScopeName && AttrName->
getName().equals(
"maybe_unused");
3852 assert(Tok.
is(tok::l_paren) &&
"Not a C++11 attribute argument list");
3865 if (ScopeName && ScopeName->
getName() ==
"gnu") {
3868 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
3875 if (ScopeName && ScopeName->
getName() ==
"clang")
3877 ParseClangAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
3881 ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
3893 Diag(LParenLoc, diag::err_attribute_requires_arguments) << AttrName;
3899 Diag(LParenLoc, diag::err_cxx11_attribute_forbids_arguments)
3934 if (Tok.
is(tok::kw_alignas)) {
3936 ParseAlignmentSpecifier(attrs, endLoc);
3940 assert(Tok.
is(tok::l_square) &&
NextToken().
is(tok::l_square)
3941 &&
"Not a C++11 attribute list");
3950 if (Tok.
is(tok::kw_using)) {
3952 ? diag::warn_cxx14_compat_using_attribute_ns
3953 : diag::ext_using_attribute_ns);
3956 CommonScopeName = TryParseCXX11AttributeIdentifier(CommonScopeLoc);
3957 if (!CommonScopeName) {
3965 llvm::SmallDenseMap<IdentifierInfo*, SourceLocation, 4> SeenAttrs;
3967 while (Tok.
isNot(tok::r_square)) {
3975 AttrName = TryParseCXX11AttributeIdentifier(AttrLoc);
3982 ScopeName = AttrName;
3985 AttrName = TryParseCXX11AttributeIdentifier(AttrLoc);
3993 if (CommonScopeName) {
3995 Diag(ScopeLoc, diag::err_using_attribute_ns_conflict)
3998 ScopeName = CommonScopeName;
3999 ScopeLoc = CommonScopeLoc;
4004 bool AttrParsed =
false;
4007 !SeenAttrs.insert(std::make_pair(AttrName, AttrLoc)).second)
4008 Diag(AttrLoc, diag::err_cxx11_attribute_repeated)
4012 if (Tok.
is(tok::l_paren))
4013 AttrParsed = ParseCXX11AttributeArgs(AttrName, AttrLoc, attrs, endLoc,
4014 ScopeName, ScopeLoc);
4023 Diag(Tok, diag::err_cxx11_attribute_forbids_ellipsis)
4027 if (ExpectAndConsume(tok::r_square))
4031 if (ExpectAndConsume(tok::r_square))
4039 void Parser::ParseCXX11Attributes(ParsedAttributesWithRange &attrs,
4048 ParseCXX11AttributeSpecifier(attrs, endLoc);
4049 }
while (isCXX11AttributeSpecifier());
4054 void Parser::DiagnoseAndSkipCXX11Attributes() {
4061 Diag(StartLoc, diag::err_attributes_not_allowed)
4069 if (!isCXX11AttributeSpecifier())
4073 if (Tok.
is(tok::l_square)) {
4077 EndLoc = T.getCloseLocation();
4079 assert(Tok.
is(tok::kw_alignas) &&
"not an attribute specifier");
4082 if (!T.consumeOpen())
4084 EndLoc = T.getCloseLocation();
4086 }
while (isCXX11AttributeSpecifier());
4093 assert(Tok.
is(tok::identifier) &&
"Not a Microsoft attribute list");
4095 assert(UuidIdent->getName() ==
"uuid" &&
"Not a Microsoft attribute list");
4102 if (T.consumeOpen()) {
4103 Diag(Tok, diag::err_expected) << tok::l_paren;
4108 if (Tok.
is(tok::string_literal)) {
4110 ExprResult StringResult = ParseStringLiteralExpression();
4113 ArgExprs.push_back(StringResult.
get());
4130 while (Tok.
isNot(tok::r_paren)) {
4132 Diag(Tok, diag::err_attribute_uuid_malformed_guid);
4137 SpellingBuffer.resize(Tok.
getLength() + 1);
4139 StringRef TokSpelling = PP.
getSpelling(Tok, SpellingBuffer, &Invalid);
4144 StrBuffer += TokSpelling;
4150 Diag(Tok, diag::err_attribute_uuid_malformed_guid);
4160 Toks[0].
setKind(tok::string_literal);
4166 ArgExprs.push_back(UuidString);
4169 if (!T.consumeClose()) {
4186 assert(Tok.
is(tok::l_square) &&
"Not a Microsoft attribute list");
4196 if (Tok.
isNot(tok::identifier))
4199 ParseMicrosoftUuidAttributeArgs(attrs);
4206 *endLoc = T.getCloseLocation();
4207 }
while (Tok.
is(tok::l_square));
4210 void Parser::ParseMicrosoftIfExistsClassDeclaration(
DeclSpec::TST TagType,
4212 IfExistsCondition
Result;
4213 if (ParseMicrosoftIfExistsCondition(Result))
4217 if (Braces.consumeOpen()) {
4218 Diag(Tok, diag::err_expected) << tok::l_brace;
4222 switch (Result.Behavior) {
4228 Diag(Result.KeywordLoc, diag::warn_microsoft_dependent_exists)
4229 << Result.IsIfExists;
4238 while (Tok.
isNot(tok::r_brace) && !isEofOrEom()) {
4240 if (Tok.
isOneOf(tok::kw___if_exists, tok::kw___if_not_exists)) {
4241 ParseMicrosoftIfExistsClassDeclaration((
DeclSpec::TST)TagType, CurAS);
4246 if (Tok.
is(tok::semi)) {
4247 ConsumeExtraSemi(InsideStruct, TagType);
4257 if (Tok.
is(tok::colon))
4260 Diag(Tok, diag::err_expected) << tok::colon;
4266 ParseCXXClassMemberDeclaration(CurAS,
nullptr);
4269 Braces.consumeClose();
MutableArrayRef< TemplateParameterList * > MultiTemplateParamsArg
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
SourceManager & getSourceManager() const
SourceLocation getCloseLocation() const
Defines the clang::ASTContext interface.
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
TypeResult ActOnDependentTag(Scope *S, unsigned TagSpec, TagUseKind TUK, const CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation TagLoc, SourceLocation NameLoc)
DeclResult ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, SourceLocation ModulePrivateLoc, TemplateIdAnnotation &TemplateId, AttributeList *Attr, MultiTemplateParamsArg TemplateParameterLists, SkipBodyInfo *SkipBody=nullptr)
no exception specification
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
SourceLocation getRestrictSpecLoc() const
void clear()
Reset the contents of this Declarator.
SourceLocation getConstSpecLoc() const
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.
const LangOptions & getLangOpts() const
SourceLocation TemplateNameLoc
TemplateNameLoc - The location of the template name within the source.
bool isArrayOfUnknownBound() const
isArrayOfUnknownBound - This method returns true if the declarator is a declarator for an array of un...
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID. ...
const Scope * getParent() const
getParent - Return the scope that this is nested in.
static CharSourceRange getTokenRange(SourceRange R)
The name refers to a dependent template name:
ActionResult< Expr * > ExprResult
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
void CodeCompleteConstructorInitializer(Decl *Constructor, ArrayRef< CXXCtorInitializer * > Initializers)
Decl - This represents one declaration (or definition), e.g.
static LLVM_READONLY bool isLetter(unsigned char c)
Return true if this character is an ASCII letter: [a-zA-Z].
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.
SCS getStorageClassSpec() const
bool hasLeadingSpace() const
Return true if this token has whitespace before it.
void ActOnBaseSpecifiers(Decl *ClassDecl, MutableArrayRef< CXXBaseSpecifier * > Bases)
ActOnBaseSpecifiers - Attach the given base specifiers to the class, after checking whether there are...
The base class of the type hierarchy.
bool TryAnnotateCXXScopeToken(bool EnteringContext=false)
TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only annotates C++ scope specifiers and ...
This indicates that the scope corresponds to a function, which means that labels are set here...
std::unique_ptr< llvm::MemoryBuffer > Buffer
Declaration of a variable template.
static FixItHint CreateInsertionFromRange(SourceLocation InsertionLoc, CharSourceRange FromRange, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code from FromRange at a specific location...
static const char * getSpecifierName(DeclSpec::TST T, const PrintingPolicy &Policy)
Turn a type-specifier-type into a string like "_Bool" or "union".
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.
void SetIdentifier(IdentifierInfo *Id, SourceLocation IdLoc)
Set the name of this declarator to be the given identifier.
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
void ActOnFinishCXXNonNestedClass(Decl *D)
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.
void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context)
static const TST TST_interface
Like System, but searched after the system directories.
void setBegin(SourceLocation b)
Describes how types, statements, expressions, and declarations should be printed. ...
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...
friend class ObjCDeclContextSwitch
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed...
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
Return the 'spelling' of the token at the given location; does not go up to the spelling location or ...
bool 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.
void ActOnUninitializedDecl(Decl *dcl)
RecordDecl - Represents a struct/union/class.
Decl * ActOnAliasDeclaration(Scope *CurScope, AccessSpecifier AS, MultiTemplateParamsArg TemplateParams, SourceLocation UsingLoc, UnqualifiedId &Name, AttributeList *AttrList, TypeResult Type, Decl *DeclFromDeclSpec)
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
bool TryConsumeToken(tok::TokenKind Expected)
__ptr16, alignas(...), etc.
One of these records is kept for each identifier that is lexed.
Decl * ActOnNamespaceAliasDef(Scope *CurScope, SourceLocation NamespaceLoc, SourceLocation AliasLoc, IdentifierInfo *Alias, CXXScopeSpec &SS, SourceLocation IdentLoc, IdentifierInfo *Ident)
AttributeList * getList() const
void ActOnTagStartDefinition(Scope *S, Decl *TagDecl)
ActOnTagStartDefinition - Invoked when we have entered the scope of a tag's definition (e...
BaseResult ActOnBaseSpecifier(Decl *classdecl, SourceRange SpecifierRange, ParsedAttributes &Attrs, bool Virtual, AccessSpecifier Access, ParsedType basetype, SourceLocation BaseLoc, SourceLocation EllipsisLoc)
ActOnBaseSpecifier - Parsed a base specifier.
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.
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.
void setKind(tok::TokenKind K)
SourceLocation getFirstLocation() const
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)
void ClearStorageClassSpecs()
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
DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef< Decl * > Group)
BuildDeclaratorGroup - convert a list of declarations into a declaration group, performing any necess...
const TargetInfo & getTargetInfo() const
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.
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
Decl * ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc, AttributeList *Attr, AccessSpecifier AS, SourceLocation ModulePrivateLoc, MultiTemplateParamsArg TemplateParameterLists, bool &OwnedDecl, bool &IsDependent, SourceLocation ScopedEnumKWLoc, bool ScopedEnumUsesClassTag, TypeResult UnderlyingType, bool IsTypeSpecifier, bool IsTemplateParamOrArg, SkipBodyInfo *SkipBody=nullptr)
This is invoked when we see 'struct foo' or 'struct {'.
Microsoft throw(...) extension.
bool ActOnDuplicateDefinition(DeclSpec &DS, Decl *Prev, SkipBodyInfo &SkipBody)
Perform ODR-like check for C/ObjC when merging tag types from modules.
void takeAllFrom(ParsedAttributes &attrs)
ParsedTemplateArgument * getTemplateArgs()
Retrieves a pointer to the template arguments.
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...
tok::TokenKind getKind() const
void CodeCompleteFunctionQualifiers(DeclSpec &DS, Declarator &D, const VirtSpecifiers *VS=nullptr)
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
void setInvalid(bool b=true) const
detail::InMemoryDirectory::const_iterator I
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL, bool IncludeCXX11Attributes=true)
ProcessDeclAttributeList - Apply all the decl attributes in the specified attribute list to the speci...
SourceRange getRange() const
SourceLocation TemplateKWLoc
TemplateKWLoc - The location of the template keyword.
ParsingClassState PushParsingClass()
SourceLocation LAngleLoc
The location of the '<' before the template argument list.
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
A little helper class used to produce diagnostics.
TemplateParameterList * ActOnTemplateParameterList(unsigned Depth, SourceLocation ExportLoc, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< Decl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
ActOnTemplateParameterList - Builds a TemplateParameterList, optionally constrained by RequiresClause...
TST getTypeSpecType() const
SourceLocation getModulePrivateSpecLoc() const
void ActOnFinishCXXMemberDecls()
Perform any semantic analysis which needs to be delayed until all pending class member declarations h...
A class for parsing a declarator.
void SetRangeStart(SourceLocation Loc)
SourceLocation getFriendSpecLoc() const
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
TypeResult ParseTypeName(SourceRange *Range=nullptr, Declarator::TheContext Context=Declarator::TypeNameContext, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName type-name: [C99 6.7.6] specifier-qualifier-list abstract-declarator[opt].
unsigned getTypeQualifiers() const
getTypeQualifiers - Return a set of TQs.
Decl * ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, Expr *AssertExpr, Expr *AssertMessageExpr, SourceLocation RParenLoc)
Expr - This represents one expression.
StringRef getName() const
Return the actual identifier string.
Decl * ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, RecordDecl *&AnonRecord)
ParsedFreeStandingDeclSpec - This method is invoked when a declspec with no declarator (e...
static bool IsBuiltInOrStandardCXX11Attribute(IdentifierInfo *AttrName, IdentifierInfo *ScopeName)
Represents a character-granular source range.
bool isDeclarationOfFunction() const
Determine whether the declaration that will be produced from this declaration will be a function...
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...
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.
void setAsmLabel(Expr *E)
SourceLocation getVolatileSpecLoc() const
bool ActOnAccessSpecifier(AccessSpecifier Access, SourceLocation ASLoc, SourceLocation ColonLoc, AttributeList *Attrs=nullptr)
ActOnAccessSpecifier - Parsed an access specifier followed by a colon.
Decl * ActOnFinishExportDecl(Scope *S, Decl *ExportDecl, SourceLocation RBraceLoc)
Complete the definition of an export declaration.
Represents a C++ template name within the type system.
bool isPastIdentifier() const
isPastIdentifier - Return true if we have parsed beyond the point where the name would appear...
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7)...
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
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.
bool isNot(tok::TokenKind K) const
InClassInitStyle
In-class initialization styles for non-static data members.
ParsedType getInheritingConstructorName(CXXScopeSpec &SS, SourceLocation NameLoc, IdentifierInfo &Name)
Handle the result of the special case name lookup for inheriting constructor declarations.
ExceptionSpecificationType getExceptionSpecType() const
Get the type of exception specification this function has.
The result type of a method or function.
void CodeCompleteNamespaceDecl(Scope *S)
SourceLocation getAnnotationEndLoc() const
ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, SourceLocation EllipsisLoc)
Invoked when parsing a template argument followed by an ellipsis, which creates a pack expansion...
const clang::PrintingPolicy & getPrintingPolicy() const
PrettyDeclStackTraceEntry - If a crash occurs in the parser while parsing something related to a decl...
void ActOnFinishCXXMemberSpecification(Scope *S, SourceLocation RLoc, Decl *TagDecl, SourceLocation LBrac, SourceLocation RBrac, AttributeList *AttrList)
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.
Stop skipping at semicolon.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Encodes a location in the source.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, SourceRange BraceRange)
ActOnTagFinishDefinition - Invoked once we have finished parsing the definition of a tag (enumeration...
Decl * ActOnFinishLinkageSpecification(Scope *S, Decl *LinkageSpec, SourceLocation RBraceLoc)
ActOnFinishLinkageSpecification - Complete the definition of the C++ linkage specification LinkageSpe...
void setLength(unsigned Len)
Specifier getLastSpecifier() const
Expr * getRepAsExpr() const
void FinalizeDeclaration(Decl *D)
FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform any semantic actions neces...
bool isValid() const
Return true if this is a valid SourceLocation object.
TagDecl - Represents the declaration of a struct/union/class/enum.
ASTContext & getASTContext() const
static const TST TST_union
void setAnnotationEndLoc(SourceLocation L)
IdentifierTable & getIdentifierTable()
Scope * getCurScope() const
bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const
Return true if we have an ObjC keyword identifier.
ExtensionRAIIObject - This saves the state of extension warnings when constructed and disables them...
bool isInvalid() const
An error occurred during parsing of the scope specifier.
bool isTemplateParamScope() const
isTemplateParamScope - Return true if this scope is a C++ template parameter scope.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Decl * ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc, unsigned TagSpec, SourceLocation TagLoc, CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc, AttributeList *Attr, MultiTemplateParamsArg TempParamLists)
Handle a friend tag declaration where the scope specifier was templated.
Direct list-initialization.
Represents a C++11 virt-specifier-seq.
SourceLocation getBegin() const
Decl * ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc, SourceLocation LBraceLoc)
We have parsed the start of an export declaration, including the '{' (if present).
SourceLocation getBeginLoc() const
FunctionDefinitionKind
Described the kind of function definition (if any) provided for a function.
Decl * ActOnUsingDeclaration(Scope *CurScope, AccessSpecifier AS, SourceLocation UsingLoc, SourceLocation TypenameLoc, CXXScopeSpec &SS, UnqualifiedId &Name, SourceLocation EllipsisLoc, AttributeList *AttrList)
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)) {...
void ActOnMemInitializers(Decl *ConstructorDecl, SourceLocation ColonLoc, ArrayRef< CXXCtorInitializer * > MemInits, bool AnyErrors)
ActOnMemInitializers - Handle the member initializers for a constructor.
ExprResult ParseConstantExpressionInExprEvalContext(TypeCastState isTypeCast=NotTypeCast)
void setFunctionDefinitionKind(FunctionDefinitionKind Val)
Decl * ActOnUsingDirective(Scope *CurScope, SourceLocation UsingLoc, SourceLocation NamespcLoc, CXXScopeSpec &SS, SourceLocation IdentLoc, IdentifierInfo *NamespcName, AttributeList *AttrList)
TypeResult ActOnTagTemplateIdType(TagUseKind TUK, TypeSpecifierType TagSpec, SourceLocation TagLoc, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, TemplateTy TemplateD, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgsIn, SourceLocation RAngleLoc)
Parsed an elaborated-type-specifier that refers to a template-id, such as class T::template apply<U>...
SourceLocation getOpenLocation() const
The scope of a struct/union/class definition.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
static const TST TST_decltype_auto
SmallVector< Token, 4 > CachedTokens
A set of tokens that has been cached for later parsing.
static const TST TST_decltype
bool isFriendSpecified() const
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.
bool isInvalidDecl() const
void CodeCompleteTag(Scope *S, unsigned TagSpec)
bool hasTagDefinition() const
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
detail::InMemoryDirectory::const_iterator E
void ProcessDeclAttributeDelayed(Decl *D, const AttributeList *AttrList)
bool hasName() const
hasName - Whether this declarator has a name, which might be an identifier (accessible via getIdentif...
void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl, SourceLocation FinalLoc, bool IsFinalSpelledSealed, SourceLocation LBraceLoc)
ActOnStartCXXMemberDeclarations - Invoked when we have parsed a C++ record definition's base-specifie...
The name refers to a template whose specialization produces a type.
void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit)
AddInitializerToDecl - Adds the initializer Init to the declaration dcl.
void CodeCompleteNamespaceAliasDecl(Scope *S)
void setLiteralData(const char *Ptr)
void CodeCompleteUsingDirective(Scope *S)
Decl * ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc, SourceLocation NamespaceLoc, SourceLocation IdentLoc, IdentifierInfo *Ident, SourceLocation LBrace, AttributeList *AttrList, UsingDirectiveDecl *&UsingDecl)
ActOnStartNamespaceDef - This is called at the start of a namespace definition.
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
bool SetSpecifier(Specifier VS, SourceLocation Loc, const char *&PrevSpec)
void ActOnTagDefinitionError(Scope *S, Decl *TagDecl)
ActOnTagDefinitionError - Invoked when there was an unrecoverable error parsing the definition of a t...
void takeAttributesFrom(ParsedAttributes &attrs)
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
bool isKnownToGCC() const
unsigned getMaxArgs() const
NamedDecl * ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D, MultiTemplateParamsArg TemplateParameterLists, Expr *BitfieldWidth, const VirtSpecifiers &VS, InClassInitStyle InitStyle)
ActOnCXXMemberDeclarator - This is invoked when a C++ class member declarator is parsed.
static const TST TST_typename
void SetRangeEnd(SourceLocation Loc)
SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.
DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, ArrayRef< Decl * > Group)
DeclResult ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc, SourceLocation TemplateLoc, unsigned TagSpec, SourceLocation KWLoc, const CXXScopeSpec &SS, TemplateTy Template, SourceLocation TemplateNameLoc, SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc, AttributeList *Attr)
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
ActionResult< ParsedType > TypeResult
SourceLocation getLoc() const
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
A template-id, e.g., f<int>.
SmallVector< TemplateParameterList *, 4 > TemplateParameterLists
CXXScopeSpec & getTypeSpecScope()
AttributeList * addNew(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ArgsUnion *args, unsigned numArgs, AttributeList::Syntax syntax, SourceLocation ellipsisLoc=SourceLocation())
Add attribute with expression arguments.
This is a scope that can contain a declaration.
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
void getCXX11AttributeRanges(SmallVectorImpl< SourceRange > &Ranges)
Return a source range list of C++11 attributes associated with the declarator.
bool isCXX11Attribute() const
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".
SourceLocation getIdentifierLoc() const
void setEnd(SourceLocation e)
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
void ActOnPureSpecifier(Decl *D, SourceLocation PureSpecLoc)
void PopParsingClass(ParsingClassState state)
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, llvm::function_ref< ExprResult(Expr *)> Filter=[](Expr *E) -> ExprResult{return E;})
Process any TypoExprs in the given Expr and its children, generating diagnostics as appropriate and r...
static 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.
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.
MemInitResult ActOnMemInitializer(Decl *ConstructorD, Scope *S, CXXScopeSpec &SS, IdentifierInfo *MemberOrBase, ParsedType TemplateTypeTy, const DeclSpec &DS, SourceLocation IdLoc, SourceLocation LParenLoc, ArrayRef< Expr * > Args, SourceLocation RParenLoc, SourceLocation EllipsisLoc)
Handle a C++ member initializer using parentheses syntax.
static OpaquePtr make(PtrTy P)
bool isSet() const
Deprecated.
unsigned getLength() const
ExprResult ActOnStringLiteral(ArrayRef< Token > StringToks, Scope *UDLScope=nullptr)
ActOnStringLiteral - The specified tokens were lexed as pasted string fragments (e.g.
static const TST TST_struct
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD)
Invoked when we enter a tag definition that we're skipping.
void setLocation(SourceLocation L)
AttributeList * getNext() const
A trivial tuple used to represent a source range.
SourceLocation getLocation() const
ExprResult CheckBooleanCondition(SourceLocation Loc, Expr *E, bool IsConstexpr=false)
CheckBooleanCondition - Diagnose problems involving the use of the given expression as a boolean cond...
NamedDecl - This represents a decl with a name.
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
Represents C++ using-directive.
unsigned NumArgs
NumArgs - The number of template arguments.
void SetRangeEnd(SourceLocation Loc)
ParsedAttributes - A collection of parsed attributes.
SourceLocation ColonLoc
Location of ':'.
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
void setCommaLoc(SourceLocation CL)
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...
Attr - This represents one attribute.
void startToken()
Reset all flags to cleared.
ParsedTemplateTy Template
The declaration of the template corresponding to the template-name.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
AttributeList - Represents a syntactic attribute.
bool isBacktrackEnabled() const
True if EnableBacktrackAtThisPos() was called and caching of tokens is on.
Stop skipping at specified token, but don't skip the token itself.
NamedDecl * ActOnFriendFunctionDecl(Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParams)
IdentifierInfo * getIdentifierInfo() const
const AttributeList * getAttributes() const