summaryrefslogtreecommitdiff
path: root/cpp/src/slice2matlab/Main.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2017-09-23 06:32:51 -0700
committerMark Spruiell <mes@zeroc.com>2017-09-23 06:32:51 -0700
commit29e88550630a188ae8668f3dc185a1ffb672753d (patch)
tree87670852fe4f6e2ae80144019e9b769ad8fbc259 /cpp/src/slice2matlab/Main.cpp
parentRevising the mapping for sequence<struct> and sequence<enum> (diff)
downloadice-29e88550630a188ae8668f3dc185a1ffb672753d.tar.bz2
ice-29e88550630a188ae8668f3dc185a1ffb672753d.tar.xz
ice-29e88550630a188ae8668f3dc185a1ffb672753d.zip
Minor fixes to generated code for sequences
Diffstat (limited to 'cpp/src/slice2matlab/Main.cpp')
-rw-r--r--cpp/src/slice2matlab/Main.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/cpp/src/slice2matlab/Main.cpp b/cpp/src/slice2matlab/Main.cpp
index 34603cb9d5d..6f5fb2a0f94 100644
--- a/cpp/src/slice2matlab/Main.cpp
+++ b/cpp/src/slice2matlab/Main.cpp
@@ -2186,6 +2186,12 @@ CodeVisitor::visitSequence(const SequencePtr& p)
// For a sequence<class>, read() returns an instance of IceInternal.CellArrayHandle that we later replace
// with the cell array. See convert().
//
+ out << nl << "if sz == 0";
+ out.inc();
+ out << nl << "r = {};";
+ out.dec();
+ out << nl << "else";
+ out.inc();
out << nl << "r = IceInternal.CellArrayHandle();";
out << nl << "r.array = cell(1, sz);";
out << nl << "for i = 1:sz";
@@ -2196,28 +2202,43 @@ CodeVisitor::visitSequence(const SequencePtr& p)
unmarshal(out, "is", "@(v) r.set(i, v)", content, false, 0);
out.dec();
out << nl << "end";
+ out.dec();
+ out << nl << "end";
}
else if((b && b->kind() == Builtin::KindString) || dictContent || seqContent || proxy)
{
//
// These types require a cell array.
//
+ out << nl << "if sz == 0";
+ out.inc();
+ out << nl << "r = {};";
+ out.dec();
+ out << nl << "else";
+ out.inc();
out << nl << "r = cell(1, sz);";
out << nl << "for i = 1:sz";
out.inc();
unmarshal(out, "is", "r{i}", content, false, 0);
out.dec();
out << nl << "end";
+ out.dec();
+ out << nl << "end";
}
else if(enumContent)
{
const EnumeratorList enumerators = enumContent->enumerators();
+ out << nl << "r = " << getAbsolute(enumContent) << ".empty();";
+ out << nl << "if sz > 0";
+ out.inc();
out << nl << "r(1, sz) = " << getAbsolute(*enumerators.begin()) << ";";
out << nl << "for i = 1:sz";
out.inc();
unmarshal(out, "is", "r(i)", content, false, 0);
out.dec();
out << nl << "end";
+ out.dec();
+ out << nl << "end";
}
else if(structContent)
{
@@ -2226,12 +2247,17 @@ CodeVisitor::visitSequence(const SequencePtr& p)
// syntax "arr(1, sz) = Type()". Additionally, we also have to inline the unmarshaling code for
// the struct members.
//
+ out << nl << "r = " << getAbsolute(structContent) << ".empty();";
+ out << nl << "if sz > 0";
+ out.inc();
out << nl << "r(1, sz) = " << getAbsolute(structContent) << "();";
out << nl << "for i = 1:sz";
out.inc();
unmarshalStruct(out, structContent, "r(i)");
out.dec();
out << nl << "end";
+ out.dec();
+ out << nl << "end";
}
else
{