summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2013-07-25 19:24:18 +0200
committerJose <jose@zeroc.com>2013-07-25 19:24:18 +0200
commitf07348f395a6eeecae963953f19fdb4b746e536a (patch)
tree76f05767ec82d257a6584a5dcfab34488929cdee /cpp
parentMinor build rules fix (diff)
downloadice-f07348f395a6eeecae963953f19fdb4b746e536a.tar.bz2
ice-f07348f395a6eeecae963953f19fdb4b746e536a.tar.xz
ice-f07348f395a6eeecae963953f19fdb4b746e536a.zip
Fixes for optionals and enums with explicit values in checksum calculations.
Diffstat (limited to 'cpp')
-rw-r--r--cpp/src/Slice/Checksum.cpp121
-rw-r--r--cpp/test/Ice/checksum/Types.ice122
-rw-r--r--cpp/test/Ice/checksum/server/Types.ice123
3 files changed, 355 insertions, 11 deletions
diff --git a/cpp/src/Slice/Checksum.cpp b/cpp/src/Slice/Checksum.cpp
index 94fa3bf3f6c..78406e41e86 100644
--- a/cpp/src/Slice/Checksum.cpp
+++ b/cpp/src/Slice/Checksum.cpp
@@ -9,6 +9,7 @@
#include <Slice/Checksum.h>
#include <Slice/MD5.h>
+#include <IceUtil/OutputUtil.h>
using namespace std;
using namespace Slice;
@@ -113,9 +114,38 @@ Slice::ChecksumVisitor::visitClassDefStart(const ClassDefPtr& p)
if(p->hasDataMembers())
{
DataMemberList members = p->dataMembers();
+ DataMemberList optionals;
for(DataMemberList::iterator q = members.begin(); q != members.end(); ++q)
{
- ostr << typeToString((*q)->type()) << ' ' << (*q)->name() << endl;
+ if((*q)->optional())
+ {
+ optionals.push_back(*q);
+ }
+ else
+ {
+ ostr << typeToString((*q)->type()) << ' ' << (*q)->name() << endl;
+ }
+ }
+
+ if(!optionals.empty())
+ {
+ //
+ // Sort optional parameters by tag.
+ //
+ class SortFn
+ {
+ public:
+ static bool compare(const DataMemberPtr& lhs, const DataMemberPtr& rhs)
+ {
+ return lhs->tag() < rhs->tag();
+ }
+ };
+ optionals.sort(SortFn::compare);
+
+ for(DataMemberList::iterator q = optionals.begin(); q != optionals.end(); ++q)
+ {
+ ostr << typeToString((*q)->type()) << ' ' << (*q)->tag() << ' ' << (*q)->name();
+ }
}
}
@@ -124,20 +154,63 @@ Slice::ChecksumVisitor::visitClassDefStart(const ClassDefPtr& p)
OperationList ops = p->operations();
for(OperationList::iterator q = ops.begin(); q != ops.end(); ++q)
{
- ostr << typeToString((*q)->returnType()) << ' ' << (*q)->name() << '(';
+ ostr << typeToString((*q)->returnType()) << ' ';
+ if((*q)->returnIsOptional())
+ {
+ ostr << (*q)->returnTag() << ' ';
+ }
+ ostr << (*q)->name() << '(';
ParamDeclList params = (*q)->parameters();
+ ParamDeclList optionals;
for(ParamDeclList::iterator r = params.begin(); r != params.end(); ++r)
{
- if(r != params.begin())
+ if((*r)->optional())
{
- ostr << ", ";
+ optionals.push_back(*r);
}
- if((*r)->isOutParam())
+ else
{
- ostr << "out ";
+ if(r != params.begin())
+ {
+ ostr << ", ";
+ }
+ if((*r)->isOutParam())
+ {
+ ostr << "out ";
+ }
+ ostr << typeToString((*r)->type()) << ' ' << (*r)->name();
}
- ostr << typeToString((*r)->type()) << ' ' << (*r)->name();
}
+
+ if(!optionals.empty())
+ {
+ //
+ // Sort optional parameters by tag.
+ //
+ class SortFn
+ {
+ public:
+ static bool compare(const ParamDeclPtr& lhs, const ParamDeclPtr& rhs)
+ {
+ return lhs->tag() < rhs->tag();
+ }
+ };
+ optionals.sort(SortFn::compare);
+
+ for(ParamDeclList::iterator r = optionals.begin(); r != optionals.end(); ++r)
+ {
+ if(r != optionals.begin() || params.size() > optionals.size())
+ {
+ ostr << ", ";
+ }
+ if((*r)->isOutParam())
+ {
+ ostr << "out ";
+ }
+ ostr << typeToString((*r)->type()) << ' ' << (*r)->tag() << ' ' << (*r)->name();
+ }
+ }
+
ostr << ')';
ExceptionList ex = (*q)->throws();
if(!ex.empty())
@@ -252,13 +325,39 @@ Slice::ChecksumVisitor::visitEnum(const EnumPtr& p)
ostringstream ostr;
ostr << "enum " << p->name() << endl;
-
+
+ //
+ // Check if any of the enumerators were assigned an explicit value.
+ //
+ const bool explicitValue = p->explicitValue();
+
EnumeratorList enums = p->getEnumerators();
- for(EnumeratorList::iterator q = enums.begin(); q != enums.end(); ++q)
+ if(explicitValue)
{
- ostr << (*q)->name() << endl;
+ //
+ // Sort enumerators by value.
+ //
+ class SortFn
+ {
+ public:
+ static bool compare(const EnumeratorPtr& lhs, const EnumeratorPtr& rhs)
+ {
+ return lhs->value() < rhs->value();
+ }
+ };
+ enums.sort(SortFn::compare);
+ for(EnumeratorList::iterator q = enums.begin(); q != enums.end(); ++q)
+ {
+ ostr << (*q)->name() << ' ' << IceUtilInternal::int64ToString((*q)->value()) << endl;
+ }
+ }
+ else
+ {
+ for(EnumeratorList::iterator q = enums.begin(); q != enums.end(); ++q)
+ {
+ ostr << (*q)->name() << endl;
+ }
}
-
updateMap(p->scoped(), ostr.str());
}
diff --git a/cpp/test/Ice/checksum/Types.ice b/cpp/test/Ice/checksum/Types.ice
index 070f3800684..5c4a8b8d47a 100644
--- a/cpp/test/Ice/checksum/Types.ice
+++ b/cpp/test/Ice/checksum/Types.ice
@@ -48,6 +48,26 @@ enum Enum3 { Enum31, Enum32, Enum33 };
enum Enum4 { Enum41, Enum42, Enum43 };
//
+// TEST: Enum with explicit values.
+//
+enum EnumExplicit0 { EnumExplicit01 = 1, EnumExplicit02 = 2, EnumExplicit03 = 3 };
+
+//
+// TEST: Enum with same explicit values different order.
+//
+enum EnumExplicit1 { EnumExplicit11 = 1, EnumExplicit12 = 2, EnumExplicit13 = 3 };
+
+//
+// TEST: Enum with different explicit values.
+//
+enum EnumExplicit2 { EnumExplicit21 = 1, EnumExplicit22 = 2, EnumExplicit23 = 3};
+
+//
+// TEST: Enum with explicit values removed enumerator.
+//
+enum EnumExplicit3 { EnumExplicit31 = 1, EnumExplicit32 = 2, EnumExplicit33 = 3};
+
+//
// TEST: Same
//
sequence<int> Sequence1;
@@ -437,6 +457,108 @@ class Derived2 extends Compact2
};
//
+// TEST: Class with optional members.
+//
+class Optional0
+{
+ string firstName;
+ optional(1) string secondName;
+ optional(2) string emailAddress;
+};
+
+//
+// TEST: Class with optional members different order same tags.
+//
+class Optional1
+{
+ string firstName;
+ optional(1) string secondName;
+ optional(2) string emailAddress;
+};
+
+//
+// TEST: Class with different optional members.
+//
+class Optional2
+{
+ string firstName;
+ string secondName;
+ optional(1) string emailAddress;
+};
+
+//
+// TEST: Class with different optional members.
+//
+class Optional3
+{
+ string firstName;
+ optional(1) string secondName;
+ optional(2) string emailAddress;
+};
+
+//
+// TEST: Class with optional members using different tags.
+//
+class Optional4
+{
+ string firstName;
+ optional(1) string secondName;
+ optional(2) string emailAddress;
+};
+
+//
+// TEST: Class with operation optional parameters.
+//
+class OptionalParameters0
+{
+ void op1(string firstName, optional(1) string secondName,
+ optional(2) string emailAddress);
+};
+
+//
+// TEST: Class with operation optional parameters different order.
+//
+class OptionalParameters1
+{
+ void op1(string firstName, optional(1) string secondName,
+ optional(2) string emailAddress);
+};
+
+//
+// TEST: Class with operation optional parameters different tags.
+//
+class OptionalParameters2
+{
+ void op1(string firstName, optional(1) string emailAddress,
+ optional(2) string secondName);
+};
+
+//
+// TEST: Class with operation different optional parameters.
+//
+class OptionalParameters3
+{
+ void op1(string firstName, optional(1) string emailAddress,
+ string secondName);
+};
+
+//
+// TEST: Class with operation optional return type.
+//
+class OptionalReturn0
+{
+ optional(1) int op();
+};
+
+//
+// TEST: Class that change operation optional return type.
+//
+class OptionalReturn2
+{
+ optional(1) int op();
+};
+
+//
// TEST: Local
//
local enum LocalEnum { LocalEnum1, LocalEnum2, LocalEnum3 };
diff --git a/cpp/test/Ice/checksum/server/Types.ice b/cpp/test/Ice/checksum/server/Types.ice
index 9c08dd6a047..36b9bd2f54b 100644
--- a/cpp/test/Ice/checksum/server/Types.ice
+++ b/cpp/test/Ice/checksum/server/Types.ice
@@ -43,6 +43,26 @@ enum Enum2 { Enum21, Enum22, Enum23, Enum24 };
enum Enum3 { Enum32, Enum33 };
//
+// TEST: Enum with explicit values.
+//
+enum EnumExplicit0 { EnumExplicit01 = 1, EnumExplicit02 = 2, EnumExplicit03 = 3 };
+
+//
+// TEST: Enum with same explicit values different order.
+//
+enum EnumExplicit1 { EnumExplicit11 = 1, EnumExplicit13 = 3, EnumExplicit12 = 2 };
+
+//
+// TEST: Enum with different explicit values.
+//
+enum EnumExplicit2 { EnumExplicit21 = 1, EnumExplicit22 = 3, EnumExplicit23 };
+
+//
+// TEST: Enum with explicit values removed enumerator.
+//
+enum EnumExplicit3 { EnumExplicit31 = 1, EnumExplicit32 = 2};
+
+//
// TEST: Change to a different type
//
class Enum4 {};
@@ -432,6 +452,109 @@ class Derived2 extends Compact2
};
//
+// TEST: Class with optional members.
+//
+class Optional0
+{
+ string firstName;
+ optional(1) string secondName;
+ optional(2) string emailAddress;
+};
+
+//
+// TEST: Class with optional members different order same tags.
+//
+class Optional1
+{
+ string firstName;
+ optional(2) string emailAddress;
+ optional(1) string secondName;
+};
+
+//
+// TEST: Class with different optional members.
+//
+class Optional2
+{
+ string firstName;
+ optional(1) string secondName;
+ string emailAddress;
+};
+
+//
+// TEST: Class with different optional members.
+//
+class Optional3
+{
+ string firstName;
+ optional(1) string secondName;
+ optional(2) string emailAddress;
+ optional(3) string phoneNumber;
+};
+
+//
+// TEST: Class with optional members using different tags.
+//
+class Optional4
+{
+ string firstName;
+ optional(2) string secondName;
+ optional(1) string emailAddress;
+};
+
+//
+// TEST: Class with operation optional parameters.
+//
+class OptionalParameters0
+{
+ void op1(string firstName, optional(1) string secondName,
+ optional(2) string emailAddress);
+};
+
+//
+// TEST: Class with operation optional parameters different order.
+//
+class OptionalParameters1
+{
+ void op1(string firstName, optional(2) string emailAddress,
+ optional(1) string secondName);
+};
+
+//
+// TEST: Class with operation optional parameters different tags.
+//
+class OptionalParameters2
+{
+ void op1(string firstName, optional(2) string emailAddress,
+ optional(1) string secondName);
+};
+
+//
+// TEST: Class with operation different optional parameters.
+//
+class OptionalParameters3
+{
+ void op1(string firstName, string emailAddress,
+ optional(1) string secondName);
+};
+
+//
+// TEST: Class with operation optional return type.
+//
+class OptionalReturn0
+{
+ optional(1) int op();
+};
+
+//
+// TEST: Class that change operation optional return type.
+//
+class OptionalReturn2
+{
+ int op();
+};
+
+//
// TEST: Local
//
local enum LocalEnum { LocalEnum1, LocalEnum2, LocalEnum3 };