summaryrefslogtreecommitdiff
path: root/cpp/src/slice2swift/SwiftUtil.cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2019-03-12 17:30:20 +0100
committerJose <jose@zeroc.com>2019-03-12 17:30:20 +0100
commit1b02bf54163b420000758b15c40aa7ff8a17b957 (patch)
treeb54e49a5f9785bb2de6ebf87b19aec06d226030b /cpp/src/slice2swift/SwiftUtil.cpp
parentFix proxy unmarshaling (diff)
downloadice-1b02bf54163b420000758b15c40aa7ff8a17b957.tar.bz2
ice-1b02bf54163b420000758b15c40aa7ff8a17b957.tar.xz
ice-1b02bf54163b420000758b15c40aa7ff8a17b957.zip
Fixes for exception and interface by value marshal unmarshal code
Diffstat (limited to 'cpp/src/slice2swift/SwiftUtil.cpp')
-rw-r--r--cpp/src/slice2swift/SwiftUtil.cpp64
1 files changed, 42 insertions, 22 deletions
diff --git a/cpp/src/slice2swift/SwiftUtil.cpp b/cpp/src/slice2swift/SwiftUtil.cpp
index 0cb0c732da7..5de3229e663 100644
--- a/cpp/src/slice2swift/SwiftUtil.cpp
+++ b/cpp/src/slice2swift/SwiftUtil.cpp
@@ -317,15 +317,22 @@ SwiftGenerator::typeToString(const TypePtr& type, const ContainedPtr& toplevel,
if(cl)
{
- //
- // Annotate nonnull closure as @escaping, Swift optional closure parameters are always
- // @escaping see https://www.jessesquires.com/blog/why-optional-swift-closures-are-escaping/
- //
- if(cl->isLocal() && cl->definition() && cl->definition()->isDelegate() && inparam && nonnull)
+ if(cl->isInterface() && !cl->isLocal())
{
- t = "@escaping ";
+ t = getUnqualified(builtinTable[Builtin::KindValue], currentModule);
+ }
+ else
+ {
+ //
+ // Annotate nonnull closure as @escaping, Swift optional closure parameters are always
+ // @escaping see https://www.jessesquires.com/blog/why-optional-swift-closures-are-escaping/
+ //
+ if(cl->isLocal() && cl->definition() && cl->definition()->isDelegate() && inparam && nonnull)
+ {
+ t = "@escaping ";
+ }
+ t += getUnqualified(getAbsoluteImpl(cl), currentModule);
}
- t += getUnqualified(getAbsoluteImpl(cl), currentModule);
}
else if(prx)
{
@@ -857,7 +864,8 @@ SwiftGenerator::writeMarshalUnmarshalCode(Output &out,
if(ClassDeclPtr::dynamicCast(type))
{
- if (marshal)
+ ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
+ if(marshal)
{
out << nl << stream << "write(" << marshalParam << ")";
}
@@ -867,24 +875,36 @@ SwiftGenerator::writeMarshalUnmarshalCode(Output &out,
{
out << nl << "var " << param << ": " << typeStr;
}
- out << nl << "try " << stream << "read";
- out << spar;
- if(!unmarshalParam.empty())
+ if(cl->isInterface())
{
- out << unmarshalParam;
+ out << nl << "try " << stream << "read(" << unmarshalParam << ") { ";
+ if(!declareParam)
+ {
+ out << "self.";
+ }
+ out << param << " = $0 }";
}
- const string swiftModule = getSwiftModule(getTopLevelModule(ContainedPtr::dynamicCast(type)));
- const string className = getUnqualified(getAbsolute(type), swiftModule);
- out << ("value: " + className + ".self");
- out << epar;
- out << sb;
- out << nl;
- if(!declareParam)
+ else
{
- out << "self.";
+ out << nl << "try " << stream << "read";
+ out << spar;
+ if(!unmarshalParam.empty())
+ {
+ out << unmarshalParam;
+ }
+ const string swiftModule = getSwiftModule(getTopLevelModule(ContainedPtr::dynamicCast(type)));
+ const string className = getUnqualified(getAbsolute(type), swiftModule);
+ out << ("value: " + className + ".self");
+ out << epar;
+ out << sb;
+ out << nl;
+ if(!declareParam)
+ {
+ out << "self.";
+ }
+ out << param << " = $0";
+ out << eb;
}
- out << param << " = $0";
- out << eb;
}
return;
}