@@ -3597,15 +3597,20 @@ namespace {
3597
3597
3598
3598
// Check if this method _is_ an overloaded operator but is not a
3599
3599
// call / subscript. Those 2 operators do not need static versions
3600
- if (cxxOperatorKind != clang::OverloadedOperatorKind::OO_None &&
3600
+ if (cxxOperatorKind != clang::OverloadedOperatorKind::OO_None &&
3601
3601
cxxOperatorKind != clang::OverloadedOperatorKind::OO_Call &&
3602
- cxxOperatorKind != clang::OverloadedOperatorKind::OO_Subscript) {
3602
+ cxxOperatorKind !=
3603
+ clang::OverloadedOperatorKind::OO_Subscript) {
3603
3604
3604
3605
auto opFuncDecl = makeOperator (MD, cxxMethod);
3605
3606
3606
3607
Impl.addAlternateDecl (MD, opFuncDecl);
3607
3608
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" );
3609
3614
3610
3615
// Make the actual member operator private.
3611
3616
MD->overwriteAccess (AccessLevel::Private);
@@ -5397,7 +5402,8 @@ namespace {
5397
5402
// / \param setter function returning `UnsafeMutablePointer<T>`
5398
5403
// / \return subscript declaration
5399
5404
SubscriptDecl *makeSubscript (FuncDecl *getter, FuncDecl *setter);
5400
- FuncDecl *makeOperator (FuncDecl *operatorMethod, clang::CXXMethodDecl *clangOperator);
5405
+ FuncDecl *makeOperator (FuncDecl *operatorMethod,
5406
+ clang::CXXMethodDecl *clangOperator);
5401
5407
5402
5408
VarDecl *makeComputedPropertyFromCXXMethods (FuncDecl *getter,
5403
5409
FuncDecl *setter);
@@ -8087,48 +8093,55 @@ SwiftDeclConverter::makeSubscript(FuncDecl *getter, FuncDecl *setter) {
8087
8093
return subscript;
8088
8094
}
8089
8095
8090
-
8091
8096
static std::pair<BraceStmt *, bool >
8092
8097
synthesizeOperatorMethodBody (AbstractFunctionDecl *afd, void *context) {
8093
8098
ASTContext &ctx = afd->getASTContext ();
8094
8099
8095
8100
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 */
8097
8103
8098
8104
SmallVector<Expr *, 8 > forwardingParams;
8099
8105
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 ());
8105
8114
8106
- if (param->isInOut ()) {
8107
- paramRefExpr->setType (LValueType::get (param->getType ()));
8115
+ if (param->isInOut ()) {
8116
+ paramRefExpr->setType (LValueType::get (param->getType ()));
8108
8117
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
+ }
8113
8122
8114
- forwardingParams.push_back (paramRefExpr);
8123
+ forwardingParams.push_back (paramRefExpr);
8115
8124
}
8116
8125
8117
- auto methodExpr = new (ctx) DeclRefExpr (methodDecl, DeclNameLoc (), /* implicit*/ true );
8126
+ auto methodExpr =
8127
+ new (ctx) DeclRefExpr (methodDecl, DeclNameLoc (), /* implicit*/ true );
8118
8128
methodExpr->setType (methodDecl->getInterfaceType ());
8119
8129
8120
8130
// Lhs parameter
8121
8131
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 );
8123
8134
baseExpr->setType (baseParam->getType ());
8124
8135
if (baseParam->isInOut ()) {
8125
- baseExpr->setType (LValueType::get (baseParam->getType ()));
8136
+ baseExpr->setType (LValueType::get (baseParam->getType ()));
8126
8137
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 ()));
8129
8141
}
8130
8142
8131
- auto dotCallExpr = DotSyntaxCallExpr::create (ctx, methodExpr, SourceLoc (), baseExpr);
8143
+ auto dotCallExpr =
8144
+ DotSyntaxCallExpr::create (ctx, methodExpr, SourceLoc (), baseExpr);
8132
8145
dotCallExpr->setType (methodDecl->getMethodInterfaceType ());
8133
8146
dotCallExpr->setThrows (false );
8134
8147
@@ -8140,27 +8153,30 @@ synthesizeOperatorMethodBody(AbstractFunctionDecl *afd, void *context) {
8140
8153
auto returnStmt = new (ctx) ReturnStmt (SourceLoc (), callExpr,
8141
8154
/* implicit=*/ true );
8142
8155
8143
-
8144
8156
auto body = BraceStmt::create (ctx, SourceLoc (), {returnStmt}, SourceLoc (),
8145
8157
/* implicit=*/ true );
8146
8158
return {body, /* isTypeChecked=*/ true };
8147
8159
}
8148
8160
8149
- FuncDecl *SwiftDeclConverter::makeOperator (FuncDecl *operatorMethod, clang::CXXMethodDecl *clangOperator) {
8161
+ FuncDecl *
8162
+ SwiftDeclConverter::makeOperator (FuncDecl *operatorMethod,
8163
+ clang::CXXMethodDecl *clangOperator) {
8150
8164
auto &ctx = Impl.SwiftContext ;
8151
- auto opName = clang::getOperatorSpelling (clangOperator->getOverloadedOperator ());
8165
+ auto opName =
8166
+ clang::getOperatorSpelling (clangOperator->getOverloadedOperator ());
8152
8167
auto paramList = operatorMethod->getParameters ();
8153
8168
auto genericParamList = operatorMethod->getGenericParams ();
8154
8169
8155
8170
auto opId = ctx.getIdentifier (opName);
8156
8171
8157
8172
auto parentCtx = operatorMethod->getDeclContext ();
8158
8173
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);
8162
8177
8163
- lhsParam->setInterfaceType (operatorMethod->getDeclContext ()->getSelfInterfaceType ());
8178
+ lhsParam->setInterfaceType (
8179
+ operatorMethod->getDeclContext ()->getSelfInterfaceType ());
8164
8180
8165
8181
if (operatorMethod->isMutating ()) {
8166
8182
// This implicitly makes the parameter indirect.
@@ -8172,35 +8188,32 @@ FuncDecl *SwiftDeclConverter::makeOperator(FuncDecl *operatorMethod, clang::CXXM
8172
8188
SmallVector<ParamDecl *, 4 > newParams;
8173
8189
newParams.push_back (lhsParam);
8174
8190
8175
- for (auto param : *paramList) {
8176
- newParams.push_back (param);
8191
+ for (auto param : *paramList) {
8192
+ newParams.push_back (param);
8177
8193
}
8178
8194
8179
8195
auto oldArgNames = operatorMethod->getName ().getArgumentNames ();
8180
8196
SmallVector<Identifier, 4 > newArgNames;
8181
8197
newArgNames.push_back (Identifier ());
8182
8198
8183
- for (auto id : oldArgNames) {
8184
- newArgNames.push_back (id);
8199
+ for (auto id : oldArgNames) {
8200
+ newArgNames.push_back (id);
8185
8201
}
8186
8202
8187
- auto opDeclName = DeclName (ctx, opId, {newArgNames.begin (), newArgNames.end ()});
8203
+ auto opDeclName =
8204
+ DeclName (ctx, opId, {newArgNames.begin (), newArgNames.end ()});
8188
8205
8189
8206
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);
8198
8211
8199
8212
topLevelStaticFuncDecl->setAccess (AccessLevel::Public);
8200
- topLevelStaticFuncDecl->setImplicit ();
8201
8213
topLevelStaticFuncDecl->setIsDynamic (false );
8202
8214
topLevelStaticFuncDecl->setStatic ();
8203
- topLevelStaticFuncDecl->setBodySynthesizer (synthesizeOperatorMethodBody, operatorMethod);
8215
+ topLevelStaticFuncDecl->setBodySynthesizer (synthesizeOperatorMethodBody,
8216
+ operatorMethod);
8204
8217
8205
8218
return topLevelStaticFuncDecl;
8206
8219
}
0 commit comments