Skip to content

Commit 5aa5bcf

Browse files
committed
[NFC] [cxx-interop] Flatten findOptionSetEnum() and move it to ImportEnumInfo.cpp
It's at home there alongside other ObjC enum-specific logic, rather than in the middle of ImportDecl.cpp (since it isn't directly or exclusively related to importing decls).
1 parent c7070e7 commit 5aa5bcf

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -847,26 +847,6 @@ static bool isPrintLikeMethod(DeclName name, const DeclContext *dc) {
847847
using MirroredMethodEntry =
848848
std::tuple<const clang::ObjCMethodDecl*, ProtocolDecl*, bool /*isAsync*/>;
849849

850-
ImportedType importer::findOptionSetEnum(clang::QualType type,
851-
ClangImporter::Implementation &Impl) {
852-
if (auto typedefType = dyn_cast<clang::TypedefType>(type)) {
853-
if (Impl.isUnavailableInSwift(typedefType->getDecl())) {
854-
if (auto clangEnum =
855-
findAnonymousEnumForTypedef(Impl.SwiftContext, typedefType)) {
856-
// If this fails, it means that we need a stronger predicate for
857-
// determining the relationship between an enum and typedef.
858-
assert(
859-
clangEnum.value()->getIntegerType()->getCanonicalTypeInternal() ==
860-
typedefType->getCanonicalTypeInternal());
861-
if (auto swiftEnum = Impl.importDecl(*clangEnum, Impl.CurrentVersion)) {
862-
return {cast<TypeDecl>(swiftEnum)->getDeclaredInterfaceType(), false};
863-
}
864-
}
865-
}
866-
}
867-
return {};
868-
}
869-
870850
static bool areRecordFieldsComplete(const clang::CXXRecordDecl *decl) {
871851
for (const auto *f : decl->fields()) {
872852
auto *fieldRecord = f->getType()->getAsCXXRecordDecl();

lib/ClangImporter/ImportEnumInfo.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,29 @@ const clang::Type *importer::getUnderlyingType(const clang::EnumDecl *decl) {
247247
return importer::desugarIfElaborated(decl->getIntegerType().getTypePtr());
248248
}
249249

250+
ImportedType importer::findOptionSetEnum(clang::QualType type,
251+
ClangImporter::Implementation &Impl) {
252+
auto typedefType = dyn_cast<clang::TypedefType>(type);
253+
if (!typedefType || !Impl.isUnavailableInSwift(typedefType->getDecl()))
254+
// If this isn't a typedef, or it is a typedef that is available in Swift,
255+
// then this definitely isn't used for {CF,NS}_OPTIONS.
256+
return {};
257+
258+
auto clangEnum = findAnonymousEnumForTypedef(Impl.SwiftContext, typedefType);
259+
if (!clangEnum)
260+
return {};
261+
262+
// If this fails, it means that we need a stronger predicate for
263+
// determining the relationship between an enum and typedef.
264+
assert(clangEnum.value()->getIntegerType()->getCanonicalTypeInternal() ==
265+
typedefType->getCanonicalTypeInternal());
266+
267+
if (auto *swiftEnum = Impl.importDecl(*clangEnum, Impl.CurrentVersion))
268+
return {cast<TypeDecl>(swiftEnum)->getDeclaredInterfaceType(), false};
269+
270+
return {};
271+
}
272+
250273
/// Determine the prefix to be stripped from the names of the enum constants
251274
/// within the given enum.
252275
void EnumInfo::determineConstantNamePrefix(const clang::EnumDecl *decl) {

0 commit comments

Comments
 (0)