summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorJoe George <joe@zeroc.com>2016-07-07 14:21:50 -0400
committerJoe George <joe@zeroc.com>2016-07-08 09:36:51 -0400
commite5c2e3c8a6255fbb09b294e37b717dd3452e5ffb (patch)
treed6110ee21fbea6cc67334a5b49361d4501d614b6 /cpp/src
parentFixed JavaScript optionalBidir test failure (diff)
downloadice-e5c2e3c8a6255fbb09b294e37b717dd3452e5ffb.tar.bz2
ice-e5c2e3c8a6255fbb09b294e37b717dd3452e5ffb.tar.xz
ice-e5c2e3c8a6255fbb09b294e37b717dd3452e5ffb.zip
ICE-7172 - Replace generated comparsion operators
- Add ice_tuple function to structs and classes. Returns a tuple of data members - Replace generated comparsion for structs (and classes) with template comparsion operators which use ice_tuple
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/IceGridLib/msbuild/icegrid++11/icegrid++11.vcxproj4
-rw-r--r--cpp/src/Slice/CPlusPlusUtil.cpp26
-rw-r--r--cpp/src/Slice/CPlusPlusUtil.h4
-rw-r--r--cpp/src/Slice/Parser.cpp21
-rw-r--r--cpp/src/Slice/Parser.h1
-rw-r--r--cpp/src/slice2cpp/Gen.cpp103
6 files changed, 72 insertions, 87 deletions
diff --git a/cpp/src/IceGridLib/msbuild/icegrid++11/icegrid++11.vcxproj b/cpp/src/IceGridLib/msbuild/icegrid++11/icegrid++11.vcxproj
index 2addaad07fe..9cad1eb92e6 100644
--- a/cpp/src/IceGridLib/msbuild/icegrid++11/icegrid++11.vcxproj
+++ b/cpp/src/IceGridLib/msbuild/icegrid++11/icegrid++11.vcxproj
@@ -74,21 +74,25 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PreprocessorDefinitions>ICE_GRID_API_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <DisableSpecificWarnings>4250;4251;4275;4503</DisableSpecificWarnings>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PreprocessorDefinitions>ICE_GRID_API_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <DisableSpecificWarnings>4250;4251;4275;4503</DisableSpecificWarnings>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PreprocessorDefinitions>ICE_GRID_API_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <DisableSpecificWarnings>4250;4251;4275;4503</DisableSpecificWarnings>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PreprocessorDefinitions>ICE_GRID_API_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <DisableSpecificWarnings>4250;4251;4275;4503</DisableSpecificWarnings>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp
index 88e0f96da8e..1e3134c718a 100644
--- a/cpp/src/Slice/CPlusPlusUtil.cpp
+++ b/cpp/src/Slice/CPlusPlusUtil.cpp
@@ -1453,6 +1453,32 @@ Slice::writeStreamHelpers(Output& out, bool checkClassMetaData, const ContainedP
out << eb << ";" << nl;
}
}
+void
+Slice::writeIceTuple(::IceUtilInternal::Output& out, DataMemberList dataMembers, int useWstring)
+{
+ out << sp << nl << "std::tuple<";
+ for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
+ {
+ if(q != dataMembers.begin())
+ {
+ out << ", ";
+ }
+ out << "const ";
+ out << typeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), useWstring | TypeContextCpp11) << "&";
+ }
+ out << "> ice_tuple() const";
+ out << sb;
+ out << nl << "return std::tie(";
+ for(DataMemberList::const_iterator pi = dataMembers.begin(); pi != dataMembers.end(); ++pi)
+ {
+ if(pi != dataMembers.begin())
+ {
+ out << ", ";
+ }
+ out << fixKwd((*pi)->name());
+ }
+ out << ");" << eb;
+}
bool
Slice::findMetaData(const string& prefix, const ClassDeclPtr& cl, string& value)
diff --git a/cpp/src/Slice/CPlusPlusUtil.h b/cpp/src/Slice/CPlusPlusUtil.h
index da430845e30..1cd1d8f32c6 100644
--- a/cpp/src/Slice/CPlusPlusUtil.h
+++ b/cpp/src/Slice/CPlusPlusUtil.h
@@ -60,7 +60,9 @@ void writeAllocateCode(::IceUtilInternal::Output&, const ParamDeclList&, const O
std::string getEndArg(const TypePtr&, const StringList&, const std::string&);
void writeEndCode(::IceUtilInternal::Output&, const ParamDeclList&, const OperationPtr&, bool = false);
void writeMarshalUnmarshalDataMemberInHolder(IceUtilInternal::Output&, const std::string&, const DataMemberPtr&, bool);
-void writeStreamHelpers(::IceUtilInternal::Output&, bool, const ContainedPtr&, DataMemberList, DataMemberList = DataMemberList());
+void writeStreamHelpers(::IceUtilInternal::Output&, bool, const ContainedPtr&, DataMemberList,
+ DataMemberList = DataMemberList());
+void writeIceTuple(::IceUtilInternal::Output&, DataMemberList, int);
bool findMetaData(const std::string&, const ClassDeclPtr&, std::string&);
bool findMetaData(const std::string&, const StringList&, std::string&);
diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp
index 502d20677be..1c3eb315032 100644
--- a/cpp/src/Slice/Parser.cpp
+++ b/cpp/src/Slice/Parser.cpp
@@ -1650,6 +1650,27 @@ Slice::Container::hasNonLocalExceptions() const
}
bool
+Slice::Container::hasStructs() const
+{
+ for(ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p)
+ {
+ StructPtr q = StructPtr::dynamicCast(*p);
+ if(q)
+ {
+ return true;
+ }
+
+ ContainerPtr container = ContainerPtr::dynamicCast(*p);
+ if(container && container->hasStructs())
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool
Slice::Container::hasExceptions() const
{
for(ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p)
diff --git a/cpp/src/Slice/Parser.h b/cpp/src/Slice/Parser.h
index ece0c696e02..5d0d7c547ea 100644
--- a/cpp/src/Slice/Parser.h
+++ b/cpp/src/Slice/Parser.h
@@ -448,6 +448,7 @@ public:
bool hasLocalClassDefsWithAsync() const;
bool hasNonLocalSequences() const;
bool hasNonLocalExceptions() const;
+ bool hasStructs() const;
bool hasExceptions() const;
bool hasDictionaries() const;
bool hasOnlyDictionaries(DictionaryList&) const;
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 62b72beaa30..93c4540b8e0 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -778,6 +778,7 @@ Slice::Gen::generate(const UnitPtr& p)
H << "\n#include <Ice/Exception.h>";
H << "\n#include <Ice/LocalObject.h>";
H << "\n#include <Ice/StreamHelpers.h>";
+ H << "\n#include <Ice/Comparable.h>";
if(p->hasNonLocalClassDefs())
{
@@ -5631,8 +5632,17 @@ Slice::Gen::Cpp11TypesVisitor::visitModuleStart(const ModulePtr& p)
}
void
-Slice::Gen::Cpp11TypesVisitor::visitModuleEnd(const ModulePtr&)
+Slice::Gen::Cpp11TypesVisitor::visitModuleEnd(const ModulePtr& p)
{
+ if(p->hasStructs())
+ {
+ H << sp << nl << "using Ice::operator<;";
+ H << nl << "using Ice::operator<=;";
+ H << nl << "using Ice::operator>;";
+ H << nl << "using Ice::operator>=;";
+ H << nl << "using Ice::operator==;";
+ H << nl << "using Ice::operator!=;";
+ }
H << sp << nl << '}';
_useWstring = resetUseWstring(_useWstringHist);
}
@@ -5913,13 +5923,9 @@ Slice::Gen::Cpp11TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
bool
Slice::Gen::Cpp11TypesVisitor::visitStructStart(const StructPtr& p)
{
- DataMemberList dataMembers = p->dataMembers();
_useWstring = setUseWstring(p, _useWstringHist, _useWstring);
- string name = fixKwd(p->name());
-
-
- H << sp << nl << "struct " << name;
+ H << sp << nl << "struct " << fixKwd(p->name());
H << sb;
return true;
@@ -5928,75 +5934,7 @@ Slice::Gen::Cpp11TypesVisitor::visitStructStart(const StructPtr& p)
void
Slice::Gen::Cpp11TypesVisitor::visitStructEnd(const StructPtr& p)
{
- string name = fixKwd(p->name());
- string scoped = fixKwd(p->scoped());
- string scope = fixKwd(p->scope());
-
- DataMemberList dataMembers = p->dataMembers();
-
- vector<string> params;
- vector<string>::const_iterator pi;
-
- for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
- {
- params.push_back(fixKwd((*q)->name()));
- }
-
- bool containsSequence = false;
- if((Dictionary::legalKeyType(p, containsSequence) && !containsSequence))
- {
- H << sp << nl << "bool operator==(const " << name << "& __rhs) const";
- H << sb;
- H << nl << "if(this == &__rhs)";
- H << sb;
- H << nl << "return true;";
- H << eb;
- for(vector<string>::const_iterator pi = params.begin(); pi != params.end(); ++pi)
- {
- H << nl << "if(" << *pi << " != __rhs." << *pi << ')';
- H << sb;
- H << nl << "return false;";
- H << eb;
- }
- H << nl << "return true;";
- H << eb;
- H << sp << nl << "bool operator<(const " << name << "& __rhs) const";
- H << sb;
- H << nl << "if(this == &__rhs)";
- H << sb;
- H << nl << "return false;";
- H << eb;
- for(vector<string>::const_iterator pi = params.begin(); pi != params.end(); ++pi)
- {
- H << nl << "if(" << *pi << " < __rhs." << *pi << ')';
- H << sb;
- H << nl << "return true;";
- H << eb;
- H << nl << "else if(__rhs." << *pi << " < " << *pi << ')';
- H << sb;
- H << nl << "return false;";
- H << eb;
- }
- H << nl << "return false;";
- H << eb;
-
- H << sp << nl << "bool operator!=(const " << name << "& __rhs) const";
- H << sb;
- H << nl << "return !operator==(__rhs);";
- H << eb;
- H << nl << "bool operator<=(const " << name << "& __rhs) const";
- H << sb;
- H << nl << "return operator<(__rhs) || operator==(__rhs);";
- H << eb;
- H << nl << "bool operator>(const " << name << "& __rhs) const";
- H << sb;
- H << nl << "return !operator<(__rhs) && !operator==(__rhs);";
- H << eb;
- H << nl << "bool operator>=(const " << name << "& __rhs) const";
- H << sb;
- H << nl << "return !operator<(__rhs);";
- H << eb;
- }
+ writeIceTuple(H, p->dataMembers(), _useWstring);
H << eb << ';';
_useWstring = resetUseWstring(_useWstringHist);
}
@@ -7692,26 +7630,19 @@ Slice::Gen::Cpp11ValueVisitor::visitClassDefStart(const ClassDefPtr& p)
C << eb;
vector<string> params;
- vector<string> allTypes;
- vector<string> allParamDecls;
for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
params.push_back(fixKwd((*q)->name()));
}
- for(DataMemberList::const_iterator q = allDataMembers.begin(); q != allDataMembers.end(); ++q)
- {
- string typeName = inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring);
- allTypes.push_back(typeName);
- allParamDecls.push_back(typeName + " __ice_" + (*q)->name());
- }
-
H << sp << nl << name << "() = default;";
emitOneShotConstructor(p);
- H << sp;
- H << nl << _dllMemberExport << "static const ::std::string& ice_staticId();";
+
+ writeIceTuple(H, p->dataMembers(), _useWstring);
+
+ H << sp << nl << _dllMemberExport << "static const ::std::string& ice_staticId();";
return true;
}