diff --git a/cpp/src/Slice/CsUtil.cpp b/cpp/src/Slice/CsUtil.cpp index 387de74..0f4ff68 100755 --- a/cpp/src/Slice/CsUtil.cpp +++ b/cpp/src/Slice/CsUtil.cpp @@ -479,21 +479,40 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, { if(marshal) { - if(streamingAPI) + if(!isValueType(st)) { - out << nl << param << ".ice_write(" << stream << ");"; + out << nl << "if(" << param << " == null)"; + out << sb; + string typeS = typeToString(st); + out << nl << typeS << " " << "tmp__ = new " << typeS << "();"; + out << nl << "tmp__."; + out << (streamingAPI ? "ice_write" : "write__") << "(" << stream << ");"; + out << eb; + out << nl << "else"; + out << sb; + out << nl << param << "." << (streamingAPI ? "ice_write" : "write__") << "(" << stream << ");"; + out << eb; } else { - out << nl << param << ".write__(" << stream << ");"; + if(streamingAPI) + { + out << nl << param << ".ice_write(" << stream << ");"; + } + else + { + out << nl << param << ".write__(" << stream << ");"; + } } } else { - string typeS = typeToString(type); - if(param.size() < 6 || param.substr(param.size() - 5) != "_prop") + if(!isValueType(st)) { - out << nl << param << " = new " << typeS << "();"; + out << nl << "if(" << param << " == null)"; + out << sb; + out << nl << param << " = new " << typeToString(type) << "();"; + out << eb; } if(streamingAPI) { diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 80c096b..6083631 100755 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -386,6 +386,18 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) if(!isClass) { _out << nl << typeS << ' ' << param << ';'; + StructPtr st = StructPtr::dynamicCast(q->first); + if(st) + { + if(isValueType(q->first)) + { + _out << nl << param << " = new " << typeS << "();"; + } + else + { + _out << nl << param << " = null;"; + } + } } writeMarshalUnmarshalCode(_out, q->first, param, false, false, true); } @@ -501,12 +513,26 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) // for(q = inParams.begin(); q != inParams.end(); ++q) { + string param = fixId(q->second); + string typeS = typeToString(q->first); BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first); bool isClass = (builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(q->first); if(!isClass) { - _out << nl << typeToString(q->first) << ' ' << fixId(q->second) << ';'; + _out << nl << typeS << ' ' << param << ';'; + StructPtr st = StructPtr::dynamicCast(q->first); + if(st) + { + if(isValueType(q->first)) + { + _out << nl << param << " = new " << typeS << "();"; + } + else + { + _out << nl << param << " = null;"; + } + } } writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false, false, true); } @@ -2436,6 +2462,8 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) DataMemberList dataMembers = p->dataMembers(); DataMemberList::const_iterator q; + bool propertyMapping = p->hasMetaData("clr:property"); + _out << sp << nl << "#endregion"; // Slice data members bool isClass = !isValueType(p); @@ -2446,17 +2474,34 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) _out << "s"; _out << sp << nl << "public " << name << "()"; _out << sb; + /* + if(!p->isLocal()) + { + for(q = dataMembers.begin(); q != dataMembers.end(); ++q) + { + if(!isValueType((*q)->type())) + { + string memberName = fixId((*q)->name(), isClass ? DotNet::ICloneable : 0); + string memberType = typeToString((*q)->type()); + _out << nl << "this." << memberName; + if(propertyMapping) + { + _out << "_prop"; + } + _out << " = new " << memberType << "();"; + } + } + } + */ _out << eb; } - bool propertyMapping = p->hasMetaData("clr:property"); - _out << sp << nl << "public " << name << spar; vector paramDecl; vector paramNames; for(q = dataMembers.begin(); q != dataMembers.end(); ++q) { - string memberName = fixId((*q)->name()); + string memberName = fixId((*q)->name(), isClass ? DotNet::ICloneable : 0); string memberType = typeToString((*q)->type()); paramDecl.push_back(memberType + " " + memberName); paramNames.push_back(memberName); @@ -3916,10 +3961,35 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) _out << nl << "for(int i__ = 0; i__ < sz__; ++i__)"; _out << sb; _out << nl << keyS << " k__;"; + StructPtr st = StructPtr::dynamicCast(key); + if(st) + { + if(isValueType(key)) + { + _out << nl << "v__ = new " << typeToString(key) << "();"; + } + else + { + _out << nl << "k__ = null;"; + } + } writeMarshalUnmarshalCode(_out, key, "k__", false, false, false); if(!hasClassValue) { _out << nl << valueS << " v__;"; + + StructPtr st = StructPtr::dynamicCast(value); + if(st) + { + if(isValueType(value)) + { + _out << nl << "v__ = new " << typeToString(value) << "();"; + } + else + { + _out << nl << "v__ = null;"; + } + } } writeMarshalUnmarshalCode(_out, value, "v__", false, false, false, "r__, k__"); if(!hasClassValue) @@ -3956,10 +4026,34 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) _out << nl << "for(int i__ = 0; i__ < sz__; ++i__)"; _out << sb; _out << nl << keyS << " k__;"; + StructPtr st = StructPtr::dynamicCast(key); + if(st) + { + if(isValueType(key)) + { + _out << nl << "v__ = new " << typeToString(key) << "();"; + } + else + { + _out << nl << "k__ = null;"; + } + } writeMarshalUnmarshalCode(_out, key, "k__", false, true, false); if(!hasClassValue) { _out << nl << valueS << " v__;"; + StructPtr st = StructPtr::dynamicCast(value); + if(st) + { + if(isValueType(value)) + { + _out << nl << "v__ = new " << typeToString(value) << "();"; + } + else + { + _out << nl << "v__ = null;"; + } + } } writeMarshalUnmarshalCode(_out, value, "v__", false, true, false, "r__, k__"); if(!hasClassValue) @@ -4192,7 +4286,20 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) _out << eb; for(q = outParams.begin(); q != outParams.end(); ++q) { - writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false, false, true, ""); + string param = fixId(q->second); + StructPtr st = StructPtr::dynamicCast(q->first); + if(st) + { + if(isValueType(q->first)) + { + _out << nl << param << " = new " << typeToString(q->first) << "();"; + } + else + { + _out << nl << param << " = null;"; + } + } + writeMarshalUnmarshalCode(_out, q->first, param, false, false, true, ""); } if(ret) { @@ -4208,6 +4315,18 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) else { _out << nl << retS << " ret__;"; + StructPtr st = StructPtr::dynamicCast(ret); + if(st) + { + if(isValueType(st)) + { + _out << nl << "ret__ = new " << retS << "();"; + } + else + { + _out << nl << "ret__ = null;"; + } + } writeMarshalUnmarshalCode(_out, ret, "ret__", false, false, true, ""); } } @@ -4618,7 +4737,9 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) _out << sb; for(q = outParams.begin(); q != outParams.end(); ++q) { - _out << nl << typeToString(q->first) << ' ' << fixId(q->second) << ';'; + string param = fixId(q->second); + string typeS = typeToString(q->first); + _out << nl << typeS << ' ' << param << ';'; } if(ret) { @@ -4646,10 +4767,33 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) _out << eb; for(q = outParams.begin(); q != outParams.end(); ++q) { + string param = fixId(q->second); + StructPtr st = StructPtr::dynamicCast(q->first); + if(st) + if(isValueType(st)) + { + _out << nl << param << " = new " << typeToString(q->first) << "();"; + } + else + { + _out << nl << param << " = null;"; + } writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false, false, true); } if(ret) { + StructPtr st = StructPtr::dynamicCast(ret); + if(st) + { + if(isValueType(ret)) + { + _out << nl << "ret__ = new " << retS << "();"; + } + else + { + _out << nl << "ret__ = null;"; + } + } writeMarshalUnmarshalCode(_out, ret, "ret__", false, false, true); } if(p->returnsClasses())