mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #60842 from WANGJIEKE/cxx-interop-enum-creation
[Interop][SwiftToCxx] Support enum creation from Cxx
This commit is contained in:
@@ -825,3 +825,44 @@ bool DeclAndTypeClangFunctionPrinter::hasKnownOptionalNullableCxxMapping(
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void DeclAndTypeClangFunctionPrinter::printCustomCxxFunction(
|
||||
const SmallVector<Type> &neededTypes, PrinterTy retTypeAndNamePrinter,
|
||||
PrinterTy paramPrinter, bool isConstFunc, PrinterTy bodyPrinter,
|
||||
ModuleDecl *emittedModule, raw_ostream &outOfLineOS) {
|
||||
llvm::MapVector<Type, std::string> types;
|
||||
|
||||
for (auto &type : neededTypes) {
|
||||
std::string typeStr;
|
||||
llvm::raw_string_ostream typeOS(typeStr);
|
||||
OptionalTypeKind optKind;
|
||||
Type objectType;
|
||||
std::tie(objectType, optKind) =
|
||||
DeclAndTypePrinter::getObjectTypeAndOptionality(
|
||||
type->getNominalOrBoundGenericNominal(), type);
|
||||
|
||||
// Use FunctionSignatureTypeUse::ReturnType to avoid printing extra const or
|
||||
// references
|
||||
CFunctionSignatureTypePrinter typePrinter(
|
||||
typeOS, cPrologueOS, typeMapping, OutputLanguageMode::Cxx,
|
||||
interopContext, CFunctionSignatureTypePrinterModifierDelegate(),
|
||||
emittedModule, declPrinter, FunctionSignatureTypeUse::ReturnType);
|
||||
typePrinter.visit(objectType, optKind, /* isInOutParam */ false);
|
||||
|
||||
types.insert({type, typeStr});
|
||||
}
|
||||
|
||||
retTypeAndNamePrinter(types);
|
||||
os << '(';
|
||||
outOfLineOS << '(';
|
||||
paramPrinter(types);
|
||||
os << ')';
|
||||
outOfLineOS << ')';
|
||||
if (isConstFunc) {
|
||||
os << " const;\n";
|
||||
outOfLineOS << " const";
|
||||
}
|
||||
outOfLineOS << " {\n";
|
||||
bodyPrinter(types);
|
||||
outOfLineOS << "}\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user