Skip to content

Commit 3ac7dbf

Browse files
committed
[gardening] Remove uses of "importDeclCached" and cleanup "VisitEnumConstantDecl".
Cleans up the EnumConstantDecl visitor by consolidating cases and removing calls to "importDeclCached".
1 parent 3d91d7f commit 3ac7dbf

File tree

1 file changed

+11
-49
lines changed

1 file changed

+11
-49
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3591,8 +3591,10 @@ namespace {
35913591
if (name.empty())
35923592
return nullptr;
35933593

3594-
switch (Impl.getEnumKind(clangEnum)) {
3595-
case EnumKind::Constants: {
3594+
auto enumKind = Impl.getEnumKind(clangEnum);
3595+
switch (enumKind) {
3596+
case EnumKind::Constants:
3597+
case EnumKind::Unknown: {
35963598
// The enumeration was simply mapped to an integral type. Create a
35973599
// constant with that integral type.
35983600

@@ -3609,54 +3611,14 @@ namespace {
36093611
isInSystemModule(dc), Bridgeability::None);
36103612
if (!type)
36113613
return nullptr;
3612-
// FIXME: Importing the type will recursively revisit this same
3613-
// EnumConstantDecl. Short-circuit out if we already emitted the import
3614-
// for this decl.
3615-
if (auto Known = Impl.importDeclCached(decl, getVersion()))
3616-
return Known;
36173614

36183615
// Create the global constant.
3619-
auto result = Impl.createConstant(name, dc, type,
3620-
clang::APValue(decl->getInitVal()),
3621-
ConstantConvertKind::None,
3622-
/*static*/dc->isTypeContext(), decl);
3623-
Impl.ImportedDecls[{decl->getCanonicalDecl(), getVersion()}] = result;
3624-
3625-
// If this is a compatibility stub, mark it as such.
3626-
if (correctSwiftName)
3627-
markAsVariant(result, *correctSwiftName);
3628-
3629-
return result;
3630-
}
3631-
3632-
case EnumKind::Unknown: {
3633-
// The enumeration was mapped to a struct containing the integral
3634-
// type. Create a constant with that struct type.
3635-
3636-
// The context where the constant will be introduced.
3637-
auto dc =
3638-
Impl.importDeclContextOf(decl, importedName.getEffectiveContext());
3639-
if (!dc)
3640-
return nullptr;
3641-
3642-
// Import the enumeration type.
3643-
auto enumType = Impl.importTypeIgnoreIUO(
3644-
Impl.getClangASTContext().getTagDeclType(clangEnum),
3645-
ImportTypeKind::Value, isInSystemModule(dc), Bridgeability::None);
3646-
if (!enumType)
3647-
return nullptr;
3648-
3649-
// FIXME: Importing the type will can recursively revisit this same
3650-
// EnumConstantDecl. Short-circuit out if we already emitted the import
3651-
// for this decl.
3652-
if (auto Known = Impl.importDeclCached(decl, getVersion()))
3653-
return Known;
3654-
3655-
// Create the global constant.
3656-
auto result = Impl.createConstant(name, dc, enumType,
3657-
clang::APValue(decl->getInitVal()),
3658-
ConstantConvertKind::Construction,
3659-
/*static*/ false, decl);
3616+
bool isStatic = enumKind != EnumKind::Unknown && dc->isTypeContext();
3617+
auto result = Impl.createConstant(
3618+
name, dc, type, clang::APValue(decl->getInitVal()),
3619+
enumKind == EnumKind::Unknown ? ConstantConvertKind::Construction
3620+
: ConstantConvertKind::None,
3621+
isStatic, decl);
36603622
Impl.ImportedDecls[{decl->getCanonicalDecl(), getVersion()}] = result;
36613623

36623624
// If this is a compatibility stub, mark it as such.
@@ -3678,7 +3640,7 @@ namespace {
36783640
return nullptr;
36793641
}
36803642
}
3681-
3643+
36823644
llvm_unreachable("Invalid EnumKind.");
36833645
}
36843646

0 commit comments

Comments
 (0)