From d6a28b75aac582df29c12e7ebcbdd17ed5a6a4ca Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Mon, 7 Oct 2024 09:21:54 -0400 Subject: [PATCH 1/4] Move proxy functions to ProxyFunctions.cpp (#2860) --- cpp/include/Ice/Comparable.h | 150 +++++++++++--------- cpp/include/Ice/Object.h | 1 + cpp/include/Ice/Proxy.h | 1 + cpp/include/Ice/ProxyFunctions.h | 4 +- cpp/src/Ice/BatchRequestQueue.h | 1 + cpp/src/Ice/Proxy.cpp | 112 +-------------- cpp/src/Ice/ProxyFunctions.cpp | 89 ++++++++++++ cpp/src/Ice/msbuild/ice/ice.vcxproj | 1 + cpp/src/Ice/msbuild/ice/ice.vcxproj.filters | 3 + cpp/src/slice2cpp/Gen.cpp | 19 ++- 10 files changed, 190 insertions(+), 191 deletions(-) create mode 100644 cpp/src/Ice/ProxyFunctions.cpp diff --git a/cpp/include/Ice/Comparable.h b/cpp/include/Ice/Comparable.h index dc8c85c6e67..ccca9247ed5 100644 --- a/cpp/include/Ice/Comparable.h +++ b/cpp/include/Ice/Comparable.h @@ -5,7 +5,8 @@ #ifndef ICE_COMPARABLE_H #define ICE_COMPARABLE_H -#include +#include +#include namespace Ice { @@ -113,80 +114,91 @@ namespace Ice } }; - // - // Relational operators for generated structs and classes - // - - /** - * Relational operator for generated structs and classes. - * @param lhs The left-hand side. - * @param rhs The right-hand side. - * @return True if the left-hand side compares less than the right-hand side, false otherwise. - */ - template::value>> - bool operator<(const C& lhs, const C& rhs) + namespace Tuple { - return lhs.ice_tuple() < rhs.ice_tuple(); - } + /** + * Relational operator for generated structs and classes. + * @param lhs The left-hand side. + * @param rhs The right-hand side. + * @return True if the left-hand side compares less than the right-hand side, false otherwise. + */ + template< + class C, + std::enable_if_t::value, bool> = true> + bool operator<(const C& lhs, const C& rhs) + { + return lhs.ice_tuple() < rhs.ice_tuple(); + } - /** - * Relational operator for generated structs and classes. - * @param lhs The left-hand side. - * @param rhs The right-hand side. - * @return True if the left-hand side compares less than or equal to the right-hand side, false otherwise. - */ - template::value>> - bool operator<=(const C& lhs, const C& rhs) - { - return lhs.ice_tuple() <= rhs.ice_tuple(); - } + /** + * Relational operator for generated structs and classes. + * @param lhs The left-hand side. + * @param rhs The right-hand side. + * @return True if the left-hand side compares less than or equal to the right-hand side, false otherwise. + */ + template< + class C, + std::enable_if_t::value, bool> = true> + bool operator<=(const C& lhs, const C& rhs) + { + return lhs.ice_tuple() <= rhs.ice_tuple(); + } - /** - * Relational operator for generated structs and classes. - * @param lhs The left-hand side. - * @param rhs The right-hand side. - * @return True if the left-hand side compares greater than the right-hand side, false otherwise. - */ - template::value>> - bool operator>(const C& lhs, const C& rhs) - { - return lhs.ice_tuple() > rhs.ice_tuple(); - } + /** + * Relational operator for generated structs and classes. + * @param lhs The left-hand side. + * @param rhs The right-hand side. + * @return True if the left-hand side compares greater than the right-hand side, false otherwise. + */ + template< + class C, + std::enable_if_t::value, bool> = true> + bool operator>(const C& lhs, const C& rhs) + { + return lhs.ice_tuple() > rhs.ice_tuple(); + } - /** - * Relational operator for generated structs and classes. - * @param lhs The left-hand side. - * @param rhs The right-hand side. - * @return True if the left-hand side compares greater than or equal to the right-hand side, false otherwise. - */ - template::value>> - bool operator>=(const C& lhs, const C& rhs) - { - return lhs.ice_tuple() >= rhs.ice_tuple(); - } + /** + * Relational operator for generated structs and classes. + * @param lhs The left-hand side. + * @param rhs The right-hand side. + * @return True if the left-hand side compares greater than or equal to the right-hand side, false otherwise. + */ + template< + class C, + std::enable_if_t::value, bool> = true> + bool operator>=(const C& lhs, const C& rhs) + { + return lhs.ice_tuple() >= rhs.ice_tuple(); + } - /** - * Relational operator for generated structs and classes. - * @param lhs The left-hand side. - * @param rhs The right-hand side. - * @return True if the left-hand side compares equal to the right-hand side, false otherwise. - */ - template::value>> - bool operator==(const C& lhs, const C& rhs) - { - return lhs.ice_tuple() == rhs.ice_tuple(); - } + /** + * Relational operator for generated structs and classes. + * @param lhs The left-hand side. + * @param rhs The right-hand side. + * @return True if the left-hand side compares equal to the right-hand side, false otherwise. + */ + template< + class C, + std::enable_if_t::value, bool> = true> + bool operator==(const C& lhs, const C& rhs) + { + return lhs.ice_tuple() == rhs.ice_tuple(); + } - /** - * Relational operator for generated structs and classes. - * @param lhs The left-hand side. - * @param rhs The right-hand side. - * @return True if the left-hand side is not equal to the right-hand side, false otherwise. - */ - template::value>> - bool operator!=(const C& lhs, const C& rhs) - { - return lhs.ice_tuple() != rhs.ice_tuple(); + /** + * Relational operator for generated structs and classes. + * @param lhs The left-hand side. + * @param rhs The right-hand side. + * @return True if the left-hand side is not equal to the right-hand side, false otherwise. + */ + template< + class C, + std::enable_if_t::value, bool> = true> + bool operator!=(const C& lhs, const C& rhs) + { + return lhs.ice_tuple() != rhs.ice_tuple(); + } } } diff --git a/cpp/include/Ice/Object.h b/cpp/include/Ice/Object.h index a15dc03d83c..90a25118561 100644 --- a/cpp/include/Ice/Object.h +++ b/cpp/include/Ice/Object.h @@ -9,6 +9,7 @@ #include "ObjectF.h" #include "OutgoingResponse.h" +#include #include namespace Ice diff --git a/cpp/include/Ice/Proxy.h b/cpp/include/Ice/Proxy.h index 88a9d1d2773..88a1a8041ec 100644 --- a/cpp/include/Ice/Proxy.h +++ b/cpp/include/Ice/Proxy.h @@ -16,6 +16,7 @@ #include "RequestHandlerF.h" #include +#include #include #include #include diff --git a/cpp/include/Ice/ProxyFunctions.h b/cpp/include/Ice/ProxyFunctions.h index f4673fb9d80..01cf42ba099 100644 --- a/cpp/include/Ice/ProxyFunctions.h +++ b/cpp/include/Ice/ProxyFunctions.h @@ -160,8 +160,8 @@ namespace Ice return proxy ? checkedCast(proxy->ice_facet(std::move(facet)), context) : std::nullopt; } - ICE_API bool operator<(const ObjectPrx&, const ObjectPrx&) noexcept; - ICE_API bool operator==(const ObjectPrx&, const ObjectPrx&) noexcept; + ICE_API bool operator<(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept; + ICE_API bool operator==(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept; inline bool operator>(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept { return rhs < lhs; } inline bool operator<=(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept { return !(lhs > rhs); } diff --git a/cpp/src/Ice/BatchRequestQueue.h b/cpp/src/Ice/BatchRequestQueue.h index 6df309ba1c2..68baca5b804 100644 --- a/cpp/src/Ice/BatchRequestQueue.h +++ b/cpp/src/Ice/BatchRequestQueue.h @@ -11,6 +11,7 @@ #include "Ice/OutputStream.h" #include +#include #include namespace IceInternal diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp index 8f517edd929..5c2f87d517f 100644 --- a/cpp/src/Ice/Proxy.cpp +++ b/cpp/src/Ice/Proxy.cpp @@ -1,16 +1,11 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// +// Copyright (c) ZeroC, Inc. #include "Ice/Proxy.h" #include "CheckIdentity.h" #include "ConnectionI.h" #include "EndpointI.h" -#include "Ice/Communicator.h" -#include "Ice/Comparable.h" -#include "Ice/Current.h" +#include "Ice/Initialize.h" #include "Ice/LocalExceptions.h" -#include "Ice/ObjectAdapter.h" #include "Instance.h" #include "LocatorInfo.h" #include "Reference.h" @@ -18,7 +13,6 @@ #include "RequestHandlerCache.h" #include "RouterInfo.h" -#include #include using namespace std; @@ -580,105 +574,3 @@ Ice::ObjectPrx::_twoway() const return _reference->changeMode(Reference::ModeTwoway); } } - -// TODO: move the code below to ProxyFunctions.cpp - -void -IceInternal::throwNullProxyMarshalException(const char* file, int line, const Current& current) -{ - ostringstream os; - os << "null proxy passed to " << current.operation << " on object " - << current.adapter->getCommunicator()->identityToString(current.id); - throw MarshalException{file, line, os.str()}; -} - -namespace Ice -{ - bool operator<(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept - { - return targetLess(lhs._getReference(), rhs._getReference()); - } - - bool operator==(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept - { - return targetEqualTo(lhs._getReference(), rhs._getReference()); - } -} - -bool -Ice::proxyIdentityLess(const optional& lhs, const optional& rhs) noexcept -{ - return lhs && rhs ? lhs->ice_getIdentity() < rhs->ice_getIdentity() - : std::less()(static_cast(lhs), static_cast(rhs)); -} - -bool -Ice::proxyIdentityEqual(const optional& lhs, const optional& rhs) noexcept -{ - return lhs && rhs ? lhs->ice_getIdentity() == rhs->ice_getIdentity() - : std::equal_to()(static_cast(lhs), static_cast(rhs)); -} - -bool -Ice::proxyIdentityAndFacetLess(const optional& lhs, const optional& rhs) noexcept -{ - if (lhs && rhs) - { - Identity lhsIdentity = lhs->ice_getIdentity(); - Identity rhsIdentity = rhs->ice_getIdentity(); - - if (lhsIdentity < rhsIdentity) - { - return true; - } - else if (rhsIdentity < lhsIdentity) - { - return false; - } - - string lhsFacet = lhs->ice_getFacet(); - string rhsFacet = rhs->ice_getFacet(); - - if (lhsFacet < rhsFacet) - { - return true; - } - else if (rhsFacet < lhsFacet) - { - return false; - } - - return false; - } - else - { - return std::less()(static_cast(lhs), static_cast(rhs)); - } -} - -bool -Ice::proxyIdentityAndFacetEqual(const optional& lhs, const optional& rhs) noexcept -{ - if (lhs && rhs) - { - Identity lhsIdentity = lhs->ice_getIdentity(); - Identity rhsIdentity = rhs->ice_getIdentity(); - - if (lhsIdentity == rhsIdentity) - { - string lhsFacet = lhs->ice_getFacet(); - string rhsFacet = rhs->ice_getFacet(); - - if (lhsFacet == rhsFacet) - { - return true; - } - } - - return false; - } - else - { - return std::equal_to()(static_cast(lhs), static_cast(rhs)); - } -} diff --git a/cpp/src/Ice/ProxyFunctions.cpp b/cpp/src/Ice/ProxyFunctions.cpp new file mode 100644 index 00000000000..dbf2ad33fee --- /dev/null +++ b/cpp/src/Ice/ProxyFunctions.cpp @@ -0,0 +1,89 @@ +// Copyright (c) ZeroC, Inc. + +#include "Ice/ProxyFunctions.h" +#include "Ice/Communicator.h" +#include "Ice/Current.h" +#include "Ice/ObjectAdapter.h" +#include "Reference.h" + +#include + +using namespace std; +using namespace Ice; +using namespace IceInternal; + +void +IceInternal::throwNullProxyMarshalException(const char* file, int line, const Current& current) +{ + ostringstream os; + os << "null proxy passed to " << current.operation << " on object " + << current.adapter->getCommunicator()->identityToString(current.id); + throw MarshalException{file, line, os.str()}; +} + +bool +Ice::operator<(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept +{ + return targetLess(lhs._getReference(), rhs._getReference()); +} + +bool +Ice::operator==(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept +{ + return targetEqualTo(lhs._getReference(), rhs._getReference()); +} + +bool +Ice::proxyIdentityLess(const optional& lhs, const optional& rhs) noexcept +{ + return lhs && rhs ? lhs->ice_getIdentity() < rhs->ice_getIdentity() + : std::less()(lhs.has_value(), rhs.has_value()); +} + +bool +Ice::proxyIdentityEqual(const optional& lhs, const optional& rhs) noexcept +{ + return lhs && rhs ? lhs->ice_getIdentity() == rhs->ice_getIdentity() + : std::equal_to()(static_cast(lhs), static_cast(rhs)); +} + +bool +Ice::proxyIdentityAndFacetLess(const optional& lhs, const optional& rhs) noexcept +{ + if (lhs && rhs) + { + Identity lhsIdentity = lhs->ice_getIdentity(); + Identity rhsIdentity = rhs->ice_getIdentity(); + + if (lhsIdentity < rhsIdentity) + { + return true; + } + else if (rhsIdentity < lhsIdentity) + { + return false; + } + + string lhsFacet = lhs->ice_getFacet(); + string rhsFacet = rhs->ice_getFacet(); + + return lhsFacet < rhsFacet; + } + else + { + return std::less()(static_cast(lhs), static_cast(rhs)); + } +} + +bool +Ice::proxyIdentityAndFacetEqual(const optional& lhs, const optional& rhs) noexcept +{ + if (lhs && rhs) + { + return lhs->ice_getIdentity() == rhs->ice_getIdentity() && lhs->ice_getFacet() == rhs->ice_getFacet(); + } + else + { + return std::equal_to()(static_cast(lhs), static_cast(rhs)); + } +} diff --git a/cpp/src/Ice/msbuild/ice/ice.vcxproj b/cpp/src/Ice/msbuild/ice/ice.vcxproj index a7fb0e32443..cb2cc0d68e3 100644 --- a/cpp/src/Ice/msbuild/ice/ice.vcxproj +++ b/cpp/src/Ice/msbuild/ice/ice.vcxproj @@ -174,6 +174,7 @@ + diff --git a/cpp/src/Ice/msbuild/ice/ice.vcxproj.filters b/cpp/src/Ice/msbuild/ice/ice.vcxproj.filters index 173f42aa478..ee23b352829 100644 --- a/cpp/src/Ice/msbuild/ice/ice.vcxproj.filters +++ b/cpp/src/Ice/msbuild/ice/ice.vcxproj.filters @@ -559,6 +559,9 @@ Source Files + + Source Files + Source Files diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 7a51d4e0f45..3999ccc4e75 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -2000,17 +2000,16 @@ Slice::Gen::DataDefVisitor::visitModuleStart(const ModulePtr& p) } void -Slice::Gen::DataDefVisitor::visitModuleEnd(const ModulePtr& p) +Slice::Gen::DataDefVisitor::visitModuleEnd(const ModulePtr&) { - if (p->contains()) - { - 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!=;"; - } + // Always generated when this module contains a struct, class, or exception. + H << sp; + H << nl << "using Ice::Tuple::operator<;"; + H << nl << "using Ice::Tuple::operator<=;"; + H << nl << "using Ice::Tuple::operator>;"; + H << nl << "using Ice::Tuple::operator>=;"; + H << nl << "using Ice::Tuple::operator==;"; + H << nl << "using Ice::Tuple::operator!=;"; H << sp << nl << '}'; _useWstring = resetUseWstring(_useWstringHist); } From a4fefb8debf5043be40a903ac852334ddd2cee80 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Mon, 7 Oct 2024 10:35:55 -0400 Subject: [PATCH 2/4] Remove StreamWriters and most StreamReaders (#2861) --- cpp/include/Ice/StreamHelpers.h | 17 +--- cpp/src/slice2cpp/CPlusPlusUtil.cpp | 148 ++++++++++++---------------- cpp/src/slice2cpp/CPlusPlusUtil.h | 12 ++- cpp/src/slice2cpp/Gen.cpp | 35 +------ cpp/src/slice2cpp/Gen.h | 4 +- 5 files changed, 82 insertions(+), 134 deletions(-) diff --git a/cpp/include/Ice/StreamHelpers.h b/cpp/include/Ice/StreamHelpers.h index 37483e26e1f..a8faae2cb6e 100644 --- a/cpp/include/Ice/StreamHelpers.h +++ b/cpp/include/Ice/StreamHelpers.h @@ -70,24 +70,11 @@ namespace Ice // /** - * General reader. slice2cpp generates specializations as needed. + * Reader used/generated for structs. Always specialized. * \headerfile Ice/Ice.h */ template struct StreamReader { - static void read(InputStream*, T&) - { - // Default is to read nothing - } - }; - - /** - * General writer. slice2cpp generates specializations as needed. - * \headerfile Ice/Ice.h - */ - template struct StreamWriter - { - static void write(OutputStream* stream, const T& v) { stream->writeAll(v.ice_tuple()); } }; /** @@ -96,7 +83,7 @@ namespace Ice */ template struct StreamHelper { - static void write(OutputStream* stream, const T& v) { StreamWriter::write(stream, v); } + static void write(OutputStream* stream, const T& v) { stream->writeAll(v.ice_tuple()); } static void read(InputStream* stream, T& v) { StreamReader::read(stream, v); } }; diff --git a/cpp/src/slice2cpp/CPlusPlusUtil.cpp b/cpp/src/slice2cpp/CPlusPlusUtil.cpp index 8befee82db7..ab86cd99390 100644 --- a/cpp/src/slice2cpp/CPlusPlusUtil.cpp +++ b/cpp/src/slice2cpp/CPlusPlusUtil.cpp @@ -93,6 +93,31 @@ namespace } } + // Split data members in required and optional members; the optional members are sorted in tag order + std::pair split(const DataMemberList& dataMembers) + { + DataMemberList requiredMembers; + DataMemberList optionalMembers; + + for (const auto& q : dataMembers) + { + if (q->optional()) + { + optionalMembers.push_back(q); + } + else + { + requiredMembers.push_back(q); + } + } + + // Sort optional data members + optionalMembers.sort([](const DataMemberPtr& lhs, const DataMemberPtr& rhs) + { return lhs->tag() < rhs->tag(); }); + + return {requiredMembers, optionalMembers}; + } + // Do we pass this type by value when it's an input parameter? bool inputParamByValue(const TypePtr& type, const StringList& metadata) { @@ -832,119 +857,74 @@ Slice::writeMarshalUnmarshalAllInHolder( { ostringstream os; os << "{"; - for (DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) + bool firstElement = true; + for (const auto& q : dataMembers) { - if (q != dataMembers.begin()) + if (firstElement) + { + firstElement = false; + } + else { os << ", "; } - os << (*q)->tag(); + os << q->tag(); } os << "}"; out << os.str(); } - for (DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) + for (const auto& q : dataMembers) { - out << holder + fixKwd((*q)->name()); + out << holder + fixKwd(q->name()); } out << epar << ";"; } void -Slice::writeStreamHelpers(Output& out, const ContainedPtr& c, DataMemberList dataMembers, bool hasBaseDataMembers) +Slice::writeStreamReader(Output& out, const StructPtr& p, const DataMemberList& dataMembers) { - // If c is a class/exception whose base class contains data members (recursively), then we need to generate - // a StreamWriter even if its implementation is empty. This is because our default marshaling uses ice_tuple() which - // contains all of our class/exception's data members as well the base data members, which breaks marshaling. This - // is not an issue for structs. - if (dataMembers.empty() && !hasBaseDataMembers) - { - return; - } - - DataMemberList requiredMembers; - DataMemberList optionalMembers; - - for (DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) - { - if ((*q)->optional()) - { - optionalMembers.push_back(*q); - } - else - { - requiredMembers.push_back(*q); - } - } - - // Sort optional data members - class SortFn - { - public: - static bool compare(const DataMemberPtr& lhs, const DataMemberPtr& rhs) { return lhs->tag() < rhs->tag(); } - }; - optionalMembers.sort(SortFn::compare); + string fullName = fixKwd(p->scoped()); - string fullName = fixKwd(c->scoped()); - string holder = "v."; - - // - // Generate StreamWriter - // - // Only generate StreamWriter specializations if we are generating optional data members and no - // base class data members - // - if (!optionalMembers.empty() || hasBaseDataMembers) - { - out << nl << "template<>"; - out << nl << "struct StreamWriter<" << fullName << ">"; - out << sb; - if (requiredMembers.empty() && optionalMembers.empty()) - { - out << nl << "static void write(OutputStream*, const " << fullName << "&)"; - } - else - { - out << nl << "static void write(OutputStream* ostr, const " << fullName << "& v)"; - } - - out << sb; - - writeMarshalUnmarshalAllInHolder(out, holder, requiredMembers, false, true); - writeMarshalUnmarshalAllInHolder(out, holder, optionalMembers, true, true); - - out << eb; - out << eb << ";" << nl; - } - - // - // Generate StreamReader - // out << nl << "template<>"; out << nl << "struct StreamReader<" << fullName << ">"; out << sb; - if (requiredMembers.empty() && optionalMembers.empty()) - { - out << nl << "static void read(InputStream*, " << fullName << "&)"; - } - else - { - out << nl << "static void read(InputStream* istr, " << fullName << "& v)"; - } - + out << nl << "static void read(InputStream* istr, " << fullName << "& v)"; out << sb; - writeMarshalUnmarshalAllInHolder(out, holder, requiredMembers, false, false); - writeMarshalUnmarshalAllInHolder(out, holder, optionalMembers, true, false); + writeMarshalUnmarshalAllInHolder(out, "v.", dataMembers, false, false); out << eb; out << eb << ";" << nl; } void -Slice::writeIceTuple(::IceInternal::Output& out, DataMemberList dataMembers, TypeContext typeCtx) +Slice::readDataMembers(Output& out, const DataMemberList& dataMembers) +{ + assert(dataMembers.size() > 0); + + auto [requiredMembers, optionalMembers] = split(dataMembers); + string holder = "this->"; + + writeMarshalUnmarshalAllInHolder(out, holder, requiredMembers, false, false); + writeMarshalUnmarshalAllInHolder(out, holder, optionalMembers, true, false); +} + +void +Slice::writeDataMembers(Output& out, const DataMemberList& dataMembers) +{ + assert(dataMembers.size() > 0); + + auto [requiredMembers, optionalMembers] = split(dataMembers); + string holder = "this->"; + + writeMarshalUnmarshalAllInHolder(out, holder, requiredMembers, false, true); + writeMarshalUnmarshalAllInHolder(out, holder, optionalMembers, true, true); +} + +void +Slice::writeIceTuple(::IceInternal::Output& out, const DataMemberList& dataMembers, TypeContext typeCtx) { // // Use an empty scope to get full qualified names from calls to typeToString. diff --git a/cpp/src/slice2cpp/CPlusPlusUtil.h b/cpp/src/slice2cpp/CPlusPlusUtil.h index fae8be79ca1..f116d9f9617 100644 --- a/cpp/src/slice2cpp/CPlusPlusUtil.h +++ b/cpp/src/slice2cpp/CPlusPlusUtil.h @@ -66,9 +66,17 @@ namespace Slice const std::string&, TypeContext); + // TODO: remove from header file. void writeMarshalUnmarshalAllInHolder(IceInternal::Output&, const std::string&, const DataMemberList&, bool, bool); - void writeStreamHelpers(::IceInternal::Output&, const ContainedPtr&, DataMemberList, bool); - void writeIceTuple(::IceInternal::Output&, DataMemberList, TypeContext); + + // Writes the StreamReader specialization for a struct. + void writeStreamReader(IceInternal::Output&, const StructPtr&, const DataMemberList&); + + // Reads or writes the data members of a class or exceptions slice. + void readDataMembers(IceInternal::Output&, const DataMemberList&); + void writeDataMembers(IceInternal::Output&, const DataMemberList&); + + void writeIceTuple(::IceInternal::Output&, const DataMemberList&, TypeContext); bool findMetadata(const std::string&, const ClassDeclPtr&, std::string&); bool findMetadata(const std::string&, const StringList&, std::string&); diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 3999ccc4e75..a732c85466b 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -2274,7 +2274,7 @@ Slice::Gen::DataDefVisitor::visitExceptionEnd(const ExceptionPtr& p) C << nl << "ostr->startSlice(ice_staticId(), -1, " << (base ? "false" : "true") << ");"; if (!dataMembers.empty()) { - C << nl << "::Ice::StreamWriter<" << name << ">::write(ostr, *this);"; + writeDataMembers(C, dataMembers); } C << nl << "ostr->endSlice();"; if (base) @@ -2289,7 +2289,7 @@ Slice::Gen::DataDefVisitor::visitExceptionEnd(const ExceptionPtr& p) C << nl << "istr->startSlice();"; if (!dataMembers.empty()) { - C << nl << "::Ice::StreamReader<" << name << ">::read(istr, *this);"; + readDataMembers(C, dataMembers); } C << nl << "istr->endSlice();"; if (base) @@ -2408,7 +2408,6 @@ Slice::Gen::DataDefVisitor::visitClassDefEnd(const ClassDefPtr& p) // Emit data members. Access visibility may be specified by metadata. // bool inProtected = false; - bool generateFriend = false; DataMemberList dataMembers = p->dataMembers(); bool prot = p->hasMetadata("protected"); bool needSp = true; @@ -2425,7 +2424,6 @@ Slice::Gen::DataDefVisitor::visitClassDefEnd(const ClassDefPtr& p) inProtected = true; needSp = false; } - generateFriend = true; } else { @@ -2460,15 +2458,6 @@ Slice::Gen::DataDefVisitor::visitClassDefEnd(const ClassDefPtr& p) inProtected = true; } - if (generateFriend) - { - H << nl << "template"; - H << nl << "friend struct Ice::StreamWriter;"; - H << nl << "template"; - H << nl << "friend struct Ice::StreamReader;"; - H << sp; - } - H << nl << name << "(const " << name << "&) = default;"; H << sp << nl << _dllMemberExport << "::Ice::ValuePtr _iceCloneImpl() const override;"; C << sp; @@ -2486,7 +2475,7 @@ Slice::Gen::DataDefVisitor::visitClassDefEnd(const ClassDefPtr& p) C << nl << "ostr->startSlice(ice_staticId(), -1, " << (base ? "false" : "true") << ");"; if (!dataMembers.empty()) { - C << nl << "::Ice::StreamWriter<" << name << ">::write(ostr, *this);"; + writeDataMembers(C, dataMembers); } C << nl << "ostr->endSlice();"; if (base) @@ -2501,7 +2490,7 @@ Slice::Gen::DataDefVisitor::visitClassDefEnd(const ClassDefPtr& p) C << nl << "istr->startSlice();"; if (!dataMembers.empty()) { - C << nl << "::Ice::StreamReader<" << name << ">::read(istr, *this);"; + readDataMembers(C, dataMembers); } C << nl << "istr->endSlice();"; if (base) @@ -3270,24 +3259,10 @@ Slice::Gen::StreamVisitor::visitStructStart(const StructPtr& p) H << nl << "static const bool fixedLength = " << (p->isVariableLength() ? "false" : "true") << ";"; H << eb << ";" << nl; - writeStreamHelpers(H, p, p->dataMembers(), false); - - return false; -} - -bool -Slice::Gen::StreamVisitor::visitClassDefStart(const ClassDefPtr& c) -{ - writeStreamHelpers(H, c, c->dataMembers(), c->hasBaseDataMembers()); + writeStreamReader(H, p, p->dataMembers()); return false; } -void -Slice::Gen::StreamVisitor::visitExceptionEnd(const ExceptionPtr& p) -{ - writeStreamHelpers(H, p, p->dataMembers(), p->hasBaseDataMembers()); -} - void Slice::Gen::StreamVisitor::visitEnum(const EnumPtr& p) { diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h index 32ff237599b..0c66d86aa52 100644 --- a/cpp/src/slice2cpp/Gen.h +++ b/cpp/src/slice2cpp/Gen.h @@ -185,7 +185,7 @@ namespace Slice std::list _useWstringHist; }; - // Generates internal StreamHelper template specializations for enums, structs, classes and exceptions. + // Generates internal StreamHelper template specializations for enums and structs. class StreamVisitor final : public ParserVisitor { public: @@ -195,8 +195,6 @@ namespace Slice bool visitModuleStart(const ModulePtr&) final; void visitModuleEnd(const ModulePtr&) final; bool visitStructStart(const StructPtr&) final; - bool visitClassDefStart(const ClassDefPtr&) final; - void visitExceptionEnd(const ExceptionPtr&) final; void visitEnum(const EnumPtr&) final; private: From ea24d76715ef4504918cdac2c9b364a44ec66f73 Mon Sep 17 00:00:00 2001 From: Austin Henriksen Date: Mon, 7 Oct 2024 10:58:14 -0400 Subject: [PATCH 3/4] Switch 'findMetadata' to Return an 'optional' (#2840) --- cpp/src/Slice/Parser.cpp | 120 +++++++++++++++------------- cpp/src/Slice/Parser.h | 10 +-- cpp/src/ice2slice/Gen.cpp | 5 +- cpp/src/slice2cpp/CPlusPlusUtil.cpp | 36 ++------- cpp/src/slice2cpp/CPlusPlusUtil.h | 2 - cpp/src/slice2cpp/Gen.cpp | 26 +++--- cpp/src/slice2cpp/Main.cpp | 5 +- cpp/src/slice2cs/CsUtil.cpp | 28 +++---- cpp/src/slice2cs/Gen.cpp | 13 ++- cpp/src/slice2java/Gen.cpp | 3 +- cpp/src/slice2java/JavaUtil.cpp | 50 +++++------- cpp/src/slice2js/Gen.cpp | 7 +- cpp/src/slice2js/JsUtil.cpp | 19 +---- cpp/src/slice2js/JsUtil.h | 1 - cpp/src/slice2matlab/Main.cpp | 18 ++--- cpp/src/slice2php/Main.cpp | 6 +- cpp/src/slice2py/PythonUtil.cpp | 43 ++++------ cpp/src/slice2rb/RubyUtil.cpp | 29 ++++--- cpp/src/slice2swift/Gen.cpp | 7 +- cpp/src/slice2swift/SwiftUtil.cpp | 24 +----- 20 files changed, 181 insertions(+), 271 deletions(-) diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index 09c334c1c97..1c56bb07f0d 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -136,7 +136,7 @@ Slice::DefinitionContext::setSeenDefinition() bool Slice::DefinitionContext::hasMetadata(const string& directive) const { - return findMetadata(directive) == directive; + return findMetadata(directive).has_value(); } void @@ -146,7 +146,7 @@ Slice::DefinitionContext::setMetadata(const StringList& metadata) initSuppressedWarnings(); } -string +optional Slice::DefinitionContext::findMetadata(const string& prefix) const { for (const auto& p : _metadata) @@ -156,7 +156,7 @@ Slice::DefinitionContext::findMetadata(const string& prefix) const return p; } } - return string(); + return nullopt; } StringList @@ -186,39 +186,42 @@ Slice::DefinitionContext::initSuppressedWarnings() { _suppressedWarnings.clear(); const string prefix = "suppress-warning"; - string value = findMetadata(prefix); - if (value == prefix) - { - _suppressedWarnings.insert(All); - } - else if (!value.empty()) + if (auto meta = findMetadata(prefix)) { - assert(value.length() > prefix.length()); - if (value[prefix.length()] == ':') + string value = *meta; + if (value == prefix) { - value = value.substr(prefix.length() + 1); - vector result; - IceInternal::splitString(value, ",", result); - for (const auto& p : result) + _suppressedWarnings.insert(All); + } + else + { + assert(value.length() > prefix.length()); + if (value[prefix.length()] == ':') { - string s = IceInternal::trim(p); - if (s == "all") + value = value.substr(prefix.length() + 1); + vector result; + IceInternal::splitString(value, ",", result); + for (const auto& p : result) { - _suppressedWarnings.insert(All); - } - else if (s == "deprecated") - { - _suppressedWarnings.insert(Deprecated); - } - else if (s == "invalid-metadata") - { - _suppressedWarnings.insert(InvalidMetadata); - } - else - { - ostringstream os; - os << "invalid category `" << s << "' in file metadata suppress-warning"; - warning(InvalidMetadata, "", -1, os.str()); + string s = IceInternal::trim(p); + if (s == "all") + { + _suppressedWarnings.insert(All); + } + else if (s == "deprecated") + { + _suppressedWarnings.insert(Deprecated); + } + else if (s == "invalid-metadata") + { + _suppressedWarnings.insert(InvalidMetadata); + } + else + { + ostringstream os; + os << "invalid category `" << s << "' in file metadata suppress-warning"; + warning(InvalidMetadata, "", -1, os.str()); + } } } } @@ -881,38 +884,36 @@ Slice::Contained::includeLevel() const bool Slice::Contained::hasMetadata(const string& directive) const { - return find(_metadata.begin(), _metadata.end(), directive) != _metadata.end(); + return findMetadata(directive).has_value(); } -bool -Slice::Contained::findMetadata(const string& prefix, string& output) const +optional +Slice::Contained::findMetadata(const string& prefix) const { for (const auto& p : _metadata) { if (p.find(prefix) == 0) { - output = p; - return true; + return p; } } - - return false; + return nullopt; } -list +StringList Slice::Contained::getMetadata() const { return _metadata; } void -Slice::Contained::setMetadata(const list& metadata) +Slice::Contained::setMetadata(const StringList& metadata) { _metadata = metadata; } std::optional -Slice::Contained::parseFormatMetadata(const list& metadata) +Slice::Contained::parseFormatMetadata(const StringList& metadata) { std::optional result; @@ -952,31 +953,40 @@ Slice::Contained::isDeprecated(bool checkParent) const { const string prefix1 = "deprecate"; const string prefix2 = "deprecated"; - string metadata; ContainedPtr parent = checkParent ? dynamic_pointer_cast(_container) : nullptr; - return (findMetadata(prefix1, metadata) || (parent && parent->findMetadata(prefix1, metadata))) || - (findMetadata(prefix2, metadata) || (parent && parent->findMetadata(prefix2, metadata))); + return (hasMetadata(prefix1) || (parent && parent->hasMetadata(prefix1))) || + (hasMetadata(prefix2) || (parent && parent->hasMetadata(prefix2))); } optional Slice::Contained::getDeprecationReason(bool checkParent) const { - string metadata; - ContainedPtr parent = checkParent ? dynamic_pointer_cast(_container) : nullptr; - const string prefix1 = "deprecate:"; - if (findMetadata(prefix1, metadata) || (parent && parent->findMetadata(prefix1, metadata))) + const string prefix2 = "deprecated:"; + + // First, we check if the element itself is deprecated. + if (auto meta = findMetadata(prefix1)) { - assert(metadata.find(prefix1) == 0); - return metadata.substr(prefix1.size()); + return meta->substr(prefix1.size()); + } + if (auto meta = findMetadata(prefix2)) + { + return meta->substr(prefix2.size()); } - const string prefix2 = "deprecated:"; - if (findMetadata(prefix2, metadata) || (parent && parent->findMetadata(prefix2, metadata))) + // Then, if necessary, we check if the container it's within is deprecated. + ContainedPtr parent = checkParent ? dynamic_pointer_cast(_container) : nullptr; + if (checkParent && parent) { - assert(metadata.find(prefix2) == 0); - return metadata.substr(prefix2.size()); + if (auto meta = parent->findMetadata(prefix1)) + { + return meta->substr(prefix1.size()); + } + if (auto meta = parent->findMetadata(prefix2)) + { + return meta->substr(prefix2.size()); + } } return nullopt; diff --git a/cpp/src/Slice/Parser.h b/cpp/src/Slice/Parser.h index 2debaf2b3c2..87928ed7c29 100644 --- a/cpp/src/Slice/Parser.h +++ b/cpp/src/Slice/Parser.h @@ -176,7 +176,7 @@ namespace Slice bool hasMetadata(const std::string& directive) const; void setMetadata(const StringList& metadata); - std::string findMetadata(const std::string& prefix) const; + std::optional findMetadata(const std::string& prefix) const; StringList getMetadata() const; /// Emits a warning unless it should be filtered out by a [["suppress-warning"]]. @@ -347,11 +347,11 @@ namespace Slice int includeLevel() const; bool hasMetadata(const std::string& directive) const; - bool findMetadata(const std::string& prefix, std::string& output) const; - std::list getMetadata() const; - void setMetadata(const std::list& metadata); + std::optional findMetadata(const std::string& prefix) const; + StringList getMetadata() const; + void setMetadata(const StringList& metadata); - static std::optional parseFormatMetadata(const std::list& metadata); + static std::optional parseFormatMetadata(const StringList& metadata); /// Returns true if this item is deprecated (due to the presence of 'deprecated' metadata). /// @param checkParent If true, this item's immediate container will also be checked for 'deprecated' metadata. diff --git a/cpp/src/ice2slice/Gen.cpp b/cpp/src/ice2slice/Gen.cpp index a732bf157f6..37e3472a111 100644 --- a/cpp/src/ice2slice/Gen.cpp +++ b/cpp/src/ice2slice/Gen.cpp @@ -108,11 +108,10 @@ namespace static const string prefix = "cs:namespace:"; - string q; - if (m->findMetadata(prefix, q)) + if (auto meta = m->findMetadata(prefix)) { hasCSharpNamespaceAttribute = true; - return q.substr(prefix.size()) + "." + csharpNamespace; + return meta->substr(prefix.size()) + "." + csharpNamespace; } else { diff --git a/cpp/src/slice2cpp/CPlusPlusUtil.cpp b/cpp/src/slice2cpp/CPlusPlusUtil.cpp index ab86cd99390..cddf3bea664 100644 --- a/cpp/src/slice2cpp/CPlusPlusUtil.cpp +++ b/cpp/src/slice2cpp/CPlusPlusUtil.cpp @@ -809,15 +809,15 @@ Slice::writeAllocateCode( const string& clScope, TypeContext typeCtx) { - for (ParamDeclList::const_iterator p = params.begin(); p != params.end(); ++p) + for (const auto& param : params) { writeParamAllocateCode( out, - (*p)->type(), - (*p)->optional(), + param->type(), + param->optional(), clScope, - fixKwd(paramPrefix + (*p)->name()), - (*p)->getMetadata(), + fixKwd(paramPrefix + param->name()), + param->getMetadata(), typeCtx); } @@ -955,32 +955,6 @@ Slice::writeIceTuple(::IceInternal::Output& out, const DataMemberList& dataMembe out << ");" << eb; } -bool -Slice::findMetadata(const string& prefix, const ClassDeclPtr& cl, string& value) -{ - if (findMetadata(prefix, cl->getMetadata(), value)) - { - return true; - } - - ClassDefPtr def = cl->definition(); - return def ? findMetadata(prefix, def->getMetadata(), value) : false; -} - -bool -Slice::findMetadata(const string& prefix, const StringList& metadata, string& value) -{ - for (const auto& s : metadata) - { - if (s.find(prefix) == 0) - { - value = s.substr(prefix.size()); - return true; - } - } - return false; -} - string Slice::findMetadata(const StringList& metadata, TypeContext typeCtx) { diff --git a/cpp/src/slice2cpp/CPlusPlusUtil.h b/cpp/src/slice2cpp/CPlusPlusUtil.h index f116d9f9617..313562be14b 100644 --- a/cpp/src/slice2cpp/CPlusPlusUtil.h +++ b/cpp/src/slice2cpp/CPlusPlusUtil.h @@ -78,8 +78,6 @@ namespace Slice void writeIceTuple(::IceInternal::Output&, const DataMemberList&, TypeContext); - bool findMetadata(const std::string&, const ClassDeclPtr&, std::string&); - bool findMetadata(const std::string&, const StringList&, std::string&); std::string findMetadata(const StringList&, TypeContext = TypeContext::None); bool inWstringModule(const SequencePtr&); } diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index a732c85466b..a2a50580a8f 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -407,10 +407,9 @@ namespace static const string prefix = "cpp:doxygen:include:"; DefinitionContextPtr dc = unt->findDefinitionContext(file); assert(dc); - string q = dc->findMetadata(prefix); - if (!q.empty()) + if (auto meta = dc->findMetadata(prefix)) { - out << nl << " * \\headerfile " << q.substr(prefix.size()); + out << nl << " * \\headerfile " << meta->substr(prefix.size()); } } @@ -662,10 +661,9 @@ Slice::Gen::generate(const UnitPtr& p) if (_dllExport.empty()) { static const string dllExportPrefix = "cpp:dll-export:"; - string meta = dc->findMetadata(dllExportPrefix); - if (meta.size() > dllExportPrefix.size()) + if (auto meta = dc->findMetadata(dllExportPrefix)) { - _dllExport = meta.substr(dllExportPrefix.size()); + _dllExport = meta->substr(dllExportPrefix.size()); } } @@ -1200,31 +1198,27 @@ Slice::Gen::resetUseWstring(list& hist) string Slice::Gen::getHeaderExt(const string& file, const UnitPtr& ut) { - string ext; static const string headerExtPrefix = "cpp:header-ext:"; DefinitionContextPtr dc = ut->findDefinitionContext(file); assert(dc); - string meta = dc->findMetadata(headerExtPrefix); - if (meta.size() > headerExtPrefix.size()) + if (auto meta = dc->findMetadata(headerExtPrefix)) { - ext = meta.substr(headerExtPrefix.size()); + return meta->substr(headerExtPrefix.size()); } - return ext; + return ""; } string Slice::Gen::getSourceExt(const string& file, const UnitPtr& ut) { - string ext; static const string sourceExtPrefix = "cpp:source-ext:"; DefinitionContextPtr dc = ut->findDefinitionContext(file); assert(dc); - string meta = dc->findMetadata(sourceExtPrefix); - if (meta.size() > sourceExtPrefix.size()) + if (auto meta = dc->findMetadata(sourceExtPrefix)) { - ext = meta.substr(sourceExtPrefix.size()); + return meta->substr(sourceExtPrefix.size()); } - return ext; + return ""; } Slice::Gen::ForwardDeclVisitor::ForwardDeclVisitor(Output& h) : H(h), _useWstring(TypeContext::None) {} diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp index 460305c6861..d015829bcdd 100644 --- a/cpp/src/slice2cpp/Main.cpp +++ b/cpp/src/slice2cpp/Main.cpp @@ -213,10 +213,9 @@ compile(const vector& argv) static const string headerExtPrefix = "cpp:header-ext:"; DefinitionContextPtr dc = u->findDefinitionContext(u->topLevelFile()); assert(dc); - string meta = dc->findMetadata(headerExtPrefix); - if (meta.size() > headerExtPrefix.size()) + if (auto meta = dc->findMetadata(headerExtPrefix)) { - ext = meta.substr(headerExtPrefix.size()); + ext = meta->substr(headerExtPrefix.size()); } u->destroy(); diff --git a/cpp/src/slice2cs/CsUtil.cpp b/cpp/src/slice2cs/CsUtil.cpp index 4b41422bd7f..9a619070cb6 100644 --- a/cpp/src/slice2cs/CsUtil.cpp +++ b/cpp/src/slice2cs/CsUtil.cpp @@ -81,13 +81,11 @@ Slice::CsGenerator::getNamespacePrefix(const ContainedPtr& cont) assert(m); static const string prefix = "cs:namespace:"; - - string q; - if (m->findMetadata(prefix, q)) + if (auto meta = m->findMetadata(prefix)) { - q = q.substr(prefix.size()); + return meta->substr(prefix.size()); } - return q; + return ""; } string @@ -360,10 +358,9 @@ Slice::CsGenerator::typeToString(const TypePtr& type, const string& package, boo if (seq) { string prefix = "cs:generic:"; - string meta; - if (seq->findMetadata(prefix, meta)) + if (auto meta = seq->findMetadata(prefix)) { - string customType = meta.substr(prefix.size()); + string customType = meta->substr(prefix.size()); if (customType == "List" || customType == "LinkedList" || customType == "Queue" || customType == "Stack") { return "global::System.Collections.Generic." + customType + "<" + typeToString(seq->type(), package) + @@ -382,11 +379,10 @@ Slice::CsGenerator::typeToString(const TypePtr& type, const string& package, boo if (d) { string prefix = "cs:generic:"; - string meta; string typeName; - if (d->findMetadata(prefix, meta)) + if (auto meta = d->findMetadata(prefix)) { - typeName = meta.substr(prefix.size()); + typeName = meta->substr(prefix.size()); } else { @@ -1164,14 +1160,15 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode( const string genericPrefix = "cs:generic:"; string genericType; string addMethod = "Add"; - const bool isGeneric = seq->findMetadata(genericPrefix, genericType); + bool isGeneric = false; bool isStack = false; bool isList = false; bool isLinkedList = false; bool isCustom = false; - if (isGeneric) + if (auto meta = seq->findMetadata(genericPrefix)) { - genericType = genericType.substr(genericPrefix.size()); + isGeneric = true; + genericType = meta->substr(genericPrefix.size()); if (genericType == "LinkedList") { addMethod = "AddLast"; @@ -1788,8 +1785,7 @@ Slice::CsGenerator::writeOptionalSequenceMarshalUnmarshalCode( const string typeS = typeToString(type, scope); const string seqS = typeToString(seq, scope); - string meta; - const bool isArray = !seq->findMetadata("cs:generic:", meta); + const bool isArray = !seq->hasMetadata("cs:generic:"); const string length = isArray ? param + ".Length" : param + ".Count"; BuiltinPtr builtin = dynamic_pointer_cast(type); diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index e88c2ca6908..94440a2f662 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -3163,10 +3163,9 @@ Slice::Gen::HelperVisitor::visitSequence(const SequencePtr& p) _out << eb; string prefix = "cs:generic:"; - string meta; - if (p->findMetadata(prefix, meta)) + if (auto meta = p->findMetadata(prefix)) { - string type = meta.substr(prefix.size()); + string type = meta->substr(prefix.size()); if (type == "List" || type == "LinkedList" || type == "Queue" || type == "Stack") { return; @@ -3200,17 +3199,15 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) TypePtr key = p->keyType(); TypePtr value = p->valueType(); - string meta; - string prefix = "cs:generic:"; string genericType; - if (!p->findMetadata(prefix, meta)) + if (auto meta = p->findMetadata(prefix)) { - genericType = "Dictionary"; + genericType = meta->substr(prefix.size()); } else { - genericType = meta.substr(prefix.size()); + genericType = "Dictionary"; } string ns = getNamespace(p); diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp index 8ca6baaa33e..35eeaf76f85 100644 --- a/cpp/src/slice2java/Gen.cpp +++ b/cpp/src/slice2java/Gen.cpp @@ -3762,13 +3762,12 @@ Slice::Gen::HelperVisitor::HelperVisitor(const string& dir) : JavaVisitor(dir) { void Slice::Gen::HelperVisitor::visitSequence(const SequencePtr& p) { - string meta; BuiltinPtr builtin = dynamic_pointer_cast(p->type()); if (!hasTypeMetadata(p) && builtin && builtin->kind() <= Builtin::KindString) { return; // No helpers for sequence of primitive types } - else if (hasTypeMetadata(p) && !p->findMetadata("java:type", meta)) + else if (hasTypeMetadata(p) && !p->hasMetadata("java:type")) { return; // No helpers for custom metadata other than java:type } diff --git a/cpp/src/slice2java/JavaUtil.cpp b/cpp/src/slice2java/JavaUtil.cpp index da3c0516eee..94e8d1f35e9 100644 --- a/cpp/src/slice2java/JavaUtil.cpp +++ b/cpp/src/slice2java/JavaUtil.cpp @@ -515,10 +515,10 @@ Slice::getSerialVersionUID(const ContainedPtr& p) optional serialVersionUID = nullopt; // Check if the user provided their own UID value with metadata. - string metadata; - if (p->findMetadata("java:serialVersionUID", metadata)) + if (auto meta = p->findMetadata("java:serialVersionUID")) { - string::size_type pos = metadata.rfind(":") + 1; + string value = *meta; + string::size_type pos = value.rfind(":") + 1; if (pos == string::npos) { ostringstream os; @@ -531,8 +531,8 @@ Slice::getSerialVersionUID(const ContainedPtr& p) { try { - metadata = metadata.substr(pos); - serialVersionUID = std::stoll(metadata, nullptr, 0); + value = value.substr(pos); + serialVersionUID = std::stoll(value, nullptr, 0); } catch (const std::exception&) { @@ -909,24 +909,20 @@ Slice::JavaGenerator::getPackagePrefix(const ContainedPtr& cont) const // static const string prefix = "java:package:"; - string q; - if (!m->findMetadata(prefix, q)) + if (auto meta = m->findMetadata(prefix)) { - UnitPtr ut = cont->unit(); - string file = cont->file(); - assert(!file.empty()); - - DefinitionContextPtr dc = ut->findDefinitionContext(file); - assert(dc); - q = dc->findMetadata(prefix); + return meta->substr(prefix.size()); } - if (!q.empty()) + string file = cont->file(); + DefinitionContextPtr dc = cont->unit()->findDefinitionContext(file); + assert(dc); + if (auto meta = dc->findMetadata(prefix)) { - q = q.substr(prefix.size()); + return meta->substr(prefix.size()); } - return q; + return ""; } string @@ -1545,7 +1541,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode( return; } } - else if (findMetadata("java:serializable", seq->getMetadata(), ignored)) + else if (seq->hasMetadata("java:serializable")) { if (marshal) { @@ -1560,7 +1556,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode( } } else if ( - !hasTypeMetadata(seq, metadata) || findMetadata("java:type", seq->getMetadata(), ignored) || + !hasTypeMetadata(seq, metadata) || seq->hasMetadata("java:type") || findMetadata("java:type", metadata, ignored)) { string instanceType, formalType, origInstanceType, origFormalType; @@ -1614,8 +1610,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode( { string ignored2; out << nl << "final int optSize = " << s << " == null ? 0 : "; - if (findMetadata("java:buffer", seq->getMetadata(), ignored2) || - findMetadata("java:buffer", metadata, ignored2)) + if (seq->hasMetadata("java:buffer") || findMetadata("java:buffer", metadata, ignored2)) { out << s << ".remaining() / " << sz << ";"; } @@ -1876,9 +1871,8 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode( BuiltinPtr builtin = dynamic_pointer_cast(seq->type()); if (builtin && builtin->kind() == Builtin::KindByte) { - string meta; static const string serializable = "java:serializable:"; - if (seq->findMetadata(serializable, meta)) + if (seq->hasMetadata(serializable)) { if (marshal) { @@ -1900,7 +1894,7 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode( { string meta; static const string bytebuffer = "java:buffer"; - if (seq->findMetadata(bytebuffer, meta) || findMetadata(bytebuffer, metadata, meta)) + if (seq->hasMetadata(bytebuffer) || findMetadata(bytebuffer, metadata, meta)) { if (marshal) { @@ -2450,10 +2444,9 @@ Slice::JavaGenerator::getSequenceTypes( if (builtin->kind() == Builtin::KindByte) { string prefix = "java:serializable:"; - string meta; - if (seq->findMetadata(prefix, meta)) + if (auto meta = seq->findMetadata(prefix)) { - instanceType = formalType = meta.substr(prefix.size()); + instanceType = formalType = meta->substr(prefix.size()); return true; } } @@ -2463,9 +2456,8 @@ Slice::JavaGenerator::getSequenceTypes( builtin->kind() == Builtin::KindFloat || builtin->kind() == Builtin::KindDouble)) { string prefix = "java:buffer"; - string meta; string ignored; - if (seq->findMetadata(prefix, meta) || findMetadata(prefix, metadata, ignored)) + if (seq->hasMetadata(prefix) || findMetadata(prefix, metadata, ignored)) { instanceType = formalType = typeToBufferString(seq->type()); return true; diff --git a/cpp/src/slice2js/Gen.cpp b/cpp/src/slice2js/Gen.cpp index 0408b93d54c..245d47563d3 100644 --- a/cpp/src/slice2js/Gen.cpp +++ b/cpp/src/slice2js/Gen.cpp @@ -1987,12 +1987,11 @@ namespace string getDefinedIn(const ContainedPtr& p) { const string prefix = "js:defined-in:"; - string meta; - if (p->findMetadata(prefix, meta)) + if (auto meta = p->findMetadata(prefix)) { - return meta.substr(prefix.size()); + return meta->substr(prefix.size()); } - return meta; + return ""; } } diff --git a/cpp/src/slice2js/JsUtil.cpp b/cpp/src/slice2js/JsUtil.cpp index 7861710d867..4b3266f89dd 100644 --- a/cpp/src/slice2js/JsUtil.cpp +++ b/cpp/src/slice2js/JsUtil.cpp @@ -145,8 +145,8 @@ Slice::getJavaScriptModule(const DefinitionContextPtr& dc) // Check if the file contains the js:module file metadata.- assert(dc); const string prefix = "js:module:"; - const string value = dc->findMetadata(prefix); - return value.empty() ? value : value.substr(prefix.size()); + const optional value = dc->findMetadata(prefix); + return value.has_value() ? (*value).substr(prefix.size()) : ""; } // @@ -196,21 +196,6 @@ Slice::JsGenerator::fixDataMemberName(const std::string& name, bool isStruct, bo return Slice::JsGenerator::fixId(name); } -bool -Slice::JsGenerator::findMetadata(const string& prefix, const StringList& metadata, string& value) -{ - for (StringList::const_iterator i = metadata.begin(); i != metadata.end(); i++) - { - string s = *i; - if (s.find(prefix) == 0) - { - value = s.substr(prefix.size()); - return true; - } - } - return false; -} - string Slice::JsGenerator::getUnqualified(const string& type, const string& scope, const string& importPrefix) { diff --git a/cpp/src/slice2js/JsUtil.h b/cpp/src/slice2js/JsUtil.h index dbf9c09c8bf..670f0cfa1c0 100644 --- a/cpp/src/slice2js/JsUtil.h +++ b/cpp/src/slice2js/JsUtil.h @@ -24,7 +24,6 @@ namespace Slice JsGenerator& operator=(const JsGenerator&) = delete; static std::string fixDataMemberName(const std::string&, bool, bool); static std::string fixId(const std::string&); - static bool findMetadata(const std::string&, const StringList&, std::string&); static std::string getUnqualified(const std::string&, const std::string&, const std::string&); diff --git a/cpp/src/slice2matlab/Main.cpp b/cpp/src/slice2matlab/Main.cpp index 81ed862393d..80030be1a8d 100644 --- a/cpp/src/slice2matlab/Main.cpp +++ b/cpp/src/slice2matlab/Main.cpp @@ -1676,13 +1676,13 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) // out << nl << "properties(Access=protected)"; out.inc(); - for (DataMemberList::const_iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { - writeMemberDoc(out, *q); - out << nl << fixIdent((*q)->name()); - if (declarePropertyType((*q)->type(), (*q)->optional())) + writeMemberDoc(out, member); + out << nl << fixIdent(member->name()); + if (declarePropertyType(member->type(), member->optional())) { - out << " " << typeToString((*q)->type()); + out << " " << typeToString(member->type()); } } out.dec(); @@ -1691,15 +1691,15 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) else { DataMemberList prot, pub; - for (DataMemberList::const_iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { - if ((*q)->hasMetadata("protected")) + if (member->hasMetadata("protected")) { - prot.push_back(*q); + prot.push_back(member); } else { - pub.push_back(*q); + pub.push_back(member); } } if (!pub.empty()) diff --git a/cpp/src/slice2php/Main.cpp b/cpp/src/slice2php/Main.cpp index 549ac14ace8..45984992d97 100644 --- a/cpp/src/slice2php/Main.cpp +++ b/cpp/src/slice2php/Main.cpp @@ -254,10 +254,10 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) { _out << sp; bool isProtected = p->hasMetadata("protected"); - for (DataMemberList::iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : members) { _out << nl; - if (isProtected || (*q)->hasMetadata("protected")) + if (isProtected || member->hasMetadata("protected")) { _out << "protected "; } @@ -265,7 +265,7 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) { _out << "public "; } - _out << "$" << fixIdent((*q)->name()) << ";"; + _out << "$" << fixIdent(member->name()) << ";"; } } diff --git a/cpp/src/slice2py/PythonUtil.cpp b/cpp/src/slice2py/PythonUtil.cpp index 3ba8fff861a..b021011747c 100644 --- a/cpp/src/slice2py/PythonUtil.cpp +++ b/cpp/src/slice2py/PythonUtil.cpp @@ -2014,21 +2014,19 @@ Slice::Python::CodeVisitor::collectClassMembers(const ClassDefPtr& p, MemberInfo collectClassMembers(base, allMembers, true); } - DataMemberList members = p->dataMembers(); - - for (DataMemberList::iterator q = members.begin(); q != members.end(); ++q) + for (const auto& member : p->dataMembers()) { MemberInfo m; - if (p->hasMetadata("protected") || (*q)->hasMetadata("protected")) + if (p->hasMetadata("protected") || member->hasMetadata("protected")) { - m.fixedName = "_" + fixIdent((*q)->name()); + m.fixedName = "_" + fixIdent(member->name()); } else { - m.fixedName = fixIdent((*q)->name()); + m.fixedName = fixIdent(member->name()); } m.inherited = inherited; - m.dataMember = *q; + m.dataMember = member; allMembers.push_back(m); } } @@ -2741,16 +2739,12 @@ Slice::Python::getPackageDirectory(const string& file, const UnitPtr& ut) DefinitionContextPtr dc = ut->findDefinitionContext(file); assert(dc); const string prefix = "python:pkgdir:"; - string pkgdir = dc->findMetadata(prefix); - if (!pkgdir.empty()) + if (auto meta = dc->findMetadata(prefix)) { - // // The metadata is present, so the generated file was placed in the specified directory. - // - pkgdir = pkgdir.substr(prefix.size()); - assert(!pkgdir.empty()); // This situation should have been caught by MetadataVisitor. + return meta->substr(prefix.size()); } - return pkgdir; + return ""; } string @@ -2902,25 +2896,20 @@ Slice::Python::getPackageMetadata(const ContainedPtr& cont) // The python:package metadata can be defined as file metadata or applied to a top-level module. // We check for the metadata at the top-level module first and then fall back to the global scope. static const string prefix = "python:package:"; - - string q; - if (!m->findMetadata(prefix, q)) + if (auto meta = m->findMetadata(prefix)) { - UnitPtr ut = cont->unit(); - string file = cont->file(); - assert(!file.empty()); - - DefinitionContextPtr dc = ut->findDefinitionContext(file); - assert(dc); - q = dc->findMetadata(prefix); + return meta->substr(prefix.size()); } - if (!q.empty()) + string file = cont->file(); + DefinitionContextPtr dc = cont->unit()->findDefinitionContext(file); + assert(dc); + if (auto meta = dc->findMetadata(prefix)) { - q = q.substr(prefix.size()); + return meta->substr(prefix.size()); } - return q; + return ""; } string diff --git a/cpp/src/slice2rb/RubyUtil.cpp b/cpp/src/slice2rb/RubyUtil.cpp index 482746b7423..76cb10349e8 100644 --- a/cpp/src/slice2rb/RubyUtil.cpp +++ b/cpp/src/slice2rb/RubyUtil.cpp @@ -546,13 +546,13 @@ Slice::Ruby::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { _out << sp; } - for (OperationList::iterator s = ops.begin(); s != ops.end(); ++s) + for (const auto& op : ops) { - ParamDeclList params = (*s)->parameters(); - ParamDeclList::iterator t; + ParamDeclList params = op->parameters(); + ParamDeclList::const_iterator t; int count; string format; - optional opFormat = (*s)->format(); + optional opFormat = op->format(); if (opFormat) { switch (*opFormat) @@ -572,9 +572,8 @@ Slice::Ruby::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) format = "nil"; } - _out << nl << name << "Prx_mixin::OP_" << (*s)->name() << " = ::Ice::__defineOperation('" << (*s)->name() - << "', "; - switch ((*s)->mode()) + _out << nl << name << "Prx_mixin::OP_" << op->name() << " = ::Ice::__defineOperation('" << op->name() << "', "; + switch (op->mode()) { case Operation::Normal: _out << "::Ice::OperationMode::Normal"; @@ -583,7 +582,7 @@ Slice::Ruby::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) _out << "::Ice::OperationMode::Idempotent"; break; } - _out << ", " << ((p->hasMetadata("amd") || (*s)->hasMetadata("amd")) ? "true" : "false") << ", " << format + _out << ", " << ((p->hasMetadata("amd") || op->hasMetadata("amd")) ? "true" : "false") << ", " << format << ", ["; for (t = params.begin(), count = 0; t != params.end(); ++t) { @@ -617,7 +616,7 @@ Slice::Ruby::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) } } _out << "], "; - TypePtr returnType = (*s)->returnType(); + TypePtr returnType = op->returnType(); if (returnType) { // @@ -627,15 +626,15 @@ Slice::Ruby::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // _out << '['; writeType(returnType); - _out << ", " << ((*s)->returnIsOptional() ? "true" : "false") << ", " - << ((*s)->returnIsOptional() ? (*s)->returnTag() : 0) << ']'; + _out << ", " << (op->returnIsOptional() ? "true" : "false") << ", " + << (op->returnIsOptional() ? op->returnTag() : 0) << ']'; } else { _out << "nil"; } _out << ", ["; - ExceptionList exceptions = (*s)->throws(); + ExceptionList exceptions = op->throws(); for (ExceptionList::iterator u = exceptions.begin(); u != exceptions.end(); ++u) { if (u != exceptions.begin()) @@ -646,11 +645,11 @@ Slice::Ruby::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) } _out << "])"; - if ((*s)->isDeprecated(true)) + if (op->isDeprecated(true)) { // Get the deprecation reason if present, or default to an empty string. - string reason = (*s)->getDeprecationReason(true).value_or(""); - _out << nl << name << "Prx_mixin::OP_" << (*s)->name() << ".deprecate(\"" << reason << "\")"; + string reason = op->getDeprecationReason(true).value_or(""); + _out << nl << name << "Prx_mixin::OP_" << op->name() << ".deprecate(\"" << reason << "\")"; } } diff --git a/cpp/src/slice2swift/Gen.cpp b/cpp/src/slice2swift/Gen.cpp index dfb04f22434..3332e9daaf9 100644 --- a/cpp/src/slice2swift/Gen.cpp +++ b/cpp/src/slice2swift/Gen.cpp @@ -27,12 +27,11 @@ namespace assert(dc); static const string classResolverPrefix = "swift:class-resolver-prefix:"; - string result = dc->findMetadata(classResolverPrefix); - if (!result.empty()) + if (auto meta = dc->findMetadata(classResolverPrefix)) { - result = result.substr(classResolverPrefix.size()); + return meta->substr(classResolverPrefix.size()); } - return result; + return ""; } } diff --git a/cpp/src/slice2swift/SwiftUtil.cpp b/cpp/src/slice2swift/SwiftUtil.cpp index b6c1636f4d4..4c3238e61f6 100644 --- a/cpp/src/slice2swift/SwiftUtil.cpp +++ b/cpp/src/slice2swift/SwiftUtil.cpp @@ -191,9 +191,9 @@ Slice::getSwiftModule(const ModulePtr& module, string& swiftPrefix) string swiftModule; - if (module->findMetadata(modulePrefix, swiftModule)) + if (auto meta = module->findMetadata(modulePrefix)) { - swiftModule = swiftModule.substr(modulePrefix.size()); + swiftModule = meta->substr(modulePrefix.size()); size_t pos = swiftModule.find(':'); if (pos != string::npos) @@ -1668,26 +1668,8 @@ SwiftGenerator::MetadataVisitor::visitModuleStart(const ModulePtr& p) // top-level module const UnitPtr unit = p->unit(); - const string modulePrefix = "swift:module:"; - - string swiftModule; string swiftPrefix; - - if (p->findMetadata(modulePrefix, swiftModule)) - { - swiftModule = swiftModule.substr(modulePrefix.size()); - - size_t pos = swiftModule.find(':'); - if (pos != string::npos) - { - swiftPrefix = swiftModule.substr(pos + 1); - swiftModule = swiftModule.substr(0, pos); - } - } - else - { - swiftModule = p->name(); - } + string swiftModule = getSwiftModule(p, swiftPrefix); const string filename = p->definitionContext()->filename(); ModuleMap::const_iterator current = _modules.find(filename); From dfbdfb35e9f51cef21346ef25a09220e5aa545a5 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Mon, 7 Oct 2024 11:55:02 -0400 Subject: [PATCH 4/4] Disable relational operators for classes and exceptions (#2862) --- cpp/include/Ice/Comparable.h | 36 ++++++++---- cpp/src/slice2cpp/Gen.cpp | 22 ++++--- cpp/test/Ice/objects/AllTests.cpp | 10 +--- cpp/test/Ice/scope/AllTests.cpp | 96 +++++++++++++++---------------- 4 files changed, 88 insertions(+), 76 deletions(-) diff --git a/cpp/include/Ice/Comparable.h b/cpp/include/Ice/Comparable.h index ccca9247ed5..c2322564240 100644 --- a/cpp/include/Ice/Comparable.h +++ b/cpp/include/Ice/Comparable.h @@ -117,84 +117,96 @@ namespace Ice namespace Tuple { /** - * Relational operator for generated structs and classes. + * Relational operator for generated structs. * @param lhs The left-hand side. * @param rhs The right-hand side. * @return True if the left-hand side compares less than the right-hand side, false otherwise. */ template< class C, - std::enable_if_t::value, bool> = true> + std::enable_if_t< + std::is_member_function_pointer::value && !std::is_polymorphic_v, + bool> = true> bool operator<(const C& lhs, const C& rhs) { return lhs.ice_tuple() < rhs.ice_tuple(); } /** - * Relational operator for generated structs and classes. + * Relational operator for generated structs. * @param lhs The left-hand side. * @param rhs The right-hand side. * @return True if the left-hand side compares less than or equal to the right-hand side, false otherwise. */ template< class C, - std::enable_if_t::value, bool> = true> + std::enable_if_t< + std::is_member_function_pointer::value && !std::is_polymorphic_v, + bool> = true> bool operator<=(const C& lhs, const C& rhs) { return lhs.ice_tuple() <= rhs.ice_tuple(); } /** - * Relational operator for generated structs and classes. + * Relational operator for generated structs. * @param lhs The left-hand side. * @param rhs The right-hand side. * @return True if the left-hand side compares greater than the right-hand side, false otherwise. */ template< class C, - std::enable_if_t::value, bool> = true> + std::enable_if_t< + std::is_member_function_pointer::value && !std::is_polymorphic_v, + bool> = true> bool operator>(const C& lhs, const C& rhs) { return lhs.ice_tuple() > rhs.ice_tuple(); } /** - * Relational operator for generated structs and classes. + * Relational operator for generated structs. * @param lhs The left-hand side. * @param rhs The right-hand side. * @return True if the left-hand side compares greater than or equal to the right-hand side, false otherwise. */ template< class C, - std::enable_if_t::value, bool> = true> + std::enable_if_t< + std::is_member_function_pointer::value && !std::is_polymorphic_v, + bool> = true> bool operator>=(const C& lhs, const C& rhs) { return lhs.ice_tuple() >= rhs.ice_tuple(); } /** - * Relational operator for generated structs and classes. + * Relational operator for generated structs. * @param lhs The left-hand side. * @param rhs The right-hand side. * @return True if the left-hand side compares equal to the right-hand side, false otherwise. */ template< class C, - std::enable_if_t::value, bool> = true> + std::enable_if_t< + std::is_member_function_pointer::value && !std::is_polymorphic_v, + bool> = true> bool operator==(const C& lhs, const C& rhs) { return lhs.ice_tuple() == rhs.ice_tuple(); } /** - * Relational operator for generated structs and classes. + * Relational operator for generated structs. * @param lhs The left-hand side. * @param rhs The right-hand side. * @return True if the left-hand side is not equal to the right-hand side, false otherwise. */ template< class C, - std::enable_if_t::value, bool> = true> + std::enable_if_t< + std::is_member_function_pointer::value && !std::is_polymorphic_v, + bool> = true> bool operator!=(const C& lhs, const C& rhs) { return lhs.ice_tuple() != rhs.ice_tuple(); diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index a2a50580a8f..5798d33cb82 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -1994,16 +1994,20 @@ Slice::Gen::DataDefVisitor::visitModuleStart(const ModulePtr& p) } void -Slice::Gen::DataDefVisitor::visitModuleEnd(const ModulePtr&) +Slice::Gen::DataDefVisitor::visitModuleEnd(const ModulePtr& p) { - // Always generated when this module contains a struct, class, or exception. - H << sp; - H << nl << "using Ice::Tuple::operator<;"; - H << nl << "using Ice::Tuple::operator<=;"; - H << nl << "using Ice::Tuple::operator>;"; - H << nl << "using Ice::Tuple::operator>=;"; - H << nl << "using Ice::Tuple::operator==;"; - H << nl << "using Ice::Tuple::operator!=;"; + if (p->contains()) + { + // Bring in relational operators for structs. + H << sp; + H << nl << "using Ice::Tuple::operator<;"; + H << nl << "using Ice::Tuple::operator<=;"; + H << nl << "using Ice::Tuple::operator>;"; + H << nl << "using Ice::Tuple::operator>=;"; + H << nl << "using Ice::Tuple::operator==;"; + H << nl << "using Ice::Tuple::operator!=;"; + } + H << sp << nl << '}'; _useWstring = resetUseWstring(_useWstringHist); } diff --git a/cpp/test/Ice/objects/AllTests.cpp b/cpp/test/Ice/objects/AllTests.cpp index 9fda75de661..e498215931b 100644 --- a/cpp/test/Ice/objects/AllTests.cpp +++ b/cpp/test/Ice/objects/AllTests.cpp @@ -66,18 +66,14 @@ allTests(Test::TestHelper* helper) test(ba2->theS.str == "hello"); test(ba2->str == "hi"); - test(*ba1 < *ba2); - test(*ba2 > *ba1); - test(*ba1 != *ba2); + auto [s2, str2] = ba2->ice_tuple(); + test(s2 == s); + test(str2 == "hi"); ba1 = ba2->ice_clone(); test(ba1->theS.str == "hello"); test(ba1->str == "hi"); - test(*ba1 == *ba2); - test(*ba1 >= *ba2); - test(*ba1 <= *ba2); - BasePtr bp1 = make_shared(); bp1 = ba2->ice_clone(); test(bp1->theS.str == "hello"); diff --git a/cpp/test/Ice/scope/AllTests.cpp b/cpp/test/Ice/scope/AllTests.cpp index c0c2b2de29f..4804799d941 100644 --- a/cpp/test/Ice/scope/AllTests.cpp +++ b/cpp/test/Ice/scope/AllTests.cpp @@ -105,24 +105,24 @@ allTests(Test::TestHelper* helper) Test::CPtr c1 = make_shared(s1); { auto result = i->opCAsync(c1).get(); - test(Ice::targetEqualTo(std::get<0>(result), c1)); - test(Ice::targetEqualTo(std::get<1>(result), c1)); + test(std::get<0>(result)->ice_tuple() == c1->ice_tuple()); + test(std::get<1>(result)->ice_tuple() == c1->ice_tuple()); } Test::CSeq cseq1; cseq1.push_back(c1); { auto result = i->opCSeqAsync(cseq1).get(); - test(Ice::targetEqualTo(std::get<0>(result)[0], c1)); - test(Ice::targetEqualTo(std::get<1>(result)[0], c1)); + test(std::get<0>(result)[0]->ice_tuple() == c1->ice_tuple()); + test(std::get<1>(result)[0]->ice_tuple() == c1->ice_tuple()); } Test::CMap cmap1; cmap1["a"] = c1; { auto result = i->opCMapAsync(cmap1).get(); - test(Ice::targetEqualTo(std::get<0>(result)["a"], c1)); - test(Ice::targetEqualTo(std::get<1>(result)["a"], c1)); + test(std::get<0>(result)["a"]->ice_tuple() == c1->ice_tuple()); + test(std::get<1>(result)["a"]->ice_tuple() == c1->ice_tuple()); } { @@ -235,8 +235,8 @@ allTests(Test::TestHelper* helper) c1, [&p, &c1](Test::CPtr c2, Test::CPtr c3) { - test(Ice::targetEqualTo(c2, c1)); - test(Ice::targetEqualTo(c3, c1)); + test(c2->ice_tuple() == c1->ice_tuple()); + test(c3->ice_tuple() == c1->ice_tuple()); p.set_value(); }, [&p](exception_ptr e) { p.set_exception(e); }); @@ -261,8 +261,8 @@ allTests(Test::TestHelper* helper) cseq1, [&p, c1](Test::CSeq c2, Test::CSeq c3) { - test(Ice::targetEqualTo(c2[0], c1)); - test(Ice::targetEqualTo(c3[0], c1)); + test(c2[0]->ice_tuple() == c1->ice_tuple()); + test((c3[0]->ice_tuple() == c1->ice_tuple())); p.set_value(); }, [&p](exception_ptr e) { p.set_exception(e); }); @@ -287,8 +287,8 @@ allTests(Test::TestHelper* helper) cmap1, [&p, c1](Test::CMap c2, Test::CMap c3) { - test(Ice::targetEqualTo(c2["a"], c1)); - test(Ice::targetEqualTo(c3["a"], c1)); + test(c2["a"]->ice_tuple() == c1->ice_tuple()); + test((c3["a"]->ice_tuple() == c1->ice_tuple())); p.set_value(); }, [&p](exception_ptr e) { p.set_exception(e); }); @@ -454,24 +454,24 @@ allTests(Test::TestHelper* helper) Test::Inner::Inner2::CPtr c1 = make_shared(s1); { auto result = i->opCAsync(c1).get(); - test(Ice::targetEqualTo(std::get<0>(result), c1)); - test(Ice::targetEqualTo(std::get<1>(result), c1)); + test(std::get<0>(result)->ice_tuple() == c1->ice_tuple()); + test(std::get<1>(result)->ice_tuple() == c1->ice_tuple()); } Test::Inner::Inner2::CSeq cseq1; cseq1.push_back(c1); { auto result = i->opCSeqAsync(cseq1).get(); - test(Ice::targetEqualTo(std::get<0>(result)[0], c1)); - test(Ice::targetEqualTo(std::get<1>(result)[0], c1)); + test(std::get<0>(result)[0]->ice_tuple() == c1->ice_tuple()); + test(std::get<1>(result)[0]->ice_tuple() == c1->ice_tuple()); } Test::Inner::Inner2::CMap cmap1; cmap1["a"] = c1; { auto result = i->opCMapAsync(cmap1).get(); - test(Ice::targetEqualTo(std::get<0>(result)["a"], c1)); - test(Ice::targetEqualTo(std::get<1>(result)["a"], c1)); + test(std::get<0>(result)["a"]->ice_tuple() == c1->ice_tuple()); + test(std::get<1>(result)["a"]->ice_tuple() == c1->ice_tuple()); } } @@ -567,8 +567,8 @@ allTests(Test::TestHelper* helper) c1, [&p, &c1](shared_ptr c2, shared_ptr c3) { - test(Ice::targetEqualTo(c2, c1)); - test(Ice::targetEqualTo(c3, c1)); + test(c2->ice_tuple() == c1->ice_tuple()); + test((c3->ice_tuple() == c1->ice_tuple())); p.set_value(); }, [&p](exception_ptr e) { p.set_exception(e); }); @@ -593,8 +593,8 @@ allTests(Test::TestHelper* helper) cseq1, [&p, c1](Test::Inner::Inner2::CSeq c2, Test::Inner::Inner2::CSeq c3) { - test(Ice::targetEqualTo(c2[0], c1)); - test(Ice::targetEqualTo(c3[0], c1)); + test(c2[0]->ice_tuple() == c1->ice_tuple()); + test((c3[0]->ice_tuple() == c1->ice_tuple())); p.set_value(); }, [&p](exception_ptr e) { p.set_exception(e); }); @@ -619,8 +619,8 @@ allTests(Test::TestHelper* helper) cmap1, [&p, c1](Test::Inner::Inner2::CMap c2, Test::Inner::Inner2::CMap c3) { - test(Ice::targetEqualTo(c2["a"], c1)); - test(Ice::targetEqualTo(c3["a"], c1)); + test(c2["a"]->ice_tuple() == c1->ice_tuple()); + test((c3["a"]->ice_tuple() == c1->ice_tuple())); p.set_value(); }, [&p](exception_ptr e) { p.set_exception(e); }); @@ -715,24 +715,24 @@ allTests(Test::TestHelper* helper) Test::Inner::Inner2::CPtr c1 = make_shared(s1); { auto result = i->opCAsync(c1).get(); - test(Ice::targetEqualTo(std::get<0>(result), c1)); - test(Ice::targetEqualTo(std::get<1>(result), c1)); + test(std::get<0>(result)->ice_tuple() == c1->ice_tuple()); + test(std::get<1>(result)->ice_tuple() == c1->ice_tuple()); } Test::Inner::Inner2::CSeq cseq1; cseq1.push_back(c1); { auto result = i->opCSeqAsync(cseq1).get(); - test(Ice::targetEqualTo(std::get<0>(result)[0], c1)); - test(Ice::targetEqualTo(std::get<1>(result)[0], c1)); + test(std::get<0>(result)[0]->ice_tuple() == c1->ice_tuple()); + test(std::get<1>(result)[0]->ice_tuple() == c1->ice_tuple()); } Test::Inner::Inner2::CMap cmap1; cmap1["a"] = c1; { auto result = i->opCMapAsync(cmap1).get(); - test(Ice::targetEqualTo(std::get<0>(result)["a"], c1)); - test(Ice::targetEqualTo(std::get<1>(result)["a"], c1)); + test(std::get<0>(result)["a"]->ice_tuple() == c1->ice_tuple()); + test(std::get<1>(result)["a"]->ice_tuple() == c1->ice_tuple()); } } @@ -828,8 +828,8 @@ allTests(Test::TestHelper* helper) c1, [&p, &c1](shared_ptr c2, shared_ptr c3) { - test(Ice::targetEqualTo(c2, c1)); - test(Ice::targetEqualTo(c3, c1)); + test(c2->ice_tuple() == c1->ice_tuple()); + test(c3->ice_tuple() == c1->ice_tuple()); p.set_value(); }, [&p](exception_ptr e) { p.set_exception(e); }); @@ -854,8 +854,8 @@ allTests(Test::TestHelper* helper) cseq1, [&p, c1](Test::Inner::Inner2::CSeq c2, Test::Inner::Inner2::CSeq c3) { - test(Ice::targetEqualTo(c2[0], c1)); - test(Ice::targetEqualTo(c3[0], c1)); + test(c2[0]->ice_tuple() == c1->ice_tuple()); + test(c3[0]->ice_tuple() == c1->ice_tuple()); p.set_value(); }, [&p](exception_ptr e) { p.set_exception(e); }); @@ -880,8 +880,8 @@ allTests(Test::TestHelper* helper) cmap1, [&p, c1](Test::Inner::Inner2::CMap c2, Test::Inner::Inner2::CMap c3) { - test(Ice::targetEqualTo(c2["a"], c1)); - test(Ice::targetEqualTo(c3["a"], c1)); + test(c2["a"]->ice_tuple() == c1->ice_tuple()); + test(c3["a"]->ice_tuple() == c1->ice_tuple()); p.set_value(); }, [&p](exception_ptr e) { p.set_exception(e); }); @@ -976,24 +976,24 @@ allTests(Test::TestHelper* helper) Test::CPtr c1 = make_shared(s1); { auto result = i->opCAsync(c1).get(); - test(Ice::targetEqualTo(std::get<0>(result), c1)); - test(Ice::targetEqualTo(std::get<1>(result), c1)); + test(std::get<0>(result)->ice_tuple() == c1->ice_tuple()); + test(std::get<1>(result)->ice_tuple() == c1->ice_tuple()); } Test::CSeq cseq1; cseq1.push_back(c1); { auto result = i->opCSeqAsync(cseq1).get(); - test(Ice::targetEqualTo(std::get<0>(result)[0], c1)); - test(Ice::targetEqualTo(std::get<1>(result)[0], c1)); + test(std::get<0>(result)[0]->ice_tuple() == c1->ice_tuple()); + test(std::get<1>(result)[0]->ice_tuple() == c1->ice_tuple()); } Test::CMap cmap1; cmap1["a"] = c1; { auto result = i->opCMapAsync(cmap1).get(); - test(Ice::targetEqualTo(std::get<0>(result)["a"], c1)); - test(Ice::targetEqualTo(std::get<1>(result)["a"], c1)); + test(std::get<0>(result)["a"]->ice_tuple() == c1->ice_tuple()); + test(std::get<1>(result)["a"]->ice_tuple() == c1->ice_tuple()); } } @@ -1089,8 +1089,8 @@ allTests(Test::TestHelper* helper) c1, [&p, &c1](shared_ptr c2, shared_ptr c3) { - test(Ice::targetEqualTo(c2, c1)); - test(Ice::targetEqualTo(c3, c1)); + test(c2->ice_tuple() == c1->ice_tuple()); + test(c3->ice_tuple() == c1->ice_tuple()); p.set_value(); }, [&p](exception_ptr e) { p.set_exception(e); }); @@ -1115,8 +1115,8 @@ allTests(Test::TestHelper* helper) cseq1, [&p, c1](Test::CSeq c2, Test::CSeq c3) { - test(Ice::targetEqualTo(c2[0], c1)); - test(Ice::targetEqualTo(c3[0], c1)); + test(c2[0]->ice_tuple() == c1->ice_tuple()); + test(c3[0]->ice_tuple() == c1->ice_tuple()); p.set_value(); }, [&p](exception_ptr e) { p.set_exception(e); }); @@ -1141,8 +1141,8 @@ allTests(Test::TestHelper* helper) cmap1, [&p, c1](Test::CMap c2, Test::CMap c3) { - test(Ice::targetEqualTo(c2["a"], c1)); - test(Ice::targetEqualTo(c3["a"], c1)); + test(c2["a"]->ice_tuple() == c1->ice_tuple()); + test(c3["a"]->ice_tuple() == c1->ice_tuple()); p.set_value(); }, [&p](exception_ptr e) { p.set_exception(e); });