summaryrefslogtreecommitdiff
path: root/cpp/src/slice2cpp/Gen.cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2016-06-23 17:00:13 -0400
committerBernard Normier <bernard@zeroc.com>2016-06-23 17:00:13 -0400
commit2c800541ecacb5b5fe51ba2be975cc4e3d47be99 (patch)
treed9f9c80275ad5ba7edda911a782cbe6562fe1969 /cpp/src/slice2cpp/Gen.cpp
parentFixed version (diff)
downloadice-2c800541ecacb5b5fe51ba2be975cc4e3d47be99.tar.bz2
ice-2c800541ecacb5b5fe51ba2be975cc4e3d47be99.tar.xz
ice-2c800541ecacb5b5fe51ba2be975cc4e3d47be99.zip
C++11 proxy generation cleanup
Diffstat (limited to 'cpp/src/slice2cpp/Gen.cpp')
-rw-r--r--cpp/src/slice2cpp/Gen.cpp192
1 files changed, 78 insertions, 114 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 645aea8a316..81c335ad2dc 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -453,6 +453,70 @@ writeDataMemberInitializers(IceUtilInternal::Output& C, const DataMemberList& me
}
}
+void
+writeInParamsLambda(IceUtilInternal::Output& C, const OperationPtr& p, const ParamDeclList& inParams)
+{
+ if(inParams.empty())
+ {
+ C << "nullptr";
+ }
+ else
+ {
+ C << "[&](::Ice::OutputStream* __os)";
+ C << sb;
+ writeMarshalCode(C, inParams, 0, true, TypeContextInParam | TypeContextCpp11);
+ if(p->sendsClasses(false))
+ {
+ C << nl << "__os->writePendingValues();";
+ }
+ C << eb;
+ }
+}
+
+void
+throwUserExceptionLambda(IceUtilInternal::Output& C, ExceptionList throws)
+{
+ if(throws.empty())
+ {
+ C << "nullptr";
+ }
+ else
+ {
+ throws.sort();
+ throws.unique();
+
+ //
+ // Arrange exceptions into most-derived to least-derived order. If we don't
+ // do this, a base exception handler can appear before a derived exception
+ // handler, causing compiler warnings and resulting in the base exception
+ // being marshaled instead of the derived exception.
+ //
+ throws.sort(Slice::DerivedToBaseCompare());
+
+ C << "[](const ::Ice::UserException& __ex)";
+ C << sb;
+ C << nl << "try";
+ C << sb;
+ C << nl << "__ex.ice_throw();";
+ C << eb;
+ //
+ // Generate a catch block for each legal user exception.
+ //
+ for(ExceptionList::const_iterator i = throws.begin(); i != throws.end(); ++i)
+ {
+ string scoped = (*i)->scoped();
+ C << nl << "catch(const " << fixKwd((*i)->scoped()) << "&)";
+ C << sb;
+ C << nl << "throw;";
+ C << eb;
+ }
+ C << nl << "catch(const ::Ice::UserException&)";
+ C << sb;
+ C << eb;
+ C << eb;
+ }
+}
+
string
resultStructName(const string& name, const string& scope = "")
{
@@ -6177,12 +6241,20 @@ Slice::Gen::Cpp11ProxyVisitor::visitClassDefEnd(const ClassDefPtr& p)
H.inc();
H << sp << nl << prx << "() = default;";
H << nl << "friend ::std::shared_ptr<" << prx << "> IceInternal::createProxy<" << prx << ">();";
+ H << sp;
+ H << nl << "virtual ::std::shared_ptr<::Ice::ObjectPrx> __newInstance() const override;";
H << eb << ';';
string suffix = p->isInterface() ? "" : "Disp";
string scoped = fixKwd(p->scoped() + "Prx");
C << sp;
+ C << nl << "::std::shared_ptr<::Ice::ObjectPrx>";
+ C << nl << scoped.substr(2) << "::__newInstance() const";
+ C << sb;
+ C << nl << "return ::IceInternal::createProxy<" << prx << ">();";
+ C << eb;
+ C << sp;
C << nl << "const ::std::string&" << nl << scoped.substr(2) << "::ice_staticId()";
C << sb;
C << nl << "return "<< fixKwd(p->scope() + p->name() + suffix).substr(2) << "::ice_staticId();";
@@ -6462,69 +6534,14 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p)
C << "shared_from_this(), __read, __ex, __sent);";
C << sp;
- // TODO: fix duplication with "private implementation" code below
-
C << nl << "__outAsync->invoke(" << flatName << ", ";
C << operationModeToString(p->sendMode(), true) << ", " << opFormatTypeToString(p) << ", __ctx, ";
C.inc();
C << nl;
- if(inParams.empty())
- {
- C << "nullptr";
- }
- else
- {
- C << "[&](::Ice::OutputStream* __os)";
- C << sb;
- writeMarshalCode(C, inParams, 0, true, TypeContextInParam | TypeContextCpp11);
- if(p->sendsClasses(false))
- {
- C << nl << "__os->writePendingValues();";
- }
- C << eb;
- }
- C << "," << nl;
-
- ExceptionList throws = p->throws();
- if(throws.empty())
- {
- C << "nullptr";
- }
- else
- {
- throws.sort();
- throws.unique();
-
- //
- // Arrange exceptions into most-derived to least-derived order. If we don't
- // do this, a base exception handler can appear before a derived exception
- // handler, causing compiler warnings and resulting in the base exception
- // being marshaled instead of the derived exception.
- //
- throws.sort(Slice::DerivedToBaseCompare());
- C << "[](const ::Ice::UserException& __ex)";
- C << sb;
- C << nl << "try";
- C << sb;
- C << nl << "__ex.ice_throw();";
- C << eb;
- //
- // Generate a catch block for each legal user exception.
- //
- for(ExceptionList::const_iterator i = throws.begin(); i != throws.end(); ++i)
- {
- string scoped = (*i)->scoped();
- C << nl << "catch(const " << fixKwd((*i)->scoped()) << "&)";
- C << sb;
- C << nl << "throw;";
- C << eb;
- }
- C << nl << "catch(const ::Ice::UserException&)";
- C << sb;
- C << eb;
- C << eb;
- }
+ writeInParamsLambda(C, p, inParams);
+ C << "," << nl;
+ throwUserExceptionLambda(C, p->throws());
C.dec();
C << ");";
@@ -6592,63 +6609,10 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p)
C << operationModeToString(p->sendMode(), true) << ", " << opFormatTypeToString(p) << ", __ctx, ";
C.inc();
C << nl;
- if(inParams.empty())
- {
- C << "nullptr";
- }
- else
- {
- C << "[&](::Ice::OutputStream* __os)";
- C << sb;
- writeMarshalCode(C, inParams, 0, true, TypeContextInParam | TypeContextCpp11);
- if(p->sendsClasses(false))
- {
- C << nl << "__os->writePendingValues();";
- }
- C << eb;
- }
- C << "," << nl;
- ExceptionList throws = p->throws();
- if(throws.empty())
- {
- C << "nullptr";
- }
- else
- {
- throws.sort();
- throws.unique();
-
- //
- // Arrange exceptions into most-derived to least-derived order. If we don't
- // do this, a base exception handler can appear before a derived exception
- // handler, causing compiler warnings and resulting in the base exception
- // being marshaled instead of the derived exception.
- //
- throws.sort(Slice::DerivedToBaseCompare());
-
- C << "[](const ::Ice::UserException& __ex)";
- C << sb;
- C << nl << "try";
- C << sb;
- C << nl << "__ex.ice_throw();";
- C << eb;
- //
- // Generate a catch block for each legal user exception.
- //
- for(ExceptionList::const_iterator i = throws.begin(); i != throws.end(); ++i)
- {
- string scoped = (*i)->scoped();
- C << nl << "catch(const " << fixKwd((*i)->scoped()) << "&)";
- C << sb;
- C << nl << "throw;";
- C << eb;
- }
- C << nl << "catch(const ::Ice::UserException&)";
- C << sb;
- C << eb;
- C << eb;
- }
+ writeInParamsLambda(C, p, inParams);
+ C << "," << nl;
+ throwUserExceptionLambda(C, p->throws());
if(futureOutParams.size() > 1)
{