Skip to content

Commit 3102e23

Browse files
committed
Clang importer: switch init method importing over to importFullName.
Yet more name-importing refactoring toward eliminating some redundant code. As a drive-by, happens to fix swift_private imports for no-parameter init methods.
1 parent 13c1805 commit 3102e23

File tree

2 files changed

+12
-53
lines changed

2 files changed

+12
-53
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 11 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3108,54 +3108,6 @@ namespace {
31083108
}
31093109
}
31103110

3111-
/// Map an init method to a Swift declaration name.
3112-
///
3113-
/// Some special cased remappings also change the parameter signature of the
3114-
/// imported initializer, such as to drop vararg parameters.
3115-
///
3116-
/// All parameters are in/out parameters.
3117-
DeclName
3118-
mapInitSelectorToDeclName(ObjCSelector &selector,
3119-
ArrayRef<const clang::ParmVarDecl *> &args,
3120-
bool &variadic,
3121-
bool isSwiftPrivate) {
3122-
auto &C = Impl.SwiftContext;
3123-
3124-
// Map a few initializers to non-variadic versions that drop the
3125-
// variadic parameter.
3126-
if (variadic && shouldMakeSelectorNonVariadic(selector)) {
3127-
selector = ObjCSelector(C, selector.getNumArgs() - 1,
3128-
selector.getSelectorPieces().slice(0,
3129-
selector.getSelectorPieces().size() - 1));
3130-
args = args.slice(0, args.size() - 1);
3131-
variadic = false;
3132-
}
3133-
3134-
return Impl.mapSelectorToDeclName(selector, /*initializer*/true,
3135-
isSwiftPrivate);
3136-
}
3137-
3138-
static bool shouldMakeSelectorNonVariadic(ObjCSelector selector) {
3139-
// This is UIActionSheet's designated initializer.
3140-
if (selector.isNonNullarySelector({ "initWithTitle",
3141-
"delegate",
3142-
"cancelButtonTitle",
3143-
"destructiveButtonTitle",
3144-
"otherButtonTitles" }))
3145-
return true;
3146-
3147-
// This is UIAlertView's designated initializer.
3148-
if (selector.isNonNullarySelector({ "initWithTitle",
3149-
"message",
3150-
"delegate",
3151-
"cancelButtonTitle",
3152-
"otherButtonTitles" }))
3153-
return true;
3154-
3155-
// Nothing else for now.
3156-
return false;
3157-
}
3158-
31593111
/// \brief Given an imported method, try to import it as a constructor.
31603112
///
31613113
/// Objective-C methods in the 'init' family are imported as
@@ -3188,14 +3140,21 @@ namespace {
31883140
objcMethod->param_begin(),
31893141
objcMethod->param_end()
31903142
};
3191-
bool isSwiftPrivate = objcMethod->hasAttr<clang::SwiftPrivateAttr>();
3143+
31923144
bool variadic = objcMethod->isVariadic();
3193-
DeclName name = mapInitSelectorToDeclName(selector, params, variadic,
3194-
isSwiftPrivate);
3145+
auto importedName = Impl.importFullName(objcMethod);
3146+
if (!importedName) return nullptr;
3147+
3148+
// If we dropped the variadic, handle it now.
3149+
if (importedName.DroppedVariadic) {
3150+
params = params.slice(1);
3151+
variadic = false;
3152+
}
31953153

31963154
bool redundant;
31973155
return importConstructor(objcMethod, dc, implicit, kind, required,
3198-
selector, name, /*customName=*/false, params,
3156+
selector, importedName,
3157+
importedName.HasCustomName, params,
31993158
variadic, redundant);
32003159
}
32013160

test/ClangModules/Inputs/SwiftPrivateAttr.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Foo : NSObject, __PrivProto {
2525
init()
2626
}
2727
class Bar : NSObject {
28-
init!()
28+
init!(__: ())
2929
init!(__noArgs: ())
3030
init!(__oneArg arg: Int32)
3131
init!(__twoArgs arg: Int32, other arg2: Int32)

0 commit comments

Comments
 (0)