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