summaryrefslogtreecommitdiff
path: root/cpp/src/slice2cs
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2016-10-31 15:54:21 -0400
committerBernard Normier <bernard@zeroc.com>2016-10-31 15:54:21 -0400
commit107e03ea13e0eba9c33f120f0d95ac9fefc7dcad (patch)
tree00191b7ccb83fe436ad61bdbb43b523f431c6698 /cpp/src/slice2cs
parentUpdate 3.7 changelog (diff)
downloadice-107e03ea13e0eba9c33f120f0d95ac9fefc7dcad.tar.bz2
ice-107e03ea13e0eba9c33f120f0d95ac9fefc7dcad.tar.xz
ice-107e03ea13e0eba9c33f120f0d95ac9fefc7dcad.zip
Replaced slice compiler options --ice, --underscore and --dll-export by
global metadata directives (ice-prefix, underscore, cpp:dll-export:SYMBOL and objc:dll-export:SYMBOL) Added new cs:tie and java:tie metadata
Diffstat (limited to 'cpp/src/slice2cs')
-rw-r--r--cpp/src/slice2cs/CsUtil.cpp5
-rw-r--r--cpp/src/slice2cs/Gen.cpp155
-rw-r--r--cpp/src/slice2cs/Gen.h21
-rw-r--r--cpp/src/slice2cs/Main.cpp16
4 files changed, 77 insertions, 120 deletions
diff --git a/cpp/src/slice2cs/CsUtil.cpp b/cpp/src/slice2cs/CsUtil.cpp
index 83aabc950d5..3487cde3fce 100644
--- a/cpp/src/slice2cs/CsUtil.cpp
+++ b/cpp/src/slice2cs/CsUtil.cpp
@@ -2531,10 +2531,15 @@ Slice::CsGenerator::MetaDataVisitor::validate(const ContainedPtr& cont)
if(s.find(prefix) == 0)
{
static const string csAttributePrefix = prefix + "attribute:";
+ static const string csTie = prefix + "tie";
if(s.find(csAttributePrefix) == 0 && s.size() > csAttributePrefix.size())
{
continue;
}
+ else if(s.find(csTie) == 0 && s.size() == csTie.size())
+ {
+ continue;
+ }
emitWarning(cont->file(), cont->line(), msg + " `" + s + "'");
_history.insert(s);
}
diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp
index 1fe547582ab..9122c83a68b 100644
--- a/cpp/src/slice2cs/Gen.cpp
+++ b/cpp/src/slice2cs/Gen.cpp
@@ -1984,7 +1984,9 @@ Slice::CsVisitor::writeDocCommentParam(const OperationPtr& p, ParamDir paramType
}
Slice::Gen::Gen(const string& base, const vector<string>& includePaths, const string& dir,
- bool impl, bool implTie) : _includePaths(includePaths)
+ bool tie, bool impl, bool implTie) :
+ _includePaths(includePaths),
+ _tie(tie)
{
string fileBase = base;
string::size_type pos = base.find_last_of("/\\");
@@ -2084,18 +2086,11 @@ Slice::Gen::generate(const UnitPtr& p)
HelperVisitor helperVisitor(_out);
p->visit(&helperVisitor, false);
- DispatcherVisitor dispatcherVisitor(_out);
+ DispatcherVisitor dispatcherVisitor(_out, _tie);
p->visit(&dispatcherVisitor, false);
}
void
-Slice::Gen::generateTie(const UnitPtr& p)
-{
- TieVisitor tieVisitor(_out);
- p->visit(&tieVisitor, false);
-}
-
-void
Slice::Gen::generateImpl(const UnitPtr& p)
{
ImplVisitor implVisitor(_impl);
@@ -5149,8 +5144,9 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p)
_out << eb;
}
-Slice::Gen::DispatcherVisitor::DispatcherVisitor(::IceUtilInternal::Output &out)
- : CsVisitor(out)
+Slice::Gen::DispatcherVisitor::DispatcherVisitor(::IceUtilInternal::Output& out, bool tie) :
+ CsVisitor(out),
+ _tie(tie)
{
}
@@ -5241,113 +5237,80 @@ Slice::Gen::DispatcherVisitor::visitClassDefStart(const ClassDefPtr& p)
}
writeInheritedOperations(p);
-
writeDispatch(p);
- _out << eb;
-
- return true;
-}
-
-Slice::Gen::TieVisitor::TieVisitor(IceUtilInternal::Output& out)
- : CsVisitor(out)
-{
-}
-
-bool
-Slice::Gen::TieVisitor::visitModuleStart(const ModulePtr& p)
-{
- if(!p->hasClassDefs())
+ if((_tie || p->hasMetaData("cs:tie")) && !p->isLocal() && p->isAbstract())
{
- return false;
- }
-
- _out << sp << nl << "namespace " << fixId(p->name());
- _out << sb;
+ // Need to generate tie
- return true;
-}
-
-void
-Slice::Gen::TieVisitor::visitModuleEnd(const ModulePtr&)
-{
- _out << eb;
-}
-
-bool
-Slice::Gen::TieVisitor::visitClassDefStart(const ClassDefPtr& p)
-{
- if(p->isLocal() || !p->isAbstract())
- {
- return false;
- }
+ // close previous class
+ _out << eb;
- string name = p->name();
- string opIntfName = "Operations";
+ string opIntfName = "Operations";
- _out << sp;
- emitComVisibleAttribute();
- emitGeneratedCodeAttribute();
- _out << nl << "public class " << name << "Tie_ : " << name << "Disp_, Ice.TieBase";
+ _out << sp;
+ emitComVisibleAttribute();
+ emitGeneratedCodeAttribute();
+ _out << nl << "public class " << name << "Tie_ : " << name << "Disp_, Ice.TieBase";
- _out << sb;
+ _out << sb;
- _out << sp << nl << "public " << name << "Tie_()";
- _out << sb;
- _out << eb;
+ _out << sp << nl << "public " << name << "Tie_()";
+ _out << sb;
+ _out << eb;
- _out << sp << nl << "public " << name << "Tie_(" << name << opIntfName << "_ del)";
- _out << sb;
- _out << nl << "_ice_delegate = del;";
- _out << eb;
+ _out << sp << nl << "public " << name << "Tie_(" << name << opIntfName << "_ del)";
+ _out << sb;
+ _out << nl << "_ice_delegate = del;";
+ _out << eb;
- _out << sp << nl << "public object ice_delegate()";
- _out << sb;
- _out << nl << "return _ice_delegate;";
- _out << eb;
+ _out << sp << nl << "public object ice_delegate()";
+ _out << sb;
+ _out << nl << "return _ice_delegate;";
+ _out << eb;
- _out << sp << nl << "public void ice_delegate(object del)";
- _out << sb;
- _out << nl << "_ice_delegate = (" << name << opIntfName << "_)del;";
- _out << eb;
+ _out << sp << nl << "public void ice_delegate(object del)";
+ _out << sb;
+ _out << nl << "_ice_delegate = (" << name << opIntfName << "_)del;";
+ _out << eb;
- _out << sp << nl << "public override int GetHashCode()";
- _out << sb;
- _out << nl << "return _ice_delegate == null ? 0 : _ice_delegate.GetHashCode();";
- _out << eb;
+ _out << sp << nl << "public override int GetHashCode()";
+ _out << sb;
+ _out << nl << "return _ice_delegate == null ? 0 : _ice_delegate.GetHashCode();";
+ _out << eb;
- _out << sp << nl << "public override bool Equals(object rhs)";
- _out << sb;
- _out << nl << "if(object.ReferenceEquals(this, rhs))";
- _out << sb;
- _out << nl << "return true;";
- _out << eb;
- _out << nl << "if(!(rhs is " << name << "Tie_))";
- _out << sb;
- _out << nl << "return false;";
- _out << eb;
- _out << nl << "if(_ice_delegate == null)";
- _out << sb;
- _out << nl << "return ((" << name << "Tie_)rhs)._ice_delegate == null;";
- _out << eb;
- _out << nl << "return _ice_delegate.Equals(((" << name << "Tie_)rhs)._ice_delegate);";
- _out << eb;
+ _out << sp << nl << "public override bool Equals(object rhs)";
+ _out << sb;
+ _out << nl << "if(object.ReferenceEquals(this, rhs))";
+ _out << sb;
+ _out << nl << "return true;";
+ _out << eb;
+ _out << nl << "if(!(rhs is " << name << "Tie_))";
+ _out << sb;
+ _out << nl << "return false;";
+ _out << eb;
+ _out << nl << "if(_ice_delegate == null)";
+ _out << sb;
+ _out << nl << "return ((" << name << "Tie_)rhs)._ice_delegate == null;";
+ _out << eb;
+ _out << nl << "return _ice_delegate.Equals(((" << name << "Tie_)rhs)._ice_delegate);";
+ _out << eb;
- writeOperations(p);
+ writeTieOperations(p);
- _out << sp << nl << "private " << name << opIntfName << "_ _ice_delegate;";
+ _out << sp << nl << "private " << name << opIntfName << "_ _ice_delegate;";
+ }
return true;
}
-
void
-Slice::Gen::TieVisitor::visitClassDefEnd(const ClassDefPtr&)
+Slice::Gen::DispatcherVisitor::visitClassDefEnd(const ClassDefPtr&)
{
_out << eb;
}
void
-Slice::Gen::TieVisitor::writeOperations(const ClassDefPtr& p, NameSet* opNames)
+Slice::Gen::DispatcherVisitor::writeTieOperations(const ClassDefPtr& p, NameSet* opNames)
{
OperationList ops = p->operations();
for(OperationList::const_iterator r = ops.begin(); r != ops.end(); ++r)
@@ -5382,7 +5345,7 @@ Slice::Gen::TieVisitor::writeOperations(const ClassDefPtr& p, NameSet* opNames)
ClassList bases = p->bases();
for(ClassList::const_iterator i = bases.begin(); i != bases.end(); ++i)
{
- writeOperations(*i, &opNames);
+ writeTieOperations(*i, &opNames);
}
}
else
@@ -5390,7 +5353,7 @@ Slice::Gen::TieVisitor::writeOperations(const ClassDefPtr& p, NameSet* opNames)
ClassList bases = p->bases();
for(ClassList::const_iterator i = bases.begin(); i != bases.end(); ++i)
{
- writeOperations(*i, opNames);
+ writeTieOperations(*i, opNames);
}
}
}
diff --git a/cpp/src/slice2cs/Gen.h b/cpp/src/slice2cs/Gen.h
index 230c0fd5942..1b3096d415e 100644
--- a/cpp/src/slice2cs/Gen.h
+++ b/cpp/src/slice2cs/Gen.h
@@ -85,11 +85,11 @@ public:
const std::vector<std::string>&,
const std::string&,
bool,
+ bool,
bool);
~Gen();
void generate(const UnitPtr&);
- void generateTie(const UnitPtr&);
void generateImpl(const UnitPtr&);
void generateImplTie(const UnitPtr&);
void generateChecksums(const UnitPtr&);
@@ -99,8 +99,8 @@ private:
IceUtilInternal::Output _out;
IceUtilInternal::Output _impl;
-
std::vector<std::string> _includePaths;
+ bool _tie;
void printHeader();
@@ -219,18 +219,7 @@ private:
{
public:
- DispatcherVisitor(::IceUtilInternal::Output&);
-
- virtual bool visitModuleStart(const ModulePtr&);
- virtual void visitModuleEnd(const ModulePtr&);
- virtual bool visitClassDefStart(const ClassDefPtr&);
- };
-
- class TieVisitor : public CsVisitor
- {
- public:
-
- TieVisitor(::IceUtilInternal::Output&);
+ DispatcherVisitor(::IceUtilInternal::Output&, bool);
virtual bool visitModuleStart(const ModulePtr&);
virtual void visitModuleEnd(const ModulePtr&);
@@ -240,7 +229,9 @@ private:
private:
typedef std::set<std::string> NameSet;
- void writeOperations(const ClassDefPtr&, NameSet* = 0);
+ void writeTieOperations(const ClassDefPtr&, NameSet* = 0);
+
+ bool _tie;
};
class BaseImplVisitor : public CsVisitor
diff --git a/cpp/src/slice2cs/Main.cpp b/cpp/src/slice2cs/Main.cpp
index 2268eb1fa0a..e9a18c20d6a 100644
--- a/cpp/src/slice2cs/Main.cpp
+++ b/cpp/src/slice2cs/Main.cpp
@@ -68,16 +68,18 @@ usage(const string& n)
"-IDIR Put DIR in the include file search path.\n"
"-E Print preprocessor output on stdout.\n"
"--output-dir DIR Create files in the directory DIR.\n"
- "--tie Generate TIE classes.\n"
+ "--tie Generate tie classes.\n"
"--impl Generate sample implementations.\n"
- "--impl-tie Generate sample TIE implementations.\n"
+ "--impl-tie Generate sample tie implementations.\n"
"--depend Generate Makefile dependencies.\n"
"--depend-xml Generate dependencies in XML format.\n"
"--depend-file FILE Write dependencies to FILE instead of standard output.\n"
"-d, --debug Print debug messages.\n"
- "--ice Allow reserved Ice prefix in Slice identifiers.\n"
- "--underscore Allow underscores in Slice identifiers.\n"
"--checksum Generate checksums for Slice definitions.\n"
+ "--ice Allow reserved Ice prefix in Slice identifiers\n"
+ " deprecated: use instead [[\"ice-prefix\"]] metadata.\n"
+ "--underscore Allow underscores in Slice identifiers\n"
+ " deprecated: use instead [[\"underscore\"]] metadata.\n"
;
}
@@ -309,12 +311,8 @@ compile(const vector<string>& argv)
{
try
{
- Gen gen(icecpp->getBaseName(), includePaths, output, impl, implTie);
+ Gen gen(icecpp->getBaseName(), includePaths, output, tie, impl, implTie);
gen.generate(p);
- if(tie)
- {
- gen.generateTie(p);
- }
if(impl)
{
gen.generateImpl(p);