Skip to content

Commit 80e7546

Browse files
[Interop][SwiftToCxx] Replacing static by inline on _SwiftStdlibCxxOverlay.h and fixing code duplication on PrintClangFunction.cpp
1 parent ce666ac commit 80e7546

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

lib/PrintAsClang/PrintClangFunction.cpp

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,45 +1249,38 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
12491249
os << "#else\n";
12501250
if (resultTy->isVoid()) {
12511251
os << " return SWIFT_RETURN_THUNK(void, Swift::Error(opaqueError));\n";
1252+
os << "#endif\n";
12521253
} else {
1253-
os << " return SWIFT_RETURN_THUNK(";
12541254
auto directResultType = signature.getDirectResultType();
12551255
printDirectReturnOrParamCType(
12561256
*directResultType, resultTy, moduleContext, os, cPrologueOS,
12571257
typeMapping, interopContext, [&]() {
1258+
os << " return SWIFT_RETURN_THUNK(";
12581259
OptionalTypeKind retKind;
12591260
Type objTy;
12601261
std::tie(objTy, retKind) =
12611262
DeclAndTypePrinter::getObjectTypeAndOptionality(FD, resultTy);
12621263

12631264
auto s = printClangFunctionReturnType(objTy, retKind, const_cast<ModuleDecl *>(moduleContext),
12641265
OutputLanguageMode::Cxx);
1266+
os << ", Swift::Error(opaqueError));\n";
1267+
os << "#endif\n";
1268+
1269+
// Return the function result value if it doesn't throw.
1270+
if (!resultTy->isVoid() && hasThrows) {
1271+
os << "\n";
1272+
os << " return SWIFT_RETURN_THUNK(";
1273+
printClangFunctionReturnType(
1274+
objTy, retKind, const_cast<ModuleDecl *>(moduleContext),
1275+
OutputLanguageMode::Cxx);
1276+
os << ", returnValue);\n";
1277+
}
1278+
12651279
assert(!s.isUnsupported());
12661280
});
1267-
os << ", Swift::Error(opaqueError));\n";
12681281
}
1269-
os << "#endif\n";
12701282
}
12711283

1272-
// Return the function result value if it doesn't throw.
1273-
if (!resultTy->isVoid() && hasThrows) {
1274-
os << "\n";
1275-
os << " return SWIFT_RETURN_THUNK(";
1276-
auto directResultType = signature.getDirectResultType();
1277-
printDirectReturnOrParamCType(
1278-
*directResultType, resultTy, moduleContext, os, cPrologueOS,
1279-
typeMapping, interopContext, [&]() {
1280-
OptionalTypeKind retKind;
1281-
Type objTy;
1282-
std::tie(objTy, retKind) =
1283-
DeclAndTypePrinter::getObjectTypeAndOptionality(FD, resultTy);
1284-
1285-
auto s = printClangFunctionReturnType(objTy, retKind, const_cast<ModuleDecl *>(moduleContext),
1286-
OutputLanguageMode::Cxx);
1287-
assert(!s.isUnsupported());
1288-
});
1289-
os << ", returnValue);\n";
1290-
}
12911284
}
12921285

12931286
static StringRef getConstructorName(const AbstractFunctionDecl *FD) {

lib/PrintAsClang/_SwiftStdlibCxxOverlay.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class Error {
181181

182182
namespace _impl {
183183

184-
constexpr static std::size_t max(std::size_t a, std::size_t b) {
184+
constexpr inline std::size_t max(std::size_t a, std::size_t b) {
185185
return a > b ? a : b;
186186
}
187187

0 commit comments

Comments
 (0)