diff options
Diffstat (limited to 'contrib/llvm-project/clang/lib/Parse/ParseExpr.cpp')
-rw-r--r-- | contrib/llvm-project/clang/lib/Parse/ParseExpr.cpp | 364 |
1 files changed, 233 insertions, 131 deletions
diff --git a/contrib/llvm-project/clang/lib/Parse/ParseExpr.cpp b/contrib/llvm-project/clang/lib/Parse/ParseExpr.cpp index e862856a08ca..e82b56527283 100644 --- a/contrib/llvm-project/clang/lib/Parse/ParseExpr.cpp +++ b/contrib/llvm-project/clang/lib/Parse/ParseExpr.cpp @@ -30,6 +30,12 @@ #include "clang/Sema/EnterExpressionEvaluationContext.h" #include "clang/Sema/ParsedTemplate.h" #include "clang/Sema/Scope.h" +#include "clang/Sema/SemaCUDA.h" +#include "clang/Sema/SemaCodeCompletion.h" +#include "clang/Sema/SemaObjC.h" +#include "clang/Sema/SemaOpenACC.h" +#include "clang/Sema/SemaOpenMP.h" +#include "clang/Sema/SemaSYCL.h" #include "clang/Sema/TypoCorrection.h" #include "llvm/ADT/SmallVector.h" #include <optional> @@ -163,8 +169,8 @@ Parser::ParseExpressionWithLeadingExtension(SourceLocation ExtLoc) { ExprResult Parser::ParseAssignmentExpression(TypeCastState isTypeCast) { if (Tok.is(tok::code_completion)) { cutOffParsing(); - Actions.CodeCompleteExpression(getCurScope(), - PreferredType.get(Tok.getLocation())); + Actions.CodeCompletion().CodeCompleteExpression( + getCurScope(), PreferredType.get(Tok.getLocation())); return ExprError(); } @@ -179,6 +185,19 @@ ExprResult Parser::ParseAssignmentExpression(TypeCastState isTypeCast) { return ParseRHSOfBinaryExpression(LHS, prec::Assignment); } +ExprResult Parser::ParseConditionalExpression() { + if (Tok.is(tok::code_completion)) { + cutOffParsing(); + Actions.CodeCompletion().CodeCompleteExpression( + getCurScope(), PreferredType.get(Tok.getLocation())); + return ExprError(); + } + + ExprResult LHS = ParseCastExpression( + AnyCastExpr, /*isAddressOfOperand=*/false, NotTypeCast); + return ParseRHSOfBinaryExpression(LHS, prec::Conditional); +} + /// Parse an assignment expression where part of an Objective-C message /// send has already been parsed. /// @@ -741,6 +760,109 @@ class CastExpressionIdValidator final : public CorrectionCandidateCallback { }; } +bool Parser::isRevertibleTypeTrait(const IdentifierInfo *II, + tok::TokenKind *Kind) { + if (RevertibleTypeTraits.empty()) { +// Revertible type trait is a feature for backwards compatibility with older +// standard libraries that declare their own structs with the same name as +// the builtins listed below. New builtins should NOT be added to this list. +#define RTT_JOIN(X, Y) X##Y +#define REVERTIBLE_TYPE_TRAIT(Name) \ + RevertibleTypeTraits[PP.getIdentifierInfo(#Name)] = RTT_JOIN(tok::kw_, Name) + + REVERTIBLE_TYPE_TRAIT(__is_abstract); + REVERTIBLE_TYPE_TRAIT(__is_aggregate); + REVERTIBLE_TYPE_TRAIT(__is_arithmetic); + REVERTIBLE_TYPE_TRAIT(__is_array); + REVERTIBLE_TYPE_TRAIT(__is_assignable); + REVERTIBLE_TYPE_TRAIT(__is_base_of); + REVERTIBLE_TYPE_TRAIT(__is_bounded_array); + REVERTIBLE_TYPE_TRAIT(__is_class); + REVERTIBLE_TYPE_TRAIT(__is_complete_type); + REVERTIBLE_TYPE_TRAIT(__is_compound); + REVERTIBLE_TYPE_TRAIT(__is_const); + REVERTIBLE_TYPE_TRAIT(__is_constructible); + REVERTIBLE_TYPE_TRAIT(__is_convertible); + REVERTIBLE_TYPE_TRAIT(__is_convertible_to); + REVERTIBLE_TYPE_TRAIT(__is_destructible); + REVERTIBLE_TYPE_TRAIT(__is_empty); + REVERTIBLE_TYPE_TRAIT(__is_enum); + REVERTIBLE_TYPE_TRAIT(__is_floating_point); + REVERTIBLE_TYPE_TRAIT(__is_final); + REVERTIBLE_TYPE_TRAIT(__is_function); + REVERTIBLE_TYPE_TRAIT(__is_fundamental); + REVERTIBLE_TYPE_TRAIT(__is_integral); + REVERTIBLE_TYPE_TRAIT(__is_interface_class); + REVERTIBLE_TYPE_TRAIT(__is_literal); + REVERTIBLE_TYPE_TRAIT(__is_lvalue_expr); + REVERTIBLE_TYPE_TRAIT(__is_lvalue_reference); + REVERTIBLE_TYPE_TRAIT(__is_member_function_pointer); + REVERTIBLE_TYPE_TRAIT(__is_member_object_pointer); + REVERTIBLE_TYPE_TRAIT(__is_member_pointer); + REVERTIBLE_TYPE_TRAIT(__is_nothrow_assignable); + REVERTIBLE_TYPE_TRAIT(__is_nothrow_constructible); + REVERTIBLE_TYPE_TRAIT(__is_nothrow_destructible); + REVERTIBLE_TYPE_TRAIT(__is_nullptr); + REVERTIBLE_TYPE_TRAIT(__is_object); + REVERTIBLE_TYPE_TRAIT(__is_pod); + REVERTIBLE_TYPE_TRAIT(__is_pointer); + REVERTIBLE_TYPE_TRAIT(__is_polymorphic); + REVERTIBLE_TYPE_TRAIT(__is_reference); + REVERTIBLE_TYPE_TRAIT(__is_referenceable); + REVERTIBLE_TYPE_TRAIT(__is_rvalue_expr); + REVERTIBLE_TYPE_TRAIT(__is_rvalue_reference); + REVERTIBLE_TYPE_TRAIT(__is_same); + REVERTIBLE_TYPE_TRAIT(__is_scalar); + REVERTIBLE_TYPE_TRAIT(__is_scoped_enum); + REVERTIBLE_TYPE_TRAIT(__is_sealed); + REVERTIBLE_TYPE_TRAIT(__is_signed); + REVERTIBLE_TYPE_TRAIT(__is_standard_layout); + REVERTIBLE_TYPE_TRAIT(__is_trivial); + REVERTIBLE_TYPE_TRAIT(__is_trivially_assignable); + REVERTIBLE_TYPE_TRAIT(__is_trivially_constructible); + REVERTIBLE_TYPE_TRAIT(__is_trivially_copyable); + REVERTIBLE_TYPE_TRAIT(__is_unbounded_array); + REVERTIBLE_TYPE_TRAIT(__is_union); + REVERTIBLE_TYPE_TRAIT(__is_unsigned); + REVERTIBLE_TYPE_TRAIT(__is_void); + REVERTIBLE_TYPE_TRAIT(__is_volatile); + REVERTIBLE_TYPE_TRAIT(__reference_binds_to_temporary); +#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) \ + REVERTIBLE_TYPE_TRAIT(RTT_JOIN(__, Trait)); +#include "clang/Basic/TransformTypeTraits.def" +#undef REVERTIBLE_TYPE_TRAIT +#undef RTT_JOIN + } + llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind>::iterator Known = + RevertibleTypeTraits.find(II); + if (Known != RevertibleTypeTraits.end()) { + if (Kind) + *Kind = Known->second; + return true; + } + return false; +} + +ExprResult Parser::ParseBuiltinPtrauthTypeDiscriminator() { + SourceLocation Loc = ConsumeToken(); + + BalancedDelimiterTracker T(*this, tok::l_paren); + if (T.expectAndConsume()) + return ExprError(); + + TypeResult Ty = ParseTypeName(); + if (Ty.isInvalid()) { + SkipUntil(tok::r_paren, StopAtSemi); + return ExprError(); + } + + SourceLocation EndLoc = Tok.getLocation(); + T.consumeClose(); + return Actions.ActOnUnaryExprOrTypeTraitExpr( + Loc, UETT_PtrAuthTypeDiscriminator, + /*isType=*/true, Ty.get().getAsOpaquePtr(), SourceRange(Loc, EndLoc)); +} + /// Parse a cast-expression, or, if \pisUnaryExpression is true, parse /// a unary-expression. /// @@ -999,6 +1121,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind, // primary-expression case tok::numeric_constant: + case tok::binary_data: // constant: integer-constant // constant: floating-constant @@ -1047,6 +1170,12 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind, break; } + case tok::annot_embed: { + injectEmbedTokens(); + return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast, + isVectorLiteral, NotPrimaryExpression); + } + case tok::kw___super: case tok::kw_decltype: // Annotate the token and tail recurse. @@ -1065,103 +1194,37 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind, if (getLangOpts().CPlusPlus) { // Avoid the unnecessary parse-time lookup in the common case // where the syntax forbids a type. - const Token &Next = NextToken(); + Token Next = NextToken(); + + if (Next.is(tok::ellipsis) && Tok.is(tok::identifier) && + GetLookAheadToken(2).is(tok::l_square)) { + // Annotate the token and tail recurse. + // If the token is not annotated, then it might be an expression pack + // indexing + if (!TryAnnotateTypeOrScopeToken() && + Tok.is(tok::annot_pack_indexing_type)) + return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast, + isVectorLiteral, NotPrimaryExpression); + } // If this identifier was reverted from a token ID, and the next token // is a parenthesis, this is likely to be a use of a type trait. Check // those tokens. - if (Next.is(tok::l_paren) && - Tok.is(tok::identifier) && - Tok.getIdentifierInfo()->hasRevertedTokenIDToIdentifier()) { + else if (Next.is(tok::l_paren) && Tok.is(tok::identifier) && + Tok.getIdentifierInfo()->hasRevertedTokenIDToIdentifier()) { IdentifierInfo *II = Tok.getIdentifierInfo(); - // Build up the mapping of revertible type traits, for future use. - if (RevertibleTypeTraits.empty()) { -#define RTT_JOIN(X,Y) X##Y -#define REVERTIBLE_TYPE_TRAIT(Name) \ - RevertibleTypeTraits[PP.getIdentifierInfo(#Name)] \ - = RTT_JOIN(tok::kw_,Name) - - REVERTIBLE_TYPE_TRAIT(__is_abstract); - REVERTIBLE_TYPE_TRAIT(__is_aggregate); - REVERTIBLE_TYPE_TRAIT(__is_arithmetic); - REVERTIBLE_TYPE_TRAIT(__is_array); - REVERTIBLE_TYPE_TRAIT(__is_assignable); - REVERTIBLE_TYPE_TRAIT(__is_base_of); - REVERTIBLE_TYPE_TRAIT(__is_bounded_array); - REVERTIBLE_TYPE_TRAIT(__is_class); - REVERTIBLE_TYPE_TRAIT(__is_complete_type); - REVERTIBLE_TYPE_TRAIT(__is_compound); - REVERTIBLE_TYPE_TRAIT(__is_const); - REVERTIBLE_TYPE_TRAIT(__is_constructible); - REVERTIBLE_TYPE_TRAIT(__is_convertible); - REVERTIBLE_TYPE_TRAIT(__is_convertible_to); - REVERTIBLE_TYPE_TRAIT(__is_destructible); - REVERTIBLE_TYPE_TRAIT(__is_empty); - REVERTIBLE_TYPE_TRAIT(__is_enum); - REVERTIBLE_TYPE_TRAIT(__is_floating_point); - REVERTIBLE_TYPE_TRAIT(__is_final); - REVERTIBLE_TYPE_TRAIT(__is_function); - REVERTIBLE_TYPE_TRAIT(__is_fundamental); - REVERTIBLE_TYPE_TRAIT(__is_integral); - REVERTIBLE_TYPE_TRAIT(__is_interface_class); - REVERTIBLE_TYPE_TRAIT(__is_literal); - REVERTIBLE_TYPE_TRAIT(__is_lvalue_expr); - REVERTIBLE_TYPE_TRAIT(__is_lvalue_reference); - REVERTIBLE_TYPE_TRAIT(__is_member_function_pointer); - REVERTIBLE_TYPE_TRAIT(__is_member_object_pointer); - REVERTIBLE_TYPE_TRAIT(__is_member_pointer); - REVERTIBLE_TYPE_TRAIT(__is_nothrow_assignable); - REVERTIBLE_TYPE_TRAIT(__is_nothrow_constructible); - REVERTIBLE_TYPE_TRAIT(__is_nothrow_destructible); - REVERTIBLE_TYPE_TRAIT(__is_nullptr); - REVERTIBLE_TYPE_TRAIT(__is_object); - REVERTIBLE_TYPE_TRAIT(__is_pod); - REVERTIBLE_TYPE_TRAIT(__is_pointer); - REVERTIBLE_TYPE_TRAIT(__is_polymorphic); - REVERTIBLE_TYPE_TRAIT(__is_reference); - REVERTIBLE_TYPE_TRAIT(__is_referenceable); - REVERTIBLE_TYPE_TRAIT(__is_rvalue_expr); - REVERTIBLE_TYPE_TRAIT(__is_rvalue_reference); - REVERTIBLE_TYPE_TRAIT(__is_same); - REVERTIBLE_TYPE_TRAIT(__is_scalar); - REVERTIBLE_TYPE_TRAIT(__is_scoped_enum); - REVERTIBLE_TYPE_TRAIT(__is_sealed); - REVERTIBLE_TYPE_TRAIT(__is_signed); - REVERTIBLE_TYPE_TRAIT(__is_standard_layout); - REVERTIBLE_TYPE_TRAIT(__is_trivial); - REVERTIBLE_TYPE_TRAIT(__is_trivially_assignable); - REVERTIBLE_TYPE_TRAIT(__is_trivially_constructible); - REVERTIBLE_TYPE_TRAIT(__is_trivially_copyable); - REVERTIBLE_TYPE_TRAIT(__is_unbounded_array); - REVERTIBLE_TYPE_TRAIT(__is_union); - REVERTIBLE_TYPE_TRAIT(__is_unsigned); - REVERTIBLE_TYPE_TRAIT(__is_void); - REVERTIBLE_TYPE_TRAIT(__is_volatile); - REVERTIBLE_TYPE_TRAIT(__reference_binds_to_temporary); - REVERTIBLE_TYPE_TRAIT(__reference_constructs_from_temporary); -#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) \ - REVERTIBLE_TYPE_TRAIT(RTT_JOIN(__, Trait)); -#include "clang/Basic/TransformTypeTraits.def" -#undef REVERTIBLE_TYPE_TRAIT -#undef RTT_JOIN - } - - // If we find that this is in fact the name of a type trait, - // update the token kind in place and parse again to treat it as - // the appropriate kind of type trait. - llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind>::iterator Known - = RevertibleTypeTraits.find(II); - if (Known != RevertibleTypeTraits.end()) { - Tok.setKind(Known->second); + tok::TokenKind Kind; + if (isRevertibleTypeTrait(II, &Kind)) { + Tok.setKind(Kind); return ParseCastExpression(ParseKind, isAddressOfOperand, NotCastExpr, isTypeCast, isVectorLiteral, NotPrimaryExpression); } } - if ((!ColonIsSacred && Next.is(tok::colon)) || - Next.isOneOf(tok::coloncolon, tok::less, tok::l_paren, - tok::l_brace)) { + else if ((!ColonIsSacred && Next.is(tok::colon)) || + Next.isOneOf(tok::coloncolon, tok::less, tok::l_paren, + tok::l_brace)) { // If TryAnnotateTypeOrScopeToken annotates the token, tail recurse. if (TryAnnotateTypeOrScopeToken()) return ExprError(); @@ -1187,7 +1250,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind, if (Tok.is(tok::code_completion) && &II != Ident_super) { cutOffParsing(); - Actions.CodeCompleteObjCClassPropertyRefExpr( + Actions.CodeCompletion().CodeCompleteObjCClassPropertyRefExpr( getCurScope(), II, ILoc, ExprStatementTokLoc == ILoc); return ExprError(); } @@ -1200,8 +1263,8 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind, IdentifierInfo &PropertyName = *Tok.getIdentifierInfo(); SourceLocation PropertyLoc = ConsumeToken(); - Res = Actions.ActOnClassPropertyRefExpr(II, PropertyName, - ILoc, PropertyLoc); + Res = Actions.ObjC().ActOnClassPropertyRefExpr(II, PropertyName, ILoc, + PropertyLoc); break; } @@ -1289,6 +1352,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind, /*isVectorLiteral=*/false, NotPrimaryExpression); } + Res = tryParseCXXPackIndexingExpression(Res); if (!Res.isInvalid() && Tok.is(tok::less)) checkPotentialAngleBracket(Res); break; @@ -1451,8 +1515,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind, return Res; } case tok::kw__Alignof: // unary-expression: '_Alignof' '(' type-name ')' - if (!getLangOpts().C11) - Diag(Tok, diag::ext_c11_feature) << Tok.getName(); + diagnoseUseOfC11Keyword(Tok); [[fallthrough]]; case tok::kw_alignof: // unary-expression: 'alignof' '(' type-id ')' case tok::kw___alignof: // unary-expression: '__alignof' unary-expression @@ -1549,6 +1612,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind, [[fallthrough]]; case tok::annot_decltype: + case tok::annot_pack_indexing_type: case tok::kw_char: case tok::kw_wchar_t: case tok::kw_char8_t: @@ -1597,7 +1661,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind, if (TryAnnotateTypeOrScopeToken()) return ExprError(); - if (!Actions.isSimpleTypeSpecifier(Tok.getKind())) + if (!Tok.isSimpleTypeSpecifier(getLangOpts())) // We are trying to parse a simple-type-specifier but might not get such // a token after error recovery. return ExprError(); @@ -1764,6 +1828,9 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind, Res = ParseArrayTypeTrait(); break; + case tok::kw___builtin_ptrauth_type_discriminator: + return ParseBuiltinPtrauthTypeDiscriminator(); + case tok::kw___is_lvalue_expr: case tok::kw___is_rvalue_expr: if (NotPrimaryExpression) @@ -1782,8 +1849,8 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind, break; case tok::code_completion: { cutOffParsing(); - Actions.CodeCompleteExpression(getCurScope(), - PreferredType.get(Tok.getLocation())); + Actions.CodeCompletion().CodeCompleteExpression( + getCurScope(), PreferredType.get(Tok.getLocation())); return ExprError(); } #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait: @@ -1798,7 +1865,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind, } goto ExpectedExpression; case tok::l_square: - if (getLangOpts().CPlusPlus11) { + if (getLangOpts().CPlusPlus) { if (getLangOpts().ObjC) { // C++11 lambda expressions and Objective-C message sends both start with a // square bracket. There are three possibilities here: @@ -1927,7 +1994,7 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { return LHS; cutOffParsing(); - Actions.CodeCompletePostfixExpression( + Actions.CodeCompletion().CodeCompletePostfixExpression( getCurScope(), LHS, PreferredType.get(Tok.getLocation())); return ExprError(); @@ -2010,7 +2077,8 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { if (Tok.is(tok::colon)) { // Consume ':' ColonLocFirst = ConsumeToken(); - Length = Actions.CorrectDelayedTyposInExpr(ParseExpression()); + if (Tok.isNot(tok::r_square)) + Length = Actions.CorrectDelayedTyposInExpr(ParseExpression()); } } else if (ArgExprs.size() <= 1 && getLangOpts().OpenMP) { ColonProtectionRAIIObject RAII(*this); @@ -2042,15 +2110,22 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { if (!LHS.isInvalid() && !HasError && !Length.isInvalid() && !Stride.isInvalid() && Tok.is(tok::r_square)) { if (ColonLocFirst.isValid() || ColonLocSecond.isValid()) { - // FIXME: OpenACC hasn't implemented Sema/Array section handling at a - // semantic level yet. For now, just reuse the OpenMP implementation - // as it gets the parsing/type management mostly right, and we can - // replace this call to ActOnOpenACCArraySectionExpr in the future. - // Eventually we'll genericize the OPenMPArraySectionExpr type as - // well. - LHS = Actions.ActOnOMPArraySectionExpr( - LHS.get(), Loc, ArgExprs.empty() ? nullptr : ArgExprs[0], - ColonLocFirst, ColonLocSecond, Length.get(), Stride.get(), RLoc); + // Like above, AllowOpenACCArraySections is 'more specific' and only + // enabled when actively parsing a 'var' in a 'var-list' during + // clause/'cache' construct parsing, so it is more specific. So we + // should do it first, so that the correct node gets created. + if (AllowOpenACCArraySections) { + assert(!Stride.isUsable() && !ColonLocSecond.isValid() && + "Stride/second colon not allowed for OpenACC"); + LHS = Actions.OpenACC().ActOnArraySectionExpr( + LHS.get(), Loc, ArgExprs.empty() ? nullptr : ArgExprs[0], + ColonLocFirst, Length.get(), RLoc); + } else { + LHS = Actions.OpenMP().ActOnOMPArraySectionExpr( + LHS.get(), Loc, ArgExprs.empty() ? nullptr : ArgExprs[0], + ColonLocFirst, ColonLocSecond, Length.get(), Stride.get(), + RLoc); + } } else { LHS = Actions.ActOnArraySubscriptExpr(getCurScope(), LHS.get(), Loc, ArgExprs, RLoc); @@ -2103,10 +2178,8 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { } if (!LHS.isInvalid()) { - ExprResult ECResult = Actions.ActOnCUDAExecConfigExpr(getCurScope(), - OpenLoc, - ExecConfigExprs, - CloseLoc); + ExprResult ECResult = Actions.CUDA().ActOnExecConfigExpr( + getCurScope(), OpenLoc, ExecConfigExprs, CloseLoc); if (ECResult.isInvalid()) LHS = ExprError(); else @@ -2119,8 +2192,9 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { ExprVector ArgExprs; auto RunSignatureHelp = [&]() -> QualType { - QualType PreferredType = Actions.ProduceCallSignatureHelp( - LHS.get(), ArgExprs, PT.getOpenLocation()); + QualType PreferredType = + Actions.CodeCompletion().ProduceCallSignatureHelp( + LHS.get(), ArgExprs, PT.getOpenLocation()); CalledSignatureHelp = true; return PreferredType; }; @@ -2244,7 +2318,7 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { // Code completion for a member access expression. cutOffParsing(); - Actions.CodeCompleteMemberReferenceExpr( + Actions.CodeCompletion().CodeCompleteMemberReferenceExpr( getCurScope(), Base, CorrectedBase, OpLoc, OpKind == tok::arrow, Base && ExprStatementTokLoc == Base->getBeginLoc(), PreferredType.get(Tok.getLocation())); @@ -2465,8 +2539,8 @@ ExprResult Parser::ParseSYCLUniqueStableNameExpression() { if (T.consumeClose()) return ExprError(); - return Actions.ActOnSYCLUniqueStableNameExpr(OpLoc, T.getOpenLocation(), - T.getCloseLocation(), Ty.get()); + return Actions.SYCL().ActOnUniqueStableNameExpr( + OpLoc, T.getOpenLocation(), T.getCloseLocation(), Ty.get()); } /// Parse a sizeof or alignof expression. @@ -2966,7 +3040,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr, if (Tok.is(tok::code_completion)) { cutOffParsing(); - Actions.CodeCompleteExpression( + Actions.CodeCompletion().CodeCompleteExpression( getCurScope(), PreferredType.get(Tok.getLocation()), /*IsParenthesized=*/ExprType >= CompoundLiteral); return ExprError(); @@ -3059,9 +3133,9 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr, if (Ty.isInvalid() || SubExpr.isInvalid()) return ExprError(); - return Actions.ActOnObjCBridgedCast(getCurScope(), OpenLoc, Kind, - BridgeKeywordLoc, Ty.get(), - RParenLoc, SubExpr.get()); + return Actions.ObjC().ActOnObjCBridgedCast(getCurScope(), OpenLoc, Kind, + BridgeKeywordLoc, Ty.get(), + RParenLoc, SubExpr.get()); } else if (ExprType >= CompoundLiteral && isTypeIdInParens(isAmbiguousTypeId)) { @@ -3252,7 +3326,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr, if (ErrorFound) { Result = ExprError(); } else if (!Result.isInvalid()) { - Result = Actions.ActOnOMPArrayShapingExpr( + Result = Actions.OpenMP().ActOnOMPArrayShapingExpr( Result.get(), OpenLoc, RParenLoc, OMPDimensions, OMPBracketsRanges); } return Result; @@ -3377,8 +3451,8 @@ ExprResult Parser::ParseStringLiteralExpression(bool AllowUserDefinedLiteral, /// \endverbatim ExprResult Parser::ParseGenericSelectionExpression() { assert(Tok.is(tok::kw__Generic) && "_Generic keyword expected"); - if (!getLangOpts().C11) - Diag(Tok, diag::ext_c11_feature) << Tok.getName(); + + diagnoseUseOfC11Keyword(Tok); SourceLocation KeyLoc = ConsumeToken(); BalancedDelimiterTracker T(*this, tok::l_paren); @@ -3397,7 +3471,8 @@ ExprResult Parser::ParseGenericSelectionExpression() { } const auto *LIT = cast<LocInfoType>(ControllingType.get().get()); SourceLocation Loc = LIT->getTypeSourceInfo()->getTypeLoc().getBeginLoc(); - Diag(Loc, diag::ext_generic_with_type_arg); + Diag(Loc, getLangOpts().C2y ? diag::warn_c2y_compat_generic_with_type_arg + : diag::ext_c2y_generic_with_type_arg); } else { // C11 6.5.1.1p3 "The controlling expression of a generic selection is // not evaluated." @@ -3526,6 +3601,31 @@ ExprResult Parser::ParseFoldExpression(ExprResult LHS, T.getCloseLocation()); } +void Parser::injectEmbedTokens() { + EmbedAnnotationData *Data = + reinterpret_cast<EmbedAnnotationData *>(Tok.getAnnotationValue()); + MutableArrayRef<Token> Toks(PP.getPreprocessorAllocator().Allocate<Token>( + Data->BinaryData.size() * 2 - 1), + Data->BinaryData.size() * 2 - 1); + unsigned I = 0; + for (auto &Byte : Data->BinaryData) { + Toks[I].startToken(); + Toks[I].setKind(tok::binary_data); + Toks[I].setLocation(Tok.getLocation()); + Toks[I].setLength(1); + Toks[I].setLiteralData(&Byte); + if (I != ((Data->BinaryData.size() - 1) * 2)) { + Toks[I + 1].startToken(); + Toks[I + 1].setKind(tok::comma); + Toks[I + 1].setLocation(Tok.getLocation()); + } + I += 2; + } + PP.EnterTokenStream(std::move(Toks), /*DisableMacroExpansion=*/true, + /*IsReinject=*/true); + ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); +} + /// ParseExpressionList - Used for C/C++ (argument-)expression-list. /// /// \verbatim @@ -3643,7 +3743,8 @@ bool Parser::ParseSimpleExpressionList(SmallVectorImpl<Expr *> &Exprs) { void Parser::ParseBlockId(SourceLocation CaretLoc) { if (Tok.is(tok::code_completion)) { cutOffParsing(); - Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Type); + Actions.CodeCompletion().CodeCompleteOrdinaryName( + getCurScope(), SemaCodeCompletion::PCC_Type); return; } @@ -3777,7 +3878,7 @@ ExprResult Parser::ParseBlockLiteralExpression() { /// '__objc_no' ExprResult Parser::ParseObjCBoolLiteral() { tok::TokenKind Kind = Tok.getKind(); - return Actions.ActOnObjCBoolLiteral(ConsumeToken(), Kind); + return Actions.ObjC().ActOnObjCBoolLiteral(ConsumeToken(), Kind); } /// Validate availability spec list, emitting diagnostics if necessary. Returns @@ -3832,7 +3933,7 @@ std::optional<AvailabilitySpec> Parser::ParseAvailabilitySpec() { // Parse the platform name. if (Tok.is(tok::code_completion)) { cutOffParsing(); - Actions.CodeCompleteAvailabilityPlatformName(); + Actions.CodeCompletion().CodeCompleteAvailabilityPlatformName(); return std::nullopt; } if (Tok.isNot(tok::identifier)) { @@ -3851,7 +3952,8 @@ std::optional<AvailabilitySpec> Parser::ParseAvailabilitySpec() { StringRef Platform = AvailabilityAttr::canonicalizePlatformName(GivenPlatform); - if (AvailabilityAttr::getPrettyPlatformName(Platform).empty()) { + if (AvailabilityAttr::getPrettyPlatformName(Platform).empty() || + (GivenPlatform.contains("xros") || GivenPlatform.contains("xrOS"))) { Diag(PlatformIdentifier->Loc, diag::err_avail_query_unrecognized_platform_name) << GivenPlatform; @@ -3897,6 +3999,6 @@ ExprResult Parser::ParseAvailabilityCheckExpr(SourceLocation BeginLoc) { if (Parens.consumeClose()) return ExprError(); - return Actions.ActOnObjCAvailabilityCheckExpr(AvailSpecs, BeginLoc, - Parens.getCloseLocation()); + return Actions.ObjC().ActOnObjCAvailabilityCheckExpr( + AvailSpecs, BeginLoc, Parens.getCloseLocation()); } |