diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2006-02-08 14:44:10 +0000 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2006-02-08 14:44:10 +0000 |
commit | 99028ae4feebf092ef2b68cd93d979172e8c0463 (patch) | |
tree | bc8c11335563b0351ae7f5accfc7fc080606bc10 /cpp | |
parent | Added missing dependencies on slice2cpp (diff) | |
download | ice-99028ae4feebf092ef2b68cd93d979172e8c0463.tar.bz2 ice-99028ae4feebf092ef2b68cd93d979172e8c0463.tar.xz ice-99028ae4feebf092ef2b68cd93d979172e8c0463.zip |
Fixes to alternate sequence code to get around Sun issues.
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/include/Ice/BasicStream.h | 251 | ||||
-rw-r--r-- | cpp/src/Slice/CPlusPlusUtil.cpp | 232 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 2 | ||||
-rw-r--r-- | cpp/src/slice2cppe/Gen.cpp | 2 |
4 files changed, 44 insertions, 443 deletions
diff --git a/cpp/include/Ice/BasicStream.h b/cpp/include/Ice/BasicStream.h index efd7944e17f..5f27785477e 100644 --- a/cpp/include/Ice/BasicStream.h +++ b/cpp/include/Ice/BasicStream.h @@ -285,257 +285,6 @@ private: ObjectList* _objectList; }; -// -// Template functions for marshalling alternative sequence mappings -// - -// Sequences of Builtin Types -// Sequences of Bool Sequences -template<typename T> void -writeSequence1(::IceInternal::BasicStream* __os, const T& seq) -{ - ::Ice::Int size = static_cast< ::Ice::Int>(seq.size()); - __os->writeSize(size); - typedef typename T::const_iterator I; - for(I p = seq.begin(); p != seq.end(); ++p) - { - __os->write(*p); - } -} - -// Sequences of Structures -template<typename T> void -writeSequence2(::IceInternal::BasicStream* __os, const T& seq) -{ - ::Ice::Int size = static_cast< ::Ice::Int>(seq.size()); - __os->writeSize(size); - typedef typename T::const_iterator I; - for(I p = seq.begin(); p != seq.end(); ++p) - { - (*p).__write(__os); - } -} - -// Sequences of regular Builtin Type Sequences (except Bool) -template<typename T> void -writeSequence3(::IceInternal::BasicStream* __os, const T& seq) -{ - ::Ice::Int size = static_cast< ::Ice::Int>(seq.size()); - __os->writeSize(size); - typedef typename T::const_iterator I; - for(I p = seq.begin(); p != seq.end(); ++p) - { - __os->write(&(*p)[0], &(*p)[0] + (*p).size()); - } -} - -// Sequences of regular non-Builtin Type Sequences -template<typename T, typename S, typename C> void -writeSequence4(::IceInternal::BasicStream* __os, const T& seq, - void (*func)(::IceInternal::BasicStream*, const S*, const S*, C)) -{ - ::Ice::Int size = static_cast< ::Ice::Int>(seq.size()); - __os->writeSize(size); - typedef typename T::const_iterator I; - for(I p = seq.begin(); p != seq.end(); ++p) - { - (*func)(__os, &(*p)[0], &(*p)[0] + (*p).size(), C()); - } -} - -// Sequences of alternative Sequences -// Sequences of Dictionaries -template<typename T, typename S, typename C> void -writeSequence5(::IceInternal::BasicStream* __os, const T& seq, - void (*func)(::IceInternal::BasicStream*, const S&, C)) -{ - ::Ice::Int size = static_cast< ::Ice::Int>(seq.size()); - __os->writeSize(size); - typedef typename T::const_iterator I; - for(I p = seq.begin(); p != seq.end(); ++p) - { - (*func)(__os, *p, C()); - } -} - -// Sequences of Enums -template<typename T, typename E> void -writeSequence6(::IceInternal::BasicStream* __os, const T& seq, - void (*func)(::IceInternal::BasicStream*, E)) -{ - ::Ice::Int size = static_cast< ::Ice::Int>(seq.size()); - __os->writeSize(size); - typedef typename T::const_iterator I; - for(I p = seq.begin(); p != seq.end(); ++p) - { - (*func)(__os, *p); - } -} - -// Sequences of Proxies -template<typename T, typename P> void -writeSequence7(::IceInternal::BasicStream* __os, const T& seq, - void (*func)(::IceInternal::BasicStream*, const P&)) -{ - ::Ice::Int size = static_cast< ::Ice::Int>(seq.size()); - __os->writeSize(size); - typedef typename T::const_iterator I; - for(I p = seq.begin(); p != seq.end(); ++p) - { - (*func)(__os, *p); - } -} - -// Sequences of Builtin Types -// Sequences of Builtin Type Sequences (except Byte) -template<typename T> void -readSequence1(::IceInternal::BasicStream* __is, T& seq, bool isVariable) -{ - ::Ice::Int size; - __is->readSize(size); - T(size).swap(seq); - if(size > 0) - { - if(isVariable) - { - __is->startSeq(size, 1); - } - typedef typename T::iterator I; - for(I p = seq.begin(); p != seq.end(); ++p) - { - __is->read(*p); - if(isVariable) - { - __is->checkSeq(); - __is->endElement(); - } - } - if(isVariable) - { - __is->endSeq(size); - } - } -} - -// Sequences of Structures -template<typename T> void -readSequence2(::IceInternal::BasicStream* __is, T& seq, int elemSize, bool isVariable) -{ - ::Ice::Int size; - __is->readSize(size); - T(size).swap(seq); - if(size > 0) - { - if(isVariable) - { - __is->startSeq(size, elemSize); - } - else - { - __is->checkFixedSeq(size, elemSize); - } - typedef typename T::iterator I; - for(I p = seq.begin(); p != seq.end(); ++p) - { - (*p).__read(__is); - if(isVariable) - { - __is->checkSeq(); - __is->endElement(); - } - } - if(isVariable) - { - __is->endSeq(size); - } - } -} - -// Sequences of Byte Sequences -template<typename T> void -readSequence3(::IceInternal::BasicStream* __is, T& seq) -{ - ::Ice::Int size; - __is->readSize(size); - T(size).swap(seq); - if(size > 0) - { - __is->startSeq(size, 1); - typedef typename T::iterator I; - for(I p = seq.begin(); p != seq.end(); ++p) - { - std::pair<const Ice::Byte*, const Ice::Byte*> tmp; - __is->read(tmp); - std::vector<Ice::Byte>(tmp.first, tmp.second).swap(*p); - __is->checkSeq(); - __is->endElement(); - } - __is->endSeq(size); - } -} - -// Sequences of regular Non-Builtin Type Sequences -// Sequences of Alternative Sequences -// Sequences of Dictionaries -template<typename T, typename S, typename C> void -readSequence4(::IceInternal::BasicStream* __is, T& seq, void (*func)(::IceInternal::BasicStream*, S&, C)) -{ - ::Ice::Int size; - __is->readSize(size); - T(size).swap(seq); - if(size > 0) - { - __is->startSeq(size, 1); - typedef typename T::iterator I; - for(I p = seq.begin(); p != seq.end(); ++p) - { - (*func)(__is, *p, C()); - __is->checkSeq(); - __is->endElement(); - } - __is->endSeq(size); - } -} - -// Sequences of Enums -// Sequences of Proxies -template<typename T, typename S> void -readSequence5(::IceInternal::BasicStream* __is, T& seq, void (*func)(::IceInternal::BasicStream*, S&)) -{ - ::Ice::Int size; - __is->readSize(size); - T(size).swap(seq); - if(size > 0) - { - typedef typename T::iterator I; - for(I p = seq.begin(); p != seq.end(); ++p) - { - (*func)(__is, *p); - } - } -} - -// Sequences of Classes -template<typename T> void -readSequence6(::IceInternal::BasicStream* __is, T& seq, int elemSize, void (*func)(void*, ::Ice::ObjectPtr&)) -{ - ::Ice::Int size; - __is->readSize(size); - T(size).swap(seq); - if(size > 0) - { - __is->startSeq(size, elemSize); - typedef typename T::iterator I; - for(I p = seq.begin(); p != seq.end(); ++p) - { - __is->read(*func, &(*p)); - __is->checkSeq(); - __is->endElement(); - } - __is->endSeq(size); - } -} - } // End namespace IceInternal #endif diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp index a3ec06913c4..af5f4be10c2 100644 --- a/cpp/src/Slice/CPlusPlusUtil.cpp +++ b/cpp/src/Slice/CPlusPlusUtil.cpp @@ -640,7 +640,7 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string& { seqType = fixKwd(seq->scoped()); } - out << nl << stream << deref << "writeSize(static_cast< ::Ice::Int>(::std::distance(" + out << nl << stream << deref << "writeSize(static_cast< ::Ice::Int>(ice_distance(" << fixedParam << ".first, " << fixedParam << ".second)));"; out << nl << "for(" << seqType << "::const_iterator __" << fixedParam << " = " << fixedParam << ".first; __" << fixedParam << " != " << fixedParam << ".second; ++__" @@ -651,106 +651,13 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string& } else if(!seqType.empty()) { - // - // Using alternate sequence type. In this case we use the templated writeSequence functions, - // choosing the appropriate function depending on the type contained in the sequence, which - // have differing write semantics. - // - string typeStr = typeToString(type, metaData); - if(typeStr[0] == ':') - { - typeStr = " " + typeStr; - } - if(typeStr[typeStr.size() - 1] == '>') - { - typeStr += " "; - } - if(!builtin || builtin->kind() == Builtin::KindObject || builtin->kind() == Builtin::KindObjectProxy) - { - SequencePtr innerSeq = SequencePtr::dynamicCast(seq->type()); - if(innerSeq) - { - string innerScope = fixKwd(innerSeq->scope()); - StringList l = innerSeq->getMetaData(); - seqType = findMetaData(l, false); - builtin = BuiltinPtr::dynamicCast(innerSeq->type()); - if(!seqType.empty()) - { - out << nl << "::IceInternal::writeSequence5<" << typeStr << ", " << innerScope - << fixKwd(innerSeq->name()) << ", " << innerScope << "__U__" - << fixKwd(innerSeq->name()) << ">(" << stream << ", " << fixedParam << ", " - << innerScope << "__write);"; - } - else if(!builtin || builtin->kind() == Builtin::KindObject || - builtin->kind() == Builtin::KindObjectProxy) - { - out << nl << "::IceInternal::writeSequence4<" << typeStr << ", " - << typeToString(innerSeq->type()) << ", " << innerScope << "__U__" - << fixKwd(innerSeq->name()) << ">(" << stream << ", " << fixedParam << ", " - << innerScope << "__write);"; - } - else if(builtin->kind() == Builtin::KindBool) - { - out << nl << "::IceInternal::writeSequence1<" << typeStr << ">(" << stream << ", " - << fixedParam << ");"; - } - else - { - out << nl << "::IceInternal::writeSequence3<" << typeStr << ">(" << stream << ", " - << fixedParam << ");"; - } - return; - } - - DictionaryPtr innerDict = DictionaryPtr::dynamicCast(seq->type()); - if(innerDict) - { - string innerScope = fixKwd(innerDict->scope()); - out << nl << "::IceInternal::writeSequence5<" << typeStr << ", " << innerScope - << fixKwd(innerDict->name()) << ", " << innerScope << "__U__" << fixKwd(innerDict->name()) - << ">(" << stream << ", " << fixedParam << ", " << innerScope << "__write);"; - return; - } - - EnumPtr innerEnum = EnumPtr::dynamicCast(seq->type()); - if(innerEnum) - { - string innerScope = fixKwd(innerEnum->scope()); - out << nl << "::IceInternal::writeSequence6<" << typeStr << ", " << innerScope - << fixKwd(innerEnum->name()) << ">(" << stream << ", " << fixedParam << ", " - << innerScope << "__write);"; - return; - } - - ProxyPtr innerProxy = ProxyPtr::dynamicCast(seq->type()); - if(innerProxy) - { - string innerScope = fixKwd(innerProxy->_class()->scope()); - out << nl << "::IceInternal::writeSequence7<" << typeStr << ", " - << typeToString(innerProxy) << ">(" << stream << ", " << fixedParam << ", " - << innerScope << "__write);"; - return; - } - - ClassDeclPtr innerClass = ClassDeclPtr::dynamicCast(seq->type()); - if(innerClass) - { - string innerScope = fixKwd(innerClass->scope()); - out << nl << "::IceInternal::writeSequence7<" << typeStr << ", " - << typeToString(innerClass) << ">(" << stream << ", " << fixedParam << ", " - << innerScope << "__write);"; - return; - } - - - out << nl << "::IceInternal::writeSequence2<" << typeStr << ">(" << stream - << ", " << fixedParam << ");"; - } - else - { - out << nl << "::IceInternal::writeSequence1<" << typeStr << ">(" << stream << ", " - << fixedParam << ");"; - } + out << nl << stream << deref << "writeSize(static_cast< ::Ice::Int>(" << fixedParam << ".size()));"; + out << nl << seqType << "::const_iterator __p_" << fixedParam << ";"; + out << nl << "for(__p_" << fixedParam << " = " << fixedParam << ".begin(); __p_" << fixedParam + << " != " << fixedParam << ".end(); ++__p_" << fixedParam << ")"; + out << sb; + writeMarshalUnmarshalCode(out, seq->type(), "(*__p_" + fixedParam + ")", true); + out << eb; } else { @@ -864,98 +771,39 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string& else if(!seqType.empty()) { // - // Using alternate sequence type. In this case we use the templated readSequence functions, - // choosing the appropriate function depending on the type contained in the sequence, which - // have differing read semantics. + // Using alternate sequence type. // - string typeStr = typeToString(type, metaData); - if(typeStr[0] == ':') - { - typeStr = " " + typeStr; - } - if(typeStr[typeStr.size() - 1] == '>') - { - typeStr += " "; - } - if(!builtin || builtin->kind() == Builtin::KindObject || builtin->kind() == Builtin::KindObjectProxy) - { - SequencePtr innerSeq = SequencePtr::dynamicCast(seq->type()); - if(innerSeq) - { - string innerScope = fixKwd(innerSeq->scope()); - StringList l = innerSeq->getMetaData(); - seqType = findMetaData(l, false); - builtin = BuiltinPtr::dynamicCast(innerSeq->type()); - if(!seqType.empty() || !builtin || builtin->kind() == Builtin::KindObject || - builtin->kind() == Builtin::KindObjectProxy) - { - out << nl << "::IceInternal::readSequence4<" << typeStr << ", " << innerScope - << fixKwd(innerSeq->name()) << ", " << innerScope << "__U__" << fixKwd(innerSeq->name()) - << ">(" << stream << ", " << fixedParam << ", " << innerScope << "__read);"; - } - else if(builtin->kind() == Builtin::KindByte) - { - out << nl << "::IceInternal::readSequence3<" << typeStr << ">(" << stream << ", " - << fixedParam << ");"; - } - else - { - out << nl << "::IceInternal::readSequence1<" << typeStr << ">(" << stream << ", " - << fixedParam << ", true);"; - } - return; - } - - DictionaryPtr innerDict = DictionaryPtr::dynamicCast(seq->type()); - if(innerDict) - { - string innerScope = fixKwd(innerDict->scope()); - out << nl << "::IceInternal::readSequence4<" << typeStr << ", " << innerScope - << fixKwd(innerDict->name()) << ", " << innerScope << "__U__" << fixKwd(innerDict->name()) - << ">(" << stream << ", " << fixedParam << ", " << innerScope << "__read);"; - return; - } - - EnumPtr innerEnum = EnumPtr::dynamicCast(seq->type()); - if(innerEnum) - { - string innerScope = fixKwd(innerEnum->scope()); - out << nl << "::IceInternal::readSequence5<" << typeStr << ", " << innerScope - << fixKwd(innerEnum->name()) << ">(" << stream << ", " << fixedParam << ", " << innerScope - << "__read);"; - return; - } - - ProxyPtr innerProxy = ProxyPtr::dynamicCast(seq->type()); - if(innerProxy) - { - string innerScope = fixKwd(innerProxy->_class()->scope()); - out << nl << "::IceInternal::readSequence5<" << typeStr << ", " - << typeToString(innerProxy) << ">(" << stream << ", " << fixedParam << ", " << innerScope - << "__read);"; - return; - } - - ClassDeclPtr innerClass = ClassDeclPtr::dynamicCast(seq->type()); - if(innerClass) - { - string innerScope = fixKwd(innerClass->scope()); - out << nl << "::IceInternal::readSequence6<" << typeStr << ">(" << stream << ", " - << fixedParam << ", " << innerClass->minWireSize() << ", " - << innerScope << "__patch__" << innerClass->name() << "Ptr);"; - return; - } - - TypePtr elemType = seq->type(); - out << nl << "::IceInternal::readSequence2<" << typeStr << ">(" << stream << ", " - << fixedParam << ", " << elemType->minWireSize() << ", " - << (elemType->isVariableLength() ? "true" : "false") << ");"; - } - else - { - out << nl << "::IceInternal::readSequence1<" << typeStr << ">(" << stream << ", " - << fixedParam << ", " << (builtin->kind() == Builtin::KindString ? "true" : "false") << ");"; - } + out << nl << "::Ice::Int __sz_" << fixedParam << ";"; + out << nl << stream << deref << "readSize(__sz_" << fixedParam << ");"; + out << nl << seqType << "(__sz_" << fixedParam << ").swap(" << fixedParam << ");"; + if(seq->type()->isVariableLength()) + { + out << nl << stream << deref << "startSeq(__sz_" << fixedParam << ", " + << seq->type()->minWireSize() << ");"; + } + else + { + out << nl << stream << deref << "checkFixedSeq(__sz_" << fixedParam << ", " + << seq->type()->minWireSize() << ");"; + } + out << nl << seqType << "::iterator __p_" << fixedParam << ";"; + out << nl << "for(__p_" << fixedParam << " = " << fixedParam << ".begin(); __p_" << fixedParam + << " != " << fixedParam << ".end(); ++__p_" << fixedParam << ")"; + out << sb; + writeMarshalUnmarshalCode(out, seq->type(), "(*__p_" + fixedParam + ")", false); + if(seq->type()->isVariableLength()) + { + if(!SequencePtr::dynamicCast(seq->type())) + { + out << nl << stream << deref << "checkSeq();"; + } + out << nl << stream << deref << "endElement();"; + } + out << eb; + if(seq->type()->isVariableLength()) + { + out << nl << stream << deref << "endSeq(__sz_" << fixedParam << ");"; + } } else { diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 79843be2ce1..97718dd9328 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -239,6 +239,8 @@ Slice::Gen::generate(const UnitPtr& p) C << "\n#include <Ice/SliceChecksums.h>"; } + C << "\n#include <IceUtil/Iterator.h>"; + StringList includes = p->includeFiles(); for(StringList::const_iterator q = includes.begin(); q != includes.end(); ++q) diff --git a/cpp/src/slice2cppe/Gen.cpp b/cpp/src/slice2cppe/Gen.cpp index e8f5780133e..52d18fddce3 100644 --- a/cpp/src/slice2cppe/Gen.cpp +++ b/cpp/src/slice2cppe/Gen.cpp @@ -238,6 +238,8 @@ Slice::Gen::generate(const UnitPtr& p) C << "\n#include <IceE/LocalException.h>"; } + C << "\n#include <IceE/Iterator.h>"; + StringList includes = p->includeFiles(); for(StringList::const_iterator q = includes.begin(); q != includes.end(); ++q) |