diff options
author | Michi Henning <michi@zeroc.com> | 2004-09-17 05:23:37 +0000 |
---|---|---|
committer | Michi Henning <michi@zeroc.com> | 2004-09-17 05:23:37 +0000 |
commit | b7d910a615587cf296fac580b138d9a5b7d1c44b (patch) | |
tree | 4be272d17b0a85a9b157283d44f3fe5bf49f2e8a /cpp/src | |
parent | transfer data members of more local exceptions (diff) | |
download | ice-b7d910a615587cf296fac580b138d9a5b7d1c44b.tar.bz2 ice-b7d910a615587cf296fac580b138d9a5b7d1c44b.tar.xz ice-b7d910a615587cf296fac580b138d9a5b7d1c44b.zip |
Fixed bugs in sequence code generation for slice2cs and slice2vb.
Diffstat (limited to 'cpp/src')
-rwxr-xr-x | cpp/src/Slice/CsUtil.cpp | 30 | ||||
-rwxr-xr-x | cpp/src/Slice/VbUtil.cpp | 56 | ||||
-rwxr-xr-x | cpp/src/slice2vb/Gen.cpp | 73 |
3 files changed, 122 insertions, 37 deletions
diff --git a/cpp/src/Slice/CsUtil.cpp b/cpp/src/Slice/CsUtil.cpp index 075274b38fe..c5c94d78366 100755 --- a/cpp/src/Slice/CsUtil.cpp +++ b/cpp/src/Slice/CsUtil.cpp @@ -181,6 +181,23 @@ Slice::CsGenerator::typeToString(const TypePtr& type) return "???"; } +static string +toArrayAlloc(const string& decl, const string& sz) +{ + int count = 0; + string::size_type pos = decl.size(); + while(pos > 1 && decl.substr(pos - 2, 2) == "[]") + { + ++count; + pos -= 2; + } + assert(count > 0); + + ostringstream o; + o << decl.substr(0, pos) << '[' << sz << ']' << decl.substr(pos + 2); + return o.str(); +} + bool Slice::CsGenerator::isValueType(const TypePtr& type) { @@ -550,6 +567,7 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << stream << ".checkSeq();"; out << nl << stream << ".endElement();"; out << eb; + out << nl << stream << ".endSeq(__len);"; } break; } @@ -602,7 +620,7 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << param << " = new "; if(isArray) { - out << typeS << "[sz]"; + out << toArrayAlloc(typeS + "[]", "sz"); } else { @@ -617,6 +635,7 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << stream << ".checkSeq();"; out << nl << stream << ".endElement();"; out << eb; + out << nl << stream << ".endSeq(sz);"; out << eb; } return; @@ -641,7 +660,7 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << param << " = new "; if(isArray) { - out << typeS << "[sz]"; + out << toArrayAlloc(typeS + "[]", "sz"); } else { @@ -657,6 +676,7 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << stream << ".endElement();"; } out << eb; + out << nl << stream << ".endSeq(sz);"; out << eb; } return; @@ -682,7 +702,7 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << param << " = new "; if(isArray) { - out << typeS << "[sz]"; + out << toArrayAlloc(typeS + "[]", "sz"); } else { @@ -700,6 +720,7 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << param << ".Add((" << typeS << ')' << stream << ".readByte());"; } out << eb; + out << nl << stream << ".endSeq(sz);"; out << eb; } return; @@ -723,7 +744,7 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << param << " = new "; if(isArray) { - out << typeS << "[sz]"; + out << toArrayAlloc(typeS + "[]", "sz"); } else { @@ -749,6 +770,7 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << stream << ".endElement();"; } out << eb; + out << nl << stream << ".endSeq(sz);"; out << eb; } diff --git a/cpp/src/Slice/VbUtil.cpp b/cpp/src/Slice/VbUtil.cpp index 75681aa38d7..ef139252589 100755 --- a/cpp/src/Slice/VbUtil.cpp +++ b/cpp/src/Slice/VbUtil.cpp @@ -191,6 +191,23 @@ Slice::VbGenerator::typeToString(const TypePtr& type) return "???"; } +static string +toArrayAlloc(const string& decl, const string& sz) +{ + int count = 0; + string::size_type pos = decl.size(); + while(pos > 1 && decl.substr(pos - 2, 2) == "()") + { + ++count; + pos -= 2; + } + assert(count > 0); + + ostringstream o; + o << decl.substr(0, pos) << '(' << sz << ')' << decl.substr(pos + 2); + return o.str(); +} + bool Slice::VbGenerator::isValueType(const TypePtr& type) { @@ -341,7 +358,7 @@ Slice::VbGenerator::writeMarshalUnmarshalCode(Output &out, { if(marshal) { - out << nl << stream << ".writeObject(" << param << ")"; + out << nl << stream << ".writeObject(" << param << ')'; } else { @@ -362,7 +379,7 @@ Slice::VbGenerator::writeMarshalUnmarshalCode(Output &out, { if(marshal) { - out << nl << stream << ".writeProxy(" << param << ")"; + out << nl << stream << ".writeProxy(" << param << ')'; } else { @@ -444,17 +461,17 @@ Slice::VbGenerator::writeMarshalUnmarshalCode(Output &out, if(sz <= 0x7f) { func = marshal ? "writeByte" : "readByte"; - cast = marshal ? "(byte)" : fixId(en->scoped()); + cast = marshal ? "Byte" : fixId(en->scoped()); } else if(sz <= 0x7fff) { func = marshal ? "writeShort" : "readShort"; - cast = marshal ? "(short)" : fixId(en->scoped()); + cast = marshal ? "Short" : fixId(en->scoped()); } else { func = marshal ? "writeInt" : "readInt"; - cast = marshal ? "(int)" : fixId(en->scoped()); + cast = marshal ? "Integer" : fixId(en->scoped()); } if(marshal) { @@ -478,11 +495,11 @@ Slice::VbGenerator::writeMarshalUnmarshalCode(Output &out, string helperName = fixId(ContainedPtr::dynamicCast(type)->scoped() + "Helper"); if(marshal) { - out << nl << helperName << ".write(" << stream << ", " << param << ");"; + out << nl << helperName << ".write(" << stream << ", " << param << ')'; } else { - out << nl << param << " = " << helperName << ".read(" << stream << ')' << ';'; + out << nl << param << " = " << helperName << ".read(" << stream << ')'; } } @@ -566,6 +583,7 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, } out << nl << stream << ".checkSeq()"; out << nl << stream << ".endElement()"; + out << nl << stream << ".endSeq(__len)"; } break; } @@ -617,11 +635,11 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << "For __block As Integer = 0 To 1"; out.inc(); out << nl << "Dim sz As Integer = " << stream << ".readSize()"; - out << nl << stream << ".startSeq(sz, " << static_cast<unsigned>(type->minWireSize()) << ")"; + out << nl << stream << ".startSeq(sz, " << static_cast<unsigned>(type->minWireSize()) << ')'; out << nl << param << " = New "; if(isArray) { - out << typeS << "(sz) {}"; + out << toArrayAlloc(typeS + "()", "sz") << " {}"; } else { @@ -636,6 +654,7 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << stream << ".endElement()"; out.dec(); out << nl << "Next"; + out << nl << stream << ".endSeq(sz)"; out.dec(); out << nl << "Next"; } @@ -663,7 +682,7 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << param << " = New "; if(isArray) { - out << typeS << "(sz) {}"; + out << toArrayAlloc(typeS + "()", "sz") << " {}"; } else { @@ -679,6 +698,7 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, } out.dec(); out << nl << "Next"; + out << nl << stream << ".endSeq(sz)"; out.dec(); out << nl << "Next"; } @@ -707,7 +727,7 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << param << " = New "; if(isArray) { - out << typeS << "(sz) {}"; + out << toArrayAlloc(typeS + "()", "sz") << " {}"; } else { @@ -725,13 +745,22 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, } out.dec(); out << nl << "Next"; + out << nl << stream << ".endSeq(sz)"; out.dec(); out << nl << "Next"; } return; } - string helperName = fixId(ContainedPtr::dynamicCast(type)->scoped() + "Helper"); + string helperName; + if(ProxyPtr::dynamicCast(type)) + { + helperName = fixId(ProxyPtr::dynamicCast(type)->_class()->scoped() + "PrxHelper"); + } + else + { + helperName = fixId(ContainedPtr::dynamicCast(type)->scoped() + "Helper"); + } if(marshal) { @@ -753,7 +782,7 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << param << " = New "; if(isArray) { - out << typeS << "(sz) {}"; + out << toArrayAlloc(typeS + "()", "sz") << " {}"; } else { @@ -779,6 +808,7 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, } out.dec(); out << nl << "Next"; + out << nl << stream << ".endSeq(sz)"; out.dec(); out << nl << "Next"; } diff --git a/cpp/src/slice2vb/Gen.cpp b/cpp/src/slice2vb/Gen.cpp index f2dbc084451..48894beb618 100755 --- a/cpp/src/slice2vb/Gen.cpp +++ b/cpp/src/slice2vb/Gen.cpp @@ -114,7 +114,8 @@ Slice::VbVisitor::writeInheritedOperations(const ClassDefPtr& p) { _out << " As " << retS; } - _out << " Implements _" << p->name() << "OperationsNC." << fixId(name); + _out << " Implements " << fixId(containingClass->scope()) << "_" << containingClass->name() + << "OperationsNC." << fixId(name); _out.inc(); _out << nl; if((*op)->returnType()) @@ -127,7 +128,8 @@ Slice::VbVisitor::writeInheritedOperations(const ClassDefPtr& p) _out << sp << nl << "Public MustOverride " << vbOp << ' ' << fixId(name) << spar << params << "ByVal __current As Ice.Current" << epar - << " Implements _" << containingClass->name() << "Operations." << fixId(name); + << " Implements " << fixId(containingClass->scope()) << "_" << containingClass->name() + << "Operations." << fixId(name); } else { @@ -135,7 +137,8 @@ Slice::VbVisitor::writeInheritedOperations(const ClassDefPtr& p) vector<string> args = getArgsAsync(*op); _out << sp << nl << "Public Sub " << ' ' << name << "_async" << spar << params << epar - << " Implements _" << p->name() << "OperationsNC." << name << "_async"; + << " Implements " << fixId(containingClass->scope()) << "_" << containingClass->name() + << "OperationsNC." << name << "_async"; _out.inc(); _out << nl << name << "_async" << spar << args << epar; _out.dec(); @@ -143,7 +146,8 @@ Slice::VbVisitor::writeInheritedOperations(const ClassDefPtr& p) _out << sp << nl << "Public MustOverride Sub " << name << "_async" << spar << params << "ByVal __current As Ice.Current" << epar - << " Implements _" << containingClass->name() << "Operations." << name << "_async"; + << " Implements " << fixId(containingClass->scope()) << "_" << containingClass->name() + << "Operations." << name << "_async"; } } @@ -1185,7 +1189,7 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) DataMemberList allClassMembers = p->allClassDataMembers(); if(allClassMembers.size() != 0) { - _out << sp << nl << "Public NotInheritable Overloads Class __Patcher"; + _out << sp << nl << "Public NotInheritable Class __Patcher"; _out.inc(); _out << nl << "Inherits IceInternal.Patcher"; _out << sp << nl << "Friend Sub New(ByVal instance As Ice.ObjectImpl"; @@ -1761,6 +1765,12 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) _out << nl << "' Bug in VB 7.1: cast to Object should not be necessary."; _out << nl << "__h = 5 * __h + CType(" << memberName << ", Object).GetHashCode()"; } + else if(ProxyPtr::dynamicCast((*q)->type())) + { + _out << nl << "' Bug in VB 7.1: cast should not be necessary."; + _out << nl << "__h = 5 * __h + CType(" << memberName << ", " + << typeToString((*q)->type()) << "Helper).GetHashCode()"; + } else { _out << nl << "__h = 5 * __h + " << memberName << ".GetHashCode()"; @@ -1804,6 +1814,12 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) _out << nl << "If Not CType(" << memberName << ", Object).Equals(CType(__other, " << name << ")." << memberName << ") Then"; } + else if(ProxyPtr::dynamicCast((*q)->type())) + { + _out << nl << "' Bug in VB 7.1: cast should not be necessary."; + _out << nl << "If Not CType(" << memberName << ", " << typeToString((*q)->type()) + << "Helper).Equals(CType(__other, " << name << ")." << memberName << ") Then"; + } else { _out << nl << "If Not " << memberName << ".Equals(CType(__other, " << name << ")." @@ -1873,7 +1889,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) DataMemberList allClassMembers = p->allClassDataMembers(); if(allClassMembers.size() != 0) { - _out << sp << nl << "Public NotInheritable Overloads Class __Patcher"; + _out << sp << nl << "Public NotInheritable Class __Patcher"; _out.inc(); _out << nl << "Inherits IceInternal.Patcher"; _out << sp << nl << "Friend Sub New(ByVal instance As Ice.Exception"; @@ -2056,6 +2072,12 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) _out << nl << "' Bug in VB 7.1: cast to Object should not be necessary."; _out << nl << "__h = 5 * __h + CType(" << memberName << ", Object).GetHashCode()"; } + else if(ProxyPtr::dynamicCast((*q)->type())) + { + _out << nl << "' Bug in VB 7.1: cast should not be necessary."; + _out << nl << "__h = 5 * __h + CType(" << memberName << ", " + << typeToString((*q)->type()) << "Helper).GetHashCode()"; + } else { _out << nl << "__h = 5 * __h + " << memberName << ".GetHashCode()"; @@ -2104,6 +2126,12 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) _out << nl << "If Not CType(" << memberName << ", Object).Equals(CType(__other, " << name << ")." << memberName << ") Then"; } + else if(ProxyPtr::dynamicCast((*q)->type())) + { + _out << nl << "' Bug in VB 7.1: cast should not be necessary."; + _out << nl << "If Not CType(" << memberName << ", " << typeToString((*q)->type()) + << "Helper).Equals(CType(__other, " << name << ")." << memberName << ") Then"; + } else { _out << nl << "If Not " << memberName << ".Equals(CType(__other, " << name << ")." @@ -2177,7 +2205,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) if(classMembers.size() != 0) { - _out << sp << nl << "Public NotInheritable Overloads Class __Patcher"; + _out << sp << nl << "Public NotInheritable Class __Patcher"; _out.inc(); _out << nl << "Inherits IceInternal.Patcher"; _out << sp << nl << "Friend Sub New(ByVal instance As " << name; @@ -2552,6 +2580,11 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p) _out << nl << "' Bug in VB 7.1: cast to Object should not be necessary."; _out << nl << "If Not CType(__vlhs(i), Object).Equals(__vrhs(i))"; } + else if(ProxyPtr::dynamicCast(p->valueType())) + { + _out << nl << "' Bug in VB 7.1: cast should not be necessary."; + _out << nl << "If Not CType(__vlhs(i), " << typeToString(p->valueType()) << "Helper).Equals(__vrhs(i))"; + } else { _out << nl << "If Not __vlhs(i).Equals(__vrhs(i))"; @@ -3050,7 +3083,7 @@ Slice::Gen::HelperVisitor::visitClassDefStart(const ClassDefPtr& p) { _out << " As " << retS; } - _out << " Implements " << name << "Prx." << opName; + _out << " Implements " << name << "Prx." << opName; // TODO: should be containing class? _out.inc(); _out << nl << "Dim __cnt As Integer = 0"; _out << nl << "While True"; @@ -3130,7 +3163,7 @@ Slice::Gen::HelperVisitor::visitClassDefStart(const ClassDefPtr& p) // context parameter // _out << sp << nl << "Public Sub " << opName << "_async" << spar << paramsAMI << epar - << " Implements " << name << "Prx." << opName << "_async"; + << " Implements " << name << "Prx." << opName << "_async"; // TODO: should be containing class? _out.inc(); _out << nl << opName << "_async" << spar << argsAMI << "__defaultContext()" << epar; _out.dec(); @@ -3138,7 +3171,7 @@ Slice::Gen::HelperVisitor::visitClassDefStart(const ClassDefPtr& p) _out << sp << nl << "Public Sub " << opName << "_async" << spar << paramsAMI << "ByVal __ctx As Ice.Context" << epar - << " Implements " << name << "Prx." << opName << "_async"; + << " Implements " << name << "Prx." << opName << "_async"; // TODO: should be containing class? _out.inc(); _out << nl << "__checkTwowayOnly(\"" << p->name() << "\")"; _out << nl << "__cb.__invoke" << spar << "Me" << argsAMI << "__ctx" << epar; @@ -3356,7 +3389,7 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) _out.inc(); string keyArg = "CType(__e.Key, " + keyS + ")"; writeMarshalUnmarshalCode(_out, key, keyArg, true, false); - string valueArg = "CType(__e.Value, " + valueS + ")"; + string valueArg = "__e.Value"; writeMarshalUnmarshalCode(_out, value, valueArg, true, false); _out.dec(); _out << nl << "Next"; @@ -3369,7 +3402,7 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) bool hasClassValue = (builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(value); if(hasClassValue) { - _out << sp << nl << "Public NotInheritable Overloads Class __Patcher"; + _out << sp << nl << "Public NotInheritable Class __Patcher"; _out.inc(); _out << nl << "Inherits IceInternal.Patcher"; _out << sp << nl << "Friend Sub New(ByVal m As " << name << ", ByVal key As " << keyS << ')'; @@ -3606,7 +3639,7 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) { _out << " As " << retS; } - _out << " Implements _" << name << "Del." << opName; + _out << " Implements _" << name << "Del." << opName; // TODO: should be containing class? _out.inc(); _out << nl << "Dim __out As IceInternal.Outgoing = getOutgoing(\"" @@ -3813,7 +3846,7 @@ Slice::Gen::DelegateDVisitor::visitClassDefStart(const ClassDefPtr& p) { _out << " As " << retS; } - _out << " Implements _" << name << "Del." << opName; + _out << " Implements _" << name << "Del." << opName; // TODO: should be containing class? _out.inc(); if(containingClass->hasMetaData("amd") || op->hasMetaData("amd")) { @@ -3957,7 +3990,7 @@ Slice::Gen::DispatcherVisitor::visitClassDefStart(const ClassDefPtr& p) { _out << " As " << typeToString(ret); } - _out << " Implements _" << p->name() << "OperationsNC" << '.' << name; + _out << " Implements _" << p->name() << "OperationsNC" << '.' << name; // TODO: should be containing class? _out.inc(); _out << nl; if(ret) @@ -3978,7 +4011,7 @@ Slice::Gen::DispatcherVisitor::visitClassDefStart(const ClassDefPtr& p) { _out << " As " << typeToString(ret); } - _out << " Implements _" << p->name() << "Operations" << '.' << name; + _out << " Implements _" << p->name() << "Operations" << '.' << name; // TODO: should be containing class? } if(!ops.empty()) @@ -4282,7 +4315,7 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) _out << nl << "End Sub"; _out << sp << nl << "Public Sub ice_response" << spar << paramsAMD << epar - << " Implements " << classNameAMD << '_' << name << ".ice_response"; + << " Implements " << classNameAMD << '_' << name << ".ice_response"; // TODO: should be containing class? _out.inc(); _out << nl << "If Not _finished Then"; _out.inc(); @@ -4319,7 +4352,7 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) _out << nl << "End Sub"; _out << sp << nl << "Public Sub ice_exception(ByVal ex As _System.Exception)" - << " Implements " << classNameAMD << '_' << name << ".ice_exception"; + << " Implements " << classNameAMD << '_' << name << ".ice_exception"; // TODO: should be containing class? _out.inc(); _out << nl << "If Not _finished Then"; _out.inc(); @@ -4672,7 +4705,7 @@ Slice::Gen::BaseImplVisitor::writeOperation(const OperationPtr& op, bool local, { if(forTie) { - _out << " Implements _" << cl->name() << "Operations." << opName << "_async"; + _out << " Implements _" << cl->name() << "Operations." << opName << "_async"; // TODO: should be containing class? } } @@ -4734,7 +4767,7 @@ Slice::Gen::BaseImplVisitor::writeOperation(const OperationPtr& op, bool local, { if(forTie) { - _out << " Implements _" << cl->name() << "Operations." << fixId(opName); + _out << " Implements _" << cl->name() << "Operations." << fixId(opName); // TODO: should be containing class? } } _out.inc(); |