diff options
author | Joe George <joe@zeroc.com> | 2019-03-05 17:20:14 -0500 |
---|---|---|
committer | Joe George <joe@zeroc.com> | 2019-03-05 17:20:14 -0500 |
commit | e8de1a033691804c5716b3026f825efe19b8d647 (patch) | |
tree | b69936ddc62d533a918667cc45dbdc2f8ce2e470 /cpp/src/slice2swift/SwiftUtil.cpp | |
parent | More InputStream/OutputStream updates (diff) | |
download | ice-e8de1a033691804c5716b3026f825efe19b8d647.tar.bz2 ice-e8de1a033691804c5716b3026f825efe19b8d647.tar.xz ice-e8de1a033691804c5716b3026f825efe19b8d647.zip |
slice2swift marshal/unmarshal updates
Diffstat (limited to 'cpp/src/slice2swift/SwiftUtil.cpp')
-rw-r--r-- | cpp/src/slice2swift/SwiftUtil.cpp | 84 |
1 files changed, 79 insertions, 5 deletions
diff --git a/cpp/src/slice2swift/SwiftUtil.cpp b/cpp/src/slice2swift/SwiftUtil.cpp index ce5d8d98901..afc3e4c4514 100644 --- a/cpp/src/slice2swift/SwiftUtil.cpp +++ b/cpp/src/slice2swift/SwiftUtil.cpp @@ -649,17 +649,91 @@ void SwiftGenerator::writeMarshalUnmarshalCode(Output &out, const TypePtr& type, const string& param, + const string& swiftModule, + bool insideStream, + bool declareParam, bool marshal) { + string unqualifiedType = getUnqualified(getAbsolute(type), swiftModule); + string streamName = marshal ? "ostr" : "istr"; + string assign = declareParam ? ("let " + param + ": " + unqualifiedType) : param; + string marshalParam = insideStream ? ("v." + param) : param; + string stream = insideStream ? "" : (streamName + "."); + + BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); + if(builtin) + { + switch(builtin->kind()) + { + case Builtin::KindByte: + case Builtin::KindBool: + case Builtin::KindShort: + case Builtin::KindInt: + case Builtin::KindLong: + case Builtin::KindFloat: + case Builtin::KindDouble: + case Builtin::KindString: + case Builtin::KindObjectProxy: + { + if(marshal) + { + out << nl << stream << "write(" << marshalParam << ")"; + } + else + { + out << nl << assign << " = try " << stream << "read()"; + } + break; + } + case Builtin::KindObject: + case Builtin::KindValue: + { + if(marshal) + { + out << nl << stream << "write(" << marshalParam << ")"; + } + else + { + out << nl << assign << "= try " << stream << "read(value: " << unqualifiedType << ") { "; + out << param << " = $0 }"; + + } + break; + } + case Builtin::KindLocalObject: + { + assert(false); + break; + } + default: + { + + } + } + } + + EnumPtr en = EnumPtr::dynamicCast(type); + if(en) + { + if(marshal) + { + out << nl << stream << "write(" << marshalParam << ")"; + } + else + { + out << nl << assign << " = try " << stream << "read()"; + } + return; + } } void -SwiftGenerator::writeOptionalMarshalUnmarshalCode(Output &out, - const TypePtr& type, - const string& param, - int tag, - bool marshal) +SwiftGenerator::writeOptionalMarshalUnmarshalCode(Output&, + const TypePtr&, + const string&, + int, + bool) { } |