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,
570 Token &Replacement) {
574 switch (Tok.getKind()) {
575 case tok::annot_non_type: {
576 NamedDecl *ND = getNonTypeAnnotation(Tok);
577 SourceLocation Loc = ConsumeAnnotationToken();
578 E = Actions.ActOnNameClassifiedAsNonType(
getCurScope(), SS, ND, Loc, Tok);
582 case tok::annot_non_type_dependent: {
583 IdentifierInfo *II = getIdentifierAnnotation(Tok);
584 SourceLocation Loc = ConsumeAnnotationToken();
588 if (isAddressOfOperand && isPostfixExpressionSuffixStart())
589 isAddressOfOperand =
false;
591 E = Actions.ActOnNameClassifiedAsDependentNonType(SS, II, Loc,
596 case tok::annot_non_type_undeclared: {
598 "undeclared non-type annotation should be unqualified");
599 IdentifierInfo *II = getIdentifierAnnotation(Tok);
600 SourceLocation Loc = ConsumeAnnotationToken();
601 E = Actions.ActOnNameClassifiedAsUndeclaredNonType(II, Loc);
606 SourceLocation TemplateKWLoc;
613 false, &TemplateKWLoc, Name))
618 if (isAddressOfOperand && isPostfixExpressionSuffixStart())
619 isAddressOfOperand =
false;
621 E = Actions.ActOnIdExpression(
622 getCurScope(), SS, TemplateKWLoc, Name, Tok.is(tok::l_paren),
623 isAddressOfOperand,
nullptr,
false,
629 E = tryParseCXXPackIndexingExpression(E);
632 checkPotentialAngleBracket(E);
637 assert(Tok.is(tok::ellipsis) &&
NextToken().
is(tok::l_square) &&
643 if (T.consumeClose() || IndexExpr.
isInvalid())
645 return Actions.ActOnPackIndexingExpr(
getCurScope(), PackIdExpression.
get(),
646 EllipsisLoc, T.getOpenLocation(),
647 IndexExpr.
get(), T.getCloseLocation());
651Parser::tryParseCXXPackIndexingExpression(
ExprResult PackIdExpression) {
654 Tok.is(tok::ellipsis) &&
NextToken().
is(tok::l_square)) {
655 E = ParseCXXPackIndexingExpression(E);
660ExprResult Parser::ParseCXXIdExpression(
bool isAddressOfOperand) {
666 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
672 tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement);
676 UnconsumeToken(Replacement);
677 Result = tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement);
679 assert(!
Result.isUnset() &&
"Typo correction suggested a keyword replacement "
680 "for a previous keyword suggestion");
686 LambdaIntroducer Intro;
687 if (ParseLambdaIntroducer(Intro)) {
694 return ParseLambdaExpressionAfterIntroducer(Intro);
697ExprResult Parser::TryParseLambdaExpression() {
699 "Not at the start of a possible lambda expression.");
702 if (
Next.is(tok::eof))
707 if (
Next.is(tok::r_square) ||
708 Next.is(tok::equal) ||
709 (
Next.is(tok::amp) &&
710 After.isOneOf(tok::r_square, tok::comma)) ||
711 (
Next.is(tok::identifier) &&
712 After.is(tok::r_square)) ||
713 Next.is(tok::ellipsis)) {
714 return ParseLambdaExpression();
719 if (
Next.is(tok::identifier) &&
After.is(tok::identifier))
727 LambdaIntroducer Intro;
729 TentativeParsingAction TPA(*
this);
730 LambdaIntroducerTentativeParse Tentative;
731 if (ParseLambdaIntroducer(Intro, &Tentative)) {
737 case LambdaIntroducerTentativeParse::Success:
741 case LambdaIntroducerTentativeParse::Incomplete:
745 Intro = LambdaIntroducer();
746 if (ParseLambdaIntroducer(Intro))
750 case LambdaIntroducerTentativeParse::MessageSend:
751 case LambdaIntroducerTentativeParse::Invalid:
758 return ParseLambdaExpressionAfterIntroducer(Intro);
762 LambdaIntroducerTentativeParse *Tentative) {
764 *Tentative = LambdaIntroducerTentativeParse::Success;
766 assert(Tok.is(tok::l_square) &&
"Lambda expressions begin with '['.");
776 auto Result = [&](llvm::function_ref<void()> Action,
777 LambdaIntroducerTentativeParse State =
778 LambdaIntroducerTentativeParse::Invalid) {
789 auto NonTentativeAction = [&](llvm::function_ref<void()> Action) {
791 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
797 if (Tok.is(tok::amp) &&
802 if (!Tok.getIdentifierInfo()) {
807 }
else if (Tok.is(tok::equal)) {
814 while (Tok.isNot(tok::r_square)) {
816 if (Tok.isNot(tok::comma)) {
821 if (Tok.is(tok::code_completion) &&
824 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
831 Diag(Tok.getLocation(), diag::err_expected_comma_or_rsquare);
837 if (Tok.is(tok::code_completion)) {
842 Actions.CodeCompletion().CodeCompleteObjCMessageReceiver(
getCurScope());
844 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
856 IdentifierInfo *Id =
nullptr;
857 SourceLocation EllipsisLocs[4];
859 SourceLocation LocStart = Tok.getLocation();
861 if (Tok.is(tok::star)) {
863 if (Tok.is(tok::kw_this)) {
868 Diag(Tok.getLocation(), diag::err_expected_star_this_capture);
871 }
else if (Tok.is(tok::kw_this)) {
874 }
else if (Tok.isOneOf(tok::amp, tok::equal) &&
882 [&] {
Diag(Tok.getLocation(), diag::err_capture_default_first); },
883 LambdaIntroducerTentativeParse::Incomplete);
887 if (Tok.is(tok::amp)) {
891 if (Tok.is(tok::code_completion)) {
893 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
902 if (Tok.is(tok::identifier)) {
903 Id = Tok.getIdentifierInfo();
905 }
else if (Tok.is(tok::kw_this)) {
908 Diag(Tok.getLocation(), diag::err_this_captured_by_reference);
912 [&] {
Diag(Tok.getLocation(), diag::err_expected_capture); });
917 if (Tok.is(tok::l_paren)) {
926 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
927 }
else if (ParseExpressionList(Exprs)) {
932 Init = Actions.ActOnParenListExpr(
Parens.getOpenLocation(),
933 Parens.getCloseLocation(),
936 }
else if (Tok.isOneOf(tok::l_brace, tok::equal)) {
940 EnterExpressionEvaluationContext EC(
949 Init = ParseInitializer();
950 }
else if (Tok.is(tok::l_brace)) {
954 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
976 SourceLocation StartLoc = Tok.getLocation();
978 Init = ParseInitializer();
980 if (Tok.getLocation() != StartLoc) {
982 PP.RevertCachedTokens(1);
985 Tok.setLocation(StartLoc);
986 Tok.setKind(tok::annot_primary_expr);
987 setExprAnnotation(Tok,
Init);
988 Tok.setAnnotationEndLoc(PP.getLastCachedTokenLocation());
989 PP.AnnotateCachedTokens(Tok);
992 ConsumeAnnotationToken();
1001 if (Tentative && Tok.is(tok::identifier) &&
1004 *Tentative = LambdaIntroducerTentativeParse::MessageSend;
1009 SourceLocation EllipsisLoc;
1010 if (llvm::any_of(EllipsisLocs,
1011 [](SourceLocation Loc) {
return Loc.
isValid(); })) {
1015 SourceLocation *ExpectedEllipsisLoc =
1016 !InitCapture ? &EllipsisLocs[2] :
1019 EllipsisLoc = *ExpectedEllipsisLoc;
1021 unsigned DiagID = 0;
1023 DiagID = diag::err_lambda_capture_misplaced_ellipsis;
1024 for (SourceLocation Loc : EllipsisLocs) {
1029 unsigned NumEllipses = std::accumulate(
1030 std::begin(EllipsisLocs), std::end(EllipsisLocs), 0,
1031 [](
int N, SourceLocation Loc) {
return N + Loc.
isValid(); });
1032 if (NumEllipses > 1)
1033 DiagID = diag::err_lambda_capture_multiple_ellipses;
1036 NonTentativeAction([&] {
1038 SourceLocation DiagLoc;
1039 for (SourceLocation &Loc : EllipsisLocs) {
1040 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid()) {
1045 assert(DiagLoc.
isValid() &&
"no location for diagnostic");
1049 auto &&D =
Diag(DiagLoc, DiagID);
1050 if (DiagID == diag::err_lambda_capture_misplaced_ellipsis) {
1051 SourceLocation ExpectedLoc =
1057 for (SourceLocation &Loc : EllipsisLocs) {
1058 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid())
1070 if (
Init.isUsable()) {
1071 NonTentativeAction([&] {
1074 Expr *InitExpr =
Init.get();
1077 InitCaptureType = Actions.actOnLambdaInitCaptureInitialization(
1078 Loc, Kind ==
LCK_ByRef, EllipsisLoc, Id, InitKind, InitExpr);
1083 SourceLocation LocEnd = PrevTokLocation;
1086 InitCaptureType, SourceRange(LocStart, LocEnd));
1108 auto ConsumeLocation = [&P, &DeclEndLoc](
SourceLocation &SpecifierLoc,
1110 if (SpecifierLoc.isValid()) {
1112 diag::err_lambda_decl_specifier_repeated)
1117 DeclEndLoc = SpecifierLoc;
1122 case tok::kw_mutable:
1123 ConsumeLocation(MutableLoc, 0);
1125 case tok::kw_static:
1126 ConsumeLocation(StaticLoc, 1);
1128 case tok::kw_constexpr:
1129 ConsumeLocation(ConstexprLoc, 2);
1131 case tok::kw_consteval:
1132 ConsumeLocation(ConstevalLoc, 3);
1144 ? diag::err_static_lambda
1145 : diag::warn_cxx20_compat_static_lambda);
1146 const char *PrevSpec =
nullptr;
1147 unsigned DiagID = 0;
1151 assert(PrevSpec ==
nullptr && DiagID == 0 &&
1152 "Static cannot have been set previously!");
1161 ? diag::ext_constexpr_on_lambda_cxx17
1162 : diag::warn_cxx14_compat_constexpr_on_lambda);
1163 const char *PrevSpec =
nullptr;
1164 unsigned DiagID = 0;
1167 assert(PrevSpec ==
nullptr && DiagID == 0 &&
1168 "Constexpr cannot have been set previously!");
1176 P.
Diag(ConstevalLoc, diag::warn_cxx20_compat_consteval);
1177 const char *PrevSpec =
nullptr;
1178 unsigned DiagID = 0;
1182 P.
Diag(ConstevalLoc, DiagID) << PrevSpec;
1198 P.
Diag(StaticLoc, diag::err_static_mutable_lambda);
1200 P.
Diag(StaticLoc, diag::err_static_lambda_captures);
1204ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
1208 Diag(LambdaBeginLoc, diag::ext_hlsl_lambda) << 1;
1211 ? diag::warn_cxx98_compat_lambda
1215 PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), LambdaBeginLoc,
1216 "lambda expression parsing");
1219 DeclSpec DS(AttrFactory);
1221 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1227 Actions.PushLambdaScope();
1228 SourceLocation DeclLoc = Tok.getLocation();
1230 Actions.ActOnLambdaExpressionAfterIntroducer(Intro,
getCurScope());
1232 ParsedAttributes Attributes(AttrFactory);
1240 if (Tok.is(tok::kw___noinline__)) {
1241 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1243 Attributes.addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
1245 0, tok::kw___noinline__);
1246 }
else if (Tok.is(tok::kw___attribute))
1247 ParseGNUAttributes(Attributes,
nullptr, &D);
1252 D.takeAttributesAppending(Attributes);
1256 if (Tok.is(tok::less)) {
1258 ? diag::warn_cxx17_compat_lambda_template_parameter_list
1259 : diag::ext_lambda_template_parameter_list);
1261 SmallVector<NamedDecl*, 4> TemplateParams;
1262 SourceLocation LAngleLoc, RAngleLoc;
1263 if (ParseTemplateParameters(TemplateParamScope,
1264 CurTemplateDepthTracker.getDepth(),
1265 TemplateParams, LAngleLoc, RAngleLoc)) {
1266 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1270 if (TemplateParams.empty()) {
1272 diag::err_lambda_template_parameter_list_empty);
1283 ++CurTemplateDepthTracker;
1293 Actions.ActOnLambdaExplicitTemplateParameterList(
1294 Intro, LAngleLoc, TemplateParams, RAngleLoc, RequiresClause);
1302 if (isCXX11AttributeSpecifier() !=
1305 ? diag::warn_cxx20_compat_decl_attrs_on_lambda
1306 : diag::ext_decl_attrs_on_lambda)
1307 << Tok.isRegularKeywordAttribute() << Tok.getIdentifierInfo();
1308 MaybeParseCXX11Attributes(D);
1312 SourceLocation TrailingReturnTypeLoc;
1313 SourceLocation LParenLoc, RParenLoc;
1314 SourceLocation DeclEndLoc = DeclLoc;
1315 bool HasParentheses =
false;
1316 bool HasSpecifiers =
false;
1317 SourceLocation MutableLoc;
1324 SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
1325 SourceLocation EllipsisLoc;
1327 if (Tok.is(tok::l_paren)) {
1330 LParenLoc = T.getOpenLocation();
1332 if (Tok.isNot(tok::r_paren)) {
1333 Actions.RecordParsingTemplateParameterDepth(
1334 CurTemplateDepthTracker.getOriginalDepth());
1336 ParseParameterDeclarationClause(D, Attributes, ParamInfo, EllipsisLoc);
1342 if (Actions.getCurGenericLambda())
1343 CurTemplateDepthTracker.setAddedDepth(1);
1347 DeclEndLoc = RParenLoc = T.getCloseLocation();
1348 HasParentheses =
true;
1352 Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
1353 tok::kw_constexpr, tok::kw_consteval, tok::kw_static,
1354 tok::kw___private, tok::kw___global, tok::kw___local,
1355 tok::kw___constant, tok::kw___generic, tok::kw_groupshared,
1356 tok::kw_requires, tok::kw_noexcept) ||
1357 Tok.isRegularKeywordAttribute() ||
1358 (Tok.is(tok::l_square) &&
NextToken().
is(tok::l_square));
1364 Diag(Tok, diag::ext_lambda_missing_parens)
1368 if (HasParentheses || HasSpecifiers) {
1372 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec, Attributes);
1375 SourceLocation ConstexprLoc;
1376 SourceLocation ConstevalLoc;
1377 SourceLocation StaticLoc;
1380 ConstevalLoc, DeclEndLoc);
1389 Actions.ActOnLambdaClosureParameters(
getCurScope(), ParamInfo);
1391 if (!HasParentheses)
1392 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1394 if (HasSpecifiers || HasParentheses) {
1397 SourceRange ESpecRange;
1398 SmallVector<ParsedType, 2> DynamicExceptions;
1399 SmallVector<SourceRange, 2> DynamicExceptionRanges;
1403 ESpecType = tryParseExceptionSpecification(
1404 false, ESpecRange, DynamicExceptions,
1405 DynamicExceptionRanges, NoexceptExpr, ExceptionSpecTokens);
1408 DeclEndLoc = ESpecRange.
getEnd();
1411 if (MaybeParseCXX11Attributes(Attributes))
1412 DeclEndLoc = Attributes.Range.getEnd();
1415 if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
1416 tok::kw___constant, tok::kw___generic)) {
1417 ParseOpenCLQualifiers(DS.getAttributes());
1424 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1426 SourceLocation FunLocalRangeEnd = DeclEndLoc;
1429 if (Tok.is(tok::arrow)) {
1430 FunLocalRangeEnd = Tok.getLocation();
1432 TrailingReturnType =
1433 ParseTrailingReturnType(Range,
false);
1434 TrailingReturnTypeLoc =
Range.getBegin();
1435 if (
Range.getEnd().isValid())
1436 DeclEndLoc =
Range.getEnd();
1439 SourceLocation NoLoc;
1442 false, LParenLoc, ParamInfo.data(),
1443 ParamInfo.size(), EllipsisLoc, RParenLoc,
1445 NoLoc, MutableLoc, ESpecType,
1446 ESpecRange, DynamicExceptions.data(),
1447 DynamicExceptionRanges.data(), DynamicExceptions.size(),
1448 NoexceptExpr.
isUsable() ? NoexceptExpr.
get() :
nullptr,
1450 {}, LParenLoc, FunLocalRangeEnd, D,
1451 TrailingReturnType, TrailingReturnTypeLoc, &DS),
1452 std::move(Attributes), DeclEndLoc);
1454 if (HasParentheses && Tok.is(tok::kw_requires))
1455 ParseTrailingRequiresClause(D);
1461 for (
const ParsedAttr &A : Attributes)
1462 if (A.getKind() == ParsedAttr::AT_CUDADevice ||
1463 A.getKind() == ParsedAttr::AT_CUDAHost ||
1464 A.getKind() == ParsedAttr::AT_CUDAGlobal)
1465 Diag(A.getLoc(), diag::warn_cuda_attr_lambda_position)
1466 << A.getAttrName()->getName();
1477 Actions.ActOnStartOfLambdaDefinition(Intro, D, DS);
1480 if (!Tok.is(tok::l_brace)) {
1481 Diag(Tok, diag::err_expected_lambda_body);
1482 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1486 StmtResult Stmt(ParseCompoundStatementBody());
1488 TemplateParamScope.Exit();
1491 if (!Stmt.isInvalid() && !TrailingReturnType.
isInvalid() &&
1493 return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.get());
1495 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1501 const char *CastName =
nullptr;
1504 default: llvm_unreachable(
"Unknown C++ cast!");
1505 case tok::kw_addrspace_cast: CastName =
"addrspace_cast";
break;
1506 case tok::kw_const_cast: CastName =
"const_cast";
break;
1507 case tok::kw_dynamic_cast: CastName =
"dynamic_cast";
break;
1508 case tok::kw_reinterpret_cast: CastName =
"reinterpret_cast";
break;
1509 case tok::kw_static_cast: CastName =
"static_cast";
break;
1513 SourceLocation LAngleBracketLoc = Tok.getLocation();
1517 if (Tok.is(tok::l_square) && Tok.getLength() == 2) {
1519 if (
Next.is(tok::colon) && areTokensAdjacent(Tok,
Next))
1523 if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName))
1527 DeclSpec DS(AttrFactory);
1528 ParseSpecifierQualifierList(DS,
AS_none,
1529 DeclSpecContext::DSC_type_specifier);
1534 ParseDeclarator(DeclaratorInfo);
1536 SourceLocation RAngleBracketLoc = Tok.getLocation();
1538 if (ExpectAndConsume(tok::greater))
1539 return ExprError(
Diag(LAngleBracketLoc, diag::note_matching) << tok::less);
1543 if (T.expectAndConsume(diag::err_expected_lparen_after, CastName))
1551 if (!
Result.isInvalid() && !DeclaratorInfo.isInvalidType())
1552 Result = Actions.ActOnCXXNamedCast(OpLoc, Kind,
1553 LAngleBracketLoc, DeclaratorInfo,
1555 T.getOpenLocation(),
Result.get(),
1556 T.getCloseLocation());
1562 assert(Tok.is(tok::kw_typeid) &&
"Not 'typeid'!");
1565 SourceLocation LParenLoc, RParenLoc;
1569 if (T.expectAndConsume(diag::err_expected_lparen_after,
"typeid"))
1571 LParenLoc = T.getOpenLocation();
1592 if (isTypeIdInParens()) {
1597 RParenLoc = T.getCloseLocation();
1601 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
true,
1611 RParenLoc = T.getCloseLocation();
1615 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
false,
1616 Result.get(), RParenLoc);
1624 assert(Tok.is(tok::kw___uuidof) &&
"Not '__uuidof'!");
1630 if (T.expectAndConsume(diag::err_expected_lparen_after,
"__uuidof"))
1635 if (isTypeIdInParens()) {
1644 Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(),
true,
1646 T.getCloseLocation());
1658 Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(),
1660 Result.get(), T.getCloseLocation());
1675 SourceLocation CCLoc;
1676 if (Tok.is(tok::identifier)) {
1677 FirstTypeName.
setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
1679 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1681 }
else if (Tok.is(tok::annot_template_id)) {
1682 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
1687 ConsumeAnnotationToken();
1688 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1691 assert(SS.
isEmpty() &&
"missing last component of nested name specifier");
1696 assert(Tok.is(tok::tilde) &&
"ParseOptionalCXXScopeSpecifier fail");
1699 if (Tok.is(tok::kw_decltype) && !FirstTypeName.
isValid()) {
1700 DeclSpec DS(AttrFactory);
1701 ParseDecltypeSpecifier(DS);
1704 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1708 if (!Tok.is(tok::identifier)) {
1709 Diag(Tok, diag::err_destructor_tilde_identifier);
1716 DeclSpec DS(AttrFactory);
1717 ParsePackIndexingType(DS);
1718 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1724 IdentifierInfo *Name = Tok.getIdentifierInfo();
1736 if (Tok.is(tok::less) &&
1737 ParseUnqualifiedIdTemplateId(
1738 SS, ObjectType, Base &&
Base->containsErrors(), SourceLocation(),
1739 Name, NameLoc,
false, SecondTypeName,
1743 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1744 SS, FirstTypeName, CCLoc, TildeLoc,
1750 return Actions.ActOnCXXBoolLiteral(
ConsumeToken(), Kind);
1754 assert(Tok.is(tok::kw_throw) &&
"Not throw!");
1760 switch (Tok.getKind()) {
1767 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc,
nullptr);
1771 if (Expr.isInvalid())
return Expr;
1772 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc, Expr.get());
1777 assert(Tok.is(tok::kw_co_yield) &&
"Not co_yield!");
1780 ExprResult Expr = Tok.is(tok::l_brace) ? ParseBraceInitializer()
1788 assert(Tok.is(tok::kw_this) &&
"Not 'this'!");
1790 return Actions.ActOnCXXThis(ThisLoc);
1794Parser::ParseCXXTypeConstructExpression(
const DeclSpec &DS) {
1797 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
1799 assert((Tok.is(tok::l_paren) ||
1801 &&
"Expected '(' or '{'!");
1803 if (Tok.is(tok::l_brace)) {
1804 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1806 if (
Init.isInvalid())
1809 return Actions.ActOnCXXTypeConstructExpr(
1816 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1820 auto RunSignatureHelp = [&]() {
1821 QualType PreferredType;
1824 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
1826 Exprs, T.getOpenLocation(),
false);
1827 CalledSignatureHelp =
true;
1828 return PreferredType;
1831 if (Tok.isNot(tok::r_paren)) {
1832 if (ParseExpressionList(Exprs, [&] {
1833 PreferredType.enterFunctionArgument(Tok.getLocation(),
1836 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
1850 return Actions.ActOnCXXTypeConstructExpr(TypeRep, T.getOpenLocation(),
1851 Exprs, T.getCloseLocation(),
1859 assert(Tok.is(tok::kw_using) &&
"Expected using");
1862 "Unexpected Declarator Context");
1866 DG = ParseUsingDeclaration(Context, {}, DeclStart, DeclEnd, Attrs,
AS_none);
1871 ? diag::ext_alias_in_init_statement
1872 : diag::warn_cxx20_alias_in_init_statement)
1873 << SourceRange(DeclStart, DeclEnd);
1881 ForRangeInfo *FRI,
bool EnterForConditionScope) {
1883 struct ForConditionScopeRAII {
1885 void enter(
bool IsConditionVariable) {
1891 ~ForConditionScopeRAII() {
1898 PreferredType.enterCondition(Actions, Tok.getLocation());
1900 if (Tok.is(tok::code_completion)) {
1902 Actions.CodeCompletion().CodeCompleteOrdinaryName(
1907 ParsedAttributes attrs(AttrFactory);
1908 MaybeParseCXX11Attributes(attrs);
1910 const auto WarnOnInit = [
this, &CK] {
1912 ? diag::warn_cxx14_compat_init_statement
1913 : diag::ext_init_statement)
1918 switch (isCXXConditionDeclarationOrInitStatement(InitStmt, FRI)) {
1919 case ConditionOrInitStatement::Expression: {
1921 ForConditionScope.enter(
false);
1923 ProhibitAttributes(attrs);
1927 if (InitStmt && Tok.is(tok::semi)) {
1929 SourceLocation SemiLoc = Tok.getLocation();
1930 if (!Tok.hasLeadingEmptyMacro() && !SemiLoc.
isMacroID()) {
1931 Diag(SemiLoc, diag::warn_empty_init_statement)
1936 *InitStmt = Actions.ActOnNullStmt(SemiLoc);
1937 return ParseCXXCondition(
nullptr, Loc, CK, MissingOK);
1940 EnterExpressionEvaluationContext Eval(
1951 if (InitStmt && Tok.is(tok::semi)) {
1953 *InitStmt = Actions.ActOnExprStmt(Expr.
get());
1955 return ParseCXXCondition(
nullptr, Loc, CK, MissingOK);
1958 return Actions.ActOnCondition(
getCurScope(), Loc, Expr.
get(), CK,
1962 case ConditionOrInitStatement::InitStmtDecl: {
1965 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
1966 if (Tok.is(tok::kw_using))
1967 DG = ParseAliasDeclarationInInitStatement(
1970 ParsedAttributes DeclSpecAttrs(AttrFactory);
1972 attrs, DeclSpecAttrs,
true);
1974 *InitStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd);
1975 return ParseCXXCondition(
nullptr, Loc, CK, MissingOK);
1978 case ConditionOrInitStatement::ForRangeDecl: {
1982 assert(FRI &&
"should not parse a for range declaration here");
1983 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
1984 ParsedAttributes DeclSpecAttrs(AttrFactory);
1987 FRI->LoopVar = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
1988 return Sema::ConditionResult();
1991 case ConditionOrInitStatement::ConditionDecl:
1992 case ConditionOrInitStatement::Error:
1997 ForConditionScope.enter(
true);
2000 DeclSpec DS(AttrFactory);
2001 ParseSpecifierQualifierList(DS,
AS_none, DeclSpecContext::DSC_condition);
2005 ParseDeclarator(DeclaratorInfo);
2008 if (Tok.is(tok::kw_asm)) {
2010 ExprResult AsmLabel(ParseSimpleAsm(
true, &Loc));
2011 if (AsmLabel.isInvalid()) {
2015 DeclaratorInfo.setAsmLabel(AsmLabel.get());
2016 DeclaratorInfo.SetRangeEnd(Loc);
2020 MaybeParseGNUAttributes(DeclaratorInfo);
2031 bool CopyInitialization = isTokenEqualOrEqualTypo();
2032 if (CopyInitialization)
2037 Diag(Tok.getLocation(),
2038 diag::warn_cxx98_compat_generalized_initializer_lists);
2039 InitExpr = ParseBraceInitializer();
2040 }
else if (CopyInitialization) {
2041 PreferredType.enterVariableInit(Tok.getLocation(), DeclOut);
2043 }
else if (Tok.is(tok::l_paren)) {
2045 SourceLocation LParen = ConsumeParen(), RParen = LParen;
2047 RParen = ConsumeParen();
2049 diag::err_expected_init_in_condition_lparen)
2050 << SourceRange(LParen, RParen);
2056 Actions.AddInitializerToDecl(DeclOut, InitExpr.
get(), !CopyInitialization);
2058 Actions.ActOnInitializerError(DeclOut);
2060 Actions.FinalizeDeclaration(DeclOut);
2061 return Actions.ActOnConditionVariable(DeclOut, Loc, CK);
2064void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) {
2066 const char *PrevSpec;
2068 SourceLocation Loc = Tok.getLocation();
2069 const clang::PrintingPolicy &Policy =
2070 Actions.getASTContext().getPrintingPolicy();
2072 switch (Tok.getKind()) {
2073 case tok::identifier:
2074 case tok::coloncolon:
2075 llvm_unreachable(
"Annotation token should already be formed!");
2077 llvm_unreachable(
"Not a simple-type-specifier token!");
2080 case tok::annot_typename: {
2084 ConsumeAnnotationToken();
2085 DS.
Finish(Actions, Policy);
2089 case tok::kw__ExtInt:
2090 case tok::kw__BitInt: {
2091 DiagnoseBitIntUse(Tok);
2100 DS.
Finish(Actions, Policy);
2113 case tok::kw___int64:
2117 case tok::kw_signed:
2120 case tok::kw_unsigned:
2135 case tok::kw___int128:
2138 case tok::kw___bf16:
2147 case tok::kw_double:
2150 case tok::kw__Float16:
2153 case tok::kw___float128:
2156 case tok::kw___ibm128:
2159 case tok::kw_wchar_t:
2162 case tok::kw_char8_t:
2165 case tok::kw_char16_t:
2168 case tok::kw_char32_t:
2174 case tok::kw__Accum:
2177 case tok::kw__Fract:
2183#define GENERIC_IMAGE_TYPE(ImgType, Id) \
2184 case tok::kw_##ImgType##_t: \
2185 DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, DiagID, \
2188#include "clang/Basic/OpenCLImageTypes.def"
2189#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
2190 case tok::kw_##Name: \
2191 DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, DiagID, Policy); \
2193#include "clang/Basic/HLSLIntangibleTypes.def"
2195 case tok::annot_decltype:
2196 case tok::kw_decltype:
2198 return DS.
Finish(Actions, Policy);
2200 case tok::annot_pack_indexing_type:
2202 return DS.
Finish(Actions, Policy);
2205 case tok::kw_typeof:
2206 ParseTypeofSpecifier(DS);
2207 DS.
Finish(Actions, Policy);
2212 DS.
Finish(Actions, Policy);
2216 ParseSpecifierQualifierList(DS,
AS_none,
2217 getDeclSpecContextFromDeclaratorContext(Context));
2218 DS.
Finish(Actions, Actions.getASTContext().getPrintingPolicy());
2222bool Parser::ParseUnqualifiedIdTemplateId(
2223 CXXScopeSpec &SS,
ParsedType ObjectType,
bool ObjectHadErrors,
2224 SourceLocation TemplateKWLoc, IdentifierInfo *Name, SourceLocation NameLoc,
2225 bool EnteringContext, UnqualifiedId &Id,
bool AssumeTemplateId) {
2226 assert(Tok.is(tok::less) &&
"Expected '<' to finish parsing a template-id");
2234 if (AssumeTemplateId) {
2237 TNK = Actions.ActOnTemplateName(
getCurScope(), SS, TemplateKWLoc, Id,
2238 ObjectType, EnteringContext,
Template,
2241 bool MemberOfUnknownSpecialization;
2244 ObjectType, EnteringContext,
Template,
2245 MemberOfUnknownSpecialization);
2250 isTemplateArgumentList(0) == TPResult::False)
2254 ObjectType && isTemplateArgumentList(0) == TPResult::True) {
2257 if (!ObjectHadErrors) {
2276 TNK = Actions.ActOnTemplateName(
2277 getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext,
2287 bool MemberOfUnknownSpecialization;
2292 MemberOfUnknownSpecialization);
2300 bool MemberOfUnknownSpecialization;
2303 TNK = Actions.ActOnTemplateName(
2310 MemberOfUnknownSpecialization);
2313 Diag(NameLoc, diag::err_destructor_template_id)
2326 SourceLocation LAngleLoc, RAngleLoc;
2327 TemplateArgList TemplateArgs;
2328 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs, RAngleLoc,
2343 const IdentifierInfo *TemplateII =
2353 LAngleLoc, RAngleLoc, TemplateArgs,
false, TemplateIds);
2365 SourceLocation(), SS, TemplateKWLoc,
Template,
2366 Name, NameLoc, LAngleLoc, TemplateArgsPtr, RAngleLoc,
2368 if (
Type.isInvalid())
2379bool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
2382 assert(Tok.is(tok::kw_operator) &&
"Expected 'operator' keyword");
2388 unsigned SymbolIdx = 0;
2389 SourceLocation SymbolLocations[3];
2391 switch (Tok.getKind()) {
2393 case tok::kw_delete: {
2394 bool isNew = Tok.getKind() == tok::kw_new;
2398 if (Tok.is(tok::l_square) &&
2404 if (T.getCloseLocation().isInvalid())
2407 SymbolLocations[SymbolIdx++] = T.getOpenLocation();
2408 SymbolLocations[SymbolIdx++] = T.getCloseLocation();
2409 Op = isNew? OO_Array_New : OO_Array_Delete;
2411 Op = isNew? OO_New : OO_Delete;
2416#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
2418 SymbolLocations[SymbolIdx++] = ConsumeToken(); \
2421#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
2422#include "clang/Basic/OperatorKinds.def"
2424 case tok::l_paren: {
2429 if (T.getCloseLocation().isInvalid())
2432 SymbolLocations[SymbolIdx++] = T.getOpenLocation();
2433 SymbolLocations[SymbolIdx++] = T.getCloseLocation();
2438 case tok::l_square: {
2443 if (T.getCloseLocation().isInvalid())
2446 SymbolLocations[SymbolIdx++] = T.getOpenLocation();
2447 SymbolLocations[SymbolIdx++] = T.getCloseLocation();
2452 case tok::code_completion: {
2456 Actions.CodeCompletion().CodeCompleteOperatorName(
getCurScope());
2466 Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations);
2477 Diag(Tok.getLocation(), diag::warn_cxx98_compat_literal_operator);
2479 SourceLocation DiagLoc;
2480 unsigned DiagId = 0;
2484 SmallVector<Token, 4> Toks;
2485 SmallVector<SourceLocation, 4> TokLocs;
2486 while (isTokenStringLiteral()) {
2487 if (!Tok.is(tok::string_literal) && !DiagId) {
2491 DiagLoc = Tok.getLocation();
2492 DiagId = diag::err_literal_operator_string_prefix;
2494 Toks.push_back(Tok);
2495 TokLocs.push_back(ConsumeStringToken());
2498 StringLiteralParser
Literal(Toks, PP);
2504 bool IsUDSuffix = !
Literal.getUDSuffix().empty();
2505 IdentifierInfo *II =
nullptr;
2506 SourceLocation SuffixLoc;
2508 II = &PP.getIdentifierTable().get(
Literal.getUDSuffix());
2513 }
else if (Tok.is(tok::identifier)) {
2514 II = Tok.getIdentifierInfo();
2516 TokLocs.push_back(SuffixLoc);
2518 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
2528 DiagLoc = TokLocs.front();
2529 DiagId = diag::err_literal_operator_string_not_empty;
2535 SmallString<32> Str;
2539 SourceRange(TokLocs.front(), TokLocs.back()), Str);
2542 Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
2544 return Actions.checkLiteralOperatorId(SS,
Result, IsUDSuffix);
2559 DeclSpec DS(AttrFactory);
2560 if (ParseCXXTypeSpecifierSeq(
2568 ParseDeclaratorInternal(D,
nullptr);
2576 Result.setConversionFunctionId(KeywordLoc, Ty.
get(),
2577 D.getSourceRange().getEnd());
2582 bool ObjectHadErrors,
bool EnteringContext,
2583 bool AllowDestructorName,
2584 bool AllowConstructorName,
2585 bool AllowDeductionGuide,
2593 bool TemplateSpecified =
false;
2594 if (Tok.is(tok::kw_template)) {
2595 if (TemplateKWLoc && (ObjectType || SS.
isSet())) {
2596 TemplateSpecified =
true;
2600 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2608 if (Tok.is(tok::identifier)) {
2617 Result.setIdentifier(Id, IdLoc);
2622 if (AllowConstructorName &&
2623 Actions.isCurrentClassName(*Id,
getCurScope(), &SS)) {
2629 Result.setConstructorName(Ty, IdLoc, IdLoc);
2632 Actions.isDeductionGuideName(
getCurScope(), *Id, IdLoc, SS,
2638 Result.setIdentifier(Id, IdLoc);
2643 if (Tok.is(tok::less))
2644 return ParseUnqualifiedIdTemplateId(
2645 SS, ObjectType, ObjectHadErrors,
2647 EnteringContext,
Result, TemplateSpecified);
2649 if (TemplateSpecified) {
2652 ObjectType, EnteringContext,
Template,
2663 Diag(IdLoc, diag::missing_template_arg_list_after_template_kw);
2670 if (Tok.is(tok::annot_template_id)) {
2676 ConsumeAnnotationToken();
2681 if (AllowConstructorName && TemplateId->
Name &&
2689 diag::err_out_of_line_constructor_template_id)
2700 ConsumeAnnotationToken();
2704 Result.setConstructorTemplateId(TemplateId);
2705 ConsumeAnnotationToken();
2711 Result.setTemplateId(TemplateId);
2714 if (TemplateKWLoc && (ObjectType || SS.
isSet()))
2715 *TemplateKWLoc = TemplateLoc;
2717 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2720 ConsumeAnnotationToken();
2727 if (Tok.is(tok::kw_operator)) {
2728 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
Result))
2740 return ParseUnqualifiedIdTemplateId(
2741 SS, ObjectType, ObjectHadErrors,
2744 else if (TemplateSpecified &&
2745 Actions.ActOnTemplateName(
2755 (AllowDestructorName || SS.
isSet()) && Tok.is(tok::tilde)) {
2764 if (TemplateSpecified) {
2775 Diag(*TemplateKWLoc, diag::err_unexpected_template_in_destructor_name)
2776 << Tok.getLocation();
2780 if (SS.
isEmpty() && Tok.is(tok::kw_decltype)) {
2784 Actions.getDestructorTypeForDecltype(DS, ObjectType)) {
2785 Result.setDestructorName(TildeLoc,
Type, EndLoc);
2792 if (Tok.isNot(tok::identifier)) {
2793 Diag(Tok, diag::err_destructor_tilde_identifier);
2798 DeclaratorScopeObj DeclScopeObj(*
this, SS);
2806 AnnotateScopeToken(SS,
true);
2809 if (ParseOptionalCXXScopeSpecifier(SS, ObjectType, ObjectHadErrors,
2813 ObjectType =
nullptr;
2814 if (Tok.isNot(tok::identifier) ||
NextToken().
is(tok::coloncolon) ||
2816 Diag(TildeLoc, diag::err_destructor_tilde_scope);
2821 Diag(TildeLoc, diag::err_destructor_tilde_scope)
2826 if (Actions.ShouldEnterDeclaratorScope(
getCurScope(), SS))
2827 DeclScopeObj.EnterDeclaratorScope();
2834 if (Tok.is(tok::less)) {
2835 Result.setDestructorName(TildeLoc,
nullptr, ClassNameLoc);
2836 return ParseUnqualifiedIdTemplateId(
2837 SS, ObjectType, ObjectHadErrors,
2839 ClassNameLoc, EnteringContext,
Result, TemplateSpecified);
2844 Actions.getDestructorName(*ClassName, ClassNameLoc,
getCurScope(), SS,
2845 ObjectType, EnteringContext);
2849 Result.setDestructorName(TildeLoc, Ty, ClassNameLoc);
2853 switch (Tok.getKind()) {
2854#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
2855#include "clang/Basic/TransformTypeTraits.def"
2857 Tok.setKind(tok::identifier);
2858 Diag(Tok, diag::ext_keyword_as_ident)
2859 << Tok.getIdentifierInfo()->getName() << 0;
2860 goto ParseIdentifier;
2864 Diag(Tok, diag::err_expected_unqualified_id) <<
getLangOpts().CPlusPlus;
2870Parser::ParseCXXNewExpression(
bool UseGlobal,
SourceLocation Start) {
2871 assert(
Tok.is(tok::kw_new) &&
"expected 'new' token");
2877 ExprVector PlacementArgs;
2884 if (
Tok.is(tok::l_paren)) {
2888 PlacementLParen = T.getOpenLocation();
2889 if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) {
2895 PlacementRParen = T.getCloseLocation();
2901 if (PlacementArgs.empty()) {
2903 TypeIdParens = T.getRange();
2904 PlacementLParen = PlacementRParen = SourceLocation();
2907 if (Tok.is(tok::l_paren)) {
2910 MaybeParseGNUAttributes(DeclaratorInfo);
2911 ParseSpecifierQualifierList(DS);
2913 ParseDeclarator(DeclaratorInfo);
2915 TypeIdParens = T.getRange();
2917 MaybeParseGNUAttributes(DeclaratorInfo);
2918 if (ParseCXXTypeSpecifierSeq(DS))
2919 DeclaratorInfo.setInvalidType(
true);
2922 ParseDeclaratorInternal(DeclaratorInfo,
2923 &Parser::ParseDirectNewDeclarator);
2930 MaybeParseGNUAttributes(DeclaratorInfo);
2932 DeclaratorInfo.setInvalidType(
true);
2935 ParseDeclaratorInternal(DeclaratorInfo,
2936 &Parser::ParseDirectNewDeclarator);
2939 if (DeclaratorInfo.isInvalidType()) {
2946 if (Tok.is(tok::l_paren)) {
2947 SourceLocation ConstructorLParen, ConstructorRParen;
2948 ExprVector ConstructorArgs;
2951 ConstructorLParen = T.getOpenLocation();
2952 if (Tok.isNot(tok::r_paren)) {
2953 auto RunSignatureHelp = [&]() {
2954 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
2955 QualType PreferredType;
2961 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
2963 DeclaratorInfo.getEndLoc(), ConstructorArgs,
2966 CalledSignatureHelp =
true;
2967 return PreferredType;
2969 if (ParseExpressionList(ConstructorArgs, [&] {
2970 PreferredType.enterFunctionArgument(Tok.getLocation(),
2973 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
2980 ConstructorRParen = T.getCloseLocation();
2985 Initializer = Actions.ActOnParenListExpr(ConstructorLParen,
2989 Diag(Tok.getLocation(),
2990 diag::warn_cxx98_compat_generalized_initializer_lists);
2996 return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen,
2997 PlacementArgs, PlacementRParen,
3001void Parser::ParseDirectNewDeclarator(Declarator &D) {
3004 while (Tok.is(tok::l_square)) {
3006 if (CheckProhibitedCXX11Attribute())
3015 if (
Size.isInvalid()) {
3017 SkipUntil(tok::r_square, StopAtSemi);
3025 ParsedAttributes Attrs(AttrFactory);
3026 MaybeParseCXX11Attributes(Attrs);
3030 Size.get(), T.getOpenLocation(),
3031 T.getCloseLocation()),
3032 std::move(Attrs), T.getCloseLocation());
3034 if (T.getCloseLocation().isInvalid())
3039bool Parser::ParseExpressionListOrTypeId(
3040 SmallVectorImpl<Expr*> &PlacementArgs,
3043 if (isTypeIdInParens()) {
3051 return ParseExpressionList(PlacementArgs);
3055Parser::ParseCXXDeleteExpression(
bool UseGlobal, SourceLocation Start) {
3056 assert(Tok.is(tok::kw_delete) &&
"Expected 'delete' keyword");
3060 bool ArrayDelete =
false;
3061 if (Tok.is(tok::l_square) &&
NextToken().
is(tok::r_square)) {
3072 if (
Next.isOneOf(tok::l_brace, tok::less) ||
3073 (
Next.is(tok::l_paren) &&
3077 TentativeParsingAction TPA(*
this);
3078 SourceLocation LSquareLoc = Tok.getLocation();
3084 SourceLocation RBraceLoc;
3085 bool EmitFixIt =
false;
3086 if (Tok.is(tok::l_brace)) {
3089 RBraceLoc = Tok.getLocation();
3096 Diag(Start, diag::err_lambda_after_delete)
3097 << SourceRange(Start, RSquareLoc)
3101 RBraceLoc, 0, Actions.getSourceManager(),
getLangOpts()),
3104 Diag(Start, diag::err_lambda_after_delete)
3105 << SourceRange(Start, RSquareLoc);
3114 Lambda = ParsePostfixExpressionSuffix(Lambda);
3117 return Actions.ActOnCXXDelete(Start, UseGlobal,
false,
3126 if (T.getCloseLocation().isInvalid())
3134 return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete,
Operand.get());
3137ExprResult Parser::ParseRequiresExpression() {
3138 assert(Tok.is(tok::kw_requires) &&
"Expected 'requires' keyword");
3141 llvm::SmallVector<ParmVarDecl *, 2> LocalParameterDecls;
3143 if (Tok.is(tok::l_paren)) {
3148 if (!Tok.is(tok::r_paren)) {
3150 SourceLocation EllipsisLoc;
3151 llvm::SmallVector<DeclaratorChunk::ParamInfo, 2> LocalParameters;
3153 FirstArgAttrs, LocalParameters,
3156 Diag(EllipsisLoc, diag::err_requires_expr_parameter_list_ellipsis);
3157 for (
auto &ParamInfo : LocalParameters)
3164 if (
Braces.expectAndConsume())
3168 llvm::SmallVector<concepts::Requirement *, 2> Requirements;
3172 EnterExpressionEvaluationContext Ctx(
3180 RequiresExprBodyDecl *Body = Actions.ActOnStartRequiresExpr(
3181 RequiresKWLoc, LocalParameterDecls,
getCurScope());
3183 if (Tok.is(tok::r_brace)) {
3190 Diag(Tok, diag::err_empty_requires_expr);
3193 while (!Tok.is(tok::r_brace)) {
3194 switch (Tok.getKind()) {
3195 case tok::l_brace: {
3206 ExprBraces.consumeOpen();
3208 if (Expression.isUsable())
3209 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3210 if (!Expression.isUsable()) {
3211 ExprBraces.skipToEnd();
3217 if (ExprBraces.consumeClose())
3220 concepts::Requirement *Req =
nullptr;
3221 SourceLocation NoexceptLoc;
3223 if (Tok.is(tok::semi)) {
3224 Req = Actions.ActOnCompoundRequirement(Expression.get(), NoexceptLoc);
3226 Requirements.push_back(Req);
3231 Diag(Tok, diag::err_requires_expr_missing_arrow)
3234 if (TryAnnotateTypeConstraint()) {
3238 if (!isTypeConstraintAnnotation()) {
3239 Diag(Tok, diag::err_requires_expr_expected_type_constraint);
3244 if (Tok.is(tok::annot_cxxscope)) {
3245 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
3246 Tok.getAnnotationRange(),
3248 ConsumeAnnotationToken();
3251 Req = Actions.ActOnCompoundRequirement(
3252 Expression.get(), NoexceptLoc, SS, takeTemplateIdAnnotation(Tok),
3253 TemplateParameterDepth);
3254 ConsumeAnnotationToken();
3256 Requirements.push_back(Req);
3260 bool PossibleRequiresExprInSimpleRequirement =
false;
3261 if (Tok.is(tok::kw_requires)) {
3262 auto IsNestedRequirement = [&] {
3263 RevertingTentativeParsingAction TPA(*
this);
3265 if (Tok.is(tok::l_brace))
3272 if (Tok.is(tok::l_paren)) {
3275 auto Res = TryParseParameterDeclarationClause();
3276 if (Res != TPResult::False) {
3279 while (Depth != 0) {
3280 bool FoundParen =
SkipUntil(tok::l_paren, tok::r_paren,
3284 if (Tok.is(tok::l_paren))
3286 else if (Tok.is(tok::r_paren))
3297 if (Tok.is(tok::l_brace))
3306 if (IsNestedRequirement()) {
3319 Actions.ActOnNestedRequirement(ConstraintExpr.
get()))
3320 Requirements.push_back(Req);
3328 PossibleRequiresExprInSimpleRequirement =
true;
3329 }
else if (Tok.is(tok::kw_typename)) {
3332 TentativeParsingAction TPA(*
this);
3342 if (Tok.is(tok::annot_cxxscope)) {
3343 Actions.RestoreNestedNameSpecifierAnnotation(
3344 Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS);
3345 ConsumeAnnotationToken();
3348 if (Tok.isOneOf(tok::identifier, tok::annot_template_id) &&
3351 SourceLocation NameLoc = Tok.getLocation();
3352 IdentifierInfo *II =
nullptr;
3353 TemplateIdAnnotation *TemplateId =
nullptr;
3354 if (Tok.is(tok::identifier)) {
3355 II = Tok.getIdentifierInfo();
3358 TemplateId = takeTemplateIdAnnotation(Tok);
3359 ConsumeAnnotationToken();
3364 if (
auto *Req = Actions.ActOnTypeRequirement(TypenameKWLoc, SS,
3367 Requirements.push_back(Req);
3377 SourceLocation StartLoc = Tok.getLocation();
3379 if (Expression.isUsable())
3380 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3381 if (!Expression.isUsable()) {
3385 if (!Expression.isInvalid() && PossibleRequiresExprInSimpleRequirement)
3386 Diag(StartLoc, diag::err_requires_expr_in_simple_requirement)
3388 if (
auto *Req = Actions.ActOnSimpleRequirement(Expression.get()))
3389 Requirements.push_back(Req);
3395 if (Tok.is(tok::kw_noexcept)) {
3396 Diag(Tok, diag::err_requires_expr_simple_requirement_noexcept)
3405 if (ExpectAndConsumeSemi(diag::err_expected_semi_requirement)) {
3411 if (Requirements.empty()) {
3416 Actions.ActOnFinishRequiresExpr();
3421 Actions.ActOnFinishRequiresExpr();
3422 ParsingBodyDecl.complete(Body);
3423 return Actions.ActOnRequiresExpr(
3424 RequiresKWLoc, Body,
Parens.getOpenLocation(), LocalParameterDecls,
3425 Parens.getCloseLocation(), Requirements,
Braces.getCloseLocation());
3430 default: llvm_unreachable(
"Not a known type trait");
3431#define TYPE_TRAIT_1(Spelling, Name, Key) \
3432case tok::kw_ ## Spelling: return UTT_ ## Name;
3433#define TYPE_TRAIT_2(Spelling, Name, Key) \
3434case tok::kw_ ## Spelling: return BTT_ ## Name;
3435#include "clang/Basic/TokenKinds.def"
3436#define TYPE_TRAIT_N(Spelling, Name, Key) \
3437 case tok::kw_ ## Spelling: return TT_ ## Name;
3438#include "clang/Basic/TokenKinds.def"
3445 llvm_unreachable(
"Not a known array type trait");
3446#define ARRAY_TYPE_TRAIT(Spelling, Name, Key) \
3447 case tok::kw_##Spelling: \
3449#include "clang/Basic/TokenKinds.def"
3456 llvm_unreachable(
"Not a known unary expression trait.");
3457#define EXPRESSION_TRAIT(Spelling, Name, Key) \
3458 case tok::kw_##Spelling: \
3460#include "clang/Basic/TokenKinds.def"
3470 if (
Parens.expectAndConsume())
3473 SmallVector<ParsedType, 2> Args;
3486 if (Tok.is(tok::ellipsis)) {
3495 Args.push_back(Ty.
get());
3498 if (
Parens.consumeClose())
3501 SourceLocation EndLoc =
Parens.getCloseLocation();
3511 if (T.expectAndConsume())
3523 case ATT_ArrayRank: {
3525 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(),
nullptr,
3526 T.getCloseLocation());
3528 case ATT_ArrayExtent: {
3529 if (ExpectAndConsume(tok::comma)) {
3540 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(), DimExpr.
get(),
3541 T.getCloseLocation());
3544 llvm_unreachable(
"Invalid ArrayTypeTrait!");
3552 if (T.expectAndConsume())
3559 return Actions.ActOnExpressionTrait(ET, Loc, Expr.
get(),
3560 T.getCloseLocation());
3570 "Compound literals are not ambiguous!");
3571 assert(isTypeIdInParens() &&
"Not a type-id!");
3600 if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) {
3606 if (Tok.is(tok::l_brace)) {
3610 if (Tok.is(tok::l_paren) &&
NextToken().
is(tok::r_paren)) {
3618 false , NotCastExpr,
3631 AttrEnd.startToken();
3632 AttrEnd.setKind(tok::eof);
3633 AttrEnd.setLocation(Tok.getLocation());
3634 AttrEnd.setEofData(Toks.data());
3635 Toks.push_back(AttrEnd);
3638 Toks.push_back(Tok);
3641 PP.EnterTokenStream(Toks,
true,
3649 DeclSpec DS(AttrFactory);
3654 ParseSpecifierQualifierList(DS);
3655 ParseDeclarator(DeclaratorInfo);
3663 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3668 if (DeclaratorInfo.isInvalidType())
3671 TypeResult Ty = Actions.ActOnTypeName(DeclaratorInfo);
3672 return ParseCompoundLiteralExpression(Ty.
get(),
3680 if (DeclaratorInfo.isInvalidType())
3686 DeclaratorInfo, CastTy,
3696 if (!
Result.isInvalid() && Tok.is(tok::r_paren))
3698 Tok.getLocation(),
Result.get());
3701 if (
Result.isInvalid()) {
3702 while (Tok.isNot(tok::eof))
3704 assert(Tok.getEofData() == AttrEnd.getEofData());
3711 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3720 if (T.expectAndConsume(diag::err_expected_lparen_after,
"__builtin_bit_cast"))
3724 DeclSpec DS(AttrFactory);
3725 ParseSpecifierQualifierList(DS);
3730 ParseDeclarator(DeclaratorInfo);
3732 if (ExpectAndConsume(tok::comma)) {
3733 Diag(Tok.getLocation(), diag::err_expected) << tok::comma;
3740 if (T.consumeClose())
3743 if (
Operand.isInvalid() || DeclaratorInfo.isInvalidType())
3746 return Actions.ActOnBuiltinBitCastExpr(KWLoc, DeclaratorInfo, Operand,
3747 T.getCloseLocation());
Defines the clang::ASTContext interface.
This file defines the classes used to store parsed information about declaration-specifiers and decla...
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
static void addConstexprToLambdaDeclSpecifier(Parser &P, SourceLocation ConstexprLoc, DeclSpec &DS)
static void FixDigraph(Parser &P, Preprocessor &PP, Token &DigraphToken, Token &ColonToken, tok::TokenKind Kind, bool AtDigraph)
static ArrayTypeTrait ArrayTypeTraitFromTokKind(tok::TokenKind kind)
static void tryConsumeLambdaSpecifierToken(Parser &P, SourceLocation &MutableLoc, SourceLocation &StaticLoc, SourceLocation &ConstexprLoc, SourceLocation &ConstevalLoc, SourceLocation &DeclEndLoc)
static ExpressionTrait ExpressionTraitFromTokKind(tok::TokenKind kind)
static void addConstevalToLambdaDeclSpecifier(Parser &P, SourceLocation ConstevalLoc, DeclSpec &DS)
static TypeTrait TypeTraitFromTokKind(tok::TokenKind kind)
static void DiagnoseStaticSpecifierRestrictions(Parser &P, SourceLocation StaticLoc, SourceLocation MutableLoc, const LambdaIntroducer &Intro)
static int SelectDigraphErrorMessage(tok::TokenKind Kind)
static void addStaticToLambdaDeclSpecifier(Parser &P, SourceLocation StaticLoc, DeclSpec &DS)
Defines the PrettyStackTraceEntry class, which is used to make crashes give more contextual informati...
static constexpr bool isOneOf()
This file declares facilities that support code completion.
Defines the clang::TemplateNameKind enum.
Defines the clang::TokenKind enum and support functions.
const clang::PrintingPolicy & getPrintingPolicy() const
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ....
SourceLocation getOpenLocation() const
SourceLocation getCloseLocation() const
Represents a C++ nested-name-specifier or a global scope specifier.
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
SourceRange getRange() const
SourceLocation getBeginLoc() const
bool isSet() const
Deprecated.
void setEndLoc(SourceLocation Loc)
void SetInvalid(SourceRange R)
Indicate that this nested-name-specifier is invalid.
bool isEmpty() const
No scope specifier.
void restore()
restore - This can be used to restore the state early, before the dtor is run.
Captures information about "declaration specifiers".
static const TST TST_typename
SourceLocation getEndLoc() const LLVM_READONLY
bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec and return false if there was no error.
static const TST TST_char8
static const TST TST_BFloat16
bool SetConstexprSpec(ConstexprSpecKind ConstexprKind, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
bool SetTypeSpecWidth(TypeSpecifierWidth W, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec, but return true and ignore the request if ...
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
SourceRange getSourceRange() const LLVM_READONLY
void SetRangeEnd(SourceLocation Loc)
bool SetBitIntType(SourceLocation KWLoc, Expr *BitWidth, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
static const TST TST_double
void SetRangeStart(SourceLocation Loc)
static const TST TST_char
static const TST TST_bool
static const TST TST_char16
static const TST TST_accum
static const TST TST_half
static const TST TST_ibm128
static const TST TST_float128
void Finish(Sema &S, const PrintingPolicy &Policy)
Finish - This does final analysis of the declspec, issuing diagnostics for things like "_Complex" (la...
static const TST TST_wchar
static const TST TST_void
static const TST TST_float
static const TST TST_fract
static const TST TST_float16
static const TST TST_decltype_auto
static const TST TST_error
static const TST TST_char32
static const TST TST_int128
bool SetTypeSpecSign(TypeSpecifierSign S, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
static const TST TST_auto
SourceLocation getLocation() const
Information about one declarator, including the parsed type information and the identifier.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
void SetSourceRange(SourceRange R)
void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc)
AddTypeInfo - Add a chunk to this declarator.
bool isInvalidType() const
DeclSpec & getMutableDeclSpec()
getMutableDeclSpec - Return a non-const version of the DeclSpec.
This represents one expression.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
static SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, unsigned Characters, const SourceManager &SM, const LangOptions &LangOpts)
AdvanceToTokenCharacter - If the current SourceLocation specifies a location at the start of a token,...
static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, const LangOptions &LangOpts)
Computes the source location just past the end of the token at this source location.
void * getAsOpaquePtr() const
static OpaquePtr make(QualType P)
static const ParsedAttributesView & none()
ParsedAttributes - A collection of parsed attributes.
Introduces zero or more scopes for parsing.
ParseScope - Introduces a new scope for parsing.
Parser - This implements a parser for the C family of languages.
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeName, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
SourceLocation getEndOfPreviousToken() const
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
AttributeFactory & getAttrFactory()
Sema & getActions() const
static TypeResult getTypeAnnotation(const Token &Tok)
getTypeAnnotation - Read a parsed type out of an annotation token.
ExprResult ParseConstraintLogicalOrExpression(bool IsTrailingRequiresClause)
Parse a constraint-logical-or-expression.
bool ParseUnqualifiedId(CXXScopeSpec &SS, ParsedType ObjectType, bool ObjectHadErrors, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, SourceLocation *TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
bool TryAnnotateOptionalCXXScopeToken(bool EnteringContext=false)
friend class ColonProtectionRAIIObject
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type.
const Token & GetLookAheadToken(unsigned N)
GetLookAheadToken - This peeks ahead N tokens and returns that token without consuming any tokens.
ExprResult ParseConstantExpression()
bool TryConsumeToken(tok::TokenKind Expected)
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
Scope * getCurScope() const
friend class InMessageExpressionRAIIObject
OpaquePtr< TemplateName > TemplateTy
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
const Token & getCurToken() const
const LangOptions & getLangOpts() const
friend class ParenBraceBracketBalancer
ExprResult ParseExpression(TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
Simple precedence-based parser for binary/ternary operators.
@ StopBeforeMatch
Stop skipping at specified token, but don't skip the token itself.
@ StopAtSemi
Stop skipping at semicolon.
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
ExprResult ParseAssignmentExpression(TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
Parse an expr that doesn't include (top-level) commas.
friend class BalancedDelimiterTracker
ExprResult ParseConstraintExpression()
Parse a constraint-expression.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
void Lex(Token &Result)
Lex the next token for this preprocessor.
void AddFlags(unsigned Flags)
Sets up the specified scope flags and adjusts the scope state variables accordingly.
void setIsConditionVarScope(bool InConditionVarScope)
@ FunctionPrototypeScope
This is a scope that corresponds to the parameters within a function prototype.
@ LambdaScope
This is the scope for a lambda, after the lambda introducer.
@ BlockScope
This is a scope that corresponds to a block/closure object.
@ ContinueScope
This is a while, do, for, which can have continue statements embedded into it.
@ BreakScope
This is a while, do, switch, for, etc that can have break statements embedded into it.
@ CompoundStmtScope
This is a compound statement scope.
@ FunctionDeclarationScope
This is a scope that corresponds to the parameters within a function prototype for a function declara...
@ FnScope
This indicates that the scope corresponds to a function, which means that labels are set here.
@ DeclScope
This is a scope that can contain a declaration.
@ PCC_Condition
Code completion occurs within the condition of an if, while, switch, or for statement.
@ Switch
An integral condition for a 'switch' statement.
@ ConstexprIf
A constant boolean condition from 'if constexpr'.
ASTContext & getASTContext() const
@ ConstantEvaluated
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
static ConditionResult ConditionError()
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
A trivial tuple used to represent a source range.
void setBegin(SourceLocation b)
SourceLocation getEnd() const
SourceLocation getBegin() const
void setEnd(SourceLocation e)
SourceLocation getEndLoc() const LLVM_READONLY
SourceLocation getBeginLoc() const LLVM_READONLY
Represents a C++ template name within the type system.
Token - This structure provides full information about a lexed token.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
const char * getName() const
void setLength(unsigned Len)
void setKind(tok::TokenKind K)
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
tok::TokenKind getKind() const
void setLocation(SourceLocation L)
The base class of the type hierarchy.
QualType getCanonicalTypeInternal() const
Represents a C++ unqualified-id that has been parsed.
struct OFI OperatorFunctionId
When Kind == IK_OperatorFunctionId, the overloaded operator that we parsed.
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
bool isValid() const
Determine whether this unqualified-id refers to a valid name.
void setDestructorName(SourceLocation TildeLoc, ParsedType ClassType, SourceLocation EndLoc)
Specify that this unqualified-id was parsed as a destructor name.
void setTemplateId(TemplateIdAnnotation *TemplateId)
Specify that this unqualified-id was parsed as a template-id.
UnionParsedType DestructorName
When Kind == IK_DestructorName, the type referred to by the class-name.
SourceLocation StartLocation
The location of the first token that describes this unqualified-id, which will be the location of the...
void setConstructorName(ParsedType ClassType, SourceLocation ClassNameLoc, SourceLocation EndLoc)
Specify that this unqualified-id was parsed as a constructor name.
const IdentifierInfo * Identifier
When Kind == IK_Identifier, the parsed identifier, or when Kind == IK_UserLiteralId,...
UnqualifiedIdKind getKind() const
Determine what kind of name we have.
uint32_t Literal
Literals are represented as positive integers.
@ After
Like System, but searched after the system directories.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
OpaquePtr< TemplateName > ParsedTemplateTy
@ NotAttributeSpecifier
This is not an attribute specifier.
ArrayTypeTrait
Names for the array type traits.
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
LambdaCaptureKind
The different capture forms in a lambda introducer.
@ LCK_ByCopy
Capturing by copy (a.k.a., by value)
@ LCK_ByRef
Capturing by reference.
@ LCK_StarThis
Capturing the *this object by copy.
@ LCK_This
Capturing the *this object by reference.
@ IK_ConstructorName
A constructor name.
@ IK_LiteralOperatorId
A user-defined literal name, e.g., operator "" _i.
@ IK_Identifier
An identifier.
@ IK_DestructorName
A destructor name.
@ IK_OperatorFunctionId
An overloaded operator name, e.g., operator+.
ActionResult< Decl * > DeclResult
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
MutableArrayRef< Expr * > MultiExprArg
@ CopyInit
[a = b], [a = {b}]
@ Result
The result type of a method or function.
ActionResult< ParsedType > TypeResult
@ Template
We are parsing a template declaration.
@ Type
The name was classified as a type.
MutableArrayRef< ParsedTemplateArgument > ASTTemplateArgsPtr
TemplateNameKind
Specifies the kind of template name that an identifier refers to.
@ TNK_Var_template
The name refers to a variable template whose specialization produces a variable.
@ TNK_Dependent_template_name
The name refers to a dependent template name:
@ TNK_Function_template
The name refers to a function template or a set of overloaded functions that includes at least one fu...
@ TNK_Non_template
The name does not refer to a template.
@ TNK_Undeclared_template
Lookup for the name failed, but we're assuming it was a template name anyway.
const char * getOperatorSpelling(OverloadedOperatorKind Operator)
Retrieve the spelling of the given overloaded operator, without the preceding "operator" keyword.
U cast(CodeGen::Address addr)
SmallVector< Token, 4 > CachedTokens
A set of tokens that has been cached for later parsing.
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
@ None
No keyword precedes the qualified type name.
ParenParseOption
ParenParseOption - Control what ParseParenExpression will parse.
ActionResult< Expr * > ExprResult
TypeTrait
Names for traits that operate specifically on types.
@ Parens
New-expression has a C++98 paren-delimited initializer.
@ Braces
New-expression has a C++11 list-initializer.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_None
no exception specification
ActionResult< Stmt * > StmtResult
static DeclaratorChunk getFunction(bool HasProto, bool IsAmbiguous, SourceLocation LParenLoc, ParamInfo *Params, unsigned NumParams, SourceLocation EllipsisLoc, SourceLocation RParenLoc, bool RefQualifierIsLvalueRef, SourceLocation RefQualifierLoc, SourceLocation MutableLoc, ExceptionSpecificationType ESpecType, SourceRange ESpecRange, ParsedType *Exceptions, SourceRange *ExceptionRanges, unsigned NumExceptions, Expr *NoexceptExpr, CachedTokens *ExceptionSpecTokens, ArrayRef< NamedDecl * > DeclsInPrototype, SourceLocation LocalRangeBegin, SourceLocation LocalRangeEnd, Declarator &TheDeclarator, TypeResult TrailingReturnType=TypeResult(), SourceLocation TrailingReturnTypeLoc=SourceLocation(), DeclSpec *MethodQualifiers=nullptr)
DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
static DeclaratorChunk getArray(unsigned TypeQuals, bool isStatic, bool isStar, Expr *NumElts, SourceLocation LBLoc, SourceLocation RBLoc)
Return a DeclaratorChunk for an array.
Represents a complete lambda introducer.
bool hasLambdaCapture() const
void addCapture(LambdaCaptureKind Kind, SourceLocation Loc, IdentifierInfo *Id, SourceLocation EllipsisLoc, LambdaCaptureInitKind InitKind, ExprResult Init, ParsedType InitCaptureType, SourceRange ExplicitRange)
Append a capture in a lambda introducer.
SourceLocation DefaultLoc
LambdaCaptureDefault Default
Information about a template-id annotation token.
const IdentifierInfo * Name
FIXME: Temporarily stores the name of a specialization.
unsigned NumArgs
NumArgs - The number of template arguments.
SourceLocation TemplateNameLoc
TemplateNameLoc - The location of the template name within the source.
ParsedTemplateArgument * getTemplateArgs()
Retrieves a pointer to the template arguments.
SourceLocation RAngleLoc
The location of the '>' after the template argument list.
SourceLocation LAngleLoc
The location of the '<' before the template argument list.
SourceLocation TemplateKWLoc
TemplateKWLoc - The location of the template keyword.
ParsedTemplateTy Template
The declaration of the template corresponding to the template-name.
static TemplateIdAnnotation * Create(SourceLocation TemplateKWLoc, SourceLocation TemplateNameLoc, const IdentifierInfo *Name, OverloadedOperatorKind OperatorKind, ParsedTemplateTy OpaqueTemplateName, TemplateNameKind TemplateKind, SourceLocation LAngleLoc, SourceLocation RAngleLoc, ArrayRef< ParsedTemplateArgument > TemplateArgs, bool ArgsInvalid, SmallVectorImpl< TemplateIdAnnotation * > &CleanupList)
Creates a new TemplateIdAnnotation with NumArgs arguments and appends it to List.
OpaquePtr< T > get() const
OverloadedOperatorKind Operator
The kind of overloaded operator.