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 (!HasScopeSpecifier && 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;
244 auto RestoreScopeSpecRange = [&](SourceRange
Range) {
250 auto SavedType = PreferredType;
252 if (HasScopeSpecifier) {
253 if (Tok.is(tok::code_completion)) {
257 Actions.CodeCompletion().CodeCompleteQualifiedId(
258 getCurScope(), SS, EnteringContext, InUsingDeclaration,
259 IsAddressOfOperand, IsInDeclarationContext, ObjectType.
get(),
279 ObjectType =
nullptr;
287 if (Tok.is(tok::kw_template)) {
291 if (!HasScopeSpecifier && !ObjectType)
294 TentativeParsingAction TPA(*
this);
298 if (Tok.is(tok::identifier)) {
300 TemplateName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
302 }
else if (Tok.is(tok::kw_operator)) {
307 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
316 diag::err_id_after_template_in_nested_name_spec)
329 if (Tok.isNot(tok::less)) {
340 if (AnnotateTemplateIdToken(
Template, TNK, SS, TemplateKWLoc,
347 if (Tok.is(tok::annot_template_id) &&
NextToken().
is(tok::coloncolon)) {
355 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
357 *MayBePseudoDestructor =
true;
362 *LastII = TemplateId->
Name;
364 SourceLocation StartLoc =
368 ConsumeAnnotationToken();
370 assert(Tok.is(tok::coloncolon) &&
"NextToken() not working properly!");
373 HasScopeSpecifier =
true;
379 Actions.ActOnCXXNestedNameSpecifier(
383 CCLoc, EnteringContext)) {
386 RestoreScopeSpecRange(SourceRange(StartLoc, CCLoc));
392 switch (Tok.getKind()) {
393#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
394#include "clang/Basic/BuiltinTraits.inc"
396 Tok.setKind(tok::identifier);
397 Diag(Tok, diag::ext_keyword_as_ident)
398 << Tok.getIdentifierInfo()->getName() << 0;
408 if (Tok.isNot(tok::identifier))
411 IdentifierInfo &II = *Tok.getIdentifierInfo();
418 Sema::NestedNameSpecInfo IdInfo(&II, Tok.getLocation(),
Next.getLocation(),
423 if (
Next.is(tok::colon) && !ColonIsSacred &&
424 !ParsingGenericAssociationType) {
425 if (Actions.IsInvalidUnlessNestedName(
getCurScope(), SS, IdInfo,
430 PP.LookAhead(1).is(tok::identifier)) {
431 Diag(
Next, diag::err_unexpected_colon_in_nested_name_spec)
434 Next.setKind(tok::coloncolon);
441 Token Identifier = Tok;
445 UnconsumeToken(Identifier);
449 if (
Next.is(tok::coloncolon)) {
451 *MayBePseudoDestructor =
true;
457 if (Next2.
is(tok::kw_private) || Next2.
is(tok::kw_protected) ||
458 Next2.
is(tok::kw_public) || Next2.
is(tok::kw_virtual)) {
459 Diag(Next2, diag::err_unexpected_token_in_nested_name_spec)
464 ColonColon.
setKind(tok::colon);
465 PP.EnterToken(ColonColon,
true);
475 Token Identifier = Tok;
477 assert(Tok.isOneOf(tok::coloncolon, tok::colon) &&
478 "NextToken() not working properly!");
479 Token ColonColon = Tok;
483 bool IsCorrectedToColon =
false;
484 bool *CorrectionFlagPtr = ColonIsSacred ? &IsCorrectedToColon :
nullptr;
485 if (Actions.ActOnCXXNestedNameSpecifier(
486 getCurScope(), IdInfo, EnteringContext, SS, CorrectionFlagPtr,
490 if (CorrectionFlagPtr && IsCorrectedToColon) {
491 ColonColon.
setKind(tok::colon);
492 PP.EnterToken(Tok,
true);
493 PP.EnterToken(ColonColon,
true);
499 RestoreScopeSpecRange(SourceRange(ScopeBeginLoc, CCLoc));
501 HasScopeSpecifier =
true;
505 SourceRange ScopeRange = SS.
getRange();
506 CheckForTemplateAndDigraph(
Next, ObjectType, EnteringContext, II, SS);
510 if (
Next.is(tok::less)) {
515 bool MemberOfUnknownSpecialization;
519 EnteringContext,
Template, MemberOfUnknownSpecialization,
526 isTemplateArgumentList(1) == TPResult::False)
529 RestoreScopeSpecRange(ScopeRange);
540 if (AnnotateTemplateIdToken(
Template, TNK, SS, SourceLocation(),
546 Tok.setLocation(ScopeRange.
getBegin());
547 PP.AnnotateCachedTokens(Tok);
552 if (MemberOfUnknownSpecialization && !Disambiguation &&
553 (ObjectType || SS.
isSet()) &&
554 (IsTypename || isTemplateArgumentList(1) == TPResult::True)) {
557 if (!ObjectHadErrors) {
562 unsigned DiagID = diag::err_missing_dependent_template_keyword;
564 DiagID = diag::warn_missing_dependent_template_keyword;
566 Diag(Tok.getLocation(), DiagID)
574 ObjectType, EnteringContext,
Template,
576 if (AnnotateTemplateIdToken(
Template, TNK, SS, SourceLocation(),
592 if (CheckForDestructor && !HasScopeSpecifier && Tok.is(tok::tilde))
593 *MayBePseudoDestructor =
true;
599 bool isAddressOfOperand) {
603 switch (Tok.getKind()) {
604 case tok::annot_non_type: {
605 NamedDecl *ND = getNonTypeAnnotation(Tok);
606 SourceLocation Loc = ConsumeAnnotationToken();
607 E = Actions.ActOnNameClassifiedAsNonType(
getCurScope(), SS, ND, Loc, Tok);
611 case tok::annot_non_type_dependent: {
612 IdentifierInfo *II = getIdentifierAnnotation(Tok);
613 SourceLocation Loc = ConsumeAnnotationToken();
617 if (isAddressOfOperand && isPostfixExpressionSuffixStart())
618 isAddressOfOperand =
false;
620 E = Actions.ActOnNameClassifiedAsDependentNonType(SS, II, Loc,
625 case tok::annot_non_type_undeclared: {
627 "undeclared non-type annotation should be unqualified");
628 IdentifierInfo *II = getIdentifierAnnotation(Tok);
629 SourceLocation Loc = ConsumeAnnotationToken();
630 E = Actions.ActOnNameClassifiedAsUndeclaredNonType(II, Loc);
635 SourceLocation TemplateKWLoc;
642 false, &TemplateKWLoc, Name))
647 if (isAddressOfOperand && isPostfixExpressionSuffixStart())
648 isAddressOfOperand =
false;
650 E = Actions.ActOnIdExpression(
651 getCurScope(), SS, TemplateKWLoc, Name, Tok.is(tok::l_paren),
652 isAddressOfOperand,
nullptr,
false);
657 E = tryParseCXXPackIndexingExpression(E);
660 checkPotentialAngleBracket(E);
665 assert(Tok.is(tok::ellipsis) &&
NextToken().
is(tok::l_square) &&
671 if (
T.consumeClose() || IndexExpr.
isInvalid())
673 return Actions.ActOnPackIndexingExpr(
getCurScope(), PackIdExpression.
get(),
674 EllipsisLoc,
T.getOpenLocation(),
675 IndexExpr.
get(),
T.getCloseLocation());
679Parser::tryParseCXXPackIndexingExpression(
ExprResult PackIdExpression) {
682 Tok.is(tok::ellipsis) &&
NextToken().
is(tok::l_square)) {
683 E = ParseCXXPackIndexingExpression(E);
688ExprResult Parser::ParseCXXIdExpression(
bool isAddressOfOperand) {
694 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
699 assert(!
Result.isUnset() &&
"Typo correction suggested a keyword replacement "
700 "for a previous keyword suggestion");
706 LambdaIntroducer Intro;
707 if (ParseLambdaIntroducer(Intro)) {
714 return ParseLambdaExpressionAfterIntroducer(Intro);
717ExprResult Parser::TryParseLambdaExpression() {
719 "Not at the start of a possible lambda expression.");
722 if (
Next.is(tok::eof))
727 if (
Next.is(tok::r_square) ||
728 Next.is(tok::equal) ||
729 (
Next.is(tok::amp) &&
730 After.isOneOf(tok::r_square, tok::comma)) ||
731 (
Next.is(tok::identifier) &&
732 After.is(tok::r_square)) ||
733 Next.is(tok::ellipsis)) {
734 return ParseLambdaExpression();
739 if (
Next.is(tok::identifier) &&
After.is(tok::identifier))
747 LambdaIntroducer Intro;
749 TentativeParsingAction TPA(*
this);
750 LambdaIntroducerTentativeParse Tentative;
751 if (ParseLambdaIntroducer(Intro, &Tentative)) {
757 case LambdaIntroducerTentativeParse::Success:
761 case LambdaIntroducerTentativeParse::Incomplete:
765 Intro = LambdaIntroducer();
766 if (ParseLambdaIntroducer(Intro))
770 case LambdaIntroducerTentativeParse::MessageSend:
771 case LambdaIntroducerTentativeParse::Invalid:
778 return ParseLambdaExpressionAfterIntroducer(Intro);
782 LambdaIntroducerTentativeParse *Tentative) {
784 *Tentative = LambdaIntroducerTentativeParse::Success;
786 assert(Tok.is(tok::l_square) &&
"Lambda expressions begin with '['.");
796 auto Result = [&](llvm::function_ref<void()> Action,
797 LambdaIntroducerTentativeParse State =
798 LambdaIntroducerTentativeParse::Invalid) {
809 auto NonTentativeAction = [&](llvm::function_ref<void()> Action) {
811 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
817 if (Tok.is(tok::amp) &&
822 if (!Tok.getIdentifierInfo()) {
827 }
else if (Tok.is(tok::equal)) {
834 while (Tok.isNot(tok::r_square)) {
836 if (Tok.isNot(tok::comma)) {
841 if (Tok.is(tok::code_completion) &&
844 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
851 Diag(Tok.getLocation(), diag::err_expected_comma_or_rsquare);
857 if (Tok.is(tok::code_completion)) {
862 Actions.CodeCompletion().CodeCompleteObjCMessageReceiver(
getCurScope());
864 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
876 IdentifierInfo *Id =
nullptr;
877 SourceLocation EllipsisLocs[4];
879 SourceLocation LocStart = Tok.getLocation();
881 if (Tok.is(tok::star)) {
883 if (Tok.is(tok::kw_this)) {
888 Diag(Tok.getLocation(), diag::err_expected_star_this_capture);
891 }
else if (Tok.is(tok::kw_this)) {
894 }
else if (Tok.isOneOf(tok::amp, tok::equal) &&
902 [&] {
Diag(Tok.getLocation(), diag::err_capture_default_first); },
903 LambdaIntroducerTentativeParse::Incomplete);
907 if (Tok.is(tok::amp)) {
911 if (Tok.is(tok::code_completion)) {
913 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
922 if (Tok.is(tok::identifier)) {
923 Id = Tok.getIdentifierInfo();
925 }
else if (Tok.is(tok::kw_this)) {
928 Diag(Tok.getLocation(), diag::err_this_captured_by_reference);
932 [&] {
Diag(Tok.getLocation(), diag::err_expected_capture); });
937 if (Tok.is(tok::l_paren)) {
946 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
947 }
else if (ParseExpressionList(Exprs)) {
952 Init = Actions.ActOnParenListExpr(
Parens.getOpenLocation(),
953 Parens.getCloseLocation(),
956 }
else if (Tok.isOneOf(tok::l_brace, tok::equal)) {
960 EnterExpressionEvaluationContext EC(
969 Init = ParseInitializer();
970 }
else if (Tok.is(tok::l_brace)) {
974 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
996 SourceLocation StartLoc = Tok.getLocation();
998 Init = ParseInitializer();
1000 if (Tok.getLocation() != StartLoc) {
1002 PP.RevertCachedTokens(1);
1005 Tok.setLocation(StartLoc);
1006 Tok.setKind(tok::annot_primary_expr);
1007 setExprAnnotation(Tok,
Init);
1008 Tok.setAnnotationEndLoc(PP.getLastCachedTokenLocation());
1009 PP.AnnotateCachedTokens(Tok);
1012 ConsumeAnnotationToken();
1021 if (Tentative && Tok.is(tok::identifier) &&
1024 *Tentative = LambdaIntroducerTentativeParse::MessageSend;
1029 SourceLocation EllipsisLoc;
1030 if (llvm::any_of(EllipsisLocs,
1031 [](SourceLocation Loc) {
return Loc.
isValid(); })) {
1035 SourceLocation *ExpectedEllipsisLoc =
1036 !InitCapture ? &EllipsisLocs[2] :
1039 EllipsisLoc = *ExpectedEllipsisLoc;
1041 unsigned DiagID = 0;
1043 DiagID = diag::err_lambda_capture_misplaced_ellipsis;
1044 for (SourceLocation Loc : EllipsisLocs) {
1049 unsigned NumEllipses = std::accumulate(
1050 std::begin(EllipsisLocs), std::end(EllipsisLocs), 0,
1051 [](
int N, SourceLocation Loc) {
return N + Loc.
isValid(); });
1052 if (NumEllipses > 1)
1053 DiagID = diag::err_lambda_capture_multiple_ellipses;
1056 NonTentativeAction([&] {
1058 SourceLocation DiagLoc;
1059 for (SourceLocation &Loc : EllipsisLocs) {
1060 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid()) {
1065 assert(DiagLoc.
isValid() &&
"no location for diagnostic");
1069 auto &&D =
Diag(DiagLoc, DiagID);
1070 if (DiagID == diag::err_lambda_capture_misplaced_ellipsis) {
1071 SourceLocation ExpectedLoc =
1077 for (SourceLocation &Loc : EllipsisLocs) {
1078 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid())
1090 if (
Init.isUsable()) {
1091 NonTentativeAction([&] {
1094 Expr *InitExpr =
Init.get();
1097 InitCaptureType = Actions.actOnLambdaInitCaptureInitialization(
1098 Loc, Kind ==
LCK_ByRef, EllipsisLoc, Id, InitKind, InitExpr);
1103 SourceLocation LocEnd = PrevTokLocation;
1106 InitCaptureType, SourceRange(LocStart, LocEnd));
1128 auto ConsumeLocation = [&P, &DeclEndLoc](
SourceLocation &SpecifierLoc,
1130 if (SpecifierLoc.isValid()) {
1132 diag::err_lambda_decl_specifier_repeated)
1137 DeclEndLoc = SpecifierLoc;
1142 case tok::kw_mutable:
1143 ConsumeLocation(MutableLoc, 0);
1145 case tok::kw_static:
1146 ConsumeLocation(StaticLoc, 1);
1148 case tok::kw_constexpr:
1149 ConsumeLocation(ConstexprLoc, 2);
1151 case tok::kw_consteval:
1152 ConsumeLocation(ConstevalLoc, 3);
1163 P.
DiagCompat(StaticLoc, diag_compat::static_lambda);
1164 const char *PrevSpec =
nullptr;
1165 unsigned DiagID = 0;
1169 assert(PrevSpec ==
nullptr && DiagID == 0 &&
1170 "Static cannot have been set previously!");
1178 P.
DiagCompat(ConstexprLoc, diag_compat::constexpr_on_lambda);
1179 const char *PrevSpec =
nullptr;
1180 unsigned DiagID = 0;
1183 assert(PrevSpec ==
nullptr && DiagID == 0 &&
1184 "Constexpr cannot have been set previously!");
1192 P.
Diag(ConstevalLoc, diag::warn_cxx20_compat_consteval);
1193 const char *PrevSpec =
nullptr;
1194 unsigned DiagID = 0;
1198 P.
Diag(ConstevalLoc, DiagID) << PrevSpec;
1214 P.
Diag(StaticLoc, diag::err_static_mutable_lambda);
1216 P.
Diag(StaticLoc, diag::err_static_lambda_captures);
1220bool Parser::isLambdaSpecifier() {
1221 return Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
1222 tok::kw_constexpr, tok::kw_consteval, tok::kw_static,
1223 tok::kw___private, tok::kw___global, tok::kw___local,
1224 tok::kw___constant, tok::kw___generic, tok::kw_groupshared,
1225 tok::kw_requires, tok::kw_noexcept) ||
1226 Tok.isRegularKeywordAttribute() ||
1227 (Tok.is(tok::l_square) &&
NextToken().
is(tok::l_square));
1230ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
1234 Diag(LambdaBeginLoc, diag::ext_hlsl_lambda) << 1;
1237 ? diag::warn_cxx98_compat_lambda
1241 PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), LambdaBeginLoc,
1242 "lambda expression parsing");
1245 DeclSpec DS(AttrFactory);
1247 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1253 Actions.PushLambdaScope();
1254 SourceLocation DeclLoc = Tok.getLocation();
1256 Actions.ActOnLambdaExpressionAfterIntroducer(Intro,
getCurScope());
1258 ParsedAttributes Attributes(AttrFactory);
1266 if (Tok.is(tok::kw___noinline__)) {
1267 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1269 Attributes.addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
1271 0, tok::kw___noinline__);
1272 }
else if (Tok.is(tok::kw___attribute))
1273 ParseGNUAttributes(Attributes,
nullptr, &D);
1278 D.takeAttributesAppending(Attributes);
1282 if (Tok.is(tok::less)) {
1283 DiagCompat(Tok, diag_compat::lambda_template_parameter_list);
1285 SmallVector<NamedDecl*, 4> TemplateParams;
1286 SourceLocation LAngleLoc, RAngleLoc;
1287 if (ParseTemplateParameters(TemplateParamScope,
1288 CurTemplateDepthTracker.getDepth(),
1289 TemplateParams, LAngleLoc, RAngleLoc)) {
1290 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1294 if (TemplateParams.empty()) {
1296 diag::err_lambda_template_parameter_list_empty);
1307 ++CurTemplateDepthTracker;
1317 Actions.ActOnLambdaExplicitTemplateParameterList(
1318 Intro, LAngleLoc, TemplateParams, RAngleLoc, RequiresClause);
1326 if (isCXX11AttributeSpecifier() !=
1329 ? diag::warn_cxx20_compat_decl_attrs_on_lambda
1330 : diag::ext_decl_attrs_on_lambda)
1331 << Tok.isRegularKeywordAttribute() << Tok.getIdentifierInfo();
1332 MaybeParseCXX11Attributes(D);
1336 SourceLocation TrailingReturnTypeLoc;
1337 SourceLocation LParenLoc, RParenLoc;
1338 SourceLocation DeclEndLoc = DeclLoc;
1339 bool HasParentheses =
false;
1340 bool HasSpecifiers =
false;
1341 SourceLocation MutableLoc;
1348 SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
1349 SourceLocation EllipsisLoc;
1351 if (Tok.is(tok::l_paren)) {
1354 LParenLoc =
T.getOpenLocation();
1356 if (Tok.isNot(tok::r_paren)) {
1357 Actions.RecordParsingTemplateParameterDepth(
1358 CurTemplateDepthTracker.getOriginalDepth());
1360 ParseParameterDeclarationClause(D, Attributes, ParamInfo, EllipsisLoc);
1366 if (Actions.getCurGenericLambda())
1367 CurTemplateDepthTracker.setAddedDepth(1);
1371 DeclEndLoc = RParenLoc =
T.getCloseLocation();
1372 HasParentheses =
true;
1375 HasSpecifiers = isLambdaSpecifier();
1381 Diag(Tok, diag::ext_lambda_missing_parens)
1385 if (HasParentheses || HasSpecifiers) {
1389 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec, Attributes);
1392 SourceLocation ConstexprLoc;
1393 SourceLocation ConstevalLoc;
1394 SourceLocation StaticLoc;
1397 ConstevalLoc, DeclEndLoc);
1406 Actions.ActOnLambdaClosureParameters(
getCurScope(), ParamInfo);
1408 if (!HasParentheses)
1409 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1411 if (HasSpecifiers || HasParentheses) {
1414 SourceRange ESpecRange;
1415 SmallVector<ParsedType, 2> DynamicExceptions;
1416 SmallVector<SourceRange, 2> DynamicExceptionRanges;
1420 ESpecType = tryParseExceptionSpecification(
1421 false, ESpecRange, DynamicExceptions,
1422 DynamicExceptionRanges, NoexceptExpr, ExceptionSpecTokens);
1425 DeclEndLoc = ESpecRange.
getEnd();
1428 if (MaybeParseCXX11Attributes(Attributes))
1429 DeclEndLoc = Attributes.Range.getEnd();
1432 if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
1433 tok::kw___constant, tok::kw___generic)) {
1434 ParseOpenCLQualifiers(DS.getAttributes());
1441 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1443 SourceLocation FunLocalRangeEnd = DeclEndLoc;
1446 if (Tok.is(tok::arrow)) {
1447 FunLocalRangeEnd = Tok.getLocation();
1450 ParseTrailingReturnType(Range,
false);
1451 TrailingReturnTypeLoc =
Range.getBegin();
1452 if (
Range.getEnd().isValid())
1453 DeclEndLoc =
Range.getEnd();
1456 SourceLocation NoLoc;
1459 false, LParenLoc, ParamInfo.data(),
1460 ParamInfo.size(), EllipsisLoc, RParenLoc,
1462 NoLoc, MutableLoc, ESpecType,
1463 ESpecRange, DynamicExceptions.data(),
1464 DynamicExceptionRanges.data(), DynamicExceptions.size(),
1465 NoexceptExpr.
isUsable() ? NoexceptExpr.
get() :
nullptr,
1467 {}, LParenLoc, FunLocalRangeEnd, D,
1468 TrailingReturnType, TrailingReturnTypeLoc, &DS),
1469 std::move(Attributes), DeclEndLoc);
1471 if (HasParentheses && Tok.is(tok::kw_requires))
1472 ParseTrailingRequiresClause(D);
1478 for (
const ParsedAttr &A : Attributes)
1479 if (A.getKind() == ParsedAttr::AT_CUDADevice ||
1480 A.getKind() == ParsedAttr::AT_CUDAHost ||
1481 A.getKind() == ParsedAttr::AT_CUDAGlobal)
1482 Diag(A.getLoc(), diag::warn_cuda_attr_lambda_position)
1483 << A.getAttrName()->getName();
1494 Actions.ActOnStartOfLambdaDefinition(Intro, D, DS);
1497 if (!Tok.is(tok::l_brace)) {
1498 Diag(Tok, diag::err_expected_lambda_body);
1499 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1503 StmtResult Stmt(ParseCompoundStatementBody());
1505 TemplateParamScope.Exit();
1510 return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.get());
1512 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1518 const char *CastName =
nullptr;
1521 default: llvm_unreachable(
"Unknown C++ cast!");
1522 case tok::kw_addrspace_cast: CastName =
"addrspace_cast";
break;
1523 case tok::kw_const_cast: CastName =
"const_cast";
break;
1524 case tok::kw_dynamic_cast: CastName =
"dynamic_cast";
break;
1525 case tok::kw_reinterpret_cast: CastName =
"reinterpret_cast";
break;
1526 case tok::kw_static_cast: CastName =
"static_cast";
break;
1530 SourceLocation LAngleBracketLoc = Tok.getLocation();
1534 if (Tok.is(tok::l_square) && Tok.getLength() == 2) {
1536 if (
Next.is(tok::colon) && areTokensAdjacent(Tok,
Next))
1540 if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName))
1544 DeclSpec DS(AttrFactory);
1545 ParseSpecifierQualifierList(DS,
AS_none,
1546 DeclSpecContext::DSC_type_specifier);
1551 ParseDeclarator(DeclaratorInfo);
1553 SourceLocation RAngleBracketLoc = Tok.getLocation();
1555 if (ExpectAndConsume(tok::greater))
1556 return ExprError(
Diag(LAngleBracketLoc, diag::note_matching) << tok::less);
1560 if (
T.expectAndConsume(diag::err_expected_lparen_after, CastName))
1568 if (!
Result.isInvalid() && !DeclaratorInfo.isInvalidType())
1569 Result = Actions.ActOnCXXNamedCast(OpLoc, Kind,
1570 LAngleBracketLoc, DeclaratorInfo,
1572 T.getOpenLocation(),
Result.get(),
1573 T.getCloseLocation());
1579 assert(Tok.is(tok::kw_typeid) &&
"Not 'typeid'!");
1582 SourceLocation LParenLoc, RParenLoc;
1586 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"typeid"))
1588 LParenLoc =
T.getOpenLocation();
1609 if (isTypeIdInParens()) {
1614 RParenLoc =
T.getCloseLocation();
1618 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
true,
1628 RParenLoc =
T.getCloseLocation();
1632 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
false,
1633 Result.get(), RParenLoc);
1641 assert(Tok.is(tok::kw___uuidof) &&
"Not '__uuidof'!");
1647 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"__uuidof"))
1652 if (isTypeIdInParens()) {
1661 Result = Actions.ActOnCXXUuidof(OpLoc,
T.getOpenLocation(),
true,
1663 T.getCloseLocation());
1675 Result = Actions.ActOnCXXUuidof(OpLoc,
T.getOpenLocation(),
1677 Result.get(),
T.getCloseLocation());
1692 SourceLocation CCLoc;
1693 if (Tok.is(tok::identifier)) {
1694 FirstTypeName.
setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
1696 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1698 }
else if (Tok.is(tok::annot_template_id)) {
1699 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
1704 ConsumeAnnotationToken();
1705 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1708 assert(SS.
isEmpty() &&
"missing last component of nested name specifier");
1713 assert(Tok.is(tok::tilde) &&
"ParseOptionalCXXScopeSpecifier fail");
1716 if (Tok.is(tok::kw_decltype) && !FirstTypeName.
isValid()) {
1717 DeclSpec DS(AttrFactory);
1718 ParseDecltypeSpecifier(DS);
1721 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1725 if (!Tok.is(tok::identifier)) {
1726 Diag(Tok, diag::err_destructor_tilde_identifier);
1733 DeclSpec DS(AttrFactory);
1734 ParsePackIndexingType(DS);
1735 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1741 IdentifierInfo *Name = Tok.getIdentifierInfo();
1753 if (Tok.is(tok::less) &&
1754 ParseUnqualifiedIdTemplateId(
1755 SS, ObjectType, Base &&
Base->containsErrors(), SourceLocation(),
1756 Name, NameLoc,
false, SecondTypeName,
1760 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1761 SS, FirstTypeName, CCLoc, TildeLoc,
1767 return Actions.ActOnCXXBoolLiteral(
ConsumeToken(), Kind);
1771 assert(Tok.is(tok::kw_throw) &&
"Not throw!");
1777 switch (Tok.getKind()) {
1784 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc,
nullptr);
1788 if (Expr.isInvalid())
return Expr;
1789 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc, Expr.get());
1794 assert(Tok.is(tok::kw_co_yield) &&
"Not co_yield!");
1797 ExprResult Expr = Tok.is(tok::l_brace) ? ParseBraceInitializer()
1805 assert(Tok.is(tok::kw_this) &&
"Not 'this'!");
1807 return Actions.ActOnCXXThis(ThisLoc);
1811Parser::ParseCXXTypeConstructExpression(
const DeclSpec &DS) {
1814 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
1816 assert((Tok.is(tok::l_paren) ||
1818 &&
"Expected '(' or '{'!");
1820 if (Tok.is(tok::l_brace)) {
1821 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1823 if (
Init.isInvalid())
1826 return Actions.ActOnCXXTypeConstructExpr(
1833 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1837 auto RunSignatureHelp = [&]() {
1838 QualType PreferredType;
1841 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
1843 Exprs,
T.getOpenLocation(),
false);
1844 CalledSignatureHelp =
true;
1845 return PreferredType;
1848 if (Tok.isNot(tok::r_paren)) {
1849 if (ParseExpressionList(Exprs, [&] {
1850 PreferredType.enterFunctionArgument(Tok.getLocation(),
1853 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
1867 return Actions.ActOnCXXTypeConstructExpr(TypeRep,
T.getOpenLocation(),
1868 Exprs,
T.getCloseLocation(),
1876 assert(Tok.is(tok::kw_using) &&
"Expected using");
1879 "Unexpected Declarator Context");
1883 DG = ParseUsingDeclaration(Context, {}, DeclStart, DeclEnd, Attrs,
AS_none);
1887 DiagCompat(DeclStart, diag_compat::alias_in_init_statement);
1896 ForRangeInfo *FRI) {
1898 PreferredType.enterCondition(Actions, Tok.getLocation());
1900 if (Tok.is(tok::code_completion)) {
1902 Actions.CodeCompletion().CodeCompleteOrdinaryName(
1907 if (Tok.is(tok::kw___extension__)) {
1915 std::optional<ExtensionRAIIObject> ExtensionGuard;
1916 ExtensionGuard.emplace(Diags);
1925 ParsedAttributes attrs(AttrFactory);
1926 bool ParsedAttrs = MaybeParseCXX11Attributes(attrs);
1928 const auto WarnOnInit = [
this, &CK] {
1930 DiagCompat(Tok.getLocation(), diag_compat::init_statement)
1933 DiagCompat(Tok.getLocation(), diag_compat::decl_statement)
1938 if (isDeclarationStatement() && !isCXXSimpleDeclaration(
false)) {
1942 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
1943 ParsedAttributes DeclSpecAttrs(AttrFactory);
1947 StmtResult DeclStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd);
1948 if (InitStmt ==
nullptr) {
1949 if (DeclStmt.isUsable())
1950 Diag(DeclStmt.get()->getBeginLoc(), diag::err_expected_expression)
1951 << DeclStmt.get()->getSourceRange();
1953 Diag(DeclStart, diag::err_expected_expression);
1955 *InitStmt = DeclStmt;
1956 return ParseCondition(
nullptr, Loc, CK, MissingOK);
1961 if (InitStmt && Tok.is(tok::semi)) {
1965 *InitStmt = Actions.ActOnAttributedStmt(attrs,
Null.get());
1968 diag::err_c2y_first_condition_clause_is_not_declaration);
1969 return ParseCondition(
nullptr, Loc, CK, MissingOK);
1974 switch (isCXXConditionDeclarationOrInitStatement(InitStmt, FRI)) {
1975 case ConditionOrInitStatement::Expression: {
1976 ProhibitAttributes(attrs);
1980 if (InitStmt && Tok.is(tok::semi)) {
1982 SourceLocation SemiLoc = Tok.getLocation();
1983 if (!Tok.hasLeadingEmptyMacro() && !SemiLoc.
isMacroID()) {
1984 Diag(SemiLoc, diag::warn_empty_init_statement)
1989 *InitStmt = Actions.ActOnNullStmt(SemiLoc);
1990 return ParseCondition(
nullptr, Loc, CK, MissingOK);
1993 EnterExpressionEvaluationContext Eval(
2004 if (InitStmt && Tok.is(tok::semi)) {
2006 *InitStmt = Actions.ActOnExprStmt(Expr.
get());
2008 return ParseCondition(
nullptr, Loc, CK, MissingOK);
2011 return Actions.ActOnCondition(
getCurScope(), Loc, Expr.
get(), CK,
2015 case ConditionOrInitStatement::InitStmtDecl: {
2018 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
2019 if (Tok.is(tok::kw_using))
2020 DG = ParseAliasDeclarationInInitStatement(
2023 ParsedAttributes DeclSpecAttrs(AttrFactory);
2025 attrs, DeclSpecAttrs,
true);
2027 *InitStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd);
2028 return ParseCondition(
nullptr, Loc, CK, MissingOK);
2031 case ConditionOrInitStatement::ForRangeDecl: {
2035 assert(FRI &&
"should not parse a for range declaration here");
2036 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
2037 ParsedAttributes DeclSpecAttrs(AttrFactory);
2040 FRI->LoopVar = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
2041 return Sema::ConditionResult();
2044 case ConditionOrInitStatement::ConditionDecl:
2045 case ConditionOrInitStatement::Error:
2050 DeclSpec DS(AttrFactory);
2051 ParseSpecifierQualifierList(DS,
AS_none, DeclSpecContext::DSC_condition);
2055 ParseDeclarator(DeclaratorInfo);
2058 if (Tok.is(tok::kw_asm)) {
2060 ExprResult AsmLabel(ParseSimpleAsm(
true, &Loc));
2061 if (AsmLabel.isInvalid()) {
2065 DeclaratorInfo.setAsmLabel(AsmLabel.get());
2066 DeclaratorInfo.SetRangeEnd(Loc);
2070 MaybeParseGNUAttributes(DeclaratorInfo);
2081 bool CopyInitialization = isTokenEqualOrEqualTypo();
2082 if (CopyInitialization)
2087 Diag(Tok.getLocation(), diag::compat_cxx11_generalized_initializer_lists);
2088 InitExpr = ParseBraceInitializer();
2089 }
else if (CopyInitialization) {
2090 PreferredType.enterVariableInit(Tok.getLocation(), DeclOut);
2092 }
else if (Tok.is(tok::l_paren)) {
2094 SourceLocation LParen = ConsumeParen(), RParen = LParen;
2096 RParen = ConsumeParen();
2098 diag::err_expected_init_in_condition_lparen)
2099 << SourceRange(LParen, RParen);
2105 Actions.AddInitializerToDecl(DeclOut, InitExpr.
get(), !CopyInitialization);
2107 Actions.ActOnInitializerError(DeclOut);
2109 Actions.FinalizeDeclaration(DeclOut);
2110 return Actions.ActOnConditionVariable(DeclOut, Loc, CK);
2113void Parser::ParseCXXSimpleTypeSpecifier(
DeclSpec &DS) {
2115 const char *PrevSpec;
2117 SourceLocation Loc = Tok.getLocation();
2118 const clang::PrintingPolicy &Policy =
2119 Actions.getASTContext().getPrintingPolicy();
2121 switch (Tok.getKind()) {
2122 case tok::identifier:
2123 case tok::coloncolon:
2124 llvm_unreachable(
"Annotation token should already be formed!");
2126 llvm_unreachable(
"Not a simple-type-specifier token!");
2129 case tok::annot_typename: {
2133 ConsumeAnnotationToken();
2134 DS.
Finish(Actions, Policy);
2138 case tok::kw__ExtInt:
2139 case tok::kw__BitInt: {
2140 DiagnoseBitIntUse(Tok);
2149 DS.
Finish(Actions, Policy);
2162 case tok::kw___int64:
2166 case tok::kw_signed:
2169 case tok::kw_unsigned:
2184 case tok::kw___int128:
2187 case tok::kw___bf16:
2196 case tok::kw_double:
2199 case tok::kw__Float16:
2202 case tok::kw___float128:
2205 case tok::kw___ibm128:
2208 case tok::kw_wchar_t:
2211 case tok::kw_char8_t:
2214 case tok::kw_char16_t:
2217 case tok::kw_char32_t:
2223 case tok::kw__Accum:
2226 case tok::kw__Fract:
2232#define GENERIC_IMAGE_TYPE(ImgType, Id) \
2233 case tok::kw_##ImgType##_t: \
2234 DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, DiagID, \
2237#include "clang/Basic/OpenCLImageTypes.def"
2238#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
2239 case tok::kw_##Name: \
2240 DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, DiagID, Policy); \
2242#include "clang/Basic/HLSLIntangibleTypes.def"
2243#define HLSL_PACKED_TYPE(Name, Id, SingletonId) \
2244 case tok::kw_##Name: \
2245 DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, DiagID, Policy); \
2247#include "clang/Basic/HLSLPackedTypes.def"
2249 case tok::annot_decltype:
2250 case tok::kw_decltype:
2252 return DS.
Finish(Actions, Policy);
2254 case tok::annot_pack_indexing_type:
2256 return DS.
Finish(Actions, Policy);
2259 case tok::kw_typeof:
2260 case tok::kw_typeof_unqual:
2261 ParseTypeofSpecifier(DS);
2262 DS.
Finish(Actions, Policy);
2267 DS.
Finish(Actions, Policy);
2271 ParseSpecifierQualifierList(DS,
AS_none,
2272 getDeclSpecContextFromDeclaratorContext(Context));
2273 DS.
Finish(Actions, Actions.getASTContext().getPrintingPolicy());
2277bool Parser::ParseUnqualifiedIdTemplateId(
2280 bool EnteringContext,
UnqualifiedId &Id,
bool AssumeTemplateId) {
2281 assert(Tok.is(tok::less) &&
"Expected '<' to finish parsing a template-id");
2289 if (AssumeTemplateId) {
2292 TNK = Actions.ActOnTemplateName(
getCurScope(), SS, TemplateKWLoc, Id,
2293 ObjectType, EnteringContext,
Template,
2296 bool MemberOfUnknownSpecialization;
2299 ObjectType, EnteringContext,
Template,
2300 MemberOfUnknownSpecialization);
2305 isTemplateArgumentList(0) == TPResult::False)
2309 ObjectType && isTemplateArgumentList(0) == TPResult::True) {
2312 if (!ObjectHadErrors) {
2331 TNK = Actions.ActOnTemplateName(
2332 getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext,
2342 bool MemberOfUnknownSpecialization;
2347 MemberOfUnknownSpecialization);
2355 bool MemberOfUnknownSpecialization;
2358 TNK = Actions.ActOnTemplateName(
2364 Template, MemberOfUnknownSpecialization,
2368 Diag(NameLoc, diag::err_destructor_template_id)
2381 SourceLocation LAngleLoc, RAngleLoc;
2382 TemplateArgList TemplateArgs;
2383 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs, RAngleLoc,
2398 const IdentifierInfo *TemplateII =
2408 LAngleLoc, RAngleLoc, TemplateArgs,
false, TemplateIds);
2420 SourceLocation(), SS, TemplateKWLoc,
Template,
2421 Name, NameLoc, LAngleLoc, TemplateArgsPtr, RAngleLoc,
2423 if (
Type.isInvalid())
2434bool Parser::ParseUnqualifiedIdOperator(
CXXScopeSpec &SS,
bool EnteringContext,
2437 assert(Tok.is(tok::kw_operator) &&
"Expected 'operator' keyword");
2443 unsigned SymbolIdx = 0;
2444 SourceLocation SymbolLocations[3];
2446 switch (Tok.getKind()) {
2448 case tok::kw_delete: {
2449 bool isNew = Tok.getKind() == tok::kw_new;
2453 if (Tok.is(tok::l_square) &&
2459 if (
T.getCloseLocation().isInvalid())
2462 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2463 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2464 Op = isNew? OO_Array_New : OO_Array_Delete;
2466 Op = isNew? OO_New : OO_Delete;
2471#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
2473 SymbolLocations[SymbolIdx++] = ConsumeToken(); \
2476#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
2477#include "clang/Basic/OperatorKinds.def"
2479 case tok::l_paren: {
2484 if (
T.getCloseLocation().isInvalid())
2487 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2488 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2493 case tok::l_square: {
2498 if (
T.getCloseLocation().isInvalid())
2501 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2502 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2507 case tok::code_completion: {
2511 Actions.CodeCompletion().CodeCompleteOperatorName(
getCurScope());
2514 case tok::lesslessless: {
2519 SourceLocation TokLoc = Tok.getLocation();
2523 SourceLocation LessLessLoc = PP.SplitToken(TokLoc, LessLessLength);
2524 Token LessLess = Tok;
2526 LessLess.
setKind(tok::lessless);
2529 unsigned OldLength = Tok.getLength();
2531 bool CachingTokens = PP.IsPreviousCachedToken(Tok);
2532 Tok.setKind(tok::less);
2533 Tok.setLength(OldLength - LessLessLength);
2538 PP.ReplacePreviousCachedToken({LessLess, Tok});
2540 SymbolLocations[SymbolIdx++] = LessLessLoc;
2551 Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations);
2562 Diag(Tok.getLocation(), diag::warn_cxx98_compat_literal_operator);
2564 SourceLocation DiagLoc;
2565 unsigned DiagId = 0;
2569 SmallVector<Token, 4> Toks;
2570 SmallVector<SourceLocation, 4> TokLocs;
2571 while (isTokenStringLiteral()) {
2572 if (!Tok.is(tok::string_literal) && !DiagId) {
2576 DiagLoc = Tok.getLocation();
2577 DiagId = diag::err_literal_operator_string_prefix;
2579 Toks.push_back(Tok);
2580 TokLocs.push_back(ConsumeStringToken());
2583 StringLiteralParser
Literal(Toks, PP);
2589 bool IsUDSuffix = !
Literal.getUDSuffix().empty();
2590 IdentifierInfo *II =
nullptr;
2591 SourceLocation SuffixLoc;
2593 II = &PP.getIdentifierTable().get(
Literal.getUDSuffix());
2598 }
else if (Tok.is(tok::identifier)) {
2599 II = Tok.getIdentifierInfo();
2601 TokLocs.push_back(SuffixLoc);
2603 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
2613 DiagLoc = TokLocs.front();
2614 DiagId = diag::err_literal_operator_string_not_empty;
2620 SmallString<32> Str;
2624 SourceRange(TokLocs.front(), TokLocs.back()), Str);
2627 Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
2629 return Actions.checkLiteralOperatorId(SS,
Result, IsUDSuffix);
2644 DeclSpec DS(AttrFactory);
2645 if (ParseCXXTypeSpecifierSeq(
2653 ParseDeclaratorInternal(D,
nullptr);
2661 Result.setConversionFunctionId(KeywordLoc, Ty.
get(),
2662 D.getSourceRange().getEnd());
2667 bool ObjectHadErrors,
bool EnteringContext,
2668 bool AllowDestructorName,
2669 bool AllowConstructorName,
2670 bool AllowDeductionGuide,
2678 bool TemplateSpecified =
false;
2679 if (Tok.is(tok::kw_template)) {
2680 if (TemplateKWLoc && (ObjectType || SS.
isSet())) {
2681 TemplateSpecified =
true;
2685 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2693 if (Tok.is(tok::identifier)) {
2702 Result.setIdentifier(Id, IdLoc);
2707 if (AllowConstructorName &&
2708 Actions.isCurrentClassName(*Id,
getCurScope(), &SS)) {
2714 Result.setConstructorName(Ty, IdLoc, IdLoc);
2717 Actions.isDeductionGuideName(
getCurScope(), *Id, IdLoc, SS,
2723 Result.setIdentifier(Id, IdLoc);
2728 if (Tok.is(tok::less))
2729 return ParseUnqualifiedIdTemplateId(
2730 SS, ObjectType, ObjectHadErrors,
2732 EnteringContext,
Result, TemplateSpecified);
2734 if (TemplateSpecified) {
2737 ObjectType, EnteringContext,
Template,
2748 Diag(IdLoc, diag::missing_template_arg_list_after_template_kw);
2755 if (Tok.is(tok::annot_template_id)) {
2761 ConsumeAnnotationToken();
2766 if (AllowConstructorName && TemplateId->
Name &&
2774 diag::err_out_of_line_constructor_template_id)
2785 ConsumeAnnotationToken();
2789 Result.setConstructorTemplateId(TemplateId);
2790 ConsumeAnnotationToken();
2796 Result.setTemplateId(TemplateId);
2799 if (TemplateKWLoc && (ObjectType || SS.
isSet()))
2800 *TemplateKWLoc = TemplateLoc;
2802 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2805 ConsumeAnnotationToken();
2812 if (Tok.is(tok::kw_operator)) {
2813 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
Result))
2825 return ParseUnqualifiedIdTemplateId(
2826 SS, ObjectType, ObjectHadErrors,
2829 else if (TemplateSpecified &&
2830 Actions.ActOnTemplateName(
2840 (AllowDestructorName || SS.
isSet()) && Tok.is(tok::tilde)) {
2849 if (TemplateSpecified) {
2860 Diag(*TemplateKWLoc, diag::err_unexpected_template_in_destructor_name)
2861 << Tok.getLocation();
2865 if (SS.
isEmpty() && Tok.is(tok::kw_decltype)) {
2869 Actions.getDestructorTypeForDecltype(DS, ObjectType)) {
2870 Result.setDestructorName(TildeLoc,
Type, EndLoc);
2877 if (Tok.isNot(tok::identifier)) {
2878 Diag(Tok, diag::err_destructor_tilde_identifier);
2883 DeclaratorScopeObj DeclScopeObj(*
this, SS);
2891 AnnotateScopeToken(SS,
true);
2894 if (ParseOptionalCXXScopeSpecifier(SS, ObjectType, ObjectHadErrors,
2898 ObjectType =
nullptr;
2899 if (Tok.isNot(tok::identifier) ||
NextToken().
is(tok::coloncolon) ||
2901 Diag(TildeLoc, diag::err_destructor_tilde_scope);
2906 Diag(TildeLoc, diag::err_destructor_tilde_scope)
2911 if (Actions.ShouldEnterDeclaratorScope(
getCurScope(), SS))
2912 DeclScopeObj.EnterDeclaratorScope();
2919 if (Tok.is(tok::less)) {
2920 Result.setDestructorName(TildeLoc,
nullptr, ClassNameLoc);
2921 return ParseUnqualifiedIdTemplateId(
2922 SS, ObjectType, ObjectHadErrors,
2924 ClassNameLoc, EnteringContext,
Result, TemplateSpecified);
2929 Actions.getDestructorName(*ClassName, ClassNameLoc,
getCurScope(), SS,
2930 ObjectType, EnteringContext);
2934 Result.setDestructorName(TildeLoc, Ty, ClassNameLoc);
2938 switch (Tok.getKind()) {
2939#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
2940#include "clang/Basic/BuiltinTraits.inc"
2942 Tok.setKind(tok::identifier);
2943 Diag(Tok, diag::ext_keyword_as_ident)
2944 << Tok.getIdentifierInfo()->getName() << 0;
2945 goto ParseIdentifier;
2949 Diag(Tok, diag::err_expected_unqualified_id) <<
getLangOpts().CPlusPlus;
2955Parser::ParseCXXNewExpression(
bool UseGlobal,
SourceLocation Start) {
2956 assert(
Tok.is(tok::kw_new) &&
"expected 'new' token");
2962 ExprVector PlacementArgs;
2969 if (
Tok.is(tok::l_paren)) {
2973 PlacementLParen =
T.getOpenLocation();
2974 if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) {
2980 PlacementRParen =
T.getCloseLocation();
2986 if (PlacementArgs.empty()) {
2988 TypeIdParens =
T.getRange();
2989 PlacementLParen = PlacementRParen = SourceLocation();
2992 if (Tok.is(tok::l_paren)) {
2995 MaybeParseGNUAttributes(DeclaratorInfo);
2996 ParseSpecifierQualifierList(DS);
2998 ParseDeclarator(DeclaratorInfo);
3000 TypeIdParens =
T.getRange();
3002 MaybeParseGNUAttributes(DeclaratorInfo);
3003 if (ParseCXXTypeSpecifierSeq(DS))
3004 DeclaratorInfo.setInvalidType(
true);
3007 ParseDeclaratorInternal(DeclaratorInfo,
3008 &Parser::ParseDirectNewDeclarator);
3015 MaybeParseGNUAttributes(DeclaratorInfo);
3017 DeclaratorInfo.setInvalidType(
true);
3020 ParseDeclaratorInternal(DeclaratorInfo,
3021 &Parser::ParseDirectNewDeclarator);
3024 if (DeclaratorInfo.isInvalidType()) {
3031 if (Tok.is(tok::l_paren)) {
3032 SourceLocation ConstructorLParen, ConstructorRParen;
3033 ExprVector ConstructorArgs;
3036 ConstructorLParen =
T.getOpenLocation();
3037 if (Tok.isNot(tok::r_paren)) {
3038 auto RunSignatureHelp = [&]() {
3039 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
3040 QualType PreferredType;
3046 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
3048 DeclaratorInfo.getEndLoc(), ConstructorArgs,
3051 CalledSignatureHelp =
true;
3052 return PreferredType;
3054 if (ParseExpressionList(ConstructorArgs, [&] {
3055 PreferredType.enterFunctionArgument(Tok.getLocation(),
3058 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
3065 ConstructorRParen =
T.getCloseLocation();
3070 Initializer = Actions.ActOnParenListExpr(ConstructorLParen,
3074 Diag(Tok.getLocation(), diag::compat_cxx11_generalized_initializer_lists);
3080 return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen,
3081 PlacementArgs, PlacementRParen,
3085void Parser::ParseDirectNewDeclarator(
Declarator &D) {
3088 while (Tok.is(tok::l_square)) {
3090 if (CheckProhibitedCXX11Attribute())
3099 if (
Size.isInvalid()) {
3101 SkipUntil(tok::r_square, StopAtSemi);
3109 ParsedAttributes Attrs(AttrFactory);
3110 MaybeParseCXX11Attributes(Attrs);
3114 Size.get(),
T.getOpenLocation(),
3115 T.getCloseLocation()),
3116 std::move(Attrs),
T.getCloseLocation());
3118 if (
T.getCloseLocation().isInvalid())
3123bool Parser::ParseExpressionListOrTypeId(
3127 if (isTypeIdInParens()) {
3135 return ParseExpressionList(PlacementArgs);
3139Parser::ParseCXXDeleteExpression(
bool UseGlobal,
SourceLocation Start) {
3140 assert(Tok.is(tok::kw_delete) &&
"Expected 'delete' keyword");
3144 bool ArrayDelete =
false;
3145 if (Tok.is(tok::l_square) &&
NextToken().
is(tok::r_square)) {
3156 if (
Next.isOneOf(tok::l_brace, tok::less) ||
3157 (
Next.is(tok::l_paren) &&
3161 TentativeParsingAction TPA(*
this);
3162 SourceLocation LSquareLoc = Tok.getLocation();
3168 SourceLocation RBraceLoc;
3169 bool EmitFixIt =
false;
3170 if (Tok.is(tok::l_brace)) {
3173 RBraceLoc = Tok.getLocation();
3180 Diag(Start, diag::err_lambda_after_delete)
3181 << SourceRange(Start, RSquareLoc)
3185 RBraceLoc, 0, Actions.getSourceManager(),
getLangOpts()),
3188 Diag(Start, diag::err_lambda_after_delete)
3189 << SourceRange(Start, RSquareLoc);
3198 Lambda = ParsePostfixExpressionSuffix(Lambda);
3201 return Actions.ActOnCXXDelete(Start, UseGlobal,
false,
3210 if (
T.getCloseLocation().isInvalid())
3218 return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete,
Operand.get());
3221ExprResult Parser::ParseRequiresExpression() {
3222 assert(Tok.is(tok::kw_requires) &&
"Expected 'requires' keyword");
3225 llvm::SmallVector<ParmVarDecl *, 2> LocalParameterDecls;
3227 if (Tok.is(tok::l_paren)) {
3232 if (!Tok.is(tok::r_paren)) {
3234 SourceLocation EllipsisLoc;
3235 llvm::SmallVector<DeclaratorChunk::ParamInfo, 2> LocalParameters;
3237 FirstArgAttrs, LocalParameters,
3240 Diag(EllipsisLoc, diag::err_requires_expr_parameter_list_ellipsis);
3241 for (
auto &ParamInfo : LocalParameters)
3248 if (
Braces.expectAndConsume())
3252 llvm::SmallVector<concepts::Requirement *, 2> Requirements;
3256 EnterExpressionEvaluationContext Ctx(
3264 RequiresExprBodyDecl *Body = Actions.ActOnStartRequiresExpr(
3265 RequiresKWLoc, LocalParameterDecls,
getCurScope());
3267 if (Tok.is(tok::r_brace)) {
3274 Diag(Tok, diag::err_empty_requires_expr);
3277 while (!Tok.is(tok::r_brace)) {
3278 switch (Tok.getKind()) {
3279 case tok::l_brace: {
3290 ExprBraces.consumeOpen();
3292 if (Expression.isUsable())
3293 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3294 if (!Expression.isUsable()) {
3295 ExprBraces.skipToEnd();
3301 if (ExprBraces.consumeClose())
3304 concepts::Requirement *Req =
nullptr;
3305 SourceLocation NoexceptLoc;
3307 if (Tok.is(tok::semi)) {
3308 Req = Actions.ActOnCompoundRequirement(Expression.get(), NoexceptLoc);
3310 Requirements.push_back(Req);
3315 Diag(Tok, diag::err_requires_expr_missing_arrow)
3318 if (TryAnnotateTypeConstraint()) {
3322 if (!isTypeConstraintAnnotation()) {
3323 Diag(Tok, diag::err_requires_expr_expected_type_constraint);
3328 if (Tok.is(tok::annot_cxxscope)) {
3329 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
3330 Tok.getAnnotationRange(),
3332 ConsumeAnnotationToken();
3335 Req = Actions.ActOnCompoundRequirement(
3336 Expression.get(), NoexceptLoc, SS, takeTemplateIdAnnotation(Tok),
3337 TemplateParameterDepth);
3338 ConsumeAnnotationToken();
3340 Requirements.push_back(Req);
3344 bool PossibleRequiresExprInSimpleRequirement =
false;
3345 if (Tok.is(tok::kw_requires)) {
3346 auto IsNestedRequirement = [&] {
3347 RevertingTentativeParsingAction TPA(*
this);
3349 if (Tok.is(tok::l_brace))
3356 if (Tok.is(tok::l_paren)) {
3359 auto Res = TryParseParameterDeclarationClause();
3360 if (Res != TPResult::False) {
3363 while (Depth != 0) {
3364 bool FoundParen =
SkipUntil(tok::l_paren, tok::r_paren,
3368 if (Tok.is(tok::l_paren))
3370 else if (Tok.is(tok::r_paren))
3381 if (Tok.is(tok::l_brace))
3390 if (IsNestedRequirement()) {
3403 Actions.ActOnNestedRequirement(ConstraintExpr.
get()))
3404 Requirements.push_back(Req);
3412 PossibleRequiresExprInSimpleRequirement =
true;
3413 }
else if (Tok.is(tok::kw_typename)) {
3416 TentativeParsingAction TPA(*
this);
3426 if (Tok.is(tok::annot_cxxscope)) {
3427 Actions.RestoreNestedNameSpecifierAnnotation(
3428 Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS);
3429 ConsumeAnnotationToken();
3432 if (Tok.isOneOf(tok::identifier, tok::annot_template_id) &&
3435 SourceLocation NameLoc = Tok.getLocation();
3436 IdentifierInfo *II =
nullptr;
3437 TemplateIdAnnotation *TemplateId =
nullptr;
3438 if (Tok.is(tok::identifier)) {
3439 II = Tok.getIdentifierInfo();
3442 TemplateId = takeTemplateIdAnnotation(Tok);
3443 ConsumeAnnotationToken();
3448 if (
auto *Req = Actions.ActOnTypeRequirement(TypenameKWLoc, SS,
3451 Requirements.push_back(Req);
3461 SourceLocation StartLoc = Tok.getLocation();
3463 if (Expression.isUsable())
3464 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3465 if (!Expression.isUsable()) {
3469 if (!Expression.isInvalid() && PossibleRequiresExprInSimpleRequirement)
3470 Diag(StartLoc, diag::err_requires_expr_in_simple_requirement)
3472 if (
auto *Req = Actions.ActOnSimpleRequirement(Expression.get()))
3473 Requirements.push_back(Req);
3479 if (Tok.is(tok::kw_noexcept)) {
3480 Diag(Tok, diag::err_requires_expr_simple_requirement_noexcept)
3489 if (ExpectAndConsumeSemi(diag::err_expected_semi_requirement)) {
3495 if (Requirements.empty()) {
3500 Actions.ActOnFinishRequiresExpr();
3505 Actions.ActOnFinishRequiresExpr();
3506 ParsingBodyDecl.complete(Body);
3507 return Actions.ActOnRequiresExpr(
3508 RequiresKWLoc, Body,
Parens.getOpenLocation(), LocalParameterDecls,
3509 Parens.getCloseLocation(), Requirements,
Braces.getCloseLocation());
3514 default: llvm_unreachable(
"Not a known type trait");
3515#define TYPE_TRAIT_1(Spelling, Name, Key) \
3516case tok::kw_ ## Spelling: return UTT_ ## Name;
3517#define TYPE_TRAIT_2(Spelling, Name, Key) \
3518case tok::kw_ ## Spelling: return BTT_ ## Name;
3519#include "clang/Basic/TokenKinds.def"
3520#define TYPE_TRAIT_N(Spelling, Name, Key) \
3521 case tok::kw_ ## Spelling: return TT_ ## Name;
3522#include "clang/Basic/BuiltinTraits.inc"
3529 llvm_unreachable(
"Not a known array type trait");
3530#define ARRAY_TYPE_TRAIT(Spelling, Name, Key) \
3531 case tok::kw_##Spelling: \
3533#include "clang/Basic/BuiltinTraits.inc"
3540 llvm_unreachable(
"Not a known unary expression trait.");
3541#define EXPRESSION_TRAIT(Spelling, Name, Key) \
3542 case tok::kw_##Spelling: \
3544#include "clang/Basic/BuiltinTraits.inc"
3554 if (
Parens.expectAndConsume())
3557 SmallVector<ParsedType, 2> Args;
3570 if (Tok.is(tok::ellipsis)) {
3579 Args.push_back(Ty.
get());
3582 if (
Parens.consumeClose())
3585 SourceLocation EndLoc =
Parens.getCloseLocation();
3595 if (
T.expectAndConsume())
3607 case ATT_ArrayRank: {
3609 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(),
nullptr,
3610 T.getCloseLocation());
3612 case ATT_ArrayExtent: {
3613 if (ExpectAndConsume(tok::comma)) {
3624 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(), DimExpr.
get(),
3625 T.getCloseLocation());
3628 llvm_unreachable(
"Invalid ArrayTypeTrait!");
3636 if (
T.expectAndConsume())
3643 return Actions.ActOnExpressionTrait(ET, Loc, Expr.
get(),
3644 T.getCloseLocation());
3654 "Compound literals are not ambiguous!");
3655 assert(isTypeIdInParens() &&
"Not a type-id!");
3684 if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) {
3690 if (Tok.is(tok::l_brace)) {
3694 if (Tok.is(tok::l_paren) &&
NextToken().
is(tok::r_paren)) {
3702 false , NotCastExpr,
3715 Toks.push_back(AttrEnd);
3718 Toks.push_back(Tok);
3721 PP.EnterTokenStream(Toks,
true,
3729 DeclSpec DS(AttrFactory);
3734 ParseSpecifierQualifierList(DS);
3735 ParseDeclarator(DeclaratorInfo);
3743 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3748 if (DeclaratorInfo.isInvalidType())
3751 TypeResult Ty = Actions.ActOnTypeName(DeclaratorInfo);
3752 return ParseCompoundLiteralExpression(Ty.
get(),
3760 if (DeclaratorInfo.isInvalidType())
3766 DeclaratorInfo, CastTy,
3776 if (!
Result.isInvalid() && Tok.is(tok::r_paren))
3778 Tok.getLocation(),
Result.get());
3781 if (
Result.isInvalid()) {
3782 while (Tok.isNot(tok::eof))
3784 assert(Tok.getEofData() == AttrEnd.getEofData());
3791 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3800 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"__builtin_bit_cast"))
3804 DeclSpec DS(AttrFactory);
3805 ParseSpecifierQualifierList(DS);
3810 ParseDeclarator(DeclaratorInfo);
3812 if (ExpectAndConsume(tok::comma)) {
3813 Diag(Tok.getLocation(), diag::err_expected) << tok::comma;
3820 if (
T.consumeClose())
3823 if (
Operand.isInvalid() || DeclaratorInfo.isInvalidType())
3826 return Actions.ActOnBuiltinBitCastExpr(KWLoc, DeclaratorInfo, Operand,
3827 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.
bool isValid() const
A scope specifier is present, and it refers to a real scope.
void MakeTrivial(ASTContext &Context, NestedNameSpecifier Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
SourceRange getRange() const
SourceLocation getBeginLoc() const
bool isSet() const
Deprecated.
NestedNameSpecifier getScopeRep() const
Retrieve the representation of the nested-name-specifier.
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 unsigned getTokenPrefixLength(SourceLocation TokStart, unsigned CharNo, const SourceManager &SM, const LangOptions &LangOpts)
Get the physical length (including trigraphs and escaped newlines) of the first CharNo characters of ...
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)
static Token createEof(SourceLocation Loc=SourceLocation(), const void *Data=nullptr)
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.
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.
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.