summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2015-12-03 12:11:37 +0100
committerJose <jose@zeroc.com>2015-12-03 12:11:37 +0100
commit976e866498771ba630ee0f3e5ec682d1dca79440 (patch)
tree339a9fd1321e4c025aabe12e9ef9dc1619edbf7a /cpp
parentMerge branch '3.6' (diff)
downloadice-976e866498771ba630ee0f3e5ec682d1dca79440.tar.bz2
ice-976e866498771ba630ee0f3e5ec682d1dca79440.tar.xz
ice-976e866498771ba630ee0f3e5ec682d1dca79440.zip
C++11 mapping: fixes for optionals generated code
Diffstat (limited to 'cpp')
-rw-r--r--cpp/include/Slice/CPlusPlusUtil.h1
-rw-r--r--cpp/src/Slice/CPlusPlusUtil.cpp106
-rw-r--r--cpp/src/slice2cpp/Gen.cpp23
3 files changed, 105 insertions, 25 deletions
diff --git a/cpp/include/Slice/CPlusPlusUtil.h b/cpp/include/Slice/CPlusPlusUtil.h
index 6f25e95ea9c..9d3bc8ebc94 100644
--- a/cpp/include/Slice/CPlusPlusUtil.h
+++ b/cpp/include/Slice/CPlusPlusUtil.h
@@ -34,6 +34,7 @@ const int TypeContextAMIPrivateEnd = 4;
const int TypeContextAMICallPrivateEnd = 8;
const int TypeContextUseWstring = 16;
const int TypeContextReadClosure = 32;
+const int TypeContextLocalOperation = 64;
SLICE_API bool isMovable(const TypePtr&);
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp
index 474976e89f0..480feedd064 100644
--- a/cpp/src/Slice/CPlusPlusUtil.cpp
+++ b/cpp/src/Slice/CPlusPlusUtil.cpp
@@ -512,7 +512,21 @@ Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx
}
else
{
- return cpp11 ? cpp11BuiltinTable[builtin->kind()] : builtinTable[builtin->kind()];
+ if(cpp11)
+ {
+ if(builtin->kind() == Builtin::KindObject && !(typeCtx & TypeContextLocalOperation))
+ {
+ return "::std::shared_ptr<::Ice::Value>";
+ }
+ else
+ {
+ return cpp11BuiltinTable[builtin->kind()];
+ }
+ }
+ else
+ {
+ return builtinTable[builtin->kind()];
+ }
}
}
@@ -565,7 +579,19 @@ Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx
{
if(cpp11)
{
- return "::std::shared_ptr<" + fixKwd(proxy->_class()->scoped() + "Prx") + ">";
+ ClassDefPtr def = proxy->_class()->definition();
+ //
+ // Non local classes without operations map to the base
+ // proxy class shared_ptr<Ice::ObjectPrx>
+ //
+ if(def && !def->isInterface() && def->allOperations().empty())
+ {
+ return "::std::shared_ptr<::Ice::ObjectPrx>";
+ }
+ else
+ {
+ return "::std::shared_ptr<" + fixKwd(proxy->_class()->scoped() + "Prx") + ">";
+ }
}
else
{
@@ -605,7 +631,7 @@ Slice::typeToString(const TypePtr& type, bool optional, const StringList& metaDa
{
if(optional)
{
- return "IceUtil::Optional<" + toTemplateArg(typeToString(type, metaData, typeCtx)) + ">";
+ return "IceUtil::Optional<" + toTemplateArg(typeToString(type, metaData, typeCtx, cpp11)) + ">";
}
else
{
@@ -623,7 +649,7 @@ Slice::returnTypeToString(const TypePtr& type, bool optional, const StringList&
if(optional)
{
- return "IceUtil::Optional<" + toTemplateArg(typeToString(type, metaData, typeCtx)) + ">";
+ return "IceUtil::Optional<" + toTemplateArg(typeToString(type, metaData, typeCtx, cpp11)) + ">";
}
return typeToString(type, metaData, typeCtx, cpp11);
@@ -648,7 +674,7 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m
"const ::Ice::ValuePtr&"
};
- static const char* cpp1InputBuiltinTable[] =
+ static const char* cpp11InputBuiltinTable[] =
{
"::Ice::Byte",
"bool",
@@ -658,17 +684,17 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m
"float",
"double",
"const ::std::string&",
- "const ::Ice::ObjectPtr&",
+ "const ::std::shared_ptr<::Ice::Object>&",
"const ::std::shared_ptr<::Ice::ObjectPrx>&",
"const ::std::shared_ptr<void>&",
- "const ::Ice::ValuePtr&"
+ "const ::std::shared_ptr<::Ice::Value>&"
};
typeCtx |= TypeContextInParam;
if(optional)
{
- return "const IceUtil::Optional<" + toTemplateArg(typeToString(type, metaData, typeCtx)) +">&";
+ return "const IceUtil::Optional<" + toTemplateArg(typeToString(type, metaData, typeCtx, cpp11)) +">&";
}
BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
@@ -680,7 +706,21 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m
}
else
{
- return cpp11 ? cpp1InputBuiltinTable[builtin->kind()] : inputBuiltinTable[builtin->kind()];
+ if(cpp11)
+ {
+ if(builtin->kind() == Builtin::KindObject && !(typeCtx & TypeContextLocalOperation))
+ {
+ return "const ::std::shared_ptr<::Ice::Value>&";
+ }
+ else
+ {
+ return cpp11InputBuiltinTable[builtin->kind()];
+ }
+ }
+ else
+ {
+ return inputBuiltinTable[builtin->kind()];
+ }
}
}
@@ -696,7 +736,7 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m
}
else if(cl->isInterface() && !cl->isLocal())
{
- return "const ::Ice::ValuePtr&";
+ return "const ::std::shared_ptr<::Ice::Value>&";
}
else
{
@@ -724,7 +764,19 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m
{
if(cpp11)
{
- return "const ::std::shared_ptr<" + fixKwd(proxy->_class()->scoped() + "Prx") + ">&";
+ ClassDefPtr def = proxy->_class()->definition();
+ //
+ // Non local classes without operations map to the base
+ // proxy class shared_ptr<Ice::ObjectPrx>
+ //
+ if(def && !def->isInterface() && def->allOperations().empty())
+ {
+ return "const ::std::shared_ptr<::Ice::ObjectPrx>";
+ }
+ else
+ {
+ return "const ::std::shared_ptr<" + fixKwd(proxy->_class()->scoped() + "Prx") + ">&";
+ }
}
else
{
@@ -796,7 +848,7 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const StringList&
if(optional)
{
- return "IceUtil::Optional<" + toTemplateArg(typeToString(type, metaData, typeCtx)) +">&";
+ return "IceUtil::Optional<" + toTemplateArg(typeToString(type, metaData, typeCtx, cpp11)) +">&";
}
BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
@@ -808,7 +860,21 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const StringList&
}
else
{
- return cpp11 ? cpp11OutputBuiltinTable[builtin->kind()] : outputBuiltinTable[builtin->kind()];
+ if(cpp11)
+ {
+ if(builtin->kind() == Builtin::KindObject && !(typeCtx & TypeContextLocalOperation))
+ {
+ return "::std::shared_ptr<::Ice::Value>";
+ }
+ else
+ {
+ return cpp11OutputBuiltinTable[builtin->kind()];
+ }
+ }
+ else
+ {
+ return outputBuiltinTable[builtin->kind()];
+ }
}
}
@@ -850,7 +916,19 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const StringList&
{
if(cpp11)
{
- return "::std::shared_ptr<" + fixKwd(proxy->_class()->scoped() + "Prx>&");
+ ClassDefPtr def = proxy->_class()->definition();
+ //
+ // Non local classes without operations map to the base
+ // proxy class shared_ptr<Ice::ObjectPrx>
+ //
+ if(def && !def->isInterface() && def->allOperations().empty())
+ {
+ return "::std::shared_ptr<::Ice::ObjectPrx>";
+ }
+ else
+ {
+ return "::std::shared_ptr<" + fixKwd(proxy->_class()->scoped() + "Prx") + ">&";
+ }
}
else
{
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index dca641def2d..961bac75c3c 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -6326,7 +6326,8 @@ Slice::Gen::Cpp11TypesVisitor::visitSequence(const SequencePtr& p)
{
string name = fixKwd(p->name());
TypePtr type = p->type();
- string s = typeToString(type, p->typeMetaData(), _useWstring, true);
+ int typeCtx = p->isLocal() ? (_useWstring | TypeContextLocalOperation) : _useWstring;
+ string s = typeToString(type, p->typeMetaData(), typeCtx, true);
StringList metaData = p->getMetaData();
string seqType = findMetaData(metaData, _useWstring);
@@ -6347,7 +6348,7 @@ Slice::Gen::Cpp11TypesVisitor::visitDictionary(const DictionaryPtr& p)
{
string name = fixKwd(p->name());
string dictType = findMetaData(p->getMetaData());
-
+ int typeCtx = p->isLocal() ? (_useWstring | TypeContextLocalOperation) : _useWstring;
if(dictType.empty())
{
//
@@ -6356,12 +6357,12 @@ Slice::Gen::Cpp11TypesVisitor::visitDictionary(const DictionaryPtr& p)
TypePtr keyType = p->keyType();
TypePtr valueType = p->valueType();
- string ks = typeToString(keyType, p->keyMetaData(), _useWstring);
+ string ks = typeToString(keyType, p->keyMetaData(), typeCtx, true);
if(ks[0] == ':')
{
ks.insert(0, " ");
}
- string vs = typeToString(valueType, p->valueMetaData(), _useWstring);
+ string vs = typeToString(valueType, p->valueMetaData(), typeCtx, true);
H << sp << nl << "typedef ::std::map<" << ks << ", " << vs << "> " << name << ';';
}
@@ -7625,7 +7626,7 @@ Slice::Gen::Cpp11LocalObjectVisitor::visitOperation(const OperationPtr& p)
string scope = fixKwd(p->scope());
TypePtr ret = p->returnType();
- string retS = returnTypeToString(ret, p->returnIsOptional(), p->getMetaData(), _useWstring, true);
+ string retS = returnTypeToString(ret, p->returnIsOptional(), p->getMetaData(), _useWstring | TypeContextLocalOperation, true);
string params = "(";
string paramsDecl = "(";
@@ -7648,12 +7649,12 @@ Slice::Gen::Cpp11LocalObjectVisitor::visitOperation(const OperationPtr& p)
if(isOutParam)
{
outParams.push_back(*q);
- typeString = outputTypeToString(type, (*q)->optional(), (*q)->getMetaData(), _useWstring, true);
+ typeString = outputTypeToString(type, (*q)->optional(), (*q)->getMetaData(), _useWstring | TypeContextLocalOperation, true);
}
else
{
inParams.push_back(*q);
- typeString = inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring, true);
+ typeString = inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring | TypeContextLocalOperation, true);
}
if(q != paramList.begin())
@@ -7671,7 +7672,7 @@ Slice::Gen::Cpp11LocalObjectVisitor::visitOperation(const OperationPtr& p)
if(isOutParam)
{
- outDecls.push_back(inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring, true));
+ outDecls.push_back(inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring | TypeContextLocalOperation, true));
}
}
@@ -7702,11 +7703,11 @@ Slice::Gen::Cpp11LocalObjectVisitor::visitOperation(const OperationPtr& p)
if((*r)->isOutParam())
{
typeString = outputTypeToString((*r)->type(), (*r)->optional(), metaData,
- _useWstring | TypeContextAMIEnd, true);
+ _useWstring | TypeContextAMIEnd | TypeContextLocalOperation, true);
}
else
{
- typeString = inputTypeToString((*r)->type(), (*r)->optional(), metaData, _useWstring, true);
+ typeString = inputTypeToString((*r)->type(), (*r)->optional(), metaData, _useWstring | TypeContextLocalOperation, true);
}
if(!(*r)->isOutParam())
@@ -8698,7 +8699,7 @@ Slice::Gen::Cpp11ObjectVisitor::emitOneShotConstructor(const ClassDefPtr& p)
for(DataMemberList::const_iterator q = allDataMembers.begin(); q != allDataMembers.end(); ++q)
{
- string typeName = inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring);
+ string typeName = inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring, true);
allParamDecls.push_back(typeName + " __ice_" + (*q)->name());
}