diff options
Diffstat (limited to 'cpp/src')
-rwxr-xr-x | cpp/src/Slice/CsUtil.cpp | 13 | ||||
-rwxr-xr-x | cpp/src/slice2cs/Gen.cpp | 63 |
2 files changed, 52 insertions, 24 deletions
diff --git a/cpp/src/Slice/CsUtil.cpp b/cpp/src/Slice/CsUtil.cpp index 643670836e4..4290a7a1b8b 100755 --- a/cpp/src/Slice/CsUtil.cpp +++ b/cpp/src/Slice/CsUtil.cpp @@ -415,8 +415,8 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, { if(isOutParam) { - out << nl << "IceInternal.ParamPatcher " << param - << "_PP = new IceInternal.ParamPatcher(typeof(Ice.Object), \"::Ice::Object\");"; + out << nl << "IceInternal.ParamPatcher<Ice.Object> " << param + << "_PP = new IceInternal.ParamPatcher<Ice.Object>();"; out << nl << stream << ".readObject("; if(streamingAPI) { @@ -495,8 +495,8 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, if(isOutParam) { ContainedPtr contained = ContainedPtr::dynamicCast(type); - out << nl << "IceInternal.ParamPatcher " << param - << "_PP = new IceInternal.ParamPatcher(typeof(" << typeToString(type) << "), \"" << contained->scoped() << "\");"; + out << nl << "IceInternal.ParamPatcher<" << typeToString(type) << ">" << param + << "_PP = new IceInternal.ParamPatcher<" << typeToString(type) << ">();"; out << nl << stream << ".readObject("; if(streamingAPI) { @@ -802,8 +802,7 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, { patcherName = "Sequence"; } - out << "new IceInternal." << patcherName << "Patcher<" << typeS << ">(" - << param << ", typeof(Ice.Object), ix__));"; + out << "new IceInternal." << patcherName << "Patcher<Ice.Object>(" << param << ", ix__));"; } else { @@ -996,7 +995,7 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, patcherName = "Sequence"; } out << nl << "IceInternal." << patcherName << "Patcher<" << typeS << "> spx = new IceInternal." - << patcherName << "Patcher<" << typeS << ">(" << param << ", " << "typeof(" << typeS << "), ix__);"; + << patcherName << "Patcher<" << typeS << ">(" << param << ", ix__);"; out << nl << stream << ".readObject("; if(streamingAPI) { diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 24df02af591..88c730e8d55 100755 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -673,7 +673,7 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) { _out << "new "; } - _out << "class Patcher__ : IceInternal.Patcher"; + _out << "class Patcher__ : IceInternal.Patcher<" << name << ">"; _out << sb; _out << sp << nl << "internal Patcher__(Ice.ObjectImpl instance"; if(allClassMembers.size() > 1) @@ -709,9 +709,8 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) } string memberName = fixId((*d)->name(), DotNet::ICloneable, true); string memberType = typeToString((*d)->type()); - _out << nl << "type_ = typeof(" << memberType << ");"; _out << nl << "_instance." << memberName << " = (" << memberType << ")v;"; - _out << nl << "_typeId = \"" << (*d)->type()->typeId() << "\";"; + _out << nl << "_typeId = \"" << memberType << "\";"; if(allClassMembers.size() > 1) { _out << nl << "break;"; @@ -1330,7 +1329,7 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) _out << sp << nl << "public " << name << "Helper(Ice.InputStream inS__)"; _out << sb; _out << nl << "_in = inS__;"; - _out << nl << "_pp = new IceInternal.ParamPatcher(typeof(" << scoped << "), \"" << p->scoped() << "\");"; + _out << nl << "_pp = new IceInternal.ParamPatcher<" << scoped << ">();"; _out << eb; _out << sp << nl << "public static void write(Ice.OutputStream outS__, " << fixId(name) << " v__)"; @@ -1352,7 +1351,7 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) _out << eb; _out << sp << nl << "private Ice.InputStream _in;"; - _out << nl << "private IceInternal.ParamPatcher _pp;"; + _out << nl << "private IceInternal.ParamPatcher<" << scoped << "> _pp;"; _out << eb; } @@ -1956,7 +1955,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) { _out << "new "; } - _out << "class Patcher__ : IceInternal.Patcher"; + _out << "class Patcher__ : IceInternal.Patcher<" << name << ">"; _out << sb; _out << sp << nl << "internal Patcher__(Ice.Exception instance"; if(allClassMembers.size() > 1) @@ -1992,9 +1991,8 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) } string memberName = fixId((*q)->name(), DotNet::ApplicationException); string memberType = typeToString((*q)->type()); - _out << nl << "type_ = typeof(" << memberType << ");"; _out << nl << "_instance." << memberName << " = (" << memberType << ")v;"; - _out << nl << "_typeId = \"" << (*q)->type()->typeId() << "\";"; + _out << nl << "_typeId = \"" << memberType << "\";"; if(allClassMembers.size() > 1) { _out << nl << "break;"; @@ -2376,7 +2374,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) if(isClass && classMembers.size() != 0) { - _out << sp << nl << "public sealed class Patcher__ : IceInternal.Patcher"; + _out << sp << nl << "public sealed class Patcher__ : IceInternal.Patcher<" << name << ">"; _out << sb; _out << sp << nl << "internal Patcher__(" << name << " instance"; if(classMembers.size() > 1) @@ -2412,9 +2410,8 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) } string memberType = typeToString((*q)->type()); string memberName = fixId((*q)->name(), isClass ? DotNet::ICloneable : 0); - _out << nl << "type_ = typeof(" << memberType << ");"; _out << nl << "_instance." << memberName << " = (" << memberType << ")v;"; - _out << nl << "_typeId = \"" << (*q)->type()->typeId() << "\";"; + _out << nl << "_typeId = \"" << memberType<< "\";"; if(classMembers.size() > 1) { _out << nl << "break;"; @@ -3415,6 +3412,39 @@ Slice::Gen::HelperVisitor::visitSequence(const SequencePtr& p) } _out << eb; + + string prefix = "clr:generic:"; + string meta; + if(p->findMetaData(prefix, meta)) + { + string type = meta.substr(prefix.size()); + if(type == "List" || type == "LinkedList" || type == "Queue" || type == "Stack") + { + return; + } + BuiltinPtr builtin = BuiltinPtr::dynamicCast(p->type()); + bool isClass = (builtin && builtin->kind() == Builtin::KindObject) + || ClassDeclPtr::dynamicCast(p->type()); + + if(!isClass) + { + return; + } + + // + // The sequence is a custom sequence with elements of class type. + // Emit a dummy class that causes a compile-time error if the + // custom sequence type does not implement an indexer. + // + _out << sp << nl << "public class " << p->name() << "_Tester"; + _out << sb; + _out << nl << p->name() << "_Tester()"; + _out << sb; + _out << nl << typeS << " test = new " << typeS << "();"; + _out << nl << "test[0] = null;"; + _out << eb; + _out << eb; + } } void @@ -3490,7 +3520,7 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) bool hasClassValue = (builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(value); if(hasClassValue) { - _out << sp << nl << "public sealed class Patcher__ : IceInternal.Patcher"; + _out << sp << nl << "public sealed class Patcher__ : IceInternal.Patcher<" << name << ">"; _out << sb; _out << sp << nl << "internal Patcher__(" << name << " m, " << keyS << " key)"; _out << sb; @@ -3500,7 +3530,6 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) _out << sp << nl << "public override void" << nl << "patch(Ice.Object v)"; _out << sb; - _out << nl << "type_ = typeof(" << typeToString(p->valueType()) << ");"; _out << nl << "try"; _out << sb; _out << nl << "_m[_key] = (" << valueS << ")v;"; @@ -3508,8 +3537,8 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) _out << nl << "catch(System.InvalidCastException)"; _out << sb; _out << nl << "Ice.UnexpectedObjectException _e = new Ice.UnexpectedObjectException();"; - _out << nl << "_e.type = v.ice_id();"; - _out << nl << "_e.expectedType = \"" << value->typeId() << "\";"; + _out << nl << "_e.type = v.GetType().FullName;"; + _out << nl << "_e.expectedType = \"" << typeToString(p->valueType()) << "\";"; _out << nl << "throw _e;"; _out << eb; _out << eb; @@ -3884,8 +3913,8 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) { _out << nl << retS << " ret__;"; ContainedPtr contained = ContainedPtr::dynamicCast(ret); - _out << nl << "IceInternal.ParamPatcher ret___PP = new IceInternal.ParamPatcher(typeof(" - << retS << "), \"" << (contained? contained->scoped() : string("::Ice::Object")) << "\");"; + _out << nl << "IceInternal.ParamPatcher<" << retS << "> ret___PP = new IceInternal.ParamPatcher<" + << retS << ">();"; _out << nl << "is__.readObject(ret___PP);"; } else |