34#include "llvm/ADT/SmallVector.h"
128 return ParseRHSOfBinaryExpression(LHS,
prec::Comma);
139 return ParseRHSOfBinaryExpression(LHS,
prec::Comma);
146Parser::ParseExpressionWithLeadingExtension(
SourceLocation ExtLoc) {
152 LHS = ParseCastExpression(AnyCastExpr);
155 if (!LHS.isInvalid())
159 return ParseRHSOfBinaryExpression(LHS,
prec::Comma);
164 if (Tok.
is(tok::code_completion)) {
171 if (Tok.
is(tok::kw_throw))
172 return ParseThrowExpression();
173 if (Tok.
is(tok::kw_co_yield))
174 return ParseCoyieldExpression();
176 ExprResult LHS = ParseCastExpression(AnyCastExpr,
192Parser::ParseAssignmentExprWithObjCMessageExprStart(
SourceLocation LBracLoc,
195 Expr *ReceiverExpr) {
197 = ParseObjCMessageExpressionBody(LBracLoc, SuperLoc,
198 ReceiverType, ReceiverExpr);
199 R = ParsePostfixExpressionSuffix(R);
207 "Call this function only if your ExpressionEvaluationContext is "
208 "already ConstantEvaluated");
209 ExprResult LHS(ParseCastExpression(AnyCastExpr,
false, isTypeCast));
229 Actions.
ExprEvalContexts.back().InConditionallyConstantEvaluateContext =
true;
250 ExprResult LHS(ParseCastExpression(AnyCastExpr));
272 bool NotPrimaryExpression =
false;
273 auto ParsePrimary = [&] () {
274 ExprResult E = ParseCastExpression(PrimaryExprOnly,
278 &NotPrimaryExpression);
282 E = ParsePostfixExpressionSuffix(E);
289 ? diag::note_unparenthesized_non_primary_expr_in_requires_clause
290 : diag::err_unparenthesized_non_primary_expr_in_requires_clause)
298 if (NotPrimaryExpression ||
305 Tok.
isOneOf(tok::period, tok::plusplus, tok::minusminus) ||
306 (Tok.
is(tok::l_square) && !
NextToken().is(tok::l_square))) {
307 E = RecoverFromNonPrimary(E,
false);
310 NotPrimaryExpression =
false;
312 bool PossibleNonPrimary;
313 bool IsConstraintExpr =
315 IsTrailingRequiresClause);
316 if (!IsConstraintExpr || PossibleNonPrimary) {
321 if (PossibleNonPrimary)
322 E = RecoverFromNonPrimary(E, !IsConstraintExpr);
331 while (Tok.
is(tok::ampamp)) {
339 tok::ampamp, LHS.
get(), RHS.
get());
365 while (Tok.
is(tok::pipepipe)) {
374 tok::pipepipe, LHS.
get(), RHS.
get());
385bool Parser::isNotExpressionStart() {
387 if (K == tok::l_brace || K == tok::r_brace ||
388 K == tok::kw_for || K == tok::kw_while ||
389 K == tok::kw_if || K == tok::kw_else ||
390 K == tok::kw_goto || K == tok::kw_try)
393 return isKnownToBeDeclarationSpecifier();
396bool Parser::isFoldOperator(
prec::Level Level)
const {
410 GreaterThanIsOperator,
414 auto SavedType = PreferredType;
417 PreferredType = SavedType;
421 if (NextTokPrec < MinPrec)
428 if (OpToken.
is(tok::caretcaret)) {
429 return ExprError(
Diag(Tok, diag::err_opencl_logical_exclusive_or));
434 if (OpToken.
isOneOf(tok::comma, tok::greater, tok::greatergreater,
435 tok::greatergreatergreater) &&
436 checkPotentialAngleBracketDelimiter(OpToken))
444 if (OpToken.
is(tok::comma) && isNotExpressionStart()) {
452 if (isFoldOperator(NextTokPrec) && Tok.
is(tok::ellipsis)) {
466 Tok.
isOneOf(tok::colon, tok::r_square) &&
479 TernaryMiddle = ParseBraceInitializer();
480 if (!TernaryMiddle.isInvalid()) {
481 Diag(BraceLoc, diag::err_init_list_bin_op)
486 }
else if (Tok.
isNot(tok::colon)) {
498 TernaryMiddle =
nullptr;
499 Diag(Tok, diag::ext_gnu_conditional_expr);
502 if (TernaryMiddle.isInvalid()) {
505 TernaryMiddle =
nullptr;
514 const char *FIText =
": ";
518 bool IsInvalid =
false;
519 const char *SourcePtr =
521 if (!IsInvalid && *SourcePtr ==
' ') {
524 if (!IsInvalid && *SourcePtr ==
' ') {
531 Diag(Tok, diag::err_expected)
533 Diag(OpToken, diag::note_matching) << tok::question;
551 bool RHSIsInitList =
false;
553 RHS = ParseBraceInitializer();
554 RHSIsInitList =
true;
558 RHS = ParseCastExpression(AnyCastExpr);
564 if (TernaryMiddle.isUsable())
581 if (ThisPrec < NextTokPrec ||
582 (ThisPrec == NextTokPrec && isRightAssoc)) {
584 Diag(Tok, diag::err_init_list_bin_op)
593 RHS = ParseRHSOfBinaryExpression(RHS,
594 static_cast<prec::Level>(ThisPrec + !isRightAssoc));
595 RHSIsInitList =
false;
601 if (TernaryMiddle.isUsable())
612 Diag(OpToken, diag::warn_cxx98_compat_generalized_initializer_lists)
614 }
else if (ColonLoc.
isValid()) {
615 Diag(ColonLoc, diag::err_init_list_bin_op)
620 Diag(OpToken, diag::err_init_list_bin_op)
630 if (TernaryMiddle.isInvalid()) {
634 if (!GreaterThanIsOperator && OpToken.
is(tok::greatergreater))
636 diag::warn_cxx11_right_shift_in_template_arg,
646 {LHS.get(), RHS.get()});
654 std::vector<clang::Expr *> Args;
656 if (TernaryMiddle.get())
657 Args = {LHS.
get(), TernaryMiddle.get(), RHS.
get()};
659 Args = {LHS.
get(), RHS.
get()};
687ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
688 bool isAddressOfOperand,
689 TypeCastState isTypeCast,
690 bool isVectorLiteral,
691 bool *NotPrimaryExpression) {
693 ExprResult Res = ParseCastExpression(ParseKind,
698 NotPrimaryExpression);
700 Diag(Tok, diag::err_expected_expression);
707 CastExpressionIdValidator(
Token Next,
bool AllowTypes,
bool AllowNonTypes)
708 : NextToken(Next), AllowNonTypes(AllowNonTypes) {
709 WantTypeSpecifiers = WantFunctionLikeCasts = AllowTypes;
712 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
717 if (isa<TypeDecl>(ND))
718 return WantTypeSpecifiers;
723 if (!NextToken.isOneOf(tok::equal, tok::arrow, tok::period))
726 for (
auto *
C : candidate) {
728 if (isa<ValueDecl>(ND) && !isa<FunctionDecl>(ND))
734 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
735 return std::make_unique<CastExpressionIdValidator>(*
this);
927ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
928 bool isAddressOfOperand,
930 TypeCastState isTypeCast,
931 bool isVectorLiteral,
932 bool *NotPrimaryExpression) {
935 auto SavedType = PreferredType;
941 bool AllowSuffix =
true;
957 ParenParseOption ParenExprType;
959 case CastParseKind::UnaryExprOnly:
962 case CastParseKind::AnyCastExpr:
963 ParenExprType = ParenParseOption::CastExpr;
965 case CastParseKind::PrimaryExprOnly:
966 ParenExprType = FoldExpr;
971 Res = ParseParenExpression(ParenExprType,
false,
980 switch (ParenExprType) {
981 case SimpleExpr:
break;
983 case CompoundLiteral:
1001 case tok::numeric_constant:
1011 Res = ParseCXXBoolLiteral();
1014 case tok::kw___objc_yes:
1015 case tok::kw___objc_no:
1016 Res = ParseObjCBoolLiteral();
1019 case tok::kw_nullptr:
1021 Diag(Tok, diag::warn_cxx98_compat_nullptr);
1024 : diag::ext_c_nullptr) << Tok.
getName();
1029 case tok::annot_primary_expr:
1030 case tok::annot_overload_set:
1031 Res = getExprAnnotation(Tok);
1034 ConsumeAnnotationToken();
1036 checkPotentialAngleBracket(Res);
1039 case tok::annot_non_type:
1040 case tok::annot_non_type_dependent:
1041 case tok::annot_non_type_undeclared: {
1044 Res = tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement);
1046 "should not perform typo correction on annotation token");
1050 case tok::kw___super:
1051 case tok::kw_decltype:
1055 assert(Tok.
isNot(tok::kw_decltype) && Tok.
isNot(tok::kw___super));
1056 return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast,
1057 isVectorLiteral, NotPrimaryExpression);
1059 case tok::identifier:
1073 if (Next.is(tok::l_paren) &&
1074 Tok.
is(tok::identifier) &&
1078 if (RevertibleTypeTraits.empty()) {
1079#define RTT_JOIN(X,Y) X##Y
1080#define REVERTIBLE_TYPE_TRAIT(Name) \
1081 RevertibleTypeTraits[PP.getIdentifierInfo(#Name)] \
1082 = RTT_JOIN(tok::kw_,Name)
1142#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) \
1143 REVERTIBLE_TYPE_TRAIT(RTT_JOIN(__, Trait));
1144#include "clang/Basic/TransformTypeTraits.def"
1145#undef REVERTIBLE_TYPE_TRAIT
1152 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind>::iterator Known
1153 = RevertibleTypeTraits.find(II);
1154 if (Known != RevertibleTypeTraits.end()) {
1156 return ParseCastExpression(ParseKind, isAddressOfOperand,
1157 NotCastExpr, isTypeCast,
1158 isVectorLiteral, NotPrimaryExpression);
1162 if ((!ColonIsSacred && Next.is(tok::colon)) ||
1163 Next.isOneOf(tok::coloncolon, tok::less, tok::l_paren,
1168 if (!Tok.
is(tok::identifier))
1169 return ParseCastExpression(ParseKind, isAddressOfOperand,
1170 NotCastExpr, isTypeCast,
1172 NotPrimaryExpression);
1185 (&II == Ident_super &&
getCurScope()->isInObjcMethodScope()))) {
1188 if (Tok.
is(tok::code_completion) && &II != Ident_super) {
1191 getCurScope(), II, ILoc, ExprStatementTokLoc == ILoc);
1195 if (Tok.
isNot(tok::identifier) &&
1197 Diag(Tok, diag::err_expected_property_name);
1212 if (
getLangOpts().
ObjC && &II == Ident_super && !InMessageExpression &&
1214 ((Tok.
is(tok::identifier) &&
1216 Tok.
is(tok::code_completion))) {
1217 Res = ParseObjCMessageExpressionBody(
SourceLocation(), ILoc,
nullptr,
1228 ((Tok.
is(tok::identifier) && !InMessageExpression) ||
1229 Tok.
is(tok::code_completion))) {
1231 if (Tok.
is(tok::code_completion) ||
1232 Next.is(tok::colon) || Next.is(tok::r_square))
1234 if (Typ.get()->isObjCObjectOrInterfaceType()) {
1237 DS.SetRangeStart(ILoc);
1238 DS.SetRangeEnd(ILoc);
1239 const char *PrevSpec =
nullptr;
1241 DS.SetTypeSpecType(
TST_typename, ILoc, PrevSpec, DiagID, Typ,
1259 if (isAddressOfOperand && isPostfixExpressionSuffixStart())
1260 isAddressOfOperand =
false;
1269 CastExpressionIdValidator Validator(
1273 Validator.IsAddressOfOperand = isAddressOfOperand;
1274 if (Tok.
isOneOf(tok::periodstar, tok::arrowstar)) {
1275 Validator.WantExpressionKeywords =
false;
1276 Validator.WantRemainingKeywords =
false;
1278 Validator.WantRemainingKeywords = Tok.
isNot(tok::r_paren);
1280 Name.setIdentifier(&II, ILoc);
1282 getCurScope(), ScopeSpec, TemplateKWLoc, Name, Tok.
is(tok::l_paren),
1283 isAddressOfOperand, &Validator,
1285 Tok.
is(tok::r_paren) ?
nullptr : &Replacement);
1287 UnconsumeToken(Replacement);
1288 return ParseCastExpression(ParseKind, isAddressOfOperand,
1289 NotCastExpr, isTypeCast,
1291 NotPrimaryExpression);
1294 checkPotentialAngleBracket(Res);
1297 case tok::char_constant:
1298 case tok::wide_char_constant:
1299 case tok::utf8_char_constant:
1300 case tok::utf16_char_constant:
1301 case tok::utf32_char_constant:
1305 case tok::kw___func__:
1306 case tok::kw___FUNCTION__:
1307 case tok::kw___FUNCDNAME__:
1308 case tok::kw___FUNCSIG__:
1309 case tok::kw_L__FUNCTION__:
1310 case tok::kw_L__FUNCSIG__:
1311 case tok::kw___PRETTY_FUNCTION__:
1323 case tok::string_literal:
1324 case tok::wide_string_literal:
1325 case tok::utf8_string_literal:
1326 case tok::utf16_string_literal:
1327 case tok::utf32_string_literal:
1330 case tok::kw__Generic:
1331 Res = ParseGenericSelectionExpression();
1333 case tok::kw___builtin_available:
1334 Res = ParseAvailabilityCheckExpr(Tok.
getLocation());
1336 case tok::kw___builtin_va_arg:
1337 case tok::kw___builtin_offsetof:
1338 case tok::kw___builtin_choose_expr:
1339 case tok::kw___builtin_astype:
1340 case tok::kw___builtin_convertvector:
1341 case tok::kw___builtin_COLUMN:
1342 case tok::kw___builtin_FILE:
1343 case tok::kw___builtin_FILE_NAME:
1344 case tok::kw___builtin_FUNCTION:
1345 case tok::kw___builtin_FUNCSIG:
1346 case tok::kw___builtin_LINE:
1347 case tok::kw___builtin_source_location:
1348 if (NotPrimaryExpression)
1349 *NotPrimaryExpression =
true;
1351 return ParseBuiltinPrimaryExpression();
1352 case tok::kw___null:
1357 case tok::minusminus: {
1358 if (NotPrimaryExpression)
1359 *NotPrimaryExpression =
true;
1364 Token SavedTok = Tok;
1373 UnaryExprOnly : AnyCastExpr,
1380 UnconsumeToken(SavedTok);
1394 if (NotPrimaryExpression)
1395 *NotPrimaryExpression =
true;
1400 Res = ParseCastExpression(AnyCastExpr,
true);
1416 case tok::kw___real:
1417 case tok::kw___imag: {
1418 if (NotPrimaryExpression)
1419 *NotPrimaryExpression =
true;
1422 Res = ParseCastExpression(AnyCastExpr);
1426 isAddressOfOperand);
1433 case tok::kw_co_await: {
1434 if (NotPrimaryExpression)
1435 *NotPrimaryExpression =
true;
1437 Res = ParseCastExpression(AnyCastExpr);
1443 case tok::kw___extension__:{
1445 if (NotPrimaryExpression)
1446 *NotPrimaryExpression =
true;
1449 Res = ParseCastExpression(AnyCastExpr);
1454 case tok::kw__Alignof:
1456 Diag(Tok, diag::ext_c11_feature) << Tok.
getName();
1458 case tok::kw_alignof:
1459 case tok::kw___alignof:
1461 case tok::kw_sizeof:
1465 case tok::kw___datasizeof:
1466 case tok::kw_vec_step:
1468 case tok::kw___builtin_omp_required_simd_align:
1469 case tok::kw___builtin_vectorelements:
1470 if (NotPrimaryExpression)
1471 *NotPrimaryExpression =
true;
1472 AllowSuffix =
false;
1473 Res = ParseUnaryExprOrTypeTraitExpression();
1476 if (NotPrimaryExpression)
1477 *NotPrimaryExpression =
true;
1479 if (Tok.
isNot(tok::identifier))
1480 return ExprError(
Diag(Tok, diag::err_expected) << tok::identifier);
1483 return ExprError(
Diag(Tok, diag::err_address_of_label_outside_fn));
1485 Diag(AmpAmpLoc, diag::ext_gnu_address_of_label);
1490 AllowSuffix =
false;
1493 case tok::kw_const_cast:
1494 case tok::kw_dynamic_cast:
1495 case tok::kw_reinterpret_cast:
1496 case tok::kw_static_cast:
1497 case tok::kw_addrspace_cast:
1498 if (NotPrimaryExpression)
1499 *NotPrimaryExpression =
true;
1500 Res = ParseCXXCasts();
1502 case tok::kw___builtin_bit_cast:
1503 if (NotPrimaryExpression)
1504 *NotPrimaryExpression =
true;
1505 Res = ParseBuiltinBitCast();
1507 case tok::kw_typeid:
1508 if (NotPrimaryExpression)
1509 *NotPrimaryExpression =
true;
1510 Res = ParseCXXTypeid();
1512 case tok::kw___uuidof:
1513 if (NotPrimaryExpression)
1514 *NotPrimaryExpression =
true;
1515 Res = ParseCXXUuidof();
1518 Res = ParseCXXThis();
1520 case tok::kw___builtin_sycl_unique_stable_name:
1521 Res = ParseSYCLUniqueStableNameExpression();
1524 case tok::annot_typename:
1525 if (isStartOfObjCClassMessageMissingOpenBracket()) {
1533 const char *PrevSpec =
nullptr;
1536 PrevSpec, DiagID,
Type,
1545 ConsumeAnnotationToken();
1552 case tok::annot_decltype:
1554 case tok::kw_wchar_t:
1555 case tok::kw_char8_t:
1556 case tok::kw_char16_t:
1557 case tok::kw_char32_t:
1562 case tok::kw___int64:
1563 case tok::kw___int128:
1564 case tok::kw__ExtInt:
1565 case tok::kw__BitInt:
1566 case tok::kw_signed:
1567 case tok::kw_unsigned:
1570 case tok::kw_double:
1571 case tok::kw___bf16:
1572 case tok::kw__Float16:
1573 case tok::kw___float128:
1574 case tok::kw___ibm128:
1577 case tok::kw_typename:
1578 case tok::kw_typeof:
1579 case tok::kw___vector:
1580 case tok::kw__Accum:
1581 case tok::kw__Fract:
1583#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
1584#include "clang/Basic/OpenCLImageTypes.def"
1587 Diag(Tok, diag::err_expected_expression);
1592 if (NotPrimaryExpression)
1593 *NotPrimaryExpression =
true;
1595 if (SavedKind == tok::kw_typename) {
1612 ParseCXXSimpleTypeSpecifier(DS);
1613 if (Tok.
isNot(tok::l_paren) &&
1615 return ExprError(
Diag(Tok, diag::err_expected_lparen_after_type)
1616 << DS.getSourceRange());
1618 if (Tok.
is(tok::l_brace))
1619 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
1621 Res = ParseCXXTypeConstructExpression(DS);
1625 case tok::annot_cxxscope: {
1630 if (!Tok.
is(tok::annot_cxxscope))
1631 return ParseCastExpression(ParseKind, isAddressOfOperand, NotCastExpr,
1632 isTypeCast, isVectorLiteral,
1633 NotPrimaryExpression);
1636 if (Next.is(tok::annot_template_id)) {
1643 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
1647 return ParseCastExpression(ParseKind, isAddressOfOperand, NotCastExpr,
1648 isTypeCast, isVectorLiteral,
1649 NotPrimaryExpression);
1654 Res = ParseCXXIdExpression(isAddressOfOperand);
1658 case tok::annot_template_id: {
1666 return ParseCastExpression(ParseKind, isAddressOfOperand,
1667 NotCastExpr, isTypeCast, isVectorLiteral,
1668 NotPrimaryExpression);
1675 case tok::kw_operator:
1676 Res = ParseCXXIdExpression(isAddressOfOperand);
1679 case tok::coloncolon: {
1684 if (!Tok.
is(tok::coloncolon))
1685 return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast,
1686 isVectorLiteral, NotPrimaryExpression);
1691 if (Tok.
is(tok::kw_new)) {
1692 if (NotPrimaryExpression)
1693 *NotPrimaryExpression =
true;
1694 Res = ParseCXXNewExpression(
true, CCLoc);
1695 AllowSuffix =
false;
1698 if (Tok.
is(tok::kw_delete)) {
1699 if (NotPrimaryExpression)
1700 *NotPrimaryExpression =
true;
1701 Res = ParseCXXDeleteExpression(
true, CCLoc);
1702 AllowSuffix =
false;
1707 Diag(CCLoc, diag::err_expected_expression);
1712 if (NotPrimaryExpression)
1713 *NotPrimaryExpression =
true;
1714 Res = ParseCXXNewExpression(
false, Tok.
getLocation());
1715 AllowSuffix =
false;
1718 case tok::kw_delete:
1719 if (NotPrimaryExpression)
1720 *NotPrimaryExpression =
true;
1721 Res = ParseCXXDeleteExpression(
false, Tok.
getLocation());
1722 AllowSuffix =
false;
1725 case tok::kw_requires:
1726 Res = ParseRequiresExpression();
1727 AllowSuffix =
false;
1730 case tok::kw_noexcept: {
1731 if (NotPrimaryExpression)
1732 *NotPrimaryExpression =
true;
1733 Diag(Tok, diag::warn_cxx98_compat_noexcept_expr);
1737 if (T.expectAndConsume(diag::err_expected_lparen_after,
"noexcept"))
1750 T.getCloseLocation());
1751 AllowSuffix =
false;
1755#define TYPE_TRAIT(N,Spelling,K) \
1756 case tok::kw_##Spelling:
1757#include "clang/Basic/TokenKinds.def"
1758 Res = ParseTypeTrait();
1761 case tok::kw___array_rank:
1762 case tok::kw___array_extent:
1763 if (NotPrimaryExpression)
1764 *NotPrimaryExpression =
true;
1765 Res = ParseArrayTypeTrait();
1768 case tok::kw___is_lvalue_expr:
1769 case tok::kw___is_rvalue_expr:
1770 if (NotPrimaryExpression)
1771 *NotPrimaryExpression =
true;
1772 Res = ParseExpressionTrait();
1776 if (NotPrimaryExpression)
1777 *NotPrimaryExpression =
true;
1779 return ParseObjCAtExpression(AtLoc);
1782 Res = ParseBlockLiteralExpression();
1784 case tok::code_completion: {
1790#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
1791#include "clang/Basic/TransformTypeTraits.def"
1796 Diag(Tok, diag::ext_keyword_as_ident)
1798 goto ParseIdentifier;
1800 goto ExpectedExpression;
1809 Res = TryParseLambdaExpression();
1813 if (NotPrimaryExpression)
1814 *NotPrimaryExpression =
true;
1815 Res = ParseObjCMessageExpression();
1819 Res = ParseLambdaExpression();
1823 Res = ParseObjCMessageExpression();
1837 if (ParseKind == PrimaryExprOnly)
1852 case tok::minusminus:
1870 Diag(Tok.
getLocation(), diag::err_postfix_after_unary_requires_parens)
1878 PreferredType = SavedType;
1879 Res = ParsePostfixExpressionSuffix(Res);
1881 !
getActions().getOpenCLOptions().isAvailableOption(
1883 if (
Expr *PostfixExpr = Res.
get()) {
1884 QualType Ty = PostfixExpr->getType();
1886 Diag(PostfixExpr->getExprLoc(),
1887 diag::err_opencl_taking_function_address_parser);
1917Parser::ParsePostfixExpressionSuffix(
ExprResult LHS) {
1921 auto SavedType = PreferredType;
1924 PreferredType = SavedType;
1926 case tok::code_completion:
1927 if (InMessageExpression)
1935 case tok::identifier:
1942 nullptr, LHS.
get());
1950 case tok::l_square: {
1958 isSimpleObjCMessageExpression())
1963 if (CheckProhibitedCXX11Attribute()) {
1969 Loc = T.getOpenLocation();
1972 ExprVector ArgExprs;
1973 bool HasError =
false;
1984 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
1985 Idx = ParseBraceInitializer();
1994 ArgExprs.push_back(Idx.
get());
1996 }
else if (Tok.
isNot(tok::r_square)) {
1997 if (ParseExpressionList(ArgExprs)) {
2004 if (ArgExprs.size() <= 1 &&
getLangOpts().OpenMP) {
2006 if (Tok.
is(tok::colon)) {
2009 if (Tok.
isNot(tok::r_square) &&
2017 (OMPClauseKind == llvm::omp::Clause::OMPC_to ||
2018 OMPClauseKind == llvm::omp::Clause::OMPC_from) &&
2019 Tok.
is(tok::colon)) {
2022 if (Tok.
isNot(tok::r_square)) {
2035 LHS.
get(), Loc, ArgExprs.empty() ?
nullptr : ArgExprs[0],
2036 ColonLocFirst, ColonLocSecond, Length.
get(), Stride.
get(), RLoc);
2051 case tok::lesslessless: {
2056 Expr *ExecConfig =
nullptr;
2060 if (OpKind == tok::lesslessless) {
2061 ExprVector ExecConfigExprs;
2064 if (ParseSimpleExpressionList(ExecConfigExprs)) {
2075 Diag(Tok, diag::err_expected) << tok::greatergreatergreater;
2076 Diag(OpenLoc, diag::note_matching) << tok::lesslessless;
2082 if (ExpectAndConsume(tok::l_paren))
2085 Loc = PrevTokLocation;
2096 ExecConfig = ECResult.
get();
2100 Loc = PT.getOpenLocation();
2103 ExprVector ArgExprs;
2104 auto RunSignatureHelp = [&]() ->
QualType {
2106 LHS.
get(), ArgExprs, PT.getOpenLocation());
2107 CalledSignatureHelp =
true;
2108 return PreferredType;
2110 if (OpKind == tok::l_paren || !LHS.
isInvalid()) {
2111 if (Tok.
isNot(tok::r_paren)) {
2112 if (ParseExpressionList(ArgExprs, [&] {
2113 PreferredType.enterFunctionArgument(Tok.
getLocation(),
2125 for (
auto &E : ArgExprs)
2134 }
else if (Tok.
isNot(tok::r_paren)) {
2135 bool HadDelayedTypo =
false;
2137 HadDelayedTypo =
true;
2138 for (
auto &E : ArgExprs)
2140 HadDelayedTypo =
true;
2155 ArgExprs.insert(ArgExprs.begin(), Fn);
2173 bool MayBePseudoDestructor =
false;
2176 PreferredType.enterMemAccess(Actions, Tok.
getLocation(), OrigLHS);
2180 const Type* BaseType =
Base->getType().getTypePtrOrNull();
2181 if (BaseType && Tok.
is(tok::l_paren) &&
2184 Diag(OpLoc, diag::err_function_is_not_record)
2185 << OpKind <<
Base->getSourceRange()
2187 return ParsePostfixExpressionSuffix(
Base);
2192 MayBePseudoDestructor);
2197 if (Tok.
is(tok::code_completion)) {
2203 ParseOptionalCXXScopeSpecifier(
2205 false, &MayBePseudoDestructor);
2207 ObjectType =
nullptr;
2210 if (Tok.
is(tok::code_completion)) {
2212 OpKind == tok::arrow ? tok::period : tok::arrow;
2219 getCurScope(), OrigLHS, OpLoc, CorrectedOpKind, ObjectType,
2220 MayBePseudoDestructor);
2224 Expr *CorrectedBase = CorrectedLHS.get();
2226 CorrectedBase =
Base;
2232 Base && ExprStatementTokLoc ==
Base->getBeginLoc(),
2238 if (MayBePseudoDestructor && !LHS.
isInvalid()) {
2239 LHS = ParseCXXPseudoDestructor(LHS.
get(), OpLoc, OpKind, SS,
2254 Tok.
is(tok::kw_class)) {
2264 Name.setIdentifier(
Id, Loc);
2271 false, &TemplateKWLoc, Name)) {
2278 OpKind, SS, TemplateKWLoc, Name,
2279 CurParsedObjCImpl ? CurParsedObjCImpl->Dcl
2282 if (Tok.
is(tok::less))
2283 checkPotentialAngleBracket(LHS);
2284 }
else if (OrigLHS && Name.isValid()) {
2287 Name.getEndLoc(), {OrigLHS});
2292 case tok::minusminus:
2340Parser::ParseExprAfterUnaryExprOrTypeTrait(
const Token &OpTok,
2345 assert(OpTok.
isOneOf(tok::kw_typeof, tok::kw_typeof_unqual, tok::kw_sizeof,
2346 tok::kw___datasizeof, tok::kw___alignof, tok::kw_alignof,
2347 tok::kw__Alignof, tok::kw_vec_step,
2348 tok::kw___builtin_omp_required_simd_align,
2349 tok::kw___builtin_vectorelements) &&
2350 "Not a typeof/sizeof/alignof/vec_step expression!");
2355 if (Tok.
isNot(tok::l_paren)) {
2358 if (OpTok.
isOneOf(tok::kw_sizeof, tok::kw___datasizeof, tok::kw___alignof,
2359 tok::kw_alignof, tok::kw__Alignof)) {
2360 if (isTypeIdUnambiguously()) {
2362 ParseSpecifierQualifierList(DS);
2365 ParseDeclarator(DeclaratorInfo);
2371 diag::err_expected_parentheses_around_typename)
2374 Diag(LParenLoc, diag::err_expected_parentheses_around_typename)
2384 if (OpTok.
isOneOf(tok::kw_typeof, tok::kw_typeof_unqual) &&
2391 Operand = ParseCastExpression(UnaryExprOnly);
2397 ParenParseOption ExprType =
CastExpr;
2400 Operand = ParseParenExpression(ExprType,
true,
2401 false, CastTy, RParenLoc);
2412 !OpTok.
isOneOf(tok::kw_typeof, tok::kw_typeof_unqual)) {
2429ExprResult Parser::ParseSYCLUniqueStableNameExpression() {
2430 assert(Tok.
is(tok::kw___builtin_sycl_unique_stable_name) &&
2431 "Not __builtin_sycl_unique_stable_name");
2437 if (T.expectAndConsume(diag::err_expected_lparen_after,
2438 "__builtin_sycl_unique_stable_name"))
2448 if (T.consumeClose())
2452 T.getCloseLocation(), Ty.
get());
2469ExprResult Parser::ParseUnaryExprOrTypeTraitExpression() {
2470 assert(Tok.
isOneOf(tok::kw_sizeof, tok::kw___datasizeof, tok::kw___alignof,
2471 tok::kw_alignof, tok::kw__Alignof, tok::kw_vec_step,
2472 tok::kw___builtin_omp_required_simd_align,
2473 tok::kw___builtin_vectorelements) &&
2474 "Not a sizeof/alignof/vec_step expression!");
2479 if (Tok.
is(tok::ellipsis) && OpTok.
is(tok::kw_sizeof)) {
2484 if (Tok.
is(tok::l_paren)) {
2487 LParenLoc = T.getOpenLocation();
2488 if (Tok.
is(tok::identifier)) {
2492 RParenLoc = T.getCloseLocation();
2496 Diag(Tok, diag::err_expected_parameter_pack);
2499 }
else if (Tok.
is(tok::identifier)) {
2504 Diag(LParenLoc, diag::err_paren_sizeof_parameter_pack)
2509 Diag(Tok, diag::err_sizeof_parameter_pack);
2526 OpTok.
isOneOf(tok::kw_alignof, tok::kw__Alignof))
2527 Diag(OpTok, diag::warn_cxx98_compat_alignof);
2529 Diag(OpTok, diag::warn_c23_compat_keyword) << OpTok.
getName();
2545 case tok::kw_alignof:
2546 case tok::kw__Alignof:
2547 ExprKind = UETT_AlignOf;
2549 case tok::kw___alignof:
2550 ExprKind = UETT_PreferredAlignOf;
2552 case tok::kw_vec_step:
2553 ExprKind = UETT_VecStep;
2555 case tok::kw___builtin_omp_required_simd_align:
2556 ExprKind = UETT_OpenMPRequiredSimdAlign;
2558 case tok::kw___datasizeof:
2559 ExprKind = UETT_DataSizeOf;
2561 case tok::kw___builtin_vectorelements:
2562 ExprKind = UETT_VectorElements;
2575 if (OpTok.
isOneOf(tok::kw_alignof, tok::kw__Alignof))
2611ExprResult Parser::ParseBuiltinPrimaryExpression() {
2619 if (Tok.
isNot(tok::l_paren))
2620 return ExprError(
Diag(Tok, diag::err_expected_after) << BuiltinII
2629 default: llvm_unreachable(
"Not a builtin primary expression!");
2630 case tok::kw___builtin_va_arg: {
2633 if (ExpectAndConsume(tok::comma)) {
2640 if (Tok.
isNot(tok::r_paren)) {
2641 Diag(Tok, diag::err_expected) << tok::r_paren;
2651 case tok::kw___builtin_offsetof: {
2657 if (MacroName ==
"offsetof")
2670 if (ExpectAndConsume(tok::comma)) {
2676 if (Tok.
isNot(tok::identifier)) {
2677 Diag(Tok, diag::err_expected) << tok::identifier;
2686 Comps.back().isBrackets =
false;
2688 Comps.back().LocStart = Comps.back().LocEnd =
ConsumeToken();
2692 if (Tok.
is(tok::period)) {
2695 Comps.back().isBrackets =
false;
2698 if (Tok.
isNot(tok::identifier)) {
2699 Diag(Tok, diag::err_expected) << tok::identifier;
2705 }
else if (Tok.
is(tok::l_square)) {
2706 if (CheckProhibitedCXX11Attribute())
2711 Comps.back().isBrackets =
true;
2714 Comps.back().LocStart = ST.getOpenLocation();
2720 Comps.back().U.E = Res.
get();
2723 Comps.back().LocEnd = ST.getCloseLocation();
2725 if (Tok.
isNot(tok::r_paren)) {
2734 PT.getCloseLocation());
2741 case tok::kw___builtin_choose_expr: {
2743 if (Cond.isInvalid()) {
2747 if (ExpectAndConsume(tok::comma)) {
2753 if (Expr1.isInvalid()) {
2757 if (ExpectAndConsume(tok::comma)) {
2763 if (Expr2.isInvalid()) {
2767 if (Tok.
isNot(tok::r_paren)) {
2768 Diag(Tok, diag::err_expected) << tok::r_paren;
2772 Expr2.get(), ConsumeParen());
2775 case tok::kw___builtin_astype: {
2778 if (
Expr.isInvalid()) {
2783 if (ExpectAndConsume(tok::comma)) {
2794 if (Tok.
isNot(tok::r_paren)) {
2795 Diag(Tok, diag::err_expected) << tok::r_paren;
2804 case tok::kw___builtin_convertvector: {
2807 if (
Expr.isInvalid()) {
2812 if (ExpectAndConsume(tok::comma)) {
2823 if (Tok.
isNot(tok::r_paren)) {
2824 Diag(Tok, diag::err_expected) << tok::r_paren;
2833 case tok::kw___builtin_COLUMN:
2834 case tok::kw___builtin_FILE:
2835 case tok::kw___builtin_FILE_NAME:
2836 case tok::kw___builtin_FUNCTION:
2837 case tok::kw___builtin_FUNCSIG:
2838 case tok::kw___builtin_LINE:
2839 case tok::kw___builtin_source_location: {
2841 if (Tok.
isNot(tok::r_paren)) {
2842 Diag(Tok, diag::err_expected) << tok::r_paren;
2848 case tok::kw___builtin_FILE:
2850 case tok::kw___builtin_FILE_NAME:
2852 case tok::kw___builtin_FUNCTION:
2854 case tok::kw___builtin_FUNCSIG:
2856 case tok::kw___builtin_LINE:
2858 case tok::kw___builtin_COLUMN:
2860 case tok::kw___builtin_source_location:
2863 llvm_unreachable(
"invalid keyword");
2876 return ParsePostfixExpressionSuffix(Res.
get());
2879bool Parser::tryParseOpenMPArrayShapingCastPart() {
2880 assert(Tok.
is(tok::l_square) &&
"Expected open bracket");
2881 bool ErrorFound =
true;
2882 TentativeParsingAction TPA(*
this);
2884 if (Tok.
isNot(tok::l_square))
2889 while (!
SkipUntil(tok::r_square, tok::annot_pragma_openmp_end,
2892 if (Tok.
isNot(tok::r_square))
2897 if (Tok.
is(tok::r_paren)) {
2901 }
while (Tok.
isNot(tok::annot_pragma_openmp_end));
2934Parser::ParseParenExpression(ParenParseOption &ExprType,
bool stopIfCastExpr,
2937 assert(Tok.
is(tok::l_paren) &&
"Not a paren expr!");
2940 if (T.consumeOpen())
2944 PreferredType.enterParenExpr(Tok.
getLocation(), OpenLoc);
2947 bool isAmbiguousTypeId;
2950 if (Tok.
is(tok::code_completion)) {
2954 ExprType >= CompoundLiteral);
2961 tok::kw___bridge_transfer,
2962 tok::kw___bridge_retained,
2963 tok::kw___bridge_retain));
2964 if (BridgeCast && !
getLangOpts().ObjCAutoRefCount) {
2966 StringRef BridgeCastName = Tok.
getName();
2969 Diag(BridgeKeywordLoc, diag::warn_arc_bridge_cast_nonarc)
2979 Diag(Tok, OpenLoc.
isMacroID() ? diag::ext_gnu_statement_expr_macro
2980 : diag::ext_gnu_statement_expr);
2982 checkCompoundToken(OpenLoc, tok::l_paren, CompoundToken::StmtExprBegin);
2991 while (CodeDC->
isRecord() || isa<EnumDecl>(CodeDC)) {
2994 "statement expr not in code context");
3004 if (!
Stmt.isInvalid()) {
3011 }
else if (ExprType >= CompoundLiteral && BridgeCast) {
3017 if (tokenKind == tok::kw___bridge)
3019 else if (tokenKind == tok::kw___bridge_transfer)
3021 else if (tokenKind == tok::kw___bridge_retained)
3026 assert(tokenKind == tok::kw___bridge_retain);
3029 Diag(BridgeKeywordLoc, diag::err_arc_bridge_retain)
3031 "__bridge_retained");
3036 ColonProtection.restore();
3037 RParenLoc = T.getCloseLocation();
3040 ExprResult SubExpr = ParseCastExpression(AnyCastExpr);
3046 BridgeKeywordLoc, Ty.
get(),
3047 RParenLoc, SubExpr.
get());
3048 }
else if (ExprType >= CompoundLiteral &&
3049 isTypeIdInParens(isAmbiguousTypeId)) {
3058 if (isAmbiguousTypeId && !stopIfCastExpr) {
3059 ExprResult res = ParseCXXAmbiguousParenExpression(ExprType, CastTy, T,
3061 RParenLoc = T.getCloseLocation();
3067 ParseSpecifierQualifierList(DS);
3070 ParseDeclarator(DeclaratorInfo);
3075 if (!DeclaratorInfo.isInvalidType() && Tok.
is(tok::identifier) &&
3089 ColonProtection.restore();
3090 RParenLoc = T.getCloseLocation();
3091 if (Tok.
is(tok::l_brace)) {
3092 ExprType = CompoundLiteral;
3098 return ParseCompoundLiteralExpression(Ty.
get(), OpenLoc, RParenLoc);
3101 if (Tok.
is(tok::l_paren)) {
3122 Result = ParseCastExpression(AnyCastExpr,
3127 if (!
Result.isInvalid()) {
3129 DeclaratorInfo, CastTy,
3130 RParenLoc,
Result.get());
3134 if (!
Result.isInvalid()) {
3146 if (DeclaratorInfo.isInvalidType())
3151 if (stopIfCastExpr) {
3165 GetLookAheadToken(1).isNot(tok::period)) {
3174 Result = ParseCastExpression(AnyCastExpr,
3177 if (!
Result.isInvalid()) {
3179 DeclaratorInfo, CastTy,
3180 RParenLoc,
Result.get());
3185 Diag(Tok, diag::err_expected_lbrace_in_compound_literal);
3188 }
else if (ExprType >= FoldExpr && Tok.
is(tok::ellipsis) &&
3190 ExprType = FoldExpr;
3192 }
else if (isTypeCast) {
3195 ExprVector ArgExprs;
3197 if (!ParseSimpleExpressionList(ArgExprs)) {
3200 if (ExprType >= FoldExpr && ArgExprs.size() == 1 &&
3202 ExprType = FoldExpr;
3203 return ParseFoldExpression(ArgExprs[0], T);
3206 ExprType = SimpleExpr;
3210 }
else if (
getLangOpts().OpenMP >= 50 && OpenMPDirectiveParsing &&
3211 ExprType ==
CastExpr && Tok.
is(tok::l_square) &&
3212 tryParseOpenMPArrayShapingCastPart()) {
3213 bool ErrorFound =
false;
3223 while (!
SkipUntil(tok::r_square, tok::r_paren,
3228 OMPDimensions.push_back(NumElements.
get());
3229 OMPBracketsRanges.push_back(TS.getRange());
3230 }
while (Tok.
isNot(tok::r_paren));
3233 RParenLoc = T.getCloseLocation();
3237 }
else if (!
Result.isInvalid()) {
3239 Result.get(), OpenLoc, RParenLoc, OMPDimensions, OMPBracketsRanges);
3252 if (ExprType >= FoldExpr && isFoldOperator(Tok.
getKind()) &&
3254 ExprType = FoldExpr;
3255 return ParseFoldExpression(
Result, T);
3257 ExprType = SimpleExpr;
3260 if (!
Result.isInvalid() && Tok.
is(tok::r_paren))
3266 if (
Result.isInvalid()) {
3272 RParenLoc = T.getCloseLocation();
3285Parser::ParseCompoundLiteralExpression(
ParsedType Ty,
3288 assert(Tok.
is(tok::l_brace) &&
"Not a compound literal!");
3290 Diag(LParenLoc, diag::ext_c99_compound_literal);
3293 if (!
Result.isInvalid() && Ty)
3319 "Not a string-literal-like token!");
3327 StringToks.push_back(Tok);
3332 assert(!AllowUserDefinedLiteral &&
"UDL are always evaluated");
3361ExprResult Parser::ParseGenericSelectionExpression() {
3362 assert(Tok.
is(tok::kw__Generic) &&
"_Generic keyword expected");
3364 Diag(Tok, diag::ext_c11_feature) << Tok.
getName();
3368 if (T.expectAndConsume())
3375 if (isTypeIdForGenericSelection()) {
3381 const auto *LIT = cast<LocInfoType>(ControllingType.
get().get());
3382 SourceLocation Loc = LIT->getTypeSourceInfo()->getTypeLoc().getBeginLoc();
3383 Diag(Loc, diag::ext_generic_with_type_arg);
3397 if (ExpectAndConsume(tok::comma)) {
3407 if (Tok.
is(tok::kw_default)) {
3411 Diag(Tok, diag::err_duplicate_default_assoc);
3412 Diag(DefaultLoc, diag::note_previous_default_assoc);
3427 Types.push_back(Ty);
3429 if (ExpectAndConsume(tok::colon)) {
3438 if (ER.isInvalid()) {
3442 Exprs.push_back(ER.get());
3446 if (T.getCloseLocation().isInvalid())
3449 void *ExprOrTy = ControllingExpr.
isUsable()
3450 ? ControllingExpr.
get()
3451 : ControllingType.
get().getAsOpaquePtr();
3454 KeyLoc, DefaultLoc, T.getCloseLocation(), ControllingExpr.
isUsable(),
3455 ExprOrTy, Types, Exprs);
3477 assert(isFoldOperator(Kind) &&
"missing fold-operator");
3481 assert(Tok.
is(tok::ellipsis) &&
"not a fold-expression");
3485 if (Tok.
isNot(tok::r_paren)) {
3486 if (!isFoldOperator(Tok.
getKind()))
3489 if (Kind != tok::unknown && Tok.
getKind() != Kind)
3503 ? diag::warn_cxx14_compat_fold_expression
3504 : diag::ext_fold_expression);
3508 Kind, EllipsisLoc, RHS.
get(),
3535 llvm::function_ref<
void()> ExpressionStarts,
3536 bool FailImmediatelyOnInvalidExpr,
3537 bool EarlyTypoCorrection) {
3538 bool SawError =
false;
3540 if (ExpressionStarts)
3545 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
3546 Expr = ParseBraceInitializer();
3550 if (EarlyTypoCorrection)
3553 if (Tok.
is(tok::ellipsis))
3555 else if (Tok.
is(tok::code_completion)) {
3565 if (
Expr.isInvalid()) {
3567 if (FailImmediatelyOnInvalidExpr)
3571 Exprs.push_back(
Expr.get());
3574 if (Tok.
isNot(tok::comma))
3579 checkPotentialAngleBracketDelimiter(Comma);
3584 for (
auto &E : Exprs) {
3586 if (
Expr.isUsable()) E =
Expr.get();
3603 if (
Expr.isInvalid())
3606 Exprs.push_back(
Expr.get());
3616 checkPotentialAngleBracketDelimiter(Comma);
3627 if (Tok.
is(tok::code_completion)) {
3635 ParseSpecifierQualifierList(DS);
3641 ParseDeclarator(DeclaratorInfo);
3643 MaybeParseGNUAttributes(DeclaratorInfo);
3659ExprResult Parser::ParseBlockLiteralExpression() {
3660 assert(Tok.
is(tok::caret) &&
"block literal starts with ^");
3664 "block literal parsing");
3687 if (Tok.
is(tok::l_paren)) {
3688 ParseParenDeclarator(ParamInfo);
3693 ParamInfo.SetIdentifier(
nullptr, CaretLoc);
3694 ParamInfo.SetRangeEnd(Tmp);
3695 if (ParamInfo.isInvalidType()) {
3703 MaybeParseGNUAttributes(ParamInfo);
3707 }
else if (!Tok.
is(tok::l_brace)) {
3708 ParseBlockId(CaretLoc);
3712 ParamInfo.AddTypeInfo(
3730 CaretLoc, CaretLoc, ParamInfo),
3733 MaybeParseGNUAttributes(ParamInfo);
3741 if (!Tok.
is(tok::l_brace)) {
3743 Diag(Tok, diag::err_expected_expression);
3750 if (!
Stmt.isInvalid())
3770 llvm::SmallSet<StringRef, 4> Platforms;
3771 bool HasOtherPlatformSpec =
false;
3773 for (
const auto &Spec : AvailSpecs) {
3774 if (Spec.isOtherPlatformSpec()) {
3775 if (HasOtherPlatformSpec) {
3776 P.Diag(Spec.getBeginLoc(), diag::err_availability_query_repeated_star);
3780 HasOtherPlatformSpec =
true;
3784 bool Inserted = Platforms.insert(Spec.getPlatform()).second;
3789 StringRef Platform = Spec.getPlatform();
3790 P.Diag(Spec.getBeginLoc(), diag::err_availability_query_repeated_platform)
3791 << Spec.getEndLoc() << Platform;
3796 if (!HasOtherPlatformSpec) {
3797 SourceLocation InsertWildcardLoc = AvailSpecs.back().getEndLoc();
3798 P.Diag(InsertWildcardLoc, diag::err_availability_query_wildcard_required)
3811std::optional<AvailabilitySpec> Parser::ParseAvailabilitySpec() {
3812 if (Tok.
is(tok::star)) {
3816 if (Tok.
is(tok::code_completion)) {
3819 return std::nullopt;
3821 if (Tok.
isNot(tok::identifier)) {
3822 Diag(Tok, diag::err_avail_query_expected_platform_name);
3823 return std::nullopt;
3828 VersionTuple Version = ParseVersionTuple(VersionRange);
3830 if (Version.empty())
3831 return std::nullopt;
3833 StringRef GivenPlatform = PlatformIdentifier->
Ident->
getName();
3834 StringRef Platform =
3835 AvailabilityAttr::canonicalizePlatformName(GivenPlatform);
3837 if (AvailabilityAttr::getPrettyPlatformName(Platform).empty()) {
3839 diag::err_avail_query_unrecognized_platform_name)
3841 return std::nullopt;
3850 assert(Tok.
is(tok::kw___builtin_available) ||
3857 if (Parens.expectAndConsume())
3861 bool HasError =
false;
3863 std::optional<AvailabilitySpec> Spec = ParseAvailabilitySpec();
3867 AvailSpecs.push_back(*Spec);
3880 if (Parens.consumeClose())
3884 Parens.getCloseLocation());
Defines the clang::ASTContext interface.
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.
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type.
ExprResult ParseConstantExpression()
bool TryConsumeToken(tok::TokenKind Expected)
Scope * getCurScope() const
ExprResult ParseArrayBoundExpression()
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 ParseUnevaluatedStringLiteralExpression()
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'.
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)
ExprResult ActOnUnevaluatedStringLiteral(ArrayRef< Token > StringToks)
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 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 .
ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool PredicateIsExpr, void *ControllingExprOrType, ArrayRef< ParsedType > ArgTypes, ArrayRef< Expr * > ArgExprs)
ControllingExprOrType is either an opaque pointer coming out of a ParsedType or an Expr *.
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 ActOnSourceLocExpr(SourceLocIdentKind Kind, SourceLocation BuiltinLoc, SourceLocation RPLoc)
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.
bool tokenIsLikeStringLiteral(const Token &Tok, const LangOptions &LO)
Return true if the token is a string literal, or a function local predefined macro,...
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
@ 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.