mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[interop][SwiftToCxx] start emitting bindings for Swift class types
This includes release on destruction, and correctly returning class values from Swift to C++.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "DeclAndTypePrinter.h"
|
||||
#include "OutputLanguageMode.h"
|
||||
#include "PrimitiveTypeMapping.h"
|
||||
#include "PrintClangClassType.h"
|
||||
#include "PrintClangValueType.h"
|
||||
#include "SwiftToClangInteropContext.h"
|
||||
#include "swift/AST/Decl.h"
|
||||
@@ -147,6 +148,21 @@ public:
|
||||
visitPart(aliasTy->getSinglyDesugaredType(), optionalKind, isInOutParam);
|
||||
}
|
||||
|
||||
void visitClassType(ClassType *CT, Optional<OptionalTypeKind> optionalKind,
|
||||
bool isInOutParam) {
|
||||
// FIXME: handle optionalKind.
|
||||
// FIXME: handle isInOutParam.
|
||||
if (languageMode != OutputLanguageMode::Cxx) {
|
||||
os << "void * _Nonnull";
|
||||
return;
|
||||
}
|
||||
if (typeUseKind == FunctionSignatureTypeUse::ParamType)
|
||||
os << "const ";
|
||||
ClangSyntaxPrinter(os).printBaseName(CT->getDecl());
|
||||
if (typeUseKind == FunctionSignatureTypeUse::ParamType)
|
||||
os << "&";
|
||||
}
|
||||
|
||||
void visitEnumType(EnumType *ET, Optional<OptionalTypeKind> optionalKind,
|
||||
bool isInOutParam) {
|
||||
visitValueType(ET, optionalKind, isInOutParam);
|
||||
@@ -559,6 +575,12 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
|
||||
os << ";\n return returnValue;\n";
|
||||
return;
|
||||
}
|
||||
if (auto *classDecl = resultTy->getClassOrBoundGenericClass()) {
|
||||
ClangClassTypePrinter::printClassTypeReturnScaffold(
|
||||
os, classDecl, moduleContext,
|
||||
[&]() { printCallToCFunc(/*additionalParam=*/None); });
|
||||
return;
|
||||
}
|
||||
if (auto *decl = resultTy->getNominalOrBoundGenericNominal()) {
|
||||
if ((isa<StructDecl>(decl) || isa<EnumDecl>(decl))) {
|
||||
bool isIndirect =
|
||||
|
||||
Reference in New Issue
Block a user