32#include "llvm/ADT/SmallVector.h"
126 return ParseRHSOfBinaryExpression(LHS,
prec::Comma);
137 return ParseRHSOfBinaryExpression(LHS,
prec::Comma);
144Parser::ParseExpressionWithLeadingExtension(
SourceLocation ExtLoc) {
150 LHS = ParseCastExpression(AnyCastExpr);
153 if (!LHS.isInvalid())
157 return ParseRHSOfBinaryExpression(LHS,
prec::Comma);
162 if (Tok.
is(tok::code_completion)) {
169 if (Tok.
is(tok::kw_throw))
170 return ParseThrowExpression();
171 if (Tok.
is(tok::kw_co_yield))
172 return ParseCoyieldExpression();
174 ExprResult LHS = ParseCastExpression(AnyCastExpr,
190Parser::ParseAssignmentExprWithObjCMessageExprStart(
SourceLocation LBracLoc,
193 Expr *ReceiverExpr) {
195 = ParseObjCMessageExpressionBody(LBracLoc, SuperLoc,
196 ReceiverType, ReceiverExpr);
197 R = ParsePostfixExpressionSuffix(R);
205 "Call this function only if your ExpressionEvaluationContext is "
206 "already ConstantEvaluated");
207 ExprResult LHS(ParseCastExpression(AnyCastExpr,
false, isTypeCast));
239 ExprResult LHS(ParseCastExpression(AnyCastExpr));
261 bool NotPrimaryExpression =
false;
262 auto ParsePrimary = [&] () {
263 ExprResult E = ParseCastExpression(PrimaryExprOnly,
267 &NotPrimaryExpression);
271 E = ParsePostfixExpressionSuffix(E);
278 ? diag::note_unparenthesized_non_primary_expr_in_requires_clause
279 : diag::err_unparenthesized_non_primary_expr_in_requires_clause)
287 if (NotPrimaryExpression ||
294 Tok.
isOneOf(tok::period, tok::plusplus, tok::minusminus) ||
295 (Tok.
is(tok::l_square) && !
NextToken().is(tok::l_square))) {
296 E = RecoverFromNonPrimary(E,
false);
299 NotPrimaryExpression =
false;
301 bool PossibleNonPrimary;
302 bool IsConstraintExpr =
304 IsTrailingRequiresClause);
305 if (!IsConstraintExpr || PossibleNonPrimary) {
310 if (PossibleNonPrimary)
311 E = RecoverFromNonPrimary(E, !IsConstraintExpr);
320 while (Tok.
is(tok::ampamp)) {
328 tok::ampamp, LHS.
get(), RHS.
get());
354 while (Tok.
is(tok::pipepipe)) {
363 tok::pipepipe, LHS.
get(), RHS.
get());
374bool Parser::isNotExpressionStart() {
376 if (K == tok::l_brace || K == tok::r_brace ||
377 K == tok::kw_for || K == tok::kw_while ||
378 K == tok::kw_if || K == tok::kw_else ||
379 K == tok::kw_goto || K == tok::kw_try)
382 return isKnownToBeDeclarationSpecifier();
385bool Parser::isFoldOperator(
prec::Level Level)
const {
399 GreaterThanIsOperator,
403 auto SavedType = PreferredType;
406 PreferredType = SavedType;
410 if (NextTokPrec < MinPrec)
417 if (OpToken.
is(tok::caretcaret)) {
418 return ExprError(
Diag(Tok, diag::err_opencl_logical_exclusive_or));
423 if (OpToken.
isOneOf(tok::comma, tok::greater, tok::greatergreater,
424 tok::greatergreatergreater) &&
425 checkPotentialAngleBracketDelimiter(OpToken))
433 if (OpToken.
is(tok::comma) && isNotExpressionStart()) {
441 if (isFoldOperator(NextTokPrec) && Tok.
is(tok::ellipsis)) {
455 Tok.
isOneOf(tok::colon, tok::r_square) &&
468 TernaryMiddle = ParseBraceInitializer();
469 if (!TernaryMiddle.isInvalid()) {
470 Diag(BraceLoc, diag::err_init_list_bin_op)
475 }
else if (Tok.
isNot(tok::colon)) {
487 TernaryMiddle =
nullptr;
488 Diag(Tok, diag::ext_gnu_conditional_expr);
491 if (TernaryMiddle.isInvalid()) {
494 TernaryMiddle =
nullptr;
503 const char *FIText =
": ";
507 bool IsInvalid =
false;
508 const char *SourcePtr =
510 if (!IsInvalid && *SourcePtr ==
' ') {
513 if (!IsInvalid && *SourcePtr ==
' ') {
520 Diag(Tok, diag::err_expected)
522 Diag(OpToken, diag::note_matching) << tok::question;
540 bool RHSIsInitList =
false;
542 RHS = ParseBraceInitializer();
543 RHSIsInitList =
true;
547 RHS = ParseCastExpression(AnyCastExpr);
553 if (TernaryMiddle.isUsable())
570 if (ThisPrec < NextTokPrec ||
571 (ThisPrec == NextTokPrec && isRightAssoc)) {
573 Diag(Tok, diag::err_init_list_bin_op)
582 RHS = ParseRHSOfBinaryExpression(RHS,
583 static_cast<prec::Level>(ThisPrec + !isRightAssoc));
584 RHSIsInitList =
false;
590 if (TernaryMiddle.isUsable())
601 Diag(OpToken, diag::warn_cxx98_compat_generalized_initializer_lists)
603 }
else if (ColonLoc.
isValid()) {
604 Diag(ColonLoc, diag::err_init_list_bin_op)
609 Diag(OpToken, diag::err_init_list_bin_op)
619 if (TernaryMiddle.isInvalid()) {
623 if (!GreaterThanIsOperator && OpToken.
is(tok::greatergreater))
625 diag::warn_cxx11_right_shift_in_template_arg,
635 {LHS.get(), RHS.get()});
643 std::vector<clang::Expr *> Args;
645 if (TernaryMiddle.get())
646 Args = {LHS.
get(), TernaryMiddle.get(), RHS.
get()};
648 Args = {LHS.
get(), RHS.
get()};
676ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
677 bool isAddressOfOperand,
678 TypeCastState isTypeCast,
679 bool isVectorLiteral,
680 bool *NotPrimaryExpression) {
682 ExprResult Res = ParseCastExpression(ParseKind,
687 NotPrimaryExpression);
689 Diag(Tok, diag::err_expected_expression);
696 CastExpressionIdValidator(
Token Next,
bool AllowTypes,
bool AllowNonTypes)
697 : NextToken(Next), AllowNonTypes(AllowNonTypes) {
698 WantTypeSpecifiers = WantFunctionLikeCasts = AllowTypes;
701 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
706 if (isa<TypeDecl>(ND))
707 return WantTypeSpecifiers;
712 if (!NextToken.isOneOf(tok::equal, tok::arrow, tok::period))
715 for (
auto *
C : candidate) {
717 if (isa<ValueDecl>(ND) && !isa<FunctionDecl>(ND))
723 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
724 return std::make_unique<CastExpressionIdValidator>(*
this);
915ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
916 bool isAddressOfOperand,
918 TypeCastState isTypeCast,
919 bool isVectorLiteral,
920 bool *NotPrimaryExpression) {
923 auto SavedType = PreferredType;
929 bool AllowSuffix =
true;
945 ParenParseOption ParenExprType;
947 case CastParseKind::UnaryExprOnly:
950 case CastParseKind::AnyCastExpr:
951 ParenExprType = ParenParseOption::CastExpr;
953 case CastParseKind::PrimaryExprOnly:
954 ParenExprType = FoldExpr;
959 Res = ParseParenExpression(ParenExprType,
false,
968 switch (ParenExprType) {
969 case SimpleExpr:
break;
971 case CompoundLiteral:
989 case tok::numeric_constant:
999 Res = ParseCXXBoolLiteral();
1002 case tok::kw___objc_yes:
1003 case tok::kw___objc_no:
1004 Res = ParseObjCBoolLiteral();
1007 case tok::kw_nullptr:
1009 Diag(Tok, diag::warn_cxx98_compat_nullptr);
1012 : diag::ext_c_nullptr) << Tok.
getName();
1017 case tok::annot_primary_expr:
1018 case tok::annot_overload_set:
1019 Res = getExprAnnotation(Tok);
1022 ConsumeAnnotationToken();
1024 checkPotentialAngleBracket(Res);
1027 case tok::annot_non_type:
1028 case tok::annot_non_type_dependent:
1029 case tok::annot_non_type_undeclared: {
1032 Res = tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement);
1034 "should not perform typo correction on annotation token");
1038 case tok::kw___super:
1039 case tok::kw_decltype:
1043 assert(Tok.
isNot(tok::kw_decltype) && Tok.
isNot(tok::kw___super));
1044 return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast,
1045 isVectorLiteral, NotPrimaryExpression);
1047 case tok::identifier:
1061 if (Next.is(tok::l_paren) &&
1062 Tok.
is(tok::identifier) &&
1066 if (RevertibleTypeTraits.empty()) {
1067#define RTT_JOIN(X,Y) X##Y
1068#define REVERTIBLE_TYPE_TRAIT(Name) \
1069 RevertibleTypeTraits[PP.getIdentifierInfo(#Name)] \
1070 = RTT_JOIN(tok::kw_,Name)
1128#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) \
1129 REVERTIBLE_TYPE_TRAIT(RTT_JOIN(__, Trait));
1130#include "clang/Basic/TransformTypeTraits.def"
1131#undef REVERTIBLE_TYPE_TRAIT
1138 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind>::iterator Known
1139 = RevertibleTypeTraits.find(II);
1140 if (Known != RevertibleTypeTraits.end()) {
1142 return ParseCastExpression(ParseKind, isAddressOfOperand,
1143 NotCastExpr, isTypeCast,
1144 isVectorLiteral, NotPrimaryExpression);
1148 if ((!ColonIsSacred && Next.is(tok::colon)) ||
1149 Next.isOneOf(tok::coloncolon, tok::less, tok::l_paren,
1154 if (!Tok.
is(tok::identifier))
1155 return ParseCastExpression(ParseKind, isAddressOfOperand,
1156 NotCastExpr, isTypeCast,
1158 NotPrimaryExpression);
1171 (&II == Ident_super &&
getCurScope()->isInObjcMethodScope()))) {
1174 if (Tok.
is(tok::code_completion) && &II != Ident_super) {
1177 getCurScope(), II, ILoc, ExprStatementTokLoc == ILoc);
1181 if (Tok.
isNot(tok::identifier) &&
1183 Diag(Tok, diag::err_expected_property_name);
1198 if (
getLangOpts().
ObjC && &II == Ident_super && !InMessageExpression &&
1200 ((Tok.
is(tok::identifier) &&
1202 Tok.
is(tok::code_completion))) {
1203 Res = ParseObjCMessageExpressionBody(
SourceLocation(), ILoc,
nullptr,
1214 ((Tok.
is(tok::identifier) && !InMessageExpression) ||
1215 Tok.
is(tok::code_completion))) {
1217 if (Tok.
is(tok::code_completion) ||
1218 Next.is(tok::colon) || Next.is(tok::r_square))
1220 if (Typ.get()->isObjCObjectOrInterfaceType()) {
1223 DS.SetRangeStart(ILoc);
1224 DS.SetRangeEnd(ILoc);
1225 const char *PrevSpec =
nullptr;
1227 DS.SetTypeSpecType(
TST_typename, ILoc, PrevSpec, DiagID, Typ,
1245 if (isAddressOfOperand && isPostfixExpressionSuffixStart())
1246 isAddressOfOperand =
false;
1255 CastExpressionIdValidator Validator(
1259 Validator.IsAddressOfOperand = isAddressOfOperand;
1260 if (Tok.
isOneOf(tok::periodstar, tok::arrowstar)) {
1261 Validator.WantExpressionKeywords =
false;
1262 Validator.WantRemainingKeywords =
false;
1264 Validator.WantRemainingKeywords = Tok.
isNot(tok::r_paren);
1266 Name.setIdentifier(&II, ILoc);
1268 getCurScope(), ScopeSpec, TemplateKWLoc, Name, Tok.
is(tok::l_paren),
1269 isAddressOfOperand, &Validator,
1271 Tok.
is(tok::r_paren) ?
nullptr : &Replacement);
1273 UnconsumeToken(Replacement);
1274 return ParseCastExpression(ParseKind, isAddressOfOperand,
1275 NotCastExpr, isTypeCast,
1277 NotPrimaryExpression);
1280 checkPotentialAngleBracket(Res);
1283 case tok::char_constant:
1284 case tok::wide_char_constant:
1285 case tok::utf8_char_constant:
1286 case tok::utf16_char_constant:
1287 case tok::utf32_char_constant:
1291 case tok::kw___func__:
1292 case tok::kw___FUNCTION__:
1293 case tok::kw___FUNCDNAME__:
1294 case tok::kw___FUNCSIG__:
1295 case tok::kw_L__FUNCTION__:
1296 case tok::kw_L__FUNCSIG__:
1297 case tok::kw___PRETTY_FUNCTION__:
1301 case tok::string_literal:
1302 case tok::wide_string_literal:
1303 case tok::utf8_string_literal:
1304 case tok::utf16_string_literal:
1305 case tok::utf32_string_literal:
1308 case tok::kw__Generic:
1309 Res = ParseGenericSelectionExpression();
1311 case tok::kw___builtin_available:
1312 Res = ParseAvailabilityCheckExpr(Tok.
getLocation());
1314 case tok::kw___builtin_va_arg:
1315 case tok::kw___builtin_offsetof:
1316 case tok::kw___builtin_choose_expr:
1317 case tok::kw___builtin_astype:
1318 case tok::kw___builtin_convertvector:
1319 case tok::kw___builtin_COLUMN:
1320 case tok::kw___builtin_FILE:
1321 case tok::kw___builtin_FILE_NAME:
1322 case tok::kw___builtin_FUNCTION:
1323 case tok::kw___builtin_LINE:
1324 case tok::kw___builtin_source_location:
1325 if (NotPrimaryExpression)
1326 *NotPrimaryExpression =
true;
1328 return ParseBuiltinPrimaryExpression();
1329 case tok::kw___null:
1334 case tok::minusminus: {
1335 if (NotPrimaryExpression)
1336 *NotPrimaryExpression =
true;
1341 Token SavedTok = Tok;
1350 UnaryExprOnly : AnyCastExpr,
1357 UnconsumeToken(SavedTok);
1371 if (NotPrimaryExpression)
1372 *NotPrimaryExpression =
true;
1377 Res = ParseCastExpression(AnyCastExpr,
true);
1393 case tok::kw___real:
1394 case tok::kw___imag: {
1395 if (NotPrimaryExpression)
1396 *NotPrimaryExpression =
true;
1399 Res = ParseCastExpression(AnyCastExpr);
1403 isAddressOfOperand);
1410 case tok::kw_co_await: {
1411 if (NotPrimaryExpression)
1412 *NotPrimaryExpression =
true;
1414 Res = ParseCastExpression(AnyCastExpr);
1420 case tok::kw___extension__:{
1422 if (NotPrimaryExpression)
1423 *NotPrimaryExpression =
true;
1426 Res = ParseCastExpression(AnyCastExpr);
1431 case tok::kw__Alignof:
1433 Diag(Tok, diag::ext_c11_feature) << Tok.
getName();
1435 case tok::kw_alignof:
1436 case tok::kw___alignof:
1438 case tok::kw_sizeof:
1440 case tok::kw_vec_step:
1442 case tok::kw___builtin_omp_required_simd_align:
1443 if (NotPrimaryExpression)
1444 *NotPrimaryExpression =
true;
1445 AllowSuffix =
false;
1446 Res = ParseUnaryExprOrTypeTraitExpression();
1449 if (NotPrimaryExpression)
1450 *NotPrimaryExpression =
true;
1452 if (Tok.
isNot(tok::identifier))
1453 return ExprError(
Diag(Tok, diag::err_expected) << tok::identifier);
1456 return ExprError(
Diag(Tok, diag::err_address_of_label_outside_fn));
1458 Diag(AmpAmpLoc, diag::ext_gnu_address_of_label);
1463 AllowSuffix =
false;
1466 case tok::kw_const_cast:
1467 case tok::kw_dynamic_cast:
1468 case tok::kw_reinterpret_cast:
1469 case tok::kw_static_cast:
1470 case tok::kw_addrspace_cast:
1471 if (NotPrimaryExpression)
1472 *NotPrimaryExpression =
true;
1473 Res = ParseCXXCasts();
1475 case tok::kw___builtin_bit_cast:
1476 if (NotPrimaryExpression)
1477 *NotPrimaryExpression =
true;
1478 Res = ParseBuiltinBitCast();
1480 case tok::kw_typeid:
1481 if (NotPrimaryExpression)
1482 *NotPrimaryExpression =
true;
1483 Res = ParseCXXTypeid();
1485 case tok::kw___uuidof:
1486 if (NotPrimaryExpression)
1487 *NotPrimaryExpression =
true;
1488 Res = ParseCXXUuidof();
1491 Res = ParseCXXThis();
1493 case tok::kw___builtin_sycl_unique_stable_name:
1494 Res = ParseSYCLUniqueStableNameExpression();
1497 case tok::annot_typename:
1498 if (isStartOfObjCClassMessageMissingOpenBracket()) {
1506 const char *PrevSpec =
nullptr;
1509 PrevSpec, DiagID,
Type,
1518 ConsumeAnnotationToken();
1525 case tok::annot_decltype:
1527 case tok::kw_wchar_t:
1528 case tok::kw_char8_t:
1529 case tok::kw_char16_t:
1530 case tok::kw_char32_t:
1535 case tok::kw___int64:
1536 case tok::kw___int128:
1537 case tok::kw__ExtInt:
1538 case tok::kw__BitInt:
1539 case tok::kw_signed:
1540 case tok::kw_unsigned:
1543 case tok::kw_double:
1544 case tok::kw___bf16:
1545 case tok::kw__Float16:
1546 case tok::kw___float128:
1547 case tok::kw___ibm128:
1550 case tok::kw_typename:
1551 case tok::kw_typeof:
1552 case tok::kw___vector:
1553#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
1554#include "clang/Basic/OpenCLImageTypes.def"
1557 Diag(Tok, diag::err_expected_expression);
1562 if (NotPrimaryExpression)
1563 *NotPrimaryExpression =
true;
1565 if (SavedKind == tok::kw_typename) {
1582 ParseCXXSimpleTypeSpecifier(DS);
1583 if (Tok.
isNot(tok::l_paren) &&
1585 return ExprError(
Diag(Tok, diag::err_expected_lparen_after_type)
1586 << DS.getSourceRange());
1588 if (Tok.
is(tok::l_brace))
1589 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
1591 Res = ParseCXXTypeConstructExpression(DS);
1595 case tok::annot_cxxscope: {
1600 if (!Tok.
is(tok::annot_cxxscope))
1601 return ParseCastExpression(ParseKind, isAddressOfOperand, NotCastExpr,
1602 isTypeCast, isVectorLiteral,
1603 NotPrimaryExpression);
1606 if (Next.is(tok::annot_template_id)) {
1613 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
1617 return ParseCastExpression(ParseKind, isAddressOfOperand, NotCastExpr,
1618 isTypeCast, isVectorLiteral,
1619 NotPrimaryExpression);
1624 Res = ParseCXXIdExpression(isAddressOfOperand);
1628 case tok::annot_template_id: {
1636 return ParseCastExpression(ParseKind, isAddressOfOperand,
1637 NotCastExpr, isTypeCast, isVectorLiteral,
1638 NotPrimaryExpression);
1645 case tok::kw_operator:
1646 Res = ParseCXXIdExpression(isAddressOfOperand);
1649 case tok::coloncolon: {
1654 if (!Tok.
is(tok::coloncolon))
1655 return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast,
1656 isVectorLiteral, NotPrimaryExpression);
1661 if (Tok.
is(tok::kw_new)) {
1662 if (NotPrimaryExpression)
1663 *NotPrimaryExpression =
true;
1664 Res = ParseCXXNewExpression(
true, CCLoc);
1665 AllowSuffix =
false;
1668 if (Tok.
is(tok::kw_delete)) {
1669 if (NotPrimaryExpression)
1670 *NotPrimaryExpression =
true;
1671 Res = ParseCXXDeleteExpression(
true, CCLoc);
1672 AllowSuffix =
false;
1677 Diag(CCLoc, diag::err_expected_expression);
1682 if (NotPrimaryExpression)
1683 *NotPrimaryExpression =
true;
1684 Res = ParseCXXNewExpression(
false, Tok.
getLocation());
1685 AllowSuffix =
false;
1688 case tok::kw_delete:
1689 if (NotPrimaryExpression)
1690 *NotPrimaryExpression =
true;
1691 Res = ParseCXXDeleteExpression(
false, Tok.
getLocation());
1692 AllowSuffix =
false;
1695 case tok::kw_requires:
1696 Res = ParseRequiresExpression();
1697 AllowSuffix =
false;
1700 case tok::kw_noexcept: {
1701 if (NotPrimaryExpression)
1702 *NotPrimaryExpression =
true;
1703 Diag(Tok, diag::warn_cxx98_compat_noexcept_expr);
1707 if (T.expectAndConsume(diag::err_expected_lparen_after,
"noexcept"))
1720 T.getCloseLocation());
1721 AllowSuffix =
false;
1725#define TYPE_TRAIT(N,Spelling,K) \
1726 case tok::kw_##Spelling:
1727#include "clang/Basic/TokenKinds.def"
1728 Res = ParseTypeTrait();
1731 case tok::kw___array_rank:
1732 case tok::kw___array_extent:
1733 if (NotPrimaryExpression)
1734 *NotPrimaryExpression =
true;
1735 Res = ParseArrayTypeTrait();
1738 case tok::kw___is_lvalue_expr:
1739 case tok::kw___is_rvalue_expr:
1740 if (NotPrimaryExpression)
1741 *NotPrimaryExpression =
true;
1742 Res = ParseExpressionTrait();
1746 if (NotPrimaryExpression)
1747 *NotPrimaryExpression =
true;
1749 return ParseObjCAtExpression(AtLoc);
1752 Res = ParseBlockLiteralExpression();
1754 case tok::code_completion: {
1760#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
1761#include "clang/Basic/TransformTypeTraits.def"
1766 Diag(Tok, diag::ext_keyword_as_ident)
1768 goto ParseIdentifier;
1770 goto ExpectedExpression;
1779 Res = TryParseLambdaExpression();
1783 if (NotPrimaryExpression)
1784 *NotPrimaryExpression =
true;
1785 Res = ParseObjCMessageExpression();
1789 Res = ParseLambdaExpression();
1793 Res = ParseObjCMessageExpression();
1807 if (ParseKind == PrimaryExprOnly)
1822 case tok::minusminus:
1840 Diag(Tok.
getLocation(), diag::err_postfix_after_unary_requires_parens)
1848 PreferredType = SavedType;
1849 Res = ParsePostfixExpressionSuffix(Res);
1851 !
getActions().getOpenCLOptions().isAvailableOption(
1853 if (
Expr *PostfixExpr = Res.
get()) {
1854 QualType Ty = PostfixExpr->getType();
1856 Diag(PostfixExpr->getExprLoc(),
1857 diag::err_opencl_taking_function_address_parser);
1887Parser::ParsePostfixExpressionSuffix(
ExprResult LHS) {
1891 auto SavedType = PreferredType;
1894 PreferredType = SavedType;
1896 case tok::code_completion:
1897 if (InMessageExpression)
1905 case tok::identifier:
1912 nullptr, LHS.
get());
1920 case tok::l_square: {
1928 isSimpleObjCMessageExpression())
1933 if (CheckProhibitedCXX11Attribute()) {
1939 Loc = T.getOpenLocation();
1942 ExprVector ArgExprs;
1943 bool HasError =
false;
1954 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
1955 Idx = ParseBraceInitializer();
1964 ArgExprs.push_back(Idx.
get());
1966 }
else if (Tok.
isNot(tok::r_square)) {
1967 if (ParseExpressionList(ArgExprs)) {
1974 if (ArgExprs.size() <= 1 &&
getLangOpts().OpenMP) {
1976 if (Tok.
is(tok::colon)) {
1979 if (Tok.
isNot(tok::r_square) &&
1987 (OMPClauseKind == llvm::omp::Clause::OMPC_to ||
1988 OMPClauseKind == llvm::omp::Clause::OMPC_from) &&
1989 Tok.
is(tok::colon)) {
1992 if (Tok.
isNot(tok::r_square)) {
2005 LHS.
get(), Loc, ArgExprs.empty() ?
nullptr : ArgExprs[0],
2006 ColonLocFirst, ColonLocSecond, Length.
get(), Stride.
get(), RLoc);
2021 case tok::lesslessless: {
2026 Expr *ExecConfig =
nullptr;
2030 if (OpKind == tok::lesslessless) {
2031 ExprVector ExecConfigExprs;
2034 if (ParseSimpleExpressionList(ExecConfigExprs)) {
2045 Diag(Tok, diag::err_expected) << tok::greatergreatergreater;
2046 Diag(OpenLoc, diag::note_matching) << tok::lesslessless;
2052 if (ExpectAndConsume(tok::l_paren))
2055 Loc = PrevTokLocation;
2066 ExecConfig = ECResult.
get();
2070 Loc = PT.getOpenLocation();
2073 ExprVector ArgExprs;
2074 auto RunSignatureHelp = [&]() ->
QualType {
2076 LHS.
get(), ArgExprs, PT.getOpenLocation());
2077 CalledSignatureHelp =
true;
2078 return PreferredType;
2080 if (OpKind == tok::l_paren || !LHS.
isInvalid()) {
2081 if (Tok.
isNot(tok::r_paren)) {
2082 if (ParseExpressionList(ArgExprs, [&] {
2083 PreferredType.enterFunctionArgument(Tok.
getLocation(),
2095 for (
auto &E : ArgExprs)
2104 }
else if (Tok.
isNot(tok::r_paren)) {
2105 bool HadDelayedTypo =
false;
2107 HadDelayedTypo =
true;
2108 for (
auto &E : ArgExprs)
2110 HadDelayedTypo =
true;
2125 ArgExprs.insert(ArgExprs.begin(), Fn);
2143 bool MayBePseudoDestructor =
false;
2146 PreferredType.enterMemAccess(Actions, Tok.
getLocation(), OrigLHS);
2150 const Type* BaseType =
Base->getType().getTypePtrOrNull();
2151 if (BaseType && Tok.
is(tok::l_paren) &&
2154 Diag(OpLoc, diag::err_function_is_not_record)
2155 << OpKind <<
Base->getSourceRange()
2157 return ParsePostfixExpressionSuffix(
Base);
2162 MayBePseudoDestructor);
2167 if (Tok.
is(tok::code_completion)) {
2173 ParseOptionalCXXScopeSpecifier(
2175 false, &MayBePseudoDestructor);
2177 ObjectType =
nullptr;
2180 if (Tok.
is(tok::code_completion)) {
2182 OpKind == tok::arrow ? tok::period : tok::arrow;
2189 getCurScope(), OrigLHS, OpLoc, CorrectedOpKind, ObjectType,
2190 MayBePseudoDestructor);
2194 Expr *CorrectedBase = CorrectedLHS.get();
2196 CorrectedBase =
Base;
2202 Base && ExprStatementTokLoc ==
Base->getBeginLoc(),
2208 if (MayBePseudoDestructor && !LHS.
isInvalid()) {
2209 LHS = ParseCXXPseudoDestructor(LHS.
get(), OpLoc, OpKind, SS,
2224 Tok.
is(tok::kw_class)) {
2234 Name.setIdentifier(
Id, Loc);
2241 false, &TemplateKWLoc, Name)) {
2248 OpKind, SS, TemplateKWLoc, Name,
2249 CurParsedObjCImpl ? CurParsedObjCImpl->Dcl
2252 if (Tok.
is(tok::less))
2253 checkPotentialAngleBracket(LHS);
2254 }
else if (OrigLHS && Name.isValid()) {
2257 Name.getEndLoc(), {OrigLHS});
2262 case tok::minusminus:
2308Parser::ParseExprAfterUnaryExprOrTypeTrait(
const Token &OpTok,
2313 assert(OpTok.
isOneOf(tok::kw_typeof, tok::kw_typeof_unqual, tok::kw_sizeof,
2314 tok::kw___alignof, tok::kw_alignof, tok::kw__Alignof,
2316 tok::kw___builtin_omp_required_simd_align) &&
2317 "Not a typeof/sizeof/alignof/vec_step expression!");
2322 if (Tok.
isNot(tok::l_paren)) {
2325 if (OpTok.
isOneOf(tok::kw_sizeof, tok::kw___alignof, tok::kw_alignof,
2326 tok::kw__Alignof)) {
2327 if (isTypeIdUnambiguously()) {
2329 ParseSpecifierQualifierList(DS);
2332 ParseDeclarator(DeclaratorInfo);
2338 diag::err_expected_parentheses_around_typename)
2341 Diag(LParenLoc, diag::err_expected_parentheses_around_typename)
2351 if (OpTok.
isOneOf(tok::kw_typeof, tok::kw_typeof_unqual) &&
2358 Operand = ParseCastExpression(UnaryExprOnly);
2364 ParenParseOption ExprType =
CastExpr;
2367 Operand = ParseParenExpression(ExprType,
true,
2368 false, CastTy, RParenLoc);
2379 !OpTok.
isOneOf(tok::kw_typeof, tok::kw_typeof_unqual)) {
2396ExprResult Parser::ParseSYCLUniqueStableNameExpression() {
2397 assert(Tok.
is(tok::kw___builtin_sycl_unique_stable_name) &&
2398 "Not __builtin_sycl_unique_stable_name");
2404 if (T.expectAndConsume(diag::err_expected_lparen_after,
2405 "__builtin_sycl_unique_stable_name"))
2415 if (T.consumeClose())
2419 T.getCloseLocation(), Ty.
get());
2434ExprResult Parser::ParseUnaryExprOrTypeTraitExpression() {
2435 assert(Tok.
isOneOf(tok::kw_sizeof, tok::kw___alignof, tok::kw_alignof,
2436 tok::kw__Alignof, tok::kw_vec_step,
2437 tok::kw___builtin_omp_required_simd_align) &&
2438 "Not a sizeof/alignof/vec_step expression!");
2443 if (Tok.
is(tok::ellipsis) && OpTok.
is(tok::kw_sizeof)) {
2448 if (Tok.
is(tok::l_paren)) {
2451 LParenLoc = T.getOpenLocation();
2452 if (Tok.
is(tok::identifier)) {
2456 RParenLoc = T.getCloseLocation();
2460 Diag(Tok, diag::err_expected_parameter_pack);
2463 }
else if (Tok.
is(tok::identifier)) {
2468 Diag(LParenLoc, diag::err_paren_sizeof_parameter_pack)
2473 Diag(Tok, diag::err_sizeof_parameter_pack);
2490 OpTok.
isOneOf(tok::kw_alignof, tok::kw__Alignof))
2491 Diag(OpTok, diag::warn_cxx98_compat_alignof);
2493 Diag(OpTok, diag::warn_c2x_compat_keyword) << OpTok.
getName();
2508 if (OpTok.
isOneOf(tok::kw_alignof, tok::kw__Alignof))
2509 ExprKind = UETT_AlignOf;
2510 else if (OpTok.
is(tok::kw___alignof))
2511 ExprKind = UETT_PreferredAlignOf;
2512 else if (OpTok.
is(tok::kw_vec_step))
2513 ExprKind = UETT_VecStep;
2514 else if (OpTok.
is(tok::kw___builtin_omp_required_simd_align))
2515 ExprKind = UETT_OpenMPRequiredSimdAlign;
2524 if (OpTok.
isOneOf(tok::kw_alignof, tok::kw__Alignof))
2559ExprResult Parser::ParseBuiltinPrimaryExpression() {
2567 if (Tok.
isNot(tok::l_paren))
2568 return ExprError(
Diag(Tok, diag::err_expected_after) << BuiltinII
2577 default: llvm_unreachable(
"Not a builtin primary expression!");
2578 case tok::kw___builtin_va_arg: {
2581 if (ExpectAndConsume(tok::comma)) {
2588 if (Tok.
isNot(tok::r_paren)) {
2589 Diag(Tok, diag::err_expected) << tok::r_paren;
2599 case tok::kw___builtin_offsetof: {
2605 if (MacroName ==
"offsetof")
2618 if (ExpectAndConsume(tok::comma)) {
2624 if (Tok.
isNot(tok::identifier)) {
2625 Diag(Tok, diag::err_expected) << tok::identifier;
2634 Comps.back().isBrackets =
false;
2636 Comps.back().LocStart = Comps.back().LocEnd =
ConsumeToken();
2640 if (Tok.
is(tok::period)) {
2643 Comps.back().isBrackets =
false;
2646 if (Tok.
isNot(tok::identifier)) {
2647 Diag(Tok, diag::err_expected) << tok::identifier;
2653 }
else if (Tok.
is(tok::l_square)) {
2654 if (CheckProhibitedCXX11Attribute())
2659 Comps.back().isBrackets =
true;
2662 Comps.back().LocStart = ST.getOpenLocation();
2668 Comps.back().U.E = Res.
get();
2671 Comps.back().LocEnd = ST.getCloseLocation();
2673 if (Tok.
isNot(tok::r_paren)) {
2682 PT.getCloseLocation());
2689 case tok::kw___builtin_choose_expr: {
2691 if (Cond.isInvalid()) {
2695 if (ExpectAndConsume(tok::comma)) {
2701 if (Expr1.isInvalid()) {
2705 if (ExpectAndConsume(tok::comma)) {
2711 if (Expr2.isInvalid()) {
2715 if (Tok.
isNot(tok::r_paren)) {
2716 Diag(Tok, diag::err_expected) << tok::r_paren;
2720 Expr2.get(), ConsumeParen());
2723 case tok::kw___builtin_astype: {
2726 if (
Expr.isInvalid()) {
2731 if (ExpectAndConsume(tok::comma)) {
2742 if (Tok.
isNot(tok::r_paren)) {
2743 Diag(Tok, diag::err_expected) << tok::r_paren;
2752 case tok::kw___builtin_convertvector: {
2755 if (
Expr.isInvalid()) {
2760 if (ExpectAndConsume(tok::comma)) {
2771 if (Tok.
isNot(tok::r_paren)) {
2772 Diag(Tok, diag::err_expected) << tok::r_paren;
2781 case tok::kw___builtin_COLUMN:
2782 case tok::kw___builtin_FILE:
2783 case tok::kw___builtin_FILE_NAME:
2784 case tok::kw___builtin_FUNCTION:
2785 case tok::kw___builtin_LINE:
2786 case tok::kw___builtin_source_location: {
2788 if (Tok.
isNot(tok::r_paren)) {
2789 Diag(Tok, diag::err_expected) << tok::r_paren;
2795 case tok::kw___builtin_FILE:
2797 case tok::kw___builtin_FILE_NAME:
2799 case tok::kw___builtin_FUNCTION:
2801 case tok::kw___builtin_LINE:
2803 case tok::kw___builtin_COLUMN:
2805 case tok::kw___builtin_source_location:
2808 llvm_unreachable(
"invalid keyword");
2821 return ParsePostfixExpressionSuffix(Res.
get());
2824bool Parser::tryParseOpenMPArrayShapingCastPart() {
2825 assert(Tok.
is(tok::l_square) &&
"Expected open bracket");
2826 bool ErrorFound =
true;
2827 TentativeParsingAction TPA(*
this);
2829 if (Tok.
isNot(tok::l_square))
2834 while (!
SkipUntil(tok::r_square, tok::annot_pragma_openmp_end,
2837 if (Tok.
isNot(tok::r_square))
2842 if (Tok.
is(tok::r_paren)) {
2846 }
while (Tok.
isNot(tok::annot_pragma_openmp_end));
2879Parser::ParseParenExpression(ParenParseOption &ExprType,
bool stopIfCastExpr,
2882 assert(Tok.
is(tok::l_paren) &&
"Not a paren expr!");
2885 if (T.consumeOpen())
2889 PreferredType.enterParenExpr(Tok.
getLocation(), OpenLoc);
2892 bool isAmbiguousTypeId;
2895 if (Tok.
is(tok::code_completion)) {
2899 ExprType >= CompoundLiteral);
2906 tok::kw___bridge_transfer,
2907 tok::kw___bridge_retained,
2908 tok::kw___bridge_retain));
2909 if (BridgeCast && !
getLangOpts().ObjCAutoRefCount) {
2911 StringRef BridgeCastName = Tok.
getName();
2914 Diag(BridgeKeywordLoc, diag::warn_arc_bridge_cast_nonarc)
2924 Diag(Tok, OpenLoc.
isMacroID() ? diag::ext_gnu_statement_expr_macro
2925 : diag::ext_gnu_statement_expr);
2927 checkCompoundToken(OpenLoc, tok::l_paren, CompoundToken::StmtExprBegin);
2936 while (CodeDC->
isRecord() || isa<EnumDecl>(CodeDC)) {
2939 "statement expr not in code context");
2949 if (!
Stmt.isInvalid()) {
2956 }
else if (ExprType >= CompoundLiteral && BridgeCast) {
2962 if (tokenKind == tok::kw___bridge)
2964 else if (tokenKind == tok::kw___bridge_transfer)
2966 else if (tokenKind == tok::kw___bridge_retained)
2971 assert(tokenKind == tok::kw___bridge_retain);
2974 Diag(BridgeKeywordLoc, diag::err_arc_bridge_retain)
2976 "__bridge_retained");
2981 ColonProtection.restore();
2982 RParenLoc = T.getCloseLocation();
2985 ExprResult SubExpr = ParseCastExpression(AnyCastExpr);
2991 BridgeKeywordLoc, Ty.
get(),
2992 RParenLoc, SubExpr.
get());
2993 }
else if (ExprType >= CompoundLiteral &&
2994 isTypeIdInParens(isAmbiguousTypeId)) {
3003 if (isAmbiguousTypeId && !stopIfCastExpr) {
3004 ExprResult res = ParseCXXAmbiguousParenExpression(ExprType, CastTy, T,
3006 RParenLoc = T.getCloseLocation();
3012 ParseSpecifierQualifierList(DS);
3015 ParseDeclarator(DeclaratorInfo);
3020 if (!DeclaratorInfo.isInvalidType() && Tok.
is(tok::identifier) &&
3034 ColonProtection.restore();
3035 RParenLoc = T.getCloseLocation();
3036 if (Tok.
is(tok::l_brace)) {
3037 ExprType = CompoundLiteral;
3043 return ParseCompoundLiteralExpression(Ty.
get(), OpenLoc, RParenLoc);
3046 if (Tok.
is(tok::l_paren)) {
3067 Result = ParseCastExpression(AnyCastExpr,
3072 if (!
Result.isInvalid()) {
3074 DeclaratorInfo, CastTy,
3075 RParenLoc,
Result.get());
3079 if (!
Result.isInvalid()) {
3091 if (DeclaratorInfo.isInvalidType())
3096 if (stopIfCastExpr) {
3110 GetLookAheadToken(1).isNot(tok::period)) {
3119 Result = ParseCastExpression(AnyCastExpr,
3122 if (!
Result.isInvalid()) {
3124 DeclaratorInfo, CastTy,
3125 RParenLoc,
Result.get());
3130 Diag(Tok, diag::err_expected_lbrace_in_compound_literal);
3133 }
else if (ExprType >= FoldExpr && Tok.
is(tok::ellipsis) &&
3135 ExprType = FoldExpr;
3137 }
else if (isTypeCast) {
3140 ExprVector ArgExprs;
3142 if (!ParseSimpleExpressionList(ArgExprs)) {
3145 if (ExprType >= FoldExpr && ArgExprs.size() == 1 &&
3147 ExprType = FoldExpr;
3148 return ParseFoldExpression(ArgExprs[0], T);
3151 ExprType = SimpleExpr;
3155 }
else if (
getLangOpts().OpenMP >= 50 && OpenMPDirectiveParsing &&
3156 ExprType ==
CastExpr && Tok.
is(tok::l_square) &&
3157 tryParseOpenMPArrayShapingCastPart()) {
3158 bool ErrorFound =
false;
3168 while (!
SkipUntil(tok::r_square, tok::r_paren,
3173 OMPDimensions.push_back(NumElements.
get());
3174 OMPBracketsRanges.push_back(TS.getRange());
3175 }
while (Tok.
isNot(tok::r_paren));
3178 RParenLoc = T.getCloseLocation();
3182 }
else if (!
Result.isInvalid()) {
3184 Result.get(), OpenLoc, RParenLoc, OMPDimensions, OMPBracketsRanges);
3197 if (ExprType >= FoldExpr && isFoldOperator(Tok.
getKind()) &&
3199 ExprType = FoldExpr;
3200 return ParseFoldExpression(
Result, T);
3202 ExprType = SimpleExpr;
3205 if (!
Result.isInvalid() && Tok.
is(tok::r_paren))
3211 if (
Result.isInvalid()) {
3217 RParenLoc = T.getCloseLocation();
3230Parser::ParseCompoundLiteralExpression(
ParsedType Ty,
3233 assert(Tok.
is(tok::l_brace) &&
"Not a compound literal!");
3235 Diag(LParenLoc, diag::ext_c99_compound_literal);
3238 if (!
Result.isInvalid() && Ty)
3252 assert(isTokenStringLiteral() &&
"Not a string literal!");
3259 StringToks.push_back(Tok);
3260 ConsumeStringToken();
3261 }
while (isTokenStringLiteral());
3282ExprResult Parser::ParseGenericSelectionExpression() {
3283 assert(Tok.
is(tok::kw__Generic) &&
"_Generic keyword expected");
3285 Diag(Tok, diag::ext_c11_feature) << Tok.
getName();
3289 if (T.expectAndConsume())
3306 if (ExpectAndConsume(tok::comma)) {
3316 if (Tok.
is(tok::kw_default)) {
3320 Diag(Tok, diag::err_duplicate_default_assoc);
3321 Diag(DefaultLoc, diag::note_previous_default_assoc);
3336 Types.push_back(Ty);
3338 if (ExpectAndConsume(tok::colon)) {
3347 if (ER.isInvalid()) {
3351 Exprs.push_back(ER.get());
3355 if (T.getCloseLocation().isInvalid())
3359 T.getCloseLocation(),
3360 ControllingExpr.
get(),
3383 assert(isFoldOperator(Kind) &&
"missing fold-operator");
3387 assert(Tok.
is(tok::ellipsis) &&
"not a fold-expression");
3391 if (Tok.
isNot(tok::r_paren)) {
3392 if (!isFoldOperator(Tok.
getKind()))
3395 if (Kind != tok::unknown && Tok.
getKind() != Kind)
3409 ? diag::warn_cxx14_compat_fold_expression
3410 : diag::ext_fold_expression);
3414 Kind, EllipsisLoc, RHS.
get(),
3441 llvm::function_ref<
void()> ExpressionStarts,
3442 bool FailImmediatelyOnInvalidExpr,
3443 bool EarlyTypoCorrection) {
3444 bool SawError =
false;
3446 if (ExpressionStarts)
3451 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
3452 Expr = ParseBraceInitializer();
3456 if (EarlyTypoCorrection)
3459 if (Tok.
is(tok::ellipsis))
3461 else if (Tok.
is(tok::code_completion)) {
3471 if (
Expr.isInvalid()) {
3473 if (FailImmediatelyOnInvalidExpr)
3477 Exprs.push_back(
Expr.get());
3480 if (Tok.
isNot(tok::comma))
3485 checkPotentialAngleBracketDelimiter(Comma);
3490 for (
auto &E : Exprs) {
3492 if (
Expr.isUsable()) E =
Expr.get();
3509 if (
Expr.isInvalid())
3512 Exprs.push_back(
Expr.get());
3522 checkPotentialAngleBracketDelimiter(Comma);
3533 if (Tok.
is(tok::code_completion)) {
3541 ParseSpecifierQualifierList(DS);
3547 ParseDeclarator(DeclaratorInfo);
3549 MaybeParseGNUAttributes(DeclaratorInfo);
3565ExprResult Parser::ParseBlockLiteralExpression() {
3566 assert(Tok.
is(tok::caret) &&
"block literal starts with ^");
3570 "block literal parsing");
3593 if (Tok.
is(tok::l_paren)) {
3594 ParseParenDeclarator(ParamInfo);
3599 ParamInfo.SetIdentifier(
nullptr, CaretLoc);
3600 ParamInfo.SetRangeEnd(Tmp);
3601 if (ParamInfo.isInvalidType()) {
3609 MaybeParseGNUAttributes(ParamInfo);
3613 }
else if (!Tok.
is(tok::l_brace)) {
3614 ParseBlockId(CaretLoc);
3618 ParamInfo.AddTypeInfo(
3636 CaretLoc, CaretLoc, ParamInfo),
3639 MaybeParseGNUAttributes(ParamInfo);
3647 if (!Tok.
is(tok::l_brace)) {
3649 Diag(Tok, diag::err_expected_expression);
3656 if (!
Stmt.isInvalid())
3676 llvm::SmallSet<StringRef, 4> Platforms;
3677 bool HasOtherPlatformSpec =
false;
3679 for (
const auto &Spec : AvailSpecs) {
3680 if (Spec.isOtherPlatformSpec()) {
3681 if (HasOtherPlatformSpec) {
3682 P.Diag(Spec.getBeginLoc(), diag::err_availability_query_repeated_star);
3686 HasOtherPlatformSpec =
true;
3690 bool Inserted = Platforms.insert(Spec.getPlatform()).second;
3695 StringRef Platform = Spec.getPlatform();
3696 P.Diag(Spec.getBeginLoc(), diag::err_availability_query_repeated_platform)
3697 << Spec.getEndLoc() << Platform;
3702 if (!HasOtherPlatformSpec) {
3703 SourceLocation InsertWildcardLoc = AvailSpecs.back().getEndLoc();
3704 P.Diag(InsertWildcardLoc, diag::err_availability_query_wildcard_required)
3717std::optional<AvailabilitySpec> Parser::ParseAvailabilitySpec() {
3718 if (Tok.
is(tok::star)) {
3722 if (Tok.
is(tok::code_completion)) {
3725 return std::nullopt;
3727 if (Tok.
isNot(tok::identifier)) {
3728 Diag(Tok, diag::err_avail_query_expected_platform_name);
3729 return std::nullopt;
3734 VersionTuple Version = ParseVersionTuple(VersionRange);
3736 if (Version.empty())
3737 return std::nullopt;
3739 StringRef GivenPlatform = PlatformIdentifier->
Ident->
getName();
3740 StringRef Platform =
3741 AvailabilityAttr::canonicalizePlatformName(GivenPlatform);
3743 if (AvailabilityAttr::getPrettyPlatformName(Platform).empty()) {
3745 diag::err_avail_query_unrecognized_platform_name)
3747 return std::nullopt;
3756 assert(Tok.
is(tok::kw___builtin_available) ||
3763 if (Parens.expectAndConsume())
3767 bool HasError =
false;
3769 std::optional<AvailabilitySpec> Spec = ParseAvailabilitySpec();
3773 AvailSpecs.push_back(*Spec);
3786 if (Parens.consumeClose())
3790 Parens.getCloseLocation());
Defines the clang::ASTContext interface.
static CompilationDatabasePluginRegistry::Add< FixedCompilationDatabasePlugin > X("fixed-compilation-database", "Reads plain-text flags file")
static Decl::Kind getKind(const Decl *D)
Defines the clang::Expr interface and subclasses for C++ expressions.
static bool CheckAvailabilitySpecList(Parser &P, ArrayRef< AvailabilitySpec > AvailSpecs)
Validate availability spec list, emitting diagnostics if necessary.
#define REVERTIBLE_TYPE_TRAIT(Name)
Defines the PrettyStackTraceEntry class, which is used to make crashes give more contextual informati...
const clang::PrintingPolicy & getPrintingPolicy() const
One specifier in an @available expression.
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.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed.
CompoundStmt - This represents a group of statements like { stmt stmt }.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
virtual bool ValidateCandidate(const TypoCorrection &candidate)
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool isFileContext() const
Captures information about "declaration specifiers".
Information about one declarator, including the parsed type information and the identifier.
RAII object that enters a new expression evaluation context.
This represents one expression.
bool containsErrors() const
Whether this expression contains subexpressions which had errors, e.g.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
ExtensionRAIIObject - This saves the state of extension warnings when constructed and disables them.
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.
bool hasRevertedTokenIDToIdentifier() const
True if revertTokenIDToIdentifier() was called.
StringRef getName() const
Return the actual identifier string.
Represents the declaration of a label.
static StringRef getImmediateMacroNameForDiagnostics(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts)
Retrieve the name of the immediate macro expansion.
This represents a decl that may have a name.
void * getAsOpaquePtr() const
static const ParsedAttributesView & none()
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 type-name: [C99 6.7.6] specifier-qualifier-list abstract-declarator[opt].
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
Sema & getActions() const
static TypeResult getTypeAnnotation(const Token &Tok)
getTypeAnnotation - Read a parsed type out of an annotation token.
ExprResult ParseCaseExpression(SourceLocation CaseLoc)
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.
ExprResult ParseConstantExpression()
bool TryConsumeToken(tok::TokenKind Expected)
Scope * getCurScope() const
ExprResult ParseConstraintLogicalAndExpression(bool IsTrailingRequiresClause)
Parse a constraint-logical-and-expression.
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 ...
ExprResult ParseAssignmentExpression(TypeCastState isTypeCast=NotTypeCast)
Parse an expr that doesn't include (top-level) commas.
ExprResult ParseConstantExpressionInExprEvalContext(TypeCastState isTypeCast=NotTypeCast)
const LangOptions & getLangOpts() const
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
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.
bool TryAnnotateTypeOrScopeToken(ImplicitTypenameContext AllowImplicitTypename=ImplicitTypenameContext::No)
TryAnnotateTypeOrScopeToken - If the current token position is on a typename (possibly qualified in C...
TypeCastState
TypeCastState - State whether an expression is or may be a type cast.
ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral=false)
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
ExprResult ParseConstraintExpression()
Parse a constraint-expression.
void enterSubscript(Sema &S, SourceLocation Tok, Expr *LHS)
void enterUnary(Sema &S, SourceLocation Tok, tok::TokenKind OpKind, SourceLocation OpLoc)
void enterBinary(Sema &S, SourceLocation Tok, Expr *LHS, tok::TokenKind Op)
QualType get(SourceLocation Tok) const
Get the expected type associated with this location, if any.
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
SourceManager & getSourceManager() const
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
Return the 'spelling' of the token at the given location; does not go up to the spelling location or ...
bool isAtStartOfMacroExpansion(SourceLocation loc, SourceLocation *MacroBegin=nullptr) const
Returns true if the given MacroID location points at the first token of the macro expansion.
bool isCodeCompletionReached() const
Returns true if code-completion is enabled and we have hit the code-completion point.
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
If a crash happens while one of these objects are live, the message is printed out along with the spe...
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
@ BlockScope
This is a scope that corresponds to a block/closure object.
@ CompoundStmtScope
This is a compound statement scope.
@ 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.
RAII class used to indicate that we are performing provisional semantic analysis to determine the val...
ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, tok::TokenKind Op, Expr *Input, bool IsAfterAmp=false)
ExprResult ActOnConstantExpression(ExprResult Res)
ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen, Expr *Operand, SourceLocation RParen)
void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, Expr *OtherOpBase, SourceLocation OpLoc, bool IsArrow, bool IsBaseExprStatement, QualType PreferredType)
ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, ParsedType Ty, SourceLocation RParenLoc, Expr *InitExpr)
void ActOnStartStmtExpr()
QualType ProduceCallSignatureHelp(Expr *Fn, ArrayRef< Expr * > Args, SourceLocation OpenParLoc)
Determines the preferred type of the current function argument, by examining the signatures of all po...
void ActOnStmtExprError()
ExprResult ActOnObjCBridgedCast(Scope *S, SourceLocation LParenLoc, ObjCBridgeCastKind Kind, SourceLocation BridgeKeywordLoc, ParsedType Type, SourceLocation RParenLoc, Expr *SubExpr)
ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, UnqualifiedId &Id, bool HasTrailingLParen, bool IsAddressOfOperand, CorrectionCandidateCallback *CCC=nullptr, bool IsInlineAsmIdentifier=false, Token *KeywordReplacement=nullptr)
ExprResult ActOnCharacterConstant(const Token &Tok, Scope *UDLScope=nullptr)
ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc, MultiExprArg ExecConfig, SourceLocation GGGLoc)
ExprResult ActOnStartCXXMemberReference(Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, ParsedType &ObjectType, bool &MayBePseudoDestructor)
ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val)
TypeResult ActOnTypeName(Scope *S, Declarator &D)
ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc, Expr *LowerBound, SourceLocation ColonLocFirst, SourceLocation ColonLocSecond, Expr *Length, Expr *Stride, SourceLocation RBLoc)
void CodeCompleteObjCClassPropertyRefExpr(Scope *S, IdentifierInfo &ClassName, SourceLocation ClassNameLoc, bool IsBaseExprStatement)
void CodeCompletePostfixExpression(Scope *S, ExprResult LHS, QualType PreferredType)
ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc)
ActOnCXXNullPtrLiteral - Parse 'nullptr'.
ExprResult ActOnSourceLocExpr(SourceLocExpr::IdentKind Kind, SourceLocation BuiltinLoc, SourceLocation RPLoc)
void CodeCompleteAvailabilityPlatformName()
bool CheckConstraintExpression(const Expr *CE, Token NextToken=Token(), bool *PossibleNonPrimary=nullptr, bool IsTrailingRequiresClause=false)
Check whether the given expression is a valid constraint expression.
ASTContext & getASTContext() const
ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, LabelDecl *TheDecl)
ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val)
ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr, SourceLocation RPLoc)
void CodeCompleteExpression(Scope *S, const CodeCompleteExpressionData &Data)
Perform code-completion in an expression context when we know what type we're looking for.
SourceRange getExprRange(Expr *E) const
ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, Expr *ControllingExpr, ArrayRef< ParsedType > ArgTypes, ArrayRef< Expr * > ArgExprs)
ExprResult ActOnCoawaitExpr(Scope *S, SourceLocation KwLoc, Expr *E)
ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, UnqualifiedId &Member, Decl *ObjCImpDecl)
The main callback when the parser finds something like expression .
void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope)
ActOnBlockError - If there is an error parsing a block, this callback is invoked to pop the informati...
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc)
@ PCC_Type
Code completion occurs where only a type is permitted.
ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E)
ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, SourceLocation ColonLoc, Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr)
ActOnConditionalOp - Parse a ?: operation.
ExprResult ActOnSYCLUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, ParsedType ParsedTy)
ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind)
ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals.
LabelDecl * LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, SourceLocation GnuLabelLoc=SourceLocation())
LookupOrCreateLabel - Do a name lookup of a label with the specified name.
ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, SourceLocation EllipsisLoc)
Invoked when parsing a template argument followed by an ellipsis, which creates a pack expansion.
ExprResult ActOnStringLiteral(ArrayRef< Token > StringToks, Scope *UDLScope=nullptr)
ActOnStringLiteral - The specified tokens were lexed as pasted string fragments (e....
ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr)
ExprResult ActOnOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, SourceLocation RParenLoc, ArrayRef< Expr * > Dims, ArrayRef< SourceRange > Brackets)
ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec *SS=nullptr, bool isClassName=false, bool HasTrailingDot=false, ParsedType ObjectType=nullptr, bool IsCtorOrDtorName=false, bool WantNontrivialTypeSourceInfo=false, bool IsClassTemplateDeductionContext=true, ImplicitTypenameContext AllowImplicitTypename=ImplicitTypenameContext::No, IdentifierInfo **CorrectedII=nullptr)
If the identifier refers to a type name within this scope, return the declaration of that type.
ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind)
@ ConstantEvaluated
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy, SourceLocation BuiltinLoc, SourceLocation RParenLoc)
__builtin_astype(...)
ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty, SourceLocation RPLoc)
void CodeCompleteOrdinaryName(Scope *S, ParserCompletionContext CompletionContext)
ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, Declarator &D, ParsedType &Ty, SourceLocation RParenLoc, Expr *CastExpr)
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
ExprResult ActOnSizeofParameterPackExpr(Scope *S, SourceLocation OpLoc, IdentifierInfo &Name, SourceLocation NameLoc, SourceLocation RParenLoc)
Called when an expression computing the size of a parameter pack is parsed.
ExprResult ActOnStmtExpr(Scope *S, SourceLocation LPLoc, Stmt *SubStmt, SourceLocation RPLoc)
ExprResult ActOnCXXFoldExpr(Scope *S, SourceLocation LParenLoc, Expr *LHS, tok::TokenKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc)
Handle a C++1z fold-expression: ( expr op ... op expr ).
ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, Scope *CurScope)
ActOnBlockStmtExpr - This is called when the body of a block statement literal was successfully compl...
ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, tok::TokenKind Kind, Expr *Input)
ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, ArrayRef< Expr * > SubExprs, QualType T=QualType())
Attempts to produce a RecoveryExpr after some AST node cannot be created.
ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope=nullptr)
void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope)
ActOnBlockStart - This callback is invoked when a block literal is started.
ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, MultiExprArg ArgExprs, SourceLocation RLoc)
ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, MultiExprArg ArgExprs, SourceLocation RParenLoc, Expr *ExecConfig=nullptr)
ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
ExprResult ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, bool IsType, void *TyOrEx, SourceRange ArgRange)
ActOnUnaryExprOrTypeTraitExpr - Handle sizeof(type) and sizeof expr and the same for alignof and __al...
void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo, Scope *CurScope)
ActOnBlockArguments - This callback allows processing of block arguments.
ExprResult ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, IdentifierInfo &propertyName, SourceLocation receiverNameLoc, SourceLocation propertyNameLoc)
ExprResult ActOnObjCAvailabilityCheckExpr(llvm::ArrayRef< AvailabilitySpec > AvailSpecs, SourceLocation AtLoc, SourceLocation RParen)
ExprResult ActOnConvertVectorExpr(Expr *E, ParsedType ParsedDestTy, SourceLocation BuiltinLoc, SourceLocation RParenLoc)
__builtin_convertvector(...)
bool isSimpleTypeSpecifier(tok::TokenKind Kind) const
Determine whether the token kind starts a simple-type-specifier.
ExprResult ActOnBuiltinOffsetOf(Scope *S, SourceLocation BuiltinLoc, SourceLocation TypeLoc, ParsedType ParsedArgTy, ArrayRef< OffsetOfComponent > Components, SourceLocation RParenLoc)
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, bool RecoverUncorrectedTypos=false, 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...
ExprResult ActOnNameClassifiedAsOverloadSet(Scope *S, Expr *OverloadSet)
Act on the result of classifying a name as an overload set.
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.
This class handles loading and caching of source files into memory.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
Stmt - This represents one statement.
SourceLocation getEndLoc() const LLVM_READONLY
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
Token - This structure provides full information about a lexed token.
IdentifierInfo * getIdentifierInfo() const
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
const char * getName() const
void setKind(tok::TokenKind K)
SourceLocation getAnnotationEndLoc() const
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
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
bool isNot(tok::TokenKind K) const
bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const
Return true if we have an ObjC keyword identifier.
SourceLocation getLastLoc() const
Base wrapper for a particular "section" of type source info.
The base class of the type hierarchy.
bool isSpecificPlaceholderType(unsigned K) const
Test for a specific placeholder type.
bool isFunctionType() const
bool isVectorType() const
Simple class containing the result of Sema::CorrectTypo.
NamedDecl * getCorrectionDecl() const
Gets the pointer to the declaration of the typo correction.
Represents a C++ unqualified-id that has been parsed.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
@ C
Languages that the frontend can parse and compile.
@ Result
The result type of a method or function.
ObjCBridgeCastKind
The kind of bridging performed by the Objective-C bridge cast.
@ OBC_Bridge
Bridging via __bridge, which does nothing but reinterpret the bits.
@ OBC_BridgeTransfer
Bridging via __bridge_transfer, which transfers ownership of an Objective-C pointer into ARC.
@ OBC_BridgeRetained
Bridging via __bridge_retain, which makes an ARC object available as a +1 C pointer.
ActionResult< Expr * > ExprResult
prec::Level getBinOpPrecedence(tok::TokenKind Kind, bool GreaterThanIsOperator, bool CPlusPlus11)
Return the precedence of the specified binary operator token.
@ TNK_Type_template
The name refers to a template whose specialization produces a type.
@ EST_None
no exception specification
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.
Wraps an identifier and optional source location for the identifier.
Information about a template-id annotation token.
TemplateNameKind Kind
The kind of template that Template refers to.