diff options
author | Matthew Newhook <matthew@zeroc.com> | 2002-01-23 16:22:43 +0000 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2002-01-23 16:22:43 +0000 |
commit | 48b22912b2d0b30ed6a4bf3b175801c57f12525b (patch) | |
tree | 0ce25e038871c5f8607794af01b16aa2095175bf /cpp/src/Slice/CPlusPlusUtil.cpp | |
parent | fixes (diff) | |
download | ice-48b22912b2d0b30ed6a4bf3b175801c57f12525b.tar.bz2 ice-48b22912b2d0b30ed6a4bf3b175801c57f12525b.tar.xz ice-48b22912b2d0b30ed6a4bf3b175801c57f12525b.zip |
Initial commit of generic marshaling.
Diffstat (limited to 'cpp/src/Slice/CPlusPlusUtil.cpp')
-rw-r--r-- | cpp/src/Slice/CPlusPlusUtil.cpp | 218 |
1 files changed, 205 insertions, 13 deletions
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp index ea27d37219f..c922559d9f3 100644 --- a/cpp/src/Slice/CPlusPlusUtil.cpp +++ b/cpp/src/Slice/CPlusPlusUtil.cpp @@ -299,7 +299,7 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string& } else { - out << nl << stream << deref << func << "::Ice::Object::__classIds[0], " << param << ");"; + out << nl << stream << deref << func << "::Ice::Object::__classIds[0], 0, " << param << ");"; } return; } @@ -323,24 +323,22 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string& { out << nl << "::Ice::ObjectPtr " << obj << ';'; ClassDefPtr def = cl->definition(); + string factory; + string type; if (def && !def->isAbstract()) { - out << nl << "if (" << stream << deref << func << cl->scoped() << "::__classIds[0], " << obj << "))"; - out << sb; - out << nl << param << " = " << cl->scoped() << "Ptr::dynamicCast(" << obj << ");"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << param << " = new " << cl->scoped() << ';'; - out << nl << obj << " = " << param << ';'; - out << nl << stream << deref << func << obj << ");"; - out << eb; + factory = cl->scoped(); + factory += "::_factory"; + type = cl->scoped(); + type += "::__classIds[0]"; } else { - out << nl << stream << deref << func << "\"\"," << obj << ");"; - out << nl << param << " = " << cl->scoped() << "Ptr::dynamicCast(" << obj << ");"; + factory = "0"; + type = "\"\""; } + out << nl << stream << deref << func << type << ", " << factory << ", " << obj << ");"; + out << nl << param << " = " << cl->scoped() << "Ptr::dynamicCast(" << obj << ");"; } out << eb; @@ -428,3 +426,197 @@ Slice::writeAllocateCode(Output& out, const list<pair<TypePtr, string> >& params out << nl << typeToString(p->first) << ' ' << p->second << ';'; } } + +void +Slice::writeGenericMarshalUnmarshalCode(Output& out, const TypePtr& type, const string& param, + bool marshal, const string& tn, const string& str, bool pointer) +{ + string stream; + if (str.empty()) + { + stream = marshal ? "__os" : "__is"; + } + else + { + stream = str; + } + + string deref; + if (pointer) + { + deref = "->"; + } + else + { + deref = '.'; + } + + string obj; + if (stream.find("__") == 0) + { + obj = "__obj"; + } + else + { + obj = "obj"; + } + + static const char* outputBuiltinTable[] = + { + "Byte", + "Bool", + "Short", + "Int", + "Long", + "Float", + "Double", + "String", + "Object", + "Proxy", + "???" + }; + string tagName; + if (tn.empty()) + { + tagName = "\""; + tagName += param; + tagName += "\""; + } + else + { + tagName = tn; + } + + string streamFunc = marshal ? "write" : "read"; + string genFunc = marshal ? "ice_marshal(" : "ice_unmarshal("; + + BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); + if (builtin) + { + if (builtin->kind() == Builtin::KindObject) + { + streamFunc += outputBuiltinTable[builtin->kind()]; + if (marshal) + { + out << nl << stream << deref << streamFunc << "(" << tagName << ", " << param << ");"; + } + else + { + out << nl << stream << deref << streamFunc << "(" << tagName << ", ::Ice::Object::__classIds[0], 0, " + << param << ");"; + } + return; + } + else + { + out << nl << stream << deref << streamFunc << outputBuiltinTable[builtin->kind()] + << "(" << tagName << ", " << param << ");"; + return; + } + } + + ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); + if (cl) + { + out << sb; + if (marshal) + { + out << nl << "::Ice::ObjectPtr " << obj << " = " << param << ';'; + out << nl << stream << deref << streamFunc << "Object(" << tagName << ", " << obj << ");"; + } + else + { + out << nl << "::Ice::ObjectPtr " << obj << ';'; + ClassDefPtr def = cl->definition(); + string factory; + string type; + if (def && !def->isAbstract()) + { + factory = cl->scoped(); + factory += "::_factory"; + type = cl->scoped(); + type += "::__classIds[0]"; + } + else + { + factory = "0"; + type = "\"\""; + } + out << nl << stream << deref << streamFunc << "Object(" << tagName << ", " + << type << ", " << factory << ", " << obj << ");"; + out << nl << param << " = " << cl->scoped() << "Ptr::dynamicCast(" << obj << ");"; + } + out << eb; + + return; + } + + StructPtr st = StructPtr::dynamicCast(type); + if (st) + { + out << nl << param << "." << genFunc << tagName << ", " << (pointer ? "" : "&") << stream << ");"; + return; + } + + SequencePtr seq = SequencePtr::dynamicCast(type); + if (seq) + { + BuiltinPtr builtin = BuiltinPtr::dynamicCast(seq->type()); + if (builtin) + { + out << nl << stream << deref << streamFunc << outputBuiltinTable[builtin->kind()] << "Seq(" + << tagName << ", " << param << ");"; + } + else + { + out << nl << seq->scope() << genFunc << tagName << ", " << (pointer ? "" : "&") << stream + << ", " << param << ", " << seq->scope() << "__U__" << seq->name() << "());"; + } + return; + } + + DictionaryPtr dict = DictionaryPtr::dynamicCast(type); + if (dict) + { + out << nl << dict->scope() << genFunc << tagName << ", " << (pointer ? "" : "&") << stream + << ", " << param << ", " << dict->scope() << "__U__" << dict->name() << "());"; + return; + } + + ConstructedPtr constructed = ConstructedPtr::dynamicCast(type); + if (!constructed) + { + ProxyPtr proxy = ProxyPtr::dynamicCast(type); + assert(proxy); + constructed = proxy->_class(); + } + + out << nl << constructed->scope() << genFunc << tagName << ", " << (pointer ? "" : "&") << stream + << ", " << param << ");"; +} + +void +Slice::writeGenericMarshalCode(Output& out, const list<pair<TypePtr, string> >& params, const TypePtr& ret) +{ + for (list<pair<TypePtr, string> >::const_iterator p = params.begin(); p != params.end(); ++p) + { + writeGenericMarshalUnmarshalCode(out, p->first, p->second, true); + } + if (ret) + { + writeGenericMarshalUnmarshalCode(out, ret, "__ret", true); + } +} + +void +Slice::writeGenericUnmarshalCode(Output& out, const list<pair<TypePtr, string> >& params, const TypePtr& ret) +{ + for (list<pair<TypePtr, string> >::const_iterator p = params.begin(); p != params.end(); ++p) + { + writeGenericMarshalUnmarshalCode(out, p->first, p->second, false); + } + if (ret) + { + writeGenericMarshalUnmarshalCode(out, ret, "__ret", false); + } +} |