diff options
author | Joe George <joe@zeroc.com> | 2019-02-28 11:00:33 -0500 |
---|---|---|
committer | Joe George <joe@zeroc.com> | 2019-03-05 11:38:52 -0500 |
commit | 91830088f0528f14d954235afee68a4d8335277b (patch) | |
tree | 9be0343027846d3425ee1ab0945736dbfbc004d8 /cpp/src/slice2swift/Gen.cpp | |
parent | Put back Xcode projects to use with Carthage (diff) | |
download | ice-91830088f0528f14d954235afee68a4d8335277b.tar.bz2 ice-91830088f0528f14d954235afee68a4d8335277b.tar.xz ice-91830088f0528f14d954235afee68a4d8335277b.zip |
Remove Streamable
Diffstat (limited to 'cpp/src/slice2swift/Gen.cpp')
-rw-r--r-- | cpp/src/slice2swift/Gen.cpp | 104 |
1 files changed, 61 insertions, 43 deletions
diff --git a/cpp/src/slice2swift/Gen.cpp b/cpp/src/slice2swift/Gen.cpp index 7bfda21774e..9fe247af7aa 100644 --- a/cpp/src/slice2swift/Gen.cpp +++ b/cpp/src/slice2swift/Gen.cpp @@ -214,7 +214,6 @@ Gen::ImportVisitor::visitSequence(const SequencePtr& seq) addImport(seq->type(), seq); } - void Gen::ImportVisitor::visitDictionary(const DictionaryPtr& dict) { @@ -304,40 +303,50 @@ Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) const DataMemberList baseMembers = base ? base->allDataMembers() : DataMemberList(); bool rootClass = !base && !p->isLocal(); + // bool required = writeMembers(out, members, p); - writeDefaultInitializer(out, members, p, rootClass); + writeDefaultInitializer(out, members, p, rootClass, true); writeMemberwiseInitializer(out, members, baseMembers, allMembers, p, rootClass); if(!p->isLocal()) { out << sp; - out << nl << "required public init(from ins: " << getUnqualified("Ice.InputStream", swiftModule) << ") throws"; + out << nl; + if(base) + { + out << "override "; + } + out << "public func _iceWriteImpl(to os: " << getUnqualified("Ice.OutputStream", swiftModule) << ")"; out << sb; for(DataMemberList::const_iterator q = members.begin(); q != members.end(); ++q) { - DataMemberPtr member = *q; - StringList metadata = member->getMetaData(); - out << nl << "self." << member->name() << " = try " - << getUnqualified(getAbsolute(member->type()), swiftModule) << "(from: ins)"; + out << nl << "os.write" << spar << fixIdent((*q)->name()) << epar; } if(base) { - out << nl << "try super.init(from: ins)"; + out << nl << "super._iceWriteImpl(to: os)"; } out << eb; out << sp; out << nl; - out << nl; if(base) { out << "override "; } - out << "public func ice_write(to os: " << getUnqualified("Ice.OutputStream", swiftModule) << ")"; + out << "public func _iceReadImpl(from ins: " << getUnqualified("Ice.InputStream", swiftModule) << ") throws"; out << sb; for(DataMemberList::const_iterator q = members.begin(); q != members.end(); ++q) { - out << nl << fixIdent((*q)->name()) << ".ice_write(to: os)"; + DataMemberPtr member = *q; + StringList metadata = member->getMetaData(); + TypePtr type = member->type(); + out << nl; + out << member->name() << " = try ins.read()"; + } + if(base) + { + out << nl << "try super._iceReadImpl(from: ins)"; } out << eb; @@ -382,32 +391,38 @@ Gen::TypesVisitor::visitStructStart(const StructPtr& p) if(!p->isLocal()) { - out << nl << "extension " << name << ": Ice.Streamable" << sb; - - out << sp; - out << nl << "public init(from ins: Ice.InputStream) throws" << sb; + out << nl << "public extension " << getUnqualified("Ice.InputStream", swiftModule); + out << sb; + out << nl << "func read() throws -> " << name; + out << sb; for(DataMemberList::const_iterator q = members.begin(); q != members.end(); ++q) { DataMemberPtr member = *q; StringList metadata = member->getMetaData(); TypePtr type = member->type(); - out << nl << "self." << member->name() << " = "; - if(isProxyType(type)) - { - out << "try ins.read(proxy: " << getUnqualified(getAbsolute(type), swiftModule) << ".self)"; - } - else - { - out << "try " << typeToString(type, p, metadata, member->optional()) << "(from: ins)"; - } + out << nl; + out << "let " << member->name() << ": " << getUnqualified(getAbsolute(type), swiftModule) << " = try read()"; } + + out << nl << "return " << name; + out << spar; + for(DataMemberList::const_iterator q = members.begin(); q != members.end(); ++q) + { + out << ((*q)->name() + ": " + (*q)->name()); + } + out << epar; + out << eb; + out << eb; out << sp; - out << nl << "public func ice_write(to os: Ice.OutputStream)" << sb; + out << nl << "public extension " << getUnqualified("Ice.OutputStream", swiftModule); + out << sb; + + out << nl << "func write(_ v: " << name << ")" << sb; for(DataMemberList::const_iterator q = members.begin(); q != members.end(); ++q) { - out << nl << fixIdent((*q)->name()) << ".ice_write(to: os)"; + out << nl << "write(v." << fixIdent((*q)->name()) << ")"; } out << eb; @@ -456,32 +471,36 @@ Gen::TypesVisitor::visitEnum(const EnumPtr& p) { out << nl << "case " << fixIdent((*en)->name()) << " = " << (*en)->value(); } - out << eb; - - out << sp; - out << nl << "extension " << name << ": Ice.Streamable"; - out << sb; out << nl << "public init()"; out << sb; out << nl << "self = ." << fixIdent((*enumerators.begin())->name()); out << eb; + out << eb; + out << sp; - out << nl << "public init(from ins: Ice.InputStream) throws"; + out << nl << "public extension " << getUnqualified("Ice.InputStream", swiftModule); + out << sb; + out << nl << "func read() throws -> " << name; out << sb; out << nl << "var rawValue = " << enumType << "()"; - out << nl << "try ins.read(enum: &rawValue, maxValue: " << p->maxValue() << ")"; - out << nl << "guard let val = " << name << "(rawValue: rawValue) else" << sb; + out << nl << "try read(enum: &rawValue, maxValue: " << p->maxValue() << ")"; + out << nl << "guard let val = " << name << "(rawValue: rawValue) else"; + out << sb; out << nl << "throw MarshalException(reason: \"invalid enum value\")"; out << eb; - out << nl << "self = val"; + out << nl << "return val"; + out << eb; + out << eb; out << sp; - out << nl << "public func ice_write(to os: Ice.OutputStream)"; + out << nl << "public extension " << getUnqualified("Ice.OutputStream", swiftModule); out << sb; - out << nl << "os.write(enum: self.rawValue, maxValue: " << p->maxValue() << ")"; + out << nl << "func write(_ v: " << name << ")"; + out << sb; + out << nl << "write(enum: v.rawValue, maxValue: " << p->maxValue() << ")"; out << eb; out << eb; @@ -577,7 +596,7 @@ Gen::ProxyVisitor::visitClassDefStart(const ClassDefPtr& p) out << eb; // - // ImputStream extension + // InputStream extension // out << sp; out << nl << "public extension " << getUnqualified("Ice.InputStream", swiftModule); @@ -694,7 +713,7 @@ Gen::ValueVisitor::visitClassDefStart(const ClassDefPtr& p) { out << "override "; } - out << "public func iceReadImpl(from: " << getUnqualified("Ice.InputStream", swiftModule) << ") throws"; + out << "public func _iceReadImpl(from: " << getUnqualified("Ice.InputStream", swiftModule) << ") throws"; out << sb; out << eb; @@ -704,7 +723,7 @@ Gen::ValueVisitor::visitClassDefStart(const ClassDefPtr& p) { out << "override "; } - out << "public func iceWriteImpl(to: " << getUnqualified("Ice.OutputStream", swiftModule) << ")"; + out << "public func _iceWriteImpl(to os: " << getUnqualified("Ice.OutputStream", swiftModule) << ")"; out << sb; out << nl << "// to.startSlice(ice_staticId(), " << p->compactId() << (!base ? ", true" : ", false") << ");"; for(DataMemberList::const_iterator i = members.begin(); i != members.end(); ++i) @@ -712,7 +731,7 @@ Gen::ValueVisitor::visitClassDefStart(const ClassDefPtr& p) DataMemberPtr member = *i; if(!member->optional()) { - out << nl << fixIdent(member->name()) << ".ice_write(to: to)"; + out << nl << "os.write(" << fixIdent(member->name()) << ")"; } } for(DataMemberList::const_iterator d = optionalMembers.begin(); d != optionalMembers.end(); ++d) @@ -721,7 +740,7 @@ Gen::ValueVisitor::visitClassDefStart(const ClassDefPtr& p) out << nl << "// to.endSlice();"; if(base) { - out << nl << "super.iceWriteImpl(to: to);"; + out << nl << "super._iceWriteImpl(to: os);"; } out << eb; @@ -739,7 +758,6 @@ Gen::ValueVisitor::visitOperation(const OperationPtr&) { } - Gen::ObjectVisitor::ObjectVisitor(::IceUtilInternal::Output& o) : out(o) { } |