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 case tok::kw_typeof_unqual:
2177 ParseTypeofSpecifier(DS);
2178 DS.
Finish(Actions, Policy);
2183 DS.
Finish(Actions, Policy);
2187 ParseSpecifierQualifierList(DS,
AS_none,
2188 getDeclSpecContextFromDeclaratorContext(Context));
2189 DS.
Finish(Actions, Actions.getASTContext().getPrintingPolicy());
2193bool Parser::ParseUnqualifiedIdTemplateId(
2196 bool EnteringContext,
UnqualifiedId &Id,
bool AssumeTemplateId) {
2197 assert(Tok.is(tok::less) &&
"Expected '<' to finish parsing a template-id");
2205 if (AssumeTemplateId) {
2208 TNK = Actions.ActOnTemplateName(
getCurScope(), SS, TemplateKWLoc, Id,
2209 ObjectType, EnteringContext,
Template,
2212 bool MemberOfUnknownSpecialization;
2215 ObjectType, EnteringContext,
Template,
2216 MemberOfUnknownSpecialization);
2221 isTemplateArgumentList(0) == TPResult::False)
2225 ObjectType && isTemplateArgumentList(0) == TPResult::True) {
2228 if (!ObjectHadErrors) {
2247 TNK = Actions.ActOnTemplateName(
2248 getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext,
2258 bool MemberOfUnknownSpecialization;
2263 MemberOfUnknownSpecialization);
2271 bool MemberOfUnknownSpecialization;
2274 TNK = Actions.ActOnTemplateName(
2281 MemberOfUnknownSpecialization);
2284 Diag(NameLoc, diag::err_destructor_template_id)
2297 SourceLocation LAngleLoc, RAngleLoc;
2298 TemplateArgList TemplateArgs;
2299 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs, RAngleLoc,
2314 const IdentifierInfo *TemplateII =
2324 LAngleLoc, RAngleLoc, TemplateArgs,
false, TemplateIds);
2336 SourceLocation(), SS, TemplateKWLoc,
Template,
2337 Name, NameLoc, LAngleLoc, TemplateArgsPtr, RAngleLoc,
2339 if (
Type.isInvalid())
2350bool Parser::ParseUnqualifiedIdOperator(
CXXScopeSpec &SS,
bool EnteringContext,
2353 assert(Tok.is(tok::kw_operator) &&
"Expected 'operator' keyword");
2359 unsigned SymbolIdx = 0;
2360 SourceLocation SymbolLocations[3];
2362 switch (Tok.getKind()) {
2364 case tok::kw_delete: {
2365 bool isNew = Tok.getKind() == tok::kw_new;
2369 if (Tok.is(tok::l_square) &&
2375 if (T.getCloseLocation().isInvalid())
2378 SymbolLocations[SymbolIdx++] = T.getOpenLocation();
2379 SymbolLocations[SymbolIdx++] = T.getCloseLocation();
2380 Op = isNew? OO_Array_New : OO_Array_Delete;
2382 Op = isNew? OO_New : OO_Delete;
2387#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
2389 SymbolLocations[SymbolIdx++] = ConsumeToken(); \
2392#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
2393#include "clang/Basic/OperatorKinds.def"
2395 case tok::l_paren: {
2400 if (T.getCloseLocation().isInvalid())
2403 SymbolLocations[SymbolIdx++] = T.getOpenLocation();
2404 SymbolLocations[SymbolIdx++] = T.getCloseLocation();
2409 case tok::l_square: {
2414 if (T.getCloseLocation().isInvalid())
2417 SymbolLocations[SymbolIdx++] = T.getOpenLocation();
2418 SymbolLocations[SymbolIdx++] = T.getCloseLocation();
2423 case tok::code_completion: {
2427 Actions.CodeCompletion().CodeCompleteOperatorName(
getCurScope());
2437 Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations);
2448 Diag(Tok.getLocation(), diag::warn_cxx98_compat_literal_operator);
2450 SourceLocation DiagLoc;
2451 unsigned DiagId = 0;
2455 SmallVector<Token, 4> Toks;
2456 SmallVector<SourceLocation, 4> TokLocs;
2457 while (isTokenStringLiteral()) {
2458 if (!Tok.is(tok::string_literal) && !DiagId) {
2462 DiagLoc = Tok.getLocation();
2463 DiagId = diag::err_literal_operator_string_prefix;
2465 Toks.push_back(Tok);
2466 TokLocs.push_back(ConsumeStringToken());
2469 StringLiteralParser
Literal(Toks, PP);
2475 bool IsUDSuffix = !
Literal.getUDSuffix().empty();
2476 IdentifierInfo *II =
nullptr;
2477 SourceLocation SuffixLoc;
2479 II = &PP.getIdentifierTable().get(
Literal.getUDSuffix());
2484 }
else if (Tok.is(tok::identifier)) {
2485 II = Tok.getIdentifierInfo();
2487 TokLocs.push_back(SuffixLoc);
2489 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
2499 DiagLoc = TokLocs.front();
2500 DiagId = diag::err_literal_operator_string_not_empty;
2506 SmallString<32> Str;
2510 SourceRange(TokLocs.front(), TokLocs.back()), Str);
2513 Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
2515 return Actions.checkLiteralOperatorId(SS,
Result, IsUDSuffix);
2530 DeclSpec DS(AttrFactory);
2531 if (ParseCXXTypeSpecifierSeq(
2539 ParseDeclaratorInternal(D,
nullptr);
2547 Result.setConversionFunctionId(KeywordLoc, Ty.
get(),
2548 D.getSourceRange().getEnd());
2553 bool ObjectHadErrors,
bool EnteringContext,
2554 bool AllowDestructorName,
2555 bool AllowConstructorName,
2556 bool AllowDeductionGuide,
2564 bool TemplateSpecified =
false;
2565 if (Tok.is(tok::kw_template)) {
2566 if (TemplateKWLoc && (ObjectType || SS.
isSet())) {
2567 TemplateSpecified =
true;
2571 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2579 if (Tok.is(tok::identifier)) {
2588 Result.setIdentifier(Id, IdLoc);
2593 if (AllowConstructorName &&
2594 Actions.isCurrentClassName(*Id,
getCurScope(), &SS)) {
2600 Result.setConstructorName(Ty, IdLoc, IdLoc);
2603 Actions.isDeductionGuideName(
getCurScope(), *Id, IdLoc, SS,
2609 Result.setIdentifier(Id, IdLoc);
2614 if (Tok.is(tok::less))
2615 return ParseUnqualifiedIdTemplateId(
2616 SS, ObjectType, ObjectHadErrors,
2618 EnteringContext,
Result, TemplateSpecified);
2620 if (TemplateSpecified) {
2623 ObjectType, EnteringContext,
Template,
2634 Diag(IdLoc, diag::missing_template_arg_list_after_template_kw);
2641 if (Tok.is(tok::annot_template_id)) {
2647 ConsumeAnnotationToken();
2652 if (AllowConstructorName && TemplateId->
Name &&
2660 diag::err_out_of_line_constructor_template_id)
2671 ConsumeAnnotationToken();
2675 Result.setConstructorTemplateId(TemplateId);
2676 ConsumeAnnotationToken();
2682 Result.setTemplateId(TemplateId);
2685 if (TemplateKWLoc && (ObjectType || SS.
isSet()))
2686 *TemplateKWLoc = TemplateLoc;
2688 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2691 ConsumeAnnotationToken();
2698 if (Tok.is(tok::kw_operator)) {
2699 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
Result))
2711 return ParseUnqualifiedIdTemplateId(
2712 SS, ObjectType, ObjectHadErrors,
2715 else if (TemplateSpecified &&
2716 Actions.ActOnTemplateName(
2726 (AllowDestructorName || SS.
isSet()) && Tok.is(tok::tilde)) {
2735 if (TemplateSpecified) {
2746 Diag(*TemplateKWLoc, diag::err_unexpected_template_in_destructor_name)
2747 << Tok.getLocation();
2751 if (SS.
isEmpty() && Tok.is(tok::kw_decltype)) {
2755 Actions.getDestructorTypeForDecltype(DS, ObjectType)) {
2756 Result.setDestructorName(TildeLoc,
Type, EndLoc);
2763 if (Tok.isNot(tok::identifier)) {
2764 Diag(Tok, diag::err_destructor_tilde_identifier);
2769 DeclaratorScopeObj DeclScopeObj(*
this, SS);
2777 AnnotateScopeToken(SS,
true);
2780 if (ParseOptionalCXXScopeSpecifier(SS, ObjectType, ObjectHadErrors,
2784 ObjectType =
nullptr;
2785 if (Tok.isNot(tok::identifier) ||
NextToken().
is(tok::coloncolon) ||
2787 Diag(TildeLoc, diag::err_destructor_tilde_scope);
2792 Diag(TildeLoc, diag::err_destructor_tilde_scope)
2797 if (Actions.ShouldEnterDeclaratorScope(
getCurScope(), SS))
2798 DeclScopeObj.EnterDeclaratorScope();
2805 if (Tok.is(tok::less)) {
2806 Result.setDestructorName(TildeLoc,
nullptr, ClassNameLoc);
2807 return ParseUnqualifiedIdTemplateId(
2808 SS, ObjectType, ObjectHadErrors,
2810 ClassNameLoc, EnteringContext,
Result, TemplateSpecified);
2815 Actions.getDestructorName(*ClassName, ClassNameLoc,
getCurScope(), SS,
2816 ObjectType, EnteringContext);
2820 Result.setDestructorName(TildeLoc, Ty, ClassNameLoc);
2824 switch (Tok.getKind()) {
2825#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
2826#include "clang/Basic/TransformTypeTraits.def"
2828 Tok.setKind(tok::identifier);
2829 Diag(Tok, diag::ext_keyword_as_ident)
2830 << Tok.getIdentifierInfo()->getName() << 0;
2831 goto ParseIdentifier;
2835 Diag(Tok, diag::err_expected_unqualified_id) <<
getLangOpts().CPlusPlus;
2841Parser::ParseCXXNewExpression(
bool UseGlobal,
SourceLocation Start) {
2842 assert(
Tok.is(tok::kw_new) &&
"expected 'new' token");
2848 ExprVector PlacementArgs;
2855 if (
Tok.is(tok::l_paren)) {
2859 PlacementLParen = T.getOpenLocation();
2860 if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) {
2866 PlacementRParen = T.getCloseLocation();
2872 if (PlacementArgs.empty()) {
2874 TypeIdParens = T.getRange();
2875 PlacementLParen = PlacementRParen = SourceLocation();
2878 if (Tok.is(tok::l_paren)) {
2881 MaybeParseGNUAttributes(DeclaratorInfo);
2882 ParseSpecifierQualifierList(DS);
2884 ParseDeclarator(DeclaratorInfo);
2886 TypeIdParens = T.getRange();
2888 MaybeParseGNUAttributes(DeclaratorInfo);
2889 if (ParseCXXTypeSpecifierSeq(DS))
2890 DeclaratorInfo.setInvalidType(
true);
2893 ParseDeclaratorInternal(DeclaratorInfo,
2894 &Parser::ParseDirectNewDeclarator);
2901 MaybeParseGNUAttributes(DeclaratorInfo);
2903 DeclaratorInfo.setInvalidType(
true);
2906 ParseDeclaratorInternal(DeclaratorInfo,
2907 &Parser::ParseDirectNewDeclarator);
2910 if (DeclaratorInfo.isInvalidType()) {
2917 if (Tok.is(tok::l_paren)) {
2918 SourceLocation ConstructorLParen, ConstructorRParen;
2919 ExprVector ConstructorArgs;
2922 ConstructorLParen = T.getOpenLocation();
2923 if (Tok.isNot(tok::r_paren)) {
2924 auto RunSignatureHelp = [&]() {
2925 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
2926 QualType PreferredType;
2932 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
2934 DeclaratorInfo.getEndLoc(), ConstructorArgs,
2937 CalledSignatureHelp =
true;
2938 return PreferredType;
2940 if (ParseExpressionList(ConstructorArgs, [&] {
2941 PreferredType.enterFunctionArgument(Tok.getLocation(),
2944 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
2951 ConstructorRParen = T.getCloseLocation();
2956 Initializer = Actions.ActOnParenListExpr(ConstructorLParen,
2960 Diag(Tok.getLocation(),
2961 diag::warn_cxx98_compat_generalized_initializer_lists);
2967 return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen,
2968 PlacementArgs, PlacementRParen,
2972void Parser::ParseDirectNewDeclarator(
Declarator &D) {
2975 while (Tok.is(tok::l_square)) {
2977 if (CheckProhibitedCXX11Attribute())
2986 if (
Size.isInvalid()) {
2988 SkipUntil(tok::r_square, StopAtSemi);
2996 ParsedAttributes Attrs(AttrFactory);
2997 MaybeParseCXX11Attributes(Attrs);
3001 Size.get(), T.getOpenLocation(),
3002 T.getCloseLocation()),
3003 std::move(Attrs), T.getCloseLocation());
3005 if (T.getCloseLocation().isInvalid())
3010bool Parser::ParseExpressionListOrTypeId(
3014 if (isTypeIdInParens()) {
3022 return ParseExpressionList(PlacementArgs);
3026Parser::ParseCXXDeleteExpression(
bool UseGlobal,
SourceLocation Start) {
3027 assert(Tok.is(tok::kw_delete) &&
"Expected 'delete' keyword");
3031 bool ArrayDelete =
false;
3032 if (Tok.is(tok::l_square) &&
NextToken().
is(tok::r_square)) {
3043 if (
Next.isOneOf(tok::l_brace, tok::less) ||
3044 (
Next.is(tok::l_paren) &&
3048 TentativeParsingAction TPA(*
this);
3049 SourceLocation LSquareLoc = Tok.getLocation();
3055 SourceLocation RBraceLoc;
3056 bool EmitFixIt =
false;
3057 if (Tok.is(tok::l_brace)) {
3060 RBraceLoc = Tok.getLocation();
3067 Diag(Start, diag::err_lambda_after_delete)
3068 << SourceRange(Start, RSquareLoc)
3072 RBraceLoc, 0, Actions.getSourceManager(),
getLangOpts()),
3075 Diag(Start, diag::err_lambda_after_delete)
3076 << SourceRange(Start, RSquareLoc);
3085 Lambda = ParsePostfixExpressionSuffix(Lambda);
3088 return Actions.ActOnCXXDelete(Start, UseGlobal,
false,
3097 if (T.getCloseLocation().isInvalid())
3105 return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete,
Operand.get());
3108ExprResult Parser::ParseRequiresExpression() {
3109 assert(Tok.is(tok::kw_requires) &&
"Expected 'requires' keyword");
3112 llvm::SmallVector<ParmVarDecl *, 2> LocalParameterDecls;
3114 if (Tok.is(tok::l_paren)) {
3119 if (!Tok.is(tok::r_paren)) {
3121 SourceLocation EllipsisLoc;
3122 llvm::SmallVector<DeclaratorChunk::ParamInfo, 2> LocalParameters;
3124 FirstArgAttrs, LocalParameters,
3127 Diag(EllipsisLoc, diag::err_requires_expr_parameter_list_ellipsis);
3128 for (
auto &ParamInfo : LocalParameters)
3135 if (
Braces.expectAndConsume())
3139 llvm::SmallVector<concepts::Requirement *, 2> Requirements;
3143 EnterExpressionEvaluationContext Ctx(
3151 RequiresExprBodyDecl *Body = Actions.ActOnStartRequiresExpr(
3152 RequiresKWLoc, LocalParameterDecls,
getCurScope());
3154 if (Tok.is(tok::r_brace)) {
3161 Diag(Tok, diag::err_empty_requires_expr);
3164 while (!Tok.is(tok::r_brace)) {
3165 switch (Tok.getKind()) {
3166 case tok::l_brace: {
3177 ExprBraces.consumeOpen();
3179 if (Expression.isUsable())
3180 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3181 if (!Expression.isUsable()) {
3182 ExprBraces.skipToEnd();
3188 if (ExprBraces.consumeClose())
3191 concepts::Requirement *Req =
nullptr;
3192 SourceLocation NoexceptLoc;
3194 if (Tok.is(tok::semi)) {
3195 Req = Actions.ActOnCompoundRequirement(Expression.get(), NoexceptLoc);
3197 Requirements.push_back(Req);
3202 Diag(Tok, diag::err_requires_expr_missing_arrow)
3205 if (TryAnnotateTypeConstraint()) {
3209 if (!isTypeConstraintAnnotation()) {
3210 Diag(Tok, diag::err_requires_expr_expected_type_constraint);
3215 if (Tok.is(tok::annot_cxxscope)) {
3216 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
3217 Tok.getAnnotationRange(),
3219 ConsumeAnnotationToken();
3222 Req = Actions.ActOnCompoundRequirement(
3223 Expression.get(), NoexceptLoc, SS, takeTemplateIdAnnotation(Tok),
3224 TemplateParameterDepth);
3225 ConsumeAnnotationToken();
3227 Requirements.push_back(Req);
3231 bool PossibleRequiresExprInSimpleRequirement =
false;
3232 if (Tok.is(tok::kw_requires)) {
3233 auto IsNestedRequirement = [&] {
3234 RevertingTentativeParsingAction TPA(*
this);
3236 if (Tok.is(tok::l_brace))
3243 if (Tok.is(tok::l_paren)) {
3246 auto Res = TryParseParameterDeclarationClause();
3247 if (Res != TPResult::False) {
3250 while (Depth != 0) {
3251 bool FoundParen =
SkipUntil(tok::l_paren, tok::r_paren,
3255 if (Tok.is(tok::l_paren))
3257 else if (Tok.is(tok::r_paren))
3268 if (Tok.is(tok::l_brace))
3277 if (IsNestedRequirement()) {
3290 Actions.ActOnNestedRequirement(ConstraintExpr.
get()))
3291 Requirements.push_back(Req);
3299 PossibleRequiresExprInSimpleRequirement =
true;
3300 }
else if (Tok.is(tok::kw_typename)) {
3303 TentativeParsingAction TPA(*
this);
3313 if (Tok.is(tok::annot_cxxscope)) {
3314 Actions.RestoreNestedNameSpecifierAnnotation(
3315 Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS);
3316 ConsumeAnnotationToken();
3319 if (Tok.isOneOf(tok::identifier, tok::annot_template_id) &&
3322 SourceLocation NameLoc = Tok.getLocation();
3323 IdentifierInfo *II =
nullptr;
3324 TemplateIdAnnotation *TemplateId =
nullptr;
3325 if (Tok.is(tok::identifier)) {
3326 II = Tok.getIdentifierInfo();
3329 TemplateId = takeTemplateIdAnnotation(Tok);
3330 ConsumeAnnotationToken();
3335 if (
auto *Req = Actions.ActOnTypeRequirement(TypenameKWLoc, SS,
3338 Requirements.push_back(Req);
3348 SourceLocation StartLoc = Tok.getLocation();
3350 if (Expression.isUsable())
3351 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3352 if (!Expression.isUsable()) {
3356 if (!Expression.isInvalid() && PossibleRequiresExprInSimpleRequirement)
3357 Diag(StartLoc, diag::err_requires_expr_in_simple_requirement)
3359 if (
auto *Req = Actions.ActOnSimpleRequirement(Expression.get()))
3360 Requirements.push_back(Req);
3366 if (Tok.is(tok::kw_noexcept)) {
3367 Diag(Tok, diag::err_requires_expr_simple_requirement_noexcept)
3376 if (ExpectAndConsumeSemi(diag::err_expected_semi_requirement)) {
3382 if (Requirements.empty()) {
3387 Actions.ActOnFinishRequiresExpr();
3392 Actions.ActOnFinishRequiresExpr();
3393 ParsingBodyDecl.complete(Body);
3394 return Actions.ActOnRequiresExpr(
3395 RequiresKWLoc, Body,
Parens.getOpenLocation(), LocalParameterDecls,
3396 Parens.getCloseLocation(), Requirements,
Braces.getCloseLocation());
3401 default: llvm_unreachable(
"Not a known type trait");
3402#define TYPE_TRAIT_1(Spelling, Name, Key) \
3403case tok::kw_ ## Spelling: return UTT_ ## Name;
3404#define TYPE_TRAIT_2(Spelling, Name, Key) \
3405case tok::kw_ ## Spelling: return BTT_ ## Name;
3406#include "clang/Basic/TokenKinds.def"
3407#define TYPE_TRAIT_N(Spelling, Name, Key) \
3408 case tok::kw_ ## Spelling: return TT_ ## Name;
3409#include "clang/Basic/TokenKinds.def"
3416 llvm_unreachable(
"Not a known array type trait");
3417#define ARRAY_TYPE_TRAIT(Spelling, Name, Key) \
3418 case tok::kw_##Spelling: \
3420#include "clang/Basic/TokenKinds.def"
3427 llvm_unreachable(
"Not a known unary expression trait.");
3428#define EXPRESSION_TRAIT(Spelling, Name, Key) \
3429 case tok::kw_##Spelling: \
3431#include "clang/Basic/TokenKinds.def"
3441 if (
Parens.expectAndConsume())
3444 SmallVector<ParsedType, 2> Args;
3457 if (Tok.is(tok::ellipsis)) {
3466 Args.push_back(Ty.
get());
3469 if (
Parens.consumeClose())
3472 SourceLocation EndLoc =
Parens.getCloseLocation();
3482 if (T.expectAndConsume())
3494 case ATT_ArrayRank: {
3496 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(),
nullptr,
3497 T.getCloseLocation());
3499 case ATT_ArrayExtent: {
3500 if (ExpectAndConsume(tok::comma)) {
3511 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(), DimExpr.
get(),
3512 T.getCloseLocation());
3515 llvm_unreachable(
"Invalid ArrayTypeTrait!");
3523 if (T.expectAndConsume())
3530 return Actions.ActOnExpressionTrait(ET, Loc, Expr.
get(),
3531 T.getCloseLocation());
3541 "Compound literals are not ambiguous!");
3542 assert(isTypeIdInParens() &&
"Not a type-id!");
3571 if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) {
3577 if (Tok.is(tok::l_brace)) {
3581 if (Tok.is(tok::l_paren) &&
NextToken().
is(tok::r_paren)) {
3589 false , NotCastExpr,
3602 AttrEnd.startToken();
3603 AttrEnd.setKind(tok::eof);
3604 AttrEnd.setLocation(Tok.getLocation());
3605 AttrEnd.setEofData(Toks.data());
3606 Toks.push_back(AttrEnd);
3609 Toks.push_back(Tok);
3612 PP.EnterTokenStream(Toks,
true,
3620 DeclSpec DS(AttrFactory);
3625 ParseSpecifierQualifierList(DS);
3626 ParseDeclarator(DeclaratorInfo);
3634 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3639 if (DeclaratorInfo.isInvalidType())
3642 TypeResult Ty = Actions.ActOnTypeName(DeclaratorInfo);
3643 return ParseCompoundLiteralExpression(Ty.
get(),
3651 if (DeclaratorInfo.isInvalidType())
3657 DeclaratorInfo, CastTy,
3667 if (!
Result.isInvalid() && Tok.is(tok::r_paren))
3669 Tok.getLocation(),
Result.get());
3672 if (
Result.isInvalid()) {
3673 while (Tok.isNot(tok::eof))
3675 assert(Tok.getEofData() == AttrEnd.getEofData());
3682 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3691 if (T.expectAndConsume(diag::err_expected_lparen_after,
"__builtin_bit_cast"))
3695 DeclSpec DS(AttrFactory);
3696 ParseSpecifierQualifierList(DS);
3701 ParseDeclarator(DeclaratorInfo);
3703 if (ExpectAndConsume(tok::comma)) {
3704 Diag(Tok.getLocation(), diag::err_expected) << tok::comma;
3711 if (T.consumeClose())
3714 if (
Operand.isInvalid() || DeclaratorInfo.isInvalidType())
3717 return Actions.ActOnBuiltinBitCastExpr(KWLoc, DeclaratorInfo, Operand,
3718 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.