32 #include "llvm/ADT/SmallVector.h"
33 using namespace clang;
125 return ParseRHSOfBinaryExpression(LHS,
prec::Comma);
136 return ParseRHSOfBinaryExpression(LHS,
prec::Comma);
143 Parser::ParseExpressionWithLeadingExtension(
SourceLocation ExtLoc) {
149 LHS = ParseCastExpression(AnyCastExpr);
152 if (!LHS.isInvalid())
156 return ParseRHSOfBinaryExpression(LHS,
prec::Comma);
161 if (Tok.
is(tok::code_completion)) {
168 if (Tok.
is(tok::kw_throw))
169 return ParseThrowExpression();
170 if (Tok.
is(tok::kw_co_yield))
171 return ParseCoyieldExpression();
173 ExprResult LHS = ParseCastExpression(AnyCastExpr,
189 Parser::ParseAssignmentExprWithObjCMessageExprStart(
SourceLocation LBracLoc,
192 Expr *ReceiverExpr) {
194 = ParseObjCMessageExpressionBody(LBracLoc, SuperLoc,
195 ReceiverType, ReceiverExpr);
196 R = ParsePostfixExpressionSuffix(R);
204 "Call this function only if your ExpressionEvaluationContext is "
205 "already ConstantEvaluated");
206 ExprResult LHS(ParseCastExpression(AnyCastExpr,
false, isTypeCast));
238 ExprResult LHS(ParseCastExpression(AnyCastExpr));
260 bool NotPrimaryExpression =
false;
261 auto ParsePrimary = [&] () {
262 ExprResult E = ParseCastExpression(PrimaryExprOnly,
266 &NotPrimaryExpression);
269 auto RecoverFromNonPrimary = [&] (
ExprResult E,
bool Note) {
270 E = ParsePostfixExpressionSuffix(E);
277 ? diag::note_unparenthesized_non_primary_expr_in_requires_clause
278 : diag::err_unparenthesized_non_primary_expr_in_requires_clause)
286 if (NotPrimaryExpression ||
293 Tok.
isOneOf(tok::period, tok::plusplus, tok::minusminus) ||
294 (Tok.
is(tok::l_square) && !
NextToken().is(tok::l_square))) {
295 E = RecoverFromNonPrimary(E,
false);
298 NotPrimaryExpression =
false;
300 bool PossibleNonPrimary;
301 bool IsConstraintExpr =
303 IsTrailingRequiresClause);
304 if (!IsConstraintExpr || PossibleNonPrimary) {
309 if (PossibleNonPrimary)
310 E = RecoverFromNonPrimary(E, !IsConstraintExpr);
319 while (Tok.
is(tok::ampamp)) {
327 tok::ampamp, LHS.
get(), RHS.
get());
353 while (Tok.
is(tok::pipepipe)) {
362 tok::pipepipe, LHS.
get(), RHS.
get());
373 bool Parser::isNotExpressionStart() {
375 if (K == tok::l_brace || K == tok::r_brace ||
376 K == tok::kw_for || K == tok::kw_while ||
377 K == tok::kw_if || K == tok::kw_else ||
378 K == tok::kw_goto || K == tok::kw_try)
381 return isKnownToBeDeclarationSpecifier();
398 GreaterThanIsOperator,
402 auto SavedType = PreferredType;
405 PreferredType = SavedType;
409 if (NextTokPrec < MinPrec)
416 if (OpToken.
is(tok::caretcaret)) {
417 return ExprError(
Diag(Tok, diag::err_opencl_logical_exclusive_or));
422 if (OpToken.
isOneOf(tok::comma, tok::greater, tok::greatergreater,
423 tok::greatergreatergreater) &&
424 checkPotentialAngleBracketDelimiter(OpToken))
432 if (OpToken.
is(tok::comma) && isNotExpressionStart()) {
440 if (isFoldOperator(NextTokPrec) && Tok.
is(tok::ellipsis)) {
454 Tok.
isOneOf(tok::colon, tok::r_square) &&
467 TernaryMiddle = ParseBraceInitializer();
468 if (!TernaryMiddle.isInvalid()) {
469 Diag(BraceLoc, diag::err_init_list_bin_op)
474 }
else if (Tok.
isNot(tok::colon)) {
486 TernaryMiddle =
nullptr;
487 Diag(Tok, diag::ext_gnu_conditional_expr);
490 if (TernaryMiddle.isInvalid()) {
493 TernaryMiddle =
nullptr;
502 const char *FIText =
": ";
506 bool IsInvalid =
false;
507 const char *SourcePtr =
509 if (!IsInvalid && *SourcePtr ==
' ') {
512 if (!IsInvalid && *SourcePtr ==
' ') {
519 Diag(Tok, diag::err_expected)
521 Diag(OpToken, diag::note_matching) << tok::question;
539 bool RHSIsInitList =
false;
541 RHS = ParseBraceInitializer();
542 RHSIsInitList =
true;
546 RHS = ParseCastExpression(AnyCastExpr);
552 if (TernaryMiddle.isUsable())
569 if (ThisPrec < NextTokPrec ||
570 (ThisPrec == NextTokPrec && isRightAssoc)) {
572 Diag(Tok, diag::err_init_list_bin_op)
581 RHS = ParseRHSOfBinaryExpression(RHS,
582 static_cast<prec::Level>(ThisPrec + !isRightAssoc));
583 RHSIsInitList =
false;
589 if (TernaryMiddle.isUsable())
600 Diag(OpToken, diag::warn_cxx98_compat_generalized_initializer_lists)
602 }
else if (ColonLoc.
isValid()) {
603 Diag(ColonLoc, diag::err_init_list_bin_op)
608 Diag(OpToken, diag::err_init_list_bin_op)
618 if (TernaryMiddle.isInvalid()) {
622 if (!GreaterThanIsOperator && OpToken.
is(tok::greatergreater))
624 diag::warn_cxx11_right_shift_in_template_arg,
634 {LHS.get(), RHS.get()});
642 std::vector<clang::Expr *> Args;
644 if (TernaryMiddle.get())
645 Args = {LHS.
get(), TernaryMiddle.get(), RHS.
get()};
647 Args = {LHS.
get(), RHS.
get()};
675 ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
676 bool isAddressOfOperand,
677 TypeCastState isTypeCast,
678 bool isVectorLiteral,
679 bool *NotPrimaryExpression) {
681 ExprResult Res = ParseCastExpression(ParseKind,
686 NotPrimaryExpression);
688 Diag(Tok, diag::err_expected_expression);
695 CastExpressionIdValidator(
Token Next,
bool AllowTypes,
bool AllowNonTypes)
696 : NextToken(Next), AllowNonTypes(AllowNonTypes) {
697 WantTypeSpecifiers = WantFunctionLikeCasts = AllowTypes;
700 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
705 if (isa<TypeDecl>(ND))
706 return WantTypeSpecifiers;
711 if (!NextToken.isOneOf(tok::equal, tok::arrow, tok::period))
714 for (
auto *C : candidate) {
716 if (isa<ValueDecl>(ND) && !isa<FunctionDecl>(ND))
722 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
723 return std::make_unique<CastExpressionIdValidator>(*
this);
913 ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
914 bool isAddressOfOperand,
916 TypeCastState isTypeCast,
917 bool isVectorLiteral,
918 bool *NotPrimaryExpression) {
921 auto SavedType = PreferredType;
927 bool AllowSuffix =
true;
943 ParenParseOption ParenExprType;
945 case CastParseKind::UnaryExprOnly:
947 ParenExprType = CompoundLiteral;
949 case CastParseKind::AnyCastExpr:
950 ParenExprType = ParenParseOption::CastExpr;
952 case CastParseKind::PrimaryExprOnly:
953 ParenExprType = FoldExpr;
958 Res = ParseParenExpression(ParenExprType,
false,
967 switch (ParenExprType) {
968 case SimpleExpr:
break;
970 case CompoundLiteral:
988 case tok::numeric_constant:
998 Res = ParseCXXBoolLiteral();
1001 case tok::kw___objc_yes:
1002 case tok::kw___objc_no:
1003 Res = ParseObjCBoolLiteral();
1006 case tok::kw_nullptr:
1007 Diag(Tok, diag::warn_cxx98_compat_nullptr);
1011 case tok::annot_primary_expr:
1012 case tok::annot_overload_set:
1013 Res = getExprAnnotation(Tok);
1016 ConsumeAnnotationToken();
1018 checkPotentialAngleBracket(Res);
1021 case tok::annot_non_type:
1022 case tok::annot_non_type_dependent:
1023 case tok::annot_non_type_undeclared: {
1026 Res = tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement);
1028 "should not perform typo correction on annotation token");
1032 case tok::kw___super:
1033 case tok::kw_decltype:
1037 assert(Tok.
isNot(tok::kw_decltype) && Tok.
isNot(tok::kw___super));
1038 return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast,
1039 isVectorLiteral, NotPrimaryExpression);
1041 case tok::identifier: {
1054 if (Next.is(tok::l_paren) &&
1055 Tok.
is(tok::identifier) &&
1059 if (RevertibleTypeTraits.empty()) {
1060 #define RTT_JOIN(X,Y) X##Y
1061 #define REVERTIBLE_TYPE_TRAIT(Name) \
1062 RevertibleTypeTraits[PP.getIdentifierInfo(#Name)] \
1063 = RTT_JOIN(tok::kw_,Name)
1116 #undef REVERTIBLE_TYPE_TRAIT
1123 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind>::iterator Known
1124 = RevertibleTypeTraits.find(II);
1125 if (Known != RevertibleTypeTraits.end()) {
1127 return ParseCastExpression(ParseKind, isAddressOfOperand,
1128 NotCastExpr, isTypeCast,
1129 isVectorLiteral, NotPrimaryExpression);
1133 if ((!ColonIsSacred && Next.is(tok::colon)) ||
1134 Next.isOneOf(tok::coloncolon, tok::less, tok::l_paren,
1139 if (!Tok.
is(tok::identifier))
1140 return ParseCastExpression(ParseKind, isAddressOfOperand,
1141 NotCastExpr, isTypeCast,
1143 NotPrimaryExpression);
1156 (&II == Ident_super &&
getCurScope()->isInObjcMethodScope()))) {
1159 if (Tok.
is(tok::code_completion) && &II != Ident_super) {
1162 getCurScope(), II, ILoc, ExprStatementTokLoc == ILoc);
1166 if (Tok.
isNot(tok::identifier) &&
1168 Diag(Tok, diag::err_expected_property_name);
1183 if (
getLangOpts().ObjC && &II == Ident_super && !InMessageExpression &&
1185 ((Tok.
is(tok::identifier) &&
1187 Tok.
is(tok::code_completion))) {
1188 Res = ParseObjCMessageExpressionBody(
SourceLocation(), ILoc,
nullptr,
1199 ((Tok.
is(tok::identifier) && !InMessageExpression) ||
1200 Tok.
is(tok::code_completion))) {
1202 if (Tok.
is(tok::code_completion) ||
1203 Next.is(tok::colon) || Next.is(tok::r_square))
1205 if (Typ.get()->isObjCObjectOrInterfaceType()) {
1208 DS.SetRangeStart(ILoc);
1209 DS.SetRangeEnd(ILoc);
1210 const char *PrevSpec =
nullptr;
1212 DS.SetTypeSpecType(
TST_typename, ILoc, PrevSpec, DiagID, Typ,
1229 if (isAddressOfOperand && isPostfixExpressionSuffixStart())
1230 isAddressOfOperand =
false;
1239 CastExpressionIdValidator Validator(
1243 Validator.IsAddressOfOperand = isAddressOfOperand;
1244 if (Tok.
isOneOf(tok::periodstar, tok::arrowstar)) {
1245 Validator.WantExpressionKeywords =
false;
1246 Validator.WantRemainingKeywords =
false;
1248 Validator.WantRemainingKeywords = Tok.
isNot(tok::r_paren);
1250 Name.setIdentifier(&II, ILoc);
1252 getCurScope(), ScopeSpec, TemplateKWLoc, Name, Tok.
is(tok::l_paren),
1253 isAddressOfOperand, &Validator,
1255 Tok.
is(tok::r_paren) ?
nullptr : &Replacement);
1257 UnconsumeToken(Replacement);
1258 return ParseCastExpression(ParseKind, isAddressOfOperand,
1259 NotCastExpr, isTypeCast,
1261 NotPrimaryExpression);
1264 checkPotentialAngleBracket(Res);
1267 case tok::char_constant:
1268 case tok::wide_char_constant:
1269 case tok::utf8_char_constant:
1270 case tok::utf16_char_constant:
1271 case tok::utf32_char_constant:
1275 case tok::kw___func__:
1276 case tok::kw___FUNCTION__:
1277 case tok::kw___FUNCDNAME__:
1278 case tok::kw___FUNCSIG__:
1279 case tok::kw_L__FUNCTION__:
1280 case tok::kw_L__FUNCSIG__:
1281 case tok::kw___PRETTY_FUNCTION__:
1285 case tok::string_literal:
1286 case tok::wide_string_literal:
1287 case tok::utf8_string_literal:
1288 case tok::utf16_string_literal:
1289 case tok::utf32_string_literal:
1292 case tok::kw__Generic:
1293 Res = ParseGenericSelectionExpression();
1295 case tok::kw___builtin_available:
1296 Res = ParseAvailabilityCheckExpr(Tok.
getLocation());
1298 case tok::kw___builtin_va_arg:
1299 case tok::kw___builtin_offsetof:
1300 case tok::kw___builtin_choose_expr:
1301 case tok::kw___builtin_astype:
1302 case tok::kw___builtin_convertvector:
1303 case tok::kw___builtin_COLUMN:
1304 case tok::kw___builtin_FILE:
1305 case tok::kw___builtin_FUNCTION:
1306 case tok::kw___builtin_LINE:
1307 case tok::kw___builtin_source_location:
1308 if (NotPrimaryExpression)
1309 *NotPrimaryExpression =
true;
1311 return ParseBuiltinPrimaryExpression();
1312 case tok::kw___null:
1317 case tok::minusminus: {
1318 if (NotPrimaryExpression)
1319 *NotPrimaryExpression =
true;
1324 Token SavedTok = Tok;
1333 UnaryExprOnly : AnyCastExpr,
1340 UnconsumeToken(SavedTok);
1354 if (NotPrimaryExpression)
1355 *NotPrimaryExpression =
true;
1359 Res = ParseCastExpression(AnyCastExpr,
true);
1375 case tok::kw___real:
1376 case tok::kw___imag: {
1377 if (NotPrimaryExpression)
1378 *NotPrimaryExpression =
true;
1381 Res = ParseCastExpression(AnyCastExpr);
1391 case tok::kw_co_await: {
1392 if (NotPrimaryExpression)
1393 *NotPrimaryExpression =
true;
1395 Res = ParseCastExpression(AnyCastExpr);
1401 case tok::kw___extension__:{
1403 if (NotPrimaryExpression)
1404 *NotPrimaryExpression =
true;
1407 Res = ParseCastExpression(AnyCastExpr);
1412 case tok::kw__Alignof:
1414 Diag(Tok, diag::ext_c11_feature) << Tok.
getName();
1416 case tok::kw_alignof:
1417 case tok::kw___alignof:
1419 case tok::kw_sizeof:
1421 case tok::kw_vec_step:
1423 case tok::kw___builtin_omp_required_simd_align:
1424 if (NotPrimaryExpression)
1425 *NotPrimaryExpression =
true;
1426 AllowSuffix =
false;
1427 Res = ParseUnaryExprOrTypeTraitExpression();
1430 if (NotPrimaryExpression)
1431 *NotPrimaryExpression =
true;
1433 if (Tok.
isNot(tok::identifier))
1434 return ExprError(
Diag(Tok, diag::err_expected) << tok::identifier);
1437 return ExprError(
Diag(Tok, diag::err_address_of_label_outside_fn));
1439 Diag(AmpAmpLoc, diag::ext_gnu_address_of_label);
1444 AllowSuffix =
false;
1447 case tok::kw_const_cast:
1448 case tok::kw_dynamic_cast:
1449 case tok::kw_reinterpret_cast:
1450 case tok::kw_static_cast:
1451 case tok::kw_addrspace_cast:
1452 if (NotPrimaryExpression)
1453 *NotPrimaryExpression =
true;
1454 Res = ParseCXXCasts();
1456 case tok::kw___builtin_bit_cast:
1457 if (NotPrimaryExpression)
1458 *NotPrimaryExpression =
true;
1459 Res = ParseBuiltinBitCast();
1461 case tok::kw_typeid:
1462 if (NotPrimaryExpression)
1463 *NotPrimaryExpression =
true;
1464 Res = ParseCXXTypeid();
1466 case tok::kw___uuidof:
1467 if (NotPrimaryExpression)
1468 *NotPrimaryExpression =
true;
1469 Res = ParseCXXUuidof();
1472 Res = ParseCXXThis();
1474 case tok::kw___builtin_sycl_unique_stable_name:
1475 Res = ParseSYCLUniqueStableNameExpression();
1478 case tok::annot_typename:
1479 if (isStartOfObjCClassMessageMissingOpenBracket()) {
1487 const char *PrevSpec =
nullptr;
1490 PrevSpec, DiagID,
Type,
1498 ConsumeAnnotationToken();
1505 case tok::annot_decltype:
1507 case tok::kw_wchar_t:
1508 case tok::kw_char8_t:
1509 case tok::kw_char16_t:
1510 case tok::kw_char32_t:
1515 case tok::kw___int64:
1516 case tok::kw___int128:
1517 case tok::kw__ExtInt:
1518 case tok::kw__BitInt:
1519 case tok::kw_signed:
1520 case tok::kw_unsigned:
1523 case tok::kw_double:
1524 case tok::kw___bf16:
1525 case tok::kw__Float16:
1526 case tok::kw___float128:
1527 case tok::kw___ibm128:
1530 case tok::kw_typename:
1531 case tok::kw_typeof:
1532 case tok::kw___vector:
1533 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
1534 #include "clang/Basic/OpenCLImageTypes.def"
1537 Diag(Tok, diag::err_expected_expression);
1542 if (NotPrimaryExpression)
1543 *NotPrimaryExpression =
true;
1545 if (SavedKind == tok::kw_typename) {
1562 ParseCXXSimpleTypeSpecifier(DS);
1563 if (Tok.
isNot(tok::l_paren) &&
1565 return ExprError(
Diag(Tok, diag::err_expected_lparen_after_type)
1566 << DS.getSourceRange());
1568 if (Tok.
is(tok::l_brace))
1569 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
1571 Res = ParseCXXTypeConstructExpression(DS);
1575 case tok::annot_cxxscope: {
1580 if (!Tok.
is(tok::annot_cxxscope))
1581 return ParseCastExpression(ParseKind, isAddressOfOperand, NotCastExpr,
1582 isTypeCast, isVectorLiteral,
1583 NotPrimaryExpression);
1586 if (Next.is(tok::annot_template_id)) {
1593 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
1596 AnnotateTemplateIdTokenAsType(SS);
1597 return ParseCastExpression(ParseKind, isAddressOfOperand, NotCastExpr,
1598 isTypeCast, isVectorLiteral,
1599 NotPrimaryExpression);
1604 Res = ParseCXXIdExpression(isAddressOfOperand);
1608 case tok::annot_template_id: {
1615 AnnotateTemplateIdTokenAsType(SS);
1616 return ParseCastExpression(ParseKind, isAddressOfOperand,
1617 NotCastExpr, isTypeCast, isVectorLiteral,
1618 NotPrimaryExpression);
1625 case tok::kw_operator:
1626 Res = ParseCXXIdExpression(isAddressOfOperand);
1629 case tok::coloncolon: {
1634 if (!Tok.
is(tok::coloncolon))
1635 return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast,
1636 isVectorLiteral, NotPrimaryExpression);
1641 if (Tok.
is(tok::kw_new)) {
1642 if (NotPrimaryExpression)
1643 *NotPrimaryExpression =
true;
1644 Res = ParseCXXNewExpression(
true, CCLoc);
1645 AllowSuffix =
false;
1648 if (Tok.
is(tok::kw_delete)) {
1649 if (NotPrimaryExpression)
1650 *NotPrimaryExpression =
true;
1651 Res = ParseCXXDeleteExpression(
true, CCLoc);
1652 AllowSuffix =
false;
1657 Diag(CCLoc, diag::err_expected_expression);
1662 if (NotPrimaryExpression)
1663 *NotPrimaryExpression =
true;
1664 Res = ParseCXXNewExpression(
false, Tok.
getLocation());
1665 AllowSuffix =
false;
1668 case tok::kw_delete:
1669 if (NotPrimaryExpression)
1670 *NotPrimaryExpression =
true;
1671 Res = ParseCXXDeleteExpression(
false, Tok.
getLocation());
1672 AllowSuffix =
false;
1675 case tok::kw_requires:
1676 Res = ParseRequiresExpression();
1677 AllowSuffix =
false;
1680 case tok::kw_noexcept: {
1681 if (NotPrimaryExpression)
1682 *NotPrimaryExpression =
true;
1683 Diag(Tok, diag::warn_cxx98_compat_noexcept_expr);
1687 if (T.expectAndConsume(diag::err_expected_lparen_after,
"noexcept"))
1700 T.getCloseLocation());
1701 AllowSuffix =
false;
1705 #define TYPE_TRAIT(N,Spelling,K) \
1706 case tok::kw_##Spelling:
1707 #include "clang/Basic/TokenKinds.def"
1708 Res = ParseTypeTrait();
1711 case tok::kw___array_rank:
1712 case tok::kw___array_extent:
1713 if (NotPrimaryExpression)
1714 *NotPrimaryExpression =
true;
1715 Res = ParseArrayTypeTrait();
1718 case tok::kw___is_lvalue_expr:
1719 case tok::kw___is_rvalue_expr:
1720 if (NotPrimaryExpression)
1721 *NotPrimaryExpression =
true;
1722 Res = ParseExpressionTrait();
1726 if (NotPrimaryExpression)
1727 *NotPrimaryExpression =
true;
1729 return ParseObjCAtExpression(AtLoc);
1732 Res = ParseBlockLiteralExpression();
1734 case tok::code_completion: {
1748 Res = TryParseLambdaExpression();
1752 if (NotPrimaryExpression)
1753 *NotPrimaryExpression =
true;
1754 Res = ParseObjCMessageExpression();
1758 Res = ParseLambdaExpression();
1762 Res = ParseObjCMessageExpression();
1775 if (ParseKind == PrimaryExprOnly)
1790 case tok::minusminus:
1808 Diag(Tok.
getLocation(), diag::err_postfix_after_unary_requires_parens)
1816 PreferredType = SavedType;
1817 Res = ParsePostfixExpressionSuffix(Res);
1819 !
getActions().getOpenCLOptions().isAvailableOption(
1821 if (
Expr *PostfixExpr = Res.
get()) {
1822 QualType Ty = PostfixExpr->getType();
1824 Diag(PostfixExpr->getExprLoc(),
1825 diag::err_opencl_taking_function_address_parser);
1855 Parser::ParsePostfixExpressionSuffix(
ExprResult LHS) {
1859 auto SavedType = PreferredType;
1862 PreferredType = SavedType;
1864 case tok::code_completion:
1865 if (InMessageExpression)
1873 case tok::identifier:
1880 nullptr, LHS.
get());
1888 case tok::l_square: {
1896 isSimpleObjCMessageExpression())
1901 if (CheckProhibitedCXX11Attribute()) {
1907 Loc = T.getOpenLocation();
1910 ExprVector ArgExprs;
1911 bool HasError =
false;
1922 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
1923 Idx = ParseBraceInitializer();
1932 ArgExprs.push_back(Idx.
get());
1934 }
else if (Tok.
isNot(tok::r_square)) {
1935 CommaLocsTy CommaLocs;
1936 if (ParseExpressionList(ArgExprs, CommaLocs)) {
1941 (ArgExprs.empty() || ArgExprs.size() == CommaLocs.size() + 1) &&
1942 "Unexpected number of commas!");
1946 if (ArgExprs.size() <= 1 &&
getLangOpts().OpenMP) {
1948 if (Tok.
is(tok::colon)) {
1951 if (Tok.
isNot(tok::r_square) &&
1959 (OMPClauseKind == llvm::omp::Clause::OMPC_to ||
1960 OMPClauseKind == llvm::omp::Clause::OMPC_from) &&
1961 Tok.
is(tok::colon)) {
1964 if (Tok.
isNot(tok::r_square)) {
1977 LHS.
get(), Loc, ArgExprs.empty() ?
nullptr : ArgExprs[0],
1978 ColonLocFirst, ColonLocSecond, Length.
get(), Stride.
get(), RLoc);
1993 case tok::lesslessless: {
1998 Expr *ExecConfig =
nullptr;
2002 if (OpKind == tok::lesslessless) {
2003 ExprVector ExecConfigExprs;
2004 CommaLocsTy ExecConfigCommaLocs;
2007 if (ParseSimpleExpressionList(ExecConfigExprs, ExecConfigCommaLocs)) {
2018 Diag(Tok, diag::err_expected) << tok::greatergreatergreater;
2019 Diag(OpenLoc, diag::note_matching) << tok::lesslessless;
2025 if (ExpectAndConsume(tok::l_paren))
2028 Loc = PrevTokLocation;
2039 ExecConfig = ECResult.
get();
2043 Loc = PT.getOpenLocation();
2046 ExprVector ArgExprs;
2047 CommaLocsTy CommaLocs;
2048 auto RunSignatureHelp = [&]() ->
QualType {
2050 LHS.
get(), ArgExprs, PT.getOpenLocation());
2051 CalledSignatureHelp =
true;
2052 return PreferredType;
2054 if (OpKind == tok::l_paren || !LHS.
isInvalid()) {
2055 if (Tok.
isNot(tok::r_paren)) {
2056 if (ParseExpressionList(ArgExprs, CommaLocs, [&] {
2057 PreferredType.enterFunctionArgument(Tok.
getLocation(),
2069 for (
auto &E : ArgExprs)
2078 }
else if (Tok.
isNot(tok::r_paren)) {
2079 bool HadDelayedTypo =
false;
2081 HadDelayedTypo =
true;
2082 for (
auto &E : ArgExprs)
2084 HadDelayedTypo =
true;
2095 (ArgExprs.size() == 0 || ArgExprs.size() - 1 == CommaLocs.size()) &&
2096 "Unexpected number of commas!");
2102 ArgExprs.insert(ArgExprs.begin(), Fn);
2120 bool MayBePseudoDestructor =
false;
2123 PreferredType.enterMemAccess(Actions, Tok.
getLocation(), OrigLHS);
2127 const Type* BaseType =
Base->getType().getTypePtrOrNull();
2128 if (BaseType && Tok.
is(tok::l_paren) &&
2131 Diag(OpLoc, diag::err_function_is_not_record)
2132 << OpKind <<
Base->getSourceRange()
2134 return ParsePostfixExpressionSuffix(
Base);
2139 MayBePseudoDestructor);
2144 if (Tok.
is(tok::code_completion)) {
2150 ParseOptionalCXXScopeSpecifier(
2152 false, &MayBePseudoDestructor);
2154 ObjectType =
nullptr;
2157 if (Tok.
is(tok::code_completion)) {
2159 OpKind == tok::arrow ? tok::period : tok::arrow;
2166 getCurScope(), OrigLHS, OpLoc, CorrectedOpKind, ObjectType,
2167 MayBePseudoDestructor);
2171 Expr *CorrectedBase = CorrectedLHS.get();
2173 CorrectedBase =
Base;
2179 Base && ExprStatementTokLoc ==
Base->getBeginLoc(),
2185 if (MayBePseudoDestructor && !LHS.
isInvalid()) {
2186 LHS = ParseCXXPseudoDestructor(LHS.
get(), OpLoc, OpKind, SS,
2200 if (
getLangOpts().ObjC && OpKind == tok::period &&
2201 Tok.
is(tok::kw_class)) {
2211 Name.setIdentifier(
Id, Loc);
2218 false, &TemplateKWLoc, Name)) {
2225 OpKind, SS, TemplateKWLoc, Name,
2226 CurParsedObjCImpl ? CurParsedObjCImpl->Dcl
2229 if (Tok.
is(tok::less))
2230 checkPotentialAngleBracket(LHS);
2231 }
else if (OrigLHS && Name.isValid()) {
2234 Name.getEndLoc(), {OrigLHS});
2239 case tok::minusminus:
2278 Parser::ParseExprAfterUnaryExprOrTypeTrait(
const Token &OpTok,
2283 assert(OpTok.
isOneOf(tok::kw_typeof, tok::kw_sizeof, tok::kw___alignof,
2284 tok::kw_alignof, tok::kw__Alignof, tok::kw_vec_step,
2285 tok::kw___builtin_omp_required_simd_align) &&
2286 "Not a typeof/sizeof/alignof/vec_step expression!");
2291 if (Tok.
isNot(tok::l_paren)) {
2294 if (OpTok.
isOneOf(tok::kw_sizeof, tok::kw___alignof, tok::kw_alignof,
2295 tok::kw__Alignof)) {
2296 if (isTypeIdUnambiguously()) {
2298 ParseSpecifierQualifierList(DS);
2300 ParseDeclarator(DeclaratorInfo);
2306 diag::err_expected_parentheses_around_typename)
2309 Diag(LParenLoc, diag::err_expected_parentheses_around_typename)
2325 Operand = ParseCastExpression(UnaryExprOnly);
2331 ParenParseOption ExprType =
CastExpr;
2334 Operand = ParseParenExpression(ExprType,
true,
2335 false, CastTy, RParenLoc);
2362 ExprResult Parser::ParseSYCLUniqueStableNameExpression() {
2363 assert(Tok.
is(tok::kw___builtin_sycl_unique_stable_name) &&
2364 "Not __builtin_sycl_unique_stable_name");
2370 if (T.expectAndConsume(diag::err_expected_lparen_after,
2371 "__builtin_sycl_unique_stable_name"))
2381 if (T.consumeClose())
2385 T.getCloseLocation(), Ty.
get());
2400 ExprResult Parser::ParseUnaryExprOrTypeTraitExpression() {
2401 assert(Tok.
isOneOf(tok::kw_sizeof, tok::kw___alignof, tok::kw_alignof,
2402 tok::kw__Alignof, tok::kw_vec_step,
2403 tok::kw___builtin_omp_required_simd_align) &&
2404 "Not a sizeof/alignof/vec_step expression!");
2409 if (Tok.
is(tok::ellipsis) && OpTok.
is(tok::kw_sizeof)) {
2414 if (Tok.
is(tok::l_paren)) {
2417 LParenLoc = T.getOpenLocation();
2418 if (Tok.
is(tok::identifier)) {
2422 RParenLoc = T.getCloseLocation();
2426 Diag(Tok, diag::err_expected_parameter_pack);
2429 }
else if (Tok.
is(tok::identifier)) {
2434 Diag(LParenLoc, diag::err_paren_sizeof_parameter_pack)
2439 Diag(Tok, diag::err_sizeof_parameter_pack);
2455 if (OpTok.
isOneOf(tok::kw_alignof, tok::kw__Alignof))
2456 Diag(OpTok, diag::warn_cxx98_compat_alignof);
2471 if (OpTok.
isOneOf(tok::kw_alignof, tok::kw__Alignof))
2472 ExprKind = UETT_AlignOf;
2473 else if (OpTok.
is(tok::kw___alignof))
2474 ExprKind = UETT_PreferredAlignOf;
2475 else if (OpTok.
is(tok::kw_vec_step))
2476 ExprKind = UETT_VecStep;
2477 else if (OpTok.
is(tok::kw___builtin_omp_required_simd_align))
2478 ExprKind = UETT_OpenMPRequiredSimdAlign;
2487 if (OpTok.
isOneOf(tok::kw_alignof, tok::kw__Alignof))
2521 ExprResult Parser::ParseBuiltinPrimaryExpression() {
2529 if (Tok.
isNot(tok::l_paren))
2530 return ExprError(
Diag(Tok, diag::err_expected_after) << BuiltinII
2539 default: llvm_unreachable(
"Not a builtin primary expression!");
2540 case tok::kw___builtin_va_arg: {
2543 if (ExpectAndConsume(tok::comma)) {
2550 if (Tok.
isNot(tok::r_paren)) {
2551 Diag(Tok, diag::err_expected) << tok::r_paren;
2561 case tok::kw___builtin_offsetof: {
2569 if (ExpectAndConsume(tok::comma)) {
2575 if (Tok.
isNot(tok::identifier)) {
2576 Diag(Tok, diag::err_expected) << tok::identifier;
2585 Comps.back().isBrackets =
false;
2587 Comps.back().LocStart = Comps.back().LocEnd =
ConsumeToken();
2591 if (Tok.
is(tok::period)) {
2594 Comps.back().isBrackets =
false;
2597 if (Tok.
isNot(tok::identifier)) {
2598 Diag(Tok, diag::err_expected) << tok::identifier;
2605 }
else if (Tok.
is(tok::l_square)) {
2606 if (CheckProhibitedCXX11Attribute())
2611 Comps.back().isBrackets =
true;
2614 Comps.back().LocStart = ST.getOpenLocation();
2620 Comps.back().U.E = Res.
get();
2623 Comps.back().LocEnd = ST.getCloseLocation();
2625 if (Tok.
isNot(tok::r_paren)) {
2634 PT.getCloseLocation());
2641 case tok::kw___builtin_choose_expr: {
2643 if (Cond.isInvalid()) {
2647 if (ExpectAndConsume(tok::comma)) {
2653 if (Expr1.isInvalid()) {
2657 if (ExpectAndConsume(tok::comma)) {
2663 if (Expr2.isInvalid()) {
2667 if (Tok.
isNot(tok::r_paren)) {
2668 Diag(Tok, diag::err_expected) << tok::r_paren;
2672 Expr2.get(), ConsumeParen());
2675 case tok::kw___builtin_astype: {
2678 if (
Expr.isInvalid()) {
2683 if (ExpectAndConsume(tok::comma)) {
2694 if (Tok.
isNot(tok::r_paren)) {
2695 Diag(Tok, diag::err_expected) << tok::r_paren;
2704 case tok::kw___builtin_convertvector: {
2707 if (
Expr.isInvalid()) {
2712 if (ExpectAndConsume(tok::comma)) {
2723 if (Tok.
isNot(tok::r_paren)) {
2724 Diag(Tok, diag::err_expected) << tok::r_paren;
2733 case tok::kw___builtin_COLUMN:
2734 case tok::kw___builtin_FILE:
2735 case tok::kw___builtin_FUNCTION:
2736 case tok::kw___builtin_LINE:
2737 case tok::kw___builtin_source_location: {
2739 if (Tok.
isNot(tok::r_paren)) {
2740 Diag(Tok, diag::err_expected) << tok::r_paren;
2746 case tok::kw___builtin_FILE:
2748 case tok::kw___builtin_FUNCTION:
2750 case tok::kw___builtin_LINE:
2752 case tok::kw___builtin_COLUMN:
2754 case tok::kw___builtin_source_location:
2757 llvm_unreachable(
"invalid keyword");
2770 return ParsePostfixExpressionSuffix(Res.
get());
2773 bool Parser::tryParseOpenMPArrayShapingCastPart() {
2774 assert(Tok.
is(tok::l_square) &&
"Expected open bracket");
2775 bool ErrorFound =
true;
2776 TentativeParsingAction TPA(*
this);
2778 if (Tok.
isNot(tok::l_square))
2783 while (!
SkipUntil(tok::r_square, tok::annot_pragma_openmp_end,
2786 if (Tok.
isNot(tok::r_square))
2791 if (Tok.
is(tok::r_paren)) {
2795 }
while (Tok.
isNot(tok::annot_pragma_openmp_end));
2828 Parser::ParseParenExpression(ParenParseOption &ExprType,
bool stopIfCastExpr,
2831 assert(Tok.
is(tok::l_paren) &&
"Not a paren expr!");
2834 if (T.consumeOpen())
2838 PreferredType.enterParenExpr(Tok.
getLocation(), OpenLoc);
2841 bool isAmbiguousTypeId;
2844 if (Tok.
is(tok::code_completion)) {
2848 ExprType >= CompoundLiteral);
2855 tok::kw___bridge_transfer,
2856 tok::kw___bridge_retained,
2857 tok::kw___bridge_retain));
2858 if (BridgeCast && !
getLangOpts().ObjCAutoRefCount) {
2860 StringRef BridgeCastName = Tok.
getName();
2863 Diag(BridgeKeywordLoc, diag::warn_arc_bridge_cast_nonarc)
2873 Diag(Tok, diag::ext_gnu_statement_expr);
2875 checkCompoundToken(OpenLoc, tok::l_paren, CompoundToken::StmtExprBegin);
2878 Result =
ExprError(
Diag(OpenLoc, diag::err_stmtexpr_file_scope));
2884 while (CodeDC->
isRecord() || isa<EnumDecl>(CodeDC)) {
2887 "statement expr not in code context");
2897 if (!
Stmt.isInvalid()) {
2904 }
else if (ExprType >= CompoundLiteral && BridgeCast) {
2910 if (tokenKind == tok::kw___bridge)
2912 else if (tokenKind == tok::kw___bridge_transfer)
2914 else if (tokenKind == tok::kw___bridge_retained)
2919 assert(tokenKind == tok::kw___bridge_retain);
2922 Diag(BridgeKeywordLoc, diag::err_arc_bridge_retain)
2924 "__bridge_retained");
2929 ColonProtection.restore();
2930 RParenLoc = T.getCloseLocation();
2933 ExprResult SubExpr = ParseCastExpression(AnyCastExpr);
2939 BridgeKeywordLoc, Ty.
get(),
2940 RParenLoc, SubExpr.
get());
2941 }
else if (ExprType >= CompoundLiteral &&
2942 isTypeIdInParens(isAmbiguousTypeId)) {
2951 if (isAmbiguousTypeId && !stopIfCastExpr) {
2952 ExprResult res = ParseCXXAmbiguousParenExpression(ExprType, CastTy, T,
2954 RParenLoc = T.getCloseLocation();
2960 ParseSpecifierQualifierList(DS);
2962 ParseDeclarator(DeclaratorInfo);
2967 if (!DeclaratorInfo.isInvalidType() && Tok.
is(tok::identifier) &&
2981 ColonProtection.restore();
2982 RParenLoc = T.getCloseLocation();
2983 if (Tok.
is(tok::l_brace)) {
2984 ExprType = CompoundLiteral;
2990 return ParseCompoundLiteralExpression(Ty.
get(), OpenLoc, RParenLoc);
2993 if (Tok.
is(tok::l_paren)) {
3014 Result = ParseCastExpression(AnyCastExpr,
3019 if (!Result.isInvalid()) {
3021 DeclaratorInfo, CastTy,
3022 RParenLoc, Result.get());
3026 if (!Result.isInvalid()) {
3027 Result = ParsePostfixExpressionSuffix(Result);
3038 if (DeclaratorInfo.isInvalidType())
3043 if (stopIfCastExpr) {
3057 GetLookAheadToken(1).isNot(tok::period)) {
3066 Result = ParseCastExpression(AnyCastExpr,
3069 if (!Result.isInvalid()) {
3071 DeclaratorInfo, CastTy,
3072 RParenLoc, Result.get());
3077 Diag(Tok, diag::err_expected_lbrace_in_compound_literal);
3080 }
else if (ExprType >= FoldExpr && Tok.
is(tok::ellipsis) &&
3082 ExprType = FoldExpr;
3084 }
else if (isTypeCast) {
3088 ExprVector ArgExprs;
3089 CommaLocsTy CommaLocs;
3091 if (!ParseSimpleExpressionList(ArgExprs, CommaLocs)) {
3094 if (ExprType >= FoldExpr && ArgExprs.size() == 1 &&
3096 ExprType = FoldExpr;
3097 return ParseFoldExpression(ArgExprs[0], T);
3100 ExprType = SimpleExpr;
3104 }
else if (
getLangOpts().OpenMP >= 50 && OpenMPDirectiveParsing &&
3105 ExprType ==
CastExpr && Tok.
is(tok::l_square) &&
3106 tryParseOpenMPArrayShapingCastPart()) {
3107 bool ErrorFound =
false;
3117 while (!
SkipUntil(tok::r_square, tok::r_paren,
3122 OMPDimensions.push_back(NumElements.
get());
3123 OMPBracketsRanges.push_back(TS.getRange());
3124 }
while (Tok.
isNot(tok::r_paren));
3127 RParenLoc = T.getCloseLocation();
3131 }
else if (!Result.isInvalid()) {
3133 Result.get(), OpenLoc, RParenLoc, OMPDimensions, OMPBracketsRanges);
3146 if (ExprType >= FoldExpr && isFoldOperator(Tok.
getKind()) &&
3148 ExprType = FoldExpr;
3149 return ParseFoldExpression(Result, T);
3151 ExprType = SimpleExpr;
3154 if (!Result.isInvalid() && Tok.
is(tok::r_paren))
3160 if (Result.isInvalid()) {
3166 RParenLoc = T.getCloseLocation();
3179 Parser::ParseCompoundLiteralExpression(
ParsedType Ty,
3182 assert(Tok.
is(tok::l_brace) &&
"Not a compound literal!");
3184 Diag(LParenLoc, diag::ext_c99_compound_literal);
3187 if (!Result.isInvalid() && Ty)
3201 assert(isTokenStringLiteral() &&
"Not a string literal!");
3208 StringToks.push_back(Tok);
3209 ConsumeStringToken();
3210 }
while (isTokenStringLiteral());
3231 ExprResult Parser::ParseGenericSelectionExpression() {
3232 assert(Tok.
is(tok::kw__Generic) &&
"_Generic keyword expected");
3234 Diag(Tok, diag::ext_c11_feature) << Tok.
getName();
3238 if (T.expectAndConsume())
3255 if (ExpectAndConsume(tok::comma)) {
3265 if (Tok.
is(tok::kw_default)) {
3269 Diag(Tok, diag::err_duplicate_default_assoc);
3270 Diag(DefaultLoc, diag::note_previous_default_assoc);
3285 Types.push_back(Ty);
3287 if (ExpectAndConsume(tok::colon)) {
3296 if (ER.isInvalid()) {
3300 Exprs.push_back(ER.get());
3304 if (T.getCloseLocation().isInvalid())
3308 T.getCloseLocation(),
3309 ControllingExpr.
get(),
3332 assert(isFoldOperator(
Kind) &&
"missing fold-operator");
3336 assert(Tok.
is(tok::ellipsis) &&
"not a fold-expression");
3340 if (Tok.
isNot(tok::r_paren)) {
3341 if (!isFoldOperator(Tok.
getKind()))
3358 ? diag::warn_cxx14_compat_fold_expression
3359 : diag::ext_fold_expression);
3391 llvm::function_ref<
void()> ExpressionStarts,
3392 bool FailImmediatelyOnInvalidExpr,
3393 bool EarlyTypoCorrection) {
3394 bool SawError =
false;
3396 if (ExpressionStarts)
3401 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
3402 Expr = ParseBraceInitializer();
3406 if (EarlyTypoCorrection)
3409 if (Tok.
is(tok::ellipsis))
3411 else if (Tok.
is(tok::code_completion)) {
3421 if (
Expr.isInvalid()) {
3423 if (FailImmediatelyOnInvalidExpr)
3427 Exprs.push_back(
Expr.get());
3430 if (Tok.
isNot(tok::comma))
3436 checkPotentialAngleBracketDelimiter(Comma);
3441 for (
auto &E : Exprs) {
3443 if (
Expr.isUsable()) E =
Expr.get();
3462 if (
Expr.isInvalid())
3465 Exprs.push_back(
Expr.get());
3467 if (Tok.
isNot(tok::comma))
3474 checkPotentialAngleBracketDelimiter(Comma);
3485 if (Tok.
is(tok::code_completion)) {
3493 ParseSpecifierQualifierList(DS);
3498 ParseDeclarator(DeclaratorInfo);
3500 MaybeParseGNUAttributes(DeclaratorInfo);
3516 ExprResult Parser::ParseBlockLiteralExpression() {
3517 assert(Tok.
is(tok::caret) &&
"block literal starts with ^");
3521 "block literal parsing");
3543 if (Tok.
is(tok::l_paren)) {
3544 ParseParenDeclarator(ParamInfo);
3549 ParamInfo.SetIdentifier(
nullptr, CaretLoc);
3550 ParamInfo.SetRangeEnd(Tmp);
3551 if (ParamInfo.isInvalidType()) {
3559 MaybeParseGNUAttributes(ParamInfo);
3563 }
else if (!Tok.
is(tok::l_brace)) {
3564 ParseBlockId(CaretLoc);
3568 ParamInfo.AddTypeInfo(
3586 CaretLoc, ParamInfo),
3589 MaybeParseGNUAttributes(ParamInfo);
3597 if (!Tok.
is(tok::l_brace)) {
3599 Diag(Tok, diag::err_expected_expression);
3606 if (!
Stmt.isInvalid())
3626 llvm::SmallSet<StringRef, 4> Platforms;
3627 bool HasOtherPlatformSpec =
false;
3629 for (
const auto &Spec : AvailSpecs) {
3630 if (Spec.isOtherPlatformSpec()) {
3631 if (HasOtherPlatformSpec) {
3632 P.Diag(Spec.getBeginLoc(), diag::err_availability_query_repeated_star);
3636 HasOtherPlatformSpec =
true;
3640 bool Inserted = Platforms.insert(Spec.getPlatform()).second;
3645 StringRef Platform = Spec.getPlatform();
3646 P.Diag(Spec.getBeginLoc(), diag::err_availability_query_repeated_platform)
3647 << Spec.getEndLoc() << Platform;
3652 if (!HasOtherPlatformSpec) {
3653 SourceLocation InsertWildcardLoc = AvailSpecs.back().getEndLoc();
3654 P.Diag(InsertWildcardLoc, diag::err_availability_query_wildcard_required)
3668 if (Tok.
is(tok::star)) {
3672 if (Tok.
is(tok::code_completion)) {
3677 if (Tok.
isNot(tok::identifier)) {
3678 Diag(Tok, diag::err_avail_query_expected_platform_name);
3684 VersionTuple Version = ParseVersionTuple(VersionRange);
3686 if (Version.empty())
3689 StringRef GivenPlatform = PlatformIdentifier->
Ident->
getName();
3690 StringRef Platform =
3691 AvailabilityAttr::canonicalizePlatformName(GivenPlatform);
3693 if (AvailabilityAttr::getPrettyPlatformName(Platform).empty()) {
3695 diag::err_avail_query_unrecognized_platform_name)
3706 assert(Tok.
is(tok::kw___builtin_available) ||
3713 if (Parens.expectAndConsume())
3717 bool HasError =
false;
3723 AvailSpecs.push_back(*Spec);
3736 if (Parens.consumeClose())
3740 Parens.getCloseLocation());