summaryrefslogtreecommitdiff
path: root/cpp/src/slice2cpp/Gen.cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2017-05-03 20:14:31 -0400
committerBernard Normier <bernard@zeroc.com>2017-05-03 20:14:31 -0400
commit34156adcd7d7a1cc458260aabbd6b1857dab84b7 (patch)
tree7379294e035ba71def6df3131ee7edc882258505 /cpp/src/slice2cpp/Gen.cpp
parentMore makefile fixes (diff)
downloadice-34156adcd7d7a1cc458260aabbd6b1857dab84b7.tar.bz2
ice-34156adcd7d7a1cc458260aabbd6b1857dab84b7.tar.xz
ice-34156adcd7d7a1cc458260aabbd6b1857dab84b7.zip
Generate alias for "delegate" in C++11 (ICE-7859)
Diffstat (limited to 'cpp/src/slice2cpp/Gen.cpp')
-rw-r--r--cpp/src/slice2cpp/Gen.cpp35
1 files changed, 32 insertions, 3 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 8b1ebf320ee..e096ae39e1e 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -6408,12 +6408,41 @@ Slice::Gen::Cpp11LocalObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
{
return false;
}
+
+ string name = fixKwd(p->name());
+
if(p->isDelegate())
{
+ int typeCtx = _useWstring | TypeContextLocal | TypeContextCpp11;
+
+ // Generate alias
+ H << sp << nl << "using " << name << " = ";
+
+ // A delegate only has one operation
+ OperationPtr op = p->allOperations().front();
+ TypePtr ret = op->returnType();
+ string retS = returnTypeToString(ret, op->returnIsOptional(), op->getMetaData(), typeCtx);
+
+ H << "::std::function<" << retS << "(";
+
+ ParamDeclList paramList = op->parameters();
+ for(ParamDeclList::iterator q = paramList.begin(); q != paramList.end(); ++q)
+ {
+ if((*q)->isOutParam())
+ {
+ H << outputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), typeCtx);
+ }
+ else
+ {
+ H << inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), typeCtx);
+ }
+ H << (IceUtilInternal::distance(q, paramList.end()) == 1 ? "" : ", ");
+ }
+ H << ")>;";
+
return false;
}
- string name = fixKwd(p->name());
string scope = fixKwd(p->scope());
string scoped = fixKwd(p->scoped());
ClassList bases = p->bases();
@@ -6434,7 +6463,7 @@ Slice::Gen::Cpp11LocalObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
bool virtualInheritance = p->isInterface();
while(q != bases.end())
{
- H << "public ";
+ H << "public ";
if(virtualInheritance || (*q)->isInterface())
{
H << "virtual ";
@@ -6589,7 +6618,7 @@ Slice::Gen::Cpp11LocalObjectVisitor::visitOperation(const OperationPtr& p)
int typeCtx = _useWstring | TypeContextLocal | TypeContextCpp11;
TypePtr ret = p->returnType();
string retS = returnTypeToString(ret, p->returnIsOptional(), p->getMetaData(),
- typeCtx | TypeContextCpp11);
+ typeCtx);
string params = "(";
string paramsDecl = "(";