summaryrefslogtreecommitdiff
path: root/cpp/src/slice2swift
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2019-06-11 14:19:57 +0200
committerJose <jose@zeroc.com>2019-06-11 14:19:57 +0200
commitb6f32a3a4e94cbf6bc99cbbff51a40e2bf80afe4 (patch)
tree4cdeaf52131ad1f5b975a95881370f3c00b187ba /cpp/src/slice2swift
parentSync Ice/operations test with 3.7 (diff)
downloadice-b6f32a3a4e94cbf6bc99cbbff51a40e2bf80afe4.tar.bz2
ice-b6f32a3a4e94cbf6bc99cbbff51a40e2bf80afe4.tar.xz
ice-b6f32a3a4e94cbf6bc99cbbff51a40e2bf80afe4.zip
Swift servant dispatch updates
Diffstat (limited to 'cpp/src/slice2swift')
-rw-r--r--cpp/src/slice2swift/Gen.cpp152
-rw-r--r--cpp/src/slice2swift/Gen.h16
-rw-r--r--cpp/src/slice2swift/SwiftUtil.cpp4
3 files changed, 109 insertions, 63 deletions
diff --git a/cpp/src/slice2swift/Gen.cpp b/cpp/src/slice2swift/Gen.cpp
index b972a44e3e2..b550435e73c 100644
--- a/cpp/src/slice2swift/Gen.cpp
+++ b/cpp/src/slice2swift/Gen.cpp
@@ -101,6 +101,9 @@ Gen::generate(const UnitPtr& p)
ObjectExtVisitor objectExtVisitor(_out);
p->visit(&objectExtVisitor, false);
+ ObjectDispVisitor objectDispVisitor(_out);
+ p->visit(&objectDispVisitor, false);
+
LocalObjectVisitor localObjectVisitor(_out);
p->visit(&localObjectVisitor, false);
}
@@ -1513,20 +1516,13 @@ Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
}
const string swiftModule = getSwiftModule(getTopLevelModule(ContainedPtr::dynamicCast(p)));
- const string name = fixIdent(getUnqualified(getAbsolute(p), swiftModule) + (p->isInterface() ? "" : "Disp"));
+ const string name = fixIdent(getUnqualified(getAbsolute(p), swiftModule) + (p->isInterface() ? "" : "Operations"));
StringList baseNames;
- if(!hasBase)
- {
- baseNames.push_back(getUnqualified("Ice.Object", swiftModule));
- }
- else
+ for(ClassList::const_iterator i = bases.begin(); i != bases.end(); ++i)
{
- for(ClassList::const_iterator i = bases.begin(); i != bases.end(); ++i)
- {
- baseNames.push_back(fixIdent(getUnqualified(getAbsolute(*i), swiftModule) +
- ((*i)->isInterface() ? "" : "Disp")));
- }
+ baseNames.push_back(fixIdent(getUnqualified(getAbsolute(*i), swiftModule) +
+ ((*i)->isInterface() ? "" : "Operations")));
}
//
@@ -1544,7 +1540,11 @@ Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
out << sp;
writeDocSummary(out, p);
- out << nl << "public protocol " << name << ":";
+ out << nl << "public protocol " << name;
+ if(!baseNames.empty())
+ {
+ out << ":";
+ }
for(StringList::const_iterator i = baseNames.begin(); i != baseNames.end();)
{
@@ -1627,7 +1627,64 @@ Gen::ObjectExtVisitor::visitClassDefStart(const ClassDefPtr& p)
}
const string swiftModule = getSwiftModule(getTopLevelModule(ContainedPtr::dynamicCast(p)));
- const string name = getUnqualified(getAbsolute(p), swiftModule) + (!p->isInterface() ? "Disp" : "");
+ const string name = getUnqualified(getAbsolute(p), swiftModule) + (p->isInterface() ? "" : "Operations");
+
+ ClassList allBases = p->allBases();
+
+ out << sp;
+ writeServantDocSummary(out, p, swiftModule);
+ out << nl << "public extension " << fixIdent(name);
+
+ out << sb;
+ return true;
+}
+
+void
+Gen::ObjectExtVisitor::visitClassDefEnd(const ClassDefPtr&)
+{
+ out << eb;
+}
+
+void
+Gen::ObjectExtVisitor::visitOperation(const OperationPtr& op)
+{
+ if(operationIsAmd(op))
+ {
+ writeDispatchAsyncOperation(out, op);
+ }
+ else
+ {
+ writeDispatchOperation(out, op);
+ }
+}
+
+Gen::ObjectDispVisitor::ObjectDispVisitor(::IceUtilInternal::Output& o) : out(o)
+{
+}
+
+bool
+Gen::ObjectDispVisitor::visitModuleStart(const ModulePtr&)
+{
+ return true;
+}
+
+void
+Gen::ObjectDispVisitor::visitModuleEnd(const ModulePtr&)
+{
+}
+
+bool
+Gen::ObjectDispVisitor::visitClassDefStart(const ClassDefPtr& p)
+{
+ if(p->isLocal() || (!p->isInterface() && p->allOperations().empty()))
+ {
+ return false;
+ }
+
+ const string swiftModule = getSwiftModule(getTopLevelModule(ContainedPtr::dynamicCast(p)));
+ const string name = fixIdent(getUnqualified(getAbsolute(p), swiftModule) + "Disp");
+ const string servant = fixIdent(getUnqualified(getAbsolute(p), swiftModule) +
+ (p->isInterface() ? "" : "Operations"));
ClassList allBases = p->allBases();
StringList allIds;
@@ -1653,52 +1710,30 @@ Gen::ObjectExtVisitor::visitClassDefStart(const ClassDefPtr& p)
out << sp;
writeServantDocSummary(out, p, swiftModule);
- out << nl << "public extension " << fixIdent(name);
+ out << nl << "public struct " << name << ": "
+ << getUnqualified("Ice.Disp", swiftModule) << ", "
+ << getUnqualified("Ice.InterfaceTraits", swiftModule);
out << sb;
- out << sp;
- out << nl << "/// Returns the Slice type ID of the most-derived interface supported by this object.";
- out << nl << "///";
- out << nl << "/// parameter current: `Ice.Current` - The Current object for the invocation.";
- out << nl << "///";
- out << nl << "/// - returns: `String` - The Slice type ID of the most-derived interface supported by this object";
- out << nl << "func ice_id(current _: Current) throws -> Swift.String";
- out << sb;
- out << nl << "return \"" << p->scoped() << "\"";
- out << eb;
+ out << nl << "public static let staticIds = " << ids.str();
+ out << nl << "public static let staticId = \"" << p->scoped() << '"';
+ out << nl << "public let servant: " << servant;
- out << sp;
- out << nl << "/// Returns the Slice type IDs of the interfaces supported by this object";
- out << nl << "///";
- out << nl << "/// - parameter current: `Ice.Current` - The Current object for the invocation.";
- out << nl << "///";
- out << nl << "/// - returns: `[Swift.String]` - The Slice type IDs of the interfaces supported by this object,";
- out << nl << "/// in base-to-derived order.";
- out << nl << "func ice_ids(current _: Current) throws -> [Swift.String]";
- out << sb;
- out << nl << "return " << ids.str();
- out << eb;
+ out << nl << "private static let defaultObjectImpl = " << getUnqualified("Ice.DefaultObjectImpl", swiftModule)
+ << "<" << name << ">()";
out << sp;
- out << nl << "/// Tests whether this object supports a specific Slice interface.";
- out << nl << "///";
- out << nl << "/// - parameter s: `String` - The name of the interface to be check.";
- out << nl << "///";
- out << nl << "/// - parameter current: `Ice.Current` - The Current object for the invocation.";
- out << nl << "///";
- out << nl << "/// - returns: `Bool` - True if this object supports the interface specified by s or derives";
- out << nl << "/// from the interface specified by s.";
- out << nl << "func ice_isA(s: Swift.String, current _: Current) throws -> Swift.Bool";
+ out << nl << "public init(_ servant: " << servant << ")";
out << sb;
- out << nl << "return " << ids.str() << ".contains(s)";
+ out << nl << "self.servant = servant";
out << eb;
return true;
}
void
-Gen::ObjectExtVisitor::visitClassDefEnd(const ClassDefPtr& p)
+Gen::ObjectDispVisitor::visitClassDefEnd(const ClassDefPtr& p)
{
const string swiftModule = getSwiftModule(getTopLevelModule(ContainedPtr::dynamicCast(p)));
const string name = getUnqualified(getAbsolute(p), swiftModule);
@@ -1717,7 +1752,7 @@ Gen::ObjectExtVisitor::visitClassDefEnd(const ClassDefPtr& p)
out << sp;
out << nl;
- out << "func _iceDispatch";
+ out << "public func dispatch";
out << spar;
out << ("incoming inS: " + getUnqualified("Ice.Incoming", swiftModule));
out << ("current: " + getUnqualified("Ice.Current", swiftModule));
@@ -1733,7 +1768,15 @@ Gen::ObjectExtVisitor::visitClassDefEnd(const ClassDefPtr& p)
const string opName = *q;
out << nl << "case \"" << opName << "\":";
out.inc();
- out << nl << "try _iceD_" << opName << "(incoming: inS, current: current)";
+ if(opName == "ice_id" || opName == "ice_ids" || opName == "ice_isA" || opName == "ice_ping")
+ {
+ out << nl << "try (servant as? Object ?? " << fixIdent(name + "Disp") << ".defaultObjectImpl)._iceD_"
+ << opName << "(incoming: inS, current: current)";
+ }
+ else
+ {
+ out << nl << "try servant._iceD_" << opName << "(incoming: inS, current: current)";
+ }
out.dec();
}
out << nl << "default:";
@@ -1748,19 +1791,6 @@ Gen::ObjectExtVisitor::visitClassDefEnd(const ClassDefPtr& p)
out << eb;
}
-void
-Gen::ObjectExtVisitor::visitOperation(const OperationPtr& op)
-{
- if(operationIsAmd(op))
- {
- writeDispatchAsyncOperation(out, op);
- }
- else
- {
- writeDispatchOperation(out, op);
- }
-}
-
Gen::LocalObjectVisitor::LocalObjectVisitor(::IceUtilInternal::Output& o) : out(o)
{
}
diff --git a/cpp/src/slice2swift/Gen.h b/cpp/src/slice2swift/Gen.h
index 14c246946fd..b5939d4b99c 100644
--- a/cpp/src/slice2swift/Gen.h
+++ b/cpp/src/slice2swift/Gen.h
@@ -144,6 +144,22 @@ private:
IceUtilInternal::Output& out;
};
+ class ObjectDispVisitor : public SwiftGenerator, public ParserVisitor
+ {
+ public:
+
+ ObjectDispVisitor(::IceUtilInternal::Output&);
+
+ virtual bool visitModuleStart(const ModulePtr&);
+ virtual void visitModuleEnd(const ModulePtr&);
+ virtual bool visitClassDefStart(const ClassDefPtr&);
+ virtual void visitClassDefEnd(const ClassDefPtr&);
+
+ private:
+
+ IceUtilInternal::Output& out;
+ };
+
class LocalObjectVisitor : public SwiftGenerator, public ParserVisitor
{
public:
diff --git a/cpp/src/slice2swift/SwiftUtil.cpp b/cpp/src/slice2swift/SwiftUtil.cpp
index d81801b5040..e458c185069 100644
--- a/cpp/src/slice2swift/SwiftUtil.cpp
+++ b/cpp/src/slice2swift/SwiftUtil.cpp
@@ -1085,7 +1085,7 @@ SwiftGenerator::typeToString(const TypePtr& type,
"Swift.Float",
"Swift.Double",
"Swift.String",
- "Ice.Object", // Object
+ "Ice.Disp", // Object
"Ice.ObjectPrx", // ObjectPrx
"Swift.AnyObject", // LocalObject
"Ice.Value" // Value
@@ -1191,7 +1191,7 @@ SwiftGenerator::getAbsolute(const TypePtr& type)
"Swift.Float",
"Swift.Double",
"Swift.String",
- "Ice.Object", // Object
+ "Ice.Disp", // Object
"Ice.ObjectPrx", // ObjectPrx
"Swift.AnyObject", // LocalObject
"Ice.Value" // Value