summaryrefslogtreecommitdiff
path: root/cpp/src/slice2swift/SwiftUtil.cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2019-02-26 17:21:37 +0100
committerJose <jose@zeroc.com>2019-02-26 17:21:58 +0100
commit70abc6c81a9c85373dad873f835805cbc6354872 (patch)
tree3c06821adfdd4cd04d0ff7231165c7f44d5c1d05 /cpp/src/slice2swift/SwiftUtil.cpp
parentVarious fixes (diff)
downloadice-70abc6c81a9c85373dad873f835805cbc6354872.tar.bz2
ice-70abc6c81a9c85373dad873f835805cbc6354872.tar.xz
ice-70abc6c81a9c85373dad873f835805cbc6354872.zip
slice2swift updates
Diffstat (limited to 'cpp/src/slice2swift/SwiftUtil.cpp')
-rw-r--r--cpp/src/slice2swift/SwiftUtil.cpp37
1 files changed, 23 insertions, 14 deletions
diff --git a/cpp/src/slice2swift/SwiftUtil.cpp b/cpp/src/slice2swift/SwiftUtil.cpp
index fcf7b72bff0..6bd9c55f942 100644
--- a/cpp/src/slice2swift/SwiftUtil.cpp
+++ b/cpp/src/slice2swift/SwiftUtil.cpp
@@ -224,7 +224,7 @@ SwiftGenerator::getLocalScope(const string& scope, const string& separator)
}
string
-SwiftGenerator::typeToString(const TypePtr& type, const ContainedPtr& c)
+SwiftGenerator::typeToString(const TypePtr& type, const ContainedPtr& toplevel)
{
static const char* builtinTable[] =
{
@@ -247,18 +247,12 @@ SwiftGenerator::typeToString(const TypePtr& type, const ContainedPtr& c)
return "";
}
- const bool hasNonOptionalMetadata = c && c->hasMetaData("swift:non-optional");
- const ParamDeclPtr p = ParamDeclPtr::dynamicCast(c);
- const bool isOptionalParam = p && p->optional();
string str;
- bool optional = isOptionalParam || (!isValueType(type) && !hasNonOptionalMetadata);
-
BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
if(builtin)
{
- str = builtinTable[builtin->kind()];
- return optional ? str + "?" : str;
+ return builtinTable[builtin->kind()];
}
ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
@@ -289,22 +283,19 @@ SwiftGenerator::typeToString(const TypePtr& type, const ContainedPtr& c)
ProxyPtr proxy = ProxyPtr::dynamicCast(type);
if(proxy)
{
- str = getAbsolute(proxy->_class(), "", "Prx");
- return optional ? str + "?" : str;
+ return getAbsolute(proxy->_class(), "", "Prx");
}
DictionaryPtr dict = DictionaryPtr::dynamicCast(type);
if(dict)
{
- str = getAbsolute(dict);
- return optional ? str + "?" : str;
+ return getAbsolute(dict);
}
ContainedPtr contained = ContainedPtr::dynamicCast(type);
if(contained)
{
- str = getAbsolute(contained);
- return optional ? str + "?" : str;
+ return getAbsolute(contained);
}
return "???";
@@ -388,6 +379,24 @@ SwiftGenerator::getAbsolute(const ContainedPtr& cont,
return replace(str, "::", ".");
}
+string
+SwiftGenerator::getUnqualified(const string& type, const string& module)
+{
+ if(importPrefix.empty())
+ {
+ const string localScope = getLocalScope(scope) + ".";
+ if(type.find(localScope) == 0)
+ {
+ string t = type.substr(localScope.size());
+ if(t.find(".") == string::npos)
+ {
+ return t;
+ }
+ }
+ }
+ return type;
+}
+
std::string
SwiftGenerator::modeToString(Operation::Mode opMode)
{