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"
@@ -100,6 +101,12 @@ bool ClangSyntaxPrinter::printNominalTypeOutsideMemberDeclInnerStaticAssert(
100
101
}
101
102
102
103
void ClangSyntaxPrinter::printClangTypeReference (const clang::Decl *typeDecl) {
104
+ StringRef osObjectName = DeclAndTypePrinter::maybeGetOSObjectBaseName (
105
+ dyn_cast<clang::NamedDecl>(cast<clang::NamedDecl>(typeDecl)));
106
+ if (!osObjectName.empty ()) {
107
+ os << osObjectName << " _t" ;
108
+ return ;
109
+ }
103
110
if (cast<clang::NamedDecl>(typeDecl)->getDeclName ().isEmpty () &&
104
111
isa<clang::TagDecl>(typeDecl)) {
105
112
if (auto *tnd =
Original file line number Diff line number Diff line change @@ -3127,6 +3127,8 @@ const TypeDecl *DeclAndTypePrinter::getObjCTypeDecl(const TypeDecl* TD) {
3127
3127
3128
3128
StringRef
3129
3129
DeclAndTypePrinter::maybeGetOSObjectBaseName (const clang::NamedDecl *decl) {
3130
+ if (!decl)
3131
+ return StringRef ();
3130
3132
StringRef name = decl->getName ();
3131
3133
if (!name.consume_front (" OS_" ))
3132
3134
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"
@@ -628,8 +629,13 @@ void ClangValueTypePrinter::printTypeGenericTraits(
628
629
os << " } // end namespace \n\n " ;
629
630
os << " namespace swift SWIFT_PRIVATE_ATTR {\n " ;
630
631
auto classDecl = dyn_cast<ClassDecl>(typeDecl);
631
- bool addPointer =
632
- typeDecl->isObjC () || (classDecl && classDecl->isForeignReferenceType ());
632
+
633
+ bool isOSObject = false ;
634
+ if (const auto nd =
635
+ dyn_cast_or_null<clang::NamedDecl>(typeDecl->getClangDecl ()))
636
+ isOSObject = !DeclAndTypePrinter::maybeGetOSObjectBaseName (nd).empty ();
637
+ bool addPointer = (typeDecl->isObjC () && !isOSObject) ||
638
+ (classDecl && classDecl->isForeignReferenceType ());
633
639
634
640
if (objCxxOnly)
635
641
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