Skip to content

Commit abd3c16

Browse files
committed
[NFC] Remove out parameters. Create struct for return type.
Instead of having out parameters for a couple of flags, create a small struct with the type and the flags and return that struct inside the Optional of importParameterType. Additionally change the naming of some variables to make the function and method code more similar.
1 parent 691dcc9 commit abd3c16

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,21 +2241,23 @@ getImportTypeKindForParam(const clang::ParmVarDecl *param) {
22412241
return importKind;
22422242
}
22432243

2244-
Optional<swift::Type> ClangImporter::Implementation::importParameterType(
2244+
Optional<ClangImporter::Implementation::ImportParameterTypeResult>
2245+
ClangImporter::Implementation::importParameterType(
22452246
const clang::ParmVarDecl *param, OptionalTypeKind optionalityOfParam,
22462247
bool allowNSUIntegerAsInt, bool isNSDictionarySubscriptGetter,
22472248
bool paramIsError, bool paramIsCompletionHandler,
22482249
Optional<unsigned> completionHandlerErrorParamIndex,
22492250
ArrayRef<GenericTypeParamDecl *> genericParams,
2250-
llvm::function_ref<void(Diagnostic &&)> addImportDiagnosticFn,
2251-
bool &isInOut, bool &isParamTypeImplicitlyUnwrapped) {
2251+
llvm::function_ref<void(Diagnostic &&)> addImportDiagnosticFn) {
22522252
auto paramTy = param->getType();
22532253

22542254
ImportTypeKind importKind = getImportTypeKindForParam(param);
22552255

22562256
// Import the parameter type into Swift.
22572257
auto attrs = getImportTypeAttrs(param, /*isParam=*/true);
22582258
Type swiftParamTy;
2259+
bool isInOut = false;
2260+
bool isParamTypeImplicitlyUnwrapped = false;
22592261

22602262
// Sometimes we import unavailable typedefs as enums. If that's the case,
22612263
// use the enum, not the typedef here.
@@ -2351,7 +2353,8 @@ Optional<swift::Type> ClangImporter::Implementation::importParameterType(
23512353
swiftParamTy = importedType.getType();
23522354
}
23532355

2354-
return swiftParamTy;
2356+
return ImportParameterTypeResult{swiftParamTy, isInOut,
2357+
isParamTypeImplicitlyUnwrapped};
23552358
}
23562359

23572360
static ParamDecl *getParameterInfo(ClangImporter::Implementation *impl,
@@ -2409,23 +2412,22 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
24092412

24102413
ImportDiagnosticAdder paramAddDiag(*this, clangDecl, param->getLocation());
24112414

2412-
bool isInOut = false;
2413-
bool isParamTypeImplicitlyUnwrapped = false;
2414-
24152415
auto swiftParamTyOpt = importParameterType(
24162416
param, optionalityOfParam, allowNSUIntegerAsInt,
24172417
/*isNSDictionarySubscriptGetter=*/false,
24182418
/*paramIsError=*/false,
24192419
/*paramIsCompletionHandler=*/false,
2420-
/*completionHandlerErrorParamIndex=*/None, genericParams, paramAddDiag,
2421-
isInOut, isParamTypeImplicitlyUnwrapped);
2420+
/*completionHandlerErrorParamIndex=*/None, genericParams, paramAddDiag);
24222421
if (!swiftParamTyOpt) {
24232422
addImportDiagnostic(param,
24242423
Diagnostic(diag::parameter_type_not_imported, param),
24252424
param->getSourceRange().getBegin());
24262425
return nullptr;
24272426
}
2428-
auto swiftParamTy = *swiftParamTyOpt;
2427+
auto swiftParamTy = swiftParamTyOpt->swiftTy;
2428+
bool isInOut = swiftParamTyOpt->isInOut;
2429+
bool isParamTypeImplicitlyUnwrapped =
2430+
swiftParamTyOpt->isParamTypeImplicitlyUnwrapped;
24292431

24302432
// Retrieve the argument name.
24312433
Identifier name;
@@ -2984,20 +2986,21 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
29842986

29852987
ImportDiagnosticAdder paramAddDiag(*this, clangDecl, param->getLocation());
29862988

2987-
bool isInOut = false;
2988-
bool paramIsIUO = false;
29892989
auto swiftParamTyOpt = importParameterType(
29902990
param, optionalityOfParam, allowNSUIntegerAsIntInParam,
29912991
kind == SpecialMethodKind::NSDictionarySubscriptGetter, paramIsError,
29922992
paramIsCompletionHandler, completionHandlerErrorParamIndex,
2993-
ArrayRef<GenericTypeParamDecl *>(), paramAddDiag, isInOut, paramIsIUO);
2993+
ArrayRef<GenericTypeParamDecl *>(), paramAddDiag);
29942994
if (!swiftParamTyOpt) {
29952995
addImportDiagnostic(param,
29962996
Diagnostic(diag::parameter_type_not_imported, param),
29972997
param->getSourceRange().getBegin());
29982998
return {Type(), false};
29992999
}
3000-
auto swiftParamTy = *swiftParamTyOpt;
3000+
auto swiftParamTy = swiftParamTyOpt->swiftTy;
3001+
bool isInOut = swiftParamTyOpt->isInOut;
3002+
bool isParamTypeImplicitlyUnwrapped =
3003+
swiftParamTyOpt->isParamTypeImplicitlyUnwrapped;
30013004

30023005
swiftParamTy = mapGenericArgs(origDC, dc, swiftParamTy);
30033006

@@ -3044,8 +3047,8 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
30443047
++nameIndex;
30453048

30463049
// Set up the parameter info
3047-
auto paramInfo =
3048-
getParameterInfo(this, param, name, swiftParamTy, isInOut, paramIsIUO);
3050+
auto paramInfo = getParameterInfo(this, param, name, swiftParamTy, isInOut,
3051+
isParamTypeImplicitlyUnwrapped);
30493052

30503053
// Determine whether we have a default argument.
30513054
if (kind == SpecialMethodKind::Regular ||

lib/ClangImporter/ImporterImpl.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,15 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
13641364
bool allowNSUIntegerAsInt, ArrayRef<Identifier> argNames,
13651365
ArrayRef<GenericTypeParamDecl *> genericParams, Type resultType);
13661366

1367+
struct ImportParameterTypeResult {
1368+
/// The imported parameter Swift type.
1369+
swift::Type swiftTy;
1370+
/// If the parameter is or not inout.
1371+
bool isInOut;
1372+
/// If the parameter is implicitly unwrapped or not.
1373+
bool isParamTypeImplicitlyUnwrapped;
1374+
};
1375+
13671376
/// Import a parameter type
13681377
///
13691378
/// \param param The underlaying parameter declaraction.
@@ -1390,20 +1399,15 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
13901399
/// diagnostics to the declaration being imported. This can be any
13911400
/// lambda or callable object, but it's designed to be compatible
13921401
/// with \c ImportDiagnosticAdder .
1393-
/// \param[out] isInOut On return, true if the parameter is inout. False,
1394-
/// otherwise.
1395-
/// \param[out] isParamTypeImplicitlyUnwrapped On return, true if the
1396-
/// parameter is implicitly unwrapped. False, otherwise.
13971402
///
1398-
/// \returns The imported parameter type on success, or None on failure.
1399-
Optional<swift::Type> importParameterType(
1403+
/// \returns The imported parameter result on success, or None on failure.
1404+
Optional<ImportParameterTypeResult> importParameterType(
14001405
const clang::ParmVarDecl *param, OptionalTypeKind optionalityOfParam,
14011406
bool allowNSUIntegerAsInt, bool isNSDictionarySubscriptGetter,
14021407
bool paramIsError, bool paramIsCompletionHandler,
14031408
Optional<unsigned> completionHandlerErrorParamIndex,
14041409
ArrayRef<GenericTypeParamDecl *> genericParams,
1405-
llvm::function_ref<void(Diagnostic &&)> addImportDiagnosticFn,
1406-
bool &isInOut, bool &isParamTypeImplicitlyUnwrapped);
1410+
llvm::function_ref<void(Diagnostic &&)> addImportDiagnosticFn);
14071411

14081412
ImportedType importPropertyType(const clang::ObjCPropertyDecl *clangDecl,
14091413
bool isFromSystemModule);

0 commit comments

Comments
 (0)