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 Invalid = [&](llvm::function_ref<void()> Action) {
777 *Tentative = LambdaIntroducerTentativeParse::Invalid;
786 auto NonTentativeAction = [&](llvm::function_ref<void()> Action) {
788 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
794 if (Tok.is(tok::amp) &&
799 if (!Tok.getIdentifierInfo()) {
804 }
else if (Tok.is(tok::equal)) {
811 while (Tok.isNot(tok::r_square)) {
813 if (Tok.isNot(tok::comma)) {
818 if (Tok.is(tok::code_completion) &&
821 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
828 Diag(Tok.getLocation(), diag::err_expected_comma_or_rsquare);
834 if (Tok.is(tok::code_completion)) {
839 Actions.CodeCompletion().CodeCompleteObjCMessageReceiver(
getCurScope());
841 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
853 IdentifierInfo *Id =
nullptr;
854 SourceLocation EllipsisLocs[4];
856 SourceLocation LocStart = Tok.getLocation();
858 if (Tok.is(tok::star)) {
860 if (Tok.is(tok::kw_this)) {
865 Diag(Tok.getLocation(), diag::err_expected_star_this_capture);
868 }
else if (Tok.is(tok::kw_this)) {
871 }
else if (Tok.isOneOf(tok::amp, tok::equal) &&
879 [&] {
Diag(Tok.getLocation(), diag::err_capture_default_first); });
883 if (Tok.is(tok::amp)) {
887 if (Tok.is(tok::code_completion)) {
889 Actions.CodeCompletion().CodeCompleteLambdaIntroducer(
898 if (Tok.is(tok::identifier)) {
899 Id = Tok.getIdentifierInfo();
901 }
else if (Tok.is(tok::kw_this)) {
904 Diag(Tok.getLocation(), diag::err_this_captured_by_reference);
908 Diag(Tok.getLocation(), diag::err_expected_capture);
914 if (Tok.is(tok::l_paren)) {
923 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
924 }
else if (ParseExpressionList(Exprs)) {
929 Init = Actions.ActOnParenListExpr(
Parens.getOpenLocation(),
930 Parens.getCloseLocation(),
933 }
else if (Tok.isOneOf(tok::l_brace, tok::equal)) {
937 EnterExpressionEvaluationContext EC(
946 Init = ParseInitializer();
947 }
else if (Tok.is(tok::l_brace)) {
951 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
973 SourceLocation StartLoc = Tok.getLocation();
975 Init = ParseInitializer();
977 if (Tok.getLocation() != StartLoc) {
979 PP.RevertCachedTokens(1);
982 Tok.setLocation(StartLoc);
983 Tok.setKind(tok::annot_primary_expr);
984 setExprAnnotation(Tok,
Init);
985 Tok.setAnnotationEndLoc(PP.getLastCachedTokenLocation());
986 PP.AnnotateCachedTokens(Tok);
989 ConsumeAnnotationToken();
998 if (Tentative && Tok.is(tok::identifier) &&
1001 *Tentative = LambdaIntroducerTentativeParse::MessageSend;
1006 SourceLocation EllipsisLoc;
1007 if (llvm::any_of(EllipsisLocs,
1008 [](SourceLocation Loc) {
return Loc.
isValid(); })) {
1012 SourceLocation *ExpectedEllipsisLoc =
1013 !InitCapture ? &EllipsisLocs[2] :
1016 EllipsisLoc = *ExpectedEllipsisLoc;
1018 unsigned DiagID = 0;
1020 DiagID = diag::err_lambda_capture_misplaced_ellipsis;
1021 for (SourceLocation Loc : EllipsisLocs) {
1026 unsigned NumEllipses = std::accumulate(
1027 std::begin(EllipsisLocs), std::end(EllipsisLocs), 0,
1028 [](
int N, SourceLocation Loc) {
return N + Loc.
isValid(); });
1029 if (NumEllipses > 1)
1030 DiagID = diag::err_lambda_capture_multiple_ellipses;
1033 NonTentativeAction([&] {
1035 SourceLocation DiagLoc;
1036 for (SourceLocation &Loc : EllipsisLocs) {
1037 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid()) {
1042 assert(DiagLoc.
isValid() &&
"no location for diagnostic");
1046 auto &&D =
Diag(DiagLoc, DiagID);
1047 if (DiagID == diag::err_lambda_capture_misplaced_ellipsis) {
1048 SourceLocation ExpectedLoc =
1054 for (SourceLocation &Loc : EllipsisLocs) {
1055 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid())
1067 if (
Init.isUsable()) {
1068 NonTentativeAction([&] {
1071 Expr *InitExpr =
Init.get();
1074 InitCaptureType = Actions.actOnLambdaInitCaptureInitialization(
1075 Loc, Kind ==
LCK_ByRef, EllipsisLoc, Id, InitKind, InitExpr);
1080 SourceLocation LocEnd = PrevTokLocation;
1083 InitCaptureType, SourceRange(LocStart, LocEnd));
1105 auto ConsumeLocation = [&P, &DeclEndLoc](
SourceLocation &SpecifierLoc,
1107 if (SpecifierLoc.isValid()) {
1109 diag::err_lambda_decl_specifier_repeated)
1114 DeclEndLoc = SpecifierLoc;
1119 case tok::kw_mutable:
1120 ConsumeLocation(MutableLoc, 0);
1122 case tok::kw_static:
1123 ConsumeLocation(StaticLoc, 1);
1125 case tok::kw_constexpr:
1126 ConsumeLocation(ConstexprLoc, 2);
1128 case tok::kw_consteval:
1129 ConsumeLocation(ConstevalLoc, 3);
1141 ? diag::err_static_lambda
1142 : diag::warn_cxx20_compat_static_lambda);
1143 const char *PrevSpec =
nullptr;
1144 unsigned DiagID = 0;
1148 assert(PrevSpec ==
nullptr && DiagID == 0 &&
1149 "Static cannot have been set previously!");
1158 ? diag::ext_constexpr_on_lambda_cxx17
1159 : diag::warn_cxx14_compat_constexpr_on_lambda);
1160 const char *PrevSpec =
nullptr;
1161 unsigned DiagID = 0;
1164 assert(PrevSpec ==
nullptr && DiagID == 0 &&
1165 "Constexpr cannot have been set previously!");
1173 P.
Diag(ConstevalLoc, diag::warn_cxx20_compat_consteval);
1174 const char *PrevSpec =
nullptr;
1175 unsigned DiagID = 0;
1179 P.
Diag(ConstevalLoc, DiagID) << PrevSpec;
1195 P.
Diag(StaticLoc, diag::err_static_mutable_lambda);
1197 P.
Diag(StaticLoc, diag::err_static_lambda_captures);
1201ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
1205 Diag(LambdaBeginLoc, diag::ext_hlsl_lambda) << 1;
1208 ? diag::warn_cxx98_compat_lambda
1212 PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), LambdaBeginLoc,
1213 "lambda expression parsing");
1216 DeclSpec DS(AttrFactory);
1218 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1224 Actions.PushLambdaScope();
1225 Actions.ActOnLambdaExpressionAfterIntroducer(Intro,
getCurScope());
1227 ParsedAttributes Attributes(AttrFactory);
1235 if (Tok.is(tok::kw___noinline__)) {
1236 IdentifierInfo *
AttrName = Tok.getIdentifierInfo();
1238 Attributes.addNew(AttrName, AttrNameLoc, AttributeScopeInfo(),
1240 0, tok::kw___noinline__);
1241 }
else if (Tok.is(tok::kw___attribute))
1242 ParseGNUAttributes(Attributes,
nullptr, &D);
1247 D.takeAttributes(Attributes);
1251 if (Tok.is(tok::less)) {
1253 ? diag::warn_cxx17_compat_lambda_template_parameter_list
1254 : diag::ext_lambda_template_parameter_list);
1256 SmallVector<NamedDecl*, 4> TemplateParams;
1257 SourceLocation LAngleLoc, RAngleLoc;
1258 if (ParseTemplateParameters(TemplateParamScope,
1259 CurTemplateDepthTracker.getDepth(),
1260 TemplateParams, LAngleLoc, RAngleLoc)) {
1261 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1265 if (TemplateParams.empty()) {
1267 diag::err_lambda_template_parameter_list_empty);
1278 ++CurTemplateDepthTracker;
1288 Actions.ActOnLambdaExplicitTemplateParameterList(
1289 Intro, LAngleLoc, TemplateParams, RAngleLoc, RequiresClause);
1297 if (isCXX11AttributeSpecifier() !=
1300 ? diag::warn_cxx20_compat_decl_attrs_on_lambda
1301 : diag::ext_decl_attrs_on_lambda)
1302 << Tok.getIdentifierInfo() << Tok.isRegularKeywordAttribute();
1303 MaybeParseCXX11Attributes(D);
1307 SourceLocation TrailingReturnTypeLoc;
1308 SourceLocation LParenLoc, RParenLoc;
1309 SourceLocation DeclEndLoc;
1310 bool HasParentheses =
false;
1311 bool HasSpecifiers =
false;
1312 SourceLocation MutableLoc;
1319 SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
1320 SourceLocation EllipsisLoc;
1322 if (Tok.is(tok::l_paren)) {
1325 LParenLoc =
T.getOpenLocation();
1327 if (Tok.isNot(tok::r_paren)) {
1328 Actions.RecordParsingTemplateParameterDepth(
1329 CurTemplateDepthTracker.getOriginalDepth());
1331 ParseParameterDeclarationClause(D, Attributes, ParamInfo, EllipsisLoc);
1337 if (Actions.getCurGenericLambda())
1338 CurTemplateDepthTracker.setAddedDepth(1);
1342 DeclEndLoc = RParenLoc =
T.getCloseLocation();
1343 HasParentheses =
true;
1347 Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
1348 tok::kw_constexpr, tok::kw_consteval, tok::kw_static,
1349 tok::kw___private, tok::kw___global, tok::kw___local,
1350 tok::kw___constant, tok::kw___generic, tok::kw_groupshared,
1351 tok::kw_requires, tok::kw_noexcept) ||
1352 Tok.isRegularKeywordAttribute() ||
1353 (Tok.is(tok::l_square) &&
NextToken().
is(tok::l_square));
1359 Diag(Tok, diag::ext_lambda_missing_parens)
1363 if (HasParentheses || HasSpecifiers) {
1367 MaybeParseAttributes(PAKM_GNU | PAKM_Declspec, Attributes);
1370 SourceLocation ConstexprLoc;
1371 SourceLocation ConstevalLoc;
1372 SourceLocation StaticLoc;
1375 ConstevalLoc, DeclEndLoc);
1384 Actions.ActOnLambdaClosureParameters(
getCurScope(), ParamInfo);
1386 if (!HasParentheses)
1387 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1389 if (HasSpecifiers || HasParentheses) {
1392 SourceRange ESpecRange;
1393 SmallVector<ParsedType, 2> DynamicExceptions;
1394 SmallVector<SourceRange, 2> DynamicExceptionRanges;
1398 ESpecType = tryParseExceptionSpecification(
1399 false, ESpecRange, DynamicExceptions,
1400 DynamicExceptionRanges, NoexceptExpr, ExceptionSpecTokens);
1403 DeclEndLoc = ESpecRange.
getEnd();
1406 if (MaybeParseCXX11Attributes(Attributes))
1407 DeclEndLoc = Attributes.Range.getEnd();
1410 if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
1411 tok::kw___constant, tok::kw___generic)) {
1412 ParseOpenCLQualifiers(DS.getAttributes());
1416 SourceLocation FunLocalRangeEnd = DeclEndLoc;
1419 if (Tok.is(tok::arrow)) {
1420 FunLocalRangeEnd = Tok.getLocation();
1422 TrailingReturnType =
1423 ParseTrailingReturnType(Range,
false);
1424 TrailingReturnTypeLoc =
Range.getBegin();
1425 if (
Range.getEnd().isValid())
1426 DeclEndLoc =
Range.getEnd();
1429 SourceLocation NoLoc;
1432 false, LParenLoc, ParamInfo.data(),
1433 ParamInfo.size(), EllipsisLoc, RParenLoc,
1435 NoLoc, MutableLoc, ESpecType,
1436 ESpecRange, DynamicExceptions.data(),
1437 DynamicExceptionRanges.data(), DynamicExceptions.size(),
1438 NoexceptExpr.
isUsable() ? NoexceptExpr.
get() :
nullptr,
1440 {}, LParenLoc, FunLocalRangeEnd, D,
1441 TrailingReturnType, TrailingReturnTypeLoc, &DS),
1442 std::move(Attributes), DeclEndLoc);
1447 Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
1449 if (HasParentheses && Tok.is(tok::kw_requires))
1450 ParseTrailingRequiresClause(D);
1456 for (
const ParsedAttr &A : Attributes)
1457 if (A.getKind() == ParsedAttr::AT_CUDADevice ||
1458 A.getKind() == ParsedAttr::AT_CUDAHost ||
1459 A.getKind() == ParsedAttr::AT_CUDAGlobal)
1460 Diag(A.getLoc(), diag::warn_cuda_attr_lambda_position)
1461 << A.getAttrName()->getName();
1472 Actions.ActOnStartOfLambdaDefinition(Intro, D, DS);
1475 if (!Tok.is(tok::l_brace)) {
1476 Diag(Tok, diag::err_expected_lambda_body);
1477 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1481 StmtResult Stmt(ParseCompoundStatementBody());
1483 TemplateParamScope.Exit();
1486 if (!Stmt.isInvalid() && !TrailingReturnType.
isInvalid() &&
1488 return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.get());
1490 Actions.ActOnLambdaError(LambdaBeginLoc,
getCurScope());
1496 const char *CastName =
nullptr;
1499 default: llvm_unreachable(
"Unknown C++ cast!");
1500 case tok::kw_addrspace_cast: CastName =
"addrspace_cast";
break;
1501 case tok::kw_const_cast: CastName =
"const_cast";
break;
1502 case tok::kw_dynamic_cast: CastName =
"dynamic_cast";
break;
1503 case tok::kw_reinterpret_cast: CastName =
"reinterpret_cast";
break;
1504 case tok::kw_static_cast: CastName =
"static_cast";
break;
1508 SourceLocation LAngleBracketLoc = Tok.getLocation();
1512 if (Tok.is(tok::l_square) && Tok.getLength() == 2) {
1514 if (
Next.is(tok::colon) && areTokensAdjacent(Tok,
Next))
1518 if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName))
1522 DeclSpec DS(AttrFactory);
1523 ParseSpecifierQualifierList(DS,
AS_none,
1524 DeclSpecContext::DSC_type_specifier);
1529 ParseDeclarator(DeclaratorInfo);
1531 SourceLocation RAngleBracketLoc = Tok.getLocation();
1533 if (ExpectAndConsume(tok::greater))
1534 return ExprError(
Diag(LAngleBracketLoc, diag::note_matching) << tok::less);
1538 if (
T.expectAndConsume(diag::err_expected_lparen_after, CastName))
1546 if (!
Result.isInvalid() && !DeclaratorInfo.isInvalidType())
1547 Result = Actions.ActOnCXXNamedCast(OpLoc, Kind,
1548 LAngleBracketLoc, DeclaratorInfo,
1550 T.getOpenLocation(),
Result.get(),
1551 T.getCloseLocation());
1557 assert(Tok.is(tok::kw_typeid) &&
"Not 'typeid'!");
1560 SourceLocation LParenLoc, RParenLoc;
1564 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"typeid"))
1566 LParenLoc =
T.getOpenLocation();
1587 if (isTypeIdInParens()) {
1592 RParenLoc =
T.getCloseLocation();
1596 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
true,
1606 RParenLoc =
T.getCloseLocation();
1610 Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc,
false,
1611 Result.get(), RParenLoc);
1619 assert(Tok.is(tok::kw___uuidof) &&
"Not '__uuidof'!");
1625 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"__uuidof"))
1630 if (isTypeIdInParens()) {
1639 Result = Actions.ActOnCXXUuidof(OpLoc,
T.getOpenLocation(),
true,
1641 T.getCloseLocation());
1653 Result = Actions.ActOnCXXUuidof(OpLoc,
T.getOpenLocation(),
1655 Result.get(),
T.getCloseLocation());
1670 SourceLocation CCLoc;
1671 if (Tok.is(tok::identifier)) {
1672 FirstTypeName.
setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
1674 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1676 }
else if (Tok.is(tok::annot_template_id)) {
1677 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
1682 ConsumeAnnotationToken();
1683 assert(Tok.is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1686 assert(SS.
isEmpty() &&
"missing last component of nested name specifier");
1691 assert(Tok.is(tok::tilde) &&
"ParseOptionalCXXScopeSpecifier fail");
1694 if (Tok.is(tok::kw_decltype) && !FirstTypeName.
isValid()) {
1695 DeclSpec DS(AttrFactory);
1696 ParseDecltypeSpecifier(DS);
1699 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1703 if (!Tok.is(tok::identifier)) {
1704 Diag(Tok, diag::err_destructor_tilde_identifier);
1711 DeclSpec DS(AttrFactory);
1712 ParsePackIndexingType(DS);
1713 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1719 IdentifierInfo *Name = Tok.getIdentifierInfo();
1731 if (Tok.is(tok::less) &&
1732 ParseUnqualifiedIdTemplateId(
1733 SS, ObjectType, Base &&
Base->containsErrors(), SourceLocation(),
1734 Name, NameLoc,
false, SecondTypeName,
1738 return Actions.ActOnPseudoDestructorExpr(
getCurScope(), Base, OpLoc, OpKind,
1739 SS, FirstTypeName, CCLoc, TildeLoc,
1745 return Actions.ActOnCXXBoolLiteral(
ConsumeToken(), Kind);
1749 assert(Tok.is(tok::kw_throw) &&
"Not throw!");
1755 switch (Tok.getKind()) {
1762 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc,
nullptr);
1766 if (Expr.isInvalid())
return Expr;
1767 return Actions.ActOnCXXThrow(
getCurScope(), ThrowLoc, Expr.get());
1772 assert(Tok.is(tok::kw_co_yield) &&
"Not co_yield!");
1775 ExprResult Expr = Tok.is(tok::l_brace) ? ParseBraceInitializer()
1783 assert(Tok.is(tok::kw_this) &&
"Not 'this'!");
1785 return Actions.ActOnCXXThis(ThisLoc);
1789Parser::ParseCXXTypeConstructExpression(
const DeclSpec &DS) {
1792 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
1794 assert((Tok.is(tok::l_paren) ||
1796 &&
"Expected '(' or '{'!");
1798 if (Tok.is(tok::l_brace)) {
1799 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1801 if (
Init.isInvalid())
1804 return Actions.ActOnCXXTypeConstructExpr(
1811 PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.
get());
1815 auto RunSignatureHelp = [&]() {
1816 QualType PreferredType;
1819 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
1821 Exprs,
T.getOpenLocation(),
false);
1822 CalledSignatureHelp =
true;
1823 return PreferredType;
1826 if (Tok.isNot(tok::r_paren)) {
1827 if (ParseExpressionList(Exprs, [&] {
1828 PreferredType.enterFunctionArgument(Tok.getLocation(),
1831 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
1845 return Actions.ActOnCXXTypeConstructExpr(TypeRep,
T.getOpenLocation(),
1846 Exprs,
T.getCloseLocation(),
1854 assert(Tok.is(tok::kw_using) &&
"Expected using");
1857 "Unexpected Declarator Context");
1861 DG = ParseUsingDeclaration(Context, {}, DeclStart, DeclEnd, Attrs,
AS_none);
1866 ? diag::ext_alias_in_init_statement
1867 : diag::warn_cxx20_alias_in_init_statement)
1868 << SourceRange(DeclStart, DeclEnd);
1876 ForRangeInfo *FRI,
bool EnterForConditionScope) {
1878 struct ForConditionScopeRAII {
1880 void enter(
bool IsConditionVariable) {
1886 ~ForConditionScopeRAII() {
1893 PreferredType.enterCondition(Actions, Tok.getLocation());
1895 if (Tok.is(tok::code_completion)) {
1897 Actions.CodeCompletion().CodeCompleteOrdinaryName(
1902 ParsedAttributes attrs(AttrFactory);
1903 MaybeParseCXX11Attributes(attrs);
1905 const auto WarnOnInit = [
this, &CK] {
1907 ? diag::warn_cxx14_compat_init_statement
1908 : diag::ext_init_statement)
1913 switch (isCXXConditionDeclarationOrInitStatement(InitStmt, FRI)) {
1914 case ConditionOrInitStatement::Expression: {
1916 ForConditionScope.enter(
false);
1918 ProhibitAttributes(attrs);
1922 if (InitStmt && Tok.is(tok::semi)) {
1924 SourceLocation SemiLoc = Tok.getLocation();
1925 if (!Tok.hasLeadingEmptyMacro() && !SemiLoc.
isMacroID()) {
1926 Diag(SemiLoc, diag::warn_empty_init_statement)
1931 *InitStmt = Actions.ActOnNullStmt(SemiLoc);
1932 return ParseCXXCondition(
nullptr, Loc, CK, MissingOK);
1935 EnterExpressionEvaluationContext Eval(
1946 if (InitStmt && Tok.is(tok::semi)) {
1948 *InitStmt = Actions.ActOnExprStmt(Expr.
get());
1950 return ParseCXXCondition(
nullptr, Loc, CK, MissingOK);
1953 return Actions.ActOnCondition(
getCurScope(), Loc, Expr.
get(), CK,
1957 case ConditionOrInitStatement::InitStmtDecl: {
1960 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
1961 if (Tok.is(tok::kw_using))
1962 DG = ParseAliasDeclarationInInitStatement(
1965 ParsedAttributes DeclSpecAttrs(AttrFactory);
1967 attrs, DeclSpecAttrs,
true);
1969 *InitStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd);
1970 return ParseCXXCondition(
nullptr, Loc, CK, MissingOK);
1973 case ConditionOrInitStatement::ForRangeDecl: {
1977 assert(FRI &&
"should not parse a for range declaration here");
1978 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
1979 ParsedAttributes DeclSpecAttrs(AttrFactory);
1982 FRI->LoopVar = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
1983 return Sema::ConditionResult();
1986 case ConditionOrInitStatement::ConditionDecl:
1987 case ConditionOrInitStatement::Error:
1992 ForConditionScope.enter(
true);
1995 DeclSpec DS(AttrFactory);
1996 ParseSpecifierQualifierList(DS,
AS_none, DeclSpecContext::DSC_condition);
2000 ParseDeclarator(DeclaratorInfo);
2003 if (Tok.is(tok::kw_asm)) {
2005 ExprResult AsmLabel(ParseSimpleAsm(
true, &Loc));
2006 if (AsmLabel.isInvalid()) {
2010 DeclaratorInfo.setAsmLabel(AsmLabel.get());
2011 DeclaratorInfo.SetRangeEnd(Loc);
2015 MaybeParseGNUAttributes(DeclaratorInfo);
2026 bool CopyInitialization = isTokenEqualOrEqualTypo();
2027 if (CopyInitialization)
2032 Diag(Tok.getLocation(),
2033 diag::warn_cxx98_compat_generalized_initializer_lists);
2034 InitExpr = ParseBraceInitializer();
2035 }
else if (CopyInitialization) {
2036 PreferredType.enterVariableInit(Tok.getLocation(), DeclOut);
2038 }
else if (Tok.is(tok::l_paren)) {
2040 SourceLocation LParen = ConsumeParen(), RParen = LParen;
2042 RParen = ConsumeParen();
2044 diag::err_expected_init_in_condition_lparen)
2045 << SourceRange(LParen, RParen);
2051 Actions.AddInitializerToDecl(DeclOut, InitExpr.
get(), !CopyInitialization);
2053 Actions.ActOnInitializerError(DeclOut);
2055 Actions.FinalizeDeclaration(DeclOut);
2056 return Actions.ActOnConditionVariable(DeclOut, Loc, CK);
2059void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) {
2061 const char *PrevSpec;
2063 SourceLocation Loc = Tok.getLocation();
2064 const clang::PrintingPolicy &Policy =
2065 Actions.getASTContext().getPrintingPolicy();
2067 switch (Tok.getKind()) {
2068 case tok::identifier:
2069 case tok::coloncolon:
2070 llvm_unreachable(
"Annotation token should already be formed!");
2072 llvm_unreachable(
"Not a simple-type-specifier token!");
2075 case tok::annot_typename: {
2079 ConsumeAnnotationToken();
2080 DS.
Finish(Actions, Policy);
2084 case tok::kw__ExtInt:
2085 case tok::kw__BitInt: {
2086 DiagnoseBitIntUse(Tok);
2095 DS.
Finish(Actions, Policy);
2108 case tok::kw___int64:
2112 case tok::kw_signed:
2115 case tok::kw_unsigned:
2130 case tok::kw___int128:
2133 case tok::kw___bf16:
2142 case tok::kw_double:
2145 case tok::kw__Float16:
2148 case tok::kw___float128:
2151 case tok::kw___ibm128:
2154 case tok::kw_wchar_t:
2157 case tok::kw_char8_t:
2160 case tok::kw_char16_t:
2163 case tok::kw_char32_t:
2169 case tok::kw__Accum:
2172 case tok::kw__Fract:
2178#define GENERIC_IMAGE_TYPE(ImgType, Id) \
2179 case tok::kw_##ImgType##_t: \
2180 DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, DiagID, \
2183#include "clang/Basic/OpenCLImageTypes.def"
2184#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
2185 case tok::kw_##Name: \
2186 DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, DiagID, Policy); \
2188#include "clang/Basic/HLSLIntangibleTypes.def"
2190 case tok::annot_decltype:
2191 case tok::kw_decltype:
2193 return DS.
Finish(Actions, Policy);
2195 case tok::annot_pack_indexing_type:
2197 return DS.
Finish(Actions, Policy);
2200 case tok::kw_typeof:
2201 ParseTypeofSpecifier(DS);
2202 DS.
Finish(Actions, Policy);
2207 DS.
Finish(Actions, Policy);
2211 ParseSpecifierQualifierList(DS,
AS_none,
2212 getDeclSpecContextFromDeclaratorContext(Context));
2213 DS.
Finish(Actions, Actions.getASTContext().getPrintingPolicy());
2217bool Parser::ParseUnqualifiedIdTemplateId(
2218 CXXScopeSpec &SS,
ParsedType ObjectType,
bool ObjectHadErrors,
2219 SourceLocation TemplateKWLoc, IdentifierInfo *Name, SourceLocation NameLoc,
2220 bool EnteringContext, UnqualifiedId &Id,
bool AssumeTemplateId) {
2221 assert(Tok.is(tok::less) &&
"Expected '<' to finish parsing a template-id");
2229 if (AssumeTemplateId) {
2232 TNK = Actions.ActOnTemplateName(
getCurScope(), SS, TemplateKWLoc, Id,
2233 ObjectType, EnteringContext,
Template,
2236 bool MemberOfUnknownSpecialization;
2239 ObjectType, EnteringContext,
Template,
2240 MemberOfUnknownSpecialization);
2245 isTemplateArgumentList(0) == TPResult::False)
2249 ObjectType && isTemplateArgumentList(0) == TPResult::True) {
2252 if (!ObjectHadErrors) {
2271 TNK = Actions.ActOnTemplateName(
2272 getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext,
2282 bool MemberOfUnknownSpecialization;
2287 MemberOfUnknownSpecialization);
2295 bool MemberOfUnknownSpecialization;
2298 TNK = Actions.ActOnTemplateName(
2305 MemberOfUnknownSpecialization);
2308 Diag(NameLoc, diag::err_destructor_template_id)
2321 SourceLocation LAngleLoc, RAngleLoc;
2322 TemplateArgList TemplateArgs;
2323 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs, RAngleLoc,
2338 const IdentifierInfo *TemplateII =
2348 LAngleLoc, RAngleLoc, TemplateArgs,
false, TemplateIds);
2360 SourceLocation(), SS, TemplateKWLoc,
Template,
2361 Name, NameLoc, LAngleLoc, TemplateArgsPtr, RAngleLoc,
2363 if (
Type.isInvalid())
2374bool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec &SS,
bool EnteringContext,
2377 assert(Tok.is(tok::kw_operator) &&
"Expected 'operator' keyword");
2383 unsigned SymbolIdx = 0;
2384 SourceLocation SymbolLocations[3];
2386 switch (Tok.getKind()) {
2388 case tok::kw_delete: {
2389 bool isNew = Tok.getKind() == tok::kw_new;
2393 if (Tok.is(tok::l_square) &&
2399 if (
T.getCloseLocation().isInvalid())
2402 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2403 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2404 Op = isNew? OO_Array_New : OO_Array_Delete;
2406 Op = isNew? OO_New : OO_Delete;
2411#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
2413 SymbolLocations[SymbolIdx++] = ConsumeToken(); \
2416#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
2417#include "clang/Basic/OperatorKinds.def"
2419 case tok::l_paren: {
2424 if (
T.getCloseLocation().isInvalid())
2427 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2428 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2433 case tok::l_square: {
2438 if (
T.getCloseLocation().isInvalid())
2441 SymbolLocations[SymbolIdx++] =
T.getOpenLocation();
2442 SymbolLocations[SymbolIdx++] =
T.getCloseLocation();
2447 case tok::code_completion: {
2451 Actions.CodeCompletion().CodeCompleteOperatorName(
getCurScope());
2461 Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations);
2472 Diag(Tok.getLocation(), diag::warn_cxx98_compat_literal_operator);
2474 SourceLocation DiagLoc;
2475 unsigned DiagId = 0;
2479 SmallVector<Token, 4> Toks;
2480 SmallVector<SourceLocation, 4> TokLocs;
2481 while (isTokenStringLiteral()) {
2482 if (!Tok.is(tok::string_literal) && !DiagId) {
2486 DiagLoc = Tok.getLocation();
2487 DiagId = diag::err_literal_operator_string_prefix;
2489 Toks.push_back(Tok);
2490 TokLocs.push_back(ConsumeStringToken());
2493 StringLiteralParser
Literal(Toks, PP);
2499 bool IsUDSuffix = !
Literal.getUDSuffix().empty();
2500 IdentifierInfo *II =
nullptr;
2501 SourceLocation SuffixLoc;
2503 II = &PP.getIdentifierTable().get(
Literal.getUDSuffix());
2508 }
else if (Tok.is(tok::identifier)) {
2509 II = Tok.getIdentifierInfo();
2511 TokLocs.push_back(SuffixLoc);
2513 Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
2523 DiagLoc = TokLocs.front();
2524 DiagId = diag::err_literal_operator_string_not_empty;
2530 SmallString<32> Str;
2534 SourceRange(TokLocs.front(), TokLocs.back()), Str);
2537 Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
2539 return Actions.checkLiteralOperatorId(SS,
Result, IsUDSuffix);
2554 DeclSpec DS(AttrFactory);
2555 if (ParseCXXTypeSpecifierSeq(
2563 ParseDeclaratorInternal(D,
nullptr);
2571 Result.setConversionFunctionId(KeywordLoc, Ty.
get(),
2572 D.getSourceRange().getEnd());
2577 bool ObjectHadErrors,
bool EnteringContext,
2578 bool AllowDestructorName,
2579 bool AllowConstructorName,
2580 bool AllowDeductionGuide,
2588 bool TemplateSpecified =
false;
2589 if (Tok.is(tok::kw_template)) {
2590 if (TemplateKWLoc && (ObjectType || SS.
isSet())) {
2591 TemplateSpecified =
true;
2595 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2603 if (Tok.is(tok::identifier)) {
2612 Result.setIdentifier(Id, IdLoc);
2617 if (AllowConstructorName &&
2618 Actions.isCurrentClassName(*Id,
getCurScope(), &SS)) {
2624 Result.setConstructorName(Ty, IdLoc, IdLoc);
2627 Actions.isDeductionGuideName(
getCurScope(), *Id, IdLoc, SS,
2633 Result.setIdentifier(Id, IdLoc);
2638 if (Tok.is(tok::less))
2639 return ParseUnqualifiedIdTemplateId(
2640 SS, ObjectType, ObjectHadErrors,
2642 EnteringContext,
Result, TemplateSpecified);
2644 if (TemplateSpecified) {
2647 ObjectType, EnteringContext,
Template,
2658 Diag(IdLoc, diag::missing_template_arg_list_after_template_kw);
2665 if (Tok.is(tok::annot_template_id)) {
2671 ConsumeAnnotationToken();
2676 if (AllowConstructorName && TemplateId->
Name &&
2684 diag::err_out_of_line_constructor_template_id)
2695 ConsumeAnnotationToken();
2699 Result.setConstructorTemplateId(TemplateId);
2700 ConsumeAnnotationToken();
2706 Result.setTemplateId(TemplateId);
2709 if (TemplateKWLoc && (ObjectType || SS.
isSet()))
2710 *TemplateKWLoc = TemplateLoc;
2712 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2715 ConsumeAnnotationToken();
2722 if (Tok.is(tok::kw_operator)) {
2723 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
Result))
2735 return ParseUnqualifiedIdTemplateId(
2736 SS, ObjectType, ObjectHadErrors,
2739 else if (TemplateSpecified &&
2740 Actions.ActOnTemplateName(
2750 (AllowDestructorName || SS.
isSet()) && Tok.is(tok::tilde)) {
2759 if (TemplateSpecified) {
2770 Diag(*TemplateKWLoc, diag::err_unexpected_template_in_destructor_name)
2771 << Tok.getLocation();
2775 if (SS.
isEmpty() && Tok.is(tok::kw_decltype)) {
2779 Actions.getDestructorTypeForDecltype(DS, ObjectType)) {
2780 Result.setDestructorName(TildeLoc,
Type, EndLoc);
2787 if (Tok.isNot(tok::identifier)) {
2788 Diag(Tok, diag::err_destructor_tilde_identifier);
2793 DeclaratorScopeObj DeclScopeObj(*
this, SS);
2801 AnnotateScopeToken(SS,
true);
2804 if (ParseOptionalCXXScopeSpecifier(SS, ObjectType, ObjectHadErrors,
2808 ObjectType =
nullptr;
2809 if (Tok.isNot(tok::identifier) ||
NextToken().
is(tok::coloncolon) ||
2811 Diag(TildeLoc, diag::err_destructor_tilde_scope);
2816 Diag(TildeLoc, diag::err_destructor_tilde_scope)
2821 if (Actions.ShouldEnterDeclaratorScope(
getCurScope(), SS))
2822 DeclScopeObj.EnterDeclaratorScope();
2829 if (Tok.is(tok::less)) {
2830 Result.setDestructorName(TildeLoc,
nullptr, ClassNameLoc);
2831 return ParseUnqualifiedIdTemplateId(
2832 SS, ObjectType, ObjectHadErrors,
2834 ClassNameLoc, EnteringContext,
Result, TemplateSpecified);
2839 Actions.getDestructorName(*ClassName, ClassNameLoc,
getCurScope(), SS,
2840 ObjectType, EnteringContext);
2844 Result.setDestructorName(TildeLoc, Ty, ClassNameLoc);
2848 switch (Tok.getKind()) {
2849#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
2850#include "clang/Basic/TransformTypeTraits.def"
2852 Tok.setKind(tok::identifier);
2853 Diag(Tok, diag::ext_keyword_as_ident)
2854 << Tok.getIdentifierInfo()->getName() << 0;
2855 goto ParseIdentifier;
2859 Diag(Tok, diag::err_expected_unqualified_id) <<
getLangOpts().CPlusPlus;
2865Parser::ParseCXXNewExpression(
bool UseGlobal,
SourceLocation Start) {
2866 assert(
Tok.is(tok::kw_new) &&
"expected 'new' token");
2872 ExprVector PlacementArgs;
2879 if (
Tok.is(tok::l_paren)) {
2883 PlacementLParen =
T.getOpenLocation();
2884 if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) {
2890 PlacementRParen =
T.getCloseLocation();
2896 if (PlacementArgs.empty()) {
2898 TypeIdParens =
T.getRange();
2899 PlacementLParen = PlacementRParen = SourceLocation();
2902 if (Tok.is(tok::l_paren)) {
2905 MaybeParseGNUAttributes(DeclaratorInfo);
2906 ParseSpecifierQualifierList(DS);
2908 ParseDeclarator(DeclaratorInfo);
2910 TypeIdParens =
T.getRange();
2912 MaybeParseGNUAttributes(DeclaratorInfo);
2913 if (ParseCXXTypeSpecifierSeq(DS))
2914 DeclaratorInfo.setInvalidType(
true);
2917 ParseDeclaratorInternal(DeclaratorInfo,
2918 &Parser::ParseDirectNewDeclarator);
2925 MaybeParseGNUAttributes(DeclaratorInfo);
2927 DeclaratorInfo.setInvalidType(
true);
2930 ParseDeclaratorInternal(DeclaratorInfo,
2931 &Parser::ParseDirectNewDeclarator);
2934 if (DeclaratorInfo.isInvalidType()) {
2941 if (Tok.is(tok::l_paren)) {
2942 SourceLocation ConstructorLParen, ConstructorRParen;
2943 ExprVector ConstructorArgs;
2946 ConstructorLParen =
T.getOpenLocation();
2947 if (Tok.isNot(tok::r_paren)) {
2948 auto RunSignatureHelp = [&]() {
2949 ParsedType TypeRep = Actions.ActOnTypeName(DeclaratorInfo).
get();
2950 QualType PreferredType;
2956 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
2958 DeclaratorInfo.getEndLoc(), ConstructorArgs,
2961 CalledSignatureHelp =
true;
2962 return PreferredType;
2964 if (ParseExpressionList(ConstructorArgs, [&] {
2965 PreferredType.enterFunctionArgument(Tok.getLocation(),
2968 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
2975 ConstructorRParen =
T.getCloseLocation();
2980 Initializer = Actions.ActOnParenListExpr(ConstructorLParen,
2984 Diag(Tok.getLocation(),
2985 diag::warn_cxx98_compat_generalized_initializer_lists);
2991 return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen,
2992 PlacementArgs, PlacementRParen,
2996void Parser::ParseDirectNewDeclarator(Declarator &D) {
2999 while (Tok.is(tok::l_square)) {
3001 if (CheckProhibitedCXX11Attribute())
3010 if (
Size.isInvalid()) {
3012 SkipUntil(tok::r_square, StopAtSemi);
3020 ParsedAttributes Attrs(AttrFactory);
3021 MaybeParseCXX11Attributes(Attrs);
3025 Size.get(),
T.getOpenLocation(),
3026 T.getCloseLocation()),
3027 std::move(Attrs),
T.getCloseLocation());
3029 if (
T.getCloseLocation().isInvalid())
3034bool Parser::ParseExpressionListOrTypeId(
3035 SmallVectorImpl<Expr*> &PlacementArgs,
3038 if (isTypeIdInParens()) {
3046 return ParseExpressionList(PlacementArgs);
3050Parser::ParseCXXDeleteExpression(
bool UseGlobal, SourceLocation Start) {
3051 assert(Tok.is(tok::kw_delete) &&
"Expected 'delete' keyword");
3055 bool ArrayDelete =
false;
3056 if (Tok.is(tok::l_square) &&
NextToken().
is(tok::r_square)) {
3067 if (
Next.isOneOf(tok::l_brace, tok::less) ||
3068 (
Next.is(tok::l_paren) &&
3072 TentativeParsingAction TPA(*
this);
3073 SourceLocation LSquareLoc = Tok.getLocation();
3079 SourceLocation RBraceLoc;
3080 bool EmitFixIt =
false;
3081 if (Tok.is(tok::l_brace)) {
3084 RBraceLoc = Tok.getLocation();
3091 Diag(Start, diag::err_lambda_after_delete)
3092 << SourceRange(Start, RSquareLoc)
3096 RBraceLoc, 0, Actions.getSourceManager(),
getLangOpts()),
3099 Diag(Start, diag::err_lambda_after_delete)
3100 << SourceRange(Start, RSquareLoc);
3109 Lambda = ParsePostfixExpressionSuffix(Lambda);
3112 return Actions.ActOnCXXDelete(Start, UseGlobal,
false,
3121 if (
T.getCloseLocation().isInvalid())
3129 return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete,
Operand.get());
3132ExprResult Parser::ParseRequiresExpression() {
3133 assert(Tok.is(tok::kw_requires) &&
"Expected 'requires' keyword");
3136 llvm::SmallVector<ParmVarDecl *, 2> LocalParameterDecls;
3138 if (Tok.is(tok::l_paren)) {
3143 if (!Tok.is(tok::r_paren)) {
3145 SourceLocation EllipsisLoc;
3146 llvm::SmallVector<DeclaratorChunk::ParamInfo, 2> LocalParameters;
3148 FirstArgAttrs, LocalParameters,
3151 Diag(EllipsisLoc, diag::err_requires_expr_parameter_list_ellipsis);
3152 for (
auto &ParamInfo : LocalParameters)
3159 if (
Braces.expectAndConsume())
3163 llvm::SmallVector<concepts::Requirement *, 2> Requirements;
3167 EnterExpressionEvaluationContext Ctx(
3175 RequiresExprBodyDecl *Body = Actions.ActOnStartRequiresExpr(
3176 RequiresKWLoc, LocalParameterDecls,
getCurScope());
3178 if (Tok.is(tok::r_brace)) {
3185 Diag(Tok, diag::err_empty_requires_expr);
3188 while (!Tok.is(tok::r_brace)) {
3189 switch (Tok.getKind()) {
3190 case tok::l_brace: {
3201 ExprBraces.consumeOpen();
3203 if (!Expression.isUsable()) {
3204 ExprBraces.skipToEnd();
3210 if (ExprBraces.consumeClose())
3213 concepts::Requirement *Req =
nullptr;
3214 SourceLocation NoexceptLoc;
3216 if (Tok.is(tok::semi)) {
3217 Req = Actions.ActOnCompoundRequirement(Expression.get(), NoexceptLoc);
3219 Requirements.push_back(Req);
3224 Diag(Tok, diag::err_requires_expr_missing_arrow)
3227 if (TryAnnotateTypeConstraint()) {
3231 if (!isTypeConstraintAnnotation()) {
3232 Diag(Tok, diag::err_requires_expr_expected_type_constraint);
3237 if (Tok.is(tok::annot_cxxscope)) {
3238 Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
3239 Tok.getAnnotationRange(),
3241 ConsumeAnnotationToken();
3244 Req = Actions.ActOnCompoundRequirement(
3245 Expression.get(), NoexceptLoc, SS, takeTemplateIdAnnotation(Tok),
3246 TemplateParameterDepth);
3247 ConsumeAnnotationToken();
3249 Requirements.push_back(Req);
3253 bool PossibleRequiresExprInSimpleRequirement =
false;
3254 if (Tok.is(tok::kw_requires)) {
3255 auto IsNestedRequirement = [&] {
3256 RevertingTentativeParsingAction TPA(*
this);
3258 if (Tok.is(tok::l_brace))
3265 if (Tok.is(tok::l_paren)) {
3268 auto Res = TryParseParameterDeclarationClause();
3269 if (Res != TPResult::False) {
3272 while (Depth != 0) {
3273 bool FoundParen =
SkipUntil(tok::l_paren, tok::r_paren,
3277 if (Tok.is(tok::l_paren))
3279 else if (Tok.is(tok::r_paren))
3290 if (Tok.is(tok::l_brace))
3299 if (IsNestedRequirement()) {
3312 Actions.ActOnNestedRequirement(ConstraintExpr.
get()))
3313 Requirements.push_back(Req);
3321 PossibleRequiresExprInSimpleRequirement =
true;
3322 }
else if (Tok.is(tok::kw_typename)) {
3325 TentativeParsingAction TPA(*
this);
3335 if (Tok.is(tok::annot_cxxscope)) {
3336 Actions.RestoreNestedNameSpecifierAnnotation(
3337 Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS);
3338 ConsumeAnnotationToken();
3341 if (Tok.isOneOf(tok::identifier, tok::annot_template_id) &&
3344 SourceLocation NameLoc = Tok.getLocation();
3345 IdentifierInfo *II =
nullptr;
3346 TemplateIdAnnotation *TemplateId =
nullptr;
3347 if (Tok.is(tok::identifier)) {
3348 II = Tok.getIdentifierInfo();
3351 TemplateId = takeTemplateIdAnnotation(Tok);
3352 ConsumeAnnotationToken();
3357 if (
auto *Req = Actions.ActOnTypeRequirement(TypenameKWLoc, SS,
3360 Requirements.push_back(Req);
3370 SourceLocation StartLoc = Tok.getLocation();
3372 if (!Expression.isUsable()) {
3376 if (!Expression.isInvalid() && PossibleRequiresExprInSimpleRequirement)
3377 Diag(StartLoc, diag::err_requires_expr_in_simple_requirement)
3379 if (
auto *Req = Actions.ActOnSimpleRequirement(Expression.get()))
3380 Requirements.push_back(Req);
3386 if (Tok.is(tok::kw_noexcept)) {
3387 Diag(Tok, diag::err_requires_expr_simple_requirement_noexcept)
3396 if (ExpectAndConsumeSemi(diag::err_expected_semi_requirement)) {
3402 if (Requirements.empty()) {
3407 Actions.ActOnFinishRequiresExpr();
3412 Actions.ActOnFinishRequiresExpr();
3413 ParsingBodyDecl.complete(Body);
3414 return Actions.ActOnRequiresExpr(
3415 RequiresKWLoc, Body,
Parens.getOpenLocation(), LocalParameterDecls,
3416 Parens.getCloseLocation(), Requirements,
Braces.getCloseLocation());
3421 default: llvm_unreachable(
"Not a known type trait");
3422#define TYPE_TRAIT_1(Spelling, Name, Key) \
3423case tok::kw_ ## Spelling: return UTT_ ## Name;
3424#define TYPE_TRAIT_2(Spelling, Name, Key) \
3425case tok::kw_ ## Spelling: return BTT_ ## Name;
3426#include "clang/Basic/TokenKinds.def"
3427#define TYPE_TRAIT_N(Spelling, Name, Key) \
3428 case tok::kw_ ## Spelling: return TT_ ## Name;
3429#include "clang/Basic/TokenKinds.def"
3436 llvm_unreachable(
"Not a known array type trait");
3437#define ARRAY_TYPE_TRAIT(Spelling, Name, Key) \
3438 case tok::kw_##Spelling: \
3440#include "clang/Basic/TokenKinds.def"
3447 llvm_unreachable(
"Not a known unary expression trait.");
3448#define EXPRESSION_TRAIT(Spelling, Name, Key) \
3449 case tok::kw_##Spelling: \
3451#include "clang/Basic/TokenKinds.def"
3461 if (
Parens.expectAndConsume())
3464 SmallVector<ParsedType, 2> Args;
3477 if (Tok.is(tok::ellipsis)) {
3486 Args.push_back(Ty.
get());
3489 if (
Parens.consumeClose())
3492 SourceLocation EndLoc =
Parens.getCloseLocation();
3502 if (
T.expectAndConsume())
3514 case ATT_ArrayRank: {
3516 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(),
nullptr,
3517 T.getCloseLocation());
3519 case ATT_ArrayExtent: {
3520 if (ExpectAndConsume(tok::comma)) {
3531 return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.
get(), DimExpr.
get(),
3532 T.getCloseLocation());
3535 llvm_unreachable(
"Invalid ArrayTypeTrait!");
3543 if (
T.expectAndConsume())
3550 return Actions.ActOnExpressionTrait(ET, Loc, Expr.
get(),
3551 T.getCloseLocation());
3561 "Compound literals are not ambiguous!");
3562 assert(isTypeIdInParens() &&
"Not a type-id!");
3591 if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) {
3597 if (Tok.is(tok::l_brace)) {
3601 if (Tok.is(tok::l_paren) &&
NextToken().
is(tok::r_paren)) {
3609 false , NotCastExpr,
3622 AttrEnd.startToken();
3623 AttrEnd.setKind(tok::eof);
3624 AttrEnd.setLocation(Tok.getLocation());
3625 AttrEnd.setEofData(Toks.data());
3626 Toks.push_back(AttrEnd);
3629 Toks.push_back(Tok);
3632 PP.EnterTokenStream(Toks,
true,
3640 DeclSpec DS(AttrFactory);
3645 ParseSpecifierQualifierList(DS);
3646 ParseDeclarator(DeclaratorInfo);
3654 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3659 if (DeclaratorInfo.isInvalidType())
3662 TypeResult Ty = Actions.ActOnTypeName(DeclaratorInfo);
3663 return ParseCompoundLiteralExpression(Ty.
get(),
3671 if (DeclaratorInfo.isInvalidType())
3677 DeclaratorInfo, CastTy,
3687 if (!
Result.isInvalid() && Tok.is(tok::r_paren))
3689 Tok.getLocation(),
Result.get());
3692 if (
Result.isInvalid()) {
3693 while (Tok.isNot(tok::eof))
3695 assert(Tok.getEofData() == AttrEnd.getEofData());
3702 assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3711 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"__builtin_bit_cast"))
3715 DeclSpec DS(AttrFactory);
3716 ParseSpecifierQualifierList(DS);
3721 ParseDeclarator(DeclaratorInfo);
3723 if (ExpectAndConsume(tok::comma)) {
3724 Diag(Tok.getLocation(), diag::err_expected) << tok::comma;
3731 if (
T.consumeClose())
3734 if (
Operand.isInvalid() || DeclaratorInfo.isInvalidType())
3737 return Actions.ActOnBuiltinBitCastExpr(KWLoc, DeclaratorInfo, Operand,
3738 T.getCloseLocation());
Defines the clang::ASTContext interface.
This file defines the classes used to store parsed information about declaration-specifiers and decla...
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
static void addConstexprToLambdaDeclSpecifier(Parser &P, SourceLocation ConstexprLoc, DeclSpec &DS)
static void FixDigraph(Parser &P, Preprocessor &PP, Token &DigraphToken, Token &ColonToken, tok::TokenKind Kind, bool AtDigraph)
static ArrayTypeTrait ArrayTypeTraitFromTokKind(tok::TokenKind kind)
static void tryConsumeLambdaSpecifierToken(Parser &P, SourceLocation &MutableLoc, SourceLocation &StaticLoc, SourceLocation &ConstexprLoc, SourceLocation &ConstevalLoc, SourceLocation &DeclEndLoc)
static ExpressionTrait ExpressionTraitFromTokKind(tok::TokenKind kind)
static void addConstevalToLambdaDeclSpecifier(Parser &P, SourceLocation ConstevalLoc, DeclSpec &DS)
static TypeTrait TypeTraitFromTokKind(tok::TokenKind kind)
static void DiagnoseStaticSpecifierRestrictions(Parser &P, SourceLocation StaticLoc, SourceLocation MutableLoc, const LambdaIntroducer &Intro)
static int SelectDigraphErrorMessage(tok::TokenKind Kind)
static void addStaticToLambdaDeclSpecifier(Parser &P, SourceLocation StaticLoc, DeclSpec &DS)
Defines the PrettyStackTraceEntry class, which is used to make crashes give more contextual informati...
static constexpr bool isOneOf()
This file declares facilities that support code completion.
Defines the clang::TemplateNameKind enum.
Defines the clang::TokenKind enum and support functions.
const clang::PrintingPolicy & getPrintingPolicy() const
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ....
SourceLocation getOpenLocation() const
SourceLocation getCloseLocation() const
Represents a C++ nested-name-specifier or a global scope specifier.
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
SourceRange getRange() const
SourceLocation getBeginLoc() const
bool isSet() const
Deprecated.
void setEndLoc(SourceLocation Loc)
void SetInvalid(SourceRange R)
Indicate that this nested-name-specifier is invalid.
bool isEmpty() const
No scope specifier.
void restore()
restore - This can be used to restore the state early, before the dtor is run.
Captures information about "declaration specifiers".
static const TST TST_typename
SourceLocation getEndLoc() const LLVM_READONLY
bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec and return false if there was no error.
static const TST TST_char8
static const TST TST_BFloat16
bool SetConstexprSpec(ConstexprSpecKind ConstexprKind, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
bool SetTypeSpecWidth(TypeSpecifierWidth W, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec, but return true and ignore the request if ...
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
SourceRange getSourceRange() const LLVM_READONLY
void SetRangeEnd(SourceLocation Loc)
bool SetBitIntType(SourceLocation KWLoc, Expr *BitWidth, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
static const TST TST_double
void SetRangeStart(SourceLocation Loc)
static const TST TST_char
static const TST TST_bool
static const TST TST_char16
static const TST TST_accum
static const TST TST_half
static const TST TST_ibm128
static const TST TST_float128
void Finish(Sema &S, const PrintingPolicy &Policy)
Finish - This does final analysis of the declspec, issuing diagnostics for things like "_Complex" (la...
static const TST TST_wchar
static const TST TST_void
static const TST TST_float
static const TST TST_fract
static const TST TST_float16
static const TST TST_decltype_auto
static const TST TST_error
static const TST TST_char32
static const TST TST_int128
bool SetTypeSpecSign(TypeSpecifierSign S, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
static const TST TST_auto
SourceLocation getLocation() const
Information about one declarator, including the parsed type information and the identifier.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
void SetSourceRange(SourceRange R)
void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc)
AddTypeInfo - Add a chunk to this declarator.
bool isInvalidType() const
DeclSpec & getMutableDeclSpec()
getMutableDeclSpec - Return a non-const version of the DeclSpec.
This represents one expression.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
static SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, unsigned Characters, const SourceManager &SM, const LangOptions &LangOpts)
AdvanceToTokenCharacter - If the current SourceLocation specifies a location at the start of a token,...
static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, const LangOptions &LangOpts)
Computes the source location just past the end of the token at this source location.
void * getAsOpaquePtr() const
static OpaquePtr make(QualType P)
static const ParsedAttributesView & none()
ParsedAttributes - A collection of parsed attributes.
Introduces zero or more scopes for parsing.
ParseScope - Introduces a new scope for parsing.
Parser - This implements a parser for the C family of languages.
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeName, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
SourceLocation getEndOfPreviousToken() const
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
AttributeFactory & getAttrFactory()
Sema & getActions() const
static TypeResult getTypeAnnotation(const Token &Tok)
getTypeAnnotation - Read a parsed type out of an annotation token.
ExprResult ParseConstraintLogicalOrExpression(bool IsTrailingRequiresClause)
Parse a constraint-logical-or-expression.
bool ParseUnqualifiedId(CXXScopeSpec &SS, ParsedType ObjectType, bool ObjectHadErrors, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, SourceLocation *TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
bool TryAnnotateOptionalCXXScopeToken(bool EnteringContext=false)
friend class ColonProtectionRAIIObject
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type.
const Token & GetLookAheadToken(unsigned N)
GetLookAheadToken - This peeks ahead N tokens and returns that token without consuming any tokens.
ExprResult ParseConstantExpression()
bool TryConsumeToken(tok::TokenKind Expected)
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
Scope * getCurScope() const
friend class InMessageExpressionRAIIObject
OpaquePtr< TemplateName > TemplateTy
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
const Token & getCurToken() const
const LangOptions & getLangOpts() const
friend class ParenBraceBracketBalancer
ExprResult ParseExpression(TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
Simple precedence-based parser for binary/ternary operators.
@ StopBeforeMatch
Stop skipping at specified token, but don't skip the token itself.
@ StopAtSemi
Stop skipping at semicolon.
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
ExprResult ParseAssignmentExpression(TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
Parse an expr that doesn't include (top-level) commas.
friend class BalancedDelimiterTracker
ExprResult ParseConstraintExpression()
Parse a constraint-expression.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
void Lex(Token &Result)
Lex the next token for this preprocessor.
void AddFlags(unsigned Flags)
Sets up the specified scope flags and adjusts the scope state variables accordingly.
void setIsConditionVarScope(bool InConditionVarScope)
@ FunctionPrototypeScope
This is a scope that corresponds to the parameters within a function prototype.
@ LambdaScope
This is the scope for a lambda, after the lambda introducer.
@ BlockScope
This is a scope that corresponds to a block/closure object.
@ ContinueScope
This is a while, do, for, which can have continue statements embedded into it.
@ BreakScope
This is a while, do, switch, for, etc that can have break statements embedded into it.
@ CompoundStmtScope
This is a compound statement scope.
@ FunctionDeclarationScope
This is a scope that corresponds to the parameters within a function prototype for a function declara...
@ FnScope
This indicates that the scope corresponds to a function, which means that labels are set here.
@ DeclScope
This is a scope that can contain a declaration.
@ PCC_Condition
Code completion occurs within the condition of an if, while, switch, or for statement.
@ Switch
An integral condition for a 'switch' statement.
@ ConstexprIf
A constant boolean condition from 'if constexpr'.
ASTContext & getASTContext() const
@ ConstantEvaluated
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
static ConditionResult ConditionError()
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
A trivial tuple used to represent a source range.
void setBegin(SourceLocation b)
SourceLocation getEnd() const
SourceLocation getBegin() const
void setEnd(SourceLocation e)
SourceLocation getEndLoc() const LLVM_READONLY
SourceLocation getBeginLoc() const LLVM_READONLY
Represents a C++ template name within the type system.
Token - This structure provides full information about a lexed token.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
const char * getName() const
void setLength(unsigned Len)
void setKind(tok::TokenKind K)
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
tok::TokenKind getKind() const
void setLocation(SourceLocation L)
The base class of the type hierarchy.
QualType getCanonicalTypeInternal() const
Represents a C++ unqualified-id that has been parsed.
struct OFI OperatorFunctionId
When Kind == IK_OperatorFunctionId, the overloaded operator that we parsed.
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
bool isValid() const
Determine whether this unqualified-id refers to a valid name.
void setDestructorName(SourceLocation TildeLoc, ParsedType ClassType, SourceLocation EndLoc)
Specify that this unqualified-id was parsed as a destructor name.
void setTemplateId(TemplateIdAnnotation *TemplateId)
Specify that this unqualified-id was parsed as a template-id.
UnionParsedType DestructorName
When Kind == IK_DestructorName, the type referred to by the class-name.
SourceLocation StartLocation
The location of the first token that describes this unqualified-id, which will be the location of the...
void setConstructorName(ParsedType ClassType, SourceLocation ClassNameLoc, SourceLocation EndLoc)
Specify that this unqualified-id was parsed as a constructor name.
const IdentifierInfo * Identifier
When Kind == IK_Identifier, the parsed identifier, or when Kind == IK_UserLiteralId,...
UnqualifiedIdKind getKind() const
Determine what kind of name we have.
uint32_t Literal
Literals are represented as positive integers.
@ After
Like System, but searched after the system directories.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
OpaquePtr< TemplateName > ParsedTemplateTy
@ NotAttributeSpecifier
This is not an attribute specifier.
ArrayTypeTrait
Names for the array type traits.
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
LambdaCaptureKind
The different capture forms in a lambda introducer.
@ LCK_ByCopy
Capturing by copy (a.k.a., by value)
@ LCK_ByRef
Capturing by reference.
@ LCK_StarThis
Capturing the *this object by copy.
@ LCK_This
Capturing the *this object by reference.
@ IK_ConstructorName
A constructor name.
@ IK_LiteralOperatorId
A user-defined literal name, e.g., operator "" _i.
@ IK_Identifier
An identifier.
@ IK_DestructorName
A destructor name.
@ IK_OperatorFunctionId
An overloaded operator name, e.g., operator+.
ActionResult< Decl * > DeclResult
nullptr
This class represents a compute construct, representing a 'Kind' of βparallelβ, 'serial',...
MutableArrayRef< Expr * > MultiExprArg
@ CopyInit
[a = b], [a = {b}]
@ Result
The result type of a method or function.
ActionResult< ParsedType > TypeResult
const FunctionProtoType * T
@ Template
We are parsing a template declaration.
@ Type
The name was classified as a type.
MutableArrayRef< ParsedTemplateArgument > ASTTemplateArgsPtr
TemplateNameKind
Specifies the kind of template name that an identifier refers to.
@ TNK_Var_template
The name refers to a variable template whose specialization produces a variable.
@ TNK_Dependent_template_name
The name refers to a dependent template name:
@ TNK_Function_template
The name refers to a function template or a set of overloaded functions that includes at least one fu...
@ TNK_Non_template
The name does not refer to a template.
@ TNK_Undeclared_template
Lookup for the name failed, but we're assuming it was a template name anyway.
const char * getOperatorSpelling(OverloadedOperatorKind Operator)
Retrieve the spelling of the given overloaded operator, without the preceding "operator" keyword.
U cast(CodeGen::Address addr)
SmallVector< Token, 4 > CachedTokens
A set of tokens that has been cached for later parsing.
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
@ None
No keyword precedes the qualified type name.
ParenParseOption
ParenParseOption - Control what ParseParenExpression will parse.
ActionResult< Expr * > ExprResult
TypeTrait
Names for traits that operate specifically on types.
@ Parens
New-expression has a C++98 paren-delimited initializer.
@ Braces
New-expression has a C++11 list-initializer.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_None
no exception specification
ActionResult< Stmt * > StmtResult
static DeclaratorChunk getFunction(bool HasProto, bool IsAmbiguous, SourceLocation LParenLoc, ParamInfo *Params, unsigned NumParams, SourceLocation EllipsisLoc, SourceLocation RParenLoc, bool RefQualifierIsLvalueRef, SourceLocation RefQualifierLoc, SourceLocation MutableLoc, ExceptionSpecificationType ESpecType, SourceRange ESpecRange, ParsedType *Exceptions, SourceRange *ExceptionRanges, unsigned NumExceptions, Expr *NoexceptExpr, CachedTokens *ExceptionSpecTokens, ArrayRef< NamedDecl * > DeclsInPrototype, SourceLocation LocalRangeBegin, SourceLocation LocalRangeEnd, Declarator &TheDeclarator, TypeResult TrailingReturnType=TypeResult(), SourceLocation TrailingReturnTypeLoc=SourceLocation(), DeclSpec *MethodQualifiers=nullptr)
DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
static DeclaratorChunk getArray(unsigned TypeQuals, bool isStatic, bool isStar, Expr *NumElts, SourceLocation LBLoc, SourceLocation RBLoc)
Return a DeclaratorChunk for an array.
Represents a complete lambda introducer.
bool hasLambdaCapture() const
void addCapture(LambdaCaptureKind Kind, SourceLocation Loc, IdentifierInfo *Id, SourceLocation EllipsisLoc, LambdaCaptureInitKind InitKind, ExprResult Init, ParsedType InitCaptureType, SourceRange ExplicitRange)
Append a capture in a lambda introducer.
SourceLocation DefaultLoc
LambdaCaptureDefault Default
Information about a template-id annotation token.
const IdentifierInfo * Name
FIXME: Temporarily stores the name of a specialization.
unsigned NumArgs
NumArgs - The number of template arguments.
SourceLocation TemplateNameLoc
TemplateNameLoc - The location of the template name within the source.
ParsedTemplateArgument * getTemplateArgs()
Retrieves a pointer to the template arguments.
SourceLocation RAngleLoc
The location of the '>' after the template argument list.
SourceLocation LAngleLoc
The location of the '<' before the template argument list.
SourceLocation TemplateKWLoc
TemplateKWLoc - The location of the template keyword.
ParsedTemplateTy Template
The declaration of the template corresponding to the template-name.
static TemplateIdAnnotation * Create(SourceLocation TemplateKWLoc, SourceLocation TemplateNameLoc, const IdentifierInfo *Name, OverloadedOperatorKind OperatorKind, ParsedTemplateTy OpaqueTemplateName, TemplateNameKind TemplateKind, SourceLocation LAngleLoc, SourceLocation RAngleLoc, ArrayRef< ParsedTemplateArgument > TemplateArgs, bool ArgsInvalid, SmallVectorImpl< TemplateIdAnnotation * > &CleanupList)
Creates a new TemplateIdAnnotation with NumArgs arguments and appends it to List.
OpaquePtr< T > get() const
OverloadedOperatorKind Operator
The kind of overloaded operator.