diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/src/slice2swift/Gen.cpp | 32 | ||||
-rw-r--r-- | cpp/src/slice2swift/SwiftUtil.cpp | 8 | ||||
-rw-r--r-- | cpp/src/slice2swift/SwiftUtil.h | 1 |
3 files changed, 37 insertions, 4 deletions
diff --git a/cpp/src/slice2swift/Gen.cpp b/cpp/src/slice2swift/Gen.cpp index d3d05567e8e..11dfe2da2ba 100644 --- a/cpp/src/slice2swift/Gen.cpp +++ b/cpp/src/slice2swift/Gen.cpp @@ -841,6 +841,38 @@ Gen::ValueVisitor::visitClassDefStart(const ClassDefPtr& p) base = bases.front(); } + // + // For each Value class we generate a extension in ClassResolver + // + ostringstream factory; + StringList parts = splitScopedName(p->scoped()); + for(StringList::const_iterator it = parts.begin(); it != parts.end();) + { + factory << (*it); + if(++it != parts.end()) + { + factory << "_"; + } + } + + out << sp; + out << nl << "public class " << name << "_TypeResolver: Ice.ValueTypeResolver"; + out << sb; + out << nl << "public override func type() -> Ice.Value.Type"; + out << sb; + out << nl << "return " << name << ".self"; + out << eb; + out << eb; + + out << sp; + out << nl << "public extension Ice.ClassResolver"; + out << sb; + out << nl << "@objc public static func " << factory.str() << "() -> Ice.ValueTypeResolver"; + out << sb; + out << nl << "return " << name << "_TypeResolver()"; + out << eb; + out << eb; + out << sp; out << nl << "public class " << name << ": "; if(base) diff --git a/cpp/src/slice2swift/SwiftUtil.cpp b/cpp/src/slice2swift/SwiftUtil.cpp index 1fe9ccf7fe0..5c3bcac9013 100644 --- a/cpp/src/slice2swift/SwiftUtil.cpp +++ b/cpp/src/slice2swift/SwiftUtil.cpp @@ -62,11 +62,13 @@ replace(string s, string patt, string val) return r; } +} + // // Split a scoped name into its components and return the components as a list of (unscoped) identifiers. // -static StringList -splitScopedName(const string& scoped) +StringList +Slice::splitScopedName(const string& scoped) { assert(scoped[0] == ':'); StringList ids; @@ -97,8 +99,6 @@ splitScopedName(const string& scoped) return ids; } -} - // // Check the given identifier against Swift's list of reserved words. If it matches // a reserved word, then an escaped version is returned with a leading underscore. diff --git a/cpp/src/slice2swift/SwiftUtil.h b/cpp/src/slice2swift/SwiftUtil.h index 3a8f952675e..9adb06df0b2 100644 --- a/cpp/src/slice2swift/SwiftUtil.h +++ b/cpp/src/slice2swift/SwiftUtil.h @@ -26,6 +26,7 @@ ModulePtr getTopLevelModule(const ContainedPtr&); ModulePtr getTopLevelModule(const TypePtr&); std::string fixIdent(const std::string&); +StringList splitScopedName(const std::string&); class SwiftGenerator : private IceUtil::noncopyable { |