summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/CPlusPlusUtil.cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2018-06-19 14:16:11 +0200
committerJose <jose@zeroc.com>2018-06-19 14:16:11 +0200
commit26452aaa7f31129a3c1889fee669eedda00cad75 (patch)
tree3da1350b5a3939ec5e62e30c0e2b8e1a2ce02b79 /cpp/src/Slice/CPlusPlusUtil.cpp
parentTestHelper pass InitializationData as const reference (diff)
downloadice-26452aaa7f31129a3c1889fee669eedda00cad75.tar.bz2
ice-26452aaa7f31129a3c1889fee669eedda00cad75.tar.xz
ice-26452aaa7f31129a3c1889fee669eedda00cad75.zip
slice2cpp generates invalid code wrt namespace qualification
Closes #104
Diffstat (limited to 'cpp/src/Slice/CPlusPlusUtil.cpp')
-rw-r--r--cpp/src/Slice/CPlusPlusUtil.cpp94
1 files changed, 49 insertions, 45 deletions
diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp
index f83eeb98231..8ebdd2f16b2 100644
--- a/cpp/src/Slice/CPlusPlusUtil.cpp
+++ b/cpp/src/Slice/CPlusPlusUtil.cpp
@@ -124,7 +124,7 @@ sequenceTypeToString(const SequencePtr& seq, const string& scope, const StringLi
}
else
{
- s = getAbsolute(fixKwd(seq->scoped()), scope);
+ s = getUnqualified(fixKwd(seq->scoped()), scope);
}
if(typeCtx & TypeContextAMIPrivateEnd)
@@ -145,7 +145,7 @@ sequenceTypeToString(const SequencePtr& seq, const string& scope, const StringLi
}
else
{
- return getAbsolute(fixKwd(seq->scoped()), scope);
+ return getUnqualified(fixKwd(seq->scoped()), scope);
}
}
@@ -155,7 +155,7 @@ dictionaryTypeToString(const DictionaryPtr& dict, const string& scope, const Str
const string dictType = findMetaData(metaData, typeCtx);
if(dictType.empty())
{
- return getAbsolute(fixKwd(dict->scoped()), scope);
+ return getUnqualified(fixKwd(dict->scoped()), scope);
}
else
{
@@ -610,7 +610,7 @@ Slice::isMovable(const TypePtr& type)
}
string
-Slice::getAbsolute(const std::string& type, const std::string& scope)
+Slice::getUnqualified(const std::string& type, const std::string& scope)
{
if(type.find("::") != string::npos)
{
@@ -627,7 +627,11 @@ Slice::getAbsolute(const std::string& type, const std::string& scope)
if(type.find(scope, prefix.size()) == prefix.size())
{
- return prefix + type.substr(prefix.size() + scope.size());
+ string t = type.substr(prefix.size() + scope.size());
+ if(t.find("::") == string::npos)
+ {
+ return prefix + t;
+ }
}
}
return type;
@@ -695,16 +699,16 @@ Slice::typeToString(const TypePtr& type, const string& scope, const StringList&
{
if(builtin->kind() == Builtin::KindObject && !(typeCtx & TypeContextLocal))
{
- return getAbsolute(cpp11BuiltinTable[Builtin::KindValue], scope);
+ return getUnqualified(cpp11BuiltinTable[Builtin::KindValue], scope);
}
else
{
- return getAbsolute(cpp11BuiltinTable[builtin->kind()], scope);
+ return getUnqualified(cpp11BuiltinTable[builtin->kind()], scope);
}
}
else
{
- return getAbsolute(builtinTable[builtin->kind()], scope);
+ return getUnqualified(builtinTable[builtin->kind()], scope);
}
}
@@ -715,20 +719,20 @@ Slice::typeToString(const TypePtr& type, const string& scope, const StringList&
{
if(cl->definition() && cl->definition()->isDelegate())
{
- return getAbsolute(fixKwd(cl->scoped()), scope);
+ return getUnqualified(fixKwd(cl->scoped()), scope);
}
else if(cl->isInterface() && !cl->isLocal())
{
- return getAbsolute(cpp11BuiltinTable[Builtin::KindValue], scope);
+ return getUnqualified(cpp11BuiltinTable[Builtin::KindValue], scope);
}
else
{
- return "::std::shared_ptr<" + getAbsolute(cl->scoped(), scope) + ">";
+ return "::std::shared_ptr<" + getUnqualified(cl->scoped(), scope) + ">";
}
}
else
{
- return getAbsolute(cl->scoped() + "Ptr", scope);
+ return getUnqualified(cl->scoped() + "Ptr", scope);
}
}
@@ -740,11 +744,11 @@ Slice::typeToString(const TypePtr& type, const string& scope, const StringList&
//
if(!cpp11 && findMetaData(st->getMetaData()) == "%class")
{
- return getAbsolute(fixKwd(st->scoped() + "Ptr"), scope);
+ return getUnqualified(fixKwd(st->scoped() + "Ptr"), scope);
}
else
{
- return getAbsolute(fixKwd(st->scoped()), scope);
+ return getUnqualified(fixKwd(st->scoped()), scope);
}
}
@@ -760,23 +764,23 @@ Slice::typeToString(const TypePtr& type, const string& scope, const StringList&
//
if(def && !def->isInterface() && def->allOperations().empty())
{
- return getAbsolute(cpp11BuiltinTable[Builtin::KindObjectProxy], scope);
+ return getUnqualified(cpp11BuiltinTable[Builtin::KindObjectProxy], scope);
}
else
{
- return "::std::shared_ptr<" + getAbsolute(fixKwd(proxy->_class()->scoped() + "Prx"), scope) + ">";
+ return "::std::shared_ptr<" + getUnqualified(fixKwd(proxy->_class()->scoped() + "Prx"), scope) + ">";
}
}
else
{
- return getAbsolute(fixKwd(proxy->_class()->scoped() + "Prx"), scope);
+ return getUnqualified(fixKwd(proxy->_class()->scoped() + "Prx"), scope);
}
}
EnumPtr en = EnumPtr::dynamicCast(type);
if(en)
{
- return getAbsolute(fixKwd(en->scoped()), scope);
+ return getUnqualified(fixKwd(en->scoped()), scope);
}
SequencePtr seq = SequencePtr::dynamicCast(type);
@@ -880,16 +884,16 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const string& scope
{
if(builtin->kind() == Builtin::KindObject && !(typeCtx & TypeContextLocal))
{
- return getAbsolute(cpp11InputBuiltinTable[Builtin::KindValue], scope);
+ return getUnqualified(cpp11InputBuiltinTable[Builtin::KindValue], scope);
}
else
{
- return getAbsolute(cpp11InputBuiltinTable[builtin->kind()], scope);
+ return getUnqualified(cpp11InputBuiltinTable[builtin->kind()], scope);
}
}
else
{
- return getAbsolute(cpp98InputBuiltinTable[builtin->kind()], scope);
+ return getUnqualified(cpp98InputBuiltinTable[builtin->kind()], scope);
}
}
@@ -900,20 +904,20 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const string& scope
{
if(cl->definition() && cl->definition()->isDelegate())
{
- return getAbsolute(fixKwd(cl->scoped()), scope);
+ return getUnqualified(fixKwd(cl->scoped()), scope);
}
else if(cl->isInterface() && !cl->isLocal())
{
- return getAbsolute(cpp11InputBuiltinTable[Builtin::KindValue], scope);
+ return getUnqualified(cpp11InputBuiltinTable[Builtin::KindValue], scope);
}
else
{
- return "const ::std::shared_ptr<" + getAbsolute(fixKwd(cl->scoped()), scope) + ">&";
+ return "const ::std::shared_ptr<" + getUnqualified(fixKwd(cl->scoped()), scope) + ">&";
}
}
else
{
- return "const " + getAbsolute(fixKwd(cl->scoped() + "Ptr&"), scope);
+ return "const " + getUnqualified(fixKwd(cl->scoped() + "Ptr&"), scope);
}
}
@@ -922,17 +926,17 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const string& scope
{
if(cpp11)
{
- return "const " + getAbsolute(fixKwd(st->scoped()), scope) + "&";
+ return "const " + getUnqualified(fixKwd(st->scoped()), scope) + "&";
}
else
{
if(findMetaData(st->getMetaData()) == "%class")
{
- return "const " + getAbsolute(fixKwd(st->scoped() + "Ptr"), scope) + "&";
+ return "const " + getUnqualified(fixKwd(st->scoped() + "Ptr"), scope) + "&";
}
else
{
- return "const " + getAbsolute(fixKwd(st->scoped()), scope) + "&";
+ return "const " + getUnqualified(fixKwd(st->scoped()), scope) + "&";
}
}
}
@@ -945,23 +949,23 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const string& scope
ClassDefPtr def = proxy->_class()->definition();
if(def && !def->isInterface() && def->allOperations().empty())
{
- return getAbsolute(cpp11InputBuiltinTable[Builtin::KindObjectProxy], scope);
+ return getUnqualified(cpp11InputBuiltinTable[Builtin::KindObjectProxy], scope);
}
else
{
- return "const ::std::shared_ptr<" + getAbsolute(fixKwd(proxy->_class()->scoped() + "Prx"), scope) + ">&";
+ return "const ::std::shared_ptr<" + getUnqualified(fixKwd(proxy->_class()->scoped() + "Prx"), scope) + ">&";
}
}
else
{
- return "const " + getAbsolute(fixKwd(proxy->_class()->scoped() + "Prx"), scope) + "&";
+ return "const " + getUnqualified(fixKwd(proxy->_class()->scoped() + "Prx"), scope) + "&";
}
}
EnumPtr en = EnumPtr::dynamicCast(type);
if(en)
{
- return getAbsolute(fixKwd(en->scoped()), scope);
+ return getUnqualified(fixKwd(en->scoped()), scope);
}
SequencePtr seq = SequencePtr::dynamicCast(type);
@@ -1033,16 +1037,16 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const string& scop
{
if(builtin->kind() == Builtin::KindObject && !(typeCtx & TypeContextLocal))
{
- return getAbsolute(cpp11OutputBuiltinTable[Builtin::KindValue], scope);
+ return getUnqualified(cpp11OutputBuiltinTable[Builtin::KindValue], scope);
}
else
{
- return getAbsolute(cpp11OutputBuiltinTable[builtin->kind()], scope);
+ return getUnqualified(cpp11OutputBuiltinTable[builtin->kind()], scope);
}
}
else
{
- return getAbsolute(outputBuiltinTable[builtin->kind()], scope);
+ return getUnqualified(outputBuiltinTable[builtin->kind()], scope);
}
}
@@ -1053,20 +1057,20 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const string& scop
{
if(cl->definition() && cl->definition()->isDelegate())
{
- return getAbsolute(fixKwd(cl->scoped()), scope) + "&";
+ return getUnqualified(fixKwd(cl->scoped()), scope) + "&";
}
else if(cl->isInterface() && !cl->isLocal())
{
- return getAbsolute(cpp11OutputBuiltinTable[Builtin::KindValue], scope);
+ return getUnqualified(cpp11OutputBuiltinTable[Builtin::KindValue], scope);
}
else
{
- return "::std::shared_ptr<" + getAbsolute(fixKwd(cl->scoped()), scope) + ">&";
+ return "::std::shared_ptr<" + getUnqualified(fixKwd(cl->scoped()), scope) + ">&";
}
}
else
{
- return getAbsolute(fixKwd(cl->scoped() + "Ptr&"), scope);
+ return getUnqualified(fixKwd(cl->scoped() + "Ptr&"), scope);
}
}
@@ -1075,11 +1079,11 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const string& scop
{
if(!cpp11 && findMetaData(st->getMetaData()) == "%class")
{
- return getAbsolute(fixKwd(st->scoped() + "Ptr&"), scope);
+ return getUnqualified(fixKwd(st->scoped() + "Ptr&"), scope);
}
else
{
- return getAbsolute(fixKwd(st->scoped()), scope) + "&";
+ return getUnqualified(fixKwd(st->scoped()), scope) + "&";
}
}
@@ -1095,23 +1099,23 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const string& scop
//
if(def && !def->isInterface() && def->allOperations().empty())
{
- return getAbsolute(cpp11OutputBuiltinTable[Builtin::KindObjectProxy], scope);
+ return getUnqualified(cpp11OutputBuiltinTable[Builtin::KindObjectProxy], scope);
}
else
{
- return "::std::shared_ptr<" + getAbsolute(fixKwd(proxy->_class()->scoped() + "Prx"), scope) + ">&";
+ return "::std::shared_ptr<" + getUnqualified(fixKwd(proxy->_class()->scoped() + "Prx"), scope) + ">&";
}
}
else
{
- return getAbsolute(fixKwd(proxy->_class()->scoped() + "Prx&"), scope);
+ return getUnqualified(fixKwd(proxy->_class()->scoped() + "Prx&"), scope);
}
}
EnumPtr en = EnumPtr::dynamicCast(type);
if(en)
{
- return getAbsolute(fixKwd(en->scoped()), scope) + "&";
+ return getUnqualified(fixKwd(en->scoped()), scope) + "&";
}
SequencePtr seq = SequencePtr::dynamicCast(type);