From d9285e958448e51e205d83f161956208bea7e506 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Thu, 22 Feb 2024 14:27:02 -0500 Subject: [PATCH 1/8] Use local allOperations array --- cpp/src/slice2cpp/Gen.cpp | 60 +++++++++++++++++++++------------------ cpp/src/slice2cpp/Gen.h | 2 ++ 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index f43a6bd4e79..34016cced0e 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -1742,8 +1742,6 @@ Slice::Gen::DefaultFactoryVisitor::visitExceptionStart(const ExceptionPtr& p) bool Slice::Gen::DefaultFactoryVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { - OperationList allOps = p->allOperations(); - C << sp; StringList ids = p->ids(); @@ -1759,27 +1757,6 @@ Slice::Gen::DefaultFactoryVisitor::visitInterfaceDefStart(const InterfaceDefPtr& } C << eb << ';'; - StringList allOpNames; - transform(allOps.begin(), allOps.end(), back_inserter(allOpNames), [](const auto &c) { return c->name(); }); - allOpNames.push_back("ice_id"); - allOpNames.push_back("ice_ids"); - allOpNames.push_back("ice_isA"); - allOpNames.push_back("ice_ping"); - allOpNames.sort(); - allOpNames.unique(); - - C << nl << "const ::std::string iceC" << p->flattenedScope() << p->name() << "_ops[] ="; - C << sb; - for (StringList::const_iterator q = allOpNames.begin(); q != allOpNames.end();) - { - C << nl << '"' << *q << '"'; - if (++q != allOpNames.end()) - { - C << ','; - } - } - C << eb << ';'; - return true; } @@ -3317,8 +3294,6 @@ Slice::Gen::InterfaceVisitor::visitInterfaceDefEnd(const InterfaceDefPtr& p) allOpNames.sort(); allOpNames.unique(); - string flatName = "iceC" + p->flattenedScope() + p->name() + "_ops"; - H << sp; H << nl << "/// \\cond INTERNAL"; H << nl << "virtual bool _iceDispatch(::IceInternal::Incoming&, const " @@ -3332,8 +3307,11 @@ Slice::Gen::InterfaceVisitor::visitInterfaceDefEnd(const InterfaceDefPtr& p) << getUnqualified("::Ice::Current&", scope) << " current)"; C << sb; + emitAllOperationsArray(p); + + C << sp; C << nl << "::std::pair r = " - << "::std::equal_range(" << flatName << ", " << flatName << " + " << allOpNames.size() + << "::std::equal_range(allOperations, allOperations" << " + " << allOpNames.size() << ", current.operation);"; C << nl << "if(r.first == r.second)"; C << sb; @@ -3341,7 +3319,7 @@ Slice::Gen::InterfaceVisitor::visitInterfaceDefEnd(const InterfaceDefPtr& p) << "(__FILE__, __LINE__, current.id, current.facet, current.operation);"; C << eb; C << sp; - C << nl << "switch(r.first - " << flatName << ')'; + C << nl << "switch(r.first - allOperations)"; C << sb; int i = 0; for(StringList::const_iterator q = allOpNames.begin(); q != allOpNames.end(); ++q) @@ -3661,6 +3639,34 @@ Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p) C << nl << "/// \\endcond"; } +void +Slice::Gen::InterfaceVisitor::emitAllOperationsArray(const InterfaceDefPtr& p) +{ + C << sp; + + OperationList allOps = p->allOperations(); + StringList allOpNames; + transform(allOps.begin(), allOps.end(), back_inserter(allOpNames), [](const auto &c) { return c->name(); }); + allOpNames.push_back("ice_id"); + allOpNames.push_back("ice_ids"); + allOpNames.push_back("ice_isA"); + allOpNames.push_back("ice_ping"); + allOpNames.sort(); + allOpNames.unique(); + + C << nl << "static const ::std::string allOperations[] ="; + C << sb; + for (StringList::const_iterator q = allOpNames.begin(); q != allOpNames.end();) + { + C << nl << '"' << *q << '"'; + if (++q != allOpNames.end()) + { + C << ','; + } + } + C << eb << ';'; +} + Slice::Gen::StreamVisitor::StreamVisitor(Output& h) : H(h) { diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h index 0c0fd7813b2..9f62438517c 100644 --- a/cpp/src/slice2cpp/Gen.h +++ b/cpp/src/slice2cpp/Gen.h @@ -192,6 +192,8 @@ class Gen private: + void emitAllOperationsArray(const InterfaceDefPtr&); + ::IceUtilInternal::Output& H; ::IceUtilInternal::Output& C; From a90c5d19af2b117e49b05610d574c633764a8c1d Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Thu, 22 Feb 2024 14:36:45 -0500 Subject: [PATCH 2/8] Use constexpr string_view --- cpp/src/slice2cpp/Gen.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 34016cced0e..38e5923fcf4 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -3310,7 +3310,7 @@ Slice::Gen::InterfaceVisitor::visitInterfaceDefEnd(const InterfaceDefPtr& p) emitAllOperationsArray(p); C << sp; - C << nl << "::std::pair r = " + C << nl << "::std::pair r = " << "::std::equal_range(allOperations, allOperations" << " + " << allOpNames.size() << ", current.operation);"; C << nl << "if(r.first == r.second)"; @@ -3654,7 +3654,7 @@ Slice::Gen::InterfaceVisitor::emitAllOperationsArray(const InterfaceDefPtr& p) allOpNames.sort(); allOpNames.unique(); - C << nl << "static const ::std::string allOperations[] ="; + C << nl << "static constexpr ::std::string_view allOperations[] ="; C << sb; for (StringList::const_iterator q = allOpNames.begin(); q != allOpNames.end();) { From 0e3c557b98dfa9ab24fa275880585be288408fb6 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Thu, 22 Feb 2024 14:59:48 -0500 Subject: [PATCH 3/8] Generate operation name as local static --- cpp/include/Ice/LocalException.h | 12 ++++++++++++ cpp/include/Ice/Proxy.h | 2 +- cpp/src/Ice/Proxy.cpp | 2 +- cpp/src/slice2cpp/Gen.cpp | 25 ++++++++++++------------- cpp/src/slice2cpp/Gen.h | 1 - 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/cpp/include/Ice/LocalException.h b/cpp/include/Ice/LocalException.h index 5bda1e9b550..8a19ef2416a 100644 --- a/cpp/include/Ice/LocalException.h +++ b/cpp/include/Ice/LocalException.h @@ -365,6 +365,18 @@ class ICE_CLASS(ICE_API) TwowayOnlyException : public LocalExceptionHelper(file, line), operation(operation) { + } + + /** + * One-shot constructor to initialize all data members. + * The file and line number are required for all local exceptions. + * @param file The file name in which the exception was raised, typically __FILE__. + * @param line The line number at which the exception was raised, typically __LINE__. + * @param operation The name of the operation that was invoked. + */ + TwowayOnlyException(const char* file, int line, ::std::string_view operation) : LocalExceptionHelper(file, line), + operation(operation) + { } /** diff --git a/cpp/include/Ice/Proxy.h b/cpp/include/Ice/Proxy.h index a92221c6c43..9f2f1cdcdd0 100644 --- a/cpp/include/Ice/Proxy.h +++ b/cpp/include/Ice/Proxy.h @@ -826,7 +826,7 @@ class ICE_API ObjectPrx : public Proxy const ::IceInternal::ReferencePtr& _getReference() const { return _reference; } const ::IceInternal::RequestHandlerCachePtr& _getRequestHandlerCache() const { return _requestHandlerCache; } - void _checkTwowayOnly(const std::string&) const; + void _checkTwowayOnly(std::string_view) const; int _hash() const; diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp index 78b202aa977..b93b1175ad4 100644 --- a/cpp/src/Ice/Proxy.cpp +++ b/cpp/src/Ice/Proxy.cpp @@ -58,7 +58,7 @@ Ice::ObjectPrx::ObjectPrx(ReferencePtr&& ref) : } void -Ice::ObjectPrx::_checkTwowayOnly(const string& name) const +Ice::ObjectPrx::_checkTwowayOnly(string_view name) const { if (!ice_isTwoway()) { diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 38e5923fcf4..f8a5f7138aa 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -1760,13 +1760,6 @@ Slice::Gen::DefaultFactoryVisitor::visitInterfaceDefStart(const InterfaceDefPtr& return true; } -void -Slice::Gen::DefaultFactoryVisitor::visitOperation(const OperationPtr& p) -{ - string flatName = "iceC" + p->flattenedScope() + p->name() + "_name"; - C << nl << "const ::std::string " << flatName << " = \"" << p->name() << "\";"; -} - Slice::Gen::ProxyVisitor::ProxyVisitor(Output& h, Output& c, const string& dllExport) : H(h), C(c), _dllExport(dllExport), _useWstring(false) { @@ -1932,8 +1925,6 @@ void Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) { string name = p->name(); - string flatName = "iceC" + p->flattenedScope() + p->name() + "_name"; - InterfaceDefPtr interface = p->interface(); string interfaceScope = fixKwd(interface->scope()); @@ -2196,9 +2187,14 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) // "Custom" implementation in .cpp file // C << sb; + + // TODO: switch to string_view and constexpr. + C << nl << "static const ::std::string operationName = \"" << name << "\";"; + C << sp; + if(p->returnsData()) { - C << nl << "_checkTwowayOnly(" << flatName << ");"; + C << nl << "_checkTwowayOnly(operationName);"; } C << nl << "::std::function read;"; @@ -2237,7 +2233,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) C << "*this, read, ex, sent);"; C << sp; - C << nl << "outAsync->invoke(" << flatName << ", "; + C << nl << "outAsync->invoke(operationName, "; C << operationModeToString(p->sendMode(), true) << ", " << opFormatTypeToString(p, true) << ", context,"; C.inc(); C << nl; @@ -2311,11 +2307,14 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) C << inParamsImplDecl << ("const " + getUnqualified("::Ice::Context&", interfaceScope) + " context"); C << epar << " const"; C << sb; + // TODO: switch to string_view and constexpr. + C << nl << "static const ::std::string operationName = \"" << name << "\";"; + C << sp; if(p->returnsData()) { - C << nl << "_checkTwowayOnly(" << flatName << ");"; + C << nl << "_checkTwowayOnly(operationName);"; } - C << nl << "outAsync->invoke(" << flatName << ", "; + C << nl << "outAsync->invoke(operationName, "; C << getUnqualified(operationModeToString(p->sendMode(), true), interfaceScope) << ", " << getUnqualified(opFormatTypeToString(p, true), interfaceScope) << ", context,"; C.inc(); diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h index 9f62438517c..2c507bcd78c 100644 --- a/cpp/src/slice2cpp/Gen.h +++ b/cpp/src/slice2cpp/Gen.h @@ -109,7 +109,6 @@ class Gen // TODO: temporary - move to InterfaceVisitor. bool visitInterfaceDefStart(const InterfaceDefPtr&) final; - void visitOperation(const OperationPtr&) final; private: From 892e2b450b781511a797ce84bd10ce0fccb6dd2c Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Thu, 22 Feb 2024 15:15:18 -0500 Subject: [PATCH 4/8] Update implementation of ice_isA --- cpp/src/Ice/Object.cpp | 5 ++-- cpp/src/slice2cpp/Gen.cpp | 57 +++++++++------------------------------ cpp/src/slice2cpp/Gen.h | 2 -- 3 files changed, 15 insertions(+), 49 deletions(-) diff --git a/cpp/src/Ice/Object.cpp b/cpp/src/Ice/Object.cpp index 591fefdddb3..7ec8e421af9 100644 --- a/cpp/src/Ice/Object.cpp +++ b/cpp/src/Ice/Object.cpp @@ -42,9 +42,10 @@ Ice::Request::~Request() } bool -Ice::Object::ice_isA(string s, const Current&) const +Ice::Object::ice_isA(string s, const Current& current) const { - return s == object_ids[0]; + vector allIds = ice_ids(current); // sorted type IDs + return ::std::binary_search(allIds.begin(), allIds.end(), s); } void diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index f8a5f7138aa..40072b7a58d 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -3204,15 +3204,6 @@ Slice::Gen::InterfaceVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) H << sp; H << nl << "/**"; - H << nl << " * Determines whether this object supports an interface with the given Slice type ID."; - H << nl << " * @param id The fully-scoped Slice type ID."; - H << nl << " * @param current The Current object for the invocation."; - H << nl << " * @return True if this object supports the interface, false, otherwise."; - H << nl << " */"; - H << nl << "bool ice_isA(::std::string id, const " << getUnqualified("::Ice::Current&", scope) - << " current) const override;"; - H << sp; - H << nl << "/**"; H << nl << " * Obtains a list of the Slice type IDs representing the interfaces supported by this object."; H << nl << " * @param current The Current object for the invocation."; H << nl << " * @return A list of fully-scoped type IDs."; @@ -3237,13 +3228,6 @@ Slice::Gen::InterfaceVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) string flatName = "iceC" + p->flattenedScope() + p->name() + "_ids"; - C << sp; - C << nl << "bool" << nl << scoped.substr(2) << "::ice_isA(::std::string s, const " - << getUnqualified("::Ice::Current&", scope) << ") const"; - C << sb; - C << nl << "return ::std::binary_search(" << flatName << ", " << flatName << " + " << ids.size() << ", s);"; - C << eb; - C << sp; C << nl << "::std::vector<::std::string>" << nl << scoped.substr(2) << "::ice_ids(const " << getUnqualified("::Ice::Current&", scope) << ") const"; @@ -3306,7 +3290,18 @@ Slice::Gen::InterfaceVisitor::visitInterfaceDefEnd(const InterfaceDefPtr& p) << getUnqualified("::Ice::Current&", scope) << " current)"; C << sb; - emitAllOperationsArray(p); + C << sp; + C << nl << "static constexpr ::std::string_view allOperations[] ="; + C << sb; + for (StringList::const_iterator q = allOpNames.begin(); q != allOpNames.end();) + { + C << nl << '"' << *q << '"'; + if (++q != allOpNames.end()) + { + C << ','; + } + } + C << eb << ';'; C << sp; C << nl << "::std::pair r = " @@ -3638,34 +3633,6 @@ Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p) C << nl << "/// \\endcond"; } -void -Slice::Gen::InterfaceVisitor::emitAllOperationsArray(const InterfaceDefPtr& p) -{ - C << sp; - - OperationList allOps = p->allOperations(); - StringList allOpNames; - transform(allOps.begin(), allOps.end(), back_inserter(allOpNames), [](const auto &c) { return c->name(); }); - allOpNames.push_back("ice_id"); - allOpNames.push_back("ice_ids"); - allOpNames.push_back("ice_isA"); - allOpNames.push_back("ice_ping"); - allOpNames.sort(); - allOpNames.unique(); - - C << nl << "static constexpr ::std::string_view allOperations[] ="; - C << sb; - for (StringList::const_iterator q = allOpNames.begin(); q != allOpNames.end();) - { - C << nl << '"' << *q << '"'; - if (++q != allOpNames.end()) - { - C << ','; - } - } - C << eb << ';'; -} - Slice::Gen::StreamVisitor::StreamVisitor(Output& h) : H(h) { diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h index 2c507bcd78c..2f02ea62d91 100644 --- a/cpp/src/slice2cpp/Gen.h +++ b/cpp/src/slice2cpp/Gen.h @@ -191,8 +191,6 @@ class Gen private: - void emitAllOperationsArray(const InterfaceDefPtr&); - ::IceUtilInternal::Output& H; ::IceUtilInternal::Output& C; From 339bceeb6718473638e0e69a4bffe6b40914e749 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Thu, 22 Feb 2024 15:23:45 -0500 Subject: [PATCH 5/8] Cleanup --- cpp/src/Ice/Object.cpp | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/cpp/src/Ice/Object.cpp b/cpp/src/Ice/Object.cpp index 7ec8e421af9..2f571e9d8c9 100644 --- a/cpp/src/Ice/Object.cpp +++ b/cpp/src/Ice/Object.cpp @@ -18,24 +18,6 @@ namespace Ice const Current emptyCurrent = Current(); } -namespace -{ - -const string object_ids[] = -{ - "::Ice::Object" -}; - -const string object_all[] = -{ - "ice_id", - "ice_ids", - "ice_isA", - "ice_ping" -}; - -} - Ice::Request::~Request() { // Out of line to avoid weak vtable @@ -44,8 +26,8 @@ Ice::Request::~Request() bool Ice::Object::ice_isA(string s, const Current& current) const { - vector allIds = ice_ids(current); // sorted type IDs - return ::std::binary_search(allIds.begin(), allIds.end(), s); + vector allTypeIds = ice_ids(current); // sorted type IDs + return ::std::binary_search(allTypeIds.begin(), allTypeIds.end(), s); } void @@ -57,19 +39,21 @@ Ice::Object::ice_ping(const Current&) const vector Ice::Object::ice_ids(const Current&) const { - return vector(&object_ids[0], &object_ids[1]); + static const vector allTypeIds = { "::Ice::Object" }; + return allTypeIds; } string Ice::Object::ice_id(const Current&) const { - return object_ids[0]; + return ice_staticId(); } const string& Ice::Object::ice_staticId() { - return object_ids[0]; + static const ::std::string typeId = "::Ice::Object"; + return typeId; } bool @@ -153,14 +137,22 @@ Ice::Object::ice_dispatch(Request& request, std::function r, std::functi bool Ice::Object::_iceDispatch(Incoming& in, const Current& current) { - pair r = equal_range(object_all, object_all + sizeof(object_all) / sizeof(string), current.operation); + static constexpr string_view allOperations[] = + { + "ice_id", + "ice_ids", + "ice_isA", + "ice_ping" + }; + + pair r = equal_range(allOperations, allOperations + 4, current.operation); if(r.first == r.second) { throw OperationNotExistException(__FILE__, __LINE__, current.id, current.facet, current.operation); } - switch(r.first - object_all) + switch(r.first - allOperations) { case 0: { From ab31cef1131ea3e1675985262f934010598c56c6 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Thu, 22 Feb 2024 16:52:07 -0500 Subject: [PATCH 6/8] Simplify code generation --- cpp/include/Ice/Config.h | 1 + cpp/include/IceUtil/OutputUtil.h | 4 +++ cpp/src/Ice/InputStream.cpp | 4 +-- cpp/src/Ice/OutputStream.cpp | 2 +- cpp/src/IceUtil/OutputUtil.cpp | 15 +++++++++ cpp/src/slice2cpp/Gen.cpp | 54 +++++++++++--------------------- cpp/src/slice2cpp/Gen.h | 3 -- 7 files changed, 42 insertions(+), 41 deletions(-) diff --git a/cpp/include/Ice/Config.h b/cpp/include/Ice/Config.h index 9b75d6ec580..79a642b5608 100644 --- a/cpp/include/Ice/Config.h +++ b/cpp/include/Ice/Config.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include diff --git a/cpp/include/IceUtil/OutputUtil.h b/cpp/include/IceUtil/OutputUtil.h index c9786071b8c..3418ae1dffc 100644 --- a/cpp/include/IceUtil/OutputUtil.h +++ b/cpp/include/IceUtil/OutputUtil.h @@ -9,6 +9,7 @@ #include #include #include +#include namespace IceUtilInternal { @@ -99,6 +100,9 @@ class ICE_API Output : public OutputBase void spar(char = '('); // Start a paramater list. void epar(char = ')'); // End a paramater list. + void spar(std::string_view); // Start a paramater list. + void epar(std::string_view); // End a paramater list. + private: std::string _blockStart; diff --git a/cpp/src/Ice/InputStream.cpp b/cpp/src/Ice/InputStream.cpp index 45849c86803..9c34bfed47e 100644 --- a/cpp/src/Ice/InputStream.cpp +++ b/cpp/src/Ice/InputStream.cpp @@ -1950,7 +1950,7 @@ Ice::InputStream::EncapsDecoder10::readInstance() // For the 1.0 encoding, the type ID for the base Object class // marks the last slice. // - if(_typeId == Object::ice_staticId()) + if(_typeId == Value::ice_staticId()) { throw NoValueFactoryException(__FILE__, __LINE__, "", mostDerivedId); } @@ -2424,7 +2424,7 @@ Ice::InputStream::EncapsDecoder11::readInstance(int32_t index, PatchFunc patchFu // We pass the "::Ice::Object" ID to indicate that this is the // last chance to preserve the object. // - v = newInstance(Object::ice_staticId()); + v = newInstance(Value::ice_staticId()); if(!v) { v = make_shared(mostDerivedId); diff --git a/cpp/src/Ice/OutputStream.cpp b/cpp/src/Ice/OutputStream.cpp index ebc55f174e8..667502b5c52 100644 --- a/cpp/src/Ice/OutputStream.cpp +++ b/cpp/src/Ice/OutputStream.cpp @@ -949,7 +949,7 @@ Ice::OutputStream::EncapsEncoder10::endInstance() // // Write the Object slice. // - startSlice(Object::ice_staticId(), -1, true); + startSlice(Value::ice_staticId(), -1, true); _stream->writeSize(0); // For compatibility with the old AFM. endSlice(); } diff --git a/cpp/src/IceUtil/OutputUtil.cpp b/cpp/src/IceUtil/OutputUtil.cpp index 2584cc8d1a1..dc9746f861f 100644 --- a/cpp/src/IceUtil/OutputUtil.cpp +++ b/cpp/src/IceUtil/OutputUtil.cpp @@ -346,6 +346,21 @@ IceUtilInternal::Output::epar(char c) _out << c; } +void +IceUtilInternal::Output::spar(string_view s) +{ + _emptyBlock = false; + _out << s; + _par = 0; +} + +void +IceUtilInternal::Output::epar(string_view s) +{ + _par = -1; + _out << s; +} + Output& IceUtilInternal::operator<<(Output& out, ios_base& (*val)(ios_base&)) { diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 40072b7a58d..64420865ee9 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -1739,27 +1739,6 @@ Slice::Gen::DefaultFactoryVisitor::visitExceptionStart(const ExceptionPtr& p) return false; } -bool -Slice::Gen::DefaultFactoryVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) -{ - C << sp; - - StringList ids = p->ids(); - C << nl << "const ::std::string iceC" << p->flattenedScope() << p->name() << "_ids[" << ids.size() << "] ="; - C << sb; - for (StringList::const_iterator r = ids.begin(); r != ids.end();) - { - C << nl << '"' << *r << '"'; - if (++r != ids.end()) - { - C << ','; - } - } - C << eb << ';'; - - return true; -} - Slice::Gen::ProxyVisitor::ProxyVisitor(Output& h, Output& c, const string& dllExport) : H(h), C(c), _dllExport(dllExport), _useWstring(false) { @@ -3221,19 +3200,27 @@ Slice::Gen::InterfaceVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) << " current) const override;"; H << sp; H << nl << "/**"; - H << nl << " * Obtains the Slice type ID corresponding to this class."; + H << nl << " * Obtains the Slice type ID corresponding to this interface."; H << nl << " * @return A fully-scoped type ID."; H << nl << " */"; H << nl << "static const ::std::string& ice_staticId();"; - string flatName = "iceC" + p->flattenedScope() + p->name() + "_ids"; - C << sp; C << nl << "::std::vector<::std::string>" << nl << scoped.substr(2) << "::ice_ids(const " << getUnqualified("::Ice::Current&", scope) << ") const"; C << sb; - C << nl << "return ::std::vector<::std::string>(&" << flatName << "[0], &" << flatName << '[' << ids.size() - << "]);"; + + // These type IDs are sorted alphabetically. + C << nl << "static const ::std::vector<::std::string> allTypeIds = "; + C.spar("{ "); + for (auto typeId : p->ids()) + { + C << '"' + typeId + '"'; + } + C.epar(" }"); + C << ";"; + + C << nl << "return allTypeIds;"; C << eb; C << sp; @@ -3291,17 +3278,14 @@ Slice::Gen::InterfaceVisitor::visitInterfaceDefEnd(const InterfaceDefPtr& p) C << sb; C << sp; - C << nl << "static constexpr ::std::string_view allOperations[] ="; - C << sb; - for (StringList::const_iterator q = allOpNames.begin(); q != allOpNames.end();) + C << nl << "static constexpr ::std::string_view allOperations[] = "; + C.spar("{ "); + for (auto opName : allOpNames) { - C << nl << '"' << *q << '"'; - if (++q != allOpNames.end()) - { - C << ','; - } + C << '"' + opName + '"'; } - C << eb << ';'; + C.epar(" }"); + C << ";"; C << sp; C << nl << "::std::pair r = " diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h index 2f02ea62d91..bffc74efa7a 100644 --- a/cpp/src/slice2cpp/Gen.h +++ b/cpp/src/slice2cpp/Gen.h @@ -107,9 +107,6 @@ class Gen bool visitClassDefStart(const ClassDefPtr&) final; bool visitExceptionStart(const ExceptionPtr&) final; - // TODO: temporary - move to InterfaceVisitor. - bool visitInterfaceDefStart(const InterfaceDefPtr&) final; - private: ::IceUtilInternal::Output& C; From 5f9950d6b8cc4a2f036d436f4ec07a83eda8b2a7 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Thu, 22 Feb 2024 16:59:40 -0500 Subject: [PATCH 7/8] Cleanup --- cpp/include/Ice/LocalException.h | 16 ++-------------- cpp/src/Ice/Proxy.cpp | 2 +- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/cpp/include/Ice/LocalException.h b/cpp/include/Ice/LocalException.h index 8a19ef2416a..3e22493bf71 100644 --- a/cpp/include/Ice/LocalException.h +++ b/cpp/include/Ice/LocalException.h @@ -362,20 +362,8 @@ class ICE_CLASS(ICE_API) TwowayOnlyException : public LocalExceptionHelper(file, line), - operation(operation) - { - } - - /** - * One-shot constructor to initialize all data members. - * The file and line number are required for all local exceptions. - * @param file The file name in which the exception was raised, typically __FILE__. - * @param line The line number at which the exception was raised, typically __LINE__. - * @param operation The name of the operation that was invoked. - */ - TwowayOnlyException(const char* file, int line, ::std::string_view operation) : LocalExceptionHelper(file, line), - operation(operation) + TwowayOnlyException(const char* file, int line, ::std::string operation) : LocalExceptionHelper(file, line), + operation(std::move(operation)) { } diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp index b93b1175ad4..943a274c0d3 100644 --- a/cpp/src/Ice/Proxy.cpp +++ b/cpp/src/Ice/Proxy.cpp @@ -62,7 +62,7 @@ Ice::ObjectPrx::_checkTwowayOnly(string_view name) const { if (!ice_isTwoway()) { - throw Ice::TwowayOnlyException(__FILE__, __LINE__, name); + throw Ice::TwowayOnlyException(__FILE__, __LINE__, string(name)); } } From 66e447d2c9f37956e4f861b9ca7c911a8bc84004 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Fri, 23 Feb 2024 09:18:32 -0500 Subject: [PATCH 8/8] Fix review comments --- cpp/src/slice2cpp/Gen.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 64420865ee9..2059361de90 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -3213,7 +3213,7 @@ Slice::Gen::InterfaceVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // These type IDs are sorted alphabetically. C << nl << "static const ::std::vector<::std::string> allTypeIds = "; C.spar("{ "); - for (auto typeId : p->ids()) + for (const auto& typeId : p->ids()) { C << '"' + typeId + '"'; } @@ -3280,7 +3280,7 @@ Slice::Gen::InterfaceVisitor::visitInterfaceDefEnd(const InterfaceDefPtr& p) C << sp; C << nl << "static constexpr ::std::string_view allOperations[] = "; C.spar("{ "); - for (auto opName : allOpNames) + for (const auto& opName : allOpNames) { C << '"' + opName + '"'; }