@@ -2292,53 +2292,6 @@ namespace {
2292
2292
}
2293
2293
2294
2294
if (auto MD = dyn_cast<FuncDecl>(member)) {
2295
- if (auto cxxMethod = dyn_cast<clang::CXXMethodDecl>(m)) {
2296
- ImportedName methodImportedName =
2297
- Impl.importFullName (cxxMethod, getActiveSwiftVersion ());
2298
- auto cxxOperatorKind = cxxMethod->getOverloadedOperator ();
2299
-
2300
- if (cxxOperatorKind == clang::OverloadedOperatorKind::OO_PlusPlus) {
2301
- // Make sure the type is not a foreign reference type.
2302
- // We cannot handle `operator++` for those types, since the
2303
- // current implementation creates a new instance of the type.
2304
- if (cxxMethod->param_empty () && !isa<ClassDecl>(result)) {
2305
- // This is a pre-increment operator. We synthesize a
2306
- // non-mutating function called `successor() -> Self`.
2307
- FuncDecl *successorFunc = synthesizer.makeSuccessorFunc (MD);
2308
- result->addMember (successorFunc);
2309
-
2310
- Impl.markUnavailable (MD, " use .successor()" );
2311
- } else {
2312
- Impl.markUnavailable (MD, " unable to create .successor() func" );
2313
- }
2314
- MD->overwriteAccess (AccessLevel::Private);
2315
- }
2316
- // Check if this method _is_ an overloaded operator but is not a
2317
- // call / subscript / dereference / increment. Those
2318
- // operators do not need static versions.
2319
- else if (cxxOperatorKind !=
2320
- clang::OverloadedOperatorKind::OO_None &&
2321
- cxxOperatorKind !=
2322
- clang::OverloadedOperatorKind::OO_PlusPlus &&
2323
- cxxOperatorKind !=
2324
- clang::OverloadedOperatorKind::OO_Call &&
2325
- !methodImportedName.isSubscriptAccessor () &&
2326
- !methodImportedName.isDereferenceAccessor ()) {
2327
-
2328
- auto opFuncDecl = synthesizer.makeOperator (MD, cxxMethod);
2329
-
2330
- Impl.addAlternateDecl (MD, opFuncDecl);
2331
-
2332
- auto msg = " use " + std::string{clang::getOperatorSpelling (cxxOperatorKind)} + " instead" ;
2333
- Impl.markUnavailable (MD,msg);
2334
-
2335
- // Make the actual member operator private.
2336
- MD->overwriteAccess (AccessLevel::Private);
2337
-
2338
- // Make sure the synthesized decl can be found by lookupDirect.
2339
- result->addMemberToLookupTable (opFuncDecl);
2340
- }
2341
- }
2342
2295
methods.push_back (MD);
2343
2296
continue ;
2344
2297
}
@@ -3272,12 +3225,19 @@ namespace {
3272
3225
}
3273
3226
3274
3227
// / Handles special functions such as subscripts and dereference operators.
3275
- bool processSpecialImportedFunc (FuncDecl *func, ImportedName importedName) {
3228
+ bool
3229
+ processSpecialImportedFunc (FuncDecl *func, ImportedName importedName,
3230
+ clang::OverloadedOperatorKind cxxOperatorKind) {
3231
+ if (cxxOperatorKind == clang::OverloadedOperatorKind::OO_None)
3232
+ return true ;
3233
+
3276
3234
auto dc = func->getDeclContext ();
3235
+ auto typeDecl = dc->getSelfNominalTypeDecl ();
3236
+ if (!typeDecl)
3237
+ return true ;
3277
3238
3278
3239
if (importedName.isSubscriptAccessor ()) {
3279
3240
assert (func->getParameters ()->size () == 1 );
3280
- auto typeDecl = dc->getSelfNominalTypeDecl ();
3281
3241
auto parameter = func->getParameters ()->get (0 );
3282
3242
auto parameterType = parameter->getTypeInContext ();
3283
3243
if (!typeDecl || !parameterType)
@@ -3307,10 +3267,10 @@ namespace {
3307
3267
}
3308
3268
3309
3269
Impl.markUnavailable (func, " use subscript" );
3270
+ return true ;
3310
3271
}
3311
3272
3312
3273
if (importedName.isDereferenceAccessor ()) {
3313
- auto typeDecl = dc->getSelfNominalTypeDecl ();
3314
3274
auto &getterAndSetter = Impl.cxxDereferenceOperators [typeDecl];
3315
3275
3316
3276
switch (importedName.getAccessorKind ()) {
@@ -3325,6 +3285,42 @@ namespace {
3325
3285
}
3326
3286
3327
3287
Impl.markUnavailable (func, " use .pointee property" );
3288
+ return true ;
3289
+ }
3290
+
3291
+ if (cxxOperatorKind == clang::OverloadedOperatorKind::OO_PlusPlus) {
3292
+ // Make sure the type is not a foreign reference type.
3293
+ // We cannot handle `operator++` for those types, since the
3294
+ // current implementation creates a new instance of the type.
3295
+ if (func->getParameters ()->size () == 0 && !isa<ClassDecl>(typeDecl)) {
3296
+ // This is a pre-increment operator. We synthesize a
3297
+ // non-mutating function called `successor() -> Self`.
3298
+ FuncDecl *successorFunc = synthesizer.makeSuccessorFunc (func);
3299
+ typeDecl->addMember (successorFunc);
3300
+
3301
+ Impl.markUnavailable (func, " use .successor()" );
3302
+ } else {
3303
+ Impl.markUnavailable (func, " unable to create .successor() func" );
3304
+ }
3305
+ func->overwriteAccess (AccessLevel::Private);
3306
+ return true ;
3307
+ }
3308
+
3309
+ // Check if this method _is_ an overloaded operator but is not a
3310
+ // call / subscript / dereference / increment. Those
3311
+ // operators do not need static versions.
3312
+ if (cxxOperatorKind != clang::OverloadedOperatorKind::OO_Call) {
3313
+ auto opFuncDecl = synthesizer.makeOperator (func, cxxOperatorKind);
3314
+ Impl.addAlternateDecl (func, opFuncDecl);
3315
+
3316
+ Impl.markUnavailable (
3317
+ func, (Twine (" use " ) + clang::getOperatorSpelling (cxxOperatorKind) +
3318
+ " instead" )
3319
+ .str ());
3320
+
3321
+ // Make sure the synthesized decl can be found by lookupDirect.
3322
+ typeDecl->addMemberToLookupTable (opFuncDecl);
3323
+ return true ;
3328
3324
}
3329
3325
3330
3326
return true ;
@@ -3654,7 +3650,8 @@ namespace {
3654
3650
func->setAccess (AccessLevel::Public);
3655
3651
3656
3652
if (!importFuncWithoutSignature) {
3657
- bool success = processSpecialImportedFunc (func, importedName);
3653
+ bool success = processSpecialImportedFunc (
3654
+ func, importedName, decl->getOverloadedOperator ());
3658
3655
if (!success)
3659
3656
return nullptr ;
3660
3657
}
@@ -4010,6 +4007,12 @@ namespace {
4010
4007
if (!importedDC)
4011
4008
return nullptr ;
4012
4009
4010
+ // While importing the DeclContext, we might have imported the decl
4011
+ // itself.
4012
+ auto known = Impl.importDeclCached (decl, getVersion ());
4013
+ if (known.has_value ())
4014
+ return known.value ();
4015
+
4013
4016
if (isa<clang::TypeDecl>(decl->getTargetDecl ())) {
4014
4017
Decl *SwiftDecl = Impl.importDecl (decl->getUnderlyingDecl (), getActiveSwiftVersion ());
4015
4018
if (!SwiftDecl)
@@ -4058,7 +4061,8 @@ namespace {
4058
4061
if (!clonedMethod)
4059
4062
return nullptr ;
4060
4063
4061
- bool success = processSpecialImportedFunc (clonedMethod, importedName);
4064
+ bool success = processSpecialImportedFunc (
4065
+ clonedMethod, importedName, targetMethod->getOverloadedOperator ());
4062
4066
if (!success)
4063
4067
return nullptr ;
4064
4068
0 commit comments