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 SourceLocation DeclLoc = Tok.getLocation();
1229 Actions.ActOnLambdaExpressionAfterIntroducer(Intro,
getCurScope());
1231 ParsedAttributes Attributes(AttrFactory);
1239 if (Tok.is(tok::kw___noinline__)) {
1240 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1242 Attributes.addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
1244 0, tok::kw___noinline__);
1245 }
else if (Tok.is(tok::kw___attribute))
1246 ParseGNUAttributes(Attributes,
nullptr, &D);
1251 D.takeAttributesAppending(Attributes);
1255 if (Tok.is(tok::less)) {
1257 ? diag::warn_cxx17_compat_lambda_template_parameter_list
1258 : diag::ext_lambda_template_parameter_list);
1260 SmallVector<NamedDecl*, 4> TemplateParams;
1261 SourceLocation LAngleLoc, RAngleLoc;
1262 if (ParseTemplateParameters(TemplateParamScope,
1263 CurTemplateDepthTracker.getDepth(),
1264 TemplateParams, LAngleLoc, RAngleLoc)) {
1265 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1269 if (TemplateParams.empty()) {
1271 diag::err_lambda_template_parameter_list_empty);
1282 ++CurTemplateDepthTracker;
1292 Actions.ActOnLambdaExplicitTemplateParameterList(
1293 Intro, LAngleLoc, TemplateParams, RAngleLoc, RequiresClause);
1301 if (isCXX11AttributeSpecifier() !=
1304 ? diag::warn_cxx20_compat_decl_attrs_on_lambda
1305 : diag::ext_decl_attrs_on_lambda)
1306 << Tok.isRegularKeywordAttribute() << Tok.getIdentifierInfo();
1307 MaybeParseCXX11Attributes(D);
1311 SourceLocation TrailingReturnTypeLoc;
1312 SourceLocation LParenLoc, RParenLoc;
1313 SourceLocation DeclEndLoc = DeclLoc;
1314 bool HasParentheses =
false;
1315 bool HasSpecifiers =
false;
1316 SourceLocation MutableLoc;
1323 SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
1324 SourceLocation EllipsisLoc;
1326 if (Tok.is(tok::l_paren)) {
1329 LParenLoc =
T.getOpenLocation();
1331 if (Tok.isNot(tok::r_paren)) {
1332 Actions.RecordParsingTemplateParameterDepth(
1333 CurTemplateDepthTracker.getOriginalDepth());
1335 ParseParameterDeclarationClause(D, Attributes, ParamInfo, EllipsisLoc);
1341 if (Actions.getCurGenericLambda())
1342 CurTemplateDepthTracker.setAddedDepth(1);
1346 DeclEndLoc = RParenLoc =
T.getCloseLocation();
1347 HasParentheses =
true;
1351 Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
1352 tok::kw_constexpr, tok::kw_consteval, tok::kw_static,
1353 tok::kw___private, tok::kw___global, tok::kw___local,
1354 tok::kw___constant, tok::kw___generic, tok::kw_groupshared,
1355 tok::kw_requires, tok::kw_noexcept) ||
1356 Tok.isRegularKeywordAttribute() ||
1357 (Tok.is(tok::l_square) &&
NextToken().
is(tok::l_square));
1363 Diag(Tok, diag::ext_lambda_missing_parens)
1367 if (HasParentheses || HasSpecifiers) {
1371 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec, Attributes);
1374 SourceLocation ConstexprLoc;
1375 SourceLocation ConstevalLoc;
1376 SourceLocation StaticLoc;
1379 ConstevalLoc, DeclEndLoc);
1388 Actions.ActOnLambdaClosureParameters(
getCurScope(), ParamInfo);
1390 if (!HasParentheses)
1391 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1393 if (HasSpecifiers || HasParentheses) {
1396 SourceRange ESpecRange;
1397 SmallVector<ParsedType, 2> DynamicExceptions;
1398 SmallVector<SourceRange, 2> DynamicExceptionRanges;
1402 ESpecType = tryParseExceptionSpecification(
1403 false, ESpecRange, DynamicExceptions,
1404 DynamicExceptionRanges, NoexceptExpr, ExceptionSpecTokens);
1407 DeclEndLoc = ESpecRange.
getEnd();
1410 if (MaybeParseCXX11Attributes(Attributes))
1411 DeclEndLoc = Attributes.Range.getEnd();
1414 if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
1415 tok::kw___constant, tok::kw___generic)) {
1416 ParseOpenCLQualifiers(DS.getAttributes());
1420 SourceLocation FunLocalRangeEnd = DeclEndLoc;
1423 if (Tok.is(tok::arrow)) {
1424 FunLocalRangeEnd = Tok.getLocation();
1426 TrailingReturnType =
1427 ParseTrailingReturnType(Range,
false);
1428 TrailingReturnTypeLoc =
Range.getBegin();
1429 if (
Range.getEnd().isValid())
1430 DeclEndLoc =
Range.getEnd();
1433 SourceLocation NoLoc;
1436 false, LParenLoc, ParamInfo.data(),
1437 ParamInfo.size(), EllipsisLoc, RParenLoc,
1439 NoLoc, MutableLoc, ESpecType,
1440 ESpecRange, DynamicExceptions.data(),
1441 DynamicExceptionRanges.data(), DynamicExceptions.size(),
1442 NoexceptExpr.
isUsable() ? NoexceptExpr.
get() :
nullptr,
1444 {}, LParenLoc, FunLocalRangeEnd, D,
1445 TrailingReturnType, TrailingReturnTypeLoc, &DS),
1446 std::move(Attributes), DeclEndLoc);
1451 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1453 if (HasParentheses && Tok.is(tok::kw_requires))
1454 ParseTrailingRequiresClause(D);
1460 for (
const ParsedAttr &A : Attributes)
1461 if (A.getKind() == ParsedAttr::AT_CUDADevice ||
1462 A.getKind() == ParsedAttr::AT_CUDAHost ||
1463 A.getKind() == ParsedAttr::AT_CUDAGlobal)
1464 Diag(A.getLoc(), diag::warn_cuda_attr_lambda_position)
1465 << A.getAttrName()->getName();
1476 Actions.ActOnStartOfLambdaDefinition(Intro, D, DS);
1479 if (!Tok.is(tok::l_brace)) {
1480 Diag(Tok, diag::err_expected_lambda_body);
1481 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1485 StmtResult Stmt(ParseCompoundStatementBody());
1487 TemplateParamScope.Exit();
1490 if (!Stmt.isInvalid() && !TrailingReturnType.
isInvalid() &&
1492 return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.get());
1494 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1500 const char *CastName =
nullptr;
1503 default: llvm_unreachable(
"Unknown C++ cast!");
1504 case tok::kw_addrspace_cast: CastName =
"addrspace_cast";
break;
1505 case tok::kw_const_cast: CastName =
"const_cast";
break;
1506 case tok::kw_dynamic_cast: CastName =
"dynamic_cast";
break;
1507 case tok::kw_reinterpret_cast: CastName =
"reinterpret_cast";
break;
1508 case tok::kw_static_cast: CastName =
"static_cast";
break;
1512 SourceLocation LAngleBracketLoc = Tok.getLocation();
1516 if (Tok.is(tok::l_square) && Tok.getLength() == 2) {
1518 if (
Next.is(tok::colon) && areTokensAdjacent(Tok,
Next))
1522 if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName))
1526 DeclSpec DS(AttrFactory);
1527 ParseSpecifierQualifierList(DS,
AS_none,
1528 DeclSpecContext::DSC_type_specifier);
1533 ParseDeclarator(DeclaratorInfo);
1535 SourceLocation RAngleBracketLoc = Tok.getLocation();
1537 if (ExpectAndConsume(tok::greater))
1538 return ExprError(
Diag(LAngleBracketLoc, diag::note_matching) << tok::less);
1542 if (
T.expectAndConsume(diag::err_expected_lparen_after, CastName))
1550 if (!
Result.isInvalid() && !DeclaratorInfo.isInvalidType())
1551 Result = Actions.ActOnCXXNamedCast(OpLoc, Kind,
1552 LAngleBracketLoc, DeclaratorInfo,
1554 T.getOpenLocation(),
Result.get(),
1555 T.getCloseLocation());
1561 assert(Tok.is(tok::kw_typeid) &&
"Not 'typeid'!");
1564 SourceLocation LParenLoc, RParenLoc;
1568 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"typeid"))
1570 LParenLoc =
T.getOpenLocation();
1591 if (isTypeIdInParens()) {
1596 RParenLoc =
T.getCloseLocation();
1600 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
true,
1610 RParenLoc =
T.getCloseLocation();
1614 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
false,
1615 Result.get(), RParenLoc);
1623 assert(Tok.is(tok::kw___uuidof) &&
"Not '__uuidof'!");
1629 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"__uuidof"))
1634 if (isTypeIdInParens()) {
1643 Result = Actions.ActOnCXXUuidof(OpLoc,
T.getOpenLocation(),
true,
1645 T.getCloseLocation());
1657 Result = Actions.ActOnCXXUuidof(OpLoc,
T.getOpenLocation(),
1659 Result.get(),
T.getCloseLocation());
1674 SourceLocation CCLoc;
1675 if (Tok.is(tok::identifier)) {
1676 FirstTypeName.
setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
1678 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1680 }
else if (Tok.is(tok::annot_template_id)) {
1681 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
1686 ConsumeAnnotationToken();
1687 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1690 assert(SS.
isEmpty() &&
"missing last component of nested name specifier");
1695 assert(Tok.is(tok::tilde) &&
"ParseOptionalCXXScopeSpecifier fail");
1698 if (Tok.is(tok::kw_decltype) && !FirstTypeName.
isValid()) {
1699 DeclSpec DS(AttrFactory);
1700 ParseDecltypeSpecifier(DS);
1703 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1707 if (!Tok.is(tok::identifier)) {
1708 Diag(Tok, diag::err_destructor_tilde_identifier);
1715 DeclSpec DS(AttrFactory);
1716 ParsePackIndexingType(DS);
1717 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1723 IdentifierInfo *Name = Tok.getIdentifierInfo();
1735 if (Tok.is(tok::less) &&
1736 ParseUnqualifiedIdTemplateId(
1737 SS, ObjectType, Base &&
Base->containsErrors(), SourceLocation(),
1738 Name, NameLoc,
false, SecondTypeName,
1742 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1743 SS, FirstTypeName, CCLoc, TildeLoc,
1749 return Actions.ActOnCXXBoolLiteral(
ConsumeToken(), Kind);
1753 assert(Tok.is(tok::kw_throw) &&
"Not throw!");
1759 switch (Tok.getKind()) {
1766 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc,
nullptr);
1770 if (Expr.isInvalid())
return Expr;
1771 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc, Expr.get());
1776 assert(Tok.is(tok::kw_co_yield) &&
"Not co_yield!");
1779 ExprResult Expr = Tok.is(tok::l_brace) ? ParseBraceInitializer()
1787 assert(Tok.is(tok::kw_this) &&
"Not 'this'!");
1789 return Actions.ActOnCXXThis(ThisLoc);
1793Parser::ParseCXXTypeConstructExpression(
const DeclSpec &DS) {
1796 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
1798 assert((Tok.is(tok::l_paren) ||
1800 &&
"Expected '(' or '{'!");
1802 if (Tok.is(tok::l_brace)) {
1803 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1805 if (
Init.isInvalid())
1808 return Actions.ActOnCXXTypeConstructExpr(
1815 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1819 auto RunSignatureHelp = [&]() {
1820 QualType PreferredType;
1823 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
1825 Exprs,
T.getOpenLocation(),
false);
1826 CalledSignatureHelp =
true;
1827 return PreferredType;
1830 if (Tok.isNot(tok::r_paren)) {
1831 if (ParseExpressionList(Exprs, [&] {
1832 PreferredType.enterFunctionArgument(Tok.getLocation(),
1835 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
1849 return Actions.ActOnCXXTypeConstructExpr(TypeRep,
T.getOpenLocation(),
1850 Exprs,
T.getCloseLocation(),
1858 assert(Tok.is(tok::kw_using) &&
"Expected using");
1861 "Unexpected Declarator Context");
1865 DG = ParseUsingDeclaration(Context, {}, DeclStart, DeclEnd, Attrs,
AS_none);
1870 ? diag::ext_alias_in_init_statement
1871 : diag::warn_cxx20_alias_in_init_statement)
1872 << SourceRange(DeclStart, DeclEnd);
1880 ForRangeInfo *FRI,
bool EnterForConditionScope) {
1882 struct ForConditionScopeRAII {
1884 void enter(
bool IsConditionVariable) {
1890 ~ForConditionScopeRAII() {
1897 PreferredType.enterCondition(Actions, Tok.getLocation());
1899 if (Tok.is(tok::code_completion)) {
1901 Actions.CodeCompletion().CodeCompleteOrdinaryName(
1906 ParsedAttributes attrs(AttrFactory);
1907 MaybeParseCXX11Attributes(attrs);
1909 const auto WarnOnInit = [
this, &CK] {
1911 ? diag::warn_cxx14_compat_init_statement
1912 : diag::ext_init_statement)
1917 switch (isCXXConditionDeclarationOrInitStatement(InitStmt, FRI)) {
1918 case ConditionOrInitStatement::Expression: {
1920 ForConditionScope.enter(
false);
1922 ProhibitAttributes(attrs);
1926 if (InitStmt && Tok.is(tok::semi)) {
1928 SourceLocation SemiLoc = Tok.getLocation();
1929 if (!Tok.hasLeadingEmptyMacro() && !SemiLoc.
isMacroID()) {
1930 Diag(SemiLoc, diag::warn_empty_init_statement)
1935 *InitStmt = Actions.ActOnNullStmt(SemiLoc);
1936 return ParseCXXCondition(
nullptr, Loc, CK, MissingOK);
1939 EnterExpressionEvaluationContext Eval(
1950 if (InitStmt && Tok.is(tok::semi)) {
1952 *InitStmt = Actions.ActOnExprStmt(Expr.
get());
1954 return ParseCXXCondition(
nullptr, Loc, CK, MissingOK);
1957 return Actions.ActOnCondition(
getCurScope(), Loc, Expr.
get(), CK,
1961 case ConditionOrInitStatement::InitStmtDecl: {
1964 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
1965 if (Tok.is(tok::kw_using))
1966 DG = ParseAliasDeclarationInInitStatement(
1969 ParsedAttributes DeclSpecAttrs(AttrFactory);
1971 attrs, DeclSpecAttrs,
true);
1973 *InitStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd);
1974 return ParseCXXCondition(
nullptr, Loc, CK, MissingOK);
1977 case ConditionOrInitStatement::ForRangeDecl: {
1981 assert(FRI &&
"should not parse a for range declaration here");
1982 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
1983 ParsedAttributes DeclSpecAttrs(AttrFactory);
1986 FRI->LoopVar = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
1987 return Sema::ConditionResult();
1990 case ConditionOrInitStatement::ConditionDecl:
1991 case ConditionOrInitStatement::Error:
1996 ForConditionScope.enter(
true);
1999 DeclSpec DS(AttrFactory);
2000 ParseSpecifierQualifierList(DS,
AS_none, DeclSpecContext::DSC_condition);
2004 ParseDeclarator(DeclaratorInfo);
2007 if (Tok.is(tok::kw_asm)) {
2009 ExprResult AsmLabel(ParseSimpleAsm(
true, &Loc));
2010 if (AsmLabel.isInvalid()) {
2014 DeclaratorInfo.setAsmLabel(AsmLabel.get());
2015 DeclaratorInfo.SetRangeEnd(Loc);
2019 MaybeParseGNUAttributes(DeclaratorInfo);
2030 bool CopyInitialization = isTokenEqualOrEqualTypo();
2031 if (CopyInitialization)
2036 Diag(Tok.getLocation(),
2037 diag::warn_cxx98_compat_generalized_initializer_lists);
2038 InitExpr = ParseBraceInitializer();
2039 }
else if (CopyInitialization) {
2040 PreferredType.enterVariableInit(Tok.getLocation(), DeclOut);
2042 }
else if (Tok.is(tok::l_paren)) {
2044 SourceLocation LParen = ConsumeParen(), RParen = LParen;
2046 RParen = ConsumeParen();
2048 diag::err_expected_init_in_condition_lparen)
2049 << SourceRange(LParen, RParen);
2055 Actions.AddInitializerToDecl(DeclOut, InitExpr.
get(), !CopyInitialization);
2057 Actions.ActOnInitializerError(DeclOut);
2059 Actions.FinalizeDeclaration(DeclOut);
2060 return Actions.ActOnConditionVariable(DeclOut, Loc, CK);
2063void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) {
2065 const char *PrevSpec;
2067 SourceLocation Loc = Tok.getLocation();
2068 const clang::PrintingPolicy &Policy =
2069 Actions.getASTContext().getPrintingPolicy();
2071 switch (Tok.getKind()) {
2072 case tok::identifier:
2073 case tok::coloncolon:
2074 llvm_unreachable(
"Annotation token should already be formed!");
2076 llvm_unreachable(
"Not a simple-type-specifier token!");
2079 case tok::annot_typename: {
2083 ConsumeAnnotationToken();
2084 DS.
Finish(Actions, Policy);
2088 case tok::kw__ExtInt:
2089 case tok::kw__BitInt: {
2090 DiagnoseBitIntUse(Tok);
2099 DS.
Finish(Actions, Policy);
2112 case tok::kw___int64:
2116 case tok::kw_signed:
2119 case tok::kw_unsigned:
2134 case tok::kw___int128:
2137 case tok::kw___bf16:
2146 case tok::kw_double:
2149 case tok::kw__Float16:
2152 case tok::kw___float128:
2155 case tok::kw___ibm128:
2158 case tok::kw_wchar_t:
2161 case tok::kw_char8_t:
2164 case tok::kw_char16_t:
2167 case tok::kw_char32_t:
2173 case tok::kw__Accum:
2176 case tok::kw__Fract:
2182#define GENERIC_IMAGE_TYPE(ImgType, Id) \
2183 case tok::kw_##ImgType##_t: \
2184 DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, DiagID, \
2187#include "clang/Basic/OpenCLImageTypes.def"
2188#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
2189 case tok::kw_##Name: \
2190 DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, DiagID, Policy); \
2192#include "clang/Basic/HLSLIntangibleTypes.def"
2194 case tok::annot_decltype:
2195 case tok::kw_decltype:
2197 return DS.
Finish(Actions, Policy);
2199 case tok::annot_pack_indexing_type:
2201 return DS.
Finish(Actions, Policy);
2204 case tok::kw_typeof:
2205 ParseTypeofSpecifier(DS);
2206 DS.
Finish(Actions, Policy);
2211 DS.
Finish(Actions, Policy);
2215 ParseSpecifierQualifierList(DS,
AS_none,
2216 getDeclSpecContextFromDeclaratorContext(Context));
2217 DS.
Finish(Actions, Actions.getASTContext().getPrintingPolicy());
2221bool Parser::ParseUnqualifiedIdTemplateId(
2222 CXXScopeSpec &SS,
ParsedType ObjectType,
bool ObjectHadErrors,
2223 SourceLocation TemplateKWLoc, IdentifierInfo *Name, SourceLocation NameLoc,
2224 bool EnteringContext, UnqualifiedId &Id,
bool AssumeTemplateId) {
2225 assert(Tok.is(tok::less) &&
"Expected '<' to finish parsing a template-id");
2233 if (AssumeTemplateId) {
2236 TNK = Actions.ActOnTemplateName(
getCurScope(), SS, TemplateKWLoc, Id,
2237 ObjectType, EnteringContext,
Template,
2240 bool MemberOfUnknownSpecialization;
2243 ObjectType, EnteringContext,
Template,
2244 MemberOfUnknownSpecialization);
2249 isTemplateArgumentList(0) == TPResult::False)
2253 ObjectType && isTemplateArgumentList(0) == TPResult::True) {
2256 if (!ObjectHadErrors) {
2275 TNK = Actions.ActOnTemplateName(
2276 getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext,
2286 bool MemberOfUnknownSpecialization;
2291 MemberOfUnknownSpecialization);
2299 bool MemberOfUnknownSpecialization;
2302 TNK = Actions.ActOnTemplateName(
2309 MemberOfUnknownSpecialization);
2312 Diag(NameLoc, diag::err_destructor_template_id)
2325 SourceLocation LAngleLoc, RAngleLoc;
2326 TemplateArgList TemplateArgs;
2327 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs, RAngleLoc,
2342 const IdentifierInfo *TemplateII =
2352 LAngleLoc, RAngleLoc, TemplateArgs,
false, TemplateIds);
2364 SourceLocation(), SS, TemplateKWLoc,
Template,
2365 Name, NameLoc, LAngleLoc, TemplateArgsPtr, RAngleLoc,
2367 if (
Type.isInvalid())
2378bool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
2381 assert(Tok.is(tok::kw_operator) &&
"Expected 'operator' keyword");
2387 unsigned SymbolIdx = 0;
2388 SourceLocation SymbolLocations[3];
2390 switch (Tok.getKind()) {
2392 case tok::kw_delete: {
2393 bool isNew = Tok.getKind() == tok::kw_new;
2397 if (Tok.is(tok::l_square) &&
2403 if (
T.getCloseLocation().isInvalid())
2406 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2407 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2408 Op = isNew? OO_Array_New : OO_Array_Delete;
2410 Op = isNew? OO_New : OO_Delete;
2415#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
2417 SymbolLocations[SymbolIdx++] = ConsumeToken(); \
2420#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
2421#include "clang/Basic/OperatorKinds.def"
2423 case tok::l_paren: {
2428 if (
T.getCloseLocation().isInvalid())
2431 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2432 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2437 case tok::l_square: {
2442 if (
T.getCloseLocation().isInvalid())
2445 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2446 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2451 case tok::code_completion: {
2455 Actions.CodeCompletion().CodeCompleteOperatorName(
getCurScope());
2465 Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations);
2476 Diag(Tok.getLocation(), diag::warn_cxx98_compat_literal_operator);
2478 SourceLocation DiagLoc;
2479 unsigned DiagId = 0;
2483 SmallVector<Token, 4> Toks;
2484 SmallVector<SourceLocation, 4> TokLocs;
2485 while (isTokenStringLiteral()) {
2486 if (!Tok.is(tok::string_literal) && !DiagId) {
2490 DiagLoc = Tok.getLocation();
2491 DiagId = diag::err_literal_operator_string_prefix;
2493 Toks.push_back(Tok);
2494 TokLocs.push_back(ConsumeStringToken());
2497 StringLiteralParser
Literal(Toks, PP);
2503 bool IsUDSuffix = !
Literal.getUDSuffix().empty();
2504 IdentifierInfo *II =
nullptr;
2505 SourceLocation SuffixLoc;
2507 II = &PP.getIdentifierTable().get(
Literal.getUDSuffix());
2512 }
else if (Tok.is(tok::identifier)) {
2513 II = Tok.getIdentifierInfo();
2515 TokLocs.push_back(SuffixLoc);
2517 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
2527 DiagLoc = TokLocs.front();
2528 DiagId = diag::err_literal_operator_string_not_empty;
2534 SmallString<32> Str;
2538 SourceRange(TokLocs.front(), TokLocs.back()), Str);
2541 Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
2543 return Actions.checkLiteralOperatorId(SS,
Result, IsUDSuffix);
2558 DeclSpec DS(AttrFactory);
2559 if (ParseCXXTypeSpecifierSeq(
2567 ParseDeclaratorInternal(D,
nullptr);
2575 Result.setConversionFunctionId(KeywordLoc, Ty.
get(),
2576 D.getSourceRange().getEnd());
2581 bool ObjectHadErrors,
bool EnteringContext,
2582 bool AllowDestructorName,
2583 bool AllowConstructorName,
2584 bool AllowDeductionGuide,
2592 bool TemplateSpecified =
false;
2593 if (Tok.is(tok::kw_template)) {
2594 if (TemplateKWLoc && (ObjectType || SS.
isSet())) {
2595 TemplateSpecified =
true;
2599 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2607 if (Tok.is(tok::identifier)) {
2616 Result.setIdentifier(Id, IdLoc);
2621 if (AllowConstructorName &&
2622 Actions.isCurrentClassName(*Id,
getCurScope(), &SS)) {
2628 Result.setConstructorName(Ty, IdLoc, IdLoc);
2631 Actions.isDeductionGuideName(
getCurScope(), *Id, IdLoc, SS,
2637 Result.setIdentifier(Id, IdLoc);
2642 if (Tok.is(tok::less))
2643 return ParseUnqualifiedIdTemplateId(
2644 SS, ObjectType, ObjectHadErrors,
2646 EnteringContext,
Result, TemplateSpecified);
2648 if (TemplateSpecified) {
2651 ObjectType, EnteringContext,
Template,
2662 Diag(IdLoc, diag::missing_template_arg_list_after_template_kw);
2669 if (Tok.is(tok::annot_template_id)) {
2675 ConsumeAnnotationToken();
2680 if (AllowConstructorName && TemplateId->
Name &&
2688 diag::err_out_of_line_constructor_template_id)
2699 ConsumeAnnotationToken();
2703 Result.setConstructorTemplateId(TemplateId);
2704 ConsumeAnnotationToken();
2710 Result.setTemplateId(TemplateId);
2713 if (TemplateKWLoc && (ObjectType || SS.
isSet()))
2714 *TemplateKWLoc = TemplateLoc;
2716 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2719 ConsumeAnnotationToken();
2726 if (Tok.is(tok::kw_operator)) {
2727 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
Result))
2739 return ParseUnqualifiedIdTemplateId(
2740 SS, ObjectType, ObjectHadErrors,
2743 else if (TemplateSpecified &&
2744 Actions.ActOnTemplateName(
2754 (AllowDestructorName || SS.
isSet()) && Tok.is(tok::tilde)) {
2763 if (TemplateSpecified) {
2774 Diag(*TemplateKWLoc, diag::err_unexpected_template_in_destructor_name)
2775 << Tok.getLocation();
2779 if (SS.
isEmpty() && Tok.is(tok::kw_decltype)) {
2783 Actions.getDestructorTypeForDecltype(DS, ObjectType)) {
2784 Result.setDestructorName(TildeLoc,
Type, EndLoc);
2791 if (Tok.isNot(tok::identifier)) {
2792 Diag(Tok, diag::err_destructor_tilde_identifier);
2797 DeclaratorScopeObj DeclScopeObj(*
this, SS);
2805 AnnotateScopeToken(SS,
true);
2808 if (ParseOptionalCXXScopeSpecifier(SS, ObjectType, ObjectHadErrors,
2812 ObjectType =
nullptr;
2813 if (Tok.isNot(tok::identifier) ||
NextToken().
is(tok::coloncolon) ||
2815 Diag(TildeLoc, diag::err_destructor_tilde_scope);
2820 Diag(TildeLoc, diag::err_destructor_tilde_scope)
2825 if (Actions.ShouldEnterDeclaratorScope(
getCurScope(), SS))
2826 DeclScopeObj.EnterDeclaratorScope();
2833 if (Tok.is(tok::less)) {
2834 Result.setDestructorName(TildeLoc,
nullptr, ClassNameLoc);
2835 return ParseUnqualifiedIdTemplateId(
2836 SS, ObjectType, ObjectHadErrors,
2838 ClassNameLoc, EnteringContext,
Result, TemplateSpecified);
2843 Actions.getDestructorName(*ClassName, ClassNameLoc,
getCurScope(), SS,
2844 ObjectType, EnteringContext);
2848 Result.setDestructorName(TildeLoc, Ty, ClassNameLoc);
2852 switch (Tok.getKind()) {
2853#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
2854#include "clang/Basic/TransformTypeTraits.def"
2856 Tok.setKind(tok::identifier);
2857 Diag(Tok, diag::ext_keyword_as_ident)
2858 << Tok.getIdentifierInfo()->getName() << 0;
2859 goto ParseIdentifier;
2863 Diag(Tok, diag::err_expected_unqualified_id) <<
getLangOpts().CPlusPlus;
2869Parser::ParseCXXNewExpression(
bool UseGlobal,
SourceLocation Start) {
2870 assert(
Tok.is(tok::kw_new) &&
"expected 'new' token");
2876 ExprVector PlacementArgs;
2883 if (
Tok.is(tok::l_paren)) {
2887 PlacementLParen =
T.getOpenLocation();
2888 if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) {
2894 PlacementRParen =
T.getCloseLocation();
2900 if (PlacementArgs.empty()) {
2902 TypeIdParens =
T.getRange();
2903 PlacementLParen = PlacementRParen = SourceLocation();
2906 if (Tok.is(tok::l_paren)) {
2909 MaybeParseGNUAttributes(DeclaratorInfo);
2910 ParseSpecifierQualifierList(DS);
2912 ParseDeclarator(DeclaratorInfo);
2914 TypeIdParens =
T.getRange();
2916 MaybeParseGNUAttributes(DeclaratorInfo);
2917 if (ParseCXXTypeSpecifierSeq(DS))
2918 DeclaratorInfo.setInvalidType(
true);
2921 ParseDeclaratorInternal(DeclaratorInfo,
2922 &Parser::ParseDirectNewDeclarator);
2929 MaybeParseGNUAttributes(DeclaratorInfo);
2931 DeclaratorInfo.setInvalidType(
true);
2934 ParseDeclaratorInternal(DeclaratorInfo,
2935 &Parser::ParseDirectNewDeclarator);
2938 if (DeclaratorInfo.isInvalidType()) {
2945 if (Tok.is(tok::l_paren)) {
2946 SourceLocation ConstructorLParen, ConstructorRParen;
2947 ExprVector ConstructorArgs;
2950 ConstructorLParen =
T.getOpenLocation();
2951 if (Tok.isNot(tok::r_paren)) {
2952 auto RunSignatureHelp = [&]() {
2953 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
2954 QualType PreferredType;
2960 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
2962 DeclaratorInfo.getEndLoc(), ConstructorArgs,
2965 CalledSignatureHelp =
true;
2966 return PreferredType;
2968 if (ParseExpressionList(ConstructorArgs, [&] {
2969 PreferredType.enterFunctionArgument(Tok.getLocation(),
2972 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
2979 ConstructorRParen =
T.getCloseLocation();
2984 Initializer = Actions.ActOnParenListExpr(ConstructorLParen,
2988 Diag(Tok.getLocation(),
2989 diag::warn_cxx98_compat_generalized_initializer_lists);
2995 return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen,
2996 PlacementArgs, PlacementRParen,
3000void Parser::ParseDirectNewDeclarator(Declarator &D) {
3003 while (Tok.is(tok::l_square)) {
3005 if (CheckProhibitedCXX11Attribute())
3014 if (
Size.isInvalid()) {
3016 SkipUntil(tok::r_square, StopAtSemi);
3024 ParsedAttributes Attrs(AttrFactory);
3025 MaybeParseCXX11Attributes(Attrs);
3029 Size.get(),
T.getOpenLocation(),
3030 T.getCloseLocation()),
3031 std::move(Attrs),
T.getCloseLocation());
3033 if (
T.getCloseLocation().isInvalid())
3038bool Parser::ParseExpressionListOrTypeId(
3039 SmallVectorImpl<Expr*> &PlacementArgs,
3042 if (isTypeIdInParens()) {
3050 return ParseExpressionList(PlacementArgs);
3054Parser::ParseCXXDeleteExpression(
bool UseGlobal, SourceLocation Start) {
3055 assert(Tok.is(tok::kw_delete) &&
"Expected 'delete' keyword");
3059 bool ArrayDelete =
false;
3060 if (Tok.is(tok::l_square) &&
NextToken().
is(tok::r_square)) {
3071 if (
Next.isOneOf(tok::l_brace, tok::less) ||
3072 (
Next.is(tok::l_paren) &&
3076 TentativeParsingAction TPA(*
this);
3077 SourceLocation LSquareLoc = Tok.getLocation();
3083 SourceLocation RBraceLoc;
3084 bool EmitFixIt =
false;
3085 if (Tok.is(tok::l_brace)) {
3088 RBraceLoc = Tok.getLocation();
3095 Diag(Start, diag::err_lambda_after_delete)
3096 << SourceRange(Start, RSquareLoc)
3100 RBraceLoc, 0, Actions.getSourceManager(),
getLangOpts()),
3103 Diag(Start, diag::err_lambda_after_delete)
3104 << SourceRange(Start, RSquareLoc);
3113 Lambda = ParsePostfixExpressionSuffix(Lambda);
3116 return Actions.ActOnCXXDelete(Start, UseGlobal,
false,
3125 if (
T.getCloseLocation().isInvalid())
3133 return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete,
Operand.get());
3136ExprResult Parser::ParseRequiresExpression() {
3137 assert(Tok.is(tok::kw_requires) &&
"Expected 'requires' keyword");
3140 llvm::SmallVector<ParmVarDecl *, 2> LocalParameterDecls;
3142 if (Tok.is(tok::l_paren)) {
3147 if (!Tok.is(tok::r_paren)) {
3149 SourceLocation EllipsisLoc;
3150 llvm::SmallVector<DeclaratorChunk::ParamInfo, 2> LocalParameters;
3152 FirstArgAttrs, LocalParameters,
3155 Diag(EllipsisLoc, diag::err_requires_expr_parameter_list_ellipsis);
3156 for (
auto &ParamInfo : LocalParameters)
3163 if (
Braces.expectAndConsume())
3167 llvm::SmallVector<concepts::Requirement *, 2> Requirements;
3171 EnterExpressionEvaluationContext Ctx(
3179 RequiresExprBodyDecl *Body = Actions.ActOnStartRequiresExpr(
3180 RequiresKWLoc, LocalParameterDecls,
getCurScope());
3182 if (Tok.is(tok::r_brace)) {
3189 Diag(Tok, diag::err_empty_requires_expr);
3192 while (!Tok.is(tok::r_brace)) {
3193 switch (Tok.getKind()) {
3194 case tok::l_brace: {
3205 ExprBraces.consumeOpen();
3207 if (Expression.isUsable())
3208 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3209 if (!Expression.isUsable()) {
3210 ExprBraces.skipToEnd();
3216 if (ExprBraces.consumeClose())
3219 concepts::Requirement *Req =
nullptr;
3220 SourceLocation NoexceptLoc;
3222 if (Tok.is(tok::semi)) {
3223 Req = Actions.ActOnCompoundRequirement(Expression.get(), NoexceptLoc);
3225 Requirements.push_back(Req);
3230 Diag(Tok, diag::err_requires_expr_missing_arrow)
3233 if (TryAnnotateTypeConstraint()) {
3237 if (!isTypeConstraintAnnotation()) {
3238 Diag(Tok, diag::err_requires_expr_expected_type_constraint);
3243 if (Tok.is(tok::annot_cxxscope)) {
3244 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
3245 Tok.getAnnotationRange(),
3247 ConsumeAnnotationToken();
3250 Req = Actions.ActOnCompoundRequirement(
3251 Expression.get(), NoexceptLoc, SS, takeTemplateIdAnnotation(Tok),
3252 TemplateParameterDepth);
3253 ConsumeAnnotationToken();
3255 Requirements.push_back(Req);
3259 bool PossibleRequiresExprInSimpleRequirement =
false;
3260 if (Tok.is(tok::kw_requires)) {
3261 auto IsNestedRequirement = [&] {
3262 RevertingTentativeParsingAction TPA(*
this);
3264 if (Tok.is(tok::l_brace))
3271 if (Tok.is(tok::l_paren)) {
3274 auto Res = TryParseParameterDeclarationClause();
3275 if (Res != TPResult::False) {
3278 while (Depth != 0) {
3279 bool FoundParen =
SkipUntil(tok::l_paren, tok::r_paren,
3283 if (Tok.is(tok::l_paren))
3285 else if (Tok.is(tok::r_paren))
3296 if (Tok.is(tok::l_brace))
3305 if (IsNestedRequirement()) {
3318 Actions.ActOnNestedRequirement(ConstraintExpr.
get()))
3319 Requirements.push_back(Req);
3327 PossibleRequiresExprInSimpleRequirement =
true;
3328 }
else if (Tok.is(tok::kw_typename)) {
3331 TentativeParsingAction TPA(*
this);
3341 if (Tok.is(tok::annot_cxxscope)) {
3342 Actions.RestoreNestedNameSpecifierAnnotation(
3343 Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS);
3344 ConsumeAnnotationToken();
3347 if (Tok.isOneOf(tok::identifier, tok::annot_template_id) &&
3350 SourceLocation NameLoc = Tok.getLocation();
3351 IdentifierInfo *II =
nullptr;
3352 TemplateIdAnnotation *TemplateId =
nullptr;
3353 if (Tok.is(tok::identifier)) {
3354 II = Tok.getIdentifierInfo();
3357 TemplateId = takeTemplateIdAnnotation(Tok);
3358 ConsumeAnnotationToken();
3363 if (
auto *Req = Actions.ActOnTypeRequirement(TypenameKWLoc, SS,
3366 Requirements.push_back(Req);
3376 SourceLocation StartLoc = Tok.getLocation();
3378 if (Expression.isUsable())
3379 Expression = Actions.CheckPlaceholderExpr(Expression.get());
3380 if (!Expression.isUsable()) {
3384 if (!Expression.isInvalid() && PossibleRequiresExprInSimpleRequirement)
3385 Diag(StartLoc, diag::err_requires_expr_in_simple_requirement)
3387 if (
auto *Req = Actions.ActOnSimpleRequirement(Expression.get()))
3388 Requirements.push_back(Req);
3394 if (Tok.is(tok::kw_noexcept)) {
3395 Diag(Tok, diag::err_requires_expr_simple_requirement_noexcept)
3404 if (ExpectAndConsumeSemi(diag::err_expected_semi_requirement)) {
3410 if (Requirements.empty()) {
3415 Actions.ActOnFinishRequiresExpr();
3420 Actions.ActOnFinishRequiresExpr();
3421 ParsingBodyDecl.complete(Body);
3422 return Actions.ActOnRequiresExpr(
3423 RequiresKWLoc, Body,
Parens.getOpenLocation(), LocalParameterDecls,
3424 Parens.getCloseLocation(), Requirements,
Braces.getCloseLocation());
3429 default: llvm_unreachable(
"Not a known type trait");
3430#define TYPE_TRAIT_1(Spelling, Name, Key) \
3431case tok::kw_ ## Spelling: return UTT_ ## Name;
3432#define TYPE_TRAIT_2(Spelling, Name, Key) \
3433case tok::kw_ ## Spelling: return BTT_ ## Name;
3434#include "clang/Basic/TokenKinds.def"
3435#define TYPE_TRAIT_N(Spelling, Name, Key) \
3436 case tok::kw_ ## Spelling: return TT_ ## Name;
3437#include "clang/Basic/TokenKinds.def"
3444 llvm_unreachable(
"Not a known array type trait");
3445#define ARRAY_TYPE_TRAIT(Spelling, Name, Key) \
3446 case tok::kw_##Spelling: \
3448#include "clang/Basic/TokenKinds.def"
3455 llvm_unreachable(
"Not a known unary expression trait.");
3456#define EXPRESSION_TRAIT(Spelling, Name, Key) \
3457 case tok::kw_##Spelling: \
3459#include "clang/Basic/TokenKinds.def"
3469 if (
Parens.expectAndConsume())
3472 SmallVector<ParsedType, 2> Args;
3485 if (Tok.is(tok::ellipsis)) {
3494 Args.push_back(Ty.
get());
3497 if (
Parens.consumeClose())
3500 SourceLocation EndLoc =
Parens.getCloseLocation();
3510 if (
T.expectAndConsume())
3522 case ATT_ArrayRank: {
3524 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(),
nullptr,
3525 T.getCloseLocation());
3527 case ATT_ArrayExtent: {
3528 if (ExpectAndConsume(tok::comma)) {
3539 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(), DimExpr.
get(),
3540 T.getCloseLocation());
3543 llvm_unreachable(
"Invalid ArrayTypeTrait!");
3551 if (
T.expectAndConsume())
3558 return Actions.ActOnExpressionTrait(ET, Loc, Expr.
get(),
3559 T.getCloseLocation());
3569 "Compound literals are not ambiguous!");
3570 assert(isTypeIdInParens() &&
"Not a type-id!");
3599 if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) {
3605 if (Tok.is(tok::l_brace)) {
3609 if (Tok.is(tok::l_paren) &&
NextToken().
is(tok::r_paren)) {
3617 false , NotCastExpr,
3630 AttrEnd.startToken();
3631 AttrEnd.setKind(tok::eof);
3632 AttrEnd.setLocation(Tok.getLocation());
3633 AttrEnd.setEofData(Toks.data());
3634 Toks.push_back(AttrEnd);
3637 Toks.push_back(Tok);
3640 PP.EnterTokenStream(Toks,
true,
3648 DeclSpec DS(AttrFactory);
3653 ParseSpecifierQualifierList(DS);
3654 ParseDeclarator(DeclaratorInfo);
3662 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3667 if (DeclaratorInfo.isInvalidType())
3670 TypeResult Ty = Actions.ActOnTypeName(DeclaratorInfo);
3671 return ParseCompoundLiteralExpression(Ty.
get(),
3679 if (DeclaratorInfo.isInvalidType())
3685 DeclaratorInfo, CastTy,
3695 if (!
Result.isInvalid() && Tok.is(tok::r_paren))
3697 Tok.getLocation(),
Result.get());
3700 if (
Result.isInvalid()) {
3701 while (Tok.isNot(tok::eof))
3703 assert(Tok.getEofData() == AttrEnd.getEofData());
3710 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3719 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"__builtin_bit_cast"))
3723 DeclSpec DS(AttrFactory);
3724 ParseSpecifierQualifierList(DS);
3729 ParseDeclarator(DeclaratorInfo);
3731 if (ExpectAndConsume(tok::comma)) {
3732 Diag(Tok.getLocation(), diag::err_expected) << tok::comma;
3739 if (
T.consumeClose())
3742 if (
Operand.isInvalid() || DeclaratorInfo.isInvalidType())
3745 return Actions.ActOnBuiltinBitCastExpr(KWLoc, DeclaratorInfo, Operand,
3746 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
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.