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);
1872 ForRangeInfo *FRI) {
1874 PreferredType.enterCondition(Actions, Tok.getLocation());
1876 if (Tok.is(tok::code_completion)) {
1878 Actions.CodeCompletion().CodeCompleteOrdinaryName(
1883 ParsedAttributes attrs(AttrFactory);
1884 MaybeParseCXX11Attributes(attrs);
1886 const auto WarnOnInit = [
this, &CK] {
1888 ? diag::warn_cxx14_compat_init_statement
1889 : diag::ext_init_statement)
1894 switch (isCXXConditionDeclarationOrInitStatement(InitStmt, FRI)) {
1895 case ConditionOrInitStatement::Expression: {
1896 ProhibitAttributes(attrs);
1900 if (InitStmt && Tok.is(tok::semi)) {
1902 SourceLocation SemiLoc = Tok.getLocation();
1903 if (!Tok.hasLeadingEmptyMacro() && !SemiLoc.
isMacroID()) {
1904 Diag(SemiLoc, diag::warn_empty_init_statement)
1909 *InitStmt = Actions.ActOnNullStmt(SemiLoc);
1910 return ParseCXXCondition(
nullptr, Loc, CK, MissingOK);
1913 EnterExpressionEvaluationContext Eval(
1924 if (InitStmt && Tok.is(tok::semi)) {
1926 *InitStmt = Actions.ActOnExprStmt(Expr.
get());
1928 return ParseCXXCondition(
nullptr, Loc, CK, MissingOK);
1931 return Actions.ActOnCondition(
getCurScope(), Loc, Expr.
get(), CK,
1935 case ConditionOrInitStatement::InitStmtDecl: {
1938 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
1939 if (Tok.is(tok::kw_using))
1940 DG = ParseAliasDeclarationInInitStatement(
1943 ParsedAttributes DeclSpecAttrs(AttrFactory);
1945 attrs, DeclSpecAttrs,
true);
1947 *InitStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd);
1948 return ParseCXXCondition(
nullptr, Loc, CK, MissingOK);
1951 case ConditionOrInitStatement::ForRangeDecl: {
1955 assert(FRI &&
"should not parse a for range declaration here");
1956 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
1957 ParsedAttributes DeclSpecAttrs(AttrFactory);
1960 FRI->LoopVar = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
1961 return Sema::ConditionResult();
1964 case ConditionOrInitStatement::ConditionDecl:
1965 case ConditionOrInitStatement::Error:
1970 DeclSpec DS(AttrFactory);
1971 ParseSpecifierQualifierList(DS,
AS_none, DeclSpecContext::DSC_condition);
1975 ParseDeclarator(DeclaratorInfo);
1978 if (Tok.is(tok::kw_asm)) {
1980 ExprResult AsmLabel(ParseSimpleAsm(
true, &Loc));
1981 if (AsmLabel.isInvalid()) {
1985 DeclaratorInfo.setAsmLabel(AsmLabel.get());
1986 DeclaratorInfo.SetRangeEnd(Loc);
1990 MaybeParseGNUAttributes(DeclaratorInfo);
2001 bool CopyInitialization = isTokenEqualOrEqualTypo();
2002 if (CopyInitialization)
2007 Diag(Tok.getLocation(),
2008 diag::warn_cxx98_compat_generalized_initializer_lists);
2009 InitExpr = ParseBraceInitializer();
2010 }
else if (CopyInitialization) {
2011 PreferredType.enterVariableInit(Tok.getLocation(), DeclOut);
2013 }
else if (Tok.is(tok::l_paren)) {
2015 SourceLocation LParen = ConsumeParen(), RParen = LParen;
2017 RParen = ConsumeParen();
2019 diag::err_expected_init_in_condition_lparen)
2020 << SourceRange(LParen, RParen);
2026 Actions.AddInitializerToDecl(DeclOut, InitExpr.
get(), !CopyInitialization);
2028 Actions.ActOnInitializerError(DeclOut);
2030 Actions.FinalizeDeclaration(DeclOut);
2031 return Actions.ActOnConditionVariable(DeclOut, Loc, CK);
2034void Parser::ParseCXXSimpleTypeSpecifier(
DeclSpec &DS) {
2036 const char *PrevSpec;
2038 SourceLocation Loc = Tok.getLocation();
2039 const clang::PrintingPolicy &Policy =
2040 Actions.getASTContext().getPrintingPolicy();
2042 switch (Tok.getKind()) {
2043 case tok::identifier:
2044 case tok::coloncolon:
2045 llvm_unreachable(
"Annotation token should already be formed!");
2047 llvm_unreachable(
"Not a simple-type-specifier token!");
2050 case tok::annot_typename: {
2054 ConsumeAnnotationToken();
2055 DS.
Finish(Actions, Policy);
2059 case tok::kw__ExtInt:
2060 case tok::kw__BitInt: {
2061 DiagnoseBitIntUse(Tok);
2070 DS.
Finish(Actions, Policy);
2083 case tok::kw___int64:
2087 case tok::kw_signed:
2090 case tok::kw_unsigned:
2105 case tok::kw___int128:
2108 case tok::kw___bf16:
2117 case tok::kw_double:
2120 case tok::kw__Float16:
2123 case tok::kw___float128:
2126 case tok::kw___ibm128:
2129 case tok::kw_wchar_t:
2132 case tok::kw_char8_t:
2135 case tok::kw_char16_t:
2138 case tok::kw_char32_t:
2144 case tok::kw__Accum:
2147 case tok::kw__Fract:
2153#define GENERIC_IMAGE_TYPE(ImgType, Id) \
2154 case tok::kw_##ImgType##_t: \
2155 DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, DiagID, \
2158#include "clang/Basic/OpenCLImageTypes.def"
2159#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
2160 case tok::kw_##Name: \
2161 DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, DiagID, Policy); \
2163#include "clang/Basic/HLSLIntangibleTypes.def"
2165 case tok::annot_decltype:
2166 case tok::kw_decltype:
2168 return DS.
Finish(Actions, Policy);
2170 case tok::annot_pack_indexing_type:
2172 return DS.
Finish(Actions, Policy);
2175 case tok::kw_typeof:
2176 ParseTypeofSpecifier(DS);
2177 DS.
Finish(Actions, Policy);
2182 DS.
Finish(Actions, Policy);
2186 ParseSpecifierQualifierList(DS,
AS_none,
2187 getDeclSpecContextFromDeclaratorContext(Context));
2188 DS.
Finish(Actions, Actions.getASTContext().getPrintingPolicy());
2192bool Parser::ParseUnqualifiedIdTemplateId(
2195 bool EnteringContext,
UnqualifiedId &Id,
bool AssumeTemplateId) {
2196 assert(Tok.is(tok::less) &&
"Expected '<' to finish parsing a template-id");
2204 if (AssumeTemplateId) {
2207 TNK = Actions.ActOnTemplateName(
getCurScope(), SS, TemplateKWLoc, Id,
2208 ObjectType, EnteringContext,
Template,
2211 bool MemberOfUnknownSpecialization;
2214 ObjectType, EnteringContext,
Template,
2215 MemberOfUnknownSpecialization);
2220 isTemplateArgumentList(0) == TPResult::False)
2224 ObjectType && isTemplateArgumentList(0) == TPResult::True) {
2227 if (!ObjectHadErrors) {
2246 TNK = Actions.ActOnTemplateName(
2247 getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext,
2257 bool MemberOfUnknownSpecialization;
2262 MemberOfUnknownSpecialization);
2270 bool MemberOfUnknownSpecialization;
2273 TNK = Actions.ActOnTemplateName(
2280 MemberOfUnknownSpecialization);
2283 Diag(NameLoc, diag::err_destructor_template_id)
2296 SourceLocation LAngleLoc, RAngleLoc;
2297 TemplateArgList TemplateArgs;
2298 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs, RAngleLoc,
2313 const IdentifierInfo *TemplateII =
2323 LAngleLoc, RAngleLoc, TemplateArgs,
false, TemplateIds);
2335 SourceLocation(), SS, TemplateKWLoc,
Template,
2336 Name, NameLoc, LAngleLoc, TemplateArgsPtr, RAngleLoc,
2338 if (
Type.isInvalid())
2349bool Parser::ParseUnqualifiedIdOperator(
CXXScopeSpec &SS,
bool EnteringContext,
2352 assert(Tok.is(tok::kw_operator) &&
"Expected 'operator' keyword");
2358 unsigned SymbolIdx = 0;
2359 SourceLocation SymbolLocations[3];
2361 switch (Tok.getKind()) {
2363 case tok::kw_delete: {
2364 bool isNew = Tok.getKind() == tok::kw_new;
2368 if (Tok.is(tok::l_square) &&
2374 if (T.getCloseLocation().isInvalid())
2377 SymbolLocations[SymbolIdx++] = T.getOpenLocation();
2378 SymbolLocations[SymbolIdx++] = T.getCloseLocation();
2379 Op = isNew? OO_Array_New : OO_Array_Delete;
2381 Op = isNew? OO_New : OO_Delete;
2386#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
2388 SymbolLocations[SymbolIdx++] = ConsumeToken(); \
2391#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
2392#include "clang/Basic/OperatorKinds.def"
2394 case tok::l_paren: {
2399 if (T.getCloseLocation().isInvalid())
2402 SymbolLocations[SymbolIdx++] = T.getOpenLocation();
2403 SymbolLocations[SymbolIdx++] = T.getCloseLocation();
2408 case tok::l_square: {
2413 if (T.getCloseLocation().isInvalid())
2416 SymbolLocations[SymbolIdx++] = T.getOpenLocation();
2417 SymbolLocations[SymbolIdx++] = T.getCloseLocation();
2422 case tok::code_completion: {
2426 Actions.CodeCompletion().CodeCompleteOperatorName(
getCurScope());
2436 Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations);
2447 Diag(Tok.getLocation(), diag::warn_cxx98_compat_literal_operator);
2449 SourceLocation DiagLoc;
2450 unsigned DiagId = 0;
2454 SmallVector<Token, 4> Toks;
2455 SmallVector<SourceLocation, 4> TokLocs;
2456 while (isTokenStringLiteral()) {
2457 if (!Tok.is(tok::string_literal) && !DiagId) {
2461 DiagLoc = Tok.getLocation();
2462 DiagId = diag::err_literal_operator_string_prefix;
2464 Toks.push_back(Tok);
2465 TokLocs.push_back(ConsumeStringToken());
2468 StringLiteralParser
Literal(Toks, PP);
2474 bool IsUDSuffix = !
Literal.getUDSuffix().empty();
2475 IdentifierInfo *II =
nullptr;
2476 SourceLocation SuffixLoc;
2478 II = &PP.getIdentifierTable().get(
Literal.getUDSuffix());
2483 }
else if (Tok.is(tok::identifier)) {
2484 II = Tok.getIdentifierInfo();
2486 TokLocs.push_back(SuffixLoc);
2488 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
2498 DiagLoc = TokLocs.front();
2499 DiagId = diag::err_literal_operator_string_not_empty;
2505 SmallString<32> Str;
2509 SourceRange(TokLocs.front(), TokLocs.back()), Str);
2512 Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
2514 return Actions.checkLiteralOperatorId(SS,
Result, IsUDSuffix);
2529 DeclSpec DS(AttrFactory);
2530 if (ParseCXXTypeSpecifierSeq(
2538 ParseDeclaratorInternal(D,
nullptr);
2546 Result.setConversionFunctionId(KeywordLoc, Ty.
get(),
2547 D.getSourceRange().getEnd());
2552 bool ObjectHadErrors,
bool EnteringContext,
2553 bool AllowDestructorName,
2554 bool AllowConstructorName,
2555 bool AllowDeductionGuide,
2563 bool TemplateSpecified =
false;
2564 if (Tok.is(tok::kw_template)) {
2565 if (TemplateKWLoc && (ObjectType || SS.
isSet())) {
2566 TemplateSpecified =
true;
2570 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2578 if (Tok.is(tok::identifier)) {
2587 Result.setIdentifier(Id, IdLoc);
2592 if (AllowConstructorName &&
2593 Actions.isCurrentClassName(*Id,
getCurScope(), &SS)) {
2599 Result.setConstructorName(Ty, IdLoc, IdLoc);
2602 Actions.isDeductionGuideName(
getCurScope(), *Id, IdLoc, SS,
2608 Result.setIdentifier(Id, IdLoc);
2613 if (Tok.is(tok::less))
2614 return ParseUnqualifiedIdTemplateId(
2615 SS, ObjectType, ObjectHadErrors,
2617 EnteringContext,
Result, TemplateSpecified);
2619 if (TemplateSpecified) {
2622 ObjectType, EnteringContext,
Template,
2633 Diag(IdLoc, diag::missing_template_arg_list_after_template_kw);
2640 if (Tok.is(tok::annot_template_id)) {
2646 ConsumeAnnotationToken();
2651 if (AllowConstructorName && TemplateId->
Name &&
2659 diag::err_out_of_line_constructor_template_id)
2670 ConsumeAnnotationToken();
2674 Result.setConstructorTemplateId(TemplateId);
2675 ConsumeAnnotationToken();
2681 Result.setTemplateId(TemplateId);
2684 if (TemplateKWLoc && (ObjectType || SS.
isSet()))
2685 *TemplateKWLoc = TemplateLoc;
2687 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2690 ConsumeAnnotationToken();
2697 if (Tok.is(tok::kw_operator)) {
2698 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
Result))
2710 return ParseUnqualifiedIdTemplateId(
2711 SS, ObjectType, ObjectHadErrors,
2714 else if (TemplateSpecified &&
2715 Actions.ActOnTemplateName(
2725 (AllowDestructorName || SS.
isSet()) && Tok.is(tok::tilde)) {
2734 if (TemplateSpecified) {
2745 Diag(*TemplateKWLoc, diag::err_unexpected_template_in_destructor_name)
2746 << Tok.getLocation();
2750 if (SS.
isEmpty() && Tok.is(tok::kw_decltype)) {
2754 Actions.getDestructorTypeForDecltype(DS, ObjectType)) {
2755 Result.setDestructorName(TildeLoc,
Type, EndLoc);
2762 if (Tok.isNot(tok::identifier)) {
2763 Diag(Tok, diag::err_destructor_tilde_identifier);
2768 DeclaratorScopeObj DeclScopeObj(*
this, SS);
2776 AnnotateScopeToken(SS,
true);
2779 if (ParseOptionalCXXScopeSpecifier(SS, ObjectType, ObjectHadErrors,
2783 ObjectType =
nullptr;
2784 if (Tok.isNot(tok::identifier) ||
NextToken().
is(tok::coloncolon) ||
2786 Diag(TildeLoc, diag::err_destructor_tilde_scope);
2791 Diag(TildeLoc, diag::err_destructor_tilde_scope)
2796 if (Actions.ShouldEnterDeclaratorScope(
getCurScope(), SS))
2797 DeclScopeObj.EnterDeclaratorScope();
2804 if (Tok.is(tok::less)) {
2805 Result.setDestructorName(TildeLoc,
nullptr, ClassNameLoc);
2806 return ParseUnqualifiedIdTemplateId(
2807 SS, ObjectType, ObjectHadErrors,
2809 ClassNameLoc, EnteringContext,
Result, TemplateSpecified);
2814 Actions.getDestructorName(*ClassName, ClassNameLoc,
getCurScope(), SS,
2815 ObjectType, EnteringContext);
2819 Result.setDestructorName(TildeLoc, Ty, ClassNameLoc);
2823 switch (Tok.getKind()) {
2824#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
2825#include "clang/Basic/TransformTypeTraits.def"
2827 Tok.setKind(tok::identifier);
2828 Diag(Tok, diag::ext_keyword_as_ident)
2829 << Tok.getIdentifierInfo()->getName() << 0;
2830 goto ParseIdentifier;
2834 Diag(Tok, diag::err_expected_unqualified_id) <<
getLangOpts().CPlusPlus;
2840Parser::ParseCXXNewExpression(
bool UseGlobal,
SourceLocation Start) {
2841 assert(
Tok.is(tok::kw_new) &&
"expected 'new' token");
2847 ExprVector PlacementArgs;
2854 if (
Tok.is(tok::l_paren)) {
2858 PlacementLParen = T.getOpenLocation();
2859 if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) {
2865 PlacementRParen = T.getCloseLocation();
2871 if (PlacementArgs.empty()) {
2873 TypeIdParens = T.getRange();
2874 PlacementLParen = PlacementRParen = SourceLocation();
2877 if (Tok.is(tok::l_paren)) {
2880 MaybeParseGNUAttributes(DeclaratorInfo);
2881 ParseSpecifierQualifierList(DS);
2883 ParseDeclarator(DeclaratorInfo);
2885 TypeIdParens = T.getRange();
2887 MaybeParseGNUAttributes(DeclaratorInfo);
2888 if (ParseCXXTypeSpecifierSeq(DS))
2889 DeclaratorInfo.setInvalidType(
true);
2892 ParseDeclaratorInternal(DeclaratorInfo,
2893 &Parser::ParseDirectNewDeclarator);
2900 MaybeParseGNUAttributes(DeclaratorInfo);
2902 DeclaratorInfo.setInvalidType(
true);
2905 ParseDeclaratorInternal(DeclaratorInfo,
2906 &Parser::ParseDirectNewDeclarator);
2909 if (DeclaratorInfo.isInvalidType()) {
2916 if (Tok.is(tok::l_paren)) {
2917 SourceLocation ConstructorLParen, ConstructorRParen;
2918 ExprVector ConstructorArgs;
2921 ConstructorLParen = T.getOpenLocation();
2922 if (Tok.isNot(tok::r_paren)) {
2923 auto RunSignatureHelp = [&]() {
2924 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
2925 QualType PreferredType;
2931 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
2933 DeclaratorInfo.getEndLoc(), ConstructorArgs,
2936 CalledSignatureHelp =
true;
2937 return PreferredType;
2939 if (ParseExpressionList(ConstructorArgs, [&] {
2940 PreferredType.enterFunctionArgument(Tok.getLocation(),
2943 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
2950 ConstructorRParen = T.getCloseLocation();
2955 Initializer = Actions.ActOnParenListExpr(ConstructorLParen,
2959 Diag(Tok.getLocation(),
2960 diag::warn_cxx98_compat_generalized_initializer_lists);
2966 return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen,
2967 PlacementArgs, PlacementRParen,
2971void Parser::ParseDirectNewDeclarator(
Declarator &D) {
2974 while (Tok.is(tok::l_square)) {
2976 if (CheckProhibitedCXX11Attribute())
2985 if (
Size.isInvalid()) {
2987 SkipUntil(tok::r_square, StopAtSemi);
2995 ParsedAttributes Attrs(AttrFactory);
2996 MaybeParseCXX11Attributes(Attrs);
3000 Size.get(), T.getOpenLocation(),
3001 T.getCloseLocation()),
3002 std::move(Attrs), T.getCloseLocation());
3004 if (T.getCloseLocation().isInvalid())
3009bool Parser::ParseExpressionListOrTypeId(
3013 if (isTypeIdInParens()) {
3021 return ParseExpressionList(PlacementArgs);
3025Parser::ParseCXXDeleteExpression(
bool UseGlobal,
SourceLocation Start) {
3026 assert(Tok.is(tok::kw_delete) &&
"Expected 'delete' keyword");
3030 bool ArrayDelete =
false;
3031 if (Tok.is(tok::l_square) &&
NextToken().
is(tok::r_square)) {
3042 if (
Next.isOneOf(tok::l_brace, tok::less) ||
3043 (
Next.is(tok::l_paren) &&
3047 TentativeParsingAction TPA(*
this);
3048 SourceLocation LSquareLoc = Tok.getLocation();
3054 SourceLocation RBraceLoc;
3055 bool EmitFixIt =
false;
3056 if (Tok.is(tok::l_brace)) {
3059 RBraceLoc = Tok.getLocation();
3066 Diag(Start, diag::err_lambda_after_delete)
3067 << SourceRange(Start, RSquareLoc)
3071 RBraceLoc, 0, Actions.getSourceManager(),
getLangOpts()),
3074 Diag(Start, diag::err_lambda_after_delete)
3075 << SourceRange(Start, RSquareLoc);
3084 Lambda = ParsePostfixExpressionSuffix(Lambda);
3087 return Actions.ActOnCXXDelete(Start, UseGlobal,
false,
3096 if (T.getCloseLocation().isInvalid())
3104 return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete,
Operand.get());
3107ExprResult Parser::ParseRequiresExpression() {
3108 assert(Tok.is(tok::kw_requires) &&
"Expected 'requires' keyword");
3111 llvm::SmallVector<ParmVarDecl *, 2> LocalParameterDecls;
3113 if (Tok.is(tok::l_paren)) {
3118 if (!Tok.is(tok::r_paren)) {
3120 SourceLocation EllipsisLoc;
3121 llvm::SmallVector<DeclaratorChunk::ParamInfo, 2> LocalParameters;
3123 FirstArgAttrs, LocalParameters,
3126 Diag(EllipsisLoc, diag::err_requires_expr_parameter_list_ellipsis);
3127 for (
auto &ParamInfo : LocalParameters)
3134 if (
Braces.expectAndConsume())
3138 llvm::SmallVector<concepts::Requirement *, 2> Requirements;
3142 EnterExpressionEvaluationContext Ctx(
3150 RequiresExprBodyDecl *Body = Actions.ActOnStartRequiresExpr(
3151 RequiresKWLoc, LocalParameterDecls,
getCurScope());
3153 if (Tok.is(tok::r_brace)) {
3160 Diag(Tok, diag::err_empty_requires_expr);
3163 while (!Tok.is(tok::r_brace)) {
3164 switch (Tok.getKind()) {
3165 case tok::l_brace: {
3176 ExprBraces.consumeOpen();
3178 if (Expression.isUsable())
3179 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3180 if (!Expression.isUsable()) {
3181 ExprBraces.skipToEnd();
3187 if (ExprBraces.consumeClose())
3190 concepts::Requirement *Req =
nullptr;
3191 SourceLocation NoexceptLoc;
3193 if (Tok.is(tok::semi)) {
3194 Req = Actions.ActOnCompoundRequirement(Expression.get(), NoexceptLoc);
3196 Requirements.push_back(Req);
3201 Diag(Tok, diag::err_requires_expr_missing_arrow)
3204 if (TryAnnotateTypeConstraint()) {
3208 if (!isTypeConstraintAnnotation()) {
3209 Diag(Tok, diag::err_requires_expr_expected_type_constraint);
3214 if (Tok.is(tok::annot_cxxscope)) {
3215 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
3216 Tok.getAnnotationRange(),
3218 ConsumeAnnotationToken();
3221 Req = Actions.ActOnCompoundRequirement(
3222 Expression.get(), NoexceptLoc, SS, takeTemplateIdAnnotation(Tok),
3223 TemplateParameterDepth);
3224 ConsumeAnnotationToken();
3226 Requirements.push_back(Req);
3230 bool PossibleRequiresExprInSimpleRequirement =
false;
3231 if (Tok.is(tok::kw_requires)) {
3232 auto IsNestedRequirement = [&] {
3233 RevertingTentativeParsingAction TPA(*
this);
3235 if (Tok.is(tok::l_brace))
3242 if (Tok.is(tok::l_paren)) {
3245 auto Res = TryParseParameterDeclarationClause();
3246 if (Res != TPResult::False) {
3249 while (Depth != 0) {
3250 bool FoundParen =
SkipUntil(tok::l_paren, tok::r_paren,
3254 if (Tok.is(tok::l_paren))
3256 else if (Tok.is(tok::r_paren))
3267 if (Tok.is(tok::l_brace))
3276 if (IsNestedRequirement()) {
3289 Actions.ActOnNestedRequirement(ConstraintExpr.
get()))
3290 Requirements.push_back(Req);
3298 PossibleRequiresExprInSimpleRequirement =
true;
3299 }
else if (Tok.is(tok::kw_typename)) {
3302 TentativeParsingAction TPA(*
this);
3312 if (Tok.is(tok::annot_cxxscope)) {
3313 Actions.RestoreNestedNameSpecifierAnnotation(
3314 Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS);
3315 ConsumeAnnotationToken();
3318 if (Tok.isOneOf(tok::identifier, tok::annot_template_id) &&
3321 SourceLocation NameLoc = Tok.getLocation();
3322 IdentifierInfo *II =
nullptr;
3323 TemplateIdAnnotation *TemplateId =
nullptr;
3324 if (Tok.is(tok::identifier)) {
3325 II = Tok.getIdentifierInfo();
3328 TemplateId = takeTemplateIdAnnotation(Tok);
3329 ConsumeAnnotationToken();
3334 if (
auto *Req = Actions.ActOnTypeRequirement(TypenameKWLoc, SS,
3337 Requirements.push_back(Req);
3347 SourceLocation StartLoc = Tok.getLocation();
3349 if (Expression.isUsable())
3350 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3351 if (!Expression.isUsable()) {
3355 if (!Expression.isInvalid() && PossibleRequiresExprInSimpleRequirement)
3356 Diag(StartLoc, diag::err_requires_expr_in_simple_requirement)
3358 if (
auto *Req = Actions.ActOnSimpleRequirement(Expression.get()))
3359 Requirements.push_back(Req);
3365 if (Tok.is(tok::kw_noexcept)) {
3366 Diag(Tok, diag::err_requires_expr_simple_requirement_noexcept)
3375 if (ExpectAndConsumeSemi(diag::err_expected_semi_requirement)) {
3381 if (Requirements.empty()) {
3386 Actions.ActOnFinishRequiresExpr();
3391 Actions.ActOnFinishRequiresExpr();
3392 ParsingBodyDecl.complete(Body);
3393 return Actions.ActOnRequiresExpr(
3394 RequiresKWLoc, Body,
Parens.getOpenLocation(), LocalParameterDecls,
3395 Parens.getCloseLocation(), Requirements,
Braces.getCloseLocation());
3400 default: llvm_unreachable(
"Not a known type trait");
3401#define TYPE_TRAIT_1(Spelling, Name, Key) \
3402case tok::kw_ ## Spelling: return UTT_ ## Name;
3403#define TYPE_TRAIT_2(Spelling, Name, Key) \
3404case tok::kw_ ## Spelling: return BTT_ ## Name;
3405#include "clang/Basic/TokenKinds.def"
3406#define TYPE_TRAIT_N(Spelling, Name, Key) \
3407 case tok::kw_ ## Spelling: return TT_ ## Name;
3408#include "clang/Basic/TokenKinds.def"
3415 llvm_unreachable(
"Not a known array type trait");
3416#define ARRAY_TYPE_TRAIT(Spelling, Name, Key) \
3417 case tok::kw_##Spelling: \
3419#include "clang/Basic/TokenKinds.def"
3426 llvm_unreachable(
"Not a known unary expression trait.");
3427#define EXPRESSION_TRAIT(Spelling, Name, Key) \
3428 case tok::kw_##Spelling: \
3430#include "clang/Basic/TokenKinds.def"
3440 if (
Parens.expectAndConsume())
3443 SmallVector<ParsedType, 2> Args;
3456 if (Tok.is(tok::ellipsis)) {
3465 Args.push_back(Ty.
get());
3468 if (
Parens.consumeClose())
3471 SourceLocation EndLoc =
Parens.getCloseLocation();
3481 if (T.expectAndConsume())
3493 case ATT_ArrayRank: {
3495 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(),
nullptr,
3496 T.getCloseLocation());
3498 case ATT_ArrayExtent: {
3499 if (ExpectAndConsume(tok::comma)) {
3510 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(), DimExpr.
get(),
3511 T.getCloseLocation());
3514 llvm_unreachable(
"Invalid ArrayTypeTrait!");
3522 if (T.expectAndConsume())
3529 return Actions.ActOnExpressionTrait(ET, Loc, Expr.
get(),
3530 T.getCloseLocation());
3540 "Compound literals are not ambiguous!");
3541 assert(isTypeIdInParens() &&
"Not a type-id!");
3570 if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) {
3576 if (Tok.is(tok::l_brace)) {
3580 if (Tok.is(tok::l_paren) &&
NextToken().
is(tok::r_paren)) {
3588 false , NotCastExpr,
3601 AttrEnd.startToken();
3602 AttrEnd.setKind(tok::eof);
3603 AttrEnd.setLocation(Tok.getLocation());
3604 AttrEnd.setEofData(Toks.data());
3605 Toks.push_back(AttrEnd);
3608 Toks.push_back(Tok);
3611 PP.EnterTokenStream(Toks,
true,
3619 DeclSpec DS(AttrFactory);
3624 ParseSpecifierQualifierList(DS);
3625 ParseDeclarator(DeclaratorInfo);
3633 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3638 if (DeclaratorInfo.isInvalidType())
3641 TypeResult Ty = Actions.ActOnTypeName(DeclaratorInfo);
3642 return ParseCompoundLiteralExpression(Ty.
get(),
3650 if (DeclaratorInfo.isInvalidType())
3656 DeclaratorInfo, CastTy,
3666 if (!
Result.isInvalid() && Tok.is(tok::r_paren))
3668 Tok.getLocation(),
Result.get());
3671 if (
Result.isInvalid()) {
3672 while (Tok.isNot(tok::eof))
3674 assert(Tok.getEofData() == AttrEnd.getEofData());
3681 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3690 if (T.expectAndConsume(diag::err_expected_lparen_after,
"__builtin_bit_cast"))
3694 DeclSpec DS(AttrFactory);
3695 ParseSpecifierQualifierList(DS);
3700 ParseDeclarator(DeclaratorInfo);
3702 if (ExpectAndConsume(tok::comma)) {
3703 Diag(Tok.getLocation(), diag::err_expected) << tok::comma;
3710 if (T.consumeClose())
3713 if (
Operand.isInvalid() || DeclaratorInfo.isInvalidType())
3716 return Actions.ActOnBuiltinBitCastExpr(KWLoc, DeclaratorInfo, Operand,
3717 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.
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed.
void restore()
restore - This can be used to restore the state early, before the dtor is run.
Captures information about "declaration specifiers".
static const TST TST_typename
SourceLocation getEndLoc() const LLVM_READONLY
bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec and return false if there was no error.
static const TST TST_char8
static const TST TST_BFloat16
bool SetConstexprSpec(ConstexprSpecKind ConstexprKind, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
bool SetTypeSpecWidth(TypeSpecifierWidth W, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec, but return true and ignore the request if ...
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
SourceRange getSourceRange() const LLVM_READONLY
void SetRangeEnd(SourceLocation Loc)
bool SetBitIntType(SourceLocation KWLoc, Expr *BitWidth, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
static const TST TST_double
void SetRangeStart(SourceLocation Loc)
static const TST TST_char
static const TST TST_bool
static const TST TST_char16
static const TST TST_accum
static const TST TST_half
static const TST TST_ibm128
static const TST TST_float128
void Finish(Sema &S, const PrintingPolicy &Policy)
Finish - This does final analysis of the declspec, issuing diagnostics for things like "_Complex" (la...
static const TST TST_wchar
static const TST TST_void
static const TST TST_float
static const TST TST_fract
static const TST TST_float16
static const TST TST_decltype_auto
static const TST TST_error
static const TST TST_char32
static const TST TST_int128
bool SetTypeSpecSign(TypeSpecifierSign S, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
static const TST TST_auto
SourceLocation getLocation() const
Information about one declarator, including the parsed type information and the identifier.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
void SetSourceRange(SourceRange R)
void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc)
AddTypeInfo - Add a chunk to this declarator.
bool isInvalidType() const
DeclSpec & getMutableDeclSpec()
getMutableDeclSpec - Return a non-const version of the DeclSpec.
This represents one expression.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
static SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, unsigned Characters, const SourceManager &SM, const LangOptions &LangOpts)
AdvanceToTokenCharacter - If the current SourceLocation specifies a location at the start of a token,...
static 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.
@ 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.
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
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.