File tree Expand file tree Collapse file tree 2 files changed +66
-0
lines changed
test/Interop/CxxToSwiftToCxx Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change 14
14
#include " ImporterImpl.h"
15
15
#include " swift/ClangImporter/ClangImporter.h"
16
16
#include " clang/AST/TemplateArgumentVisitor.h"
17
+ #include " clang/AST/Type.h"
17
18
#include " clang/AST/TypeVisitor.h"
18
19
19
20
using namespace swift ;
@@ -94,6 +95,18 @@ struct TemplateInstantiationNamePrinter
94
95
return " _" ;
95
96
}
96
97
98
+ std::string VisitReferenceType (const clang::ReferenceType *type) {
99
+ llvm::SmallString<128 > storage;
100
+ llvm::raw_svector_ostream buffer (storage);
101
+ if (type->isLValueReferenceType ()) {
102
+ buffer << " __cxxLRef<" ;
103
+ } else {
104
+ buffer << " __cxxRRef<" ;
105
+ }
106
+ buffer << Visit (type->getPointeeType ().getTypePtr ()) << " >" ;
107
+ return buffer.str ().str ();
108
+ }
109
+
97
110
std::string VisitPointerType (const clang::PointerType *type) {
98
111
std::string pointeeResult = Visit (type->getPointeeType ().getTypePtr ());
99
112
Original file line number Diff line number Diff line change
1
+ // RUN: %empty-directory(%t)
2
+ // RUN: split-file %s %t
3
+
4
+ // RUN: %target-swift-frontend -typecheck %t/use-cxx-types.swift -typecheck -module-name UseCxx -emit-clang-header-path %t/UseCxx.h -I %t -enable-experimental-cxx-interop -clang-header-expose-decls=all-public
5
+
6
+ // RUN: %target-interop-build-clangxx -std=c++20 -c %t/use-swift-cxx-types.cpp -I %t -o %t/swift-cxx-execution.o -g
7
+ // RUN: %target-interop-build-swift %t/use-cxx-types.swift -o %t/swift-cxx-execution -Xlinker %t/swift-cxx-execution.o -module-name UseCxx -Xfrontend -entry-point-function-name -Xfrontend swiftMain -I %t -g
8
+
9
+ // RUN: %target-codesign %t/swift-cxx-execution
10
+ // RUN: %target-run %t/swift-cxx-execution
11
+
12
+ // REQUIRES: executable_test
13
+
14
+ // --- header.h
15
+ #include < functional>
16
+ namespace my_cpp {
17
+ struct First {
18
+ double value;
19
+ };
20
+ struct Second {
21
+ bool value;
22
+ };
23
+
24
+ using First_cb = std::function<void (const First &)>;
25
+ using Second_cb = std::function<void (const Second &)>;
26
+ } // namespace my_cpp
27
+
28
+ // --- module.modulemap
29
+ module CxxTest {
30
+ header " header.h"
31
+ requires cplusplus
32
+ }
33
+
34
+ // --- use-cxx-types.swift
35
+ import CxxStdlib
36
+ import CxxTest
37
+
38
+ public func
39
+ hello (first : my_cpp.First_cb /* std::function */ ,
40
+ second : my_cpp.Second_cb /* std::function */ ) {
41
+ first.callAsFunction (my_cpp.First (value : 3.14 ))
42
+ second.callAsFunction (my_cpp.Second (value : true ))
43
+ }
44
+
45
+ // --- use-swift-cxx-types.cpp
46
+
47
+ #include " header.h"
48
+ #include " UseCxx.h"
49
+ #include < assert.h>
50
+
51
+ int main () {
52
+ UseCxx::hello ([](const my_cpp::First &) {}, [](const my_cpp::Second &) {});
53
+ }
You can’t perform that action at this time.
0 commit comments