summaryrefslogtreecommitdiff
path: root/cpp/src/slice2objc
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2015-02-10 19:19:24 +0100
committerBenoit Foucher <benoit@zeroc.com>2015-02-10 19:19:24 +0100
commit22d72a2059f312a7ae7572dc2d3c4565b5d22e3d (patch)
tree7c03ab153c0f78b795ff41365fbf589d1558d1fd /cpp/src/slice2objc
parentMinor fix to ObjC ServantLcoator code (diff)
downloadice-22d72a2059f312a7ae7572dc2d3c4565b5d22e3d.tar.bz2
ice-22d72a2059f312a7ae7572dc2d3c4565b5d22e3d.tar.xz
ice-22d72a2059f312a7ae7572dc2d3c4565b5d22e3d.zip
Fixed ICE-6257 - support for visibility attribute
Diffstat (limited to 'cpp/src/slice2objc')
-rw-r--r--cpp/src/slice2objc/Gen.cpp102
-rw-r--r--cpp/src/slice2objc/Gen.h19
-rw-r--r--cpp/src/slice2objc/Main.cpp6
3 files changed, 79 insertions, 48 deletions
diff --git a/cpp/src/slice2objc/Gen.cpp b/cpp/src/slice2objc/Gen.cpp
index 2322af24b15..033706758cc 100644
--- a/cpp/src/slice2objc/Gen.cpp
+++ b/cpp/src/slice2objc/Gen.cpp
@@ -102,7 +102,7 @@ public:
}
-Slice::ObjCVisitor::ObjCVisitor(Output& h, Output& m) : _H(h), _M(m)
+Slice::ObjCVisitor::ObjCVisitor(Output& h, Output& m, const string& dllExport) : _H(h), _M(m), _dllExport(dllExport)
{
}
@@ -618,10 +618,11 @@ Slice::ObjCVisitor::getServerArgs(const OperationPtr& op) const
}
Slice::Gen::Gen(const string& name, const string& base, const string& include, const vector<string>& includePaths,
- const string& dir)
+ const string& dir, const string& dllExport)
: _base(base),
_include(include),
- _includePaths(includePaths)
+ _includePaths(includePaths),
+ _dllExport(dllExport)
{
for(vector<string>::iterator p = _includePaths.begin(); p != _includePaths.end(); ++p)
{
@@ -746,25 +747,48 @@ Slice::Gen::generate(const UnitPtr& p)
_H << changeInclude(*q, _includePaths) << ".h>";
}
- UnitVisitor unitVisitor(_H, _M);
+ if(_dllExport.size())
+ {
+ _M << nl;
+ _M << nl << "#ifndef " << _dllExport << "_EXPORTS";
+ _M << nl << "# define " << _dllExport << "_EXPORTS";
+ _M << nl << "#endif";
+ _M << nl;
+
+ _H << nl;
+ _H << nl << "#ifndef " << _dllExport;
+ _H << nl << "# ifdef " << _dllExport << "_EXPORTS";
+ _H << nl << "# define " << _dllExport << " ICE_DECLSPEC_EXPORT";
+ _H << nl << "# else";
+ _H << nl << "# define " << _dllExport << " ICE_DECLSPEC_IMPORT";
+ _H << nl << "# endif";
+ _H << nl << "#endif";
+ }
+
+ if(!_dllExport.empty())
+ {
+ _dllExport += " ";
+ }
+
+ UnitVisitor unitVisitor(_H, _M, _dllExport);
p->visit(&unitVisitor, false);
- ObjectDeclVisitor objectDeclVisitor(_H, _M);
+ ObjectDeclVisitor objectDeclVisitor(_H, _M, _dllExport);
p->visit(&objectDeclVisitor, false);
- ProxyDeclVisitor proxyDeclVisitor(_H, _M);
+ ProxyDeclVisitor proxyDeclVisitor(_H, _M, _dllExport);
p->visit(&proxyDeclVisitor, false);
- TypesVisitor typesVisitor(_H, _M);
+ TypesVisitor typesVisitor(_H, _M, _dllExport);
p->visit(&typesVisitor, false);
- ProxyVisitor proxyVisitor(_H, _M);
+ ProxyVisitor proxyVisitor(_H, _M, _dllExport);
p->visit(&proxyVisitor, false);
- DelegateMVisitor delegateMVisitor(_H, _M);
+ DelegateMVisitor delegateMVisitor(_H, _M, _dllExport);
p->visit(&delegateMVisitor, false);
- HelperVisitor HelperVisitor(_H, _M);
+ HelperVisitor HelperVisitor(_H, _M, _dllExport);
p->visit(&HelperVisitor, false);
}
@@ -793,8 +817,8 @@ Slice::Gen::printHeader(Output& o)
o << "\n// Ice version " << ICE_STRING_VERSION;
}
-Slice::Gen::UnitVisitor::UnitVisitor(Output& H, Output& M) :
- ObjCVisitor(H, M)
+Slice::Gen::UnitVisitor::UnitVisitor(Output& H, Output& M, const string& dllExport) :
+ ObjCVisitor(H, M, dllExport)
{
}
@@ -835,8 +859,8 @@ Slice::Gen::UnitVisitor::visitUnitEnd(const UnitPtr& unit)
}
}
-Slice::Gen::ObjectDeclVisitor::ObjectDeclVisitor(Output& H, Output& M)
- : ObjCVisitor(H, M)
+Slice::Gen::ObjectDeclVisitor::ObjectDeclVisitor(Output& H, Output& M, const string& dllExport)
+ : ObjCVisitor(H, M, dllExport)
{
}
@@ -851,8 +875,8 @@ Slice::Gen::ObjectDeclVisitor::visitClassDecl(const ClassDeclPtr& p)
_H << nl << "@protocol " << fixName(p) << ";";
}
-Slice::Gen::ProxyDeclVisitor::ProxyDeclVisitor(Output& H, Output& M)
- : ObjCVisitor(H, M)
+Slice::Gen::ProxyDeclVisitor::ProxyDeclVisitor(Output& H, Output& M, const string& dllExport)
+ : ObjCVisitor(H, M, dllExport)
{
}
@@ -866,8 +890,8 @@ Slice::Gen::ProxyDeclVisitor::visitClassDecl(const ClassDeclPtr& p)
}
}
-Slice::Gen::TypesVisitor::TypesVisitor(Output& H, Output& M)
- : ObjCVisitor(H, M)
+Slice::Gen::TypesVisitor::TypesVisitor(Output& H, Output& M, const string& dllExport)
+ : ObjCVisitor(H, M, dllExport)
{
}
@@ -900,7 +924,7 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p)
string name = fixName(p);
ClassList bases = p->bases();
- _H << sp << nl << "@protocol " << name;
+ _H << sp << nl << _dllExport << "@protocol " << name;
if(!bases.empty())
{
_H << " <";
@@ -952,7 +976,7 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p)
return;
}
- _H << sp << nl << "@interface " << name << " : " << baseName;
+ _H << sp << nl << _dllExport << "@interface " << name << " : " << baseName;
if(!dataMembers.empty() || (preserved && !basePreserved))
{
@@ -1149,7 +1173,7 @@ Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p)
_H << sp;
- _H << nl << "@interface " << name << " : ";
+ _H << nl << _dllExport << "@interface " << name << " : ";
if(base)
{
_H << fixName(base);
@@ -1305,7 +1329,7 @@ Slice::Gen::TypesVisitor::visitStructStart(const StructPtr& p)
_H << sp;
- _H << nl << "@interface " << name << " : NSObject <NSCopying>";
+ _H << nl << _dllExport << "@interface " << name << " : NSObject <NSCopying>";
_H << sb;
_H << nl << "@private";
_H.inc();
@@ -2077,8 +2101,8 @@ Slice::Gen::TypesVisitor::writeMemberUnmarshal(const DataMemberList& dataMembers
}
}
-Slice::Gen::ProxyVisitor::ProxyVisitor(Output& H, Output& M)
- : ObjCVisitor(H, M)
+Slice::Gen::ProxyVisitor::ProxyVisitor(Output& H, Output& M, const string& dllExport)
+ : ObjCVisitor(H, M, dllExport)
{
}
@@ -2093,7 +2117,7 @@ Slice::Gen::ProxyVisitor::visitClassDefStart(const ClassDefPtr& p)
string name = fixName(p);
ClassList bases = p->bases();
- _H << sp << nl << "@protocol " << name << "Prx <";
+ _H << sp << nl << _dllExport << "@protocol " << name << "Prx <";
if(bases.empty())
{
_H << "ICEObjectPrx";
@@ -2191,8 +2215,8 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
_H << " response:(" << responseCBSig << ")response_ exception:(void(^)(ICEException*))exception_ sent:(void(^)(BOOL))sent_;";
}
-Slice::Gen::HelperVisitor::HelperVisitor(Output& H, Output& M) :
- ObjCVisitor(H, M)
+Slice::Gen::HelperVisitor::HelperVisitor(Output& H, Output& M, const string& dllExport) :
+ ObjCVisitor(H, M, dllExport)
{
}
@@ -2209,7 +2233,7 @@ Slice::Gen::HelperVisitor::visitClassDefStart(const ClassDefPtr& p)
//
{
string name = moduleName(findModule(p)) + p->name() + "PrxHelper";
- _H << sp << nl << "@interface " << name << " : ICEProxyHelper";
+ _H << sp << nl << _dllExport << "@interface " << name << " : ICEProxyHelper";
_H << nl << "@end";
_M << sp << nl << "@implementation " << name;
@@ -2231,7 +2255,7 @@ Slice::Gen::HelperVisitor::visitClassDefStart(const ClassDefPtr& p)
}
else
{
- _H << sp << nl << "@interface " << name << " : ICEObjectHelper";
+ _H << sp << nl << _dllExport << "@interface " << name << " : ICEObjectHelper";
_H << nl << "@end";
_M << sp << nl << "@implementation " << name;
@@ -2255,7 +2279,7 @@ Slice::Gen::HelperVisitor::visitEnum(const EnumPtr& p)
string name = moduleName(findModule(p)) + p->name() + "Helper";
- _H << sp << nl << "@interface " << name << " : ICEEnumHelper";
+ _H << sp << nl << _dllExport << "@interface " << name << " : ICEEnumHelper";
_H << nl << "@end";
_M << sp << nl << "@implementation " << name;
@@ -2290,7 +2314,7 @@ Slice::Gen::HelperVisitor::visitSequence(const SequencePtr& p)
EnumPtr en = EnumPtr::dynamicCast(p->type());
if(en)
{
- _H << sp << nl << "@interface " << name << " : ICEEnumSequenceHelper";
+ _H << sp << nl << _dllExport << "@interface " << name << " : ICEEnumSequenceHelper";
_H << nl << "@end";
string typeS = typeToString(en);
@@ -2312,7 +2336,7 @@ Slice::Gen::HelperVisitor::visitSequence(const SequencePtr& p)
ClassDeclPtr cl = ClassDeclPtr::dynamicCast(p->type());
if(cl)
{
- _H << sp << nl << "@interface " << name << " : ICEObjectSequenceHelper";
+ _H << sp << nl << _dllExport << "@interface " << name << " : ICEObjectSequenceHelper";
_H << nl << "@end";
_M << sp << nl << "@implementation " << name;
@@ -2326,7 +2350,7 @@ Slice::Gen::HelperVisitor::visitSequence(const SequencePtr& p)
ProxyPtr proxy = ProxyPtr::dynamicCast(p->type());
ContainedPtr contained = ContainedPtr::dynamicCast(p->type());
- _H << sp << nl << "@interface " << name << " : ICEArraySequenceHelper";
+ _H << sp << nl << _dllExport << "@interface " << name << " : ICEArraySequenceHelper";
_H << nl << "@end";
_M << sp << nl << "@implementation " << name;
@@ -2390,7 +2414,7 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p)
ClassDeclPtr valueClass = ClassDeclPtr::dynamicCast(valueType);
if((valueBuiltin && valueBuiltin->kind() == Builtin::KindObject) || valueClass)
{
- _H << sp << nl << "@interface " << name << " : ICEObjectDictionaryHelper";
+ _H << sp << nl << _dllExport << "@interface " << name << " : ICEObjectDictionaryHelper";
_H << nl << "@end";
_M << sp << nl << "@implementation " << name;
@@ -2428,7 +2452,7 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p)
ContainedPtr contained = ContainedPtr::dynamicCast(valueType);
valueS = moduleName(findModule(contained)) + contained->name() + "Helper";
}
- _H << sp << nl << "@interface " << name << " : ICEDictionaryHelper";
+ _H << sp << nl << _dllExport << "@interface " << name << " : ICEDictionaryHelper";
_H << nl << "@end";
_M << sp << nl << "@implementation " << name;
@@ -2464,7 +2488,7 @@ Slice::Gen::HelperVisitor::visitStructStart(const StructPtr& p)
string name = fixName(p);
- _H << sp << nl << "@interface " << name << "Helper : ICEStructHelper";
+ _H << sp << nl << _dllExport << "@interface " << name << "Helper : ICEStructHelper";
_H << nl << "@end";
_M << sp << nl << "@implementation " << name << "Helper";
@@ -2494,8 +2518,8 @@ Slice::Gen::HelperVisitor::visitStructStart(const StructPtr& p)
return false;
}
-Slice::Gen::DelegateMVisitor::DelegateMVisitor(Output& H, Output& M)
- : ObjCVisitor(H, M)
+Slice::Gen::DelegateMVisitor::DelegateMVisitor(Output& H, Output& M, const string& dllExport)
+ : ObjCVisitor(H, M, dllExport)
{
}
@@ -2523,7 +2547,7 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p)
OperationList ops = p->allOperations();
OperationList::const_iterator r;
- _H << sp << nl << "@interface " << name << "Prx : ICEObjectPrx <" << name << "Prx>";
+ _H << sp << nl << _dllExport << "@interface " << name << "Prx : ICEObjectPrx <" << name << "Prx>";
_H << nl << "+(NSString *) ice_staticId;";
_M << sp << nl << "@implementation " << name << "Prx";
diff --git a/cpp/src/slice2objc/Gen.h b/cpp/src/slice2objc/Gen.h
index ef9557127cb..4cff82707d5 100644
--- a/cpp/src/slice2objc/Gen.h
+++ b/cpp/src/slice2objc/Gen.h
@@ -20,7 +20,7 @@ class ObjCVisitor : public ObjCGenerator, public ParserVisitor
{
public:
- ObjCVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&);
+ ObjCVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&, const std::string&);
virtual ~ObjCVisitor();
protected:
@@ -41,6 +41,7 @@ protected:
::IceUtilInternal::Output& _H;
::IceUtilInternal::Output& _M;
+ std::string _dllExport;
};
class Gen : private ::IceUtil::noncopyable
@@ -51,6 +52,7 @@ public:
const std::string&,
const std::string&,
const std::vector<std::string>&,
+ const std::string&,
const std::string&);
~Gen();
@@ -67,6 +69,7 @@ private:
std::string _base;
std::string _include;
std::vector<std::string> _includePaths;
+ std::string _dllExport;
void printHeader(::IceUtilInternal::Output&);
@@ -74,7 +77,7 @@ private:
{
public:
- UnitVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&);
+ UnitVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&, const std::string&);
virtual bool visitModuleStart(const ModulePtr&);
virtual void visitUnitEnd(const UnitPtr&);
@@ -88,7 +91,7 @@ private:
{
public:
- ObjectDeclVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&);
+ ObjectDeclVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&, const std::string&);
virtual void visitClassDecl(const ClassDeclPtr&);
};
@@ -97,7 +100,7 @@ private:
{
public:
- ProxyDeclVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&);
+ ProxyDeclVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&, const std::string&);
virtual void visitClassDecl(const ClassDeclPtr&);
};
@@ -106,7 +109,7 @@ private:
{
public:
- TypesVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&);
+ TypesVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&, const std::string&);
virtual bool visitModuleStart(const ModulePtr&);
virtual void visitModuleEnd(const ModulePtr&);
@@ -151,7 +154,7 @@ private:
{
public:
- ProxyVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&);
+ ProxyVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&, const std::string&);
virtual bool visitClassDefStart(const ClassDefPtr&);
virtual void visitClassDefEnd(const ClassDefPtr&);
@@ -162,7 +165,7 @@ private:
{
public:
- HelperVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&);
+ HelperVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&, const std::string&);
virtual bool visitClassDefStart(const ClassDefPtr&);
virtual void visitEnum(const EnumPtr&);
@@ -175,7 +178,7 @@ private:
{
public:
- DelegateMVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&);
+ DelegateMVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&, const std::string&);
virtual bool visitModuleStart(const ModulePtr&);
virtual void visitModuleEnd(const ModulePtr&);
diff --git a/cpp/src/slice2objc/Main.cpp b/cpp/src/slice2objc/Main.cpp
index 4c19bf88523..91843743c3d 100644
--- a/cpp/src/slice2objc/Main.cpp
+++ b/cpp/src/slice2objc/Main.cpp
@@ -67,6 +67,7 @@ usage(const char* n)
"-E Print preprocessor output on stdout.\n"
"--include-dir DIR Use DIR as the header include directory in source files.\n"
"--output-dir DIR Create files in the directory DIR.\n"
+ "--dll-export SYMBOL Use SYMBOL for DLL exports.\n"
"--depend Generate Makefile dependencies.\n"
"--depend-xml Generate dependencies in XML format.\n"
"-d, --debug Print debug messages.\n"
@@ -88,6 +89,7 @@ main(int argc, char* argv[])
opts.addOpt("E");
opts.addOpt("", "include-dir", IceUtilInternal::Options::NeedArg);
opts.addOpt("", "output-dir", IceUtilInternal::Options::NeedArg);
+ opts.addOpt("", "dll-export", IceUtilInternal::Options::NeedArg);
opts.addOpt("", "depend");
opts.addOpt("", "depend-xml");
opts.addOpt("d", "debug");
@@ -145,6 +147,8 @@ main(int argc, char* argv[])
string output = opts.optArg("output-dir");
+ string dllExport = opts.optArg("dll-export");
+
bool depend = opts.isSet("depend");
bool dependxml = opts.isSet("depend-xml");
@@ -247,7 +251,7 @@ main(int argc, char* argv[])
{
try
{
- Gen gen(argv[0], icecpp->getBaseName(), include, includePaths, output);
+ Gen gen(argv[0], icecpp->getBaseName(), include, includePaths, output, dllExport);
if(!gen)
{
u->destroy();