Skip to content

Commit 585a3a1

Browse files
committed
[NFC] Move some lines earlier in code flow
To make the refactor of the methods `importFunctionParameterList` and `importMethodParamsAndReturnType` easier in a later commit, move some lines that were intermixed with the common code earlier in each of those two methods. Even if some lines move earlier, there should be no difference functionally.
1 parent 0f3f460 commit 585a3a1

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,12 +2295,14 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
22952295

22962296
ImportTypeKind importKind = getImportTypeKindForParam(param);
22972297

2298-
// Import the parameter type into Swift.
22992298
ImportDiagnosticAdder paramAddDiag(*this, clangDecl, param->getLocation());
2299+
2300+
bool isInOut = false;
2301+
bool isParamTypeImplicitlyUnwrapped = false;
2302+
2303+
// Import the parameter type into Swift.
23002304
auto attrs = getImportTypeAttrs(param, /*isParam=*/true);
23012305
Type swiftParamTy;
2302-
bool isParamTypeImplicitlyUnwrapped = false;
2303-
bool isInOut = false;
23042306

23052307
// Sometimes we import unavailable typedefs as enums. If that's the case,
23062308
// use the enum, not the typedef here.
@@ -2902,13 +2904,20 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
29022904

29032905
bool paramIsCompletionHandler =
29042906
asyncInfo && paramIndex == asyncInfo->completionHandlerParamIndex();
2905-
2906-
// Import the parameter type into Swift.
2907+
// Figure out if this is a completion handler parameter whose error
2908+
// parameter is used to indicate throwing.
2909+
Optional<unsigned> completionHandlerErrorParamIndex;
2910+
if (isAsync && paramIsCompletionHandler) {
2911+
completionHandlerErrorParamIndex =
2912+
asyncInfo->completionHandlerErrorParamIndex();
2913+
}
29072914

29082915
// Check nullability of the parameter.
2909-
OptionalTypeKind optionalityOfParam
2910-
= getParamOptionality(param,
2911-
!nonNullArgs.empty() && nonNullArgs[paramIndex]);
2916+
bool knownNonNull = !nonNullArgs.empty() && nonNullArgs[paramIndex];
2917+
OptionalTypeKind optionalityOfParam =
2918+
getParamOptionality(param, knownNonNull);
2919+
2920+
// Import the parameter type into Swift.
29122921

29132922
bool allowNSUIntegerAsIntInParam = isFromSystemModule;
29142923
if (allowNSUIntegerAsIntInParam) {
@@ -2922,11 +2931,13 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
29222931
allowNSUIntegerAsIntInParam = !nameContainsUnsigned(name);
29232932
}
29242933

2925-
// Special case for NSDictionary's subscript.
29262934
ImportTypeKind importKind = getImportTypeKindForParam(param);
29272935
ImportDiagnosticAdder paramAddDiag(*this, clangDecl, param->getLocation());
2928-
Type swiftParamTy;
2936+
2937+
bool isInOut = false;
29292938
bool paramIsIUO = false;
2939+
2940+
Type swiftParamTy;
29302941
if (auto typedefType = dyn_cast<clang::TypedefType>(paramTy.getTypePtr())) {
29312942
if (isUnavailableInSwift(typedefType->getDecl())) {
29322943
if (auto clangEnum = findAnonymousEnumForTypedef(SwiftContext, typedefType)) {
@@ -2941,6 +2952,7 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
29412952
}
29422953
}
29432954

2955+
// Special case for NSDictionary's subscript.
29442956
if (kind == SpecialMethodKind::NSDictionarySubscriptGetter &&
29452957
paramTy->isObjCIdType()) {
29462958
// Not using `getImportTypeAttrs()` is unprincipled but OK for this hack.
@@ -2953,14 +2965,6 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
29532965

29542966
paramIsIUO = optionalityOfParam == OTK_ImplicitlyUnwrappedOptional;
29552967
} else if (!swiftParamTy) {
2956-
// Figure out if this is a completion handler parameter whose error
2957-
// parameter is used to indicate throwing.
2958-
Optional<unsigned> completionHandlerErrorParamIndex;
2959-
if (isAsync && paramIsCompletionHandler) {
2960-
completionHandlerErrorParamIndex =
2961-
asyncInfo->completionHandlerErrorParamIndex();
2962-
}
2963-
29642968
bool sendableByDefault = paramIsCompletionHandler &&
29652969
SwiftContext.LangOpts.hasFeature(Feature::SendableCompletionHandlers);
29662970

@@ -3033,8 +3037,8 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
30333037
++nameIndex;
30343038

30353039
// Set up the parameter info
3036-
auto paramInfo = getParameterInfo(this, param, name, swiftParamTy,
3037-
/*isInOut=*/false, paramIsIUO);
3040+
auto paramInfo =
3041+
getParameterInfo(this, param, name, swiftParamTy, isInOut, paramIsIUO);
30383042

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

0 commit comments

Comments
 (0)