Skip to content

Commit d1c2c76

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). (cherry picked from commit 5aa5bcf)
1 parent 1f4ce61 commit d1c2c76

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
@@ -846,26 +846,6 @@ static bool isPrintLikeMethod(DeclName name, const DeclContext *dc) {
846846
using MirroredMethodEntry =
847847
std::tuple<const clang::ObjCMethodDecl*, ProtocolDecl*, bool /*isAsync*/>;
848848

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