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