From e69370f9717a2eacbb7497be57e169b7b8f8ac3e Mon Sep 17 00:00:00 2001 From: Mark Spruiell Date: Sat, 24 May 2003 04:34:46 +0000 Subject: adding generic sequence patchers; bug fixes --- cpp/src/Slice/JavaUtil.cpp | 107 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 92 insertions(+), 15 deletions(-) (limited to 'cpp/src/Slice/JavaUtil.cpp') diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp index a5b55146e1f..f5a4b92b924 100644 --- a/cpp/src/Slice/JavaUtil.cpp +++ b/cpp/src/Slice/JavaUtil.cpp @@ -584,7 +584,14 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out, } else { - out << nl << stream << ".readObject(new Patcher(" << patchParams << "));"; + if(patchParams.empty()) + { + out << nl << stream << ".readObject(new Patcher());"; + } + else + { + out << nl << stream << ".readObject(new " << patchParams << ");"; + } } } break; @@ -641,7 +648,14 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out, } else { - out << nl << stream << ".readObject(new Patcher(" << patchParams << "));"; + if(patchParams.empty()) + { + out << nl << stream << ".readObject(new Patcher());"; + } + else + { + out << nl << stream << ".readObject(new " << patchParams << ");"; + } } } return; @@ -766,6 +780,14 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, SequencePtr s = SequencePtr::dynamicCast(origContent); while(s) { + // + // Stop if the inner sequence type has metadata. + // + string m = findMetaData(s->getMetaData()); + if(!m.empty()) + { + break; + } depth++; origContent = s->type(); s = SequencePtr::dynamicCast(origContent); @@ -774,6 +796,9 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, if(!listType.empty()) { + // + // Marshal/unmarshal a custom sequence type + // BuiltinPtr b = BuiltinPtr::dynamicCast(seq->type()); if(b && b->kind() != Builtin::KindObject && b->kind() != Builtin::KindObjectProxy) { @@ -880,7 +905,7 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, } case Builtin::KindBool: { - out << nl << o.str() << " __seq" << iter << " = " << stream << ".readByteSeq();"; + out << nl << o.str() << " __seq" << iter << " = " << stream << ".readBoolSeq();"; out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __seq" << iter << ".length; __i" << iter << "++)"; out << sb; @@ -985,17 +1010,37 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, } else { + bool isObject = false; + BuiltinPtr builtin = BuiltinPtr::dynamicCast(origContent); + if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(origContent)) + { + isObject = true; + } out << nl << v << " = new " << listType << "();"; - out << nl << "int __len" << iter << " = " << stream << ".readSize();"; + out << nl << "final int __len" << iter << " = " << stream << ".readSize();"; + if(isObject) + { + if(builtin) + { + out << nl << "final String __type" << iter << " = Ice.ObjectImpl.ice_staticId();"; + } + else + { + out << nl << "final String __type" << iter << " = " << origContentS << ".ice_staticId();"; + } + } out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __len" << iter << "; __i" << iter << "++)"; out << sb; - BuiltinPtr builtin = BuiltinPtr::dynamicCast(origContent); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(origContent)) + if(isObject) { + // + // Add a null value to the list as a placeholder for the element. + // out << nl << v << ".add(null);"; ostringstream patchParams; - patchParams << v << ", __i" << iter; + patchParams << "IceInternal.ListPatcher(" << v << ", " << origContentS << ".class, __type" << iter + << ", __i" << iter << ')'; writeMarshalUnmarshalCode(out, scope, seq->type(), "__elem", false, iter, false, list(), patchParams.str()); } @@ -1005,7 +1050,7 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, writeMarshalUnmarshalCode(out, scope, seq->type(), "__elem", false, iter, false); } iter++; - if((builtin && builtin->kind() != Builtin::KindObject) && !ClassDeclPtr::dynamicCast(origContent)) + if(!isObject) { out << nl << v << ".add(__elem);"; } @@ -1148,7 +1193,23 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, } else { - out << nl << "int __len" << iter << " = " << stream << ".readSize();"; + bool isObject = false; + if((b && b->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(origContent)) + { + isObject = true; + } + out << nl << "final int __len" << iter << " = " << stream << ".readSize();"; + if(isObject) + { + if(b) + { + out << nl << "final String __type" << iter << " = Ice.ObjectImpl.ice_staticId();"; + } + else + { + out << nl << "final String __type" << iter << " = " << origContentS << ".ice_staticId();"; + } + } out << nl << v << " = new " << origContentS << "[__len" << iter << "]"; int d = depth; while(d--) @@ -1162,9 +1223,17 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, ostringstream o; o << v << "[__i" << iter << "]"; ostringstream patchParams; - patchParams << v << ", __i" << iter; - writeMarshalUnmarshalCode(out, scope, seq->type(), o.str(), false, iter, false, - list(), patchParams.str()); + if(isObject) + { + patchParams << "IceInternal.SequencePatcher(" << v << ", " << origContentS + << ".class, __type" << iter << ", __i" << iter << ')'; + writeMarshalUnmarshalCode(out, scope, seq->type(), o.str(), false, iter, false, + list(), patchParams.str()); + } + else + { + writeMarshalUnmarshalCode(out, scope, seq->type(), o.str(), false, iter, false); + } iter++; out << eb; } @@ -1497,6 +1566,14 @@ Slice::JavaGenerator::writeGenericSequenceMarshalUnmarshalCode(Output& out, SequencePtr s = SequencePtr::dynamicCast(origContent); while(s) { + // + // Stop if the inner sequence type has metadata. + // + string m = findMetaData(s->getMetaData()); + if(!m.empty()) + { + break; + } depth++; origContent = s->type(); s = SequencePtr::dynamicCast(origContent); @@ -1613,7 +1690,7 @@ Slice::JavaGenerator::writeGenericSequenceMarshalUnmarshalCode(Output& out, } case Builtin::KindBool: { - out << nl << o.str() << " __seq" << iter << " = " << stream << ".readByteSeq(" << name << ");"; + out << nl << o.str() << " __seq" << iter << " = " << stream << ".readBoolSeq(" << name << ");"; out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __seq" << iter << ".length; __i" << iter << "++)"; out << sb; @@ -1722,7 +1799,7 @@ Slice::JavaGenerator::writeGenericSequenceMarshalUnmarshalCode(Output& out, else { out << nl << v << " = new " << listType << "();"; - out << nl << "int __len" << iter << " = " << stream << ".startReadSequence(" << name << ");"; + out << nl << "final int __len" << iter << " = " << stream << ".startReadSequence(" << name << ");"; out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __len" << iter << "; __i" << iter << "++)"; out << sb; @@ -1873,7 +1950,7 @@ Slice::JavaGenerator::writeGenericSequenceMarshalUnmarshalCode(Output& out, } else { - out << nl << "int __len" << iter << " = " << stream << ".startReadSequence(" << name << ");"; + out << nl << "final int __len" << iter << " = " << stream << ".startReadSequence(" << name << ");"; out << nl << v << " = new " << origContentS << "[__len" << iter << "]"; int d = depth; while(d--) -- cgit v1.2.3