diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Slice/CPlusPlusUtil.cpp | 412 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 354 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.h | 18 |
3 files changed, 357 insertions, 427 deletions
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp index 93c5f25a1d3..a19636f2ef8 100644 --- a/cpp/src/Slice/CPlusPlusUtil.cpp +++ b/cpp/src/Slice/CPlusPlusUtil.cpp @@ -1124,418 +1124,14 @@ Slice::writeStreamMarshalUnmarshalCode(Output& out, const TypePtr& type, const s stream = str; } - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - switch(builtin->kind()) - { - case Builtin::KindByte: - { - if(marshal) - { - out << nl << stream << "->writeByte(" << fixedParam << ");"; - } - else - { - out << nl << fixedParam << " = " << stream << "->readByte();"; - } - break; - } - case Builtin::KindBool: - { - if(marshal) - { - out << nl << stream << "->writeBool(" << fixedParam << ");"; - } - else - { - out << nl << fixedParam << " = " << stream << "->readBool();"; - } - break; - } - case Builtin::KindShort: - { - if(marshal) - { - out << nl << stream << "->writeShort(" << fixedParam << ");"; - } - else - { - out << nl << fixedParam << " = " << stream << "->readShort();"; - } - break; - } - case Builtin::KindInt: - { - if(marshal) - { - out << nl << stream << "->writeInt(" << fixedParam << ");"; - } - else - { - out << nl << fixedParam << " = " << stream << "->readInt();"; - } - break; - } - case Builtin::KindLong: - { - if(marshal) - { - out << nl << stream << "->writeLong(" << fixedParam << ");"; - } - else - { - out << nl << fixedParam << " = " << stream << "->readLong();"; - } - break; - } - case Builtin::KindFloat: - { - if(marshal) - { - out << nl << stream << "->writeFloat(" << fixedParam << ");"; - } - else - { - out << nl << fixedParam << " = " << stream << "->readFloat();"; - } - break; - } - case Builtin::KindDouble: - { - if(marshal) - { - out << nl << stream << "->writeDouble(" << fixedParam << ");"; - } - else - { - out << nl << fixedParam << " = " << stream << "->readDouble();"; - } - break; - } - case Builtin::KindString: - { - string strType = findMetaData(metaData, true); - if(strType != "string" && (useWstring || strType == "wstring")) - { - if(marshal) - { - out << nl << stream << "->writeWstring(" << fixedParam << ");"; - } - else - { - out << nl << fixedParam << " = " << stream << "->readWstring();"; - } - } - else - { - if(marshal) - { - out << nl << stream << "->writeString(" << fixedParam << ");"; - } - else - { - out << nl << fixedParam << " = " << stream << "->readString();"; - } - } - break; - } - case Builtin::KindObject: - { - if(marshal) - { - out << nl << "::Ice::ice_writeObject(" << stream << ", " << fixedParam << ");"; - } - else - { - out << nl << "::Ice::ice_readObject(" << stream << ", " << fixedParam << ");"; - } - break; - } - case Builtin::KindObjectProxy: - { - // TODO - if(marshal) - { - out << nl << stream << "->writeProxy(" << fixedParam << ");"; - } - else - { - out << nl << fixedParam << " = " << stream << "->readProxy();"; - } - break; - } - case Builtin::KindLocalObject: - { - assert(false); - break; - } - } - - return; - } - - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - if(cl) + if(marshal) { - string scope = fixKwd(cl->scope()); - if(marshal) - { - out << nl << scope << "ice_write" << cl->name() << "(" << stream << ", " << fixedParam << ");"; - } - else - { - out << nl << scope << "ice_read" << cl->name() << "(" << stream << ", " << fixedParam << ");"; - } - - return; + out << nl << stream << "->write(" << fixedParam << ");"; } - - StructPtr st = StructPtr::dynamicCast(type); - if(st) - { - string scope = fixKwd(st->scope()); - if(marshal) - { - out << nl << scope << "ice_write" << st->name() << "(" << stream << ", " << fixedParam << ");"; - } - else - { - if(findMetaData(st->getMetaData(), false) == "class") - { - out << nl << fixedParam << " = new " << fixKwd(st->scoped()) << ";"; - } - out << nl << scope << "ice_read" << st->name() << "(" << stream << ", " << fixedParam << ");"; - } - - return; - } - - SequencePtr seq = SequencePtr::dynamicCast(type); - if(seq) - { - string seqType = findMetaData(metaData, false); - if(!seqType.empty()) - { - if(marshal) - { - out << nl << stream << "->writeSize(static_cast< ::Ice::Int>(" << fixedParam << ".size()));"; - out << nl << seqType << "::const_iterator ___" << fixedParam << ";"; - out << nl << "for(___" << fixedParam << " = " << fixedParam << ".begin(); ___" << fixedParam << " != " - << fixedParam << ".end(); ++___" << fixedParam << ")"; - out << sb; - writeStreamMarshalUnmarshalCode(out, seq->type(), "(*___" + fixedParam + ")", true); - out << eb; - } - else - { - out << nl << seqType << "(static_cast< ::Ice::Int>(" << stream << "->readSize())).swap(" - << fixedParam << ");"; - out << nl << seqType << "::iterator ___" << fixedParam << ";"; - out << nl << "for(___" << fixedParam << " = " << fixedParam << ".begin(); ___" << fixedParam << " != " - << fixedParam << ".end(); ++___" << fixedParam << ")"; - out << sb; - writeStreamMarshalUnmarshalCode(out, seq->type(), "(*___" + fixedParam + ")", false); - out << eb; - } - } - else - { - bool protobuf; - seqType = findMetaData(seq, seq->getMetaData(), false, protobuf); - builtin = BuiltinPtr::dynamicCast(seq->type()); - if(protobuf || !seqType.empty() || !builtin || (builtin->kind() == Builtin::KindObject || - builtin->kind() == Builtin::KindObjectProxy)) - { - string scope = fixKwd(seq->scope()); - if(marshal) - { - out << nl << scope << "ice_write" << seq->name() << '(' << stream << ", " << fixedParam << ");"; - } - else - { - out << nl << scope << "ice_read" << seq->name() << '(' << stream << ", " << fixedParam << ");"; - } - } - else - { - switch(builtin->kind()) - { - case Builtin::KindByte: - { - if(marshal) - { - out << nl << stream << "->writeByteSeq(" << fixedParam << ");"; - } - else - { - out << nl << fixedParam << " = " << stream << "->readByteSeq();"; - } - break; - } - case Builtin::KindBool: - { - if(marshal) - { - out << nl << stream << "->writeBoolSeq(" << fixedParam << ");"; - } - else - { - out << nl << fixedParam << " = " << stream << "->readBoolSeq();"; - } - break; - } - case Builtin::KindShort: - { - if(marshal) - { - out << nl << stream << "->writeShortSeq(" << fixedParam << ");"; - } - else - { - out << nl << fixedParam << " = " << stream << "->readShortSeq();"; - } - break; - } - case Builtin::KindInt: - { - if(marshal) - { - out << nl << stream << "->writeIntSeq(" << fixedParam << ");"; - } - else - { - out << nl << fixedParam << " = " << stream << "->readIntSeq();"; - } - break; - } - case Builtin::KindLong: - { - if(marshal) - { - out << nl << stream << "->writeLongSeq(" << fixedParam << ");"; - } - else - { - out << nl << fixedParam << " = " << stream << "->readLongSeq();"; - } - break; - } - case Builtin::KindFloat: - { - if(marshal) - { - out << nl << stream << "->writeFloatSeq(" << fixedParam << ");"; - } - else - { - out << nl << fixedParam << " = " << stream << "->readFloatSeq();"; - } - break; - } - case Builtin::KindDouble: - { - if(marshal) - { - out << nl << stream << "->writeDoubleSeq(" << fixedParam << ");"; - } - else - { - out << nl << fixedParam << " = " << stream << "->readDoubleSeq();"; - } - break; - } - case Builtin::KindString: - { - string strType = findMetaData(seq->typeMetaData(), true); - if(strType != "string" && (useWstring || strType == "wstring")) - { - if(marshal) - { - out << nl << stream << "->writeWstringSeq(" << fixedParam << ");"; - } - else - { - out << nl << fixedParam << " = " << stream << "->readWstringSeq();"; - } - } - else - { - if(marshal) - { - out << nl << stream << "->writeStringSeq(" << fixedParam << ");"; - } - else - { - out << nl << fixedParam << " = " << stream << "->readStringSeq();"; - } - } - break; - } - case Builtin::KindObject: - case Builtin::KindObjectProxy: - case Builtin::KindLocalObject: - { - assert(false); - break; - } - } - } - } - - return; - } - - DictionaryPtr dict = DictionaryPtr::dynamicCast(type); - if(dict) - { - string scope = fixKwd(dict->scope()); - if(marshal) - { - out << nl << scope << "ice_write" << dict->name() << "(" << stream << ", " << fixedParam << ");"; - } - else - { - out << nl << scope << "ice_read" << dict->name() << "(" << stream << ", " << fixedParam << ");"; - } - - return; - } - - EnumPtr en = EnumPtr::dynamicCast(type); - if(en) - { - string scope = fixKwd(en->scope()); - if(marshal) - { - out << nl << scope << "ice_write" << en->name() << "(" << stream << ", " << fixedParam << ");"; - } - else - { - out << nl << scope << "ice_read" << en->name() << "(" << stream << ", " << fixedParam << ");"; - } - - return; - } - - ProxyPtr prx = ProxyPtr::dynamicCast(type); - if(prx) + else { - ClassDeclPtr cls = prx->_class(); - string scope = fixKwd(cls->scope()); - if(marshal) - { - out << nl << scope << "ice_write" << cls->name() << "Prx(" << stream << ", " << fixedParam << ");"; - } - else - { - out << nl << scope << "ice_read" << cls->name() << "Prx(" << stream << ", " << fixedParam << ");"; - } - - return; + out << nl << stream << "->read(" << fixedParam << ");"; } - - assert(false); } // Accepted metadata. diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 774d1766bc5..18369db167e 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -260,8 +260,6 @@ Slice::Gen::generate(const UnitPtr& p) if(_stream || p->hasNonLocalClassDefs() || p->hasNonLocalExceptions()) { - H << "\n#include <Ice/StreamF.h>"; - if(!p->hasNonLocalClassDefs()) { C << "\n#include <Ice/LocalException.h>"; @@ -269,7 +267,7 @@ Slice::Gen::generate(const UnitPtr& p) if(_stream) { - C << "\n#include <Ice/Stream.h>"; + H << "\n#include <Ice/Stream.h>"; } } @@ -364,6 +362,11 @@ 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); + } if(_impl) { implH << "\n#include <"; @@ -698,9 +701,20 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) H << sp << nl << "virtual void __write(::IceInternal::BasicStream*) const;"; H << nl << "virtual void __read(::IceInternal::BasicStream*, bool);"; + + H.zeroIndent(); + H << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + H.restoreIndent(); + H << nl << "//Stream api is not supported in VC++ 6"; + H.zeroIndent(); + H << nl << "#else"; + 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(); + C << sp << nl << "void" << nl << scoped.substr(2) << "::__write(::IceInternal::BasicStream* __os) const"; C << sb; C << nl << "__os->write(::std::string(\"" << p->scoped() << "\"), false);"; @@ -737,6 +751,13 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) if(_stream) { + C.zeroIndent(); + C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + C.restoreIndent(); + C << nl << "//Stream api is not supported in VC++ 6"; + C.zeroIndent(); + C << nl << "#else"; + C.restoreIndent(); C << sp << nl << "void" << nl << scoped.substr(2) << "::__write(const ::Ice::OutputStreamPtr& __outS) const"; C << sb; @@ -773,12 +794,22 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) emitUpcall(base, "::__read(__inS, true);"); } C << eb; + C.zeroIndent(); + C << nl << "#endif"; + C.restoreIndent(); } else { // // Emit placeholder functions to catch errors. // + C.zeroIndent(); + C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + C.restoreIndent(); + C << nl << "//Stream api is not supported in VC++ 6"; + C.zeroIndent(); + C << nl << "#else"; + C.restoreIndent(); C << sp << nl << "void" << nl << scoped.substr(2) << "::__write(const ::Ice::OutputStreamPtr&) const"; C << sb; C << nl << "Ice::MarshalException ex(__FILE__, __LINE__);"; @@ -792,6 +823,10 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) 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()) @@ -1020,8 +1055,18 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) if(_stream) { + H.zeroIndent(); + H << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + H.restoreIndent(); + H << nl << "//Stream api is not supported in VC++ 6"; + H.zeroIndent(); + H << nl << "#else"; + H.restoreIndent(); H << sp << 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(); } C << sp << nl << "void" << nl << scoped.substr(2) << "::__write(::IceInternal::BasicStream* __os) const"; @@ -1042,6 +1087,13 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) if(_stream) { + C.zeroIndent(); + C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + C.restoreIndent(); + C << nl << "//Stream api is not supported in VC++ 6"; + C.zeroIndent(); + C << nl << "#else"; + C.restoreIndent(); C << sp << nl << "void" << nl << scoped.substr(2) << "::ice_write(const ::Ice::OutputStreamPtr& __outS) const"; C << sb; @@ -1060,6 +1112,9 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) (*q)->getMetaData()); } C << eb; + C.zeroIndent(); + C << nl << "#endif"; + C.restoreIndent(); } } @@ -1070,11 +1125,28 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) if(!p->isLocal() && _stream) { + H.zeroIndent(); + H << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + H.restoreIndent(); + H << nl << "//Stream api is not supported in VC++ 6"; + H.zeroIndent(); + H << nl << "#else"; + H.restoreIndent(); H << sp << 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.zeroIndent(); + C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + C.restoreIndent(); + C << nl << "//Stream api is not supported in VC++ 6"; + C.zeroIndent(); + C << nl << "#else"; + C.restoreIndent(); C << sp << nl << "void" << nl << scope.substr(2) << "ice_write" << p->name() << "(const ::Ice::OutputStreamPtr& __outS, const " << fixKwd(p->scoped() + "Ptr") << "& __v)"; C << sb; @@ -1086,16 +1158,36 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) C << sb; C << nl << "__v->ice_read(__inS);"; C << eb; + C.zeroIndent(); + C << nl << "#endif"; + C.restoreIndent(); } } else { if(!p->isLocal() && _stream) { + H.zeroIndent(); + H << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + H.restoreIndent(); + H << nl << "//Stream api is not supported in VC++ 6"; + H.zeroIndent(); + H << nl << "#else"; + H.restoreIndent(); H << sp << 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.zeroIndent(); + C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + C.restoreIndent(); + C << nl << "//Stream api is not supported in VC++ 6"; + C.zeroIndent(); + C << nl << "#else"; + C.restoreIndent(); C << sp << nl << "void" << nl << scope.substr(2) << "ice_write" << p->name() << "(const ::Ice::OutputStreamPtr& __outS, const " << scoped << "& __v)"; C << sb; @@ -1107,6 +1199,9 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) C << sb; C << nl << "__v.ice_read(__inS);"; C << eb; + C.zeroIndent(); + C << nl << "#endif"; + C.restoreIndent(); } } @@ -1186,10 +1281,20 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p) if(_stream) { - H << nl << _dllExport << "void ice_write" << p->name() << "(const ::Ice::OutputStreamPtr&, const " + H.zeroIndent(); + H << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + H.restoreIndent(); + H << nl << "//Stream api is not supported in VC++ 6"; + H.zeroIndent(); + H << nl << "#else"; + H.restoreIndent(); + H << nl << _dllExport << "ICE_DEPRECATED_API void ice_write" << p->name() << "(const ::Ice::OutputStreamPtr&, const " << typeName << "&);"; - H << nl << _dllExport << "void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << 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 << @@ -1280,6 +1385,13 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p) if(_stream) { + C.zeroIndent(); + C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + C.restoreIndent(); + C << nl << "//Stream api is not supported in VC++ 6"; + C.zeroIndent(); + C << nl << "#else"; + C.restoreIndent(); C << sp << nl << "void" << nl << scope.substr(2) << "ice_write" << p->name() << "(const ::Ice::OutputStreamPtr& __outS, const " << scopedName << "& v)"; C << sb; @@ -1328,6 +1440,9 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p) C << eb; } C << eb; + C.zeroIndent(); + C << nl << "#endif"; + C.restoreIndent(); } } else if(!builtin || builtin->kind() == Builtin::KindObject || builtin->kind() == Builtin::KindObjectProxy) @@ -1338,10 +1453,20 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p) if(_stream) { - H << nl << _dllExport << "void ice_write" << p->name() << "(const ::Ice::OutputStreamPtr&, const " + H.zeroIndent(); + H << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + H.restoreIndent(); + H << nl << "//Stream api is not supported in VC++ 6"; + H.zeroIndent(); + H << nl << "#else"; + H.restoreIndent(); + H << nl << _dllExport << "ICE_DEPRECATED_API void ice_write" << p->name() << "(const ::Ice::OutputStreamPtr&, const " << name << "&);"; - H << nl << _dllExport << "void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << 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 @@ -1404,6 +1529,13 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p) if(_stream) { + C.zeroIndent(); + C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + C.restoreIndent(); + C << nl << "//Stream api is not supported in VC++ 6"; + C.zeroIndent(); + C << nl << "#else"; + C.restoreIndent(); C << sp << nl << "void" << nl << scope.substr(2) << "ice_write" << p->name() << "(const ::Ice::OutputStreamPtr& __outS, const " << scoped << "& v)"; C << sb; @@ -1425,6 +1557,9 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p) writeStreamMarshalUnmarshalCode(C, type, "v[i]", false, "", _useWstring); C << eb; C << eb; + C.zeroIndent(); + C << nl << "#endif"; + C.restoreIndent(); } } } @@ -1470,9 +1605,19 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p) if(_stream) { - H << nl << _dllExport << "void ice_write" << p->name() << "(const ::Ice::OutputStreamPtr&, const " << name + H.zeroIndent(); + H << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + H.restoreIndent(); + H << nl << "//Stream api is not supported in VC++ 6"; + H.zeroIndent(); + H << nl << "#else"; + H.restoreIndent(); + H << nl << _dllExport << "ICE_DEPRECATED_API void ice_write" << p->name() << "(const ::Ice::OutputStreamPtr&, const " << name << "&);"; - H << nl << _dllExport << "void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << 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 @@ -1504,6 +1649,13 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p) if(_stream) { + C.zeroIndent(); + C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + C.restoreIndent(); + C << nl << "//Stream api is not supported in VC++ 6"; + C.zeroIndent(); + C << nl << "#else"; + C.restoreIndent(); C << sp << nl << "void" << nl << scope.substr(2) << "ice_write" << p->name() << "(const ::Ice::OutputStreamPtr& __outS, const " << scoped << "& v)"; C << sb; @@ -1528,6 +1680,9 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p) writeStreamMarshalUnmarshalCode(C, valueType, "__i->second", false, "", _useWstring, p->valueMetaData()); C << eb; C << eb; + C.zeroIndent(); + C << nl << "#endif"; + C.restoreIndent(); } } } @@ -1563,9 +1718,19 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) if(_stream) { - H << sp << nl << _dllExport << "void ice_write" << p->name() + H.zeroIndent(); + H << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + H.restoreIndent(); + H << nl << "//Stream api is not supported in VC++ 6"; + H.zeroIndent(); + H.restoreIndent(); + H << nl << "#else"; + H << sp << nl << _dllExport << "ICE_DEPRECATED_API void ice_write" << p->name() << "(const ::Ice::OutputStreamPtr&, " << name << ");"; - H << nl << _dllExport << "void ice_read" << p->name() << "(const ::Ice::InputStreamPtr&, " << 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 @@ -1606,6 +1771,13 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) if(_stream) { + C.zeroIndent(); + C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + C.restoreIndent(); + C << nl << "//Stream api is not supported in VC++ 6"; + C.zeroIndent(); + C.restoreIndent(); + C << nl << "#else"; C << sp << nl << "void" << nl << scope.substr(2) << "ice_write" << p->name() << "(const ::Ice::OutputStreamPtr& __outS, " << scoped << " v)"; C << sb; @@ -1658,6 +1830,9 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) C << eb; C << nl << "v = static_cast< " << scoped << ">(val);"; C << eb; + C.zeroIndent(); + C << nl << "#endif"; + C.restoreIndent(); } } } @@ -3734,9 +3909,21 @@ 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 << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + H.restoreIndent(); + H << nl << "//Stream api is not supported in VC++ 6"; + H.zeroIndent(); + H << nl << "#else"; + 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(); + C << sp; C << nl << "void" << nl << scoped.substr(2) << "::__write(::IceInternal::BasicStream* __os) const"; @@ -3771,6 +3958,13 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) if(_stream) { + C.zeroIndent(); + C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + C.restoreIndent(); + C << nl << "//Stream api is not supported in VC++ 6"; + C.zeroIndent(); + C << nl << "#else"; + C.restoreIndent(); C << sp; C << nl << "void" << nl << scoped.substr(2) << "::__write(const ::Ice::OutputStreamPtr& __outS) const"; C << sb; @@ -3800,9 +3994,19 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) C << nl << "__inS->endSlice();"; emitUpcall(base, "::__read(__inS, true);"); C << eb; + C.zeroIndent(); + C << nl << "#endif"; + C.restoreIndent(); } else { + C.zeroIndent(); + C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + C.restoreIndent(); + C << nl << "//Stream api is not supported in VC++ 6"; + C.zeroIndent(); + C << nl << "#else"; + C.restoreIndent(); // // Emit placeholder functions to catch errors. // @@ -3820,6 +4024,9 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) 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()) @@ -4739,15 +4946,25 @@ Slice::Gen::HandleVisitor::visitClassDecl(const ClassDeclPtr& p) H << nl << _dllExport << "void __patch__" << name << "Ptr(void*, ::Ice::ObjectPtr&);"; if(_stream) { + H.zeroIndent(); + H << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + H.restoreIndent(); + H << nl << "//Stream api is not supported in VC++ 6"; + H.zeroIndent(); + H << nl << "#else"; + H.restoreIndent(); H << sp; - H << nl << _dllExport << "void ice_write" << name << "Prx(const ::Ice::OutputStreamPtr&, const " << name + H << nl << _dllExport << "ICE_DEPRECATED_API void ice_write" << name << "Prx(const ::Ice::OutputStreamPtr&, const " << name << "Prx&);"; - H << nl << _dllExport << "void ice_read" << name << "Prx(const ::Ice::InputStreamPtr&, " << name + H << nl << _dllExport << "ICE_DEPRECATED_API void ice_read" << name << "Prx(const ::Ice::InputStreamPtr&, " << name << "Prx&);"; - H << nl << _dllExport << "void ice_write" << name << "(const ::Ice::OutputStreamPtr&, const " + H << nl << _dllExport << "ICE_DEPRECATED_API void ice_write" << name << "(const ::Ice::OutputStreamPtr&, const " << name << "Ptr&);"; - H << nl << _dllExport << "void ice_read" << name << "(const ::Ice::InputStreamPtr&, " << name << "Ptr&);"; + H << nl << _dllExport << "ICE_DEPRECATED_API void ice_read" << name << "(const ::Ice::InputStreamPtr&, " << name << "Ptr&);"; + H.zeroIndent(); + H << nl << "#endif"; + H.restoreIndent(); } } } @@ -4793,6 +5010,13 @@ Slice::Gen::HandleVisitor::visitClassDefStart(const ClassDefPtr& p) if(_stream) { + C.zeroIndent(); + C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + C.restoreIndent(); + C << nl << "//Stream api is not supported in VC++ 6"; + C.zeroIndent(); + C << nl << "#else"; + C.restoreIndent(); C << sp; C << nl << "void" << nl << scope.substr(2) << "ice_write" << name << "Prx(const ::Ice::OutputStreamPtr& __outS, const " << scope << name << "Prx& v)"; @@ -4831,6 +5055,9 @@ Slice::Gen::HandleVisitor::visitClassDefStart(const ClassDefPtr& p) << name << "Ptr, &__v);"; C << nl << "__inS->readObject(__cb);"; C << eb; + C.zeroIndent(); + C << nl << "#endif"; + C.restoreIndent(); } } @@ -5757,6 +5984,95 @@ Slice::Gen::AsyncImplVisitor::visitOperation(const OperationPtr& p) } } +Slice::Gen::StreamVisitor::StreamVisitor(Output& h, Output& c) : + H(h), C(c) +{ + +} + +bool +Slice::Gen::StreamVisitor::visitModuleStart(const ModulePtr&) +{ + H.zeroIndent(); + H << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG + H << nl << "#else"; + H.restoreIndent(); + H << nl << "namespace Ice" << sb; + return true; +} + +void +Slice::Gen::StreamVisitor::visitModuleEnd(const ModulePtr&) +{ + H << eb; + H << nl; + H.zeroIndent(); + H << nl << "#endif"; + H.restoreIndent(); +} + +bool +Slice::Gen::StreamVisitor::visitStructStart(const StructPtr& p) +{ + if(!p->isLocal()) + { + bool classMetaData = findMetaData(p->getMetaData(), false) == "class"; + string scoped = p->scoped(); + H << nl << sp << "template<>"; + if(classMetaData) + { + H << nl << "struct StreamTrait< " << fixKwd(scoped + "Ptr") << " >" << nl; + } + else + { + H << nl << "struct StreamTrait< " << fixKwd(scoped) << " >" << nl; + } + H << sb; + if(classMetaData) + { + H << nl << "static const ::Ice::StreamTraitType type = ::Ice::StreamTraitTypeStructClass;" << nl; + } + else + { + H << nl << "static const ::Ice::StreamTraitType type = ::Ice::StreamTraitTypeStruct;"; + } + H << nl << "static const int enumLimit = 0;"; + H << eb << ";" << nl; + } + return true; +} + +void +Slice::Gen::StreamVisitor::visitStructEnd(const StructPtr&) +{ +} + +void +Slice::Gen::StreamVisitor::visitEnum(const EnumPtr& p) +{ + string scoped = fixKwd(p->scoped()); + H << nl << sp << "template<>" << nl + << "struct StreamTrait< " << scoped << ">" << nl + << sb << 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 << ";" + << eb << ";" << nl; +} + void Slice::Gen::validateMetaData(const UnitPtr& u) { diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h index cca39fcdbc3..2a70c01c66f 100644 --- a/cpp/src/slice2cpp/Gen.h +++ b/cpp/src/slice2cpp/Gen.h @@ -387,6 +387,24 @@ private: bool _useWstring; std::list<bool> _useWstringHist; }; + + class StreamVisitor : private ::IceUtil::noncopyable, public ParserVisitor + { + public: + + StreamVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&); + + virtual bool visitModuleStart(const ModulePtr&); + virtual void visitModuleEnd(const ModulePtr&); + virtual bool visitStructStart(const StructPtr&); + virtual void visitStructEnd(const StructPtr&); + virtual void visitEnum(const EnumPtr&); + + private: + + ::IceUtilInternal::Output& H; + ::IceUtilInternal::Output& C; + }; private: |