summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/include/Slice/VbUtil.h5
-rwxr-xr-xcpp/src/Slice/VbUtil.cpp34
-rwxr-xr-xcpp/src/slice2vb/Gen.cpp21
3 files changed, 41 insertions, 19 deletions
diff --git a/cpp/include/Slice/VbUtil.h b/cpp/include/Slice/VbUtil.h
index 7ccc9410853..f516ab34c5a 100644
--- a/cpp/include/Slice/VbUtil.h
+++ b/cpp/include/Slice/VbUtil.h
@@ -23,6 +23,11 @@ public:
virtual ~VbGenerator() {};
//
+ // Convert a dimension-less array declaration to one with a dimension.
+ //
+ static std::string toArrayAlloc(const std::string& decl, const std::string& sz);
+
+ //
// Validate all metadata in the unit with a "cs:" prefix.
//
static void validateMetaData(const UnitPtr&);
diff --git a/cpp/src/Slice/VbUtil.cpp b/cpp/src/Slice/VbUtil.cpp
index 76497a14d83..7d934b1fd5a 100755
--- a/cpp/src/Slice/VbUtil.cpp
+++ b/cpp/src/Slice/VbUtil.cpp
@@ -187,23 +187,6 @@ 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)
{
@@ -812,6 +795,23 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
return;
}
+string
+Slice::VbGenerator::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();
+}
+
void
Slice::VbGenerator::validateMetaData(const UnitPtr& unit)
{
diff --git a/cpp/src/slice2vb/Gen.cpp b/cpp/src/slice2vb/Gen.cpp
index 26bb46dcf6b..2464b7b20d3 100755
--- a/cpp/src/slice2vb/Gen.cpp
+++ b/cpp/src/slice2vb/Gen.cpp
@@ -2593,10 +2593,27 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
_out << nl << "End If";
_out.dec();
_out << nl << "Next";
- _out << nl << "Dim __vlhs() As " << vs << " = New " << vs << "(Count - 1) {}";
+ SequencePtr seq = SequencePtr::dynamicCast(p->valueType());
+ bool valueIsArray = seq && !seq->hasMetaData("cs:collection");
+ if(valueIsArray)
+ {
+ _out << nl << "Dim __vlhs As " << vs << "() = New " << toArrayAlloc(vs + "()", "Count - 1") << " {}";
+ }
+ else
+ {
+ _out << nl << "Dim __vlhs As " << vs << " = New " << toArrayAlloc(vs, "Count - 1") << " {}";
+ }
_out << nl << "Values.CopyTo(__vlhs, 0)";
_out << nl << "_System.Array.Sort(__vlhs)";
- _out << nl << "Dim __vrhs() As " << vs << " = New " << vs << "(CType(other, " << name << ").Count - 1) {}";
+ string vrhsCount = "Ctype(other, " + name + ").Count - 1";
+ if(valueIsArray)
+ {
+ _out << nl << "Dim __vrhs As " << vs << "() = New " << toArrayAlloc(vs + "()", vrhsCount) << " {}";
+ }
+ else
+ {
+ _out << nl << "Dim __vrhs As " << vs << " = New " << toArrayAlloc(vs, vrhsCount) << " {}";
+ }
_out << nl << "CType(other, " << name << ").Values.CopyTo(__vrhs, 0)";
_out << nl << "_System.Array.Sort(__vrhs)";
_out << nl << "For i As Integer = 0 To Count - 1";