diff options
Diffstat (limited to 'cpp/src/slice2cpp')
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 68 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.h | 3 | ||||
-rw-r--r-- | cpp/src/slice2cpp/GenUtil.cpp | 18 |
3 files changed, 76 insertions, 13 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index bdd00d101c4..040da988a2c 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -280,11 +280,11 @@ Slice::Gen::TypesVisitor::visitModuleEnd(const ModulePtr& p) } void -Slice::Gen::TypesVisitor::visitVector(const VectorPtr& p) +Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p) { string name = p->name(); - TypePtr subtype = p->type(); - string s = typeToString(subtype); + TypePtr type = p->type(); + string s = typeToString(type); if (s[0] == ':') { s.insert(0, " "); @@ -292,7 +292,7 @@ Slice::Gen::TypesVisitor::visitVector(const VectorPtr& p) H << sp; H << nl << "typedef ::std::vector<" << s << "> " << name << ';'; - BuiltinPtr builtin = BuiltinPtr::dynamicCast(subtype); + BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); if (!builtin) { string scoped = p->scoped(); @@ -315,7 +315,7 @@ Slice::Gen::TypesVisitor::visitVector(const VectorPtr& p) C << nl << scoped << "::const_iterator p;"; C << nl << "for (p = v.begin(); p != v.end(); ++p)"; C << sb; - writeMarshalUnmarshalCode(C, subtype, "*p", true); + writeMarshalUnmarshalCode(C, type, "*p", true); C << eb; C << eb; C << sp; @@ -331,7 +331,7 @@ Slice::Gen::TypesVisitor::visitVector(const VectorPtr& p) C.zeroIndent(); C << nl << "#ifdef WIN32"; // STLBUG C.restoreIndent(); - C << nl << "v.push_back(" << typeToString(subtype) << "());"; + C << nl << "v.push_back(" << typeToString(type) << "());"; C.zeroIndent(); C << nl << "#else"; C.restoreIndent(); @@ -339,13 +339,67 @@ Slice::Gen::TypesVisitor::visitVector(const VectorPtr& p) C.zeroIndent(); C << nl << "#endif"; C.restoreIndent(); - writeMarshalUnmarshalCode(C, subtype, "v.back()", false); + writeMarshalUnmarshalCode(C, type, "v.back()", false); C << eb; C << eb; } } void +Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p) +{ + string name = p->name(); + TypePtr keyType = p->keyType(); + TypePtr valueType = p->valueType(); + string ks = typeToString(keyType); + if (ks[0] == ':') + { + ks.insert(0, " "); + } + string vs = typeToString(valueType); + H << sp; + H << nl << "typedef ::std::map<" << ks << ", " << vs << "> " << name << ';'; + + string scoped = p->scoped(); + string scope = p->scope(); + if (scope.length()) + { + scope.erase(0, 2); + } + + H << sp; + H << nl << "class __U__" << name << " { };"; + H << nl << "void" << _dllExport << " __write(::IceInternal::Stream*, const " << name << "&, __U__" << name << ");"; + H << nl << "void" << _dllExport << " __read(::IceInternal::Stream*, " << name << "&, __U__" << name << ");"; + C << sp; + C << nl << "void" << nl << scope << "::__write(::IceInternal::Stream* __os, const " << scoped << "& v, ::" + << scope << "::__U__" << name << ')'; + C << sb; + C << nl << "__os->write(::Ice::Int(v.size()));"; + C << nl << scoped << "::const_iterator p;"; + C << nl << "for (p = v.begin(); p != v.end(); ++p)"; + C << sb; + writeMarshalUnmarshalCode(C, keyType, "p->first", true); + writeMarshalUnmarshalCode(C, valueType, "p->second", true); + C << eb; + C << eb; + C << sp; + C << nl << "void" << nl << scope << "::__read(::IceInternal::Stream* __is, " << scoped << "& v, ::" << scope + << "::__U__" << name << ')'; + C << sb; + C << nl << "::Ice::Int sz;"; + C << nl << "__is->read(sz);"; + C << nl << "while (sz--)"; + C << sb; + C << nl << "::std::pair<" << ks << ", " << vs << "> pair;"; + writeMarshalUnmarshalCode(C, keyType, "pair.first", false); + writeMarshalUnmarshalCode(C, valueType, "pair.second", false); + C << nl << "v.insert(v.end(), pair);"; + C << eb; + C << eb; +} + +void Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) { string name = p->name(); diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h index 7019d69d868..77002b264a3 100644 --- a/cpp/src/slice2cpp/Gen.h +++ b/cpp/src/slice2cpp/Gen.h @@ -53,7 +53,8 @@ private: virtual void visitModuleStart(const ModulePtr&); virtual void visitModuleEnd(const ModulePtr&); - virtual void visitVector(const VectorPtr&); + virtual void visitSequence(const SequencePtr&); + virtual void visitDictionary(const DictionaryPtr&); virtual void visitEnum(const EnumPtr&); virtual void visitNative(const NativePtr&); diff --git a/cpp/src/slice2cpp/GenUtil.cpp b/cpp/src/slice2cpp/GenUtil.cpp index 4249d7a7cda..1a94c7a1a41 100644 --- a/cpp/src/slice2cpp/GenUtil.cpp +++ b/cpp/src/slice2cpp/GenUtil.cpp @@ -287,21 +287,29 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string& return; } - VectorPtr vec = VectorPtr::dynamicCast(type); - if (vec) + SequencePtr seq = SequencePtr::dynamicCast(type); + if (seq) { - if (BuiltinPtr::dynamicCast(vec->type())) + if (BuiltinPtr::dynamicCast(seq->type())) { out << nl << stream << "->" << func << param << ");"; } else { - out << nl << vec->scope() << "::__" << func << stream << ", " << param << ", " << vec->scope() - << "::__U__" << vec->name() << "());"; + out << nl << seq->scope() << "::__" << func << stream << ", " << param << ", " << seq->scope() + << "::__U__" << seq->name() << "());"; } return; } + DictionaryPtr dict = DictionaryPtr::dynamicCast(type); + if (dict) + { + out << nl << dict->scope() << "::__" << func << stream << ", " << param << ", " << dict->scope() + << "::__U__" << dict->name() << "());"; + return; + } + NativePtr native = NativePtr::dynamicCast(type); assert(!native); // TODO |