mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[ClangImporter] Simplify the importMethodType helper.
Once upon a time this was agnostic of the declaration being imported (and possibly even still merged with importFunctionType) but that hasn't been true for a while. If we're passing the ObjCMethodDecl and ImportedName anyway, we don't need to separately pass the result type, whether it's noreturn, and the Swift name as separate arguments. No intended functionality change.
This commit is contained in:
@@ -3309,20 +3309,16 @@ namespace {
|
|||||||
kind = SpecialMethodKind::NSDictionarySubscriptGetter;
|
kind = SpecialMethodKind::NSDictionarySubscriptGetter;
|
||||||
|
|
||||||
// Import the type that this method will have.
|
// Import the type that this method will have.
|
||||||
DeclName name = importedName.getDeclName();
|
|
||||||
Optional<ForeignErrorConvention> errorConvention;
|
Optional<ForeignErrorConvention> errorConvention;
|
||||||
bodyParams.push_back(nullptr);
|
bodyParams.push_back(nullptr);
|
||||||
auto type = Impl.importMethodType(dc,
|
auto type = Impl.importMethodType(dc,
|
||||||
decl,
|
decl,
|
||||||
decl->getReturnType(),
|
|
||||||
{ decl->param_begin(),
|
{ decl->param_begin(),
|
||||||
decl->param_size() },
|
decl->param_size() },
|
||||||
decl->isVariadic(),
|
decl->isVariadic(),
|
||||||
decl->hasAttr<clang::NoReturnAttr>(),
|
|
||||||
isInSystemModule(dc),
|
isInSystemModule(dc),
|
||||||
&bodyParams.back(),
|
&bodyParams.back(),
|
||||||
importedName,
|
importedName,
|
||||||
name,
|
|
||||||
errorConvention,
|
errorConvention,
|
||||||
kind);
|
kind);
|
||||||
if (!type)
|
if (!type)
|
||||||
@@ -3341,11 +3337,10 @@ namespace {
|
|||||||
|
|
||||||
auto result = FuncDecl::create(
|
auto result = FuncDecl::create(
|
||||||
Impl.SwiftContext, /*StaticLoc=*/SourceLoc(),
|
Impl.SwiftContext, /*StaticLoc=*/SourceLoc(),
|
||||||
StaticSpellingKind::None,
|
StaticSpellingKind::None, /*FuncLoc=*/SourceLoc(),
|
||||||
/*FuncLoc=*/SourceLoc(), name, /*NameLoc=*/SourceLoc(),
|
importedName.getDeclName(), /*NameLoc=*/SourceLoc(),
|
||||||
/*Throws=*/importedName.getErrorInfo().hasValue(),
|
/*Throws=*/importedName.getErrorInfo().hasValue(),
|
||||||
/*ThrowsLoc=*/SourceLoc(),
|
/*ThrowsLoc=*/SourceLoc(), /*AccessorKeywordLoc=*/SourceLoc(),
|
||||||
/*AccessorKeywordLoc=*/SourceLoc(),
|
|
||||||
/*GenericParams=*/nullptr, bodyParams, TypeLoc(), dc, decl);
|
/*GenericParams=*/nullptr, bodyParams, TypeLoc(), dc, decl);
|
||||||
|
|
||||||
result->setAccessibility(getOverridableAccessibility(dc));
|
result->setAccessibility(getOverridableAccessibility(dc));
|
||||||
@@ -5232,12 +5227,10 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
|
|||||||
|
|
||||||
// Import the type that this method will have.
|
// Import the type that this method will have.
|
||||||
Optional<ForeignErrorConvention> errorConvention;
|
Optional<ForeignErrorConvention> errorConvention;
|
||||||
DeclName name = importedName.getDeclName();
|
|
||||||
bodyParams.push_back(nullptr);
|
bodyParams.push_back(nullptr);
|
||||||
auto type = Impl.importMethodType(
|
auto type = Impl.importMethodType(
|
||||||
dc, objcMethod, objcMethod->getReturnType(), args, variadic,
|
dc, objcMethod, args, variadic, isInSystemModule(dc),
|
||||||
objcMethod->hasAttr<clang::NoReturnAttr>(), isInSystemModule(dc),
|
&bodyParams.back(), importedName, errorConvention,
|
||||||
&bodyParams.back(), importedName, name, errorConvention,
|
|
||||||
SpecialMethodKind::Constructor);
|
SpecialMethodKind::Constructor);
|
||||||
if (!type)
|
if (!type)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -5265,7 +5258,7 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
|
|||||||
->getResult()
|
->getResult()
|
||||||
->castTo<AnyFunctionType>()
|
->castTo<AnyFunctionType>()
|
||||||
->getInput();
|
->getInput();
|
||||||
for (auto other : ownerNominal->lookupDirect(name)) {
|
for (auto other : ownerNominal->lookupDirect(importedName.getDeclName())) {
|
||||||
auto ctor = dyn_cast<ConstructorDecl>(other);
|
auto ctor = dyn_cast<ConstructorDecl>(other);
|
||||||
if (!ctor || ctor->isInvalid() ||
|
if (!ctor || ctor->isInvalid() ||
|
||||||
ctor->getAttrs().isUnavailable(Impl.SwiftContext) ||
|
ctor->getAttrs().isUnavailable(Impl.SwiftContext) ||
|
||||||
@@ -5342,8 +5335,8 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
|
|||||||
|
|
||||||
// Create the actual constructor.
|
// Create the actual constructor.
|
||||||
auto result = Impl.createDeclWithClangNode<ConstructorDecl>(
|
auto result = Impl.createDeclWithClangNode<ConstructorDecl>(
|
||||||
objcMethod, Accessibility::Public, name, /*NameLoc=*/SourceLoc(),
|
objcMethod, Accessibility::Public, importedName.getDeclName(),
|
||||||
failability, /*FailabilityLoc=*/SourceLoc(),
|
/*NameLoc=*/SourceLoc(), failability, /*FailabilityLoc=*/SourceLoc(),
|
||||||
/*Throws=*/importedName.getErrorInfo().hasValue(),
|
/*Throws=*/importedName.getErrorInfo().hasValue(),
|
||||||
/*ThrowsLoc=*/SourceLoc(), selfVar, bodyParams.back(),
|
/*ThrowsLoc=*/SourceLoc(), selfVar, bodyParams.back(),
|
||||||
/*GenericParams=*/nullptr, dc);
|
/*GenericParams=*/nullptr, dc);
|
||||||
|
|||||||
@@ -1824,13 +1824,11 @@ getForeignErrorInfo(ForeignErrorConvention::Info errorInfo,
|
|||||||
Type ClangImporter::Implementation::importMethodType(
|
Type ClangImporter::Implementation::importMethodType(
|
||||||
const DeclContext *dc,
|
const DeclContext *dc,
|
||||||
const clang::ObjCMethodDecl *clangDecl,
|
const clang::ObjCMethodDecl *clangDecl,
|
||||||
clang::QualType resultType,
|
|
||||||
ArrayRef<const clang::ParmVarDecl *> params,
|
ArrayRef<const clang::ParmVarDecl *> params,
|
||||||
bool isVariadic, bool isNoReturn,
|
bool isVariadic,
|
||||||
bool isFromSystemModule,
|
bool isFromSystemModule,
|
||||||
ParameterList **bodyParams,
|
ParameterList **bodyParams,
|
||||||
ImportedName importedName,
|
ImportedName importedName,
|
||||||
DeclName &methodName,
|
|
||||||
Optional<ForeignErrorConvention> &foreignErrorInfo,
|
Optional<ForeignErrorConvention> &foreignErrorInfo,
|
||||||
SpecialMethodKind kind) {
|
SpecialMethodKind kind) {
|
||||||
|
|
||||||
@@ -1913,6 +1911,7 @@ Type ClangImporter::Implementation::importMethodType(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clang::QualType resultType = clangDecl->getReturnType();
|
||||||
swiftResultTy = importType(resultType, resultKind,
|
swiftResultTy = importType(resultType, resultKind,
|
||||||
allowNSUIntegerAsIntInResult,
|
allowNSUIntegerAsIntInResult,
|
||||||
/*isFullyBridgeable*/true,
|
/*isFullyBridgeable*/true,
|
||||||
@@ -1979,7 +1978,7 @@ Type ClangImporter::Implementation::importMethodType(
|
|||||||
unsigned numEffectiveParams = params.size();
|
unsigned numEffectiveParams = params.size();
|
||||||
if (errorInfo) --numEffectiveParams;
|
if (errorInfo) --numEffectiveParams;
|
||||||
|
|
||||||
auto argNames = methodName.getArgumentNames();
|
auto argNames = importedName.getDeclName().getArgumentNames();
|
||||||
unsigned nameIndex = 0;
|
unsigned nameIndex = 0;
|
||||||
for (size_t paramIndex = 0; paramIndex != params.size(); paramIndex++) {
|
for (size_t paramIndex = 0; paramIndex != params.size(); paramIndex++) {
|
||||||
auto param = params[paramIndex];
|
auto param = params[paramIndex];
|
||||||
@@ -2100,9 +2099,10 @@ Type ClangImporter::Implementation::importMethodType(
|
|||||||
errorInfo->ErrorParameterIndex == params.size() - 1);
|
errorInfo->ErrorParameterIndex == params.size() - 1);
|
||||||
|
|
||||||
auto defaultArg = inferDefaultArgument(
|
auto defaultArg = inferDefaultArgument(
|
||||||
param->getType(), optionalityOfParam, methodName.getBaseName(),
|
param->getType(), optionalityOfParam,
|
||||||
numEffectiveParams, name.empty() ? StringRef() : name.str(),
|
importedName.getDeclName().getBaseName(), numEffectiveParams,
|
||||||
paramIndex == 0, isLastParameter, getNameImporter());
|
name.empty() ? StringRef() : name.str(), paramIndex == 0,
|
||||||
|
isLastParameter, getNameImporter());
|
||||||
if (defaultArg != DefaultArgumentKind::None)
|
if (defaultArg != DefaultArgumentKind::None)
|
||||||
paramInfo->setDefaultArgumentKind(defaultArg);
|
paramInfo->setDefaultArgumentKind(defaultArg);
|
||||||
}
|
}
|
||||||
@@ -2135,7 +2135,7 @@ Type ClangImporter::Implementation::importMethodType(
|
|||||||
// Form the parameter list.
|
// Form the parameter list.
|
||||||
*bodyParams = ParameterList::create(SwiftContext, swiftParams);
|
*bodyParams = ParameterList::create(SwiftContext, swiftParams);
|
||||||
|
|
||||||
if (isNoReturn) {
|
if (clangDecl->hasAttr<clang::NoReturnAttr>()) {
|
||||||
origSwiftResultTy = SwiftContext.getNeverType();
|
origSwiftResultTy = SwiftContext.getNeverType();
|
||||||
swiftResultTy = SwiftContext.getNeverType();
|
swiftResultTy = SwiftContext.getNeverType();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -979,25 +979,24 @@ public:
|
|||||||
StringRef argumentLabel, bool isFirstParameter,
|
StringRef argumentLabel, bool isFirstParameter,
|
||||||
bool isLastParameter, importer::NameImporter &);
|
bool isLastParameter, importer::NameImporter &);
|
||||||
|
|
||||||
/// \brief Import the type of an Objective-C method.
|
/// Import the type of an Objective-C method.
|
||||||
///
|
///
|
||||||
/// This routine should be preferred when importing function types for
|
/// This routine should be preferred when importing function types for
|
||||||
/// which we have actual function parameters, e.g., when dealing with a
|
/// which we have actual function parameters, e.g., when dealing with a
|
||||||
/// function declaration, because it produces a function type whose input
|
/// function declaration, because it produces a function type whose input
|
||||||
/// tuple has argument names.
|
/// tuple has argument names.
|
||||||
///
|
///
|
||||||
/// \param clangDecl The underlying declaration, if any; should only be
|
/// \param dc The context the method is being imported into.
|
||||||
/// considered for any attributes it might carry.
|
/// \param clangDecl The underlying declaration.
|
||||||
/// \param resultType The result type of the function.
|
/// \param params The parameter types to the function. Note that this may not
|
||||||
/// \param params The parameter types to the function.
|
/// include all parameters defined on the ObjCMethodDecl.
|
||||||
/// \param isVariadic Whether the function is variadic.
|
/// \param isVariadic Whether the function is variadic.
|
||||||
/// \param isNoReturn Whether the function is noreturn.
|
|
||||||
/// \param isFromSystemModule Whether to apply special rules that only apply
|
/// \param isFromSystemModule Whether to apply special rules that only apply
|
||||||
/// to system APIs.
|
/// to system APIs.
|
||||||
/// \param bodyParams The patterns visible inside the function body.
|
/// \param[out] bodyParams The patterns visible inside the function body.
|
||||||
/// whether the created arg/body patterns are different (selector-style).
|
/// whether the created arg/body patterns are different (selector-style).
|
||||||
/// \param importedName The name of the imported method.
|
/// \param importedName How to import the name of the method.
|
||||||
/// \param errorConvention Information about the method's error conventions.
|
/// \param[out] errorConvention Whether and how the method throws NSErrors.
|
||||||
/// \param kind Controls whether we're building a type for a method that
|
/// \param kind Controls whether we're building a type for a method that
|
||||||
/// needs special handling.
|
/// needs special handling.
|
||||||
///
|
///
|
||||||
@@ -1005,13 +1004,11 @@ public:
|
|||||||
/// imported.
|
/// imported.
|
||||||
Type importMethodType(const DeclContext *dc,
|
Type importMethodType(const DeclContext *dc,
|
||||||
const clang::ObjCMethodDecl *clangDecl,
|
const clang::ObjCMethodDecl *clangDecl,
|
||||||
clang::QualType resultType,
|
|
||||||
ArrayRef<const clang::ParmVarDecl *> params,
|
ArrayRef<const clang::ParmVarDecl *> params,
|
||||||
bool isVariadic, bool isNoReturn,
|
bool isVariadic,
|
||||||
bool isFromSystemModule,
|
bool isFromSystemModule,
|
||||||
ParameterList **bodyParams,
|
ParameterList **bodyParams,
|
||||||
importer::ImportedName importedName,
|
importer::ImportedName importedName,
|
||||||
DeclName &name,
|
|
||||||
Optional<ForeignErrorConvention> &errorConvention,
|
Optional<ForeignErrorConvention> &errorConvention,
|
||||||
SpecialMethodKind kind);
|
SpecialMethodKind kind);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user