@@ -804,7 +804,8 @@ static bool omitNeedlessWordsInFunctionName(
804804 ArrayRef<const clang::ParmVarDecl *> params, clang::QualType resultType,
805805 const clang::DeclContext *dc, const SmallBitVector &nonNullArgs,
806806 Optional<unsigned > errorParamIndex, bool returnsSelf, bool isInstanceMethod,
807- Optional<unsigned > completionHandlerIndex, NameImporter &nameImporter) {
807+ Optional<unsigned > completionHandlerIndex,
808+ Optional<StringRef> completionHandlerName, NameImporter &nameImporter) {
808809 clang::ASTContext &clangCtx = nameImporter.getClangContext ();
809810
810811 // Collect the parameter type names.
@@ -854,8 +855,8 @@ static bool omitNeedlessWordsInFunctionName(
854855 getClangTypeNameForOmission (clangCtx, resultType),
855856 getClangTypeNameForOmission (clangCtx, contextType),
856857 paramTypes, returnsSelf, /* isProperty=*/ false ,
857- allPropertyNames, completionHandlerIndex. hasValue () ,
858- nameImporter.getScratch ());
858+ allPropertyNames, completionHandlerIndex,
859+ completionHandlerName, nameImporter.getScratch ());
859860}
860861
861862// / Prepare global name for importing onto a swift_newtype.
@@ -1135,26 +1136,9 @@ Optional<ForeignErrorConvention::Info> NameImporter::considerErrorImport(
11351136// / Whether the given parameter name identifies a completion handler.
11361137static bool isCompletionHandlerParamName (StringRef paramName) {
11371138 return paramName == " completionHandler" || paramName == " completion" ||
1138- paramName == " withCompletionHandler" ;
1139+ paramName == " withCompletionHandler" || paramName == " withCompletion " ;
11391140}
11401141
1141- // / Whether the give base name implies that the first parameter is a completion
1142- // / handler.
1143- // /
1144- // / \returns a trimmed base name when it does, \c None others
1145- static Optional<StringRef> isCompletionHandlerInBaseName (StringRef basename) {
1146- if (basename.endswith (" WithCompletionHandler" )) {
1147- return basename.drop_back (strlen (" WithCompletionHandler" ));
1148- }
1149-
1150- if (basename.endswith (" WithCompletion" )) {
1151- return basename.drop_back (strlen (" WithCompletion" ));
1152- }
1153-
1154- return None;
1155- }
1156-
1157-
11581142// Determine whether the given type is a nullable NSError type.
11591143static bool isNullableNSErrorType (
11601144 clang::ASTContext &clangCtx, clang::QualType type) {
@@ -1185,7 +1169,7 @@ static bool isNullableNSErrorType(
11851169Optional<ForeignAsyncConvention::Info>
11861170NameImporter::considerAsyncImport (
11871171 const clang::ObjCMethodDecl *clangDecl,
1188- StringRef & baseName,
1172+ StringRef baseName,
11891173 SmallVectorImpl<StringRef> ¶mNames,
11901174 ArrayRef<const clang::ParmVarDecl *> params,
11911175 bool isInitializer, bool hasCustomName,
@@ -1207,12 +1191,14 @@ NameImporter::considerAsyncImport(
12071191
12081192 // Determine whether the naming indicates that this is a completion
12091193 // handler.
1210- Optional<StringRef> newBaseName;
12111194 if (isCompletionHandlerParamName (
1212- paramNames[completionHandlerParamNameIndex])) {
1195+ paramNames[completionHandlerParamNameIndex]) ||
1196+ (completionHandlerParamNameIndex > 0 &&
1197+ stripWithCompletionHandlerSuffix (
1198+ paramNames[completionHandlerParamNameIndex]))) {
12131199 // The argument label itself has an appropriate name.
12141200 } else if (!hasCustomName && completionHandlerParamIndex == 0 &&
1215- (newBaseName = isCompletionHandlerInBaseName ( baseName) )) {
1201+ stripWithCompletionHandlerSuffix ( baseName)) {
12161202 // The base name implies that the first parameter is a completion handler.
12171203 } else if (isCompletionHandlerParamName (
12181204 params[completionHandlerParamIndex]->getName ())) {
@@ -1301,10 +1287,6 @@ NameImporter::considerAsyncImport(
13011287 // Drop the completion handler parameter name.
13021288 paramNames.erase (paramNames.begin () + completionHandlerParamNameIndex);
13031289
1304- // Update the base name, if needed.
1305- if (newBaseName && !hasCustomName)
1306- baseName = *newBaseName;
1307-
13081290 return ForeignAsyncConvention::Info (
13091291 completionHandlerParamIndex, completionHandlerErrorParamIndex);
13101292}
@@ -1968,7 +1950,7 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
19681950 (void )omitNeedlessWords (baseName, {}, " " , propertyTypeName,
19691951 contextTypeName, {}, /* returnsSelf=*/ false ,
19701952 /* isProperty=*/ true , allPropertyNames,
1971- /* isAsync= */ false , scratch);
1953+ None, None , scratch);
19721954 }
19731955 }
19741956
@@ -1985,6 +1967,11 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
19851967 [](const ForeignAsyncConvention::Info &info) {
19861968 return info.CompletionHandlerParamIndex ;
19871969 }),
1970+ result.getAsyncInfo ().map (
1971+ [&](const ForeignAsyncConvention::Info &info) {
1972+ return method->getDeclName ().getObjCSelector ().getNameForSlot (
1973+ info.CompletionHandlerParamIndex );
1974+ }),
19881975 *this );
19891976 }
19901977
0 commit comments