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);
208 TypeSourceInfo *PatternTSI =
nullptr;
211 QualType
Type = Actions.ActOnPackIndexingType(
212 Pattern, DS.getPackIndexingExpr(), DS.getBeginLoc());
228 Diag(Start, diag::warn_pre_cxx26_ambiguous_pack_indexing_type) <<
Type;
231 ParsedType T = Actions.ActOnCXXNestedNameSpecifierIndexedPack(
232 SS, DS, PatternTSI, CCLoc,
Type);
234 AnnotateExistingIndexedTypeNamePack(
T, Start, EndLoc);
239 HasScopeSpecifier =
true;
246 auto RestoreScopeSpecRange = [&](SourceRange
Range) {
252 auto SavedType = PreferredType;
254 if (HasScopeSpecifier) {
255 if (Tok.is(tok::code_completion)) {
259 Actions.CodeCompletion().CodeCompleteQualifiedId(
260 getCurScope(), SS, EnteringContext, InUsingDeclaration,
261 IsAddressOfOperand, IsInDeclarationContext, ObjectType.
get(),
281 ObjectType =
nullptr;
289 if (Tok.is(tok::kw_template)) {
293 if (!HasScopeSpecifier && !ObjectType)
296 TentativeParsingAction TPA(*
this);
300 if (Tok.is(tok::identifier)) {
302 TemplateName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
304 }
else if (Tok.is(tok::kw_operator)) {
309 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
318 diag::err_id_after_template_in_nested_name_spec)
331 if (Tok.isNot(tok::less)) {
342 if (AnnotateTemplateIdToken(
Template, TNK, SS, TemplateKWLoc,
349 if (Tok.is(tok::annot_template_id) &&
NextToken().
is(tok::coloncolon)) {
357 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
359 *MayBePseudoDestructor =
true;
364 *LastII = TemplateId->
Name;
366 SourceLocation StartLoc =
370 ConsumeAnnotationToken();
372 assert(Tok.is(tok::coloncolon) &&
"NextToken() not working properly!");
375 HasScopeSpecifier =
true;
381 Actions.ActOnCXXNestedNameSpecifier(
385 CCLoc, EnteringContext)) {
388 RestoreScopeSpecRange(SourceRange(StartLoc, CCLoc));
394 switch (Tok.getKind()) {
395#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
396#include "clang/Basic/BuiltinTraits.inc"
398 Tok.setKind(tok::identifier);
399 Diag(Tok, diag::ext_keyword_as_ident)
400 << Tok.getIdentifierInfo()->getName() << 0;
410 if (Tok.isNot(tok::identifier))
413 IdentifierInfo &II = *Tok.getIdentifierInfo();
420 Sema::NestedNameSpecInfo IdInfo(&II, Tok.getLocation(),
Next.getLocation(),
425 if (
Next.is(tok::colon) && !ColonIsSacred &&
426 !ParsingGenericAssociationType) {
427 if (Actions.IsInvalidUnlessNestedName(
getCurScope(), SS, IdInfo,
432 PP.LookAhead(1).is(tok::identifier)) {
433 Diag(
Next, diag::err_unexpected_colon_in_nested_name_spec)
436 Next.setKind(tok::coloncolon);
443 Token Identifier = Tok;
447 UnconsumeToken(Identifier);
451 if (
Next.is(tok::coloncolon)) {
453 *MayBePseudoDestructor =
true;
459 if (Next2.
is(tok::kw_private) || Next2.
is(tok::kw_protected) ||
460 Next2.
is(tok::kw_public) || Next2.
is(tok::kw_virtual)) {
461 Diag(Next2, diag::err_unexpected_token_in_nested_name_spec)
466 ColonColon.
setKind(tok::colon);
467 PP.EnterToken(ColonColon,
true);
477 Token Identifier = Tok;
479 assert(Tok.isOneOf(tok::coloncolon, tok::colon) &&
480 "NextToken() not working properly!");
481 Token ColonColon = Tok;
485 bool IsCorrectedToColon =
false;
486 bool *CorrectionFlagPtr = ColonIsSacred ? &IsCorrectedToColon :
nullptr;
487 if (Actions.ActOnCXXNestedNameSpecifier(
488 getCurScope(), IdInfo, EnteringContext, SS, CorrectionFlagPtr,
492 if (CorrectionFlagPtr && IsCorrectedToColon) {
493 ColonColon.
setKind(tok::colon);
494 PP.EnterToken(Tok,
true);
495 PP.EnterToken(ColonColon,
true);
501 RestoreScopeSpecRange(SourceRange(ScopeBeginLoc, CCLoc));
503 HasScopeSpecifier =
true;
507 SourceRange ScopeRange = SS.
getRange();
508 CheckForTemplateAndDigraph(
Next, ObjectType, EnteringContext, II, SS);
512 if (
Next.is(tok::less)) {
517 bool MemberOfUnknownSpecialization;
521 EnteringContext,
Template, MemberOfUnknownSpecialization,
528 isTemplateArgumentList(1) == TPResult::False)
531 RestoreScopeSpecRange(ScopeRange);
542 if (AnnotateTemplateIdToken(
Template, TNK, SS, SourceLocation(),
548 Tok.setLocation(ScopeRange.
getBegin());
549 PP.AnnotateCachedTokens(Tok);
554 if (MemberOfUnknownSpecialization && !Disambiguation &&
555 (ObjectType || SS.
isSet()) &&
556 (IsTypename || isTemplateArgumentList(1) == TPResult::True)) {
559 if (!ObjectHadErrors) {
564 unsigned DiagID = diag::err_missing_dependent_template_keyword;
566 DiagID = diag::warn_missing_dependent_template_keyword;
568 Diag(Tok.getLocation(), DiagID)
576 ObjectType, EnteringContext,
Template,
578 if (AnnotateTemplateIdToken(
Template, TNK, SS, SourceLocation(),
594 if (CheckForDestructor && !HasScopeSpecifier && Tok.is(tok::tilde))
595 *MayBePseudoDestructor =
true;
601 bool isAddressOfOperand) {
605 switch (Tok.getKind()) {
606 case tok::annot_non_type: {
607 NamedDecl *ND = getNonTypeAnnotation(Tok);
608 SourceLocation Loc = ConsumeAnnotationToken();
609 E = Actions.ActOnNameClassifiedAsNonType(
getCurScope(), SS, ND, Loc, Tok);
613 case tok::annot_non_type_dependent: {
614 IdentifierInfo *II = getIdentifierAnnotation(Tok);
615 SourceLocation Loc = ConsumeAnnotationToken();
619 if (isAddressOfOperand && isPostfixExpressionSuffixStart())
620 isAddressOfOperand =
false;
622 E = Actions.ActOnNameClassifiedAsDependentNonType(SS, II, Loc,
627 case tok::annot_non_type_undeclared: {
629 "undeclared non-type annotation should be unqualified");
630 IdentifierInfo *II = getIdentifierAnnotation(Tok);
631 SourceLocation Loc = ConsumeAnnotationToken();
632 E = Actions.ActOnNameClassifiedAsUndeclaredNonType(II, Loc);
637 SourceLocation TemplateKWLoc;
644 false, &TemplateKWLoc, Name))
649 if (isAddressOfOperand && isPostfixExpressionSuffixStart())
650 isAddressOfOperand =
false;
652 E = Actions.ActOnIdExpression(
653 getCurScope(), SS, TemplateKWLoc, Name, Tok.is(tok::l_paren),
654 isAddressOfOperand,
nullptr,
false);
659 E = tryParseCXXPackIndexingExpression(E);
662 checkPotentialAngleBracket(E);
667 assert(Tok.is(tok::ellipsis) &&
NextToken().
is(tok::l_square) &&
673 if (
T.consumeClose() || IndexExpr.
isInvalid())
675 return Actions.ActOnPackIndexingExpr(
getCurScope(), PackIdExpression.
get(),
676 EllipsisLoc,
T.getOpenLocation(),
677 IndexExpr.
get(),
T.getCloseLocation());
681Parser::tryParseCXXPackIndexingExpression(
ExprResult PackIdExpression) {
684 Tok.is(tok::ellipsis) &&
NextToken().
is(tok::l_square)) {
685 E = ParseCXXPackIndexingExpression(E);
690ExprResult Parser::ParseCXXIdExpression(
bool isAddressOfOperand) {
696 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
701 assert(!
Result.isUnset() &&
"Typo correction suggested a keyword replacement "
702 "for a previous keyword suggestion");
708 LambdaIntroducer Intro;
709 if (ParseLambdaIntroducer(Intro)) {
716 return ParseLambdaExpressionAfterIntroducer(Intro);
719ExprResult Parser::TryParseLambdaExpression() {
721 "Not at the start of a possible lambda expression.");
724 if (
Next.is(tok::eof))
729 if (
Next.is(tok::r_square) ||
730 Next.is(tok::equal) ||
731 (
Next.is(tok::amp) &&
732 After.isOneOf(tok::r_square, tok::comma)) ||
733 (
Next.is(tok::identifier) &&
734 After.is(tok::r_square)) ||
735 Next.is(tok::ellipsis)) {
736 return ParseLambdaExpression();
741 if (
Next.is(tok::identifier) &&
After.is(tok::identifier))
749 LambdaIntroducer Intro;
751 TentativeParsingAction TPA(*
this);
752 LambdaIntroducerTentativeParse Tentative;
753 if (ParseLambdaIntroducer(Intro, &Tentative)) {
759 case LambdaIntroducerTentativeParse::Success:
763 case LambdaIntroducerTentativeParse::Incomplete:
767 Intro = LambdaIntroducer();
768 if (ParseLambdaIntroducer(Intro))
772 case LambdaIntroducerTentativeParse::MessageSend:
773 case LambdaIntroducerTentativeParse::Invalid:
780 return ParseLambdaExpressionAfterIntroducer(Intro);
784 LambdaIntroducerTentativeParse *Tentative) {
786 *Tentative = LambdaIntroducerTentativeParse::Success;
788 assert(Tok.is(tok::l_square) &&
"Lambda expressions begin with '['.");
798 auto Result = [&](llvm::function_ref<void()> Action,
799 LambdaIntroducerTentativeParse State =
800 LambdaIntroducerTentativeParse::Invalid) {
811 auto NonTentativeAction = [&](llvm::function_ref<void()> Action) {
813 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
819 if (Tok.is(tok::amp) &&
824 if (!Tok.getIdentifierInfo()) {
829 }
else if (Tok.is(tok::equal)) {
836 while (Tok.isNot(tok::r_square)) {
838 if (Tok.isNot(tok::comma)) {
843 if (Tok.is(tok::code_completion) &&
846 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
853 Diag(Tok.getLocation(), diag::err_expected_comma_or_rsquare);
859 if (Tok.is(tok::code_completion)) {
864 Actions.CodeCompletion().CodeCompleteObjCMessageReceiver(
getCurScope());
866 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
878 IdentifierInfo *Id =
nullptr;
879 SourceLocation EllipsisLocs[4];
881 SourceLocation LocStart = Tok.getLocation();
883 if (Tok.is(tok::star)) {
885 if (Tok.is(tok::kw_this)) {
890 Diag(Tok.getLocation(), diag::err_expected_star_this_capture);
893 }
else if (Tok.is(tok::kw_this)) {
896 }
else if (Tok.isOneOf(tok::amp, tok::equal) &&
904 [&] {
Diag(Tok.getLocation(), diag::err_capture_default_first); },
905 LambdaIntroducerTentativeParse::Incomplete);
909 if (Tok.is(tok::amp)) {
913 if (Tok.is(tok::code_completion)) {
915 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
924 if (Tok.is(tok::identifier)) {
925 Id = Tok.getIdentifierInfo();
927 }
else if (Tok.is(tok::kw_this)) {
930 Diag(Tok.getLocation(), diag::err_this_captured_by_reference);
934 [&] {
Diag(Tok.getLocation(), diag::err_expected_capture); });
939 if (Tok.is(tok::l_paren)) {
948 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
949 }
else if (ParseExpressionList(Exprs)) {
954 Init = Actions.ActOnParenListExpr(
Parens.getOpenLocation(),
955 Parens.getCloseLocation(),
958 }
else if (Tok.isOneOf(tok::l_brace, tok::equal)) {
962 EnterExpressionEvaluationContext EC(
971 Init = ParseInitializer();
972 }
else if (Tok.is(tok::l_brace)) {
976 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
998 SourceLocation StartLoc = Tok.getLocation();
1000 Init = ParseInitializer();
1002 if (Tok.getLocation() != StartLoc) {
1004 PP.RevertCachedTokens(1);
1007 Tok.setLocation(StartLoc);
1008 Tok.setKind(tok::annot_primary_expr);
1009 setExprAnnotation(Tok,
Init);
1010 Tok.setAnnotationEndLoc(PP.getLastCachedTokenLocation());
1011 PP.AnnotateCachedTokens(Tok);
1014 ConsumeAnnotationToken();
1023 if (Tentative && Tok.is(tok::identifier) &&
1026 *Tentative = LambdaIntroducerTentativeParse::MessageSend;
1031 SourceLocation EllipsisLoc;
1032 if (llvm::any_of(EllipsisLocs,
1033 [](SourceLocation Loc) {
return Loc.
isValid(); })) {
1037 SourceLocation *ExpectedEllipsisLoc =
1038 !InitCapture ? &EllipsisLocs[2] :
1041 EllipsisLoc = *ExpectedEllipsisLoc;
1043 unsigned DiagID = 0;
1045 DiagID = diag::err_lambda_capture_misplaced_ellipsis;
1046 for (SourceLocation Loc : EllipsisLocs) {
1051 unsigned NumEllipses = std::accumulate(
1052 std::begin(EllipsisLocs), std::end(EllipsisLocs), 0,
1053 [](
int N, SourceLocation Loc) {
return N + Loc.
isValid(); });
1054 if (NumEllipses > 1)
1055 DiagID = diag::err_lambda_capture_multiple_ellipses;
1058 NonTentativeAction([&] {
1060 SourceLocation DiagLoc;
1061 for (SourceLocation &Loc : EllipsisLocs) {
1062 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid()) {
1067 assert(DiagLoc.
isValid() &&
"no location for diagnostic");
1071 auto &&D =
Diag(DiagLoc, DiagID);
1072 if (DiagID == diag::err_lambda_capture_misplaced_ellipsis) {
1073 SourceLocation ExpectedLoc =
1079 for (SourceLocation &Loc : EllipsisLocs) {
1080 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid())
1092 if (
Init.isUsable()) {
1093 NonTentativeAction([&] {
1096 Expr *InitExpr =
Init.get();
1099 InitCaptureType = Actions.actOnLambdaInitCaptureInitialization(
1100 Loc, Kind ==
LCK_ByRef, EllipsisLoc, Id, InitKind, InitExpr);
1105 SourceLocation LocEnd = PrevTokLocation;
1108 InitCaptureType, SourceRange(LocStart, LocEnd));
1130 auto ConsumeLocation = [&P, &DeclEndLoc](
SourceLocation &SpecifierLoc,
1132 if (SpecifierLoc.isValid()) {
1134 diag::err_lambda_decl_specifier_repeated)
1139 DeclEndLoc = SpecifierLoc;
1144 case tok::kw_mutable:
1145 ConsumeLocation(MutableLoc, 0);
1147 case tok::kw_static:
1148 ConsumeLocation(StaticLoc, 1);
1150 case tok::kw_constexpr:
1151 ConsumeLocation(ConstexprLoc, 2);
1153 case tok::kw_consteval:
1154 ConsumeLocation(ConstevalLoc, 3);
1165 P.
DiagCompat(StaticLoc, diag_compat::static_lambda);
1166 const char *PrevSpec =
nullptr;
1167 unsigned DiagID = 0;
1171 assert(PrevSpec ==
nullptr && DiagID == 0 &&
1172 "Static cannot have been set previously!");
1180 P.
DiagCompat(ConstexprLoc, diag_compat::constexpr_on_lambda);
1181 const char *PrevSpec =
nullptr;
1182 unsigned DiagID = 0;
1185 assert(PrevSpec ==
nullptr && DiagID == 0 &&
1186 "Constexpr cannot have been set previously!");
1194 P.
Diag(ConstevalLoc, diag::warn_cxx20_compat_consteval);
1195 const char *PrevSpec =
nullptr;
1196 unsigned DiagID = 0;
1200 P.
Diag(ConstevalLoc, DiagID) << PrevSpec;
1216 P.
Diag(StaticLoc, diag::err_static_mutable_lambda);
1218 P.
Diag(StaticLoc, diag::err_static_lambda_captures);
1222bool Parser::isLambdaSpecifier() {
1223 return Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
1224 tok::kw_constexpr, tok::kw_consteval, tok::kw_static,
1225 tok::kw___private, tok::kw___global, tok::kw___local,
1226 tok::kw___constant, tok::kw___generic, tok::kw_groupshared,
1227 tok::kw_requires, tok::kw_noexcept) ||
1228 Tok.isRegularKeywordAttribute() ||
1229 (Tok.is(tok::l_square) &&
NextToken().
is(tok::l_square));
1232ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
1236 Diag(LambdaBeginLoc, diag::ext_hlsl_lambda) << 1;
1239 ? diag::warn_cxx98_compat_lambda
1243 PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), LambdaBeginLoc,
1244 "lambda expression parsing");
1247 DeclSpec DS(AttrFactory);
1249 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1255 Actions.PushLambdaScope();
1256 SourceLocation DeclLoc = Tok.getLocation();
1258 Actions.ActOnLambdaExpressionAfterIntroducer(Intro,
getCurScope());
1260 ParsedAttributes Attributes(AttrFactory);
1268 if (Tok.is(tok::kw___noinline__)) {
1269 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1271 Attributes.addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
1273 0, tok::kw___noinline__);
1274 }
else if (Tok.is(tok::kw___attribute))
1275 ParseGNUAttributes(Attributes,
nullptr, &D);
1280 D.takeAttributesAppending(Attributes);
1284 if (Tok.is(tok::less)) {
1285 DiagCompat(Tok, diag_compat::lambda_template_parameter_list);
1287 SmallVector<NamedDecl*, 4> TemplateParams;
1288 SourceLocation LAngleLoc, RAngleLoc;
1289 if (ParseTemplateParameters(TemplateParamScope,
1290 CurTemplateDepthTracker.getDepth(),
1291 TemplateParams, LAngleLoc, RAngleLoc)) {
1292 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1296 if (TemplateParams.empty()) {
1298 diag::err_lambda_template_parameter_list_empty);
1309 ++CurTemplateDepthTracker;
1319 Actions.ActOnLambdaExplicitTemplateParameterList(
1320 Intro, LAngleLoc, TemplateParams, RAngleLoc, RequiresClause);
1328 if (isCXX11AttributeSpecifier() !=
1331 ? diag::warn_cxx20_compat_decl_attrs_on_lambda
1332 : diag::ext_decl_attrs_on_lambda)
1333 << Tok.isRegularKeywordAttribute() << Tok.getIdentifierInfo();
1334 MaybeParseCXX11Attributes(D);
1338 SourceLocation TrailingReturnTypeLoc;
1339 SourceLocation LParenLoc, RParenLoc;
1340 SourceLocation DeclEndLoc = DeclLoc;
1341 bool HasParentheses =
false;
1342 bool HasSpecifiers =
false;
1343 SourceLocation MutableLoc;
1350 SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
1351 SourceLocation EllipsisLoc;
1353 if (Tok.is(tok::l_paren)) {
1356 LParenLoc =
T.getOpenLocation();
1358 if (Tok.isNot(tok::r_paren)) {
1359 Actions.RecordParsingTemplateParameterDepth(
1360 CurTemplateDepthTracker.getOriginalDepth());
1362 ParseParameterDeclarationClause(D, Attributes, ParamInfo, EllipsisLoc);
1368 if (Actions.getCurGenericLambda())
1369 CurTemplateDepthTracker.setAddedDepth(1);
1373 DeclEndLoc = RParenLoc =
T.getCloseLocation();
1374 HasParentheses =
true;
1377 HasSpecifiers = isLambdaSpecifier();
1383 Diag(Tok, diag::ext_lambda_missing_parens)
1387 if (HasParentheses || HasSpecifiers) {
1391 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec, Attributes);
1394 SourceLocation ConstexprLoc;
1395 SourceLocation ConstevalLoc;
1396 SourceLocation StaticLoc;
1399 ConstevalLoc, DeclEndLoc);
1408 Actions.ActOnLambdaClosureParameters(
getCurScope(), ParamInfo);
1410 if (!HasParentheses)
1411 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1413 if (HasSpecifiers || HasParentheses) {
1416 SourceRange ESpecRange;
1417 SmallVector<ParsedType, 2> DynamicExceptions;
1418 SmallVector<SourceRange, 2> DynamicExceptionRanges;
1422 ESpecType = tryParseExceptionSpecification(
1423 false, ESpecRange, DynamicExceptions,
1424 DynamicExceptionRanges, NoexceptExpr, ExceptionSpecTokens);
1427 DeclEndLoc = ESpecRange.
getEnd();
1430 if (MaybeParseCXX11Attributes(Attributes))
1431 DeclEndLoc = Attributes.Range.getEnd();
1434 if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
1435 tok::kw___constant, tok::kw___generic)) {
1436 ParseOpenCLQualifiers(DS.getAttributes());
1443 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1445 SourceLocation FunLocalRangeEnd = DeclEndLoc;
1448 if (Tok.is(tok::arrow)) {
1449 FunLocalRangeEnd = Tok.getLocation();
1452 ParseTrailingReturnType(Range,
false);
1453 TrailingReturnTypeLoc =
Range.getBegin();
1454 if (
Range.getEnd().isValid())
1455 DeclEndLoc =
Range.getEnd();
1458 SourceLocation NoLoc;
1461 false, LParenLoc, ParamInfo.data(),
1462 ParamInfo.size(), EllipsisLoc, RParenLoc,
1464 NoLoc, MutableLoc, ESpecType,
1465 ESpecRange, DynamicExceptions.data(),
1466 DynamicExceptionRanges.data(), DynamicExceptions.size(),
1467 NoexceptExpr.
isUsable() ? NoexceptExpr.
get() :
nullptr,
1469 {}, LParenLoc, FunLocalRangeEnd, D,
1470 TrailingReturnType, TrailingReturnTypeLoc, &DS),
1471 std::move(Attributes), DeclEndLoc);
1473 if (HasParentheses && Tok.is(tok::kw_requires))
1474 ParseTrailingRequiresClause(D);
1480 for (
const ParsedAttr &A : Attributes)
1481 if (A.getKind() == ParsedAttr::AT_CUDADevice ||
1482 A.getKind() == ParsedAttr::AT_CUDAHost ||
1483 A.getKind() == ParsedAttr::AT_CUDAGlobal)
1484 Diag(A.getLoc(), diag::warn_cuda_attr_lambda_position)
1485 << A.getAttrName()->getName();
1496 Actions.ActOnStartOfLambdaDefinition(Intro, D, DS);
1499 if (!Tok.is(tok::l_brace)) {
1500 Diag(Tok, diag::err_expected_lambda_body);
1501 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1505 StmtResult Stmt(ParseCompoundStatementBody());
1507 TemplateParamScope.Exit();
1512 return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.get());
1514 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1520 const char *CastName =
nullptr;
1523 default: llvm_unreachable(
"Unknown C++ cast!");
1524 case tok::kw_addrspace_cast: CastName =
"addrspace_cast";
break;
1525 case tok::kw_const_cast: CastName =
"const_cast";
break;
1526 case tok::kw_dynamic_cast: CastName =
"dynamic_cast";
break;
1527 case tok::kw_reinterpret_cast: CastName =
"reinterpret_cast";
break;
1528 case tok::kw_static_cast: CastName =
"static_cast";
break;
1532 SourceLocation LAngleBracketLoc = Tok.getLocation();
1536 if (Tok.is(tok::l_square) && Tok.getLength() == 2) {
1538 if (
Next.is(tok::colon) && areTokensAdjacent(Tok,
Next))
1542 if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName))
1546 DeclSpec DS(AttrFactory);
1547 ParseSpecifierQualifierList(DS,
AS_none,
1548 DeclSpecContext::DSC_type_specifier);
1553 ParseDeclarator(DeclaratorInfo);
1555 SourceLocation RAngleBracketLoc = Tok.getLocation();
1557 if (ExpectAndConsume(tok::greater))
1558 return ExprError(
Diag(LAngleBracketLoc, diag::note_matching) << tok::less);
1562 if (
T.expectAndConsume(diag::err_expected_lparen_after, CastName))
1570 if (!
Result.isInvalid() && !DeclaratorInfo.isInvalidType())
1571 Result = Actions.ActOnCXXNamedCast(OpLoc, Kind,
1572 LAngleBracketLoc, DeclaratorInfo,
1574 T.getOpenLocation(),
Result.get(),
1575 T.getCloseLocation());
1581 assert(Tok.is(tok::kw_typeid) &&
"Not 'typeid'!");
1584 SourceLocation LParenLoc, RParenLoc;
1588 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"typeid"))
1590 LParenLoc =
T.getOpenLocation();
1611 if (isTypeIdInParens()) {
1616 RParenLoc =
T.getCloseLocation();
1620 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
true,
1630 RParenLoc =
T.getCloseLocation();
1634 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
false,
1635 Result.get(), RParenLoc);
1643 assert(Tok.is(tok::kw___uuidof) &&
"Not '__uuidof'!");
1649 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"__uuidof"))
1654 if (isTypeIdInParens()) {
1663 Result = Actions.ActOnCXXUuidof(OpLoc,
T.getOpenLocation(),
true,
1665 T.getCloseLocation());
1677 Result = Actions.ActOnCXXUuidof(OpLoc,
T.getOpenLocation(),
1679 Result.get(),
T.getCloseLocation());
1694 SourceLocation CCLoc;
1695 if (Tok.is(tok::identifier)) {
1696 FirstTypeName.
setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
1698 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1700 }
else if (Tok.is(tok::annot_template_id)) {
1701 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
1706 ConsumeAnnotationToken();
1707 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1710 assert(SS.
isEmpty() &&
"missing last component of nested name specifier");
1715 assert(Tok.is(tok::tilde) &&
"ParseOptionalCXXScopeSpecifier fail");
1718 if (Tok.is(tok::kw_decltype) && !FirstTypeName.
isValid()) {
1719 DeclSpec DS(AttrFactory);
1720 ParseDecltypeSpecifier(DS);
1723 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1727 if (!Tok.is(tok::identifier)) {
1728 Diag(Tok, diag::err_destructor_tilde_identifier);
1735 DeclSpec DS(AttrFactory);
1736 ParsePackIndexingType(DS);
1737 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1743 IdentifierInfo *Name = Tok.getIdentifierInfo();
1755 if (Tok.is(tok::less) &&
1756 ParseUnqualifiedIdTemplateId(
1757 SS, ObjectType, Base &&
Base->containsErrors(), SourceLocation(),
1758 Name, NameLoc,
false, SecondTypeName,
1762 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1763 SS, FirstTypeName, CCLoc, TildeLoc,
1769 return Actions.ActOnCXXBoolLiteral(
ConsumeToken(), Kind);
1773 assert(Tok.is(tok::kw_throw) &&
"Not throw!");
1779 switch (Tok.getKind()) {
1786 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc,
nullptr);
1790 if (Expr.isInvalid())
return Expr;
1791 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc, Expr.get());
1796 assert(Tok.is(tok::kw_co_yield) &&
"Not co_yield!");
1799 ExprResult Expr = Tok.is(tok::l_brace) ? ParseBraceInitializer()
1807 assert(Tok.is(tok::kw_this) &&
"Not 'this'!");
1809 return Actions.ActOnCXXThis(ThisLoc);
1813Parser::ParseCXXTypeConstructExpression(
const DeclSpec &DS) {
1816 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
1818 assert((Tok.is(tok::l_paren) ||
1820 &&
"Expected '(' or '{'!");
1822 if (Tok.is(tok::l_brace)) {
1823 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1825 if (
Init.isInvalid())
1828 return Actions.ActOnCXXTypeConstructExpr(
1835 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1839 auto RunSignatureHelp = [&]() {
1840 QualType PreferredType;
1843 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
1845 Exprs,
T.getOpenLocation(),
false);
1846 CalledSignatureHelp =
true;
1847 return PreferredType;
1850 if (Tok.isNot(tok::r_paren)) {
1851 if (ParseExpressionList(Exprs, [&] {
1852 PreferredType.enterFunctionArgument(Tok.getLocation(),
1855 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
1869 return Actions.ActOnCXXTypeConstructExpr(TypeRep,
T.getOpenLocation(),
1870 Exprs,
T.getCloseLocation(),
1878 assert(Tok.is(tok::kw_using) &&
"Expected using");
1881 "Unexpected Declarator Context");
1885 DG = ParseUsingDeclaration(Context, {}, DeclStart, DeclEnd, Attrs,
AS_none);
1889 DiagCompat(DeclStart, diag_compat::alias_in_init_statement);
1898 ForRangeInfo *FRI) {
1900 PreferredType.enterCondition(Actions, Tok.getLocation());
1902 if (Tok.is(tok::code_completion)) {
1904 Actions.CodeCompletion().CodeCompleteOrdinaryName(
1909 if (Tok.is(tok::kw___extension__)) {
1917 std::optional<ExtensionRAIIObject> ExtensionGuard;
1918 ExtensionGuard.emplace(Diags);
1927 ParsedAttributes attrs(AttrFactory);
1928 bool ParsedAttrs = MaybeParseCXX11Attributes(attrs);
1930 const auto WarnOnInit = [
this, &CK] {
1932 DiagCompat(Tok.getLocation(), diag_compat::init_statement)
1935 DiagCompat(Tok.getLocation(), diag_compat::decl_statement)
1940 if (isDeclarationStatement() && !isCXXSimpleDeclaration(
false)) {
1944 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
1945 ParsedAttributes DeclSpecAttrs(AttrFactory);
1949 StmtResult DeclStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd);
1950 if (InitStmt ==
nullptr) {
1951 if (DeclStmt.isUsable())
1952 Diag(DeclStmt.get()->getBeginLoc(), diag::err_expected_expression)
1953 << DeclStmt.get()->getSourceRange();
1955 Diag(DeclStart, diag::err_expected_expression);
1957 *InitStmt = DeclStmt;
1958 return ParseCondition(
nullptr, Loc, CK, MissingOK);
1963 if (InitStmt && Tok.is(tok::semi)) {
1967 *InitStmt = Actions.ActOnAttributedStmt(attrs,
Null.get());
1970 diag::err_c2y_first_condition_clause_is_not_declaration);
1971 return ParseCondition(
nullptr, Loc, CK, MissingOK);
1976 switch (isCXXConditionDeclarationOrInitStatement(InitStmt, FRI)) {
1977 case ConditionOrInitStatement::Expression: {
1978 ProhibitAttributes(attrs);
1982 if (InitStmt && Tok.is(tok::semi)) {
1984 SourceLocation SemiLoc = Tok.getLocation();
1985 if (!Tok.hasLeadingEmptyMacro() && !SemiLoc.
isMacroID()) {
1986 Diag(SemiLoc, diag::warn_empty_init_statement)
1991 *InitStmt = Actions.ActOnNullStmt(SemiLoc);
1992 return ParseCondition(
nullptr, Loc, CK, MissingOK);
1995 EnterExpressionEvaluationContext Eval(
2006 if (InitStmt && Tok.is(tok::semi)) {
2008 *InitStmt = Actions.ActOnExprStmt(Expr.
get());
2010 return ParseCondition(
nullptr, Loc, CK, MissingOK);
2013 return Actions.ActOnCondition(
getCurScope(), Loc, Expr.
get(), CK,
2017 case ConditionOrInitStatement::InitStmtDecl: {
2020 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
2021 if (Tok.is(tok::kw_using))
2022 DG = ParseAliasDeclarationInInitStatement(
2025 ParsedAttributes DeclSpecAttrs(AttrFactory);
2027 attrs, DeclSpecAttrs,
true);
2029 *InitStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd);
2030 return ParseCondition(
nullptr, Loc, CK, MissingOK);
2033 case ConditionOrInitStatement::ForRangeDecl: {
2037 assert(FRI &&
"should not parse a for range declaration here");
2038 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
2039 ParsedAttributes DeclSpecAttrs(AttrFactory);
2042 FRI->LoopVar = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
2043 return Sema::ConditionResult();
2046 case ConditionOrInitStatement::ConditionDecl:
2047 case ConditionOrInitStatement::Error:
2052 DeclSpec DS(AttrFactory);
2053 ParseSpecifierQualifierList(DS,
AS_none, DeclSpecContext::DSC_condition);
2057 ParseDeclarator(DeclaratorInfo);
2060 if (Tok.is(tok::kw_asm)) {
2062 ExprResult AsmLabel(ParseSimpleAsm(
true, &Loc));
2063 if (AsmLabel.isInvalid()) {
2067 DeclaratorInfo.setAsmLabel(AsmLabel.get());
2068 DeclaratorInfo.SetRangeEnd(Loc);
2072 MaybeParseGNUAttributes(DeclaratorInfo);
2083 bool CopyInitialization = isTokenEqualOrEqualTypo();
2084 if (CopyInitialization)
2089 Diag(Tok.getLocation(), diag::compat_cxx11_generalized_initializer_lists);
2090 InitExpr = ParseBraceInitializer();
2091 }
else if (CopyInitialization) {
2092 PreferredType.enterVariableInit(Tok.getLocation(), DeclOut);
2094 }
else if (Tok.is(tok::l_paren)) {
2096 SourceLocation LParen = ConsumeParen(), RParen = LParen;
2098 RParen = ConsumeParen();
2100 diag::err_expected_init_in_condition_lparen)
2101 << SourceRange(LParen, RParen);
2107 Actions.AddInitializerToDecl(DeclOut, InitExpr.
get(), !CopyInitialization);
2109 Actions.ActOnInitializerError(DeclOut);
2111 Actions.FinalizeDeclaration(DeclOut);
2112 return Actions.ActOnConditionVariable(DeclOut, Loc, CK);
2115void Parser::ParseCXXSimpleTypeSpecifier(
DeclSpec &DS) {
2117 const char *PrevSpec;
2119 SourceLocation Loc = Tok.getLocation();
2120 const clang::PrintingPolicy &Policy =
2121 Actions.getASTContext().getPrintingPolicy();
2123 switch (Tok.getKind()) {
2124 case tok::identifier:
2125 case tok::coloncolon:
2126 llvm_unreachable(
"Annotation token should already be formed!");
2128 llvm_unreachable(
"Not a simple-type-specifier token!");
2131 case tok::annot_typename: {
2135 ConsumeAnnotationToken();
2136 DS.
Finish(Actions, Policy);
2140 case tok::kw__ExtInt:
2141 case tok::kw__BitInt: {
2142 DiagnoseBitIntUse(Tok);
2151 DS.
Finish(Actions, Policy);
2164 case tok::kw___int64:
2168 case tok::kw_signed:
2171 case tok::kw_unsigned:
2186 case tok::kw___int128:
2189 case tok::kw___bf16:
2198 case tok::kw_double:
2201 case tok::kw__Float16:
2204 case tok::kw___float128:
2207 case tok::kw___ibm128:
2210 case tok::kw_wchar_t:
2213 case tok::kw_char8_t:
2216 case tok::kw_char16_t:
2219 case tok::kw_char32_t:
2225 case tok::kw__Accum:
2228 case tok::kw__Fract:
2234#define GENERIC_IMAGE_TYPE(ImgType, Id) \
2235 case tok::kw_##ImgType##_t: \
2236 DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, DiagID, \
2239#include "clang/Basic/OpenCLImageTypes.def"
2240#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
2241 case tok::kw_##Name: \
2242 DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, DiagID, Policy); \
2244#include "clang/Basic/HLSLIntangibleTypes.def"
2245#define HLSL_PACKED_TYPE(Name, Id, SingletonId) \
2246 case tok::kw_##Name: \
2247 DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, DiagID, Policy); \
2249#include "clang/Basic/HLSLPackedTypes.def"
2251 case tok::annot_decltype:
2252 case tok::kw_decltype:
2254 return DS.
Finish(Actions, Policy);
2256 case tok::annot_pack_indexing_type:
2258 return DS.
Finish(Actions, Policy);
2261 case tok::kw_typeof:
2262 case tok::kw_typeof_unqual:
2263 ParseTypeofSpecifier(DS);
2264 DS.
Finish(Actions, Policy);
2269 DS.
Finish(Actions, Policy);
2273 ParseSpecifierQualifierList(DS,
AS_none,
2274 getDeclSpecContextFromDeclaratorContext(Context));
2275 DS.
Finish(Actions, Actions.getASTContext().getPrintingPolicy());
2279bool Parser::ParseUnqualifiedIdTemplateId(
2282 bool EnteringContext,
UnqualifiedId &Id,
bool AssumeTemplateId) {
2283 assert(Tok.is(tok::less) &&
"Expected '<' to finish parsing a template-id");
2291 if (AssumeTemplateId) {
2294 TNK = Actions.ActOnTemplateName(
getCurScope(), SS, TemplateKWLoc, Id,
2295 ObjectType, EnteringContext,
Template,
2298 bool MemberOfUnknownSpecialization;
2301 ObjectType, EnteringContext,
Template,
2302 MemberOfUnknownSpecialization);
2307 isTemplateArgumentList(0) == TPResult::False)
2311 ObjectType && isTemplateArgumentList(0) == TPResult::True) {
2314 if (!ObjectHadErrors) {
2333 TNK = Actions.ActOnTemplateName(
2334 getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext,
2344 bool MemberOfUnknownSpecialization;
2349 MemberOfUnknownSpecialization);
2357 bool MemberOfUnknownSpecialization;
2360 TNK = Actions.ActOnTemplateName(
2366 Template, MemberOfUnknownSpecialization,
2370 Diag(NameLoc, diag::err_destructor_template_id)
2383 SourceLocation LAngleLoc, RAngleLoc;
2384 TemplateArgList TemplateArgs;
2385 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs, RAngleLoc,
2400 const IdentifierInfo *TemplateII =
2410 LAngleLoc, RAngleLoc, TemplateArgs,
false, TemplateIds);
2422 SourceLocation(), SS, TemplateKWLoc,
Template,
2423 Name, NameLoc, LAngleLoc, TemplateArgsPtr, RAngleLoc,
2425 if (
Type.isInvalid())
2436bool Parser::ParseUnqualifiedIdOperator(
CXXScopeSpec &SS,
bool EnteringContext,
2439 assert(Tok.is(tok::kw_operator) &&
"Expected 'operator' keyword");
2445 unsigned SymbolIdx = 0;
2446 SourceLocation SymbolLocations[3];
2448 switch (Tok.getKind()) {
2450 case tok::kw_delete: {
2451 bool isNew = Tok.getKind() == tok::kw_new;
2455 if (Tok.is(tok::l_square) &&
2461 if (
T.getCloseLocation().isInvalid())
2464 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2465 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2466 Op = isNew? OO_Array_New : OO_Array_Delete;
2468 Op = isNew? OO_New : OO_Delete;
2473#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
2475 SymbolLocations[SymbolIdx++] = ConsumeToken(); \
2478#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
2479#include "clang/Basic/OperatorKinds.def"
2481 case tok::l_paren: {
2486 if (
T.getCloseLocation().isInvalid())
2489 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2490 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2495 case tok::l_square: {
2500 if (
T.getCloseLocation().isInvalid())
2503 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2504 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2509 case tok::code_completion: {
2513 Actions.CodeCompletion().CodeCompleteOperatorName(
getCurScope());
2516 case tok::lesslessless: {
2521 SourceLocation TokLoc = Tok.getLocation();
2525 SourceLocation LessLessLoc = PP.SplitToken(TokLoc, LessLessLength);
2526 Token LessLess = Tok;
2528 LessLess.
setKind(tok::lessless);
2531 unsigned OldLength = Tok.getLength();
2533 bool CachingTokens = PP.IsPreviousCachedToken(Tok);
2534 Tok.setKind(tok::less);
2535 Tok.setLength(OldLength - LessLessLength);
2540 PP.ReplacePreviousCachedToken({LessLess, Tok});
2542 SymbolLocations[SymbolIdx++] = LessLessLoc;
2553 Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations);
2564 Diag(Tok.getLocation(), diag::warn_cxx98_compat_literal_operator);
2566 SourceLocation DiagLoc;
2567 unsigned DiagId = 0;
2571 SmallVector<Token, 4> Toks;
2572 SmallVector<SourceLocation, 4> TokLocs;
2573 while (isTokenStringLiteral()) {
2574 if (!Tok.is(tok::string_literal) && !DiagId) {
2578 DiagLoc = Tok.getLocation();
2579 DiagId = diag::err_literal_operator_string_prefix;
2581 Toks.push_back(Tok);
2582 TokLocs.push_back(ConsumeStringToken());
2585 StringLiteralParser
Literal(Toks, PP);
2591 bool IsUDSuffix = !
Literal.getUDSuffix().empty();
2592 IdentifierInfo *II =
nullptr;
2593 SourceLocation SuffixLoc;
2595 II = &PP.getIdentifierTable().get(
Literal.getUDSuffix());
2600 }
else if (Tok.is(tok::identifier)) {
2601 II = Tok.getIdentifierInfo();
2603 TokLocs.push_back(SuffixLoc);
2605 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
2615 DiagLoc = TokLocs.front();
2616 DiagId = diag::err_literal_operator_string_not_empty;
2622 SmallString<32> Str;
2626 SourceRange(TokLocs.front(), TokLocs.back()), Str);
2629 Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
2631 return Actions.checkLiteralOperatorId(SS,
Result, IsUDSuffix);
2646 DeclSpec DS(AttrFactory);
2647 if (ParseCXXTypeSpecifierSeq(
2655 ParseDeclaratorInternal(D,
nullptr);
2663 Result.setConversionFunctionId(KeywordLoc, Ty.
get(),
2664 D.getSourceRange().getEnd());
2669 bool ObjectHadErrors,
bool EnteringContext,
2670 bool AllowDestructorName,
2671 bool AllowConstructorName,
2672 bool AllowDeductionGuide,
2680 bool TemplateSpecified =
false;
2681 if (Tok.is(tok::kw_template)) {
2682 if (TemplateKWLoc && (ObjectType || SS.
isSet())) {
2683 TemplateSpecified =
true;
2687 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2695 if (Tok.is(tok::identifier)) {
2704 Result.setIdentifier(Id, IdLoc);
2709 if (AllowConstructorName &&
2710 Actions.isCurrentClassName(*Id,
getCurScope(), &SS)) {
2716 Result.setConstructorName(Ty, IdLoc, IdLoc);
2719 Actions.isDeductionGuideName(
getCurScope(), *Id, IdLoc, SS,
2725 Result.setIdentifier(Id, IdLoc);
2730 if (Tok.is(tok::less))
2731 return ParseUnqualifiedIdTemplateId(
2732 SS, ObjectType, ObjectHadErrors,
2734 EnteringContext,
Result, TemplateSpecified);
2736 if (TemplateSpecified) {
2739 ObjectType, EnteringContext,
Template,
2750 Diag(IdLoc, diag::missing_template_arg_list_after_template_kw);
2757 if (Tok.is(tok::annot_template_id)) {
2763 ConsumeAnnotationToken();
2768 if (AllowConstructorName && TemplateId->
Name &&
2776 diag::err_out_of_line_constructor_template_id)
2787 ConsumeAnnotationToken();
2791 Result.setConstructorTemplateId(TemplateId);
2792 ConsumeAnnotationToken();
2798 Result.setTemplateId(TemplateId);
2801 if (TemplateKWLoc && (ObjectType || SS.
isSet()))
2802 *TemplateKWLoc = TemplateLoc;
2804 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2807 ConsumeAnnotationToken();
2814 if (Tok.is(tok::kw_operator)) {
2815 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
Result))
2827 return ParseUnqualifiedIdTemplateId(
2828 SS, ObjectType, ObjectHadErrors,
2831 else if (TemplateSpecified &&
2832 Actions.ActOnTemplateName(
2842 (AllowDestructorName || SS.
isSet()) && Tok.is(tok::tilde)) {
2851 if (TemplateSpecified) {
2862 Diag(*TemplateKWLoc, diag::err_unexpected_template_in_destructor_name)
2863 << Tok.getLocation();
2867 if (SS.
isEmpty() && Tok.is(tok::kw_decltype)) {
2871 Actions.getDestructorTypeForDecltype(DS, ObjectType)) {
2872 Result.setDestructorName(TildeLoc,
Type, EndLoc);
2879 if (Tok.isNot(tok::identifier)) {
2880 Diag(Tok, diag::err_destructor_tilde_identifier);
2885 DeclaratorScopeObj DeclScopeObj(*
this, SS);
2893 AnnotateScopeToken(SS,
true);
2896 if (ParseOptionalCXXScopeSpecifier(SS, ObjectType, ObjectHadErrors,
2900 ObjectType =
nullptr;
2901 if (Tok.isNot(tok::identifier) ||
NextToken().
is(tok::coloncolon) ||
2903 Diag(TildeLoc, diag::err_destructor_tilde_scope);
2908 Diag(TildeLoc, diag::err_destructor_tilde_scope)
2913 if (Actions.ShouldEnterDeclaratorScope(
getCurScope(), SS))
2914 DeclScopeObj.EnterDeclaratorScope();
2921 if (Tok.is(tok::less)) {
2922 Result.setDestructorName(TildeLoc,
nullptr, ClassNameLoc);
2923 return ParseUnqualifiedIdTemplateId(
2924 SS, ObjectType, ObjectHadErrors,
2926 ClassNameLoc, EnteringContext,
Result, TemplateSpecified);
2931 Actions.getDestructorName(*ClassName, ClassNameLoc,
getCurScope(), SS,
2932 ObjectType, EnteringContext);
2936 Result.setDestructorName(TildeLoc, Ty, ClassNameLoc);
2940 switch (Tok.getKind()) {
2941#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
2942#include "clang/Basic/BuiltinTraits.inc"
2944 Tok.setKind(tok::identifier);
2945 Diag(Tok, diag::ext_keyword_as_ident)
2946 << Tok.getIdentifierInfo()->getName() << 0;
2947 goto ParseIdentifier;
2951 Diag(Tok, diag::err_expected_unqualified_id) <<
getLangOpts().CPlusPlus;
2957Parser::ParseCXXNewExpression(
bool UseGlobal,
SourceLocation Start) {
2958 assert(
Tok.is(tok::kw_new) &&
"expected 'new' token");
2964 ExprVector PlacementArgs;
2971 if (
Tok.is(tok::l_paren)) {
2975 PlacementLParen =
T.getOpenLocation();
2976 if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) {
2982 PlacementRParen =
T.getCloseLocation();
2988 if (PlacementArgs.empty()) {
2990 TypeIdParens =
T.getRange();
2991 PlacementLParen = PlacementRParen = SourceLocation();
2994 if (Tok.is(tok::l_paren)) {
2997 MaybeParseGNUAttributes(DeclaratorInfo);
2998 ParseSpecifierQualifierList(DS);
3000 ParseDeclarator(DeclaratorInfo);
3002 TypeIdParens =
T.getRange();
3004 MaybeParseGNUAttributes(DeclaratorInfo);
3005 if (ParseCXXTypeSpecifierSeq(DS))
3006 DeclaratorInfo.setInvalidType(
true);
3009 ParseDeclaratorInternal(DeclaratorInfo,
3010 &Parser::ParseDirectNewDeclarator);
3017 MaybeParseGNUAttributes(DeclaratorInfo);
3019 DeclaratorInfo.setInvalidType(
true);
3022 ParseDeclaratorInternal(DeclaratorInfo,
3023 &Parser::ParseDirectNewDeclarator);
3026 if (DeclaratorInfo.isInvalidType()) {
3033 if (Tok.is(tok::l_paren)) {
3034 SourceLocation ConstructorLParen, ConstructorRParen;
3035 ExprVector ConstructorArgs;
3038 ConstructorLParen =
T.getOpenLocation();
3039 if (Tok.isNot(tok::r_paren)) {
3040 auto RunSignatureHelp = [&]() {
3041 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
3042 QualType PreferredType;
3048 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
3050 DeclaratorInfo.getEndLoc(), ConstructorArgs,
3053 CalledSignatureHelp =
true;
3054 return PreferredType;
3056 if (ParseExpressionList(ConstructorArgs, [&] {
3057 PreferredType.enterFunctionArgument(Tok.getLocation(),
3060 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
3067 ConstructorRParen =
T.getCloseLocation();
3072 Initializer = Actions.ActOnParenListExpr(ConstructorLParen,
3076 Diag(Tok.getLocation(), diag::compat_cxx11_generalized_initializer_lists);
3082 return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen,
3083 PlacementArgs, PlacementRParen,
3087void Parser::ParseDirectNewDeclarator(
Declarator &D) {
3090 while (Tok.is(tok::l_square)) {
3092 if (CheckProhibitedCXX11Attribute())
3101 if (
Size.isInvalid()) {
3103 SkipUntil(tok::r_square, StopAtSemi);
3111 ParsedAttributes Attrs(AttrFactory);
3112 MaybeParseCXX11Attributes(Attrs);
3116 Size.get(),
T.getOpenLocation(),
3117 T.getCloseLocation()),
3118 std::move(Attrs),
T.getCloseLocation());
3120 if (
T.getCloseLocation().isInvalid())
3125bool Parser::ParseExpressionListOrTypeId(
3129 if (isTypeIdInParens()) {
3137 return ParseExpressionList(PlacementArgs);
3141Parser::ParseCXXDeleteExpression(
bool UseGlobal,
SourceLocation Start) {
3142 assert(Tok.is(tok::kw_delete) &&
"Expected 'delete' keyword");
3146 bool ArrayDelete =
false;
3147 if (Tok.is(tok::l_square) &&
NextToken().
is(tok::r_square)) {
3158 if (
Next.isOneOf(tok::l_brace, tok::less) ||
3159 (
Next.is(tok::l_paren) &&
3163 TentativeParsingAction TPA(*
this);
3164 SourceLocation LSquareLoc = Tok.getLocation();
3170 SourceLocation RBraceLoc;
3171 bool EmitFixIt =
false;
3172 if (Tok.is(tok::l_brace)) {
3175 RBraceLoc = Tok.getLocation();
3182 Diag(Start, diag::err_lambda_after_delete)
3183 << SourceRange(Start, RSquareLoc)
3187 RBraceLoc, 0, Actions.getSourceManager(),
getLangOpts()),
3190 Diag(Start, diag::err_lambda_after_delete)
3191 << SourceRange(Start, RSquareLoc);
3200 Lambda = ParsePostfixExpressionSuffix(Lambda);
3203 return Actions.ActOnCXXDelete(Start, UseGlobal,
false,
3212 if (
T.getCloseLocation().isInvalid())
3220 return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete,
Operand.get());
3223ExprResult Parser::ParseRequiresExpression() {
3224 assert(Tok.is(tok::kw_requires) &&
"Expected 'requires' keyword");
3227 llvm::SmallVector<ParmVarDecl *, 2> LocalParameterDecls;
3229 if (Tok.is(tok::l_paren)) {
3234 if (!Tok.is(tok::r_paren)) {
3236 SourceLocation EllipsisLoc;
3237 llvm::SmallVector<DeclaratorChunk::ParamInfo, 2> LocalParameters;
3239 FirstArgAttrs, LocalParameters,
3242 Diag(EllipsisLoc, diag::err_requires_expr_parameter_list_ellipsis);
3243 for (
auto &ParamInfo : LocalParameters)
3250 if (
Braces.expectAndConsume())
3254 llvm::SmallVector<concepts::Requirement *, 2> Requirements;
3258 EnterExpressionEvaluationContext Ctx(
3266 RequiresExprBodyDecl *Body = Actions.ActOnStartRequiresExpr(
3267 RequiresKWLoc, LocalParameterDecls,
getCurScope());
3269 if (Tok.is(tok::r_brace)) {
3276 Diag(Tok, diag::err_empty_requires_expr);
3279 while (!Tok.is(tok::r_brace)) {
3280 switch (Tok.getKind()) {
3281 case tok::l_brace: {
3292 ExprBraces.consumeOpen();
3294 if (Expression.isUsable())
3295 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3296 if (!Expression.isUsable()) {
3297 ExprBraces.skipToEnd();
3303 if (ExprBraces.consumeClose())
3306 concepts::Requirement *Req =
nullptr;
3307 SourceLocation NoexceptLoc;
3309 if (Tok.is(tok::semi)) {
3310 Req = Actions.ActOnCompoundRequirement(Expression.get(), NoexceptLoc);
3312 Requirements.push_back(Req);
3317 Diag(Tok, diag::err_requires_expr_missing_arrow)
3320 if (TryAnnotateTypeConstraint()) {
3324 if (!isTypeConstraintAnnotation()) {
3325 Diag(Tok, diag::err_requires_expr_expected_type_constraint);
3330 if (Tok.is(tok::annot_cxxscope)) {
3331 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
3332 Tok.getAnnotationRange(),
3334 ConsumeAnnotationToken();
3337 Req = Actions.ActOnCompoundRequirement(
3338 Expression.get(), NoexceptLoc, SS, takeTemplateIdAnnotation(Tok),
3339 TemplateParameterDepth);
3340 ConsumeAnnotationToken();
3342 Requirements.push_back(Req);
3346 bool PossibleRequiresExprInSimpleRequirement =
false;
3347 if (Tok.is(tok::kw_requires)) {
3348 auto IsNestedRequirement = [&] {
3349 RevertingTentativeParsingAction TPA(*
this);
3351 if (Tok.is(tok::l_brace))
3358 if (Tok.is(tok::l_paren)) {
3361 auto Res = TryParseParameterDeclarationClause();
3362 if (Res != TPResult::False) {
3365 while (Depth != 0) {
3366 bool FoundParen =
SkipUntil(tok::l_paren, tok::r_paren,
3370 if (Tok.is(tok::l_paren))
3372 else if (Tok.is(tok::r_paren))
3383 if (Tok.is(tok::l_brace))
3392 if (IsNestedRequirement()) {
3405 Actions.ActOnNestedRequirement(ConstraintExpr.
get()))
3406 Requirements.push_back(Req);
3414 PossibleRequiresExprInSimpleRequirement =
true;
3415 }
else if (Tok.is(tok::kw_typename)) {
3418 TentativeParsingAction TPA(*
this);
3428 if (Tok.is(tok::annot_cxxscope)) {
3429 Actions.RestoreNestedNameSpecifierAnnotation(
3430 Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS);
3431 ConsumeAnnotationToken();
3434 if (Tok.isOneOf(tok::identifier, tok::annot_template_id) &&
3437 SourceLocation NameLoc = Tok.getLocation();
3438 IdentifierInfo *II =
nullptr;
3439 TemplateIdAnnotation *TemplateId =
nullptr;
3440 if (Tok.is(tok::identifier)) {
3441 II = Tok.getIdentifierInfo();
3444 TemplateId = takeTemplateIdAnnotation(Tok);
3445 ConsumeAnnotationToken();
3450 if (
auto *Req = Actions.ActOnTypeRequirement(TypenameKWLoc, SS,
3453 Requirements.push_back(Req);
3463 SourceLocation StartLoc = Tok.getLocation();
3465 if (Expression.isUsable())
3466 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3467 if (!Expression.isUsable()) {
3471 if (!Expression.isInvalid() && PossibleRequiresExprInSimpleRequirement)
3472 Diag(StartLoc, diag::err_requires_expr_in_simple_requirement)
3474 if (
auto *Req = Actions.ActOnSimpleRequirement(Expression.get()))
3475 Requirements.push_back(Req);
3481 if (Tok.is(tok::kw_noexcept)) {
3482 Diag(Tok, diag::err_requires_expr_simple_requirement_noexcept)
3491 if (ExpectAndConsumeSemi(diag::err_expected_semi_requirement)) {
3497 if (Requirements.empty()) {
3502 Actions.ActOnFinishRequiresExpr();
3507 Actions.ActOnFinishRequiresExpr();
3508 ParsingBodyDecl.complete(Body);
3509 return Actions.ActOnRequiresExpr(
3510 RequiresKWLoc, Body,
Parens.getOpenLocation(), LocalParameterDecls,
3511 Parens.getCloseLocation(), Requirements,
Braces.getCloseLocation());
3516 default: llvm_unreachable(
"Not a known type trait");
3517#define TYPE_TRAIT_1(Spelling, Name, Key) \
3518case tok::kw_ ## Spelling: return UTT_ ## Name;
3519#define TYPE_TRAIT_2(Spelling, Name, Key) \
3520case tok::kw_ ## Spelling: return BTT_ ## Name;
3521#include "clang/Basic/TokenKinds.def"
3522#define TYPE_TRAIT_N(Spelling, Name, Key) \
3523 case tok::kw_ ## Spelling: return TT_ ## Name;
3524#include "clang/Basic/BuiltinTraits.inc"
3531 llvm_unreachable(
"Not a known array type trait");
3532#define ARRAY_TYPE_TRAIT(Spelling, Name, Key) \
3533 case tok::kw_##Spelling: \
3535#include "clang/Basic/BuiltinTraits.inc"
3542 llvm_unreachable(
"Not a known unary expression trait.");
3543#define EXPRESSION_TRAIT(Spelling, Name, Key) \
3544 case tok::kw_##Spelling: \
3546#include "clang/Basic/BuiltinTraits.inc"
3556 if (
Parens.expectAndConsume())
3559 SmallVector<ParsedType, 2> Args;
3572 if (Tok.is(tok::ellipsis)) {
3581 Args.push_back(Ty.
get());
3584 if (
Parens.consumeClose())
3587 SourceLocation EndLoc =
Parens.getCloseLocation();
3597 if (
T.expectAndConsume())
3609 case ATT_ArrayRank: {
3611 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(),
nullptr,
3612 T.getCloseLocation());
3614 case ATT_ArrayExtent: {
3615 if (ExpectAndConsume(tok::comma)) {
3626 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(), DimExpr.
get(),
3627 T.getCloseLocation());
3630 llvm_unreachable(
"Invalid ArrayTypeTrait!");
3638 if (
T.expectAndConsume())
3645 return Actions.ActOnExpressionTrait(ET, Loc, Expr.
get(),
3646 T.getCloseLocation());
3656 "Compound literals are not ambiguous!");
3657 assert(isTypeIdInParens() &&
"Not a type-id!");
3686 if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) {
3692 if (Tok.is(tok::l_brace)) {
3696 if (Tok.is(tok::l_paren) &&
NextToken().
is(tok::r_paren)) {
3704 false , NotCastExpr,
3717 Toks.push_back(AttrEnd);
3720 Toks.push_back(Tok);
3723 PP.EnterTokenStream(Toks,
true,
3731 DeclSpec DS(AttrFactory);
3736 ParseSpecifierQualifierList(DS);
3737 ParseDeclarator(DeclaratorInfo);
3745 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3750 if (DeclaratorInfo.isInvalidType())
3753 TypeResult Ty = Actions.ActOnTypeName(DeclaratorInfo);
3754 return ParseCompoundLiteralExpression(Ty.
get(),
3762 if (DeclaratorInfo.isInvalidType())
3768 DeclaratorInfo, CastTy,
3778 if (!
Result.isInvalid() && Tok.is(tok::r_paren))
3780 Tok.getLocation(),
Result.get());
3783 if (
Result.isInvalid()) {
3784 while (Tok.isNot(tok::eof))
3786 assert(Tok.getEofData() == AttrEnd.getEofData());
3793 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3802 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"__builtin_bit_cast"))
3806 DeclSpec DS(AttrFactory);
3807 ParseSpecifierQualifierList(DS);
3812 ParseDeclarator(DeclaratorInfo);
3814 if (ExpectAndConsume(tok::comma)) {
3815 Diag(Tok.getLocation(), diag::err_expected) << tok::comma;
3822 if (
T.consumeClose())
3825 if (
Operand.isInvalid() || DeclaratorInfo.isInvalidType())
3828 return Actions.ActOnBuiltinBitCastExpr(KWLoc, DeclaratorInfo, Operand,
3829 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 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.