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(
654 getCurScope(), SS, TemplateKWLoc, Name, Tok.is(tok::l_paren),
655 isAddressOfOperand,
nullptr,
false);
660 E = tryParseCXXPackIndexingExpression(E);
663 checkPotentialAngleBracket(E);
668 assert(Tok.is(tok::ellipsis) &&
NextToken().
is(tok::l_square) &&
674 if (
T.consumeClose() || IndexExpr.
isInvalid())
676 return Actions.ActOnPackIndexingExpr(
getCurScope(), PackIdExpression.
get(),
677 EllipsisLoc,
T.getOpenLocation(),
678 IndexExpr.
get(),
T.getCloseLocation());
682Parser::tryParseCXXPackIndexingExpression(
ExprResult PackIdExpression) {
685 Tok.is(tok::ellipsis) &&
NextToken().
is(tok::l_square)) {
686 E = ParseCXXPackIndexingExpression(E);
691ExprResult Parser::ParseCXXIdExpression(
bool isAddressOfOperand) {
697 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
702 assert(!
Result.isUnset() &&
"Typo correction suggested a keyword replacement "
703 "for a previous keyword suggestion");
709 LambdaIntroducer Intro;
710 if (ParseLambdaIntroducer(Intro)) {
717 return ParseLambdaExpressionAfterIntroducer(Intro);
720ExprResult Parser::TryParseLambdaExpression() {
722 "Not at the start of a possible lambda expression.");
725 if (
Next.is(tok::eof))
730 if (
Next.is(tok::r_square) ||
731 Next.is(tok::equal) ||
732 (
Next.is(tok::amp) &&
733 After.isOneOf(tok::r_square, tok::comma)) ||
734 (
Next.is(tok::identifier) &&
735 After.is(tok::r_square)) ||
736 Next.is(tok::ellipsis)) {
737 return ParseLambdaExpression();
742 if (
Next.is(tok::identifier) &&
After.is(tok::identifier))
750 LambdaIntroducer Intro;
752 TentativeParsingAction TPA(*
this);
753 LambdaIntroducerTentativeParse Tentative;
754 if (ParseLambdaIntroducer(Intro, &Tentative)) {
760 case LambdaIntroducerTentativeParse::Success:
764 case LambdaIntroducerTentativeParse::Incomplete:
768 Intro = LambdaIntroducer();
769 if (ParseLambdaIntroducer(Intro))
773 case LambdaIntroducerTentativeParse::MessageSend:
774 case LambdaIntroducerTentativeParse::Invalid:
781 return ParseLambdaExpressionAfterIntroducer(Intro);
785 LambdaIntroducerTentativeParse *Tentative) {
787 *Tentative = LambdaIntroducerTentativeParse::Success;
789 assert(Tok.is(tok::l_square) &&
"Lambda expressions begin with '['.");
799 auto Result = [&](llvm::function_ref<void()> Action,
800 LambdaIntroducerTentativeParse State =
801 LambdaIntroducerTentativeParse::Invalid) {
812 auto NonTentativeAction = [&](llvm::function_ref<void()> Action) {
814 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
820 if (Tok.is(tok::amp) &&
825 if (!Tok.getIdentifierInfo()) {
830 }
else if (Tok.is(tok::equal)) {
837 while (Tok.isNot(tok::r_square)) {
839 if (Tok.isNot(tok::comma)) {
844 if (Tok.is(tok::code_completion) &&
847 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
854 Diag(Tok.getLocation(), diag::err_expected_comma_or_rsquare);
860 if (Tok.is(tok::code_completion)) {
865 Actions.CodeCompletion().CodeCompleteObjCMessageReceiver(
getCurScope());
867 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
879 IdentifierInfo *Id =
nullptr;
880 SourceLocation EllipsisLocs[4];
882 SourceLocation LocStart = Tok.getLocation();
884 if (Tok.is(tok::star)) {
886 if (Tok.is(tok::kw_this)) {
891 Diag(Tok.getLocation(), diag::err_expected_star_this_capture);
894 }
else if (Tok.is(tok::kw_this)) {
897 }
else if (Tok.isOneOf(tok::amp, tok::equal) &&
905 [&] {
Diag(Tok.getLocation(), diag::err_capture_default_first); },
906 LambdaIntroducerTentativeParse::Incomplete);
910 if (Tok.is(tok::amp)) {
914 if (Tok.is(tok::code_completion)) {
916 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
925 if (Tok.is(tok::identifier)) {
926 Id = Tok.getIdentifierInfo();
928 }
else if (Tok.is(tok::kw_this)) {
931 Diag(Tok.getLocation(), diag::err_this_captured_by_reference);
935 [&] {
Diag(Tok.getLocation(), diag::err_expected_capture); });
940 if (Tok.is(tok::l_paren)) {
949 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
950 }
else if (ParseExpressionList(Exprs)) {
955 Init = Actions.ActOnParenListExpr(
Parens.getOpenLocation(),
956 Parens.getCloseLocation(),
959 }
else if (Tok.isOneOf(tok::l_brace, tok::equal)) {
963 EnterExpressionEvaluationContext EC(
972 Init = ParseInitializer();
973 }
else if (Tok.is(tok::l_brace)) {
977 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
999 SourceLocation StartLoc = Tok.getLocation();
1001 Init = ParseInitializer();
1003 if (Tok.getLocation() != StartLoc) {
1005 PP.RevertCachedTokens(1);
1008 Tok.setLocation(StartLoc);
1009 Tok.setKind(tok::annot_primary_expr);
1010 setExprAnnotation(Tok,
Init);
1011 Tok.setAnnotationEndLoc(PP.getLastCachedTokenLocation());
1012 PP.AnnotateCachedTokens(Tok);
1015 ConsumeAnnotationToken();
1024 if (Tentative && Tok.is(tok::identifier) &&
1027 *Tentative = LambdaIntroducerTentativeParse::MessageSend;
1032 SourceLocation EllipsisLoc;
1033 if (llvm::any_of(EllipsisLocs,
1034 [](SourceLocation Loc) {
return Loc.
isValid(); })) {
1038 SourceLocation *ExpectedEllipsisLoc =
1039 !InitCapture ? &EllipsisLocs[2] :
1042 EllipsisLoc = *ExpectedEllipsisLoc;
1044 unsigned DiagID = 0;
1046 DiagID = diag::err_lambda_capture_misplaced_ellipsis;
1047 for (SourceLocation Loc : EllipsisLocs) {
1052 unsigned NumEllipses = std::accumulate(
1053 std::begin(EllipsisLocs), std::end(EllipsisLocs), 0,
1054 [](
int N, SourceLocation Loc) {
return N + Loc.
isValid(); });
1055 if (NumEllipses > 1)
1056 DiagID = diag::err_lambda_capture_multiple_ellipses;
1059 NonTentativeAction([&] {
1061 SourceLocation DiagLoc;
1062 for (SourceLocation &Loc : EllipsisLocs) {
1063 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid()) {
1068 assert(DiagLoc.
isValid() &&
"no location for diagnostic");
1072 auto &&D =
Diag(DiagLoc, DiagID);
1073 if (DiagID == diag::err_lambda_capture_misplaced_ellipsis) {
1074 SourceLocation ExpectedLoc =
1080 for (SourceLocation &Loc : EllipsisLocs) {
1081 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid())
1093 if (
Init.isUsable()) {
1094 NonTentativeAction([&] {
1097 Expr *InitExpr =
Init.get();
1100 InitCaptureType = Actions.actOnLambdaInitCaptureInitialization(
1101 Loc, Kind ==
LCK_ByRef, EllipsisLoc, Id, InitKind, InitExpr);
1106 SourceLocation LocEnd = PrevTokLocation;
1109 InitCaptureType, SourceRange(LocStart, LocEnd));
1131 auto ConsumeLocation = [&P, &DeclEndLoc](
SourceLocation &SpecifierLoc,
1133 if (SpecifierLoc.isValid()) {
1135 diag::err_lambda_decl_specifier_repeated)
1140 DeclEndLoc = SpecifierLoc;
1145 case tok::kw_mutable:
1146 ConsumeLocation(MutableLoc, 0);
1148 case tok::kw_static:
1149 ConsumeLocation(StaticLoc, 1);
1151 case tok::kw_constexpr:
1152 ConsumeLocation(ConstexprLoc, 2);
1154 case tok::kw_consteval:
1155 ConsumeLocation(ConstevalLoc, 3);
1166 P.
DiagCompat(StaticLoc, diag_compat::static_lambda);
1167 const char *PrevSpec =
nullptr;
1168 unsigned DiagID = 0;
1172 assert(PrevSpec ==
nullptr && DiagID == 0 &&
1173 "Static cannot have been set previously!");
1181 P.
DiagCompat(ConstexprLoc, diag_compat::constexpr_on_lambda);
1182 const char *PrevSpec =
nullptr;
1183 unsigned DiagID = 0;
1186 assert(PrevSpec ==
nullptr && DiagID == 0 &&
1187 "Constexpr cannot have been set previously!");
1195 P.
Diag(ConstevalLoc, diag::warn_cxx20_compat_consteval);
1196 const char *PrevSpec =
nullptr;
1197 unsigned DiagID = 0;
1201 P.
Diag(ConstevalLoc, DiagID) << PrevSpec;
1217 P.
Diag(StaticLoc, diag::err_static_mutable_lambda);
1219 P.
Diag(StaticLoc, diag::err_static_lambda_captures);
1223bool Parser::isLambdaSpecifier() {
1224 return Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
1225 tok::kw_constexpr, tok::kw_consteval, tok::kw_static,
1226 tok::kw___private, tok::kw___global, tok::kw___local,
1227 tok::kw___constant, tok::kw___generic, tok::kw_requires,
1228 tok::kw_noexcept) ||
1229 Tok.isRegularKeywordAttribute() ||
1230 (Tok.is(tok::l_square) &&
NextToken().
is(tok::l_square));
1233ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
1237 Diag(LambdaBeginLoc, diag::ext_hlsl_lambda) << 1;
1240 ? diag::warn_cxx98_compat_lambda
1244 PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), LambdaBeginLoc,
1245 "lambda expression parsing");
1248 DeclSpec DS(AttrFactory);
1250 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1256 Actions.PushLambdaScope();
1257 SourceLocation DeclLoc = Tok.getLocation();
1259 Actions.ActOnLambdaExpressionAfterIntroducer(Intro,
getCurScope());
1261 ParsedAttributes Attributes(AttrFactory);
1269 if (Tok.is(tok::kw___noinline__)) {
1270 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1272 Attributes.addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
1274 0, tok::kw___noinline__);
1275 }
else if (Tok.is(tok::kw___attribute))
1276 ParseGNUAttributes(Attributes,
nullptr, &D);
1281 D.takeAttributesAppending(Attributes);
1285 if (Tok.is(tok::less)) {
1286 DiagCompat(Tok, diag_compat::lambda_template_parameter_list);
1288 SmallVector<NamedDecl*, 4> TemplateParams;
1289 SourceLocation LAngleLoc, RAngleLoc;
1290 if (ParseTemplateParameters(TemplateParamScope,
1291 CurTemplateDepthTracker.getDepth(),
1292 TemplateParams, LAngleLoc, RAngleLoc)) {
1293 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1297 if (TemplateParams.empty()) {
1299 diag::err_lambda_template_parameter_list_empty);
1310 ++CurTemplateDepthTracker;
1320 Actions.ActOnLambdaExplicitTemplateParameterList(
1321 Intro, LAngleLoc, TemplateParams, RAngleLoc, RequiresClause);
1329 if (isCXX11AttributeSpecifier() !=
1332 ? diag::warn_cxx20_compat_decl_attrs_on_lambda
1333 : diag::ext_decl_attrs_on_lambda)
1334 << Tok.isRegularKeywordAttribute() << Tok.getIdentifierInfo();
1335 MaybeParseCXX11Attributes(D);
1339 SourceLocation TrailingReturnTypeLoc;
1340 SourceLocation LParenLoc, RParenLoc;
1341 SourceLocation DeclEndLoc = DeclLoc;
1342 bool HasParentheses =
false;
1343 bool HasSpecifiers =
false;
1344 SourceLocation MutableLoc;
1351 SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
1352 SourceLocation EllipsisLoc;
1354 if (Tok.is(tok::l_paren)) {
1357 LParenLoc =
T.getOpenLocation();
1359 if (Tok.isNot(tok::r_paren)) {
1360 Actions.RecordParsingTemplateParameterDepth(
1361 CurTemplateDepthTracker.getOriginalDepth());
1363 ParseParameterDeclarationClause(D, Attributes, ParamInfo, EllipsisLoc);
1369 if (Actions.getCurGenericLambda())
1370 CurTemplateDepthTracker.setAddedDepth(1);
1374 DeclEndLoc = RParenLoc =
T.getCloseLocation();
1375 HasParentheses =
true;
1378 HasSpecifiers = isLambdaSpecifier();
1384 Diag(Tok, diag::ext_lambda_missing_parens)
1388 if (HasParentheses || HasSpecifiers) {
1392 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec, Attributes);
1395 SourceLocation ConstexprLoc;
1396 SourceLocation ConstevalLoc;
1397 SourceLocation StaticLoc;
1400 ConstevalLoc, DeclEndLoc);
1409 Actions.ActOnLambdaClosureParameters(
getCurScope(), ParamInfo);
1411 if (!HasParentheses)
1412 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1414 if (HasSpecifiers || HasParentheses) {
1417 SourceRange ESpecRange;
1418 SmallVector<ParsedType, 2> DynamicExceptions;
1419 SmallVector<SourceRange, 2> DynamicExceptionRanges;
1423 ESpecType = tryParseExceptionSpecification(
1424 false, ESpecRange, DynamicExceptions,
1425 DynamicExceptionRanges, NoexceptExpr, ExceptionSpecTokens);
1428 DeclEndLoc = ESpecRange.
getEnd();
1431 if (MaybeParseCXX11Attributes(Attributes))
1432 DeclEndLoc = Attributes.Range.getEnd();
1435 if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
1436 tok::kw___constant, tok::kw___generic)) {
1437 ParseOpenCLQualifiers(DS.getAttributes());
1444 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1446 SourceLocation FunLocalRangeEnd = DeclEndLoc;
1449 if (Tok.is(tok::arrow)) {
1450 FunLocalRangeEnd = Tok.getLocation();
1453 ParseTrailingReturnType(Range,
false);
1454 TrailingReturnTypeLoc =
Range.getBegin();
1455 if (
Range.getEnd().isValid())
1456 DeclEndLoc =
Range.getEnd();
1459 SourceLocation NoLoc;
1462 false, LParenLoc, ParamInfo.data(),
1463 ParamInfo.size(), EllipsisLoc, RParenLoc,
1465 NoLoc, MutableLoc, ESpecType,
1466 ESpecRange, DynamicExceptions.data(),
1467 DynamicExceptionRanges.data(), DynamicExceptions.size(),
1468 NoexceptExpr.
isUsable() ? NoexceptExpr.
get() :
nullptr,
1470 {}, LParenLoc, FunLocalRangeEnd, D,
1471 TrailingReturnType, TrailingReturnTypeLoc, &DS),
1472 std::move(Attributes), DeclEndLoc);
1474 if (HasParentheses && Tok.is(tok::kw_requires))
1475 ParseTrailingRequiresClause(D);
1481 for (
const ParsedAttr &A : Attributes)
1482 if (A.getKind() == ParsedAttr::AT_CUDADevice ||
1483 A.getKind() == ParsedAttr::AT_CUDAHost ||
1484 A.getKind() == ParsedAttr::AT_CUDAGlobal)
1485 Diag(A.getLoc(), diag::warn_cuda_attr_lambda_position)
1486 << A.getAttrName()->getName();
1497 Actions.ActOnStartOfLambdaDefinition(Intro, D, DS);
1500 if (!Tok.is(tok::l_brace)) {
1501 Diag(Tok, diag::err_expected_lambda_body);
1502 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1506 StmtResult Stmt(ParseCompoundStatementBody());
1508 TemplateParamScope.Exit();
1513 return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.get());
1515 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1521 const char *CastName =
nullptr;
1524 default: llvm_unreachable(
"Unknown C++ cast!");
1525 case tok::kw_addrspace_cast: CastName =
"addrspace_cast";
break;
1526 case tok::kw_const_cast: CastName =
"const_cast";
break;
1527 case tok::kw_dynamic_cast: CastName =
"dynamic_cast";
break;
1528 case tok::kw_reinterpret_cast: CastName =
"reinterpret_cast";
break;
1529 case tok::kw_static_cast: CastName =
"static_cast";
break;
1533 SourceLocation LAngleBracketLoc = Tok.getLocation();
1537 if (Tok.is(tok::l_square) && Tok.getLength() == 2) {
1539 if (
Next.is(tok::colon) && areTokensAdjacent(Tok,
Next))
1543 if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName))
1547 DeclSpec DS(AttrFactory);
1548 ParseSpecifierQualifierList(DS,
AS_none,
1549 DeclSpecContext::DSC_type_specifier);
1554 ParseDeclarator(DeclaratorInfo);
1556 SourceLocation RAngleBracketLoc = Tok.getLocation();
1558 if (ExpectAndConsume(tok::greater))
1559 return ExprError(
Diag(LAngleBracketLoc, diag::note_matching) << tok::less);
1563 if (
T.expectAndConsume(diag::err_expected_lparen_after, CastName))
1571 if (!
Result.isInvalid() && !DeclaratorInfo.isInvalidType())
1572 Result = Actions.ActOnCXXNamedCast(OpLoc, Kind,
1573 LAngleBracketLoc, DeclaratorInfo,
1575 T.getOpenLocation(),
Result.get(),
1576 T.getCloseLocation());
1582 assert(Tok.is(tok::kw_typeid) &&
"Not 'typeid'!");
1585 SourceLocation LParenLoc, RParenLoc;
1589 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"typeid"))
1591 LParenLoc =
T.getOpenLocation();
1612 if (isTypeIdInParens()) {
1617 RParenLoc =
T.getCloseLocation();
1621 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
true,
1631 RParenLoc =
T.getCloseLocation();
1635 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
false,
1636 Result.get(), RParenLoc);
1644 assert(Tok.is(tok::kw___uuidof) &&
"Not '__uuidof'!");
1650 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"__uuidof"))
1655 if (isTypeIdInParens()) {
1664 Result = Actions.ActOnCXXUuidof(OpLoc,
T.getOpenLocation(),
true,
1666 T.getCloseLocation());
1678 Result = Actions.ActOnCXXUuidof(OpLoc,
T.getOpenLocation(),
1680 Result.get(),
T.getCloseLocation());
1695 SourceLocation CCLoc;
1696 if (Tok.is(tok::identifier)) {
1697 FirstTypeName.
setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
1699 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1701 }
else if (Tok.is(tok::annot_template_id)) {
1702 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
1707 ConsumeAnnotationToken();
1708 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1711 assert(SS.
isEmpty() &&
"missing last component of nested name specifier");
1716 assert(Tok.is(tok::tilde) &&
"ParseOptionalCXXScopeSpecifier fail");
1719 if (Tok.is(tok::kw_decltype) && !FirstTypeName.
isValid()) {
1720 DeclSpec DS(AttrFactory);
1721 ParseDecltypeSpecifier(DS);
1724 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1728 if (!Tok.is(tok::identifier)) {
1729 Diag(Tok, diag::err_destructor_tilde_identifier);
1736 DeclSpec DS(AttrFactory);
1737 ParsePackIndexingType(DS);
1738 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1744 IdentifierInfo *Name = Tok.getIdentifierInfo();
1756 if (Tok.is(tok::less) &&
1757 ParseUnqualifiedIdTemplateId(
1758 SS, ObjectType, Base &&
Base->containsErrors(), SourceLocation(),
1759 Name, NameLoc,
false, SecondTypeName,
1763 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1764 SS, FirstTypeName, CCLoc, TildeLoc,
1770 return Actions.ActOnCXXBoolLiteral(
ConsumeToken(), Kind);
1774 assert(Tok.is(tok::kw_throw) &&
"Not throw!");
1780 switch (Tok.getKind()) {
1787 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc,
nullptr);
1791 if (Expr.isInvalid())
return Expr;
1792 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc, Expr.get());
1797 assert(Tok.is(tok::kw_co_yield) &&
"Not co_yield!");
1800 ExprResult Expr = Tok.is(tok::l_brace) ? ParseBraceInitializer()
1808 assert(Tok.is(tok::kw_this) &&
"Not 'this'!");
1810 return Actions.ActOnCXXThis(ThisLoc);
1814Parser::ParseCXXTypeConstructExpression(
const DeclSpec &DS) {
1817 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
1819 assert((Tok.is(tok::l_paren) ||
1821 &&
"Expected '(' or '{'!");
1823 if (Tok.is(tok::l_brace)) {
1824 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1826 if (
Init.isInvalid())
1829 return Actions.ActOnCXXTypeConstructExpr(
1836 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1840 auto RunSignatureHelp = [&]() {
1841 QualType PreferredType;
1844 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
1846 Exprs,
T.getOpenLocation(),
false);
1847 CalledSignatureHelp =
true;
1848 return PreferredType;
1851 if (Tok.isNot(tok::r_paren)) {
1852 if (ParseExpressionList(Exprs, [&] {
1853 PreferredType.enterFunctionArgument(Tok.getLocation(),
1856 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
1870 return Actions.ActOnCXXTypeConstructExpr(TypeRep,
T.getOpenLocation(),
1871 Exprs,
T.getCloseLocation(),
1879 assert(Tok.is(tok::kw_using) &&
"Expected using");
1882 "Unexpected Declarator Context");
1886 DG = ParseUsingDeclaration(Context, {}, DeclStart, DeclEnd, Attrs,
AS_none);
1890 DiagCompat(DeclStart, diag_compat::alias_in_init_statement);
1898 bool MissingOK, ForRangeInfo *FRI,
1899 bool AfterInitStmt) {
1901 PreferredType.enterCondition(Actions, Tok.getLocation());
1903 if (Tok.is(tok::code_completion)) {
1905 Actions.CodeCompletion().CodeCompleteOrdinaryName(
1910 std::optional<ExtensionRAIIObject> ExtensionGuard;
1911 SourceLocation ExtLoc;
1912 if (Tok.is(tok::kw___extension__)) {
1918 ExtensionGuard.emplace(Diags);
1928 ParsedAttributes attrs(AttrFactory);
1929 bool ParsedAttrs = MaybeParseCXX11Attributes(attrs);
1931 const auto WarnOnInit = [
this, &CK] {
1933 DiagCompat(Tok.getLocation(), diag_compat::init_statement)
1936 DiagCompat(Tok.getLocation(), diag_compat::decl_statement)
1941 if (isDeclarationStatement() && !isCXXSimpleDeclaration(
false)) {
1945 if (InitStmt !=
nullptr)
1948 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
1949 ParsedAttributes DeclSpecAttrs(AttrFactory);
1953 StmtResult DeclStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd);
1954 if (InitStmt ==
nullptr) {
1958 unsigned DiagID = AfterInitStmt ? diag::err_expected_expression
1959 : diag::err_c_decl_in_while_statement;
1960 if (DeclStmt.isUsable())
1961 Diag(DeclStmt.get()->getBeginLoc(), DiagID)
1962 << DeclStmt.get()->getSourceRange();
1964 Diag(DeclStart, DiagID);
1966 *InitStmt = DeclStmt;
1967 ExtensionGuard.reset();
1968 return ParseCondition(
nullptr, Loc, CK, MissingOK,
nullptr,
1974 if (InitStmt && Tok.is(tok::semi)) {
1978 *InitStmt = Actions.ActOnAttributedStmt(attrs,
Null.get());
1981 diag::err_c2y_first_condition_clause_is_not_declaration);
1982 ExtensionGuard.reset();
1983 return ParseCondition(
nullptr, Loc, CK, MissingOK,
nullptr,
1989 switch (isCXXConditionDeclarationOrInitStatement(InitStmt, FRI)) {
1990 case ConditionOrInitStatement::Expression: {
1991 ProhibitAttributes(attrs);
1995 if (InitStmt && Tok.is(tok::semi)) {
1997 SourceLocation SemiLoc = Tok.getLocation();
1998 if (!Tok.hasLeadingEmptyMacro() && !SemiLoc.
isMacroID()) {
1999 Diag(SemiLoc, diag::warn_empty_init_statement)
2004 *InitStmt = Actions.ActOnNullStmt(SemiLoc);
2005 ExtensionGuard.reset();
2006 return ParseCondition(
nullptr, Loc, CK, MissingOK,
nullptr,
2010 EnterExpressionEvaluationContext Eval(
2016 ExtensionGuard.reset();
2018 ? ParseExpressionWithLeadingExtension(ExtLoc)
2024 if (InitStmt && Tok.is(tok::semi)) {
2026 *InitStmt = Actions.ActOnExprStmt(Expr.get());
2028 return ParseCondition(nullptr, Loc, CK, MissingOK, nullptr,
2032 return Actions.ActOnCondition(
getCurScope(), Loc, Expr.
get(), CK,
2036 case ConditionOrInitStatement::InitStmtDecl: {
2039 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
2040 if (Tok.is(tok::kw_using))
2041 DG = ParseAliasDeclarationInInitStatement(
2044 ParsedAttributes DeclSpecAttrs(AttrFactory);
2046 attrs, DeclSpecAttrs,
true);
2048 *InitStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd);
2049 ExtensionGuard.reset();
2050 return ParseCondition(
nullptr, Loc, CK, MissingOK,
nullptr,
2054 case ConditionOrInitStatement::ForRangeDecl: {
2058 assert(FRI &&
"should not parse a for range declaration here");
2059 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
2060 ParsedAttributes DeclSpecAttrs(AttrFactory);
2063 FRI->LoopVar = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
2064 return Sema::ConditionResult();
2067 case ConditionOrInitStatement::ConditionDecl:
2068 case ConditionOrInitStatement::Error:
2073 DeclSpec DS(AttrFactory);
2074 ParseSpecifierQualifierList(DS,
AS_none, DeclSpecContext::DSC_condition);
2078 ParseDeclarator(DeclaratorInfo);
2085 Diag(DeclaratorInfo.getBeginLoc(), diag::err_c_decl_in_while_statement)
2086 << DeclaratorInfo.getSourceRange();
2089 if (Tok.is(tok::kw_asm)) {
2091 ExprResult AsmLabel(ParseSimpleAsm(
true, &Loc));
2092 if (AsmLabel.isInvalid()) {
2096 DeclaratorInfo.setAsmLabel(AsmLabel.get());
2097 DeclaratorInfo.SetRangeEnd(Loc);
2101 MaybeParseGNUAttributes(DeclaratorInfo);
2112 bool CopyInitialization = isTokenEqualOrEqualTypo();
2113 if (CopyInitialization)
2118 Diag(Tok.getLocation(), diag::compat_cxx11_generalized_initializer_lists);
2119 InitExpr = ParseBraceInitializer();
2120 }
else if (CopyInitialization) {
2121 PreferredType.enterVariableInit(Tok.getLocation(), DeclOut);
2123 }
else if (Tok.is(tok::l_paren)) {
2125 SourceLocation LParen = ConsumeParen(), RParen = LParen;
2127 RParen = ConsumeParen();
2129 diag::err_expected_init_in_condition_lparen)
2130 << SourceRange(LParen, RParen);
2136 Actions.AddInitializerToDecl(DeclOut, InitExpr.
get(), !CopyInitialization);
2138 Actions.ActOnInitializerError(DeclOut);
2140 Actions.FinalizeDeclaration(DeclOut);
2141 return Actions.ActOnConditionVariable(DeclOut, Loc, CK);
2144void Parser::ParseCXXSimpleTypeSpecifier(
DeclSpec &DS) {
2146 const char *PrevSpec;
2148 SourceLocation Loc = Tok.getLocation();
2149 const clang::PrintingPolicy &Policy =
2150 Actions.getASTContext().getPrintingPolicy();
2152 switch (Tok.getKind()) {
2153 case tok::identifier:
2154 case tok::coloncolon:
2155 llvm_unreachable(
"Annotation token should already be formed!");
2157 llvm_unreachable(
"Not a simple-type-specifier token!");
2160 case tok::annot_typename: {
2164 ConsumeAnnotationToken();
2165 DS.
Finish(Actions, Policy);
2169 case tok::kw__ExtInt:
2170 case tok::kw__BitInt: {
2171 DiagnoseBitIntUse(Tok);
2180 DS.
Finish(Actions, Policy);
2193 case tok::kw___int64:
2197 case tok::kw_signed:
2200 case tok::kw_unsigned:
2215 case tok::kw___int128:
2218 case tok::kw___bf16:
2227 case tok::kw_double:
2230 case tok::kw__Float16:
2233 case tok::kw___float128:
2236 case tok::kw___ibm128:
2239 case tok::kw_wchar_t:
2242 case tok::kw_char8_t:
2245 case tok::kw_char16_t:
2248 case tok::kw_char32_t:
2254 case tok::kw__Accum:
2257 case tok::kw__Fract:
2263#define GENERIC_IMAGE_TYPE(ImgType, Id) \
2264 case tok::kw_##ImgType##_t: \
2265 DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, DiagID, \
2268#include "clang/Basic/OpenCLImageTypes.def"
2269#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
2270 case tok::kw_##Name: \
2271 DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, DiagID, Policy); \
2273#include "clang/Basic/HLSLIntangibleTypes.def"
2274#define HLSL_PACKED_TYPE(Name, Id, SingletonId) \
2275 case tok::kw_##Name: \
2276 DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, DiagID, Policy); \
2278#include "clang/Basic/HLSLPackedTypes.def"
2280 case tok::annot_decltype:
2281 case tok::kw_decltype:
2283 return DS.
Finish(Actions, Policy);
2285 case tok::annot_pack_indexing_type:
2287 return DS.
Finish(Actions, Policy);
2290 case tok::kw_typeof:
2291 case tok::kw_typeof_unqual:
2292 ParseTypeofSpecifier(DS);
2293 DS.
Finish(Actions, Policy);
2298 DS.
Finish(Actions, Policy);
2302 ParseSpecifierQualifierList(DS,
AS_none,
2303 getDeclSpecContextFromDeclaratorContext(Context));
2304 DS.
Finish(Actions, Actions.getASTContext().getPrintingPolicy());
2308bool Parser::ParseUnqualifiedIdTemplateId(
2311 bool EnteringContext,
UnqualifiedId &Id,
bool AssumeTemplateId) {
2312 assert(Tok.is(tok::less) &&
"Expected '<' to finish parsing a template-id");
2320 if (AssumeTemplateId) {
2323 TNK = Actions.ActOnTemplateName(
getCurScope(), SS, TemplateKWLoc, Id,
2324 ObjectType, EnteringContext,
Template,
2327 bool MemberOfUnknownSpecialization;
2330 ObjectType, EnteringContext,
Template,
2331 MemberOfUnknownSpecialization);
2336 isTemplateArgumentList(0) == TPResult::False)
2340 ObjectType && isTemplateArgumentList(0) == TPResult::True) {
2343 if (!ObjectHadErrors) {
2362 TNK = Actions.ActOnTemplateName(
2363 getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext,
2373 bool MemberOfUnknownSpecialization;
2378 MemberOfUnknownSpecialization);
2386 bool MemberOfUnknownSpecialization;
2389 TNK = Actions.ActOnTemplateName(
2395 Template, MemberOfUnknownSpecialization,
2399 Diag(NameLoc, diag::err_destructor_template_id)
2412 SourceLocation LAngleLoc, RAngleLoc;
2413 TemplateArgList TemplateArgs;
2414 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs, RAngleLoc,
2429 const IdentifierInfo *TemplateII =
2439 LAngleLoc, RAngleLoc, TemplateArgs,
false, TemplateIds);
2451 SourceLocation(), SS, TemplateKWLoc,
Template,
2452 Name, NameLoc, LAngleLoc, TemplateArgsPtr, RAngleLoc,
2454 if (
Type.isInvalid())
2465bool Parser::ParseUnqualifiedIdOperator(
CXXScopeSpec &SS,
bool EnteringContext,
2468 assert(Tok.is(tok::kw_operator) &&
"Expected 'operator' keyword");
2474 unsigned SymbolIdx = 0;
2475 SourceLocation SymbolLocations[3];
2477 switch (Tok.getKind()) {
2479 case tok::kw_delete: {
2480 bool isNew = Tok.getKind() == tok::kw_new;
2484 if (Tok.is(tok::l_square) &&
2490 if (
T.getCloseLocation().isInvalid())
2493 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2494 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2495 Op = isNew? OO_Array_New : OO_Array_Delete;
2497 Op = isNew? OO_New : OO_Delete;
2502#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
2504 SymbolLocations[SymbolIdx++] = ConsumeToken(); \
2507#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
2508#include "clang/Basic/OperatorKinds.def"
2510 case tok::l_paren: {
2515 if (
T.getCloseLocation().isInvalid())
2518 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2519 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2524 case tok::l_square: {
2529 if (
T.getCloseLocation().isInvalid())
2532 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2533 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2538 case tok::code_completion: {
2542 Actions.CodeCompletion().CodeCompleteOperatorName(
getCurScope());
2545 case tok::lesslessless: {
2550 SourceLocation TokLoc = Tok.getLocation();
2554 SourceLocation LessLessLoc = PP.SplitToken(TokLoc, LessLessLength);
2555 Token LessLess = Tok;
2557 LessLess.
setKind(tok::lessless);
2560 unsigned OldLength = Tok.getLength();
2562 bool CachingTokens = PP.IsPreviousCachedToken(Tok);
2563 Tok.setKind(tok::less);
2564 Tok.setLength(OldLength - LessLessLength);
2569 PP.ReplacePreviousCachedToken({LessLess, Tok});
2571 SymbolLocations[SymbolIdx++] = LessLessLoc;
2582 Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations);
2593 Diag(Tok.getLocation(), diag::warn_cxx98_compat_literal_operator);
2595 SourceLocation DiagLoc;
2596 unsigned DiagId = 0;
2600 SmallVector<Token, 4> Toks;
2601 SmallVector<SourceLocation, 4> TokLocs;
2602 while (isTokenStringLiteral()) {
2603 if (!Tok.is(tok::string_literal) && !DiagId) {
2607 DiagLoc = Tok.getLocation();
2608 DiagId = diag::err_literal_operator_string_prefix;
2610 Toks.push_back(Tok);
2611 TokLocs.push_back(ConsumeStringToken());
2614 StringLiteralParser
Literal(Toks, PP);
2620 bool IsUDSuffix = !
Literal.getUDSuffix().empty();
2621 IdentifierInfo *II =
nullptr;
2622 SourceLocation SuffixLoc;
2624 II = &PP.getIdentifierTable().get(
Literal.getUDSuffix());
2629 }
else if (Tok.is(tok::identifier)) {
2630 II = Tok.getIdentifierInfo();
2632 TokLocs.push_back(SuffixLoc);
2634 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
2644 DiagLoc = TokLocs.front();
2645 DiagId = diag::err_literal_operator_string_not_empty;
2651 SmallString<32> Str;
2655 SourceRange(TokLocs.front(), TokLocs.back()), Str);
2658 Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
2660 return Actions.checkLiteralOperatorId(SS,
Result, IsUDSuffix);
2675 DeclSpec DS(AttrFactory);
2676 if (ParseCXXTypeSpecifierSeq(
2684 ParseDeclaratorInternal(D,
nullptr);
2692 Result.setConversionFunctionId(KeywordLoc, Ty.
get(),
2693 D.getSourceRange().getEnd());
2698 bool ObjectHadErrors,
bool EnteringContext,
2699 bool AllowDestructorName,
2700 bool AllowConstructorName,
2701 bool AllowDeductionGuide,
2709 bool TemplateSpecified =
false;
2710 if (Tok.is(tok::kw_template)) {
2711 if (TemplateKWLoc && (ObjectType || SS.
isSet())) {
2712 TemplateSpecified =
true;
2716 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2724 if (Tok.is(tok::identifier)) {
2733 Result.setIdentifier(Id, IdLoc);
2738 if (AllowConstructorName &&
2739 Actions.isCurrentClassName(*Id,
getCurScope(), &SS)) {
2745 Result.setConstructorName(Ty, IdLoc, IdLoc);
2748 Actions.isDeductionGuideName(
getCurScope(), *Id, IdLoc, SS,
2754 Result.setIdentifier(Id, IdLoc);
2759 if (Tok.is(tok::less))
2760 return ParseUnqualifiedIdTemplateId(
2761 SS, ObjectType, ObjectHadErrors,
2763 EnteringContext,
Result, TemplateSpecified);
2765 if (TemplateSpecified) {
2768 ObjectType, EnteringContext,
Template,
2779 Diag(IdLoc, diag::missing_template_arg_list_after_template_kw);
2786 if (Tok.is(tok::annot_template_id)) {
2792 ConsumeAnnotationToken();
2797 if (AllowConstructorName && TemplateId->
Name &&
2805 diag::err_out_of_line_constructor_template_id)
2816 ConsumeAnnotationToken();
2820 Result.setConstructorTemplateId(TemplateId);
2821 ConsumeAnnotationToken();
2827 Result.setTemplateId(TemplateId);
2830 if (TemplateKWLoc && (ObjectType || SS.
isSet()))
2831 *TemplateKWLoc = TemplateLoc;
2833 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2836 ConsumeAnnotationToken();
2843 if (Tok.is(tok::kw_operator)) {
2844 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
Result))
2856 return ParseUnqualifiedIdTemplateId(
2857 SS, ObjectType, ObjectHadErrors,
2860 else if (TemplateSpecified &&
2861 Actions.ActOnTemplateName(
2871 (AllowDestructorName || SS.
isSet()) && Tok.is(tok::tilde)) {
2880 if (TemplateSpecified) {
2891 Diag(*TemplateKWLoc, diag::err_unexpected_template_in_destructor_name)
2892 << Tok.getLocation();
2896 if (SS.
isEmpty() && Tok.is(tok::kw_decltype)) {
2900 Actions.getDestructorTypeForDecltype(DS, ObjectType)) {
2901 Result.setDestructorName(TildeLoc,
Type, EndLoc);
2908 if (Tok.isNot(tok::identifier)) {
2909 Diag(Tok, diag::err_destructor_tilde_identifier);
2914 DeclaratorScopeObj DeclScopeObj(*
this, SS);
2922 AnnotateScopeToken(SS,
true);
2925 if (ParseOptionalCXXScopeSpecifier(SS, ObjectType, ObjectHadErrors,
2929 ObjectType =
nullptr;
2930 if (Tok.isNot(tok::identifier) ||
NextToken().
is(tok::coloncolon) ||
2932 Diag(TildeLoc, diag::err_destructor_tilde_scope);
2937 Diag(TildeLoc, diag::err_destructor_tilde_scope)
2942 if (Actions.ShouldEnterDeclaratorScope(
getCurScope(), SS))
2943 DeclScopeObj.EnterDeclaratorScope();
2950 if (Tok.is(tok::less)) {
2951 Result.setDestructorName(TildeLoc,
nullptr, ClassNameLoc);
2952 return ParseUnqualifiedIdTemplateId(
2953 SS, ObjectType, ObjectHadErrors,
2955 ClassNameLoc, EnteringContext,
Result, TemplateSpecified);
2960 Actions.getDestructorName(*ClassName, ClassNameLoc,
getCurScope(), SS,
2961 ObjectType, EnteringContext);
2965 Result.setDestructorName(TildeLoc, Ty, ClassNameLoc);
2969 switch (Tok.getKind()) {
2970#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
2971#include "clang/Basic/BuiltinTraits.inc"
2973 Tok.setKind(tok::identifier);
2974 Diag(Tok, diag::ext_keyword_as_ident)
2975 << Tok.getIdentifierInfo()->getName() << 0;
2976 goto ParseIdentifier;
2980 Diag(Tok, diag::err_expected_unqualified_id) <<
getLangOpts().CPlusPlus;
2986Parser::ParseCXXNewExpression(
bool UseGlobal,
SourceLocation Start) {
2987 assert(
Tok.is(tok::kw_new) &&
"expected 'new' token");
2993 ExprVector PlacementArgs;
3000 if (
Tok.is(tok::l_paren)) {
3004 PlacementLParen =
T.getOpenLocation();
3005 if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) {
3011 PlacementRParen =
T.getCloseLocation();
3017 if (PlacementArgs.empty()) {
3019 TypeIdParens =
T.getRange();
3020 PlacementLParen = PlacementRParen = SourceLocation();
3023 if (Tok.is(tok::l_paren)) {
3026 MaybeParseGNUAttributes(DeclaratorInfo);
3027 ParseSpecifierQualifierList(DS);
3029 ParseDeclarator(DeclaratorInfo);
3031 TypeIdParens =
T.getRange();
3033 MaybeParseGNUAttributes(DeclaratorInfo);
3034 if (ParseCXXTypeSpecifierSeq(DS))
3035 DeclaratorInfo.setInvalidType(
true);
3038 ParseDeclaratorInternal(DeclaratorInfo,
3039 &Parser::ParseDirectNewDeclarator);
3046 MaybeParseGNUAttributes(DeclaratorInfo);
3048 DeclaratorInfo.setInvalidType(
true);
3051 ParseDeclaratorInternal(DeclaratorInfo,
3052 &Parser::ParseDirectNewDeclarator);
3055 if (DeclaratorInfo.isInvalidType()) {
3062 if (Tok.is(tok::l_paren)) {
3063 SourceLocation ConstructorLParen, ConstructorRParen;
3064 ExprVector ConstructorArgs;
3067 ConstructorLParen =
T.getOpenLocation();
3068 if (Tok.isNot(tok::r_paren)) {
3069 auto RunSignatureHelp = [&]() {
3070 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
3071 QualType PreferredType;
3077 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
3079 DeclaratorInfo.getEndLoc(), ConstructorArgs,
3082 CalledSignatureHelp =
true;
3083 return PreferredType;
3085 if (ParseExpressionList(ConstructorArgs, [&] {
3086 PreferredType.enterFunctionArgument(Tok.getLocation(),
3089 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
3096 ConstructorRParen =
T.getCloseLocation();
3101 Initializer = Actions.ActOnParenListExpr(ConstructorLParen,
3105 Diag(Tok.getLocation(), diag::compat_cxx11_generalized_initializer_lists);
3111 return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen,
3112 PlacementArgs, PlacementRParen,
3116void Parser::ParseDirectNewDeclarator(
Declarator &D) {
3119 while (Tok.is(tok::l_square)) {
3121 if (CheckProhibitedCXX11Attribute())
3130 if (
Size.isInvalid()) {
3132 SkipUntil(tok::r_square, StopAtSemi);
3140 ParsedAttributes Attrs(AttrFactory);
3141 MaybeParseCXX11Attributes(Attrs);
3145 Size.get(),
T.getOpenLocation(),
3146 T.getCloseLocation()),
3147 std::move(Attrs),
T.getCloseLocation());
3149 if (
T.getCloseLocation().isInvalid())
3154bool Parser::ParseExpressionListOrTypeId(
3158 if (isTypeIdInParens()) {
3166 return ParseExpressionList(PlacementArgs);
3170Parser::ParseCXXDeleteExpression(
bool UseGlobal,
SourceLocation Start) {
3171 assert(Tok.is(tok::kw_delete) &&
"Expected 'delete' keyword");
3175 bool ArrayDelete =
false;
3176 if (Tok.is(tok::l_square) &&
NextToken().
is(tok::r_square)) {
3187 if (
Next.isOneOf(tok::l_brace, tok::less) ||
3188 (
Next.is(tok::l_paren) &&
3192 TentativeParsingAction TPA(*
this);
3193 SourceLocation LSquareLoc = Tok.getLocation();
3199 SourceLocation RBraceLoc;
3200 bool EmitFixIt =
false;
3201 if (Tok.is(tok::l_brace)) {
3204 RBraceLoc = Tok.getLocation();
3211 Diag(Start, diag::err_lambda_after_delete)
3212 << SourceRange(Start, RSquareLoc)
3216 RBraceLoc, 0, Actions.getSourceManager(),
getLangOpts()),
3219 Diag(Start, diag::err_lambda_after_delete)
3220 << SourceRange(Start, RSquareLoc);
3229 Lambda = ParsePostfixExpressionSuffix(Lambda);
3232 return Actions.ActOnCXXDelete(Start, UseGlobal,
false,
3241 if (
T.getCloseLocation().isInvalid())
3249 return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete,
Operand.get());
3252ExprResult Parser::ParseRequiresExpression() {
3253 assert(Tok.is(tok::kw_requires) &&
"Expected 'requires' keyword");
3256 llvm::SmallVector<ParmVarDecl *, 2> LocalParameterDecls;
3258 if (Tok.is(tok::l_paren)) {
3263 if (!Tok.is(tok::r_paren)) {
3265 SourceLocation EllipsisLoc;
3266 llvm::SmallVector<DeclaratorChunk::ParamInfo, 2> LocalParameters;
3268 FirstArgAttrs, LocalParameters,
3271 Diag(EllipsisLoc, diag::err_requires_expr_parameter_list_ellipsis);
3272 for (
auto &ParamInfo : LocalParameters)
3279 if (
Braces.expectAndConsume())
3283 llvm::SmallVector<concepts::Requirement *, 2> Requirements;
3287 EnterExpressionEvaluationContext Ctx(
3295 RequiresExprBodyDecl *Body = Actions.ActOnStartRequiresExpr(
3296 RequiresKWLoc, LocalParameterDecls,
getCurScope());
3298 if (Tok.is(tok::r_brace)) {
3305 Diag(Tok, diag::err_empty_requires_expr);
3308 while (!Tok.is(tok::r_brace)) {
3309 switch (Tok.getKind()) {
3310 case tok::l_brace: {
3321 ExprBraces.consumeOpen();
3323 if (Expression.isUsable())
3324 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3325 if (!Expression.isUsable()) {
3326 ExprBraces.skipToEnd();
3332 if (ExprBraces.consumeClose())
3335 concepts::Requirement *Req =
nullptr;
3336 SourceLocation NoexceptLoc;
3338 if (Tok.is(tok::semi)) {
3339 Req = Actions.ActOnCompoundRequirement(Expression.get(), NoexceptLoc);
3341 Requirements.push_back(Req);
3346 Diag(Tok, diag::err_requires_expr_missing_arrow)
3349 if (TryAnnotateTypeConstraint()) {
3353 if (!isTypeConstraintAnnotation()) {
3354 Diag(Tok, diag::err_requires_expr_expected_type_constraint);
3359 if (Tok.is(tok::annot_cxxscope)) {
3360 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
3361 Tok.getAnnotationRange(),
3363 ConsumeAnnotationToken();
3366 Req = Actions.ActOnCompoundRequirement(
3367 Expression.get(), NoexceptLoc, SS, takeTemplateIdAnnotation(Tok),
3368 TemplateParameterDepth);
3369 ConsumeAnnotationToken();
3371 Requirements.push_back(Req);
3375 bool PossibleRequiresExprInSimpleRequirement =
false;
3376 if (Tok.is(tok::kw_requires)) {
3377 auto IsNestedRequirement = [&] {
3378 RevertingTentativeParsingAction TPA(*
this);
3380 if (Tok.is(tok::l_brace))
3387 if (Tok.is(tok::l_paren)) {
3390 auto Res = TryParseParameterDeclarationClause();
3391 if (Res != TPResult::False) {
3394 while (Depth != 0) {
3395 bool FoundParen =
SkipUntil(tok::l_paren, tok::r_paren,
3399 if (Tok.is(tok::l_paren))
3401 else if (Tok.is(tok::r_paren))
3412 if (Tok.is(tok::l_brace))
3421 if (IsNestedRequirement()) {
3434 Actions.ActOnNestedRequirement(ConstraintExpr.
get()))
3435 Requirements.push_back(Req);
3443 PossibleRequiresExprInSimpleRequirement =
true;
3444 }
else if (Tok.is(tok::kw_typename)) {
3447 TentativeParsingAction TPA(*
this);
3457 if (Tok.is(tok::annot_cxxscope)) {
3458 Actions.RestoreNestedNameSpecifierAnnotation(
3459 Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS);
3460 ConsumeAnnotationToken();
3463 if (Tok.isOneOf(tok::identifier, tok::annot_template_id) &&
3466 SourceLocation NameLoc = Tok.getLocation();
3467 IdentifierInfo *II =
nullptr;
3468 TemplateIdAnnotation *TemplateId =
nullptr;
3469 if (Tok.is(tok::identifier)) {
3470 II = Tok.getIdentifierInfo();
3473 TemplateId = takeTemplateIdAnnotation(Tok);
3474 ConsumeAnnotationToken();
3479 if (
auto *Req = Actions.ActOnTypeRequirement(TypenameKWLoc, SS,
3482 Requirements.push_back(Req);
3492 SourceLocation StartLoc = Tok.getLocation();
3494 if (Expression.isUsable())
3495 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3496 if (!Expression.isUsable()) {
3500 if (!Expression.isInvalid() && PossibleRequiresExprInSimpleRequirement)
3501 Diag(StartLoc, diag::err_requires_expr_in_simple_requirement)
3503 if (
auto *Req = Actions.ActOnSimpleRequirement(Expression.get()))
3504 Requirements.push_back(Req);
3510 if (Tok.is(tok::kw_noexcept)) {
3511 Diag(Tok, diag::err_requires_expr_simple_requirement_noexcept)
3520 if (ExpectAndConsumeSemi(diag::err_expected_semi_requirement)) {
3526 if (Requirements.empty()) {
3531 Actions.ActOnFinishRequiresExpr();
3536 Actions.ActOnFinishRequiresExpr();
3537 ParsingBodyDecl.complete(Body);
3538 return Actions.ActOnRequiresExpr(
3539 RequiresKWLoc, Body,
Parens.getOpenLocation(), LocalParameterDecls,
3540 Parens.getCloseLocation(), Requirements,
Braces.getCloseLocation());
3545 default: llvm_unreachable(
"Not a known type trait");
3546#define TYPE_TRAIT_1(Spelling, Name, Key) \
3547case tok::kw_ ## Spelling: return UTT_ ## Name;
3548#define TYPE_TRAIT_2(Spelling, Name, Key) \
3549case tok::kw_ ## Spelling: return BTT_ ## Name;
3550#include "clang/Basic/TokenKinds.def"
3551#define TYPE_TRAIT_N(Spelling, Name, Key) \
3552 case tok::kw_ ## Spelling: return TT_ ## Name;
3553#include "clang/Basic/BuiltinTraits.inc"
3560 llvm_unreachable(
"Not a known array type trait");
3561#define ARRAY_TYPE_TRAIT(Spelling, Name, Key) \
3562 case tok::kw_##Spelling: \
3564#include "clang/Basic/BuiltinTraits.inc"
3571 llvm_unreachable(
"Not a known unary expression trait.");
3572#define EXPRESSION_TRAIT(Spelling, Name, Key) \
3573 case tok::kw_##Spelling: \
3575#include "clang/Basic/BuiltinTraits.inc"
3585 if (
Parens.expectAndConsume())
3588 SmallVector<ParsedType, 2> Args;
3601 if (Tok.is(tok::ellipsis)) {
3610 Args.push_back(Ty.
get());
3613 if (
Parens.consumeClose())
3616 SourceLocation EndLoc =
Parens.getCloseLocation();
3626 if (
T.expectAndConsume())
3638 case ATT_ArrayRank: {
3640 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(),
nullptr,
3641 T.getCloseLocation());
3643 case ATT_ArrayExtent: {
3644 if (ExpectAndConsume(tok::comma)) {
3655 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(), DimExpr.
get(),
3656 T.getCloseLocation());
3659 llvm_unreachable(
"Invalid ArrayTypeTrait!");
3667 if (
T.expectAndConsume())
3674 return Actions.ActOnExpressionTrait(ET, Loc, Expr.
get(),
3675 T.getCloseLocation());
3685 "Compound literals are not ambiguous!");
3686 assert(isTypeIdInParens() &&
"Not a type-id!");
3715 if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) {
3721 if (Tok.is(tok::l_brace)) {
3725 if (Tok.is(tok::l_paren) &&
NextToken().
is(tok::r_paren)) {
3733 false , NotCastExpr,
3746 Toks.push_back(AttrEnd);
3749 Toks.push_back(Tok);
3752 PP.EnterTokenStream(Toks,
true,
3760 DeclSpec DS(AttrFactory);
3765 ParseSpecifierQualifierList(DS);
3766 ParseDeclarator(DeclaratorInfo);
3774 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3779 if (DeclaratorInfo.isInvalidType())
3782 TypeResult Ty = Actions.ActOnTypeName(DeclaratorInfo);
3783 return ParseCompoundLiteralExpression(Ty.
get(),
3791 if (DeclaratorInfo.isInvalidType())
3797 DeclaratorInfo, CastTy,
3807 if (!
Result.isInvalid() && Tok.is(tok::r_paren))
3809 Tok.getLocation(),
Result.get());
3812 if (
Result.isInvalid()) {
3813 while (Tok.isNot(tok::eof))
3815 assert(Tok.getEofData() == AttrEnd.getEofData());
3822 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3831 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"__builtin_bit_cast"))
3835 DeclSpec DS(AttrFactory);
3836 ParseSpecifierQualifierList(DS);
3841 ParseDeclarator(DeclaratorInfo);
3843 if (ExpectAndConsume(tok::comma)) {
3844 Diag(Tok.getLocation(), diag::err_expected) << tok::comma;
3851 if (
T.consumeClose())
3854 if (
Operand.isInvalid() || DeclaratorInfo.isInvalidType())
3857 return Actions.ActOnBuiltinBitCastExpr(KWLoc, DeclaratorInfo, Operand,
3858 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 AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc, const LateParsedAttrList &LateAttrs={})
AddTypeInfo - Add a chunk to this declarator.
void SetSourceRange(SourceRange R)
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
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.