32#include "llvm/Support/TimeProfiler.h"
40 assert(Tok.is(tok::kw_namespace) &&
"Not a namespace!");
42 ObjCDeclContextSwitch ObjCDC(*
this);
44 if (Tok.is(tok::code_completion)) {
46 Actions.CodeCompletion().CodeCompleteNamespaceDecl(
getCurScope());
50 SourceLocation IdentLoc;
51 IdentifierInfo *Ident =
nullptr;
52 InnerNamespaceInfoList ExtraNSs;
53 SourceLocation FirstNestedInlineLoc;
55 ParsedAttributes attrs(AttrFactory);
57 while (MaybeParseGNUAttributes(attrs) || isAllowedCXX11AttributeSpecifier()) {
58 if (isAllowedCXX11AttributeSpecifier()) {
61 ? diag::warn_cxx14_compat_ns_enum_attribute
62 : diag::ext_ns_enum_attribute)
64 ParseCXX11Attributes(attrs);
68 if (Tok.is(tok::identifier)) {
69 Ident = Tok.getIdentifierInfo();
71 while (Tok.is(tok::coloncolon) &&
76 InnerNamespaceInfo Info;
79 if (Tok.is(tok::kw_inline)) {
82 FirstNestedInlineLoc = Info.InlineLoc;
85 Info.Ident = Tok.getIdentifierInfo();
88 ExtraNSs.push_back(Info);
92 DiagnoseAndSkipCXX11Attributes();
93 MaybeParseGNUAttributes(attrs);
94 DiagnoseAndSkipCXX11Attributes();
96 SourceLocation attrLoc = attrs.Range.getBegin();
99 if (!ExtraNSs.empty() && attrLoc.
isValid())
100 Diag(attrLoc, diag::err_unexpected_nested_namespace_attribute);
102 if (Tok.is(tok::equal)) {
104 Diag(Tok, diag::err_expected) << tok::identifier;
109 if (!ExtraNSs.empty()) {
110 Diag(ExtraNSs.front().NamespaceLoc,
111 diag::err_unexpected_qualified_namespace_alias)
112 << SourceRange(ExtraNSs.front().NamespaceLoc,
113 ExtraNSs.back().IdentLoc);
118 Diag(attrLoc, diag::err_unexpected_namespace_attributes_alias);
120 Diag(InlineLoc, diag::err_inline_namespace_alias)
122 Decl *NSAlias = ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd);
123 return Actions.ConvertDeclToDeclGroup(NSAlias);
127 if (
T.consumeOpen()) {
129 Diag(Tok, diag::err_expected) << tok::l_brace;
131 Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace;
138 Diag(
T.getOpenLocation(), diag::err_namespace_nonnamespace_scope);
143 if (ExtraNSs.empty()) {
145 }
else if (InlineLoc.
isValid()) {
146 Diag(InlineLoc, diag::err_inline_nested_namespace_definition);
148 Diag(ExtraNSs[0].NamespaceLoc,
149 diag::warn_cxx14_compat_nested_namespace_definition);
150 if (FirstNestedInlineLoc.
isValid())
151 Diag(FirstNestedInlineLoc,
152 diag::warn_cxx17_compat_inline_nested_namespace_definition);
154 Diag(ExtraNSs[0].NamespaceLoc,
155 diag::warn_cxx14_compat_nested_namespace_definition);
156 if (FirstNestedInlineLoc.
isValid())
157 Diag(FirstNestedInlineLoc, diag::ext_inline_nested_namespace_definition);
159 TentativeParsingAction TPA(*
this);
161 Token rBraceToken = Tok;
164 if (!rBraceToken.
is(tok::r_brace)) {
165 Diag(ExtraNSs[0].NamespaceLoc, diag::ext_nested_namespace_definition)
166 << SourceRange(ExtraNSs.front().NamespaceLoc,
167 ExtraNSs.back().IdentLoc);
169 std::string NamespaceFix;
170 for (
const auto &ExtraNS : ExtraNSs) {
171 NamespaceFix +=
" { ";
172 if (ExtraNS.InlineLoc.isValid())
173 NamespaceFix +=
"inline ";
174 NamespaceFix +=
"namespace ";
175 NamespaceFix += ExtraNS.Ident->getName();
179 for (
unsigned i = 0, e = ExtraNSs.size(); i != e; ++i)
182 Diag(ExtraNSs[0].NamespaceLoc, diag::ext_nested_namespace_definition)
184 SourceRange(ExtraNSs.front().NamespaceLoc,
185 ExtraNSs.back().IdentLoc),
191 if (FirstNestedInlineLoc.
isValid())
192 Diag(FirstNestedInlineLoc, diag::ext_inline_nested_namespace_definition);
198 ? diag::warn_cxx98_compat_inline_namespace
199 : diag::ext_inline_namespace);
204 UsingDirectiveDecl *ImplicitUsingDirectiveDecl =
nullptr;
205 Decl *NamespcDecl = Actions.ActOnStartNamespaceDef(
206 getCurScope(), InlineLoc, NamespaceLoc, IdentLoc, Ident,
207 T.getOpenLocation(), attrs, ImplicitUsingDirectiveDecl,
false);
209 PrettyDeclStackTraceEntry CrashInfo(Actions.Context, NamespcDecl,
210 NamespaceLoc,
"parsing namespace");
214 ParseInnerNamespace(ExtraNSs, 0, InlineLoc, attrs,
T);
217 NamespaceScope.Exit();
219 DeclEnd =
T.getCloseLocation();
220 Actions.ActOnFinishNamespaceDef(NamespcDecl, DeclEnd);
222 return Actions.ConvertDeclToDeclGroup(NamespcDecl,
223 ImplicitUsingDirectiveDecl);
226void Parser::ParseInnerNamespace(
const InnerNamespaceInfoList &InnerNSs,
230 if (index == InnerNSs.size()) {
231 while (!tryParseMisplacedModuleImport() && Tok.isNot(tok::r_brace) &&
232 Tok.isNot(tok::eof)) {
233 ParsedAttributes DeclAttrs(AttrFactory);
234 MaybeParseCXX11Attributes(DeclAttrs);
235 ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
236 ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs);
250 UsingDirectiveDecl *ImplicitUsingDirectiveDecl =
nullptr;
251 Decl *NamespcDecl = Actions.ActOnStartNamespaceDef(
252 getCurScope(), InnerNSs[index].InlineLoc, InnerNSs[index].NamespaceLoc,
253 InnerNSs[index].IdentLoc, InnerNSs[index].Ident,
255 assert(!ImplicitUsingDirectiveDecl &&
256 "nested namespace definition cannot define anonymous namespace");
258 ParseInnerNamespace(InnerNSs, ++index, InlineLoc, attrs, Tracker);
260 NamespaceScope.Exit();
268 assert(Tok.is(tok::equal) &&
"Not equal token");
272 if (Tok.is(tok::code_completion)) {
274 Actions.CodeCompletion().CodeCompleteNamespaceAliasDecl(
getCurScope());
280 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
288 if (Tok.isNot(tok::identifier)) {
289 Diag(Tok, diag::err_expected_namespace_name);
303 IdentifierInfo *Ident = Tok.getIdentifierInfo();
307 DeclEnd = Tok.getLocation();
308 if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after_namespace_name))
311 return Actions.ActOnNamespaceAliasDef(
getCurScope(), NamespaceLoc, AliasLoc,
312 Alias, SS, IdentLoc, Ident);
316 assert(isTokenStringLiteral() &&
"Not a string literal!");
323 : Actions.ActOnStartLinkageSpecification(
325 Tok.is(tok::l_brace) ? Tok.getLocation() : SourceLocation());
327 ParsedAttributes DeclAttrs(AttrFactory);
328 ParsedAttributes DeclSpecAttrs(AttrFactory);
330 while (MaybeParseCXX11Attributes(DeclAttrs) ||
331 MaybeParseGNUAttributes(DeclSpecAttrs))
334 if (Tok.isNot(tok::l_brace)) {
341 ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs, &DS);
342 return LinkageSpec ? Actions.ActOnFinishLinkageSpecification(
349 ProhibitAttributes(DeclAttrs);
354 unsigned NestedModules = 0;
356 switch (Tok.getKind()) {
357 case tok::annot_module_begin:
362 case tok::annot_module_end:
369 case tok::annot_module_include:
381 ParsedAttributes DeclAttrs(AttrFactory);
382 ParsedAttributes DeclSpecAttrs(AttrFactory);
383 while (MaybeParseCXX11Attributes(DeclAttrs) ||
384 MaybeParseGNUAttributes(DeclSpecAttrs))
386 ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs);
394 return LinkageSpec ? Actions.ActOnFinishLinkageSpecification(
399Decl *Parser::ParseExportDeclaration() {
400 assert(Tok.is(tok::kw_export));
403 if (Tok.is(tok::code_completion)) {
405 Actions.CodeCompletion().CodeCompleteOrdinaryName(
413 Decl *ExportDecl = Actions.ActOnStartExportDecl(
415 Tok.is(tok::l_brace) ? Tok.getLocation() : SourceLocation());
417 if (Tok.isNot(tok::l_brace)) {
419 ParsedAttributes DeclAttrs(AttrFactory);
420 MaybeParseCXX11Attributes(DeclAttrs);
421 ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
422 ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs);
423 return Actions.ActOnFinishExportDecl(
getCurScope(), ExportDecl,
430 while (!tryParseMisplacedModuleImport() && Tok.isNot(tok::r_brace) &&
431 Tok.isNot(tok::eof)) {
432 ParsedAttributes DeclAttrs(AttrFactory);
433 MaybeParseCXX11Attributes(DeclAttrs);
434 ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
435 ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs);
439 return Actions.ActOnFinishExportDecl(
getCurScope(), ExportDecl,
440 T.getCloseLocation());
446 assert(Tok.is(tok::kw_using) &&
"Not using token");
447 ObjCDeclContextSwitch ObjCDC(*
this);
452 if (Tok.is(tok::code_completion)) {
454 Actions.CodeCompletion().CodeCompleteUsing(
getCurScope());
459 while (Tok.is(tok::kw_template)) {
461 Diag(TemplateLoc, diag::err_unexpected_template_after_using)
466 if (Tok.is(tok::kw_namespace)) {
469 SourceRange
R = TemplateInfo.getSourceRange();
470 Diag(UsingLoc, diag::err_templated_using_directive_declaration)
474 Decl *UsingDir = ParseUsingDirective(Context, UsingLoc, DeclEnd, Attrs);
475 return Actions.ConvertDeclToDeclGroup(UsingDir);
479 return ParseUsingDeclaration(Context, TemplateInfo, UsingLoc, DeclEnd, Attrs,
487 assert(Tok.is(tok::kw_namespace) &&
"Not 'namespace' token");
492 if (Tok.is(tok::code_completion)) {
494 Actions.CodeCompletion().CodeCompleteUsingDirective(
getCurScope());
500 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
508 IdentifierInfo *NamespcName =
nullptr;
509 SourceLocation IdentLoc = SourceLocation();
512 if (Tok.isNot(tok::identifier)) {
513 Diag(Tok, diag::err_expected_namespace_name);
528 NamespcName = Tok.getIdentifierInfo();
532 bool GNUAttr =
false;
533 if (Tok.is(tok::kw___attribute)) {
535 ParseGNUAttributes(attrs);
539 DeclEnd = Tok.getLocation();
540 if (ExpectAndConsume(tok::semi,
541 GNUAttr ? diag::err_expected_semi_after_attribute_list
542 : diag::err_expected_semi_after_namespace_name))
545 return Actions.ActOnUsingDirective(
getCurScope(), UsingLoc, NamespcLoc, SS,
546 IdentLoc, NamespcName, attrs);
550 UsingDeclarator &D) {
557 if (Tok.is(tok::kw___super)) {
558 Diag(Tok.getLocation(), diag::err_super_in_using_declaration);
563 const IdentifierInfo *LastII =
nullptr;
564 if (ParseOptionalCXXScopeSpecifier(D.SS,
nullptr,
574 if (D.SS.isInvalid())
588 Tok.is(tok::identifier) &&
593 D.SS.isNotEmpty() && LastII == Tok.getIdentifierInfo() &&
597 Actions.getInheritingConstructorName(D.SS, IdLoc, *LastII);
598 D.Name.setConstructorName(
Type, IdLoc, IdLoc);
605 !(Tok.is(tok::identifier) &&
NextToken().
is(tok::equal)),
606 false,
nullptr, D.Name))
612 ? diag::warn_cxx17_compat_using_declaration_pack
613 : diag::ext_using_declaration_pack);
622 SourceLocation UELoc;
629 ? diag::warn_cxx17_compat_using_enum_declaration
630 : diag::ext_using_enum_declaration);
632 DiagnoseCXX11AttributeExtension(PrefixAttrs);
635 SourceRange
R = TemplateInfo.getSourceRange();
636 Diag(UsingLoc, diag::err_templated_using_directive_declaration)
642 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
654 if (Tok.is(tok::code_completion)) {
656 Actions.CodeCompletion().CodeCompleteUsing(
getCurScope());
664 if (Tok.is(tok::identifier)) {
665 IdentifierInfo *IdentInfo = Tok.getIdentifierInfo();
674 UED = Actions.ActOnUsingEnumDeclaration(
676 }
else if (Tok.is(tok::annot_template_id)) {
677 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
683 assert(Tok.is(tok::annot_typename) &&
"template-id -> type failed");
685 SourceRange Loc = Tok.getAnnotationRange();
686 ConsumeAnnotationToken();
688 UED = Actions.ActOnUsingEnumDeclaration(
getCurScope(), AS, UsingLoc,
689 UELoc, Loc, *TemplateId->
Name,
692 Diag(Tok.getLocation(), diag::err_using_enum_not_enum)
697 Diag(Tok.getLocation(), diag::err_using_enum_expect_identifier)
698 << Tok.is(tok::kw_enum);
708 DeclEnd = Tok.getLocation();
709 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
710 "using-enum declaration"))
713 return Actions.ConvertDeclToDeclGroup(UED);
718 ParsedAttributes MisplacedAttrs(AttrFactory);
719 MaybeParseCXX11Attributes(MisplacedAttrs);
721 if (InInitStatement && Tok.isNot(tok::identifier))
725 bool InvalidDeclarator = ParseUsingDeclarator(Context, D);
727 ParsedAttributes Attrs(AttrFactory);
728 MaybeParseAttributes(PAKM_GNU | PAKM_CXX11, Attrs);
732 if (MisplacedAttrs.Range.isValid()) {
734 MisplacedAttrs.empty() ?
nullptr : &MisplacedAttrs.front();
735 auto &
Range = MisplacedAttrs.Range;
736 (FirstAttr && FirstAttr->isRegularKeywordAttribute()
737 ?
Diag(
Range.getBegin(), diag::err_keyword_not_allowed) << FirstAttr
738 :
Diag(
Range.getBegin(), diag::err_attributes_not_allowed))
746 if (Tok.is(tok::equal) || InInitStatement) {
747 if (InvalidDeclarator) {
752 ProhibitAttributes(PrefixAttrs);
754 Decl *DeclFromDeclSpec =
nullptr;
760 Decl *AD = ParseAliasDeclarationAfterDeclarator(
761 TemplateInfo, UsingLoc, D, DeclEnd, AS, Attrs, &DeclFromDeclSpec);
766 return Actions.ConvertDeclToDeclGroup(AD, DeclFromDeclSpec);
769 DiagnoseCXX11AttributeExtension(PrefixAttrs);
775 SourceRange
R = TemplateInfo.getSourceRange();
776 Diag(UsingLoc, diag::err_templated_using_directive_declaration)
785 SmallVector<Decl *, 8> DeclsInGroup;
788 MaybeParseAttributes(PAKM_GNU | PAKM_CXX11, Attrs);
789 DiagnoseCXX11AttributeExtension(Attrs);
792 if (InvalidDeclarator)
797 if (D.TypenameLoc.isValid() &&
799 Diag(D.Name.getSourceRange().getBegin(),
800 diag::err_typename_identifiers_only)
803 D.TypenameLoc = SourceLocation();
807 D.TypenameLoc, D.SS, D.Name,
808 D.EllipsisLoc, Attrs);
810 DeclsInGroup.push_back(UD);
818 InvalidDeclarator = ParseUsingDeclarator(Context, D);
821 if (DeclsInGroup.size() > 1)
822 Diag(Tok.getLocation(),
824 ? diag::warn_cxx17_compat_multi_using_declaration
825 : diag::ext_multi_using_declaration);
828 DeclEnd = Tok.getLocation();
829 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
830 !Attrs.
empty() ?
"attributes list"
831 : UELoc.
isValid() ?
"using-enum declaration"
832 :
"using declaration"))
835 return Actions.BuildDeclaratorGroup(DeclsInGroup);
838Decl *Parser::ParseAliasDeclarationAfterDeclarator(
842 if (ExpectAndConsume(tok::equal)) {
848 ? diag::warn_cxx98_compat_alias_declaration
849 : diag::ext_alias_declaration);
860 if (SpecKind != -1) {
863 Range = SourceRange(D.Name.TemplateId->LAngleLoc,
864 D.Name.TemplateId->RAngleLoc);
866 Range = TemplateInfo.getSourceRange();
867 Diag(
Range.getBegin(), diag::err_alias_declaration_specialization)
868 << SpecKind <<
Range;
875 Diag(D.Name.StartLocation, diag::err_alias_declaration_not_identifier);
879 }
else if (D.TypenameLoc.isValid())
880 Diag(D.TypenameLoc, diag::err_alias_declaration_not_identifier)
882 SourceRange(D.TypenameLoc, D.SS.isNotEmpty() ? D.SS.getEndLoc()
884 else if (D.SS.isNotEmpty())
885 Diag(D.SS.getBeginLoc(), diag::err_alias_declaration_not_identifier)
887 if (D.EllipsisLoc.isValid())
888 Diag(D.EllipsisLoc, diag::err_alias_declaration_pack_expansion)
891 Decl *DeclFromDeclSpec =
nullptr;
896 AS, &DeclFromDeclSpec, &Attrs);
898 *OwnedType = DeclFromDeclSpec;
901 DeclEnd = Tok.getLocation();
902 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
903 !Attrs.
empty() ?
"attributes list"
904 :
"alias declaration"))
909 TemplateParams ? TemplateParams->data() :
nullptr,
910 TemplateParams ? TemplateParams->size() : 0);
911 return Actions.ActOnAliasDeclaration(
getCurScope(), AS, TemplateParamsArg,
918 if (
const auto *BO = dyn_cast_or_null<BinaryOperator>(AssertExpr)) {
919 if (BO->getOpcode() == BO_LAnd &&
927 assert(Tok.isOneOf(tok::kw_static_assert, tok::kw__Static_assert) &&
928 "Not a static_assert declaration");
931 const char *TokName = Tok.getName();
933 if (Tok.is(tok::kw__Static_assert))
934 diagnoseUseOfC11Keyword(Tok);
935 else if (Tok.is(tok::kw_static_assert)) {
938 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName();
940 Diag(Tok, diag::warn_cxx98_compat_static_assert);
946 if (
T.consumeOpen()) {
947 Diag(Tok, diag::err_expected) << tok::l_paren;
952 EnterExpressionEvaluationContext ConstantEvaluated(
955 if (AssertExpr.isInvalid()) {
961 if (Tok.is(tok::r_paren)) {
964 DiagVal = diag::warn_cxx14_compat_static_assert_no_message;
966 DiagVal = diag::ext_cxx_static_assert_no_message;
968 DiagVal = diag::warn_c17_compat_static_assert_no_message;
970 DiagVal = diag::ext_c_static_assert_no_message;
974 if (ExpectAndConsume(tok::comma)) {
979 bool ParseAsExpression =
false;
981 for (
unsigned I = 0;; ++I) {
983 if (
T.is(tok::r_paren))
986 ParseAsExpression =
true;
992 if (ParseAsExpression) {
994 if (Tok.is(tok::r_paren)) {
997 ? diag::warn_cxx20_compat_static_assert_user_generated_message
998 : diag::ext_cxx_static_assert_user_generated_message);
1006 Diag(Tok, diag::err_expected_string_literal)
1020 DeclEnd = Tok.getLocation();
1021 ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert, TokName);
1023 return Actions.ActOnStaticAssertDeclaration(StaticAssertLoc, AssertExpr.get(),
1024 AssertMessage.
get(),
1025 T.getCloseLocation());
1029 assert(Tok.isOneOf(tok::kw_decltype, tok::annot_decltype) &&
1030 "Not a decltype specifier");
1033 SourceLocation StartLoc = Tok.getLocation();
1034 SourceLocation EndLoc;
1036 if (Tok.is(tok::annot_decltype)) {
1037 Result = getExprAnnotation(Tok);
1038 EndLoc = Tok.getAnnotationEndLoc();
1042 ConsumeAnnotationToken();
1043 if (
Result.isInvalid()) {
1048 if (Tok.getIdentifierInfo()->isStr(
"decltype"))
1049 Diag(Tok, diag::warn_cxx98_compat_decltype);
1054 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"decltype",
1057 return T.getOpenLocation() == Tok.getLocation() ? StartLoc
1058 :
T.getOpenLocation();
1062 if (Tok.is(tok::kw_auto) &&
NextToken().
is(tok::r_paren)) {
1065 Diag(Tok.getLocation(),
1067 ? diag::warn_cxx11_compat_decltype_auto_type_specifier
1068 : diag::ext_decltype_auto_type_specifier);
1079 if (
Result.isInvalid()) {
1082 EndLoc = ConsumeParen();
1084 if (PP.isBacktrackEnabled() && Tok.is(tok::semi)) {
1086 PP.RevertCachedTokens(2);
1090 EndLoc = Tok.getLocation();
1096 Result = Actions.ActOnDecltypeExpression(
Result.get());
1102 if (
T.getCloseLocation().isInvalid()) {
1106 return T.getCloseLocation();
1109 if (
Result.isInvalid()) {
1111 return T.getCloseLocation();
1114 EndLoc =
T.getCloseLocation();
1116 assert(!
Result.isInvalid());
1118 const char *PrevSpec =
nullptr;
1120 const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy();
1123 PrevSpec, DiagID,
Result.get(), Policy)
1125 PrevSpec, DiagID, Policy)) {
1126 Diag(StartLoc, DiagID) << PrevSpec;
1133void Parser::AnnotateExistingDecltypeSpecifier(
const DeclSpec &DS,
1137 if (PP.isBacktrackEnabled()) {
1138 PP.RevertCachedTokens(1);
1140 PP.EnterToken(Tok,
true);
1142 Tok.setKind(tok::annot_decltype);
1143 setExprAnnotation(Tok,
1147 Tok.setAnnotationEndLoc(EndLoc);
1148 Tok.setLocation(StartLoc);
1149 PP.AnnotateCachedTokens(Tok);
1153 assert(Tok.isOneOf(tok::annot_pack_indexing_type, tok::identifier) &&
1154 "Expected an identifier");
1157 SourceLocation StartLoc;
1158 SourceLocation EllipsisLoc;
1159 const char *PrevSpec;
1161 const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy();
1163 if (Tok.is(tok::annot_pack_indexing_type)) {
1164 StartLoc = Tok.getLocation();
1165 SourceLocation EndLoc;
1167 EndLoc = Tok.getAnnotationEndLoc();
1171 ConsumeAnnotationToken();
1172 if (
Type.isInvalid()) {
1177 DiagID,
Type, Policy);
1183 return Tok.getEndLoc();
1186 ParsedType Ty = Actions.getTypeName(*Tok.getIdentifierInfo(),
1190 return Tok.getEndLoc();
1205 ASTContext &
C = Actions.getASTContext();
1207 C.getSizeType(), SourceLocation());
1213 return T.getCloseLocation();
1216void Parser::AnnotateExistingIndexedTypeNamePack(
ParsedType T,
1220 if (PP.isBacktrackEnabled()) {
1221 PP.RevertCachedTokens(1);
1227 EndLoc = PP.getLastCachedTokenLocation();
1230 PP.EnterToken(Tok,
true);
1232 Tok.setKind(tok::annot_pack_indexing_type);
1233 setTypeAnnotation(Tok,
T);
1234 Tok.setAnnotationEndLoc(EndLoc);
1235 Tok.setLocation(StartLoc);
1236 PP.AnnotateCachedTokens(Tok);
1240 switch (Tok.getKind()) {
1241#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) \
1242 case tok::kw___##Trait: \
1243 return DeclSpec::TST_##Trait;
1244#include "clang/Basic/BuiltinTraits.inc"
1246 llvm_unreachable(
"passed in an unhandled type transformation built-in");
1250bool Parser::MaybeParseTypeTransformTypeSpecifier(
DeclSpec &DS) {
1252 Tok.setKind(tok::identifier);
1255 DeclSpec::TST TypeTransformTST = TypeTransformTokToDeclSpec();
1259 if (
T.expectAndConsume(diag::err_expected_lparen_after, Tok.getName(),
1264 if (
Result.isInvalid()) {
1270 if (
T.getCloseLocation().isInvalid())
1273 const char *PrevSpec =
nullptr;
1277 Actions.getASTContext().getPrintingPolicy()))
1278 Diag(StartLoc, DiagID) << PrevSpec;
1286 if (Tok.is(tok::kw_typename)) {
1287 Diag(Tok, diag::err_expected_class_name_not_template)
1294 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
1299 BaseLoc = Tok.getLocation();
1304 if (Tok.isOneOf(tok::kw_decltype, tok::annot_decltype)) {
1309 DeclSpec DS(AttrFactory);
1311 EndLocation = ParseDecltypeSpecifier(DS);
1315 return Actions.ActOnTypeName(DeclaratorInfo);
1318 if (Tok.is(tok::annot_pack_indexing_type)) {
1319 DeclSpec DS(AttrFactory);
1320 ParsePackIndexingType(DS);
1323 return Actions.ActOnTypeName(DeclaratorInfo);
1329 if (Tok.is(tok::annot_template_id)) {
1330 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
1335 assert(Tok.is(tok::annot_typename) &&
"template-id -> type failed");
1337 EndLocation = Tok.getAnnotationEndLoc();
1338 ConsumeAnnotationToken();
1345 if (Tok.isNot(tok::identifier)) {
1346 Diag(Tok, diag::err_expected_class_name);
1350 IdentifierInfo *Id = Tok.getIdentifierInfo();
1353 if (Tok.is(tok::less)) {
1360 if (!Actions.DiagnoseUnknownTemplateName(*Id, IdLoc,
getCurScope(), &SS,
1362 Diag(IdLoc, diag::err_unknown_template_name) << Id;
1370 if (AnnotateTemplateIdToken(
Template, TNK, SS, SourceLocation(),
1373 if (Tok.is(tok::annot_template_id) &&
1374 takeTemplateIdAnnotation(Tok)->mightBeType())
1380 if (Tok.isNot(tok::annot_typename))
1385 EndLocation = Tok.getAnnotationEndLoc();
1387 ConsumeAnnotationToken();
1392 IdentifierInfo *CorrectedII =
nullptr;
1394 *Id, IdLoc,
getCurScope(), &SS,
true,
false,
nullptr,
1400 Diag(IdLoc, diag::err_expected_class_name);
1405 EndLocation = IdLoc;
1408 DeclSpec DS(AttrFactory);
1413 const char *PrevSpec =
nullptr;
1416 Actions.getASTContext().getPrintingPolicy());
1420 return Actions.ActOnTypeName(DeclaratorInfo);
1423void Parser::ParseMicrosoftInheritanceClassAttributes(
ParsedAttributes &attrs) {
1424 while (Tok.isOneOf(tok::kw___single_inheritance,
1425 tok::kw___multiple_inheritance,
1426 tok::kw___virtual_inheritance)) {
1427 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1428 auto Kind = Tok.getKind();
1430 attrs.
addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
nullptr, 0, Kind);
1435 while (Tok.is(tok::kw__Nullable)) {
1436 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1437 auto Kind = Tok.getKind();
1439 attrs.
addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
nullptr, 0, Kind);
1443bool Parser::isValidAfterTypeSpecifier(
bool CouldBeBitfield) {
1445 switch (Tok.getKind()) {
1447 if (Tok.isRegularKeywordAttribute())
1454 case tok::identifier:
1456 case tok::coloncolon:
1457 case tok::annot_cxxscope:
1458 case tok::annot_typename:
1459 case tok::annot_template_id:
1460 case tok::kw_decltype:
1463 case tok::kw_operator:
1464 case tok::kw___declspec:
1469 case tok::kw___attribute:
1470 case tok::annot_pragma_pack:
1472 case tok::annot_pragma_ms_pragma:
1474 case tok::annot_pragma_ms_vtordisp:
1476 case tok::annot_pragma_ms_pointers_to_members:
1478 case tok::annot_pragma_export:
1481 return CouldBeBitfield ||
1484 case tok::kw___cdecl:
1485 case tok::kw___fastcall:
1486 case tok::kw___stdcall:
1487 case tok::kw___thiscall:
1488 case tok::kw___vectorcall:
1494 case tok::kw_volatile:
1495 case tok::kw_restrict:
1496 case tok::kw__Atomic:
1497 case tok::kw___unaligned:
1501 case tok::kw_inline:
1502 case tok::kw_virtual:
1503 case tok::kw_friend:
1505 case tok::kw_static:
1506 case tok::kw_extern:
1507 case tok::kw_typedef:
1508 case tok::kw_register:
1510 case tok::kw_mutable:
1511 case tok::kw_thread_local:
1512 case tok::kw_constexpr:
1513 case tok::kw_consteval:
1514 case tok::kw_constinit:
1530 if (!isKnownToBeTypeSpecifier(
NextToken()))
1547 ParsedTemplateInfo &TemplateInfo,
1549 DeclSpecContext DSC,
1552 if (TagTokKind == tok::kw_struct)
1554 else if (TagTokKind == tok::kw___interface)
1556 else if (TagTokKind == tok::kw_class)
1559 assert(TagTokKind == tok::kw_union &&
"Not a class specifier");
1563 if (Tok.is(tok::code_completion)) {
1566 Actions.CodeCompletion().CodeCompleteTag(
getCurScope(), TagType);
1577 const bool shouldDelayDiagsInTag =
1579 SuppressAccessChecks diagsFromTag(*
this, shouldDelayDiagsInTag);
1581 ParsedAttributes attrs(AttrFactory);
1584 MaybeParseAttributes(PAKM_CXX11 | PAKM_Declspec | PAKM_GNU, attrs);
1586 if (Tok.isOneOf(tok::kw___single_inheritance,
1587 tok::kw___multiple_inheritance,
1588 tok::kw___virtual_inheritance)) {
1589 ParseMicrosoftInheritanceClassAttributes(attrs);
1592 if (Tok.is(tok::kw__Nullable)) {
1593 ParseNullabilityClassAttributes(attrs);
1601 SourceLocation AttrFixitLoc = Tok.getLocation();
1604 !Tok.isAnnotation() && Tok.getIdentifierInfo() &&
1607#include
"clang/Basic/BuiltinTraits.inc"
1608 tok::kw___is_abstract,
1609 tok::kw___is_aggregate,
1610 tok::kw___is_arithmetic,
1612 tok::kw___is_assignable,
1613 tok::kw___is_base_of,
1614 tok::kw___is_bounded_array,
1616 tok::kw___is_complete_type,
1617 tok::kw___is_compound,
1619 tok::kw___is_constructible,
1620 tok::kw___is_convertible,
1621 tok::kw___is_convertible_to,
1622 tok::kw___is_destructible,
1625 tok::kw___is_floating_point,
1627 tok::kw___is_function,
1628 tok::kw___is_fundamental,
1629 tok::kw___is_integral,
1630 tok::kw___is_interface_class,
1631 tok::kw___is_literal,
1632 tok::kw___is_lvalue_expr,
1633 tok::kw___is_lvalue_reference,
1634 tok::kw___is_member_function_pointer,
1635 tok::kw___is_member_object_pointer,
1636 tok::kw___is_member_pointer,
1637 tok::kw___is_nothrow_assignable,
1638 tok::kw___is_nothrow_constructible,
1639 tok::kw___is_nothrow_convertible,
1640 tok::kw___is_nothrow_destructible,
1641 tok::kw___is_object,
1643 tok::kw___is_pointer,
1644 tok::kw___is_polymorphic,
1645 tok::kw___is_reference,
1646 tok::kw___is_rvalue_expr,
1647 tok::kw___is_rvalue_reference,
1649 tok::kw___is_scalar,
1650 tok::kw___is_scoped_enum,
1651 tok::kw___is_sealed,
1652 tok::kw___is_signed,
1653 tok::kw___is_standard_layout,
1654 tok::kw___is_trivial,
1655 tok::kw___is_trivially_equality_comparable,
1656 tok::kw___is_trivially_assignable,
1657 tok::kw___is_trivially_constructible,
1658 tok::kw___is_trivially_copyable,
1659 tok::kw___is_unbounded_array,
1661 tok::kw___is_unsigned,
1663 tok::kw___is_volatile
1670 TryKeywordIdentFallback(
true);
1672 struct PreserveAtomicIdentifierInfoRAII {
1673 PreserveAtomicIdentifierInfoRAII(Token &
Tok,
bool Enabled)
1677 assert(
Tok.
is(tok::kw__Atomic));
1682 ~PreserveAtomicIdentifierInfoRAII() {
1685 AtomicII->revertIdentifierToTokenID(tok::kw__Atomic);
1687 IdentifierInfo *AtomicII;
1695 bool ShouldChangeAtomicToIdentifier =
getLangOpts().MSVCCompat &&
1696 Tok.is(tok::kw__Atomic) &&
1698 PreserveAtomicIdentifierInfoRAII AtomicTokenGuard(
1699 Tok, ShouldChangeAtomicToIdentifier);
1703 CXXScopeSpec InvalidDeclScope;
1713 if (TemplateInfo.TemplateParams)
1716 bool HasValidSpec =
true;
1717 if (ParseOptionalCXXScopeSpecifier(Spec,
nullptr,
1721 HasValidSpec =
false;
1724 if (Tok.isNot(tok::identifier) && Tok.isNot(tok::annot_template_id)) {
1725 Diag(Tok, diag::err_expected) << tok::identifier;
1726 HasValidSpec =
false;
1734 auto RecoverFromUndeclaredTemplateName = [&](IdentifierInfo *Name,
1735 SourceLocation NameLoc,
1736 SourceRange TemplateArgRange,
1737 bool KnownUndeclared) {
1738 Diag(NameLoc, diag::err_explicit_spec_non_template)
1740 << TagTokKind << Name << TemplateArgRange << KnownUndeclared;
1744 if (TemplateParams && TemplateInfo.LastParameterListWasEmpty) {
1745 if (TemplateParams->size() > 1) {
1746 TemplateParams->pop_back();
1748 TemplateParams =
nullptr;
1753 TemplateParams =
nullptr;
1755 TemplateInfo.TemplateLoc = SourceLocation();
1756 TemplateInfo.ExternLoc = SourceLocation();
1761 IdentifierInfo *Name =
nullptr;
1762 SourceLocation NameLoc;
1763 TemplateIdAnnotation *TemplateId =
nullptr;
1764 if (Tok.is(tok::identifier)) {
1765 Name = Tok.getIdentifierInfo();
1773 TemplateArgList TemplateArgs;
1774 SourceLocation LAngleLoc, RAngleLoc;
1775 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs,
1779 LAngleLoc = RAngleLoc = SourceLocation();
1781 RecoverFromUndeclaredTemplateName(
1782 Name, NameLoc, SourceRange(LAngleLoc, RAngleLoc),
false);
1784 }
else if (Tok.is(tok::annot_template_id)) {
1785 TemplateId = takeTemplateIdAnnotation(Tok);
1786 NameLoc = ConsumeAnnotationToken();
1790 Actions.ActOnUndeclaredTypeTemplateName(
1793 RecoverFromUndeclaredTemplateName(
1796 TemplateId =
nullptr;
1804 SourceRange
Range(NameLoc);
1809 Diag(TemplateId->
LAngleLoc, diag::err_template_spec_syntax_non_template)
1810 << TemplateId->
Name <<
static_cast<int>(TemplateId->
Kind) << Range;
1845 MaybeParseCXX11Attributes(Attributes);
1847 const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy();
1854 Tok.isOneOf(tok::comma, tok::ellipsis))
1857 AllowDefiningTypeSpec::No ||
1860 else if (Tok.is(tok::l_brace) ||
1861 (DSC != DeclSpecContext::DSC_association &&
1863 (isClassCompatibleKeyword() &&
1865 isClassCompatibleKeyword(
NextToken())))) {
1869 Diag(Tok.getLocation(), diag::err_friend_decl_defines_type)
1880 }
else if (isClassCompatibleKeyword() &&
1887 TentativeParsingAction PA(*
this);
1890 while (isClassCompatibleKeyword())
1895 if (Tok.is(tok::l_square) &&
NextToken().
is(tok::l_square)) {
1899 }
else if (Tok.is(tok::kw_alignas) &&
NextToken().
is(tok::l_paren)) {
1904 }
else if (Tok.isRegularKeywordAttribute()) {
1909 if (!
T.consumeOpen())
1917 if (Tok.isOneOf(tok::l_brace, tok::colon))
1923 }
else if (!isTypeSpecifier(DSC) &&
1924 (Tok.is(tok::semi) ||
1925 (Tok.isAtStartOfLine() && !isValidAfterTypeSpecifier(
false)))) {
1927 if (Tok.isNot(tok::semi)) {
1928 const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy();
1930 ExpectAndConsume(tok::semi, diag::err_expected_after,
1932 PP.EnterToken(Tok,
true);
1933 Tok.setKind(tok::semi);
1946 SourceRange AttrRange = Attributes.
Range;
1950 (FirstAttr && FirstAttr->isRegularKeywordAttribute()
1951 ?
Diag(Loc, diag::err_keyword_not_allowed) << FirstAttr
1952 :
Diag(Loc, diag::err_attributes_not_allowed))
1955 AttrFixitLoc, CharSourceRange(AttrRange,
true))
1964 if (!Name && !TemplateId &&
1969 Diag(StartLoc, diag::err_anon_type_definition)
1988 SkipBodyInfo SkipBody;
2002 ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
2003 diag::err_keyword_not_allowed,
2006 TagOrTempResult = Actions.ActOnExplicitInstantiation(
2007 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc,
2008 TagType, StartLoc, SS, TemplateId->
Template,
2015 ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
2016 diag::err_keyword_not_allowed,
2039 "Expected a definition here");
2043 TemplateParams =
nullptr;
2045 SourceLocation LAngleLoc =
2046 PP.getLocForEndOfToken(TemplateInfo.TemplateLoc);
2048 diag::err_explicit_instantiation_with_definition)
2049 << SourceRange(TemplateInfo.TemplateLoc)
2055 FakedParamLists.push_back(Actions.ActOnTemplateParameterList(
2056 0, SourceLocation(), TemplateInfo.TemplateLoc, LAngleLoc, {},
2057 LAngleLoc,
nullptr));
2058 TemplateParams = &FakedParamLists;
2063 TagOrTempResult = Actions.ActOnClassTemplateSpecialization(
2065 SS, *TemplateId, attrs,
2068 TemplateParams ? TemplateParams->size() : 0),
2078 ProhibitAttributes(attrs);
2080 TagOrTempResult = Actions.ActOnExplicitInstantiation(
2081 getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc,
2082 TagType, StartLoc, SS, Name, NameLoc, attrs);
2085 ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
2086 diag::err_keyword_not_allowed,
2090 SourceLocation EllipsisLoc;
2102 if (Tok.is(tok::comma)) {
2103 Diag(Tok.getLocation(),
2104 diag::err_friend_template_decl_multiple_specifiers);
2113 TagOrTempResult = Actions.ActOnTemplatedFriendTag(
2115 NameLoc, EllipsisLoc, attrs,
2117 TemplateParams ? TemplateParams->size() : 0),
2121 ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
2122 diag::err_keyword_not_allowed,
2129 Diag(Tok, diag::err_template_defn_explicit_instantiation)
2131 TemplateParams =
nullptr;
2134 bool IsDependent =
false;
2144 stripTypeAttributesOffDeclSpec(attrs, DS, TUK);
2147 TagOrTempResult = Actions.ActOnTag(
2148 getCurScope(), TagType, TUK, StartLoc, SS, Name, NameLoc, attrs, AS,
2151 DSC == DeclSpecContext::DSC_type_specifier,
2152 DSC == DeclSpecContext::DSC_template_param ||
2153 DSC == DeclSpecContext::DSC_template_type_arg,
2154 OffsetOfState, &SkipBody);
2161 Name, StartLoc, NameLoc);
2168 if (shouldDelayDiagsInTag) {
2169 diagsFromTag.done();
2172 diagsFromTag.redelay();
2177 assert(Tok.is(tok::l_brace) ||
2179 isClassCompatibleKeyword());
2181 SkipCXXMemberSpecification(StartLoc, AttrFixitLoc, TagType,
2182 TagOrTempResult.
get());
2184 ParseCXXMemberSpecification(StartLoc, AttrFixitLoc, attrs, TagType,
2185 TagOrTempResult.
get());
2193 TagOrTempResult.
get(), SkipBody)) {
2202 Actions.ProcessDeclAttributeDelayed(TagOrTempResult.
get(), attrs);
2204 const char *PrevSpec =
nullptr;
2209 NameLoc.
isValid() ? NameLoc : StartLoc,
2211 }
else if (!TagOrTempResult.
isInvalid()) {
2213 TagType, StartLoc, NameLoc.
isValid() ? NameLoc : StartLoc, PrevSpec,
2214 DiagID, TagOrTempResult.
get(), Owned, Policy);
2221 Diag(StartLoc, DiagID) << PrevSpec;
2238 if (Tok.isNot(tok::semi)) {
2239 const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy();
2240 ExpectAndConsume(tok::semi, diag::err_expected_after,
2245 PP.EnterToken(Tok,
true);
2246 Tok.setKind(tok::semi);
2251void Parser::ParseBaseClause(
Decl *ClassDecl) {
2252 assert(Tok.is(tok::colon) &&
"Not a base clause");
2256 SmallVector<CXXBaseSpecifier *, 8> BaseInfo;
2261 if (!
Result.isUsable()) {
2267 BaseInfo.push_back(
Result.get());
2277 Actions.ActOnBaseSpecifiers(ClassDecl, BaseInfo);
2281 bool IsVirtual =
false;
2282 SourceLocation StartLoc = Tok.getLocation();
2284 ParsedAttributes Attributes(AttrFactory);
2285 MaybeParseCXX11Attributes(Attributes);
2291 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2298 Diag(Tok.getLocation(), diag::ext_hlsl_access_specifiers);
2301 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2305 if (Tok.is(tok::kw_virtual)) {
2309 Diag(VirtualLoc, diag::err_dup_virtual)
2317 Diag(Tok.getLocation(), diag::err_hlsl_virtual_inheritance);
2319 CheckMisplacedCXX11Attribute(Attributes, StartLoc);
2327 if (
getLangOpts().MSVCCompat && Tok.is(tok::kw__Atomic) &&
2329 Tok.setKind(tok::identifier);
2331 SourceLocation EndLocation;
2332 SourceLocation BaseLoc;
2333 TypeResult BaseType = ParseBaseTypeSpecifier(BaseLoc, EndLocation);
2340 SourceLocation EllipsisLoc;
2344 SourceRange
Range(StartLoc, EndLocation);
2348 return Actions.ActOnBaseSpecifier(ClassDecl, Range, Attributes, IsVirtual,
2349 Access, BaseType.
get(), BaseLoc,
2354 switch (Tok.getKind()) {
2357 case tok::kw_private:
2359 case tok::kw_protected:
2361 case tok::kw_public:
2366void Parser::HandleMemberFunctionDeclDelays(
Declarator &DeclaratorInfo,
2373 if (!NeedLateParse) {
2375 for (
unsigned ParamIdx = 0; ParamIdx < FTI.
NumParams; ++ParamIdx) {
2377 if (Param->hasUnparsedDefaultArg()) {
2378 NeedLateParse =
true;
2384 if (NeedLateParse) {
2387 auto LateMethod =
new LateParsedMethodDeclaration(
this, ThisDecl);
2388 getCurrentClass().LateParsedDeclarations.push_back(LateMethod);
2393 LateMethod->DefaultArgs.reserve(FTI.
NumParams);
2394 for (
unsigned ParamIdx = 0; ParamIdx < FTI.
NumParams; ++ParamIdx)
2395 LateMethod->DefaultArgs.push_back(LateParsedDefaultArgument(
2411 const IdentifierInfo *II = Tok.getIdentifierInfo();
2415 Ident_final = &PP.getIdentifierTable().get(
"final");
2417 Ident_GNU_final = &PP.getIdentifierTable().get(
"__final");
2419 Ident_sealed = &PP.getIdentifierTable().get(
"sealed");
2420 Ident_abstract = &PP.getIdentifierTable().get(
"abstract");
2422 Ident_override = &PP.getIdentifierTable().get(
"override");
2425 if (II == Ident_override)
2428 if (II == Ident_sealed)
2431 if (II == Ident_abstract)
2434 if (II == Ident_final)
2437 if (II == Ident_GNU_final)
2443void Parser::ParseOptionalCXX11VirtSpecifierSeq(
VirtSpecifiers &VS,
2452 Diag(Tok.getLocation(), diag::err_friend_decl_spec)
2455 << SourceRange(FriendLoc, FriendLoc);
2462 const char *PrevSpec =
nullptr;
2463 if (VS.
SetSpecifier(Specifier, Tok.getLocation(), PrevSpec))
2464 Diag(Tok.getLocation(), diag::err_duplicate_virt_specifier)
2469 Diag(Tok.getLocation(), diag::err_override_control_interface)
2472 Diag(Tok.getLocation(), diag::ext_ms_sealed_keyword);
2474 Diag(Tok.getLocation(), diag::ext_ms_abstract_keyword);
2476 Diag(Tok.getLocation(), diag::ext_warn_gnu_final);
2478 Diag(Tok.getLocation(),
2480 ? diag::warn_cxx98_compat_override_control_keyword
2481 : diag::ext_override_control_keyword)
2488bool Parser::isCXX11FinalKeyword()
const {
2495bool Parser::isClassCompatibleKeyword(
Token Tok)
const {
2503bool Parser::isClassCompatibleKeyword()
const {
2504 return isClassCompatibleKeyword(Tok);
2509bool Parser::ParseCXXMemberDeclaratorBeforeInitializer(
2522 if (Tok.isNot(tok::colon))
2523 ParseDeclarator(DeclaratorInfo);
2528 if (!IsFunctionDeclarator && !
getLangOpts().MSVCCompat)
2529 MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs);
2532 MaybeParseHLSLAnnotations(DeclaratorInfo,
nullptr,
2537 "don't know where identifier would go yet?");
2541 }
else if (Tok.is(tok::kw_requires)) {
2542 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
2547 ++CurTemplateDepthTracker;
2548 ParseTrailingRequiresClauseWithScope(DeclaratorInfo);
2550 ParseOptionalCXX11VirtSpecifierSeq(
2551 VS, getCurrentClass().IsInterface,
2554 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo,
2559 if (Tok.is(tok::kw_asm)) {
2561 ExprResult AsmLabel(ParseSimpleAsm(
true, &Loc));
2562 if (AsmLabel.isInvalid())
2572 DiagnoseAndSkipCXX11Attributes();
2573 MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs);
2574 DiagnoseAndSkipCXX11Attributes();
2579 ParseOptionalCXX11VirtSpecifierSeq(
2580 VS, getCurrentClass().IsInterface,
2586 if (AL.isKnownToGCC() && !AL.isCXX11Attribute())
2587 Diag(AL.getLoc(), diag::warn_gcc_attribute_location);
2589 MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(DeclaratorInfo,
2604void Parser::MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(
2606 DeclSpec DS(AttrFactory);
2610 ParseTypeQualifierListOpt(
2611 DS, AR_NoAttributesParsed,
false,
2613 Actions.CodeCompletion().CodeCompleteFunctionQualifiers(DS, D, &VS);
2620 auto DeclSpecCheck = [&](
DeclSpec::TQ TypeQual, StringRef FixItName,
2621 SourceLocation SpecLoc) {
2622 FixItHint Insertion;
2623 auto &MQ =
Function.getOrCreateMethodQualifiers();
2624 if (!(MQ.getTypeQualifiers() & TypeQual)) {
2625 std::string Name(FixItName.data());
2628 MQ.SetTypeQual(TypeQual, SpecLoc);
2630 Diag(SpecLoc, diag::err_declspec_after_virtspec)
2639 bool RefQualifierIsLValueRef =
true;
2640 SourceLocation RefQualifierLoc;
2641 if (ParseRefQualifier(RefQualifierIsLValueRef, RefQualifierLoc)) {
2642 const char *Name = (RefQualifierIsLValueRef ?
"& " :
"&& ");
2643 FixItHint Insertion =
2645 Function.RefQualifierIsLValueRef = RefQualifierIsLValueRef;
2646 Function.RefQualifierLoc = RefQualifierLoc;
2648 Diag(RefQualifierLoc, diag::err_declspec_after_virtspec)
2649 << (RefQualifierIsLValueRef ?
"&" :
"&&")
2661 "ParseCXXClassMemberDeclaration should only be called in C++ mode");
2662 if (Tok.is(tok::at)) {
2664 Diag(Tok, diag::err_at_defs_cxx);
2666 Diag(Tok, diag::err_at_in_class);
2682 bool MalformedTypeSpec =
false;
2684 Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) {
2686 MalformedTypeSpec =
true;
2689 if (Tok.isNot(tok::annot_cxxscope))
2690 isAccessDecl =
false;
2699 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
2709 SourceLocation TemplateKWLoc;
2712 false,
false,
true,
true,
2713 false, &TemplateKWLoc, Name)) {
2719 if (ExpectAndConsume(tok::semi, diag::err_expected_after,
2720 "access declaration")) {
2728 SourceLocation(), SS, Name,
2730 ParsedAttributesView())));
2737 Tok.isOneOf(tok::kw_static_assert, tok::kw__Static_assert)) {
2738 SourceLocation DeclEnd;
2740 DeclGroupRef(ParseStaticAssertDeclaration(DeclEnd)));
2743 if (Tok.is(tok::kw_template)) {
2744 assert(!TemplateInfo.TemplateParams &&
2745 "Nested template improperly parsed?");
2746 ObjCDeclContextSwitch ObjCDC(*
this);
2747 SourceLocation DeclEnd;
2749 DeclEnd, AccessAttrs, AS);
2753 if (Tok.is(tok::kw___extension__)) {
2755 ExtensionRAIIObject O(Diags);
2757 return ParseCXXClassMemberDeclaration(AS, AccessAttrs, TemplateInfo,
2761 ParsedAttributes DeclAttrs(AttrFactory);
2763 MaybeParseCXX11Attributes(DeclAttrs);
2768 if (Tok.is(tok::annot_attr_openmp))
2769 return ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, DeclAttrs);
2771 if (Tok.is(tok::kw_using)) {
2776 while (Tok.is(tok::kw_template)) {
2778 Diag(TemplateLoc, diag::err_unexpected_template_after_using)
2782 if (Tok.is(tok::kw_namespace)) {
2783 Diag(UsingLoc, diag::err_using_namespace_in_class);
2787 SourceLocation DeclEnd;
2790 UsingLoc, DeclEnd, DeclAttrs, AS);
2793 ParsedAttributes DeclSpecAttrs(AttrFactory);
2795 LateParsedAttrList CommonLateParsedAttrs;
2797 while (MaybeParseCXX11Attributes(DeclAttrs) ||
2798 MaybeParseGNUAttributes(DeclSpecAttrs, &CommonLateParsedAttrs) ||
2799 MaybeParseMicrosoftAttributes(DeclSpecAttrs))
2802 SourceLocation DeclStart;
2803 if (DeclAttrs.Range.isValid()) {
2804 DeclStart = DeclSpecAttrs.Range.
isInvalid()
2805 ? DeclAttrs.Range.getBegin()
2806 : std::min(DeclAttrs.Range.getBegin(),
2807 DeclSpecAttrs.Range.getBegin());
2809 DeclStart = DeclSpecAttrs.Range.getBegin();
2814 ParsingDeclSpec DS(*
this, TemplateDiags);
2817 if (MalformedTypeSpec)
2825 bool IsTemplateSpecOrInst =
2828 SuppressAccessChecks diagsFromTag(*
this, IsTemplateSpecOrInst);
2830 ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DeclSpecContext::DSC_class,
2831 &CommonLateParsedAttrs);
2833 if (IsTemplateSpecOrInst)
2834 diagsFromTag.done();
2846 DiagnoseMissingSemiAfterTagDefinition(DS, AS, DeclSpecContext::DSC_class,
2847 &CommonLateParsedAttrs))
2851 TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->data()
2853 TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->size() : 0);
2857 ProhibitAttributes(DeclAttrs);
2859 RecordDecl *AnonRecord =
nullptr;
2860 Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(
2861 getCurScope(), AS, DS, DeclAttrs, TemplateParams,
false, AnonRecord);
2862 Actions.ActOnDefinedDeclarationSpecifier(TheDecl);
2863 DS.complete(TheDecl);
2865 Decl *decls[] = {AnonRecord, TheDecl};
2866 return Actions.BuildDeclaratorGroup(decls);
2868 return Actions.ConvertDeclToDeclGroup(TheDecl);
2872 Actions.ActOnDefinedDeclarationSpecifier(DS.
getRepAsDecl());
2878 ? diag::warn_cxx23_variadic_friends
2879 : diag::ext_variadic_friends);
2882 SmallVector<Decl *> Decls;
2885 auto ParsedFriendDecl = [&](ParsingDeclSpec &DeclSpec) {
2886 SourceLocation VariadicLoc;
2889 RecordDecl *AnonRecord =
nullptr;
2890 Decl *D = Actions.ParsedFreeStandingDeclSpec(
2891 getCurScope(), AS, DeclSpec, DeclAttrs, TemplateParams,
false,
2892 AnonRecord, VariadicLoc);
2893 DeclSpec.complete(D);
2903 if (ParsedFriendDecl(DS))
2907 ParsingDeclSpec DeclSpec(*
this, TemplateDiags);
2908 const char *PrevSpec =
nullptr;
2909 unsigned DiagId = 0;
2910 DeclSpec.SetFriendSpec(FriendLoc, PrevSpec, DiagId);
2911 ParseDeclarationSpecifiers(DeclSpec, TemplateInfo, AS,
2912 DeclSpecContext::DSC_class,
nullptr);
2913 if (ParsedFriendDecl(DeclSpec))
2917 ExpectAndConsume(tok::semi, diag::err_expected_semi_after_stmt,
2918 "friend declaration");
2920 return Actions.BuildDeclaratorGroup(Decls);
2926 if (Tok.is(tok::kw_concept)) {
2930 ? llvm::to_underlying(diag::err_friend_concept)
2931 : llvm::to_underlying(
2933 err_concept_decls_may_only_appear_in_global_namespace_scope));
2938 ParsingDeclarator DeclaratorInfo(*
this, DS, DeclAttrs,
2940 if (TemplateInfo.TemplateParams)
2945 LateParsedAttrList LateParsedAttrs;
2947 SourceLocation EqualLoc;
2948 SourceLocation PureSpecLoc;
2950 auto TryConsumePureSpecifier = [&](
bool AllowDefinition) {
2951 if (Tok.isNot(tok::equal))
2955 SmallString<8> Buffer;
2956 if (
Zero.isNot(tok::numeric_constant) ||
2957 PP.getSpelling(
Zero, Buffer) !=
"0")
2961 if (!
After.isOneOf(tok::semi, tok::comma) &&
2962 !(AllowDefinition &&
2963 After.isOneOf(tok::l_brace, tok::colon, tok::kw_try)))
2971 SmallVector<Decl *, 8> DeclsInGroup;
2974 bool ExpectSemi =
true;
2979 SuppressAccessChecks SAC(*
this, IsTemplateSpecOrInst);
2982 if (ParseCXXMemberDeclaratorBeforeInitializer(
2983 DeclaratorInfo, VS, BitfieldSize, LateParsedAttrs)) {
2988 if (IsTemplateSpecOrInst)
2996 TryConsumePureSpecifier(
true);
3007 if (Tok.isOneOf(tok::l_brace, tok::colon, tok::kw_try)) {
3009 }
else if (Tok.is(tok::equal)) {
3011 if (KW.
is(tok::kw_default))
3013 else if (KW.
is(tok::kw_delete))
3015 else if (KW.
is(tok::code_completion)) {
3017 Actions.CodeCompletion().CodeCompleteAfterFunctionEquals(
3032 ProhibitAttributes(DeclAttrs);
3049 diag::err_function_declared_typedef);
3055 Decl *FunDecl = ParseCXXInlineMethodDef(AS, AccessAttrs, DeclaratorInfo,
3056 TemplateInfo, VS, PureSpecLoc);
3059 for (
unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i) {
3060 CommonLateParsedAttrs[i]->addDecl(FunDecl);
3062 for (
unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i) {
3063 LateParsedAttrs[i]->addDecl(FunDecl);
3066 LateParsedAttrs.clear();
3069 if (Tok.is(tok::semi))
3082 bool HasStaticInitializer =
false;
3083 if (Tok.isOneOf(tok::equal, tok::l_brace) && PureSpecLoc.
isInvalid()) {
3087 Diag(Tok, diag::err_anon_bitfield_member_init);
3091 if (!TryConsumePureSpecifier(
false))
3093 HasStaticInitializer =
true;
3101 if (BitfieldSize.
get())
3103 ? diag::warn_cxx17_compat_bitfield_member_init
3104 : diag::ext_bitfield_member_init);
3107 HasStaticInitializer =
true;
3115 NamedDecl *ThisDecl =
nullptr;
3123 if (AL.isCXX11Attribute() || AL.isRegularKeywordAttribute()) {
3124 auto Loc = AL.getRange().getBegin();
3125 (AL.isRegularKeywordAttribute()
3126 ?
Diag(Loc, diag::err_keyword_not_allowed) << AL
3127 :
Diag(Loc, diag::err_attributes_not_allowed))
3131 ThisDecl = Actions.ActOnFriendFunctionDecl(
getCurScope(), DeclaratorInfo,
3134 ThisDecl = Actions.ActOnCXXMemberDeclarator(
3135 getCurScope(), AS, DeclaratorInfo, TemplateParams, BitfieldSize.
get(),
3136 VS, HasInClassInit);
3138 if (VarTemplateDecl *VT =
3139 ThisDecl ? dyn_cast<VarTemplateDecl>(ThisDecl) :
nullptr)
3142 ThisDecl = VT->getTemplatedDecl();
3145 Actions.ProcessDeclAttributeList(
getCurScope(), ThisDecl, AccessAttrs);
3154 HasStaticInitializer =
true;
3158 Diag(PureSpecLoc, diag::err_duplicate_virt_specifier) <<
"abstract";
3160 if (ThisDecl && PureSpecLoc.
isValid())
3161 Actions.ActOnPureSpecifier(ThisDecl, PureSpecLoc);
3169 ? diag::warn_cxx98_compat_nonstatic_member_init
3170 : diag::ext_nonstatic_member_init);
3178 Diag(Tok, diag::err_incomplete_array_member_init);
3185 ParseCXXNonStaticMemberInitializer(ThisDecl);
3186 }
else if (HasStaticInitializer) {
3191 if (
Init.isInvalid()) {
3193 Actions.ActOnUninitializedDecl(ThisDecl);
3195 }
else if (ThisDecl)
3196 Actions.AddInitializerToDecl(ThisDecl,
Init.get(),
3200 Actions.ActOnUninitializedDecl(ThisDecl);
3205 for (
unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i)
3206 CommonLateParsedAttrs[i]->addDecl(ThisDecl);
3208 for (
unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i)
3209 LateParsedAttrs[i]->addDecl(ThisDecl);
3211 Actions.FinalizeDeclaration(ThisDecl);
3212 DeclsInGroup.push_back(ThisDecl);
3217 HandleMemberFunctionDeclDelays(DeclaratorInfo, ThisDecl);
3219 LateParsedAttrs.clear();
3221 DeclaratorInfo.complete(ThisDecl);
3225 SourceLocation CommaLoc;
3229 if (Tok.isAtStartOfLine() &&
3234 Diag(CommaLoc, diag::err_expected_semi_declaration)
3246 Diag(CommaLoc, diag::err_multiple_template_declarators)
3247 << TemplateInfo.Kind;
3251 DeclaratorInfo.
clear();
3254 EqualLoc = PureSpecLoc = SourceLocation();
3260 DiagnoseAndSkipCXX11Attributes();
3261 MaybeParseGNUAttributes(DeclaratorInfo);
3262 DiagnoseAndSkipCXX11Attributes();
3264 if (ParseCXXMemberDeclaratorBeforeInitializer(
3265 DeclaratorInfo, VS, BitfieldSize, LateParsedAttrs))
3270 ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list) &&
3271 !isLikelyAtStartOfNewDeclaration()) {
3279 return Actions.FinalizeDeclaratorGroup(
getCurScope(), DS, DeclsInGroup);
3282ExprResult Parser::ParseCXXMemberInitializer(
Decl *D,
bool IsFunction,
3284 assert(Tok.isOneOf(tok::equal, tok::l_brace) &&
3285 "Data member initializer not starting with '=' or '{'");
3287 bool IsFieldInitialization = isa_and_present<FieldDecl>(D);
3289 EnterExpressionEvaluationContext Context(
3291 IsFieldInitialization
3299 Actions.ExprEvalContexts.back().InImmediateEscalatingFunctionContext =
3300 IsFieldInitialization;
3303 if (Tok.is(tok::kw_delete)) {
3310 if (IsFunction ||
Next.isOneOf(tok::semi, tok::comma, tok::eof)) {
3316 SkipDeletedFunctionBody();
3319 }
else if (Tok.is(tok::kw_default)) {
3321 Diag(Tok, diag::err_default_delete_in_multiple_declaration)
3329 if (
const auto *PD = dyn_cast_or_null<MSPropertyDecl>(D)) {
3330 Diag(Tok, diag::err_ms_property_initializer) << PD;
3333 return ParseInitializer(D);
3340 while (isClassCompatibleKeyword())
3345 ParsedAttributes Attrs(AttrFactory);
3346 CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc);
3351 if (Tok.isNot(tok::colon) && Tok.isNot(tok::l_brace))
3357 if (Tok.is(tok::colon)) {
3360 ParsingClassDefinition ParsingDef(*
this, TagDecl,
true,
3363 Actions.ActOnTagStartSkippedDefinition(
getCurScope(), TagDecl);
3366 ParseBaseClause(
nullptr);
3368 Actions.ActOnTagFinishSkippedDefinition(OldContext);
3370 if (!Tok.is(tok::l_brace)) {
3371 Diag(PP.getLocForEndOfToken(PrevTokLocation),
3372 diag::err_expected_lbrace_after_base_specifiers);
3378 assert(Tok.is(tok::l_brace));
3384 if (Tok.is(tok::kw___attribute)) {
3385 ParsedAttributes Attrs(AttrFactory);
3386 MaybeParseGNUAttributes(Attrs);
3395 switch (Tok.getKind()) {
3396 case tok::kw___if_exists:
3397 case tok::kw___if_not_exists:
3398 ParseMicrosoftIfExistsClassDeclaration(TagType, AccessAttrs, AS);
3407 case tok::annot_pragma_vis:
3408 HandlePragmaVisibility();
3410 case tok::annot_pragma_pack:
3413 case tok::annot_pragma_align:
3414 HandlePragmaAlign();
3416 case tok::annot_pragma_ms_pointers_to_members:
3417 HandlePragmaMSPointersToMembers();
3419 case tok::annot_pragma_ms_pragma:
3420 HandlePragmaMSPragma();
3422 case tok::annot_pragma_ms_vtordisp:
3423 HandlePragmaMSVtorDisp();
3425 case tok::annot_pragma_export:
3426 HandlePragmaExport();
3428 case tok::annot_pragma_dump:
3432 case tok::kw_namespace:
3437 case tok::kw_private:
3441 ParsedTemplateInfo TemplateInfo;
3442 return ParseCXXClassMemberDeclaration(AS, AccessAttrs, TemplateInfo);
3445 case tok::kw_public:
3446 case tok::kw_protected: {
3448 Diag(Tok.getLocation(), diag::ext_hlsl_access_specifiers);
3453 SourceLocation ASLoc = Tok.getLocation();
3454 unsigned TokLength = Tok.getLength();
3456 AccessAttrs.
clear();
3457 MaybeParseGNUAttributes(AccessAttrs);
3459 SourceLocation EndLoc;
3462 Diag(EndLoc, diag::err_expected)
3466 Diag(EndLoc, diag::err_expected)
3476 if (Actions.ActOnAccessSpecifier(NewAS, ASLoc, EndLoc, AccessAttrs)) {
3478 AccessAttrs.
clear();
3484 case tok::annot_attr_openmp:
3485 case tok::annot_pragma_openmp:
3486 return ParseOpenMPDeclarativeDirectiveWithExtDecl(
3487 AS, AccessAttrs,
true, TagType, TagDecl);
3488 case tok::annot_pragma_openacc:
3493 Diag(Tok.getLocation(), diag::err_pragma_misplaced_in_decl)
3495 TagType, Actions.getASTContext().getPrintingPolicy());
3496 ConsumeAnnotationToken();
3499 ParsedTemplateInfo TemplateInfo;
3500 return ParseCXXClassMemberDeclaration(AS, AccessAttrs, TemplateInfo);
3511 "Invalid TagType!");
3513 llvm::TimeTraceScope TimeScope(
"ParseClass", [&]() {
3514 if (
auto *TD = dyn_cast_or_null<NamedDecl>(TagDecl))
3515 return TD->getQualifiedNameAsString();
3516 return std::string(
"<anonymous>");
3519 PrettyDeclStackTraceEntry CrashInfo(Actions.Context, TagDecl,
RecordLoc,
3520 "parsing struct/union/class body");
3524 bool NonNestedClass =
true;
3525 if (!ClassStack.empty()) {
3527 if (S->isClassScope()) {
3529 NonNestedClass =
false;
3532 if (getCurrentClass().IsInterface) {
3542 if (S->isFunctionScope())
3553 ParsingClassDefinition ParsingDef(*
this, TagDecl, NonNestedClass,
3557 Actions.ActOnTagStartDefinition(
getCurScope(), TagDecl);
3559 SourceLocation FinalLoc;
3560 SourceLocation AbstractLoc;
3561 bool IsFinalSpelledSealed =
false;
3562 bool IsAbstract =
false;
3571 if (isCXX11FinalKeyword()) {
3574 Diag(Skipped, diag::err_duplicate_class_virt_specifier)
3579 IsFinalSpelledSealed =
true;
3584 Diag(Skipped, diag::err_duplicate_class_virt_specifier)
3592 Diag(FinalLoc, diag::err_override_control_interface)
3596 ? diag::warn_cxx98_compat_override_control_keyword
3597 : diag::ext_override_control_keyword)
3600 Diag(FinalLoc, diag::ext_ms_sealed_keyword);
3602 Diag(AbstractLoc, diag::ext_ms_abstract_keyword);
3604 Diag(FinalLoc, diag::ext_warn_gnu_final);
3607 "not a class definition");
3613 CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc);
3622 if (!Tok.is(tok::colon) && !Tok.is(tok::l_brace)) {
3624 Actions.ActOnTagDefinitionError(
getCurScope(), TagDecl);
3629 if (Tok.is(tok::colon)) {
3633 ParseBaseClause(TagDecl);
3634 if (!Tok.is(tok::l_brace)) {
3635 bool SuggestFixIt =
false;
3636 SourceLocation BraceLoc = PP.getLocForEndOfToken(PrevTokLocation);
3637 if (Tok.isAtStartOfLine()) {
3638 switch (Tok.getKind()) {
3639 case tok::kw_private:
3640 case tok::kw_protected:
3641 case tok::kw_public:
3644 case tok::kw_static_assert:
3648 case tok::kw_template:
3649 SuggestFixIt =
true;
3651 case tok::identifier:
3652 SuggestFixIt = isConstructorDeclarator(
true);
3655 SuggestFixIt = isCXXSimpleDeclaration(
false);
3659 DiagnosticBuilder LBraceDiag =
3660 Diag(BraceLoc, diag::err_expected_lbrace_after_base_specifiers);
3664 PP.EnterToken(Tok,
true);
3665 Tok.setKind(tok::l_brace);
3668 Actions.ActOnTagDefinitionError(
getCurScope(), TagDecl);
3674 assert(Tok.is(tok::l_brace));
3679 Actions.ActOnStartCXXMemberDeclarations(
getCurScope(), TagDecl, FinalLoc,
3680 IsFinalSpelledSealed, IsAbstract,
3681 T.getOpenLocation());
3692 ParsedAttributes AccessAttrs(AttrFactory);
3696 while (!tryParseMisplacedModuleImport() && Tok.isNot(tok::r_brace) &&
3697 Tok.isNot(tok::eof)) {
3699 ParseCXXClassMemberDeclarationWithPragmas(
3700 CurAS, AccessAttrs,
static_cast<DeclSpec::TST>(TagType), TagDecl);
3701 MaybeDestroyTemplateIds();
3709 ParsedAttributes attrs(AttrFactory);
3710 MaybeParseGNUAttributes(attrs);
3714 T.getOpenLocation(),
3715 T.getCloseLocation(), attrs);
3722 if (TagDecl && NonNestedClass) {
3728 SourceLocation SavedPrevTokLocation = PrevTokLocation;
3729 ParseLexedPragmas(getCurrentClass());
3730 ParseLexedAttributes(getCurrentClass());
3731 ParseLexedMethodDeclarations(getCurrentClass());
3734 Actions.ActOnFinishCXXMemberDecls();
3736 ParseLexedMemberInitializers(getCurrentClass());
3737 ParseLexedMethodDefs(getCurrentClass());
3738 PrevTokLocation = SavedPrevTokLocation;
3742 Actions.ActOnFinishCXXNonNestedClass();
3746 Actions.ActOnTagFinishDefinition(
getCurScope(), TagDecl,
T.getRange());
3753void Parser::DiagnoseUnexpectedNamespace(
NamedDecl *D) {
3754 assert(Tok.is(tok::kw_namespace));
3759 Diag(Tok.getLocation(), diag::note_missing_end_of_definition_before) << D;
3762 PP.EnterToken(Tok,
true);
3765 Tok.
setLocation(PP.getLocForEndOfToken(PrevTokLocation));
3766 Tok.setKind(tok::semi);
3767 PP.EnterToken(Tok,
true);
3769 Tok.setKind(tok::r_brace);
3772void Parser::ParseConstructorInitializer(
Decl *ConstructorDecl) {
3773 assert(Tok.is(tok::colon) &&
3774 "Constructor initializer always starts with ':'");
3781 SmallVector<CXXCtorInitializer *, 4> MemInitializers;
3782 bool AnyErrors =
false;
3785 if (Tok.is(tok::code_completion)) {
3787 Actions.CodeCompletion().CodeCompleteConstructorInitializer(
3788 ConstructorDecl, MemInitializers);
3792 MemInitResult MemInit = ParseMemInitializer(ConstructorDecl);
3794 MemInitializers.push_back(MemInit.
get());
3798 if (Tok.is(tok::comma))
3800 else if (Tok.is(tok::l_brace))
3805 Tok.isOneOf(tok::identifier, tok::coloncolon)) {
3806 SourceLocation Loc = PP.getLocForEndOfToken(PrevTokLocation);
3807 Diag(Loc, diag::err_ctor_init_missing_comma)
3812 Diag(Tok.getLocation(), diag::err_expected_either)
3813 << tok::l_brace << tok::comma;
3819 Actions.ActOnMemInitializers(ConstructorDecl, ColonLoc, MemInitializers,
3826 if (ParseOptionalCXXScopeSpecifier(SS,
nullptr,
3832 IdentifierInfo *II =
nullptr;
3833 SourceLocation IdLoc = Tok.getLocation();
3835 DeclSpec DS(AttrFactory);
3839 if (Tok.is(tok::identifier)) {
3842 II = Tok.getIdentifierInfo();
3844 }
else if (Tok.is(tok::annot_decltype)) {
3849 ParseDecltypeSpecifier(DS);
3850 }
else if (Tok.is(tok::annot_pack_indexing_type)) {
3853 ParsePackIndexingType(DS);
3855 TemplateIdAnnotation *TemplateId = Tok.is(tok::annot_template_id)
3856 ? takeTemplateIdAnnotation(Tok)
3861 assert(Tok.is(tok::annot_typename) &&
"template-id -> type failed");
3863 ConsumeAnnotationToken();
3865 Diag(Tok, diag::err_expected_member_or_base_name);
3872 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
3875 ExprResult InitList = ParseBraceInitializer();
3879 SourceLocation EllipsisLoc;
3884 return Actions.ActOnMemInitializer(ConstructorDecl,
getCurScope(), SS, II,
3885 TemplateTypeTy.
get(), DS, IdLoc,
3886 InitList.
get(), EllipsisLoc);
3887 }
else if (Tok.is(tok::l_paren)) {
3892 ExprVector ArgExprs;
3893 auto RunSignatureHelp = [&] {
3896 QualType PreferredType =
3897 Actions.CodeCompletion().ProduceCtorInitMemberSignatureHelp(
3898 ConstructorDecl, SS, TemplateTypeTy.
get(), ArgExprs, II,
3899 T.getOpenLocation(),
false);
3900 CalledSignatureHelp =
true;
3901 return PreferredType;
3903 if (Tok.isNot(tok::r_paren) && ParseExpressionList(ArgExprs, [&] {
3904 PreferredType.enterFunctionArgument(Tok.getLocation(),
3907 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
3915 SourceLocation EllipsisLoc;
3920 return Actions.ActOnMemInitializer(
3921 ConstructorDecl,
getCurScope(), SS, II, TemplateTypeTy.
get(), DS, IdLoc,
3922 T.getOpenLocation(), ArgExprs,
T.getCloseLocation(), EllipsisLoc);
3929 return Diag(Tok, diag::err_expected_either) << tok::l_paren << tok::l_brace;
3931 return Diag(Tok, diag::err_expected) << tok::l_paren;
3940 ExceptionSpecTokens =
nullptr;
3944 if (Tok.isNot(tok::kw_throw) && Tok.isNot(tok::kw_noexcept))
3948 bool IsNoexcept = Tok.is(tok::kw_noexcept);
3949 Token StartTok = Tok;
3953 if (!Tok.is(tok::l_paren)) {
3956 Diag(Tok, diag::warn_cxx98_compat_noexcept_decl);
3957 NoexceptExpr =
nullptr;
3961 Diag(Tok, diag::err_expected_lparen_after) <<
"throw";
3967 ExceptionSpecTokens->push_back(StartTok);
3968 ExceptionSpecTokens->push_back(Tok);
3969 SpecificationRange.
setEnd(ConsumeParen());
3971 ConsumeAndStoreUntil(tok::r_paren, *ExceptionSpecTokens,
3974 SpecificationRange.
setEnd(ExceptionSpecTokens->back().getLocation());
3980 if (Tok.is(tok::kw_throw)) {
3981 Result = ParseDynamicExceptionSpecification(
3982 SpecificationRange, DynamicExceptions, DynamicExceptionRanges);
3983 assert(DynamicExceptions.size() == DynamicExceptionRanges.size() &&
3984 "Produced different number of exception types and ranges.");
3988 if (Tok.isNot(tok::kw_noexcept))
3991 Diag(Tok, diag::warn_cxx98_compat_noexcept_decl);
3995 SourceRange NoexceptRange;
3999 if (Tok.is(tok::l_paren)) {
4004 EnterExpressionEvaluationContext ConstantEvaluated(
4011 Actions.ActOnNoexceptSpec(NoexceptExpr.
get(), NoexceptType);
4012 NoexceptRange = SourceRange(KeywordLoc,
T.getCloseLocation());
4019 NoexceptRange = SourceRange(KeywordLoc, KeywordLoc);
4023 SpecificationRange = NoexceptRange;
4028 if (Tok.is(tok::kw_throw)) {
4029 Diag(Tok.getLocation(), diag::err_dynamic_and_noexcept_specification);
4030 ParseDynamicExceptionSpecification(NoexceptRange, DynamicExceptions,
4031 DynamicExceptionRanges);
4034 Diag(Tok.getLocation(), diag::err_dynamic_and_noexcept_specification);
4043 const char *Replacement = IsNoexcept ?
"noexcept" :
"noexcept(false)";
4045 ? diag::ext_dynamic_exception_spec
4046 : diag::warn_exception_spec_deprecated)
4048 P.
Diag(Range.getBegin(), diag::note_exception_spec_deprecated)
4056 assert(Tok.is(tok::kw_throw) &&
"expected throw");
4060 if (
T.consumeOpen()) {
4061 Diag(Tok, diag::err_expected_lparen_after) <<
"throw";
4068 if (Tok.is(tok::ellipsis)) {
4071 Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec);
4073 SpecificationRange.
setEnd(
T.getCloseLocation());
4080 while (Tok.isNot(tok::r_paren)) {
4083 if (Tok.is(tok::ellipsis)) {
4088 Range.setEnd(Ellipsis);
4089 if (!Res.isInvalid())
4090 Res = Actions.ActOnPackExpansion(Res.get(), Ellipsis);
4093 if (!Res.isInvalid()) {
4094 Exceptions.push_back(Res.get());
4095 Ranges.push_back(Range);
4103 SpecificationRange.
setEnd(
T.getCloseLocation());
4105 Exceptions.empty());
4110 bool MayBeFollowedByDirectInit) {
4111 assert(Tok.is(tok::arrow) &&
"expected arrow");
4120void Parser::ParseTrailingRequiresClauseWithScope(
Declarator &D) {
4121 assert(Tok.is(tok::kw_requires) &&
"expected requires");
4137 DeclaratorScopeObj DeclScopeObj(*
this, SS);
4139 DeclScopeObj.EnterDeclaratorScope();
4145 ParseTrailingRequiresClause(D);
4148void Parser::ParseTrailingRequiresClause(
Declarator &D) {
4149 assert(Tok.is(tok::kw_requires) &&
"expected requires");
4152 "trailing requires-clause must be parsed in a function prototype scope");
4157 Actions.ActOnStartTrailingRequiresClause(
getCurScope(), D);
4159 std::optional<Sema::CXXThisScopeRAII> ThisScope;
4160 InitCXXThisScopeForDeclaratorIfRelevant(D, D.
getDeclSpec(), ThisScope);
4162 TrailingRequiresClause =
4165 TrailingRequiresClause =
4166 Actions.ActOnFinishTrailingRequiresClause(TrailingRequiresClause);
4170 diag::err_requires_clause_on_declarator_not_declaring_a_function);
4175 SkipUntil({tok::l_brace, tok::arrow, tok::kw_try, tok::comma, tok::colon},
4183 SourceLocation ArrowLoc = Tok.getLocation();
4186 ParseTrailingReturnType(Range,
false);
4190 diag::err_requires_clause_must_appear_after_trailing_return)
4194 FunctionChunk.TrailingReturnType = TrailingReturnType.
get();
4195 FunctionChunk.TrailingReturnTypeLoc =
Range.getBegin();
4197 SkipUntil({tok::equal, tok::l_brace, tok::arrow, tok::kw_try, tok::comma},
4203 bool NonNestedClass,
4205 assert((NonNestedClass || !ClassStack.empty()) &&
4206 "Nested class without outer class");
4207 ClassStack.push(
new ParsingClass(ClassDecl, NonNestedClass, IsInterface));
4208 return Actions.PushParsingClass();
4211void Parser::DeallocateParsedClasses(Parser::ParsingClass *
Class) {
4212 for (
unsigned I = 0, N =
Class->LateParsedDeclarations.size(); I != N; ++I)
4213 delete Class->LateParsedDeclarations[I];
4218 assert(!ClassStack.empty() &&
"Mismatched push/pop for class parsing");
4220 Actions.PopParsingClass(state);
4222 ParsingClass *Victim = ClassStack.top();
4224 if (Victim->TopLevelClass) {
4227 DeallocateParsedClasses(Victim);
4230 assert(!ClassStack.empty() &&
"Missing top-level class?");
4232 if (Victim->LateParsedDeclarations.empty()) {
4237 DeallocateParsedClasses(Victim);
4245 "Nested class outside of class scope?");
4246 ClassStack.top()->LateParsedDeclarations.push_back(
4247 new LateParsedClass(
this, Victim));
4253 switch (Tok.getKind()) {
4256 if (!Tok.isAnnotation()) {
4257 if (IdentifierInfo *II = Tok.getIdentifierInfo()) {
4264 case tok::code_completion:
4266 Actions.CodeCompletion().CodeCompleteAttribute(
4271 case tok::numeric_constant: {
4275 if (Tok.getLocation().isMacroID()) {
4276 SmallString<8> ExpansionBuf;
4277 SourceLocation ExpansionLoc =
4278 PP.getSourceManager().getExpansionLoc(Tok.getLocation());
4279 StringRef Spelling = PP.getSpelling(ExpansionLoc, ExpansionBuf);
4280 if (Spelling ==
"__clang__") {
4281 SourceRange TokRange(
4283 PP.getSourceManager().getExpansionLoc(Tok.getEndLoc()));
4284 Diag(Tok, diag::warn_wrong_clang_attr_namespace)
4287 return &PP.getIdentifierTable().get(
"_Clang");
4300 case tok::pipeequal:
4301 case tok::caretequal:
4303 case tok::exclaimequal:
4306 SmallString<8> SpellingBuf;
4307 SourceLocation SpellingLoc =
4308 PP.getSourceManager().getSpellingLoc(Tok.getLocation());
4309 StringRef Spelling = PP.getSpelling(SpellingLoc, SpellingBuf);
4312 return &PP.getIdentifierTable().get(Spelling);
4318void Parser::ParseOpenMPAttributeArgs(
const IdentifierInfo *AttrName,
4323 if (
T.consumeOpen()) {
4324 Diag(Tok, diag::err_expected) << tok::l_paren;
4328 if (
AttrName->isStr(
"directive")) {
4334 OMPBeginTok.
setKind(tok::annot_attr_openmp);
4336 OpenMPTokens.push_back(OMPBeginTok);
4338 ConsumeAndStoreUntil(tok::r_paren, OpenMPTokens,
false,
4342 OMPEndTok.
setKind(tok::annot_pragma_openmp_end);
4344 OpenMPTokens.push_back(OMPEndTok);
4346 assert(
AttrName->isStr(
"sequence") &&
4347 "Expected either 'directive' or 'sequence'");
4355 SourceLocation IdentLoc;
4356 const IdentifierInfo *Ident = TryParseCXX11AttributeIdentifier(IdentLoc);
4360 if (Ident && Ident->
isStr(
"omp") && !ExpectAndConsume(tok::coloncolon))
4361 Ident = TryParseCXX11AttributeIdentifier(IdentLoc);
4365 if (!Ident || (!Ident->
isStr(
"directive") && !Ident->
isStr(
"sequence"))) {
4366 Diag(Tok.getLocation(), diag::err_expected_sequence_or_directive);
4372 ParseOpenMPAttributeArgs(Ident, OpenMPTokens);
4386 case ParsedAttr::AT_CarriesDependency:
4387 case ParsedAttr::AT_Deprecated:
4388 case ParsedAttr::AT_FallThrough:
4389 case ParsedAttr::AT_CXX11NoReturn:
4390 case ParsedAttr::AT_NoUniqueAddress:
4391 case ParsedAttr::AT_Likely:
4392 case ParsedAttr::AT_Unlikely:
4394 case ParsedAttr::AT_WarnUnusedResult:
4395 return !ScopeName && AttrName->getName() ==
"nodiscard";
4396 case ParsedAttr::AT_Unused:
4397 return !ScopeName && AttrName->getName() ==
"maybe_unused";
4403bool Parser::ParseCXXAssumeAttributeArg(
4407 assert(Tok.is(tok::l_paren) &&
"Not a C++11 attribute argument list");
4415 TentativeParsingAction TPA(*
this);
4420 if (Tok.is(tok::r_paren))
4425 if (!Tok.isOneOf(tok::r_paren, tok::r_square)) {
4431 auto *E = Res.
get();
4432 Diag(E->getExprLoc(), diag::err_assume_attr_expects_cond_expr)
4436 << E->getSourceRange();
4445 auto RParen = Tok.getLocation();
4447 Attrs.
addNew(AttrName, SourceRange(AttrNameLoc, RParen),
4448 AttributeScopeInfo(ScopeName, ScopeLoc), &Assumption, 1, Form);
4456bool Parser::ParseCXX11AttributeArgs(
4460 assert(Tok.is(tok::l_paren) &&
"Not a C++11 attribute argument list");
4461 SourceLocation LParenLoc = Tok.getLocation();
4463 ParsedAttr::Form Form =
4464 LO.CPlusPlus ? ParsedAttr::Form::CXX11() : ParsedAttr::Form::
C23();
4470 Form = ParsedAttr::Form::Microsoft();
4474 TentativeParsingAction TPA(*this);
4475 bool HasInvalidArgument = false;
4476 while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::eof)) {
4477 if (Tok.isOneOf(tok::hash, tok::hashhash)) {
4478 Diag(Tok.getLocation(), diag::ext_invalid_attribute_argument)
4479 << PP.getSpelling(Tok);
4480 HasInvalidArgument = true;
4485 if (HasInvalidArgument) {
4499 ScopeName, AttrName, getTargetInfo(), getLangOpts())) {
4502 SkipUntil(tok::r_paren);
4506 if (ScopeName && (ScopeName->
isStr(
"gnu") || ScopeName->
isStr(
"__gnu__"))) {
4509 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
4510 ScopeLoc, Form, nullptr);
4515 if (ScopeName && ScopeName->
isStr(
"omp") &&
4517 Diag(AttrNameLoc, getLangOpts().OpenMP >= 51
4518 ? diag::warn_omp51_compat_attributes
4519 : diag::ext_omp_attributes);
4521 ParseOpenMPAttributeArgs(AttrName, OpenMPTokens);
4530 if (ScopeName && (ScopeName->
isStr(
"clang") || ScopeName->
isStr(
"_Clang")))
4531 NumArgs = ParseClangAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc,
4532 ScopeName, ScopeLoc, Form);
4534 else if (!ScopeName &&
AttrName->isStr(
"assume")) {
4535 if (ParseCXXAssumeAttributeArg(Attrs, AttrName, AttrNameLoc, nullptr,
4536 SourceLocation{}, EndLoc, Form))
4540 NumArgs = ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
4541 ScopeName, ScopeLoc, Form);
4543 if (!Attrs.
empty() &&
4548 if (!
Attr.existsInTarget(getTargetInfo())) {
4549 Actions.DiagnoseUnknownAttribute(
Attr);
4550 Attr.setInvalid(
true);
4558 if (
Attr.getMaxArgs() && !NumArgs) {
4561 Diag(LParenLoc, diag::err_attribute_requires_arguments) <<
AttrName;
4562 Attr.setInvalid(
true);
4563 }
else if (!
Attr.getMaxArgs()) {
4567 auto D =
Diag(LParenLoc, diag::err_cxx11_attribute_forbids_arguments)
4571 Attr.setInvalid(
true);
4580 if (Tok.is(tok::kw_alignas)) {
4586 Diag(Tok.getLocation(), diag::warn_cxx98_compat_alignas);
4587 ParseAlignmentSpecifier(Attrs, EndLoc);
4591 if (Tok.isRegularKeywordAttribute()) {
4592 SourceLocation Loc = Tok.getLocation();
4593 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
4594 ParsedAttr::Form Form = ParsedAttr::Form(Tok.getKind());
4598 if (!Tok.is(tok::l_paren))
4599 Diag(Tok.getLocation(), diag::err_expected_lparen_after) <<
AttrName;
4601 ParseAttributeArgsCommon(AttrName, Loc, Attrs, EndLoc,
4605 Attrs.
addNew(AttrName, Loc, AttributeScopeInfo(),
nullptr, 0, Form);
4609 assert(Tok.is(tok::l_square) &&
NextToken().
is(tok::l_square) &&
4610 "Not a double square bracket attribute list");
4612 SourceLocation OpenLoc = Tok.getLocation();
4615 : diag::warn_ext_cxx11_attributes);
4618 : diag::warn_ext_c23_attributes);
4622 checkCompoundToken(OpenLoc, tok::l_square, CompoundToken::AttrBegin);
4625 SourceLocation CommonScopeLoc;
4626 IdentifierInfo *CommonScopeName =
nullptr;
4627 if (Tok.is(tok::kw_using)) {
4629 ? diag::warn_cxx14_compat_using_attribute_ns
4630 : diag::ext_using_attribute_ns);
4633 CommonScopeName = TryParseCXX11AttributeIdentifier(
4635 if (!CommonScopeName) {
4636 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
4640 Diag(Tok.getLocation(), diag::err_expected) << tok::colon;
4643 bool AttrParsed =
false;
4644 while (!Tok.isOneOf(tok::r_square, tok::semi, tok::eof)) {
4648 if (ExpectAndConsume(tok::comma)) {
4659 SourceLocation ScopeLoc, AttrLoc;
4660 IdentifierInfo *ScopeName =
nullptr, *
AttrName =
nullptr;
4662 AttrName = TryParseCXX11AttributeIdentifier(
4674 AttrName = TryParseCXX11AttributeIdentifier(
4678 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
4684 if (CommonScopeName) {
4686 Diag(ScopeLoc, diag::err_using_attribute_ns_conflict)
4687 << SourceRange(CommonScopeLoc);
4689 ScopeName = CommonScopeName;
4690 ScopeLoc = CommonScopeLoc;
4695 if (Tok.is(tok::l_paren))
4696 AttrParsed = ParseCXX11AttributeArgs(AttrName, AttrLoc, Attrs, EndLoc,
4697 ScopeName, ScopeLoc, OpenMPTokens);
4705 AttributeScopeInfo(ScopeName, ScopeLoc, CommonScopeLoc),
4708 : ParsedAttr::Form::C23());
4713 Diag(Tok, diag::err_cxx11_attribute_forbids_ellipsis) <<
AttrName;
4716 SourceLocation CloseLoc = Tok.getLocation();
4717 bool IsTokenNotFound = ExpectAndConsume(tok::r_square);
4718 if (IsTokenNotFound)
4720 else if (Tok.is(tok::r_square))
4721 checkCompoundToken(CloseLoc, tok::r_square, CompoundToken::AttrEnd);
4723 *EndLoc = Tok.getLocation();
4724 if (!IsTokenNotFound && ExpectAndConsume(tok::r_square))
4729 SourceLocation StartLoc = Tok.getLocation();
4730 SourceLocation EndLoc = StartLoc;
4733 ParseCXX11AttributeSpecifier(Attrs, &EndLoc);
4734 }
while (isAllowedCXX11AttributeSpecifier());
4736 Attrs.
Range = SourceRange(StartLoc, EndLoc);
4739void Parser::DiagnoseAndSkipCXX11Attributes() {
4741 Tok.isRegularKeywordAttribute() ? Tok.getIdentifierInfo() :
nullptr;
4743 SourceLocation StartLoc = Tok.getLocation();
4744 SourceLocation EndLoc = SkipCXX11Attributes();
4747 SourceRange
Range(StartLoc, EndLoc);
4749 :
Diag(StartLoc, diag::err_attributes_not_allowed))
4755 SourceLocation EndLoc;
4761 if (Tok.is(tok::l_square)) {
4765 EndLoc =
T.getCloseLocation();
4766 }
else if (Tok.isRegularKeywordAttribute() &&
4768 EndLoc = Tok.getLocation();
4771 assert((Tok.is(tok::kw_alignas) || Tok.isRegularKeywordAttribute()) &&
4772 "not an attribute specifier");
4775 if (!
T.consumeOpen())
4777 EndLoc =
T.getCloseLocation();
4779 }
while (isCXX11AttributeSpecifier() !=
4786 assert(Tok.is(tok::identifier) &&
"Not a Microsoft attribute list");
4787 IdentifierInfo *UuidIdent = Tok.getIdentifierInfo();
4788 assert(UuidIdent->
getName() ==
"uuid" &&
"Not a Microsoft attribute list");
4790 SourceLocation UuidLoc = Tok.getLocation();
4795 if (
T.consumeOpen()) {
4796 Diag(Tok, diag::err_expected) << tok::l_paren;
4801 if (isTokenStringLiteral()) {
4806 ArgExprs.push_back(StringResult.
get());
4812 SmallString<42> StrBuffer;
4822 SourceLocation StartLoc = Tok.getLocation();
4823 while (Tok.isNot(tok::r_paren)) {
4824 if (Tok.hasLeadingSpace() || Tok.isAtStartOfLine()) {
4825 Diag(Tok, diag::err_attribute_uuid_malformed_guid);
4829 SmallString<16> SpellingBuffer;
4830 SpellingBuffer.resize(Tok.getLength() + 1);
4831 bool Invalid =
false;
4832 StringRef TokSpelling = PP.getSpelling(Tok, SpellingBuffer, &Invalid);
4837 StrBuffer += TokSpelling;
4842 if (Tok.hasLeadingSpace() || Tok.isAtStartOfLine()) {
4843 Diag(Tok, diag::err_attribute_uuid_malformed_guid);
4853 Toks[0].
setKind(tok::string_literal);
4857 StringLiteral *UuidString =
4859 ArgExprs.push_back(UuidString);
4862 if (!
T.consumeClose()) {
4863 Attrs.
addNew(UuidIdent, SourceRange(UuidLoc,
T.getCloseLocation()),
4864 AttributeScopeInfo(), ArgExprs.data(), ArgExprs.size(),
4865 ParsedAttr::Form::Microsoft());
4870 assert(Tok.is(tok::identifier) &&
4871 "Expected an identifier to denote which MS attribute to consider");
4872 IdentifierInfo *RootSignatureIdent = Tok.getIdentifierInfo();
4873 assert(RootSignatureIdent->
getName() ==
"RootSignature" &&
4874 "Expected RootSignature identifier for root signature attribute");
4876 SourceLocation RootSignatureLoc = Tok.getLocation();
4881 if (
T.consumeOpen()) {
4882 Diag(Tok, diag::err_expected) << tok::l_paren;
4886 auto ProcessStringLiteral = [
this]() -> std::optional<StringLiteral *> {
4887 if (!isTokenStringLiteral())
4888 return std::nullopt;
4892 return std::nullopt;
4894 if (
auto Lit = dyn_cast<StringLiteral>(StringResult.
get()))
4897 return std::nullopt;
4900 auto Signature = ProcessStringLiteral();
4901 if (!Signature.has_value()) {
4902 Diag(Tok, diag::err_expected_string_literal)
4903 << 4 <<
"RootSignature";
4909 Actions,
getLangOpts().HLSLRootSigVer, *Signature);
4917 IdentifierLoc *ILoc = ::new (Actions.getASTContext())
4918 IdentifierLoc(RootSignatureLoc, DeclIdent);
4922 if (!
T.consumeClose())
4923 Attrs.
addNew(RootSignatureIdent,
4924 SourceRange(RootSignatureLoc,
T.getCloseLocation()),
4925 AttributeScopeInfo(), Args.data(), Args.size(),
4926 ParsedAttr::Form::Microsoft());
4930 assert(Tok.is(tok::l_square) &&
"Not a Microsoft attribute list");
4932 SourceLocation StartLoc = Tok.getLocation();
4933 SourceLocation EndLoc = StartLoc;
4941 SkipUntil(tok::r_square, tok::identifier,
4943 if (Tok.is(tok::code_completion)) {
4945 Actions.CodeCompletion().CodeCompleteAttribute(
4951 if (Tok.isNot(tok::identifier))
4953 if (Tok.getIdentifierInfo()->getName() ==
"uuid")
4954 ParseMicrosoftUuidAttributeArgs(Attrs);
4955 else if (Tok.getIdentifierInfo()->getName() ==
"RootSignature")
4956 ParseHLSLRootSignatureAttributeArgs(Attrs);
4958 IdentifierInfo *II = Tok.getIdentifierInfo();
4959 SourceLocation NameLoc = Tok.getLocation();
4966 bool AttrParsed =
false;
4967 if (Tok.is(tok::l_paren)) {
4970 ParseCXX11AttributeArgs(II, NameLoc, Attrs, &EndLoc,
nullptr,
4971 SourceLocation(), OpenMPTokens);
4972 ReplayOpenMPAttributeTokens(OpenMPTokens);
4975 Attrs.
addNew(II, NameLoc, AttributeScopeInfo(),
nullptr, 0,
4976 ParsedAttr::Form::Microsoft());
4983 EndLoc =
T.getCloseLocation();
4984 }
while (Tok.is(tok::l_square));
4986 Attrs.
Range = SourceRange(StartLoc, EndLoc);
4989void Parser::ParseMicrosoftIfExistsClassDeclaration(
4992 IfExistsCondition
Result;
4993 if (ParseMicrosoftIfExistsCondition(
Result))
4997 if (
Braces.consumeOpen()) {
4998 Diag(Tok, diag::err_expected) << tok::l_brace;
5002 switch (
Result.Behavior) {
5008 Diag(
Result.KeywordLoc, diag::warn_microsoft_dependent_exists)
5018 while (Tok.isNot(tok::r_brace) && !isEofOrEom()) {
5020 if (Tok.isOneOf(tok::kw___if_exists, tok::kw___if_not_exists)) {
5021 ParseMicrosoftIfExistsClassDeclaration(TagType, AccessAttrs, CurAS);
5026 if (Tok.is(tok::semi)) {
5035 SourceLocation ASLoc = Tok.getLocation();
5037 if (Tok.is(tok::colon))
5038 Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.getLocation(),
5039 ParsedAttributesView{});
5041 Diag(Tok, diag::err_expected) << tok::colon;
5046 ParsedTemplateInfo TemplateInfo;
5048 ParseCXXClassMemberDeclaration(CurAS, AccessAttrs, TemplateInfo);
Defines the clang::ASTContext interface.
This file defines the classes used to store parsed information about declaration-specifiers and decla...
Defines the C++ template declaration subclasses.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
llvm::MachO::RecordLoc RecordLoc
static void diagnoseDynamicExceptionSpecification(Parser &P, SourceRange Range, bool IsNoexcept)
static bool IsBuiltInOrStandardCXX11Attribute(IdentifierInfo *AttrName, IdentifierInfo *ScopeName)
static FixItHint getStaticAssertNoMessageFixIt(const Expr *AssertExpr, SourceLocation EndExprLoc)
This file declares facilities that support code completion.
This file declares semantic analysis for HLSL constructs.
Defines the clang::TokenKind enum and support functions.
#define TRANSFORM_TYPE_TRAIT_DEF(Enum, _)
Attr - This represents one attribute.
@ AS_Microsoft
[uuid("...")] class Foo
Kind getParsedKind() const
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ....
SourceLocation getOpenLocation() const
SourceLocation getCloseLocation() const
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
bool isValid() const
A scope specifier is present, and it refers to a real scope.
SourceRange getRange() const
SourceLocation getBeginLoc() const
bool isSet() const
Deprecated.
bool isInvalid() const
An error occurred during parsing of the scope specifier.
void setTemplateParamLists(ArrayRef< TemplateParameterList * > L)
static CharSourceRange getTokenRange(SourceRange R)
Captures information about "declaration specifiers".
void setTypeArgumentRange(SourceRange range)
static const TST TST_typename
bool hasTypeSpecifier() const
Return true if any type-specifier has been found.
void ClearStorageClassSpecs()
TST getTypeSpecType() const
SCS getStorageClassSpec() const
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
SourceRange getSourceRange() const LLVM_READONLY
void SetPackIndexingExpr(SourceLocation EllipsisLoc, Expr *Pack)
void SetRangeEnd(SourceLocation Loc)
static const TST TST_interface
unsigned getTypeQualifiers() const
getTypeQualifiers - Return a set of TQs.
void SetRangeStart(SourceLocation Loc)
static const TST TST_union
static const TST TST_typename_pack_indexing
SourceLocation getFriendSpecLoc() const
SourceLocation getModulePrivateSpecLoc() const
bool isFriendSpecifiedFirst() const
Expr * getRepAsExpr() const
static const TST TST_decltype
void takeAttributesAppendingingFrom(ParsedAttributes &attrs)
static const TST TST_class
bool hasTagDefinition() const
static const char * getSpecifierName(DeclSpec::TST T, const PrintingPolicy &Policy)
Turn a type-specifier-type into a string like "_Bool" or "union".
Decl * getRepAsDecl() const
CXXScopeSpec & getTypeSpecScope()
static const TST TST_decltype_auto
void setExternInLinkageSpec(bool Value)
static const TST TST_error
void forEachQualifier(llvm::function_ref< void(TQ, StringRef, SourceLocation)> Handle)
This method calls the passed in handler on each qual being set.
FriendSpecified isFriendSpecified() const
static const TST TST_struct
Decl - This represents one declaration (or definition), e.g.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
bool isInvalidDecl() const
SourceLocation getLocation() const
void setLocation(SourceLocation L)
Information about one declarator, including the parsed type information and the identifier.
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
bool isPastIdentifier() const
isPastIdentifier - Return true if we have parsed beyond the point where the name would appear.
bool isArrayOfUnknownBound() const
isArrayOfUnknownBound - This method returns true if the declarator is a declarator for an array of un...
bool isDeclarationOfFunction() const
Determine whether the declaration that will be produced from this declaration will be a function.
void setCommaLoc(SourceLocation CL)
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
const ParsedAttributes & getAttributes() const
SourceLocation getIdentifierLoc() const
void SetIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Set the name of this declarator to be the given identifier.
TemplateParameterList * getInventedTemplateParameterList() const
The template parameter list generated from the explicit template parameters along with any invented t...
void setTrailingRequiresClause(Expr *TRC)
Sets a trailing requires clause for this declarator.
void setTemplateParameterLists(ArrayRef< TemplateParameterList * > TPLs)
Sets the template parameter lists that preceded the declarator.
bool isFirstDeclarator() const
void setFunctionDefinitionKind(FunctionDefinitionKind Val)
const CXXScopeSpec & getCXXScopeSpec() const
getCXXScopeSpec - Return the C++ scope specifier (global scope or nested-name-specifier) that is part...
bool hasName() const
hasName - Whether this declarator has a name, which might be an identifier (accessible via getIdentif...
ArrayRef< TemplateParameterList * > getTemplateParameterLists() const
The template parameter lists that preceded the declarator.
void clear()
Reset the contents of this Declarator.
void setAsmLabel(Expr *E)
void ExtendWithDeclSpec(const DeclSpec &DS)
ExtendWithDeclSpec - Extend the declarator source range to include the given declspec,...
void SetRangeEnd(SourceLocation Loc)
SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.
bool isStaticMember()
Returns true if this declares a static member.
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
This represents one expression.
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
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 FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
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.
One of these records is kept for each identifier that is lexed.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
void revertTokenIDToIdentifier()
Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2 compatibility.
StringRef getName() const
Return the actual identifier string.
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
This represents a decl that may have a name.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
static OpaquePtr make(DeclGroupRef P)
ParsedAttr - Represents a syntactic attribute.
static const ParsedAttributesView & none()
void prepend(iterator B, iterator E)
ParsedAttributes - A collection of parsed attributes.
void takeAllPrependingFrom(ParsedAttributes &Other)
void takeAllAppendingFrom(ParsedAttributes &Other)
ParsedAttr * addNew(IdentifierInfo *attrName, SourceRange attrRange, AttributeScopeInfo scope, ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form, SourceLocation ellipsisLoc=SourceLocation())
Add attribute with expression arguments.
ParseScope - Introduces a new scope for parsing.
Parser - This implements a parser for the C family of languages.
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeName, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
static TypeResult getTypeAnnotation(const Token &Tok)
getTypeAnnotation - Read a parsed type out of an annotation token.
ExprResult ParseConstraintLogicalOrExpression(bool IsTrailingRequiresClause)
Parse a constraint-logical-or-expression.
ExprResult ParseConstantExpressionInExprEvalContext(TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
bool ParseUnqualifiedId(CXXScopeSpec &SS, ParsedType ObjectType, bool ObjectHadErrors, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, SourceLocation *TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
friend class ColonProtectionRAIIObject
DeclGroupPtrTy ParseOpenACCDirectiveDecl(AccessSpecifier &AS, ParsedAttributes &Attrs, DeclSpec::TST TagType, Decl *TagDecl)
Parse OpenACC directive on a declaration.
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type.
const Token & GetLookAheadToken(unsigned N)
GetLookAheadToken - This peeks ahead N tokens and returns that token without consuming any tokens.
ExprResult ParseConstantExpression()
ExprResult ParseConditionalExpression()
bool TryConsumeToken(tok::TokenKind Expected)
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
Scope * getCurScope() const
const TargetInfo & getTargetInfo() const
OpaquePtr< TemplateName > TemplateTy
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
void SkipMalformedDecl()
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a s...
friend class PoisonSEHIdentifiersRAIIObject
const LangOptions & getLangOpts() const
friend class ParenBraceBracketBalancer
ExprResult ParseExpression(TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
Simple precedence-based parser for binary/ternary operators.
@ StopBeforeMatch
Stop skipping at specified token, but don't skip the token itself.
@ StopAtCodeCompletion
Stop at code completion.
@ StopAtSemi
Stop skipping at semicolon.
ExprResult ParseUnevaluatedStringLiteralExpression()
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
friend class BalancedDelimiterTracker
SmallVector< TemplateParameterList *, 4 > TemplateParameterLists
bool TryAnnotateCXXScopeToken(bool EnteringContext=false)
TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only annotates C++ scope specifiers and ...
RAII object used to inform the actions that we're currently parsing a declaration.
A class for parsing a DeclSpec.
Scope - A scope is a transient data structure that is used while parsing the program.
unsigned getFlags() const
getFlags - Return the flags for this scope.
const Scope * getParent() const
getParent - Return the scope that this is nested in.
@ FunctionPrototypeScope
This is a scope that corresponds to the parameters within a function prototype.
@ TypeAliasScope
This is a scope of type alias declaration.
@ ClassInheritanceScope
We are between inheritance colon and the real class/struct definition scope.
@ ClassScope
The scope of a struct/union/class definition.
@ FunctionDeclarationScope
This is a scope that corresponds to the parameters within a function prototype for a function declara...
@ DeclScope
This is a scope that can contain a declaration.
@ PCC_TopLevelOrExpression
Code completion occurs at top-level in a REPL session.
@ PCC_Namespace
Code completion occurs at top-level or namespace context.
ProcessingContextState ParsingClassState
@ ConstantEvaluated
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
@ PotentiallyEvaluatedIfUsed
The current expression is potentially evaluated, but any declarations referenced inside that expressi...
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
A trivial tuple used to represent a source range.
void setBegin(SourceLocation b)
SourceLocation getBegin() const
void setEnd(SourceLocation e)
Represents the declaration of a struct/union/class/enum.
bool isDependent() const
Determines whether this is a dependent template name.
Token - This structure provides full information about a lexed token.
IdentifierInfo * getIdentifierInfo() const
void setLiteralData(const char *Ptr)
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
void setLength(unsigned Len)
void setKind(tok::TokenKind K)
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)) {....
tok::TokenKind getKind() const
void setLocation(SourceLocation L)
void startToken()
Reset all flags to cleared.
Represents a C++11 virt-specifier-seq.
Specifier getLastSpecifier() const
SourceLocation getFirstLocation() const
SourceLocation getAbstractLoc() const
static const char * getSpecifierName(Specifier VS)
bool SetSpecifier(Specifier VS, SourceLocation Loc, const char *&PrevSpec)
Defines the clang::TargetInfo interface.
@ After
Like System, but searched after the system directories.
IdentifierInfo * ParseHLSLRootSignature(Sema &Actions, llvm::dxbc::RootSignatureVersion Version, StringLiteral *Signature)
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
constexpr bool isRegularKeywordAttribute(TokenKind K)
bool isPragmaAnnotation(TokenKind K)
Return true if this is an annotation token representing a pragma.
Top level wrappers for InstallAPI frontend operations.
bool doesKeywordAttributeTakeArgs(tok::TokenKind Kind)
bool isa(CodeGen::Address addr)
@ NotAttributeSpecifier
This is not an attribute specifier.
MutableArrayRef< TemplateParameterList * > MultiTemplateParamsArg
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
FunctionDefinitionKind
Described the kind of function definition (if any) provided for a function.
int hasAttribute(AttributeCommonInfo::Syntax Syntax, llvm::StringRef ScopeName, llvm::StringRef AttrName, const TargetInfo &Target, const LangOptions &LangOpts, bool CheckPlugins)
Return the version number associated with the attribute if we recognize and implement the attribute s...
InClassInitStyle
In-class initialization styles for non-static data members.
@ ICIS_CopyInit
Copy initialization.
@ ICIS_ListInit
Direct list-initialization.
@ ICIS_NoInit
No in-class initializer.
llvm::PointerUnion< Expr *, IdentifierLoc * > ArgsUnion
A union of the various pointer types that can be passed to an ParsedAttr as an argument.
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
bool tokenIsLikeStringLiteral(const Token &Tok, const LangOptions &LO)
Return true if the token is a string literal, or a function local predefined macro,...
@ IK_TemplateId
A template-id, e.g., f<int>.
@ IK_Identifier
An identifier.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
ActionResult< Decl * > DeclResult
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
llvm::SmallVector< ArgsUnion, 12U > ArgsVector
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
@ Skip
Skip the block entirely; this code is never used.
@ Parse
Parse the block; this code is always used.
LLVM_READONLY bool isLetter(unsigned char c)
Return true if this character is an ASCII letter: [a-zA-Z].
@ Result
The result type of a method or function.
ActionResult< ParsedType > TypeResult
ActionResult< CXXCtorInitializer * > MemInitResult
const FunctionProtoType * T
@ Template
We are parsing a template declaration.
@ ExplicitSpecialization
We are parsing an explicit specialization.
@ ExplicitInstantiation
We are parsing an explicit instantiation.
@ NonTemplate
We are not parsing a template at all.
ActionResult< CXXBaseSpecifier * > BaseResult
@ Keyword
The name has been typo-corrected to a keyword.
@ Type
The name was classified as a type.
MutableArrayRef< ParsedTemplateArgument > ASTTemplateArgsPtr
@ AfterMemberFunctionDefinition
TemplateNameKind
Specifies the kind of template name that an identifier refers to.
@ TNK_Non_template
The name does not refer to a template.
@ TNK_Undeclared_template
Lookup for the name failed, but we're assuming it was a template name anyway.
U cast(CodeGen::Address addr)
SmallVector< Token, 4 > CachedTokens
A set of tokens that has been cached for later parsing.
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
ActionResult< Expr * > ExprResult
@ Braces
New-expression has a C++11 list-initializer.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_Unparsed
not parsed yet
@ EST_None
no exception specification
@ EST_MSAny
Microsoft throw(...) extension.
@ EST_BasicNoexcept
noexcept
@ EST_Dynamic
throw(T1, T2)
CachedTokens * ExceptionSpecTokens
Pointer to the cached tokens for an exception-specification that has not yet been parsed.
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
unsigned HasTrailingReturnType
HasTrailingReturnType - If this is true, a trailing return type was specified.
ExceptionSpecificationType getExceptionSpecType() const
Get the type of exception specification this function has.
std::unique_ptr< CachedTokens > DefaultArgTokens
DefaultArgTokens - When the parameter's default argument cannot be parsed immediately (because it occ...
const IdentifierInfo * Name
FIXME: Temporarily stores the name of a specialization.
TemplateNameKind Kind
The kind of template that Template refers to.
unsigned NumArgs
NumArgs - The number of template arguments.
SourceLocation TemplateNameLoc
TemplateNameLoc - The location of the template name within the source.
ParsedTemplateArgument * getTemplateArgs()
Retrieves a pointer to the template arguments.
SourceLocation RAngleLoc
The location of the '>' after the template argument list.
SourceLocation LAngleLoc
The location of the '<' before the template argument list.
SourceLocation TemplateKWLoc
TemplateKWLoc - The location of the template keyword.
bool mightBeType() const
Determine whether this might be a type template.
ParsedTemplateTy Template
The declaration of the template corresponding to the template-name.