Implementing a naive exception to be thrown in C++ if an Error is thrown in Swift

Creating new Interop - SwiftToCxx test
This commit is contained in:
Roberto Rosmaninho
2022-07-15 20:14:13 -03:00
parent 4e1a1b82b9
commit b15c6a5537
5 changed files with 98 additions and 5 deletions

View File

@@ -433,9 +433,29 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
}
// Primitive values are returned directly without any conversions.
os << " return ";
// Assign the function return value to a variable if the function can throw.
if (!resultTy->isVoid() && hasThrows)
os << " auto returnValue = ";
// If the function doesn't have a return value just call it.
else if (resultTy->isVoid() && hasThrows)
os << " ";
// If the function can't throw just return its value result.
else if (!hasThrows)
os << " return ";
printCallToCFunc(/*additionalParam=*/None);
os << ";\n";
// Create the condition and the statement to throw an exception.
if (hasThrows) {
os << " if (opaqueError != nullptr)\n";
os << " throw (swift::_impl::NaiveException(\"Exception\"));\n";
}
// Return the function result value if it doesn't throw.
if (!resultTy->isVoid() && hasThrows) {
os << "\n";
os << "return returnValue;\n";
}
}
void DeclAndTypeClangFunctionPrinter::printCxxMethod(