@@ -804,7 +804,8 @@ static bool omitNeedlessWordsInFunctionName(
804
804
ArrayRef<const clang::ParmVarDecl *> params, clang::QualType resultType,
805
805
const clang::DeclContext *dc, const SmallBitVector &nonNullArgs,
806
806
Optional<unsigned > errorParamIndex, bool returnsSelf, bool isInstanceMethod,
807
- Optional<unsigned > completionHandlerIndex, NameImporter &nameImporter) {
807
+ Optional<unsigned > completionHandlerIndex,
808
+ Optional<StringRef> completionHandlerName, NameImporter &nameImporter) {
808
809
clang::ASTContext &clangCtx = nameImporter.getClangContext ();
809
810
810
811
// Collect the parameter type names.
@@ -854,8 +855,8 @@ static bool omitNeedlessWordsInFunctionName(
854
855
getClangTypeNameForOmission (clangCtx, resultType),
855
856
getClangTypeNameForOmission (clangCtx, contextType),
856
857
paramTypes, returnsSelf, /* isProperty=*/ false ,
857
- allPropertyNames, completionHandlerIndex. hasValue () ,
858
- nameImporter.getScratch ());
858
+ allPropertyNames, completionHandlerIndex,
859
+ completionHandlerName, nameImporter.getScratch ());
859
860
}
860
861
861
862
// / Prepare global name for importing onto a swift_newtype.
@@ -1135,26 +1136,9 @@ Optional<ForeignErrorConvention::Info> NameImporter::considerErrorImport(
1135
1136
// / Whether the given parameter name identifies a completion handler.
1136
1137
static bool isCompletionHandlerParamName (StringRef paramName) {
1137
1138
return paramName == " completionHandler" || paramName == " completion" ||
1138
- paramName == " withCompletionHandler" ;
1139
+ paramName == " withCompletionHandler" || paramName == " withCompletion " ;
1139
1140
}
1140
1141
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
-
1158
1142
// Determine whether the given type is a nullable NSError type.
1159
1143
static bool isNullableNSErrorType (
1160
1144
clang::ASTContext &clangCtx, clang::QualType type) {
@@ -1185,7 +1169,7 @@ static bool isNullableNSErrorType(
1185
1169
Optional<ForeignAsyncConvention::Info>
1186
1170
NameImporter::considerAsyncImport (
1187
1171
const clang::ObjCMethodDecl *clangDecl,
1188
- StringRef & baseName,
1172
+ StringRef baseName,
1189
1173
SmallVectorImpl<StringRef> ¶mNames,
1190
1174
ArrayRef<const clang::ParmVarDecl *> params,
1191
1175
bool isInitializer, bool hasCustomName,
@@ -1207,12 +1191,14 @@ NameImporter::considerAsyncImport(
1207
1191
1208
1192
// Determine whether the naming indicates that this is a completion
1209
1193
// handler.
1210
- Optional<StringRef> newBaseName;
1211
1194
if (isCompletionHandlerParamName (
1212
- paramNames[completionHandlerParamNameIndex])) {
1195
+ paramNames[completionHandlerParamNameIndex]) ||
1196
+ (completionHandlerParamNameIndex > 0 &&
1197
+ stripWithCompletionHandlerSuffix (
1198
+ paramNames[completionHandlerParamNameIndex]))) {
1213
1199
// The argument label itself has an appropriate name.
1214
1200
} else if (!hasCustomName && completionHandlerParamIndex == 0 &&
1215
- (newBaseName = isCompletionHandlerInBaseName ( baseName) )) {
1201
+ stripWithCompletionHandlerSuffix ( baseName)) {
1216
1202
// The base name implies that the first parameter is a completion handler.
1217
1203
} else if (isCompletionHandlerParamName (
1218
1204
params[completionHandlerParamIndex]->getName ())) {
@@ -1301,10 +1287,6 @@ NameImporter::considerAsyncImport(
1301
1287
// Drop the completion handler parameter name.
1302
1288
paramNames.erase (paramNames.begin () + completionHandlerParamNameIndex);
1303
1289
1304
- // Update the base name, if needed.
1305
- if (newBaseName && !hasCustomName)
1306
- baseName = *newBaseName;
1307
-
1308
1290
return ForeignAsyncConvention::Info (
1309
1291
completionHandlerParamIndex, completionHandlerErrorParamIndex);
1310
1292
}
@@ -1968,7 +1950,7 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
1968
1950
(void )omitNeedlessWords (baseName, {}, " " , propertyTypeName,
1969
1951
contextTypeName, {}, /* returnsSelf=*/ false ,
1970
1952
/* isProperty=*/ true , allPropertyNames,
1971
- /* isAsync= */ false , scratch);
1953
+ None, None , scratch);
1972
1954
}
1973
1955
}
1974
1956
@@ -1985,6 +1967,11 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
1985
1967
[](const ForeignAsyncConvention::Info &info) {
1986
1968
return info.CompletionHandlerParamIndex ;
1987
1969
}),
1970
+ result.getAsyncInfo ().map (
1971
+ [&](const ForeignAsyncConvention::Info &info) {
1972
+ return method->getDeclName ().getObjCSelector ().getNameForSlot (
1973
+ info.CompletionHandlerParamIndex );
1974
+ }),
1988
1975
*this );
1989
1976
}
1990
1977
0 commit comments