Merge pull request #60842 from WANGJIEKE/cxx-interop-enum-creation

[Interop][SwiftToCxx] Support enum creation from Cxx
This commit is contained in:
Alex Lorenz
2022-08-31 14:00:50 -07:00
committed by GitHub
15 changed files with 716 additions and 1227 deletions

View File

@@ -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";
}