summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/ObjCUtil.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2015-01-20 17:02:24 +0100
committerBenoit Foucher <benoit@zeroc.com>2015-01-20 17:02:24 +0100
commitad95d30b390e7eab690f35f7ccb6d841d49e8fda (patch)
tree28b903ee99f2fb9fa411044b54951ff121bb6f45 /cpp/src/Slice/ObjCUtil.cpp
parentICE-6212 Don't use port 9990 in demos (diff)
downloadice-ad95d30b390e7eab690f35f7ccb6d841d49e8fda.tar.bz2
ice-ad95d30b390e7eab690f35f7ccb6d841d49e8fda.tar.xz
ice-ad95d30b390e7eab690f35f7ccb6d841d49e8fda.zip
Updated the Objective-C to generate Slice local interfaces and classes
Diffstat (limited to 'cpp/src/Slice/ObjCUtil.cpp')
-rw-r--r--cpp/src/Slice/ObjCUtil.cpp99
1 files changed, 96 insertions, 3 deletions
diff --git a/cpp/src/Slice/ObjCUtil.cpp b/cpp/src/Slice/ObjCUtil.cpp
index ab2c03d02e7..a765081c06e 100644
--- a/cpp/src/Slice/ObjCUtil.cpp
+++ b/cpp/src/Slice/ObjCUtil.cpp
@@ -92,6 +92,27 @@ lookupKwd(const string& name, int baseType, bool mangleCasts = false)
return name;
}
+static string
+lookupParamIdKwd(const string& name)
+{
+ //
+ // All lists in this method *must* be kept in case-insensitive
+ // alphabetical order.
+ //
+ static string keywordList[] =
+ {
+ "nil", "NO", "YES"
+ };
+ if(binary_search(&keywordList[0],
+ &keywordList[sizeof(keywordList) / sizeof(*keywordList)],
+ name,
+ Slice::CICompare()))
+ {
+ return name + "_";
+ }
+ return name;
+}
+
bool
Slice::ObjCGenerator::addModule(const ModulePtr& m, const string& name)
{
@@ -173,6 +194,56 @@ Slice::ObjCGenerator::fixName(const ContainedPtr& cont, int baseTypes, bool mang
}
string
+Slice::ObjCGenerator::getParamId(const ContainedPtr& param)
+{
+ string n;
+ if(ParamDeclPtr::dynamicCast(param) && param->findMetaData("objc:param:", n))
+ {
+ return lookupParamIdKwd(n.substr(11));
+ }
+ else
+ {
+ return lookupParamIdKwd(param->name());
+ }
+}
+
+string
+Slice::ObjCGenerator::getFactoryMethod(const ContainedPtr& p, bool deprecated)
+{
+ ClassDefPtr def = ClassDefPtr::dynamicCast(p);
+ if(def && def->declaration()->isLocal())
+ {
+ deprecated = false; // Local classes don't have this issue since they were added after this fix.
+ }
+
+ //
+ // If deprecated is true, we return uDPConnectionInfo for a class
+ // named UDPConnectionInfo, return udpConnectionInfo otherwise.
+ //
+ string name = fixId(p->name());
+ if(name.empty())
+ {
+ return name;
+ }
+ else if(deprecated || name.size() < 2 || !isupper(*(name.begin() + 1)))
+ {
+ *name.begin() = tolower(*name.begin());
+ }
+ else
+ {
+ for(string::iterator p = name.begin(); p != name.end() - 1; ++p)
+ {
+ if(!isupper(*(p + 1)))
+ {
+ break;
+ }
+ *p = tolower(*p);
+ }
+ }
+ return name;
+}
+
+string
Slice::ObjCGenerator::typeToString(const TypePtr& type)
{
if(!type)
@@ -221,9 +292,24 @@ Slice::ObjCGenerator::typeToString(const TypePtr& type)
}
ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
- if(cl && cl->isInterface())
+ if(cl)
{
- return "ICEObject";
+ if(cl->isInterface())
+ {
+ if(cl->isLocal())
+ {
+ return "id<" + fixName(cl) + ">";
+ }
+ else
+ {
+ return "ICEObject";
+ }
+ }
+ else if(cl->isLocal())
+ {
+ string name = fixName(cl);
+ return name + "<" + name + ">";
+ }
}
ContainedPtr contained = ContainedPtr::dynamicCast(type);
@@ -397,7 +483,14 @@ Slice::ObjCGenerator::mapsToPointerType(const TypePtr& type)
ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
if(cl && cl->isInterface())
{
- return true;
+ if(cl->isLocal())
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
}
return !ProxyPtr::dynamicCast(type);
}