summaryrefslogtreecommitdiff
path: root/cpp/src/slice2cpp/Gen.cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2012-08-10 23:53:37 +0200
committerJose <jose@zeroc.com>2012-08-10 23:53:37 +0200
commit1d5c04bb8c0e786a717e36467e17f34bcc4f1d95 (patch)
treec1c91f034589260e97033131061d536ecfc2b9cb /cpp/src/slice2cpp/Gen.cpp
parentICE-4702 - Poor hash algorithm (diff)
downloadice-1d5c04bb8c0e786a717e36467e17f34bcc4f1d95.tar.bz2
ice-1d5c04bb8c0e786a717e36467e17f34bcc4f1d95.tar.xz
ice-1d5c04bb8c0e786a717e36467e17f34bcc4f1d95.zip
C++11 ami lambda support
Diffstat (limited to 'cpp/src/slice2cpp/Gen.cpp')
-rw-r--r--cpp/src/slice2cpp/Gen.cpp296
1 files changed, 260 insertions, 36 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index db170626d26..1d713299433 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -1774,6 +1774,38 @@ Slice::Gen::ProxyVisitor::visitClassDefEnd(const ClassDefPtr& p)
_useWstring = resetUseWstring(_useWstringHist);
}
+namespace
+{
+
+bool
+usePrivateEnd(const OperationPtr& p)
+{
+ TypePtr ret = p->returnType();
+ bool retIsOpt = p->returnIsOptional();
+ string retSEnd = returnTypeToString(ret, retIsOpt, p->getMetaData(), TypeContextAMIEnd);
+ string retSPrivateEnd = returnTypeToString(ret, retIsOpt, p->getMetaData(), TypeContextAMIPrivateEnd);
+
+ ParamDeclList outParams;
+ vector<string> outDeclsEnd;
+ vector<string> outDeclsPrivateEnd;
+
+ ParamDeclList paramList = p->parameters();
+ for(ParamDeclList::const_iterator q = paramList.begin(); q != paramList.end(); ++q)
+ {
+ if((*q)->isOutParam())
+ {
+ outDeclsEnd.push_back(outputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(),
+ TypeContextAMIEnd));
+ outDeclsPrivateEnd.push_back(outputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(),
+ TypeContextAMIPrivateEnd));
+ }
+ }
+
+ return retSEnd != retSPrivateEnd || outDeclsEnd != outDeclsPrivateEnd;
+}
+
+}
+
void
Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
{
@@ -1782,14 +1814,17 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
string scope = fixKwd(p->scope());
TypePtr ret = p->returnType();
+
bool retIsOpt = p->returnIsOptional();
string retS = returnTypeToString(ret, retIsOpt, p->getMetaData(), _useWstring | TypeContextAMIEnd);
string retSEndAMI = returnTypeToString(ret, retIsOpt, p->getMetaData(), _useWstring | TypeContextAMIPrivateEnd);
+ string retInS = retS != "void" ? inputTypeToString(ret, retIsOpt, p->getMetaData(), _useWstring) : "";
ContainerPtr container = p->container();
ClassDefPtr cl = ClassDefPtr::dynamicCast(container);
+ string clName = cl->name();
string clScope = fixKwd(cl->scope());
- string delName = "Callback_" + cl->name() + "_" + name;
+ string delName = "Callback_" + clName + "_" + name;
string delNameScoped = clScope + delName;
vector<string> params;
@@ -1800,12 +1835,18 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
vector<string> paramsDeclAMI;
vector<string> argsAMI;
vector<string> outParamsAMI;
+ vector<string> outParamNamesAMI;
vector<string> outParamsDeclAMI;
vector<string> outParamsDeclEndAMI;
-
+ vector<string> outDecls;
+
ParamDeclList paramList = p->parameters();
ParamDeclList inParams;
ParamDeclList outParams;
+
+
+ vector<string> outEndArgs;
+
for(ParamDeclList::const_iterator q = paramList.begin(); q != paramList.end(); ++q)
{
string paramName = fixKwd((*q)->name());
@@ -1838,9 +1879,12 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
else
{
outParamsAMI.push_back(typeString);
+ outParamNamesAMI.push_back(paramName);
outParamsDeclAMI.push_back(typeString + ' ' + paramName);
outParamsDeclEndAMI.push_back(typeStringEndAMI + ' ' + paramName);
outParams.push_back(*q);
+ outDecls.push_back(inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring));
+ outEndArgs.push_back(getEndArg((*q)->type(), (*q)->getMetaData(), outParamNamesAMI.back()));
}
}
@@ -1884,6 +1928,201 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
}
H << fixKwd(name) << spar << args << "&__ctx" << epar << ';';
H << eb;
+
+ H.zeroIndent();
+ H << nl << "#ifdef ICE_CPP11";
+ H.restoreIndent();
+
+ string retEndArg = getEndArg(ret, p->getMetaData(), "__ret");
+
+ H << nl << "::Ice::AsyncResultPtr";
+ H << nl << "begin_" << name << spar << paramsDeclAMI
+ << "const ::IceInternal::Function<void " << spar;
+ if(!retInS.empty())
+ {
+ H << retInS;
+ }
+ H << outDecls << epar << ">& response, "
+ << "const ::IceInternal::Function<void (const ::Ice::Exception&)>& exception = "
+ "::IceInternal::Function<void (const ::Ice::Exception&)>(), "
+ << "const ::IceInternal::Function<void (bool)>& sent = ::IceInternal::Function<void (bool)>()" << epar;
+
+ H << sb;
+ if(p->returnsData())
+ {
+ H << nl << "return __begin_" << name << spar << argsAMI << "0, response, exception, sent" << epar << ";";
+ }
+ else
+ {
+ H << nl << "return begin_" << name << spar << argsAMI
+ << "0, new ::IceInternal::Cpp11FnOnewayCallbackNC(response, exception, sent)" << epar << ";";
+
+ }
+ H << eb;
+
+ H << nl << "::Ice::AsyncResultPtr";
+ H << nl << "begin_" << name << spar << paramsDeclAMI
+ << "const ::IceInternal::Function<void (const ::Ice::AsyncResultPtr&)>& completed"
+ << "const ::IceInternal::Function<void (const ::Ice::AsyncResultPtr&)>& sent = "
+ "::IceInternal::Function<void (const ::Ice::AsyncResultPtr&)>()" << epar;
+ H << sb;
+ H << nl << "return begin_" << name << spar << argsAMI << "0, ::Ice::newCallback(completed, sent), 0" << epar << ";";
+ H << eb;
+
+
+ H << nl << "::Ice::AsyncResultPtr";
+ H << nl << "begin_" << name << spar << paramsDeclAMI << "const ::Ice::Context& ctx"
+ << "const ::IceInternal::Function<void " << spar;
+ if(!retInS.empty())
+ {
+ H << retInS;
+ }
+ H << outDecls << epar << ">& response, "
+ << "const ::IceInternal::Function<void (const ::Ice::Exception&)>& exception = "
+ "::IceInternal::Function<void (const ::Ice::Exception&)>(), "
+ << "const ::IceInternal::Function<void (bool)>& sent = ::IceInternal::Function<void (bool)>()" << epar;
+
+ H << sb;
+ if(p->returnsData())
+ {
+ H << nl << "return __begin_" << name << spar << argsAMI << "&ctx, response, exception, sent" << epar << ";";
+ }
+ else
+ {
+ H << nl << "return begin_" << name << spar << argsAMI
+ << "&ctx, new ::IceInternal::Cpp11FnOnewayCallbackNC(response, exception, sent), 0" << epar << ";";
+ }
+ H << eb;
+
+ H << nl << "::Ice::AsyncResultPtr";
+ H << nl << "begin_" << name << spar << paramsDeclAMI
+ << "const ::Ice::Context& ctx"
+ << "const ::IceInternal::Function<void (const ::Ice::AsyncResultPtr&)>& completed"
+ << "const ::IceInternal::Function<void (const ::Ice::AsyncResultPtr&)>& sent = "
+ "::IceInternal::Function<void (const ::Ice::AsyncResultPtr&)>()" << epar;
+ H << sb;
+ H << nl << "return begin_" << name << spar << argsAMI << "&ctx, ::Ice::newCallback(completed, sent)" << epar << ";";
+ H << eb;
+
+ if(p->returnsData())
+ {
+ H << nl;
+ H.dec();
+ H << nl << "private:";
+ H.inc();
+
+
+ H << sp << nl << "::Ice::AsyncResultPtr __begin_" << name << spar << paramsDeclAMI
+ << "const ::Ice::Context* ctx" << "const ::IceInternal::Function<void " << spar;
+
+
+ if(!retInS.empty())
+ {
+ H << retInS;
+ }
+ H << outDecls;
+
+ H << epar << ">& response, "
+ << "const ::IceInternal::Function<void (const ::Ice::Exception&)>& exception, "
+ << "const ::IceInternal::Function<void (bool)>& sent" << epar;
+ H << sb;
+ H << nl << "class Cpp11CB : public ::IceInternal::Cpp11FnCallbackNC";
+ H << sb;
+ H.dec();
+ H << nl << "public:";
+ H.inc();
+ H << sp << nl << "Cpp11CB" << spar << "const ::std::function<void " << spar;
+ if(!retInS.empty())
+ {
+ H << retInS;
+ }
+ H << outDecls;
+ H << epar << ">& responseFunc, "
+ << "const ::std::function<void (const ::Ice::Exception&)>& exceptionFunc, "
+ << "const ::std::function<void (bool)>& sentFunc" << epar << " :";
+ H.inc();
+ H << nl << "::IceInternal::Cpp11FnCallbackNC(exceptionFunc, sentFunc),";
+ H << nl << "_response(responseFunc)";
+ H.dec();
+ H << sb;
+ H << nl << "CallbackBase::checkCallback(true, responseFunc || exceptionFunc != nullptr);";
+ H << eb;
+
+ //
+ // completed.
+ //
+ H << sp << nl << "virtual void __completed(const ::Ice::AsyncResultPtr& __result) const";
+ H << sb;
+ H << nl << clScope << clName << "Prx __proxy = " << clScope << clName
+ << "Prx::uncheckedCast(__result->getProxy());";
+ writeAllocateCode(H, outParams, p, _useWstring | TypeContextInParam | TypeContextAMICallPrivateEnd);
+ H << nl << "try";
+ H << sb;
+ H << nl;
+ if(!usePrivateEnd(p))
+ {
+ if(ret)
+ {
+ H << retEndArg << " = ";
+ }
+ H << "__proxy->end_" << p->name() << spar << outEndArgs << "__result" << epar << ';';
+ }
+ else
+ {
+ H << "__proxy->___end_" << p->name() << spar << outEndArgs;
+ if(ret)
+ {
+ H << retEndArg;
+ }
+ H << "__result" << epar << ';';
+ }
+ writeEndCode(H, outParams, p);
+ H << eb;
+ H << nl << "catch(::Ice::Exception& ex)";
+ H << sb;
+ H << nl << "Cpp11FnCallbackNC::__exception(__result, ex);";
+ H << nl << "return;";
+ H << eb;
+ H << nl << "if(_response != nullptr)";
+ H << sb;
+ H << nl << "_response" << spar;
+ if(ret)
+ {
+ H << "__ret";
+ }
+ H << outParamNamesAMI;
+ H << epar << ';';
+ H << eb;
+ H << eb;
+
+ H.dec();
+ H << nl << nl << "private:";
+ H.inc();
+ H << nl;
+ H << nl << "::std::function<void " << spar;
+
+ if(!retInS.empty())
+ {
+ H << retInS;
+ }
+ H << outDecls;
+
+ H << epar << "> _response;";
+
+ H << eb << ';';
+
+ H << nl << "return begin_" << name << spar << argsAMI << "ctx" << "new Cpp11CB(response, exception, sent)"
+ << epar << ';';
+ H << eb;
+ H << nl;
+ H.dec();
+ H << nl << "public:";
+ H.inc();
+ }
+
+ H.zeroIndent();
+ H << nl << "#endif";
+ H.restoreIndent();
H << sp << nl << "::Ice::AsyncResultPtr begin_" << name << spar << paramsDeclAMI << epar;
H << sb;
@@ -1932,7 +2171,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
<< "const ::Ice::AsyncResultPtr&" << epar << ';';
if(generatePrivateEnd)
{
- H << sp << nl << "void ___end_" << name << spar << outParamsDeclEndAMI;
+ H << sp << nl << _dllExport << " void ___end_" << name << spar << outParamsDeclEndAMI;
H << "const ::Ice::AsyncResultPtr&" << epar << ';';
}
@@ -1949,7 +2188,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
H.dec();
H << nl << "public:";
H.inc();
-
+
C << sp << nl << retS << nl << "IceProxy" << scoped << spar << paramsDecl << "const ::Ice::Context* __ctx" << epar;
C << sb;
C << nl << "int __cnt = 0;";
@@ -3971,6 +4210,7 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p)
ParamDeclList inParams;
ParamDeclList outParams;
ParamDeclList paramList = p->parameters();
+ vector< string> outDecls;
for(ParamDeclList::const_iterator q = paramList.begin(); q != paramList.end(); ++q)
{
string paramName = fixKwd((*q)->name());
@@ -4012,6 +4252,10 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p)
argsAMD += paramName;
argsAMD += ", ";
}
+ else
+ {
+ outDecls.push_back(inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring));
+ }
}
if(!cl->isLocal())
@@ -4202,6 +4446,18 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p)
outParamsDeclAMI.push_back(typeString + ' ' + paramName);
}
}
+
+ H.zeroIndent();
+ H << nl << "#ifdef ICE_CPP11";
+ H.restoreIndent();
+
+ H << nl << "virtual ::Ice::AsyncResultPtr begin_" << name << spar << paramsDeclAMI
+ << "const ::IceInternal::Function<void (const ::Ice::Exception&)>& exception"
+ << "const ::IceInternal::Function<void (bool)>& sent = ::IceInternal::Function<void (bool)>()" << epar << " = 0;";
+
+ H.zeroIndent();
+ H << nl << "#endif";
+ H.restoreIndent();
H << sp << nl << "virtual ::Ice::AsyncResultPtr begin_" << name << spar << paramsDeclAMI << epar << " = 0;";
@@ -4730,38 +4986,6 @@ Slice::Gen::AsyncCallbackTemplateVisitor::visitClassDefEnd(const ClassDefPtr& p)
_useWstring = resetUseWstring(_useWstringHist);
}
-namespace
-{
-
-bool
-usePrivateEnd(const OperationPtr& p)
-{
- TypePtr ret = p->returnType();
- bool retIsOpt = p->returnIsOptional();
- string retSEnd = returnTypeToString(ret, retIsOpt, p->getMetaData(), TypeContextAMIEnd);
- string retSPrivateEnd = returnTypeToString(ret, retIsOpt, p->getMetaData(), TypeContextAMIPrivateEnd);
-
- ParamDeclList outParams;
- vector<string> outDeclsEnd;
- vector<string> outDeclsPrivateEnd;
-
- ParamDeclList paramList = p->parameters();
- for(ParamDeclList::const_iterator q = paramList.begin(); q != paramList.end(); ++q)
- {
- if((*q)->isOutParam())
- {
- outDeclsEnd.push_back(outputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(),
- TypeContextAMIEnd));
- outDeclsPrivateEnd.push_back(outputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(),
- TypeContextAMIPrivateEnd));
- }
- }
-
- return retSEnd != retSPrivateEnd || outDeclsEnd != outDeclsPrivateEnd;
-}
-
-}
-
void
Slice::Gen::AsyncCallbackTemplateVisitor::visitOperation(const OperationPtr& p)
{