diff options
author | Bernard Normier <bernard@zeroc.com> | 2016-10-31 15:54:21 -0400 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2016-10-31 15:54:21 -0400 |
commit | 107e03ea13e0eba9c33f120f0d95ac9fefc7dcad (patch) | |
tree | 00191b7ccb83fe436ad61bdbb43b523f431c6698 /cpp/src/slice2java | |
parent | Update 3.7 changelog (diff) | |
download | ice-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/slice2java')
-rw-r--r-- | cpp/src/slice2java/GenCompat.cpp | 534 | ||||
-rw-r--r-- | cpp/src/slice2java/GenCompat.h | 19 | ||||
-rw-r--r-- | cpp/src/slice2java/Main.cpp | 16 |
3 files changed, 274 insertions, 295 deletions
diff --git a/cpp/src/slice2java/GenCompat.cpp b/cpp/src/slice2java/GenCompat.cpp index 205d4093750..43205b19db6 100644 --- a/cpp/src/slice2java/GenCompat.cpp +++ b/cpp/src/slice2java/GenCompat.cpp @@ -2199,10 +2199,11 @@ Slice::JavaCompatVisitor::writeDocCommentParam(Output& out, const OperationPtr& } } -Slice::GenCompat::GenCompat(const string& /*name*/, const string& base, const vector<string>& includePaths, const string& dir) : +Slice::GenCompat::GenCompat(const string& /*name*/, const string& base, const vector<string>& includePaths, const string& dir, bool tie) : _base(base), _includePaths(includePaths), - _dir(dir) + _dir(dir), + _tie(tie) { } @@ -2236,7 +2237,7 @@ Slice::GenCompat::generate(const UnitPtr& p) ProxyVisitor proxyVisitor(_dir); p->visit(&proxyVisitor, false); - DispatcherVisitor dispatcherVisitor(_dir); + DispatcherVisitor dispatcherVisitor(_dir, _tie); p->visit(&dispatcherVisitor, false); AsyncVisitor asyncVisitor(_dir); @@ -2244,13 +2245,6 @@ Slice::GenCompat::generate(const UnitPtr& p) } void -Slice::GenCompat::generateTie(const UnitPtr& p) -{ - TieVisitor tieVisitor(_dir); - p->visit(&tieVisitor, false); -} - -void Slice::GenCompat::generateImpl(const UnitPtr& p) { ImplVisitor implVisitor(_dir); @@ -2461,218 +2455,6 @@ Slice::GenCompat::OpsVisitor::writeOperations(const ClassDefPtr& p, bool noCurre close(); } -Slice::GenCompat::TieVisitor::TieVisitor(const string& dir) : - JavaCompatVisitor(dir) -{ -} - -bool -Slice::GenCompat::TieVisitor::visitClassDefStart(const ClassDefPtr& p) -{ - string name = p->name(); - ClassList bases = p->bases(); - string package = getPackage(p); - string absolute = getAbsolute(p, "", "_", "Tie"); - string opIntfName = "Operations"; - if(p->isLocal()) - { - opIntfName += "NC"; - } - - // - // Don't generate a TIE class for a non-abstract class - // - if(!p->isAbstract()) - { - return false; - } - - open(absolute, p->file()); - - Output& out = output(); - - // - // Generate the TIE class - // - out << sp << nl << "public class " << '_' << name << "Tie"; - if(p->isInterface()) - { - if(p->isLocal()) - { - out << " implements " << fixKwd(name) << ", Ice.TieBase"; - } - else - { - out << " extends " << '_' << name << "Disp implements Ice.TieBase"; - } - } - else - { - out << " extends " << fixKwd(name) << " implements Ice.TieBase"; - } - - out << sb; - - out << sp << nl << "public _" << name << "Tie()"; - out << sb; - out << eb; - - out << sp << nl << "public _" << name << "Tie(" << '_' << name << opIntfName << " delegate)"; - out << sb; - out << nl << "_ice_delegate = delegate;"; - out << eb; - - out << sp << nl << "public java.lang.Object ice_delegate()"; - out << sb; - out << nl << "return _ice_delegate;"; - out << eb; - - out << sp << nl << "public void ice_delegate(java.lang.Object delegate)"; - out << sb; - out << nl << "_ice_delegate = (_" << name << opIntfName << ")delegate;"; - out << eb; - - out << sp << nl << "public boolean equals(java.lang.Object rhs)"; - out << sb; - out << nl << "if(this == rhs)"; - out << sb; - out << nl << "return true;"; - out << eb; - out << nl << "if(!(rhs instanceof " << '_' << name << "Tie))"; - out << sb; - out << nl << "return false;"; - out << eb; - out << sp << nl << "return _ice_delegate.equals(((" << '_' << name << "Tie)rhs)._ice_delegate);"; - out << eb; - - out << sp << nl << "public int hashCode()"; - out << sb; - out << nl << "return _ice_delegate.hashCode();"; - out << eb; - - if(p->isLocal()) - { - out << sp << nl << "public _" << name << "Tie clone()"; - out.inc(); - out << nl << "throws java.lang.CloneNotSupportedException"; - out.dec(); - out << sb; - out << nl << "return (_" << name << "Tie)super.clone();"; - out << eb; - } - - OperationList ops = p->allOperations(); - for(OperationList::iterator r = ops.begin(); r != ops.end(); ++r) - { - ContainerPtr container = (*r)->container(); - ClassDefPtr cl = ClassDefPtr::dynamicCast(container); - const bool hasAMD = cl->hasMetaData("amd") || (*r)->hasMetaData("amd"); - const bool optionalMapping = useOptionalMapping(*r); - - string opName = hasAMD ? (*r)->name() + "_async" : fixKwd((*r)->name()); - - TypePtr ret = (*r)->returnType(); - string retS = typeToString(ret, TypeModeReturn, package, (*r)->getMetaData(), true, - optionalMapping && (*r)->returnIsOptional()); - - vector<string> params; - vector<string> args; - if(hasAMD) - { - params = getParamsAsync((*r), package, true, true); - args = getArgsAsync(*r); - } - else - { - params = getParams((*r), package, false, optionalMapping); - args = getArgs(*r); - } - - string deprecateReason = getDeprecateReason(*r, cl, "operation"); - - out << sp; - if(!deprecateReason.empty()) - { - out << nl << "@Deprecated"; - out << nl << "@SuppressWarnings(\"deprecation\")"; - } - out << nl << "public " << (hasAMD ? string("void") : retS) << ' ' << opName << spar << params; - if(!p->isLocal()) - { - out << "Ice.Current __current"; - } - out << epar; - - if((*r)->hasMetaData("UserException")) - { - out.inc(); - out << nl << "throws Ice.UserException"; - out.dec(); - } - else - { - ExceptionList throws = (*r)->throws(); - throws.sort(); - throws.unique(); - writeThrowsClause(package, throws); - } - out << sb; - out << nl; - if(ret && !hasAMD) - { - out << "return "; - } - out << "_ice_delegate." << opName << spar << args; - if(!p->isLocal()) - { - out << "__current"; - } - out << epar << ';'; - out << eb; - } - - out << sp << nl << "private " << '_' << name << opIntfName << " _ice_delegate;"; - out << sp << nl << "public static final long serialVersionUID = "; - string serialVersionUID; - if(p->findMetaData("java:serialVersionUID", serialVersionUID)) - { - string::size_type pos = serialVersionUID.rfind(":") + 1; - if(pos == string::npos) - { - ostringstream os; - os << "ignoring invalid serialVersionUID for class `" << p->scoped() << "'; generating default value"; - emitWarning("", "", os.str()); - out << computeSerialVersionUUID(p); - } - else - { - Int64 v = 0; - serialVersionUID = serialVersionUID.substr(pos); - if(serialVersionUID != "0") - { - if(!stringToInt64(serialVersionUID, v)) // conversion error - { - ostringstream os; - os << "ignoring invalid serialVersionUID for class `" << p->scoped() - << "'; generating default value"; - emitWarning("", "", os.str()); - out << computeSerialVersionUUID(p); - } - } - out << v; - } - } - else - { - out << computeSerialVersionUUID(p); - } - out << "L;"; - out << eb; - close(); - - return false; -} - Slice::GenCompat::PackageVisitor::PackageVisitor(const string& dir) : JavaCompatVisitor(dir) { @@ -2770,7 +2552,7 @@ Slice::GenCompat::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) out << "class " << fixKwd(name); out.useCurrentPosAsIndent(); - StringList implements; + StringList implements; bool implementsOnNewLine = true; if(bases.empty() || bases.front()->isInterface()) @@ -2778,7 +2560,7 @@ Slice::GenCompat::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) if(p->isLocal()) { implementsOnNewLine = false; - implements.push_back("java.lang.Cloneable"); + implements.push_back("java.lang.Cloneable"); } else { @@ -3134,28 +2916,28 @@ Slice::GenCompat::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) if(!p->isInterface()) { - out << sp << nl << "public " << name << nl << "clone()"; - out << sb; - - if(p->isLocal() && !baseClass) - { - out << nl << name << " c = null;"; - out << nl << "try"; - out << sb; - out << nl << "c = (" << name << ")super.clone();"; - out << eb; - out << nl << "catch(CloneNotSupportedException ex)"; - out << sb; - out << nl << "assert false; // impossible"; - out << eb; - out << nl << "return c;"; - - } - else - { - out << nl << "return (" << name << ")super.clone();"; - } - out << eb; + out << sp << nl << "public " << name << nl << "clone()"; + out << sb; + + if(p->isLocal() && !baseClass) + { + out << nl << name << " c = null;"; + out << nl << "try"; + out << sb; + out << nl << "c = (" << name << ")super.clone();"; + out << eb; + out << nl << "catch(CloneNotSupportedException ex)"; + out << sb; + out << nl << "assert false; // impossible"; + out << eb; + out << nl << "return c;"; + + } + else + { + out << nl << "return (" << name << ")super.clone();"; + } + out << eb; } if(p->isInterface() && !p->isLocal()) @@ -3566,7 +3348,7 @@ Slice::GenCompat::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) if(p->usesClasses(false)) { - if(!base || (base && !base->usesClasses(false))) + if(!base || (base && !base->usesClasses(false))) { out << sp << nl << "public boolean" << nl << "__usesClasses()"; out << sb; @@ -5752,48 +5534,252 @@ Slice::GenCompat::ProxyVisitor::visitOperation(const OperationPtr& p) } } -Slice::GenCompat::DispatcherVisitor::DispatcherVisitor(const string& dir) : - JavaCompatVisitor(dir) +Slice::GenCompat::DispatcherVisitor::DispatcherVisitor(const string& dir, bool tie) : + JavaCompatVisitor(dir), + _tie(tie) { } bool Slice::GenCompat::DispatcherVisitor::visitClassDefStart(const ClassDefPtr& p) { - if(p->isLocal() || !p->isInterface()) + string name = p->name(); + ClassList bases = p->bases(); + + if(!p->isLocal() && p->isInterface()) { - return false; + string absolute = getAbsolute(p, "", "_", "Disp"); + + open(absolute, p->file()); + + Output& out = output(); + + out << sp; + writeDocComment(out, p, getDeprecateReason(p, 0, p->isInterface() ? "interface" : "class")); + out << nl << "public abstract class _" << name << "Disp extends Ice.ObjectImpl implements " << fixKwd(name); + out << sb; + + out << sp << nl << "protected void" << nl << "ice_copyStateFrom(Ice.Object __obj)"; + out.inc(); + out << nl << "throws java.lang.CloneNotSupportedException"; + out.dec(); + out << sb; + out << nl << "throw new java.lang.CloneNotSupportedException();"; + out << eb; + + writeDispatchAndMarshalling(out, p); + + // + // Avoid serialVersionUID warnings for dispatch classes. + // + out << sp << nl << "public static final long serialVersionUID = 0L;"; + out << eb; + close(); } - string name = p->name(); - ClassList bases = p->bases(); - string absolute = getAbsolute(p, "", "_", "Disp"); + if(_tie || p->hasMetaData("java:tie")) + { + // Tie class - open(absolute, p->file()); + string package = getPackage(p); + string absolute = getAbsolute(p, "", "_", "Tie"); + string opIntfName = "Operations"; + if(p->isLocal()) + { + opIntfName += "NC"; + } - Output& out = output(); + // + // Don't generate a tie class for a non-abstract class + // + if(!p->isAbstract()) + { + return false; + } - out << sp; - writeDocComment(out, p, getDeprecateReason(p, 0, p->isInterface() ? "interface" : "class")); - out << nl << "public abstract class _" << name << "Disp extends Ice.ObjectImpl implements " << fixKwd(name); - out << sb; + open(absolute, p->file()); - out << sp << nl << "protected void" << nl << "ice_copyStateFrom(Ice.Object __obj)"; - out.inc(); - out << nl << "throws java.lang.CloneNotSupportedException"; - out.dec(); - out << sb; - out << nl << "throw new java.lang.CloneNotSupportedException();"; - out << eb; + Output& out = output(); + + // + // Generate the tie class + // + out << sp << nl << "public class " << '_' << name << "Tie"; + if(p->isInterface()) + { + if(p->isLocal()) + { + out << " implements " << fixKwd(name) << ", Ice.TieBase"; + } + else + { + out << " extends " << '_' << name << "Disp implements Ice.TieBase"; + } + } + else + { + out << " extends " << fixKwd(name) << " implements Ice.TieBase"; + } - writeDispatchAndMarshalling(out, p); + out << sb; - // - // Avoid serialVersionUID warnings for dispatch classes. - // - out << sp << nl << "public static final long serialVersionUID = 0L;"; - out << eb; - close(); + out << sp << nl << "public _" << name << "Tie()"; + out << sb; + out << eb; + + out << sp << nl << "public _" << name << "Tie(" << '_' << name << opIntfName << " delegate)"; + out << sb; + out << nl << "_ice_delegate = delegate;"; + out << eb; + + out << sp << nl << "public java.lang.Object ice_delegate()"; + out << sb; + out << nl << "return _ice_delegate;"; + out << eb; + + out << sp << nl << "public void ice_delegate(java.lang.Object delegate)"; + out << sb; + out << nl << "_ice_delegate = (_" << name << opIntfName << ")delegate;"; + out << eb; + + out << sp << nl << "public boolean equals(java.lang.Object rhs)"; + out << sb; + out << nl << "if(this == rhs)"; + out << sb; + out << nl << "return true;"; + out << eb; + out << nl << "if(!(rhs instanceof " << '_' << name << "Tie))"; + out << sb; + out << nl << "return false;"; + out << eb; + out << sp << nl << "return _ice_delegate.equals(((" << '_' << name << "Tie)rhs)._ice_delegate);"; + out << eb; + + out << sp << nl << "public int hashCode()"; + out << sb; + out << nl << "return _ice_delegate.hashCode();"; + out << eb; + + if(p->isLocal()) + { + out << sp << nl << "public _" << name << "Tie clone()"; + out.inc(); + out << nl << "throws java.lang.CloneNotSupportedException"; + out.dec(); + out << sb; + out << nl << "return (_" << name << "Tie)super.clone();"; + out << eb; + } + + OperationList ops = p->allOperations(); + for(OperationList::iterator r = ops.begin(); r != ops.end(); ++r) + { + ContainerPtr container = (*r)->container(); + ClassDefPtr cl = ClassDefPtr::dynamicCast(container); + const bool hasAMD = cl->hasMetaData("amd") || (*r)->hasMetaData("amd"); + const bool optionalMapping = useOptionalMapping(*r); + + string opName = hasAMD ? (*r)->name() + "_async" : fixKwd((*r)->name()); + + TypePtr ret = (*r)->returnType(); + string retS = typeToString(ret, TypeModeReturn, package, (*r)->getMetaData(), true, + optionalMapping && (*r)->returnIsOptional()); + + vector<string> params; + vector<string> args; + if(hasAMD) + { + params = getParamsAsync((*r), package, true, true); + args = getArgsAsync(*r); + } + else + { + params = getParams((*r), package, false, optionalMapping); + args = getArgs(*r); + } + + string deprecateReason = getDeprecateReason(*r, cl, "operation"); + + out << sp; + if(!deprecateReason.empty()) + { + out << nl << "@Deprecated"; + out << nl << "@SuppressWarnings(\"deprecation\")"; + } + out << nl << "public " << (hasAMD ? string("void") : retS) << ' ' << opName << spar << params; + if(!p->isLocal()) + { + out << "Ice.Current __current"; + } + out << epar; + + if((*r)->hasMetaData("UserException")) + { + out.inc(); + out << nl << "throws Ice.UserException"; + out.dec(); + } + else + { + ExceptionList throws = (*r)->throws(); + throws.sort(); + throws.unique(); + writeThrowsClause(package, throws); + } + out << sb; + out << nl; + if(ret && !hasAMD) + { + out << "return "; + } + out << "_ice_delegate." << opName << spar << args; + if(!p->isLocal()) + { + out << "__current"; + } + out << epar << ';'; + out << eb; + } + + out << sp << nl << "private " << '_' << name << opIntfName << " _ice_delegate;"; + out << sp << nl << "public static final long serialVersionUID = "; + string serialVersionUID; + if(p->findMetaData("java:serialVersionUID", serialVersionUID)) + { + string::size_type pos = serialVersionUID.rfind(":") + 1; + if(pos == string::npos) + { + ostringstream os; + os << "ignoring invalid serialVersionUID for class `" << p->scoped() << "'; generating default value"; + emitWarning("", "", os.str()); + out << computeSerialVersionUUID(p); + } + else + { + Int64 v = 0; + serialVersionUID = serialVersionUID.substr(pos); + if(serialVersionUID != "0") + { + if(!stringToInt64(serialVersionUID, v)) // conversion error + { + ostringstream os; + os << "ignoring invalid serialVersionUID for class `" << p->scoped() + << "'; generating default value"; + emitWarning("", "", os.str()); + out << computeSerialVersionUUID(p); + } + } + out << v; + } + } + else + { + out << computeSerialVersionUUID(p); + } + out << "L;"; + out << eb; + close(); + } return false; } diff --git a/cpp/src/slice2java/GenCompat.h b/cpp/src/slice2java/GenCompat.h index c03d491f380..a55841a43c9 100644 --- a/cpp/src/slice2java/GenCompat.h +++ b/cpp/src/slice2java/GenCompat.h @@ -127,11 +127,11 @@ public: GenCompat(const std::string&, const std::string&, const std::vector<std::string>&, - const std::string&); + const std::string&, + bool); ~GenCompat(); void generate(const UnitPtr&); - void generateTie(const UnitPtr&); void generateImpl(const UnitPtr&); void generateImplTie(const UnitPtr&); @@ -142,6 +142,7 @@ private: std::string _base; std::vector<std::string> _includePaths; std::string _dir; + bool _tie; class OpsVisitor : public JavaCompatVisitor { @@ -155,15 +156,6 @@ private: void writeOperations(const ClassDefPtr&, bool); }; - class TieVisitor : public JavaCompatVisitor - { - public: - - TieVisitor(const std::string&); - - virtual bool visitClassDefStart(const ClassDefPtr&); - }; - class PackageVisitor : public JavaCompatVisitor { public: @@ -253,9 +245,12 @@ private: { public: - DispatcherVisitor(const std::string&); + DispatcherVisitor(const std::string&, bool); virtual bool visitClassDefStart(const ClassDefPtr&); + + private: + bool _tie; }; class BaseImplVisitor : public JavaCompatVisitor diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp index d864279a544..80fec0c32a0 100644 --- a/cpp/src/slice2java/Main.cpp +++ b/cpp/src/slice2java/Main.cpp @@ -70,19 +70,21 @@ 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" "--list-generated Emit list of generated files in XML format.\n" "-d, --debug Print debug messages.\n" - "--ice Allow reserved Ice prefix in Slice identifiers.\n" - "--underscore Allow underscores in Slice identifiers.\n" "--checksum CLASS Generate checksums for Slice definitions into CLASS.\n" "--meta META Define global metadata directive META.\n" "--compat Use the backward-compatible language mapping.\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" ; } @@ -363,12 +365,8 @@ compile(const vector<string>& argv) { if(compat) { - GenCompat gen(argv[0], icecpp->getBaseName(), includePaths, output); + GenCompat gen(argv[0], icecpp->getBaseName(), includePaths, output, tie); gen.generate(p); - if(tie) - { - gen.generateTie(p); - } if(impl) { gen.generateImpl(p); |