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) {
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,
259 ObjectType =
nullptr;
267 if (Tok.is(tok::kw_template)) {
271 if (!HasScopeSpecifier && !ObjectType)
274 TentativeParsingAction TPA(*
this);
278 if (Tok.is(tok::identifier)) {
280 TemplateName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
282 }
else if (Tok.is(tok::kw_operator)) {
287 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
296 diag::err_id_after_template_in_nested_name_spec)
309 if (Tok.isNot(tok::less)) {
320 if (AnnotateTemplateIdToken(
Template, TNK, SS, TemplateKWLoc,
327 if (Tok.is(tok::annot_template_id) &&
NextToken().
is(tok::coloncolon)) {
335 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
337 *MayBePseudoDestructor =
true;
342 *LastII = TemplateId->
Name;
345 ConsumeAnnotationToken();
347 assert(Tok.is(tok::coloncolon) &&
"NextToken() not working properly!");
350 HasScopeSpecifier =
true;
366 SourceLocation StartLoc
375 switch (Tok.getKind()) {
376#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
377#include "clang/Basic/TransformTypeTraits.def"
379 Tok.setKind(tok::identifier);
380 Diag(Tok, diag::ext_keyword_as_ident)
381 << Tok.getIdentifierInfo()->getName() << 0;
391 if (Tok.isNot(tok::identifier))
394 IdentifierInfo &II = *Tok.getIdentifierInfo();
401 Sema::NestedNameSpecInfo IdInfo(&II, Tok.getLocation(),
Next.getLocation(),
406 if (
Next.is(tok::colon) && !ColonIsSacred) {
407 if (Actions.IsInvalidUnlessNestedName(
getCurScope(), SS, IdInfo,
412 PP.LookAhead(1).is(tok::identifier)) {
413 Diag(
Next, diag::err_unexpected_colon_in_nested_name_spec)
416 Next.setKind(tok::coloncolon);
423 Token Identifier = Tok;
427 UnconsumeToken(Identifier);
431 if (
Next.is(tok::coloncolon)) {
433 *MayBePseudoDestructor =
true;
439 if (Next2.
is(tok::kw_private) || Next2.
is(tok::kw_protected) ||
440 Next2.
is(tok::kw_public) || Next2.
is(tok::kw_virtual)) {
441 Diag(Next2, diag::err_unexpected_token_in_nested_name_spec)
446 ColonColon.
setKind(tok::colon);
447 PP.EnterToken(ColonColon,
true);
457 Token Identifier = Tok;
459 assert(Tok.isOneOf(tok::coloncolon, tok::colon) &&
460 "NextToken() not working properly!");
461 Token ColonColon = Tok;
464 bool IsCorrectedToColon =
false;
465 bool *CorrectionFlagPtr = ColonIsSacred ? &IsCorrectedToColon :
nullptr;
466 if (Actions.ActOnCXXNestedNameSpecifier(
467 getCurScope(), IdInfo, EnteringContext, SS, CorrectionFlagPtr,
471 if (CorrectionFlagPtr && IsCorrectedToColon) {
472 ColonColon.
setKind(tok::colon);
473 PP.EnterToken(Tok,
true);
474 PP.EnterToken(ColonColon,
true);
480 HasScopeSpecifier =
true;
484 CheckForTemplateAndDigraph(
Next, ObjectType, EnteringContext, II, SS);
488 if (
Next.is(tok::less)) {
493 bool MemberOfUnknownSpecialization;
497 EnteringContext,
Template, MemberOfUnknownSpecialization,
504 isTemplateArgumentList(1) == TPResult::False)
515 if (AnnotateTemplateIdToken(
Template, TNK, SS, SourceLocation(),
521 if (MemberOfUnknownSpecialization && !Disambiguation &&
522 (ObjectType || SS.
isSet()) &&
523 (IsTypename || isTemplateArgumentList(1) == TPResult::True)) {
526 if (!ObjectHadErrors) {
531 unsigned DiagID = diag::err_missing_dependent_template_keyword;
533 DiagID = diag::warn_missing_dependent_template_keyword;
535 Diag(Tok.getLocation(), DiagID)
543 ObjectType, EnteringContext,
Template,
545 if (AnnotateTemplateIdToken(
Template, TNK, SS, SourceLocation(),
561 if (CheckForDestructor && !HasScopeSpecifier && Tok.is(tok::tilde))
562 *MayBePseudoDestructor =
true;
568 bool isAddressOfOperand,
569 Token &Replacement) {
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,
628 E = tryParseCXXPackIndexingExpression(E);
631 checkPotentialAngleBracket(E);
636 assert(Tok.is(tok::ellipsis) &&
NextToken().
is(tok::l_square) &&
642 if (
T.consumeClose() || IndexExpr.
isInvalid())
644 return Actions.ActOnPackIndexingExpr(
getCurScope(), PackIdExpression.
get(),
645 EllipsisLoc,
T.getOpenLocation(),
646 IndexExpr.
get(),
T.getCloseLocation());
650Parser::tryParseCXXPackIndexingExpression(
ExprResult PackIdExpression) {
653 Tok.is(tok::ellipsis) &&
NextToken().
is(tok::l_square)) {
654 E = ParseCXXPackIndexingExpression(E);
659ExprResult Parser::ParseCXXIdExpression(
bool isAddressOfOperand) {
665 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
671 tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement);
675 UnconsumeToken(Replacement);
676 Result = tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement);
678 assert(!
Result.isUnset() &&
"Typo correction suggested a keyword replacement "
679 "for a previous keyword suggestion");
685 LambdaIntroducer Intro;
686 if (ParseLambdaIntroducer(Intro)) {
693 return ParseLambdaExpressionAfterIntroducer(Intro);
696ExprResult Parser::TryParseLambdaExpression() {
698 "Not at the start of a possible lambda expression.");
701 if (
Next.is(tok::eof))
706 if (
Next.is(tok::r_square) ||
707 Next.is(tok::equal) ||
708 (
Next.is(tok::amp) &&
709 After.isOneOf(tok::r_square, tok::comma)) ||
710 (
Next.is(tok::identifier) &&
711 After.is(tok::r_square)) ||
712 Next.is(tok::ellipsis)) {
713 return ParseLambdaExpression();
718 if (
Next.is(tok::identifier) &&
After.is(tok::identifier))
726 LambdaIntroducer Intro;
728 TentativeParsingAction TPA(*
this);
729 LambdaIntroducerTentativeParse Tentative;
730 if (ParseLambdaIntroducer(Intro, &Tentative)) {
736 case LambdaIntroducerTentativeParse::Success:
740 case LambdaIntroducerTentativeParse::Incomplete:
744 Intro = LambdaIntroducer();
745 if (ParseLambdaIntroducer(Intro))
749 case LambdaIntroducerTentativeParse::MessageSend:
750 case LambdaIntroducerTentativeParse::Invalid:
757 return ParseLambdaExpressionAfterIntroducer(Intro);
761 LambdaIntroducerTentativeParse *Tentative) {
763 *Tentative = LambdaIntroducerTentativeParse::Success;
765 assert(Tok.is(tok::l_square) &&
"Lambda expressions begin with '['.");
775 auto Result = [&](llvm::function_ref<void()> Action,
776 LambdaIntroducerTentativeParse State =
777 LambdaIntroducerTentativeParse::Invalid) {
788 auto NonTentativeAction = [&](llvm::function_ref<void()> Action) {
790 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
796 if (Tok.is(tok::amp) &&
801 if (!Tok.getIdentifierInfo()) {
806 }
else if (Tok.is(tok::equal)) {
813 while (Tok.isNot(tok::r_square)) {
815 if (Tok.isNot(tok::comma)) {
820 if (Tok.is(tok::code_completion) &&
823 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
830 Diag(Tok.getLocation(), diag::err_expected_comma_or_rsquare);
836 if (Tok.is(tok::code_completion)) {
841 Actions.CodeCompletion().CodeCompleteObjCMessageReceiver(
getCurScope());
843 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
855 IdentifierInfo *Id =
nullptr;
856 SourceLocation EllipsisLocs[4];
858 SourceLocation LocStart = Tok.getLocation();
860 if (Tok.is(tok::star)) {
862 if (Tok.is(tok::kw_this)) {
867 Diag(Tok.getLocation(), diag::err_expected_star_this_capture);
870 }
else if (Tok.is(tok::kw_this)) {
873 }
else if (Tok.isOneOf(tok::amp, tok::equal) &&
881 [&] {
Diag(Tok.getLocation(), diag::err_capture_default_first); },
882 LambdaIntroducerTentativeParse::Incomplete);
886 if (Tok.is(tok::amp)) {
890 if (Tok.is(tok::code_completion)) {
892 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
901 if (Tok.is(tok::identifier)) {
902 Id = Tok.getIdentifierInfo();
904 }
else if (Tok.is(tok::kw_this)) {
907 Diag(Tok.getLocation(), diag::err_this_captured_by_reference);
911 [&] {
Diag(Tok.getLocation(), diag::err_expected_capture); });
916 if (Tok.is(tok::l_paren)) {
925 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
926 }
else if (ParseExpressionList(Exprs)) {
931 Init = Actions.ActOnParenListExpr(
Parens.getOpenLocation(),
932 Parens.getCloseLocation(),
935 }
else if (Tok.isOneOf(tok::l_brace, tok::equal)) {
939 EnterExpressionEvaluationContext EC(
948 Init = ParseInitializer();
949 }
else if (Tok.is(tok::l_brace)) {
953 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
975 SourceLocation StartLoc = Tok.getLocation();
977 Init = ParseInitializer();
979 if (Tok.getLocation() != StartLoc) {
981 PP.RevertCachedTokens(1);
984 Tok.setLocation(StartLoc);
985 Tok.setKind(tok::annot_primary_expr);
986 setExprAnnotation(Tok,
Init);
987 Tok.setAnnotationEndLoc(PP.getLastCachedTokenLocation());
988 PP.AnnotateCachedTokens(Tok);
991 ConsumeAnnotationToken();
1000 if (Tentative && Tok.is(tok::identifier) &&
1003 *Tentative = LambdaIntroducerTentativeParse::MessageSend;
1008 SourceLocation EllipsisLoc;
1009 if (llvm::any_of(EllipsisLocs,
1010 [](SourceLocation Loc) {
return Loc.
isValid(); })) {
1014 SourceLocation *ExpectedEllipsisLoc =
1015 !InitCapture ? &EllipsisLocs[2] :
1018 EllipsisLoc = *ExpectedEllipsisLoc;
1020 unsigned DiagID = 0;
1022 DiagID = diag::err_lambda_capture_misplaced_ellipsis;
1023 for (SourceLocation Loc : EllipsisLocs) {
1028 unsigned NumEllipses = std::accumulate(
1029 std::begin(EllipsisLocs), std::end(EllipsisLocs), 0,
1030 [](
int N, SourceLocation Loc) {
return N + Loc.
isValid(); });
1031 if (NumEllipses > 1)
1032 DiagID = diag::err_lambda_capture_multiple_ellipses;
1035 NonTentativeAction([&] {
1037 SourceLocation DiagLoc;
1038 for (SourceLocation &Loc : EllipsisLocs) {
1039 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid()) {
1044 assert(DiagLoc.
isValid() &&
"no location for diagnostic");
1048 auto &&D =
Diag(DiagLoc, DiagID);
1049 if (DiagID == diag::err_lambda_capture_misplaced_ellipsis) {
1050 SourceLocation ExpectedLoc =
1056 for (SourceLocation &Loc : EllipsisLocs) {
1057 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid())
1069 if (
Init.isUsable()) {
1070 NonTentativeAction([&] {
1073 Expr *InitExpr =
Init.get();
1076 InitCaptureType = Actions.actOnLambdaInitCaptureInitialization(
1077 Loc, Kind ==
LCK_ByRef, EllipsisLoc, Id, InitKind, InitExpr);
1082 SourceLocation LocEnd = PrevTokLocation;
1085 InitCaptureType, SourceRange(LocStart, LocEnd));
1107 auto ConsumeLocation = [&P, &DeclEndLoc](
SourceLocation &SpecifierLoc,
1109 if (SpecifierLoc.isValid()) {
1111 diag::err_lambda_decl_specifier_repeated)
1116 DeclEndLoc = SpecifierLoc;
1121 case tok::kw_mutable:
1122 ConsumeLocation(MutableLoc, 0);
1124 case tok::kw_static:
1125 ConsumeLocation(StaticLoc, 1);
1127 case tok::kw_constexpr:
1128 ConsumeLocation(ConstexprLoc, 2);
1130 case tok::kw_consteval:
1131 ConsumeLocation(ConstevalLoc, 3);
1143 ? diag::err_static_lambda
1144 : diag::warn_cxx20_compat_static_lambda);
1145 const char *PrevSpec =
nullptr;
1146 unsigned DiagID = 0;
1150 assert(PrevSpec ==
nullptr && DiagID == 0 &&
1151 "Static cannot have been set previously!");
1160 ? diag::ext_constexpr_on_lambda_cxx17
1161 : diag::warn_cxx14_compat_constexpr_on_lambda);
1162 const char *PrevSpec =
nullptr;
1163 unsigned DiagID = 0;
1166 assert(PrevSpec ==
nullptr && DiagID == 0 &&
1167 "Constexpr cannot have been set previously!");
1175 P.
Diag(ConstevalLoc, diag::warn_cxx20_compat_consteval);
1176 const char *PrevSpec =
nullptr;
1177 unsigned DiagID = 0;
1181 P.
Diag(ConstevalLoc, DiagID) << PrevSpec;
1197 P.
Diag(StaticLoc, diag::err_static_mutable_lambda);
1199 P.
Diag(StaticLoc, diag::err_static_lambda_captures);
1203ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
1207 Diag(LambdaBeginLoc, diag::ext_hlsl_lambda) << 1;
1210 ? diag::warn_cxx98_compat_lambda
1214 PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), LambdaBeginLoc,
1215 "lambda expression parsing");
1218 DeclSpec DS(AttrFactory);
1220 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1226 Actions.PushLambdaScope();
1227 Actions.ActOnLambdaExpressionAfterIntroducer(Intro,
getCurScope());
1229 ParsedAttributes Attributes(AttrFactory);
1237 if (Tok.is(tok::kw___noinline__)) {
1238 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1240 Attributes.addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
1242 0, tok::kw___noinline__);
1243 }
else if (Tok.is(tok::kw___attribute))
1244 ParseGNUAttributes(Attributes,
nullptr, &D);
1249 D.takeAttributesAppending(Attributes);
1253 if (Tok.is(tok::less)) {
1255 ? diag::warn_cxx17_compat_lambda_template_parameter_list
1256 : diag::ext_lambda_template_parameter_list);
1258 SmallVector<NamedDecl*, 4> TemplateParams;
1259 SourceLocation LAngleLoc, RAngleLoc;
1260 if (ParseTemplateParameters(TemplateParamScope,
1261 CurTemplateDepthTracker.getDepth(),
1262 TemplateParams, LAngleLoc, RAngleLoc)) {
1263 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1267 if (TemplateParams.empty()) {
1269 diag::err_lambda_template_parameter_list_empty);
1280 ++CurTemplateDepthTracker;
1290 Actions.ActOnLambdaExplicitTemplateParameterList(
1291 Intro, LAngleLoc, TemplateParams, RAngleLoc, RequiresClause);
1299 if (isCXX11AttributeSpecifier() !=
1302 ? diag::warn_cxx20_compat_decl_attrs_on_lambda
1303 : diag::ext_decl_attrs_on_lambda)
1304 << Tok.isRegularKeywordAttribute() << Tok.getIdentifierInfo();
1305 MaybeParseCXX11Attributes(D);
1309 SourceLocation TrailingReturnTypeLoc;
1310 SourceLocation LParenLoc, RParenLoc;
1311 SourceLocation DeclEndLoc;
1312 bool HasParentheses =
false;
1313 bool HasSpecifiers =
false;
1314 SourceLocation MutableLoc;
1321 SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
1322 SourceLocation EllipsisLoc;
1324 if (Tok.is(tok::l_paren)) {
1327 LParenLoc =
T.getOpenLocation();
1329 if (Tok.isNot(tok::r_paren)) {
1330 Actions.RecordParsingTemplateParameterDepth(
1331 CurTemplateDepthTracker.getOriginalDepth());
1333 ParseParameterDeclarationClause(D, Attributes, ParamInfo, EllipsisLoc);
1339 if (Actions.getCurGenericLambda())
1340 CurTemplateDepthTracker.setAddedDepth(1);
1344 DeclEndLoc = RParenLoc =
T.getCloseLocation();
1345 HasParentheses =
true;
1349 Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
1350 tok::kw_constexpr, tok::kw_consteval, tok::kw_static,
1351 tok::kw___private, tok::kw___global, tok::kw___local,
1352 tok::kw___constant, tok::kw___generic, tok::kw_groupshared,
1353 tok::kw_requires, tok::kw_noexcept) ||
1354 Tok.isRegularKeywordAttribute() ||
1355 (Tok.is(tok::l_square) &&
NextToken().
is(tok::l_square));
1361 Diag(Tok, diag::ext_lambda_missing_parens)
1365 if (HasParentheses || HasSpecifiers) {
1369 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec, Attributes);
1372 SourceLocation ConstexprLoc;
1373 SourceLocation ConstevalLoc;
1374 SourceLocation StaticLoc;
1377 ConstevalLoc, DeclEndLoc);
1386 Actions.ActOnLambdaClosureParameters(
getCurScope(), ParamInfo);
1388 if (!HasParentheses)
1389 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1391 if (HasSpecifiers || HasParentheses) {
1394 SourceRange ESpecRange;
1395 SmallVector<ParsedType, 2> DynamicExceptions;
1396 SmallVector<SourceRange, 2> DynamicExceptionRanges;
1400 ESpecType = tryParseExceptionSpecification(
1401 false, ESpecRange, DynamicExceptions,
1402 DynamicExceptionRanges, NoexceptExpr, ExceptionSpecTokens);
1405 DeclEndLoc = ESpecRange.
getEnd();
1408 if (MaybeParseCXX11Attributes(Attributes))
1409 DeclEndLoc = Attributes.Range.getEnd();
1412 if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
1413 tok::kw___constant, tok::kw___generic)) {
1414 ParseOpenCLQualifiers(DS.getAttributes());
1418 SourceLocation FunLocalRangeEnd = DeclEndLoc;
1421 if (Tok.is(tok::arrow)) {
1422 FunLocalRangeEnd = Tok.getLocation();
1424 TrailingReturnType =
1425 ParseTrailingReturnType(Range,
false);
1426 TrailingReturnTypeLoc =
Range.getBegin();
1427 if (
Range.getEnd().isValid())
1428 DeclEndLoc =
Range.getEnd();
1431 SourceLocation NoLoc;
1434 false, LParenLoc, ParamInfo.data(),
1435 ParamInfo.size(), EllipsisLoc, RParenLoc,
1437 NoLoc, MutableLoc, ESpecType,
1438 ESpecRange, DynamicExceptions.data(),
1439 DynamicExceptionRanges.data(), DynamicExceptions.size(),
1440 NoexceptExpr.
isUsable() ? NoexceptExpr.
get() :
nullptr,
1442 {}, LParenLoc, FunLocalRangeEnd, D,
1443 TrailingReturnType, TrailingReturnTypeLoc, &DS),
1444 std::move(Attributes), DeclEndLoc);
1449 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1451 if (HasParentheses && Tok.is(tok::kw_requires))
1452 ParseTrailingRequiresClause(D);
1458 for (
const ParsedAttr &A : Attributes)
1459 if (A.getKind() == ParsedAttr::AT_CUDADevice ||
1460 A.getKind() == ParsedAttr::AT_CUDAHost ||
1461 A.getKind() == ParsedAttr::AT_CUDAGlobal)
1462 Diag(A.getLoc(), diag::warn_cuda_attr_lambda_position)
1463 << A.getAttrName()->getName();
1474 Actions.ActOnStartOfLambdaDefinition(Intro, D, DS);
1477 if (!Tok.is(tok::l_brace)) {
1478 Diag(Tok, diag::err_expected_lambda_body);
1479 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1483 StmtResult Stmt(ParseCompoundStatementBody());
1485 TemplateParamScope.Exit();
1488 if (!Stmt.isInvalid() && !TrailingReturnType.
isInvalid() &&
1490 return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.get());
1492 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1498 const char *CastName =
nullptr;
1501 default: llvm_unreachable(
"Unknown C++ cast!");
1502 case tok::kw_addrspace_cast: CastName =
"addrspace_cast";
break;
1503 case tok::kw_const_cast: CastName =
"const_cast";
break;
1504 case tok::kw_dynamic_cast: CastName =
"dynamic_cast";
break;
1505 case tok::kw_reinterpret_cast: CastName =
"reinterpret_cast";
break;
1506 case tok::kw_static_cast: CastName =
"static_cast";
break;
1510 SourceLocation LAngleBracketLoc = Tok.getLocation();
1514 if (Tok.is(tok::l_square) && Tok.getLength() == 2) {
1516 if (
Next.is(tok::colon) && areTokensAdjacent(Tok,
Next))
1520 if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName))
1524 DeclSpec DS(AttrFactory);
1525 ParseSpecifierQualifierList(DS,
AS_none,
1526 DeclSpecContext::DSC_type_specifier);
1531 ParseDeclarator(DeclaratorInfo);
1533 SourceLocation RAngleBracketLoc = Tok.getLocation();
1535 if (ExpectAndConsume(tok::greater))
1536 return ExprError(
Diag(LAngleBracketLoc, diag::note_matching) << tok::less);
1540 if (
T.expectAndConsume(diag::err_expected_lparen_after, CastName))
1548 if (!
Result.isInvalid() && !DeclaratorInfo.isInvalidType())
1549 Result = Actions.ActOnCXXNamedCast(OpLoc, Kind,
1550 LAngleBracketLoc, DeclaratorInfo,
1552 T.getOpenLocation(),
Result.get(),
1553 T.getCloseLocation());
1559 assert(Tok.is(tok::kw_typeid) &&
"Not 'typeid'!");
1562 SourceLocation LParenLoc, RParenLoc;
1566 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"typeid"))
1568 LParenLoc =
T.getOpenLocation();
1589 if (isTypeIdInParens()) {
1594 RParenLoc =
T.getCloseLocation();
1598 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
true,
1608 RParenLoc =
T.getCloseLocation();
1612 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
false,
1613 Result.get(), RParenLoc);
1621 assert(Tok.is(tok::kw___uuidof) &&
"Not '__uuidof'!");
1627 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"__uuidof"))
1632 if (isTypeIdInParens()) {
1641 Result = Actions.ActOnCXXUuidof(OpLoc,
T.getOpenLocation(),
true,
1643 T.getCloseLocation());
1655 Result = Actions.ActOnCXXUuidof(OpLoc,
T.getOpenLocation(),
1657 Result.get(),
T.getCloseLocation());
1672 SourceLocation CCLoc;
1673 if (Tok.is(tok::identifier)) {
1674 FirstTypeName.
setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
1676 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1678 }
else if (Tok.is(tok::annot_template_id)) {
1679 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
1684 ConsumeAnnotationToken();
1685 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1688 assert(SS.
isEmpty() &&
"missing last component of nested name specifier");
1693 assert(Tok.is(tok::tilde) &&
"ParseOptionalCXXScopeSpecifier fail");
1696 if (Tok.is(tok::kw_decltype) && !FirstTypeName.
isValid()) {
1697 DeclSpec DS(AttrFactory);
1698 ParseDecltypeSpecifier(DS);
1701 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1705 if (!Tok.is(tok::identifier)) {
1706 Diag(Tok, diag::err_destructor_tilde_identifier);
1713 DeclSpec DS(AttrFactory);
1714 ParsePackIndexingType(DS);
1715 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1721 IdentifierInfo *Name = Tok.getIdentifierInfo();
1733 if (Tok.is(tok::less) &&
1734 ParseUnqualifiedIdTemplateId(
1735 SS, ObjectType, Base &&
Base->containsErrors(), SourceLocation(),
1736 Name, NameLoc,
false, SecondTypeName,
1740 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1741 SS, FirstTypeName, CCLoc, TildeLoc,
1747 return Actions.ActOnCXXBoolLiteral(
ConsumeToken(), Kind);
1751 assert(Tok.is(tok::kw_throw) &&
"Not throw!");
1757 switch (Tok.getKind()) {
1764 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc,
nullptr);
1768 if (Expr.isInvalid())
return Expr;
1769 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc, Expr.get());
1774 assert(Tok.is(tok::kw_co_yield) &&
"Not co_yield!");
1777 ExprResult Expr = Tok.is(tok::l_brace) ? ParseBraceInitializer()
1785 assert(Tok.is(tok::kw_this) &&
"Not 'this'!");
1787 return Actions.ActOnCXXThis(ThisLoc);
1791Parser::ParseCXXTypeConstructExpression(
const DeclSpec &DS) {
1794 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
1796 assert((Tok.is(tok::l_paren) ||
1798 &&
"Expected '(' or '{'!");
1800 if (Tok.is(tok::l_brace)) {
1801 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1803 if (
Init.isInvalid())
1806 return Actions.ActOnCXXTypeConstructExpr(
1813 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1817 auto RunSignatureHelp = [&]() {
1818 QualType PreferredType;
1821 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
1823 Exprs,
T.getOpenLocation(),
false);
1824 CalledSignatureHelp =
true;
1825 return PreferredType;
1828 if (Tok.isNot(tok::r_paren)) {
1829 if (ParseExpressionList(Exprs, [&] {
1830 PreferredType.enterFunctionArgument(Tok.getLocation(),
1833 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
1847 return Actions.ActOnCXXTypeConstructExpr(TypeRep,
T.getOpenLocation(),
1848 Exprs,
T.getCloseLocation(),
1856 assert(Tok.is(tok::kw_using) &&
"Expected using");
1859 "Unexpected Declarator Context");
1863 DG = ParseUsingDeclaration(Context, {}, DeclStart, DeclEnd, Attrs,
AS_none);
1868 ? diag::ext_alias_in_init_statement
1869 : diag::warn_cxx20_alias_in_init_statement)
1870 << SourceRange(DeclStart, DeclEnd);
1878 ForRangeInfo *FRI,
bool EnterForConditionScope) {
1880 struct ForConditionScopeRAII {
1882 void enter(
bool IsConditionVariable) {
1888 ~ForConditionScopeRAII() {
1895 PreferredType.enterCondition(Actions, Tok.getLocation());
1897 if (Tok.is(tok::code_completion)) {
1899 Actions.CodeCompletion().CodeCompleteOrdinaryName(
1904 ParsedAttributes attrs(AttrFactory);
1905 MaybeParseCXX11Attributes(attrs);
1907 const auto WarnOnInit = [
this, &CK] {
1909 ? diag::warn_cxx14_compat_init_statement
1910 : diag::ext_init_statement)
1915 switch (isCXXConditionDeclarationOrInitStatement(InitStmt, FRI)) {
1916 case ConditionOrInitStatement::Expression: {
1918 ForConditionScope.enter(
false);
1920 ProhibitAttributes(attrs);
1924 if (InitStmt && Tok.is(tok::semi)) {
1926 SourceLocation SemiLoc = Tok.getLocation();
1927 if (!Tok.hasLeadingEmptyMacro() && !SemiLoc.
isMacroID()) {
1928 Diag(SemiLoc, diag::warn_empty_init_statement)
1933 *InitStmt = Actions.ActOnNullStmt(SemiLoc);
1934 return ParseCXXCondition(
nullptr, Loc, CK, MissingOK);
1937 EnterExpressionEvaluationContext Eval(
1948 if (InitStmt && Tok.is(tok::semi)) {
1950 *InitStmt = Actions.ActOnExprStmt(Expr.
get());
1952 return ParseCXXCondition(
nullptr, Loc, CK, MissingOK);
1955 return Actions.ActOnCondition(
getCurScope(), Loc, Expr.
get(), CK,
1959 case ConditionOrInitStatement::InitStmtDecl: {
1962 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
1963 if (Tok.is(tok::kw_using))
1964 DG = ParseAliasDeclarationInInitStatement(
1967 ParsedAttributes DeclSpecAttrs(AttrFactory);
1969 attrs, DeclSpecAttrs,
true);
1971 *InitStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd);
1972 return ParseCXXCondition(
nullptr, Loc, CK, MissingOK);
1975 case ConditionOrInitStatement::ForRangeDecl: {
1979 assert(FRI &&
"should not parse a for range declaration here");
1980 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
1981 ParsedAttributes DeclSpecAttrs(AttrFactory);
1984 FRI->LoopVar = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
1985 return Sema::ConditionResult();
1988 case ConditionOrInitStatement::ConditionDecl:
1989 case ConditionOrInitStatement::Error:
1994 ForConditionScope.enter(
true);
1997 DeclSpec DS(AttrFactory);
1998 ParseSpecifierQualifierList(DS,
AS_none, DeclSpecContext::DSC_condition);
2002 ParseDeclarator(DeclaratorInfo);
2005 if (Tok.is(tok::kw_asm)) {
2007 ExprResult AsmLabel(ParseSimpleAsm(
true, &Loc));
2008 if (AsmLabel.isInvalid()) {
2012 DeclaratorInfo.setAsmLabel(AsmLabel.get());
2013 DeclaratorInfo.SetRangeEnd(Loc);
2017 MaybeParseGNUAttributes(DeclaratorInfo);
2028 bool CopyInitialization = isTokenEqualOrEqualTypo();
2029 if (CopyInitialization)
2034 Diag(Tok.getLocation(),
2035 diag::warn_cxx98_compat_generalized_initializer_lists);
2036 InitExpr = ParseBraceInitializer();
2037 }
else if (CopyInitialization) {
2038 PreferredType.enterVariableInit(Tok.getLocation(), DeclOut);
2040 }
else if (Tok.is(tok::l_paren)) {
2042 SourceLocation LParen = ConsumeParen(), RParen = LParen;
2044 RParen = ConsumeParen();
2046 diag::err_expected_init_in_condition_lparen)
2047 << SourceRange(LParen, RParen);
2053 Actions.AddInitializerToDecl(DeclOut, InitExpr.
get(), !CopyInitialization);
2055 Actions.ActOnInitializerError(DeclOut);
2057 Actions.FinalizeDeclaration(DeclOut);
2058 return Actions.ActOnConditionVariable(DeclOut, Loc, CK);
2061void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) {
2063 const char *PrevSpec;
2065 SourceLocation Loc = Tok.getLocation();
2066 const clang::PrintingPolicy &Policy =
2067 Actions.getASTContext().getPrintingPolicy();
2069 switch (Tok.getKind()) {
2070 case tok::identifier:
2071 case tok::coloncolon:
2072 llvm_unreachable(
"Annotation token should already be formed!");
2074 llvm_unreachable(
"Not a simple-type-specifier token!");
2077 case tok::annot_typename: {
2081 ConsumeAnnotationToken();
2082 DS.
Finish(Actions, Policy);
2086 case tok::kw__ExtInt:
2087 case tok::kw__BitInt: {
2088 DiagnoseBitIntUse(Tok);
2097 DS.
Finish(Actions, Policy);
2110 case tok::kw___int64:
2114 case tok::kw_signed:
2117 case tok::kw_unsigned:
2132 case tok::kw___int128:
2135 case tok::kw___bf16:
2144 case tok::kw_double:
2147 case tok::kw__Float16:
2150 case tok::kw___float128:
2153 case tok::kw___ibm128:
2156 case tok::kw_wchar_t:
2159 case tok::kw_char8_t:
2162 case tok::kw_char16_t:
2165 case tok::kw_char32_t:
2171 case tok::kw__Accum:
2174 case tok::kw__Fract:
2180#define GENERIC_IMAGE_TYPE(ImgType, Id) \
2181 case tok::kw_##ImgType##_t: \
2182 DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, DiagID, \
2185#include "clang/Basic/OpenCLImageTypes.def"
2186#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
2187 case tok::kw_##Name: \
2188 DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, DiagID, Policy); \
2190#include "clang/Basic/HLSLIntangibleTypes.def"
2192 case tok::annot_decltype:
2193 case tok::kw_decltype:
2195 return DS.
Finish(Actions, Policy);
2197 case tok::annot_pack_indexing_type:
2199 return DS.
Finish(Actions, Policy);
2202 case tok::kw_typeof:
2203 ParseTypeofSpecifier(DS);
2204 DS.
Finish(Actions, Policy);
2209 DS.
Finish(Actions, Policy);
2213 ParseSpecifierQualifierList(DS,
AS_none,
2214 getDeclSpecContextFromDeclaratorContext(Context));
2215 DS.
Finish(Actions, Actions.getASTContext().getPrintingPolicy());
2219bool Parser::ParseUnqualifiedIdTemplateId(
2220 CXXScopeSpec &SS,
ParsedType ObjectType,
bool ObjectHadErrors,
2221 SourceLocation TemplateKWLoc, IdentifierInfo *Name, SourceLocation NameLoc,
2222 bool EnteringContext, UnqualifiedId &Id,
bool AssumeTemplateId) {
2223 assert(Tok.is(tok::less) &&
"Expected '<' to finish parsing a template-id");
2231 if (AssumeTemplateId) {
2234 TNK = Actions.ActOnTemplateName(
getCurScope(), SS, TemplateKWLoc, Id,
2235 ObjectType, EnteringContext,
Template,
2238 bool MemberOfUnknownSpecialization;
2241 ObjectType, EnteringContext,
Template,
2242 MemberOfUnknownSpecialization);
2247 isTemplateArgumentList(0) == TPResult::False)
2251 ObjectType && isTemplateArgumentList(0) == TPResult::True) {
2254 if (!ObjectHadErrors) {
2273 TNK = Actions.ActOnTemplateName(
2274 getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext,
2284 bool MemberOfUnknownSpecialization;
2289 MemberOfUnknownSpecialization);
2297 bool MemberOfUnknownSpecialization;
2300 TNK = Actions.ActOnTemplateName(
2307 MemberOfUnknownSpecialization);
2310 Diag(NameLoc, diag::err_destructor_template_id)
2323 SourceLocation LAngleLoc, RAngleLoc;
2324 TemplateArgList TemplateArgs;
2325 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs, RAngleLoc,
2340 const IdentifierInfo *TemplateII =
2350 LAngleLoc, RAngleLoc, TemplateArgs,
false, TemplateIds);
2362 SourceLocation(), SS, TemplateKWLoc,
Template,
2363 Name, NameLoc, LAngleLoc, TemplateArgsPtr, RAngleLoc,
2365 if (
Type.isInvalid())
2376bool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
2379 assert(Tok.is(tok::kw_operator) &&
"Expected 'operator' keyword");
2385 unsigned SymbolIdx = 0;
2386 SourceLocation SymbolLocations[3];
2388 switch (Tok.getKind()) {
2390 case tok::kw_delete: {
2391 bool isNew = Tok.getKind() == tok::kw_new;
2395 if (Tok.is(tok::l_square) &&
2401 if (
T.getCloseLocation().isInvalid())
2404 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2405 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2406 Op = isNew? OO_Array_New : OO_Array_Delete;
2408 Op = isNew? OO_New : OO_Delete;
2413#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
2415 SymbolLocations[SymbolIdx++] = ConsumeToken(); \
2418#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
2419#include "clang/Basic/OperatorKinds.def"
2421 case tok::l_paren: {
2426 if (
T.getCloseLocation().isInvalid())
2429 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2430 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2435 case tok::l_square: {
2440 if (
T.getCloseLocation().isInvalid())
2443 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2444 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2449 case tok::code_completion: {
2453 Actions.CodeCompletion().CodeCompleteOperatorName(
getCurScope());
2463 Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations);
2474 Diag(Tok.getLocation(), diag::warn_cxx98_compat_literal_operator);
2476 SourceLocation DiagLoc;
2477 unsigned DiagId = 0;
2481 SmallVector<Token, 4> Toks;
2482 SmallVector<SourceLocation, 4> TokLocs;
2483 while (isTokenStringLiteral()) {
2484 if (!Tok.is(tok::string_literal) && !DiagId) {
2488 DiagLoc = Tok.getLocation();
2489 DiagId = diag::err_literal_operator_string_prefix;
2491 Toks.push_back(Tok);
2492 TokLocs.push_back(ConsumeStringToken());
2495 StringLiteralParser
Literal(Toks, PP);
2501 bool IsUDSuffix = !
Literal.getUDSuffix().empty();
2502 IdentifierInfo *II =
nullptr;
2503 SourceLocation SuffixLoc;
2505 II = &PP.getIdentifierTable().get(
Literal.getUDSuffix());
2510 }
else if (Tok.is(tok::identifier)) {
2511 II = Tok.getIdentifierInfo();
2513 TokLocs.push_back(SuffixLoc);
2515 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
2525 DiagLoc = TokLocs.front();
2526 DiagId = diag::err_literal_operator_string_not_empty;
2532 SmallString<32> Str;
2536 SourceRange(TokLocs.front(), TokLocs.back()), Str);
2539 Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
2541 return Actions.checkLiteralOperatorId(SS,
Result, IsUDSuffix);
2556 DeclSpec DS(AttrFactory);
2557 if (ParseCXXTypeSpecifierSeq(
2565 ParseDeclaratorInternal(D,
nullptr);
2573 Result.setConversionFunctionId(KeywordLoc, Ty.
get(),
2574 D.getSourceRange().getEnd());
2579 bool ObjectHadErrors,
bool EnteringContext,
2580 bool AllowDestructorName,
2581 bool AllowConstructorName,
2582 bool AllowDeductionGuide,
2590 bool TemplateSpecified =
false;
2591 if (Tok.is(tok::kw_template)) {
2592 if (TemplateKWLoc && (ObjectType || SS.
isSet())) {
2593 TemplateSpecified =
true;
2597 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2605 if (Tok.is(tok::identifier)) {
2614 Result.setIdentifier(Id, IdLoc);
2619 if (AllowConstructorName &&
2620 Actions.isCurrentClassName(*Id,
getCurScope(), &SS)) {
2626 Result.setConstructorName(Ty, IdLoc, IdLoc);
2629 Actions.isDeductionGuideName(
getCurScope(), *Id, IdLoc, SS,
2635 Result.setIdentifier(Id, IdLoc);
2640 if (Tok.is(tok::less))
2641 return ParseUnqualifiedIdTemplateId(
2642 SS, ObjectType, ObjectHadErrors,
2644 EnteringContext,
Result, TemplateSpecified);
2646 if (TemplateSpecified) {
2649 ObjectType, EnteringContext,
Template,
2660 Diag(IdLoc, diag::missing_template_arg_list_after_template_kw);
2667 if (Tok.is(tok::annot_template_id)) {
2673 ConsumeAnnotationToken();
2678 if (AllowConstructorName && TemplateId->
Name &&
2686 diag::err_out_of_line_constructor_template_id)
2697 ConsumeAnnotationToken();
2701 Result.setConstructorTemplateId(TemplateId);
2702 ConsumeAnnotationToken();
2708 Result.setTemplateId(TemplateId);
2711 if (TemplateKWLoc && (ObjectType || SS.
isSet()))
2712 *TemplateKWLoc = TemplateLoc;
2714 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2717 ConsumeAnnotationToken();
2724 if (Tok.is(tok::kw_operator)) {
2725 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
Result))
2737 return ParseUnqualifiedIdTemplateId(
2738 SS, ObjectType, ObjectHadErrors,
2741 else if (TemplateSpecified &&
2742 Actions.ActOnTemplateName(
2752 (AllowDestructorName || SS.
isSet()) && Tok.is(tok::tilde)) {
2761 if (TemplateSpecified) {
2772 Diag(*TemplateKWLoc, diag::err_unexpected_template_in_destructor_name)
2773 << Tok.getLocation();
2777 if (SS.
isEmpty() && Tok.is(tok::kw_decltype)) {
2781 Actions.getDestructorTypeForDecltype(DS, ObjectType)) {
2782 Result.setDestructorName(TildeLoc,
Type, EndLoc);
2789 if (Tok.isNot(tok::identifier)) {
2790 Diag(Tok, diag::err_destructor_tilde_identifier);
2795 DeclaratorScopeObj DeclScopeObj(*
this, SS);
2803 AnnotateScopeToken(SS,
true);
2806 if (ParseOptionalCXXScopeSpecifier(SS, ObjectType, ObjectHadErrors,
2810 ObjectType =
nullptr;
2811 if (Tok.isNot(tok::identifier) ||
NextToken().
is(tok::coloncolon) ||
2813 Diag(TildeLoc, diag::err_destructor_tilde_scope);
2818 Diag(TildeLoc, diag::err_destructor_tilde_scope)
2823 if (Actions.ShouldEnterDeclaratorScope(
getCurScope(), SS))
2824 DeclScopeObj.EnterDeclaratorScope();
2831 if (Tok.is(tok::less)) {
2832 Result.setDestructorName(TildeLoc,
nullptr, ClassNameLoc);
2833 return ParseUnqualifiedIdTemplateId(
2834 SS, ObjectType, ObjectHadErrors,
2836 ClassNameLoc, EnteringContext,
Result, TemplateSpecified);
2841 Actions.getDestructorName(*ClassName, ClassNameLoc,
getCurScope(), SS,
2842 ObjectType, EnteringContext);
2846 Result.setDestructorName(TildeLoc, Ty, ClassNameLoc);
2850 switch (Tok.getKind()) {
2851#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
2852#include "clang/Basic/TransformTypeTraits.def"
2854 Tok.setKind(tok::identifier);
2855 Diag(Tok, diag::ext_keyword_as_ident)
2856 << Tok.getIdentifierInfo()->getName() << 0;
2857 goto ParseIdentifier;
2861 Diag(Tok, diag::err_expected_unqualified_id) <<
getLangOpts().CPlusPlus;
2867Parser::ParseCXXNewExpression(
bool UseGlobal,
SourceLocation Start) {
2868 assert(
Tok.is(tok::kw_new) &&
"expected 'new' token");
2874 ExprVector PlacementArgs;
2881 if (
Tok.is(tok::l_paren)) {
2885 PlacementLParen =
T.getOpenLocation();
2886 if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) {
2892 PlacementRParen =
T.getCloseLocation();
2898 if (PlacementArgs.empty()) {
2900 TypeIdParens =
T.getRange();
2901 PlacementLParen = PlacementRParen = SourceLocation();
2904 if (Tok.is(tok::l_paren)) {
2907 MaybeParseGNUAttributes(DeclaratorInfo);
2908 ParseSpecifierQualifierList(DS);
2910 ParseDeclarator(DeclaratorInfo);
2912 TypeIdParens =
T.getRange();
2914 MaybeParseGNUAttributes(DeclaratorInfo);
2915 if (ParseCXXTypeSpecifierSeq(DS))
2916 DeclaratorInfo.setInvalidType(
true);
2919 ParseDeclaratorInternal(DeclaratorInfo,
2920 &Parser::ParseDirectNewDeclarator);
2927 MaybeParseGNUAttributes(DeclaratorInfo);
2929 DeclaratorInfo.setInvalidType(
true);
2932 ParseDeclaratorInternal(DeclaratorInfo,
2933 &Parser::ParseDirectNewDeclarator);
2936 if (DeclaratorInfo.isInvalidType()) {
2943 if (Tok.is(tok::l_paren)) {
2944 SourceLocation ConstructorLParen, ConstructorRParen;
2945 ExprVector ConstructorArgs;
2948 ConstructorLParen =
T.getOpenLocation();
2949 if (Tok.isNot(tok::r_paren)) {
2950 auto RunSignatureHelp = [&]() {
2951 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
2952 QualType PreferredType;
2958 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
2960 DeclaratorInfo.getEndLoc(), ConstructorArgs,
2963 CalledSignatureHelp =
true;
2964 return PreferredType;
2966 if (ParseExpressionList(ConstructorArgs, [&] {
2967 PreferredType.enterFunctionArgument(Tok.getLocation(),
2970 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
2977 ConstructorRParen =
T.getCloseLocation();
2982 Initializer = Actions.ActOnParenListExpr(ConstructorLParen,
2986 Diag(Tok.getLocation(),
2987 diag::warn_cxx98_compat_generalized_initializer_lists);
2993 return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen,
2994 PlacementArgs, PlacementRParen,
2998void Parser::ParseDirectNewDeclarator(Declarator &D) {
3001 while (Tok.is(tok::l_square)) {
3003 if (CheckProhibitedCXX11Attribute())
3012 if (
Size.isInvalid()) {
3014 SkipUntil(tok::r_square, StopAtSemi);
3022 ParsedAttributes Attrs(AttrFactory);
3023 MaybeParseCXX11Attributes(Attrs);
3027 Size.get(),
T.getOpenLocation(),
3028 T.getCloseLocation()),
3029 std::move(Attrs),
T.getCloseLocation());
3031 if (
T.getCloseLocation().isInvalid())
3036bool Parser::ParseExpressionListOrTypeId(
3037 SmallVectorImpl<Expr*> &PlacementArgs,
3040 if (isTypeIdInParens()) {
3048 return ParseExpressionList(PlacementArgs);
3052Parser::ParseCXXDeleteExpression(
bool UseGlobal, SourceLocation Start) {
3053 assert(Tok.is(tok::kw_delete) &&
"Expected 'delete' keyword");
3057 bool ArrayDelete =
false;
3058 if (Tok.is(tok::l_square) &&
NextToken().
is(tok::r_square)) {
3069 if (
Next.isOneOf(tok::l_brace, tok::less) ||
3070 (
Next.is(tok::l_paren) &&
3074 TentativeParsingAction TPA(*
this);
3075 SourceLocation LSquareLoc = Tok.getLocation();
3081 SourceLocation RBraceLoc;
3082 bool EmitFixIt =
false;
3083 if (Tok.is(tok::l_brace)) {
3086 RBraceLoc = Tok.getLocation();
3093 Diag(Start, diag::err_lambda_after_delete)
3094 << SourceRange(Start, RSquareLoc)
3098 RBraceLoc, 0, Actions.getSourceManager(),
getLangOpts()),
3101 Diag(Start, diag::err_lambda_after_delete)
3102 << SourceRange(Start, RSquareLoc);
3111 Lambda = ParsePostfixExpressionSuffix(Lambda);
3114 return Actions.ActOnCXXDelete(Start, UseGlobal,
false,
3123 if (
T.getCloseLocation().isInvalid())
3131 return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete,
Operand.get());
3134ExprResult Parser::ParseRequiresExpression() {
3135 assert(Tok.is(tok::kw_requires) &&
"Expected 'requires' keyword");
3138 llvm::SmallVector<ParmVarDecl *, 2> LocalParameterDecls;
3140 if (Tok.is(tok::l_paren)) {
3145 if (!Tok.is(tok::r_paren)) {
3147 SourceLocation EllipsisLoc;
3148 llvm::SmallVector<DeclaratorChunk::ParamInfo, 2> LocalParameters;
3150 FirstArgAttrs, LocalParameters,
3153 Diag(EllipsisLoc, diag::err_requires_expr_parameter_list_ellipsis);
3154 for (
auto &ParamInfo : LocalParameters)
3161 if (
Braces.expectAndConsume())
3165 llvm::SmallVector<concepts::Requirement *, 2> Requirements;
3169 EnterExpressionEvaluationContext Ctx(
3177 RequiresExprBodyDecl *Body = Actions.ActOnStartRequiresExpr(
3178 RequiresKWLoc, LocalParameterDecls,
getCurScope());
3180 if (Tok.is(tok::r_brace)) {
3187 Diag(Tok, diag::err_empty_requires_expr);
3190 while (!Tok.is(tok::r_brace)) {
3191 switch (Tok.getKind()) {
3192 case tok::l_brace: {
3203 ExprBraces.consumeOpen();
3205 if (Expression.isUsable())
3206 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3207 if (!Expression.isUsable()) {
3208 ExprBraces.skipToEnd();
3214 if (ExprBraces.consumeClose())
3217 concepts::Requirement *Req =
nullptr;
3218 SourceLocation NoexceptLoc;
3220 if (Tok.is(tok::semi)) {
3221 Req = Actions.ActOnCompoundRequirement(Expression.get(), NoexceptLoc);
3223 Requirements.push_back(Req);
3228 Diag(Tok, diag::err_requires_expr_missing_arrow)
3231 if (TryAnnotateTypeConstraint()) {
3235 if (!isTypeConstraintAnnotation()) {
3236 Diag(Tok, diag::err_requires_expr_expected_type_constraint);
3241 if (Tok.is(tok::annot_cxxscope)) {
3242 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
3243 Tok.getAnnotationRange(),
3245 ConsumeAnnotationToken();
3248 Req = Actions.ActOnCompoundRequirement(
3249 Expression.get(), NoexceptLoc, SS, takeTemplateIdAnnotation(Tok),
3250 TemplateParameterDepth);
3251 ConsumeAnnotationToken();
3253 Requirements.push_back(Req);
3257 bool PossibleRequiresExprInSimpleRequirement =
false;
3258 if (Tok.is(tok::kw_requires)) {
3259 auto IsNestedRequirement = [&] {
3260 RevertingTentativeParsingAction TPA(*
this);
3262 if (Tok.is(tok::l_brace))
3269 if (Tok.is(tok::l_paren)) {
3272 auto Res = TryParseParameterDeclarationClause();
3273 if (Res != TPResult::False) {
3276 while (Depth != 0) {
3277 bool FoundParen =
SkipUntil(tok::l_paren, tok::r_paren,
3281 if (Tok.is(tok::l_paren))
3283 else if (Tok.is(tok::r_paren))
3294 if (Tok.is(tok::l_brace))
3303 if (IsNestedRequirement()) {
3316 Actions.ActOnNestedRequirement(ConstraintExpr.
get()))
3317 Requirements.push_back(Req);
3325 PossibleRequiresExprInSimpleRequirement =
true;
3326 }
else if (Tok.is(tok::kw_typename)) {
3329 TentativeParsingAction TPA(*
this);
3339 if (Tok.is(tok::annot_cxxscope)) {
3340 Actions.RestoreNestedNameSpecifierAnnotation(
3341 Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS);
3342 ConsumeAnnotationToken();
3345 if (Tok.isOneOf(tok::identifier, tok::annot_template_id) &&
3348 SourceLocation NameLoc = Tok.getLocation();
3349 IdentifierInfo *II =
nullptr;
3350 TemplateIdAnnotation *TemplateId =
nullptr;
3351 if (Tok.is(tok::identifier)) {
3352 II = Tok.getIdentifierInfo();
3355 TemplateId = takeTemplateIdAnnotation(Tok);
3356 ConsumeAnnotationToken();
3361 if (
auto *Req = Actions.ActOnTypeRequirement(TypenameKWLoc, SS,
3364 Requirements.push_back(Req);
3374 SourceLocation StartLoc = Tok.getLocation();
3376 if (Expression.isUsable())
3377 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3378 if (!Expression.isUsable()) {
3382 if (!Expression.isInvalid() && PossibleRequiresExprInSimpleRequirement)
3383 Diag(StartLoc, diag::err_requires_expr_in_simple_requirement)
3385 if (
auto *Req = Actions.ActOnSimpleRequirement(Expression.get()))
3386 Requirements.push_back(Req);
3392 if (Tok.is(tok::kw_noexcept)) {
3393 Diag(Tok, diag::err_requires_expr_simple_requirement_noexcept)
3402 if (ExpectAndConsumeSemi(diag::err_expected_semi_requirement)) {
3408 if (Requirements.empty()) {
3413 Actions.ActOnFinishRequiresExpr();
3418 Actions.ActOnFinishRequiresExpr();
3419 ParsingBodyDecl.complete(Body);
3420 return Actions.ActOnRequiresExpr(
3421 RequiresKWLoc, Body,
Parens.getOpenLocation(), LocalParameterDecls,
3422 Parens.getCloseLocation(), Requirements,
Braces.getCloseLocation());
3427 default: llvm_unreachable(
"Not a known type trait");
3428#define TYPE_TRAIT_1(Spelling, Name, Key) \
3429case tok::kw_ ## Spelling: return UTT_ ## Name;
3430#define TYPE_TRAIT_2(Spelling, Name, Key) \
3431case tok::kw_ ## Spelling: return BTT_ ## Name;
3432#include "clang/Basic/TokenKinds.def"
3433#define TYPE_TRAIT_N(Spelling, Name, Key) \
3434 case tok::kw_ ## Spelling: return TT_ ## Name;
3435#include "clang/Basic/TokenKinds.def"
3442 llvm_unreachable(
"Not a known array type trait");
3443#define ARRAY_TYPE_TRAIT(Spelling, Name, Key) \
3444 case tok::kw_##Spelling: \
3446#include "clang/Basic/TokenKinds.def"
3453 llvm_unreachable(
"Not a known unary expression trait.");
3454#define EXPRESSION_TRAIT(Spelling, Name, Key) \
3455 case tok::kw_##Spelling: \
3457#include "clang/Basic/TokenKinds.def"
3467 if (
Parens.expectAndConsume())
3470 SmallVector<ParsedType, 2> Args;
3483 if (Tok.is(tok::ellipsis)) {
3492 Args.push_back(Ty.
get());
3495 if (
Parens.consumeClose())
3498 SourceLocation EndLoc =
Parens.getCloseLocation();
3508 if (
T.expectAndConsume())
3520 case ATT_ArrayRank: {
3522 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(),
nullptr,
3523 T.getCloseLocation());
3525 case ATT_ArrayExtent: {
3526 if (ExpectAndConsume(tok::comma)) {
3537 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(), DimExpr.
get(),
3538 T.getCloseLocation());
3541 llvm_unreachable(
"Invalid ArrayTypeTrait!");
3549 if (
T.expectAndConsume())
3556 return Actions.ActOnExpressionTrait(ET, Loc, Expr.
get(),
3557 T.getCloseLocation());
3567 "Compound literals are not ambiguous!");
3568 assert(isTypeIdInParens() &&
"Not a type-id!");
3597 if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) {
3603 if (Tok.is(tok::l_brace)) {
3607 if (Tok.is(tok::l_paren) &&
NextToken().
is(tok::r_paren)) {
3615 false , NotCastExpr,
3628 AttrEnd.startToken();
3629 AttrEnd.setKind(tok::eof);
3630 AttrEnd.setLocation(Tok.getLocation());
3631 AttrEnd.setEofData(Toks.data());
3632 Toks.push_back(AttrEnd);
3635 Toks.push_back(Tok);
3638 PP.EnterTokenStream(Toks,
true,
3646 DeclSpec DS(AttrFactory);
3651 ParseSpecifierQualifierList(DS);
3652 ParseDeclarator(DeclaratorInfo);
3660 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3665 if (DeclaratorInfo.isInvalidType())
3668 TypeResult Ty = Actions.ActOnTypeName(DeclaratorInfo);
3669 return ParseCompoundLiteralExpression(Ty.
get(),
3677 if (DeclaratorInfo.isInvalidType())
3683 DeclaratorInfo, CastTy,
3693 if (!
Result.isInvalid() && Tok.is(tok::r_paren))
3695 Tok.getLocation(),
Result.get());
3698 if (
Result.isInvalid()) {
3699 while (Tok.isNot(tok::eof))
3701 assert(Tok.getEofData() == AttrEnd.getEofData());
3708 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3717 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"__builtin_bit_cast"))
3721 DeclSpec DS(AttrFactory);
3722 ParseSpecifierQualifierList(DS);
3727 ParseDeclarator(DeclaratorInfo);
3729 if (ExpectAndConsume(tok::comma)) {
3730 Diag(Tok.getLocation(), diag::err_expected) << tok::comma;
3737 if (
T.consumeClose())
3740 if (
Operand.isInvalid() || DeclaratorInfo.isInvalidType())
3743 return Actions.ActOnBuiltinBitCastExpr(KWLoc, DeclaratorInfo, Operand,
3744 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.
static void addConstexprToLambdaDeclSpecifier(Parser &P, SourceLocation ConstexprLoc, DeclSpec &DS)
static void FixDigraph(Parser &P, Preprocessor &PP, Token &DigraphToken, Token &ColonToken, tok::TokenKind Kind, bool AtDigraph)
static ArrayTypeTrait ArrayTypeTraitFromTokKind(tok::TokenKind kind)
static void tryConsumeLambdaSpecifierToken(Parser &P, SourceLocation &MutableLoc, SourceLocation &StaticLoc, SourceLocation &ConstexprLoc, SourceLocation &ConstevalLoc, SourceLocation &DeclEndLoc)
static ExpressionTrait ExpressionTraitFromTokKind(tok::TokenKind kind)
static void addConstevalToLambdaDeclSpecifier(Parser &P, SourceLocation ConstevalLoc, DeclSpec &DS)
static TypeTrait TypeTraitFromTokKind(tok::TokenKind kind)
static void DiagnoseStaticSpecifierRestrictions(Parser &P, SourceLocation StaticLoc, SourceLocation MutableLoc, const LambdaIntroducer &Intro)
static int SelectDigraphErrorMessage(tok::TokenKind Kind)
static void addStaticToLambdaDeclSpecifier(Parser &P, SourceLocation StaticLoc, DeclSpec &DS)
Defines the PrettyStackTraceEntry class, which is used to make crashes give more contextual informati...
static constexpr bool isOneOf()
This file declares facilities that support code completion.
Defines the clang::TemplateNameKind enum.
Defines the clang::TokenKind enum and support functions.
const clang::PrintingPolicy & getPrintingPolicy() const
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ....
SourceLocation getOpenLocation() const
SourceLocation getCloseLocation() const
Represents a C++ nested-name-specifier or a global scope specifier.
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
SourceRange getRange() const
SourceLocation getBeginLoc() const
bool isSet() const
Deprecated.
void setEndLoc(SourceLocation Loc)
void SetInvalid(SourceRange R)
Indicate that this nested-name-specifier is invalid.
bool isEmpty() const
No scope specifier.
void restore()
restore - This can be used to restore the state early, before the dtor is run.
Captures information about "declaration specifiers".
static const TST TST_typename
SourceLocation getEndLoc() const LLVM_READONLY
bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec and return false if there was no error.
static const TST TST_char8
static const TST TST_BFloat16
bool SetConstexprSpec(ConstexprSpecKind ConstexprKind, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
bool SetTypeSpecWidth(TypeSpecifierWidth W, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec, but return true and ignore the request if ...
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
SourceRange getSourceRange() const LLVM_READONLY
void SetRangeEnd(SourceLocation Loc)
bool SetBitIntType(SourceLocation KWLoc, Expr *BitWidth, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
static const TST TST_double
void SetRangeStart(SourceLocation Loc)
static const TST TST_char
static const TST TST_bool
static const TST TST_char16
static const TST TST_accum
static const TST TST_half
static const TST TST_ibm128
static const TST TST_float128
void Finish(Sema &S, const PrintingPolicy &Policy)
Finish - This does final analysis of the declspec, issuing diagnostics for things like "_Complex" (la...
static const TST TST_wchar
static const TST TST_void
static const TST TST_float
static const TST TST_fract
static const TST TST_float16
static const TST TST_decltype_auto
static const TST TST_error
static const TST TST_char32
static const TST TST_int128
bool SetTypeSpecSign(TypeSpecifierSign S, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
static const TST TST_auto
SourceLocation getLocation() const
Information about one declarator, including the parsed type information and the identifier.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
void SetSourceRange(SourceRange R)
void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc)
AddTypeInfo - Add a chunk to this declarator.
bool isInvalidType() const
DeclSpec & getMutableDeclSpec()
getMutableDeclSpec - Return a non-const version of the DeclSpec.
This represents one expression.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
static SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, unsigned Characters, const SourceManager &SM, const LangOptions &LangOpts)
AdvanceToTokenCharacter - If the current SourceLocation specifies a location at the start of a token,...
static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, const LangOptions &LangOpts)
Computes the source location just past the end of the token at this source location.
void * getAsOpaquePtr() const
static OpaquePtr make(QualType P)
static const ParsedAttributesView & none()
ParsedAttributes - A collection of parsed attributes.
Introduces zero or more scopes for parsing.
ParseScope - Introduces a new scope for parsing.
Parser - This implements a parser for the C family of languages.
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeName, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
SourceLocation getEndOfPreviousToken() const
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
AttributeFactory & getAttrFactory()
Sema & getActions() const
static TypeResult getTypeAnnotation(const Token &Tok)
getTypeAnnotation - Read a parsed type out of an annotation token.
ExprResult ParseConstraintLogicalOrExpression(bool IsTrailingRequiresClause)
Parse a constraint-logical-or-expression.
bool ParseUnqualifiedId(CXXScopeSpec &SS, ParsedType ObjectType, bool ObjectHadErrors, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, SourceLocation *TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
bool TryAnnotateOptionalCXXScopeToken(bool EnteringContext=false)
friend class ColonProtectionRAIIObject
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type.
const Token & GetLookAheadToken(unsigned N)
GetLookAheadToken - This peeks ahead N tokens and returns that token without consuming any tokens.
ExprResult ParseConstantExpression()
bool TryConsumeToken(tok::TokenKind Expected)
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
Scope * getCurScope() const
friend class InMessageExpressionRAIIObject
OpaquePtr< TemplateName > TemplateTy
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
const Token & getCurToken() const
const LangOptions & getLangOpts() const
friend class ParenBraceBracketBalancer
ExprResult ParseExpression(TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
Simple precedence-based parser for binary/ternary operators.
@ StopBeforeMatch
Stop skipping at specified token, but don't skip the token itself.
@ StopAtSemi
Stop skipping at semicolon.
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
ExprResult ParseAssignmentExpression(TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
Parse an expr that doesn't include (top-level) commas.
friend class BalancedDelimiterTracker
ExprResult ParseConstraintExpression()
Parse a constraint-expression.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
void Lex(Token &Result)
Lex the next token for this preprocessor.
void AddFlags(unsigned Flags)
Sets up the specified scope flags and adjusts the scope state variables accordingly.
void setIsConditionVarScope(bool InConditionVarScope)
@ FunctionPrototypeScope
This is a scope that corresponds to the parameters within a function prototype.
@ LambdaScope
This is the scope for a lambda, after the lambda introducer.
@ BlockScope
This is a scope that corresponds to a block/closure object.
@ ContinueScope
This is a while, do, for, which can have continue statements embedded into it.
@ BreakScope
This is a while, do, switch, for, etc that can have break statements embedded into it.
@ CompoundStmtScope
This is a compound statement scope.
@ FunctionDeclarationScope
This is a scope that corresponds to the parameters within a function prototype for a function declara...
@ FnScope
This indicates that the scope corresponds to a function, which means that labels are set here.
@ DeclScope
This is a scope that can contain a declaration.
@ PCC_Condition
Code completion occurs within the condition of an if, while, switch, or for statement.
@ Switch
An integral condition for a 'switch' statement.
@ ConstexprIf
A constant boolean condition from 'if constexpr'.
ASTContext & getASTContext() const
@ ConstantEvaluated
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
static ConditionResult ConditionError()
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
A trivial tuple used to represent a source range.
void setBegin(SourceLocation b)
SourceLocation getEnd() const
SourceLocation getBegin() const
void setEnd(SourceLocation e)
SourceLocation getEndLoc() const LLVM_READONLY
SourceLocation getBeginLoc() const LLVM_READONLY
Represents a C++ template name within the type system.
Token - This structure provides full information about a lexed token.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
const char * getName() const
void setLength(unsigned Len)
void setKind(tok::TokenKind K)
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
tok::TokenKind getKind() const
void setLocation(SourceLocation L)
The base class of the type hierarchy.
QualType getCanonicalTypeInternal() const
Represents a C++ unqualified-id that has been parsed.
struct OFI OperatorFunctionId
When Kind == IK_OperatorFunctionId, the overloaded operator that we parsed.
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
bool isValid() const
Determine whether this unqualified-id refers to a valid name.
void setDestructorName(SourceLocation TildeLoc, ParsedType ClassType, SourceLocation EndLoc)
Specify that this unqualified-id was parsed as a destructor name.
void setTemplateId(TemplateIdAnnotation *TemplateId)
Specify that this unqualified-id was parsed as a template-id.
UnionParsedType DestructorName
When Kind == IK_DestructorName, the type referred to by the class-name.
SourceLocation StartLocation
The location of the first token that describes this unqualified-id, which will be the location of the...
void setConstructorName(ParsedType ClassType, SourceLocation ClassNameLoc, SourceLocation EndLoc)
Specify that this unqualified-id was parsed as a constructor name.
const IdentifierInfo * Identifier
When Kind == IK_Identifier, the parsed identifier, or when Kind == IK_UserLiteralId,...
UnqualifiedIdKind getKind() const
Determine what kind of name we have.
uint32_t Literal
Literals are represented as positive integers.
@ After
Like System, but searched after the system directories.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
OpaquePtr< TemplateName > ParsedTemplateTy
@ NotAttributeSpecifier
This is not an attribute specifier.
ArrayTypeTrait
Names for the array type traits.
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
LambdaCaptureKind
The different capture forms in a lambda introducer.
@ LCK_ByCopy
Capturing by copy (a.k.a., by value)
@ LCK_ByRef
Capturing by reference.
@ LCK_StarThis
Capturing the *this object by copy.
@ LCK_This
Capturing the *this object by reference.
@ IK_ConstructorName
A constructor name.
@ IK_LiteralOperatorId
A user-defined literal name, e.g., operator "" _i.
@ IK_Identifier
An identifier.
@ IK_DestructorName
A destructor name.
@ IK_OperatorFunctionId
An overloaded operator name, e.g., operator+.
ActionResult< Decl * > DeclResult
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
MutableArrayRef< Expr * > MultiExprArg
@ CopyInit
[a = b], [a = {b}]
@ Result
The result type of a method or function.
ActionResult< ParsedType > TypeResult
const FunctionProtoType * T
@ 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.