@@ -3597,15 +3597,20 @@ namespace {
35973597
35983598 // Check if this method _is_ an overloaded operator but is not a
35993599 // call / subscript. Those 2 operators do not need static versions
3600- if (cxxOperatorKind != clang::OverloadedOperatorKind::OO_None &&
3600+ if (cxxOperatorKind != clang::OverloadedOperatorKind::OO_None &&
36013601 cxxOperatorKind != clang::OverloadedOperatorKind::OO_Call &&
3602- cxxOperatorKind != clang::OverloadedOperatorKind::OO_Subscript) {
3602+ cxxOperatorKind !=
3603+ clang::OverloadedOperatorKind::OO_Subscript) {
36033604
36043605 auto opFuncDecl = makeOperator (MD, cxxMethod);
36053606
36063607 Impl.addAlternateDecl (MD, opFuncDecl);
36073608
3608- Impl.markUnavailable (MD, " use " + std::string{clang::getOperatorSpelling (cxxOperatorKind)} + " instead" );
3609+ Impl.markUnavailable (
3610+ MD,
3611+ " use " +
3612+ std::string{clang::getOperatorSpelling (cxxOperatorKind)} +
3613+ " instead" );
36093614
36103615 // Make the actual member operator private.
36113616 MD->overwriteAccess (AccessLevel::Private);
@@ -5397,7 +5402,8 @@ namespace {
53975402 // / \param setter function returning `UnsafeMutablePointer<T>`
53985403 // / \return subscript declaration
53995404 SubscriptDecl *makeSubscript (FuncDecl *getter, FuncDecl *setter);
5400- FuncDecl *makeOperator (FuncDecl *operatorMethod, clang::CXXMethodDecl *clangOperator);
5405+ FuncDecl *makeOperator (FuncDecl *operatorMethod,
5406+ clang::CXXMethodDecl *clangOperator);
54015407
54025408 VarDecl *makeComputedPropertyFromCXXMethods (FuncDecl *getter,
54035409 FuncDecl *setter);
@@ -8087,48 +8093,55 @@ SwiftDeclConverter::makeSubscript(FuncDecl *getter, FuncDecl *setter) {
80878093 return subscript;
80888094}
80898095
8090-
80918096static std::pair<BraceStmt *, bool >
80928097synthesizeOperatorMethodBody (AbstractFunctionDecl *afd, void *context) {
80938098 ASTContext &ctx = afd->getASTContext ();
80948099
80958100 auto funcDecl = cast<FuncDecl>(afd);
8096- auto methodDecl = static_cast <FuncDecl *>(context); /* Swift version of CXXMethod */
8101+ auto methodDecl =
8102+ static_cast <FuncDecl *>(context); /* Swift version of CXXMethod */
80978103
80988104 SmallVector<Expr *, 8 > forwardingParams;
80998105
8100- // We start from +1 since the first param is our lhs. All other params are forwarded
8101- for (auto itr = funcDecl->getParameters ()->begin () + 1 ; itr != funcDecl->getParameters ()->end (); itr++) {
8102- auto param = *itr;
8103- Expr *paramRefExpr = new (ctx) DeclRefExpr (param, DeclNameLoc (), /* Implicit=*/ true );
8104- paramRefExpr->setType (param->getType ());
8106+ // We start from +1 since the first param is our lhs. All other params are
8107+ // forwarded
8108+ for (auto itr = funcDecl->getParameters ()->begin () + 1 ;
8109+ itr != funcDecl->getParameters ()->end (); itr++) {
8110+ auto param = *itr;
8111+ Expr *paramRefExpr =
8112+ new (ctx) DeclRefExpr (param, DeclNameLoc (), /* Implicit=*/ true );
8113+ paramRefExpr->setType (param->getType ());
81058114
8106- if (param->isInOut ()) {
8107- paramRefExpr->setType (LValueType::get (param->getType ()));
8115+ if (param->isInOut ()) {
8116+ paramRefExpr->setType (LValueType::get (param->getType ()));
81088117
8109- paramRefExpr = new (ctx) InOutExpr (
8110- SourceLoc (), paramRefExpr, param->getType (), /* isImplicit*/ true );
8111- paramRefExpr->setType (InOutType::get (param->getType ()));
8112- }
8118+ paramRefExpr = new (ctx) InOutExpr (SourceLoc (), paramRefExpr,
8119+ param->getType (), /* isImplicit*/ true );
8120+ paramRefExpr->setType (InOutType::get (param->getType ()));
8121+ }
81138122
8114- forwardingParams.push_back (paramRefExpr);
8123+ forwardingParams.push_back (paramRefExpr);
81158124 }
81168125
8117- auto methodExpr = new (ctx) DeclRefExpr (methodDecl, DeclNameLoc (), /* implicit*/ true );
8126+ auto methodExpr =
8127+ new (ctx) DeclRefExpr (methodDecl, DeclNameLoc (), /* implicit*/ true );
81188128 methodExpr->setType (methodDecl->getInterfaceType ());
81198129
81208130 // Lhs parameter
81218131 auto baseParam = funcDecl->getParameters ()->front ();
8122- Expr *baseExpr = new (ctx) DeclRefExpr (baseParam, DeclNameLoc (), /* implicit*/ true );
8132+ Expr *baseExpr =
8133+ new (ctx) DeclRefExpr (baseParam, DeclNameLoc (), /* implicit*/ true );
81238134 baseExpr->setType (baseParam->getType ());
81248135 if (baseParam->isInOut ()) {
8125- baseExpr->setType (LValueType::get (baseParam->getType ()));
8136+ baseExpr->setType (LValueType::get (baseParam->getType ()));
81268137
8127- baseExpr = new (ctx) InOutExpr (SourceLoc (), baseExpr, baseParam->getType (), /* isImplicit*/ true );
8128- baseExpr->setType (InOutType::get (baseParam->getType ()));
8138+ baseExpr = new (ctx) InOutExpr (SourceLoc (), baseExpr, baseParam->getType (),
8139+ /* isImplicit*/ true );
8140+ baseExpr->setType (InOutType::get (baseParam->getType ()));
81298141 }
81308142
8131- auto dotCallExpr = DotSyntaxCallExpr::create (ctx, methodExpr, SourceLoc (), baseExpr);
8143+ auto dotCallExpr =
8144+ DotSyntaxCallExpr::create (ctx, methodExpr, SourceLoc (), baseExpr);
81328145 dotCallExpr->setType (methodDecl->getMethodInterfaceType ());
81338146 dotCallExpr->setThrows (false );
81348147
@@ -8140,27 +8153,30 @@ synthesizeOperatorMethodBody(AbstractFunctionDecl *afd, void *context) {
81408153 auto returnStmt = new (ctx) ReturnStmt (SourceLoc (), callExpr,
81418154 /* implicit=*/ true );
81428155
8143-
81448156 auto body = BraceStmt::create (ctx, SourceLoc (), {returnStmt}, SourceLoc (),
81458157 /* implicit=*/ true );
81468158 return {body, /* isTypeChecked=*/ true };
81478159}
81488160
8149- FuncDecl *SwiftDeclConverter::makeOperator (FuncDecl *operatorMethod, clang::CXXMethodDecl *clangOperator) {
8161+ FuncDecl *
8162+ SwiftDeclConverter::makeOperator (FuncDecl *operatorMethod,
8163+ clang::CXXMethodDecl *clangOperator) {
81508164 auto &ctx = Impl.SwiftContext ;
8151- auto opName = clang::getOperatorSpelling (clangOperator->getOverloadedOperator ());
8165+ auto opName =
8166+ clang::getOperatorSpelling (clangOperator->getOverloadedOperator ());
81528167 auto paramList = operatorMethod->getParameters ();
81538168 auto genericParamList = operatorMethod->getGenericParams ();
81548169
81558170 auto opId = ctx.getIdentifier (opName);
81568171
81578172 auto parentCtx = operatorMethod->getDeclContext ();
81588173
8159- auto lhsParam = new (ctx)
8160- ParamDecl (SourceLoc (), SourceLoc (), Identifier (), SourceLoc (),
8161- ctx.getIdentifier (" lhs" ), parentCtx);
8174+ auto lhsParam =
8175+ new (ctx) ParamDecl (SourceLoc (), SourceLoc (), Identifier (), SourceLoc (),
8176+ ctx.getIdentifier (" lhs" ), parentCtx);
81628177
8163- lhsParam->setInterfaceType (operatorMethod->getDeclContext ()->getSelfInterfaceType ());
8178+ lhsParam->setInterfaceType (
8179+ operatorMethod->getDeclContext ()->getSelfInterfaceType ());
81648180
81658181 if (operatorMethod->isMutating ()) {
81668182 // This implicitly makes the parameter indirect.
@@ -8172,35 +8188,32 @@ FuncDecl *SwiftDeclConverter::makeOperator(FuncDecl *operatorMethod, clang::CXXM
81728188 SmallVector<ParamDecl *, 4 > newParams;
81738189 newParams.push_back (lhsParam);
81748190
8175- for (auto param : *paramList) {
8176- newParams.push_back (param);
8191+ for (auto param : *paramList) {
8192+ newParams.push_back (param);
81778193 }
81788194
81798195 auto oldArgNames = operatorMethod->getName ().getArgumentNames ();
81808196 SmallVector<Identifier, 4 > newArgNames;
81818197 newArgNames.push_back (Identifier ());
81828198
8183- for (auto id : oldArgNames) {
8184- newArgNames.push_back (id);
8199+ for (auto id : oldArgNames) {
8200+ newArgNames.push_back (id);
81858201 }
81868202
8187- auto opDeclName = DeclName (ctx, opId, {newArgNames.begin (), newArgNames.end ()});
8203+ auto opDeclName =
8204+ DeclName (ctx, opId, {newArgNames.begin (), newArgNames.end ()});
81888205
81898206 auto topLevelStaticFuncDecl = FuncDecl::createImplicit (
8190- ctx,
8191- StaticSpellingKind::None,
8192- opDeclName, SourceLoc (),
8193- false , false ,
8194- genericParamList, ParameterList::create (ctx, newParams),
8195- operatorMethod->getResultInterfaceType (),
8196- parentCtx
8197- );
8207+ ctx, StaticSpellingKind::None, opDeclName, SourceLoc (),
8208+ /* Async*/ false , /* Throws*/ false , genericParamList,
8209+ ParameterList::create (ctx, newParams),
8210+ operatorMethod->getResultInterfaceType (), parentCtx);
81988211
81998212 topLevelStaticFuncDecl->setAccess (AccessLevel::Public);
8200- topLevelStaticFuncDecl->setImplicit ();
82018213 topLevelStaticFuncDecl->setIsDynamic (false );
82028214 topLevelStaticFuncDecl->setStatic ();
8203- topLevelStaticFuncDecl->setBodySynthesizer (synthesizeOperatorMethodBody, operatorMethod);
8215+ topLevelStaticFuncDecl->setBodySynthesizer (synthesizeOperatorMethodBody,
8216+ operatorMethod);
82048217
82058218 return topLevelStaticFuncDecl;
82068219}
0 commit comments