22 #include "llvm/Support/ErrorHandling.h" 25 using namespace clang;
30 case tok::unknown:
return 0;
32 case tok::kw_const_cast:
return 1;
33 case tok::kw_dynamic_cast:
return 2;
34 case tok::kw_reinterpret_cast:
return 3;
35 case tok::kw_static_cast:
return 4;
37 llvm_unreachable(
"Unknown type for digraph error message.");
42 bool Parser::areTokensAdjacent(
const Token &
First,
const Token &Second) {
60 P.
Diag(DigraphToken.
getLocation(), diag::err_missing_whitespace_digraph)
65 ColonToken.
setKind(tok::coloncolon);
68 DigraphToken.
setKind(tok::less);
79 void Parser::CheckForTemplateAndDigraph(
Token &Next,
ParsedType ObjectType,
82 if (!Next.
is(tok::l_square) || Next.
getLength() != 2)
85 Token SecondToken = GetLookAheadToken(2);
86 if (!SecondToken.
is(tok::colon) || !areTokensAdjacent(Next, SecondToken))
92 bool MemberOfUnknownSpecialization;
94 TemplateName, ObjectType, EnteringContext,
95 Template, MemberOfUnknownSpecialization))
98 FixDigraph(*
this, PP, Next, SecondToken, tok::unknown,
146 bool Parser::ParseOptionalCXXScopeSpecifier(
CXXScopeSpec &SS,
148 bool EnteringContext,
149 bool *MayBePseudoDestructor,
152 bool OnlyNamespace) {
154 "Call sites of this function should be guarded by checking for C++");
156 if (Tok.
is(tok::annot_cxxscope)) {
157 assert(!LastII &&
"want last identifier but have already annotated scope");
158 assert(!MayBePseudoDestructor &&
"unexpected annot_cxxscope");
162 ConsumeAnnotationToken();
166 if (Tok.
is(tok::annot_template_id)) {
174 bool CheckForDestructor =
false;
175 if (MayBePseudoDestructor && *MayBePseudoDestructor) {
176 CheckForDestructor =
true;
177 *MayBePseudoDestructor =
false;
183 bool HasScopeSpecifier =
false;
185 if (Tok.
is(tok::coloncolon)) {
188 if (NextKind == tok::kw_new || NextKind == tok::kw_delete)
191 if (NextKind == tok::l_brace) {
200 HasScopeSpecifier =
true;
204 if (Tok.
is(tok::kw___super)) {
206 if (!Tok.
is(tok::coloncolon)) {
214 if (!HasScopeSpecifier &&
215 Tok.
isOneOf(tok::kw_decltype, tok::annot_decltype)) {
225 AnnotateExistingDecltypeSpecifier(DS, DeclLoc, EndLoc);
232 HasScopeSpecifier =
true;
236 auto SavedType = PreferredType;
238 if (HasScopeSpecifier) {
239 if (Tok.
is(tok::code_completion)) {
264 ObjectType =
nullptr;
272 if (Tok.
is(tok::kw_template)) {
276 if (!HasScopeSpecifier && !ObjectType)
279 TentativeParsingAction TPA(*
this);
283 if (Tok.
is(tok::identifier)) {
287 }
else if (Tok.
is(tok::kw_operator)) {
292 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
301 diag::err_id_after_template_in_nested_name_spec)
314 if (Tok.
isNot(tok::less)) {
323 getCurScope(), SS, TemplateKWLoc, TemplateName, ObjectType,
324 EnteringContext, Template,
true)) {
325 if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateKWLoc,
326 TemplateName,
false))
334 if (Tok.
is(tok::annot_template_id) &&
NextToken().
is(tok::coloncolon)) {
343 if (CheckForDestructor && GetLookAheadToken(2).is(tok::tilde)) {
344 *MayBePseudoDestructor =
true;
349 *LastII = TemplateId->
Name;
352 ConsumeAnnotationToken();
354 assert(Tok.
is(tok::coloncolon) &&
"NextToken() not working properly!");
357 HasScopeSpecifier =
true;
383 if (Tok.
isNot(tok::identifier))
398 if (Next.
is(tok::colon) && !ColonIsSacred) {
405 Diag(Next, diag::err_unexpected_colon_in_nested_name_spec)
412 if (Next.
is(tok::coloncolon) && GetLookAheadToken(2).
is(tok::l_brace)) {
419 UnconsumeToken(Identifier);
423 if (Next.
is(tok::coloncolon)) {
424 if (CheckForDestructor && GetLookAheadToken(2).
is(tok::tilde) &&
426 *MayBePseudoDestructor =
true;
431 const Token &Next2 = GetLookAheadToken(2);
432 if (Next2.
is(tok::kw_private) || Next2.
is(tok::kw_protected) ||
433 Next2.
is(tok::kw_public) || Next2.
is(tok::kw_virtual)) {
434 Diag(Next2, diag::err_unexpected_token_in_nested_name_spec)
439 ColonColon.setKind(tok::colon);
452 assert(Tok.
isOneOf(tok::coloncolon, tok::colon) &&
453 "NextToken() not working properly!");
454 Token ColonColon = Tok;
457 bool IsCorrectedToColon =
false;
458 bool *CorrectionFlagPtr = ColonIsSacred ? &IsCorrectedToColon :
nullptr;
461 CorrectionFlagPtr, OnlyNamespace)) {
464 if (CorrectionFlagPtr && IsCorrectedToColon) {
465 ColonColon.setKind(tok::colon);
473 HasScopeSpecifier =
true;
477 CheckForTemplateAndDigraph(Next, ObjectType, EnteringContext, II, SS);
481 if (Next.
is(tok::less)) {
485 bool MemberOfUnknownSpecialization;
492 MemberOfUnknownSpecialization)) {
498 isTemplateArgumentList(1) == TPResult::False)
509 TemplateName,
false))
514 if (MemberOfUnknownSpecialization && (ObjectType || SS.
isSet()) &&
515 (IsTypename || isTemplateArgumentList(1) == TPResult::True)) {
520 unsigned DiagID = diag::err_missing_dependent_template_keyword;
522 DiagID = diag::warn_missing_dependent_template_keyword;
530 EnteringContext, Template,
true)) {
534 TemplateName,
false))
552 if (CheckForDestructor && Tok.
is(tok::tilde))
553 *MayBePseudoDestructor =
true;
559 Token &Replacement) {
567 nullptr, &TemplateKWLoc, Name))
572 if (isAddressOfOperand && isPostfixExpressionSuffixStart())
573 isAddressOfOperand =
false;
576 getCurScope(), SS, TemplateKWLoc, Name, Tok.
is(tok::l_paren),
577 isAddressOfOperand,
nullptr,
false,
580 checkPotentialAngleBracket(E);
626 ExprResult Parser::ParseCXXIdExpression(
bool isAddressOfOperand) {
632 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
false);
636 tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement);
640 UnconsumeToken(Replacement);
641 Result = tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement);
643 assert(!Result.
isUnset() &&
"Typo correction suggested a keyword replacement " 644 "for a previous keyword suggestion");
692 if (ParseLambdaIntroducer(Intro)) {
699 return ParseLambdaExpressionAfterIntroducer(Intro);
706 ExprResult Parser::TryParseLambdaExpression() {
708 && Tok.
is(tok::l_square)
709 &&
"Not at the start of a possible lambda expression.");
717 if (Next.is(tok::r_square) ||
718 Next.is(tok::equal) ||
719 (Next.is(tok::amp) &&
720 After.
isOneOf(tok::r_square, tok::comma)) ||
721 (Next.is(tok::identifier) &&
722 After.
is(tok::r_square)) ||
723 Next.is(tok::ellipsis)) {
724 return ParseLambdaExpression();
729 if (Next.is(tok::identifier) && After.
is(tok::identifier))
739 TentativeParsingAction TPA(*
this);
740 LambdaIntroducerTentativeParse Tentative;
741 if (ParseLambdaIntroducer(Intro, &Tentative)) {
747 case LambdaIntroducerTentativeParse::Success:
751 case LambdaIntroducerTentativeParse::Incomplete:
756 if (ParseLambdaIntroducer(Intro))
760 case LambdaIntroducerTentativeParse::MessageSend:
761 case LambdaIntroducerTentativeParse::Invalid:
768 return ParseLambdaExpressionAfterIntroducer(Intro);
781 LambdaIntroducerTentativeParse *Tentative) {
783 *Tentative = LambdaIntroducerTentativeParse::Success;
785 assert(Tok.
is(tok::l_square) &&
"Lambda expressions begin with '['.");
795 auto Invalid = [&](llvm::function_ref<void()> Action) {
797 *Tentative = LambdaIntroducerTentativeParse::Invalid;
806 auto NonTentativeAction = [&](llvm::function_ref<void()> Action) {
808 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
814 if (Tok.
is(tok::amp) &&
824 }
else if (Tok.
is(tok::equal)) {
831 while (Tok.
isNot(tok::r_square)) {
833 if (Tok.
isNot(tok::comma)) {
838 if (Tok.
is(tok::code_completion) &&
853 if (Tok.
is(tok::code_completion)) {
876 if (Tok.
is(tok::star)) {
878 if (Tok.
is(tok::kw_this)) {
886 }
else if (Tok.
is(tok::kw_this)) {
892 if (Tok.
is(tok::amp)) {
896 if (Tok.
is(tok::code_completion)) {
906 if (Tok.
is(tok::identifier)) {
909 }
else if (Tok.
is(tok::kw_this)) {
922 if (Tok.
is(tok::l_paren)) {
932 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
933 }
else if (ParseExpressionList(Exprs, Commas)) {
942 }
else if (Tok.
isOneOf(tok::l_brace, tok::equal)) {
955 Init = ParseInitializer();
956 }
else if (Tok.
is(tok::l_brace)) {
960 *Tentative = LambdaIntroducerTentativeParse::Incomplete;
984 Init = ParseInitializer();
994 Tok.
setKind(tok::annot_primary_expr);
995 setExprAnnotation(Tok, Init);
1000 ConsumeAnnotationToken();
1009 if (Tentative && Tok.
is(tok::identifier) &&
1012 *Tentative = LambdaIntroducerTentativeParse::MessageSend;
1018 if (std::any_of(std::begin(EllipsisLocs), std::end(EllipsisLocs),
1024 !InitCapture ? &EllipsisLocs[2] :
1027 EllipsisLoc = *ExpectedEllipsisLoc;
1029 unsigned DiagID = 0;
1031 DiagID = diag::err_lambda_capture_misplaced_ellipsis;
1037 unsigned NumEllipses = std::accumulate(
1038 std::begin(EllipsisLocs), std::end(EllipsisLocs), 0,
1040 if (NumEllipses > 1)
1041 DiagID = diag::err_lambda_capture_multiple_ellipses;
1044 NonTentativeAction([&] {
1048 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid()) {
1053 assert(DiagLoc.
isValid() &&
"no location for diagnostic");
1057 auto &&D =
Diag(DiagLoc, DiagID);
1058 if (DiagID == diag::err_lambda_capture_misplaced_ellipsis) {
1066 if (&Loc != ExpectedEllipsisLoc && Loc.
isValid())
1081 NonTentativeAction([&] {
1088 Loc, Kind ==
LCK_ByRef, EllipsisLoc, Id, InitKind, InitExpr);
1095 Intro.
addCapture(Kind, Loc, Id, EllipsisLoc, InitKind, Init,
1117 case tok::kw_mutable: {
1120 diag::err_lambda_decl_specifier_repeated)
1124 DeclEndLoc = MutableLoc;
1127 case tok::kw_constexpr:
1130 diag::err_lambda_decl_specifier_repeated)
1134 DeclEndLoc = ConstexprLoc;
1136 case tok::kw_consteval:
1139 diag::err_lambda_decl_specifier_repeated)
1143 DeclEndLoc = ConstevalLoc;
1156 ? diag::ext_constexpr_on_lambda_cxx17
1157 : diag::warn_cxx14_compat_constexpr_on_lambda);
1158 const char *PrevSpec =
nullptr;
1159 unsigned DiagID = 0;
1161 assert(PrevSpec ==
nullptr && DiagID == 0 &&
1162 "Constexpr cannot have been set previously!");
1170 P.
Diag(ConstevalLoc, diag::warn_cxx20_compat_consteval);
1171 const char *PrevSpec =
nullptr;
1172 unsigned DiagID = 0;
1175 P.
Diag(ConstevalLoc, DiagID) << PrevSpec;
1181 ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
1184 Diag(LambdaBeginLoc, diag::warn_cxx98_compat_lambda);
1187 "lambda expression parsing");
1197 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1205 MaybeParseGNUAttributes(D);
1210 auto WarnIfHasCUDATargetAttr = [&] {
1213 if (A.getKind() == ParsedAttr::AT_CUDADevice ||
1214 A.getKind() == ParsedAttr::AT_CUDAHost ||
1215 A.getKind() == ParsedAttr::AT_CUDAGlobal)
1216 Diag(A.getLoc(), diag::warn_cuda_attr_lambda_position)
1217 << A.getName()->getName();
1221 const bool HasExplicitTemplateParams = Tok.
is(tok::less);
1223 HasExplicitTemplateParams);
1224 if (HasExplicitTemplateParams) {
1226 ? diag::warn_cxx17_compat_lambda_template_parameter_list
1227 : diag::ext_lambda_template_parameter_list);
1231 if (ParseTemplateParameters(CurTemplateDepthTracker.getDepth(),
1232 TemplateParams, LAngleLoc, RAngleLoc)) {
1237 if (TemplateParams.empty()) {
1239 diag::err_lambda_template_parameter_list_empty);
1242 LAngleLoc, TemplateParams, RAngleLoc);
1243 ++CurTemplateDepthTracker;
1248 if (Tok.
is(tok::l_paren)) {
1249 ParseScope PrototypeScope(
this,
1262 if (Tok.
isNot(tok::r_paren)) {
1264 CurTemplateDepthTracker.getOriginalDepth());
1266 ParseParameterDeclarationClause(D, Attr, ParamInfo, EllipsisLoc);
1274 CurTemplateDepthTracker.setAddedDepth(1);
1283 MaybeParseGNUAttributes(Attr, &DeclEndLoc);
1287 MaybeParseMicrosoftDeclSpecs(Attr, &DeclEndLoc);
1295 ConstevalLoc, DeclEndLoc);
1306 ESpecType = tryParseExceptionSpecification(
false,
1309 DynamicExceptionRanges,
1311 ExceptionSpecTokens);
1314 DeclEndLoc = ESpecRange.
getEnd();
1317 MaybeParseCXX11Attributes(Attr, &DeclEndLoc);
1322 if (Tok.
is(tok::arrow)) {
1325 TrailingReturnType =
1326 ParseTrailingReturnType(Range,
false);
1328 DeclEndLoc = Range.
getEnd();
1331 PrototypeScope.Exit();
1333 WarnIfHasCUDATargetAttr();
1338 false, LParenLoc, ParamInfo.data(),
1339 ParamInfo.size(), EllipsisLoc, RParenLoc,
1341 NoLoc, MutableLoc, ESpecType,
1342 ESpecRange, DynamicExceptions.data(),
1343 DynamicExceptionRanges.data(), DynamicExceptions.size(),
1344 NoexceptExpr.
isUsable() ? NoexceptExpr.
get() :
nullptr,
1346 None, LParenLoc, FunLocalRangeEnd, D,
1347 TrailingReturnType),
1348 std::move(Attr), DeclEndLoc);
1349 }
else if (Tok.
isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
1350 tok::kw_constexpr, tok::kw_consteval) ||
1354 unsigned TokKind = 0;
1356 case tok::kw_mutable: TokKind = 0;
break;
1357 case tok::arrow: TokKind = 1;
break;
1358 case tok::kw___attribute:
1359 case tok::l_square: TokKind = 2;
break;
1360 case tok::kw_constexpr: TokKind = 3;
break;
1361 case tok::kw_consteval: TokKind = 4;
break;
1362 default: llvm_unreachable(
"Unknown token kind");
1365 Diag(Tok, diag::err_lambda_missing_parens)
1372 MaybeParseGNUAttributes(Attr, &DeclEndLoc);
1376 if (Tok.
is(tok::kw_mutable)) {
1378 DeclEndLoc = MutableLoc;
1382 MaybeParseCXX11Attributes(Attr, &DeclEndLoc);
1385 if (Tok.
is(tok::arrow)) {
1387 TrailingReturnType =
1388 ParseTrailingReturnType(Range,
false);
1390 DeclEndLoc = Range.
getEnd();
1393 WarnIfHasCUDATargetAttr();
1412 None, DeclLoc, DeclEndLoc, D,
1413 TrailingReturnType),
1414 std::move(Attr), DeclEndLoc);
1421 ParseScope BodyScope(
this, ScopeFlags);
1426 if (!Tok.
is(tok::l_brace)) {
1427 Diag(Tok, diag::err_expected_lambda_body);
1434 TemplateParamScope.Exit();
1436 if (!Stmt.isInvalid() && !TrailingReturnType.
isInvalid())
1454 const char *CastName =
nullptr;
1457 default: llvm_unreachable(
"Unknown C++ cast!");
1458 case tok::kw_const_cast: CastName =
"const_cast";
break;
1459 case tok::kw_dynamic_cast: CastName =
"dynamic_cast";
break;
1460 case tok::kw_reinterpret_cast: CastName =
"reinterpret_cast";
break;
1461 case tok::kw_static_cast: CastName =
"static_cast";
break;
1469 if (Tok.
is(tok::l_square) && Tok.
getLength() == 2) {
1471 if (Next.
is(tok::colon) && areTokensAdjacent(Tok, Next))
1472 FixDigraph(*
this, PP, Tok, Next, Kind,
true);
1475 if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName))
1480 ParseSpecifierQualifierList(DS);
1484 ParseDeclarator(DeclaratorInfo);
1488 if (ExpectAndConsume(tok::greater))
1489 return ExprError(
Diag(LAngleBracketLoc, diag::note_matching) << tok::less);
1503 LAngleBracketLoc, DeclaratorInfo,
1518 assert(Tok.
is(tok::kw_typeid) &&
"Not 'typeid'!");
1548 if (isTypeIdInParens()) {
1558 Ty.
get().getAsOpaquePtr(), RParenLoc);
1572 Result.
get(), RParenLoc);
1585 assert(Tok.
is(tok::kw___uuidof) &&
"Not '__uuidof'!");
1596 if (isTypeIdInParens()) {
1606 Ty.
get().getAsOpaquePtr(),
1657 if (Tok.
is(tok::identifier)) {
1660 assert(Tok.
is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1662 }
else if (Tok.
is(tok::annot_template_id)) {
1667 ConsumeAnnotationToken();
1668 assert(Tok.
is(tok::coloncolon) &&
"ParseOptionalCXXScopeSpecifier fail");
1675 assert(Tok.
is(tok::tilde) &&
"ParseOptionalCXXScopeSpecifier fail");
1678 if (Tok.
is(tok::kw_decltype) && !FirstTypeName.
isValid() && SS.
isEmpty()) {
1680 ParseDecltypeSpecifier(DS);
1687 if (!Tok.
is(tok::identifier)) {
1688 Diag(Tok, diag::err_destructor_tilde_identifier);
1700 if (Tok.
is(tok::less) &&
1703 false, ObjectType, SecondTypeName,
1708 SS, FirstTypeName, CCLoc, TildeLoc,
1727 assert(Tok.
is(tok::kw_throw) &&
"Not throw!");
1753 ExprResult Parser::ParseCoyieldExpression() {
1754 assert(Tok.
is(tok::kw_co_yield) &&
"Not co_yield!");
1770 assert(Tok.
is(tok::kw_this) &&
"Not 'this'!");
1789 Parser::ParseCXXTypeConstructExpression(
const DeclSpec &DS) {
1793 assert((Tok.
is(tok::l_paren) ||
1795 &&
"Expected '(' or '{'!");
1797 if (Tok.
is(tok::l_brace)) {
1812 CommaLocsTy CommaLocs;
1814 auto RunSignatureHelp = [&]() {
1818 CalledSignatureHelp =
true;
1819 return PreferredType;
1822 if (Tok.
isNot(tok::r_paren)) {
1823 if (ParseExpressionList(Exprs, CommaLocs, [&] {
1841 assert((Exprs.size() == 0 || Exprs.size()-1 == CommaLocs.size())&&
1842 "Unexpected number of commas!");
1877 ForRangeInfo *FRI) {
1881 if (Tok.
is(tok::code_completion)) {
1887 ParsedAttributesWithRange attrs(AttrFactory);
1888 MaybeParseCXX11Attributes(attrs);
1890 const auto WarnOnInit = [
this, &CK] {
1892 ? diag::warn_cxx14_compat_init_statement
1893 : diag::ext_init_statement)
1898 switch (isCXXConditionDeclarationOrInitStatement(InitStmt, FRI)) {
1899 case ConditionOrInitStatement::Expression: {
1900 ProhibitAttributes(attrs);
1904 if (InitStmt && Tok.
is(tok::semi)) {
1908 Diag(SemiLoc, diag::warn_empty_init_statement)
1914 return ParseCXXCondition(
nullptr, Loc, CK);
1922 if (InitStmt && Tok.
is(tok::semi)) {
1926 return ParseCXXCondition(
nullptr, Loc, CK);
1932 case ConditionOrInitStatement::InitStmtDecl: {
1939 return ParseCXXCondition(
nullptr, Loc, CK);
1942 case ConditionOrInitStatement::ForRangeDecl: {
1943 assert(FRI &&
"should not parse a for range declaration here");
1951 case ConditionOrInitStatement::ConditionDecl:
1952 case ConditionOrInitStatement::Error:
1959 ParseSpecifierQualifierList(DS,
AS_none, DeclSpecContext::DSC_condition);
1963 ParseDeclarator(DeclaratorInfo);
1966 if (Tok.
is(tok::kw_asm)) {
1978 MaybeParseGNUAttributes(DeclaratorInfo);
1989 bool CopyInitialization = isTokenEqualOrEqualTypo();
1990 if (CopyInitialization)
1996 diag::warn_cxx98_compat_generalized_initializer_lists);
1997 InitExpr = ParseBraceInitializer();
1998 }
else if (CopyInitialization) {
2001 }
else if (Tok.
is(tok::l_paren)) {
2005 RParen = ConsumeParen();
2007 diag::err_expected_init_in_condition_lparen)
2048 void Parser::ParseCXXSimpleTypeSpecifier(
DeclSpec &DS) {
2050 const char *PrevSpec;
2057 case tok::identifier:
2058 case tok::coloncolon:
2059 llvm_unreachable(
"Annotation token should already be formed!");
2061 llvm_unreachable(
"Not a simple-type-specifier token!");
2064 case tok::annot_typename: {
2072 ConsumeAnnotationToken();
2074 DS.
Finish(Actions, Policy);
2085 case tok::kw___int64:
2088 case tok::kw_signed:
2091 case tok::kw_unsigned:
2103 case tok::kw___int128:
2112 case tok::kw_double:
2115 case tok::kw__Float16:
2118 case tok::kw___float128:
2121 case tok::kw_wchar_t:
2124 case tok::kw_char8_t:
2127 case tok::kw_char16_t:
2130 case tok::kw_char32_t:
2136 #define GENERIC_IMAGE_TYPE(ImgType, Id) \ 2137 case tok::kw_##ImgType##_t: \ 2138 DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, DiagID, \ 2141 #include "clang/Basic/OpenCLImageTypes.def" 2143 case tok::annot_decltype:
2144 case tok::kw_decltype:
2146 return DS.
Finish(Actions, Policy);
2149 case tok::kw_typeof:
2150 ParseTypeofSpecifier(DS);
2151 DS.
Finish(Actions, Policy);
2156 DS.
Finish(Actions, Policy);
2170 bool Parser::ParseCXXTypeSpecifierSeq(
DeclSpec &DS) {
2171 ParseSpecifierQualifierList(DS,
AS_none, DeclSpecContext::DSC_type_specifier);
2208 bool Parser::ParseUnqualifiedIdTemplateId(
CXXScopeSpec &SS,
2212 bool EnteringContext,
2215 bool AssumeTemplateId) {
2216 assert(Tok.
is(tok::less) &&
"Expected '<' to finish parsing a template-id");
2224 if (AssumeTemplateId) {
2228 getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext,
2233 bool MemberOfUnknownSpecialization;
2236 ObjectType, EnteringContext, Template,
2237 MemberOfUnknownSpecialization);
2242 isTemplateArgumentList(0) == TPResult::False)
2246 ObjectType && isTemplateArgumentList(0) == TPResult::True) {
2265 getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext,
2275 bool MemberOfUnknownSpecialization;
2278 TemplateName, ObjectType,
2279 EnteringContext, Template,
2280 MemberOfUnknownSpecialization);
2286 bool MemberOfUnknownSpecialization;
2290 getCurScope(), SS, TemplateKWLoc, TemplateName, ObjectType,
2291 EnteringContext, Template,
true);
2296 TemplateName, ObjectType,
2297 EnteringContext, Template,
2298 MemberOfUnknownSpecialization);
2301 Diag(NameLoc, diag::err_destructor_template_id)
2318 TemplateArgList TemplateArgs;
2319 if (ParseTemplateIdAfterTemplateName(
true, LAngleLoc, TemplateArgs,
2339 SS, TemplateKWLoc, Id.
StartLocation, TemplateII, OpKind, Template, TNK,
2340 LAngleLoc, RAngleLoc, TemplateArgs, TemplateIds);
2351 getCurScope(), SS, TemplateKWLoc, Template, Name, NameLoc, LAngleLoc,
2352 TemplateArgsPtr, RAngleLoc,
true);
2404 bool Parser::ParseUnqualifiedIdOperator(
CXXScopeSpec &SS,
bool EnteringContext,
2407 assert(Tok.
is(tok::kw_operator) &&
"Expected 'operator' keyword");
2413 unsigned SymbolIdx = 0;
2418 case tok::kw_delete: {
2419 bool isNew = Tok.
getKind() == tok::kw_new;
2423 if (Tok.
is(tok::l_square) &&
2434 Op = isNew? OO_Array_New : OO_Array_Delete;
2436 Op = isNew? OO_New : OO_Delete;
2441 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ 2443 SymbolLocations[SymbolIdx++] = ConsumeToken(); \ 2446 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) 2447 #include "clang/Basic/OperatorKinds.def" 2449 case tok::l_paren: {
2463 case tok::l_square: {
2477 case tok::code_completion: {
2505 unsigned DiagId = 0;
2511 while (isTokenStringLiteral()) {
2512 if (!Tok.
is(tok::string_literal) && !DiagId) {
2517 DiagId = diag::err_literal_operator_string_prefix;
2519 Toks.push_back(Tok);
2520 TokLocs.push_back(ConsumeStringToken());
2537 }
else if (Tok.
is(tok::identifier)) {
2540 TokLocs.push_back(SuffixLoc);
2552 DiagLoc = TokLocs.front();
2553 DiagId = diag::err_literal_operator_string_not_empty;
2563 SourceRange(TokLocs.front(), TokLocs.back()), Str);
2584 if (ParseCXXTypeSpecifierSeq(DS))
2590 ParseDeclaratorInternal(D,
nullptr);
2636 bool AllowDestructorName,
2637 bool AllowConstructorName,
2638 bool AllowDeductionGuide,
2647 bool TemplateSpecified =
false;
2648 if (Tok.
is(tok::kw_template)) {
2649 if (TemplateKWLoc && (ObjectType || SS.
isSet())) {
2650 TemplateSpecified =
true;
2654 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2662 if (Tok.
is(tok::identifier)) {
2675 if (AllowConstructorName &&
2684 AllowDeductionGuide && SS.
isEmpty() &&
2696 if (Tok.
is(tok::less))
2697 return ParseUnqualifiedIdTemplateId(
2699 EnteringContext, ObjectType,
Result, TemplateSpecified);
2700 else if (TemplateSpecified &&
2702 getCurScope(), SS, *TemplateKWLoc, Result, ObjectType,
2703 EnteringContext, Template,
2712 if (Tok.
is(tok::annot_template_id)) {
2716 if (AllowConstructorName && TemplateId->
Name &&
2724 diag::err_out_of_line_constructor_template_id)
2735 ConsumeAnnotationToken();
2740 ConsumeAnnotationToken();
2749 if (TemplateKWLoc && (ObjectType || SS.
isSet()))
2750 *TemplateKWLoc = TemplateLoc;
2752 Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2755 ConsumeAnnotationToken();
2762 if (Tok.
is(tok::kw_operator)) {
2763 if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType, Result))
2775 return ParseUnqualifiedIdTemplateId(
2779 else if (TemplateSpecified &&
2781 getCurScope(), SS, *TemplateKWLoc, Result, ObjectType,
2782 EnteringContext, Template,
2790 (AllowDestructorName || SS.
isSet()) && Tok.
is(tok::tilde)) {
2799 if (SS.
isEmpty() && Tok.
is(tok::kw_decltype)) {
2811 if (Tok.
isNot(tok::identifier)) {
2812 Diag(Tok, diag::err_destructor_tilde_identifier);
2817 DeclaratorScopeObj DeclScopeObj(*
this, SS);
2818 if (!TemplateSpecified &&
NextToken().is(tok::coloncolon)) {
2825 AnnotateScopeToken(SS,
true);
2828 if (ParseOptionalCXXScopeSpecifier(SS, ObjectType, EnteringContext))
2831 ObjectType =
nullptr;
2834 Diag(TildeLoc, diag::err_destructor_tilde_scope);
2839 Diag(TildeLoc, diag::err_destructor_tilde_scope)
2845 DeclScopeObj.EnterDeclaratorScope();
2852 if (Tok.
is(tok::less)) {
2854 return ParseUnqualifiedIdTemplateId(
2855 SS, TemplateKWLoc ? *TemplateKWLoc :
SourceLocation(), ClassName,
2856 ClassNameLoc, EnteringContext, ObjectType, Result, TemplateSpecified);
2871 Diag(Tok, diag::err_expected_unqualified_id)
2905 Parser::ParseCXXNewExpression(
bool UseGlobal,
SourceLocation Start) {
2906 assert(Tok.
is(tok::kw_new) &&
"expected 'new' token");
2918 if (Tok.
is(tok::l_paren)) {
2923 if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) {
2935 if (PlacementArgs.empty()) {
2941 if (Tok.
is(tok::l_paren)) {
2944 MaybeParseGNUAttributes(DeclaratorInfo);
2945 ParseSpecifierQualifierList(DS);
2947 ParseDeclarator(DeclaratorInfo);
2951 MaybeParseGNUAttributes(DeclaratorInfo);
2952 if (ParseCXXTypeSpecifierSeq(DS))
2956 ParseDeclaratorInternal(DeclaratorInfo,
2957 &Parser::ParseDirectNewDeclarator);
2964 MaybeParseGNUAttributes(DeclaratorInfo);
2965 if (ParseCXXTypeSpecifierSeq(DS))
2969 ParseDeclaratorInternal(DeclaratorInfo,
2970 &Parser::ParseDirectNewDeclarator);
2980 if (Tok.
is(tok::l_paren)) {
2986 if (Tok.
isNot(tok::r_paren)) {
2988 auto RunSignatureHelp = [&]() {
2993 DeclaratorInfo.
getEndLoc(), ConstructorArgs, ConstructorLParen);
2994 CalledSignatureHelp =
true;
2995 return PreferredType;
2997 if (ParseExpressionList(ConstructorArgs, CommaLocs, [&] {
3016 }
else if (Tok.
is(tok::l_brace) &&
getLangOpts().CPlusPlus11) {
3018 diag::warn_cxx98_compat_generalized_initializer_lists);
3019 Initializer = ParseBraceInitializer();
3024 return Actions.
ActOnCXXNew(Start, UseGlobal, PlacementLParen,
3025 PlacementArgs, PlacementRParen,
3026 TypeIdParens, DeclaratorInfo, Initializer.
get());
3036 void Parser::ParseDirectNewDeclarator(
Declarator &D) {
3039 while (Tok.
is(tok::l_square)) {
3041 if (CheckProhibitedCXX11Attribute())
3061 MaybeParseCXX11Attributes(Attrs);
3084 bool Parser::ParseExpressionListOrTypeId(
3088 if (isTypeIdInParens()) {
3098 return ParseExpressionList(PlacementArgs, CommaLocs);
3113 Parser::ParseCXXDeleteExpression(
bool UseGlobal,
SourceLocation Start) {
3114 assert(Tok.
is(tok::kw_delete) &&
"Expected 'delete' keyword");
3118 bool ArrayDelete =
false;
3119 if (Tok.
is(tok::l_square) &&
NextToken().
is(tok::r_square)) {
3127 const Token Next = GetLookAheadToken(2);
3130 if (Next.
isOneOf(tok::l_brace, tok::less) ||
3131 (Next.
is(tok::l_paren) &&
3132 (GetLookAheadToken(3).
is(tok::r_paren) ||
3133 (GetLookAheadToken(3).
is(tok::identifier) &&
3134 GetLookAheadToken(4).
is(tok::identifier))))) {
3135 TentativeParsingAction TPA(*
this);
3143 bool EmitFixIt =
false;
3144 if (Tok.
is(tok::l_brace)) {
3154 Diag(Start, diag::err_lambda_after_delete)
3162 Diag(Start, diag::err_lambda_after_delete)
3172 Lambda = ParsePostfixExpressionSuffix(Lambda);
3188 ExprResult Operand(ParseCastExpression(
false));
3197 default: llvm_unreachable(
"Not a known type trait");
3198 #define TYPE_TRAIT_1(Spelling, Name, Key) \ 3199 case tok::kw_ ## Spelling: return UTT_ ## Name; 3200 #define TYPE_TRAIT_2(Spelling, Name, Key) \ 3201 case tok::kw_ ## Spelling: return BTT_ ## Name; 3202 #include "clang/Basic/TokenKinds.def" 3203 #define TYPE_TRAIT_N(Spelling, Name, Key) \ 3204 case tok::kw_ ## Spelling: return TT_ ## Name; 3205 #include "clang/Basic/TokenKinds.def" 3211 default: llvm_unreachable(
"Not a known binary type trait");
3219 default: llvm_unreachable(
"Not a known unary expression trait.");
3227 default: llvm_unreachable(
"Not a known type trait");
3228 #define TYPE_TRAIT(N,Spelling,K) case tok::kw_##Spelling: return N; 3229 #include "clang/Basic/TokenKinds.def" 3264 if (Tok.
is(tok::ellipsis)) {
3273 Args.push_back(Ty.
get());
3281 if (Arity && Args.size() != Arity) {
3282 Diag(EndLoc, diag::err_type_trait_arity)
3283 << Arity << 0 << (Arity > 1) << (
int)Args.size() <<
SourceRange(Loc);
3287 if (!Arity && Args.empty()) {
3288 Diag(EndLoc, diag::err_type_trait_arity)
3289 << 1 << 1 << 1 << (int)Args.size() <<
SourceRange(Loc);
3325 if (ExpectAndConsume(tok::comma)) {
3337 llvm_unreachable(
"Invalid ArrayTypeTrait!");
3367 Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,
3372 assert(ExprType ==
CastExpr &&
"Compound literals are not ambiguous!");
3373 assert(isTypeIdInParens() &&
"Not a type-id!");
3397 ParenParseOption ParseAs;
3402 if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) {
3408 if (Tok.
is(tok::l_brace)) {
3409 ParseAs = CompoundLiteral;
3419 Result = ParseCastExpression(
false,
3428 ParseAs = NotCastExpr ? SimpleExpr :
CastExpr;
3437 Toks.push_back(AttrEnd);
3440 Toks.push_back(Tok);
3443 PP.EnterTokenStream(Toks,
true,
3449 if (ParseAs >= CompoundLiteral) {
3455 ParseSpecifierQualifierList(DS);
3456 ParseDeclarator(DeclaratorInfo);
3467 if (ParseAs == CompoundLiteral) {
3468 ExprType = CompoundLiteral;
3473 return ParseCompoundLiteralExpression(Ty.
get(),
3487 DeclaratorInfo, CastTy,
3493 assert(ParseAs == SimpleExpr);
3495 ExprType = SimpleExpr;
3522 if (T.
expectAndConsume(diag::err_expected_lparen_after,
"__builtin_bit_cast"))
3527 ParseSpecifierQualifierList(DS);
3531 ParseDeclarator(DeclaratorInfo);
3533 if (ExpectAndConsume(tok::comma)) {
static TypeTrait TypeTraitFromTokKind(tok::TokenKind kind)
Defines the clang::ASTContext interface.
void setConstructorName(ParsedType ClassType, SourceLocation ClassNameLoc, SourceLocation EndLoc)
Specify that this unqualified-id was parsed as a constructor name.
ConditionResult ActOnCondition(Scope *S, SourceLocation Loc, Expr *SubExpr, ConditionKind CK)
ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT, SourceLocation KWLoc, ParsedType LhsTy, Expr *DimExpr, SourceLocation RParen)
ActOnArrayTypeTrait - Parsed one of the binary type trait support pseudo-functions.
StringRef getUDSuffix() const
ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, Declarator &D, ParsedType &Ty, SourceLocation RParenLoc, Expr *CastExpr)
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
no exception specification
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
void restore()
restore - This can be used to restore the state early, before the dtor is run.
A (possibly-)qualified type.
Keeps information about an identifier in a nested-name-spec.
This is a scope that corresponds to the parameters within a function prototype.
ConditionResult ActOnConditionVariable(Decl *ConditionVar, SourceLocation StmtLoc, ConditionKind CK)
static void tryConsumeLambdaSpecifierToken(Parser &P, SourceLocation &MutableLoc, SourceLocation &ConstexprLoc, SourceLocation &ConstevalLoc, SourceLocation &DeclEndLoc)
bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id)
SourceRange getSourceRange() const LLVM_READONLY
Return the source range that covers this unqualified-id.
static const TSS TSS_unsigned
bool ActOnCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo, bool EnteringContext, CXXScopeSpec &SS, bool ErrorRecoveryLookup=false, bool *IsCorrectedToColon=nullptr, bool OnlyNamespace=false)
The parser has parsed a nested-name-specifier 'identifier::'.
SourceLocation StartLocation
The location of the first token that describes this unqualified-id, which will be the location of the...
IdentifierInfo * Name
FIXME: Temporarily stores the name of a specialization.
static const TST TST_wchar
ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val)
SourceLocation TemplateNameLoc
TemplateNameLoc - The location of the template name within the source.
static ConditionResult ConditionError()
const Token & LookAhead(unsigned N)
Peeks ahead N tokens and returns that token without consuming any tokens.
Stmt - This represents one statement.
IdentifierInfo * Identifier
When Kind == IK_Identifier, the parsed identifier, or when Kind == IK_UserLiteralId, the identifier suffix.
ParsedType actOnLambdaInitCaptureInitialization(SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, IdentifierInfo *Id, LambdaCaptureInitKind InitKind, Expr *&Init)
Perform initialization analysis of the init-capture and perform any implicit conversions such as an l...
TemplateNameKind isTemplateName(Scope *S, CXXScopeSpec &SS, bool hasTemplateKeyword, const UnqualifiedId &Name, ParsedType ObjectType, bool EnteringContext, TemplateTy &Template, bool &MemberOfUnknownSpecialization)
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)) {...
bool isEmpty() const
No scope specifier.
DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D)
ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a C++ if/switch/while/for statem...
void setEndLoc(SourceLocation Loc)
static const TST TST_char16
Decl - This represents one declaration (or definition), e.g.
bool isCodeCompletionReached() const
Returns true if code-completion is enabled and we have hit the code-completion point.
Defines the PrettyStackTraceEntry class, which is used to make crashes give more contextual informati...
Defines the C++ template declaration subclasses.
The base class of the type hierarchy.
SourceLocation getCloseLocation() const
This indicates that the scope corresponds to a function, which means that labels are set here...
SourceLocation getEndLoc() const LLVM_READONLY
Parser - This implements a parser for the C family of languages.
An overloaded operator name, e.g., operator+.
bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, NestedNameSpecInfo &IdInfo, bool EnteringContext)
IsInvalidUnlessNestedName - This method is used for error recovery purposes to determine whether the ...
ExprResult ActOnExpressionTrait(ExpressionTrait OET, SourceLocation KWLoc, Expr *Queried, SourceLocation RParen)
ActOnExpressionTrait - Parsed one of the unary type trait support pseudo-functions.
static TemplateIdAnnotation * Create(CXXScopeSpec SS, SourceLocation TemplateKWLoc, SourceLocation TemplateNameLoc, IdentifierInfo *Name, OverloadedOperatorKind OperatorKind, ParsedTemplateTy OpaqueTemplateName, TemplateNameKind TemplateKind, SourceLocation LAngleLoc, SourceLocation RAngleLoc, ArrayRef< ParsedTemplateArgument > TemplateArgs, SmallVectorImpl< TemplateIdAnnotation *> &CleanupList)
Creates a new TemplateIdAnnotation with NumArgs arguments and appends it to List. ...
void CodeCompleteObjCMessageReceiver(Scope *S)
RAII object that enters a new expression evaluation context.
ActionResult< Stmt * > StmtResult
Information about one declarator, including the parsed type information and the identifier.
static const TST TST_char
Like System, but searched after the system directories.
void setBegin(SourceLocation b)
Describes how types, statements, expressions, and declarations should be printed. ...
RAII object that makes sure paren/bracket/brace count is correct after declaration/statement parsing...
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed...
tok::TokenKind getKind() const
bool SetConstexprSpec(ConstexprSpecKind ConstexprKind, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
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 ...
Information about a template-id annotation token.
void enterFunctionArgument(SourceLocation Tok, llvm::function_ref< QualType()> ComputeType)
Computing a type for the function argument may require running overloading, so we postpone its comput...
void enterVariableInit(SourceLocation Tok, Decl *D)
void CodeCompleteOrdinaryName(Scope *S, ParserCompletionContext CompletionContext)
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
bool TryConsumeToken(tok::TokenKind Expected)
bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, const DeclSpec &DS, SourceLocation ColonColonLoc)
One of these records is kept for each identifier that is lexed.
void setConstructorTemplateId(TemplateIdAnnotation *TemplateId)
Specify that this unqualified-id was parsed as a template-id that names a constructor.
SourceLocation getAnnotationEndLoc() const
sema::LambdaScopeInfo * getCurGenericLambda()
Retrieve the current generic lambda info, if any.
StmtResult ActOnExprStmt(ExprResult Arg, bool DiscardedValue=true)
static const TST TST_char8
Lookup for the name failed, but we're assuming it was a template name anyway.
void setConversionFunctionId(SourceLocation OperatorLoc, ParsedType Ty, SourceLocation EndLoc)
Specify that this unqualified-id was parsed as a conversion-function-id.
SourceLocation getBeginLoc() const LLVM_READONLY
LambdaCaptureKind
The different capture forms in a lambda introducer.
The current expression is potentially evaluated at run time, which means that code may be generated t...
bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS)
OverloadedOperatorKind Operator
The kind of overloaded operator.
static const TST TST_double
struct OFI OperatorFunctionId
When Kind == IK_OperatorFunctionId, the overloaded operator that we parsed.
ExprResult ActOnCXXUuidof(SourceLocation OpLoc, SourceLocation LParenLoc, bool isType, void *TyOrExpr, SourceLocation RParenLoc)
ActOnCXXUuidof - Parse __uuidof( something ).
Token - This structure provides full information about a lexed token.
void setKind(tok::TokenKind K)
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ...
ParsedType getDestructorName(SourceLocation TildeLoc, IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec &SS, ParsedType ObjectType, bool EnteringContext)
A user-defined literal name, e.g., operator "" _i.
void SetSourceRange(SourceRange R)
bool isInvalidType() const
ExprResult ActOnBuiltinBitCastExpr(SourceLocation KWLoc, Declarator &Dcl, ExprResult Operand, SourceLocation RParenLoc)
void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, bool AfterAmpersand)
UnionParsedType DestructorName
When Kind == IK_DestructorName, the type referred to by the class-name.
This is a scope that corresponds to a block/closure object.
ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr)
ActOnCXXThrow - Parse throw expressions.
Represents a C++ unqualified-id that has been parsed.
static ParsedType getTypeAnnotation(const Token &Tok)
getTypeAnnotation - Read a parsed type out of an annotation token.
< Capturing the *this object by copy
void ActOnInitializerError(Decl *Dcl)
ActOnInitializerError - Given that there was an error parsing an initializer for the given declaratio...
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, llvm::function_ref< ExprResult(Expr *)> Filter=[](Expr *E) -> ExprResult { return E;})
Process any TypoExprs in the given Expr and its children, generating diagnostics as appropriate and r...
SourceRange getRange() const
QualType ProduceConstructorSignatureHelp(Scope *S, QualType Type, SourceLocation Loc, ArrayRef< Expr *> Args, SourceLocation OpenParLoc)
void enterCondition(Sema &S, SourceLocation Tok)
const clang::PrintingPolicy & getPrintingPolicy() const
SourceRange getAnnotationRange() const
SourceRange of the group of tokens that this annotation token represents.
ParsedTemplateArgument * getTemplateArgs()
Retrieves a pointer to the template arguments.
If a crash happens while one of these objects are live, the message is printed out along with the spe...
void SetInvalid(SourceRange R)
Indicate that this nested-name-specifier is invalid.
ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, UnqualifiedId &Id, bool HasTrailingLParen, bool IsAddressOfOperand, CorrectionCandidateCallback *CCC=nullptr, bool IsInlineAsmIdentifier=false, Token *KeywordReplacement=nullptr)
ExprResult ActOnCXXThis(SourceLocation loc)
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...
Represents a C++ nested-name-specifier or a global scope specifier.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID. ...
ArrayTypeTrait
Names for the array type traits.
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type...
void setTemplateId(TemplateIdAnnotation *TemplateId)
Specify that this unqualified-id was parsed as a template-id.
SourceRange getSourceRange() const LLVM_READONLY
const char * getName() const
bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS, NestedNameSpecInfo &IdInfo)
SourceLocation TemplateKWLoc
TemplateKWLoc - The location of the template keyword.
static const TST TST_float
TypeTrait
Names for traits that operate specifically on types.
SourceLocation LAngleLoc
The location of the '<' before the template argument list.
DeclSpec & getMutableDeclSpec()
getMutableDeclSpec - Return a non-const version of the DeclSpec.
static const TSW TSW_long
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(), DeclSpec *MethodQualifiers=nullptr)
DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, SourceLocation EndLoc)
void SetRangeStart(SourceLocation Loc)
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.
SourceRange getRange() const
TST getTypeSpecType() const
ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body, Scope *CurScope)
ActOnLambdaExpr - This is called when the body of a lambda expression was successfully completed...
This represents one expression.
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.
bool ActOnCXXGlobalScopeSpecifier(SourceLocation CCLoc, CXXScopeSpec &SS)
The parser has parsed a global nested-name-specifier '::'.
void setDeductionGuideName(ParsedTemplateTy Template, SourceLocation TemplateLoc)
Specify that this unqualified-id was parsed as a template-name for a deduction-guide.
void AnnotateCachedTokens(const Token &Tok)
We notify the Preprocessor that if it is caching tokens (because backtrack is enabled) it should repl...
ParsedType getDestructorTypeForDecltype(const DeclSpec &DS, ParsedType ObjectType)
bool hasLeadingEmptyMacro() const
Return true if this token has an empty macro before it.
This file defines the classes used to store parsed information about declaration-specifiers and decla...
bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, ParsedType ObjectType, SourceLocation *TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
TypeResult ActOnTypeName(Scope *S, Declarator &D)
OpaquePtr< T > get() const
void setEofData(const void *D)
void RevertCachedTokens(unsigned N)
When backtracking is enabled and tokens are cached, this allows to revert a specific number of tokens...
ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, CXXScopeSpec &SS, UnqualifiedId &FirstTypeName, SourceLocation CCLoc, SourceLocation TildeLoc, UnqualifiedId &SecondTypeName)
const Token & getCurToken() const
OpaquePtr< TemplateName > TemplateTy
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
void setAsmLabel(Expr *E)
SourceLocation getBeginLoc() const
Represents a C++ template name within the type system.
This is a compound statement scope.
UnqualifiedIdKind getKind() const
Determine what kind of name we have.
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7)...
TemplateNameKind
Specifies the kind of template name that an identifier refers to.
ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc, ArrayRef< ParsedType > Args, SourceLocation RParenLoc)
Parsed one of the type trait support pseudo-functions.
void setLiteralOperatorId(const IdentifierInfo *Id, SourceLocation OpLoc, SourceLocation IdLoc)
Specific that this unqualified-id was parsed as a literal-operator-id.
StmtResult ActOnNullStmt(SourceLocation SemiLoc, bool HasLeadingEmptyMacro=false)
SourceLocation getEnd() const
bool SetTypeSpecSign(TSS S, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
SourceLocation getOpenLocation() const
static const TST TST_half
ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, bool ArrayForm, Expr *Operand)
ActOnCXXDelete - Parsed a C++ 'delete' expression.
sema::LambdaScopeInfo * PushLambdaScope()
The result type of a method or function.
static const TSW TSW_short
StringRef GetString() const
ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, SourceLocation EllipsisLoc)
Invoked when parsing a template argument followed by an ellipsis, which creates a pack expansion...
bool isValid() const
Determine whether this unqualified-id refers to a valid name.
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
SourceLocation getEndLoc() const LLVM_READONLY
const LangOptions & getLangOpts() const
bool SetTypeSpecWidth(TSW 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 ...
This is a scope that corresponds to the parameters within a function prototype for a function declara...
ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E)
SourceManager & getSourceManager() const
static const TST TST_char32
unsigned getUDSuffixOffset() const
Get the spelling offset of the first byte of the ud-suffix.
SourceLocation DefaultLoc
Stop skipping at semicolon.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
unsigned getUDSuffixToken() const
Get the index of a token containing a ud-suffix.
ASTContext & getASTContext() const
static const TST TST_float16
Encodes a location in the source.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
void setLength(unsigned Len)
static void addConstexprToLambdaDeclSpecifier(Parser &P, SourceLocation ConstexprLoc, DeclSpec &DS)
void FinalizeDeclaration(Decl *D)
FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform any semantic actions neces...
MutableArrayRef< Expr * > MultiExprArg
bool isDeductionGuideName(Scope *S, const IdentifierInfo &Name, SourceLocation NameLoc, ParsedTemplateTy *Template=nullptr)
Determine whether a particular identifier might be the name in a C++1z deduction-guide declaration...
SourceLocation getEndLoc() const LLVM_READONLY
IdentifierInfo * getIdentifierInfo() const
void setAnnotationEndLoc(SourceLocation L)
IdentifierTable & getIdentifierTable()
ParsedAttr - Represents a syntactic attribute.
static const TSS TSS_signed
ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, SourceLocation LAngleBracketLoc, Declarator &D, SourceLocation RAngleBracketLoc, SourceLocation LParenLoc, Expr *E, SourceLocation RParenLoc)
ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
void CodeCompleteOperatorName(Scope *S)
void Lex(Token &Result)
Lex the next token for this preprocessor.
ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep, SourceLocation LParenOrBraceLoc, MultiExprArg Exprs, SourceLocation RParenOrBraceLoc, bool ListInitialization)
ActOnCXXTypeConstructExpr - Parse construction of a specified type.
const void * getEofData() const
TemplateNameKind ActOnDependentTemplateName(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const UnqualifiedId &Name, ParsedType ObjectType, bool EnteringContext, TemplateTy &Template, bool AllowInjectedClassName=false)
Form a dependent template name.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
Scope * getCurScope() const
static DeclaratorChunk getArray(unsigned TypeQuals, bool isStatic, bool isStar, Expr *NumElts, SourceLocation LBLoc, SourceLocation RBLoc)
Return a DeclaratorChunk for an array.
ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, SourceRange TypeIdParens, Declarator &D, Expr *Initializer)
ActOnCXXNew - Parsed a C++ 'new' expression.
static void FixDigraph(Parser &P, Preprocessor &PP, Token &DigraphToken, Token &ColonToken, tok::TokenKind Kind, bool AtDigraph)
TypeResult ActOnTemplateIdType(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, TemplateTy Template, IdentifierInfo *TemplateII, SourceLocation TemplateIILoc, SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc, bool IsCtorOrDtorName=false, bool IsClassName=false)
StringRef getName() const
Return the actual identifier string.
SourceRange getSourceRange() const LLVM_READONLY
Get the source range that spans this declarator.
bool isNot(tok::TokenKind K) const
static const TST TST_decltype_auto
The name does not refer to a template.
Dataflow Directional Tag Classes.
void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope, bool IsInstantiation=false)
ActOnLambdaError - If there is an error parsing a lambda, this callback is invoked to pop the informa...
bool isValid() const
Return true if this is a valid SourceLocation object.
LambdaCaptureDefault Default
bool expectAndConsume(unsigned DiagID=diag::err_expected, const char *Msg="", tok::TokenKind SkipToTok=tok::unknown)
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
static const TST TST_void
CXXScopeSpec SS
The nested-name-specifier that precedes the template name.
SourceLocation RAngleLoc
The location of the '>' after the template argument list.
static const TST TST_int128
void RecordParsingTemplateParameterDepth(unsigned Depth)
This is used to inform Sema what the current TemplateParameterDepth is during Parsing.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool EnteringContext, QualType BaseType, QualType PreferredType)
This is a scope that corresponds to the template parameters of a C++ template.
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
SourceLocation getLastCachedTokenLocation() const
Get the location of the last cached token, suitable for setting the end location of an annotation tok...
bool ActOnSuperScopeSpecifier(SourceLocation SuperLoc, SourceLocation ColonColonLoc, CXXScopeSpec &SS)
The parser has parsed a '__super' nested-name-specifier.
unsigned getLength() const
void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit)
AddInitializerToDecl - Adds the initializer Init to the declaration dcl.
void ActOnLambdaExplicitTemplateParameterList(SourceLocation LAngleLoc, ArrayRef< NamedDecl *> TParams, SourceLocation RAngleLoc)
This is called after parsing the explicit template parameter list on a lambda (if it exists) in C++2a...
bool isCurrentClassName(const IdentifierInfo &II, Scope *S, const CXXScopeSpec *SS=nullptr)
isCurrentClassName - Determine whether the identifier II is the name of the class type currently bein...
ParsedType getConstructorName(IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec &SS, bool EnteringContext)
Not an overloaded operator.
void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, Declarator &ParamInfo, Scope *CurScope)
ActOnStartOfLambdaDefinition - This is called just before we start parsing the body of a lambda; it a...
QualType getCanonicalTypeInternal() const
void takeAttributesFrom(ParsedAttributes &attrs)
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
void RestoreNestedNameSpecifierAnnotation(void *Annotation, SourceRange AnnotationRange, CXXScopeSpec &SS)
Given an annotation pointer for a nested-name-specifier, restore the nested-name-specifier structure...
const char * getOperatorSpelling(OverloadedOperatorKind Operator)
Retrieve the spelling of the given overloaded operator, without the preceding "operator" keyword...
ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind)
ActOnCXXBoolLiteral - Parse {true,false} literals.
void setOperatorFunctionId(SourceLocation OperatorLoc, OverloadedOperatorKind Op, SourceLocation SymbolLocations[3])
Specify that this unqualified-id was parsed as an operator-function-id.
static const TST TST_typename
void SetRangeEnd(SourceLocation Loc)
SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.
ExprResult ParseAssignmentExpression(TypeCastState isTypeCast=NotTypeCast)
Parse an expr that doesn't include (top-level) commas.
ExprResult ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation LParenLoc, bool isType, void *TyOrExpr, SourceLocation RParenLoc)
ActOnCXXTypeid - Parse typeid( something ).
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
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.
void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc)
AddTypeInfo - Add a chunk to this declarator.
ExprResult ActOnCoyieldExpr(Scope *S, SourceLocation KwLoc, Expr *E)
Capturing the *this object by reference.
This is a scope that can contain a declaration.
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
bool isSet() const
Deprecated.
ExprResult ParseConstantExpression(TypeCastState isTypeCast=NotTypeCast)
void setInvalidType(bool Val=true)
An integral condition for a 'switch' statement.
Captures information about "declaration specifiers".
ActionResult< Expr * > ExprResult
void setEnd(SourceLocation e)
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
static ExpressionTrait ExpressionTraitFromTokKind(tok::TokenKind kind)
static int SelectDigraphErrorMessage(tok::TokenKind Kind)
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
static const TST TST_float128
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
static const TST TST_bool
StringLiteralParser - This decodes string escape characters and performs wide string analysis and Tra...
unsigned kind
All of the diagnostics that can be emitted by the frontend.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
SourceManager & getSourceManager() const
void Finish(Sema &S, const PrintingPolicy &Policy)
Finish - This does final analysis of the declspec, issuing diagnostics for things like "_Imaginary" (...
Represents a complete lambda introducer.
static const TSW TSW_longlong
void enterTypeCast(SourceLocation Tok, QualType CastType)
Handles all type casts, including C-style cast, C++ casts, etc.
Code completion occurs within the condition of an if, while, switch, or for statement.
static unsigned TypeTraitArity(tok::TokenKind kind)
static void addConstevalToLambdaDeclSpecifier(Parser &P, SourceLocation ConstevalLoc, DeclSpec &DS)
void setLocation(SourceLocation L)
A trivial tuple used to represent a source range.
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
unsigned NumArgs
NumArgs - The number of template arguments.
void * getAnnotationValue() const
void setDestructorName(SourceLocation TildeLoc, ParsedType ClassType, SourceLocation EndLoc)
Specify that this unqualified-id was parsed as a destructor name.
void SetRangeEnd(SourceLocation Loc)
SourceLocation getBegin() const
ParsedAttributes - A collection of parsed attributes.
This class handles loading and caching of source files into memory.
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeNameContext, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName type-name: [C99 6.7.6] specifier-qualifier-list abstract-declarator[opt].
static ArrayTypeTrait ArrayTypeTraitFromTokKind(tok::TokenKind kind)
Attr - This represents one attribute.
SourceLocation getLocation() const
void startToken()
Reset all flags to cleared.
ParsedTemplateTy Template
The declaration of the template corresponding to the template-name.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Stop skipping at specified token, but don't skip the token itself.