diff options
author | Joe George <joe@zeroc.com> | 2016-07-13 15:56:07 -0400 |
---|---|---|
committer | Joe George <joe@zeroc.com> | 2016-07-13 15:57:19 -0400 |
commit | aeb275aed3db271ee854f29e9b62806fe496255c (patch) | |
tree | 9e5fb1ee82729c0579dac86fc9592f2717daf1cf /cpp/src | |
parent | Various C++ cleanups (diff) | |
download | ice-aeb275aed3db271ee854f29e9b62806fe496255c.tar.bz2 ice-aeb275aed3db271ee854f29e9b62806fe496255c.tar.xz ice-aeb275aed3db271ee854f29e9b62806fe496255c.zip |
Some ice_tuple fixes
- ice_tuple now returns all data members from class base class
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Slice/CPlusPlusUtil.cpp | 17 | ||||
-rw-r--r-- | cpp/src/Slice/CPlusPlusUtil.h | 2 | ||||
-rw-r--r-- | cpp/src/Slice/Parser.cpp | 17 | ||||
-rw-r--r-- | cpp/src/Slice/Parser.h | 2 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 24 |
5 files changed, 43 insertions, 19 deletions
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp index 8987d936763..57fdf1bf2ff 100644 --- a/cpp/src/Slice/CPlusPlusUtil.cpp +++ b/cpp/src/Slice/CPlusPlusUtil.cpp @@ -1442,12 +1442,17 @@ Slice::writeMarshalUnmarshalAllInHolder(IceUtilInternal::Output& out, void Slice::writeStreamHelpers(Output& out, - bool checkClassMetaData, - bool cpp11, const ContainedPtr& c, - DataMemberList dataMembers) + DataMemberList dataMembers, + bool hasBaseDataMembers, + bool checkClassMetaData, + bool cpp11) { - if(dataMembers.empty()) + // If c is a C++11 class/exception whose base class contains data members (recursively), then we need to generate + // an StreamWriter even if its implementation is empty. This is becuase our default marsaling uses ice_tuple() which + // contains all of our class/exception's data members as well the base data members, which breaks marshaling. This + // is not an issue for structs. + if(dataMembers.empty() && !(cpp11 && hasBaseDataMembers)) { return; } @@ -1487,9 +1492,9 @@ Slice::writeStreamHelpers(Output& out, // Generate StreamWriter // // Only generate StreamWriter specializations if we are generating for C++98 or - // we are generating for C++11 with optional data members + // we are generating for C++11 with optional data members and no base class data members // - if(!cpp11 || !optionalMembers.empty()) + if(!cpp11 || !optionalMembers.empty() || hasBaseDataMembers) { out << nl << "template<typename S>"; out << nl << "struct StreamWriter" << (cpp11 ? "<" : "< ") << fullName << ", S>"; diff --git a/cpp/src/Slice/CPlusPlusUtil.h b/cpp/src/Slice/CPlusPlusUtil.h index cc5e0f44ded..0e359b9a1a7 100644 --- a/cpp/src/Slice/CPlusPlusUtil.h +++ b/cpp/src/Slice/CPlusPlusUtil.h @@ -61,7 +61,7 @@ std::string getEndArg(const TypePtr&, const StringList&, const std::string&); void writeEndCode(::IceUtilInternal::Output&, const ParamDeclList&, const OperationPtr&, bool = false); void writeMarshalUnmarshalDataMemberInHolder(IceUtilInternal::Output&, const std::string&, const DataMemberPtr&, bool); void writeMarshalUnmarshalAllInHolder(IceUtilInternal::Output&, const std::string&, const DataMemberList&, bool, bool); -void writeStreamHelpers(::IceUtilInternal::Output&, bool, bool, const ContainedPtr&, DataMemberList); +void writeStreamHelpers(::IceUtilInternal::Output&, const ContainedPtr&, DataMemberList, bool, bool, bool); void writeIceTuple(::IceUtilInternal::Output&, DataMemberList, int); bool findMetaData(const std::string&, const ClassDeclPtr&, std::string&); diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index 1c3eb315032..a8685dbce3d 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -3656,6 +3656,17 @@ Slice::ClassDef::inheritsMetaData(const string& meta) const return false; } +bool +Slice::ClassDef::hasBaseDataMembers() const +{ + if(!_bases.empty() && !_bases.front()->isInterface()) + { + return !_bases.front()->allDataMembers().empty(); + } + + return false; +} + Contained::ContainedType Slice::ClassDef::containedType() const { @@ -4097,6 +4108,12 @@ Slice::Exception::inheritsMetaData(const string& meta) const return false; } +bool +Slice::Exception::hasBaseDataMembers() const +{ + return _base && !_base->allDataMembers().empty(); +} + string Slice::Exception::kindOf() const { diff --git a/cpp/src/Slice/Parser.h b/cpp/src/Slice/Parser.h index 5d0d7c547ea..eb0e97a5269 100644 --- a/cpp/src/Slice/Parser.h +++ b/cpp/src/Slice/Parser.h @@ -660,6 +660,7 @@ public: bool hasOperations() const; bool hasDefaultValues() const; bool inheritsMetaData(const std::string&) const; + bool hasBaseDataMembers() const; virtual ContainedType containedType() const; virtual bool uses(const ContainedPtr&) const; virtual std::string kindOf() const; @@ -730,6 +731,7 @@ public: bool usesClasses(bool) const; bool hasDefaultValues() const; bool inheritsMetaData(const std::string&) const; + bool hasBaseDataMembers() const; virtual std::string kindOf() const; virtual void visit(ParserVisitor*, bool); diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index f0e3453e41a..da3b0de0e21 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -1388,7 +1388,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) C << sp << nl << "void" << nl << scoped.substr(2) << "::__writeImpl(::Ice::OutputStream* __os) const"; C << sb; C << nl << "__os->startSlice(\"" << p->scoped() << "\", -1, " << (!base ? "true" : "false") << ");"; - C << nl << "Ice::StreamWriter<" << scoped.substr(2) << ", ::Ice::OutputStream>::write(__os, *this);"; + C << nl << "Ice::StreamWriter< ::" << scoped.substr(2) << ", ::Ice::OutputStream>::write(__os, *this);"; C << nl << "__os->endSlice();"; if(base) { @@ -1399,7 +1399,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) C << sp << nl << "void" << nl << scoped.substr(2) << "::__readImpl(::Ice::InputStream* __is)"; C << sb; C << nl << "__is->startSlice();"; - C << nl << "Ice::StreamReader<" << scoped.substr(2) << ", ::Ice::InputStream>::read(__is, *this);"; + C << nl << "Ice::StreamReader< ::" << scoped.substr(2) << ", ::Ice::InputStream>::read(__is, *this);"; C << nl << "__is->endSlice();"; if(base) { @@ -2969,7 +2969,7 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) C << nl << "void" << nl << scoped.substr(2) << "::__writeImpl(::Ice::OutputStream* __os) const"; C << sb; C << nl << "__os->startSlice(ice_staticId(), " << p->compactId() << (!base ? ", true" : ", false") << ");"; - C << nl << "Ice::StreamWriter<" << scoped.substr(2) << ", ::Ice::OutputStream>::write(__os, *this);"; + C << nl << "Ice::StreamWriter< ::" << scoped.substr(2) << ", ::Ice::OutputStream>::write(__os, *this);"; C << nl << "__os->endSlice();"; if(base) { @@ -2981,7 +2981,7 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) C << nl << "void" << nl << scoped.substr(2) << "::__readImpl(::Ice::InputStream* __is)"; C << sb; C << nl << "__is->startSlice();"; - C << nl << "Ice::StreamReader<" << scoped.substr(2) << ", ::Ice::InputStream>::read(__is, *this);"; + C << nl << "Ice::StreamReader< ::" << scoped.substr(2) << ", ::Ice::InputStream>::read(__is, *this);"; C << nl << "__is->endSlice();"; if(base) { @@ -4779,7 +4779,7 @@ Slice::Gen::StreamVisitor::visitClassDefStart(const ClassDefPtr& c) { if(!c->isLocal()) { - writeStreamHelpers(H, true, false, c, c->dataMembers()); + writeStreamHelpers(H, c, c->dataMembers(), c->hasBaseDataMembers(), true, false); } return false; } @@ -4796,7 +4796,7 @@ Slice::Gen::StreamVisitor::visitExceptionStart(const ExceptionPtr& p) H << nl << "static const StreamHelperCategory helper = StreamHelperCategoryUserException;"; H << eb << ";" << nl; - writeStreamHelpers(H, true, false, p, p->dataMembers()); + writeStreamHelpers(H, p, p->dataMembers(), p->hasBaseDataMembers(), true, false); } return false; } @@ -4835,7 +4835,7 @@ Slice::Gen::StreamVisitor::visitStructStart(const StructPtr& p) } H << eb << ";" << nl; - writeStreamHelpers(H, true, false, p, p->dataMembers()); + writeStreamHelpers(H, p, p->dataMembers(), false, true, false); } return false; } @@ -5825,7 +5825,7 @@ Slice::Gen::Cpp11TypesVisitor::visitExceptionStart(const ExceptionPtr& p) H << eb; } - writeIceTuple(H, p->dataMembers(), _useWstring); + writeIceTuple(H, p->allDataMembers(), _useWstring); H << sp; H << nl << _dllMemberExport << "static const ::std::string& ice_staticId();"; @@ -7625,7 +7625,7 @@ Slice::Gen::Cpp11ValueVisitor::visitClassDefStart(const ClassDefPtr& p) emitOneShotConstructor(p); - writeIceTuple(H, p->dataMembers(), _useWstring); + writeIceTuple(H, p->allDataMembers(), _useWstring); H << sp << nl << _dllMemberExport << "static const ::std::string& ice_staticId();"; return true; @@ -7960,7 +7960,7 @@ Slice::Gen::Cpp11StreamVisitor::visitStructStart(const StructPtr& p) H << nl << "static const bool fixedLength = " << (p->isVariableLength() ? "false" : "true") << ";"; H << eb << ";" << nl; - writeStreamHelpers(H, false, true, p, p->dataMembers()); + writeStreamHelpers(H, p, p->dataMembers(), false, false, true); return false; } @@ -7970,7 +7970,7 @@ Slice::Gen::Cpp11StreamVisitor::visitClassDefStart(const ClassDefPtr& c) { if(!c->isLocal() && !c->isInterface()) { - writeStreamHelpers(H, true, true, c, c->dataMembers()); + writeStreamHelpers(H,c, c->dataMembers(), c->hasBaseDataMembers(), true, true); } return false; } @@ -7980,7 +7980,7 @@ Slice::Gen::Cpp11StreamVisitor::visitExceptionEnd(const ExceptionPtr& p) { if(!p->isLocal()) { - writeStreamHelpers(H, true, true, p, p->dataMembers()); + writeStreamHelpers(H,p, p->dataMembers(), p->hasBaseDataMembers(), true, true); } } |