summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2011-03-14 15:27:15 +0100
committerJose <jose@zeroc.com>2011-03-14 15:27:15 +0100
commit986249ba3b9cf5e9f75acf0a68ebdfce68201a0a (patch)
treefea8f1537438f037bd71609a4ddd0cb7188c7625 /cpp
parent4971 - BuiltinSequences.ice not compiled with --stream in .NET (diff)
downloadice-986249ba3b9cf5e9f75acf0a68ebdfce68201a0a.tar.bz2
ice-986249ba3b9cf5e9f75acf0a68ebdfce68201a0a.tar.xz
ice-986249ba3b9cf5e9f75acf0a68ebdfce68201a0a.zip
5030 - Patch for slice2cs with scoped constants
Diffstat (limited to 'cpp')
-rw-r--r--cpp/src/slice2cs/Gen.cpp18
-rw-r--r--cpp/test/Ice/defaultValue/AllTests.cpp35
-rw-r--r--cpp/test/Ice/defaultValue/Test.ice50
3 files changed, 87 insertions, 16 deletions
diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp
index ea4a62b7752..dac53b55108 100644
--- a/cpp/src/slice2cs/Gen.cpp
+++ b/cpp/src/slice2cs/Gen.cpp
@@ -1228,6 +1228,7 @@ Slice::CsVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePt
else
{
BuiltinPtr bp = BuiltinPtr::dynamicCast(type);
+ EnumPtr ep;
if(bp && bp->kind() == Builtin::KindString)
{
//
@@ -1271,17 +1272,24 @@ Slice::CsVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePt
{
_out << value << "F";
}
- else
+ else if(ep = EnumPtr::dynamicCast(type))
{
- EnumPtr ep = EnumPtr::dynamicCast(type);
- if(ep)
+ string enumName = fixId(ep->scoped());
+ string::size_type colon = value.rfind(':');
+ string enumerator;
+ if(colon != string::npos)
{
- _out << typeToString(type) << "." << fixId(value);
+ enumerator = fixId(value.substr(colon + 1));
}
else
{
- _out << value;
+ enumerator = fixId(value);
}
+ _out << enumName << '.' << enumerator;
+ }
+ else
+ {
+ _out << value;
}
}
}
diff --git a/cpp/test/Ice/defaultValue/AllTests.cpp b/cpp/test/Ice/defaultValue/AllTests.cpp
index 30dd341b35f..1d62c881261 100644
--- a/cpp/test/Ice/defaultValue/AllTests.cpp
+++ b/cpp/test/Ice/defaultValue/AllTests.cpp
@@ -30,7 +30,12 @@ allTests()
test(v.f == static_cast<float>(5.1));
test(v.d == 6.2);
test(v.str == "foo bar");
- test(v.c == red);
+ test(v.c1 == red);
+ test(v.c2 == green);
+ test(v.c3 == blue);
+ test(v.nc1 == Nested::red);
+ test(v.nc2 == Nested::green);
+ test(v.nc3 == Nested::blue);
test(v.noDefault.empty());
}
@@ -44,7 +49,12 @@ allTests()
test(v.f == ConstFloat);
test(v.d == ConstDouble);
test(v.str == ConstString);
- test(v.c == ConstColor);
+ test(v.c1 == ConstColor1);
+ test(v.c2 == ConstColor2);
+ test(v.c3 == ConstColor3);
+ test(v.nc1 == ConstNestedColor1);
+ test(v.nc2 == ConstNestedColor2);
+ test(v.nc3 == ConstNestedColor3);
}
{
@@ -58,7 +68,12 @@ allTests()
test(v->f == static_cast<float>(5.1));
test(v->d == 6.2);
test(v->str == "foo bar");
- test(v->c == blue);
+ test(v->c1 == red);
+ test(v->c2 == green);
+ test(v->c3 == blue);
+ test(v->nc1 == Nested::red);
+ test(v->nc2 == Nested::green);
+ test(v->nc3 == Nested::blue);
test(v->noDefault.empty());
}
@@ -88,7 +103,12 @@ allTests()
test(v->d == 6.2);
test(v->str == "foo bar");
test(v->noDefault.empty());
- test(v->c == green);
+ test(v->c1 == red);
+ test(v->c2 == green);
+ test(v->c3 == blue);
+ test(v->nc1 == Nested::red);
+ test(v->nc2 == Nested::green);
+ test(v->nc3 == Nested::blue);
}
{
@@ -117,7 +137,12 @@ allTests()
test(v.d == 6.2);
test(v.str == "foo bar");
test(v.noDefault.empty());
- test(v.c == green);
+ test(v.c1 == red);
+ test(v.c2 == green);
+ test(v.c3 == blue);
+ test(v.nc1 == Nested::red);
+ test(v.nc2 == Nested::green);
+ test(v.nc3 == Nested::blue);
}
cout << "ok" << endl;
diff --git a/cpp/test/Ice/defaultValue/Test.ice b/cpp/test/Ice/defaultValue/Test.ice
index 1ca6df58536..672819a5026 100644
--- a/cpp/test/Ice/defaultValue/Test.ice
+++ b/cpp/test/Ice/defaultValue/Test.ice
@@ -15,6 +15,13 @@ module Test
enum Color { red, green, blue };
+module Nested
+{
+
+enum Color { red, green, blue };
+
+};
+
struct Struct1
{
bool boolFalse = false;
@@ -26,7 +33,12 @@ struct Struct1
float f = 5.1;
double d = 6.2;
string str = "foo bar";
- Color c = red;
+ Color c1 = ::Test::red;
+ Color c2 = Test::green;
+ Color c3 = blue;
+ Nested::Color nc1 = ::Test::Nested::red;
+ Nested::Color nc2 = Nested::green;
+ Nested::Color nc3 = Nested::blue;
string noDefault;
};
@@ -38,7 +50,13 @@ const long ConstLong = 4;
const float ConstFloat = 5.1;
const double ConstDouble = 6.2;
const string ConstString = "foo bar";
-const Color ConstColor = red;
+const Color ConstColor1 = ::Test::red;
+const Color ConstColor2 = Test::green;
+const Color ConstColor3 = blue;
+const Nested::Color ConstNestedColor1 = ::Test::Nested::red;
+const Nested::Color ConstNestedColor2 = Test::Nested::green;
+const Nested::Color ConstNestedColor3 = Nested::blue;
+
struct Struct2
{
@@ -50,7 +68,12 @@ struct Struct2
float f = ConstFloat;
double d = ConstDouble;
string str = ConstString;
- Color c = ConstColor;
+ Color c1 = ConstColor1;
+ Color c2 = ConstColor2;
+ Color c3 = ConstColor3;
+ Nested::Color nc1 = ConstNestedColor1;
+ Nested::Color nc2 = ConstNestedColor2;
+ Nested::Color nc3 = ConstNestedColor3;
};
["cpp:class"]
@@ -65,7 +88,12 @@ struct Struct3
float f = 5.1;
double d = 6.2;
string str = "foo bar";
- Color c = blue;
+ Color c1 = ::Test::red;
+ Color c2 = Test::green;
+ Color c3 = blue;
+ Nested::Color nc1 = ::Test::Nested::red;
+ Nested::Color nc2 = Nested::green;
+ Nested::Color nc3 = Nested::blue;
string noDefault;
};
@@ -85,7 +113,12 @@ class Base
class Derived extends Base
{
- Color c = green;
+ Color c1 = ::Test::red;
+ Color c2 = Test::green;
+ Color c3 = blue;
+ Nested::Color nc1 = ::Test::Nested::red;
+ Nested::Color nc2 = Nested::green;
+ Nested::Color nc3 = Nested::blue;
};
exception BaseEx
@@ -104,7 +137,12 @@ exception BaseEx
exception DerivedEx extends BaseEx
{
- Color c = green;
+ Color c1 = ConstColor1;
+ Color c2 = ConstColor2;
+ Color c3 = ConstColor3;
+ Nested::Color nc1 = ConstNestedColor1;
+ Nested::Color nc2 = ConstNestedColor2;
+ Nested::Color nc3 = ConstNestedColor3;
};
};