diff options
author | Michi Henning <michi@zeroc.com> | 2004-06-09 08:15:57 +0000 |
---|---|---|
committer | Michi Henning <michi@zeroc.com> | 2004-06-09 08:15:57 +0000 |
commit | e13ad230c87efc7828a1b721f4fffa18513f6de0 (patch) | |
tree | 28d2b97e4234193045bf275c65cdbb38e175493c /cpp/src | |
parent | AIX fix (diff) | |
download | ice-e13ad230c87efc7828a1b721f4fffa18513f6de0.tar.bz2 ice-e13ad230c87efc7828a1b721f4fffa18513f6de0.tar.xz ice-e13ad230c87efc7828a1b721f4fffa18513f6de0.zip |
Tidied up C# code generation. Changed default sequence mapping to array
mapping. Got rid of dead source code. Re-engineered the way patching
works so it's simpler now.
Diffstat (limited to 'cpp/src')
-rwxr-xr-x | cpp/src/Slice/CsUtil.cpp | 218 | ||||
-rwxr-xr-x | cpp/src/slice2cs/Gen.cpp | 143 |
2 files changed, 150 insertions, 211 deletions
diff --git a/cpp/src/Slice/CsUtil.cpp b/cpp/src/Slice/CsUtil.cpp index 00ab7411e43..ad73b92ba51 100755 --- a/cpp/src/Slice/CsUtil.cpp +++ b/cpp/src/Slice/CsUtil.cpp @@ -167,7 +167,7 @@ Slice::CsGenerator::typeToString(const TypePtr& type) } SequencePtr seq = SequencePtr::dynamicCast(type); - if(seq && seq->hasMetaData("cs:array")) + if(seq && !seq->hasMetaData("cs:collection")) { return typeToString(seq->type()) + "[]"; } @@ -216,25 +216,11 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, const TypePtr& type, const string& param, bool marshal, - bool isSeq, bool isOutParam, const string& patchParams) { string stream = marshal ? "__os" : "__is"; - string startAssign; - string endAssign; - if(isSeq) - { - startAssign = ".Add("; - endAssign = ")"; - } - else - { - startAssign = " = "; - endAssign = ""; - } - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); if(builtin) { @@ -248,7 +234,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, } else { - out << nl << param << startAssign << stream << ".readByte()" << endAssign << ";"; + out << nl << param << " = " << stream << ".readByte()" << ';'; } break; } @@ -260,7 +246,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, } else { - out << nl << param << startAssign << stream << ".readBool()" << endAssign << ";"; + out << nl << param << " = " << stream << ".readBool()" << ';'; } break; } @@ -272,7 +258,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, } else { - out << nl << param << startAssign << stream << ".readShort()" << endAssign << ";"; + out << nl << param << " = " << stream << ".readShort()" << ';'; } break; } @@ -284,7 +270,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, } else { - out << nl << param << startAssign << stream << ".readInt()" << endAssign << ";"; + out << nl << param << " = " << stream << ".readInt()" << ';'; } break; } @@ -296,7 +282,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, } else { - out << nl << param << startAssign << stream << ".readLong()" << endAssign << ";"; + out << nl << param << " = " << stream << ".readLong()" << ';'; } break; } @@ -308,7 +294,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, } else { - out << nl << param << startAssign << stream << ".readFloat()" << endAssign << ";"; + out << nl << param << " = " << stream << ".readFloat()" << ';'; } break; } @@ -320,7 +306,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, } else { - out << nl << param << startAssign << stream << ".readDouble()" << endAssign << ";"; + out << nl << param << " = " << stream << ".readDouble()" << ';'; } break; } @@ -332,7 +318,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, } else { - out << nl << param << startAssign << stream << ".readString()" << endAssign << ";"; + out << nl << param << " = " << stream << ".readString()" << ';'; } break; } @@ -366,7 +352,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, } else { - out << nl << param << startAssign << stream << ".readProxy()" << endAssign << ";"; + out << nl << param << " = " << stream << ".readProxy()" << ';'; } break; } @@ -389,7 +375,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, } else { - out << nl << param << startAssign << typeS << "Helper.__read(" << stream << ")" << endAssign << ";"; + out << nl << param << " = " << typeS << "Helper.__read(" << stream << ')' << ';'; } return; } @@ -456,11 +442,11 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, } if(marshal) { - out << nl << stream << "." << func << "(" << cast << param << ");"; + out << nl << stream << '.' << func << '(' << cast << param << ");"; } else { - out << nl << param << startAssign << cast << stream << "." << func << "()" << endAssign << ";"; + out << nl << param << " = " << cast << stream << '.' << func << "()" << ';'; } return; } @@ -468,7 +454,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, SequencePtr seq = SequencePtr::dynamicCast(type); if(seq) { - writeSequenceMarshalUnmarshalCode(out, seq, param, marshal, isSeq); + writeSequenceMarshalUnmarshalCode(out, seq, param, marshal); return; } @@ -481,7 +467,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, } else { - out << nl << param << startAssign << typeS << "Helper.read(" << stream << ")" << endAssign << ";"; + out << nl << param << " = " << typeS << "Helper.read(" << stream << ')' << ';'; } } @@ -489,25 +475,16 @@ void Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, const SequencePtr& seq, const string& param, - bool marshal, - bool isSeq) + bool marshal) { string stream = marshal ? "__os" : "__is"; - string startAssign; - string endAssign; - if(isSeq) - { - startAssign = ".Add("; - endAssign = ")"; - } - else - { - startAssign = " = "; - endAssign = ""; - } - TypePtr type = seq->type(); + string typeS = typeToString(type); + + bool isArray = !seq->hasMetaData("cs:collection"); + string limitID = isArray ? "Length" : "Count"; + BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); if(builtin) { @@ -524,21 +501,29 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << eb; out << nl << "else"; out << sb; - out << nl << stream << ".writeSize(" << param << ".Count);"; - out << nl << "for(int __i = 0; __i < " << param << ".Count; ++__i)"; + out << nl << stream << ".writeSize(" << param << '.' << limitID << ");"; + out << nl << "for(int __i = 0; __i < " << param << '.' << limitID << "; ++__i)"; out << sb; string func = builtin->kind() == Builtin::KindObject ? "writeObject" : "writeProxy"; - out << nl << stream << "." << func << "(" << param << "[__i]);"; + out << nl << stream << '.' << func << '(' << param << "[__i]);"; out << eb; out << eb; } else { + out << nl << "int __len = " << stream << ".readSize();"; + out << nl << stream << ".startSeq(__len, " << static_cast<unsigned>(builtin->minWireSize()) << ");"; + out << nl << param << " = new "; if(builtin->kind() == Builtin::KindObject) { - out << nl << param << " = new Ice.ObjectSeq();"; - out << nl << "int __len = " << stream << ".readSize();"; - out << nl << stream << ".startSeq(__len, " << static_cast<unsigned>(builtin->minWireSize()) << ");"; + if(isArray) + { + out << "Ice.Object[__len];"; + } + else + { + out << "Ice.ObjectSeq(__len);"; + } out << nl << "for(int __i = 0; __i < __len; ++__i)"; out << sb; out << nl << stream << ".readObject(new IceInternal.SequencePatcher(" @@ -546,12 +531,17 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, } else { - out << nl << param << " = new Ice.ObjectProxySeq();"; - out << nl << "int __len = " << stream << ".readSize();"; - out << nl << stream << ".startSeq(__len, " << static_cast<unsigned>(builtin->minWireSize()) << ");"; + if(isArray) + { + out << "Ice.ObjectPrx[__len];"; + } + else + { + out << "Ice.ObjectPrxSeq(__len);"; + } out << nl << "for(int __i = 0; __i < __len; ++__i)"; out << sb; - out << nl << param << ".Add(" << stream << ".readProxy());"; + out << nl << param << "[__i] = " << stream << ".readProxy();"; } out << nl << stream << ".checkSeq();"; out << nl << stream << ".endElement();"; @@ -561,9 +551,7 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, } default: { - string typeS = typeToString(type); typeS[0] = toupper(typeS[0]); - bool isArray = seq->hasMetaData("cs:array"); if(marshal) { out << nl << stream << ".write" << typeS << "Seq(" << param; @@ -575,16 +563,15 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, } else { - out << nl << param << startAssign; if(!isArray) { - out << "new " << fixId(seq->scoped()) << "(" << stream << ".read" << typeS << "Seq())"; + out << nl << param << " = new " << fixId(seq->scoped()) + << '(' << stream << ".read" << typeS << "Seq());"; } else { - out << stream << ".read" << typeS << "Seq()"; + out << nl << param << " = " << stream << ".read" << typeS << "Seq();"; } - out << endAssign << ";"; } break; } @@ -597,8 +584,8 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, { if(marshal) { - out << nl << stream << ".writeSize(" << param << ".Count);"; - out << nl << "for(int __i = 0; __i < " << param << ".Count; ++__i)"; + out << nl << stream << ".writeSize(" << param << '.' << limitID << ");"; + out << nl << "for(int __i = 0; __i < " << param << '.' << limitID << "; ++__i)"; out << sb; out << nl << stream << ".writeObject(" << param << "[__i]);"; out << eb; @@ -607,11 +594,20 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, { out << nl << "int sz = " << stream << ".readSize();"; out << nl << stream << ".startSeq(sz, " << static_cast<unsigned>(type->minWireSize()) << ");"; - out << nl << param << " = new " << fixId(seq->scoped()) << "(sz);"; + out << nl << param << " = new "; + if(isArray) + { + out << nl << param << " = new " << typeS << "[sz];"; + } + else + { + out << fixId(seq->scoped()) << "(sz)"; + } + out << ';'; out << nl << "for(int i = 0; i < sz; ++i)"; out << sb; out << nl << "IceInternal.SequencePatcher sp = new IceInternal.SequencePatcher(" - << param << ", " << "typeof(" << typeToString(type) << "), i);"; + << param << ", " << "typeof(" << typeS << "), i);"; out << nl << stream << ".readObject(sp);"; out << nl << stream << ".checkSeq();"; out << nl << stream << ".endElement();"; @@ -625,8 +621,8 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, { if(marshal) { - out << nl << stream << ".writeSize(" << param << ".Count);"; - out << nl << "for(int __i = 0; __i < " << param << ".Count; ++__i)"; + out << nl << stream << ".writeSize(" << param << '.' << limitID << ");"; + out << nl << "for(int __i = 0; __i < " << param << '.' << limitID << "; ++__i)"; out << sb; out << nl << param << "[__i].__write(" << stream << ");"; out << eb; @@ -635,10 +631,18 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, { out << nl << "int sz = " << stream << ".readSize();"; out << nl << stream << ".startSeq(sz, " << static_cast<unsigned>(type->minWireSize()) << ");"; - out << nl << "for(int __i = 0; __i < " << param << ".Count; ++__i)"; + out << nl << param << " = new "; + if(isArray) + { + out << typeS << "[sz]"; + } + else + { + out << typeS << "(sz)"; + } + out << ';'; + out << nl << "for(int __i = 0; __i < " << param << '.' << limitID << "; ++__i)"; out << sb; - string typeS = typeToString(st); - out << nl << param << ".Add(new " << typeS << "());"; out << nl << param << "[__i].__read(" << stream << ");"; if(st->isVariableLength()) { @@ -656,60 +660,75 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, { if(marshal) { - out << nl << stream << ".writeSize(" << param << ".Count);"; - out << nl << "for(int __i = 0; __i < " << param << ".Count; ++__i)"; + out << nl << stream << ".writeSize(" << param << '.'<< limitID << ");"; + out << nl << "for(int __i = 0; __i < " << param << '.' << limitID << "; ++__i)"; out << sb; - writeMarshalUnmarshalCode(out, type, param + "[__i]", marshal, true); + out << nl << stream << ".writeByte((byte)" << param << "[__i]);"; out << eb; } else { - out << nl << param << startAssign << "new " << fixId(seq->scoped()) << "()" << endAssign << ";"; out << nl << "int sz = " << stream << ".readSize();"; out << nl << stream << ".startSeq(sz, " << static_cast<unsigned>(type->minWireSize()) << ");"; + out << nl << param << " = new "; + if(isArray) + { + out << typeS << "[sz]"; + } + else + { + out << fixId(seq->scoped()) << "(sz)"; + } + out << ';'; out << nl << "for(int __i = 0; __i < sz; ++__i)"; out << sb; - writeMarshalUnmarshalCode(out, type, param, marshal, true); + if(isArray) + { + out << nl << param << " = (" << typeS << ')' << stream << ".readByte();"; + } + else + { + out << nl << param << ".Add((" << typeS << ')' << stream << ".readByte());"; + } out << eb; } return; } - string typeS = typeToString(type); - bool seqIsArray = seq->hasMetaData("cs:array"); if(marshal) { string func = ProxyPtr::dynamicCast(type) ? "__write" : "write"; - out << nl << stream << ".writeSize(" << param << (seqIsArray ? ".Length);" : ".Count);"); - out << nl << "for(int __i = 0; __i < " << param << (seqIsArray ? ".Length" : ".Count") << "; ++__i)"; + out << nl << stream << ".writeSize(" << param << '.' << limitID << ");"; + out << nl << "for(int __i = 0; __i < " << param << '.' << limitID << "; ++__i)"; out << sb; - out << nl << typeS << "Helper." << func << "(" << stream << ", " << param << "[__i]);"; + out << nl << typeS << "Helper." << func << '(' << stream << ", " << param << "[__i]);"; out << eb; } else { string func = ProxyPtr::dynamicCast(type) ? "__read" : "read"; - if(!seqIsArray) - { - out << nl << param << startAssign << "new " << fixId(seq->scoped()) << "()" << endAssign << ";"; - } out << sb; out << nl << "int sz = " << stream << ".readSize();"; out << nl << stream << ".startSeq(sz, " << static_cast<unsigned>(type->minWireSize()) << ");"; - if(seqIsArray) + out << nl << param << " = new "; + if(isArray) { - out << nl << param << " = new " << typeS << "[sz];"; + out << typeS << "[sz]"; } + else + { + out << fixId(seq->scoped()) << "(sz)"; + } + out << ';'; out << nl << "for(int __i = 0; __i < sz; ++__i)"; out << sb; - if(!seqIsArray) + if(isArray) { - out << nl << param << ".Add(" << typeS << "Helper." << func << "(" << stream << "));"; + out << nl << param << "[__i] = " << typeS << "Helper." << func << '(' << stream << ");"; } else { - out << nl << param << "[__i]" << startAssign << typeS << "Helper." << func << "(" << stream << ")" - << endAssign << ";"; + out << nl << param << ".Add(" << typeS << "Helper." << func << '(' << stream << "));"; } if(type->isVariableLength()) { @@ -737,7 +756,12 @@ bool Slice::CsGenerator::MetaDataVisitor::visitModuleStart(const ModulePtr& p) { validate(p); - return false; + return true; +} + +void +Slice::CsGenerator::MetaDataVisitor::visitModuleEnd(const ModulePtr&) +{ } void @@ -840,25 +864,17 @@ Slice::CsGenerator::MetaDataVisitor::validate(const ContainedPtr& cont) string s = *p; if(_history.count(s) == 0) { - bool valid = true; if(s.find(prefix) == 0) { if(SequencePtr::dynamicCast(cont)) { - if(s.substr(prefix.size()) != "array") + if(s.substr(prefix.size()) == "collection") { - valid = false; + continue; } } - else - { - valid = false; - } - } - if(!valid) - { cout << file << ": warning: ignoring invalid metadata `" << s << "'" << endl; - } + } _history.insert(s); } } diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 8aafdc6faa3..1c878cb0ec3 100755 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -262,7 +262,7 @@ Slice::CsVisitor::writeDispatch(const ClassDefPtr& p) { _out << nl << typeS << ' ' << param << ';'; } - writeMarshalUnmarshalCode(_out, q->first, param, false, false, true); + writeMarshalUnmarshalCode(_out, q->first, param, false, true); } if(op->sendsClasses()) { @@ -318,11 +318,11 @@ Slice::CsVisitor::writeDispatch(const ClassDefPtr& p) // for(q = outParams.begin(); q != outParams.end(); ++q) { - writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), true, false, true, ""); + writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), true, true, ""); } if(ret) { - writeMarshalUnmarshalCode(_out, ret, "__ret", true, false, true, ""); + writeMarshalUnmarshalCode(_out, ret, "__ret", true, true, ""); } if(op->returnsClasses()) { @@ -381,7 +381,7 @@ Slice::CsVisitor::writeDispatch(const ClassDefPtr& p) { _out << nl << typeToString(q->first) << ' ' << fixId(q->second) << ';'; } - writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false, false, true); + writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false, true); } if(op->sendsClasses()) { @@ -821,7 +821,6 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) if(p->isInterface()) { _out << sp << nl << "public interface " << name << " : "; - _out.useCurrentPosAsIndent(); if(p->isLocal()) { _out << "Ice.LocalObject"; @@ -840,7 +839,6 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) q++; } } - _out.restoreIndent(); } else { @@ -851,7 +849,6 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) } _out << "class " << name << " : "; - _out.useCurrentPosAsIndent(); if(bases.empty() || bases.front()->isInterface()) { if(p->isLocal()) @@ -879,7 +876,6 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) _out << ',' << nl << fixId((*q)->scoped()); } } - _out.restoreIndent(); } _out << sb; @@ -973,7 +969,7 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) } _out << eb; - _out << sp << nl << "public void" << nl << "patch(Ice.Object v)"; + _out << sp << nl << "public override void patch(Ice.Object v)"; _out << sb; if(allClassMembers.size() > 1) { @@ -989,12 +985,9 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) _out << nl << "case " << memberCount << ":"; _out.inc(); } - if(allClassMembers.size() > 1) - { - _out << nl << "_typeId = \"" << (*d)->type()->typeId() << "\";"; - } string memberName = fixId((*d)->name()); string memberType = typeToString((*d)->type()); + _out << nl << "_type = typeof(" << memberType << ");"; _out << nl << "_instance." << memberName << " = (" << memberType << ")v;"; if(allClassMembers.size() > 1) { @@ -1008,23 +1001,10 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) } _out << eb; - _out << sp << nl << "public string" << nl << "type()"; - _out << sb; - if(allClassMembers.size() > 1) - { - _out << nl << "return _typeId;"; - } - else - { - _out << nl << "return \"" << (*allClassMembers.begin())->type()->typeId() << "\";"; - } - _out << eb; - _out << sp << nl << "private " << name << " _instance;"; if(allClassMembers.size() > 1) { _out << nl << "private int _member;"; - _out << nl << "private string _typeId;"; } _out << eb; } @@ -1051,7 +1031,7 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) patchParams << ", " << classMemberCount++; } } - writeMarshalUnmarshalCode(_out, (*d)->type(), fixId((*d)->name()), false, false, false, patchParams.str()); + writeMarshalUnmarshalCode(_out, (*d)->type(), fixId((*d)->name()), false, false, patchParams.str()); } _out << nl << "__is.endReadSlice();"; _out << nl << "base.__read(__is, true);"; @@ -1228,7 +1208,7 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p) // // No need to generate anything if the sequence is mapped as an array. // - if(p->hasMetaData("cs:array")) + if(!p->hasMetaData("cs:collection")) { return; } @@ -1238,7 +1218,7 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p) bool isValue = isValueType(p->type()); _out << sp << nl << "public class " << name - << " : _System.Collections.CollectionBase, _System.ICloneable, IceInternal.SequenceBase"; + << " : _System.Collections.CollectionBase, _System.ICloneable"; _out << sb; _out << sp << nl << "#region Constructors"; @@ -1469,19 +1449,6 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p) _out << sp << nl << "#endregion"; // Comparison members - _out << sp << nl << "#region SequenceBase members (For Ice-internal use only!"; - - _out << sp << nl << "public void ice_set(int index, object o) // For Ice-internal use only!"; - _out << sb; - _out << nl << "for(int i = InnerList.Count; i <= index; ++i)"; - _out << sb; - _out << nl << "InnerList.Add(null);"; - _out << eb; - _out << nl << "InnerList[index] = (" << s << ")o;"; - _out << eb; - - _out << sp << nl << "#endregion"; // SequenceBase members (For Ice-internal use only!"; - _out << eb; } @@ -1592,7 +1559,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) } _out << eb; - _out << sp << nl << "public void" << nl << "patch(Ice.Object v)"; + _out << sp << nl << "public override void patch(Ice.Object v)"; _out << sb; if(allClassMembers.size() > 1) { @@ -1608,12 +1575,9 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) _out << nl << "case " << memberCount << ":"; _out.inc(); } - if(allClassMembers.size() > 1) - { - _out << nl << "_typeId = \"" << (*q)->type()->typeId() << "\";"; - } string memberName = fixId((*q)->name()); string memberType = typeToString((*q)->type()); + _out << nl << "_type = typeof(" << memberType << ");"; _out << nl << "_instance." << memberName << " = (" << memberType << ")v;"; if(allClassMembers.size() > 1) { @@ -1627,22 +1591,10 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) } _out << eb; - _out << sp << nl << "public string type()"; - _out << sb; - if(allClassMembers.size() > 1) - { - _out << nl << "return _typeId;"; - } - else - { - _out << nl << "return \"" << (*allClassMembers.begin())->type()->typeId() << "\";"; - } - _out << eb; _out << sp << nl << "private " << name << " _instance;"; if(allClassMembers.size() > 1) { _out << nl << "private int _member;"; - _out << nl << "private string _typeId;"; } _out << eb; } @@ -1667,7 +1619,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) patchParams << ", " << classMemberCount++; } } - writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name()), false, false, false, patchParams.str()); + writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name()), false, false, patchParams.str()); } _out << nl << "__is.endReadSlice();"; if(base) @@ -1768,7 +1720,11 @@ Slice::Gen::TypesVisitor::visitStructStart(const StructPtr& p) { string name = fixId(p->name()); +#if 1 _out << sp << nl << "public class " << name << " : _System.ICloneable"; +#else + _out << sp << nl << "public struct " << name; +#endif _out << sb; _out << sp << nl << "#region Slice data members"; @@ -1786,6 +1742,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) _out << sp << nl << "#endregion"; // Slice data members +#if 1 _out << sp << nl << "#region ICloneable members"; _out << sp << nl << "public object Clone()"; @@ -1881,6 +1838,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) _out << eb; _out << sp << nl << "#endregion"; // Comparison members +#endif if(!p->isLocal()) { @@ -1914,7 +1872,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) } _out << eb; - _out << sp << nl << "public void" << nl << "patch(Ice.Object v)"; + _out << sp << nl << "public override void patch(Ice.Object v)"; _out << sb; if(classMembers.size() > 1) { @@ -1930,12 +1888,9 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) _out << nl << "case " << memberCount << ":"; _out.inc(); } - if(classMembers.size() > 1) - { - _out << nl << "_typeId = \"" << (*q)->type()->typeId() << "\";"; - } string memberName = fixId((*q)->name()); string memberType = typeToString((*q)->type()); + _out << nl << "_type = typeof(" << memberType << ");"; _out << nl << "_instance." << memberName << " = (" << memberType << ")v;"; if(classMembers.size() > 1) { @@ -1949,23 +1904,10 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) } _out << eb; - _out << sp << nl << "public string type()"; - _out << sb; - if(classMembers.size() > 1) - { - _out << nl << "return _typeId;"; - } - else - { - _out << nl << "return \"" << (*classMembers.begin())->type()->typeId() << "\";"; - } - _out << eb; - _out << sp << nl << "private " << name << " _instance;"; if(classMembers.size() > 1) { _out << nl << "private int _member;"; - _out << nl << "private string _typeId;"; } _out << eb; } @@ -1985,7 +1927,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) patchParams << ", " << classMemberCount++; } } - writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name()), false, false, false, patchParams.str()); + writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name()), false, false, patchParams.str()); } _out << eb; @@ -2358,7 +2300,6 @@ Slice::Gen::ProxyVisitor::visitClassDefStart(const ClassDefPtr& p) } else { - _out.useCurrentPosAsIndent(); ClassList::const_iterator q = bases.begin(); while(q != bases.end()) { @@ -2368,7 +2309,6 @@ Slice::Gen::ProxyVisitor::visitClassDefStart(const ClassDefPtr& p) _out << ',' << nl; } } - _out.restoreIndent(); } _out << sb; @@ -2441,7 +2381,6 @@ Slice::Gen::OpsVisitor::visitClassDefStart(const ClassDefPtr& p) if((bases.size() == 1 && bases.front()->isAbstract()) || bases.size() > 1) { _out << " : "; - _out.useCurrentPosAsIndent(); ClassList::const_iterator q = bases.begin(); bool first = true; while(q != bases.end()) @@ -2460,7 +2399,6 @@ Slice::Gen::OpsVisitor::visitClassDefStart(const ClassDefPtr& p) } ++q; } - _out.restoreIndent(); } _out << sb; @@ -2850,22 +2788,13 @@ Slice::Gen::HelperVisitor::visitSequence(const SequencePtr& p) _out << nl << "public static void write(IceInternal.BasicStream __os, " << typeS << " __v)"; _out << sb; - writeSequenceMarshalUnmarshalCode(_out, p, "__v", true, false); + writeSequenceMarshalUnmarshalCode(_out, p, "__v", true); _out << eb; _out << sp << nl << "public static " << typeS << " read(IceInternal.BasicStream __is)"; _out << sb; - bool isArray = p->hasMetaData("cs:array"); - _out << nl << typeS << " __v"; - if(!isArray) - { - _out << " = new " << typeS << "();"; - } - else - { - _out << ";"; - } - writeSequenceMarshalUnmarshalCode(_out, p, "__v", false, false); + _out << nl << typeS << " __v;"; + writeSequenceMarshalUnmarshalCode(_out, p, "__v", false); _out << nl << "return __v;"; _out << eb; @@ -2924,16 +2853,12 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) _out << nl << "_key = key;"; _out << eb; - _out << sp << nl << "public void" << nl << "patch(Ice.Object v)"; + _out << sp << nl << "public override void" << nl << "patch(Ice.Object v)"; _out << sb; + _out << nl << "_type = typeof(" << typeToString(p->valueType()) << ");"; _out << nl << "_m[_key] = (" << valueS << ")v;"; _out << eb; - _out << sp << nl << "public string" << nl << "type()"; - _out << sb; - _out << nl << "return \"" << p->valueType()->typeId() << "\";"; - _out << eb; - _out << sp << nl << "private " << name << " _m;"; _out << nl << "private " << keyS << " _key;"; _out << eb; @@ -2953,7 +2878,7 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) { _out << nl << valueS << " __v;"; } - writeMarshalUnmarshalCode(_out, value, "__v", false, false, false, "__r, __k"); + writeMarshalUnmarshalCode(_out, value, "__v", false, false, "__r, __k"); if(!hasClassValue) { _out << nl << "__r[__k] = __v;"; @@ -3003,7 +2928,6 @@ Slice::Gen::DelegateVisitor::visitClassDefStart(const ClassDefPtr& p) } else { - _out.useCurrentPosAsIndent(); ClassList::const_iterator q = bases.begin(); while(q != bases.end()) { @@ -3013,7 +2937,6 @@ Slice::Gen::DelegateVisitor::visitClassDefStart(const ClassDefPtr& p) _out << ',' << nl; } } - _out.restoreIndent(); } _out << sb; @@ -3175,7 +3098,7 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) } for(q = outParams.begin(); q != outParams.end(); ++q) { - writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false, false, true, ""); + writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false, true, ""); } if(ret) { @@ -3190,7 +3113,7 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) else { _out << nl << retS << " __ret;"; - writeMarshalUnmarshalCode(_out, ret, "__ret", false, false, true, ""); + writeMarshalUnmarshalCode(_out, ret, "__ret", false, true, ""); } } if(op->returnsClasses()) @@ -3571,11 +3494,11 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) _out << eb; for(q = outParams.begin(); q != outParams.end(); ++q) { - writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false, false, true); + writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false, true); } if(ret) { - writeMarshalUnmarshalCode(_out, ret, "__ret", false, false, true); + writeMarshalUnmarshalCode(_out, ret, "__ret", false, true); } if(p->returnsClasses()) { @@ -3677,12 +3600,12 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) for(q = outParams.begin(); q != outParams.end(); ++q) { string typeS = typeToString(q->first); - writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), true, false, false); + writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), true, false); } if(ret) { string retS = typeToString(ret); - writeMarshalUnmarshalCode(_out, ret, "__ret", true, false, false); + writeMarshalUnmarshalCode(_out, ret, "__ret", true, false); } if(p->returnsClasses()) { |