Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/ClangImporter/ClangClassTemplateNamePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "ImporterImpl.h"
#include "swift/ClangImporter/ClangImporter.h"
#include "clang/AST/TemplateArgumentVisitor.h"
#include "clang/AST/Type.h"
#include "clang/AST/TypeVisitor.h"

using namespace swift;
Expand Down Expand Up @@ -94,6 +95,18 @@ struct TemplateInstantiationNamePrinter
return "_";
}

std::string VisitReferenceType(const clang::ReferenceType *type) {
llvm::SmallString<128> storage;
llvm::raw_svector_ostream buffer(storage);
if (type->isLValueReferenceType()) {
buffer << "__cxxLRef<";
} else {
buffer << "__cxxRRef<";
}
buffer << Visit(type->getPointeeType().getTypePtr()) << ">";
return buffer.str().str();
}

std::string VisitPointerType(const clang::PointerType *type) {
std::string pointeeResult = Visit(type->getPointeeType().getTypePtr());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// RUN: %empty-directory(%t)
// RUN: split-file %s %t

// 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

// RUN: %target-interop-build-clangxx -std=c++20 -c %t/use-swift-cxx-types.cpp -I %t -o %t/swift-cxx-execution.o -g
// 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

// RUN: %target-codesign %t/swift-cxx-execution
// RUN: %target-run %t/swift-cxx-execution

// REQUIRES: executable_test

//--- header.h
#include <functional>
namespace my_cpp {
struct First {
double value;
};
struct Second {
bool value;
};

using First_cb = std::function<void(const First &)>;
using Second_cb = std::function<void(const Second &)>;
} // namespace my_cpp

//--- module.modulemap
module CxxTest {
header "header.h"
requires cplusplus
}

//--- use-cxx-types.swift
import CxxStdlib
import CxxTest

public func
hello(first : my_cpp.First_cb /* std::function */,
second : my_cpp.Second_cb /* std::function */) {
first.callAsFunction(my_cpp.First(value : 3.14))
second.callAsFunction(my_cpp.Second(value : true))
}

//--- use-swift-cxx-types.cpp

#include "header.h"
#include "UseCxx.h"
#include <assert.h>

int main() {
UseCxx::hello([](const my_cpp::First &) {}, [](const my_cpp::Second &) {});
}