summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/CPlusPlusUtil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/Slice/CPlusPlusUtil.cpp')
-rw-r--r--cpp/src/Slice/CPlusPlusUtil.cpp401
1 files changed, 349 insertions, 52 deletions
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp
index a7206d3219a..20b4f22fb7e 100644
--- a/cpp/src/Slice/CPlusPlusUtil.cpp
+++ b/cpp/src/Slice/CPlusPlusUtil.cpp
@@ -48,14 +48,7 @@ stringTypeToString(const TypePtr& type, const StringList& metaData, int typeCtx)
string strType = findMetaData(metaData, typeCtx);
if(strType == "wstring" || (typeCtx & TypeContextUseWstring && strType == ""))
{
- if(featureProfile == IceE)
- {
- return "::Ice::Wstring";
- }
- else
- {
- return "::std::wstring";
- }
+ return "::std::wstring";
}
else if(strType != "" && strType != "string")
{
@@ -151,9 +144,9 @@ dictionaryTypeToString(const DictionaryPtr& dict, const StringList& metaData, in
void
writeParamAllocateCode(Output& out, const TypePtr& type, bool optional, const string& fixedName,
- const StringList& metaData, int typeCtx, bool endArg)
+ const StringList& metaData, int typeCtx, bool cpp11, bool endArg)
{
- string s = typeToString(type, metaData, typeCtx);
+ string s = typeToString(type, metaData, typeCtx, cpp11);
if(optional)
{
s = "IceUtil::Optional<" + toTemplateArg(s) + '>';
@@ -181,7 +174,7 @@ writeParamAllocateCode(Output& out, const TypePtr& type, bool optional, const st
string s;
if(seqType == "%array")
{
- s = typeToString(seq, metaData, TypeContextAMIPrivateEnd);
+ s = typeToString(seq, metaData, TypeContextAMIPrivateEnd, cpp11);
}
else if(seqType.find("%range") == 0)
{
@@ -190,7 +183,7 @@ writeParamAllocateCode(Output& out, const TypePtr& type, bool optional, const st
{
md.push_back("cpp:type:" + seqType.substr(strlen("%range:")));
}
- s = typeToString(seq, md);
+ s = typeToString(seq, md, 0, cpp11);
}
if(!s.empty())
@@ -295,7 +288,8 @@ writeParamEndCode(Output& out, const TypePtr& type, bool optional, const string&
}
void
-writeMarshalUnmarshalParams(Output& out, const ParamDeclList& params, const OperationPtr& op, bool marshal, bool prepend, int typeCtx)
+writeMarshalUnmarshalParams(Output& out, const ParamDeclList& params, const OperationPtr& op, bool marshal,
+ bool prepend, int typeCtx)
{
string prefix = prepend ? paramPrefix : "";
@@ -450,9 +444,33 @@ Slice::printDllExportStuff(Output& out, const string& dllExport)
}
}
+bool
+Slice::isMovable(const TypePtr& type)
+{
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
+ if(builtin)
+ {
+ switch(builtin->kind())
+ {
+ case Builtin::KindString:
+ case Builtin::KindObject:
+ case Builtin::KindObjectProxy:
+ case Builtin::KindLocalObject:
+ case Builtin::KindValue:
+ {
+ return true;
+ }
+ default:
+ {
+ return false;
+ }
+ }
+ }
+ return !EnumPtr::dynamicCast(type);
+}
string
-Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx)
+Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx, bool cpp11)
{
static const char* builtinTable[] =
{
@@ -466,7 +484,24 @@ Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx
"::std::string",
"::Ice::ObjectPtr",
"::Ice::ObjectPrx",
- "::Ice::LocalObjectPtr"
+ "::Ice::LocalObjectPtr",
+ "::Ice::ValuePtr"
+ };
+
+ static const char* cpp11BuiltinTable[] =
+ {
+ "::Ice::Byte",
+ "bool",
+ "short",
+ "int",
+ "long long int",
+ "float",
+ "double",
+ "::std::string",
+ "::std::shared_ptr<::Ice::Object>",
+ "::std::shared_ptr<::Ice::ObjectPrx>",
+ "::std::shared_ptr<void>",
+ "::std::shared_ptr<::Ice::Value>"
};
BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
@@ -478,20 +513,55 @@ Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx
}
else
{
- return builtinTable[builtin->kind()];
+ if(cpp11)
+ {
+ if(builtin->kind() == Builtin::KindObject && !(typeCtx & TypeContextLocal))
+ {
+ return "::std::shared_ptr<::Ice::Value>";
+ }
+ else
+ {
+ return cpp11BuiltinTable[builtin->kind()];
+ }
+ }
+ else
+ {
+ return builtinTable[builtin->kind()];
+ }
}
}
ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
if(cl)
{
- return fixKwd(cl->scoped() + "Ptr");
+ if(cpp11)
+ {
+ if(cl->definition() && cl->definition()->isDelegate())
+ {
+ return classDefToDelegateString(cl->definition());
+ }
+ else if(cl->isInterface() && !cl->isLocal())
+ {
+ return "std::shared_ptr<::Ice::Value>";
+ }
+ else
+ {
+ return "::std::shared_ptr<" + cl->scoped() + ">";
+ }
+ }
+ else
+ {
+ return cl->scoped() + "Ptr";
+ }
}
StructPtr st = StructPtr::dynamicCast(type);
if(st)
{
- if(findMetaData(st->getMetaData()) == "%class")
+ //
+ // C++11 mapping doesn't accept cpp:class metdata
+ //
+ if(!cpp11 && findMetaData(st->getMetaData()) == "%class")
{
return fixKwd(st->scoped() + "Ptr");
}
@@ -501,7 +571,26 @@ Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx
ProxyPtr proxy = ProxyPtr::dynamicCast(type);
if(proxy)
{
- return fixKwd(proxy->_class()->scoped() + "Prx");
+ if(cpp11)
+ {
+ 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
+ {
+ return fixKwd(proxy->_class()->scoped() + "Prx");
+ }
}
SequencePtr seq = SequencePtr::dynamicCast(type);
@@ -532,20 +621,20 @@ Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx
}
string
-Slice::typeToString(const TypePtr& type, bool optional, const StringList& metaData, int typeCtx)
+Slice::typeToString(const TypePtr& type, bool optional, const StringList& metaData, int typeCtx, bool cpp11)
{
if(optional)
{
- return "IceUtil::Optional<" + toTemplateArg(typeToString(type, metaData, typeCtx)) + ">";
+ return "IceUtil::Optional<" + toTemplateArg(typeToString(type, metaData, typeCtx, cpp11)) + ">";
}
else
{
- return typeToString(type, metaData, typeCtx);
+ return typeToString(type, metaData, typeCtx, cpp11);
}
}
string
-Slice::returnTypeToString(const TypePtr& type, bool optional, const StringList& metaData, int typeCtx)
+Slice::returnTypeToString(const TypePtr& type, bool optional, const StringList& metaData, int typeCtx, bool cpp11)
{
if(!type)
{
@@ -554,16 +643,16 @@ 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);
+ return typeToString(type, metaData, typeCtx, cpp11);
}
string
-Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& metaData, int typeCtx)
+Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& metaData, int typeCtx, bool cpp11)
{
- static const char* inputBuiltinTable[] =
+ static const char* cpp98InputBuiltinTable[] =
{
"::Ice::Byte",
"bool",
@@ -575,14 +664,31 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m
"const ::std::string&",
"const ::Ice::ObjectPtr&",
"const ::Ice::ObjectPrx&",
- "const ::Ice::LocalObjectPtr&"
+ "const ::Ice::LocalObjectPtr&",
+ "const ::Ice::ValuePtr&"
+ };
+
+ static const char* cpp11InputBuiltinTable[] =
+ {
+ "::Ice::Byte",
+ "bool",
+ "short",
+ "int",
+ "long long int",
+ "float",
+ "double",
+ "const ::std::string&",
+ "const ::std::shared_ptr<::Ice::Object>&",
+ "const ::std::shared_ptr<::Ice::ObjectPrx>&",
+ "const ::std::shared_ptr<void>&",
+ "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);
@@ -594,30 +700,87 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m
}
else
{
- return inputBuiltinTable[builtin->kind()];
+ if(cpp11)
+ {
+ if(builtin->kind() == Builtin::KindObject && !(typeCtx & TypeContextLocal))
+ {
+ return "const ::std::shared_ptr<::Ice::Value>&";
+ }
+ else
+ {
+ return cpp11InputBuiltinTable[builtin->kind()];
+ }
+ }
+ else
+ {
+ return cpp98InputBuiltinTable[builtin->kind()];
+ }
}
}
ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
if(cl)
{
- return "const " + fixKwd(cl->scoped() + "Ptr&");
+ if(cpp11)
+ {
+ if(cl->definition() && cl->definition()->isDelegate())
+ {
+ return classDefToDelegateString(cl->definition(), typeCtx, cpp11);
+ }
+ else if(cl->isInterface() && !cl->isLocal())
+ {
+ return "const ::std::shared_ptr<::Ice::Value>&";
+ }
+ else
+ {
+ return "const ::std::shared_ptr<" + fixKwd(cl->scoped()) + ">&";
+ }
+ }
+ else
+ {
+ return "const " + fixKwd(cl->scoped() + "Ptr&");
+ }
}
StructPtr st = StructPtr::dynamicCast(type);
if(st)
{
- if(findMetaData(st->getMetaData()) == "%class")
+ if(cpp11)
{
- return "const " + fixKwd(st->scoped() + "Ptr&");
+ return "const " + fixKwd(st->scoped()) + "&";
+ }
+ else
+ {
+ if(findMetaData(st->getMetaData()) == "%class")
+ {
+ return "const " + fixKwd(st->scoped() + "Ptr&");
+ }
+ else
+ {
+ return "const " + fixKwd(st->scoped()) + "&";
+ }
}
- return "const " + fixKwd(st->scoped()) + "&";
}
ProxyPtr proxy = ProxyPtr::dynamicCast(type);
if(proxy)
{
- return "const " + fixKwd(proxy->_class()->scoped() + "Prx&");
+ if(cpp11)
+ {
+ ClassDefPtr def = proxy->_class()->definition();
+ 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
+ {
+ return "const " + fixKwd(proxy->_class()->scoped() + "Prx&");
+ }
}
EnumPtr en = EnumPtr::dynamicCast(type);
@@ -648,7 +811,7 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m
}
string
-Slice::outputTypeToString(const TypePtr& type, bool optional, const StringList& metaData, int typeCtx)
+Slice::outputTypeToString(const TypePtr& type, bool optional, const StringList& metaData, int typeCtx, bool cpp11)
{
static const char* outputBuiltinTable[] =
{
@@ -661,13 +824,30 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const StringList&
"::Ice::Double&",
"::std::string&",
"::Ice::ObjectPtr&",
- "::Ice::ObjectPrx&",
- "::Ice::LocalObjectPtr&"
+ "::Ice::ObjectPrxPtr&",
+ "::Ice::LocalObjectPtr&",
+ "::Ice::ValuePtr&"
+ };
+
+ static const char* cpp11OutputBuiltinTable[] =
+ {
+ "::Ice::Byte&",
+ "bool&",
+ "short&",
+ "int&",
+ "long long int&",
+ "float&",
+ "double&",
+ "::std::string&",
+ "::std::shared_ptr<::Ice::Object>&",
+ "::std::shared_ptr<::Ice::ObjectPrx>&",
+ "::std::shared_ptr<void>&",
+ "::std::shared_ptr<::Ice::Value>&"
};
if(optional)
{
- return "IceUtil::Optional<" + toTemplateArg(typeToString(type, metaData, typeCtx)) +">&";
+ return "IceUtil::Optional<" + toTemplateArg(typeToString(type, metaData, typeCtx, cpp11)) +">&";
}
BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
@@ -679,30 +859,84 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const StringList&
}
else
{
- return outputBuiltinTable[builtin->kind()];
+ if(cpp11)
+ {
+ if(builtin->kind() == Builtin::KindObject && !(typeCtx & TypeContextLocal))
+ {
+ return "::std::shared_ptr<::Ice::Value>";
+ }
+ else
+ {
+ return cpp11OutputBuiltinTable[builtin->kind()];
+ }
+ }
+ else
+ {
+ return outputBuiltinTable[builtin->kind()];
+ }
}
}
ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
if(cl)
{
- return fixKwd(cl->scoped() + "Ptr&");
+ if(cpp11)
+ {
+ if(cl->definition() && cl->definition()->isDelegate())
+ {
+ return classDefToDelegateString(cl->definition(), typeCtx, cpp11) + "&";
+ }
+ else if(cl->isInterface() && !cl->isLocal())
+ {
+ return "::std::shared_ptr<::Ice::Value>&";
+ }
+ else
+ {
+ return "::std::shared_ptr<" + fixKwd(cl->scoped()) + ">&";
+ }
+ }
+ else
+ {
+ return fixKwd(cl->scoped() + "Ptr&");
+ }
}
StructPtr st = StructPtr::dynamicCast(type);
if(st)
{
- if(findMetaData(st->getMetaData()) == "%class")
+ if(!cpp11 && findMetaData(st->getMetaData()) == "%class")
{
return fixKwd(st->scoped() + "Ptr&");
}
- return fixKwd(st->scoped()) + "&";
+ else
+ {
+ return fixKwd(st->scoped()) + "&";
+ }
}
ProxyPtr proxy = ProxyPtr::dynamicCast(type);
if(proxy)
{
- return fixKwd(proxy->_class()->scoped() + "Prx&");
+ if(cpp11)
+ {
+ 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
+ {
+ return fixKwd(proxy->_class()->scoped() + "Prx&");
+ }
}
SequencePtr seq = SequencePtr::dynamicCast(type);
@@ -727,23 +961,23 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const StringList&
}
string
-Slice::operationModeToString(Operation::Mode mode)
+Slice::operationModeToString(Operation::Mode mode, bool cpp11)
{
switch(mode)
{
case Operation::Normal:
{
- return "::Ice::Normal";
+ return cpp11 ? "::Ice::OperationMode::Normal" : "::Ice::Normal";
}
case Operation::Nonmutating:
{
- return "::Ice::Nonmutating";
+ return cpp11 ? "::Ice::OperationMode::Nonmutating" : "::Ice::Nonmutating";
}
case Operation::Idempotent:
{
- return "::Ice::Idempotent";
+ return cpp11 ? "::Ice::OperationMode::Idempotent" : "::Ice::Idempotent";
}
default:
@@ -949,17 +1183,17 @@ Slice::writeUnmarshalCode(Output& out, const ParamDeclList& params, const Operat
}
void
-Slice::writeAllocateCode(Output& out, const ParamDeclList& params, const OperationPtr& op, bool prepend, int typeCtx)
+Slice::writeAllocateCode(Output& out, const ParamDeclList& params, const OperationPtr& op, bool prepend, int typeCtx, bool cpp11)
{
string prefix = prepend ? paramPrefix : "";
for(ParamDeclList::const_iterator p = params.begin(); p != params.end(); ++p)
{
writeParamAllocateCode(out, (*p)->type(), (*p)->optional(), fixKwd(prefix + (*p)->name()), (*p)->getMetaData(),
- typeCtx, getEndArg((*p)->type(),(*p)->getMetaData(), (*p)->name()) != (*p)->name());
+ typeCtx, cpp11, getEndArg((*p)->type(),(*p)->getMetaData(), (*p)->name()) != (*p)->name());
}
if(op && op->returnType())
{
- writeParamAllocateCode(out, op->returnType(), op->returnIsOptional(), "__ret", op->getMetaData(), typeCtx,
+ writeParamAllocateCode(out, op->returnType(), op->returnIsOptional(), "__ret", op->getMetaData(), typeCtx, cpp11,
getEndArg(op->returnType(), op->getMetaData(), "__ret") != "__ret");
}
}
@@ -1020,6 +1254,33 @@ Slice::writeEndCode(Output& out, const ParamDeclList& params, const OperationPtr
}
}
+bool
+Slice::findMetaData(const string& prefix, const ClassDeclPtr& cl, string& value)
+{
+ if(findMetaData(prefix, cl->getMetaData(), value))
+ {
+ return true;
+ }
+
+ ClassDefPtr def = cl->definition();
+ return def ? findMetaData(prefix, def->getMetaData(), value) : false;
+}
+
+bool
+Slice::findMetaData(const string& prefix, const StringList& metaData, string& value)
+{
+ for(StringList::const_iterator i = metaData.begin(); i != metaData.end(); i++)
+ {
+ string s = *i;
+ if(s.find(prefix) == 0)
+ {
+ value = s.substr(prefix.size());
+ return true;
+ }
+ }
+ return false;
+}
+
string
Slice::findMetaData(const StringList& metaData, int typeCtx)
{
@@ -1084,7 +1345,7 @@ Slice::findMetaData(const StringList& metaData, int typeCtx)
}
}
//
- // Otherwise if the data is "class" it is returned.
+ // Otherwise if the data is "class", "unscoped" it is returned.
//
else
{
@@ -1093,6 +1354,10 @@ Slice::findMetaData(const StringList& metaData, int typeCtx)
{
return "%class";
}
+ else if(ss == "unscoped")
+ {
+ return "%unscoped";
+ }
}
}
}
@@ -1144,3 +1409,35 @@ Slice::getDataMemberRef(const DataMemberPtr& p)
return "(*" + name + ")";
}
}
+
+string
+Slice::classDefToDelegateString(const ClassDefPtr& cl, int typeCtx, bool cpp11)
+{
+ assert(cl->isDelegate());
+
+ // A delegate only has one operation
+ OperationPtr op = cl->allOperations().front();
+
+ TypePtr ret = op->returnType();
+ string retS = returnTypeToString(ret, op->returnIsOptional(), op->getMetaData(), typeCtx, cpp11);
+
+ string t = "::std::function<" + retS + " (";
+
+ ParamDeclList paramList = cl->allOperations().front()->parameters();
+ for(ParamDeclList::iterator q = paramList.begin(); q != paramList.end(); ++q)
+ {
+ if((*q)->isOutParam())
+ {
+ t += outputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), typeCtx, cpp11);
+ }
+ else
+ {
+ t += inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), typeCtx, cpp11);
+ }
+
+ t += distance(q, paramList.end()) == 1 ? "" : ", ";
+ }
+
+ t += ")>";
+ return t;
+}