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);
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);
270 E = ParsePostfixExpressionSuffix(E);
277 ? diag::note_unparenthesized_non_primary_expr_in_requires_clause
278 : diag::err_unparenthesized_non_primary_expr_in_requires_clause)
282 << E.
get()->getSourceRange();
286 if (NotPrimaryExpression ||
293 Tok.
isOneOf(tok::period, tok::plusplus, tok::minusminus) ||
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();
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);
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);
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;
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)
622 if (!GreaterThanIsOperator && OpToken.
is(tok::greatergreater))
624 diag::warn_cxx11_right_shift_in_template_arg,
633 LHS.
get(), TernaryMiddle.
get(),
657 ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
658 bool isAddressOfOperand,
660 bool isVectorLiteral,
661 bool *NotPrimaryExpression) {
663 ExprResult Res = ParseCastExpression(ParseKind,
668 NotPrimaryExpression);
670 Diag(Tok, diag::err_expected_expression);
677 CastExpressionIdValidator(
Token Next,
bool AllowTypes,
bool AllowNonTypes)
678 :
NextToken(Next), AllowNonTypes(AllowNonTypes) {
679 WantTypeSpecifiers = WantFunctionLikeCasts = AllowTypes;
682 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
687 if (isa<TypeDecl>(ND))
688 return WantTypeSpecifiers;
696 for (
auto *
C : candidate) {
698 if (isa<ValueDecl>(ND) && !isa<FunctionDecl>(ND))
704 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
705 return std::make_unique<CastExpressionIdValidator>(*this);
894 ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
895 bool isAddressOfOperand,
898 bool isVectorLiteral,
899 bool *NotPrimaryExpression) {
902 auto SavedType = PreferredType;
920 ParenParseOption ParenExprType;
922 case CastParseKind::UnaryExprOnly:
924 ParenExprType = CompoundLiteral;
926 case CastParseKind::AnyCastExpr:
927 ParenExprType = ParenParseOption::CastExpr;
929 case CastParseKind::PrimaryExprOnly:
930 ParenExprType = FoldExpr;
935 Res = ParseParenExpression(ParenExprType,
false,
941 switch (ParenExprType) {
942 case SimpleExpr:
break;
944 case CompoundLiteral:
962 case tok::numeric_constant:
966 Res = Actions.ActOnNumericConstant(Tok,
getCurScope());
972 Res = ParseCXXBoolLiteral();
975 case tok::kw___objc_yes:
976 case tok::kw___objc_no:
977 return ParseObjCBoolLiteral();
979 case tok::kw_nullptr:
980 Diag(Tok, diag::warn_cxx98_compat_nullptr);
983 case tok::annot_primary_expr:
984 Res = getExprAnnotation(Tok);
985 ConsumeAnnotationToken();
987 checkPotentialAngleBracket(Res);
990 case tok::annot_non_type:
991 case tok::annot_non_type_dependent:
992 case tok::annot_non_type_undeclared: {
995 Res = tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement);
997 "should not perform typo correction on annotation token");
1001 case tok::kw___super:
1002 case tok::kw_decltype:
1006 assert(Tok.
isNot(tok::kw_decltype) && Tok.
isNot(tok::kw___super));
1007 return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast,
1008 isVectorLiteral, NotPrimaryExpression);
1010 case tok::identifier: {
1023 if (Next.
is(tok::l_paren) &&
1024 Tok.
is(tok::identifier) &&
1025 Tok.getIdentifierInfo()->hasRevertedTokenIDToIdentifier()) {
1028 if (RevertibleTypeTraits.empty()) {
1029 #define RTT_JOIN(X,Y) X##Y 1030 #define REVERTIBLE_TYPE_TRAIT(Name) \ 1031 RevertibleTypeTraits[PP.getIdentifierInfo(#Name)] \ 1032 = RTT_JOIN(tok::kw_,Name) 1085 #undef REVERTIBLE_TYPE_TRAIT 1092 llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind>::iterator Known
1093 = RevertibleTypeTraits.find(II);
1094 if (Known != RevertibleTypeTraits.end()) {
1095 Tok.setKind(Known->second);
1096 return ParseCastExpression(ParseKind, isAddressOfOperand,
1097 NotCastExpr, isTypeCast,
1098 isVectorLiteral, NotPrimaryExpression);
1102 if ((!ColonIsSacred && Next.
is(tok::colon)) ||
1103 Next.
isOneOf(tok::coloncolon, tok::less, tok::l_paren,
1108 if (!Tok.
is(tok::identifier))
1109 return ParseCastExpression(ParseKind, isAddressOfOperand,
1110 NotCastExpr, isTypeCast,
1112 NotPrimaryExpression);
1128 if (Tok.
is(tok::code_completion) && &II != Ident_super) {
1129 Actions.CodeCompleteObjCClassPropertyRefExpr(
1130 getCurScope(), II, ILoc, ExprStatementTokLoc == ILoc);
1135 if (Tok.
isNot(tok::identifier) &&
1137 Diag(Tok, diag::err_expected_property_name);
1143 Res = Actions.ActOnClassPropertyRefExpr(II, PropertyName,
1152 if (
getLangOpts().
ObjC && &II == Ident_super && !InMessageExpression &&
1154 ((Tok.
is(tok::identifier) &&
1156 Tok.
is(tok::code_completion))) {
1157 Res = ParseObjCMessageExpressionBody(
SourceLocation(), ILoc,
nullptr,
1168 ((Tok.
is(tok::identifier) && !InMessageExpression) ||
1169 Tok.
is(tok::code_completion))) {
1171 if (Tok.
is(tok::code_completion) ||
1172 Next.
is(tok::colon) || Next.
is(tok::r_square))
1174 if (Typ.get()->isObjCObjectOrInterfaceType()) {
1179 const char *PrevSpec =
nullptr;
1182 Actions.getASTContext().getPrintingPolicy());
1198 if (isAddressOfOperand && isPostfixExpressionSuffixStart())
1199 isAddressOfOperand =
false;
1208 CastExpressionIdValidator Validator(
1212 Validator.IsAddressOfOperand = isAddressOfOperand;
1213 if (Tok.
isOneOf(tok::periodstar, tok::arrowstar)) {
1214 Validator.WantExpressionKeywords =
false;
1215 Validator.WantRemainingKeywords =
false;
1217 Validator.WantRemainingKeywords = Tok.
isNot(tok::r_paren);
1220 Res = Actions.ActOnIdExpression(
1221 getCurScope(), ScopeSpec, TemplateKWLoc, Name, Tok.
is(tok::l_paren),
1222 isAddressOfOperand, &Validator,
1224 Tok.
is(tok::r_paren) ? nullptr : &Replacement);
1226 UnconsumeToken(Replacement);
1227 return ParseCastExpression(ParseKind, isAddressOfOperand,
1228 NotCastExpr, isTypeCast,
1230 NotPrimaryExpression);
1233 checkPotentialAngleBracket(Res);
1236 case tok::char_constant:
1237 case tok::wide_char_constant:
1238 case tok::utf8_char_constant:
1239 case tok::utf16_char_constant:
1240 case tok::utf32_char_constant:
1241 Res = Actions.ActOnCharacterConstant(Tok,
getCurScope());
1244 case tok::kw___func__:
1245 case tok::kw___FUNCTION__:
1246 case tok::kw___FUNCDNAME__:
1247 case tok::kw___FUNCSIG__:
1248 case tok::kw_L__FUNCTION__:
1249 case tok::kw_L__FUNCSIG__:
1250 case tok::kw___PRETTY_FUNCTION__:
1251 Res = Actions.ActOnPredefinedExpr(Tok.getLocation(), SavedKind);
1254 case tok::string_literal:
1255 case tok::wide_string_literal:
1256 case tok::utf8_string_literal:
1257 case tok::utf16_string_literal:
1258 case tok::utf32_string_literal:
1259 Res = ParseStringLiteralExpression(
true);
1261 case tok::kw__Generic:
1262 Res = ParseGenericSelectionExpression();
1264 case tok::kw___builtin_available:
1265 return ParseAvailabilityCheckExpr(Tok.getLocation());
1266 case tok::kw___builtin_va_arg:
1267 case tok::kw___builtin_offsetof:
1268 case tok::kw___builtin_choose_expr:
1269 case tok::kw___builtin_astype:
1270 case tok::kw___builtin_convertvector:
1271 case tok::kw___builtin_COLUMN:
1272 case tok::kw___builtin_FILE:
1273 case tok::kw___builtin_FUNCTION:
1274 case tok::kw___builtin_LINE:
1275 if (NotPrimaryExpression)
1276 *NotPrimaryExpression =
true;
1277 return ParseBuiltinPrimaryExpression();
1278 case tok::kw___null:
1282 case tok::minusminus: {
1283 if (NotPrimaryExpression)
1284 *NotPrimaryExpression =
true;
1289 Token SavedTok = Tok;
1292 PreferredType.enterUnary(Actions, Tok.getLocation(), SavedTok.
getKind(),
1298 UnaryExprOnly : AnyCastExpr,
1305 UnconsumeToken(SavedTok);
1310 SavedKind, Res.
get());
1314 if (NotPrimaryExpression)
1315 *NotPrimaryExpression =
true;
1318 PreferredType.enterUnary(Actions, Tok.getLocation(), tok::amp, SavedLoc);
1319 Res = ParseCastExpression(AnyCastExpr,
true);
1321 Res = Actions.ActOnUnaryOp(
getCurScope(), SavedLoc, SavedKind, Res.
get());
1330 case tok::kw___real:
1331 case tok::kw___imag: {
1332 if (NotPrimaryExpression)
1333 *NotPrimaryExpression =
true;
1335 PreferredType.enterUnary(Actions, Tok.getLocation(), SavedKind, SavedLoc);
1336 Res = ParseCastExpression(AnyCastExpr);
1338 Res = Actions.ActOnUnaryOp(
getCurScope(), SavedLoc, SavedKind, Res.
get());
1342 case tok::kw_co_await: {
1343 if (NotPrimaryExpression)
1344 *NotPrimaryExpression =
true;
1346 Res = ParseCastExpression(AnyCastExpr);
1348 Res = Actions.ActOnCoawaitExpr(
getCurScope(), CoawaitLoc, Res.
get());
1352 case tok::kw___extension__:{
1354 if (NotPrimaryExpression)
1355 *NotPrimaryExpression =
true;
1358 Res = ParseCastExpression(AnyCastExpr);
1360 Res = Actions.ActOnUnaryOp(
getCurScope(), SavedLoc, SavedKind, Res.
get());
1363 case tok::kw__Alignof:
1365 Diag(Tok, diag::ext_c11_feature) << Tok.getName();
1367 case tok::kw_alignof:
1368 case tok::kw___alignof:
1370 case tok::kw_sizeof:
1372 case tok::kw_vec_step:
1374 case tok::kw___builtin_omp_required_simd_align:
1375 if (NotPrimaryExpression)
1376 *NotPrimaryExpression =
true;
1377 return ParseUnaryExprOrTypeTraitExpression();
1379 if (NotPrimaryExpression)
1380 *NotPrimaryExpression =
true;
1382 if (Tok.
isNot(tok::identifier))
1383 return ExprError(
Diag(Tok, diag::err_expected) << tok::identifier);
1386 return ExprError(
Diag(Tok, diag::err_address_of_label_outside_fn));
1388 Diag(AmpAmpLoc, diag::ext_gnu_address_of_label);
1389 LabelDecl *LD = Actions.LookupOrCreateLabel(Tok.getIdentifierInfo(),
1391 Res = Actions.ActOnAddrLabel(AmpAmpLoc, Tok.getLocation(), LD);
1395 case tok::kw_const_cast:
1396 case tok::kw_dynamic_cast:
1397 case tok::kw_reinterpret_cast:
1398 case tok::kw_static_cast:
1399 if (NotPrimaryExpression)
1400 *NotPrimaryExpression =
true;
1401 Res = ParseCXXCasts();
1403 case tok::kw___builtin_bit_cast:
1404 if (NotPrimaryExpression)
1405 *NotPrimaryExpression =
true;
1406 Res = ParseBuiltinBitCast();
1408 case tok::kw_typeid:
1409 if (NotPrimaryExpression)
1410 *NotPrimaryExpression =
true;
1411 Res = ParseCXXTypeid();
1413 case tok::kw___uuidof:
1414 if (NotPrimaryExpression)
1415 *NotPrimaryExpression =
true;
1416 Res = ParseCXXUuidof();
1419 Res = ParseCXXThis();
1422 case tok::annot_typename:
1423 if (isStartOfObjCClassMessageMissingOpenBracket()) {
1431 const char *PrevSpec =
nullptr;
1434 PrevSpec, DiagID, Type,
1435 Actions.getASTContext().getPrintingPolicy());
1442 ConsumeAnnotationToken();
1449 case tok::annot_decltype:
1451 case tok::kw_wchar_t:
1452 case tok::kw_char8_t:
1453 case tok::kw_char16_t:
1454 case tok::kw_char32_t:
1459 case tok::kw___int64:
1460 case tok::kw___int128:
1461 case tok::kw_signed:
1462 case tok::kw_unsigned:
1465 case tok::kw_double:
1466 case tok::kw__Float16:
1467 case tok::kw___float128:
1469 case tok::kw_typename:
1470 case tok::kw_typeof:
1471 case tok::kw___vector:
1472 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: 1473 #include "clang/Basic/OpenCLImageTypes.def" 1476 Diag(Tok, diag::err_expected_expression);
1481 if (NotPrimaryExpression)
1482 *NotPrimaryExpression =
true;
1484 if (SavedKind == tok::kw_typename) {
1490 if (!Actions.isSimpleTypeSpecifier(Tok.getKind()))
1501 ParseCXXSimpleTypeSpecifier(DS);
1502 if (Tok.
isNot(tok::l_paren) &&
1504 return ExprError(
Diag(Tok, diag::err_expected_lparen_after_type)
1507 if (Tok.
is(tok::l_brace))
1508 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
1510 Res = ParseCXXTypeConstructExpression(DS);
1514 case tok::annot_cxxscope: {
1519 if (!Tok.
is(tok::annot_cxxscope))
1520 return ParseCastExpression(ParseKind, isAddressOfOperand, NotCastExpr,
1521 isTypeCast, isVectorLiteral,
1522 NotPrimaryExpression);
1525 if (Next.
is(tok::annot_template_id)) {
1532 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
1534 AnnotateTemplateIdTokenAsType(SS);
1535 return ParseCastExpression(ParseKind, isAddressOfOperand, NotCastExpr,
1536 isTypeCast, isVectorLiteral,
1537 NotPrimaryExpression);
1542 Res = ParseCXXIdExpression(isAddressOfOperand);
1546 case tok::annot_template_id: {
1553 AnnotateTemplateIdTokenAsType(SS);
1554 return ParseCastExpression(ParseKind, isAddressOfOperand,
1555 NotCastExpr, isTypeCast, isVectorLiteral,
1556 NotPrimaryExpression);
1563 case tok::kw_operator:
1564 Res = ParseCXXIdExpression(isAddressOfOperand);
1567 case tok::coloncolon: {
1572 if (!Tok.
is(tok::coloncolon))
1573 return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast,
1574 isVectorLiteral, NotPrimaryExpression);
1579 if (Tok.
is(tok::kw_new)) {
1580 if (NotPrimaryExpression)
1581 *NotPrimaryExpression =
true;
1582 return ParseCXXNewExpression(
true, CCLoc);
1584 if (Tok.
is(tok::kw_delete)) {
1585 if (NotPrimaryExpression)
1586 *NotPrimaryExpression =
true;
1587 return ParseCXXDeleteExpression(
true, CCLoc);
1591 Diag(CCLoc, diag::err_expected_expression);
1596 if (NotPrimaryExpression)
1597 *NotPrimaryExpression =
true;
1598 return ParseCXXNewExpression(
false, Tok.getLocation());
1600 case tok::kw_delete:
1601 if (NotPrimaryExpression)
1602 *NotPrimaryExpression =
true;
1603 return ParseCXXDeleteExpression(
false, Tok.getLocation());
1605 case tok::kw_requires:
1606 return ParseRequiresExpression();
1608 case tok::kw_noexcept: {
1609 if (NotPrimaryExpression)
1610 *NotPrimaryExpression =
true;
1611 Diag(Tok, diag::warn_cxx98_compat_noexcept_expr);
1632 #define TYPE_TRAIT(N,Spelling,K) \ 1633 case tok::kw_##Spelling: 1634 #include "clang/Basic/TokenKinds.def" 1635 return ParseTypeTrait();
1637 case tok::kw___array_rank:
1638 case tok::kw___array_extent:
1639 if (NotPrimaryExpression)
1640 *NotPrimaryExpression =
true;
1641 return ParseArrayTypeTrait();
1643 case tok::kw___is_lvalue_expr:
1644 case tok::kw___is_rvalue_expr:
1645 if (NotPrimaryExpression)
1646 *NotPrimaryExpression =
true;
1647 return ParseExpressionTrait();
1650 if (NotPrimaryExpression)
1651 *NotPrimaryExpression =
true;
1653 return ParseObjCAtExpression(AtLoc);
1656 Res = ParseBlockLiteralExpression();
1658 case tok::code_completion: {
1660 PreferredType.get(Tok.getLocation()));
1672 Res = TryParseLambdaExpression();
1676 if (NotPrimaryExpression)
1677 *NotPrimaryExpression =
true;
1678 Res = ParseObjCMessageExpression();
1682 Res = ParseLambdaExpression();
1686 Res = ParseObjCMessageExpression();
1699 if (ParseKind == PrimaryExprOnly)
1705 PreferredType = SavedType;
1706 Res = ParsePostfixExpressionSuffix(Res);
1708 if (
Expr *PostfixExpr = Res.
get()) {
1709 QualType Ty = PostfixExpr->getType();
1711 Diag(PostfixExpr->getExprLoc(),
1712 diag::err_opencl_taking_function_address_parser);
1741 Parser::ParsePostfixExpressionSuffix(
ExprResult LHS) {
1745 auto SavedType = PreferredType;
1748 PreferredType = SavedType;
1749 switch (Tok.getKind()) {
1750 case tok::code_completion:
1751 if (InMessageExpression)
1754 Actions.CodeCompletePostfixExpression(
1759 case tok::identifier:
1766 nullptr, LHS.
get());
1774 case tok::l_square: {
1781 if (
getLangOpts().ObjC && Tok.isAtStartOfLine() &&
1782 isSimpleObjCMessageExpression())
1787 if (CheckProhibitedCXX11Attribute()) {
1788 (void)Actions.CorrectDelayedTyposInExpr(LHS);
1797 PreferredType.enterSubscript(Actions, Tok.getLocation(), LHS.
get());
1799 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
1800 Idx = ParseBraceInitializer();
1804 if (!Tok.
is(tok::colon)) {
1808 if (Tok.
is(tok::colon)) {
1811 if (Tok.
isNot(tok::r_square))
1819 LHS = Actions.CorrectDelayedTyposInExpr(LHS);
1820 Idx = Actions.CorrectDelayedTyposInExpr(Idx);
1821 Length = Actions.CorrectDelayedTyposInExpr(Length);
1823 Tok.
is(tok::r_square)) {
1825 LHS = Actions.ActOnOMPArraySectionExpr(LHS.
get(), Loc, Idx.
get(),
1828 LHS = Actions.ActOnArraySubscriptExpr(
getCurScope(), LHS.
get(), Loc,
1842 case tok::lesslessless: {
1847 Expr *ExecConfig =
nullptr;
1851 if (OpKind == tok::lesslessless) {
1856 if (ParseSimpleExpressionList(ExecConfigExprs, ExecConfigCommaLocs)) {
1857 (void)Actions.CorrectDelayedTyposInExpr(LHS);
1867 Diag(Tok, diag::err_expected) << tok::greatergreatergreater;
1868 Diag(OpenLoc, diag::note_matching) << tok::lesslessless;
1874 if (ExpectAndConsume(tok::l_paren))
1877 Loc = PrevTokLocation;
1888 ExecConfig = ECResult.
get();
1897 auto RunSignatureHelp = [&]() ->
QualType {
1898 QualType PreferredType = Actions.ProduceCallSignatureHelp(
1900 CalledSignatureHelp =
true;
1901 return PreferredType;
1903 if (OpKind == tok::l_paren || !LHS.
isInvalid()) {
1904 if (Tok.
isNot(tok::r_paren)) {
1905 if (ParseExpressionList(ArgExprs, CommaLocs, [&] {
1906 PreferredType.enterFunctionArgument(Tok.getLocation(),
1909 (void)Actions.CorrectDelayedTyposInExpr(LHS);
1914 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
1918 for (
auto &E : ArgExprs)
1919 Actions.CorrectDelayedTyposInExpr(E);
1927 }
else if (Tok.
isNot(tok::r_paren)) {
1928 bool HadDelayedTypo =
false;
1929 if (Actions.CorrectDelayedTyposInExpr(LHS).get() != LHS.
get())
1930 HadDelayedTypo =
true;
1931 for (
auto &E : ArgExprs)
1932 if (Actions.CorrectDelayedTyposInExpr(E).get() != E)
1933 HadDelayedTypo =
true;
1943 assert((ArgExprs.size() == 0 ||
1944 ArgExprs.size()-1 == CommaLocs.size())&&
1945 "Unexpected number of commas!");
1947 ArgExprs, Tok.getLocation(),
1963 bool MayBePseudoDestructor =
false;
1966 PreferredType.enterMemAccess(Actions, Tok.getLocation(), OrigLHS);
1971 if (BaseType && Tok.
is(tok::l_paren) &&
1974 Diag(OpLoc, diag::err_function_is_not_record)
1977 return ParsePostfixExpressionSuffix(Base);
1980 LHS = Actions.ActOnStartCXXMemberReference(
getCurScope(), Base,
1981 OpLoc, OpKind, ObjectType,
1982 MayBePseudoDestructor);
1986 ParseOptionalCXXScopeSpecifier(SS, ObjectType,
1988 &MayBePseudoDestructor);
1990 ObjectType =
nullptr;
1993 if (Tok.
is(tok::code_completion)) {
1995 OpKind == tok::arrow ? tok::period : tok::arrow;
2001 CorrectedLHS = Actions.ActOnStartCXXMemberReference(
2002 getCurScope(), OrigLHS, OpLoc, CorrectedOpKind, ObjectType,
2003 MayBePseudoDestructor);
2007 Expr *CorrectedBase = CorrectedLHS.
get();
2009 CorrectedBase = Base;
2012 Actions.CodeCompleteMemberReferenceExpr(
2013 getCurScope(), Base, CorrectedBase, OpLoc, OpKind == tok::arrow,
2014 Base && ExprStatementTokLoc == Base->
getBeginLoc(),
2015 PreferredType.get(Tok.getLocation()));
2021 if (MayBePseudoDestructor && !LHS.
isInvalid()) {
2022 LHS = ParseCXXPseudoDestructor(LHS.
get(), OpLoc, OpKind, SS,
2036 if (
getLangOpts().ObjC && OpKind == tok::period &&
2037 Tok.
is(tok::kw_class)) {
2055 ObjectType, &TemplateKWLoc, Name)) {
2056 (void)Actions.CorrectDelayedTyposInExpr(LHS);
2061 LHS = Actions.ActOnMemberAccessExpr(
getCurScope(), LHS.
get(), OpLoc,
2062 OpKind, SS, TemplateKWLoc, Name,
2063 CurParsedObjCImpl ? CurParsedObjCImpl->Dcl
2066 checkPotentialAngleBracket(LHS);
2070 case tok::minusminus:
2072 LHS = Actions.ActOnPostfixUnaryOp(
getCurScope(), Tok.getLocation(),
2073 Tok.getKind(), LHS.
get());
2105 Parser::ParseExprAfterUnaryExprOrTypeTrait(
const Token &OpTok,
2110 assert(OpTok.
isOneOf(tok::kw_typeof, tok::kw_sizeof, tok::kw___alignof,
2111 tok::kw_alignof, tok::kw__Alignof, tok::kw_vec_step,
2112 tok::kw___builtin_omp_required_simd_align) &&
2113 "Not a typeof/sizeof/alignof/vec_step expression!");
2118 if (Tok.
isNot(tok::l_paren)) {
2121 if (OpTok.
isOneOf(tok::kw_sizeof, tok::kw___alignof, tok::kw_alignof,
2122 tok::kw__Alignof)) {
2123 if (isTypeIdUnambiguously()) {
2125 ParseSpecifierQualifierList(DS);
2127 ParseDeclarator(DeclaratorInfo);
2130 SourceLocation RParenLoc = PP.getLocForEndOfToken(PrevTokLocation);
2131 Diag(LParenLoc, diag::err_expected_parentheses_around_typename)
2147 Operand = ParseCastExpression(UnaryExprOnly);
2153 ParenParseOption ExprType =
CastExpr;
2156 Operand = ParseParenExpression(ExprType,
true,
2157 false, CastTy, RParenLoc);
2172 if (!Operand.isInvalid())
2173 Operand = ParsePostfixExpressionSuffix(Operand.get());
2195 ExprResult Parser::ParseUnaryExprOrTypeTraitExpression() {
2196 assert(Tok.
isOneOf(tok::kw_sizeof, tok::kw___alignof, tok::kw_alignof,
2197 tok::kw__Alignof, tok::kw_vec_step,
2198 tok::kw___builtin_omp_required_simd_align) &&
2199 "Not a sizeof/alignof/vec_step expression!");
2204 if (Tok.
is(tok::ellipsis) && OpTok.is(tok::kw_sizeof)) {
2209 if (Tok.
is(tok::l_paren)) {
2213 if (Tok.
is(tok::identifier)) {
2214 Name = Tok.getIdentifierInfo();
2219 RParenLoc = PP.getLocForEndOfToken(NameLoc);
2221 Diag(Tok, diag::err_expected_parameter_pack);
2224 }
else if (Tok.
is(tok::identifier)) {
2225 Name = Tok.getIdentifierInfo();
2227 LParenLoc = PP.getLocForEndOfToken(EllipsisLoc);
2228 RParenLoc = PP.getLocForEndOfToken(NameLoc);
2229 Diag(LParenLoc, diag::err_paren_sizeof_parameter_pack)
2234 Diag(Tok, diag::err_sizeof_parameter_pack);
2244 return Actions.ActOnSizeofParameterPackExpr(
getCurScope(),
2245 OpTok.getLocation(),
2250 if (OpTok.isOneOf(tok::kw_alignof, tok::kw__Alignof))
2251 Diag(OpTok, diag::warn_cxx98_compat_alignof);
2260 ExprResult Operand = ParseExprAfterUnaryExprOrTypeTrait(OpTok,
2266 if (OpTok.isOneOf(tok::kw_alignof, tok::kw__Alignof))
2268 else if (OpTok.is(tok::kw___alignof))
2270 else if (OpTok.is(tok::kw_vec_step))
2272 else if (OpTok.is(tok::kw___builtin_omp_required_simd_align))
2276 return Actions.ActOnUnaryExprOrTypeTraitExpr(OpTok.getLocation(),
2282 if (OpTok.isOneOf(tok::kw_alignof, tok::kw__Alignof))
2283 Diag(OpTok, diag::ext_alignof_expr) << OpTok.getIdentifierInfo();
2287 Operand = Actions.ActOnUnaryExprOrTypeTraitExpr(OpTok.getLocation(),
2315 ExprResult Parser::ParseBuiltinPrimaryExpression() {
2323 if (Tok.
isNot(tok::l_paren))
2324 return ExprError(
Diag(Tok, diag::err_expected_after) << BuiltinII
2333 default: llvm_unreachable(
"Not a builtin primary expression!");
2334 case tok::kw___builtin_va_arg: {
2337 if (ExpectAndConsume(tok::comma)) {
2344 if (Tok.
isNot(tok::r_paren)) {
2345 Diag(Tok, diag::err_expected) << tok::r_paren;
2352 Res = Actions.ActOnVAArg(StartLoc, Expr.
get(), Ty.
get(), ConsumeParen());
2355 case tok::kw___builtin_offsetof: {
2363 if (ExpectAndConsume(tok::comma)) {
2369 if (Tok.
isNot(tok::identifier)) {
2370 Diag(Tok, diag::err_expected) << tok::identifier;
2379 Comps.back().isBrackets =
false;
2380 Comps.back().U.IdentInfo = Tok.getIdentifierInfo();
2381 Comps.back().LocStart = Comps.back().LocEnd =
ConsumeToken();
2385 if (Tok.
is(tok::period)) {
2388 Comps.back().isBrackets =
false;
2391 if (Tok.
isNot(tok::identifier)) {
2392 Diag(Tok, diag::err_expected) << tok::identifier;
2396 Comps.back().U.IdentInfo = Tok.getIdentifierInfo();
2399 }
else if (Tok.
is(tok::l_square)) {
2400 if (CheckProhibitedCXX11Attribute())
2405 Comps.back().isBrackets =
true;
2414 Comps.back().U.E = Res.
get();
2419 if (Tok.
isNot(tok::r_paren)) {
2426 Res = Actions.ActOnBuiltinOffsetOf(
getCurScope(), StartLoc, TypeLoc,
2435 case tok::kw___builtin_choose_expr: {
2441 if (ExpectAndConsume(tok::comma)) {
2451 if (ExpectAndConsume(tok::comma)) {
2461 if (Tok.
isNot(tok::r_paren)) {
2462 Diag(Tok, diag::err_expected) << tok::r_paren;
2465 Res = Actions.ActOnChooseExpr(StartLoc, Cond.
get(), Expr1.
get(),
2466 Expr2.
get(), ConsumeParen());
2469 case tok::kw___builtin_astype: {
2477 if (ExpectAndConsume(tok::comma)) {
2488 if (Tok.
isNot(tok::r_paren)) {
2489 Diag(Tok, diag::err_expected) << tok::r_paren;
2494 Res = Actions.ActOnAsTypeExpr(Expr.
get(), DestTy.
get(), StartLoc,
2498 case tok::kw___builtin_convertvector: {
2506 if (ExpectAndConsume(tok::comma)) {
2517 if (Tok.
isNot(tok::r_paren)) {
2518 Diag(Tok, diag::err_expected) << tok::r_paren;
2523 Res = Actions.ActOnConvertVectorExpr(Expr.
get(), DestTy.
get(), StartLoc,
2527 case tok::kw___builtin_COLUMN:
2528 case tok::kw___builtin_FILE:
2529 case tok::kw___builtin_FUNCTION:
2530 case tok::kw___builtin_LINE: {
2532 if (Tok.
isNot(tok::r_paren)) {
2533 Diag(Tok, diag::err_expected) << tok::r_paren;
2539 case tok::kw___builtin_FILE:
2541 case tok::kw___builtin_FUNCTION:
2543 case tok::kw___builtin_LINE:
2545 case tok::kw___builtin_COLUMN:
2548 llvm_unreachable(
"invalid keyword");
2551 Res = Actions.ActOnSourceLocExpr(Kind, StartLoc, ConsumeParen());
2561 return ParsePostfixExpressionSuffix(Res.
get());
2590 Parser::ParseParenExpression(ParenParseOption &ExprType,
bool stopIfCastExpr,
2593 assert(Tok.
is(tok::l_paren) &&
"Not a paren expr!");
2600 PreferredType.enterParenExpr(Tok.getLocation(), OpenLoc);
2603 bool isAmbiguousTypeId;
2606 if (Tok.
is(tok::code_completion)) {
2607 Actions.CodeCompleteExpression(
2608 getCurScope(), PreferredType.get(Tok.getLocation()),
2609 ExprType >= CompoundLiteral);
2617 tok::kw___bridge_transfer,
2618 tok::kw___bridge_retained,
2619 tok::kw___bridge_retain));
2620 if (BridgeCast && !
getLangOpts().ObjCAutoRefCount) {
2622 StringRef BridgeCastName = Tok.getName();
2624 if (!PP.getSourceManager().isInSystemHeader(BridgeKeywordLoc))
2625 Diag(BridgeKeywordLoc, diag::warn_arc_bridge_cast_nonarc)
2635 Diag(Tok, diag::ext_gnu_statement_expr);
2638 Result =
ExprError(
Diag(OpenLoc, diag::err_stmtexpr_file_scope));
2644 while (CodeDC->
isRecord() || isa<EnumDecl>(CodeDC)) {
2647 "statement expr not in code context");
2651 Actions.ActOnStartStmtExpr();
2658 Result = Actions.ActOnStmtExpr(OpenLoc, Stmt.
get(), Tok.getLocation());
2660 Actions.ActOnStmtExprError();
2663 }
else if (ExprType >= CompoundLiteral && BridgeCast) {
2669 if (tokenKind == tok::kw___bridge)
2671 else if (tokenKind == tok::kw___bridge_transfer)
2673 else if (tokenKind == tok::kw___bridge_retained)
2678 assert(tokenKind == tok::kw___bridge_retain);
2680 if (!PP.getSourceManager().isInSystemHeader(BridgeKeywordLoc))
2681 Diag(BridgeKeywordLoc, diag::err_arc_bridge_retain)
2683 "__bridge_retained");
2688 ColonProtection.restore();
2691 PreferredType.enterTypeCast(Tok.getLocation(), Ty.
get().get());
2692 ExprResult SubExpr = ParseCastExpression(AnyCastExpr);
2697 return Actions.ActOnObjCBridgedCast(
getCurScope(), OpenLoc, Kind,
2698 BridgeKeywordLoc, Ty.
get(),
2699 RParenLoc, SubExpr.
get());
2700 }
else if (ExprType >= CompoundLiteral &&
2701 isTypeIdInParens(isAmbiguousTypeId)) {
2710 if (isAmbiguousTypeId && !stopIfCastExpr) {
2711 ExprResult res = ParseCXXAmbiguousParenExpression(ExprType, CastTy, T,
2719 ParseSpecifierQualifierList(DS);
2721 ParseDeclarator(DeclaratorInfo);
2732 Ty = Actions.ActOnTypeName(
getCurScope(), DeclaratorInfo);
2740 ColonProtection.restore();
2742 if (Tok.
is(tok::l_brace)) {
2743 ExprType = CompoundLiteral;
2747 Ty = Actions.ActOnTypeName(
getCurScope(), DeclaratorInfo);
2749 return ParseCompoundLiteralExpression(Ty.
get(), OpenLoc, RParenLoc);
2752 if (Tok.
is(tok::l_paren)) {
2759 Ty = Actions.ActOnTypeName(
getCurScope(), DeclaratorInfo);
2773 Result = ParseCastExpression(AnyCastExpr,
2779 Result = Actions.ActOnCastExpr(
getCurScope(), OpenLoc,
2780 DeclaratorInfo, CastTy,
2781 RParenLoc, Result.
get());
2786 Result = ParsePostfixExpressionSuffix(Result);
2802 if (stopIfCastExpr) {
2806 Ty = Actions.ActOnTypeName(
getCurScope(), DeclaratorInfo);
2814 Tok.getIdentifierInfo() == Ident_super &&
2816 GetLookAheadToken(1).isNot(tok::period)) {
2817 Diag(Tok.getLocation(), diag::err_illegal_super_cast)
2822 PreferredType.enterTypeCast(Tok.getLocation(), CastTy.
get());
2825 Result = ParseCastExpression(AnyCastExpr,
2829 Result = Actions.ActOnCastExpr(
getCurScope(), OpenLoc,
2830 DeclaratorInfo, CastTy,
2831 RParenLoc, Result.
get());
2836 Diag(Tok, diag::err_expected_lbrace_in_compound_literal);
2839 }
else if (ExprType >= FoldExpr && Tok.
is(tok::ellipsis) &&
2841 ExprType = FoldExpr;
2843 }
else if (isTypeCast) {
2850 if (!ParseSimpleExpressionList(ArgExprs, CommaLocs)) {
2853 if (ExprType >= FoldExpr && ArgExprs.size() == 1 &&
2854 isFoldOperator(Tok.getKind()) &&
NextToken().
is(tok::ellipsis)) {
2855 ExprType = FoldExpr;
2856 return ParseFoldExpression(ArgExprs[0], T);
2859 ExprType = SimpleExpr;
2860 Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(),
2870 Result = Actions.CorrectDelayedTyposInExpr(Result);
2873 if (ExprType >= FoldExpr && isFoldOperator(Tok.getKind()) &&
2875 ExprType = FoldExpr;
2876 return ParseFoldExpression(Result, T);
2878 ExprType = SimpleExpr;
2883 Actions.ActOnParenExpr(OpenLoc, Tok.getLocation(), Result.
get());
2906 Parser::ParseCompoundLiteralExpression(
ParsedType Ty,
2909 assert(Tok.
is(tok::l_brace) &&
"Not a compound literal!");
2911 Diag(LParenLoc, diag::ext_c99_compound_literal);
2914 return Actions.ActOnCompoundLiteral(LParenLoc, Ty, RParenLoc, Result.
get());
2926 ExprResult Parser::ParseStringLiteralExpression(
bool AllowUserDefinedLiteral) {
2927 assert(isTokenStringLiteral() &&
"Not a string literal!");
2934 StringToks.push_back(Tok);
2935 ConsumeStringToken();
2936 }
while (isTokenStringLiteral());
2939 return Actions.ActOnStringLiteral(StringToks,
2957 ExprResult Parser::ParseGenericSelectionExpression() {
2958 assert(Tok.
is(tok::kw__Generic) &&
"_Generic keyword expected");
2960 Diag(Tok, diag::ext_c11_feature) << Tok.getName();
2981 if (ExpectAndConsume(tok::comma)) {
2991 if (Tok.
is(tok::kw_default)) {
2995 Diag(Tok, diag::err_duplicate_default_assoc);
2996 Diag(DefaultLoc, diag::note_previous_default_assoc);
3011 Types.push_back(Ty);
3013 if (ExpectAndConsume(tok::colon)) {
3022 if (ER.isInvalid()) {
3026 Exprs.push_back(ER.get());
3033 return Actions.ActOnGenericSelectionExpr(KeyLoc, DefaultLoc,
3035 ControllingExpr.
get(),
3057 Kind = Tok.getKind();
3058 assert(isFoldOperator(Kind) &&
"missing fold-operator");
3062 assert(Tok.
is(tok::ellipsis) &&
"not a fold-expression");
3066 if (Tok.
isNot(tok::r_paren)) {
3067 if (!isFoldOperator(Tok.getKind()))
3068 return Diag(Tok.getLocation(), diag::err_expected_fold_operator);
3070 if (Kind != tok::unknown && Tok.getKind() !=
Kind)
3071 Diag(Tok.getLocation(), diag::err_fold_operator_mismatch)
3073 Kind = Tok.getKind();
3084 ? diag::warn_cxx14_compat_fold_expression
3085 : diag::ext_fold_expression);
3116 llvm::function_ref<
void()> ExpressionStarts) {
3117 bool SawError =
false;
3119 if (ExpressionStarts)
3124 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
3125 Expr = ParseBraceInitializer();
3129 if (Tok.
is(tok::ellipsis))
3135 Exprs.push_back(Expr.
get());
3138 if (Tok.
isNot(tok::comma))
3144 checkPotentialAngleBracketDelimiter(Comma);
3149 for (
auto &E : Exprs) {
3173 Exprs.push_back(Expr.
get());
3175 if (Tok.
isNot(tok::comma))
3182 checkPotentialAngleBracketDelimiter(Comma);
3193 if (Tok.
is(tok::code_completion)) {
3195 return cutOffParsing();
3200 ParseSpecifierQualifierList(DS);
3205 ParseDeclarator(DeclaratorInfo);
3207 MaybeParseGNUAttributes(DeclaratorInfo);
3210 Actions.ActOnBlockArguments(CaretLoc, DeclaratorInfo,
getCurScope());
3223 ExprResult Parser::ParseBlockLiteralExpression() {
3224 assert(Tok.
is(tok::caret) &&
"block literal starts with ^");
3228 "block literal parsing");
3250 if (Tok.
is(tok::l_paren)) {
3251 ParseParenDeclarator(ParamInfo);
3266 MaybeParseGNUAttributes(ParamInfo);
3269 Actions.ActOnBlockArguments(CaretLoc, ParamInfo,
getCurScope());
3270 }
else if (!Tok.
is(tok::l_brace)) {
3271 ParseBlockId(CaretLoc);
3293 CaretLoc, ParamInfo),
3296 MaybeParseGNUAttributes(ParamInfo);
3299 Actions.ActOnBlockArguments(CaretLoc, ParamInfo,
getCurScope());
3304 if (!Tok.
is(tok::l_brace)) {
3306 Diag(Tok, diag::err_expected_expression);
3314 Result = Actions.ActOnBlockStmtExpr(CaretLoc, Stmt.
get(),
getCurScope());
3326 return Actions.ActOnObjCBoolLiteral(
ConsumeToken(), Kind);
3333 llvm::SmallSet<StringRef, 4> Platforms;
3334 bool HasOtherPlatformSpec =
false;
3336 for (
const auto &Spec : AvailSpecs) {
3337 if (Spec.isOtherPlatformSpec()) {
3338 if (HasOtherPlatformSpec) {
3339 P.
Diag(Spec.getBeginLoc(), diag::err_availability_query_repeated_star);
3343 HasOtherPlatformSpec =
true;
3347 bool Inserted = Platforms.insert(Spec.getPlatform()).second;
3352 StringRef Platform = Spec.getPlatform();
3353 P.
Diag(Spec.getBeginLoc(), diag::err_availability_query_repeated_platform)
3354 << Spec.getEndLoc() << Platform;
3359 if (!HasOtherPlatformSpec) {
3360 SourceLocation InsertWildcardLoc = AvailSpecs.back().getEndLoc();
3361 P.
Diag(InsertWildcardLoc, diag::err_availability_query_wildcard_required)
3375 if (Tok.
is(tok::star)) {
3379 if (Tok.
is(tok::code_completion)) {
3380 Actions.CodeCompleteAvailabilityPlatformName();
3384 if (Tok.
isNot(tok::identifier)) {
3385 Diag(Tok, diag::err_avail_query_expected_platform_name);
3391 VersionTuple Version = ParseVersionTuple(VersionRange);
3393 if (Version.empty())
3396 StringRef GivenPlatform = PlatformIdentifier->
Ident->
getName();
3397 StringRef Platform =
3398 AvailabilityAttr::canonicalizePlatformName(GivenPlatform);
3400 if (AvailabilityAttr::getPrettyPlatformName(Platform).empty()) {
3402 diag::err_avail_query_unrecognized_platform_name)
3413 assert(Tok.
is(tok::kw___builtin_available) ||
3424 bool HasError =
false;
3430 AvailSpecs.push_back(*Spec);
3446 return Actions.ActOnObjCAvailabilityCheckExpr(AvailSpecs, BeginLoc,
Defines the clang::ASTContext interface.
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
no exception specification
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
ParseScope - Introduces a new scope for parsing.
A (possibly-)qualified type.
Simple class containing the result of Sema::CorrectTypo.
SourceRange getExprRange(Expr *E) const
ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, SourceLocation ColonLoc, Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr)
ActOnConditionalOp - Parse a ?: operation.
ObjCBridgeCastKind
The kind of bridging performed by the Objective-C bridge cast.
Stmt - This represents one statement.
Bridging via __bridge, which does nothing but reinterpret the bits.
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {...
bool isSpecificPlaceholderType(unsigned K) const
Test for a specific placeholder type.
static bool CheckAvailabilitySpecList(Parser &P, ArrayRef< AvailabilitySpec > AvailSpecs)
Validate availability spec list, emitting diagnostics if necessary.
Defines the PrettyStackTraceEntry class, which is used to make crashes give more contextual informati...
void CodeCompleteExpression(Scope *S, const CodeCompleteExpressionData &Data)
Perform code-completion in an expression context when we know what type we're looking for...
const char * getCharacterData(SourceLocation SL, bool *Invalid=nullptr) const
Return a pointer to the start of the specified location in the appropriate spelling MemoryBuffer...
The base class of the type hierarchy.
SourceLocation getCloseLocation() const
This indicates that the scope corresponds to a function, which means that labels are set here...
TemplateNameKind Kind
The kind of template that Template refers to.
Parser - This implements a parser for the C family of languages.
TypeCastState
TypeCastState - State whether an expression is or may be a type cast.
void SetIdentifier(IdentifierInfo *Id, SourceLocation IdLoc)
Set the name of this declarator to be the given identifier.
ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val)
RAII object that enters a new expression evaluation context.
Information about one declarator, including the parsed type information and the identifier.
bool isInObjcMethodScope() const
isInObjcMethodScope - Return true if this scope is, or is contained in, an Objective-C method body...
#define REVERTIBLE_TYPE_TRAIT(Name)
Defines the clang::Expr interface and subclasses for C++ expressions.
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed...
tok::TokenKind getKind() const
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
Information about a template-id annotation token.
Base wrapper for a particular "section" of type source info.
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
bool TryConsumeToken(tok::TokenKind Expected)
One of these records is kept for each identifier that is lexed.
Used for GCC's __alignof.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
SourceLocation getBeginLoc() const LLVM_READONLY
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
Token - This structure provides full information about a lexed token.
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ...
void * getAsOpaquePtr() const
Code completion occurs where only a type is permitted.
void SetSourceRange(SourceRange R)
bool isInvalidType() const
QualType get(SourceLocation Tok) const
This is a scope that corresponds to a block/closure object.
Represents a C++ unqualified-id that has been parsed.
static ParsedType getTypeAnnotation(const Token &Tok)
getTypeAnnotation - Read a parsed type out of an annotation token.
RAII class used to indicate that we are performing provisional semantic analysis to determine the val...
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 ...
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, llvm::function_ref< ExprResult(Expr *)> Filter=[](Expr *E) -> ExprResult { return E;})
Process any TypoExprs in the given Expr and its children, generating diagnostics as appropriate and r...
If a crash happens while one of these objects are live, the message is printed out along with the spe...
Represents a C++ nested-name-specifier or a global scope specifier.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Bridging via __bridge_transfer, which transfers ownership of an Objective-C pointer into ARC...
SourceRange getSourceRange() const LLVM_READONLY
const char * getName() const
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
static DeclaratorChunk getFunction(bool HasProto, bool IsAmbiguous, SourceLocation LParenLoc, ParamInfo *Params, unsigned NumParams, SourceLocation EllipsisLoc, SourceLocation RParenLoc, bool RefQualifierIsLvalueRef, SourceLocation RefQualifierLoc, SourceLocation MutableLoc, ExceptionSpecificationType ESpecType, SourceRange ESpecRange, ParsedType *Exceptions, SourceRange *ExceptionRanges, unsigned NumExceptions, Expr *NoexceptExpr, CachedTokens *ExceptionSpecTokens, ArrayRef< NamedDecl *> DeclsInPrototype, SourceLocation LocalRangeBegin, SourceLocation LocalRangeEnd, Declarator &TheDeclarator, TypeResult TrailingReturnType=TypeResult(), DeclSpec *MethodQualifiers=nullptr)
DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
CompoundStmt - This represents a group of statements like { stmt stmt }.
void SetRangeStart(SourceLocation Loc)
virtual bool ValidateCandidate(const TypoCorrection &candidate)
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr)
This represents one expression.
This file defines the classes used to store parsed information about declaration-specifiers and decla...
bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, ParsedType ObjectType, SourceLocation *TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
bool isFileContext() const
This is a compound statement scope.
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7)...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
SourceLocation getEnd() const
SourceLocation getOpenLocation() const
Wraps an identifier and optional source location for the identifier.
The result type of a method or function.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const LangOptions & getLangOpts() const
SourceManager & getSourceManager() const
Stop skipping at semicolon.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Encodes a location in the source.
bool TryAnnotateTypeOrScopeToken()
TryAnnotateTypeOrScopeToken - If the current token position is on a typename (possibly qualified in C...
IdentifierInfo * getIdentifierInfo() const
Represents the declaration of a label.
ExtensionRAIIObject - This saves the state of extension warnings when constructed and disables them...
bool isAtStartOfMacroExpansion(SourceLocation loc, SourceLocation *MacroBegin=nullptr) const
Returns true if the given MacroID location points at the first token of the macro expansion...
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
Used for C's _Alignof and C++'s alignof.
Scope * getCurScope() const
bool isVectorType() const
ExprResult ParseConstantExpressionInExprEvalContext(TypeCastState isTypeCast=NotTypeCast)
void setFunctionDefinitionKind(FunctionDefinitionKind Val)
StringRef getName() const
Return the actual identifier string.
SourceRange getSourceRange() const LLVM_READONLY
Get the source range that spans this declarator.
bool isNot(tok::TokenKind K) const
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, tok::TokenKind Op, Expr *Input)
bool expectAndConsume(unsigned DiagID=diag::err_expected, const char *Msg="", tok::TokenKind SkipToTok=tok::unknown)
ExprResult ParseCaseExpression(SourceLocation CaseLoc)
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
ExprResult ParseConstraintExpression()
Parse a constraint-expression.
NamedDecl * getCorrectionDecl() const
Gets the pointer to the declaration of the typo correction.
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
Bridging via __bridge_retain, which makes an ARC object available as a +1 C pointer.
The name refers to a template whose specialization produces a type.
ExprResult ActOnConstantExpression(ExprResult Res)
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
bool CheckConstraintExpression(Expr *CE, Token NextToken=Token(), bool *PossibleNonPrimary=nullptr, bool IsTrailingRequiresClause=false)
Check whether the given expression is a valid constraint expression.
bool isFunctionType() const
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
void SetRangeEnd(SourceLocation Loc)
SetRangeEnd - Set the end of the source range to Loc, unless it's invalid.
ExprResult ParseAssignmentExpression(TypeCastState isTypeCast=NotTypeCast)
Parse an expr that doesn't include (top-level) commas.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc)
AddTypeInfo - Add a chunk to this declarator.
const Type * getTypePtrOrNull() const
This is a scope that can contain a declaration.
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
ExprResult ParseConstantExpression(TypeCastState isTypeCast=NotTypeCast)
Captures information about "declaration specifiers".
ActionResult< Expr * > ExprResult
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
static Decl::Kind getKind(const Decl *D)
const Scope * getFnParent() const
getFnParent - Return the closest scope that is a function body.
prec::Level getBinOpPrecedence(tok::TokenKind Kind, bool GreaterThanIsOperator, bool CPlusPlus11)
Return the precedence of the specified binary operator token.
void enterBinary(Sema &S, SourceLocation Tok, Expr *LHS, tok::TokenKind Op)
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
void SetRangeEnd(SourceLocation Loc)
SourceLocation ColonLoc
Location of ':'.
This class handles loading and caching of source files into memory.
ExprResult ParseConstraintLogicalOrExpression(bool IsTrailingRequiresClause)
Parse a constraint-logical-or-expression.
ExprResult ParseConstraintLogicalAndExpression(bool IsTrailingRequiresClause)
Parse a constraint-logical-and-expression.
One specifier in an expression.
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeNameContext, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName type-name: [C99 6.7.6] specifier-qualifier-list abstract-declarator[opt].
Stop skipping at specified token, but don't skip the token itself.