Skip to content

Commit 208c03c

Browse files
committed
[c++-interop] Adding options set struct to go with the typedef's enum bit set.
This does not work yet, but it is a proof of concept for now.
1 parent e977a21 commit 208c03c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2856,6 +2856,23 @@ namespace {
28562856
return nullptr;
28572857

28582858
auto Loc = Impl.importSourceLoc(Decl->getLocation());
2859+
2860+
if (importer::isUnavailableInSwift(Decl, nullptr, true) &&
2861+
Impl.SwiftContext.LangOpts.EnableCXXInterop) {
2862+
ASTContext &ctx = Impl.SwiftContext;
2863+
auto structDecl = Impl.createDeclWithClangNode<StructDecl>(
2864+
Decl, AccessLevel::Public, Loc, Name, Loc, None, nullptr, DC);
2865+
2866+
makeStructRawValued(Impl, structDecl, SwiftType,
2867+
{KnownProtocolKind::OptionSet});
2868+
auto selfType = structDecl->getDeclaredInterfaceType();
2869+
addSynthesizedTypealias(structDecl, ctx.Id_Element, selfType);
2870+
addSynthesizedTypealias(structDecl, ctx.Id_ArrayLiteralElement,
2871+
selfType);
2872+
// Impl.DeclsWithSuperfluousTypedefs.insert(decl);
2873+
return structDecl;
2874+
}
2875+
28592876
auto Result = Impl.createDeclWithClangNode<TypeAliasDecl>(Decl,
28602877
AccessLevel::Public,
28612878
Impl.importSourceLoc(Decl->getBeginLoc()),

test/Interop/Cxx/enum/c-enums-withOptions-omit.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33

44
import CenumsWithOptionsOmit
55

6+
// CHECK: struct NSEnumerationOptions : OptionSet {
7+
// CHECK-NEXT: init(rawValue: Int32)
8+
// CHECK-NEXT: let rawValue: Int32
9+
// CHECK-NEXT: typealias RawValue = Int32
10+
// CHECK-NEXT: typealias Element = NSEnumerationOptions
11+
// CHECK-NEXT: typealias ArrayLiteralElement = NSEnumerationOptions
12+
613
// CHECK: class NSSet {
714
// CHECK-NEXT: class func enumerateObjects(options
815
// CHECK-NEXT: func enumerateObjects(options

0 commit comments

Comments
 (0)