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.cpp1659
1 files changed, 578 insertions, 1081 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index f9cf0ecfd32..fd34162a680 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -26,7 +26,10 @@ using namespace Slice;
using namespace IceUtil;
using namespace IceUtilInternal;
-static string
+namespace
+{
+
+string
getDeprecateSymbol(const ContainedPtr& p1, const ContainedPtr& p2)
{
string deprecateMetadata, deprecateSymbol;
@@ -38,7 +41,7 @@ getDeprecateSymbol(const ContainedPtr& p1, const ContainedPtr& p2)
return deprecateSymbol;
}
-static void
+void
writeConstantValue(IceUtilInternal::Output& out, const TypePtr& type, const SyntaxTreeBasePtr& valueType,
const string& value, int useWstring, const StringList& metaData)
{
@@ -126,7 +129,32 @@ writeConstantValue(IceUtilInternal::Output& out, const TypePtr& type, const Synt
}
}
-static void
+void
+writeMarshalUnmarshalDataMember(IceUtilInternal::Output& C, const DataMemberPtr& p, bool marshal)
+{
+ writeMarshalUnmarshalCode(C, p->type(), p->optional(), p->tag(), fixKwd(p->name()), marshal, p->getMetaData());
+}
+
+void
+writeMarshalUnmarshalDataMembers(IceUtilInternal::Output& C,
+ const DataMemberList& dataMembers,
+ const DataMemberList& optionalDataMembers,
+ bool marshal)
+{
+ for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
+ {
+ if(!(*q)->optional())
+ {
+ writeMarshalUnmarshalDataMember(C, *q, marshal);
+ }
+ }
+ for(DataMemberList::const_iterator q = optionalDataMembers.begin(); q != optionalDataMembers.end(); ++q)
+ {
+ writeMarshalUnmarshalDataMember(C, *q, marshal);
+ }
+}
+
+void
writeDataMemberInitializers(IceUtilInternal::Output& C, const DataMemberList& members, int useWstring)
{
bool first = true;
@@ -152,6 +180,8 @@ writeDataMemberInitializers(IceUtilInternal::Output& C, const DataMemberList& me
}
}
+}
+
Slice::Gen::Gen(const string& base, const string& headerExtension, const string& sourceExtension,
const vector<string>& extraHeaders, const string& include,
const vector<string>& includePaths, const string& dllExport, const string& dir,
@@ -327,6 +357,7 @@ Slice::Gen::generate(const UnitPtr& p)
H << "\n#include <Ice/ObjectF.h>";
H << "\n#include <Ice/Exception.h>";
H << "\n#include <Ice/LocalObject.h>";
+ H << "\n#include <Ice/StreamTraits.h>";
if(p->usesProxies())
{
@@ -358,7 +389,9 @@ Slice::Gen::generate(const UnitPtr& p)
{
H << "\n#include <Ice/FactoryTableInit.h>";
}
+
H << "\n#include <IceUtil/ScopedArray.h>";
+ H << "\n#include <IceUtil/Optional.h>";
if(p->usesNonLocals())
{
@@ -387,6 +420,12 @@ Slice::Gen::generate(const UnitPtr& p)
}
}
+ if(p->hasContentsWithMetaData("preserve-slice"))
+ {
+ H << "\n#include <Ice/SlicedDataF.h>";
+ C << "\n#include <Ice/SlicedData.h>";
+ }
+
if(_checksum)
{
C << "\n#include <Ice/SliceChecksums.h>";
@@ -447,12 +486,12 @@ Slice::Gen::generate(const UnitPtr& p)
ObjectDeclVisitor objectDeclVisitor(H, C, _dllExport);
p->visit(&objectDeclVisitor, false);
- HandleVisitor handleVisitor(H, C, _dllExport, _stream);
- p->visit(&handleVisitor, false);
-
TypesVisitor typesVisitor(H, C, _dllExport, _stream);
p->visit(&typesVisitor, false);
+ StreamVisitor streamVistor(H, C);
+ p->visit(&streamVistor, false);
+
AsyncVisitor asyncVisitor(H, C, _dllExport);
p->visit(&asyncVisitor, false);
@@ -483,12 +522,6 @@ Slice::Gen::generate(const UnitPtr& p)
ObjectVisitor objectVisitor(H, C, _dllExport, _stream);
p->visit(&objectVisitor, false);
- if(_stream)
- {
- StreamVisitor streamVistor(H, C);
- p->visit(&streamVistor, false);
- }
-
//
// We need to delay generating the template after the proxy
// definition, because __completed calls the begin_ method in the
@@ -628,6 +661,7 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
ExceptionPtr base = p->base();
DataMemberList dataMembers = p->dataMembers();
DataMemberList allDataMembers = p->allDataMembers();
+ bool hasDefaultValues = p->hasDefaultValues();
DataMemberList::const_iterator q;
vector<string> params;
@@ -643,7 +677,7 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
for(q = allDataMembers.begin(); q != allDataMembers.end(); ++q)
{
- string typeName = inputTypeToString((*q)->type(), (*q)->getMetaData(), _useWstring);
+ string typeName = inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring);
allTypes.push_back(typeName);
allParamDecls.push_back(typeName + " __ice_" + fixKwd((*q)->name()));
}
@@ -681,7 +715,7 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
H << "const char*" << "int";
}
H << epar;
- if(!p->isLocal() && !p->hasDefaultValues())
+ if(!p->isLocal() && !hasDefaultValues)
{
H << " {}";
}
@@ -721,7 +755,7 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
C << sb;
C << eb;
}
- else if(p->hasDefaultValues())
+ else if(hasDefaultValues)
{
C << sp << nl << scoped.substr(2) << "::" << name << "() :";
C.inc();
@@ -837,151 +871,157 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
string name = fixKwd(p->name());
string scope = fixKwd(p->scope());
string scoped = fixKwd(p->scoped());
- DataMemberList dataMembers = p->dataMembers();
- DataMemberList::const_iterator q;
-
string factoryName;
if(!p->isLocal())
{
ExceptionPtr base = p->base();
+ bool basePreserved = p->inheritsMetaData("preserve-slice");
+ bool preserved = basePreserved || p->hasMetaData("preserve-slice");
H << sp << nl << "virtual void __write(::IceInternal::BasicStream*) const;";
- H << nl << "virtual void __read(::IceInternal::BasicStream*, bool);";
+ H << nl << "virtual void __writeImpl(::IceInternal::BasicStream*) const;";
+ H << nl << "virtual void __read(::IceInternal::BasicStream*);";
+ H << nl << "virtual void __readImpl(::IceInternal::BasicStream*);";
- H.zeroIndent();
- H << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- H << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- H.restoreIndent();
H << nl << "virtual void __write(const ::Ice::OutputStreamPtr&) const;";
- H << nl << "virtual void __read(const ::Ice::InputStreamPtr&, bool);";
- H.zeroIndent();
- H << nl << "#endif";
- H.restoreIndent();
-
+ H << nl << "virtual void __read(const ::Ice::InputStreamPtr&);";
+ if(_stream)
+ {
+ H << nl << "virtual void __writeImpl(const ::Ice::OutputStreamPtr&) const;";
+ H << nl << "virtual void __readImpl(const ::Ice::InputStreamPtr&);";
+ }
+
C << sp << nl << "void" << nl << scoped.substr(2) << "::__write(::IceInternal::BasicStream* __os) const";
C << sb;
- C << nl << "__os->write(::std::string(\"" << p->scoped() << "\"), false);";
- C << nl << "__os->startWriteSlice();";
- for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
+ if(preserved)
{
- writeMarshalUnmarshalCode(C, (*q)->type(), fixKwd((*q)->name()), true, "", true, (*q)->getMetaData());
+ C << nl << "__os->startWriteException(__slicedData);";
}
+ else
+ {
+ C << nl << "__os->startWriteException(0);";
+ }
+ C << nl << "__writeImpl(__os);";
+ C << nl << "__os->endWriteException();";
+ C << eb;
+
+ C << sp << nl << "void" << nl << scoped.substr(2) << "::__writeImpl(::IceInternal::BasicStream* __os) const";
+ C << sb;
+ C << nl << "__os->startWriteSlice(\"" << p->scoped() << "\", " << (!base ? "true" : "false") << ");";
+ writeMarshalUnmarshalDataMembers(C, p->dataMembers(), p->orderedOptionalDataMembers(), true);
C << nl << "__os->endWriteSlice();";
if(base)
{
- emitUpcall(base, "::__write(__os);");
+ emitUpcall(base, "::__writeImpl(__os);");
}
C << eb;
- C << sp << nl << "void" << nl << scoped.substr(2) << "::__read(::IceInternal::BasicStream* __is, bool __rid)";
- C << sb;
- C << nl << "if(__rid)";
+ C << sp << nl << "void" << nl << scoped.substr(2) << "::__read(::IceInternal::BasicStream* __is)";
C << sb;
- C << nl << "::std::string myId;";
- C << nl << "__is->read(myId, false);";
- C << eb;
- C << nl << "__is->startReadSlice();";
- for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
+ C << nl << "__is->startReadException();";
+ C << nl << "__readImpl(__is);";
+ if(preserved)
{
- writeMarshalUnmarshalCode(C, (*q)->type(), fixKwd((*q)->name()), false, "", true, (*q)->getMetaData());
+ C << nl << "__slicedData = __is->endReadException(true);";
}
+ else
+ {
+ C << nl << "__is->endReadException(false);";
+ }
+ C << eb;
+
+ C << sp << nl << "void" << nl << scoped.substr(2) << "::__readImpl(::IceInternal::BasicStream* __is)";
+ C << sb;
+ C << nl << "__is->startReadSlice();";
+ writeMarshalUnmarshalDataMembers(C, p->dataMembers(), p->orderedOptionalDataMembers(), false);
C << nl << "__is->endReadSlice();";
if(base)
{
- emitUpcall(base, "::__read(__is, true);");
+ emitUpcall(base, "::__readImpl(__is);");
}
C << eb;
if(_stream)
{
- C << sp;
- C.zeroIndent();
- C << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- C << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- C.restoreIndent();
- C << nl << "void" << nl << scoped.substr(2)
- << "::__write(const ::Ice::OutputStreamPtr& __outS) const";
+ C << sp << nl << "void" << nl << scoped.substr(2) << "::__write(const ::Ice::OutputStreamPtr& __os) const";
C << sb;
- C << nl << "__outS->write(::std::string(\"" << p->scoped() << "\"));";
- C << nl << "__outS->startSlice();";
- for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
+ if(preserved)
{
- writeStreamMarshalUnmarshalCode(C, (*q)->type(), (*q)->name(), true, "", (*q)->getMetaData(),
- _useWstring);
+ C << nl << "__os->startException(__slicedData);";
}
- C << nl << "__outS->endSlice();";
- if(base)
+ else
{
- emitUpcall(base, "::__write(__outS);");
+ C << nl << "__os->startException(0);";
}
+ C << nl << "__writeImpl(__os);";
+ C << nl << "__os->endException();";
C << eb;
- C << sp << nl << "void" << nl << scoped.substr(2)
- << "::__read(const ::Ice::InputStreamPtr& __inS, bool __rid)";
- C << sb;
- C << nl << "if(__rid)";
+ C << sp << nl << "void" << nl << scoped.substr(2)
+ << "::__writeImpl(const ::Ice::OutputStreamPtr& __os) const";
C << sb;
- C << nl << "std::string s;";
- C << nl << "__inS->read(s);";
+ C << nl << "__os->startSlice(\"" << p->scoped() << "\", " << (!base ? "true" : "false") << ");";
+ writeMarshalUnmarshalDataMembers(C, p->dataMembers(), p->orderedOptionalDataMembers(), true);
+ C << nl << "__os->endSlice();";
+ if(base)
+ {
+ emitUpcall(base, "::__writeImpl(__os);");
+ }
C << eb;
- C << nl << "__inS->startSlice();";
- for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
+
+ C << sp << nl << "void" << nl << scoped.substr(2) << "::__read(const ::Ice::InputStreamPtr& __is)";
+ C << sb;
+ C << nl << "__is->startException();";
+ C << nl << "__readImpl(__is);";
+ if(preserved)
+ {
+ C << nl << "__slicedData = __is->endException(true);";
+ }
+ else
{
- writeStreamMarshalUnmarshalCode(C, (*q)->type(), (*q)->name(), false, "", (*q)->getMetaData(),
- _useWstring);
+ C << nl << "__is->endException(false);";
}
- C << nl << "__inS->endSlice();";
+ C << eb;
+
+ C << sp << nl << "void" << nl << scoped.substr(2)
+ << "::__readImpl(const ::Ice::InputStreamPtr& __is)";
+ C << sb;
+ C << nl << "__is->startSlice();";
+ writeMarshalUnmarshalDataMembers(C, p->dataMembers(), p->orderedOptionalDataMembers(), false);
+ C << nl << "__is->endSlice();";
if(base)
{
- emitUpcall(base, "::__read(__inS, true);");
+ emitUpcall(base, "::__readImpl(__is);");
}
C << eb;
- C.zeroIndent();
- C << nl << "#endif";
- C.restoreIndent();
}
else
{
//
// Emit placeholder functions to catch errors.
//
- C << sp;
- C.zeroIndent();
- C << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- C << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- C.restoreIndent();
- C << nl << "void" << nl << scoped.substr(2) << "::__write(const ::Ice::OutputStreamPtr&) const";
+ C << sp << nl << "void" << nl << scoped.substr(2) << "::__write(const ::Ice::OutputStreamPtr&) const";
C << sb;
C << nl << "Ice::MarshalException ex(__FILE__, __LINE__);";
C << nl << "ex.reason = \"exception " << scoped.substr(2) << " was not generated with stream support\";";
C << nl << "throw ex;";
C << eb;
- C << sp << nl << "void" << nl << scoped.substr(2) << "::__read(const ::Ice::InputStreamPtr&, bool)";
+ C << sp << nl << "void" << nl << scoped.substr(2) << "::__read(const ::Ice::InputStreamPtr&)";
C << sb;
C << nl << "Ice::MarshalException ex(__FILE__, __LINE__);";
C << nl << "ex.reason = \"exception " << scoped .substr(2)<< " was not generated with stream support\";";
C << nl << "throw ex;";
C << eb;
-
- C.zeroIndent();
- C << nl << "#endif";
- C.restoreIndent();
}
- if(p->usesClasses())
+ if(preserved && !basePreserved)
{
- if(!base || (base && !base->usesClasses()))
- {
- H << nl << "virtual bool __usesClasses() const;";
-
- C << sp << nl << "bool";
- C << nl << scoped.substr(2) << "::__usesClasses() const";
- C << sb;
- C << nl << "return true;";
- C << eb;
- }
+ H.zeroIndent();
+ H << sp << nl << "protected:";
+ H.restoreIndent();
+ H << sp << nl << "::Ice::SlicedDataPtr __slicedData;";
}
factoryName = "__F" + p->flattenedScope() + p->name();
@@ -989,7 +1029,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
C << sp << nl << "struct " << factoryName << " : public ::IceInternal::UserExceptionFactory";
C << sb;
C << sp << nl << "virtual void";
- C << nl << "createAndThrow()";
+ C << nl << "createAndThrow(const ::std::string&)";
C << sb;
C << nl << "throw " << scoped << "();";
C << eb;
@@ -1114,7 +1154,7 @@ Slice::Gen::TypesVisitor::visitStructStart(const StructPtr& p)
vector<string> types;
for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
- string typeName = inputTypeToString((*q)->type(), (*q)->getMetaData(), _useWstring);
+ string typeName = inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring);
types.push_back(typeName);
paramDecls.push_back(typeName + " __ice_" + (*q)->name());
}
@@ -1238,22 +1278,15 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p)
if(_stream)
{
- H.zeroIndent();
- H << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- H << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- H.restoreIndent();
- H << nl << dllExport << "void ice_write(const ::Ice::OutputStreamPtr&) const;";
- H << nl << dllExport << "void ice_read(const ::Ice::InputStreamPtr&);";
- H.zeroIndent();
- H << nl << "#endif";
- H.restoreIndent();
+ H << nl << dllExport << "void __write(const ::Ice::OutputStreamPtr&) const;";
+ H << nl << dllExport << "void __read(const ::Ice::InputStreamPtr&);";
}
C << sp << nl << "void" << nl << scoped.substr(2) << "::__write(::IceInternal::BasicStream* __os) const";
C << sb;
for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
- writeMarshalUnmarshalCode(C, (*q)->type(), fixKwd((*q)->name()), true, "", true, (*q)->getMetaData());
+ writeMarshalUnmarshalDataMember(C, *q, true);
}
C << eb;
@@ -1261,118 +1294,35 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p)
C << sb;
for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
- writeMarshalUnmarshalCode(C, (*q)->type(), fixKwd((*q)->name()), false, "", true, (*q)->getMetaData());
+ writeMarshalUnmarshalDataMember(C, *q, false);
}
C << eb;
if(_stream)
{
- C << sp;
- C.zeroIndent();
- C << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- C << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- C.restoreIndent();
- C << nl << "void" << nl << scoped.substr(2)
- << "::ice_write(const ::Ice::OutputStreamPtr& __outS) const";
+ C << sp << nl << "void" << nl << scoped.substr(2) << "::__write(const ::Ice::OutputStreamPtr& __os) const";
C << sb;
for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
- writeStreamMarshalUnmarshalCode(C, (*q)->type(), (*q)->name(), true, "", (*q)->getMetaData(),
- _useWstring);
+ C << nl << "__os->write(" << fixKwd((*q)->name()) << ");";
}
C << eb;
- C << sp << nl << "void" << nl << scoped.substr(2) << "::ice_read(const ::Ice::InputStreamPtr& __inS)";
+ C << sp << nl << "void" << nl << scoped.substr(2) << "::__read(const ::Ice::InputStreamPtr& __is)";
C << sb;
for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
- writeStreamMarshalUnmarshalCode(C, (*q)->type(), (*q)->name(), false, "", (*q)->getMetaData(),
- _useWstring);
+ C << nl << "__is->read(" << fixKwd((*q)->name()) << ");";
}
C << eb;
- C.zeroIndent();
- C << nl << "#endif";
- C.restoreIndent();
}
}
H << eb << ';';
+
if(findMetaData(p->getMetaData()) == "class")
{
H << sp << nl << "typedef ::IceUtil::Handle< " << scoped << "> " << p->name() + "Ptr;";
-
- if(!p->isLocal() && _stream)
- {
- H << sp;
- H.zeroIndent();
- H << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- H << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- H.restoreIndent();
- H << nl << "void ice_write" << p->name() << "(const ::Ice::OutputStreamPtr&, const "
- << p->name() << "Ptr&);";
- H << nl << "void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << p->name()
- << "Ptr&);";
- H.zeroIndent();
- H << nl << "#endif";
- H.restoreIndent();
-
- C << sp;
- C.zeroIndent();
- C << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- C << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- C.restoreIndent();
- C << nl << "void" << nl << scope.substr(2) << "ice_write" << p->name()
- << "(const ::Ice::OutputStreamPtr& __outS, const " << fixKwd(p->scoped() + "Ptr") << "& __v)";
- C << sb;
- C << nl << "__v->ice_write(__outS);";
- C << eb;
-
- C << sp << nl << "void" << nl << scope.substr(2) << "ice_read" << p->name()
- << "(const ::Ice::InputStreamPtr& __inS, " << fixKwd(p->scoped() + "Ptr") << "& __v)";
- C << sb;
- C << nl << "__v->ice_read(__inS);";
- C << eb;
- C.zeroIndent();
- C << nl << "#endif";
- C.restoreIndent();
- }
- }
- else
- {
- if(!p->isLocal() && _stream)
- {
- H << sp;
- H.zeroIndent();
- H << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- H << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- H.restoreIndent();
- H << nl << dllExport << "void ice_write" << p->name() << "(const ::Ice::OutputStreamPtr&, const "
- << name << "&);";
- H << nl << dllExport << "void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << name << "&);";
- H.zeroIndent();
- H << nl << "#endif";
- H.restoreIndent();
-
- C << sp;
- C.zeroIndent();
- C << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- C << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- C.restoreIndent();
- C << nl << "void" << nl << scope.substr(2) << "ice_write" << p->name()
- << "(const ::Ice::OutputStreamPtr& __outS, const " << scoped << "& __v)";
- C << sb;
- C << nl << "__v.ice_write(__outS);";
- C << eb;
-
- C << sp << nl << "void" << nl << scope.substr(2) << "ice_read" << p->name()
- << "(const ::Ice::InputStreamPtr& __inS, " << scoped << "& __v)";
- C << sb;
- C << nl << "__v.ice_read(__inS);";
- C << eb;
- C.zeroIndent();
- C << nl << "#endif";
- C.restoreIndent();
- }
}
_useWstring = resetUseWstring(_useWstringHist);
@@ -1383,7 +1333,8 @@ Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p)
{
string name = fixKwd(p->name());
TypePtr type = p->type();
- if(p->container() != 0 && (StructPtr::dynamicCast(p->container()) || ExceptionPtr::dynamicCast(p->container())) &&
+ if(p->container() != 0 &&
+ (StructPtr::dynamicCast(p->container()) || ExceptionPtr::dynamicCast(p->container())) &&
SequencePtr::dynamicCast(type))
{
SequencePtr s = SequencePtr::dynamicCast(type);
@@ -1402,8 +1353,7 @@ Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p)
}
}
- string s = typeToString(p->type(), p->getMetaData(), _useWstring);
- H << nl << s << ' ' << name << ';';
+ H << nl << typeToString(p->type(), p->optional(), p->getMetaData(), _useWstring) << ' ' << name << ';';
}
void
@@ -1428,231 +1378,6 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p)
H << nl << "typedef ::std::vector<" << (s[0] == ':' ? " " : "") << s << "> " << name << ';';
}
}
-
- BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
- if(!p->isLocal())
- {
- string scoped = fixKwd(p->scoped());
- string scope = fixKwd(p->scope());
-
- if(protobuf || !seqType.empty())
- {
- string typeName = name;
- string scopedName = scoped;
- if(protobuf && !seqType.empty())
- {
- typeName = seqType;
- scopedName = seqType;
- }
- H << nl << _dllExport << "void __write" << name << "(::IceInternal::BasicStream*, const "
- << typeName << "&);";
- H << nl << _dllExport << "void __read" << name << "(::IceInternal::BasicStream*, "
- << typeName << "&);";
-
- if(_stream)
- {
- H.zeroIndent();
- H << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- H << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- H.restoreIndent();
- H << nl << _dllExport << "ICE_DEPRECATED_API void ice_write" << p->name() << "(const ::Ice::OutputStreamPtr&, const "
- << typeName << "&);";
- H << nl << _dllExport << "ICE_DEPRECATED_API void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << typeName
- << "&);";
- H.zeroIndent();
- H << nl << "#endif";
- H.restoreIndent();
- }
-
- C << sp << nl << "void" << nl << scope.substr(2) << "__write" << name <<
- "(::IceInternal::BasicStream* __os, const " << scopedName << "& v)";
- C << sb;
- if(protobuf)
- {
- C << nl << "std::vector< ::Ice::Byte> data(v.ByteSize());";
- C << nl << "if(!v.IsInitialized())";
- C << sb;
- C << nl << "throw ::Ice::MarshalException(__FILE__, __LINE__, \"type not fully initialized: \" + v.InitializationErrorString());";
- C << eb;
- C << nl << "if(!v.SerializeToArray(&data[0], data.size()))";
- C << sb;
- C << nl << "throw ::Ice::MarshalException(__FILE__, __LINE__, \"SerializeToArray failed\");";
- C << eb;
- C << nl << "__os->write(&data[0], &data[0] + data.size());";
- }
- else
- {
- C << nl << "::Ice::Int size = static_cast< ::Ice::Int>(v.size());";
- C << nl << "__os->writeSize(size);";
- C << nl << "for(" << name << "::const_iterator p = v.begin(); p != v.end(); ++p)";
- C << sb;
- writeMarshalUnmarshalCode(C, type, "(*p)", true);
- C << eb;
- }
- C << eb;
-
- C << sp << nl << "void" << nl << scope.substr(2) << "__read" << name
- << "(::IceInternal::BasicStream* __is, " << scopedName << "& v)";
- C << sb;
- if(protobuf)
- {
- C << nl << "::std::pair<const ::Ice::Byte*, const ::Ice::Byte*> data;";
- C << nl << "__is->read(data);";
- C << nl << "if(!v.ParseFromArray(data.first, data.second - data.first))";
- C << sb;
- C << nl << "throw ::Ice::MarshalException(__FILE__, __LINE__, \"ParseFromArray failed\");";
- C << eb;
- }
- else
- {
- C << nl << "::Ice::Int sz;";
- C << nl << "__is->readAndCheckSeqSize(" << type->minWireSize() << ", sz);";
- C << nl << name << "(sz).swap(v);";
- C << nl << "for(" << name << "::iterator p = v.begin(); p != v.end(); ++p)";
- C << sb;
- writeMarshalUnmarshalCode(C, type, "(*p)", false);
- C << eb;
- }
- C << eb;
-
- if(_stream)
- {
- C << sp;
- C.zeroIndent();
- C << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- C << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- C.restoreIndent();
- C << nl << "void" << nl << scope.substr(2) << "ice_write" << p->name()
- << "(const ::Ice::OutputStreamPtr& __outS, const " << scopedName << "& v)";
- C << sb;
- if(protobuf)
- {
- C << nl << "std::vector< ::Ice::Byte> data(v.ByteSize());";
- C << nl << "if(!v.IsInitialized())";
- C << sb;
- C << nl << "throw ::Ice::MarshalException(__FILE__, __LINE__, \"type not fully initialized: \" + v.InitializationErrorString());";
- C << eb;
- C << nl << "v.SerializeToArray(&data[0], data.size());";
-
- C << nl << "__outS->write(data);";
- }
- else
- {
- C << nl << "__outS->writeSize(::Ice::Int(v.size()));";
- C << nl << scopedName << "::const_iterator p;";
- C << nl << "for(p = v.begin(); p != v.end(); ++p)";
- C << sb;
- writeStreamMarshalUnmarshalCode(C, type, "(*p)", true, "", StringList(), _useWstring);
- C << eb;
- }
- C << eb;
-
- C << sp << nl << "void" << nl << scope.substr(2) << "ice_read" << p->name()
- << "(const ::Ice::InputStreamPtr& __inS, " << scopedName << "& v)";
- C << sb;
- if(protobuf)
- {
- C << nl << "std::pair<const ::Ice::Byte*, const ::Ice::Byte*> data;";
- C << nl << "__inS->readByteSeq(data);";
- C << nl << "if(!v.ParseFromArray(data.first, data.second - data.first))";
- C << sb;
- C << nl << "throw ::Ice::MarshalException(__FILE__, __LINE__, \"ParseFromArray failed\");";
- C << eb;
- }
- else
- {
- C << nl << "::Ice::Int sz = __inS->readAndCheckSeqSize(" << type->minWireSize() << ");";
- C << nl << scopedName << "(sz).swap(v);";
- C << nl << scopedName << "::iterator p;";
- C << nl << "for(p = v.begin(); p != v.end(); ++p)";
- C << sb;
- writeStreamMarshalUnmarshalCode(C, type, "(*p)", false, "", StringList(), _useWstring);
- C << eb;
- }
- C << eb;
- C.zeroIndent();
- C << nl << "#endif";
- C.restoreIndent();
- }
- }
- else if(!builtin || builtin->kind() == Builtin::KindObject || builtin->kind() == Builtin::KindObjectProxy)
- {
- H << nl << _dllExport << "void __write" << name << "(::IceInternal::BasicStream*, const " << s
- << "*, const " << s << "*);";
- H << nl << _dllExport << "void __read" << name << "(::IceInternal::BasicStream*, " << name << "&);";
-
- if(_stream)
- {
- H.zeroIndent();
- H << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- H << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- H.restoreIndent();
- H << nl << _dllExport << "ICE_DEPRECATED_API void ice_write" << p->name() << "(const ::Ice::OutputStreamPtr&, const "
- << name << "&);";
- H << nl << _dllExport << "ICE_DEPRECATED_API void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << name
- << "&);";
- H.zeroIndent();
- H << nl << "#endif";
- H.restoreIndent();
- }
-
- C << sp << nl << "void" << nl << scope.substr(2) << "__write" << name
- << "(::IceInternal::BasicStream* __os, const " << s << "* begin, const " << s << "* end)";
- C << sb;
- C << nl << "::Ice::Int size = static_cast< ::Ice::Int>(end - begin);";
- C << nl << "__os->writeSize(size);";
- C << nl << "for(int i = 0; i < size; ++i)";
- C << sb;
- writeMarshalUnmarshalCode(C, type, "begin[i]", true);
- C << eb;
- C << eb;
-
- C << sp << nl << "void" << nl << scope.substr(2) << "__read" << name
- << "(::IceInternal::BasicStream* __is, " << scoped << "& v)";
- C << sb;
- C << nl << "::Ice::Int sz;";
- C << nl << "__is->readAndCheckSeqSize(" << type->minWireSize() << ", sz);";
- C << nl << "v.resize(sz);";
- C << nl << "for(int i = 0; i < sz; ++i)";
- C << sb;
- writeMarshalUnmarshalCode(C, type, "v[i]", false);
- C << eb;
- C << eb;
-
- if(_stream)
- {
- C << sp;
- C.zeroIndent();
- C << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- C << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- C.restoreIndent();
- C << nl << "void" << nl << scope.substr(2) << "ice_write" << p->name()
- << "(const ::Ice::OutputStreamPtr& __outS, const " << scoped << "& v)";
- C << sb;
- C << nl << "__outS->writeSize(::Ice::Int(v.size()));";
- C << nl << scoped << "::const_iterator p;";
- C << nl << "for(p = v.begin(); p != v.end(); ++p)";
- C << sb;
- writeStreamMarshalUnmarshalCode(C, type, "(*p)", true, "", StringList(), _useWstring);
- C << eb;
- C << eb;
-
- C << sp << nl << "void" << nl << scope.substr(2) << "ice_read" << p->name()
- << "(const ::Ice::InputStreamPtr& __inS, " << scoped << "& v)";
- C << sb;
- C << nl << "::Ice::Int sz = __inS->readAndCheckSeqSize(" << type->minWireSize() << ");";
- C << nl << "v.resize(sz);";
- C << nl << "for(int i = 0; i < sz; ++i)";
- C << sb;
- writeStreamMarshalUnmarshalCode(C, type, "v[i]", false, "", StringList(), _useWstring);
- C << eb;
- C << eb;
- C.zeroIndent();
- C << nl << "#endif";
- C.restoreIndent();
- }
- }
- }
}
void
@@ -1684,92 +1409,6 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
}
string vs = typeToString(valueType, p->valueMetaData(), _useWstring);
H << sp << nl << "typedef ::std::map<" << ks << ", " << vs << "> " << name << ';';
-
- if(!p->isLocal())
- {
- string scoped = fixKwd(p->scoped());
- string scope = fixKwd(p->scope());
-
- H << nl << _dllExport << "void __write" << name << "(::IceInternal::BasicStream*, const " << name << "&);";
- H << nl << _dllExport << "void __read" << name << "(::IceInternal::BasicStream*, " << name << "&);";
-
- if(_stream)
- {
- H.zeroIndent();
- H << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- H << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- H.restoreIndent();
- H << nl << _dllExport << "ICE_DEPRECATED_API void ice_write" << p->name() << "(const ::Ice::OutputStreamPtr&, const " << name
- << "&);";
- H << nl << _dllExport << "ICE_DEPRECATED_API void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << name << "&);";
- H.zeroIndent();
- H << nl << "#endif";
- H.restoreIndent();
- }
-
- C << sp << nl << "void" << nl << scope.substr(2) << "__write" << name
- << "(::IceInternal::BasicStream* __os, const " << scoped << "& v)";
- C << sb;
- C << nl << "__os->writeSize(::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 << nl << "void" << nl << scope.substr(2) << "__read" << name
- << "(::IceInternal::BasicStream* __is, " << scoped << "& v)";
- C << sb;
- C << nl << "::Ice::Int sz;";
- C << nl << "__is->readSize(sz);";
- C << nl << "while(sz--)";
- C << sb;
- C << nl << "::std::pair<const " << ks << ", " << vs << "> pair;";
- const string pf = string("const_cast<") + ks + "&>(pair.first)";
- writeMarshalUnmarshalCode(C, keyType, pf, false);
- C << nl << scoped << "::iterator __i = v.insert(v.end(), pair);";
- writeMarshalUnmarshalCode(C, valueType, "__i->second", false);
- C << eb;
- C << eb;
-
- if(_stream)
- {
- C << sp;
- C.zeroIndent();
- C << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- C << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- C.restoreIndent();
- C << nl << "void" << nl << scope.substr(2) << "ice_write" << p->name()
- << "(const ::Ice::OutputStreamPtr& __outS, const " << scoped << "& v)";
- C << sb;
- C << nl << "__outS->writeSize(::Ice::Int(v.size()));";
- C << nl << scoped << "::const_iterator p;";
- C << nl << "for(p = v.begin(); p != v.end(); ++p)";
- C << sb;
- writeStreamMarshalUnmarshalCode(C, keyType, "p->first", true, "", p->keyMetaData(), _useWstring);
- writeStreamMarshalUnmarshalCode(C, valueType, "p->second", true, "", p->valueMetaData(), _useWstring);
- C << eb;
- C << eb;
-
- C << sp << nl << "void" << nl << scope.substr(2) << "ice_read" << p->name()
- << "(const ::Ice::InputStreamPtr& __inS, " << scoped << "& v)";
- C << sb;
- C << nl << "::Ice::Int sz = __inS->readSize();";
- C << nl << "while(sz--)";
- C << sb;
- C << nl << "::std::pair<const " << ks << ", " << vs << "> pair;";
- writeStreamMarshalUnmarshalCode(C, keyType, pf, false, "", p->keyMetaData(), _useWstring);
- C << nl << scoped << "::iterator __i = v.insert(v.end(), pair);";
- writeStreamMarshalUnmarshalCode(C, valueType, "__i->second", false, "", p->valueMetaData(), _useWstring);
- C << eb;
- C << eb;
- C.zeroIndent();
- C << nl << "#endif";
- C.restoreIndent();
- }
- }
}
void
@@ -1789,89 +1428,6 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p)
}
}
H << eb << ';';
-
- string scoped = fixKwd(p->scoped());
- string scope = fixKwd(p->scope());
-
- if(!p->isLocal())
- {
- size_t sz = enumerators.size();
- assert(sz <= 0x7fffffff); // 64-bit enums are not supported
-
- H << sp << nl << _dllExport << "void __write(::IceInternal::BasicStream*, " << name << ");";
- H << nl << _dllExport << "void __read(::IceInternal::BasicStream*, " << name << "&);";
-
- if(_stream)
- {
- H.zeroIndent();
- H << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- H << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- H << nl << _dllExport << "ICE_DEPRECATED_API void ice_write" << p->name()
- << "(const ::Ice::OutputStreamPtr&, " << name << ");";
- H << nl << _dllExport << "ICE_DEPRECATED_API void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << name << "&);";
- H.zeroIndent();
- H << nl << "#endif";
- H.restoreIndent();
- }
-
- C << sp << nl << "void" << nl << scope.substr(2) << "__write(::IceInternal::BasicStream* __os, " << scoped
- << " v)";
- C << sb;
- if(sz <= 0x7f)
- {
- C << nl << "__os->write(static_cast< ::Ice::Byte>(v), " << sz << ");";
- }
- else if(sz <= 0x7fff)
- {
- C << nl << "__os->write(static_cast< ::Ice::Short>(v), " << sz << ");";
- }
- else
- {
- C << nl << "__os->write(static_cast< ::Ice::Int>(v), " << sz << ");";
- }
- C << eb;
-
- C << sp << nl << "void" << nl << scope.substr(2) << "__read(::IceInternal::BasicStream* __is, " << scoped
- << "& v)";
- C << sb;
- if(sz <= 0x7f)
- {
- C << nl << "::Ice::Byte val;";
- }
- else if(sz <= 0x7fff)
- {
- C << nl << "::Ice::Short val;";
- }
- else
- {
- C << nl << "::Ice::Int val;";
- }
- C << nl << "__is->read(val, " << sz << ");";
- C << nl << "v = static_cast< " << scoped << ">(val);";
- C << eb;
-
- if(_stream)
- {
- C << sp;
- C.zeroIndent();
- C << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- C << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- C << nl << "void" << nl << scope.substr(2) << "ice_write" << p->name()
- << "(const ::Ice::OutputStreamPtr& __outS, " << scoped << " v)";
- C << sb;
- C << nl << "__outS->write(v);";
- C << eb;
-
- C << sp << nl << "void" << nl << scope.substr(2) << "ice_read" << p->name()
- << "(const ::Ice::InputStreamPtr& __inS, " << scoped << "& v)";
- C << sb;
- C << nl << "__inS->read(v);";
- C << eb;
- C.zeroIndent();
- C << nl << "#endif";
- C.restoreIndent();
- }
- }
}
void
@@ -1958,6 +1514,8 @@ Slice::Gen::ProxyDeclVisitor::visitClassDecl(const ClassDeclPtr& p)
string scoped = fixKwd(p->scoped());
H << sp << nl << "class " << name << ';';
+ H << nl << _dllExport << "void __read(::IceInternal::BasicStream*, ::IceInternal::ProxyHandle< ::IceProxy"
+ << scoped << ">&);";
H << nl << _dllExport << "::IceProxy::Ice::Object* upCast(::IceProxy" << scoped << "*);";
}
@@ -2067,6 +1625,23 @@ Slice::Gen::ProxyVisitor::visitClassDefStart(const ClassDefPtr& p)
<< "::IceProxy::Ice::Object* ::IceProxy" << scope << "upCast(::IceProxy" << scoped
<< "* p) { return p; }";
+ C << sp;
+ C << nl << "void" << nl << "::IceProxy" << scope << "__read(::IceInternal::BasicStream* __is, "
+ << "::IceInternal::ProxyHandle< ::IceProxy" << scoped << ">& v)";
+ C << sb;
+ C << nl << "::Ice::ObjectPrx proxy;";
+ C << nl << "__is->read(proxy);";
+ 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;
}
@@ -2106,7 +1681,7 @@ Slice::Gen::ProxyVisitor::visitClassDefEnd(const ClassDefPtr& p)
// No facet!
//
- H << nl << nl << "::IceInternal::ProxyHandle<" << name << "> ice_adapterId(const std::string& __id) const";
+ H << nl << nl << "::IceInternal::ProxyHandle<" << name << "> ice_adapterId(const ::std::string& __id) const";
H << sb;
H.dec();
H << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERFIX
@@ -2369,7 +1944,7 @@ Slice::Gen::ProxyVisitor::visitClassDefEnd(const ClassDefPtr& p)
H.inc();
H << eb;
- H << nl << nl << "::IceInternal::ProxyHandle<" << name << "> ice_connectionId(const std::string& __id) const";
+ H << nl << nl << "::IceInternal::ProxyHandle<" << name << "> ice_connectionId(const ::std::string& __id) const";
H << sb;
H.dec();
H << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERFIX
@@ -2385,6 +1960,23 @@ Slice::Gen::ProxyVisitor::visitClassDefEnd(const ClassDefPtr& p)
H.inc();
H << eb;
+ H << nl << nl << "::IceInternal::ProxyHandle<" << name
+ << "> ice_encodingVersion(const ::Ice::EncodingVersion& __v) const";
+ H << sb;
+ H.dec();
+ H << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERFIX
+ H.inc();
+ H << nl << "typedef ::IceProxy::Ice::Object _Base;";
+ H << nl << "return dynamic_cast<" << name << "*>(_Base::ice_encodingVersion(__v).get());";
+ H.dec();
+ H << nl << "#else";
+ H.inc();
+ H << nl << "return dynamic_cast<" << name << "*>(::IceProxy::Ice::Object::ice_encodingVersion(__v).get());";
+ H.dec();
+ H << nl << "#endif";
+ H.inc();
+ H << eb;
+
H << nl << nl << _dllExport << "static const ::std::string& ice_staticId();";
H.dec();
@@ -2428,8 +2020,9 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
string scope = fixKwd(p->scope());
TypePtr ret = p->returnType();
- string retS = returnTypeToString(ret, p->getMetaData(), _useWstring | TypeContextAMIEnd);
- string retSEndAMI = returnTypeToString(ret, p->getMetaData(), _useWstring | TypeContextAMIPrivateEnd);
+ bool retIsOpt = p->returnIsOptional();
+ string retS = returnTypeToString(ret, retIsOpt, p->getMetaData(), _useWstring | TypeContextAMIEnd);
+ string retSEndAMI = returnTypeToString(ret, retIsOpt, p->getMetaData(), _useWstring | TypeContextAMIPrivateEnd);
ContainerPtr container = p->container();
ClassDefPtr cl = ClassDefPtr::dynamicCast(container);
@@ -2460,12 +2053,13 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
string typeStringEndAMI;
if((*q)->isOutParam())
{
- typeString = outputTypeToString((*q)->type(), metaData, _useWstring | TypeContextAMIEnd);
- typeStringEndAMI = outputTypeToString((*q)->type(), metaData, _useWstring | TypeContextAMIPrivateEnd);
+ typeString = outputTypeToString((*q)->type(), (*q)->optional(), metaData, _useWstring | TypeContextAMIEnd);
+ typeStringEndAMI = outputTypeToString((*q)->type(), (*q)->optional(), metaData,
+ _useWstring | TypeContextAMIPrivateEnd);
}
else
{
- typeString = inputTypeToString((*q)->type(), metaData, _useWstring);
+ typeString = inputTypeToString((*q)->type(), (*q)->optional(), metaData, _useWstring);
}
params.push_back(typeString);
@@ -2501,7 +2095,8 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
bool generatePrivateEnd = retS != retSEndAMI || outParamsDeclAMI != outParamsDeclEndAMI;
if(ret && generatePrivateEnd)
{
- string typeStringEndAMI = outputTypeToString(ret, p->getMetaData(), _useWstring | TypeContextAMIPrivateEnd);
+ string typeStringEndAMI = outputTypeToString(ret, p->returnIsOptional(), p->getMetaData(),
+ _useWstring | TypeContextAMIPrivateEnd);
outParamsDeclEndAMI.push_back(typeStringEndAMI + ' ' + "__ret");
}
@@ -2652,13 +2247,21 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
C << nl << "try";
C << sb;
C << nl << "__result->__prepare(" << flatName << ", " << operationModeToString(p->sendMode()) << ", __ctx);";
- C << nl << "::IceInternal::BasicStream* __os = __result->__getOs();";
- writeMarshalCode(C, inParams, 0, StringList(), TypeContextInParam);
- if(p->sendsClasses())
+ if(inParams.empty())
{
- C << nl << "__os->writePendingObjects();";
+ C << nl << "__result->__writeEmptyParams();";
+ }
+ else
+ {
+ C << nl << "::IceInternal::BasicStream* __os = __result->__startWriteParams();";
+ FormatType format = p->format();
+ if(p->sendsClasses() && format != DefaultFormat)
+ {
+ C << nl << "__os->format(" << formatTypeToString(format) << ");";
+ }
+ writeMarshalCode(C, inParams, 0, TypeContextInParam);
+ C << nl << "__result->__endWriteParams();";
}
- C << nl << "__os->endWriteEncaps();";
C << nl << "__result->__send(true);";
C << eb;
C << nl << "catch(const ::Ice::LocalException& __ex)";
@@ -2681,7 +2284,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
// access violations errors with the test/Ice/slicing/objects test on VC9
// and Windows 64 bits when compiled with optimization (see bug 4400).
//
- writeAllocateCode(C, ParamDeclList(), ret, p->getMetaData(), _useWstring | TypeContextAMIEnd);
+ writeAllocateCode(C, ParamDeclList(), p, _useWstring | TypeContextAMIEnd);
C << nl << "if(!__result->__wait())";
C << sb;
@@ -2714,20 +2317,15 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
C << nl << "throw ::Ice::UnknownUserException(__FILE__, __LINE__, __ex.ice_name());";
C << eb;
C << eb;
- C << nl << "::IceInternal::BasicStream* __is = __result->__getIs();";
if(ret || !outParams.empty())
{
- C << nl << "__is->startReadEncaps();";
- writeUnmarshalCode(C, outParams, ret, p->getMetaData(), _useWstring | TypeContextAMIEnd);
- if(p->returnsClasses())
- {
- C << nl << "__is->readPendingObjects();";
- }
- C << nl << "__is->endReadEncaps();";
+ C << nl << "::IceInternal::BasicStream* __is = __result->__startReadParams();";
+ writeUnmarshalCode(C, outParams, p, _useWstring | TypeContextAMIEnd);
+ C << nl << "__result->__endReadParams();";
}
else
{
- C << nl << "__is->skipEmptyEncaps();";
+ C << nl << "__result->__readEmptyParams();";
}
if(ret)
{
@@ -2779,20 +2377,15 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
C << nl << "throw ::Ice::UnknownUserException(__FILE__, __LINE__, __ex.ice_name());";
C << eb;
C << eb;
- C << nl << "::IceInternal::BasicStream* __is = __result->__getIs();";
if(ret || !outParams.empty())
{
- C << nl << "__is->startReadEncaps();";
- writeUnmarshalCode(C, outParams, ret, p->getMetaData(), _useWstring | TypeContextAMIPrivateEnd);
- if(p->returnsClasses())
- {
- C << nl << "__is->readPendingObjects();";
- }
- C << nl << "__is->endReadEncaps();";
+ C << nl << "::IceInternal::BasicStream* __is = __result->__startReadParams();";
+ writeUnmarshalCode(C, outParams, p, _useWstring | TypeContextAMIPrivateEnd);
+ C << nl << "__result->__endReadParams();";
}
else
{
- C << nl << "__is->skipEmptyEncaps();";
+ C << nl << "__result->__readEmptyParams();";
}
C << eb;
}
@@ -3022,7 +2615,7 @@ Slice::Gen::DelegateVisitor::visitOperation(const OperationPtr& p)
string name = fixKwd(p->name());
TypePtr ret = p->returnType();
- string retS = returnTypeToString(ret, p->getMetaData(), _useWstring);
+ string retS = returnTypeToString(ret, p->returnIsOptional(), p->getMetaData(), _useWstring);
vector<string> params;
@@ -3030,24 +2623,15 @@ Slice::Gen::DelegateVisitor::visitOperation(const OperationPtr& p)
for(ParamDeclList::const_iterator q = paramList.begin(); q != paramList.end(); ++q)
{
StringList metaData = (*q)->getMetaData();
-#if defined(__SUNPRO_CC) && (__SUNPRO_CC==0x550)
- //
- // Work around for Sun CC 5.5 bug #4853566
- //
string typeString;
if((*q)->isOutParam())
{
- typeString = outputTypeToString((*q)->type(), metaData, _useWstring);
+ typeString = outputTypeToString((*q)->type(), (*q)->optional(), metaData, _useWstring);
}
else
{
- typeString = inputTypeToString((*q)->type(), metaData, _useWstring);
+ typeString = inputTypeToString((*q)->type(), (*q)->optional(), metaData, _useWstring);
}
-#else
- string typeString = (*q)->isOutParam() ? outputTypeToString((*q)->type(), metaData, _useWstring)
- : inputTypeToString((*q)->type(), metaData, _useWstring);
-#endif
-
params.push_back(typeString);
}
@@ -3162,7 +2746,7 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p)
string scoped = fixKwd(p->scoped());
TypePtr ret = p->returnType();
- string retS = returnTypeToString(ret, p->getMetaData(), _useWstring);
+ string retS = returnTypeToString(ret, p->returnIsOptional(), p->getMetaData(), _useWstring);
vector<string> params;
vector<string> paramsDecl;
@@ -3180,12 +2764,12 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p)
if(isOutParam)
{
outParams.push_back(*q);
- typeString = outputTypeToString(type, metaData, _useWstring);
+ typeString = outputTypeToString(type, (*q)->optional(), metaData, _useWstring);
}
else
{
inParams.push_back(*q);
- typeString = inputTypeToString(type, metaData, _useWstring);
+ typeString = inputTypeToString(type, (*q)->optional(), metaData, _useWstring);
}
params.push_back(typeString);
@@ -3202,16 +2786,25 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p)
C << sb;
C << nl << "::IceInternal::Outgoing __og(__handler.get(), " << flatName << ", "
<< operationModeToString(p->sendMode()) << ", __context);";
- if(!inParams.empty())
+ if(inParams.empty())
+ {
+ C << nl << "__og.writeEmptyParams();";
+ }
+ else
{
C << nl << "try";
C << sb;
- C << nl << "::IceInternal::BasicStream* __os = __og.os();";
- writeMarshalCode(C, inParams, 0, StringList(), TypeContextInParam);
+ C << nl<< "::IceInternal::BasicStream* __os = __og.startWriteParams();";
if(p->sendsClasses())
{
- C << nl << "__os->writePendingObjects();";
+ FormatType format = p->format();
+ if(format != DefaultFormat)
+ {
+ C << nl << "__os->format(" << formatTypeToString(format) << ");";
+ }
}
+ writeMarshalCode(C, inParams, 0, TypeContextInParam);
+ C << nl << "__og.endWriteParams();";
C << eb;
C << nl << "catch(const ::Ice::LocalException& __ex)";
C << sb;
@@ -3225,10 +2818,10 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p)
// Declare the return __ret variable at the top-level scope to
// enable NRVO with GCC (see also bug #3619).
//
- writeAllocateCode(C, ParamDeclList(), ret, p->getMetaData(), _useWstring);
+ writeAllocateCode(C, ParamDeclList(), p, _useWstring);
if(!p->returnsData())
{
- C << nl << "if(!__og.is()->b.empty())";
+ C << nl << "if(__og.hasResponse())";
C << sb;
}
C << nl << "try";
@@ -3289,29 +2882,15 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p)
C << eb;
C << eb;
- for(ParamDeclList::const_iterator opi = outParams.begin(); opi != outParams.end(); ++opi)
- {
- StructPtr st = StructPtr::dynamicCast((*opi)->type());
- if(st && findMetaData(st->getMetaData()) == "class")
- {
- C << nl << fixKwd((*opi)->name()) << " = new " << fixKwd(st->scoped()) << ";";
- }
- }
-
if(ret || !outParams.empty())
{
- C << nl << "::IceInternal::BasicStream* __is = __og.is();";
- C << nl << "__is->startReadEncaps();";
- writeUnmarshalCode(C, outParams, ret, p->getMetaData());
- if(p->returnsClasses())
- {
- C << nl << "__is->readPendingObjects();";
- }
- C << nl << "__is->endReadEncaps();";
+ C << nl << "::IceInternal::BasicStream* __is = __og.startReadParams();";
+ writeUnmarshalCode(C, outParams, p);
+ C << nl << "__og.endReadParams();";
}
else
{
- C << nl << "__og.is()->skipEmptyEncaps();";
+ C << nl << "__og.readEmptyParams();";
}
if(ret)
@@ -3436,7 +3015,7 @@ Slice::Gen::DelegateDVisitor::visitOperation(const OperationPtr& p)
string scoped = fixKwd(p->scoped());
TypePtr ret = p->returnType();
- string retS = returnTypeToString(ret, p->getMetaData(), _useWstring);
+ string retS = returnTypeToString(ret, p->returnIsOptional(), p->getMetaData(), _useWstring);
vector<string> params;
vector<string> paramsDecl;
@@ -3450,23 +3029,15 @@ Slice::Gen::DelegateDVisitor::visitOperation(const OperationPtr& p)
string paramName = fixKwd((*q)->name());
StringList metaData = (*q)->getMetaData();
-#if defined(__SUNPRO_CC) && (__SUNPRO_CC==0x550)
- //
- // Work around for Sun CC 5.5 bug #4853566
- //
string typeString;
if((*q)->isOutParam())
{
- typeString = outputTypeToString((*q)->type(), metaData, _useWstring);
+ typeString = outputTypeToString((*q)->type(), (*q)->optional(), metaData, _useWstring);
}
else
{
- typeString = inputTypeToString((*q)->type(), metaData, _useWstring);
+ typeString = inputTypeToString((*q)->type(), (*q)->optional(), metaData, _useWstring);
}
-#else
- string typeString = (*q)->isOutParam() ? outputTypeToString((*q)->type(), metaData, _useWstring)
- : inputTypeToString((*q)->type(), metaData, _useWstring);
-#endif
params.push_back(typeString);
paramsDecl.push_back(typeString + ' ' + paramName);
@@ -3515,7 +3086,7 @@ Slice::Gen::DelegateDVisitor::visitOperation(const OperationPtr& p)
C << sp << nl << "_DirectI" << spar;
if(ret)
{
- string resultRef = outputTypeToString(ret, p->getMetaData(), _useWstring);
+ string resultRef = outputTypeToString(ret, p->returnIsOptional(), p->getMetaData(), _useWstring);
C << resultRef + " __result";
}
C << directParamsDecl << "const ::Ice::Current& __current" << epar << " : ";
@@ -3592,7 +3163,7 @@ Slice::Gen::DelegateDVisitor::visitOperation(const OperationPtr& p)
C << nl;
if(ret)
{
- string resultRef= outputTypeToString(ret, p->getMetaData(), _useWstring);
+ string resultRef= outputTypeToString(ret, p->returnIsOptional(), p->getMetaData(), _useWstring);
C << nl << resultRef << " _result;";
}
@@ -3723,6 +3294,7 @@ Slice::Gen::ObjectDeclVisitor::visitClassDecl(const ClassDeclPtr& p)
H << nl << _dllExport << "::Ice::Object* upCast(" << scoped << "*);";
H << nl << "typedef ::IceInternal::Handle< " << scoped << "> " << p->name() << "Ptr;";
H << nl << "typedef ::IceInternal::ProxyHandle< ::IceProxy" << scoped << "> " << p->name() << "Prx;";
+ H << nl << _dllExport << "void __patch(" << p->name() << "Ptr&, ::Ice::ObjectPtr&);";
}
else
{
@@ -3789,7 +3361,8 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
}
DataMemberList dataMembers = p->dataMembers();
DataMemberList allDataMembers = p->allDataMembers();
-
+ bool basePreserved = p->inheritsMetaData("preserve-slice");
+ bool preserved = basePreserved || p->hasMetaData("preserve-slice");
H << sp << nl << "class " << _dllExport << name << " : ";
H.useCurrentPosAsIndent();
@@ -3825,7 +3398,7 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
bool hasBaseClass = !bases.empty() && !bases.front()->isInterface();
bool override = p->canBeCyclic() && (!hasBaseClass || !bases.front()->canBeCyclic());
- if(override)
+ if(!basePreserved && (override || preserved))
{
H << ", private IceInternal::GCShared";
}
@@ -3854,7 +3427,7 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
for(q = allDataMembers.begin(); q != allDataMembers.end(); ++q)
{
- string typeName = inputTypeToString((*q)->type(), (*q)->getMetaData(), _useWstring);
+ string typeName = inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring);
allTypes.push_back(typeName);
allParamDecls.push_back(typeName + " __ice_" + (*q)->name());
}
@@ -3863,7 +3436,7 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
{
if(p->hasDefaultValues())
{
- H << name << "() :";
+ H << sp << nl << name << "() :";
H.inc();
writeDataMemberInitializers(H, dataMembers, _useWstring);
H.dec();
@@ -4104,7 +3677,9 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
C << eb;
emitGCFunctions(p);
- } else {
+ }
+ else
+ {
C << sp << nl
<< (_dllExport.empty() ? "" : "ICE_DECLSPEC_EXPORT ")
<< "::Ice::LocalObject* " << scope.substr(2) << "upCast(" << scoped << "* p) { return p; }";
@@ -4118,16 +3693,17 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
{
string scoped = fixKwd(p->scoped());
string scope = fixKwd(p->scope());
+ ClassList bases = p->bases();
+ ClassDefPtr base;
+ if(!bases.empty() && !bases.front()->isInterface())
+ {
+ base = bases.front();
+ }
+ bool basePreserved = p->inheritsMetaData("preserve-slice");
+ bool preserved = basePreserved || p->hasMetaData("preserve-slice");
if(!p->isLocal())
{
- ClassList bases = p->bases();
- ClassDefPtr base;
- if(!bases.empty() && !bases.front()->isInterface())
- {
- base = bases.front();
- }
-
OperationList allOps = p->allOperations();
if(!allOps.empty())
{
@@ -4202,7 +3778,6 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
<< "current.facet, current.operation);";
C << eb;
-
//
// Check if we need to generate ice_operationAttributes()
//
@@ -4272,116 +3847,146 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
H << sp;
H << nl << "virtual void __write(::IceInternal::BasicStream*) const;";
- H << nl << "virtual void __read(::IceInternal::BasicStream*, bool);";
-
-
- H.zeroIndent();
- H << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- H << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- H.restoreIndent();
+ H << nl << "virtual void __writeImpl(::IceInternal::BasicStream*) const;";
+ H << nl << "virtual void __read(::IceInternal::BasicStream*);";
+ H << nl << "virtual void __readImpl(::IceInternal::BasicStream*);";
+
H << nl << "virtual void __write(const ::Ice::OutputStreamPtr&) const;";
- H << nl << "virtual void __read(const ::Ice::InputStreamPtr&, bool);";
- H.zeroIndent();
- H << nl << "#endif";
- H.restoreIndent();
-
+ H << nl << "virtual void __read(const ::Ice::InputStreamPtr&);";
+ if(_stream)
+ {
+ H << nl << "virtual void __writeImpl(const ::Ice::OutputStreamPtr&) const;";
+ H << nl << "virtual void __readImpl(const ::Ice::InputStreamPtr&);";
+ }
+
C << sp;
C << nl << "void" << nl << scoped.substr(2)
<< "::__write(::IceInternal::BasicStream* __os) const";
C << sb;
- C << nl << "__os->writeTypeId(ice_staticId());";
- C << nl << "__os->startWriteSlice();";
- DataMemberList dataMembers = p->dataMembers();
- DataMemberList::const_iterator q;
- for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
+ if(preserved)
{
- writeMarshalUnmarshalCode(C, (*q)->type(), fixKwd((*q)->name()), true, "", true, (*q)->getMetaData());
+ C << nl << "__os->startWriteObject(__slicedData);";
}
- C << nl << "__os->endWriteSlice();";
- emitUpcall(base, "::__write(__os);");
+ else
+ {
+ C << nl << "__os->startWriteObject(0);";
+ }
+ C << nl << "__writeImpl(__os);";
+ C << nl << "__os->endWriteObject();";
C << eb;
+
C << sp;
- C << nl << "void" << nl << scoped.substr(2) << "::__read(::IceInternal::BasicStream* __is, bool __rid)";
+ C << nl << "void" << nl << scoped.substr(2)
+ << "::__writeImpl(::IceInternal::BasicStream* __os) const";
C << sb;
- C << nl << "if(__rid)";
+ C << nl << "__os->startWriteSlice(ice_staticId(), " << (!base ? "true" : "false") << ");";
+ writeMarshalUnmarshalDataMembers(C, p->dataMembers(), p->orderedOptionalDataMembers(), true);
+ C << nl << "__os->endWriteSlice();";
+ if(base)
+ {
+ emitUpcall(base, "::__writeImpl(__os);");
+ }
+ C << eb;
+
+ C << sp;
+ C << nl << "void" << nl << scoped.substr(2) << "::__read(::IceInternal::BasicStream* __is)";
C << sb;
- C << nl << "::std::string myId;";
- C << nl << "__is->readTypeId(myId);";
+ C << nl << "__is->startReadObject();";
+ C << nl << "__readImpl(__is);";
+ if(preserved)
+ {
+ C << nl << "__slicedData = __is->endReadObject(true);";
+ }
+ else
+ {
+ C << nl << "__is->endReadObject(false);";
+ }
C << eb;
+
+ C << sp;
+ C << nl << "void" << nl << scoped.substr(2) << "::__readImpl(::IceInternal::BasicStream* __is)";
+ C << sb;
C << nl << "__is->startReadSlice();";
- for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
+ writeMarshalUnmarshalDataMembers(C, p->dataMembers(), p->orderedOptionalDataMembers(), false);
+ C << nl << "__is->endReadSlice();";
+ if(base)
{
- writeMarshalUnmarshalCode(C, (*q)->type(), fixKwd((*q)->name()), false, "", true, (*q)->getMetaData());
+ emitUpcall(base, "::__readImpl(__is);");
}
- C << nl << "__is->endReadSlice();";
- emitUpcall(base, "::__read(__is, true);");
C << eb;
if(_stream)
{
- C << sp;
- C.zeroIndent();
- C << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- C << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- C.restoreIndent();
- C << nl << "void" << nl << scoped.substr(2) << "::__write(const ::Ice::OutputStreamPtr& __outS) const";
+ C << sp << nl << "void" << nl << scoped.substr(2) << "::__write(const ::Ice::OutputStreamPtr& __os) const";
C << sb;
- C << nl << "__outS->writeTypeId(ice_staticId());";
- C << nl << "__outS->startSlice();";
- for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
+ if(preserved)
+ {
+ C << nl << "__os->startObject(__slicedData);";
+ }
+ else
{
- writeStreamMarshalUnmarshalCode(C, (*q)->type(), (*q)->name(), true, "", (*q)->getMetaData(),
- _useWstring);
+ C << nl << "__os->startObject(0);";
}
- C << nl << "__outS->endSlice();";
- emitUpcall(base, "::__write(__outS);");
+ C << nl << "__writeImpl(__os);";
+ C << nl << "__os->endObject();";
C << eb;
- C << sp;
- C << nl << "void" << nl << scoped.substr(2) << "::__read(const ::Ice::InputStreamPtr& __inS, bool __rid)";
+
+ C << sp << nl << "void" << nl << scoped.substr(2)
+ << "::__writeImpl(const ::Ice::OutputStreamPtr& __os) const";
C << sb;
- C << nl << "if(__rid)";
+ C << nl << "__os->startSlice(ice_staticId(), " << (!base ? "true" : "false") << ");";
+ writeMarshalUnmarshalDataMembers(C, p->dataMembers(), p->orderedOptionalDataMembers(), true);
+ C << nl << "__os->endSlice();";
+ if(base)
+ {
+ emitUpcall(base, "::__writeImpl(__os);");
+ }
+ C << eb;
+
+ C << sp << nl << "void" << nl << scoped.substr(2) << "::__read(const ::Ice::InputStreamPtr& __is)";
C << sb;
- C << nl << "__inS->readTypeId();";
+ C << nl << "__is->startObject();";
+ C << nl << "__readImpl(__is);";
+ if(preserved)
+ {
+ C << nl << "__slicedData = __is->endObject(true);";
+ }
+ else
+ {
+ C << nl << "__is->endObject(false);";
+ }
C << eb;
- C << nl << "__inS->startSlice();";
- for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
+
+ C << sp << nl << "void" << nl << scoped.substr(2) << "::__readImpl(const ::Ice::InputStreamPtr& __is)";
+ C << sb;
+ C << nl << "__is->startSlice();";
+ writeMarshalUnmarshalDataMembers(C, p->dataMembers(), p->orderedOptionalDataMembers(), false);
+ C << nl << "__is->endSlice();";
+ if(base)
{
- writeStreamMarshalUnmarshalCode(C, (*q)->type(), (*q)->name(), false, "", (*q)->getMetaData(),
- _useWstring);
+ emitUpcall(base, "::__readImpl(__is);");
}
- C << nl << "__inS->endSlice();";
- emitUpcall(base, "::__read(__inS, true);");
C << eb;
- C.zeroIndent();
- C << nl << "#endif";
- C.restoreIndent();
}
else
{
- C << sp;
- C.zeroIndent();
- C << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- C << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- C.restoreIndent();
//
// Emit placeholder functions to catch errors.
//
- C << nl << "void" << nl << scoped.substr(2) << "::__write(const ::Ice::OutputStreamPtr&) const";
+ C << sp << nl << "void" << nl << scoped.substr(2) << "::__write(const ::Ice::OutputStreamPtr&) const";
C << sb;
C << nl << "Ice::MarshalException ex(__FILE__, __LINE__);";
C << nl << "ex.reason = \"type " << scoped.substr(2) << " was not generated with stream support\";";
C << nl << "throw ex;";
C << eb;
+
C << sp;
- C << nl << "void" << nl << scoped.substr(2) << "::__read(const ::Ice::InputStreamPtr&, bool)";
+ C << nl << "void" << nl << scoped.substr(2) << "::__read(const ::Ice::InputStreamPtr&)";
C << sb;
C << nl << "Ice::MarshalException ex(__FILE__, __LINE__);";
C << nl << "ex.reason = \"type " << scoped.substr(2) << " was not generated with stream support\";";
C << nl << "throw ex;";
C << eb;
- C.zeroIndent();
- C << nl << "#endif";
- C.restoreIndent();
}
if(!p->isAbstract())
@@ -4438,7 +4043,7 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
C << nl << "const " << factoryName << "__Init " << factoryName << "__i;";
C << sp << nl << "}";
C << sp << nl << "#ifdef __APPLE__";
- std::string initfuncname = "__F" + p->flattenedScope() + p->name() + "__initializer";
+ string initfuncname = "__F" + p->flattenedScope() + p->name() + "__initializer";
C << nl << "extern \"C\" {";
C.inc();
C << nl << "void " << initfuncname << "();";
@@ -4449,51 +4054,15 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
}
}
- bool inProtected = false;
-
- if(!p->isAbstract())
- {
- //
- // We add a protected destructor to force heap instantiation of the class.
- //
- H.dec();
- H << sp << nl << "protected:";
- H.inc();
- H << sp << nl << "virtual ~" << fixKwd(p->name()) << "() {}";
-
- if(!_doneStaticSymbol)
- {
- H << sp << nl << "friend class " << p->name() << "__staticInit;";
- }
-
- inProtected = true;
- }
-
//
// Emit data members. Access visibility may be specified by metadata.
//
+ bool inProtected = false;
DataMemberList dataMembers = p->dataMembers();
DataMemberList::const_iterator q;
bool prot = p->hasMetaData("protected");
for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
- TypePtr type = (*q)->type();
- if(SequencePtr::dynamicCast(type))
- {
- SequencePtr s = SequencePtr::dynamicCast(type);
- BuiltinPtr builtin = BuiltinPtr::dynamicCast(s->type());
- if(builtin && builtin->kind() == Builtin::KindByte)
- {
- StringList metaData = s->getMetaData();
- bool protobuf;
- findMetaData(s, metaData, protobuf);
- if(protobuf)
- {
- emitWarning((*q)->file(), (*q)->line(), "protobuf cannot be used as a class member in C++");
- }
- }
- }
-
if(prot || (*q)->hasMetaData("protected"))
{
if(!inProtected)
@@ -4515,9 +4084,39 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
}
}
- string name = fixKwd((*q)->name());
- string s = typeToString((*q)->type(), (*q)->getMetaData(), _useWstring);
- H << sp << nl << s << ' ' << name << ';';
+ emitDataMember(*q);
+ }
+
+ if(!p->isAbstract())
+ {
+ //
+ // We add a protected destructor to force heap instantiation of the class.
+ //
+ if(!inProtected)
+ {
+ H.dec();
+ H << sp << nl << "protected:";
+ H.inc();
+ inProtected = true;
+ }
+ H << sp << nl << "virtual ~" << fixKwd(p->name()) << "() {}";
+
+ if(!_doneStaticSymbol)
+ {
+ H << sp << nl << "friend class " << p->name() << "__staticInit;";
+ }
+ }
+
+ if(!p->isLocal() && preserved && !basePreserved)
+ {
+ if(!inProtected)
+ {
+ H.dec();
+ H << sp << nl << "protected:";
+ H.inc();
+ inProtected = true;
+ }
+ H << sp << nl << "::Ice::SlicedDataPtr __slicedData;";
}
H << eb << ';';
@@ -4560,14 +4159,12 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
{
C << sp << nl << "void "
<< (_dllExport.empty() ? "" : "ICE_DECLSPEC_EXPORT ");
- C << nl << scope.substr(2) << "__patch__" << p->name() << "Ptr(void* __addr, ::Ice::ObjectPtr& v)";
+ C << nl << scope.substr(2) << "__patch(" << p->name() << "Ptr& handle, ::Ice::ObjectPtr& v)";
C << sb;
- C << nl << scope << p->name() << "Ptr* p = static_cast< " << scope << p->name() << "Ptr*>(__addr);";
- C << nl << "assert(p);";
- C << nl << "*p = " << scope << p->name() << "Ptr::dynamicCast(v);";
- C << nl << "if(v && !*p)";
+ C << nl << "handle = " << scope << p->name() << "Ptr::dynamicCast(v);";
+ C << nl << "if(v && !handle)";
C << sb;
- C << nl << "IceInternal::Ex::throwUOE(" << scoped << "::ice_staticId(), v->ice_id());";
+ C << nl << "IceInternal::Ex::throwUOE(" << scoped << "::ice_staticId(), v);";
C << eb;
C << eb;
@@ -4606,7 +4203,7 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p)
string scope = fixKwd(p->scope());
TypePtr ret = p->returnType();
- string retS = returnTypeToString(ret, p->getMetaData(), _useWstring);
+ string retS = returnTypeToString(ret, p->returnIsOptional(), p->getMetaData(), _useWstring);
string params = "(";
string paramsDecl = "(";
@@ -4634,12 +4231,12 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p)
if(isOutParam)
{
outParams.push_back(*q);
- typeString = outputTypeToString(type, (*q)->getMetaData(), _useWstring);
+ typeString = outputTypeToString(type, (*q)->optional(), (*q)->getMetaData(), _useWstring);
}
else
{
inParams.push_back(*q);
- typeString = inputTypeToString((*q)->type(), (*q)->getMetaData(), _useWstring);
+ typeString = inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring);
}
if(q != paramList.begin())
@@ -4742,26 +4339,17 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p)
if(!inParams.empty())
{
- C << nl << "::IceInternal::BasicStream* __is = __inS.is();";
- C << nl << "__is->startReadEncaps();";
- writeAllocateCode(C, inParams, 0, StringList(), _useWstring | TypeContextInParam);
- writeUnmarshalCode(C, inParams, 0, StringList(), TypeContextInParam);
- if(p->sendsClasses())
- {
- C << nl << "__is->readPendingObjects();";
- }
- C << nl << "__is->endReadEncaps();";
+ C << nl << "::IceInternal::BasicStream* __is = __inS.startReadParams();";
+ writeAllocateCode(C, inParams, 0, _useWstring | TypeContextInParam);
+ writeUnmarshalCode(C, inParams, 0, TypeContextInParam);
+ C << nl << "__inS.endReadParams();";
}
else
{
- C << nl << "__inS.is()->skipEmptyEncaps();";
+ C << nl << "__inS.readEmptyParams();";
}
- if(ret || !outParams.empty() || !throws.empty())
- {
- C << nl << "::IceInternal::BasicStream* __os = __inS.os();";
- }
- writeAllocateCode(C, outParams, 0, StringList(), _useWstring);
+ writeAllocateCode(C, outParams, 0, _useWstring);
if(!throws.empty())
{
C << nl << "try";
@@ -4773,11 +4361,22 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p)
C << retS << " __ret = ";
}
C << fixKwd(name) << args << ';';
- writeMarshalCode(C, outParams, ret, p->getMetaData());
- if(p->returnsClasses())
+ FormatType format = p->format();
+ if(ret || !outParams.empty())
+ {
+ C << nl << "::IceInternal::BasicStream* __os = __inS.__startWriteParams();";
+ if(p->returnsClasses() && format != DefaultFormat)
+ {
+ C << nl << "__os->format(" << formatTypeToString(format) << ");";
+ }
+ writeMarshalCode(C, outParams, p);
+ C << nl << "__inS.__endWriteParams(true);";
+ }
+ else
{
- C << nl << "__os->writePendingObjects();";
+ C << nl << "__inS.__writeEmptyParams();";
}
+ C << nl << "return ::Ice::DispatchOK;";
if(!throws.empty())
{
C << eb;
@@ -4786,13 +4385,17 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p)
{
C << nl << "catch(const " << fixKwd((*r)->scoped()) << "& __ex)";
C << sb;
+ C << nl << "::IceInternal::BasicStream* __os = __inS.__startWriteParams();";
+ if(format != DefaultFormat)
+ {
+ C << nl << "__os->format(" << formatTypeToString(format) << ");";
+ }
C << nl << "__os->write(__ex);";
- C << nl << "return ::Ice::DispatchUserException;";
+ C << nl << "__inS.__endWriteParams(false);";
C << eb;
}
+ C << nl << "return ::Ice::DispatchUserException;";
}
-
- C << nl << "return ::Ice::DispatchOK;";
}
else
{
@@ -4800,19 +4403,14 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p)
if(!inParams.empty())
{
- C << nl << "::IceInternal::BasicStream* __is = __inS.is();";
- C << nl << "__is->startReadEncaps();";
- writeAllocateCode(C, inParams, 0, StringList(), _useWstring | TypeContextInParam);
- writeUnmarshalCode(C, inParams, 0, StringList(), TypeContextInParam);
- if(p->sendsClasses())
- {
- C << nl << "__is->readPendingObjects();";
- }
- C << nl << "__is->endReadEncaps();";
+ C << nl << "::IceInternal::BasicStream* __is = __inS.startReadParams();";
+ writeAllocateCode(C, inParams, 0, _useWstring | TypeContextInParam);
+ writeUnmarshalCode(C, inParams, 0, TypeContextInParam);
+ C << nl << "__inS.endReadParams();";
}
else
{
- C << nl << "__inS.is()->skipEmptyEncaps();";
+ C << nl << "__inS.readEmptyParams();";
}
C << nl << classScopedAMD << '_' << name << "Ptr __cb = new IceAsync" << classScopedAMD << '_' << name
@@ -4848,11 +4446,12 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p)
string typeString;
if((*r)->isOutParam())
{
- typeString = outputTypeToString((*r)->type(), metaData, _useWstring | TypeContextAMIEnd);
+ typeString = outputTypeToString((*r)->type(), (*r)->optional(), metaData,
+ _useWstring | TypeContextAMIEnd);
}
else
{
- typeString = inputTypeToString((*r)->type(), metaData, _useWstring);
+ typeString = inputTypeToString((*r)->type(), (*r)->optional(), metaData, _useWstring);
}
if(!(*r)->isOutParam())
@@ -4885,10 +4484,39 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p)
}
void
+Slice::Gen::ObjectVisitor::emitDataMember(const DataMemberPtr& p)
+{
+ TypePtr type = p->type();
+ if(SequencePtr::dynamicCast(type))
+ {
+ SequencePtr s = SequencePtr::dynamicCast(type);
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(s->type());
+ if(builtin && builtin->kind() == Builtin::KindByte)
+ {
+ StringList metaData = s->getMetaData();
+ bool protobuf;
+ findMetaData(s, metaData, protobuf);
+ if(protobuf)
+ {
+ emitWarning(p->file(), p->line(), "protobuf cannot be used as a class member in C++");
+ }
+ }
+ }
+
+ string name = fixKwd(p->name());
+ H << sp << nl << typeToString(p->type(), p->optional(), p->getMetaData(), _useWstring) << ' ' << name << ';';
+}
+
+void
Slice::Gen::ObjectVisitor::emitGCFunctions(const ClassDefPtr& p)
{
string scoped = fixKwd(p->scoped());
ClassList bases = p->bases();
+ ClassDefPtr base;
+ if(!bases.empty() && !bases.front()->isInterface())
+ {
+ base = bases.front();
+ }
DataMemberList dataMembers = p->dataMembers();
//
@@ -4898,11 +4526,16 @@ Slice::Gen::ObjectVisitor::emitGCFunctions(const ClassDefPtr& p)
// We override __incRef(), __decRef(), and __addObject() only once, in the basemost potentially
// cyclic class in an inheritance hierarchy.
//
- bool hasBaseClass = !bases.empty() && !bases.front()->isInterface();
bool canBeCyclic = p->canBeCyclic();
- bool override = canBeCyclic && (!hasBaseClass || !bases.front()->canBeCyclic());
+ bool override = canBeCyclic && (!base || !base->canBeCyclic());
+ bool basePreserved = p->inheritsMetaData("preserve-slice");
+ bool preserved = basePreserved || p->hasMetaData("preserve-slice");
- if(override)
+ //
+ // We also override __addObject and __usesGC if this is the initial preserved
+ // class in the hierarchy.
+ //
+ if(!basePreserved && (override || preserved))
{
H << nl << "virtual void __addObject(::IceInternal::GCCountMap&);";
@@ -4919,9 +4552,9 @@ Slice::Gen::ObjectVisitor::emitGCFunctions(const ClassDefPtr& p)
C << eb;
C << eb;
- H << nl << "virtual bool __usesClasses();";
+ H << nl << "virtual bool __usesGC();";
- C << sp << nl << "bool" << nl << scoped.substr(2) << "::__usesClasses()";
+ C << sp << nl << "bool" << nl << scoped.substr(2) << "::__usesGC()";
C << sb;
C << nl << "return true;";
C << eb;
@@ -4931,23 +4564,35 @@ Slice::Gen::ObjectVisitor::emitGCFunctions(const ClassDefPtr& p)
// __gcReachable() and __gcClear() are overridden by the basemost class that
// can be cyclic, plus all classes derived from that class.
//
- if(canBeCyclic)
+ // We also override these methods for the initial preserved class in a
+ // hierarchy, regardless of whether the class itself is cyclic.
+ //
+ if(canBeCyclic || (preserved && !basePreserved))
{
H << nl << "virtual void __gcReachable(::IceInternal::GCCountMap&) const;";
C << sp << nl << "void" << nl << scoped.substr(2) << "::__gcReachable(::IceInternal::GCCountMap& _c) const";
C << sb;
- bool hasCyclicBase = hasBaseClass && bases.front()->canBeCyclic();
- if(hasCyclicBase)
+ bool hasCyclicBase = base && base->canBeCyclic();
+ if(hasCyclicBase || basePreserved)
{
emitUpcall(bases.front(), "::__gcReachable(_c);");
}
+
+ if(preserved && !basePreserved)
+ {
+ C << nl << "if(__slicedData)";
+ C << sb;
+ C << nl << "__slicedData->__addObject(_c);";
+ C << eb;
+ }
+
for(DataMemberList::const_iterator i = dataMembers.begin(); i != dataMembers.end(); ++i)
{
if((*i)->type()->usesClasses())
{
- emitGCInsertCode((*i)->type(), fixKwd((*i)->name()), "", 0);
+ emitGCInsertCode((*i)->type(), getDataMemberRef(*i), "", 0);
}
}
C << eb;
@@ -4956,15 +4601,34 @@ Slice::Gen::ObjectVisitor::emitGCFunctions(const ClassDefPtr& p)
C << sp << nl << "void" << nl << scoped.substr(2) << "::__gcClear()";
C << sb;
- if(hasCyclicBase)
+
+ if(hasCyclicBase || basePreserved)
{
emitUpcall(bases.front(), "::__gcClear();");
}
+
+ //
+ // Clear the reference to the SlicedData object (if any).
+ //
+ // Note that this member is treated differently than regular class data
+ // members. The SlicedData class inherits from GCShared and therefore its
+ // instances are always registered with the GC. As a result, we must never
+ // assign 0 to the __slicedData member to clear the reference.
+ //
+ if(preserved && !basePreserved)
+ {
+ C << nl << "if(__slicedData)";
+ C << sb;
+ C << nl << "__slicedData->__decRefUnsafe();";
+ C << nl << "__slicedData.__clearHandleUnsafe();";
+ C << eb;
+ }
+
for(DataMemberList::const_iterator j = dataMembers.begin(); j != dataMembers.end(); ++j)
{
if((*j)->type()->usesClasses())
{
- emitGCClearCode((*j)->type(), fixKwd((*j)->name()), "", 0);
+ emitGCClearCode((*j)->type(), getDataMemberRef(*j), "", 0);
}
}
C << eb;
@@ -4974,8 +4638,8 @@ Slice::Gen::ObjectVisitor::emitGCFunctions(const ClassDefPtr& p)
void
Slice::Gen::ObjectVisitor::emitGCInsertCode(const TypePtr& p, const string& prefix, const string& name, int level)
{
- if((BuiltinPtr::dynamicCast(p) && BuiltinPtr::dynamicCast(p)->kind() == Builtin::KindObject)
- || ClassDeclPtr::dynamicCast(p))
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(p);
+ if((builtin && BuiltinPtr::dynamicCast(p)->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(p))
{
C << nl << "if(" << prefix << name << ')';
C << sb;
@@ -5038,8 +4702,8 @@ Slice::Gen::ObjectVisitor::emitGCInsertCode(const TypePtr& p, const string& pref
void
Slice::Gen::ObjectVisitor::emitGCClearCode(const TypePtr& p, const string& prefix, const string& name, int level)
{
- if((BuiltinPtr::dynamicCast(p) && BuiltinPtr::dynamicCast(p)->kind() == Builtin::KindObject)
- || ClassDeclPtr::dynamicCast(p))
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(p);
+ if((builtin && BuiltinPtr::dynamicCast(p)->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(p))
{
C << nl << "if(" << prefix << name << ")";
C << sb;
@@ -5047,7 +4711,7 @@ Slice::Gen::ObjectVisitor::emitGCClearCode(const TypePtr& p, const string& prefi
if(decl)
{
string scope = fixKwd(decl->scope());
- C << nl << "if(" << scope << "upCast(" << prefix << name << ".get())->__usesClasses())";
+ C << nl << "if(" << scope << "upCast(" << prefix << name << ".get())->__usesGC())";
C << sb;
C << nl << scope << "upCast(" << prefix << name << ".get())->__decRefUnsafe();";
C << nl << prefix << name << ".__clearHandleUnsafe();";
@@ -5055,7 +4719,7 @@ Slice::Gen::ObjectVisitor::emitGCClearCode(const TypePtr& p, const string& prefi
}
else
{
- C << nl << "if(" << prefix << name << "->__usesClasses())";
+ C << nl << "if(" << prefix << name << "->__usesGC())";
C << sb;
C << nl << prefix << name << "->__decRefUnsafe();";
C << nl << prefix << name << ".__clearHandleUnsafe();";
@@ -5172,7 +4836,7 @@ Slice::Gen::ObjectVisitor::emitOneShotConstructor(const ClassDefPtr& p)
for(q = allDataMembers.begin(); q != allDataMembers.end(); ++q)
{
- string typeName = inputTypeToString((*q)->type(), (*q)->getMetaData(), _useWstring);
+ string typeName = inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring);
allParamDecls.push_back(typeName + " __ice_" + (*q)->name());
}
@@ -5222,17 +4886,7 @@ Slice::Gen::ObjectVisitor::emitOneShotConstructor(const ClassDefPtr& p)
void
Slice::Gen::ObjectVisitor::emitUpcall(const ClassDefPtr& base, const string& call)
{
- C.zeroIndent();
- C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERFIX
- C.restoreIndent();
- C << nl << (base ? fixKwd(base->name()) : string("Object")) << call;
- C.zeroIndent();
- C << nl << "#else";
- C.restoreIndent();
C << nl << (base ? fixKwd(base->scoped()) : string("::Ice::Object")) << call;
- C.zeroIndent();
- C << nl << "#endif";
- C.restoreIndent();
}
Slice::Gen::AsyncCallbackVisitor::AsyncCallbackVisitor(Output& h, Output& c, const string& dllExport) :
@@ -5354,8 +5008,9 @@ bool
usePrivateEnd(const OperationPtr& p)
{
TypePtr ret = p->returnType();
- string retSEnd = returnTypeToString(ret, p->getMetaData(), TypeContextAMIEnd);
- string retSPrivateEnd = returnTypeToString(ret, p->getMetaData(), TypeContextAMIPrivateEnd);
+ bool retIsOpt = p->returnIsOptional();
+ string retSEnd = returnTypeToString(ret, retIsOpt, p->getMetaData(), TypeContextAMIEnd);
+ string retSPrivateEnd = returnTypeToString(ret, retIsOpt, p->getMetaData(), TypeContextAMIPrivateEnd);
ParamDeclList outParams;
vector<string> outDeclsEnd;
@@ -5366,8 +5021,10 @@ usePrivateEnd(const OperationPtr& p)
{
if((*q)->isOutParam())
{
- outDeclsEnd.push_back(outputTypeToString((*q)->type(), (*q)->getMetaData(), TypeContextAMIEnd));
- outDeclsPrivateEnd.push_back(outputTypeToString((*q)->type(), (*q)->getMetaData(), TypeContextAMIPrivateEnd));
+ outDeclsEnd.push_back(outputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(),
+ TypeContextAMIEnd));
+ outDeclsPrivateEnd.push_back(outputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(),
+ TypeContextAMIPrivateEnd));
}
}
@@ -5398,7 +5055,7 @@ Slice::Gen::AsyncCallbackTemplateVisitor::generateOperation(const OperationPtr&
string delTmplName = (withCookie ? "Callback_" : "CallbackNC_") + clName + "_" + p->name();
TypePtr ret = p->returnType();
- string retS = inputTypeToString(ret, p->getMetaData(), _useWstring);
+ string retS = inputTypeToString(ret, p->returnIsOptional(), p->getMetaData(), _useWstring);
string retEndArg = getEndArg(ret, p->getMetaData(), "__ret");
ParamDeclList outParams;
@@ -5415,7 +5072,7 @@ Slice::Gen::AsyncCallbackTemplateVisitor::generateOperation(const OperationPtr&
outParams.push_back(*q);
outArgs.push_back(fixKwd((*q)->name()));
outEndArgs.push_back(getEndArg((*q)->type(), (*q)->getMetaData(), outArgs.back()));
- outDecls.push_back(inputTypeToString((*q)->type(), (*q)->getMetaData(), _useWstring));
+ outDecls.push_back(inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring));
}
}
@@ -5504,8 +5161,7 @@ Slice::Gen::AsyncCallbackTemplateVisitor::generateOperation(const OperationPtr&
H << sb;
H << nl << clScope << clName << "Prx __proxy = " << clScope << clName
<< "Prx::uncheckedCast(__result->getProxy());";
- writeAllocateCode(H, outParams, ret, p->getMetaData(),
- _useWstring | TypeContextInParam | TypeContextAMICallPrivateEnd);
+ writeAllocateCode(H, outParams, p, _useWstring | TypeContextInParam | TypeContextAMICallPrivateEnd);
H << nl << "try";
H << sb;
H << nl;
@@ -5526,7 +5182,7 @@ Slice::Gen::AsyncCallbackTemplateVisitor::generateOperation(const OperationPtr&
}
H << "__result" << epar << ';';
}
- writeEndCode(H, outParams, ret, p->getMetaData());
+ writeEndCode(H, outParams, p);
H << eb;
H << nl << "catch(::Ice::Exception& ex)";
H << sb;
@@ -5658,150 +5314,7 @@ Slice::Gen::AsyncCallbackTemplateVisitor::generateOperation(const OperationPtr&
}
}
-Slice::Gen::HandleVisitor::HandleVisitor(Output& h, Output& c, const string& dllExport, bool stream) :
- H(h), C(c), _dllExport(dllExport), _stream(stream)
-{
-}
-
-bool
-Slice::Gen::HandleVisitor::visitModuleStart(const ModulePtr& p)
-{
- if(!p->hasClassDecls())
- {
- return false;
- }
-
- string name = fixKwd(p->name());
-
- H << sp;
- H << nl << "namespace " << name << nl << '{';
-
- return true;
-}
-
-void
-Slice::Gen::HandleVisitor::visitModuleEnd(const ModulePtr& p)
-{
- H << sp;
- H << nl << '}';
-}
-
-void
-Slice::Gen::HandleVisitor::visitClassDecl(const ClassDeclPtr& p)
-{
- string name = p->name();
- string scoped = fixKwd(p->scoped());
-
- if(!p->isLocal())
- {
- H << sp;
- H << nl << _dllExport << "void __read(::IceInternal::BasicStream*, " << name << "Prx&);";
- H << nl << _dllExport << "void __patch__" << name << "Ptr(void*, ::Ice::ObjectPtr&);";
- if(_stream)
- {
- H << sp;
- H.zeroIndent();
- H << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- H << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- H.restoreIndent();
- H << nl << _dllExport << "ICE_DEPRECATED_API void ice_write" << name << "Prx(const ::Ice::OutputStreamPtr&, const " << name
- << "Prx&);";
- H << nl << _dllExport << "ICE_DEPRECATED_API void ice_read" << name << "Prx(const ::Ice::InputStreamPtr&, " << name
- << "Prx&);";
-
- H << nl << _dllExport << "ICE_DEPRECATED_API void ice_write" << name << "(const ::Ice::OutputStreamPtr&, const "
- << name << "Ptr&);";
- H << nl << _dllExport << "ICE_DEPRECATED_API void ice_read" << name << "(const ::Ice::InputStreamPtr&, " << name << "Ptr&);";
- H.zeroIndent();
- H << nl << "#endif";
- H.restoreIndent();
- }
- }
-}
-
-bool
-Slice::Gen::HandleVisitor::visitClassDefStart(const ClassDefPtr& p)
-{
- if(!p->isLocal())
- {
- string name = p->name();
- string scoped = fixKwd(p->scoped());
- string scope = fixKwd(p->scope());
-
- string factory;
- string type;
- if(!p->isAbstract())
- {
- type = scoped + "::ice_staticId()";
- factory = scoped + "::ice_factory()";
- }
- else
- {
- type = "\"\"";
- factory = "0";
- }
-
- C << sp;
- C << nl << "void" << nl << scope.substr(2) << "__read(::IceInternal::BasicStream* __is, "
- << scope << name << "Prx& v)";
- C << sb;
- C << nl << "::Ice::ObjectPrx proxy;";
- C << nl << "__is->read(proxy);";
- 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;
-
- if(_stream)
- {
- C << sp;
- C.zeroIndent();
- C << nl << "// COMPILERFIX: Stream API is not supported with VC++ 6";
- C << nl << "#if !defined(_MSC_VER) || (_MSC_VER >= 1300)";
- C.restoreIndent();
- C << nl << "void" << nl << scope.substr(2) << "ice_write" << name
- << "Prx(const ::Ice::OutputStreamPtr& __outS, const " << scope << name << "Prx& v)";
- C << sb;
- C << nl << "__outS->write(v);";
- C << eb;
-
- C << sp;
- C << nl << "void" << nl << scope.substr(2) << "ice_read" << name
- << "Prx(const ::Ice::InputStreamPtr& __inS, " << scope << name << "Prx& v)";
- C << sb;
- C << nl << "__inS->read(v);";
- C << eb;
-
- C << sp;
- C << nl << "void" << nl << scope.substr(2) << "ice_write" << name
- << "(const ::Ice::OutputStreamPtr& __outS, const " << scope << name << "Ptr& v)";
- C << sb;
- C << nl << "__outS->writeObject(v);";
- C << eb;
-
- C << sp;
- C << nl << "void" << nl << scope.substr(2) << "ice_read" << name << "(const ::Ice::InputStreamPtr& __inS, "
- << scope << name << "Ptr& __v)";
- C << sb;
- C << nl << "__inS->read(__v);";
- C << eb;
- C.zeroIndent();
- C << nl << "#endif";
- C.restoreIndent();
- }
- }
-
- return true;
-}
-
-Slice::Gen::ImplVisitor::ImplVisitor(Output& h, Output& c,
- const string& dllExport) :
+Slice::Gen::ImplVisitor::ImplVisitor(Output& h, Output& c, const string& dllExport) :
H(h), C(c), _dllExport(dllExport), _useWstring(false)
{
}
@@ -6038,7 +5551,7 @@ Slice::Gen::ImplVisitor::visitClassDefStart(const ClassDefPtr& p)
string opName = op->name();
TypePtr ret = op->returnType();
- string retS = returnTypeToString(ret, op->getMetaData(), _useWstring);
+ string retS = returnTypeToString(ret, op->returnIsOptional(), op->getMetaData(), _useWstring);
if(!p->isLocal() && (p->hasMetaData("amd") || op->hasMetaData("amd")))
{
@@ -6051,7 +5564,8 @@ Slice::Gen::ImplVisitor::visitClassDefStart(const ClassDefPtr& p)
{
if(!(*q)->isOutParam())
{
- H << ',' << nl << inputTypeToString((*q)->type(), (*q)->getMetaData(), _useWstring);
+ H << ',' << nl << inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(),
+ _useWstring);
}
}
H << ',' << nl << "const Ice::Current&";
@@ -6068,8 +5582,8 @@ Slice::Gen::ImplVisitor::visitClassDefStart(const ClassDefPtr& p)
{
if(!(*q)->isOutParam())
{
- C << ',' << nl << inputTypeToString((*q)->type(), (*q)->getMetaData(), _useWstring) << ' '
- << fixKwd((*q)->name());
+ C << ',' << nl << inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(),
+ _useWstring) << ' ' << fixKwd((*q)->name());
}
}
C << ',' << nl << "const Ice::Current& current";
@@ -6131,23 +5645,15 @@ Slice::Gen::ImplVisitor::visitClassDefStart(const ClassDefPtr& p)
H << ',' << nl;
}
StringList metaData = (*q)->getMetaData();
-#if defined(__SUNPRO_CC) && (__SUNPRO_CC==0x550)
- //
- // Work around for Sun CC 5.5 bug #4853566
- //
string typeString;
if((*q)->isOutParam())
{
- typeString = outputTypeToString((*q)->type(), metaData, _useWstring);
+ typeString = outputTypeToString((*q)->type(), (*q)->optional(), metaData, _useWstring);
}
else
{
- typeString = inputTypeToString((*q)->type(), metaData, _useWstring);
+ typeString = inputTypeToString((*q)->type(), (*q)->optional(), metaData, _useWstring);
}
-#else
- string typeString = (*q)->isOutParam() ? outputTypeToString((*q)->type(), metaData, _useWstring)
- : inputTypeToString((*q)->type(), metaData, _useWstring);
-#endif
H << typeString;
}
if(!p->isLocal())
@@ -6174,23 +5680,15 @@ Slice::Gen::ImplVisitor::visitClassDefStart(const ClassDefPtr& p)
C << ',' << nl;
}
StringList metaData = (*q)->getMetaData();
-#if defined(__SUNPRO_CC) && (__SUNPRO_CC==0x550)
- //
- // Work around for Sun CC 5.5 bug #4853566
- //
string typeString;
if((*q)->isOutParam())
{
- typeString = outputTypeToString((*q)->type(), _useWstring, metaData);
+ typeString = outputTypeToString((*q)->type(), (*q)->optional(), metaData, _useWstring);
}
else
{
- typeString = inputTypeToString((*q)->type(), _useWstring, metaData);
+ typeString = inputTypeToString((*q)->type(), (*q)->optional(), metaData, _useWstring);
}
-#else
- string typeString = (*q)->isOutParam() ? outputTypeToString((*q)->type(), metaData, _useWstring)
- : inputTypeToString((*q)->type(), metaData, _useWstring);
-#endif
C << typeString << ' ' << fixKwd((*q)->name());
}
if(!p->isLocal())
@@ -6299,12 +5797,12 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p)
paramsDeclInvoke.push_back("const " + proxyName + "& __prx");
TypePtr ret = p->returnType();
- string retS = inputTypeToString(ret, p->getMetaData(), _useWstring);
+ string retS = inputTypeToString(ret, p->returnIsOptional(), p->getMetaData(), _useWstring);
if(ret)
{
params.push_back(retS);
- paramsAMD.push_back(inputTypeToString(ret, p->getMetaData(), _useWstring));
+ paramsAMD.push_back(inputTypeToString(ret, p->returnIsOptional(), p->getMetaData(), _useWstring));
paramsDecl.push_back(retS + " __ret");
args.push_back("__ret");
}
@@ -6316,12 +5814,12 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p)
{
string paramName = fixKwd((*q)->name());
TypePtr type = (*q)->type();
- string typeString = inputTypeToString(type, (*q)->getMetaData(), _useWstring);
+ string typeString = inputTypeToString(type, (*q)->optional(), (*q)->getMetaData(), _useWstring);
if((*q)->isOutParam())
{
params.push_back(typeString);
- paramsAMD.push_back(inputTypeToString(type, (*q)->getMetaData(), _useWstring));
+ paramsAMD.push_back(inputTypeToString(type, (*q)->optional(), (*q)->getMetaData(), _useWstring));
paramsDecl.push_back(typeString + ' ' + paramName);
args.push_back(paramName);
@@ -6492,7 +5990,7 @@ Slice::Gen::AsyncImplVisitor::visitOperation(const OperationPtr& p)
#endif
TypePtr ret = p->returnType();
- string retS = inputTypeToString(ret, p->getMetaData(), _useWstring);
+ string retS = inputTypeToString(ret, p->returnIsOptional(), p->getMetaData(), _useWstring);
if(ret)
{
@@ -6511,7 +6009,7 @@ Slice::Gen::AsyncImplVisitor::visitOperation(const OperationPtr& p)
{
string paramName = fixKwd((*q)->name());
TypePtr type = (*q)->type();
- string typeString = inputTypeToString(type, (*q)->getMetaData(), _useWstring);
+ string typeString = inputTypeToString(type, (*q)->optional(), (*q)->getMetaData(), _useWstring);
if(ret || !outParams.empty())
{
@@ -6575,20 +6073,18 @@ Slice::Gen::AsyncImplVisitor::visitOperation(const OperationPtr& p)
C << sb;
C << nl << "if(__validateResponse(true))";
C << sb;
+ FormatType format = p->format();
if(ret || !outParams.empty())
{
C << nl << "try";
C << sb;
- C << nl << "::IceInternal::BasicStream* __os = this->__getOs();";
- writeMarshalCode(C, outParams, 0, StringList(), TypeContextInParam);
- if(ret)
- {
- writeMarshalUnmarshalCode(C, ret, "__ret", true, "", true, p->getMetaData(), TypeContextInParam);
- }
- if(p->returnsClasses())
+ C << nl << "::IceInternal::BasicStream* __os = __startWriteParams();";
+ if(p->returnsClasses() && format != DefaultFormat)
{
- C << nl << "__os->writePendingObjects();";
+ C << nl << "__os->format(" << formatTypeToString(format) << ");";
}
+ writeMarshalCode(C, outParams, p, TypeContextInParam);
+ C << nl << "__endWriteParams(true);";
C << eb;
C << nl << "catch(const ::Ice::Exception& __ex)";
C << sb;
@@ -6596,7 +6092,11 @@ Slice::Gen::AsyncImplVisitor::visitOperation(const OperationPtr& p)
C << nl << "return;";
C << eb;
}
- C << nl << "__response(true);";
+ else
+ {
+ C << nl << "__writeEmptyParams();";
+ }
+ C << nl << "__response();";
C << eb;
C << eb;
@@ -6618,8 +6118,14 @@ Slice::Gen::AsyncImplVisitor::visitOperation(const OperationPtr& p)
C << sb;
C << nl <<"if(__validateResponse(false))";
C << sb;
- C << nl << "__getOs()->write(*__ex);";
- C << nl << "__response(false);";
+ C << nl << "::IceInternal::BasicStream* __os = __startWriteParams();";
+ if(format != DefaultFormat)
+ {
+ C << nl << "__os->format(" << formatTypeToString(format) << ");";
+ }
+ C << nl << "__os->write(*__ex);";
+ C << nl << "__endWriteParams(false);";
+ C << nl << "__response();";
C << eb;
C << eb;
}
@@ -6663,10 +6169,6 @@ Slice::Gen::StreamVisitor::visitModuleStart(const ModulePtr& m)
// Only emit this for the top-level module.
//
H << sp;
- H.zeroIndent();
- H << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERFIX
- H << nl << "#else";
- H.restoreIndent();
H << nl << "namespace Ice" << nl << '{';
}
@@ -6682,9 +6184,6 @@ Slice::Gen::StreamVisitor::visitModuleEnd(const ModulePtr& m)
// Only emit this for the top-level module.
//
H << nl << '}';
- H.zeroIndent();
- H << nl << "#endif";
- H.restoreIndent();
}
}
@@ -6729,6 +6228,15 @@ Slice::Gen::StreamVisitor::visitStructStart(const StructPtr& p)
H << nl << "static const ::Ice::StreamTraitType type = ::Ice::StreamTraitTypeStruct;";
}
H << nl << "static const int minWireSize = " << p->minWireSize() << ";";
+ H << nl << "static const bool isVariableLength = " << p->isVariableLength() << ";";
+ if(p->isVariableLength())
+ {
+ H << nl << "static const ::Ice::OptionalType optionalType = ::Ice::OptionalTypeFSize;";
+ }
+ else
+ {
+ H << nl << "static const ::Ice::OptionalType optionalType = ::Ice::OptionalTypeVSize;";
+ }
H << eb << ";" << nl;
}
return false;
@@ -6741,22 +6249,11 @@ Slice::Gen::StreamVisitor::visitEnum(const EnumPtr& p)
H << nl << "template<>";
H << nl << "struct StreamTrait< " << scoped << ">";
H << sb;
- H << nl << "static const ::Ice::StreamTraitType type = ";
- size_t sz = p->getEnumerators().size();
- if(sz <= 127)
- {
- H << "::Ice::StreamTraitTypeByteEnum;";
- }
- else if(sz <= 32767)
- {
- H << "::Ice::StreamTraitTypeShortEnum;";
- }
- else
- {
- H << "::Ice::StreamTraitTypeIntEnum;";
- }
- H << nl << "static const int enumLimit = " << sz << ";";
+ H << nl << "static const ::Ice::StreamTraitType type = ::Ice::StreamTraitTypeEnum;";
+ H << nl << "static const int enumLimit = " << p->getEnumerators().size() << ";";
H << nl << "static const int minWireSize = " << p->minWireSize() << ";";
+ H << nl << "static const bool isVariableLength = true;";
+ H << nl << "static const ::Ice::OptionalType optionalType = ::Ice::OptionalTypeSize;";
H << eb << ";" << nl;
}