summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/CsUtil.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2010-05-25 08:33:27 -0700
committerMark Spruiell <mes@zeroc.com>2010-05-25 08:33:27 -0700
commitcf147b91676c328933d40cd8a5a0913b056cd3d5 (patch)
tree50ceb49b12a77e77de54694629b7bb897a3b0517 /cpp/src/Slice/CsUtil.cpp
parentbug 4752 - allow underscores in Slice identifiers (diff)
downloadice-cf147b91676c328933d40cd8a5a0913b056cd3d5.tar.bz2
ice-cf147b91676c328933d40cd8a5a0913b056cd3d5.tar.xz
ice-cf147b91676c328933d40cd8a5a0913b056cd3d5.zip
bug 4723 - bogus C# code for streaming generic types
Diffstat (limited to 'cpp/src/Slice/CsUtil.cpp')
-rw-r--r--cpp/src/Slice/CsUtil.cpp88
1 files changed, 75 insertions, 13 deletions
diff --git a/cpp/src/Slice/CsUtil.cpp b/cpp/src/Slice/CsUtil.cpp
index ae46f7158fd..b67c237b235 100644
--- a/cpp/src/Slice/CsUtil.cpp
+++ b/cpp/src/Slice/CsUtil.cpp
@@ -717,7 +717,8 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
isCustom = true;
}
}
- bool isArray = !isGeneric && !seq->hasMetaData("clr:collection");
+ bool isCollection = seq->hasMetaData("clr:collection");
+ bool isArray = !isGeneric && !isCollection;
string limitID = isArray ? "Length" : "Count";
BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
@@ -880,28 +881,62 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
break;
}
- typeS[0] = toupper(static_cast<unsigned char>(typeS[0]));
+ string func = typeS;
+ func[0] = toupper(static_cast<unsigned char>(typeS[0]));
if(marshal)
{
- out << nl << stream << ".write" << typeS << "Seq(";
if(isArray)
{
- out << param << ");";
+ out << nl << stream << ".write" << func << "Seq(" << param << ");";
}
- else if(!isGeneric)
+ else if(isCustom || isCollection)
{
- out << param << " == null ? null : " << param << ".ToArray());";
+ if(streamingAPI)
+ {
+ out << nl << stream << ".writeSize(" << param << '.' << limitID << ");";
+ out << nl << "_System.Collections.Generic.IEnumerator<" << typeS
+ << "> e__ = " << param << ".GetEnumerator();";
+ out << nl << "while(e__.MoveNext())";
+ out << sb;
+ out << nl << stream << ".write" << func << "(e__.Current);";
+ out << eb;
+ }
+ else
+ {
+ out << nl << stream << ".write" << func << "Seq(" << param << " == null ? 0 : "
+ << param << ".Count, " << param << ");";
+ }
}
else
{
- out << param << " == null ? 0 : " << param << ".Count, " << param << ");";
+ assert(isGeneric);
+ if(!streamingAPI)
+ {
+ out << nl << stream << ".write" << func << "Seq(" << param << " == null ? 0 : "
+ << param << ".Count, " << param << ");";
+ }
+ else if(isLinkedList)
+ {
+ out << nl << stream << ".writeSize(" << param << '.' << limitID << ");";
+ out << nl << "_System.Collections.Generic.IEnumerator<" << typeS
+ << "> e__ = " << param << ".GetEnumerator();";
+ out << nl << "while(e__.MoveNext())";
+ out << sb;
+ out << nl << stream << ".write" << func << "(e__.Current);";
+ out << eb;
+ }
+ else
+ {
+ out << nl << stream << ".write" << func << "Seq(" << param << " == null ? null : "
+ << param << ".ToArray());";
+ }
}
}
else
{
if(isArray)
{
- out << nl << param << " = " << stream << ".read" << typeS << "Seq();";
+ out << nl << param << " = " << stream << ".read" << func << "Seq();";
}
else if(isCustom)
{
@@ -911,18 +946,45 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
out << nl << "int szx__ = " << stream << ".readSize();";
out << nl << "for(int ix__ = 0; ix__ < szx__; ++ix__)";
out << sb;
- out << nl << param << ".Add(" << stream << ".read" << typeS << "());";
+ out << nl << param << ".Add(" << stream << ".read" << func << "());";
out << eb;
out << eb;
}
- else if(isGeneric)
+ else if(isCollection)
{
- out << nl << stream << ".read" << typeS << "Seq(out " << param << ");";
+ out << nl << param << " = new " << fixId(seq->scoped())
+ << '(' << stream << ".read" << func << "Seq());";
}
else
{
- out << nl << param << " = new " << fixId(seq->scoped())
- << '(' << stream << ".read" << typeS << "Seq());";
+ assert(isGeneric);
+ if(streamingAPI)
+ {
+ if(isStack)
+ {
+ //
+ // Stacks are marshaled in top-to-bottom order. We cannot call
+ // "new Stack(type[])" because that constructor assumes the array
+ // is in bottom-to-top order. We read the array first, then push it
+ // in reverse order.
+ //
+ out << nl << typeS << "[] arr__ = " << stream << ".read" << func << "Seq();";
+ out << nl << param << " = new " << typeToString(seq) << "(arr__.Length);";
+ out << nl << "for(int ix__ = arr__.Length - 1; ix__ >= 0; --ix__)";
+ out << sb;
+ out << nl << param << ".Push(arr__[ix__]);";
+ out << eb;
+ }
+ else
+ {
+ out << nl << param << " = new " << typeToString(seq) << '(' << stream
+ << ".read" << func << "Seq());";
+ }
+ }
+ else
+ {
+ out << nl << stream << ".read" << func << "Seq(out " << param << ");";
+ }
}
}
break;