summaryrefslogtreecommitdiff
path: root/cpp/src/slice2cpp/Gen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/slice2cpp/Gen.cpp')
-rw-r--r--cpp/src/slice2cpp/Gen.cpp324
1 files changed, 10 insertions, 314 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 994c62dc707..a35a4890328 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -195,7 +195,6 @@ Slice::Gen::generate(const UnitPtr& p)
C << "\n#include <Ice/LocalException.h>";
C << "\n#include <Ice/ObjectFactory.h>";
C << "\n#include <Ice/BasicStream.h>";
- C << "\n#include <Ice/Stream.h>";
}
else if(p->usesNonLocals())
{
@@ -203,7 +202,7 @@ Slice::Gen::generate(const UnitPtr& p)
H << "\n#include <Ice/LocalObject.h>";
C << "\n#include <Ice/BasicStream.h>";
- C << "\n#include <Ice/Stream.h>";
+ C << "\n#include <Ice/Object.h>";
}
else
{
@@ -432,10 +431,6 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
H << sp << nl << "virtual void __write(::IceInternal::BasicStream*) const;";
H << nl << "virtual void __read(::IceInternal::BasicStream*, bool = true);";
- H << sp << nl << "virtual void __marshal(const ::Ice::StreamPtr&) const;";
- H << nl << "virtual void __unmarshal(const ::Ice::StreamPtr&);";
- H << nl << "void ice_unmarshal(const ::std::string&, const ::Ice::StreamPtr&);";
-
TypeStringList memberList;
for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
@@ -463,26 +458,6 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
emitExceptionBase(base, "__read(__is)");
C << eb;
- C << sp << nl << "void" << nl << scoped.substr(2)
- << "::__marshal(const ::Ice::StreamPtr& __os) const";
- C << sb;
- emitExceptionBase(base, "__marshal(__os)"); // Base must come first (due to schema rules).
- writeGenericMarshalCode(C, memberList, 0);
- C << eb;
- C << sp << nl << "void" << nl << scoped.substr(2) << "::__unmarshal(const ::Ice::StreamPtr& __is)";
- C << sb;
- emitExceptionBase(base, "__unmarshal(__is)"); // Base must come first (due to schema rules).
- writeGenericUnmarshalCode(C, memberList, 0);
- C << eb;
-
- C << sp << nl << "void" << nl << scoped.substr(2) << "::ice_unmarshal(const ::std::string& __name, "
- << "const ::Ice::StreamPtr& __is)";
- C << sb;
- C << nl << "__is->startReadException(__name);";
- C << nl << "__unmarshal(__is);";
- C << nl << "__is->endReadException();";
- C << eb;
-
if(p->usesClasses())
{
if(!base || (base && !base->usesClasses()))
@@ -599,14 +574,11 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p)
if(!p->isLocal())
{
//
- // Neither of these four member functions are virtual!
+ // None of these member functions is virtual!
//
H << sp << nl << _dllExport << "void __write(::IceInternal::BasicStream*) const;";
H << nl << _dllExport << "void __read(::IceInternal::BasicStream*);";
- H << sp << nl << _dllExport << "void ice_marshal(const ::std::string&, const ::Ice::StreamPtr&) const;";
- H << nl << _dllExport << "void ice_unmarshal(const ::std::string&, const ::Ice::StreamPtr&);";
-
TypeStringList memberList;
for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
@@ -621,22 +593,6 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p)
C << sb;
writeUnmarshalCode(C, memberList, 0);
C << eb;
-
- C << sp << nl << "void" << nl << scoped.substr(2)
- << "::ice_marshal(const ::std::string& __name, const ::Ice::StreamPtr& __os) const";
- C << sb;
- C << nl << "__os->startWriteStruct(__name);";
- writeGenericMarshalCode(C, memberList, 0);
- C << nl << "__os->endWriteStruct();";
- C << eb;
-
- C << sp << nl << "void" << nl << scoped.substr(2)
- << "::ice_unmarshal(const ::std::string& __name, const ::Ice::StreamPtr& __is)";
- C << sb;
- C << nl << "__is->startReadStruct(__name);";
- writeGenericUnmarshalCode(C, memberList, 0);
- C << nl << "__is->endReadStruct();";
- C << eb;
}
H << eb << ';';
@@ -678,23 +634,6 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p)
<< ");";
H << nl << _dllExport << "void __read(::IceInternal::BasicStream*, " << name << "&, __U__" << name << ");";
- H << sp << nl << _dllExport << "void ice_marshal(const ::std::string&, const ::Ice::StreamPtr&, const "
- << name << "&, __U__" << name
- << ");";
- H << nl << _dllExport << "void ice_unmarshal(const ::std::string&, const ::Ice::StreamPtr&, "
- << name << "&, __U__" << name << ");";
-
- H << sp << nl << "class " << _dllExport << name << "Helper";
- H << sb;
- H.zeroIndent();
- H << nl << "public:";
- H.restoreIndent();
- H << sp << nl << "static void ice_marshal(const ::std::string&, const ::Ice::StreamPtr&, const "
- << name << "&);";
- H << nl << "static void ice_unmarshal(const ::std::string&, const ::Ice::StreamPtr&, "
- << name << "&);";
- H << eb << ";";
-
C << sp << nl << "void" << nl << scope.substr(2) << "__write(::IceInternal::BasicStream* __os, const "
<< scoped << "& v, " << scope << "__U__" << name << ")";
C << sb;
@@ -728,50 +667,6 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p)
writeMarshalUnmarshalCode(C, type, "v[i]", false);
C << eb;
C << eb;
-
- C << sp << nl << "void" << nl << scope.substr(2)
- << "ice_marshal(const ::std::string& __name, const ::Ice::StreamPtr& __os, const "
- << scoped << "& v, " << scope << "__U__" << name << ")";
- C << sb;
- C << nl << "__os->startWriteSequence(__name, ::Ice::Int(v.size()));";
- C << nl << scoped << "::const_iterator p;";
- C << nl << "for(p = v.begin(); p != v.end(); ++p)";
- C << sb;
- writeGenericMarshalUnmarshalCode(C, type, "(*p)", true, "\"e\"");
- C << eb;
- C << nl << "__os->endWriteSequence();";
- C << eb;
-
- C << sp << nl << "void" << nl << scope.substr(2) << "ice_unmarshal(const ::std::string& __name, "
- << "const ::Ice::StreamPtr& __is, " << scoped << "& v, " << scope << "__U__" << name << ')';
- C << sb;
- C << nl << "::Ice::Int sz = __is->startReadSequence(__name);";
- //
- // ML:
- // Don't use v.resize(sz) or v.reserve(sz) here, as it cannot
- // be checked whether sz is a reasonable value.
- //
- C << nl << "while(sz--)";
- C << sb;
- C << nl << "v.resize(v.size() + 1);";
- writeGenericMarshalUnmarshalCode(C, type, "v.back()", false, "\"e\"");
- C << eb;
- C << nl << "__is->endReadSequence();";
- C << eb;
-
- C << sp << nl << "void" << nl << scope.substr(2) << name << "Helper::"
- << "ice_marshal(const ::std::string& __name, const ::Ice::StreamPtr& __os, const "
- << name << "& v)";
- C << sb;
- C << nl << scope << "ice_marshal(__name, __os, v, " << scope << "__U__" << name << "());";
- C << eb;
-
- C << sp << nl << "void" << nl << scope.substr(2) << name << "Helper::"
- << "ice_unmarshal(const ::std::string& __name, const ::Ice::StreamPtr& __is, "
- << name << "& v)";
- C << sb;
- C << nl << scope << "ice_unmarshal(__name, __is, v, " << scope << "__U__" << name << "());";
- C << eb;
}
}
@@ -804,22 +699,6 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
H << nl << _dllExport << "void __read(::IceInternal::BasicStream*, " << name
<< "&, __U__" << name << ");";
- H << sp << nl << _dllExport << "void ice_marshal(const ::std::string&, const ::Ice::StreamPtr&, const "
- << name << "&, __U__" << name << ");";
- H << nl << _dllExport << "void ice_unmarshal(const ::std::string&, const ::Ice::StreamPtr&, "
- << name << "&, __U__" << name << ");";
-
- H << sp << nl << "class " << _dllExport << name << "Helper";
- H << sb;
- H.zeroIndent();
- H << nl << "public:";
- H.restoreIndent();
- H << sp << nl << "static void ice_marshal(const ::std::string&, const ::Ice::StreamPtr&, const "
- << name << "&);";
- H << nl << "static void ice_unmarshal(const ::std::string&, const ::Ice::StreamPtr&, "
- << name << "&);";
- H << eb << ";";
-
C << sp << nl << "void" << nl << scope.substr(2) << "__write(::IceInternal::BasicStream* __os, const "
<< scoped << "& v, " << scope << "__U__" << name << ")";
C << sb;
@@ -846,52 +725,6 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
writeMarshalUnmarshalCode(C, valueType, "__i->second", false);
C << eb;
C << eb;
-
- C << sp << nl << "void" << nl << scope.substr(2)
- << "ice_marshal(const ::std::string& __name, const ::Ice::StreamPtr& __os, const "
- << scoped << "& v, " << scope << "__U__" << name << ")";
- C << sb;
- C << nl << "__os->startWriteDictionary(__name, ::Ice::Int(v.size()));";
- C << nl << scoped << "::const_iterator p;";
- C << nl << "for(p = v.begin(); p != v.end(); ++p)";
- C << sb;
- C << nl << "__os->startWriteDictionaryElement();";
- writeGenericMarshalUnmarshalCode(C, keyType, "p->first", true, "\"key\"");
- writeGenericMarshalUnmarshalCode(C, valueType, "p->second", true, "\"value\"");
- C << nl << "__os->endWriteDictionaryElement();";
- C << eb;
- C << nl << "__os->endWriteDictionary();";
- C << eb;
-
- C << sp << nl << "void" << nl << scope.substr(2) << "ice_unmarshal(const ::std::string& __name, "
- << "const ::Ice::StreamPtr& __is, " << scoped << "& v, " << scope << "__U__" << name << ')';
- C << sb;
- C << nl << "::Ice::Int sz = __is->startReadDictionary(__name);";
- C << nl << "while(sz--)";
- C << sb;
- C << nl << "::std::pair<const " << ks << ", " << vs << "> pair;";
- C << nl << "__is->startReadDictionaryElement();";
- writeGenericMarshalUnmarshalCode(C, keyType, pf, false, "\"key\"");
- writeGenericMarshalUnmarshalCode(C, valueType, "pair.second", false, "\"value\"");
- C << nl << "__is->endReadDictionaryElement();";
- C << nl << "v.insert(v.end(), pair);";
- C << eb;
- C << nl << "__is->endReadDictionary();";
- C << eb;
-
- C << sp << nl << "void" << nl << scope.substr(2) << name << "Helper::"
- << "ice_marshal(const ::std::string& __name, const ::Ice::StreamPtr& __os, const "
- << name << "& v)";
- C << sb;
- C << nl << scope << "ice_marshal(__name, __os, v, " << scope << "__U__" << name << "());";
- C << eb;
-
- C << sp << nl << "void" << nl << scope.substr(2) << name << "Helper::"
- << "ice_unmarshal(const ::std::string& __name, const ::Ice::StreamPtr& __is, "
- << name << "& v)";
- C << sb;
- C << nl << scope << "ice_unmarshal(__name, __is, v, " << scope << "__U__" << name << "());";
- C << eb;
}
}
@@ -924,11 +757,6 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p)
H << sp << nl << _dllExport << "void __write(::IceInternal::BasicStream*, " << name << ");";
H << nl << _dllExport << "void __read(::IceInternal::BasicStream*, " << name << "&);";
- H << sp << nl << _dllExport << "void ice_marshal(const ::std::string&, const ::Ice::StreamPtr&, "
- << name << ");";
- H << nl << _dllExport << "void ice_unmarshal(const ::std::string&, const ::Ice::StreamPtr&, "
- << name << "&);";
-
C << sp << nl << "void" << nl << scope.substr(2) << "__write(::IceInternal::BasicStream* __os, " << scoped
<< " v)";
C << sb;
@@ -968,38 +796,6 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p)
C << nl << "v = static_cast< " << scoped << ">(val);";
}
C << eb;
-
- string tableName = "__T__";
- tableName += name;
-
- C << sp;
- C << nl << "static const ::std::string " << "__RT__" << name << "[] =";
- C << sb;
- en = enumerators.begin();
- while(en != enumerators.end())
- {
- C << nl << "\"" << (*en)->name() << "\"";
- if(++en != enumerators.end())
- {
- C << ',';
- }
- }
- C << eb << ";";
- C << nl << "static const ::Ice::StringSeq __T__" << name << "(&__RT__" << name << "[0], "
- << "&__RT__" << name << "[" << enumerators.size() << "]);";
-
- C << sp << nl << "void" << nl << scope.substr(2) << "ice_marshal(const ::std::string& __name, "
- << "const ::Ice::StreamPtr& __os, " << scoped << " v)";
- C << sb;
- C << nl << "__os->writeEnum(__name, " << "__T__" << name << ", v);";
- C << eb;
-
- C << sp << nl << "void" << nl << scope.substr(2) << "ice_unmarshal(const ::std::string& __name, "
- << "const ::Ice::StreamPtr& __is, " << scoped << "& v)";
- C << sb;
- C << nl << "::Ice::Int ordinal = __is->readEnum(__name, __T__" << name << ");";
- C << nl << "v = static_cast< " << scoped << ">(ordinal);";
- C << eb;
}
}
@@ -2396,17 +2192,9 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
}
H << sp;
- H << nl << "virtual void __write(::IceInternal::BasicStream*) const;";
+ H << nl << "virtual void __write(::IceInternal::BasicStream*, bool) const;";
H << nl << "virtual void __read(::IceInternal::BasicStream*, bool = true);";
- H << sp;
- H << nl << "virtual void __marshal(const ::Ice::StreamPtr&, bool) const;";
- H << nl << "virtual void __unmarshal(const ::Ice::StreamPtr&);";
-
- H << sp;
- H << nl << "static void ice_unmarshal(const ::std::string&, const ::Ice::StreamPtr&, "
- << scoped << "Ptr&);";
-
TypeStringList memberList;
DataMemberList dataMembers = p->dataMembers();
for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
@@ -2414,13 +2202,14 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
memberList.push_back(make_pair((*q)->type(), (*q)->name()));
}
C << sp;
- C << nl << "void" << nl << scoped.substr(2) << "::__write(::IceInternal::BasicStream* __os) const";
+ C << nl << "void" << nl << scoped.substr(2)
+ << "::__write(::IceInternal::BasicStream* __os, bool __marshalFacets) const";
C << sb;
C << nl << "__os->writeTypeId(ice_staticId());";
C << nl << "__os->startWriteSlice();";
writeMarshalCode(C, memberList, 0);
C << nl << "__os->endWriteSlice();";
- emitClassBase(base, "__os", "__write");
+ emitClassBase(base, "__os", "__write", ", __marshalFacets");
C << eb;
C << sp;
C << nl << "void" << nl << scoped.substr(2) << "::__read(::IceInternal::BasicStream* __is, bool __rid)";
@@ -2436,38 +2225,6 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
emitClassBase(base, "__is", "__read");
C << eb;
- C << sp;
- C << nl << "void" << nl << scoped.substr(2)
- << "::__marshal(const ::Ice::StreamPtr& __os, bool __marshalFacets) const";
- C << sb;
- emitClassBase(base, "__os, __marshalFacets", "__marshal");
- writeGenericMarshalCode(C, memberList, 0);
- C << eb;
-
- C << sp;
- C << nl << "void" << nl << scoped.substr(2) << "::__unmarshal(const ::Ice::StreamPtr& __is)";
- C << sb;
- emitClassBase(base, "__is", "__unmarshal");
- writeGenericUnmarshalCode(C, memberList, 0);
- C << eb;
-
- C << sp;
- C << nl << "void" << nl << scope.substr(2) << "__readObject(const ::Ice::StreamPtr& __is, "
- << "const ::std::string& __n, const ::std::string& __st, const ::Ice::ObjectFactoryPtr& __f, "
- << scoped << "Ptr& v)";
- C << sb;
- C << nl << "::Ice::ObjectPtr __obj;";
- C << nl << "__obj = __is->readObject(__n, __st, __f);";
- C << nl << "v = " << scoped << "Ptr::dynamicCast(__obj);";
- C << eb;
-
- C << sp;
- C << nl << "void" << nl << scoped.substr(2) << "::ice_unmarshal(const ::std::string& __name, "
- << "const ::Ice::StreamPtr& __is, " << scoped << "Ptr& value)";
- C << sb;
- writeGenericMarshalUnmarshalCode(C, p->declaration(), "value", false, "__name");
- C << eb;
-
if(!p->isAbstract())
{
string name = fixKwd(p->name());
@@ -2811,7 +2568,8 @@ Slice::Gen::ObjectVisitor::visitDataMember(const DataMemberPtr& p)
}
void
-Slice::Gen::ObjectVisitor::emitClassBase(const ClassDefPtr& base, const std::string& stream, const std::string& call)
+Slice::Gen::ObjectVisitor::emitClassBase(const ClassDefPtr& base, const string& stream, const string& call,
+ const string& args)
{
string winName = base ? fixKwd(base->name()) : "Object";
string unixName = base ? fixKwd(base->scoped()) : "::Ice::Object";
@@ -2819,11 +2577,11 @@ Slice::Gen::ObjectVisitor::emitClassBase(const ClassDefPtr& base, const std::str
C.zeroIndent();
C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG
C.restoreIndent();
- C << nl << winName << "::" << call << "(" << stream << ");";
+ C << nl << winName << "::" << call << "(" << stream << args << ");";
C.zeroIndent();
C << nl << "#else";
C.restoreIndent();
- C << nl << unixName << "::" << call << "(" << stream << ");";
+ C << nl << unixName << "::" << call << "(" << stream << args << ");";
C.zeroIndent();
C << nl << "#endif";
C.restoreIndent();
@@ -3029,22 +2787,6 @@ Slice::Gen::HandleVisitor::visitClassDecl(const ClassDeclPtr& p)
H << nl << _dllExport << "void __write(::IceInternal::BasicStream*, const " << name << "Ptr&);";
H << nl << _dllExport << "void __read(::IceInternal::BasicStream*, " << name << "Ptr&);";
H << nl << _dllExport << "void __patch__" << name << "Ptr(void*, ::Ice::ObjectPtr&);";
- H << nl << _dllExport << "void __writeObject(const ::Ice::StreamPtr&, const ::std::string&, const "
- << name << "Ptr&);";
- H << nl << _dllExport << "void __readObject(const ::Ice::StreamPtr&, const ::std::string&, "
- << "const ::std::string&, const ::Ice::ObjectFactoryPtr&, " << name << "Ptr&);";
-
- H << sp;
- H << nl << _dllExport << "void ice_marshal(const ::std::string&, const ::Ice::StreamPtr&, const "
- << name << "Ptr&);";
- H << nl << _dllExport << "void ice_unmarshal(const ::std::string&, const ::Ice::StreamPtr&, "
- << name << "Ptr&);";
-
- H << sp;
- H << nl << _dllExport << "void ice_marshal(const ::std::string&, const ::Ice::StreamPtr&, const "
- << name << "Prx&);";
- H << nl << _dllExport << "void ice_unmarshal(const ::std::string&, const ::Ice::StreamPtr&, "
- << name << "Prx&);";
}
}
@@ -3099,52 +2841,6 @@ Slice::Gen::HandleVisitor::visitClassDefStart(const ClassDefPtr& p)
C << sb;
C << nl << "__os->write(::Ice::ObjectPtr(v));";
C << eb;
-
- C << sp;
- C << nl << "void" << nl << scope.substr(2) << "__writeObject(const ::Ice::StreamPtr& __os, "
- << "const ::std::string& __s, const " << scoped << "Ptr& v)";
- C << sb;
- C << nl << "__os->writeObject(__s, ::Ice::ObjectPtr(v));";
- C << eb;
-
- C << sp;
- C << nl << "void" << nl << scope.substr(2)
- << "ice_marshal(const ::std::string& __name, const ::Ice::StreamPtr& __os, const " << scoped << "Ptr& v)";
- C << sb;
- C << nl << "__os->writeObject(__name, v);";
- C << eb;
-
- C << sp;
- C << nl << "void" << nl << scope.substr(2) << "ice_unmarshal(const ::std::string& __name, "
- << "const ::Ice::StreamPtr& __is, " << scoped << "Ptr& v)";
- C << sb;
- C << nl << "::Ice::ObjectPtr __obj;";
- C << nl << "__obj = __is->readObject(__name, " << type << ", " << factory << ");";
- C << nl << "v = " << scoped << "Ptr::dynamicCast(__obj);";
- C << eb;
-
- C << sp;
- C << nl << "void" << nl << scope.substr(2)
- << "ice_marshal(const ::std::string& __name, const ::Ice::StreamPtr& __os, const " << scoped << "Prx& v)";
- C << sb;
- C << nl << "__os->writeProxy(__name, v);";
- C << eb;
-
- C << sp;
- C << nl << "void" << nl << scope.substr(2) << "ice_unmarshal(const ::std::string& __name, "
- << "const ::Ice::StreamPtr& __is, " << scoped << "Prx& v)";
- C << sb;
- C << nl << "::Ice::ObjectPrx proxy = __is->readProxy(__name);";
- C << nl << "if(!proxy)";
- C << sb;
- C << nl << "v = 0;";
- C << eb;
- C << nl << "else";
- C << sb;
- C << nl << "v = new ::IceProxy" << scoped << ';';
- C << nl << "v->__copyFrom(proxy);";
- C << eb;
- C << eb;
}
return true;