28#include "llvm/Support/Compiler.h"
29#include "llvm/Support/ErrorHandling.h"
37 case tok::unknown:
return 0;
39 case tok::kw_addrspace_cast:
return 1;
40 case tok::kw_const_cast:
return 2;
41 case tok::kw_dynamic_cast:
return 3;
42 case tok::kw_reinterpret_cast:
return 4;
43 case tok::kw_static_cast:
return 5;
45 llvm_unreachable(
"Unknown type for digraph error message.");
49bool Parser::areTokensAdjacent(
const Token &
First,
const Token &Second) {
50 SourceManager &SM = PP.getSourceManager();
67 P.
Diag(DigraphToken.
getLocation(), diag::err_missing_whitespace_digraph)
72 ColonToken.
setKind(tok::coloncolon);
75 DigraphToken.
setKind(tok::less);
87 if (!
Next.is(tok::l_square) ||
Next.getLength() != 2)
91 if (!SecondToken.
is(tok::colon) || !areTokensAdjacent(
Next, SecondToken))
97 bool MemberOfUnknownSpecialization;
98 if (!Actions.isTemplateName(
getCurScope(), SS,
false,
100 Template, MemberOfUnknownSpecialization))
107bool Parser::ParseOptionalCXXScopeSpecifier(
109 bool EnteringContext,
bool *MayBePseudoDestructor,
bool IsTypename,
110 const IdentifierInfo **LastII,
bool OnlyNamespace,
bool InUsingDeclaration,
111 bool Disambiguation,
bool IsAddressOfOperand,
bool IsInDeclarationContext) {
113 "Call sites of this function should be guarded by checking for C++");
115 if (Tok.is(tok::annot_cxxscope)) {
116 assert(!LastII &&
"want last identifier but have already annotated scope");
117 assert(!MayBePseudoDestructor &&
"unexpected annot_cxxscope");
118 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
119 Tok.getAnnotationRange(),
121 ConsumeAnnotationToken();
126 bool CheckForDestructor =
false;
127 if (MayBePseudoDestructor && *MayBePseudoDestructor) {
128 CheckForDestructor =
true;
129 *MayBePseudoDestructor =
false;
135 bool HasScopeSpecifier =
false;
137 if (Tok.is(tok::coloncolon)) {
140 if (NextKind == tok::kw_new || NextKind == tok::kw_delete)
143 if (NextKind == tok::l_brace) {
149 if (Actions.ActOnCXXGlobalScopeSpecifier(
ConsumeToken(), SS))
152 HasScopeSpecifier =
true;
156 if (Tok.is(tok::kw___super)) {
158 if (!Tok.is(tok::coloncolon)) {
159 Diag(Tok.getLocation(), diag::err_expected_coloncolon_after_super);
163 return Actions.ActOnSuperScopeSpecifier(SuperLoc,
ConsumeToken(), SS);
166 if (!HasScopeSpecifier &&
167 Tok.isOneOf(tok::kw_decltype, tok::annot_decltype)) {
168 DeclSpec DS(AttrFactory);
169 SourceLocation DeclLoc = Tok.getLocation();
170 SourceLocation EndLoc = ParseDecltypeSpecifier(DS);
172 SourceLocation CCLoc;
177 AnnotateExistingDecltypeSpecifier(DS, DeclLoc, EndLoc);
181 if (Actions.ActOnCXXNestedNameSpecifierDecltype(SS, DS, CCLoc))
184 HasScopeSpecifier =
true;
187 else if (!HasScopeSpecifier && Tok.is(tok::identifier) &&
201 SourceLocation Start = Tok.getLocation();
202 DeclSpec DS(AttrFactory);
203 SourceLocation CCLoc;
204 SourceLocation EndLoc = ParsePackIndexingType(DS);
210 Actions.ActOnPackIndexingType(Pattern, DS.getPackIndexingExpr(),
211 DS.getBeginLoc(), DS.getEllipsisLoc());
227 Diag(Start, diag::warn_pre_cxx26_ambiguous_pack_indexing_type) <<
Type;
234 if (Actions.ActOnCXXNestedNameSpecifierIndexedPack(SS, DS, CCLoc,
237 HasScopeSpecifier =
true;
242 auto SavedType = PreferredType;
244 if (HasScopeSpecifier) {
245 if (Tok.is(tok::code_completion)) {
249 Actions.CodeCompletion().CodeCompleteQualifiedId(
250 getCurScope(), SS, EnteringContext, InUsingDeclaration,
251 IsAddressOfOperand, IsInDeclarationContext, ObjectType.
get(),
271 ObjectType =
nullptr;
279 if (Tok.is(tok::kw_template)) {
283 if (!HasScopeSpecifier && !ObjectType)
286 TentativeParsingAction TPA(*
this);
290 if (Tok.is(tok::identifier)) {
292 TemplateName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
294 }
else if (Tok.is(tok::kw_operator)) {
299 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
308 diag::err_id_after_template_in_nested_name_spec)
321 if (Tok.isNot(tok::less)) {
332 if (AnnotateTemplateIdToken(
Template, TNK, SS, TemplateKWLoc,
339 if (Tok.is(tok::annot_template_id) &&
NextToken().
is(tok::coloncolon)) {
347 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
349 *MayBePseudoDestructor =
true;
354 *LastII = TemplateId->
Name;
357 ConsumeAnnotationToken();
359 assert(Tok.is(tok::coloncolon) &&
"NextToken() not working properly!");
362 HasScopeSpecifier =
true;
378 SourceLocation StartLoc
387 switch (Tok.getKind()) {
388#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
389#include "clang/Basic/BuiltinTraits.inc"
391 Tok.setKind(tok::identifier);
392 Diag(Tok, diag::ext_keyword_as_ident)
393 << Tok.getIdentifierInfo()->getName() << 0;
403 if (Tok.isNot(tok::identifier))
406 IdentifierInfo &II = *Tok.getIdentifierInfo();
413 Sema::NestedNameSpecInfo IdInfo(&II, Tok.getLocation(),
Next.getLocation(),
418 if (
Next.is(tok::colon) && !ColonIsSacred) {
419 if (Actions.IsInvalidUnlessNestedName(
getCurScope(), SS, IdInfo,
424 PP.LookAhead(1).is(tok::identifier)) {
425 Diag(
Next, diag::err_unexpected_colon_in_nested_name_spec)
428 Next.setKind(tok::coloncolon);
435 Token Identifier = Tok;
439 UnconsumeToken(Identifier);
443 if (
Next.is(tok::coloncolon)) {
445 *MayBePseudoDestructor =
true;
451 if (Next2.
is(tok::kw_private) || Next2.
is(tok::kw_protected) ||
452 Next2.
is(tok::kw_public) || Next2.
is(tok::kw_virtual)) {
453 Diag(Next2, diag::err_unexpected_token_in_nested_name_spec)
458 ColonColon.
setKind(tok::colon);
459 PP.EnterToken(ColonColon,
true);
469 Token Identifier = Tok;
471 assert(Tok.isOneOf(tok::coloncolon, tok::colon) &&
472 "NextToken() not working properly!");
473 Token ColonColon = Tok;
476 bool IsCorrectedToColon =
false;
477 bool *CorrectionFlagPtr = ColonIsSacred ? &IsCorrectedToColon :
nullptr;
478 if (Actions.ActOnCXXNestedNameSpecifier(
479 getCurScope(), IdInfo, EnteringContext, SS, CorrectionFlagPtr,
483 if (CorrectionFlagPtr && IsCorrectedToColon) {
484 ColonColon.
setKind(tok::colon);
485 PP.EnterToken(Tok,
true);
486 PP.EnterToken(ColonColon,
true);
492 HasScopeSpecifier =
true;
496 CheckForTemplateAndDigraph(
Next, ObjectType, EnteringContext, II, SS);
500 if (
Next.is(tok::less)) {
505 bool MemberOfUnknownSpecialization;
509 EnteringContext,
Template, MemberOfUnknownSpecialization,
516 isTemplateArgumentList(1) == TPResult::False)
527 if (AnnotateTemplateIdToken(
Template, TNK, SS, SourceLocation(),
533 if (MemberOfUnknownSpecialization && !Disambiguation &&
534 (ObjectType || SS.
isSet()) &&
535 (IsTypename || isTemplateArgumentList(1) == TPResult::True)) {
538 if (!ObjectHadErrors) {
543 unsigned DiagID = diag::err_missing_dependent_template_keyword;
545 DiagID = diag::warn_missing_dependent_template_keyword;
547 Diag(Tok.getLocation(), DiagID)
555 ObjectType, EnteringContext,
Template,
557 if (AnnotateTemplateIdToken(
Template, TNK, SS, SourceLocation(),
573 if (CheckForDestructor && !HasScopeSpecifier && Tok.is(tok::tilde))
574 *MayBePseudoDestructor =
true;
580 bool isAddressOfOperand) {
584 switch (Tok.getKind()) {
585 case tok::annot_non_type: {
586 NamedDecl *ND = getNonTypeAnnotation(Tok);
587 SourceLocation Loc = ConsumeAnnotationToken();
588 E = Actions.ActOnNameClassifiedAsNonType(
getCurScope(), SS, ND, Loc, Tok);
592 case tok::annot_non_type_dependent: {
593 IdentifierInfo *II = getIdentifierAnnotation(Tok);
594 SourceLocation Loc = ConsumeAnnotationToken();
598 if (isAddressOfOperand && isPostfixExpressionSuffixStart())
599 isAddressOfOperand =
false;
601 E = Actions.ActOnNameClassifiedAsDependentNonType(SS, II, Loc,
606 case tok::annot_non_type_undeclared: {
608 "undeclared non-type annotation should be unqualified");
609 IdentifierInfo *II = getIdentifierAnnotation(Tok);
610 SourceLocation Loc = ConsumeAnnotationToken();
611 E = Actions.ActOnNameClassifiedAsUndeclaredNonType(II, Loc);
616 SourceLocation TemplateKWLoc;
623 false, &TemplateKWLoc, Name))
628 if (isAddressOfOperand && isPostfixExpressionSuffixStart())
629 isAddressOfOperand =
false;
631 E = Actions.ActOnIdExpression(
632 getCurScope(), SS, TemplateKWLoc, Name, Tok.is(tok::l_paren),
633 isAddressOfOperand,
nullptr,
false);
638 E = tryParseCXXPackIndexingExpression(E);
641 checkPotentialAngleBracket(E);
646 assert(Tok.is(tok::ellipsis) &&
NextToken().
is(tok::l_square) &&
652 if (
T.consumeClose() || IndexExpr.
isInvalid())
654 return Actions.ActOnPackIndexingExpr(
getCurScope(), PackIdExpression.
get(),
655 EllipsisLoc,
T.getOpenLocation(),
656 IndexExpr.
get(),
T.getCloseLocation());
660Parser::tryParseCXXPackIndexingExpression(
ExprResult PackIdExpression) {
663 Tok.is(tok::ellipsis) &&
NextToken().
is(tok::l_square)) {
664 E = ParseCXXPackIndexingExpression(E);
669ExprResult Parser::ParseCXXIdExpression(
bool isAddressOfOperand) {
675 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
680 assert(!
Result.isUnset() &&
"Typo correction suggested a keyword replacement "
681 "for a previous keyword suggestion");
687 LambdaIntroducer Intro;
688 if (ParseLambdaIntroducer(Intro)) {
695 return ParseLambdaExpressionAfterIntroducer(Intro);
698ExprResult Parser::TryParseLambdaExpression() {
700 "Not at the start of a possible lambda expression.");
703 if (
Next.is(tok::eof))
708 if (
Next.is(tok::r_square) ||
709 Next.is(tok::equal) ||
710 (
Next.is(tok::amp) &&
711 After.isOneOf(tok::r_square, tok::comma)) ||
712 (
Next.is(tok::identifier) &&
713 After.is(tok::r_square)) ||
714 Next.is(tok::ellipsis)) {
715 return ParseLambdaExpression();
720 if (
Next.is(tok::identifier) &&
After.is(tok::identifier))
728 LambdaIntroducer Intro;
730 TentativeParsingAction TPA(*
this);
731 LambdaIntroducerTentativeParse Tentative;
732 if (ParseLambdaIntroducer(Intro, &Tentative)) {
738 case LambdaIntroducerTentativeParse::Success:
742 case LambdaIntroducerTentativeParse::Incomplete:
746 Intro = LambdaIntroducer();
747 if (ParseLambdaIntroducer(Intro))
751 case LambdaIntroducerTentativeParse::MessageSend:
752 case LambdaIntroducerTentativeParse::Invalid:
759 return ParseLambdaExpressionAfterIntroducer(Intro);
763 LambdaIntroducerTentativeParse *Tentative) {
765 *Tentative = LambdaIntroducerTentativeParse::Success;
767 assert(Tok.is(tok::l_square) &&
"Lambda expressions begin with '['.");
777 auto Result = [&](llvm::function_ref<void()> Action,
778 LambdaIntroducerTentativeParse State =
779 LambdaIntroducerTentativeParse::Invalid) {
790 auto NonTentativeAction = [&](llvm::function_ref<void()> Action) {
792 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
798 if (Tok.is(tok::amp) &&
803 if (!Tok.getIdentifierInfo()) {
808 }
else if (Tok.is(tok::equal)) {
815 while (Tok.isNot(tok::r_square)) {
817 if (Tok.isNot(tok::comma)) {
822 if (Tok.is(tok::code_completion) &&
825 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
832 Diag(Tok.getLocation(), diag::err_expected_comma_or_rsquare);
838 if (Tok.is(tok::code_completion)) {
843 Actions.CodeCompletion().CodeCompleteObjCMessageReceiver(
getCurScope());
845 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
857 IdentifierInfo *Id =
nullptr;
858 SourceLocation EllipsisLocs[4];
860 SourceLocation LocStart = Tok.getLocation();
862 if (Tok.is(tok::star)) {
864 if (Tok.is(tok::kw_this)) {
869 Diag(Tok.getLocation(), diag::err_expected_star_this_capture);
872 }
else if (Tok.is(tok::kw_this)) {
875 }
else if (Tok.isOneOf(tok::amp, tok::equal) &&
883 [&] {
Diag(Tok.getLocation(), diag::err_capture_default_first); },
884 LambdaIntroducerTentativeParse::Incomplete);
888 if (Tok.is(tok::amp)) {
892 if (Tok.is(tok::code_completion)) {
894 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
903 if (Tok.is(tok::identifier)) {
904 Id = Tok.getIdentifierInfo();
906 }
else if (Tok.is(tok::kw_this)) {
909 Diag(Tok.getLocation(), diag::err_this_captured_by_reference);
913 [&] {
Diag(Tok.getLocation(), diag::err_expected_capture); });
918 if (Tok.is(tok::l_paren)) {
927 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
928 }
else if (ParseExpressionList(Exprs)) {
933 Init = Actions.ActOnParenListExpr(
Parens.getOpenLocation(),
934 Parens.getCloseLocation(),
937 }
else if (Tok.isOneOf(tok::l_brace, tok::equal)) {
941 EnterExpressionEvaluationContext EC(
950 Init = ParseInitializer();
951 }
else if (Tok.is(tok::l_brace)) {
955 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
977 SourceLocation StartLoc = Tok.getLocation();
979 Init = ParseInitializer();
981 if (Tok.getLocation() != StartLoc) {
983 PP.RevertCachedTokens(1);
986 Tok.setLocation(StartLoc);
987 Tok.setKind(tok::annot_primary_expr);
988 setExprAnnotation(Tok,
Init);
989 Tok.setAnnotationEndLoc(PP.getLastCachedTokenLocation());
990 PP.AnnotateCachedTokens(Tok);
993 ConsumeAnnotationToken();
1002 if (Tentative && Tok.is(tok::identifier) &&
1005 *Tentative = LambdaIntroducerTentativeParse::MessageSend;
1010 SourceLocation EllipsisLoc;
1011 if (llvm::any_of(EllipsisLocs,
1012 [](SourceLocation Loc) {
return Loc.
isValid(); })) {
1016 SourceLocation *ExpectedEllipsisLoc =
1017 !InitCapture ? &EllipsisLocs[2] :
1020 EllipsisLoc = *ExpectedEllipsisLoc;
1022 unsigned DiagID = 0;
1024 DiagID = diag::err_lambda_capture_misplaced_ellipsis;
1025 for (SourceLocation Loc : EllipsisLocs) {
1030 unsigned NumEllipses = std::accumulate(
1031 std::begin(EllipsisLocs), std::end(EllipsisLocs), 0,
1032 [](
int N, SourceLocation Loc) {
return N + Loc.
isValid(); });
1033 if (NumEllipses > 1)
1034 DiagID = diag::err_lambda_capture_multiple_ellipses;
1037 NonTentativeAction([&] {
1039 SourceLocation DiagLoc;
1040 for (SourceLocation &Loc : EllipsisLocs) {
1041 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid()) {
1046 assert(DiagLoc.
isValid() &&
"no location for diagnostic");
1050 auto &&D =
Diag(DiagLoc, DiagID);
1051 if (DiagID == diag::err_lambda_capture_misplaced_ellipsis) {
1052 SourceLocation ExpectedLoc =
1058 for (SourceLocation &Loc : EllipsisLocs) {
1059 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid())
1071 if (
Init.isUsable()) {
1072 NonTentativeAction([&] {
1075 Expr *InitExpr =
Init.get();
1078 InitCaptureType = Actions.actOnLambdaInitCaptureInitialization(
1079 Loc, Kind ==
LCK_ByRef, EllipsisLoc, Id, InitKind, InitExpr);
1084 SourceLocation LocEnd = PrevTokLocation;
1087 InitCaptureType, SourceRange(LocStart, LocEnd));
1109 auto ConsumeLocation = [&P, &DeclEndLoc](
SourceLocation &SpecifierLoc,
1111 if (SpecifierLoc.isValid()) {
1113 diag::err_lambda_decl_specifier_repeated)
1118 DeclEndLoc = SpecifierLoc;
1123 case tok::kw_mutable:
1124 ConsumeLocation(MutableLoc, 0);
1126 case tok::kw_static:
1127 ConsumeLocation(StaticLoc, 1);
1129 case tok::kw_constexpr:
1130 ConsumeLocation(ConstexprLoc, 2);
1132 case tok::kw_consteval:
1133 ConsumeLocation(ConstevalLoc, 3);
1144 P.
DiagCompat(StaticLoc, diag_compat::static_lambda);
1145 const char *PrevSpec =
nullptr;
1146 unsigned DiagID = 0;
1150 assert(PrevSpec ==
nullptr && DiagID == 0 &&
1151 "Static cannot have been set previously!");
1159 P.
DiagCompat(ConstexprLoc, diag_compat::constexpr_on_lambda);
1160 const char *PrevSpec =
nullptr;
1161 unsigned DiagID = 0;
1164 assert(PrevSpec ==
nullptr && DiagID == 0 &&
1165 "Constexpr cannot have been set previously!");
1173 P.
Diag(ConstevalLoc, diag::warn_cxx20_compat_consteval);
1174 const char *PrevSpec =
nullptr;
1175 unsigned DiagID = 0;
1179 P.
Diag(ConstevalLoc, DiagID) << PrevSpec;
1195 P.
Diag(StaticLoc, diag::err_static_mutable_lambda);
1197 P.
Diag(StaticLoc, diag::err_static_lambda_captures);
1201ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
1205 Diag(LambdaBeginLoc, diag::ext_hlsl_lambda) << 1;
1208 ? diag::warn_cxx98_compat_lambda
1212 PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), LambdaBeginLoc,
1213 "lambda expression parsing");
1216 DeclSpec DS(AttrFactory);
1218 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1224 Actions.PushLambdaScope();
1225 SourceLocation DeclLoc = Tok.getLocation();
1227 Actions.ActOnLambdaExpressionAfterIntroducer(Intro,
getCurScope());
1229 ParsedAttributes Attributes(AttrFactory);
1237 if (Tok.is(tok::kw___noinline__)) {
1238 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1240 Attributes.addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
1242 0, tok::kw___noinline__);
1243 }
else if (Tok.is(tok::kw___attribute))
1244 ParseGNUAttributes(Attributes,
nullptr, &D);
1249 D.takeAttributesAppending(Attributes);
1253 if (Tok.is(tok::less)) {
1254 DiagCompat(Tok, diag_compat::lambda_template_parameter_list);
1256 SmallVector<NamedDecl*, 4> TemplateParams;
1257 SourceLocation LAngleLoc, RAngleLoc;
1258 if (ParseTemplateParameters(TemplateParamScope,
1259 CurTemplateDepthTracker.getDepth(),
1260 TemplateParams, LAngleLoc, RAngleLoc)) {
1261 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1265 if (TemplateParams.empty()) {
1267 diag::err_lambda_template_parameter_list_empty);
1278 ++CurTemplateDepthTracker;
1288 Actions.ActOnLambdaExplicitTemplateParameterList(
1289 Intro, LAngleLoc, TemplateParams, RAngleLoc, RequiresClause);
1297 if (isCXX11AttributeSpecifier() !=
1300 ? diag::warn_cxx20_compat_decl_attrs_on_lambda
1301 : diag::ext_decl_attrs_on_lambda)
1302 << Tok.isRegularKeywordAttribute() << Tok.getIdentifierInfo();
1303 MaybeParseCXX11Attributes(D);
1307 SourceLocation TrailingReturnTypeLoc;
1308 SourceLocation LParenLoc, RParenLoc;
1309 SourceLocation DeclEndLoc = DeclLoc;
1310 bool HasParentheses =
false;
1311 bool HasSpecifiers =
false;
1312 SourceLocation MutableLoc;
1319 SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
1320 SourceLocation EllipsisLoc;
1322 if (Tok.is(tok::l_paren)) {
1325 LParenLoc =
T.getOpenLocation();
1327 if (Tok.isNot(tok::r_paren)) {
1328 Actions.RecordParsingTemplateParameterDepth(
1329 CurTemplateDepthTracker.getOriginalDepth());
1331 ParseParameterDeclarationClause(D, Attributes, ParamInfo, EllipsisLoc);
1337 if (Actions.getCurGenericLambda())
1338 CurTemplateDepthTracker.setAddedDepth(1);
1342 DeclEndLoc = RParenLoc =
T.getCloseLocation();
1343 HasParentheses =
true;
1347 Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
1348 tok::kw_constexpr, tok::kw_consteval, tok::kw_static,
1349 tok::kw___private, tok::kw___global, tok::kw___local,
1350 tok::kw___constant, tok::kw___generic, tok::kw_groupshared,
1351 tok::kw_requires, tok::kw_noexcept) ||
1352 Tok.isRegularKeywordAttribute() ||
1353 (Tok.is(tok::l_square) &&
NextToken().
is(tok::l_square));
1359 Diag(Tok, diag::ext_lambda_missing_parens)
1363 if (HasParentheses || HasSpecifiers) {
1367 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec, Attributes);
1370 SourceLocation ConstexprLoc;
1371 SourceLocation ConstevalLoc;
1372 SourceLocation StaticLoc;
1375 ConstevalLoc, DeclEndLoc);
1384 Actions.ActOnLambdaClosureParameters(
getCurScope(), ParamInfo);
1386 if (!HasParentheses)
1387 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1389 if (HasSpecifiers || HasParentheses) {
1392 SourceRange ESpecRange;
1393 SmallVector<ParsedType, 2> DynamicExceptions;
1394 SmallVector<SourceRange, 2> DynamicExceptionRanges;
1398 ESpecType = tryParseExceptionSpecification(
1399 false, ESpecRange, DynamicExceptions,
1400 DynamicExceptionRanges, NoexceptExpr, ExceptionSpecTokens);
1403 DeclEndLoc = ESpecRange.
getEnd();
1406 if (MaybeParseCXX11Attributes(Attributes))
1407 DeclEndLoc = Attributes.Range.getEnd();
1410 if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
1411 tok::kw___constant, tok::kw___generic)) {
1412 ParseOpenCLQualifiers(DS.getAttributes());
1419 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1421 SourceLocation FunLocalRangeEnd = DeclEndLoc;
1424 if (Tok.is(tok::arrow)) {
1425 FunLocalRangeEnd = Tok.getLocation();
1428 ParseTrailingReturnType(Range,
false);
1429 TrailingReturnTypeLoc =
Range.getBegin();
1430 if (
Range.getEnd().isValid())
1431 DeclEndLoc =
Range.getEnd();
1434 SourceLocation NoLoc;
1437 false, LParenLoc, ParamInfo.data(),
1438 ParamInfo.size(), EllipsisLoc, RParenLoc,
1440 NoLoc, MutableLoc, ESpecType,
1441 ESpecRange, DynamicExceptions.data(),
1442 DynamicExceptionRanges.data(), DynamicExceptions.size(),
1443 NoexceptExpr.
isUsable() ? NoexceptExpr.
get() :
nullptr,
1445 {}, LParenLoc, FunLocalRangeEnd, D,
1446 TrailingReturnType, TrailingReturnTypeLoc, &DS),
1447 std::move(Attributes), DeclEndLoc);
1449 if (HasParentheses && Tok.is(tok::kw_requires))
1450 ParseTrailingRequiresClause(D);
1456 for (
const ParsedAttr &A : Attributes)
1457 if (A.getKind() == ParsedAttr::AT_CUDADevice ||
1458 A.getKind() == ParsedAttr::AT_CUDAHost ||
1459 A.getKind() == ParsedAttr::AT_CUDAGlobal)
1460 Diag(A.getLoc(), diag::warn_cuda_attr_lambda_position)
1461 << A.getAttrName()->getName();
1472 Actions.ActOnStartOfLambdaDefinition(Intro, D, DS);
1475 if (!Tok.is(tok::l_brace)) {
1476 Diag(Tok, diag::err_expected_lambda_body);
1477 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1481 StmtResult Stmt(ParseCompoundStatementBody());
1483 TemplateParamScope.Exit();
1488 return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.get());
1490 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1496 const char *CastName =
nullptr;
1499 default: llvm_unreachable(
"Unknown C++ cast!");
1500 case tok::kw_addrspace_cast: CastName =
"addrspace_cast";
break;
1501 case tok::kw_const_cast: CastName =
"const_cast";
break;
1502 case tok::kw_dynamic_cast: CastName =
"dynamic_cast";
break;
1503 case tok::kw_reinterpret_cast: CastName =
"reinterpret_cast";
break;
1504 case tok::kw_static_cast: CastName =
"static_cast";
break;
1508 SourceLocation LAngleBracketLoc = Tok.getLocation();
1512 if (Tok.is(tok::l_square) && Tok.getLength() == 2) {
1514 if (
Next.is(tok::colon) && areTokensAdjacent(Tok,
Next))
1518 if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName))
1522 DeclSpec DS(AttrFactory);
1523 ParseSpecifierQualifierList(DS,
AS_none,
1524 DeclSpecContext::DSC_type_specifier);
1529 ParseDeclarator(DeclaratorInfo);
1531 SourceLocation RAngleBracketLoc = Tok.getLocation();
1533 if (ExpectAndConsume(tok::greater))
1534 return ExprError(
Diag(LAngleBracketLoc, diag::note_matching) << tok::less);
1538 if (
T.expectAndConsume(diag::err_expected_lparen_after, CastName))
1546 if (!
Result.isInvalid() && !DeclaratorInfo.isInvalidType())
1547 Result = Actions.ActOnCXXNamedCast(OpLoc, Kind,
1548 LAngleBracketLoc, DeclaratorInfo,
1550 T.getOpenLocation(),
Result.get(),
1551 T.getCloseLocation());
1557 assert(Tok.is(tok::kw_typeid) &&
"Not 'typeid'!");
1560 SourceLocation LParenLoc, RParenLoc;
1564 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"typeid"))
1566 LParenLoc =
T.getOpenLocation();
1587 if (isTypeIdInParens()) {
1592 RParenLoc =
T.getCloseLocation();
1596 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
true,
1606 RParenLoc =
T.getCloseLocation();
1610 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
false,
1611 Result.get(), RParenLoc);
1619 assert(Tok.is(tok::kw___uuidof) &&
"Not '__uuidof'!");
1625 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"__uuidof"))
1630 if (isTypeIdInParens()) {
1639 Result = Actions.ActOnCXXUuidof(OpLoc,
T.getOpenLocation(),
true,
1641 T.getCloseLocation());
1653 Result = Actions.ActOnCXXUuidof(OpLoc,
T.getOpenLocation(),
1655 Result.get(),
T.getCloseLocation());
1670 SourceLocation CCLoc;
1671 if (Tok.is(tok::identifier)) {
1672 FirstTypeName.
setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
1674 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1676 }
else if (Tok.is(tok::annot_template_id)) {
1677 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
1682 ConsumeAnnotationToken();
1683 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1686 assert(SS.
isEmpty() &&
"missing last component of nested name specifier");
1691 assert(Tok.is(tok::tilde) &&
"ParseOptionalCXXScopeSpecifier fail");
1694 if (Tok.is(tok::kw_decltype) && !FirstTypeName.
isValid()) {
1695 DeclSpec DS(AttrFactory);
1696 ParseDecltypeSpecifier(DS);
1699 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1703 if (!Tok.is(tok::identifier)) {
1704 Diag(Tok, diag::err_destructor_tilde_identifier);
1711 DeclSpec DS(AttrFactory);
1712 ParsePackIndexingType(DS);
1713 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1719 IdentifierInfo *Name = Tok.getIdentifierInfo();
1731 if (Tok.is(tok::less) &&
1732 ParseUnqualifiedIdTemplateId(
1733 SS, ObjectType, Base &&
Base->containsErrors(), SourceLocation(),
1734 Name, NameLoc,
false, SecondTypeName,
1738 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1739 SS, FirstTypeName, CCLoc, TildeLoc,
1745 return Actions.ActOnCXXBoolLiteral(
ConsumeToken(), Kind);
1749 assert(Tok.is(tok::kw_throw) &&
"Not throw!");
1755 switch (Tok.getKind()) {
1762 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc,
nullptr);
1766 if (Expr.isInvalid())
return Expr;
1767 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc, Expr.get());
1772 assert(Tok.is(tok::kw_co_yield) &&
"Not co_yield!");
1775 ExprResult Expr = Tok.is(tok::l_brace) ? ParseBraceInitializer()
1783 assert(Tok.is(tok::kw_this) &&
"Not 'this'!");
1785 return Actions.ActOnCXXThis(ThisLoc);
1789Parser::ParseCXXTypeConstructExpression(
const DeclSpec &DS) {
1792 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
1794 assert((Tok.is(tok::l_paren) ||
1796 &&
"Expected '(' or '{'!");
1798 if (Tok.is(tok::l_brace)) {
1799 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1801 if (
Init.isInvalid())
1804 return Actions.ActOnCXXTypeConstructExpr(
1811 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1815 auto RunSignatureHelp = [&]() {
1816 QualType PreferredType;
1819 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
1821 Exprs,
T.getOpenLocation(),
false);
1822 CalledSignatureHelp =
true;
1823 return PreferredType;
1826 if (Tok.isNot(tok::r_paren)) {
1827 if (ParseExpressionList(Exprs, [&] {
1828 PreferredType.enterFunctionArgument(Tok.getLocation(),
1831 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
1845 return Actions.ActOnCXXTypeConstructExpr(TypeRep,
T.getOpenLocation(),
1846 Exprs,
T.getCloseLocation(),
1854 assert(Tok.is(tok::kw_using) &&
"Expected using");
1857 "Unexpected Declarator Context");
1861 DG = ParseUsingDeclaration(Context, {}, DeclStart, DeclEnd, Attrs,
AS_none);
1865 DiagCompat(DeclStart, diag_compat::alias_in_init_statement);
1874 ForRangeInfo *FRI) {
1876 PreferredType.enterCondition(Actions, Tok.getLocation());
1878 if (Tok.is(tok::code_completion)) {
1880 Actions.CodeCompletion().CodeCompleteOrdinaryName(
1885 if (Tok.is(tok::kw___extension__)) {
1893 std::optional<ExtensionRAIIObject> ExtensionGuard;
1894 ExtensionGuard.emplace(Diags);
1903 ParsedAttributes attrs(AttrFactory);
1904 bool ParsedAttrs = MaybeParseCXX11Attributes(attrs);
1906 const auto WarnOnInit = [
this, &CK] {
1908 DiagCompat(Tok.getLocation(), diag_compat::init_statement)
1911 DiagCompat(Tok.getLocation(), diag_compat::decl_statement)
1916 if (isDeclarationStatement() && !isCXXSimpleDeclaration(
false)) {
1920 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
1921 ParsedAttributes DeclSpecAttrs(AttrFactory);
1925 StmtResult DeclStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd);
1926 if (InitStmt ==
nullptr) {
1927 if (DeclStmt.isUsable())
1928 Diag(DeclStmt.get()->getBeginLoc(), diag::err_expected_expression)
1929 << DeclStmt.get()->getSourceRange();
1931 Diag(DeclStart, diag::err_expected_expression);
1933 *InitStmt = DeclStmt;
1934 return ParseCondition(
nullptr, Loc, CK, MissingOK);
1939 if (InitStmt && Tok.is(tok::semi)) {
1943 *InitStmt = Actions.ActOnAttributedStmt(attrs,
Null.get());
1946 diag::err_c2y_first_condition_clause_is_not_declaration);
1947 return ParseCondition(
nullptr, Loc, CK, MissingOK);
1952 switch (isCXXConditionDeclarationOrInitStatement(InitStmt, FRI)) {
1953 case ConditionOrInitStatement::Expression: {
1954 ProhibitAttributes(attrs);
1958 if (InitStmt && Tok.is(tok::semi)) {
1960 SourceLocation SemiLoc = Tok.getLocation();
1961 if (!Tok.hasLeadingEmptyMacro() && !SemiLoc.
isMacroID()) {
1962 Diag(SemiLoc, diag::warn_empty_init_statement)
1967 *InitStmt = Actions.ActOnNullStmt(SemiLoc);
1968 return ParseCondition(
nullptr, Loc, CK, MissingOK);
1971 EnterExpressionEvaluationContext Eval(
1982 if (InitStmt && Tok.is(tok::semi)) {
1984 *InitStmt = Actions.ActOnExprStmt(Expr.
get());
1986 return ParseCondition(
nullptr, Loc, CK, MissingOK);
1989 return Actions.ActOnCondition(
getCurScope(), Loc, Expr.
get(), CK,
1993 case ConditionOrInitStatement::InitStmtDecl: {
1996 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
1997 if (Tok.is(tok::kw_using))
1998 DG = ParseAliasDeclarationInInitStatement(
2001 ParsedAttributes DeclSpecAttrs(AttrFactory);
2003 attrs, DeclSpecAttrs,
true);
2005 *InitStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd);
2006 return ParseCondition(
nullptr, Loc, CK, MissingOK);
2009 case ConditionOrInitStatement::ForRangeDecl: {
2013 assert(FRI &&
"should not parse a for range declaration here");
2014 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
2015 ParsedAttributes DeclSpecAttrs(AttrFactory);
2018 FRI->LoopVar = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
2019 return Sema::ConditionResult();
2022 case ConditionOrInitStatement::ConditionDecl:
2023 case ConditionOrInitStatement::Error:
2028 DeclSpec DS(AttrFactory);
2029 ParseSpecifierQualifierList(DS,
AS_none, DeclSpecContext::DSC_condition);
2033 ParseDeclarator(DeclaratorInfo);
2036 if (Tok.is(tok::kw_asm)) {
2038 ExprResult AsmLabel(ParseSimpleAsm(
true, &Loc));
2039 if (AsmLabel.isInvalid()) {
2043 DeclaratorInfo.setAsmLabel(AsmLabel.get());
2044 DeclaratorInfo.SetRangeEnd(Loc);
2048 MaybeParseGNUAttributes(DeclaratorInfo);
2059 bool CopyInitialization = isTokenEqualOrEqualTypo();
2060 if (CopyInitialization)
2065 Diag(Tok.getLocation(), diag::compat_cxx11_generalized_initializer_lists);
2066 InitExpr = ParseBraceInitializer();
2067 }
else if (CopyInitialization) {
2068 PreferredType.enterVariableInit(Tok.getLocation(), DeclOut);
2070 }
else if (Tok.is(tok::l_paren)) {
2072 SourceLocation LParen = ConsumeParen(), RParen = LParen;
2074 RParen = ConsumeParen();
2076 diag::err_expected_init_in_condition_lparen)
2077 << SourceRange(LParen, RParen);
2083 Actions.AddInitializerToDecl(DeclOut, InitExpr.
get(), !CopyInitialization);
2085 Actions.ActOnInitializerError(DeclOut);
2087 Actions.FinalizeDeclaration(DeclOut);
2088 return Actions.ActOnConditionVariable(DeclOut, Loc, CK);
2091void Parser::ParseCXXSimpleTypeSpecifier(
DeclSpec &DS) {
2093 const char *PrevSpec;
2095 SourceLocation Loc = Tok.getLocation();
2096 const clang::PrintingPolicy &Policy =
2097 Actions.getASTContext().getPrintingPolicy();
2099 switch (Tok.getKind()) {
2100 case tok::identifier:
2101 case tok::coloncolon:
2102 llvm_unreachable(
"Annotation token should already be formed!");
2104 llvm_unreachable(
"Not a simple-type-specifier token!");
2107 case tok::annot_typename: {
2111 ConsumeAnnotationToken();
2112 DS.
Finish(Actions, Policy);
2116 case tok::kw__ExtInt:
2117 case tok::kw__BitInt: {
2118 DiagnoseBitIntUse(Tok);
2127 DS.
Finish(Actions, Policy);
2140 case tok::kw___int64:
2144 case tok::kw_signed:
2147 case tok::kw_unsigned:
2162 case tok::kw___int128:
2165 case tok::kw___bf16:
2174 case tok::kw_double:
2177 case tok::kw__Float16:
2180 case tok::kw___float128:
2183 case tok::kw___ibm128:
2186 case tok::kw_wchar_t:
2189 case tok::kw_char8_t:
2192 case tok::kw_char16_t:
2195 case tok::kw_char32_t:
2201 case tok::kw__Accum:
2204 case tok::kw__Fract:
2210#define GENERIC_IMAGE_TYPE(ImgType, Id) \
2211 case tok::kw_##ImgType##_t: \
2212 DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, DiagID, \
2215#include "clang/Basic/OpenCLImageTypes.def"
2216#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
2217 case tok::kw_##Name: \
2218 DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, DiagID, Policy); \
2220#include "clang/Basic/HLSLIntangibleTypes.def"
2222 case tok::annot_decltype:
2223 case tok::kw_decltype:
2225 return DS.
Finish(Actions, Policy);
2227 case tok::annot_pack_indexing_type:
2229 return DS.
Finish(Actions, Policy);
2232 case tok::kw_typeof:
2233 case tok::kw_typeof_unqual:
2234 ParseTypeofSpecifier(DS);
2235 DS.
Finish(Actions, Policy);
2240 DS.
Finish(Actions, Policy);
2244 ParseSpecifierQualifierList(DS,
AS_none,
2245 getDeclSpecContextFromDeclaratorContext(Context));
2246 DS.
Finish(Actions, Actions.getASTContext().getPrintingPolicy());
2250bool Parser::ParseUnqualifiedIdTemplateId(
2253 bool EnteringContext,
UnqualifiedId &Id,
bool AssumeTemplateId) {
2254 assert(Tok.is(tok::less) &&
"Expected '<' to finish parsing a template-id");
2262 if (AssumeTemplateId) {
2265 TNK = Actions.ActOnTemplateName(
getCurScope(), SS, TemplateKWLoc, Id,
2266 ObjectType, EnteringContext,
Template,
2269 bool MemberOfUnknownSpecialization;
2272 ObjectType, EnteringContext,
Template,
2273 MemberOfUnknownSpecialization);
2278 isTemplateArgumentList(0) == TPResult::False)
2282 ObjectType && isTemplateArgumentList(0) == TPResult::True) {
2285 if (!ObjectHadErrors) {
2304 TNK = Actions.ActOnTemplateName(
2305 getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext,
2315 bool MemberOfUnknownSpecialization;
2320 MemberOfUnknownSpecialization);
2328 bool MemberOfUnknownSpecialization;
2331 TNK = Actions.ActOnTemplateName(
2337 Template, MemberOfUnknownSpecialization,
2341 Diag(NameLoc, diag::err_destructor_template_id)
2354 SourceLocation LAngleLoc, RAngleLoc;
2355 TemplateArgList TemplateArgs;
2356 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs, RAngleLoc,
2371 const IdentifierInfo *TemplateII =
2381 LAngleLoc, RAngleLoc, TemplateArgs,
false, TemplateIds);
2393 SourceLocation(), SS, TemplateKWLoc,
Template,
2394 Name, NameLoc, LAngleLoc, TemplateArgsPtr, RAngleLoc,
2396 if (
Type.isInvalid())
2407bool Parser::ParseUnqualifiedIdOperator(
CXXScopeSpec &SS,
bool EnteringContext,
2410 assert(Tok.is(tok::kw_operator) &&
"Expected 'operator' keyword");
2416 unsigned SymbolIdx = 0;
2417 SourceLocation SymbolLocations[3];
2419 switch (Tok.getKind()) {
2421 case tok::kw_delete: {
2422 bool isNew = Tok.getKind() == tok::kw_new;
2426 if (Tok.is(tok::l_square) &&
2432 if (
T.getCloseLocation().isInvalid())
2435 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2436 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2437 Op = isNew? OO_Array_New : OO_Array_Delete;
2439 Op = isNew? OO_New : OO_Delete;
2444#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
2446 SymbolLocations[SymbolIdx++] = ConsumeToken(); \
2449#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
2450#include "clang/Basic/OperatorKinds.def"
2452 case tok::l_paren: {
2457 if (
T.getCloseLocation().isInvalid())
2460 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2461 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2466 case tok::l_square: {
2471 if (
T.getCloseLocation().isInvalid())
2474 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2475 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2480 case tok::code_completion: {
2484 Actions.CodeCompletion().CodeCompleteOperatorName(
getCurScope());
2494 Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations);
2505 Diag(Tok.getLocation(), diag::warn_cxx98_compat_literal_operator);
2507 SourceLocation DiagLoc;
2508 unsigned DiagId = 0;
2512 SmallVector<Token, 4> Toks;
2513 SmallVector<SourceLocation, 4> TokLocs;
2514 while (isTokenStringLiteral()) {
2515 if (!Tok.is(tok::string_literal) && !DiagId) {
2519 DiagLoc = Tok.getLocation();
2520 DiagId = diag::err_literal_operator_string_prefix;
2522 Toks.push_back(Tok);
2523 TokLocs.push_back(ConsumeStringToken());
2526 StringLiteralParser
Literal(Toks, PP);
2532 bool IsUDSuffix = !
Literal.getUDSuffix().empty();
2533 IdentifierInfo *II =
nullptr;
2534 SourceLocation SuffixLoc;
2536 II = &PP.getIdentifierTable().get(
Literal.getUDSuffix());
2541 }
else if (Tok.is(tok::identifier)) {
2542 II = Tok.getIdentifierInfo();
2544 TokLocs.push_back(SuffixLoc);
2546 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
2556 DiagLoc = TokLocs.front();
2557 DiagId = diag::err_literal_operator_string_not_empty;
2563 SmallString<32> Str;
2567 SourceRange(TokLocs.front(), TokLocs.back()), Str);
2570 Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
2572 return Actions.checkLiteralOperatorId(SS,
Result, IsUDSuffix);
2587 DeclSpec DS(AttrFactory);
2588 if (ParseCXXTypeSpecifierSeq(
2596 ParseDeclaratorInternal(D,
nullptr);
2604 Result.setConversionFunctionId(KeywordLoc, Ty.
get(),
2605 D.getSourceRange().getEnd());
2610 bool ObjectHadErrors,
bool EnteringContext,
2611 bool AllowDestructorName,
2612 bool AllowConstructorName,
2613 bool AllowDeductionGuide,
2621 bool TemplateSpecified =
false;
2622 if (Tok.is(tok::kw_template)) {
2623 if (TemplateKWLoc && (ObjectType || SS.
isSet())) {
2624 TemplateSpecified =
true;
2628 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2636 if (Tok.is(tok::identifier)) {
2645 Result.setIdentifier(Id, IdLoc);
2650 if (AllowConstructorName &&
2651 Actions.isCurrentClassName(*Id,
getCurScope(), &SS)) {
2657 Result.setConstructorName(Ty, IdLoc, IdLoc);
2660 Actions.isDeductionGuideName(
getCurScope(), *Id, IdLoc, SS,
2666 Result.setIdentifier(Id, IdLoc);
2671 if (Tok.is(tok::less))
2672 return ParseUnqualifiedIdTemplateId(
2673 SS, ObjectType, ObjectHadErrors,
2675 EnteringContext,
Result, TemplateSpecified);
2677 if (TemplateSpecified) {
2680 ObjectType, EnteringContext,
Template,
2691 Diag(IdLoc, diag::missing_template_arg_list_after_template_kw);
2698 if (Tok.is(tok::annot_template_id)) {
2704 ConsumeAnnotationToken();
2709 if (AllowConstructorName && TemplateId->
Name &&
2717 diag::err_out_of_line_constructor_template_id)
2728 ConsumeAnnotationToken();
2732 Result.setConstructorTemplateId(TemplateId);
2733 ConsumeAnnotationToken();
2739 Result.setTemplateId(TemplateId);
2742 if (TemplateKWLoc && (ObjectType || SS.
isSet()))
2743 *TemplateKWLoc = TemplateLoc;
2745 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2748 ConsumeAnnotationToken();
2755 if (Tok.is(tok::kw_operator)) {
2756 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
Result))
2768 return ParseUnqualifiedIdTemplateId(
2769 SS, ObjectType, ObjectHadErrors,
2772 else if (TemplateSpecified &&
2773 Actions.ActOnTemplateName(
2783 (AllowDestructorName || SS.
isSet()) && Tok.is(tok::tilde)) {
2792 if (TemplateSpecified) {
2803 Diag(*TemplateKWLoc, diag::err_unexpected_template_in_destructor_name)
2804 << Tok.getLocation();
2808 if (SS.
isEmpty() && Tok.is(tok::kw_decltype)) {
2812 Actions.getDestructorTypeForDecltype(DS, ObjectType)) {
2813 Result.setDestructorName(TildeLoc,
Type, EndLoc);
2820 if (Tok.isNot(tok::identifier)) {
2821 Diag(Tok, diag::err_destructor_tilde_identifier);
2826 DeclaratorScopeObj DeclScopeObj(*
this, SS);
2834 AnnotateScopeToken(SS,
true);
2837 if (ParseOptionalCXXScopeSpecifier(SS, ObjectType, ObjectHadErrors,
2841 ObjectType =
nullptr;
2842 if (Tok.isNot(tok::identifier) ||
NextToken().
is(tok::coloncolon) ||
2844 Diag(TildeLoc, diag::err_destructor_tilde_scope);
2849 Diag(TildeLoc, diag::err_destructor_tilde_scope)
2854 if (Actions.ShouldEnterDeclaratorScope(
getCurScope(), SS))
2855 DeclScopeObj.EnterDeclaratorScope();
2862 if (Tok.is(tok::less)) {
2863 Result.setDestructorName(TildeLoc,
nullptr, ClassNameLoc);
2864 return ParseUnqualifiedIdTemplateId(
2865 SS, ObjectType, ObjectHadErrors,
2867 ClassNameLoc, EnteringContext,
Result, TemplateSpecified);
2872 Actions.getDestructorName(*ClassName, ClassNameLoc,
getCurScope(), SS,
2873 ObjectType, EnteringContext);
2877 Result.setDestructorName(TildeLoc, Ty, ClassNameLoc);
2881 switch (Tok.getKind()) {
2882#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
2883#include "clang/Basic/BuiltinTraits.inc"
2885 Tok.setKind(tok::identifier);
2886 Diag(Tok, diag::ext_keyword_as_ident)
2887 << Tok.getIdentifierInfo()->getName() << 0;
2888 goto ParseIdentifier;
2892 Diag(Tok, diag::err_expected_unqualified_id) <<
getLangOpts().CPlusPlus;
2898Parser::ParseCXXNewExpression(
bool UseGlobal,
SourceLocation Start) {
2899 assert(
Tok.is(tok::kw_new) &&
"expected 'new' token");
2905 ExprVector PlacementArgs;
2912 if (
Tok.is(tok::l_paren)) {
2916 PlacementLParen =
T.getOpenLocation();
2917 if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) {
2923 PlacementRParen =
T.getCloseLocation();
2929 if (PlacementArgs.empty()) {
2931 TypeIdParens =
T.getRange();
2932 PlacementLParen = PlacementRParen = SourceLocation();
2935 if (Tok.is(tok::l_paren)) {
2938 MaybeParseGNUAttributes(DeclaratorInfo);
2939 ParseSpecifierQualifierList(DS);
2941 ParseDeclarator(DeclaratorInfo);
2943 TypeIdParens =
T.getRange();
2945 MaybeParseGNUAttributes(DeclaratorInfo);
2946 if (ParseCXXTypeSpecifierSeq(DS))
2947 DeclaratorInfo.setInvalidType(
true);
2950 ParseDeclaratorInternal(DeclaratorInfo,
2951 &Parser::ParseDirectNewDeclarator);
2958 MaybeParseGNUAttributes(DeclaratorInfo);
2960 DeclaratorInfo.setInvalidType(
true);
2963 ParseDeclaratorInternal(DeclaratorInfo,
2964 &Parser::ParseDirectNewDeclarator);
2967 if (DeclaratorInfo.isInvalidType()) {
2974 if (Tok.is(tok::l_paren)) {
2975 SourceLocation ConstructorLParen, ConstructorRParen;
2976 ExprVector ConstructorArgs;
2979 ConstructorLParen =
T.getOpenLocation();
2980 if (Tok.isNot(tok::r_paren)) {
2981 auto RunSignatureHelp = [&]() {
2982 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
2983 QualType PreferredType;
2989 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
2991 DeclaratorInfo.getEndLoc(), ConstructorArgs,
2994 CalledSignatureHelp =
true;
2995 return PreferredType;
2997 if (ParseExpressionList(ConstructorArgs, [&] {
2998 PreferredType.enterFunctionArgument(Tok.getLocation(),
3001 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
3008 ConstructorRParen =
T.getCloseLocation();
3013 Initializer = Actions.ActOnParenListExpr(ConstructorLParen,
3017 Diag(Tok.getLocation(), diag::compat_cxx11_generalized_initializer_lists);
3023 return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen,
3024 PlacementArgs, PlacementRParen,
3028void Parser::ParseDirectNewDeclarator(
Declarator &D) {
3031 while (Tok.is(tok::l_square)) {
3033 if (CheckProhibitedCXX11Attribute())
3042 if (
Size.isInvalid()) {
3044 SkipUntil(tok::r_square, StopAtSemi);
3052 ParsedAttributes Attrs(AttrFactory);
3053 MaybeParseCXX11Attributes(Attrs);
3057 Size.get(),
T.getOpenLocation(),
3058 T.getCloseLocation()),
3059 std::move(Attrs),
T.getCloseLocation());
3061 if (
T.getCloseLocation().isInvalid())
3066bool Parser::ParseExpressionListOrTypeId(
3070 if (isTypeIdInParens()) {
3078 return ParseExpressionList(PlacementArgs);
3082Parser::ParseCXXDeleteExpression(
bool UseGlobal,
SourceLocation Start) {
3083 assert(Tok.is(tok::kw_delete) &&
"Expected 'delete' keyword");
3087 bool ArrayDelete =
false;
3088 if (Tok.is(tok::l_square) &&
NextToken().
is(tok::r_square)) {
3099 if (
Next.isOneOf(tok::l_brace, tok::less) ||
3100 (
Next.is(tok::l_paren) &&
3104 TentativeParsingAction TPA(*
this);
3105 SourceLocation LSquareLoc = Tok.getLocation();
3111 SourceLocation RBraceLoc;
3112 bool EmitFixIt =
false;
3113 if (Tok.is(tok::l_brace)) {
3116 RBraceLoc = Tok.getLocation();
3123 Diag(Start, diag::err_lambda_after_delete)
3124 << SourceRange(Start, RSquareLoc)
3128 RBraceLoc, 0, Actions.getSourceManager(),
getLangOpts()),
3131 Diag(Start, diag::err_lambda_after_delete)
3132 << SourceRange(Start, RSquareLoc);
3141 Lambda = ParsePostfixExpressionSuffix(Lambda);
3144 return Actions.ActOnCXXDelete(Start, UseGlobal,
false,
3153 if (
T.getCloseLocation().isInvalid())
3161 return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete,
Operand.get());
3164ExprResult Parser::ParseRequiresExpression() {
3165 assert(Tok.is(tok::kw_requires) &&
"Expected 'requires' keyword");
3168 llvm::SmallVector<ParmVarDecl *, 2> LocalParameterDecls;
3170 if (Tok.is(tok::l_paren)) {
3175 if (!Tok.is(tok::r_paren)) {
3177 SourceLocation EllipsisLoc;
3178 llvm::SmallVector<DeclaratorChunk::ParamInfo, 2> LocalParameters;
3180 FirstArgAttrs, LocalParameters,
3183 Diag(EllipsisLoc, diag::err_requires_expr_parameter_list_ellipsis);
3184 for (
auto &ParamInfo : LocalParameters)
3191 if (
Braces.expectAndConsume())
3195 llvm::SmallVector<concepts::Requirement *, 2> Requirements;
3199 EnterExpressionEvaluationContext Ctx(
3207 RequiresExprBodyDecl *Body = Actions.ActOnStartRequiresExpr(
3208 RequiresKWLoc, LocalParameterDecls,
getCurScope());
3210 if (Tok.is(tok::r_brace)) {
3217 Diag(Tok, diag::err_empty_requires_expr);
3220 while (!Tok.is(tok::r_brace)) {
3221 switch (Tok.getKind()) {
3222 case tok::l_brace: {
3233 ExprBraces.consumeOpen();
3235 if (Expression.isUsable())
3236 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3237 if (!Expression.isUsable()) {
3238 ExprBraces.skipToEnd();
3244 if (ExprBraces.consumeClose())
3247 concepts::Requirement *Req =
nullptr;
3248 SourceLocation NoexceptLoc;
3250 if (Tok.is(tok::semi)) {
3251 Req = Actions.ActOnCompoundRequirement(Expression.get(), NoexceptLoc);
3253 Requirements.push_back(Req);
3258 Diag(Tok, diag::err_requires_expr_missing_arrow)
3261 if (TryAnnotateTypeConstraint()) {
3265 if (!isTypeConstraintAnnotation()) {
3266 Diag(Tok, diag::err_requires_expr_expected_type_constraint);
3271 if (Tok.is(tok::annot_cxxscope)) {
3272 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
3273 Tok.getAnnotationRange(),
3275 ConsumeAnnotationToken();
3278 Req = Actions.ActOnCompoundRequirement(
3279 Expression.get(), NoexceptLoc, SS, takeTemplateIdAnnotation(Tok),
3280 TemplateParameterDepth);
3281 ConsumeAnnotationToken();
3283 Requirements.push_back(Req);
3287 bool PossibleRequiresExprInSimpleRequirement =
false;
3288 if (Tok.is(tok::kw_requires)) {
3289 auto IsNestedRequirement = [&] {
3290 RevertingTentativeParsingAction TPA(*
this);
3292 if (Tok.is(tok::l_brace))
3299 if (Tok.is(tok::l_paren)) {
3302 auto Res = TryParseParameterDeclarationClause();
3303 if (Res != TPResult::False) {
3306 while (Depth != 0) {
3307 bool FoundParen =
SkipUntil(tok::l_paren, tok::r_paren,
3311 if (Tok.is(tok::l_paren))
3313 else if (Tok.is(tok::r_paren))
3324 if (Tok.is(tok::l_brace))
3333 if (IsNestedRequirement()) {
3346 Actions.ActOnNestedRequirement(ConstraintExpr.
get()))
3347 Requirements.push_back(Req);
3355 PossibleRequiresExprInSimpleRequirement =
true;
3356 }
else if (Tok.is(tok::kw_typename)) {
3359 TentativeParsingAction TPA(*
this);
3369 if (Tok.is(tok::annot_cxxscope)) {
3370 Actions.RestoreNestedNameSpecifierAnnotation(
3371 Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS);
3372 ConsumeAnnotationToken();
3375 if (Tok.isOneOf(tok::identifier, tok::annot_template_id) &&
3378 SourceLocation NameLoc = Tok.getLocation();
3379 IdentifierInfo *II =
nullptr;
3380 TemplateIdAnnotation *TemplateId =
nullptr;
3381 if (Tok.is(tok::identifier)) {
3382 II = Tok.getIdentifierInfo();
3385 TemplateId = takeTemplateIdAnnotation(Tok);
3386 ConsumeAnnotationToken();
3391 if (
auto *Req = Actions.ActOnTypeRequirement(TypenameKWLoc, SS,
3394 Requirements.push_back(Req);
3404 SourceLocation StartLoc = Tok.getLocation();
3406 if (Expression.isUsable())
3407 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3408 if (!Expression.isUsable()) {
3412 if (!Expression.isInvalid() && PossibleRequiresExprInSimpleRequirement)
3413 Diag(StartLoc, diag::err_requires_expr_in_simple_requirement)
3415 if (
auto *Req = Actions.ActOnSimpleRequirement(Expression.get()))
3416 Requirements.push_back(Req);
3422 if (Tok.is(tok::kw_noexcept)) {
3423 Diag(Tok, diag::err_requires_expr_simple_requirement_noexcept)
3432 if (ExpectAndConsumeSemi(diag::err_expected_semi_requirement)) {
3438 if (Requirements.empty()) {
3443 Actions.ActOnFinishRequiresExpr();
3448 Actions.ActOnFinishRequiresExpr();
3449 ParsingBodyDecl.complete(Body);
3450 return Actions.ActOnRequiresExpr(
3451 RequiresKWLoc, Body,
Parens.getOpenLocation(), LocalParameterDecls,
3452 Parens.getCloseLocation(), Requirements,
Braces.getCloseLocation());
3457 default: llvm_unreachable(
"Not a known type trait");
3458#define TYPE_TRAIT_1(Spelling, Name, Key) \
3459case tok::kw_ ## Spelling: return UTT_ ## Name;
3460#define TYPE_TRAIT_2(Spelling, Name, Key) \
3461case tok::kw_ ## Spelling: return BTT_ ## Name;
3462#include "clang/Basic/TokenKinds.def"
3463#define TYPE_TRAIT_N(Spelling, Name, Key) \
3464 case tok::kw_ ## Spelling: return TT_ ## Name;
3465#include "clang/Basic/BuiltinTraits.inc"
3472 llvm_unreachable(
"Not a known array type trait");
3473#define ARRAY_TYPE_TRAIT(Spelling, Name, Key) \
3474 case tok::kw_##Spelling: \
3476#include "clang/Basic/BuiltinTraits.inc"
3483 llvm_unreachable(
"Not a known unary expression trait.");
3484#define EXPRESSION_TRAIT(Spelling, Name, Key) \
3485 case tok::kw_##Spelling: \
3487#include "clang/Basic/BuiltinTraits.inc"
3497 if (
Parens.expectAndConsume())
3500 SmallVector<ParsedType, 2> Args;
3513 if (Tok.is(tok::ellipsis)) {
3522 Args.push_back(Ty.
get());
3525 if (
Parens.consumeClose())
3528 SourceLocation EndLoc =
Parens.getCloseLocation();
3538 if (
T.expectAndConsume())
3550 case ATT_ArrayRank: {
3552 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(),
nullptr,
3553 T.getCloseLocation());
3555 case ATT_ArrayExtent: {
3556 if (ExpectAndConsume(tok::comma)) {
3567 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(), DimExpr.
get(),
3568 T.getCloseLocation());
3571 llvm_unreachable(
"Invalid ArrayTypeTrait!");
3579 if (
T.expectAndConsume())
3586 return Actions.ActOnExpressionTrait(ET, Loc, Expr.
get(),
3587 T.getCloseLocation());
3597 "Compound literals are not ambiguous!");
3598 assert(isTypeIdInParens() &&
"Not a type-id!");
3627 if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) {
3633 if (Tok.is(tok::l_brace)) {
3637 if (Tok.is(tok::l_paren) &&
NextToken().
is(tok::r_paren)) {
3645 false , NotCastExpr,
3658 AttrEnd.startToken();
3659 AttrEnd.setKind(tok::eof);
3660 AttrEnd.setLocation(Tok.getLocation());
3661 AttrEnd.setEofData(Toks.data());
3662 Toks.push_back(AttrEnd);
3665 Toks.push_back(Tok);
3668 PP.EnterTokenStream(Toks,
true,
3676 DeclSpec DS(AttrFactory);
3681 ParseSpecifierQualifierList(DS);
3682 ParseDeclarator(DeclaratorInfo);
3690 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3695 if (DeclaratorInfo.isInvalidType())
3698 TypeResult Ty = Actions.ActOnTypeName(DeclaratorInfo);
3699 return ParseCompoundLiteralExpression(Ty.
get(),
3707 if (DeclaratorInfo.isInvalidType())
3713 DeclaratorInfo, CastTy,
3723 if (!
Result.isInvalid() && Tok.is(tok::r_paren))
3725 Tok.getLocation(),
Result.get());
3728 if (
Result.isInvalid()) {
3729 while (Tok.isNot(tok::eof))
3731 assert(Tok.getEofData() == AttrEnd.getEofData());
3738 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3747 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"__builtin_bit_cast"))
3751 DeclSpec DS(AttrFactory);
3752 ParseSpecifierQualifierList(DS);
3757 ParseDeclarator(DeclaratorInfo);
3759 if (ExpectAndConsume(tok::comma)) {
3760 Diag(Tok.getLocation(), diag::err_expected) << tok::comma;
3767 if (
T.consumeClose())
3770 if (
Operand.isInvalid() || DeclaratorInfo.isInvalidType())
3773 return Actions.ActOnBuiltinBitCastExpr(KWLoc, DeclaratorInfo, Operand,
3774 T.getCloseLocation());
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.
Defines the clang::Expr interface and subclasses for C++ expressions.
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
static void addConstexprToLambdaDeclSpecifier(Parser &P, SourceLocation ConstexprLoc, DeclSpec &DS)
static void FixDigraph(Parser &P, Preprocessor &PP, Token &DigraphToken, Token &ColonToken, tok::TokenKind Kind, bool AtDigraph)
static ArrayTypeTrait ArrayTypeTraitFromTokKind(tok::TokenKind kind)
static void tryConsumeLambdaSpecifierToken(Parser &P, SourceLocation &MutableLoc, SourceLocation &StaticLoc, SourceLocation &ConstexprLoc, SourceLocation &ConstevalLoc, SourceLocation &DeclEndLoc)
static ExpressionTrait ExpressionTraitFromTokKind(tok::TokenKind kind)
static void addConstevalToLambdaDeclSpecifier(Parser &P, SourceLocation ConstevalLoc, DeclSpec &DS)
static TypeTrait TypeTraitFromTokKind(tok::TokenKind kind)
static void DiagnoseStaticSpecifierRestrictions(Parser &P, SourceLocation StaticLoc, SourceLocation MutableLoc, const LambdaIntroducer &Intro)
static int SelectDigraphErrorMessage(tok::TokenKind Kind)
static void addStaticToLambdaDeclSpecifier(Parser &P, SourceLocation StaticLoc, DeclSpec &DS)
Defines the PrettyStackTraceEntry class, which is used to make crashes give more contextual informati...
static constexpr bool isOneOf()
This file declares facilities that support code completion.
Defines the clang::TemplateNameKind enum.
Defines the clang::TokenKind enum and support functions.
const clang::PrintingPolicy & getPrintingPolicy() const
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ....
SourceLocation getOpenLocation() const
SourceLocation getCloseLocation() const
Represents a C++ nested-name-specifier or a global scope specifier.
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
SourceRange getRange() const
SourceLocation getBeginLoc() const
bool isSet() const
Deprecated.
void setEndLoc(SourceLocation Loc)
void SetInvalid(SourceRange R)
Indicate that this nested-name-specifier is invalid.
bool isEmpty() const
No scope specifier.
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed.
void restore()
restore - This can be used to restore the state early, before the dtor is run.
Captures information about "declaration specifiers".
static const TST TST_typename
SourceLocation getEndLoc() const LLVM_READONLY
bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec and return false if there was no error.
static const TST TST_char8
static const TST TST_BFloat16
bool SetConstexprSpec(ConstexprSpecKind ConstexprKind, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
bool SetTypeSpecWidth(TypeSpecifierWidth W, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec, but return true and ignore the request if ...
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
SourceRange getSourceRange() const LLVM_READONLY
void SetRangeEnd(SourceLocation Loc)
bool SetBitIntType(SourceLocation KWLoc, Expr *BitWidth, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
static const TST TST_double
void SetRangeStart(SourceLocation Loc)
static const TST TST_char
static const TST TST_bool
static const TST TST_char16
static const TST TST_accum
static const TST TST_half
static const TST TST_ibm128
static const TST TST_float128
void Finish(Sema &S, const PrintingPolicy &Policy)
Finish - This does final analysis of the declspec, issuing diagnostics for things like "_Complex" (la...
static const TST TST_wchar
static const TST TST_void
static const TST TST_float
static const TST TST_fract
static const TST TST_float16
static const TST TST_decltype_auto
static const TST TST_error
static const TST TST_char32
static const TST TST_int128
bool SetTypeSpecSign(TypeSpecifierSign S, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
static const TST TST_auto
SourceLocation getLocation() const
Information about one declarator, including the parsed type information and the identifier.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
void SetSourceRange(SourceRange R)
void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc)
AddTypeInfo - Add a chunk to this declarator.
bool isInvalidType() const
DeclSpec & getMutableDeclSpec()
getMutableDeclSpec - Return a non-const version of the DeclSpec.
This represents one expression.
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.
StringRef getName() const
Return the actual identifier string.
static SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, unsigned Characters, const SourceManager &SM, const LangOptions &LangOpts)
AdvanceToTokenCharacter - If the current SourceLocation specifies a location at the start of a token,...
static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, const LangOptions &LangOpts)
Computes the source location just past the end of the token at this source location.
void * getAsOpaquePtr() const
static OpaquePtr make(QualType P)
static const ParsedAttributesView & none()
ParsedAttributes - A collection of parsed attributes.
Introduces zero or more scopes for parsing.
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 getEndOfPreviousToken() const
DiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagId)
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
AttributeFactory & getAttrFactory()
Sema & getActions() const
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.
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.
bool TryAnnotateOptionalCXXScopeToken(bool EnteringContext=false)
friend class ColonProtectionRAIIObject
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()
bool TryConsumeToken(tok::TokenKind Expected)
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
Scope * getCurScope() const
friend class InMessageExpressionRAIIObject
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 ...
const Token & getCurToken() const
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.
@ StopAtSemi
Stop skipping at semicolon.
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
ExprResult ParseAssignmentExpression(TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
Parse an expr that doesn't include (top-level) commas.
friend class BalancedDelimiterTracker
ExprResult ParseConstraintExpression()
Parse a constraint-expression.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
void Lex(Token &Result)
Lex the next token for this preprocessor.
@ FunctionPrototypeScope
This is a scope that corresponds to the parameters within a function prototype.
@ LambdaScope
This is the scope for a lambda, after the lambda introducer.
@ BlockScope
This is a scope that corresponds to a block/closure object.
@ CompoundStmtScope
This is a compound statement scope.
@ FunctionDeclarationScope
This is a scope that corresponds to the parameters within a function prototype for a function declara...
@ FnScope
This indicates that the scope corresponds to a function, which means that labels are set here.
@ DeclScope
This is a scope that can contain a declaration.
@ PCC_Condition
Code completion occurs within the condition of an if, while, switch, or for statement.
@ Switch
An integral condition for a 'switch' statement.
@ ConstexprIf
A constant boolean condition from 'if constexpr'.
ASTContext & getASTContext() const
@ 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),...
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
static ConditionResult ConditionError()
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.
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID.
A trivial tuple used to represent a source range.
void setBegin(SourceLocation b)
SourceLocation getEnd() const
SourceLocation getBegin() const
void setEnd(SourceLocation e)
SourceLocation getEndLoc() const LLVM_READONLY
SourceLocation getBeginLoc() const LLVM_READONLY
Represents a C++ template name within the type system.
Token - This structure provides full information about a lexed token.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
const char * getName() const
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)
The base class of the type hierarchy.
QualType getCanonicalTypeInternal() const
Represents a C++ unqualified-id that has been parsed.
struct OFI OperatorFunctionId
When Kind == IK_OperatorFunctionId, the overloaded operator that we parsed.
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
bool isValid() const
Determine whether this unqualified-id refers to a valid name.
void setDestructorName(SourceLocation TildeLoc, ParsedType ClassType, SourceLocation EndLoc)
Specify that this unqualified-id was parsed as a destructor name.
void setTemplateId(TemplateIdAnnotation *TemplateId)
Specify that this unqualified-id was parsed as a template-id.
UnionParsedType DestructorName
When Kind == IK_DestructorName, the type referred to by the class-name.
SourceLocation StartLocation
The location of the first token that describes this unqualified-id, which will be the location of the...
void setConstructorName(ParsedType ClassType, SourceLocation ClassNameLoc, SourceLocation EndLoc)
Specify that this unqualified-id was parsed as a constructor name.
const IdentifierInfo * Identifier
When Kind == IK_Identifier, the parsed identifier, or when Kind == IK_UserLiteralId,...
UnqualifiedIdKind getKind() const
Determine what kind of name we have.
uint32_t Literal
Literals are represented as positive integers.
@ After
Like System, but searched after the system directories.
bool Null(InterpState &S, uint64_t Value, const Type *Ty)
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.
Top level wrappers for InstallAPI frontend operations.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
OpaquePtr< TemplateName > ParsedTemplateTy
@ NotAttributeSpecifier
This is not an attribute specifier.
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
LambdaCaptureKind
The different capture forms in a lambda introducer.
@ LCK_ByCopy
Capturing by copy (a.k.a., by value)
@ LCK_ByRef
Capturing by reference.
@ LCK_StarThis
Capturing the *this object by copy.
@ LCK_This
Capturing the *this object by reference.
@ IK_ConstructorName
A constructor name.
@ IK_LiteralOperatorId
A user-defined literal name, e.g., operator "" _i.
@ IK_Identifier
An identifier.
@ IK_DestructorName
A destructor name.
@ IK_OperatorFunctionId
An overloaded operator name, e.g., operator+.
ActionResult< Decl * > DeclResult
MutableArrayRef< Expr * > MultiExprArg
@ CopyInit
[a = b], [a = {b}]
@ Result
The result type of a method or function.
ActionResult< ParsedType > TypeResult
const FunctionProtoType * T
@ Template
We are parsing a template declaration.
@ Type
The name was classified as a type.
MutableArrayRef< ParsedTemplateArgument > ASTTemplateArgsPtr
TemplateNameKind
Specifies the kind of template name that an identifier refers to.
@ TNK_Var_template
The name refers to a variable template whose specialization produces a variable.
@ TNK_Dependent_template_name
The name refers to a dependent template name:
@ TNK_Function_template
The name refers to a function template or a set of overloaded functions that includes at least one fu...
@ 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.
const char * getOperatorSpelling(OverloadedOperatorKind Operator)
Retrieve the spelling of the given overloaded operator, without the preceding "operator" keyword.
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.
@ None
No keyword precedes the qualified type name.
ParenParseOption
ParenParseOption - Control what ParseParenExpression will parse.
ActionResult< Expr * > ExprResult
@ Parens
New-expression has a C++98 paren-delimited initializer.
@ Braces
New-expression has a C++11 list-initializer.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_None
no exception specification
ActionResult< Stmt * > StmtResult
static DeclaratorChunk getFunction(bool HasProto, bool IsAmbiguous, SourceLocation LParenLoc, ParamInfo *Params, unsigned NumParams, SourceLocation EllipsisLoc, SourceLocation RParenLoc, bool RefQualifierIsLvalueRef, SourceLocation RefQualifierLoc, SourceLocation MutableLoc, ExceptionSpecificationType ESpecType, SourceRange ESpecRange, ParsedType *Exceptions, SourceRange *ExceptionRanges, unsigned NumExceptions, Expr *NoexceptExpr, CachedTokens *ExceptionSpecTokens, ArrayRef< NamedDecl * > DeclsInPrototype, SourceLocation LocalRangeBegin, SourceLocation LocalRangeEnd, Declarator &TheDeclarator, TypeResult TrailingReturnType=TypeResult(), SourceLocation TrailingReturnTypeLoc=SourceLocation(), DeclSpec *MethodQualifiers=nullptr)
DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
static DeclaratorChunk getArray(unsigned TypeQuals, bool isStatic, bool isStar, Expr *NumElts, SourceLocation LBLoc, SourceLocation RBLoc)
Return a DeclaratorChunk for an array.
Represents a complete lambda introducer.
bool hasLambdaCapture() const
void addCapture(LambdaCaptureKind Kind, SourceLocation Loc, IdentifierInfo *Id, SourceLocation EllipsisLoc, LambdaCaptureInitKind InitKind, ExprResult Init, ParsedType InitCaptureType, SourceRange ExplicitRange)
Append a capture in a lambda introducer.
SourceLocation DefaultLoc
LambdaCaptureDefault Default
Information about a template-id annotation token.
const IdentifierInfo * Name
FIXME: Temporarily stores the name of a specialization.
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.
ParsedTemplateTy Template
The declaration of the template corresponding to the template-name.
static TemplateIdAnnotation * Create(SourceLocation TemplateKWLoc, SourceLocation TemplateNameLoc, const IdentifierInfo *Name, OverloadedOperatorKind OperatorKind, ParsedTemplateTy OpaqueTemplateName, TemplateNameKind TemplateKind, SourceLocation LAngleLoc, SourceLocation RAngleLoc, ArrayRef< ParsedTemplateArgument > TemplateArgs, bool ArgsInvalid, SmallVectorImpl< TemplateIdAnnotation * > &CleanupList)
Creates a new TemplateIdAnnotation with NumArgs arguments and appends it to List.
OpaquePtr< T > get() const
OverloadedOperatorKind Operator
The kind of overloaded operator.