File tree Expand file tree Collapse file tree 5 files changed +29
-3
lines changed
test/Interop/SwiftToCxx/stdlib Expand file tree Collapse file tree 5 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 11
11
// ===----------------------------------------------------------------------===//
12
12
13
13
#include " ClangSyntaxPrinter.h"
14
+ #include " DeclAndTypePrinter.h"
14
15
#include " PrimitiveTypeMapping.h"
15
16
#include " swift/ABI/MetadataValues.h"
16
17
#include " swift/AST/ASTContext.h"
@@ -99,6 +100,12 @@ bool ClangSyntaxPrinter::printNominalTypeOutsideMemberDeclInnerStaticAssert(
99
100
}
100
101
101
102
void ClangSyntaxPrinter::printClangTypeReference (const clang::Decl *typeDecl) {
103
+ StringRef osObjectName = DeclAndTypePrinter::maybeGetOSObjectBaseName (
104
+ dyn_cast<clang::NamedDecl>(cast<clang::NamedDecl>(typeDecl)));
105
+ if (!osObjectName.empty ()) {
106
+ os << osObjectName << " _t" ;
107
+ return ;
108
+ }
102
109
if (cast<clang::NamedDecl>(typeDecl)->getDeclName ().isEmpty () &&
103
110
isa<clang::TagDecl>(typeDecl)) {
104
111
if (auto *tnd =
Original file line number Diff line number Diff line change @@ -3084,6 +3084,8 @@ const TypeDecl *DeclAndTypePrinter::getObjCTypeDecl(const TypeDecl* TD) {
3084
3084
3085
3085
StringRef
3086
3086
DeclAndTypePrinter::maybeGetOSObjectBaseName (const clang::NamedDecl *decl) {
3087
+ if (!decl)
3088
+ return StringRef ();
3087
3089
StringRef name = decl->getName ();
3088
3090
if (!name.consume_front (" OS_" ))
3089
3091
return StringRef ();
Original file line number Diff line number Diff line change @@ -320,11 +320,16 @@ class CFunctionSignatureTypePrinter
320
320
auto *cd = CT->getDecl ();
321
321
if (cd->hasClangNode ()) {
322
322
const auto *clangDecl = cd->getClangDecl ();
323
- ClangSyntaxPrinter (cd->getASTContext (), os).printClangTypeReference (clangDecl);
323
+ ClangSyntaxPrinter (cd->getASTContext (), os)
324
+ .printClangTypeReference (clangDecl);
324
325
bool alreadyPointer = false ;
325
326
if (const auto *typedefDecl = dyn_cast<clang::TypedefNameDecl>(clangDecl))
326
327
if (importer::isCFTypeDecl (typedefDecl))
327
328
alreadyPointer = true ;
329
+ if (!DeclAndTypePrinter::maybeGetOSObjectBaseName (
330
+ dyn_cast<clang::NamedDecl>(clangDecl))
331
+ .empty ())
332
+ alreadyPointer = true ;
328
333
os << (alreadyPointer ? " " : " *" )
329
334
<< (!optionalKind || *optionalKind == OTK_None ? " _Nonnull"
330
335
: " _Nullable" );
Original file line number Diff line number Diff line change 23
23
#include " swift/ClangImporter/ClangImporter.h"
24
24
#include " swift/IRGen/IRABIDetailsProvider.h"
25
25
#include " swift/IRGen/Linking.h"
26
+ #include " clang/AST/Decl.h"
26
27
#include " clang/Basic/Module.h"
27
28
#include " llvm/ADT/STLExtras.h"
28
29
#include " llvm/Support/raw_ostream.h"
@@ -654,8 +655,13 @@ void ClangValueTypePrinter::printTypeGenericTraits(
654
655
os << " } // end namespace \n\n " ;
655
656
os << " namespace swift SWIFT_PRIVATE_ATTR {\n " ;
656
657
auto classDecl = dyn_cast<ClassDecl>(typeDecl);
657
- bool addPointer =
658
- typeDecl->isObjC () || (classDecl && classDecl->isForeignReferenceType ());
658
+
659
+ bool isOSObject = false ;
660
+ if (const auto nd =
661
+ dyn_cast_or_null<clang::NamedDecl>(typeDecl->getClangDecl ()))
662
+ isOSObject = !DeclAndTypePrinter::maybeGetOSObjectBaseName (nd).empty ();
663
+ bool addPointer = (typeDecl->isObjC () && !isOSObject) ||
664
+ (classDecl && classDecl->isForeignReferenceType ());
659
665
660
666
if (objCxxOnly)
661
667
os << " #if defined(__OBJC__)\n " ;
Original file line number Diff line number Diff line change 4
4
// RUN: %FileCheck %s < %t/UseCoreFoundation.h
5
5
6
6
// RUN: echo "#include <netinet/in.h>" > %t/full-header.h
7
+ // RUN: echo "#include <dispatch/dispatch.h>" >> %t/full-header.h
7
8
// RUN: cat %t/UseCoreFoundation.h >> %t/full-header.h
8
9
// RUN: %target-interop-build-clangxx -std=gnu++20 -fobjc-arc -c -x objective-c++-header %t/full-header.h -o %t/o.o
9
10
10
11
// REQUIRES: objc_interop
11
12
12
13
import CoreFoundation
13
14
import Foundation
15
+ import Dispatch
16
+
17
+ public func testDispatch( x: DispatchSemaphore ) { }
14
18
15
19
public func foobar( _ a: CFData ) -> Bool {
16
20
true
@@ -33,7 +37,9 @@ public enum MyEnum {
33
37
// CHECK: SWIFT_EXTERN bool $s17UseCoreFoundation6foobarySbSo9CFDataRefaF(CFDataRef _Nonnull a) SWIFT_NOEXCEPT SWIFT_CALL; // foobar(_:)
34
38
// CHECK: SWIFT_EXTERN CFDateRef _Nullable $s17UseCoreFoundation13returnsCFDateSo0E3RefaSgyF(void) SWIFT_NOEXCEPT SWIFT_CALL; // returnsCFDate()
35
39
// CHECK: SWIFT_EXTERN void $s17UseCoreFoundation11takesCFDate1xySo0E3RefaSg_tF(CFDateRef _Nullable x) SWIFT_NOEXCEPT SWIFT_CALL; // takesCFDate(x:)
40
+ // CHECK: SWIFT_EXTERN void $s17UseCoreFoundation12testDispatch1xySo21OS_dispatch_semaphoreC_tF(dispatch_semaphore_t _Nonnull x) SWIFT_NOEXCEPT SWIFT_CALL; // testDispatch(x:)
36
41
37
42
// CHECK: SWIFT_INLINE_THUNK swift::Optional<in_addr> networkThing() noexcept SWIFT_SYMBOL("s:17UseCoreFoundation12networkThingSo7in_addrVSgyF") SWIFT_WARN_UNUSED_RESULT {
38
43
// CHECK: SWIFT_INLINE_THUNK CFDateRef _Nullable returnsCFDate() noexcept SWIFT_SYMBOL("s:17UseCoreFoundation13returnsCFDateSo0E3RefaSgyF") SWIFT_WARN_UNUSED_RESULT {
39
44
// CHECK: SWIFT_INLINE_THUNK void takesCFDate(CFDateRef _Nullable x) noexcept SWIFT_SYMBOL("s:17UseCoreFoundation11takesCFDate1xySo0E3RefaSg_tF") {
45
+ // CHECK: SWIFT_INLINE_THUNK void testDispatch(dispatch_semaphore_t _Nonnull x) noexcept SWIFT_SYMBOL("s:17UseCoreFoundation12testDispatch1xySo21OS_dispatch_semaphoreC_tF") {
You can’t perform that action at this time.
0 commit comments