[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:
Alex Lorenz
2022-08-01 20:03:56 +01:00
parent 700ef38353
commit 26d55a2b83
9 changed files with 262 additions and 3 deletions

View File

@@ -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 =