28#include "llvm/Support/Compiler.h"
29#include "llvm/Support/ErrorHandling.h"
37 case tok::unknown:
return 0;
39 case tok::kw_addrspace_cast:
return 1;
40 case tok::kw_const_cast:
return 2;
41 case tok::kw_dynamic_cast:
return 3;
42 case tok::kw_reinterpret_cast:
return 4;
43 case tok::kw_static_cast:
return 5;
45 llvm_unreachable(
"Unknown type for digraph error message.");
49bool Parser::areTokensAdjacent(
const Token &
First,
const Token &Second) {
50 SourceManager &
SM = PP.getSourceManager();
51 SourceLocation FirstLoc =
SM.getSpellingLoc(
First.getLocation());
67 P.
Diag(DigraphToken.
getLocation(), diag::err_missing_whitespace_digraph)
72 ColonToken.
setKind(tok::coloncolon);
75 DigraphToken.
setKind(tok::less);
87 if (!
Next.is(tok::l_square) ||
Next.getLength() != 2)
91 if (!SecondToken.
is(tok::colon) || !areTokensAdjacent(
Next, SecondToken))
97 bool MemberOfUnknownSpecialization;
98 if (!Actions.isTemplateName(
getCurScope(), SS,
false,
100 Template, MemberOfUnknownSpecialization))
107bool Parser::ParseOptionalCXXScopeSpecifier(
109 bool EnteringContext,
bool *MayBePseudoDestructor,
bool IsTypename,
110 const IdentifierInfo **LastII,
bool OnlyNamespace,
bool InUsingDeclaration,
111 bool Disambiguation,
bool IsAddressOfOperand,
bool IsInDeclarationContext) {
113 "Call sites of this function should be guarded by checking for C++");
115 if (Tok.is(tok::annot_cxxscope)) {
116 assert(!LastII &&
"want last identifier but have already annotated scope");
117 assert(!MayBePseudoDestructor &&
"unexpected annot_cxxscope");
118 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
119 Tok.getAnnotationRange(),
121 ConsumeAnnotationToken();
126 bool CheckForDestructor =
false;
127 if (MayBePseudoDestructor && *MayBePseudoDestructor) {
128 CheckForDestructor =
true;
129 *MayBePseudoDestructor =
false;
135 bool HasScopeSpecifier =
false;
137 if (Tok.is(tok::coloncolon)) {
140 if (NextKind == tok::kw_new || NextKind == tok::kw_delete)
143 if (NextKind == tok::l_brace) {
149 if (Actions.ActOnCXXGlobalScopeSpecifier(
ConsumeToken(), SS))
152 HasScopeSpecifier =
true;
156 if (Tok.is(tok::kw___super)) {
158 if (!Tok.is(tok::coloncolon)) {
159 Diag(Tok.getLocation(), diag::err_expected_coloncolon_after_super);
163 return Actions.ActOnSuperScopeSpecifier(SuperLoc,
ConsumeToken(), SS);
166 if (!HasScopeSpecifier &&
167 Tok.isOneOf(tok::kw_decltype, tok::annot_decltype)) {
168 DeclSpec DS(AttrFactory);
169 SourceLocation DeclLoc = Tok.getLocation();
170 SourceLocation EndLoc = ParseDecltypeSpecifier(DS);
172 SourceLocation CCLoc;
177 AnnotateExistingDecltypeSpecifier(DS, DeclLoc, EndLoc);
181 if (Actions.ActOnCXXNestedNameSpecifierDecltype(SS, DS, CCLoc))
184 HasScopeSpecifier =
true;
187 else if (!HasScopeSpecifier && Tok.is(tok::identifier) &&
191 SourceLocation Start = Tok.getLocation();
192 DeclSpec DS(AttrFactory);
193 SourceLocation CCLoc;
194 SourceLocation EndLoc = ParsePackIndexingType(DS);
200 Actions.ActOnPackIndexingType(Pattern, DS.getPackIndexingExpr(),
201 DS.getBeginLoc(), DS.getEllipsisLoc());
217 Diag(Start, diag::warn_pre_cxx26_ambiguous_pack_indexing_type) <<
Type;
224 if (Actions.ActOnCXXNestedNameSpecifierIndexedPack(SS, DS, CCLoc,
227 HasScopeSpecifier =
true;
231 auto SavedType = PreferredType;
233 if (HasScopeSpecifier) {
234 if (Tok.is(tok::code_completion)) {
238 Actions.CodeCompletion().CodeCompleteQualifiedId(
239 getCurScope(), SS, EnteringContext, InUsingDeclaration,
240 IsAddressOfOperand, IsInDeclarationContext, ObjectType.
get(),
260 ObjectType =
nullptr;
268 if (Tok.is(tok::kw_template)) {
272 if (!HasScopeSpecifier && !ObjectType)
275 TentativeParsingAction TPA(*
this);
279 if (Tok.is(tok::identifier)) {
281 TemplateName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
283 }
else if (Tok.is(tok::kw_operator)) {
288 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
297 diag::err_id_after_template_in_nested_name_spec)
310 if (Tok.isNot(tok::less)) {
321 if (AnnotateTemplateIdToken(
Template, TNK, SS, TemplateKWLoc,
328 if (Tok.is(tok::annot_template_id) &&
NextToken().
is(tok::coloncolon)) {
336 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
338 *MayBePseudoDestructor =
true;
343 *LastII = TemplateId->
Name;
346 ConsumeAnnotationToken();
348 assert(Tok.is(tok::coloncolon) &&
"NextToken() not working properly!");
351 HasScopeSpecifier =
true;
367 SourceLocation StartLoc
376 switch (Tok.getKind()) {
377#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
378#include "clang/Basic/TransformTypeTraits.def"
380 Tok.setKind(tok::identifier);
381 Diag(Tok, diag::ext_keyword_as_ident)
382 << Tok.getIdentifierInfo()->getName() << 0;
392 if (Tok.isNot(tok::identifier))
395 IdentifierInfo &II = *Tok.getIdentifierInfo();
402 Sema::NestedNameSpecInfo IdInfo(&II, Tok.getLocation(),
Next.getLocation(),
407 if (
Next.is(tok::colon) && !ColonIsSacred) {
408 if (Actions.IsInvalidUnlessNestedName(
getCurScope(), SS, IdInfo,
413 PP.LookAhead(1).is(tok::identifier)) {
414 Diag(
Next, diag::err_unexpected_colon_in_nested_name_spec)
417 Next.setKind(tok::coloncolon);
424 Token Identifier = Tok;
428 UnconsumeToken(Identifier);
432 if (
Next.is(tok::coloncolon)) {
434 *MayBePseudoDestructor =
true;
440 if (Next2.
is(tok::kw_private) || Next2.
is(tok::kw_protected) ||
441 Next2.
is(tok::kw_public) || Next2.
is(tok::kw_virtual)) {
442 Diag(Next2, diag::err_unexpected_token_in_nested_name_spec)
447 ColonColon.
setKind(tok::colon);
448 PP.EnterToken(ColonColon,
true);
458 Token Identifier = Tok;
460 assert(Tok.isOneOf(tok::coloncolon, tok::colon) &&
461 "NextToken() not working properly!");
462 Token ColonColon = Tok;
465 bool IsCorrectedToColon =
false;
466 bool *CorrectionFlagPtr = ColonIsSacred ? &IsCorrectedToColon :
nullptr;
467 if (Actions.ActOnCXXNestedNameSpecifier(
468 getCurScope(), IdInfo, EnteringContext, SS, CorrectionFlagPtr,
472 if (CorrectionFlagPtr && IsCorrectedToColon) {
473 ColonColon.
setKind(tok::colon);
474 PP.EnterToken(Tok,
true);
475 PP.EnterToken(ColonColon,
true);
481 HasScopeSpecifier =
true;
485 CheckForTemplateAndDigraph(
Next, ObjectType, EnteringContext, II, SS);
489 if (
Next.is(tok::less)) {
494 bool MemberOfUnknownSpecialization;
498 EnteringContext,
Template, MemberOfUnknownSpecialization,
505 isTemplateArgumentList(1) == TPResult::False)
516 if (AnnotateTemplateIdToken(
Template, TNK, SS, SourceLocation(),
522 if (MemberOfUnknownSpecialization && !Disambiguation &&
523 (ObjectType || SS.
isSet()) &&
524 (IsTypename || isTemplateArgumentList(1) == TPResult::True)) {
527 if (!ObjectHadErrors) {
532 unsigned DiagID = diag::err_missing_dependent_template_keyword;
534 DiagID = diag::warn_missing_dependent_template_keyword;
536 Diag(Tok.getLocation(), DiagID)
544 ObjectType, EnteringContext,
Template,
546 if (AnnotateTemplateIdToken(
Template, TNK, SS, SourceLocation(),
562 if (CheckForDestructor && !HasScopeSpecifier && Tok.is(tok::tilde))
563 *MayBePseudoDestructor =
true;
569 bool isAddressOfOperand) {
573 switch (Tok.getKind()) {
574 case tok::annot_non_type: {
575 NamedDecl *ND = getNonTypeAnnotation(Tok);
576 SourceLocation Loc = ConsumeAnnotationToken();
577 E = Actions.ActOnNameClassifiedAsNonType(
getCurScope(), SS, ND, Loc, Tok);
581 case tok::annot_non_type_dependent: {
582 IdentifierInfo *II = getIdentifierAnnotation(Tok);
583 SourceLocation Loc = ConsumeAnnotationToken();
587 if (isAddressOfOperand && isPostfixExpressionSuffixStart())
588 isAddressOfOperand =
false;
590 E = Actions.ActOnNameClassifiedAsDependentNonType(SS, II, Loc,
595 case tok::annot_non_type_undeclared: {
597 "undeclared non-type annotation should be unqualified");
598 IdentifierInfo *II = getIdentifierAnnotation(Tok);
599 SourceLocation Loc = ConsumeAnnotationToken();
600 E = Actions.ActOnNameClassifiedAsUndeclaredNonType(II, Loc);
605 SourceLocation TemplateKWLoc;
612 false, &TemplateKWLoc, Name))
617 if (isAddressOfOperand && isPostfixExpressionSuffixStart())
618 isAddressOfOperand =
false;
620 E = Actions.ActOnIdExpression(
621 getCurScope(), SS, TemplateKWLoc, Name, Tok.is(tok::l_paren),
622 isAddressOfOperand,
nullptr,
false);
627 E = tryParseCXXPackIndexingExpression(E);
630 checkPotentialAngleBracket(E);
635 assert(Tok.is(tok::ellipsis) &&
NextToken().
is(tok::l_square) &&
641 if (T.consumeClose() || IndexExpr.
isInvalid())
643 return Actions.ActOnPackIndexingExpr(
getCurScope(), PackIdExpression.
get(),
644 EllipsisLoc, T.getOpenLocation(),
645 IndexExpr.
get(), T.getCloseLocation());
649Parser::tryParseCXXPackIndexingExpression(
ExprResult PackIdExpression) {
652 Tok.is(tok::ellipsis) &&
NextToken().
is(tok::l_square)) {
653 E = ParseCXXPackIndexingExpression(E);
658ExprResult Parser::ParseCXXIdExpression(
bool isAddressOfOperand) {
664 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
669 assert(!
Result.isUnset() &&
"Typo correction suggested a keyword replacement "
670 "for a previous keyword suggestion");
676 LambdaIntroducer Intro;
677 if (ParseLambdaIntroducer(Intro)) {
684 return ParseLambdaExpressionAfterIntroducer(Intro);
687ExprResult Parser::TryParseLambdaExpression() {
689 "Not at the start of a possible lambda expression.");
692 if (
Next.is(tok::eof))
697 if (
Next.is(tok::r_square) ||
698 Next.is(tok::equal) ||
699 (
Next.is(tok::amp) &&
700 After.isOneOf(tok::r_square, tok::comma)) ||
701 (
Next.is(tok::identifier) &&
702 After.is(tok::r_square)) ||
703 Next.is(tok::ellipsis)) {
704 return ParseLambdaExpression();
709 if (
Next.is(tok::identifier) &&
After.is(tok::identifier))
717 LambdaIntroducer Intro;
719 TentativeParsingAction TPA(*
this);
720 LambdaIntroducerTentativeParse Tentative;
721 if (ParseLambdaIntroducer(Intro, &Tentative)) {
727 case LambdaIntroducerTentativeParse::Success:
731 case LambdaIntroducerTentativeParse::Incomplete:
735 Intro = LambdaIntroducer();
736 if (ParseLambdaIntroducer(Intro))
740 case LambdaIntroducerTentativeParse::MessageSend:
741 case LambdaIntroducerTentativeParse::Invalid:
748 return ParseLambdaExpressionAfterIntroducer(Intro);
752 LambdaIntroducerTentativeParse *Tentative) {
754 *Tentative = LambdaIntroducerTentativeParse::Success;
756 assert(Tok.is(tok::l_square) &&
"Lambda expressions begin with '['.");
766 auto Result = [&](llvm::function_ref<void()> Action,
767 LambdaIntroducerTentativeParse State =
768 LambdaIntroducerTentativeParse::Invalid) {
779 auto NonTentativeAction = [&](llvm::function_ref<void()> Action) {
781 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
787 if (Tok.is(tok::amp) &&
792 if (!Tok.getIdentifierInfo()) {
797 }
else if (Tok.is(tok::equal)) {
804 while (Tok.isNot(tok::r_square)) {
806 if (Tok.isNot(tok::comma)) {
811 if (Tok.is(tok::code_completion) &&
814 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
821 Diag(Tok.getLocation(), diag::err_expected_comma_or_rsquare);
827 if (Tok.is(tok::code_completion)) {
832 Actions.CodeCompletion().CodeCompleteObjCMessageReceiver(
getCurScope());
834 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
846 IdentifierInfo *Id =
nullptr;
847 SourceLocation EllipsisLocs[4];
849 SourceLocation LocStart = Tok.getLocation();
851 if (Tok.is(tok::star)) {
853 if (Tok.is(tok::kw_this)) {
858 Diag(Tok.getLocation(), diag::err_expected_star_this_capture);
861 }
else if (Tok.is(tok::kw_this)) {
864 }
else if (Tok.isOneOf(tok::amp, tok::equal) &&
872 [&] {
Diag(Tok.getLocation(), diag::err_capture_default_first); },
873 LambdaIntroducerTentativeParse::Incomplete);
877 if (Tok.is(tok::amp)) {
881 if (Tok.is(tok::code_completion)) {
883 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
892 if (Tok.is(tok::identifier)) {
893 Id = Tok.getIdentifierInfo();
895 }
else if (Tok.is(tok::kw_this)) {
898 Diag(Tok.getLocation(), diag::err_this_captured_by_reference);
902 [&] {
Diag(Tok.getLocation(), diag::err_expected_capture); });
907 if (Tok.is(tok::l_paren)) {
916 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
917 }
else if (ParseExpressionList(Exprs)) {
922 Init = Actions.ActOnParenListExpr(
Parens.getOpenLocation(),
923 Parens.getCloseLocation(),
926 }
else if (Tok.isOneOf(tok::l_brace, tok::equal)) {
930 EnterExpressionEvaluationContext EC(
939 Init = ParseInitializer();
940 }
else if (Tok.is(tok::l_brace)) {
944 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
966 SourceLocation StartLoc = Tok.getLocation();
968 Init = ParseInitializer();
970 if (Tok.getLocation() != StartLoc) {
972 PP.RevertCachedTokens(1);
975 Tok.setLocation(StartLoc);
976 Tok.setKind(tok::annot_primary_expr);
977 setExprAnnotation(Tok,
Init);
978 Tok.setAnnotationEndLoc(PP.getLastCachedTokenLocation());
979 PP.AnnotateCachedTokens(Tok);
982 ConsumeAnnotationToken();
991 if (Tentative && Tok.is(tok::identifier) &&
994 *Tentative = LambdaIntroducerTentativeParse::MessageSend;
999 SourceLocation EllipsisLoc;
1000 if (llvm::any_of(EllipsisLocs,
1001 [](SourceLocation Loc) {
return Loc.
isValid(); })) {
1005 SourceLocation *ExpectedEllipsisLoc =
1006 !InitCapture ? &EllipsisLocs[2] :
1009 EllipsisLoc = *ExpectedEllipsisLoc;
1011 unsigned DiagID = 0;
1013 DiagID = diag::err_lambda_capture_misplaced_ellipsis;
1014 for (SourceLocation Loc : EllipsisLocs) {
1019 unsigned NumEllipses = std::accumulate(
1020 std::begin(EllipsisLocs), std::end(EllipsisLocs), 0,
1021 [](
int N, SourceLocation Loc) {
return N + Loc.
isValid(); });
1022 if (NumEllipses > 1)
1023 DiagID = diag::err_lambda_capture_multiple_ellipses;
1026 NonTentativeAction([&] {
1028 SourceLocation DiagLoc;
1029 for (SourceLocation &Loc : EllipsisLocs) {
1030 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid()) {
1035 assert(DiagLoc.
isValid() &&
"no location for diagnostic");
1039 auto &&D =
Diag(DiagLoc, DiagID);
1040 if (DiagID == diag::err_lambda_capture_misplaced_ellipsis) {
1041 SourceLocation ExpectedLoc =
1047 for (SourceLocation &Loc : EllipsisLocs) {
1048 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid())
1060 if (
Init.isUsable()) {
1061 NonTentativeAction([&] {
1064 Expr *InitExpr =
Init.get();
1067 InitCaptureType = Actions.actOnLambdaInitCaptureInitialization(
1068 Loc, Kind ==
LCK_ByRef, EllipsisLoc, Id, InitKind, InitExpr);
1073 SourceLocation LocEnd = PrevTokLocation;
1076 InitCaptureType, SourceRange(LocStart, LocEnd));
1098 auto ConsumeLocation = [&P, &DeclEndLoc](
SourceLocation &SpecifierLoc,
1100 if (SpecifierLoc.isValid()) {
1102 diag::err_lambda_decl_specifier_repeated)
1107 DeclEndLoc = SpecifierLoc;
1112 case tok::kw_mutable:
1113 ConsumeLocation(MutableLoc, 0);
1115 case tok::kw_static:
1116 ConsumeLocation(StaticLoc, 1);
1118 case tok::kw_constexpr:
1119 ConsumeLocation(ConstexprLoc, 2);
1121 case tok::kw_consteval:
1122 ConsumeLocation(ConstevalLoc, 3);
1134 ? diag::err_static_lambda
1135 : diag::warn_cxx20_compat_static_lambda);
1136 const char *PrevSpec =
nullptr;
1137 unsigned DiagID = 0;
1141 assert(PrevSpec ==
nullptr && DiagID == 0 &&
1142 "Static cannot have been set previously!");
1151 ? diag::ext_constexpr_on_lambda_cxx17
1152 : diag::warn_cxx14_compat_constexpr_on_lambda);
1153 const char *PrevSpec =
nullptr;
1154 unsigned DiagID = 0;
1157 assert(PrevSpec ==
nullptr && DiagID == 0 &&
1158 "Constexpr cannot have been set previously!");
1166 P.
Diag(ConstevalLoc, diag::warn_cxx20_compat_consteval);
1167 const char *PrevSpec =
nullptr;
1168 unsigned DiagID = 0;
1172 P.
Diag(ConstevalLoc, DiagID) << PrevSpec;
1188 P.
Diag(StaticLoc, diag::err_static_mutable_lambda);
1190 P.
Diag(StaticLoc, diag::err_static_lambda_captures);
1194ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
1198 Diag(LambdaBeginLoc, diag::ext_hlsl_lambda) << 1;
1201 ? diag::warn_cxx98_compat_lambda
1205 PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), LambdaBeginLoc,
1206 "lambda expression parsing");
1209 DeclSpec DS(AttrFactory);
1211 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1217 Actions.PushLambdaScope();
1218 SourceLocation DeclLoc = Tok.getLocation();
1220 Actions.ActOnLambdaExpressionAfterIntroducer(Intro,
getCurScope());
1222 ParsedAttributes Attributes(AttrFactory);
1230 if (Tok.is(tok::kw___noinline__)) {
1231 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1233 Attributes.addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
1235 0, tok::kw___noinline__);
1236 }
else if (Tok.is(tok::kw___attribute))
1237 ParseGNUAttributes(Attributes,
nullptr, &D);
1242 D.takeAttributesAppending(Attributes);
1246 if (Tok.is(tok::less)) {
1248 ? diag::warn_cxx17_compat_lambda_template_parameter_list
1249 : diag::ext_lambda_template_parameter_list);
1251 SmallVector<NamedDecl*, 4> TemplateParams;
1252 SourceLocation LAngleLoc, RAngleLoc;
1253 if (ParseTemplateParameters(TemplateParamScope,
1254 CurTemplateDepthTracker.getDepth(),
1255 TemplateParams, LAngleLoc, RAngleLoc)) {
1256 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1260 if (TemplateParams.empty()) {
1262 diag::err_lambda_template_parameter_list_empty);
1273 ++CurTemplateDepthTracker;
1283 Actions.ActOnLambdaExplicitTemplateParameterList(
1284 Intro, LAngleLoc, TemplateParams, RAngleLoc, RequiresClause);
1292 if (isCXX11AttributeSpecifier() !=
1295 ? diag::warn_cxx20_compat_decl_attrs_on_lambda
1296 : diag::ext_decl_attrs_on_lambda)
1297 << Tok.isRegularKeywordAttribute() << Tok.getIdentifierInfo();
1298 MaybeParseCXX11Attributes(D);
1302 SourceLocation TrailingReturnTypeLoc;
1303 SourceLocation LParenLoc, RParenLoc;
1304 SourceLocation DeclEndLoc = DeclLoc;
1305 bool HasParentheses =
false;
1306 bool HasSpecifiers =
false;
1307 SourceLocation MutableLoc;
1314 SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
1315 SourceLocation EllipsisLoc;
1317 if (Tok.is(tok::l_paren)) {
1320 LParenLoc = T.getOpenLocation();
1322 if (Tok.isNot(tok::r_paren)) {
1323 Actions.RecordParsingTemplateParameterDepth(
1324 CurTemplateDepthTracker.getOriginalDepth());
1326 ParseParameterDeclarationClause(D, Attributes, ParamInfo, EllipsisLoc);
1332 if (Actions.getCurGenericLambda())
1333 CurTemplateDepthTracker.setAddedDepth(1);
1337 DeclEndLoc = RParenLoc = T.getCloseLocation();
1338 HasParentheses =
true;
1342 Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
1343 tok::kw_constexpr, tok::kw_consteval, tok::kw_static,
1344 tok::kw___private, tok::kw___global, tok::kw___local,
1345 tok::kw___constant, tok::kw___generic, tok::kw_groupshared,
1346 tok::kw_requires, tok::kw_noexcept) ||
1347 Tok.isRegularKeywordAttribute() ||
1348 (Tok.is(tok::l_square) &&
NextToken().
is(tok::l_square));
1354 Diag(Tok, diag::ext_lambda_missing_parens)
1358 if (HasParentheses || HasSpecifiers) {
1362 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec, Attributes);
1365 SourceLocation ConstexprLoc;
1366 SourceLocation ConstevalLoc;
1367 SourceLocation StaticLoc;
1370 ConstevalLoc, DeclEndLoc);
1379 Actions.ActOnLambdaClosureParameters(
getCurScope(), ParamInfo);
1381 if (!HasParentheses)
1382 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1384 if (HasSpecifiers || HasParentheses) {
1387 SourceRange ESpecRange;
1388 SmallVector<ParsedType, 2> DynamicExceptions;
1389 SmallVector<SourceRange, 2> DynamicExceptionRanges;
1393 ESpecType = tryParseExceptionSpecification(
1394 false, ESpecRange, DynamicExceptions,
1395 DynamicExceptionRanges, NoexceptExpr, ExceptionSpecTokens);
1398 DeclEndLoc = ESpecRange.
getEnd();
1401 if (MaybeParseCXX11Attributes(Attributes))
1402 DeclEndLoc = Attributes.Range.getEnd();
1405 if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
1406 tok::kw___constant, tok::kw___generic)) {
1407 ParseOpenCLQualifiers(DS.getAttributes());
1414 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1416 SourceLocation FunLocalRangeEnd = DeclEndLoc;
1419 if (Tok.is(tok::arrow)) {
1420 FunLocalRangeEnd = Tok.getLocation();
1422 TrailingReturnType =
1423 ParseTrailingReturnType(Range,
false);
1424 TrailingReturnTypeLoc =
Range.getBegin();
1425 if (
Range.getEnd().isValid())
1426 DeclEndLoc =
Range.getEnd();
1429 SourceLocation NoLoc;
1432 false, LParenLoc, ParamInfo.data(),
1433 ParamInfo.size(), EllipsisLoc, RParenLoc,
1435 NoLoc, MutableLoc, ESpecType,
1436 ESpecRange, DynamicExceptions.data(),
1437 DynamicExceptionRanges.data(), DynamicExceptions.size(),
1438 NoexceptExpr.
isUsable() ? NoexceptExpr.
get() :
nullptr,
1440 {}, LParenLoc, FunLocalRangeEnd, D,
1441 TrailingReturnType, TrailingReturnTypeLoc, &DS),
1442 std::move(Attributes), DeclEndLoc);
1444 if (HasParentheses && Tok.is(tok::kw_requires))
1445 ParseTrailingRequiresClause(D);
1451 for (
const ParsedAttr &A : Attributes)
1452 if (A.getKind() == ParsedAttr::AT_CUDADevice ||
1453 A.getKind() == ParsedAttr::AT_CUDAHost ||
1454 A.getKind() == ParsedAttr::AT_CUDAGlobal)
1455 Diag(A.getLoc(), diag::warn_cuda_attr_lambda_position)
1456 << A.getAttrName()->getName();
1467 Actions.ActOnStartOfLambdaDefinition(Intro, D, DS);
1470 if (!Tok.is(tok::l_brace)) {
1471 Diag(Tok, diag::err_expected_lambda_body);
1472 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1476 StmtResult Stmt(ParseCompoundStatementBody());
1478 TemplateParamScope.Exit();
1481 if (!Stmt.isInvalid() && !TrailingReturnType.
isInvalid() &&
1483 return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.get());
1485 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1491 const char *CastName =
nullptr;
1494 default: llvm_unreachable(
"Unknown C++ cast!");
1495 case tok::kw_addrspace_cast: CastName =
"addrspace_cast";
break;
1496 case tok::kw_const_cast: CastName =
"const_cast";
break;
1497 case tok::kw_dynamic_cast: CastName =
"dynamic_cast";
break;
1498 case tok::kw_reinterpret_cast: CastName =
"reinterpret_cast";
break;
1499 case tok::kw_static_cast: CastName =
"static_cast";
break;
1503 SourceLocation LAngleBracketLoc = Tok.getLocation();
1507 if (Tok.is(tok::l_square) && Tok.getLength() == 2) {
1509 if (
Next.is(tok::colon) && areTokensAdjacent(Tok,
Next))
1513 if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName))
1517 DeclSpec DS(AttrFactory);
1518 ParseSpecifierQualifierList(DS,
AS_none,
1519 DeclSpecContext::DSC_type_specifier);
1524 ParseDeclarator(DeclaratorInfo);
1526 SourceLocation RAngleBracketLoc = Tok.getLocation();
1528 if (ExpectAndConsume(tok::greater))
1529 return ExprError(
Diag(LAngleBracketLoc, diag::note_matching) << tok::less);
1533 if (T.expectAndConsume(diag::err_expected_lparen_after, CastName))
1541 if (!
Result.isInvalid() && !DeclaratorInfo.isInvalidType())
1542 Result = Actions.ActOnCXXNamedCast(OpLoc, Kind,
1543 LAngleBracketLoc, DeclaratorInfo,
1545 T.getOpenLocation(),
Result.get(),
1546 T.getCloseLocation());
1552 assert(Tok.is(tok::kw_typeid) &&
"Not 'typeid'!");
1555 SourceLocation LParenLoc, RParenLoc;
1559 if (T.expectAndConsume(diag::err_expected_lparen_after,
"typeid"))
1561 LParenLoc = T.getOpenLocation();
1582 if (isTypeIdInParens()) {
1587 RParenLoc = T.getCloseLocation();
1591 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
true,
1601 RParenLoc = T.getCloseLocation();
1605 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
false,
1606 Result.get(), RParenLoc);
1614 assert(Tok.is(tok::kw___uuidof) &&
"Not '__uuidof'!");
1620 if (T.expectAndConsume(diag::err_expected_lparen_after,
"__uuidof"))
1625 if (isTypeIdInParens()) {
1634 Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(),
true,
1636 T.getCloseLocation());
1648 Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(),
1650 Result.get(), T.getCloseLocation());
1665 SourceLocation CCLoc;
1666 if (Tok.is(tok::identifier)) {
1667 FirstTypeName.
setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
1669 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1671 }
else if (Tok.is(tok::annot_template_id)) {
1672 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
1677 ConsumeAnnotationToken();
1678 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1681 assert(SS.
isEmpty() &&
"missing last component of nested name specifier");
1686 assert(Tok.is(tok::tilde) &&
"ParseOptionalCXXScopeSpecifier fail");
1689 if (Tok.is(tok::kw_decltype) && !FirstTypeName.
isValid()) {
1690 DeclSpec DS(AttrFactory);
1691 ParseDecltypeSpecifier(DS);
1694 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1698 if (!Tok.is(tok::identifier)) {
1699 Diag(Tok, diag::err_destructor_tilde_identifier);
1706 DeclSpec DS(AttrFactory);
1707 ParsePackIndexingType(DS);
1708 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1714 IdentifierInfo *Name = Tok.getIdentifierInfo();
1726 if (Tok.is(tok::less) &&
1727 ParseUnqualifiedIdTemplateId(
1728 SS, ObjectType, Base &&
Base->containsErrors(), SourceLocation(),
1729 Name, NameLoc,
false, SecondTypeName,
1733 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1734 SS, FirstTypeName, CCLoc, TildeLoc,
1740 return Actions.ActOnCXXBoolLiteral(
ConsumeToken(), Kind);
1744 assert(Tok.is(tok::kw_throw) &&
"Not throw!");
1750 switch (Tok.getKind()) {
1757 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc,
nullptr);
1761 if (Expr.isInvalid())
return Expr;
1762 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc, Expr.get());
1767 assert(Tok.is(tok::kw_co_yield) &&
"Not co_yield!");
1770 ExprResult Expr = Tok.is(tok::l_brace) ? ParseBraceInitializer()
1778 assert(Tok.is(tok::kw_this) &&
"Not 'this'!");
1780 return Actions.ActOnCXXThis(ThisLoc);
1784Parser::ParseCXXTypeConstructExpression(
const DeclSpec &DS) {
1787 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
1789 assert((Tok.is(tok::l_paren) ||
1791 &&
"Expected '(' or '{'!");
1793 if (Tok.is(tok::l_brace)) {
1794 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1796 if (
Init.isInvalid())
1799 return Actions.ActOnCXXTypeConstructExpr(
1806 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1810 auto RunSignatureHelp = [&]() {
1811 QualType PreferredType;
1814 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
1816 Exprs, T.getOpenLocation(),
false);
1817 CalledSignatureHelp =
true;
1818 return PreferredType;
1821 if (Tok.isNot(tok::r_paren)) {
1822 if (ParseExpressionList(Exprs, [&] {
1823 PreferredType.enterFunctionArgument(Tok.getLocation(),
1826 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
1840 return Actions.ActOnCXXTypeConstructExpr(TypeRep, T.getOpenLocation(),
1841 Exprs, T.getCloseLocation(),
1849 assert(Tok.is(tok::kw_using) &&
"Expected using");
1852 "Unexpected Declarator Context");
1856 DG = ParseUsingDeclaration(Context, {}, DeclStart, DeclEnd, Attrs,
AS_none);
1861 ? diag::ext_alias_in_init_statement
1862 : diag::warn_cxx20_alias_in_init_statement)
1863 << SourceRange(DeclStart, DeclEnd);
1871 ForRangeInfo *FRI,
bool EnterForConditionScope) {
1873 struct ForConditionScopeRAII {
1875 void enter(
bool IsConditionVariable) {
1881 ~ForConditionScopeRAII() {
1888 PreferredType.enterCondition(Actions, Tok.getLocation());
1890 if (Tok.is(tok::code_completion)) {
1892 Actions.CodeCompletion().CodeCompleteOrdinaryName(
1897 ParsedAttributes attrs(AttrFactory);
1898 MaybeParseCXX11Attributes(attrs);
1900 const auto WarnOnInit = [
this, &CK] {
1902 ? diag::warn_cxx14_compat_init_statement
1903 : diag::ext_init_statement)
1908 switch (isCXXConditionDeclarationOrInitStatement(InitStmt, FRI)) {
1909 case ConditionOrInitStatement::Expression: {
1911 ForConditionScope.enter(
false);
1913 ProhibitAttributes(attrs);
1917 if (InitStmt && Tok.is(tok::semi)) {
1919 SourceLocation SemiLoc = Tok.getLocation();
1920 if (!Tok.hasLeadingEmptyMacro() && !SemiLoc.
isMacroID()) {
1921 Diag(SemiLoc, diag::warn_empty_init_statement)
1926 *InitStmt = Actions.ActOnNullStmt(SemiLoc);
1927 return ParseCXXCondition(
nullptr, Loc, CK, MissingOK);
1930 EnterExpressionEvaluationContext Eval(
1941 if (InitStmt && Tok.is(tok::semi)) {
1943 *InitStmt = Actions.ActOnExprStmt(Expr.
get());
1945 return ParseCXXCondition(
nullptr, Loc, CK, MissingOK);
1948 return Actions.ActOnCondition(
getCurScope(), Loc, Expr.
get(), CK,
1952 case ConditionOrInitStatement::InitStmtDecl: {
1955 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
1956 if (Tok.is(tok::kw_using))
1957 DG = ParseAliasDeclarationInInitStatement(
1960 ParsedAttributes DeclSpecAttrs(AttrFactory);
1962 attrs, DeclSpecAttrs,
true);
1964 *InitStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd);
1965 return ParseCXXCondition(
nullptr, Loc, CK, MissingOK);
1968 case ConditionOrInitStatement::ForRangeDecl: {
1972 assert(FRI &&
"should not parse a for range declaration here");
1973 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
1974 ParsedAttributes DeclSpecAttrs(AttrFactory);
1977 FRI->LoopVar = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
1978 return Sema::ConditionResult();
1981 case ConditionOrInitStatement::ConditionDecl:
1982 case ConditionOrInitStatement::Error:
1987 ForConditionScope.enter(
true);
1990 DeclSpec DS(AttrFactory);
1991 ParseSpecifierQualifierList(DS,
AS_none, DeclSpecContext::DSC_condition);
1995 ParseDeclarator(DeclaratorInfo);
1998 if (Tok.is(tok::kw_asm)) {
2000 ExprResult AsmLabel(ParseSimpleAsm(
true, &Loc));
2001 if (AsmLabel.isInvalid()) {
2005 DeclaratorInfo.setAsmLabel(AsmLabel.get());
2006 DeclaratorInfo.SetRangeEnd(Loc);
2010 MaybeParseGNUAttributes(DeclaratorInfo);
2021 bool CopyInitialization = isTokenEqualOrEqualTypo();
2022 if (CopyInitialization)
2027 Diag(Tok.getLocation(),
2028 diag::warn_cxx98_compat_generalized_initializer_lists);
2029 InitExpr = ParseBraceInitializer();
2030 }
else if (CopyInitialization) {
2031 PreferredType.enterVariableInit(Tok.getLocation(), DeclOut);
2033 }
else if (Tok.is(tok::l_paren)) {
2035 SourceLocation LParen = ConsumeParen(), RParen = LParen;
2037 RParen = ConsumeParen();
2039 diag::err_expected_init_in_condition_lparen)
2040 << SourceRange(LParen, RParen);
2046 Actions.AddInitializerToDecl(DeclOut, InitExpr.
get(), !CopyInitialization);
2048 Actions.ActOnInitializerError(DeclOut);
2050 Actions.FinalizeDeclaration(DeclOut);
2051 return Actions.ActOnConditionVariable(DeclOut, Loc, CK);
2054void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) {
2056 const char *PrevSpec;
2058 SourceLocation Loc = Tok.getLocation();
2059 const clang::PrintingPolicy &Policy =
2060 Actions.getASTContext().getPrintingPolicy();
2062 switch (Tok.getKind()) {
2063 case tok::identifier:
2064 case tok::coloncolon:
2065 llvm_unreachable(
"Annotation token should already be formed!");
2067 llvm_unreachable(
"Not a simple-type-specifier token!");
2070 case tok::annot_typename: {
2074 ConsumeAnnotationToken();
2075 DS.
Finish(Actions, Policy);
2079 case tok::kw__ExtInt:
2080 case tok::kw__BitInt: {
2081 DiagnoseBitIntUse(Tok);
2090 DS.
Finish(Actions, Policy);
2103 case tok::kw___int64:
2107 case tok::kw_signed:
2110 case tok::kw_unsigned:
2125 case tok::kw___int128:
2128 case tok::kw___bf16:
2137 case tok::kw_double:
2140 case tok::kw__Float16:
2143 case tok::kw___float128:
2146 case tok::kw___ibm128:
2149 case tok::kw_wchar_t:
2152 case tok::kw_char8_t:
2155 case tok::kw_char16_t:
2158 case tok::kw_char32_t:
2164 case tok::kw__Accum:
2167 case tok::kw__Fract:
2173#define GENERIC_IMAGE_TYPE(ImgType, Id) \
2174 case tok::kw_##ImgType##_t: \
2175 DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, DiagID, \
2178#include "clang/Basic/OpenCLImageTypes.def"
2179#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
2180 case tok::kw_##Name: \
2181 DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, DiagID, Policy); \
2183#include "clang/Basic/HLSLIntangibleTypes.def"
2185 case tok::annot_decltype:
2186 case tok::kw_decltype:
2188 return DS.
Finish(Actions, Policy);
2190 case tok::annot_pack_indexing_type:
2192 return DS.
Finish(Actions, Policy);
2195 case tok::kw_typeof:
2196 ParseTypeofSpecifier(DS);
2197 DS.
Finish(Actions, Policy);
2202 DS.
Finish(Actions, Policy);
2206 ParseSpecifierQualifierList(DS,
AS_none,
2207 getDeclSpecContextFromDeclaratorContext(Context));
2208 DS.
Finish(Actions, Actions.getASTContext().getPrintingPolicy());
2212bool Parser::ParseUnqualifiedIdTemplateId(
2213 CXXScopeSpec &SS,
ParsedType ObjectType,
bool ObjectHadErrors,
2214 SourceLocation TemplateKWLoc, IdentifierInfo *Name, SourceLocation NameLoc,
2215 bool EnteringContext, UnqualifiedId &Id,
bool AssumeTemplateId) {
2216 assert(Tok.is(tok::less) &&
"Expected '<' to finish parsing a template-id");
2224 if (AssumeTemplateId) {
2227 TNK = Actions.ActOnTemplateName(
getCurScope(), SS, TemplateKWLoc, Id,
2228 ObjectType, EnteringContext,
Template,
2231 bool MemberOfUnknownSpecialization;
2234 ObjectType, EnteringContext,
Template,
2235 MemberOfUnknownSpecialization);
2240 isTemplateArgumentList(0) == TPResult::False)
2244 ObjectType && isTemplateArgumentList(0) == TPResult::True) {
2247 if (!ObjectHadErrors) {
2266 TNK = Actions.ActOnTemplateName(
2267 getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext,
2277 bool MemberOfUnknownSpecialization;
2282 MemberOfUnknownSpecialization);
2290 bool MemberOfUnknownSpecialization;
2293 TNK = Actions.ActOnTemplateName(
2300 MemberOfUnknownSpecialization);
2303 Diag(NameLoc, diag::err_destructor_template_id)
2316 SourceLocation LAngleLoc, RAngleLoc;
2317 TemplateArgList TemplateArgs;
2318 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs, RAngleLoc,
2333 const IdentifierInfo *TemplateII =
2343 LAngleLoc, RAngleLoc, TemplateArgs,
false, TemplateIds);
2355 SourceLocation(), SS, TemplateKWLoc,
Template,
2356 Name, NameLoc, LAngleLoc, TemplateArgsPtr, RAngleLoc,
2358 if (
Type.isInvalid())
2369bool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
2372 assert(Tok.is(tok::kw_operator) &&
"Expected 'operator' keyword");
2378 unsigned SymbolIdx = 0;
2379 SourceLocation SymbolLocations[3];
2381 switch (Tok.getKind()) {
2383 case tok::kw_delete: {
2384 bool isNew = Tok.getKind() == tok::kw_new;
2388 if (Tok.is(tok::l_square) &&
2394 if (T.getCloseLocation().isInvalid())
2397 SymbolLocations[SymbolIdx++] = T.getOpenLocation();
2398 SymbolLocations[SymbolIdx++] = T.getCloseLocation();
2399 Op = isNew? OO_Array_New : OO_Array_Delete;
2401 Op = isNew? OO_New : OO_Delete;
2406#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
2408 SymbolLocations[SymbolIdx++] = ConsumeToken(); \
2411#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
2412#include "clang/Basic/OperatorKinds.def"
2414 case tok::l_paren: {
2419 if (T.getCloseLocation().isInvalid())
2422 SymbolLocations[SymbolIdx++] = T.getOpenLocation();
2423 SymbolLocations[SymbolIdx++] = T.getCloseLocation();
2428 case tok::l_square: {
2433 if (T.getCloseLocation().isInvalid())
2436 SymbolLocations[SymbolIdx++] = T.getOpenLocation();
2437 SymbolLocations[SymbolIdx++] = T.getCloseLocation();
2442 case tok::code_completion: {
2446 Actions.CodeCompletion().CodeCompleteOperatorName(
getCurScope());
2456 Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations);
2467 Diag(Tok.getLocation(), diag::warn_cxx98_compat_literal_operator);
2469 SourceLocation DiagLoc;
2470 unsigned DiagId = 0;
2474 SmallVector<Token, 4> Toks;
2475 SmallVector<SourceLocation, 4> TokLocs;
2476 while (isTokenStringLiteral()) {
2477 if (!Tok.is(tok::string_literal) && !DiagId) {
2481 DiagLoc = Tok.getLocation();
2482 DiagId = diag::err_literal_operator_string_prefix;
2484 Toks.push_back(Tok);
2485 TokLocs.push_back(ConsumeStringToken());
2488 StringLiteralParser
Literal(Toks, PP);
2494 bool IsUDSuffix = !
Literal.getUDSuffix().empty();
2495 IdentifierInfo *II =
nullptr;
2496 SourceLocation SuffixLoc;
2498 II = &PP.getIdentifierTable().get(
Literal.getUDSuffix());
2503 }
else if (Tok.is(tok::identifier)) {
2504 II = Tok.getIdentifierInfo();
2506 TokLocs.push_back(SuffixLoc);
2508 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
2518 DiagLoc = TokLocs.front();
2519 DiagId = diag::err_literal_operator_string_not_empty;
2525 SmallString<32> Str;
2529 SourceRange(TokLocs.front(), TokLocs.back()), Str);
2532 Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
2534 return Actions.checkLiteralOperatorId(SS,
Result, IsUDSuffix);
2549 DeclSpec DS(AttrFactory);
2550 if (ParseCXXTypeSpecifierSeq(
2558 ParseDeclaratorInternal(D,
nullptr);
2566 Result.setConversionFunctionId(KeywordLoc, Ty.
get(),
2567 D.getSourceRange().getEnd());
2572 bool ObjectHadErrors,
bool EnteringContext,
2573 bool AllowDestructorName,
2574 bool AllowConstructorName,
2575 bool AllowDeductionGuide,
2583 bool TemplateSpecified =
false;
2584 if (Tok.is(tok::kw_template)) {
2585 if (TemplateKWLoc && (ObjectType || SS.
isSet())) {
2586 TemplateSpecified =
true;
2590 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2598 if (Tok.is(tok::identifier)) {
2607 Result.setIdentifier(Id, IdLoc);
2612 if (AllowConstructorName &&
2613 Actions.isCurrentClassName(*Id,
getCurScope(), &SS)) {
2619 Result.setConstructorName(Ty, IdLoc, IdLoc);
2622 Actions.isDeductionGuideName(
getCurScope(), *Id, IdLoc, SS,
2628 Result.setIdentifier(Id, IdLoc);
2633 if (Tok.is(tok::less))
2634 return ParseUnqualifiedIdTemplateId(
2635 SS, ObjectType, ObjectHadErrors,
2637 EnteringContext,
Result, TemplateSpecified);
2639 if (TemplateSpecified) {
2642 ObjectType, EnteringContext,
Template,
2653 Diag(IdLoc, diag::missing_template_arg_list_after_template_kw);
2660 if (Tok.is(tok::annot_template_id)) {
2666 ConsumeAnnotationToken();
2671 if (AllowConstructorName && TemplateId->
Name &&
2679 diag::err_out_of_line_constructor_template_id)
2690 ConsumeAnnotationToken();
2694 Result.setConstructorTemplateId(TemplateId);
2695 ConsumeAnnotationToken();
2701 Result.setTemplateId(TemplateId);
2704 if (TemplateKWLoc && (ObjectType || SS.
isSet()))
2705 *TemplateKWLoc = TemplateLoc;
2707 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2710 ConsumeAnnotationToken();
2717 if (Tok.is(tok::kw_operator)) {
2718 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
Result))
2730 return ParseUnqualifiedIdTemplateId(
2731 SS, ObjectType, ObjectHadErrors,
2734 else if (TemplateSpecified &&
2735 Actions.ActOnTemplateName(
2745 (AllowDestructorName || SS.
isSet()) && Tok.is(tok::tilde)) {
2754 if (TemplateSpecified) {
2765 Diag(*TemplateKWLoc, diag::err_unexpected_template_in_destructor_name)
2766 << Tok.getLocation();
2770 if (SS.
isEmpty() && Tok.is(tok::kw_decltype)) {
2774 Actions.getDestructorTypeForDecltype(DS, ObjectType)) {
2775 Result.setDestructorName(TildeLoc,
Type, EndLoc);
2782 if (Tok.isNot(tok::identifier)) {
2783 Diag(Tok, diag::err_destructor_tilde_identifier);
2788 DeclaratorScopeObj DeclScopeObj(*
this, SS);
2796 AnnotateScopeToken(SS,
true);
2799 if (ParseOptionalCXXScopeSpecifier(SS, ObjectType, ObjectHadErrors,
2803 ObjectType =
nullptr;
2804 if (Tok.isNot(tok::identifier) ||
NextToken().
is(tok::coloncolon) ||
2806 Diag(TildeLoc, diag::err_destructor_tilde_scope);
2811 Diag(TildeLoc, diag::err_destructor_tilde_scope)
2816 if (Actions.ShouldEnterDeclaratorScope(
getCurScope(), SS))
2817 DeclScopeObj.EnterDeclaratorScope();
2824 if (Tok.is(tok::less)) {
2825 Result.setDestructorName(TildeLoc,
nullptr, ClassNameLoc);
2826 return ParseUnqualifiedIdTemplateId(
2827 SS, ObjectType, ObjectHadErrors,
2829 ClassNameLoc, EnteringContext,
Result, TemplateSpecified);
2834 Actions.getDestructorName(*ClassName, ClassNameLoc,
getCurScope(), SS,
2835 ObjectType, EnteringContext);
2839 Result.setDestructorName(TildeLoc, Ty, ClassNameLoc);
2843 switch (Tok.getKind()) {
2844#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
2845#include "clang/Basic/TransformTypeTraits.def"
2847 Tok.setKind(tok::identifier);
2848 Diag(Tok, diag::ext_keyword_as_ident)
2849 << Tok.getIdentifierInfo()->getName() << 0;
2850 goto ParseIdentifier;
2854 Diag(Tok, diag::err_expected_unqualified_id) <<
getLangOpts().CPlusPlus;
2860Parser::ParseCXXNewExpression(
bool UseGlobal,
SourceLocation Start) {
2861 assert(
Tok.is(tok::kw_new) &&
"expected 'new' token");
2867 ExprVector PlacementArgs;
2874 if (
Tok.is(tok::l_paren)) {
2878 PlacementLParen = T.getOpenLocation();
2879 if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) {
2885 PlacementRParen = T.getCloseLocation();
2891 if (PlacementArgs.empty()) {
2893 TypeIdParens = T.getRange();
2894 PlacementLParen = PlacementRParen = SourceLocation();
2897 if (Tok.is(tok::l_paren)) {
2900 MaybeParseGNUAttributes(DeclaratorInfo);
2901 ParseSpecifierQualifierList(DS);
2903 ParseDeclarator(DeclaratorInfo);
2905 TypeIdParens = T.getRange();
2907 MaybeParseGNUAttributes(DeclaratorInfo);
2908 if (ParseCXXTypeSpecifierSeq(DS))
2909 DeclaratorInfo.setInvalidType(
true);
2912 ParseDeclaratorInternal(DeclaratorInfo,
2913 &Parser::ParseDirectNewDeclarator);
2920 MaybeParseGNUAttributes(DeclaratorInfo);
2922 DeclaratorInfo.setInvalidType(
true);
2925 ParseDeclaratorInternal(DeclaratorInfo,
2926 &Parser::ParseDirectNewDeclarator);
2929 if (DeclaratorInfo.isInvalidType()) {
2936 if (Tok.is(tok::l_paren)) {
2937 SourceLocation ConstructorLParen, ConstructorRParen;
2938 ExprVector ConstructorArgs;
2941 ConstructorLParen = T.getOpenLocation();
2942 if (Tok.isNot(tok::r_paren)) {
2943 auto RunSignatureHelp = [&]() {
2944 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
2945 QualType PreferredType;
2951 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
2953 DeclaratorInfo.getEndLoc(), ConstructorArgs,
2956 CalledSignatureHelp =
true;
2957 return PreferredType;
2959 if (ParseExpressionList(ConstructorArgs, [&] {
2960 PreferredType.enterFunctionArgument(Tok.getLocation(),
2963 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
2970 ConstructorRParen = T.getCloseLocation();
2975 Initializer = Actions.ActOnParenListExpr(ConstructorLParen,
2979 Diag(Tok.getLocation(),
2980 diag::warn_cxx98_compat_generalized_initializer_lists);
2986 return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen,
2987 PlacementArgs, PlacementRParen,
2991void Parser::ParseDirectNewDeclarator(Declarator &D) {
2994 while (Tok.is(tok::l_square)) {
2996 if (CheckProhibitedCXX11Attribute())
3005 if (
Size.isInvalid()) {
3007 SkipUntil(tok::r_square, StopAtSemi);
3015 ParsedAttributes Attrs(AttrFactory);
3016 MaybeParseCXX11Attributes(Attrs);
3020 Size.get(), T.getOpenLocation(),
3021 T.getCloseLocation()),
3022 std::move(Attrs), T.getCloseLocation());
3024 if (T.getCloseLocation().isInvalid())
3029bool Parser::ParseExpressionListOrTypeId(
3030 SmallVectorImpl<Expr*> &PlacementArgs,
3033 if (isTypeIdInParens()) {
3041 return ParseExpressionList(PlacementArgs);
3045Parser::ParseCXXDeleteExpression(
bool UseGlobal, SourceLocation Start) {
3046 assert(Tok.is(tok::kw_delete) &&
"Expected 'delete' keyword");
3050 bool ArrayDelete =
false;
3051 if (Tok.is(tok::l_square) &&
NextToken().
is(tok::r_square)) {
3062 if (
Next.isOneOf(tok::l_brace, tok::less) ||
3063 (
Next.is(tok::l_paren) &&
3067 TentativeParsingAction TPA(*
this);
3068 SourceLocation LSquareLoc = Tok.getLocation();
3074 SourceLocation RBraceLoc;
3075 bool EmitFixIt =
false;
3076 if (Tok.is(tok::l_brace)) {
3079 RBraceLoc = Tok.getLocation();
3086 Diag(Start, diag::err_lambda_after_delete)
3087 << SourceRange(Start, RSquareLoc)
3091 RBraceLoc, 0, Actions.getSourceManager(),
getLangOpts()),
3094 Diag(Start, diag::err_lambda_after_delete)
3095 << SourceRange(Start, RSquareLoc);
3104 Lambda = ParsePostfixExpressionSuffix(Lambda);
3107 return Actions.ActOnCXXDelete(Start, UseGlobal,
false,
3116 if (T.getCloseLocation().isInvalid())
3124 return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete,
Operand.get());
3127ExprResult Parser::ParseRequiresExpression() {
3128 assert(Tok.is(tok::kw_requires) &&
"Expected 'requires' keyword");
3131 llvm::SmallVector<ParmVarDecl *, 2> LocalParameterDecls;
3133 if (Tok.is(tok::l_paren)) {
3138 if (!Tok.is(tok::r_paren)) {
3140 SourceLocation EllipsisLoc;
3141 llvm::SmallVector<DeclaratorChunk::ParamInfo, 2> LocalParameters;
3143 FirstArgAttrs, LocalParameters,
3146 Diag(EllipsisLoc, diag::err_requires_expr_parameter_list_ellipsis);
3147 for (
auto &ParamInfo : LocalParameters)
3154 if (
Braces.expectAndConsume())
3158 llvm::SmallVector<concepts::Requirement *, 2> Requirements;
3162 EnterExpressionEvaluationContext Ctx(
3170 RequiresExprBodyDecl *Body = Actions.ActOnStartRequiresExpr(
3171 RequiresKWLoc, LocalParameterDecls,
getCurScope());
3173 if (Tok.is(tok::r_brace)) {
3180 Diag(Tok, diag::err_empty_requires_expr);
3183 while (!Tok.is(tok::r_brace)) {
3184 switch (Tok.getKind()) {
3185 case tok::l_brace: {
3196 ExprBraces.consumeOpen();
3198 if (Expression.isUsable())
3199 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3200 if (!Expression.isUsable()) {
3201 ExprBraces.skipToEnd();
3207 if (ExprBraces.consumeClose())
3210 concepts::Requirement *Req =
nullptr;
3211 SourceLocation NoexceptLoc;
3213 if (Tok.is(tok::semi)) {
3214 Req = Actions.ActOnCompoundRequirement(Expression.get(), NoexceptLoc);
3216 Requirements.push_back(Req);
3221 Diag(Tok, diag::err_requires_expr_missing_arrow)
3224 if (TryAnnotateTypeConstraint()) {
3228 if (!isTypeConstraintAnnotation()) {
3229 Diag(Tok, diag::err_requires_expr_expected_type_constraint);
3234 if (Tok.is(tok::annot_cxxscope)) {
3235 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
3236 Tok.getAnnotationRange(),
3238 ConsumeAnnotationToken();
3241 Req = Actions.ActOnCompoundRequirement(
3242 Expression.get(), NoexceptLoc, SS, takeTemplateIdAnnotation(Tok),
3243 TemplateParameterDepth);
3244 ConsumeAnnotationToken();
3246 Requirements.push_back(Req);
3250 bool PossibleRequiresExprInSimpleRequirement =
false;
3251 if (Tok.is(tok::kw_requires)) {
3252 auto IsNestedRequirement = [&] {
3253 RevertingTentativeParsingAction TPA(*
this);
3255 if (Tok.is(tok::l_brace))
3262 if (Tok.is(tok::l_paren)) {
3265 auto Res = TryParseParameterDeclarationClause();
3266 if (Res != TPResult::False) {
3269 while (Depth != 0) {
3270 bool FoundParen =
SkipUntil(tok::l_paren, tok::r_paren,
3274 if (Tok.is(tok::l_paren))
3276 else if (Tok.is(tok::r_paren))
3287 if (Tok.is(tok::l_brace))
3296 if (IsNestedRequirement()) {
3309 Actions.ActOnNestedRequirement(ConstraintExpr.
get()))
3310 Requirements.push_back(Req);
3318 PossibleRequiresExprInSimpleRequirement =
true;
3319 }
else if (Tok.is(tok::kw_typename)) {
3322 TentativeParsingAction TPA(*
this);
3332 if (Tok.is(tok::annot_cxxscope)) {
3333 Actions.RestoreNestedNameSpecifierAnnotation(
3334 Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS);
3335 ConsumeAnnotationToken();
3338 if (Tok.isOneOf(tok::identifier, tok::annot_template_id) &&
3341 SourceLocation NameLoc = Tok.getLocation();
3342 IdentifierInfo *II =
nullptr;
3343 TemplateIdAnnotation *TemplateId =
nullptr;
3344 if (Tok.is(tok::identifier)) {
3345 II = Tok.getIdentifierInfo();
3348 TemplateId = takeTemplateIdAnnotation(Tok);
3349 ConsumeAnnotationToken();
3354 if (
auto *Req = Actions.ActOnTypeRequirement(TypenameKWLoc, SS,
3357 Requirements.push_back(Req);
3367 SourceLocation StartLoc = Tok.getLocation();
3369 if (Expression.isUsable())
3370 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3371 if (!Expression.isUsable()) {
3375 if (!Expression.isInvalid() && PossibleRequiresExprInSimpleRequirement)
3376 Diag(StartLoc, diag::err_requires_expr_in_simple_requirement)
3378 if (
auto *Req = Actions.ActOnSimpleRequirement(Expression.get()))
3379 Requirements.push_back(Req);
3385 if (Tok.is(tok::kw_noexcept)) {
3386 Diag(Tok, diag::err_requires_expr_simple_requirement_noexcept)
3395 if (ExpectAndConsumeSemi(diag::err_expected_semi_requirement)) {
3401 if (Requirements.empty()) {
3406 Actions.ActOnFinishRequiresExpr();
3411 Actions.ActOnFinishRequiresExpr();
3412 ParsingBodyDecl.complete(Body);
3413 return Actions.ActOnRequiresExpr(
3414 RequiresKWLoc, Body,
Parens.getOpenLocation(), LocalParameterDecls,
3415 Parens.getCloseLocation(), Requirements,
Braces.getCloseLocation());
3420 default: llvm_unreachable(
"Not a known type trait");
3421#define TYPE_TRAIT_1(Spelling, Name, Key) \
3422case tok::kw_ ## Spelling: return UTT_ ## Name;
3423#define TYPE_TRAIT_2(Spelling, Name, Key) \
3424case tok::kw_ ## Spelling: return BTT_ ## Name;
3425#include "clang/Basic/TokenKinds.def"
3426#define TYPE_TRAIT_N(Spelling, Name, Key) \
3427 case tok::kw_ ## Spelling: return TT_ ## Name;
3428#include "clang/Basic/TokenKinds.def"
3435 llvm_unreachable(
"Not a known array type trait");
3436#define ARRAY_TYPE_TRAIT(Spelling, Name, Key) \
3437 case tok::kw_##Spelling: \
3439#include "clang/Basic/TokenKinds.def"
3446 llvm_unreachable(
"Not a known unary expression trait.");
3447#define EXPRESSION_TRAIT(Spelling, Name, Key) \
3448 case tok::kw_##Spelling: \
3450#include "clang/Basic/TokenKinds.def"
3460 if (
Parens.expectAndConsume())
3463 SmallVector<ParsedType, 2> Args;
3476 if (Tok.is(tok::ellipsis)) {
3485 Args.push_back(Ty.
get());
3488 if (
Parens.consumeClose())
3491 SourceLocation EndLoc =
Parens.getCloseLocation();
3501 if (T.expectAndConsume())
3513 case ATT_ArrayRank: {
3515 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(),
nullptr,
3516 T.getCloseLocation());
3518 case ATT_ArrayExtent: {
3519 if (ExpectAndConsume(tok::comma)) {
3530 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(), DimExpr.
get(),
3531 T.getCloseLocation());
3534 llvm_unreachable(
"Invalid ArrayTypeTrait!");
3542 if (T.expectAndConsume())
3549 return Actions.ActOnExpressionTrait(ET, Loc, Expr.
get(),
3550 T.getCloseLocation());
3560 "Compound literals are not ambiguous!");
3561 assert(isTypeIdInParens() &&
"Not a type-id!");
3590 if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) {
3596 if (Tok.is(tok::l_brace)) {
3600 if (Tok.is(tok::l_paren) &&
NextToken().
is(tok::r_paren)) {
3608 false , NotCastExpr,
3621 AttrEnd.startToken();
3622 AttrEnd.setKind(tok::eof);
3623 AttrEnd.setLocation(Tok.getLocation());
3624 AttrEnd.setEofData(Toks.data());
3625 Toks.push_back(AttrEnd);
3628 Toks.push_back(Tok);
3631 PP.EnterTokenStream(Toks,
true,
3639 DeclSpec DS(AttrFactory);
3644 ParseSpecifierQualifierList(DS);
3645 ParseDeclarator(DeclaratorInfo);
3653 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3658 if (DeclaratorInfo.isInvalidType())
3661 TypeResult Ty = Actions.ActOnTypeName(DeclaratorInfo);
3662 return ParseCompoundLiteralExpression(Ty.
get(),
3670 if (DeclaratorInfo.isInvalidType())
3676 DeclaratorInfo, CastTy,
3686 if (!
Result.isInvalid() && Tok.is(tok::r_paren))
3688 Tok.getLocation(),
Result.get());
3691 if (
Result.isInvalid()) {
3692 while (Tok.isNot(tok::eof))
3694 assert(Tok.getEofData() == AttrEnd.getEofData());
3701 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3710 if (T.expectAndConsume(diag::err_expected_lparen_after,
"__builtin_bit_cast"))
3714 DeclSpec DS(AttrFactory);
3715 ParseSpecifierQualifierList(DS);
3720 ParseDeclarator(DeclaratorInfo);
3722 if (ExpectAndConsume(tok::comma)) {
3723 Diag(Tok.getLocation(), diag::err_expected) << tok::comma;
3730 if (T.consumeClose())
3733 if (
Operand.isInvalid() || DeclaratorInfo.isInvalidType())
3736 return Actions.ActOnBuiltinBitCastExpr(KWLoc, DeclaratorInfo, Operand,
3737 T.getCloseLocation());
Defines the clang::ASTContext interface.
This file defines the classes used to store parsed information about declaration-specifiers and decla...
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
static void addConstexprToLambdaDeclSpecifier(Parser &P, SourceLocation ConstexprLoc, DeclSpec &DS)
static void FixDigraph(Parser &P, Preprocessor &PP, Token &DigraphToken, Token &ColonToken, tok::TokenKind Kind, bool AtDigraph)
static ArrayTypeTrait ArrayTypeTraitFromTokKind(tok::TokenKind kind)
static void tryConsumeLambdaSpecifierToken(Parser &P, SourceLocation &MutableLoc, SourceLocation &StaticLoc, SourceLocation &ConstexprLoc, SourceLocation &ConstevalLoc, SourceLocation &DeclEndLoc)
static ExpressionTrait ExpressionTraitFromTokKind(tok::TokenKind kind)
static void addConstevalToLambdaDeclSpecifier(Parser &P, SourceLocation ConstevalLoc, DeclSpec &DS)
static TypeTrait TypeTraitFromTokKind(tok::TokenKind kind)
static void DiagnoseStaticSpecifierRestrictions(Parser &P, SourceLocation StaticLoc, SourceLocation MutableLoc, const LambdaIntroducer &Intro)
static int SelectDigraphErrorMessage(tok::TokenKind Kind)
static void addStaticToLambdaDeclSpecifier(Parser &P, SourceLocation StaticLoc, DeclSpec &DS)
Defines the PrettyStackTraceEntry class, which is used to make crashes give more contextual informati...
static constexpr bool isOneOf()
This file declares facilities that support code completion.
Defines the clang::TemplateNameKind enum.
Defines the clang::TokenKind enum and support functions.
const clang::PrintingPolicy & getPrintingPolicy() const
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ....
SourceLocation getOpenLocation() const
SourceLocation getCloseLocation() const
Represents a C++ nested-name-specifier or a global scope specifier.
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
SourceRange getRange() const
SourceLocation getBeginLoc() const
bool isSet() const
Deprecated.
void setEndLoc(SourceLocation Loc)
void SetInvalid(SourceRange R)
Indicate that this nested-name-specifier is invalid.
bool isEmpty() const
No scope specifier.
void restore()
restore - This can be used to restore the state early, before the dtor is run.
Captures information about "declaration specifiers".
static const TST TST_typename
SourceLocation getEndLoc() const LLVM_READONLY
bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec and return false if there was no error.
static const TST TST_char8
static const TST TST_BFloat16
bool SetConstexprSpec(ConstexprSpecKind ConstexprKind, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
bool SetTypeSpecWidth(TypeSpecifierWidth W, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec, but return true and ignore the request if ...
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
SourceRange getSourceRange() const LLVM_READONLY
void SetRangeEnd(SourceLocation Loc)
bool SetBitIntType(SourceLocation KWLoc, Expr *BitWidth, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
static const TST TST_double
void SetRangeStart(SourceLocation Loc)
static const TST TST_char
static const TST TST_bool
static const TST TST_char16
static const TST TST_accum
static const TST TST_half
static const TST TST_ibm128
static const TST TST_float128
void Finish(Sema &S, const PrintingPolicy &Policy)
Finish - This does final analysis of the declspec, issuing diagnostics for things like "_Complex" (la...
static const TST TST_wchar
static const TST TST_void
static const TST TST_float
static const TST TST_fract
static const TST TST_float16
static const TST TST_decltype_auto
static const TST TST_error
static const TST TST_char32
static const TST TST_int128
bool SetTypeSpecSign(TypeSpecifierSign S, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
static const TST TST_auto
SourceLocation getLocation() const
Information about one declarator, including the parsed type information and the identifier.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
void SetSourceRange(SourceRange R)
void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc)
AddTypeInfo - Add a chunk to this declarator.
bool isInvalidType() const
DeclSpec & getMutableDeclSpec()
getMutableDeclSpec - Return a non-const version of the DeclSpec.
This represents one expression.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
static SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, unsigned Characters, const SourceManager &SM, const LangOptions &LangOpts)
AdvanceToTokenCharacter - If the current SourceLocation specifies a location at the start of a token,...
static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, const LangOptions &LangOpts)
Computes the source location just past the end of the token at this source location.
void * getAsOpaquePtr() const
static OpaquePtr make(QualType P)
static const ParsedAttributesView & none()
ParsedAttributes - A collection of parsed attributes.
Introduces zero or more scopes for parsing.
ParseScope - Introduces a new scope for parsing.
Parser - This implements a parser for the C family of languages.
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeName, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
SourceLocation getEndOfPreviousToken() const
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.
void AddFlags(unsigned Flags)
Sets up the specified scope flags and adjusts the scope state variables accordingly.
void setIsConditionVarScope(bool InConditionVarScope)
@ 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.
@ ContinueScope
This is a while, do, for, which can have continue statements embedded into it.
@ BreakScope
This is a while, do, switch, for, etc that can have break statements embedded into it.
@ 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.
A trivial tuple used to represent a source range.
void setBegin(SourceLocation b)
SourceLocation getEnd() const
SourceLocation getBegin() const
void setEnd(SourceLocation e)
SourceLocation getEndLoc() const LLVM_READONLY
SourceLocation getBeginLoc() const LLVM_READONLY
Represents a C++ template name within the type system.
Token - This structure provides full information about a lexed token.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
const char * getName() const
void setLength(unsigned Len)
void setKind(tok::TokenKind K)
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
tok::TokenKind getKind() const
void setLocation(SourceLocation L)
The base class of the type hierarchy.
QualType getCanonicalTypeInternal() const
Represents a C++ unqualified-id that has been parsed.
struct OFI OperatorFunctionId
When Kind == IK_OperatorFunctionId, the overloaded operator that we parsed.
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
bool isValid() const
Determine whether this unqualified-id refers to a valid name.
void setDestructorName(SourceLocation TildeLoc, ParsedType ClassType, SourceLocation EndLoc)
Specify that this unqualified-id was parsed as a destructor name.
void setTemplateId(TemplateIdAnnotation *TemplateId)
Specify that this unqualified-id was parsed as a template-id.
UnionParsedType DestructorName
When Kind == IK_DestructorName, the type referred to by the class-name.
SourceLocation StartLocation
The location of the first token that describes this unqualified-id, which will be the location of the...
void setConstructorName(ParsedType ClassType, SourceLocation ClassNameLoc, SourceLocation EndLoc)
Specify that this unqualified-id was parsed as a constructor name.
const IdentifierInfo * Identifier
When Kind == IK_Identifier, the parsed identifier, or when Kind == IK_UserLiteralId,...
UnqualifiedIdKind getKind() const
Determine what kind of name we have.
uint32_t Literal
Literals are represented as positive integers.
@ After
Like System, but searched after the system directories.
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.
The JSON file list parser is used to communicate input to InstallAPI.
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.
ArrayTypeTrait
Names for the array type traits.
@ 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
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
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.
@ Type
The name was classified as a type.
MutableArrayRef< ParsedTemplateArgument > ASTTemplateArgsPtr
TemplateNameKind
Specifies the kind of template name that an identifier refers to.
@ TNK_Var_template
The name refers to a variable template whose specialization produces a variable.
@ TNK_Dependent_template_name
The name refers to a dependent template name:
@ TNK_Function_template
The name refers to a function template or a set of overloaded functions that includes at least one fu...
@ TNK_Non_template
The name does not refer to a template.
@ TNK_Undeclared_template
Lookup for the name failed, but we're assuming it was a template name anyway.
const char * getOperatorSpelling(OverloadedOperatorKind Operator)
Retrieve the spelling of the given overloaded operator, without the preceding "operator" keyword.
U cast(CodeGen::Address addr)
SmallVector< Token, 4 > CachedTokens
A set of tokens that has been cached for later parsing.
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
@ None
No keyword precedes the qualified type name.
ParenParseOption
ParenParseOption - Control what ParseParenExpression will parse.
ActionResult< Expr * > ExprResult
TypeTrait
Names for traits that operate specifically on types.
@ 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.