28#include "llvm/Support/Compiler.h"
29#include "llvm/Support/ErrorHandling.h"
38 case tok::unknown:
return 0;
40 case tok::kw_addrspace_cast:
return 1;
41 case tok::kw_const_cast:
return 2;
42 case tok::kw_dynamic_cast:
return 3;
43 case tok::kw_reinterpret_cast:
return 4;
44 case tok::kw_static_cast:
return 5;
46 llvm_unreachable(
"Unknown type for digraph error message.");
50bool Parser::areTokensAdjacent(
const Token &
First,
const Token &Second) {
51 SourceManager &SM = PP.getSourceManager();
68 P.
Diag(DigraphToken.
getLocation(), diag::err_missing_whitespace_digraph)
73 ColonToken.
setKind(tok::coloncolon);
76 DigraphToken.
setKind(tok::less);
88 if (!
Next.is(tok::l_square) ||
Next.getLength() != 2)
92 if (!SecondToken.
is(tok::colon) || !areTokensAdjacent(
Next, SecondToken))
98 bool MemberOfUnknownSpecialization;
99 if (!Actions.isTemplateName(
getCurScope(), SS,
false,
101 Template, MemberOfUnknownSpecialization))
108bool Parser::ParseOptionalCXXScopeSpecifier(
110 bool EnteringContext,
bool *MayBePseudoDestructor,
bool IsTypename,
111 const IdentifierInfo **LastII,
bool OnlyNamespace,
bool InUsingDeclaration,
112 bool Disambiguation,
bool IsAddressOfOperand,
bool IsInDeclarationContext) {
114 "Call sites of this function should be guarded by checking for C++");
116 if (Tok.is(tok::annot_cxxscope)) {
117 assert(!LastII &&
"want last identifier but have already annotated scope");
118 assert(!MayBePseudoDestructor &&
"unexpected annot_cxxscope");
119 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
120 Tok.getAnnotationRange(),
122 ConsumeAnnotationToken();
127 bool CheckForDestructor =
false;
128 if (MayBePseudoDestructor && *MayBePseudoDestructor) {
129 CheckForDestructor =
true;
130 *MayBePseudoDestructor =
false;
136 bool HasScopeSpecifier =
false;
138 if (Tok.is(tok::coloncolon)) {
141 if (NextKind == tok::kw_new || NextKind == tok::kw_delete)
144 if (NextKind == tok::l_brace) {
150 if (Actions.ActOnCXXGlobalScopeSpecifier(
ConsumeToken(), SS))
153 HasScopeSpecifier =
true;
157 if (!HasScopeSpecifier && Tok.is(tok::kw___super)) {
159 if (!Tok.is(tok::coloncolon)) {
160 Diag(Tok.getLocation(), diag::err_expected_coloncolon_after_super);
164 return Actions.ActOnSuperScopeSpecifier(SuperLoc,
ConsumeToken(), SS);
167 if (!HasScopeSpecifier &&
168 Tok.isOneOf(tok::kw_decltype, tok::annot_decltype)) {
169 DeclSpec DS(AttrFactory);
170 SourceLocation DeclLoc = Tok.getLocation();
171 SourceLocation EndLoc = ParseDecltypeSpecifier(DS);
173 SourceLocation CCLoc;
178 AnnotateExistingDecltypeSpecifier(DS, DeclLoc, EndLoc);
182 if (Actions.ActOnCXXNestedNameSpecifierDecltype(SS, DS, CCLoc))
185 HasScopeSpecifier =
true;
188 else if (!HasScopeSpecifier && Tok.is(tok::identifier) &&
202 SourceLocation Start = Tok.getLocation();
203 DeclSpec DS(AttrFactory);
204 SourceLocation CCLoc;
205 SourceLocation EndLoc = ParsePackIndexingType(DS);
209 TypeSourceInfo *PatternTSI =
nullptr;
212 QualType
Type = Actions.ActOnPackIndexingType(
213 Pattern, DS.getPackIndexingExpr(), DS.getBeginLoc());
229 Diag(Start, diag::warn_pre_cxx26_ambiguous_pack_indexing_type) <<
Type;
232 ParsedType T = Actions.ActOnCXXNestedNameSpecifierIndexedPack(
233 SS, DS, PatternTSI, CCLoc,
Type);
235 AnnotateExistingIndexedTypeNamePack(T, Start, EndLoc);
240 HasScopeSpecifier =
true;
247 auto RestoreScopeSpecRange = [&](SourceRange
Range) {
253 auto SavedType = PreferredType;
255 if (HasScopeSpecifier) {
256 if (Tok.is(tok::code_completion)) {
260 Actions.CodeCompletion().CodeCompleteQualifiedId(
261 getCurScope(), SS, EnteringContext, InUsingDeclaration,
262 IsAddressOfOperand, IsInDeclarationContext, ObjectType.
get(),
282 ObjectType =
nullptr;
290 if (Tok.is(tok::kw_template)) {
294 if (!HasScopeSpecifier && !ObjectType)
297 TentativeParsingAction TPA(*
this);
301 if (Tok.is(tok::identifier)) {
303 TemplateName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
305 }
else if (Tok.is(tok::kw_operator)) {
310 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
319 diag::err_id_after_template_in_nested_name_spec)
332 if (Tok.isNot(tok::less)) {
343 if (AnnotateTemplateIdToken(
Template, TNK, SS, TemplateKWLoc,
350 if (Tok.is(tok::annot_template_id) &&
NextToken().
is(tok::coloncolon)) {
358 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
360 *MayBePseudoDestructor =
true;
365 *LastII = TemplateId->
Name;
367 SourceLocation StartLoc =
371 ConsumeAnnotationToken();
373 assert(Tok.is(tok::coloncolon) &&
"NextToken() not working properly!");
376 HasScopeSpecifier =
true;
382 Actions.ActOnCXXNestedNameSpecifier(
386 CCLoc, EnteringContext)) {
389 RestoreScopeSpecRange(SourceRange(StartLoc, CCLoc));
395 switch (Tok.getKind()) {
396#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
397#include "clang/Basic/BuiltinTraits.inc"
399 Tok.setKind(tok::identifier);
400 Diag(Tok, diag::ext_keyword_as_ident)
401 << Tok.getIdentifierInfo()->getName() << 0;
411 if (Tok.isNot(tok::identifier))
414 IdentifierInfo &II = *Tok.getIdentifierInfo();
421 Sema::NestedNameSpecInfo IdInfo(&II, Tok.getLocation(),
Next.getLocation(),
426 if (
Next.is(tok::colon) && !ColonIsSacred &&
427 !ParsingGenericAssociationType) {
428 if (Actions.IsInvalidUnlessNestedName(
getCurScope(), SS, IdInfo,
433 PP.LookAhead(1).is(tok::identifier)) {
434 Diag(
Next, diag::err_unexpected_colon_in_nested_name_spec)
437 Next.setKind(tok::coloncolon);
444 Token Identifier = Tok;
448 UnconsumeToken(Identifier);
452 if (
Next.is(tok::coloncolon)) {
454 *MayBePseudoDestructor =
true;
460 if (Next2.
is(tok::kw_private) || Next2.
is(tok::kw_protected) ||
461 Next2.
is(tok::kw_public) || Next2.
is(tok::kw_virtual)) {
462 Diag(Next2, diag::err_unexpected_token_in_nested_name_spec)
467 ColonColon.
setKind(tok::colon);
468 PP.EnterToken(ColonColon,
true);
478 Token Identifier = Tok;
480 assert(Tok.isOneOf(tok::coloncolon, tok::colon) &&
481 "NextToken() not working properly!");
482 Token ColonColon = Tok;
486 bool IsCorrectedToColon =
false;
487 bool *CorrectionFlagPtr = ColonIsSacred ? &IsCorrectedToColon :
nullptr;
488 if (Actions.ActOnCXXNestedNameSpecifier(
489 getCurScope(), IdInfo, EnteringContext, SS, CorrectionFlagPtr,
493 if (CorrectionFlagPtr && IsCorrectedToColon) {
494 ColonColon.
setKind(tok::colon);
495 PP.EnterToken(Tok,
true);
496 PP.EnterToken(ColonColon,
true);
502 RestoreScopeSpecRange(SourceRange(ScopeBeginLoc, CCLoc));
504 HasScopeSpecifier =
true;
508 SourceRange ScopeRange = SS.
getRange();
509 CheckForTemplateAndDigraph(
Next, ObjectType, EnteringContext, II, SS);
513 if (
Next.is(tok::less)) {
518 bool MemberOfUnknownSpecialization;
522 EnteringContext,
Template, MemberOfUnknownSpecialization,
529 isTemplateArgumentList(1) == TPResult::False)
532 RestoreScopeSpecRange(ScopeRange);
543 if (AnnotateTemplateIdToken(
Template, TNK, SS, SourceLocation(),
549 Tok.setLocation(ScopeRange.
getBegin());
550 PP.AnnotateCachedTokens(Tok);
555 if (MemberOfUnknownSpecialization && !Disambiguation &&
556 (ObjectType || SS.
isSet()) &&
557 (IsTypename || isTemplateArgumentList(1) == TPResult::True)) {
560 if (!ObjectHadErrors) {
565 unsigned DiagID = diag::err_missing_dependent_template_keyword;
567 DiagID = diag::warn_missing_dependent_template_keyword;
569 Diag(Tok.getLocation(), DiagID)
577 ObjectType, EnteringContext,
Template,
579 if (AnnotateTemplateIdToken(
Template, TNK, SS, SourceLocation(),
595 if (CheckForDestructor && !HasScopeSpecifier && Tok.is(tok::tilde))
596 *MayBePseudoDestructor =
true;
602 bool isAddressOfOperand) {
606 switch (Tok.getKind()) {
607 case tok::annot_non_type: {
608 NamedDecl *ND = getNonTypeAnnotation(Tok);
609 SourceLocation Loc = ConsumeAnnotationToken();
610 E = Actions.ActOnNameClassifiedAsNonType(
getCurScope(), SS, ND, Loc, Tok);
614 case tok::annot_non_type_dependent: {
615 IdentifierInfo *II = getIdentifierAnnotation(Tok);
616 SourceLocation Loc = ConsumeAnnotationToken();
620 if (isAddressOfOperand && isPostfixExpressionSuffixStart())
621 isAddressOfOperand =
false;
623 E = Actions.ActOnNameClassifiedAsDependentNonType(SS, II, Loc,
628 case tok::annot_non_type_undeclared: {
630 "undeclared non-type annotation should be unqualified");
631 IdentifierInfo *II = getIdentifierAnnotation(Tok);
632 SourceLocation Loc = ConsumeAnnotationToken();
633 E = Actions.ActOnNameClassifiedAsUndeclaredNonType(II, Loc);
638 SourceLocation TemplateKWLoc;
645 false, &TemplateKWLoc, Name))
650 if (isAddressOfOperand && isPostfixExpressionSuffixStart())
651 isAddressOfOperand =
false;
653 E = Actions.ActOnIdExpression(
getCurScope(), SS, TemplateKWLoc, Name,
654 Tok.isOneOf(tok::l_paren, tok::lesslessless),
655 isAddressOfOperand,
nullptr,
661 E = tryParseCXXPackIndexingExpression(E);
664 checkPotentialAngleBracket(E);
669 assert(Tok.is(tok::ellipsis) &&
NextToken().
is(tok::l_square) &&
675 if (T.consumeClose() || IndexExpr.
isInvalid())
677 return Actions.ActOnPackIndexingExpr(
getCurScope(), PackIdExpression.
get(),
678 EllipsisLoc, T.getOpenLocation(),
679 IndexExpr.
get(), T.getCloseLocation());
683Parser::tryParseCXXPackIndexingExpression(
ExprResult PackIdExpression) {
686 Tok.is(tok::ellipsis) &&
NextToken().
is(tok::l_square)) {
687 E = ParseCXXPackIndexingExpression(E);
692ExprResult Parser::ParseCXXIdExpression(
bool isAddressOfOperand) {
698 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
703 assert(!
Result.isUnset() &&
"Typo correction suggested a keyword replacement "
704 "for a previous keyword suggestion");
710 LambdaIntroducer Intro;
711 if (ParseLambdaIntroducer(Intro)) {
718 return ParseLambdaExpressionAfterIntroducer(Intro);
721ExprResult Parser::TryParseLambdaExpression() {
723 "Not at the start of a possible lambda expression.");
726 if (
Next.is(tok::eof))
731 if (
Next.is(tok::r_square) ||
732 Next.is(tok::equal) ||
733 (
Next.is(tok::amp) &&
734 After.isOneOf(tok::r_square, tok::comma)) ||
735 (
Next.is(tok::identifier) &&
736 After.is(tok::r_square)) ||
737 Next.is(tok::ellipsis)) {
738 return ParseLambdaExpression();
743 if (
Next.is(tok::identifier) &&
After.is(tok::identifier))
751 LambdaIntroducer Intro;
753 TentativeParsingAction TPA(*
this);
754 LambdaIntroducerTentativeParse Tentative;
755 if (ParseLambdaIntroducer(Intro, &Tentative)) {
761 case LambdaIntroducerTentativeParse::Success:
765 case LambdaIntroducerTentativeParse::Incomplete:
769 Intro = LambdaIntroducer();
770 if (ParseLambdaIntroducer(Intro))
774 case LambdaIntroducerTentativeParse::MessageSend:
775 case LambdaIntroducerTentativeParse::Invalid:
782 return ParseLambdaExpressionAfterIntroducer(Intro);
786 LambdaIntroducerTentativeParse *Tentative) {
788 *Tentative = LambdaIntroducerTentativeParse::Success;
790 assert(Tok.is(tok::l_square) &&
"Lambda expressions begin with '['.");
800 auto Result = [&](llvm::function_ref<void()> Action,
801 LambdaIntroducerTentativeParse State =
802 LambdaIntroducerTentativeParse::Invalid) {
813 auto NonTentativeAction = [&](llvm::function_ref<void()> Action) {
815 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
821 if (Tok.is(tok::amp) &&
826 if (!Tok.getIdentifierInfo()) {
831 }
else if (Tok.is(tok::equal)) {
838 while (Tok.isNot(tok::r_square)) {
840 if (Tok.isNot(tok::comma)) {
845 if (Tok.is(tok::code_completion) &&
848 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
855 Diag(Tok.getLocation(), diag::err_expected_comma_or_rsquare);
861 if (Tok.is(tok::code_completion)) {
866 Actions.CodeCompletion().CodeCompleteObjCMessageReceiver(
getCurScope());
868 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
880 IdentifierInfo *Id =
nullptr;
881 SourceLocation EllipsisLocs[4];
883 SourceLocation LocStart = Tok.getLocation();
885 if (Tok.is(tok::star)) {
887 if (Tok.is(tok::kw_this)) {
892 Diag(Tok.getLocation(), diag::err_expected_star_this_capture);
895 }
else if (Tok.is(tok::kw_this)) {
898 }
else if (Tok.isOneOf(tok::amp, tok::equal) &&
906 [&] {
Diag(Tok.getLocation(), diag::err_capture_default_first); },
907 LambdaIntroducerTentativeParse::Incomplete);
911 if (Tok.is(tok::amp)) {
915 if (Tok.is(tok::code_completion)) {
917 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
926 if (Tok.is(tok::identifier)) {
927 Id = Tok.getIdentifierInfo();
929 }
else if (Tok.is(tok::kw_this)) {
932 Diag(Tok.getLocation(), diag::err_this_captured_by_reference);
936 [&] {
Diag(Tok.getLocation(), diag::err_expected_capture); });
941 if (Tok.is(tok::l_paren)) {
950 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
951 }
else if (ParseExpressionList(Exprs)) {
956 Init = Actions.ActOnParenListExpr(
Parens.getOpenLocation(),
957 Parens.getCloseLocation(),
960 }
else if (Tok.isOneOf(tok::l_brace, tok::equal)) {
964 EnterExpressionEvaluationContext EC(
973 Init = ParseInitializer();
974 }
else if (Tok.is(tok::l_brace)) {
978 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
1000 SourceLocation StartLoc = Tok.getLocation();
1002 Init = ParseInitializer();
1004 if (Tok.getLocation() != StartLoc) {
1006 PP.RevertCachedTokens(1);
1009 Tok.setLocation(StartLoc);
1010 Tok.setKind(tok::annot_primary_expr);
1011 setExprAnnotation(Tok,
Init);
1012 Tok.setAnnotationEndLoc(PP.getLastCachedTokenLocation());
1013 PP.AnnotateCachedTokens(Tok);
1016 ConsumeAnnotationToken();
1025 if (Tentative && Tok.is(tok::identifier) &&
1028 *Tentative = LambdaIntroducerTentativeParse::MessageSend;
1033 SourceLocation EllipsisLoc;
1034 if (llvm::any_of(EllipsisLocs,
1035 [](SourceLocation Loc) {
return Loc.
isValid(); })) {
1039 SourceLocation *ExpectedEllipsisLoc =
1040 !InitCapture ? &EllipsisLocs[2] :
1043 EllipsisLoc = *ExpectedEllipsisLoc;
1045 unsigned DiagID = 0;
1047 DiagID = diag::err_lambda_capture_misplaced_ellipsis;
1048 for (SourceLocation Loc : EllipsisLocs) {
1053 unsigned NumEllipses = std::accumulate(
1054 std::begin(EllipsisLocs), std::end(EllipsisLocs), 0,
1055 [](
int N, SourceLocation Loc) {
return N + Loc.
isValid(); });
1056 if (NumEllipses > 1)
1057 DiagID = diag::err_lambda_capture_multiple_ellipses;
1060 NonTentativeAction([&] {
1062 SourceLocation DiagLoc;
1063 for (SourceLocation &Loc : EllipsisLocs) {
1064 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid()) {
1069 assert(DiagLoc.
isValid() &&
"no location for diagnostic");
1073 auto &&D =
Diag(DiagLoc, DiagID);
1074 if (DiagID == diag::err_lambda_capture_misplaced_ellipsis) {
1075 SourceLocation ExpectedLoc =
1081 for (SourceLocation &Loc : EllipsisLocs) {
1082 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid())
1094 if (
Init.isUsable()) {
1095 NonTentativeAction([&] {
1098 Expr *InitExpr =
Init.get();
1101 InitCaptureType = Actions.actOnLambdaInitCaptureInitialization(
1102 Loc, Kind ==
LCK_ByRef, EllipsisLoc, Id, InitKind, InitExpr);
1107 SourceLocation LocEnd = PrevTokLocation;
1110 InitCaptureType, SourceRange(LocStart, LocEnd));
1132 auto ConsumeLocation = [&P, &DeclEndLoc](
SourceLocation &SpecifierLoc,
1134 if (SpecifierLoc.isValid()) {
1136 diag::err_lambda_decl_specifier_repeated)
1141 DeclEndLoc = SpecifierLoc;
1146 case tok::kw_mutable:
1147 ConsumeLocation(MutableLoc, 0);
1149 case tok::kw_static:
1150 ConsumeLocation(StaticLoc, 1);
1152 case tok::kw_constexpr:
1153 ConsumeLocation(ConstexprLoc, 2);
1155 case tok::kw_consteval:
1156 ConsumeLocation(ConstevalLoc, 3);
1167 P.
DiagCompat(StaticLoc, diag_compat::static_lambda);
1168 const char *PrevSpec =
nullptr;
1169 unsigned DiagID = 0;
1173 assert(PrevSpec ==
nullptr && DiagID == 0 &&
1174 "Static cannot have been set previously!");
1182 P.
DiagCompat(ConstexprLoc, diag_compat::constexpr_on_lambda);
1183 const char *PrevSpec =
nullptr;
1184 unsigned DiagID = 0;
1187 assert(PrevSpec ==
nullptr && DiagID == 0 &&
1188 "Constexpr cannot have been set previously!");
1196 P.
Diag(ConstevalLoc, diag::warn_cxx20_compat_consteval);
1197 const char *PrevSpec =
nullptr;
1198 unsigned DiagID = 0;
1202 P.
Diag(ConstevalLoc, DiagID) << PrevSpec;
1218 P.
Diag(StaticLoc, diag::err_static_mutable_lambda);
1220 P.
Diag(StaticLoc, diag::err_static_lambda_captures);
1224bool Parser::isLambdaSpecifier() {
1225 return Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
1226 tok::kw_constexpr, tok::kw_consteval, tok::kw_static,
1227 tok::kw___private, tok::kw___global, tok::kw___local,
1228 tok::kw___constant, tok::kw___generic, tok::kw_requires,
1229 tok::kw_noexcept) ||
1230 Tok.isRegularKeywordAttribute() ||
1231 (Tok.is(tok::l_square) &&
NextToken().
is(tok::l_square));
1234ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
1238 Diag(LambdaBeginLoc, diag::ext_hlsl_lambda) << 1;
1241 ? diag::warn_cxx98_compat_lambda
1245 PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), LambdaBeginLoc,
1246 "lambda expression parsing");
1249 DeclSpec DS(AttrFactory);
1251 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1257 Actions.PushLambdaScope();
1258 SourceLocation DeclLoc = Tok.getLocation();
1260 Actions.ActOnLambdaExpressionAfterIntroducer(Intro,
getCurScope());
1262 ParsedAttributes Attributes(AttrFactory);
1270 if (Tok.is(tok::kw___noinline__)) {
1271 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1273 Attributes.addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
1275 0, tok::kw___noinline__);
1276 }
else if (Tok.is(tok::kw___attribute))
1277 ParseGNUAttributes(Attributes,
nullptr, &D);
1282 D.takeAttributesAppending(Attributes);
1286 if (Tok.is(tok::less)) {
1287 DiagCompat(Tok, diag_compat::lambda_template_parameter_list);
1289 SmallVector<NamedDecl*, 4> TemplateParams;
1290 SourceLocation LAngleLoc, RAngleLoc;
1291 if (ParseTemplateParameters(TemplateParamScope,
1292 CurTemplateDepthTracker.getDepth(),
1293 TemplateParams, LAngleLoc, RAngleLoc)) {
1294 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1298 if (TemplateParams.empty()) {
1300 diag::err_lambda_template_parameter_list_empty);
1311 ++CurTemplateDepthTracker;
1321 Actions.ActOnLambdaExplicitTemplateParameterList(
1322 Intro, LAngleLoc, TemplateParams, RAngleLoc, RequiresClause);
1330 if (isCXX11AttributeSpecifier() !=
1333 ? diag::warn_cxx20_compat_decl_attrs_on_lambda
1334 : diag::ext_decl_attrs_on_lambda)
1335 << Tok.isRegularKeywordAttribute() << Tok.getIdentifierInfo();
1336 MaybeParseCXX11Attributes(D);
1340 SourceLocation TrailingReturnTypeLoc;
1341 SourceLocation LParenLoc, RParenLoc;
1342 SourceLocation DeclEndLoc = DeclLoc;
1343 bool HasParentheses =
false;
1344 bool HasSpecifiers =
false;
1345 SourceLocation MutableLoc;
1352 SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
1353 SourceLocation EllipsisLoc;
1355 if (Tok.is(tok::l_paren)) {
1358 LParenLoc = T.getOpenLocation();
1360 if (Tok.isNot(tok::r_paren)) {
1361 Actions.RecordParsingTemplateParameterDepth(
1362 CurTemplateDepthTracker.getOriginalDepth());
1364 ParseParameterDeclarationClause(D, Attributes, ParamInfo, EllipsisLoc);
1370 if (Actions.getCurGenericLambda())
1371 CurTemplateDepthTracker.setAddedDepth(1);
1375 DeclEndLoc = RParenLoc = T.getCloseLocation();
1376 HasParentheses =
true;
1379 HasSpecifiers = isLambdaSpecifier();
1385 Diag(Tok, diag::ext_lambda_missing_parens)
1389 if (HasParentheses || HasSpecifiers) {
1393 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec, Attributes);
1396 SourceLocation ConstexprLoc;
1397 SourceLocation ConstevalLoc;
1398 SourceLocation StaticLoc;
1401 ConstevalLoc, DeclEndLoc);
1410 Actions.ActOnLambdaClosureParameters(
getCurScope(), ParamInfo);
1412 if (!HasParentheses)
1413 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1415 if (HasSpecifiers || HasParentheses) {
1418 SourceRange ESpecRange;
1419 SmallVector<ParsedType, 2> DynamicExceptions;
1420 SmallVector<SourceRange, 2> DynamicExceptionRanges;
1424 ESpecType = tryParseExceptionSpecification(
1425 false, ESpecRange, DynamicExceptions,
1426 DynamicExceptionRanges, NoexceptExpr, ExceptionSpecTokens);
1429 DeclEndLoc = ESpecRange.
getEnd();
1432 if (MaybeParseCXX11Attributes(Attributes))
1433 DeclEndLoc = Attributes.Range.getEnd();
1436 if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
1437 tok::kw___constant, tok::kw___generic)) {
1438 ParseOpenCLQualifiers(DS.getAttributes());
1445 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1447 SourceLocation FunLocalRangeEnd = DeclEndLoc;
1450 if (Tok.is(tok::arrow)) {
1451 FunLocalRangeEnd = Tok.getLocation();
1454 ParseTrailingReturnType(Range,
false);
1455 TrailingReturnTypeLoc =
Range.getBegin();
1456 if (
Range.getEnd().isValid())
1457 DeclEndLoc =
Range.getEnd();
1460 SourceLocation NoLoc;
1463 false, LParenLoc, ParamInfo.data(),
1464 ParamInfo.size(), EllipsisLoc, RParenLoc,
1466 NoLoc, MutableLoc, ESpecType,
1467 ESpecRange, DynamicExceptions.data(),
1468 DynamicExceptionRanges.data(), DynamicExceptions.size(),
1469 NoexceptExpr.
isUsable() ? NoexceptExpr.
get() :
nullptr,
1471 {}, LParenLoc, FunLocalRangeEnd, D,
1472 TrailingReturnType, TrailingReturnTypeLoc, &DS),
1473 std::move(Attributes), DeclEndLoc);
1475 if (HasParentheses && Tok.is(tok::kw_requires))
1476 ParseTrailingRequiresClause(D);
1482 for (
const ParsedAttr &A : Attributes)
1483 if (A.getKind() == ParsedAttr::AT_CUDADevice ||
1484 A.getKind() == ParsedAttr::AT_CUDAHost ||
1485 A.getKind() == ParsedAttr::AT_CUDAGlobal)
1486 Diag(A.getLoc(), diag::warn_cuda_attr_lambda_position)
1487 << A.getAttrName()->getName();
1498 Actions.ActOnStartOfLambdaDefinition(Intro, D, DS);
1501 if (!Tok.is(tok::l_brace)) {
1502 Diag(Tok, diag::err_expected_lambda_body);
1503 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1507 StmtResult Stmt(ParseCompoundStatementBody());
1509 TemplateParamScope.Exit();
1514 return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.get());
1516 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1522 const char *CastName =
nullptr;
1525 default: llvm_unreachable(
"Unknown C++ cast!");
1526 case tok::kw_addrspace_cast: CastName =
"addrspace_cast";
break;
1527 case tok::kw_const_cast: CastName =
"const_cast";
break;
1528 case tok::kw_dynamic_cast: CastName =
"dynamic_cast";
break;
1529 case tok::kw_reinterpret_cast: CastName =
"reinterpret_cast";
break;
1530 case tok::kw_static_cast: CastName =
"static_cast";
break;
1534 SourceLocation LAngleBracketLoc = Tok.getLocation();
1538 if (Tok.is(tok::l_square) && Tok.getLength() == 2) {
1540 if (
Next.is(tok::colon) && areTokensAdjacent(Tok,
Next))
1544 if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName))
1548 DeclSpec DS(AttrFactory);
1549 ParseSpecifierQualifierList(DS,
AS_none,
1550 DeclSpecContext::DSC_type_specifier);
1555 ParseDeclarator(DeclaratorInfo);
1557 SourceLocation RAngleBracketLoc = Tok.getLocation();
1559 if (ExpectAndConsume(tok::greater))
1560 return ExprError(
Diag(LAngleBracketLoc, diag::note_matching) << tok::less);
1564 if (T.expectAndConsume(diag::err_expected_lparen_after, CastName))
1572 if (!
Result.isInvalid() && !DeclaratorInfo.isInvalidType())
1573 Result = Actions.ActOnCXXNamedCast(OpLoc, Kind,
1574 LAngleBracketLoc, DeclaratorInfo,
1577 T.getCloseLocation());
1583 assert(Tok.is(tok::kw_typeid) &&
"Not 'typeid'!");
1586 SourceLocation LParenLoc, RParenLoc;
1590 if (T.expectAndConsume(diag::err_expected_lparen_after,
"typeid"))
1592 LParenLoc = T.getOpenLocation();
1613 if (isTypeIdInParens()) {
1618 RParenLoc = T.getCloseLocation();
1622 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
true,
1632 RParenLoc = T.getCloseLocation();
1636 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
false,
1637 Result.get(), RParenLoc);
1645 assert(Tok.is(tok::kw___uuidof) &&
"Not '__uuidof'!");
1651 if (T.expectAndConsume(diag::err_expected_lparen_after,
"__uuidof"))
1656 if (isTypeIdInParens()) {
1665 Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(),
true,
1667 T.getCloseLocation());
1679 Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(),
1696 SourceLocation CCLoc;
1697 if (Tok.is(tok::identifier)) {
1698 FirstTypeName.
setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
1700 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1702 }
else if (Tok.is(tok::annot_template_id)) {
1703 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
1708 ConsumeAnnotationToken();
1709 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1712 assert(SS.
isEmpty() &&
"missing last component of nested name specifier");
1717 assert(Tok.is(tok::tilde) &&
"ParseOptionalCXXScopeSpecifier fail");
1720 if (Tok.is(tok::kw_decltype) && !FirstTypeName.
isValid()) {
1721 DeclSpec DS(AttrFactory);
1722 ParseDecltypeSpecifier(DS);
1725 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1729 if (!Tok.is(tok::identifier)) {
1730 Diag(Tok, diag::err_destructor_tilde_identifier);
1737 DeclSpec DS(AttrFactory);
1738 ParsePackIndexingType(DS);
1739 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1745 IdentifierInfo *Name = Tok.getIdentifierInfo();
1757 if (Tok.is(tok::less) &&
1758 ParseUnqualifiedIdTemplateId(
1759 SS, ObjectType, Base &&
Base->containsErrors(), SourceLocation(),
1760 Name, NameLoc,
false, SecondTypeName,
1764 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1765 SS, FirstTypeName, CCLoc, TildeLoc,
1771 return Actions.ActOnCXXBoolLiteral(
ConsumeToken(), Kind);
1775 assert(Tok.is(tok::kw_throw) &&
"Not throw!");
1781 switch (Tok.getKind()) {
1788 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc,
nullptr);
1792 if (Expr.isInvalid())
return Expr;
1793 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc, Expr.get());
1798 assert(Tok.is(tok::kw_co_yield) &&
"Not co_yield!");
1801 ExprResult Expr = Tok.is(tok::l_brace) ? ParseBraceInitializer()
1809 assert(Tok.is(tok::kw_this) &&
"Not 'this'!");
1811 return Actions.ActOnCXXThis(ThisLoc);
1815Parser::ParseCXXTypeConstructExpression(
const DeclSpec &DS) {
1818 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
1820 assert((Tok.is(tok::l_paren) ||
1822 &&
"Expected '(' or '{'!");
1824 if (Tok.is(tok::l_brace)) {
1825 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1827 if (
Init.isInvalid())
1830 return Actions.ActOnCXXTypeConstructExpr(
1837 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1841 auto RunSignatureHelp = [&]() {
1842 QualType PreferredType;
1845 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
1847 Exprs, T.getOpenLocation(),
false);
1848 CalledSignatureHelp =
true;
1849 return PreferredType;
1852 if (Tok.isNot(tok::r_paren)) {
1853 if (ParseExpressionList(Exprs, [&] {
1854 PreferredType.enterFunctionArgument(Tok.getLocation(),
1857 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
1871 return Actions.ActOnCXXTypeConstructExpr(TypeRep, T.getOpenLocation(),
1872 Exprs, T.getCloseLocation(),
1880 assert(Tok.is(tok::kw_using) &&
"Expected using");
1883 "Unexpected Declarator Context");
1887 DG = ParseUsingDeclaration(Context, {}, DeclStart, DeclEnd, Attrs,
AS_none);
1891 DiagCompat(DeclStart, diag_compat::alias_in_init_statement);
1899 bool MissingOK, ForRangeInfo *FRI,
1900 bool AfterInitStmt) {
1902 PreferredType.enterCondition(Actions, Tok.getLocation());
1904 if (Tok.is(tok::code_completion)) {
1906 Actions.CodeCompletion().CodeCompleteOrdinaryName(
1911 std::optional<ExtensionRAIIObject> ExtensionGuard;
1912 SourceLocation ExtLoc;
1913 if (Tok.is(tok::kw___extension__)) {
1919 ExtensionGuard.emplace(Diags);
1929 ParsedAttributes attrs(AttrFactory);
1930 bool ParsedAttrs = MaybeParseCXX11Attributes(attrs);
1932 const auto WarnOnInit = [
this, &CK] {
1934 DiagCompat(Tok.getLocation(), diag_compat::init_statement)
1937 DiagCompat(Tok.getLocation(), diag_compat::decl_statement)
1942 if (isDeclarationStatement() && !isCXXSimpleDeclaration(
false)) {
1946 if (InitStmt !=
nullptr)
1949 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
1950 ParsedAttributes DeclSpecAttrs(AttrFactory);
1954 StmtResult DeclStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd);
1955 if (InitStmt ==
nullptr) {
1959 unsigned DiagID = AfterInitStmt ? diag::err_expected_expression
1960 : diag::err_c_decl_in_while_statement;
1961 if (DeclStmt.isUsable())
1962 Diag(DeclStmt.get()->getBeginLoc(), DiagID)
1963 << DeclStmt.get()->getSourceRange();
1965 Diag(DeclStart, DiagID);
1967 *InitStmt = DeclStmt;
1968 ExtensionGuard.reset();
1969 return ParseCondition(
nullptr, Loc, CK, MissingOK,
nullptr,
1975 if (InitStmt && Tok.is(tok::semi)) {
1979 *InitStmt = Actions.ActOnAttributedStmt(attrs,
Null.get());
1982 diag::err_c2y_first_condition_clause_is_not_declaration);
1983 ExtensionGuard.reset();
1984 return ParseCondition(
nullptr, Loc, CK, MissingOK,
nullptr,
1990 switch (isCXXConditionDeclarationOrInitStatement(InitStmt, FRI)) {
1991 case ConditionOrInitStatement::Expression: {
1992 ProhibitAttributes(attrs);
1996 if (InitStmt && Tok.is(tok::semi)) {
1998 SourceLocation SemiLoc = Tok.getLocation();
1999 if (!Tok.hasLeadingEmptyMacro() && !SemiLoc.
isMacroID()) {
2000 Diag(SemiLoc, diag::warn_empty_init_statement)
2005 *InitStmt = Actions.ActOnNullStmt(SemiLoc);
2006 ExtensionGuard.reset();
2007 return ParseCondition(
nullptr, Loc, CK, MissingOK,
nullptr,
2011 EnterExpressionEvaluationContext Eval(
2017 ExtensionGuard.reset();
2019 ? ParseExpressionWithLeadingExtension(ExtLoc)
2025 if (InitStmt && Tok.is(tok::semi)) {
2027 *InitStmt = Actions.ActOnExprStmt(Expr.get());
2029 return ParseCondition(nullptr, Loc, CK, MissingOK, nullptr,
2033 return Actions.ActOnCondition(
getCurScope(), Loc, Expr.
get(), CK,
2037 case ConditionOrInitStatement::InitStmtDecl: {
2040 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
2041 if (Tok.is(tok::kw_using))
2042 DG = ParseAliasDeclarationInInitStatement(
2045 ParsedAttributes DeclSpecAttrs(AttrFactory);
2047 attrs, DeclSpecAttrs,
true);
2049 *InitStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd);
2050 ExtensionGuard.reset();
2051 return ParseCondition(
nullptr, Loc, CK, MissingOK,
nullptr,
2055 case ConditionOrInitStatement::ForRangeDecl: {
2059 assert(FRI &&
"should not parse a for range declaration here");
2060 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
2061 ParsedAttributes DeclSpecAttrs(AttrFactory);
2064 FRI->LoopVar = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
2065 return Sema::ConditionResult();
2068 case ConditionOrInitStatement::ConditionDecl:
2069 case ConditionOrInitStatement::Error:
2074 DeclSpec DS(AttrFactory);
2075 ParseSpecifierQualifierList(DS,
AS_none, DeclSpecContext::DSC_condition);
2079 ParseDeclarator(DeclaratorInfo);
2086 Diag(DeclaratorInfo.getBeginLoc(), diag::err_c_decl_in_while_statement)
2087 << DeclaratorInfo.getSourceRange();
2090 if (Tok.is(tok::kw_asm)) {
2092 ExprResult AsmLabel(ParseSimpleAsm(
true, &Loc));
2093 if (AsmLabel.isInvalid()) {
2097 DeclaratorInfo.setAsmLabel(AsmLabel.get());
2098 DeclaratorInfo.SetRangeEnd(Loc);
2102 MaybeParseGNUAttributes(DeclaratorInfo);
2113 bool CopyInitialization = isTokenEqualOrEqualTypo();
2114 if (CopyInitialization)
2119 Diag(Tok.getLocation(), diag::compat_cxx11_generalized_initializer_lists);
2120 InitExpr = ParseBraceInitializer();
2121 }
else if (CopyInitialization) {
2122 PreferredType.enterVariableInit(Tok.getLocation(), DeclOut);
2124 }
else if (Tok.is(tok::l_paren)) {
2126 SourceLocation LParen = ConsumeParen(), RParen = LParen;
2128 RParen = ConsumeParen();
2130 diag::err_expected_init_in_condition_lparen)
2131 << SourceRange(LParen, RParen);
2137 Actions.AddInitializerToDecl(DeclOut, InitExpr.
get(), !CopyInitialization);
2139 Actions.ActOnInitializerError(DeclOut);
2141 Actions.FinalizeDeclaration(DeclOut);
2142 return Actions.ActOnConditionVariable(DeclOut, Loc, CK);
2145void Parser::ParseCXXSimpleTypeSpecifier(
DeclSpec &DS) {
2147 const char *PrevSpec;
2149 SourceLocation Loc = Tok.getLocation();
2150 const clang::PrintingPolicy &Policy =
2151 Actions.getASTContext().getPrintingPolicy();
2153 switch (Tok.getKind()) {
2154 case tok::identifier:
2155 case tok::coloncolon:
2156 llvm_unreachable(
"Annotation token should already be formed!");
2158 llvm_unreachable(
"Not a simple-type-specifier token!");
2161 case tok::annot_typename: {
2165 ConsumeAnnotationToken();
2166 DS.
Finish(Actions, Policy);
2170 case tok::kw__ExtInt:
2171 case tok::kw__BitInt: {
2172 DiagnoseBitIntUse(Tok);
2181 DS.
Finish(Actions, Policy);
2194 case tok::kw___int64:
2198 case tok::kw_signed:
2201 case tok::kw_unsigned:
2216 case tok::kw___int128:
2219 case tok::kw___bf16:
2228 case tok::kw_double:
2231 case tok::kw__Float16:
2234 case tok::kw___float128:
2237 case tok::kw___ibm128:
2240 case tok::kw_wchar_t:
2243 case tok::kw_char8_t:
2246 case tok::kw_char16_t:
2249 case tok::kw_char32_t:
2255 case tok::kw__Accum:
2258 case tok::kw__Fract:
2264#define GENERIC_IMAGE_TYPE(ImgType, Id) \
2265 case tok::kw_##ImgType##_t: \
2266 DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, DiagID, \
2269#include "clang/Basic/OpenCLImageTypes.def"
2270#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
2271 case tok::kw_##Name: \
2272 DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, DiagID, Policy); \
2274#include "clang/Basic/HLSLIntangibleTypes.def"
2275#define HLSL_PACKED_TYPE(Name, Id, SingletonId) \
2276 case tok::kw_##Name: \
2277 DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, DiagID, Policy); \
2279#include "clang/Basic/HLSLPackedTypes.def"
2281 case tok::annot_decltype:
2282 case tok::kw_decltype:
2284 return DS.
Finish(Actions, Policy);
2286 case tok::annot_pack_indexing_type:
2288 return DS.
Finish(Actions, Policy);
2291 case tok::kw_typeof:
2292 case tok::kw_typeof_unqual:
2293 ParseTypeofSpecifier(DS);
2294 DS.
Finish(Actions, Policy);
2299 DS.
Finish(Actions, Policy);
2303 ParseSpecifierQualifierList(DS,
AS_none,
2304 getDeclSpecContextFromDeclaratorContext(Context));
2305 DS.
Finish(Actions, Actions.getASTContext().getPrintingPolicy());
2309bool Parser::ParseUnqualifiedIdTemplateId(
2312 bool EnteringContext,
UnqualifiedId &Id,
bool AssumeTemplateId) {
2313 assert(Tok.is(tok::less) &&
"Expected '<' to finish parsing a template-id");
2321 if (AssumeTemplateId) {
2324 TNK = Actions.ActOnTemplateName(
getCurScope(), SS, TemplateKWLoc, Id,
2325 ObjectType, EnteringContext,
Template,
2328 bool MemberOfUnknownSpecialization;
2331 ObjectType, EnteringContext,
Template,
2332 MemberOfUnknownSpecialization);
2337 isTemplateArgumentList(0) == TPResult::False)
2341 ObjectType && isTemplateArgumentList(0) == TPResult::True) {
2344 if (!ObjectHadErrors) {
2363 TNK = Actions.ActOnTemplateName(
2364 getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext,
2374 bool MemberOfUnknownSpecialization;
2379 MemberOfUnknownSpecialization);
2387 bool MemberOfUnknownSpecialization;
2390 TNK = Actions.ActOnTemplateName(
2396 Template, MemberOfUnknownSpecialization,
2400 Diag(NameLoc, diag::err_destructor_template_id)
2413 SourceLocation LAngleLoc, RAngleLoc;
2414 TemplateArgList TemplateArgs;
2415 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs, RAngleLoc,
2430 const IdentifierInfo *TemplateII =
2440 LAngleLoc, RAngleLoc, TemplateArgs,
false, TemplateIds);
2452 SourceLocation(), SS, TemplateKWLoc,
Template,
2453 Name, NameLoc, LAngleLoc, TemplateArgsPtr, RAngleLoc,
2455 if (
Type.isInvalid())
2466bool Parser::ParseUnqualifiedIdOperator(
CXXScopeSpec &SS,
bool EnteringContext,
2469 assert(Tok.is(tok::kw_operator) &&
"Expected 'operator' keyword");
2475 unsigned SymbolIdx = 0;
2476 SourceLocation SymbolLocations[3];
2478 switch (Tok.getKind()) {
2480 case tok::kw_delete: {
2481 bool isNew = Tok.getKind() == tok::kw_new;
2485 if (Tok.is(tok::l_square) &&
2491 if (T.getCloseLocation().isInvalid())
2494 SymbolLocations[SymbolIdx++] = T.getOpenLocation();
2495 SymbolLocations[SymbolIdx++] = T.getCloseLocation();
2496 Op = isNew? OO_Array_New : OO_Array_Delete;
2498 Op = isNew? OO_New : OO_Delete;
2503#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
2505 SymbolLocations[SymbolIdx++] = ConsumeToken(); \
2508#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
2509#include "clang/Basic/OperatorKinds.def"
2511 case tok::l_paren: {
2516 if (T.getCloseLocation().isInvalid())
2519 SymbolLocations[SymbolIdx++] = T.getOpenLocation();
2520 SymbolLocations[SymbolIdx++] = T.getCloseLocation();
2525 case tok::l_square: {
2530 if (T.getCloseLocation().isInvalid())
2533 SymbolLocations[SymbolIdx++] = T.getOpenLocation();
2534 SymbolLocations[SymbolIdx++] = T.getCloseLocation();
2539 case tok::code_completion: {
2543 Actions.CodeCompletion().CodeCompleteOperatorName(
getCurScope());
2546 case tok::lesslessless: {
2551 SourceLocation TokLoc = Tok.getLocation();
2555 SourceLocation LessLessLoc = PP.SplitToken(TokLoc, LessLessLength);
2556 Token LessLess = Tok;
2558 LessLess.
setKind(tok::lessless);
2561 unsigned OldLength = Tok.getLength();
2563 bool CachingTokens = PP.IsPreviousCachedToken(Tok);
2564 Tok.setKind(tok::less);
2565 Tok.setLength(OldLength - LessLessLength);
2570 PP.ReplacePreviousCachedToken({LessLess, Tok});
2572 SymbolLocations[SymbolIdx++] = LessLessLoc;
2583 Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations);
2594 Diag(Tok.getLocation(), diag::warn_cxx98_compat_literal_operator);
2596 SourceLocation DiagLoc;
2597 unsigned DiagId = 0;
2601 SmallVector<Token, 4> Toks;
2602 SmallVector<SourceLocation, 4> TokLocs;
2603 while (isTokenStringLiteral()) {
2604 if (!Tok.is(tok::string_literal) && !DiagId) {
2608 DiagLoc = Tok.getLocation();
2609 DiagId = diag::err_literal_operator_string_prefix;
2611 Toks.push_back(Tok);
2612 TokLocs.push_back(ConsumeStringToken());
2615 StringLiteralParser
Literal(Toks, PP);
2621 bool IsUDSuffix = !
Literal.getUDSuffix().empty();
2622 IdentifierInfo *II =
nullptr;
2623 SourceLocation SuffixLoc;
2625 II = &PP.getIdentifierTable().get(
Literal.getUDSuffix());
2630 }
else if (Tok.is(tok::identifier)) {
2631 II = Tok.getIdentifierInfo();
2633 TokLocs.push_back(SuffixLoc);
2635 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
2645 DiagLoc = TokLocs.front();
2646 DiagId = diag::err_literal_operator_string_not_empty;
2652 SmallString<32> Str;
2656 SourceRange(TokLocs.front(), TokLocs.back()), Str);
2659 Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
2661 return Actions.checkLiteralOperatorId(SS,
Result, IsUDSuffix);
2676 DeclSpec DS(AttrFactory);
2677 if (ParseCXXTypeSpecifierSeq(
2685 ParseDeclaratorInternal(D,
nullptr);
2693 Result.setConversionFunctionId(KeywordLoc, Ty.
get(),
2694 D.getSourceRange().getEnd());
2699 bool ObjectHadErrors,
bool EnteringContext,
2700 bool AllowDestructorName,
2701 bool AllowConstructorName,
2702 bool AllowDeductionGuide,
2710 bool TemplateSpecified =
false;
2711 if (Tok.is(tok::kw_template)) {
2712 if (TemplateKWLoc && (ObjectType || SS.
isSet())) {
2713 TemplateSpecified =
true;
2717 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2725 if (Tok.is(tok::identifier)) {
2734 Result.setIdentifier(Id, IdLoc);
2739 if (AllowConstructorName &&
2740 Actions.isCurrentClassName(*Id,
getCurScope(), &SS)) {
2746 Result.setConstructorName(Ty, IdLoc, IdLoc);
2749 Actions.isDeductionGuideName(
getCurScope(), *Id, IdLoc, SS,
2755 Result.setIdentifier(Id, IdLoc);
2760 if (Tok.is(tok::less))
2761 return ParseUnqualifiedIdTemplateId(
2762 SS, ObjectType, ObjectHadErrors,
2764 EnteringContext,
Result, TemplateSpecified);
2766 if (TemplateSpecified) {
2769 ObjectType, EnteringContext,
Template,
2780 Diag(IdLoc, diag::missing_template_arg_list_after_template_kw);
2787 if (Tok.is(tok::annot_template_id)) {
2793 ConsumeAnnotationToken();
2798 if (AllowConstructorName && TemplateId->
Name &&
2806 diag::err_out_of_line_constructor_template_id)
2817 ConsumeAnnotationToken();
2821 Result.setConstructorTemplateId(TemplateId);
2822 ConsumeAnnotationToken();
2828 Result.setTemplateId(TemplateId);
2831 if (TemplateKWLoc && (ObjectType || SS.
isSet()))
2832 *TemplateKWLoc = TemplateLoc;
2834 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2837 ConsumeAnnotationToken();
2844 if (Tok.is(tok::kw_operator)) {
2845 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
Result))
2857 return ParseUnqualifiedIdTemplateId(
2858 SS, ObjectType, ObjectHadErrors,
2861 else if (TemplateSpecified &&
2862 Actions.ActOnTemplateName(
2872 (AllowDestructorName || SS.
isSet()) && Tok.is(tok::tilde)) {
2881 if (TemplateSpecified) {
2892 Diag(*TemplateKWLoc, diag::err_unexpected_template_in_destructor_name)
2893 << Tok.getLocation();
2897 if (SS.
isEmpty() && Tok.is(tok::kw_decltype)) {
2901 Actions.getDestructorTypeForDecltype(DS, ObjectType)) {
2902 Result.setDestructorName(TildeLoc,
Type, EndLoc);
2909 if (Tok.isNot(tok::identifier)) {
2910 Diag(Tok, diag::err_destructor_tilde_identifier);
2915 DeclaratorScopeObj DeclScopeObj(*
this, SS);
2923 AnnotateScopeToken(SS,
true);
2926 if (ParseOptionalCXXScopeSpecifier(SS, ObjectType, ObjectHadErrors,
2930 ObjectType =
nullptr;
2931 if (Tok.isNot(tok::identifier) ||
NextToken().
is(tok::coloncolon) ||
2933 Diag(TildeLoc, diag::err_destructor_tilde_scope);
2938 Diag(TildeLoc, diag::err_destructor_tilde_scope)
2943 if (Actions.ShouldEnterDeclaratorScope(
getCurScope(), SS))
2944 DeclScopeObj.EnterDeclaratorScope();
2951 if (Tok.is(tok::less)) {
2952 Result.setDestructorName(TildeLoc,
nullptr, ClassNameLoc);
2953 return ParseUnqualifiedIdTemplateId(
2954 SS, ObjectType, ObjectHadErrors,
2956 ClassNameLoc, EnteringContext,
Result, TemplateSpecified);
2961 Actions.getDestructorName(*ClassName, ClassNameLoc,
getCurScope(), SS,
2962 ObjectType, EnteringContext);
2966 Result.setDestructorName(TildeLoc, Ty, ClassNameLoc);
2970 switch (Tok.getKind()) {
2971#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
2972#include "clang/Basic/BuiltinTraits.inc"
2974 Tok.setKind(tok::identifier);
2975 Diag(Tok, diag::ext_keyword_as_ident)
2976 << Tok.getIdentifierInfo()->getName() << 0;
2977 goto ParseIdentifier;
2981 Diag(Tok, diag::err_expected_unqualified_id) <<
getLangOpts().CPlusPlus;
2987Parser::ParseCXXNewExpression(
bool UseGlobal,
SourceLocation Start) {
2988 assert(
Tok.is(tok::kw_new) &&
"expected 'new' token");
2994 ExprVector PlacementArgs;
3001 if (
Tok.is(tok::l_paren)) {
3005 PlacementLParen = T.getOpenLocation();
3006 if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) {
3012 PlacementRParen = T.getCloseLocation();
3018 if (PlacementArgs.empty()) {
3020 TypeIdParens = T.getRange();
3021 PlacementLParen = PlacementRParen = SourceLocation();
3024 if (Tok.is(tok::l_paren)) {
3027 MaybeParseGNUAttributes(DeclaratorInfo);
3028 ParseSpecifierQualifierList(DS);
3030 ParseDeclarator(DeclaratorInfo);
3032 TypeIdParens = T.getRange();
3034 MaybeParseGNUAttributes(DeclaratorInfo);
3035 if (ParseCXXTypeSpecifierSeq(DS))
3036 DeclaratorInfo.setInvalidType(
true);
3039 ParseDeclaratorInternal(DeclaratorInfo,
3040 &Parser::ParseDirectNewDeclarator);
3047 MaybeParseGNUAttributes(DeclaratorInfo);
3049 DeclaratorInfo.setInvalidType(
true);
3052 ParseDeclaratorInternal(DeclaratorInfo,
3053 &Parser::ParseDirectNewDeclarator);
3056 if (DeclaratorInfo.isInvalidType()) {
3063 if (Tok.is(tok::l_paren)) {
3064 SourceLocation ConstructorLParen, ConstructorRParen;
3065 ExprVector ConstructorArgs;
3068 ConstructorLParen = T.getOpenLocation();
3069 if (Tok.isNot(tok::r_paren)) {
3070 auto RunSignatureHelp = [&]() {
3071 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
3072 QualType PreferredType;
3078 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
3080 DeclaratorInfo.getEndLoc(), ConstructorArgs,
3083 CalledSignatureHelp =
true;
3084 return PreferredType;
3086 if (ParseExpressionList(ConstructorArgs, [&] {
3087 PreferredType.enterFunctionArgument(Tok.getLocation(),
3090 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
3097 ConstructorRParen = T.getCloseLocation();
3102 Initializer = Actions.ActOnParenListExpr(ConstructorLParen,
3106 Diag(Tok.getLocation(), diag::compat_cxx11_generalized_initializer_lists);
3112 return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen,
3113 PlacementArgs, PlacementRParen,
3117void Parser::ParseDirectNewDeclarator(
Declarator &D) {
3120 while (Tok.is(tok::l_square)) {
3122 if (CheckProhibitedCXX11Attribute())
3131 if (
Size.isInvalid()) {
3133 SkipUntil(tok::r_square, StopAtSemi);
3141 ParsedAttributes Attrs(AttrFactory);
3142 MaybeParseCXX11Attributes(Attrs);
3146 Size.get(), T.getOpenLocation(),
3147 T.getCloseLocation()),
3148 std::move(Attrs), T.getCloseLocation());
3150 if (T.getCloseLocation().isInvalid())
3155bool Parser::ParseExpressionListOrTypeId(
3159 if (isTypeIdInParens()) {
3167 return ParseExpressionList(PlacementArgs);
3171Parser::ParseCXXDeleteExpression(
bool UseGlobal,
SourceLocation Start) {
3172 assert(Tok.is(tok::kw_delete) &&
"Expected 'delete' keyword");
3176 bool ArrayDelete =
false;
3177 if (Tok.is(tok::l_square) &&
NextToken().
is(tok::r_square)) {
3188 if (
Next.isOneOf(tok::l_brace, tok::less) ||
3189 (
Next.is(tok::l_paren) &&
3193 TentativeParsingAction TPA(*
this);
3194 SourceLocation LSquareLoc = Tok.getLocation();
3200 SourceLocation RBraceLoc;
3201 bool EmitFixIt =
false;
3202 if (Tok.is(tok::l_brace)) {
3205 RBraceLoc = Tok.getLocation();
3212 Diag(Start, diag::err_lambda_after_delete)
3213 << SourceRange(Start, RSquareLoc)
3217 RBraceLoc, 0, Actions.getSourceManager(),
getLangOpts()),
3220 Diag(Start, diag::err_lambda_after_delete)
3221 << SourceRange(Start, RSquareLoc);
3230 Lambda = ParsePostfixExpressionSuffix(Lambda);
3233 return Actions.ActOnCXXDelete(Start, UseGlobal,
false,
3242 if (T.getCloseLocation().isInvalid())
3250 return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete,
Operand.get());
3253ExprResult Parser::ParseRequiresExpression() {
3254 assert(Tok.is(tok::kw_requires) &&
"Expected 'requires' keyword");
3257 llvm::SmallVector<ParmVarDecl *, 2> LocalParameterDecls;
3259 if (Tok.is(tok::l_paren)) {
3264 if (!Tok.is(tok::r_paren)) {
3266 SourceLocation EllipsisLoc;
3267 llvm::SmallVector<DeclaratorChunk::ParamInfo, 2> LocalParameters;
3269 FirstArgAttrs, LocalParameters,
3272 Diag(EllipsisLoc, diag::err_requires_expr_parameter_list_ellipsis);
3273 for (
auto &ParamInfo : LocalParameters)
3280 if (
Braces.expectAndConsume())
3284 llvm::SmallVector<concepts::Requirement *, 2> Requirements;
3288 EnterExpressionEvaluationContext Ctx(
3296 RequiresExprBodyDecl *Body = Actions.ActOnStartRequiresExpr(
3297 RequiresKWLoc, LocalParameterDecls,
getCurScope());
3299 if (Tok.is(tok::r_brace)) {
3306 Diag(Tok, diag::err_empty_requires_expr);
3309 while (!Tok.is(tok::r_brace)) {
3310 switch (Tok.getKind()) {
3311 case tok::l_brace: {
3322 ExprBraces.consumeOpen();
3324 if (Expression.isUsable())
3325 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3326 if (!Expression.isUsable()) {
3327 ExprBraces.skipToEnd();
3333 if (ExprBraces.consumeClose())
3336 concepts::Requirement *Req =
nullptr;
3337 SourceLocation NoexceptLoc;
3339 if (Tok.is(tok::semi)) {
3340 Req = Actions.ActOnCompoundRequirement(Expression.get(), NoexceptLoc);
3342 Requirements.push_back(Req);
3347 Diag(Tok, diag::err_requires_expr_missing_arrow)
3350 if (TryAnnotateTypeConstraint()) {
3354 if (!isTypeConstraintAnnotation()) {
3355 Diag(Tok, diag::err_requires_expr_expected_type_constraint);
3360 if (Tok.is(tok::annot_cxxscope)) {
3361 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
3362 Tok.getAnnotationRange(),
3364 ConsumeAnnotationToken();
3367 Req = Actions.ActOnCompoundRequirement(
3368 Expression.get(), NoexceptLoc, SS, takeTemplateIdAnnotation(Tok),
3369 TemplateParameterDepth);
3370 ConsumeAnnotationToken();
3372 Requirements.push_back(Req);
3376 bool PossibleRequiresExprInSimpleRequirement =
false;
3377 if (Tok.is(tok::kw_requires)) {
3378 auto IsNestedRequirement = [&] {
3379 RevertingTentativeParsingAction TPA(*
this);
3381 if (Tok.is(tok::l_brace))
3388 if (Tok.is(tok::l_paren)) {
3391 auto Res = TryParseParameterDeclarationClause();
3392 if (Res != TPResult::False) {
3395 while (Depth != 0) {
3396 bool FoundParen =
SkipUntil(tok::l_paren, tok::r_paren,
3400 if (Tok.is(tok::l_paren))
3402 else if (Tok.is(tok::r_paren))
3413 if (Tok.is(tok::l_brace))
3422 if (IsNestedRequirement()) {
3435 Actions.ActOnNestedRequirement(ConstraintExpr.
get()))
3436 Requirements.push_back(Req);
3444 PossibleRequiresExprInSimpleRequirement =
true;
3445 }
else if (Tok.is(tok::kw_typename)) {
3448 TentativeParsingAction TPA(*
this);
3458 if (Tok.is(tok::annot_cxxscope)) {
3459 Actions.RestoreNestedNameSpecifierAnnotation(
3460 Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS);
3461 ConsumeAnnotationToken();
3464 if (Tok.isOneOf(tok::identifier, tok::annot_template_id) &&
3467 SourceLocation NameLoc = Tok.getLocation();
3468 IdentifierInfo *II =
nullptr;
3469 TemplateIdAnnotation *TemplateId =
nullptr;
3470 if (Tok.is(tok::identifier)) {
3471 II = Tok.getIdentifierInfo();
3474 TemplateId = takeTemplateIdAnnotation(Tok);
3475 ConsumeAnnotationToken();
3480 if (
auto *Req = Actions.ActOnTypeRequirement(TypenameKWLoc, SS,
3483 Requirements.push_back(Req);
3493 SourceLocation StartLoc = Tok.getLocation();
3495 if (Expression.isUsable())
3496 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3497 if (!Expression.isUsable()) {
3501 if (!Expression.isInvalid() && PossibleRequiresExprInSimpleRequirement)
3502 Diag(StartLoc, diag::err_requires_expr_in_simple_requirement)
3504 if (
auto *Req = Actions.ActOnSimpleRequirement(Expression.get()))
3505 Requirements.push_back(Req);
3511 if (Tok.is(tok::kw_noexcept)) {
3512 Diag(Tok, diag::err_requires_expr_simple_requirement_noexcept)
3521 if (ExpectAndConsumeSemi(diag::err_expected_semi_requirement)) {
3527 if (Requirements.empty()) {
3532 Actions.ActOnFinishRequiresExpr();
3537 Actions.ActOnFinishRequiresExpr();
3538 ParsingBodyDecl.complete(Body);
3539 return Actions.ActOnRequiresExpr(
3540 RequiresKWLoc, Body,
Parens.getOpenLocation(), LocalParameterDecls,
3541 Parens.getCloseLocation(), Requirements,
Braces.getCloseLocation());
3546 default: llvm_unreachable(
"Not a known type trait");
3547#define TYPE_TRAIT_1(Spelling, Name, Key) \
3548case tok::kw_ ## Spelling: return UTT_ ## Name;
3549#define TYPE_TRAIT_2(Spelling, Name, Key) \
3550case tok::kw_ ## Spelling: return BTT_ ## Name;
3551#include "clang/Basic/TokenKinds.def"
3552#define TYPE_TRAIT_N(Spelling, Name, Key) \
3553 case tok::kw_ ## Spelling: return TT_ ## Name;
3554#include "clang/Basic/BuiltinTraits.inc"
3561 llvm_unreachable(
"Not a known array type trait");
3562#define ARRAY_TYPE_TRAIT(Spelling, Name, Key) \
3563 case tok::kw_##Spelling: \
3565#include "clang/Basic/BuiltinTraits.inc"
3572 llvm_unreachable(
"Not a known unary expression trait.");
3573#define EXPRESSION_TRAIT(Spelling, Name, Key) \
3574 case tok::kw_##Spelling: \
3576#include "clang/Basic/BuiltinTraits.inc"
3586 if (
Parens.expectAndConsume())
3589 SmallVector<ParsedType, 2> Args;
3602 if (Tok.is(tok::ellipsis)) {
3611 Args.push_back(Ty.
get());
3614 if (
Parens.consumeClose())
3617 SourceLocation EndLoc =
Parens.getCloseLocation();
3627 if (T.expectAndConsume())
3639 case ATT_ArrayRank: {
3641 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(),
nullptr,
3642 T.getCloseLocation());
3644 case ATT_ArrayExtent: {
3645 if (ExpectAndConsume(tok::comma)) {
3656 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(), DimExpr.
get(),
3657 T.getCloseLocation());
3660 llvm_unreachable(
"Invalid ArrayTypeTrait!");
3668 if (T.expectAndConsume())
3675 return Actions.ActOnExpressionTrait(ET, Loc, Expr.
get(),
3676 T.getCloseLocation());
3686 "Compound literals are not ambiguous!");
3687 assert(isTypeIdInParens() &&
"Not a type-id!");
3716 if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) {
3722 if (Tok.is(tok::l_brace)) {
3726 if (Tok.is(tok::l_paren) &&
NextToken().
is(tok::r_paren)) {
3734 false , NotCastExpr,
3747 Toks.push_back(AttrEnd);
3750 Toks.push_back(Tok);
3753 PP.EnterTokenStream(Toks,
true,
3761 DeclSpec DS(AttrFactory);
3766 ParseSpecifierQualifierList(DS);
3767 ParseDeclarator(DeclaratorInfo);
3775 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3780 if (DeclaratorInfo.isInvalidType())
3783 TypeResult Ty = Actions.ActOnTypeName(DeclaratorInfo);
3784 return ParseCompoundLiteralExpression(Ty.
get(),
3792 if (DeclaratorInfo.isInvalidType())
3798 DeclaratorInfo, CastTy,
3808 if (!
Result.isInvalid() && Tok.is(tok::r_paren))
3810 Tok.getLocation(),
Result.get());
3813 if (
Result.isInvalid()) {
3814 while (Tok.isNot(tok::eof))
3816 assert(Tok.getEofData() == AttrEnd.getEofData());
3823 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3832 if (T.expectAndConsume(diag::err_expected_lparen_after,
"__builtin_bit_cast"))
3836 DeclSpec DS(AttrFactory);
3837 ParseSpecifierQualifierList(DS);
3842 ParseDeclarator(DeclaratorInfo);
3844 if (ExpectAndConsume(tok::comma)) {
3845 Diag(Tok.getLocation(), diag::err_expected) << tok::comma;
3852 if (T.consumeClose())
3855 if (
Operand.isInvalid() || DeclaratorInfo.isInvalidType())
3858 return Actions.ActOnBuiltinBitCastExpr(KWLoc, DeclaratorInfo, Operand,
3859 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, const LateParsedTypeAttrInfoList &LateAttrs={})
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.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
@ 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
@ 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.