From 966061fcb0e2ec4d5d7ed9c6c280eefb27209da7 Mon Sep 17 00:00:00 2001 From: Benoit Foucher Date: Fri, 6 Jun 2008 11:39:41 +0200 Subject: Removed Ice-E --- cpp/src/slice2cppe/.depend | 2 - cpp/src/slice2cppe/Gen.cpp | 3081 ---------------------------------- cpp/src/slice2cppe/Gen.h | 307 ---- cpp/src/slice2cppe/Main.cpp | 209 --- cpp/src/slice2cppe/Makefile | 32 - cpp/src/slice2cppe/Makefile.mak | 61 - cpp/src/slice2cppe/Slice2CppE.rc | 34 - cpp/src/slice2javae/.depend | 2 - cpp/src/slice2javae/Gen.cpp | 3184 ------------------------------------ cpp/src/slice2javae/Gen.h | 236 --- cpp/src/slice2javae/Main.cpp | 216 --- cpp/src/slice2javae/Makefile | 32 - cpp/src/slice2javae/Makefile.mak | 61 - cpp/src/slice2javae/Slice2JavaE.rc | 34 - 14 files changed, 7491 deletions(-) delete mode 100644 cpp/src/slice2cppe/.depend delete mode 100644 cpp/src/slice2cppe/Gen.cpp delete mode 100644 cpp/src/slice2cppe/Gen.h delete mode 100644 cpp/src/slice2cppe/Main.cpp delete mode 100644 cpp/src/slice2cppe/Makefile delete mode 100644 cpp/src/slice2cppe/Makefile.mak delete mode 100644 cpp/src/slice2cppe/Slice2CppE.rc delete mode 100644 cpp/src/slice2javae/.depend delete mode 100644 cpp/src/slice2javae/Gen.cpp delete mode 100644 cpp/src/slice2javae/Gen.h delete mode 100644 cpp/src/slice2javae/Main.cpp delete mode 100644 cpp/src/slice2javae/Makefile delete mode 100644 cpp/src/slice2javae/Makefile.mak delete mode 100644 cpp/src/slice2javae/Slice2JavaE.rc (limited to 'cpp/src') diff --git a/cpp/src/slice2cppe/.depend b/cpp/src/slice2cppe/.depend deleted file mode 100644 index e2d738a37c1..00000000000 --- a/cpp/src/slice2cppe/.depend +++ /dev/null @@ -1,2 +0,0 @@ -Gen$(OBJEXT): Gen.cpp ./Gen.h $(includedir)/Slice/Parser.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/IceUtil/OutputUtil.h $(includedir)/Slice/CPlusPlusUtil.h $(includedir)/Slice/SignalHandler.h $(includedir)/IceUtil/Functional.h $(includedir)/IceUtil/Iterator.h -Main$(OBJEXT): Main.cpp $(includedir)/IceUtil/Options.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/RecMutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Exception.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Handle.h $(includedir)/Slice/Preprocessor.h $(includedir)/Slice/SignalHandler.h ./Gen.h $(includedir)/Slice/Parser.h $(includedir)/IceUtil/OutputUtil.h diff --git a/cpp/src/slice2cppe/Gen.cpp b/cpp/src/slice2cppe/Gen.cpp deleted file mode 100644 index 8baa671d1e6..00000000000 --- a/cpp/src/slice2cppe/Gen.cpp +++ /dev/null @@ -1,3081 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -#include -#include -#include -#include -#include -#include - -#include -#include - -using namespace std; -using namespace Slice; -using namespace IceUtil; -using namespace IceUtilInternal; - -// -// Callback for Crtl-C signal handling -// -static Gen* _gen = 0; - -static void closeCallback() -{ - if(_gen != 0) - { - _gen->closeOutput(); - } -} - -static void -getIds(const ClassDefPtr& p, StringList& ids) -{ - ClassList allBases = p->allBases(); -#if defined(__IBMCPP__) && defined(NDEBUG) -// -// VisualAge C++ 6.0 does not see that ClassDef is a Contained, -// when inlining is on. The code below issues a warning: better -// than an error! -// - transform(allBases.begin(), allBases.end(), back_inserter(ids), ::IceUtil::constMemFun(&Contained::scoped)); -#else - transform(allBases.begin(), allBases.end(), back_inserter(ids), ::IceUtil::constMemFun(&Contained::scoped)); -#endif - StringList other; - other.push_back(p->scoped()); - other.push_back("::Ice::Object"); - other.sort(); - ids.merge(other); - ids.unique(); -} - -static string -getDeprecateSymbol(const ContainedPtr& p1, const ContainedPtr& p2) -{ - string deprecateMetadata, deprecateSymbol; - if(p1->findMetaData("deprecate", deprecateMetadata) || - (p2 != 0 && p2->findMetaData("deprecate", deprecateMetadata))) - { - deprecateSymbol = "ICE_DEPRECATED_API "; - } - return deprecateSymbol; -} - -Slice::Gen::Gen(const string& name, const string& base, const string& headerExtension, - const string& sourceExtension, const vector& extraHeaders, const string& include, - const vector& includePaths, const string& dllExport, const string& dir, bool imp, - bool ice) : - _base(base), - _headerExtension(headerExtension), - _sourceExtension(sourceExtension), - _extraHeaders(extraHeaders), - _include(include), - _includePaths(includePaths), - _dllExport(dllExport), - _impl(imp), - _ice(ice) -{ - _gen = this; - SignalHandler::setCallback(closeCallback); - - Slice::featureProfile = Slice::IceE; - - for(vector::iterator p = _includePaths.begin(); p != _includePaths.end(); ++p) - { - *p = fullPath(*p); - } - - string::size_type pos = _base.find_last_of("/\\"); - if(pos != string::npos) - { - _base.erase(0, pos + 1); - } - - if(_impl) - { - string fileImplH = _base + "I." + _headerExtension; - string fileImplC = _base + "I." + _sourceExtension; - if(!dir.empty()) - { - fileImplH = dir + '/' + fileImplH; - fileImplC = dir + '/' + fileImplC; - } - SignalHandler::addFile(fileImplH); - SignalHandler::addFile(fileImplC); - - struct stat st; - if(stat(fileImplH.c_str(), &st) == 0) - { - cerr << name << ": `" << fileImplH << "' already exists - will not overwrite" << endl; - return; - } - if(stat(fileImplC.c_str(), &st) == 0) - { - cerr << name << ": `" << fileImplC << "' already exists - will not overwrite" << endl; - return; - } - - implH.open(fileImplH.c_str()); - if(!implH) - { - cerr << name << ": can't open `" << fileImplH << "' for writing" << endl; - return; - } - - implC.open(fileImplC.c_str()); - if(!implC) - { - cerr << name << ": can't open `" << fileImplC << "' for writing" << endl; - return; - } - - string s = fileImplH; - if(_include.size()) - { - s = _include + '/' + s; - } - transform(s.begin(), s.end(), s.begin(), ToIfdef()); - implH << "#ifndef __" << s << "__"; - implH << "\n#define __" << s << "__"; - implH << '\n'; - } - - string fileH = _base + "." + _headerExtension; - string fileC = _base + "." + _sourceExtension; - if(!dir.empty()) - { - fileH = dir + '/' + fileH; - fileC = dir + '/' + fileC; - } - SignalHandler::addFile(fileH); - SignalHandler::addFile(fileC); - - H.open(fileH.c_str()); - if(!H) - { - cerr << name << ": can't open `" << fileH << "' for writing" << endl; - return; - } - - C.open(fileC.c_str()); - if(!C) - { - cerr << name << ": can't open `" << fileC << "' for writing" << endl; - return; - } - - printHeader(H); - printHeader(C); - H << "\n// Generated from file `" << changeInclude(_base, _includePaths) << ".ice'\n"; - C << "\n// Generated from file `" << changeInclude(_base, _includePaths) << ".ice'\n"; - - string s = fileH; - if(_include.size()) - { - s = _include + '/' + s; - } - transform(s.begin(), s.end(), s.begin(), ToIfdef()); - H << "\n#ifndef __" << s << "__"; - H << "\n#define __" << s << "__"; - H << '\n'; -} - -Slice::Gen::~Gen() -{ - H << "\n\n#endif\n"; - C << '\n'; - - if(_impl) - { - implH << "\n\n#endif\n"; - implC << '\n'; - } - - SignalHandler::setCallback(0); -} - -bool -Slice::Gen::operator!() const -{ - if(!H || !C) - { - return true; - } - if(_impl && (!implH || !implC)) - { - return true; - } - return false; -} - -void -Slice::Gen::generate(const UnitPtr& p) -{ - validateMetaData(p); - - writeExtraHeaders(C); - - C << "\n#include <"; - if(_include.size()) - { - C << _include << '/'; - } - C << _base << "." << _headerExtension << ">"; - - H << "\n#include "; - H << "\n#ifndef ICEE_PURE_CLIENT"; - H << "\n# include "; - H << "\n#endif"; - H << "\n#include "; - H << "\n#include "; - - if(p->usesProxies()) - { - H << "\n#include "; - } - - if(p->hasNonLocalClassDefs()) - { - H << "\n#ifndef ICEE_PURE_CLIENT"; - H << "\n# include "; - H << "\n# include "; - H << "\n#endif"; - H << "\n#include "; - C << "\n#include "; - C << "\n#include "; - } - else if(p->hasNonLocalClassDecls()) - { - H << "\n#ifndef ICEE_PURE_CLIENT"; - H << "\n# include "; - H << "\n#endif"; - } - - if(p->hasNonLocalExceptions()) - { - H << "\n#include "; - } - - if(p->hasDataOnlyClasses() || p->hasNonLocalExceptions()) - { - H << "\n#include "; - } - - if(p->usesNonLocals()) - { - C << "\n#include "; - - if(!p->hasNonLocalClassDefs() && !p->hasNonLocalClassDecls()) - { - C << "\n#ifndef ICEE_PURE_CLIENT"; - C << "\n# include "; - C << "\n#endif"; - } - } - - if(p->hasNonLocalExceptions()) - { - C << "\n#include "; - } - - C << "\n#include "; - - StringList includes = p->includeFiles(); - - for(StringList::const_iterator q = includes.begin(); q != includes.end(); ++q) - { - H << "\n#include <" << changeInclude(*q, _includePaths) << "." << _headerExtension << ">"; - } - - H << "\n#include "; - - if(_ice) - { - C << "\n#include "; - } - - GlobalIncludeVisitor globalIncludeVisitor(H); - p->visit(&globalIncludeVisitor, false); - - printVersionCheck(H); - printVersionCheck(C); - - printDllExportStuff(H, _dllExport); - if(_dllExport.size()) - { - _dllExport += " "; - } - - ProxyDeclVisitor proxyDeclVisitor(H, C, _dllExport); - p->visit(&proxyDeclVisitor, false); - - ObjectDeclVisitor objectDeclVisitor(H, C, _dllExport); - p->visit(&objectDeclVisitor, false); - - IceInternalVisitor iceInternalVisitor(H, C, _dllExport); - p->visit(&iceInternalVisitor, false); - - HandleVisitor handleVisitor(H, C, _dllExport); - p->visit(&handleVisitor, false); - - TypesVisitor typesVisitor(H, C, _dllExport); - p->visit(&typesVisitor, false); - - ObjectVisitor objectVisitor(H, C, _dllExport); - p->visit(&objectVisitor, false); - - ProxyVisitor proxyVisitor(H, C, _dllExport); - p->visit(&proxyVisitor, false); - - if(_impl) - { - implH << "\n#include <"; - if(_include.size()) - { - implH << _include << '/'; - } - implH << _base << ".h>"; - - writeExtraHeaders(implC); - - implC << "\n#include <"; - if(_include.size()) - { - implC << _include << '/'; - } - implC << _base << "I.h>"; - - ImplVisitor implVisitor(implH, implC, _dllExport); - p->visit(&implVisitor, false); - } -} - -void -Slice::Gen::closeOutput() -{ - H.close(); - C.close(); - implH.close(); - implC.close(); -} - -void -Slice::Gen::writeExtraHeaders(Output& out) -{ - for(vector::const_iterator i = _extraHeaders.begin(); i != _extraHeaders.end(); ++i) - { - string hdr = *i; - string guard; - string::size_type pos = hdr.rfind(','); - if(pos != string::npos) - { - hdr = i->substr(0, pos); - guard = i->substr(pos + 1); - } - if(!guard.empty()) - { - out << "\n#ifndef " << guard; - out << "\n#define " << guard; - } - out << "\n#include <"; - if(!_include.empty()) - { - out << _include << '/'; - } - out << hdr << '>'; - if(!guard.empty()) - { - out << "\n#endif"; - } - } -} - -Slice::Gen::GlobalIncludeVisitor::GlobalIncludeVisitor(Output& h) : - H(h), _finished(false) -{ -} - -bool -Slice::Gen::GlobalIncludeVisitor::visitModuleStart(const ModulePtr& p) -{ - if(!_finished) - { - DefinitionContextPtr dc = p->definitionContext(); - assert(dc); - StringList globalMetaData = dc->getMetaData(); - - static const string includePrefix = "cpp:include:"; - - for(StringList::const_iterator q = globalMetaData.begin(); q != globalMetaData.end(); ++q) - { - string s = *q; - if(s.find(includePrefix) == 0) - { - H << nl << "#include <" << s.substr(includePrefix.size()) << ">"; - } - } - _finished = true; - } - - return false; -} - -Slice::Gen::TypesVisitor::TypesVisitor(Output& h, Output& c, const string& dllExport) : - H(h), C(c), _dllExport(dllExport), _doneStaticSymbol(false), _useWstring(false) -{ -} - -bool -Slice::Gen::TypesVisitor::visitModuleStart(const ModulePtr& p) -{ - _useWstring = setUseWstring(p, _useWstringHist, _useWstring); - - string name = fixKwd(p->name()); - - H << sp << nl << "namespace " << name << nl << '{'; - - return true; -} - -void -Slice::Gen::TypesVisitor::visitModuleEnd(const ModulePtr& p) -{ - H << sp << nl << '}'; - - _useWstring = resetUseWstring(_useWstringHist); -} - -bool -Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr&) -{ - return false; -} - -bool -Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) -{ - _useWstring = setUseWstring(p, _useWstringHist, _useWstring); - - string name = fixKwd(p->name()); - string scoped = fixKwd(p->scoped()); - ExceptionPtr base = p->base(); - DataMemberList dataMembers = p->dataMembers(); - DataMemberList allDataMembers = p->allDataMembers(); - DataMemberList::const_iterator q; - - vector params; - vector allTypes; - vector allParamDecls; - vector baseParams; - vector::const_iterator pi; - - for(q = dataMembers.begin(); q != dataMembers.end(); ++q) - { - params.push_back(fixKwd((*q)->name())); - } - - for(q = allDataMembers.begin(); q != allDataMembers.end(); ++q) - { - string typeName = inputTypeToString((*q)->type(), _useWstring, (*q)->getMetaData()); - allTypes.push_back(typeName); - allParamDecls.push_back(typeName + " __ice_" + (*q)->name()); - } - - if(base) - { - DataMemberList baseDataMembers = base->allDataMembers(); - for(q = baseDataMembers.begin(); q != baseDataMembers.end(); ++q) - { - baseParams.push_back("__ice_" + (*q)->name()); - } - } - - H << sp << nl << "class " << _dllExport << name << " : "; - H.useCurrentPosAsIndent(); - H << "public "; - if(!base) - { - H << (p->isLocal() ? "::Ice::LocalException" : "::Ice::UserException"); - } - else - { - H << fixKwd(base->scoped()); - } - H.restoreIndent(); - H << sb; - - H.dec(); - H << nl << "public:"; - H.inc(); - - H << sp << nl << name << spar; - if(p->isLocal()) - { - H << "const char*" << "int"; - } - H << epar; - if(!p->isLocal()) - { - H << " {}"; - } - else - { - H << ';'; - } - if(!allTypes.empty()) - { - H << nl; - if(!p->isLocal() && allTypes.size() == 1) - { - H << "explicit "; - } - H << name << spar; - if(p->isLocal()) - { - H << "const char*" << "int"; - } - H << allTypes << epar << ';'; - } - H << nl << "virtual ~" << name << "() throw();"; - H << sp; - - if(p->isLocal()) - { - C << sp << nl << scoped.substr(2) << "::" << name << spar << "const char* __file" << "int __line" << epar - << " :"; - C.inc(); - emitUpcall(base, "(__file, __line)", true); - C.dec(); - C << sb; - C << eb; - } - - if(!allTypes.empty()) - { - C << sp << nl; - C << scoped.substr(2) << "::" << name << spar; - if(p->isLocal()) - { - C << "const char* __file" << "int __line"; - } - C << allParamDecls << epar; - if(p->isLocal() || !baseParams.empty() || !params.empty()) - { - C << " :"; - C.inc(); - string upcall; - if(!allParamDecls.empty()) - { - upcall = "("; - if(p->isLocal()) - { - upcall += "__file, __line"; - } - for(pi = baseParams.begin(); pi != baseParams.end(); ++pi) - { - if(p->isLocal() || pi != baseParams.begin()) - { - upcall += ", "; - } - upcall += *pi; - } - upcall += ")"; - } - if(!params.empty()) - { - upcall += ","; - } - emitUpcall(base, upcall, p->isLocal()); - } - for(pi = params.begin(); pi != params.end(); ++pi) - { - if(pi != params.begin()) - { - C << ","; - } - C << nl << *pi << "(__ice_" << *pi << ')'; - } - if(p->isLocal() || !baseParams.empty() || !params.empty()) - { - C.dec(); - } - C << sb; - C << eb; - } - - C << sp << nl; - C << scoped.substr(2) << "::~" << name << "() throw()"; - C << sb; - C << eb; - - H << nl << "virtual ::std::string ice_name() const;"; - - string flatName = p->flattenedScope() + p->name() + "_name"; - - C << sp << nl << "static const char* " << flatName << " = \"" << p->scoped().substr(2) << "\";"; - C << sp << nl << "::std::string" << nl << scoped.substr(2) << "::ice_name() const"; - C << sb; - C << nl << "return " << flatName << ';'; - C << eb; - - if(p->isLocal()) - { - H << nl << "virtual ::std::string toString() const;"; - } - - H << nl << "virtual ::Ice::Exception* ice_clone() const;"; - C << sp << nl << "::Ice::Exception*" << nl << scoped.substr(2) << "::ice_clone() const"; - C << sb; - C << nl << "return new " << name << "(*this);"; - C << eb; - - H << nl << "virtual void ice_throw() const;"; - C << sp << nl << "void" << nl << scoped.substr(2) << "::ice_throw() const"; - C << sb; - C << nl << "throw *this;"; - C << eb; - - if(!p->isLocal()) - { - H << sp << nl << "static const ::IceInternal::UserExceptionFactoryPtr& ice_factory();"; - } - if(!dataMembers.empty()) - { - H << sp; - } - return true; -} - -void -Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) -{ - string name = fixKwd(p->name()); - string scope = fixKwd(p->scope()); - string scoped = fixKwd(p->scoped()); - DataMemberList dataMembers = p->dataMembers(); - DataMemberList::const_iterator q; - - string factoryName; - - if(!p->isLocal()) - { - ExceptionPtr base = p->base(); - - H << sp << nl << "virtual void __write(::IceInternal::BasicStream*) const;"; - H << nl << "virtual void __read(::IceInternal::BasicStream*, bool);"; - C << sp << nl << "void" << nl << scoped.substr(2) << "::__write(::IceInternal::BasicStream* __os) const"; - C << sb; - C << nl << "__os->write(::std::string(\"" << p->scoped() << "\"), false);"; - C << nl << "__os->startWriteSlice();"; - for(q = dataMembers.begin(); q != dataMembers.end(); ++q) - { - writeMarshalUnmarshalCode(C, (*q)->type(), fixKwd((*q)->name()), true, "", true, (*q)->getMetaData()); - } - C << nl << "__os->endWriteSlice();"; - if(base) - { - emitUpcall(base, "::__write(__os);"); - } - C << eb; - - C << sp << nl << "void" << nl << scoped.substr(2) << "::__read(::IceInternal::BasicStream* __is, bool __rid)"; - C << sb; - C << nl << "if(__rid)"; - C << sb; - C << nl << "::std::string myId;"; - C << nl << "__is->read(myId, false);"; - C << eb; - C << nl << "__is->startReadSlice();"; - for(q = dataMembers.begin(); q != dataMembers.end(); ++q) - { - writeMarshalUnmarshalCode(C, (*q)->type(), fixKwd((*q)->name()), false, "", true, (*q)->getMetaData()); - } - C << nl << "__is->endReadSlice();"; - if(base) - { - emitUpcall(base, "::__read(__is, true);"); - } - C << eb; - - factoryName = "__F" + p->flattenedScope() + p->name(); - - C << sp << nl << "struct " << factoryName << " : public ::IceInternal::UserExceptionFactory"; - C << sb; - C << sp << nl << "virtual void"; - C << nl << "createAndThrow()"; - C << sb; - C << nl << "throw " << scoped << "();"; - C << eb; - C << eb << ';'; - - C << sp << nl << "static ::IceInternal::UserExceptionFactoryPtr " << factoryName - << "__Ptr = new " << factoryName << ';'; - - C << sp << nl << "const ::IceInternal::UserExceptionFactoryPtr&"; - C << nl << scoped.substr(2) << "::ice_factory()"; - C << sb; - C << nl << "return " << factoryName << "__Ptr;"; - C << eb; - - C << sp << nl << "class " << factoryName << "__Init"; - C << sb; - C.dec(); - C << nl << "public:"; - C.inc(); - C << sp << nl << factoryName << "__Init()"; - C << sb; - C << nl << "::IceInternal::factoryTable->addExceptionFactory(\"" << p->scoped() << "\", " << scoped - << "::ice_factory());"; - C << eb; - C << sp << nl << "~" << factoryName << "__Init()"; - C << sb; - C << nl << "::IceInternal::factoryTable->removeExceptionFactory(\"" << p->scoped() << "\");"; - C << eb; - C << eb << ';'; - C << sp << nl << "static " << factoryName << "__Init "<< factoryName << "__i;"; - C << sp << nl << "#ifdef __APPLE__"; - - string initfuncname = "__F" + p->flattenedScope() + p->name() + "__initializer"; - C << nl << "extern \"C\" { void " << initfuncname << "() {} }"; - C << nl << "#endif"; - } - H << eb << ';'; - - if(!p->isLocal()) - { - // - // We need an instance here to trigger initialization if the implementation is in a shared libarry. - // But we do this only once per source file, because a single instance is sufficient to initialize - // all of the globals in a shared library. - // - if(!_doneStaticSymbol) - { - _doneStaticSymbol = true; - H << sp << nl << "static " << name << " __" << p->name() << "_init;"; - } - } - - _useWstring = resetUseWstring(_useWstringHist); -} - -bool -Slice::Gen::TypesVisitor::visitStructStart(const StructPtr& p) -{ - _useWstring = setUseWstring(p, _useWstringHist, _useWstring); - - string name = fixKwd(p->name()); - - H << sp << nl << "struct " << name; - H << sb; - - return true; -} - -void -Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) -{ - string name = fixKwd(p->name()); - string scoped = fixKwd(p->scoped()); - string scope = fixKwd(p->scope()); - - DataMemberList dataMembers = p->dataMembers(); - DataMemberList::const_iterator q; - - vector params; - vector::const_iterator pi; - - for(q = dataMembers.begin(); q != dataMembers.end(); ++q) - { - params.push_back(fixKwd((*q)->name())); - } - - H << sp; - H << nl << _dllExport << "bool operator==(const " << name << "&) const;"; - H << nl << _dllExport << "bool operator<(const " << name << "&) const;"; - H << nl << "bool operator!=(const " << name << "& __rhs) const"; - H << sb; - H << nl << "return !operator==(__rhs);"; - H << eb; - H << nl << "bool operator<=(const " << name << "& __rhs) const"; - H << sb; - H << nl << "return operator<(__rhs) || operator==(__rhs);"; - H << eb; - H << nl << "bool operator>(const " << name << "& __rhs) const"; - H << sb; - H << nl << "return !operator<(__rhs) && !operator==(__rhs);"; - H << eb; - H << nl << "bool operator>=(const " << name << "& __rhs) const"; - H << sb; - H << nl << "return !operator<(__rhs);"; - H << eb; - - C << sp << nl << "bool" << nl << scoped.substr(2) << "::operator==(const " << name << "& __rhs) const"; - C << sb; - C << nl << "if(this == &__rhs)"; - C << sb; - C << nl << "return true;"; - C << eb; - for(pi = params.begin(); pi != params.end(); ++pi) - { - C << nl << "if(" << *pi << " != __rhs." << *pi << ')'; - C << sb; - C << nl << "return false;"; - C << eb; - } - C << nl << "return true;"; - C << eb; - C << sp << nl << "bool" << nl << scoped.substr(2) << "::operator<(const " << name << "& __rhs) const"; - C << sb; - C << nl << "if(this == &__rhs)"; - C << sb; - C << nl << "return false;"; - C << eb; - for(pi = params.begin(); pi != params.end(); ++pi) - { - C << nl << "if(" << *pi << " < __rhs." << *pi << ')'; - C << sb; - C << nl << "return true;"; - C << eb; - C << nl << "else if(__rhs." << *pi << " < " << *pi << ')'; - C << sb; - C << nl << "return false;"; - C << eb; - } - C << nl << "return false;"; - C << eb; - - // - // None of these member functions is virtual! - // - H << sp << nl << _dllExport << "void __write(::IceInternal::BasicStream*) const;"; - H << nl << _dllExport << "void __read(::IceInternal::BasicStream*);"; - - C << sp << nl << "void" << nl << scoped.substr(2) << "::__write(::IceInternal::BasicStream* __os) const"; - C << sb; - for(q = dataMembers.begin(); q != dataMembers.end(); ++q) - { - writeMarshalUnmarshalCode(C, (*q)->type(), fixKwd((*q)->name()), true, "", true, (*q)->getMetaData()); - } - C << eb; - - C << sp << nl << "void" << nl << scoped.substr(2) << "::__read(::IceInternal::BasicStream* __is)"; - C << sb; - for(q = dataMembers.begin(); q != dataMembers.end(); ++q) - { - writeMarshalUnmarshalCode(C, (*q)->type(), fixKwd((*q)->name()), false, "", true, (*q)->getMetaData()); - } - C << eb; - - H << eb << ';'; - - _useWstring = resetUseWstring(_useWstringHist); -} - -void -Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p) -{ - string name = fixKwd(p->name()); - string s = typeToString(p->type(), _useWstring, p->getMetaData()); - H << nl << s << ' ' << name << ';'; -} - -void -Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p) -{ - string name = fixKwd(p->name()); - TypePtr type = p->type(); - string s = typeToString(type, _useWstring, p->typeMetaData()); - StringList metaData = p->getMetaData(); - string seqType = findMetaData(metaData, true); - if(!seqType.empty() && seqType != "array" && seqType.find("range") != 0) - { - H << sp << nl << "typedef " << seqType << ' ' << name << ';'; - } - else - { - H << sp << nl << "typedef ::std::vector<" << (s[0] == ':' ? " " : "") << s << "> " << name << ';'; - } - - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(!p->isLocal()) - { - string scoped = fixKwd(p->scoped()); - string scope = fixKwd(p->scope()); - - if(!seqType.empty()) - { - H << nl << _dllExport << "void __write" << name << "(::IceInternal::BasicStream*, const " << name << "&);"; - H << nl << _dllExport << "void __read" << name << "(::IceInternal::BasicStream*, " << name << "&);"; - - C << sp << nl << "void" << nl << scope.substr(2) << "__write" << name - << "(::IceInternal::BasicStream* __os, const " << scoped << "& v)"; - C << sb; - C << nl << "::Ice::Int size = static_cast< ::Ice::Int>(v.size());"; - C << nl << "__os->writeSize(size);"; - C << nl << "for(" << name << "::const_iterator p = v.begin(); p != v.end(); ++p)"; - C << sb; - writeMarshalUnmarshalCode(C, type, "(*p)", true); - C << eb; - C << eb; - - C << sp << nl << "void" << nl << scope.substr(2) << "__read" << name - << "(::IceInternal::BasicStream* __is, " << scoped << "& v)"; - C << sb; - C << nl << "::Ice::Int sz;"; - C << nl << "__is->readSize(sz);"; - C << nl << name << "(sz).swap(v);"; - if(type->isVariableLength()) - { - // Protect against bogus sequence sizes. - C << nl << "__is->startSeq(sz, " << type->minWireSize() << ");"; - } - else - { - C << nl << "__is->checkFixedSeq(sz, " << type->minWireSize() << ");"; - } - C << nl << "for(" << name << "::iterator p = v.begin(); p != v.end(); ++p)"; - C << sb; - writeMarshalUnmarshalCode(C, type, "(*p)", false); - - // - // After unmarshaling each element, check that there are still enough bytes left in the stream - // to unmarshal the remainder of the sequence, and decrement the count of elements - // yet to be unmarshaled for sequences with variable-length element type (that is, for sequences - // of classes, structs, dictionaries, sequences, strings, or proxies). This allows us to - // abort unmarshaling for bogus sequence sizes at the earliest possible moment. - // (For fixed-length sequences, we don't need to do this because the prediction of how many - // bytes will be taken up by the sequence is accurate.) - // - if(type->isVariableLength()) - { - if(!SequencePtr::dynamicCast(type)) - { - // - // No need to check for directly nested sequences because, at the start of each - // sequence, we check anyway. - // - C << nl << "__is->checkSeq();"; - } - C << nl << "__is->endElement();"; - } - C << eb; - if(type->isVariableLength()) - { - C << nl << "__is->endSeq(sz);"; - } - C << eb; - } - else if(!builtin || builtin->kind() == Builtin::KindObject || builtin->kind() == Builtin::KindObjectProxy) - { - H << nl << _dllExport << "void __write" << name << "(::IceInternal::BasicStream*, const " << s - << "*, const " << s << "*);"; - H << nl << _dllExport << "void __read" << name << "(::IceInternal::BasicStream*, " << name << "&);"; - - C << sp << nl << "void" << nl << scope.substr(2) << "__write" << name - << "(::IceInternal::BasicStream* __os, const " << s << "* begin, const " << s << "* end)"; - C << sb; - C << nl << "::Ice::Int size = static_cast< ::Ice::Int>(end - begin);"; - C << nl << "__os->writeSize(size);"; - C << nl << "for(int i = 0; i < size; ++i)"; - C << sb; - writeMarshalUnmarshalCode(C, type, "begin[i]", true); - C << eb; - C << eb; - - C << sp << nl << "void" << nl << scope.substr(2) << "__read" << name << - "(::IceInternal::BasicStream* __is, " << scoped << "& v)"; - C << sb; - C << nl << "::Ice::Int sz;"; - C << nl << "__is->readSize(sz);"; - if(type->isVariableLength()) - { - // Protect against bogus sequence sizes. - C << nl << "__is->startSeq(sz, " << type->minWireSize() << ");"; - } - else - { - C << nl << "__is->checkFixedSeq(sz, " << type->minWireSize() << ");"; - } - C << nl << "v.resize(sz);"; - C << nl << "for(int i = 0; i < sz; ++i)"; - C << sb; - writeMarshalUnmarshalCode(C, type, "v[i]", false); - - // - // After unmarshaling each element, check that there are still enough bytes left in the stream - // to unmarshal the remainder of the sequence, and decrement the count of elements - // yet to be unmarshaled for sequences with variable-length element type (that is, for sequences - // of classes, structs, dictionaries, sequences, strings, or proxies). This allows us to - // abort unmarshaling for bogus sequence sizes at the earliest possible moment. - // (For fixed-length sequences, we don't need to do this because the prediction of how many - // bytes will be taken up by the sequence is accurate.) - // - if(type->isVariableLength()) - { - if(!SequencePtr::dynamicCast(type)) - { - // - // No need to check for directly nested sequences because, at the start of each - // sequence, we check anyway. - // - C << nl << "__is->checkSeq();"; - } - C << nl << "__is->endElement();"; - } - C << eb; - if(type->isVariableLength()) - { - C << nl << "__is->endSeq(sz);"; - } - C << eb; - } - } -} - -void -Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p) -{ - string name = fixKwd(p->name()); - TypePtr keyType = p->keyType(); - TypePtr valueType = p->valueType(); - string ks = typeToString(keyType, _useWstring, p->keyMetaData()); - if(ks[0] == ':') - { - ks.insert(0, " "); - } - string vs = typeToString(valueType, _useWstring, p->valueMetaData()); - H << sp << nl << "typedef ::std::map<" << ks << ", " << vs << "> " << name << ';'; - - if(!p->isLocal()) - { - string scoped = fixKwd(p->scoped()); - string scope = fixKwd(p->scope()); - - H << nl << _dllExport << "void __write" << name << "(::IceInternal::BasicStream*, const " << name << "&);"; - H << nl << _dllExport << "void __read" << name << "(::IceInternal::BasicStream*, " << name << "&);"; - - C << sp << nl << "void" << nl << scope.substr(2) << "__write" << name - << "(::IceInternal::BasicStream* __os, const " << scoped << "& v)"; - C << sb; - C << nl << "__os->writeSize(::Ice::Int(v.size()));"; - C << nl << scoped << "::const_iterator p;"; - C << nl << "for(p = v.begin(); p != v.end(); ++p)"; - C << sb; - writeMarshalUnmarshalCode(C, keyType, "p->first", true); - writeMarshalUnmarshalCode(C, valueType, "p->second", true); - C << eb; - C << eb; - - C << sp << nl << "void" << nl << scope.substr(2) << "__read" << name - << "(::IceInternal::BasicStream* __is, " << scoped << "& v)"; - C << sb; - C << nl << "::Ice::Int sz;"; - C << nl << "__is->readSize(sz);"; - C << nl << "while(sz--)"; - C << sb; - C << nl << "::std::pair pair;"; - string pf = string("const_cast<") + ks + "&>(pair.first)"; - writeMarshalUnmarshalCode(C, keyType, pf, false); - C << nl << scoped << "::iterator __i = v.insert(v.end(), pair);"; - writeMarshalUnmarshalCode(C, valueType, "__i->second", false); - C << eb; - C << eb; - } -} - -void -Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) -{ - string name = fixKwd(p->name()); - EnumeratorList enumerators = p->getEnumerators(); - H << sp << nl << "enum " << name; - H << sb; - EnumeratorList::const_iterator en = enumerators.begin(); - while(en != enumerators.end()) - { - H << nl << fixKwd((*en)->name()); - if(++en != enumerators.end()) - { - H << ','; - } - } - H << eb << ';'; - - if(!p->isLocal()) - { - string scoped = fixKwd(p->scoped()); - string scope = fixKwd(p->scope()); - - size_t sz = enumerators.size(); - assert(sz <= 0x7fffffff); // 64-bit enums are not supported - - H << sp << nl << _dllExport << "void __write(::IceInternal::BasicStream*, " << name << ");"; - H << nl << _dllExport << "void __read(::IceInternal::BasicStream*, " << name << "&);"; - - C << sp << nl << "void" << nl << scope.substr(2) << "__write(::IceInternal::BasicStream* __os, " << scoped - << " v)"; - C << sb; - if(sz <= 0x7f) - { - C << nl << "__os->write(static_cast< ::Ice::Byte>(v));"; - } - else if(sz <= 0x7fff) - { - C << nl << "__os->write(static_cast< ::Ice::Short>(v));"; - } - else - { - C << nl << "__os->write(static_cast< ::Ice::Int>(v));"; - } - C << eb; - - C << sp << nl << "void" << nl << scope.substr(2) << "__read(::IceInternal::BasicStream* __is, " << scoped - << "& v)"; - C << sb; - if(sz <= 0x7f) - { - C << nl << "::Ice::Byte val;"; - C << nl << "__is->read(val);"; - C << nl << "v = static_cast< " << scoped << ">(val);"; - } - else if(sz <= 0x7fff) - { - C << nl << "::Ice::Short val;"; - C << nl << "__is->read(val);"; - C << nl << "v = static_cast< " << scoped << ">(val);"; - } - else - { - C << nl << "::Ice::Int val;"; - C << nl << "__is->read(val);"; - C << nl << "v = static_cast< " << scoped << ">(val);"; - } - C << eb; - } -} - -void -Slice::Gen::TypesVisitor::visitConst(const ConstPtr& p) -{ - H << sp; - H << nl << "const " << typeToString(p->type(), _useWstring, p->typeMetaData()) << " " << fixKwd(p->name()) - << " = "; - - BuiltinPtr bp = BuiltinPtr::dynamicCast(p->type()); - if(bp && bp->kind() == Builtin::KindString) - { - // - // Expand strings into the basic source character set. We can't use isalpha() and the like - // here because they are sensitive to the current locale. - // - static const string basicSourceChars = "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "0123456789" - "_{}[]#()<>%:;.?*+-/^&|~!=,\\\"' "; - static const set charSet(basicSourceChars.begin(), basicSourceChars.end()); - - ostringstream initString; - initString << "\""; // Opening " - - const string val = p->value(); - for(string::const_iterator c = val.begin(); c != val.end(); ++c) - { - if(charSet.find(*c) == charSet.end()) - { - unsigned char uc = *c; // char may be signed, so make it positive - ostringstream s; - s << "\\"; // Print as octal if not in basic source character set - s.flags(ios_base::oct); - s.width(3); - s.fill('0'); - s << static_cast(uc); - initString << s.str(); - } - else - { - initString << *c; // Print normally if in basic source character set - } - } - initString << "\""; // Closing " - - bool isWstring = _useWstring || findMetaData(p->typeMetaData(), true) == "wstring"; - if(isWstring) - { - H.zeroIndent(); - H << "#ifdef ICEE_HAS_WSTRING"; - H.restoreIndent(); - H << 'L' << initString.str();; - H.zeroIndent(); - H << "#else"; - H.restoreIndent(); - } - H << initString.str(); - if(isWstring) - { - H.zeroIndent(); - H << "#endif"; - H.restoreIndent(); - } - } - else if(bp && bp->kind() == Builtin::KindLong) - { - H << "ICE_INT64(" << p->value() << ")"; - } - else - { - EnumPtr ep = EnumPtr::dynamicCast(p->type()); - if(ep) - { - H << fixKwd(p->value()); - } - else - { - H << p->value(); - } - } - - H << ';'; -} - -void -Slice::Gen::TypesVisitor::emitUpcall(const ExceptionPtr& base, const string& call, bool isLocal) -{ - C.zeroIndent(); - C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG - C.restoreIndent(); - C << nl << (base ? fixKwd(base->name()) : string(isLocal ? "LocalException" : "UserException")) << call; - C.zeroIndent(); - C << nl << "#else"; - C.restoreIndent(); - C << nl << (base ? fixKwd(base->scoped()) : string(isLocal ? "::Ice::LocalException" : "::Ice::UserException")) << call; - C.zeroIndent(); - C << nl << "#endif"; - C.restoreIndent(); -} - -Slice::Gen::ProxyDeclVisitor::ProxyDeclVisitor(Output& h, Output& c, const string& dllExport) : - H(h), C(c), _dllExport(dllExport) -{ -} - -bool -Slice::Gen::ProxyDeclVisitor::visitUnitStart(const UnitPtr& p) -{ - if(!p->hasNonLocalClassDecls()) - { - return false; - } - - H << sp << nl << "namespace IceProxy" << nl << '{'; - - return true; -} - -void -Slice::Gen::ProxyDeclVisitor::visitUnitEnd(const UnitPtr& p) -{ - H << sp << nl << '}'; -} - -bool -Slice::Gen::ProxyDeclVisitor::visitModuleStart(const ModulePtr& p) -{ - if(!p->hasNonLocalClassDecls()) - { - return false; - } - - string name = fixKwd(p->name()); - - H << sp << nl << "namespace " << name << nl << '{'; - - return true; -} - -void -Slice::Gen::ProxyDeclVisitor::visitModuleEnd(const ModulePtr& p) -{ - H << sp << nl << '}'; -} - -void -Slice::Gen::ProxyDeclVisitor::visitClassDecl(const ClassDeclPtr& p) -{ - string name = fixKwd(p->name()); - - H << sp << nl << "class " << name << ';'; -} - -Slice::Gen::ProxyVisitor::ProxyVisitor(Output& h, Output& c, const string& dllExport) : - H(h), C(c), _dllExport(dllExport), _useWstring(false) -{ -} - -bool -Slice::Gen::ProxyVisitor::visitUnitStart(const UnitPtr& p) -{ - if(!p->hasNonLocalClassDefs()) - { - return false; - } - - H << sp << nl << "namespace IceProxy" << nl << '{'; - - return true; -} - -void -Slice::Gen::ProxyVisitor::visitUnitEnd(const UnitPtr& p) -{ - H << sp << nl << '}'; -} - -bool -Slice::Gen::ProxyVisitor::visitModuleStart(const ModulePtr& p) -{ - if(!p->hasNonLocalClassDefs()) - { - return false; - } - - _useWstring = setUseWstring(p, _useWstringHist, _useWstring); - - string name = fixKwd(p->name()); - - H << sp << nl << "namespace " << name << nl << '{'; - - return true; -} - -void -Slice::Gen::ProxyVisitor::visitModuleEnd(const ModulePtr& p) -{ - H << sp << nl << '}'; - - _useWstring = resetUseWstring(_useWstringHist); -} - -bool -Slice::Gen::ProxyVisitor::visitClassDefStart(const ClassDefPtr& p) -{ - _useWstring = setUseWstring(p, _useWstringHist, _useWstring); - - string name = fixKwd(p->name()); - string scoped = fixKwd(p->scoped()); - ClassList bases = p->bases(); - - H << sp << nl << "class " << name << " : "; - if(bases.empty()) - { - H << "virtual public ::IceProxy::Ice::Object"; - } - else - { - H.useCurrentPosAsIndent(); - ClassList::const_iterator q = bases.begin(); - while(q != bases.end()) - { - H << "virtual public ::IceProxy" << fixKwd((*q)->scoped()); - if(++q != bases.end()) - { - H << ',' << nl; - } - } - H.restoreIndent(); - } - - H << sb; - H.dec(); - H << nl << "public:"; - H.inc(); - - return true; -} - -void -Slice::Gen::ProxyVisitor::visitClassDefEnd(const ClassDefPtr& p) -{ - string scoped = fixKwd(p->scoped()); - string scope = fixKwd(p->scope()); - - H << nl << nl << _dllExport << "static const ::std::string& ice_staticId();"; - H << eb << ';'; - - string flatName = p->flattenedScope() + p->name() + "_ids"; - - StringList ids; - getIds(p, ids); - - StringList::const_iterator firstIter = ids.begin(); - StringList::const_iterator scopedIter = find(ids.begin(), ids.end(), p->scoped()); - assert(scopedIter != ids.end()); - StringList::difference_type scopedPos = IceUtilInternal::distance(firstIter, scopedIter); - - C << sp; - C << nl << "const ::std::string&" << nl << "IceProxy" << scoped << "::ice_staticId()"; - C << sb; - C << nl << "return " << flatName << '[' << scopedPos << "];"; - C << eb; - - _useWstring = resetUseWstring(_useWstringHist); -} - -void -Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) -{ - string name = p->name(); - string scoped = fixKwd(p->scoped()); - string scope = fixKwd(p->scope()); - - TypePtr ret = p->returnType(); - string retS = returnTypeToString(ret, _useWstring, p->getMetaData()); - - vector params; - vector paramsDecl; - vector paramsName; - vector args; - - ParamDeclList inParams; - ParamDeclList outParams; - ParamDeclList paramList = p->parameters(); - for(ParamDeclList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) - { - string paramName = fixKwd((*q)->name()); - StringList metaData = (*q)->getMetaData(); - - string typeString; - if((*q)->isOutParam()) - { - outParams.push_back(*q); - typeString = outputTypeToString((*q)->type(), _useWstring, metaData); - } - else - { - inParams.push_back(*q); - typeString = inputTypeToString((*q)->type(), _useWstring, metaData); - } - - params.push_back(typeString); - paramsDecl.push_back(typeString + ' ' + paramName); - paramsName.push_back(paramName); - args.push_back(paramName); - } - - paramsName.push_back("__outS"); - - string thisPointer = fixKwd(scope.substr(0, scope.size() - 2)) + "*"; - - ContainerPtr container = p->container(); - ClassDefPtr cl = ClassDefPtr::dynamicCast(container); - string deprecateSymbol = getDeprecateSymbol(p, cl); - H << sp << nl << deprecateSymbol << retS << ' ' << fixKwd(name) << spar << paramsDecl << epar; - H << sb; - H << nl; - if(ret) - { - H << "return "; - } - H << fixKwd(name) << spar << args << "0" << epar << ';'; - H << eb; - H << nl << deprecateSymbol << retS << ' ' << fixKwd(name) << spar << paramsDecl << "const ::Ice::Context& __ctx" - << epar; - H << sb; - H << nl; - if(ret) - { - H << "return "; - } - H << fixKwd(name) << spar << args << "&__ctx" << epar << ';'; - H << eb; - - H << nl; - H.dec(); - H << nl << "private:"; - H.inc(); - H << sp << nl << _dllExport << retS << ' ' << fixKwd(name) << spar << params << "const ::Ice::Context*" << epar - << ';'; - H << nl; - H.dec(); - H << nl << "public:"; - H.inc(); - - C << sp << nl << retS << nl << "IceProxy" << scoped << spar << paramsDecl << "const ::Ice::Context* __ctx" << epar; - C << sb; - C << nl << "int __cnt = 0;"; - C << nl << "while(true)"; - C << sb; - C << nl << "::Ice::ConnectionPtr __connection;"; - C << nl << "try"; - C << sb; - if(p->returnsData()) - { - C << nl << "__checkTwowayOnly(\"" << name << "\");"; - } - C << nl << "static const ::std::string __operation(\"" << p->name() << "\");"; - C << nl << "__connection = ice_getConnection();"; - C << nl << "::IceInternal::Outgoing __outS(__connection.get(), _reference.get(), __operation, " - << operationModeToString(p->sendMode()) << ", __ctx);"; - if(!inParams.empty()) - { - C << nl << "try"; - C << sb; - C << nl << "::IceInternal::BasicStream* __os = __outS.stream();"; - writeMarshalCode(C, inParams, 0, StringList(), true); - C << eb; - C << nl << "catch(const ::Ice::LocalException& __ex)"; - C << sb; - C << nl << "__outS.abort(__ex);"; - C << eb; - } - C << nl << "bool __ok = __outS.invoke();"; - C << nl << "try"; - C << sb; - C << nl << "::IceInternal::BasicStream* __is = __outS.stream();"; - C << nl << "if(!__ok)"; - C << sb; - C << nl << "try"; - C << sb; - C << nl << "__is->throwException();"; - C << eb; - - // - // Generate a catch block for each legal user exception. This is necessary - // to prevent an "impossible" user exception to be thrown if client and - // and server use different exception specifications for an operation. For - // example: - // - // Client compiled with: - // exception A {}; - // exception B {}; - // interface I { - // void op() throws A; - // }; - // - // Server compiled with: - // exception A {}; - // exception B {}; - // interface I { - // void op() throws B; // Differs from client - // }; - // - // We need the catch blocks so, if the server throws B from op(), the - // client receives UnknownUserException instead of B. - // - ExceptionList throws = p->throws(); - throws.sort(); - throws.unique(); -#if defined(__SUNPRO_CC) - throws.sort(derivedToBaseCompare); -#else - throws.sort(Slice::DerivedToBaseCompare()); -#endif - for(ExceptionList::const_iterator i = throws.begin(); i != throws.end(); ++i) - { - C << nl << "catch(const " << fixKwd((*i)->scoped()) << "&)"; - C << sb; - C << nl << "throw;"; - C << eb; - } - C << nl << "catch(const ::Ice::UserException& __ex)"; - C << sb; - C << nl << "::Ice::UnknownUserException __uex(__FILE__, __LINE__);"; - C << nl << "__uex.unknown = __ex.ice_name();"; - C << nl << "throw __uex;"; - C << eb; - C << eb; - - writeAllocateCode(C, ParamDeclList(), ret, p->getMetaData(), _useWstring); - writeUnmarshalCode(C, outParams, ret, p->getMetaData()); - if(ret) - { - C << nl << "return __ret;"; - } - C << eb; - - C << nl << "catch(const ::Ice::LocalException& __ex)"; - C << sb; - C << nl << "throw ::IceInternal::LocalExceptionWrapper(__ex, false);"; - C << eb; - - C.zeroIndent(); - C << nl << "#if defined(_MSC_VER) && defined(_M_ARM) // ARM bug."; // COMPILERBUG - C.restoreIndent(); - C << nl << "catch(...)"; - C << sb; - C << nl << "throw;"; - C << eb; - C.zeroIndent(); - C << nl << "#endif"; - C.restoreIndent(); - if(!ret) - { - C << nl << "return;"; - } - C << eb; - C << nl << "catch(const ::IceInternal::LocalExceptionWrapper& __ex)"; - C << sb; - if(p->mode() == Operation::Idempotent || p->mode() == Operation::Nonmutating) - { - C << nl << "__handleExceptionWrapperRelaxed(__connection, __ex, __cnt);"; - } - else - { - C << nl << "__handleExceptionWrapper(__connection, __ex);"; - } - C << eb; - C << nl << "catch(const ::Ice::LocalException& __ex)"; - C << sb; - C << nl << "__handleException(__connection, __ex, __cnt);"; - C << eb; - - C.zeroIndent(); - C << nl << "#if defined(_MSC_VER) && defined(_M_ARM) // ARM bug."; // COMPILERBUG - C.restoreIndent(); - C << nl << "catch(...)"; - C << sb; - C << nl << "throw;"; - C << eb; - C.zeroIndent(); - C << nl << "#endif"; - C.restoreIndent(); - - C << eb; - C << eb; -} - -Slice::Gen::ObjectDeclVisitor::ObjectDeclVisitor(Output& h, Output& c, const string& dllExport) : - H(h), C(c), _dllExport(dllExport) -{ -} - -bool -Slice::Gen::ObjectDeclVisitor::visitModuleStart(const ModulePtr& p) -{ - if(!p->hasClassDecls()) - { - return false; - } - - string name = fixKwd(p->name()); - - H << sp << nl << "namespace " << name << nl << '{'; - - return true; -} - -void -Slice::Gen::ObjectDeclVisitor::visitModuleEnd(const ModulePtr& p) -{ - H << sp << nl << '}'; -} - -void -Slice::Gen::ObjectDeclVisitor::visitClassDecl(const ClassDeclPtr& p) -{ - string name = fixKwd(p->name()); - - H << sp << nl << "#ifndef ICEE_PURE_CLIENT"; - H << sp << nl << "class " << name << ';'; - H << nl << _dllExport << "bool operator==(const " << name << "&, const " << name << "&);"; - H << nl << _dllExport << "bool operator<(const " << name << "&, const " << name << "&);"; - H << sp << nl << "#endif // ICEE_PURE_CLIENT"; -} - -Slice::Gen::ObjectVisitor::ObjectVisitor(Output& h, Output& c, const string& dllExport) : - H(h), C(c), _dllExport(dllExport), _useWstring(false) -{ -} - -bool -Slice::Gen::ObjectVisitor::visitModuleStart(const ModulePtr& p) -{ - if(!p->hasClassDefs()) - { - return false; - } - - _useWstring = setUseWstring(p, _useWstringHist, _useWstring); - - string name = fixKwd(p->name()); - - H << sp << nl << "namespace " << name << nl << '{'; - - return true; -} - -void -Slice::Gen::ObjectVisitor::visitModuleEnd(const ModulePtr& p) -{ - H << sp; - H << nl << '}'; - - _useWstring = resetUseWstring(_useWstringHist); -} - -bool -Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) -{ - _useWstring = setUseWstring(p, _useWstringHist, _useWstring); - - string name = fixKwd(p->name()); - string scoped = fixKwd(p->scoped()); - ClassList bases = p->bases(); - ClassDefPtr base; - if(!bases.empty() && !bases.front()->isInterface()) - { - base = bases.front(); - } - DataMemberList dataMembers = p->dataMembers(); - DataMemberList allDataMembers = p->allDataMembers(); - - H << sp << nl << "#ifndef ICEE_PURE_CLIENT"; - - H << sp << nl << "class " << _dllExport << name << " : "; - H.useCurrentPosAsIndent(); - if(bases.empty()) - { - H << "virtual public ::Ice::Object"; - } - else - { - ClassList::const_iterator q = bases.begin(); - while(q != bases.end()) - { - H << "virtual public " << fixKwd((*q)->scoped()); - if(++q != bases.end()) - { - H << ',' << nl; - } - } - } - H.restoreIndent(); - H << sb; - H.dec(); - H << nl << "public:" << sp; - H.inc(); - - H << nl << "typedef " << name << "Prx ProxyType;"; - H << nl << "typedef " << name << "Ptr PointerType;"; - H << nl; - - vector params; - vector allTypes; - vector allParamDecls; - DataMemberList::const_iterator q; - - for(q = dataMembers.begin(); q != dataMembers.end(); ++q) - { - params.push_back(fixKwd((*q)->name())); - } - - for(q = allDataMembers.begin(); q != allDataMembers.end(); ++q) - { - string typeName = inputTypeToString((*q)->type(), _useWstring, (*q)->getMetaData()); - allTypes.push_back(typeName); - allParamDecls.push_back(typeName + " __ice_" + (*q)->name()); - } - - if(!p->isInterface()) - { - H << nl << name << "() {}"; - if(!allParamDecls.empty()) - { - H << nl; - if(allParamDecls.size() == 1) - { - H << "explicit "; - } - H << name << spar << allTypes << epar << ';'; - } - - /* - * Strong guarantee: commented-out code marked "Strong guarantee" generates - * a copy-assignment operator that provides the strong exception guarantee. - * For now, this is commented out, and we use the compiler-generated - * copy-assignment operator. However, that one does not provide the strong - * guarantee. - - H << ';'; - if(!p->isAbstract()) - { - H << nl << name << "& operator=(const " << name << "&)"; - if(allDataMembers.empty()) - { - H << " { return *this; }"; - } - H << ';'; - } - - // - // __swap() is static because classes may be abstract, so we - // can't use a non-static member function when we do an upcall - // from a non-abstract derived __swap to the __swap in an abstract base. - // - H << sp << nl << "static void __swap(" << name << "&, " << name << "&) throw()"; - if(allDataMembers.empty()) - { - H << " {}"; - } - H << ';'; - H << nl << "void swap(" << name << "& rhs) throw()"; - H << sb; - if(!allDataMembers.empty()) - { - H << nl << "__swap(*this, rhs);"; - } - H << eb; - - * Strong guarantee - */ - - emitOneShotConstructor(p); - - /* - * Strong guarantee - - if(!allDataMembers.empty()) - { - C << sp << nl << "void"; - C << nl << scoped.substr(2) << "::__swap(" << name << "& __lhs, " << name << "& __rhs) throw()"; - C << sb; - - if(base) - { - emitUpcall(base, "::__swap(__lhs, __rhs);"); - } - - // - // We use a map to remember for which types we have already declared - // a temporary variable and reuse that variable if a class has - // more than one member of the same type. That way, we don't use more - // temporaries than necessary. (::std::swap() instantiates a new temporary - // each time it is used.) - // - map tmpMap; - map::iterator pos; - int tmpCount = 0; - - for(q = dataMembers.begin(); q != dataMembers.end(); ++q) - { - string memberName = fixKwd((*q)->name()); - TypePtr type = (*q)->type(); - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin && builtin->kind() != Builtin::KindString - || EnumPtr::dynamicCast(type) || ProxyPtr::dynamicCast(type) - || ClassDeclPtr::dynamicCast(type) || StructPtr::dynamicCast(type)) - { - // - // For built-in types (except string), enums, proxies, structs, and classes, - // do the swap via a temporary variable. - // - string typeName = typeToString(type); - pos = tmpMap.find(typeName); - if(pos == tmpMap.end()) - { - pos = tmpMap.insert(pos, make_pair(typeName, tmpCount)); - C << nl << typeName << " __tmp" << tmpCount << ';'; - tmpCount++; - } - C << nl << "__tmp" << pos->second << " = __rhs." << memberName << ';'; - C << nl << "__rhs." << memberName << " = __lhs." << memberName << ';'; - C << nl << "__lhs." << memberName << " = __tmp" << pos->second << ';'; - } - else - { - // - // For dictionaries, vectors, and maps, use the standard container's - // swap() (which is usually optimized). - // - C << nl << "__lhs." << memberName << ".swap(__rhs." << memberName << ");"; - } - } - C << eb; - - if(!p->isAbstract()) - { - C << sp << nl << scoped << "&"; - C << nl << scoped.substr(2) << "::operator=(const " << name << "& __rhs)"; - C << sb; - C << nl << name << " __tmp(__rhs);"; - C << nl << "__swap(*this, __tmp);"; - C << nl << "return *this;"; - C << eb; - } - } - - * Strong guarantee - */ - } - - StringList ids; - getIds(p, ids); - - StringList::const_iterator firstIter = ids.begin(); - StringList::const_iterator scopedIter = find(ids.begin(), ids.end(), p->scoped()); - assert(scopedIter != ids.end()); - StringList::difference_type scopedPos = IceUtilInternal::distance(firstIter, scopedIter); - - StringList::const_iterator q1; - - H << sp; - H << nl << "virtual bool ice_isA" - << "(const ::std::string&, const ::Ice::Current& = ::Ice::Current()) const;"; - H << nl << "virtual ::std::vector< ::std::string> ice_ids" - << "(const ::Ice::Current& = ::Ice::Current()) const;"; - H << nl << "virtual const ::std::string& ice_id(const ::Ice::Current& = ::Ice::Current()) const;"; - H << nl << "static const ::std::string& ice_staticId();"; - if(!dataMembers.empty()) - { - H << sp; - } - - string flatName = p->flattenedScope() + p->name() + "_ids"; - - C << sp; - C << nl << "static const ::std::string " << flatName << '[' << ids.size() << "] ="; - C << sb; - q1 = ids.begin(); - while(q1 != ids.end()) - { - C << nl << '"' << *q1 << '"'; - if(++q1 != ids.end()) - { - C << ','; - } - } - C << eb << ';'; - - C << sp << nl << "#ifndef ICEE_PURE_CLIENT"; - - C << sp; - C << nl << "bool" << nl << fixKwd(p->scoped()).substr(2) - << "::ice_isA(const ::std::string& _s, const ::Ice::Current&) const"; - C << sb; - C << nl << "return ::std::binary_search(" << flatName << ", " << flatName << " + " << ids.size() << ", _s);"; - C << eb; - - C << sp; - C << nl << "::std::vector< ::std::string>" << nl << fixKwd(p->scoped()).substr(2) - << "::ice_ids(const ::Ice::Current&) const"; - C << sb; - C << nl << "return ::std::vector< ::std::string>(&" << flatName << "[0], &" << flatName - << '[' << ids.size() << "]);"; - C << eb; - - C << sp; - C << nl << "const ::std::string&" << nl << fixKwd(p->scoped()).substr(2) - << "::ice_id(const ::Ice::Current&) const"; - C << sb; - C << nl << "return " << flatName << '[' << scopedPos << "];"; - C << eb; - - C << sp; - C << nl << "const ::std::string&" << nl << fixKwd(p->scoped()).substr(2) << "::ice_staticId()"; - C << sb; - C << nl << "return " << flatName << '[' << scopedPos << "];"; - C << eb; - - return true; -} - -void -Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) -{ - string scoped = fixKwd(p->scoped()); - string scope = fixKwd(p->scope()); - - ClassList bases = p->bases(); - ClassDefPtr base; - if(!bases.empty() && !bases.front()->isInterface()) - { - base = bases.front(); - } - - OperationList allOps = p->allOperations(); - if(!allOps.empty()) - { - StringList allOpNames; -#if defined(__IBMCPP__) && defined(NDEBUG) -// -// See comment for transform above -// - transform(allOps.begin(), allOps.end(), back_inserter(allOpNames), - ::IceUtil::constMemFun(&Contained::name)); -#else - transform(allOps.begin(), allOps.end(), back_inserter(allOpNames), - ::IceUtil::constMemFun(&Contained::name)); -#endif - allOpNames.push_back("ice_id"); - allOpNames.push_back("ice_ids"); - allOpNames.push_back("ice_isA"); - allOpNames.push_back("ice_ping"); - allOpNames.sort(); - allOpNames.unique(); - - StringList::const_iterator q; - - H << sp; - H << nl - << "virtual ::Ice::DispatchStatus __dispatch(::IceInternal::Incoming&, const ::Ice::Current&);"; - - string flatName = p->flattenedScope() + p->name() + "_all"; - C << sp; - C << nl << "static ::std::string " << flatName << "[] ="; - C << sb; - q = allOpNames.begin(); - while(q != allOpNames.end()) - { - C << nl << '"' << *q << '"'; - if(++q != allOpNames.end()) - { - C << ','; - } - } - C << eb << ';'; - C << sp; - C << nl << "::Ice::DispatchStatus" << nl << scoped.substr(2) - << "::__dispatch(::IceInternal::Incoming& in, const ::Ice::Current& current)"; - C << sb; - - C << nl << "::std::pair< ::std::string*, ::std::string*> r = " - << "::std::equal_range(" << flatName << ", " << flatName << " + " << allOpNames.size() - << ", current.operation);"; - C << nl << "if(r.first == r.second)"; - C << sb; - C << nl << "throw Ice::OperationNotExistException(__FILE__, __LINE__, current.id, current.facet, current.operation);"; - C << eb; - C << sp; - C << nl << "switch(r.first - " << flatName << ')'; - C << sb; - int i = 0; - for(q = allOpNames.begin(); q != allOpNames.end(); ++q) - { - C << nl << "case " << i++ << ':'; - C << sb; - C << nl << "return ___" << *q << "(in, current);"; - C << eb; - } - C << eb; - C << sp; - C << nl << "assert(false);"; - C << nl << "throw Ice::OperationNotExistException(__FILE__, __LINE__, current.id, current.facet, current.operation);"; - C << eb; - } - - // - // We add a protected destructor to force heap instantiation of the class. - // - if(!p->isAbstract()) - { - H.dec(); - H << sp << nl << "protected:"; - H.inc(); - H << sp << nl << "virtual ~" << fixKwd(p->name()) << "() {}"; - } - - H << eb << ';'; - H << sp << nl << "#endif // ICEE_PURE_CLIENT"; - - string name = p->name(); - - C << sp; - C << nl << "bool" << nl << scope.substr(2) << "operator==(const " << scoped - << "& l, const " << scoped << "& r)"; - C << sb; - C << nl << "return static_cast(l) == static_cast(r);"; - C << eb; - C << sp; - C << nl << "bool" << nl << scope.substr(2) << "operator<(const " << scoped - << "& l, const " << scoped << "& r)"; - C << sb; - C << nl << "return static_cast(l) < static_cast(r);"; - C << eb; - C << sp << nl << "#endif // ICEE_PURE_CLIENT"; - - _useWstring = resetUseWstring(_useWstringHist); -} - -bool -Slice::Gen::ObjectVisitor::visitExceptionStart(const ExceptionPtr&) -{ - return false; -} - -bool -Slice::Gen::ObjectVisitor::visitStructStart(const StructPtr&) -{ - return false; -} - -void -Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p) -{ - string name = p->name(); - string scoped = fixKwd(p->scoped()); - string scope = fixKwd(p->scope()); - - TypePtr ret = p->returnType(); - string retS = returnTypeToString(ret, _useWstring, p->getMetaData()); - - string params = "("; - string paramsDecl = "("; - string args = "("; - - ContainerPtr container = p->container(); - ClassDefPtr cl = ClassDefPtr::dynamicCast(container); - - ParamDeclList inParams; - ParamDeclList outParams; - ParamDeclList paramList = p->parameters(); - for(ParamDeclList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) - { - string paramName = fixKwd((*q)->name()); - TypePtr type = (*q)->type(); - bool isOutParam = (*q)->isOutParam(); - StringList metaData = (*q)->getMetaData(); - - string typeString; - if(isOutParam) - { - outParams.push_back(*q); - typeString = outputTypeToString(type, _useWstring, metaData); - } - else - { - inParams.push_back(*q); - typeString = inputTypeToString(type, _useWstring, metaData); - } - - if(q != paramList.begin()) - { - params += ", "; - paramsDecl += ", "; - args += ", "; - } - - params += typeString; - paramsDecl += typeString; - paramsDecl += ' '; - paramsDecl += paramName; - args += paramName; - } - - if(!paramList.empty()) - { - params += ", "; - paramsDecl += ", "; - args += ", "; - } - - params += "const ::Ice::Current& = ::Ice::Current())"; - paramsDecl += "const ::Ice::Current& __current)"; - args += "__current)"; - - bool isConst = (p->mode() == Operation::Nonmutating) || p->hasMetaData("cpp:const"); - - string deprecateSymbol = getDeprecateSymbol(p, cl); - - H << sp; - H << nl << deprecateSymbol << "virtual " << retS << ' ' << fixKwd(name) << params << (isConst ? " const" : "") - << " = 0;"; - - H << nl << "::Ice::DispatchStatus ___" << name - << "(::IceInternal::Incoming&, const ::Ice::Current&)" << (isConst ? " const" : "") << ';'; - - C << sp; - C << nl << "::Ice::DispatchStatus" << nl << scope.substr(2) << "___" << name - << "(::IceInternal::Incoming& __inS, const ::Ice::Current& __current)" << (isConst ? " const" : ""); - C << sb; - - ExceptionList throws = p->throws(); - throws.sort(); - throws.unique(); - - // - // Arrange exceptions into most-derived to least-derived order. If we don't - // do this, a base exception handler can appear before a derived exception - // handler, causing compiler warnings and resulting in the base exception - // being marshaled instead of the derived exception. - // - -#if defined(__SUNPRO_CC) - throws.sort(derivedToBaseCompare); -#else - throws.sort(Slice::DerivedToBaseCompare()); -#endif - - C << nl << "__checkMode(" << operationModeToString(p->mode()) << ", __current.mode);"; - - if(!inParams.empty()) - { - C << nl << "::IceInternal::BasicStream* __is = __inS.is();"; - } - if(ret || !outParams.empty() || !throws.empty()) - { - C << nl << "::IceInternal::BasicStream* __os = __inS.os();"; - } - - writeAllocateCode(C, inParams, 0, StringList(), _useWstring, true); - writeUnmarshalCode(C, inParams, 0, StringList(), true); - writeAllocateCode(C, outParams, 0, StringList(), _useWstring); - if(!throws.empty()) - { - C << nl << "try"; - C << sb; - } - C << nl; - if(ret) - { - C << retS << " __ret = "; - } - C << fixKwd(name) << args << ';'; - writeMarshalCode(C, outParams, ret, p->getMetaData()); - if(!throws.empty()) - { - C << eb; - ExceptionList::const_iterator r; - for(r = throws.begin(); r != throws.end(); ++r) - { - C << nl << "catch(const " << fixKwd((*r)->scoped()) << "& __ex)"; - C << sb; - C << nl << "__os->write(__ex);"; - C << nl << "return ::Ice::DispatchUserException;"; - C << eb; - } - } - C << nl << "return ::Ice::DispatchOK;"; - C << eb; -} - -void -Slice::Gen::ObjectVisitor::visitDataMember(const DataMemberPtr& p) -{ - string name = fixKwd(p->name()); - string s = typeToString(p->type(), _useWstring, p->getMetaData()); - H << nl << s << ' ' << name << ';'; -} - -bool -Slice::Gen::ObjectVisitor::emitVirtualBaseInitializers(const ClassDefPtr& p) -{ - DataMemberList allDataMembers = p->allDataMembers(); - if(allDataMembers.empty()) - { - return false; - } - - ClassList bases = p->bases(); - if(!bases.empty() && !bases.front()->isInterface()) - { - if(emitVirtualBaseInitializers(bases.front())) - { - C << ','; - } - } - - string upcall = "("; - DataMemberList::const_iterator q; - for(q = allDataMembers.begin(); q != allDataMembers.end(); ++q) - { - if(q != allDataMembers.begin()) - { - upcall += ", "; - } - upcall += "__ice_" + (*q)->name(); - } - upcall += ")"; - - C.zeroIndent(); - C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; - C.restoreIndent(); - C << nl << fixKwd(p->name()) << upcall; - C.zeroIndent(); - C << nl << "#else"; - C.restoreIndent(); - C << nl << fixKwd(p->scoped()) << upcall; - C.zeroIndent(); - C << nl << "#endif"; - C << nl; - C.restoreIndent(); - - return true; -} - -void -Slice::Gen::ObjectVisitor::emitOneShotConstructor(const ClassDefPtr& p) -{ - DataMemberList allDataMembers = p->allDataMembers(); - DataMemberList::const_iterator q; - - vector allParamDecls; - - for(q = allDataMembers.begin(); q != allDataMembers.end(); ++q) - { - string typeName = inputTypeToString((*q)->type(), _useWstring); - allParamDecls.push_back(typeName + " __ice_" + (*q)->name()); - } - - if(!allDataMembers.empty()) - { - C << sp << nl << p->scoped().substr(2) << "::" << fixKwd(p->name()) << spar << allParamDecls << epar << " :"; - C.inc(); - - DataMemberList dataMembers = p->dataMembers(); - - ClassList bases = p->bases(); - ClassDefPtr base; - if(!bases.empty() && !bases.front()->isInterface()) - { - if(emitVirtualBaseInitializers(bases.front())) - { - if(!dataMembers.empty()) - { - C << ','; - } - } - } - - if(!dataMembers.empty()) - { - C << nl; - } - for(q = dataMembers.begin(); q != dataMembers.end(); ++q) - { - if(q != dataMembers.begin()) - { - C << ',' << nl; - } - string memberName = fixKwd((*q)->name()); - C << memberName << '(' << "__ice_" << (*q)->name() << ')'; - } - - C.dec(); - C << sb; - C << eb; - } -} - -void -Slice::Gen::ObjectVisitor::emitUpcall(const ClassDefPtr& base, const string& call) -{ - C.zeroIndent(); - C << nl << "#if defined(_MSC_VER) && (_MSC_VER < 1300) // VC++ 6 compiler bug"; // COMPILERBUG - C.restoreIndent(); - C << nl << (base ? fixKwd(base->name()) : string("Object")) << call; - C.zeroIndent(); - C << nl << "#else"; - C.restoreIndent(); - C << nl << (base ? fixKwd(base->scoped()) : string("::Ice::Object")) << call; - C.zeroIndent(); - C << nl << "#endif"; - C.restoreIndent(); -} - -Slice::Gen::IceInternalVisitor::IceInternalVisitor(Output& h, Output& c, const string& dllExport) : - H(h), C(c), _dllExport(dllExport) -{ -} - -bool -Slice::Gen::IceInternalVisitor::visitUnitStart(const UnitPtr& p) -{ - if(!p->hasClassDecls()) - { - return false; - } - - H << sp; - H << nl << "namespace IceInternal" << nl << '{'; - - return true; -} - -void -Slice::Gen::IceInternalVisitor::visitUnitEnd(const UnitPtr& p) -{ - H << sp; - H << nl << '}'; -} - -void -Slice::Gen::IceInternalVisitor::visitClassDecl(const ClassDeclPtr& p) -{ - string scoped = fixKwd(p->scoped()); - - H << sp; - H << nl << "#ifndef ICEE_PURE_CLIENT"; - H << nl << _dllExport << "::Ice::Object* upCast(" << scoped << "*);"; - H << nl << "#endif // ICEE_PURE_CLIENT"; - H << nl << _dllExport << "::IceProxy::Ice::Object* upCast(::IceProxy" << scoped << "*);"; -} - -bool -Slice::Gen::IceInternalVisitor::visitClassDefStart(const ClassDefPtr& p) -{ - string scoped = fixKwd(p->scoped()); - - C << sp; - C << nl << "#ifndef ICEE_PURE_CLIENT"; - C << nl << "::Ice::Object* IceInternal::upCast(" << scoped << "* p) { return p; }"; - C << nl << "#endif // ICEE_PURE_CLIENT"; - C << nl << "::IceProxy::Ice::Object* IceInternal::upCast(::IceProxy" << scoped << "* p) { return p; }"; - - return true; -} - -Slice::Gen::HandleVisitor::HandleVisitor(Output& h, Output& c, const string& dllExport) : - H(h), C(c), _dllExport(dllExport) -{ -} - -bool -Slice::Gen::HandleVisitor::visitModuleStart(const ModulePtr& p) -{ - if(!p->hasClassDecls()) - { - return false; - } - - string name = fixKwd(p->name()); - - H << sp; - H << nl << "namespace " << name << nl << '{'; - - return true; -} - -void -Slice::Gen::HandleVisitor::visitModuleEnd(const ModulePtr& p) -{ - H << sp; - H << nl << '}'; -} - -void -Slice::Gen::HandleVisitor::visitClassDecl(const ClassDeclPtr& p) -{ - string name = p->name(); - string scoped = fixKwd(p->scoped()); - - H << sp << nl << "#ifndef ICEE_PURE_CLIENT"; - - H << sp; - H << nl << "typedef ::IceInternal::Handle< " << scoped << "> " << name << "Ptr;"; - - H << sp << nl << "#endif // ICEE_PURE_CLIENT" << sp; - - H << nl << "typedef ::IceInternal::ProxyHandle< ::IceProxy" << scoped << "> " << name << "Prx;"; - - H << sp; - H << nl << _dllExport << "void __read(::IceInternal::BasicStream*, " << name << "Prx&);"; -} - -bool -Slice::Gen::HandleVisitor::visitClassDefStart(const ClassDefPtr& p) -{ - string name = p->name(); - string scoped = fixKwd(p->scoped()); - string scope = fixKwd(p->scope()); - - string factory; - string type; - if(!p->isAbstract()) - { - type = scoped + "::ice_staticId()"; - factory = scoped + "::ice_factory()"; - } - else - { - type = "\"\""; - factory = "0"; - } - - C << sp; - C << nl << "void" << nl << scope.substr(2) << "__read(::IceInternal::BasicStream* __is, " - << scope << name << "Prx& v)"; - C << sb; - C << nl << "::Ice::ObjectPrx proxy;"; - C << nl << "__is->read(proxy);"; - C << nl << "if(!proxy)"; - C << sb; - C << nl << "v = 0;"; - C << eb; - C << nl << "else"; - C << sb; - C << nl << "v = new ::IceProxy" << scoped << ';'; - C << nl << "v->__copyFrom(proxy);"; - C << eb; - C << eb; - - return true; -} - -Slice::Gen::ImplVisitor::ImplVisitor(Output& h, Output& c, - const string& dllExport) : - H(h), C(c), _dllExport(dllExport), _useWstring(false) -{ -} - -void -Slice::Gen::ImplVisitor::writeReturn(Output& out, const TypePtr& type, const StringList& metaData) -{ - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - switch(builtin->kind()) - { - case Builtin::KindBool: - { - out << nl << "return false;"; - break; - } - case Builtin::KindByte: - case Builtin::KindShort: - case Builtin::KindInt: - case Builtin::KindLong: - { - out << nl << "return 0;"; - break; - } - case Builtin::KindFloat: - case Builtin::KindDouble: - { - out << nl << "return 0.0;"; - break; - } - case Builtin::KindString: - { - out << nl << "return ::std::string();"; - break; - } - case Builtin::KindObject: - case Builtin::KindObjectProxy: - case Builtin::KindLocalObject: - { - out << nl << "return 0;"; - break; - } - } - } - else - { - ProxyPtr prx = ProxyPtr::dynamicCast(type); - if(prx) - { - out << nl << "return 0;"; - } - else - { - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - if(cl) - { - out << nl << "return 0;"; - } - else - { - StructPtr st = StructPtr::dynamicCast(type); - if(st) - { - out << nl << "return " << fixKwd(st->scoped()) << "();"; - } - else - { - EnumPtr en = EnumPtr::dynamicCast(type); - if(en) - { - EnumeratorList enumerators = en->getEnumerators(); - out << nl << "return " << fixKwd(en->scope()) << fixKwd(enumerators.front()->name()) << ';'; - } - else - { - SequencePtr seq = SequencePtr::dynamicCast(type); - if(seq) - { - out << nl << "return " << typeToString(seq, _useWstring, metaData) << "();"; - } - else - { - DictionaryPtr dict = DictionaryPtr::dynamicCast(type); - assert(dict); - out << nl << "return " << fixKwd(dict->scoped()) << "();"; - } - } - } - } - } - } -} - -bool -Slice::Gen::ImplVisitor::visitModuleStart(const ModulePtr& p) -{ - if(!p->hasClassDefs()) - { - return false; - } - - _useWstring = setUseWstring(p, _useWstringHist, _useWstring); - - set includes; - ClassList classes = p->classes(); - for(ClassList::const_iterator q = classes.begin(); q != classes.end(); ++q) - { - ClassList bases = (*q)->bases(); - for(ClassList::const_iterator r = bases.begin(); r != bases.end(); ++r) - { - if((*r)->isAbstract()) - { - includes.insert((*r)->name()); - } - } - } - - for(set::const_iterator it = includes.begin(); it != includes.end(); ++it) - { - H << nl << "#include <" << *it << "I.h>"; - } - - string name = fixKwd(p->name()); - - H << sp << nl << "namespace " << name << nl << '{'; - - return true; -} - -void -Slice::Gen::ImplVisitor::visitModuleEnd(const ModulePtr& p) -{ - H << sp; - H << nl << '}'; - - _useWstring = resetUseWstring(_useWstringHist); -} - -bool -Slice::Gen::ImplVisitor::visitClassDefStart(const ClassDefPtr& p) -{ - if(!p->isAbstract()) - { - return false; - } - - _useWstring = setUseWstring(p, _useWstringHist, _useWstring); - - string name = p->name(); - string scope = fixKwd(p->scope()); - string cls = scope.substr(2) + name + "I"; - - ClassList bases = p->bases(); - ClassDefPtr base; - if(!bases.empty() && !bases.front()->isInterface()) - { - base = bases.front(); - } - - H << sp; - H << nl << "class " << name << "I : "; - H.useCurrentPosAsIndent(); - H << "virtual public " << fixKwd(name); - for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q) - { - H << ',' << nl << "virtual public " << fixKwd((*q)->scope()); - if((*q)->isAbstract()) - { - H << (*q)->name() << "I"; - } - else - { - H << fixKwd((*q)->name()); - } - } - H.restoreIndent(); - - H << sb; - H.dec(); - H << nl << "public:"; - H.inc(); - - OperationList ops = p->operations(); - OperationList::const_iterator r; - - for(r = ops.begin(); r != ops.end(); ++r) - { - OperationPtr op = (*r); - string opName = op->name(); - - TypePtr ret = op->returnType(); - string retS = returnTypeToString(ret, _useWstring, op->getMetaData()); - - H << sp << nl << "virtual " << retS << ' ' << fixKwd(opName) << '('; - H.useCurrentPosAsIndent(); - ParamDeclList paramList = op->parameters(); - ParamDeclList::const_iterator q; - for(q = paramList.begin(); q != paramList.end(); ++q) - { - if(q != paramList.begin()) - { - H << ',' << nl; - } - - StringList metaData = (*q)->getMetaData(); -#if defined(__SUNPRO_CC) && (__SUNPRO_CC==0x550) - // - // Work around for Sun CC 5.5 bug #4853566 - // - string typeString; - if((*q)->isOutParam()) - { - typeString = outputTypeToString((*q)->type(), _useWstring, metaData); - } - else - { - typeString = inputTypeToString((*q)->type(), _useWstring, metaData); - } -#else - string typeString = (*q)->isOutParam() ? - outputTypeToString((*q)->type(), _useWstring, metaData) : inputTypeToString((*q)->type(), _useWstring, metaData); -#endif - H << typeString; - } - - if(!paramList.empty()) - { - H << ',' << nl; - } - H << "const Ice::Current&"; - H.restoreIndent(); - - bool isConst = (op->mode() == Operation::Nonmutating) || op->hasMetaData("cpp:const"); - - H << ")" << (isConst ? " const" : "") << ';'; - - C << sp << nl << retS << nl; - C << scope.substr(2) << name << "I::" << fixKwd(opName) << '('; - C.useCurrentPosAsIndent(); - for(q = paramList.begin(); q != paramList.end(); ++q) - { - if(q != paramList.begin()) - { - C << ',' << nl; - } - - StringList metaData = (*q)->getMetaData(); -#if defined(__SUNPRO_CC) && (__SUNPRO_CC==0x550) - // - // Work around for Sun CC 5.5 bug #4853566 - // - string typeString; - if((*q)->isOutParam()) - { - typeString = outputTypeToString((*q)->type(), _useWstring, metaData); - } - else - { - typeString = inputTypeToString((*q)->type(), _useWstring, metaData); - } -#else - string typeString = (*q)->isOutParam() ? - outputTypeToString((*q)->type(), _useWstring, metaData) : inputTypeToString((*q)->type(), _useWstring, metaData); -#endif - C << typeString << ' ' << fixKwd((*q)->name()); - } - - if(!paramList.empty()) - { - C << ',' << nl; - } - C << "const Ice::Current& current"; - C.restoreIndent(); - C << ')'; - C << (isConst ? " const" : ""); - C << sb; - - if(ret) - { - writeReturn(C, ret, op->getMetaData()); - } - - C << eb; - } - - H << eb << ';'; - - return true; -} - -bool -Slice::Gen::MetaDataVisitor::visitModuleStart(const ModulePtr& p) -{ - // - // Validate global metadata. - // - DefinitionContextPtr dc = p->definitionContext(); - assert(dc); - StringList globalMetaData = dc->getMetaData(); - string file = dc->filename(); - static const string prefix = "cpp:"; - for(StringList::const_iterator q = globalMetaData.begin(); q != globalMetaData.end(); ++q) - { - string s = *q; - if(_history.count(s) == 0) - { - if(s.find(prefix) == 0) - { - string ss = s.substr(prefix.size()); - if(ss.find("include:") == 0) - { - continue; - } - cout << file << ": warning: ignoring invalid global metadata `" << s << "'" << endl; - } - _history.insert(s); - } - } - - validate(p, p->getMetaData(), p->definitionContext()->filename(), p->line()); - return true; -} - -void -Slice::Gen::MetaDataVisitor::visitModuleEnd(const ModulePtr&) -{ -} - -void -Slice::Gen::MetaDataVisitor::visitClassDecl(const ClassDeclPtr& p) -{ - validate(p, p->getMetaData(), p->definitionContext()->filename(), p->line()); -} - -bool -Slice::Gen::MetaDataVisitor::visitClassDefStart(const ClassDefPtr& p) -{ - validate(p, p->getMetaData(), p->definitionContext()->filename(), p->line()); - return true; -} - -void -Slice::Gen::MetaDataVisitor::visitClassDefEnd(const ClassDefPtr&) -{ -} - -bool -Slice::Gen::MetaDataVisitor::visitExceptionStart(const ExceptionPtr& p) -{ - validate(p, p->getMetaData(), p->definitionContext()->filename(), p->line()); - return true; -} - -void -Slice::Gen::MetaDataVisitor::visitExceptionEnd(const ExceptionPtr&) -{ -} - -bool -Slice::Gen::MetaDataVisitor::visitStructStart(const StructPtr& p) -{ - validate(p, p->getMetaData(), p->definitionContext()->filename(), p->line()); - return true; -} - -void -Slice::Gen::MetaDataVisitor::visitStructEnd(const StructPtr&) -{ -} - -void -Slice::Gen::MetaDataVisitor::visitOperation(const OperationPtr& p) -{ - StringList metaData = p->getMetaData(); - metaData.remove("cpp:const"); - - TypePtr returnType = p->returnType(); - if(!metaData.empty()) - { - if(!returnType) - { - for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); ++q) - { - if(q->find("cpp:type:", 0) == 0 || q->find("cpp:array", 0) == 0 || q->find("cpp:range", 0) == 0) - { - cout << p->definitionContext()->filename() << ":" << p->line() - << ": warning: invalid metadata for operation" << endl; - break; - } - } - } - else - { - validate(returnType, metaData, p->definitionContext()->filename(), p->line(), false); - } - } - - ParamDeclList params = p->parameters(); - for(ParamDeclList::iterator q = params.begin(); q != params.end(); ++q) - { - validate((*q)->type(), (*q)->getMetaData(), p->definitionContext()->filename(), (*q)->line(), - !(*q)->isOutParam()); - } -} - -void -Slice::Gen::MetaDataVisitor::visitParamDecl(const ParamDeclPtr& p) -{ - validate(p, p->getMetaData(), p->definitionContext()->filename(), p->line()); -} - -void -Slice::Gen::MetaDataVisitor::visitDataMember(const DataMemberPtr& p) -{ - validate(p->type(), p->getMetaData(), p->definitionContext()->filename(), p->line()); -} - -void -Slice::Gen::MetaDataVisitor::visitSequence(const SequencePtr& p) -{ - validate(p, p->getMetaData(), p->definitionContext()->filename(), p->line()); -} - -void -Slice::Gen::MetaDataVisitor::visitDictionary(const DictionaryPtr& p) -{ - validate(p, p->getMetaData(), p->definitionContext()->filename(), p->line()); -} - -void -Slice::Gen::MetaDataVisitor::visitEnum(const EnumPtr& p) -{ - validate(p, p->getMetaData(), p->definitionContext()->filename(), p->line()); -} - -void -Slice::Gen::MetaDataVisitor::visitConst(const ConstPtr& p) -{ - validate(p, p->getMetaData(), p->definitionContext()->filename(), p->line()); -} - -void -Slice::Gen::MetaDataVisitor::validate(const SyntaxTreeBasePtr& cont, const StringList& metaData, - const string& file, const string& line, bool inParam) -{ - static const string prefix = "cpp:"; - for(StringList::const_iterator p = metaData.begin(); p != metaData.end(); ++p) - { - string s = *p; - if(_history.count(s) == 0) - { - if(s.find(prefix) == 0) - { - string ss = s.substr(prefix.size()); - if(ss.find("type:string") == 0 || ss.find("type:wstring") == 0) - { - BuiltinPtr builtin = BuiltinPtr::dynamicCast(cont); - ModulePtr module = ModulePtr::dynamicCast(cont); - ClassDefPtr clss = ClassDefPtr::dynamicCast(cont); - StructPtr strct = StructPtr::dynamicCast(cont); - ExceptionPtr exception = ExceptionPtr::dynamicCast(cont); - if((builtin && builtin->kind() == Builtin::KindString) || module || clss || strct || exception) - { - continue; - } - } - if(SequencePtr::dynamicCast(cont)) - { - if(ss.find("type:") == 0 || (inParam && (ss == "array" || ss.find("range") == 0))) - { - continue; - } - } - cout << file << ":" << line << ": warning: ignoring invalid metadata `" << s << "'" << endl; - } - _history.insert(s); - } - } -} - -void -Slice::Gen::validateMetaData(const UnitPtr& u) -{ - MetaDataVisitor visitor; - u->visit(&visitor, false); -} - -bool -Slice::Gen::setUseWstring(ContainedPtr p, list& hist, bool use) -{ - hist.push_back(use); - StringList metaData = p->getMetaData(); - if(find(metaData.begin(), metaData.end(), "cpp:type:wstring") != metaData.end()) - { - use = true; - } - else if(find(metaData.begin(), metaData.end(), "cpp:type:string") != metaData.end()) - { - use = false; - } - return use; -} - -bool -Slice::Gen::resetUseWstring(list& hist) -{ - bool use = hist.back(); - hist.pop_back(); - return use; -} - -void -Slice::Gen::printHeader(Output& out) -{ - static const char* header = -"// **********************************************************************\n" -"//\n" -"// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.\n" -"//\n" -"// This copy of Ice-E is licensed to you under the terms described in the\n" -"// ICEE_LICENSE file included in this distribution.\n" -"//\n" -"// **********************************************************************\n" - ; - - out << header; - out << "\n// Ice-E version " << ICEE_STRING_VERSION; -} - -void -Slice::Gen::printVersionCheck(Output& out) -{ - out << "\n"; - out << "\n#ifndef ICEE_IGNORE_VERSION"; - out << "\n# if ICEE_INT_VERSION / 100 != " << ICEE_INT_VERSION / 100; - out << "\n# error IceE version mismatch!"; - out << "\n# endif"; - out << "\n# if ICEE_INT_VERSION % 100 < " << ICEE_INT_VERSION % 100; - out << "\n# error IceE patch level mismatch!"; - out << "\n# endif"; - out << "\n#endif"; -} - -void -Slice::Gen::printDllExportStuff(Output& out, const string& dllExport) -{ - if(dllExport.size()) - { - out << sp; - out << "\n#ifndef " << dllExport; - out << "\n# ifdef " << dllExport << "_EXPORTS"; - out << "\n# define " << dllExport << " ICE_DECLSPEC_EXPORT"; - out << "\n# else"; - out << "\n# define " << dllExport << " ICE_DECLSPEC_IMPORT"; - out << "\n# endif"; - out << "\n#endif"; - } -} diff --git a/cpp/src/slice2cppe/Gen.h b/cpp/src/slice2cppe/Gen.h deleted file mode 100644 index 3cba14ccee6..00000000000 --- a/cpp/src/slice2cppe/Gen.h +++ /dev/null @@ -1,307 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -#ifndef GEN_H -#define GEN_H - -#include -#include - -// -// The Ice-E version. -// -#define ICEE_STRING_VERSION "1.2.0" // "A.B.C", with A=major, B=minor, C=patch -#define ICEE_INT_VERSION 10200 // AABBCC, with AA=major, BB=minor, CC=patch - -namespace Slice -{ - -class Gen : private ::IceUtil::noncopyable -{ -public: - - Gen(const std::string&, - const std::string&, - const std::string&, - const std::string&, - const std::vector&, - const std::string&, - const std::vector&, - const std::string&, - const std::string&, - bool, - bool); - ~Gen(); - - bool operator!() const; // Returns true if there was a constructor error - - void generate(const UnitPtr&); - void closeOutput(); - static bool setUseWstring(ContainedPtr, std::list&, bool); - static bool resetUseWstring(std::list&); - -private: - - void writeExtraHeaders(::IceUtilInternal::Output&); - - ::IceUtilInternal::Output H; - ::IceUtilInternal::Output C; - - ::IceUtilInternal::Output implH; - ::IceUtilInternal::Output implC; - - std::string _base; - std::string _headerExtension; - std::string _sourceExtension; - std::vector _extraHeaders; - std::string _include; - std::vector _includePaths; - std::string _dllExport; - bool _impl; - bool _ice; - - class GlobalIncludeVisitor : private ::IceUtil::noncopyable, public ParserVisitor - { - public: - - GlobalIncludeVisitor(::IceUtilInternal::Output&); - - virtual bool visitModuleStart(const ModulePtr&); - - private: - - ::IceUtilInternal::Output& H; - - bool _finished; - }; - - class TypesVisitor : private ::IceUtil::noncopyable, public ParserVisitor - { - public: - - TypesVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&, const std::string&); - - virtual bool visitModuleStart(const ModulePtr&); - virtual void visitModuleEnd(const ModulePtr&); - virtual bool visitClassDefStart(const ClassDefPtr&); - virtual bool visitExceptionStart(const ExceptionPtr&); - virtual void visitExceptionEnd(const ExceptionPtr&); - virtual bool visitStructStart(const StructPtr&); - virtual void visitStructEnd(const StructPtr&); - virtual void visitSequence(const SequencePtr&); - virtual void visitDictionary(const DictionaryPtr&); - virtual void visitEnum(const EnumPtr&); - virtual void visitConst(const ConstPtr&); - virtual void visitDataMember(const DataMemberPtr&); - - private: - - void emitUpcall(const ExceptionPtr&, const std::string&, bool = false); - - ::IceUtilInternal::Output& H; - ::IceUtilInternal::Output& C; - - std::string _dllExport; - bool _doneStaticSymbol; - bool _useWstring; - std::list _useWstringHist; - }; - - class ProxyDeclVisitor : private ::IceUtil::noncopyable, public ParserVisitor - { - public: - - ProxyDeclVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&, const std::string&); - - virtual bool visitUnitStart(const UnitPtr&); - virtual void visitUnitEnd(const UnitPtr&); - virtual bool visitModuleStart(const ModulePtr&); - virtual void visitModuleEnd(const ModulePtr&); - virtual void visitClassDecl(const ClassDeclPtr&); - - private: - - ::IceUtilInternal::Output& H; - ::IceUtilInternal::Output& C; - - std::string _dllExport; - }; - - class ProxyVisitor : private ::IceUtil::noncopyable, public ParserVisitor - { - public: - - ProxyVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&, const std::string&); - - virtual bool visitUnitStart(const UnitPtr&); - virtual void visitUnitEnd(const UnitPtr&); - virtual bool visitModuleStart(const ModulePtr&); - virtual void visitModuleEnd(const ModulePtr&); - virtual bool visitClassDefStart(const ClassDefPtr&); - virtual void visitClassDefEnd(const ClassDefPtr&); - virtual void visitOperation(const OperationPtr&); - - private: - - ::IceUtilInternal::Output& H; - ::IceUtilInternal::Output& C; - - std::string _dllExport; - bool _useWstring; - std::list _useWstringHist; - }; - - class ObjectDeclVisitor : private ::IceUtil::noncopyable, public ParserVisitor - { - public: - - ObjectDeclVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&, const std::string&); - - virtual bool visitModuleStart(const ModulePtr&); - virtual void visitModuleEnd(const ModulePtr&); - virtual void visitClassDecl(const ClassDeclPtr&); - - private: - - ::IceUtilInternal::Output& H; - ::IceUtilInternal::Output& C; - - std::string _dllExport; - }; - - class ObjectVisitor : private ::IceUtil::noncopyable, public ParserVisitor - { - public: - - ObjectVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&, const std::string&); - - virtual bool visitModuleStart(const ModulePtr&); - virtual void visitModuleEnd(const ModulePtr&); - virtual bool visitClassDefStart(const ClassDefPtr&); - virtual void visitClassDefEnd(const ClassDefPtr&); - virtual bool visitExceptionStart(const ExceptionPtr&); - virtual bool visitStructStart(const StructPtr&); - virtual void visitOperation(const OperationPtr&); - virtual void visitDataMember(const DataMemberPtr&); - - private: - - bool emitVirtualBaseInitializers(const ClassDefPtr&); - void emitOneShotConstructor(const ClassDefPtr&); - void emitUpcall(const ClassDefPtr&, const std::string&); - - ::IceUtilInternal::Output& H; - ::IceUtilInternal::Output& C; - - std::string _dllExport; - bool _useWstring; - std::list _useWstringHist; - }; - - class IceInternalVisitor : private ::IceUtil::noncopyable, public ParserVisitor - { - public: - - IceInternalVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&, const std::string&); - - virtual bool visitUnitStart(const UnitPtr&); - virtual void visitUnitEnd(const UnitPtr&); - virtual void visitClassDecl(const ClassDeclPtr&); - virtual bool visitClassDefStart(const ClassDefPtr&); - - private: - - ::IceUtilInternal::Output& H; - ::IceUtilInternal::Output& C; - - std::string _dllExport; - }; - - class HandleVisitor : private ::IceUtil::noncopyable, public ParserVisitor - { - public: - - HandleVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&, const std::string&); - - virtual bool visitModuleStart(const ModulePtr&); - virtual void visitModuleEnd(const ModulePtr&); - virtual void visitClassDecl(const ClassDeclPtr&); - virtual bool visitClassDefStart(const ClassDefPtr&); - - private: - - ::IceUtilInternal::Output& H; - ::IceUtilInternal::Output& C; - - std::string _dllExport; - }; - - class ImplVisitor : private ::IceUtil::noncopyable, public ParserVisitor - { - public: - - ImplVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&, const std::string&); - - virtual bool visitModuleStart(const ModulePtr&); - virtual void visitModuleEnd(const ModulePtr&); - virtual bool visitClassDefStart(const ClassDefPtr&); - - private: - - ::IceUtilInternal::Output& H; - ::IceUtilInternal::Output& C; - - std::string _dllExport; - bool _useWstring; - std::list _useWstringHist; - - // - // Generate code to return a dummy value - // - void writeReturn(::IceUtilInternal::Output&, const TypePtr&, const StringList&); - }; - - class MetaDataVisitor : public ParserVisitor - { - public: - - virtual bool visitModuleStart(const ModulePtr&); - virtual void visitModuleEnd(const ModulePtr&); - virtual void visitClassDecl(const ClassDeclPtr&); - virtual bool visitClassDefStart(const ClassDefPtr&); - virtual void visitClassDefEnd(const ClassDefPtr&); - virtual bool visitExceptionStart(const ExceptionPtr&); - virtual void visitExceptionEnd(const ExceptionPtr&); - virtual bool visitStructStart(const StructPtr&); - virtual void visitStructEnd(const StructPtr&); - virtual void visitOperation(const OperationPtr&); - virtual void visitParamDecl(const ParamDeclPtr&); - virtual void visitDataMember(const DataMemberPtr&); - virtual void visitSequence(const SequencePtr&); - virtual void visitDictionary(const DictionaryPtr&); - virtual void visitEnum(const EnumPtr&); - virtual void visitConst(const ConstPtr&); - - private: - - void validate(const SyntaxTreeBasePtr&, const StringList&, const std::string&, const std::string&, - bool = false); - - StringSet _history; - }; - - static void validateMetaData(const UnitPtr&); - static void printHeader(IceUtilInternal::Output&); - static void printVersionCheck(IceUtilInternal::Output&); - static void printDllExportStuff(IceUtilInternal::Output&, const std::string&); -}; - -} - -#endif diff --git a/cpp/src/slice2cppe/Main.cpp b/cpp/src/slice2cppe/Main.cpp deleted file mode 100644 index 89f9ddf24ca..00000000000 --- a/cpp/src/slice2cppe/Main.cpp +++ /dev/null @@ -1,209 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -#include -#include -#include -#include - -using namespace std; -using namespace Slice; - -void -usage(const char* n) -{ - cerr << "Usage: " << n << " [options] slice-files...\n"; - cerr << - "Options:\n" - "-h, --help Show this message.\n" - "-v, --version Display the Ice version.\n" - "--header-ext EXT Use EXT instead of the default `h' extension.\n" - "--source-ext EXT Use EXT instead of the default `cpp' extension.\n" - "--add-header HDR[,GUARD] Add #include for HDR (with guard GUARD) to generated source file.\n" - "-DNAME Define NAME as 1.\n" - "-DNAME=DEF Define NAME as DEF.\n" - "-UNAME Remove any definition for NAME.\n" - "-IDIR Put DIR in the include file search path.\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" - "--impl Generate sample implementations.\n" - "--depend Generate Makefile dependencies.\n" - "-d, --debug Print debug messages.\n" - "--ice Permit `Ice' prefix (for building Ice source code only)\n" - ; - // Note: --case-sensitive is intentionally not shown here! -} - -int -main(int argc, char* argv[]) -{ - IceUtilInternal::Options opts; - opts.addOpt("h", "help"); - opts.addOpt("v", "version"); - opts.addOpt("", "header-ext", IceUtilInternal::Options::NeedArg, "h"); - opts.addOpt("", "source-ext", IceUtilInternal::Options::NeedArg, "cpp"); - opts.addOpt("", "add-header", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); - opts.addOpt("D", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); - opts.addOpt("U", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); - opts.addOpt("I", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); - 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("", "impl"); - opts.addOpt("", "depend"); - opts.addOpt("d", "debug"); - opts.addOpt("", "ice"); - opts.addOpt("", "case-sensitive"); - - vector args; - try - { - args = opts.parse(argc, (const char**)argv); - } - catch(const IceUtilInternal::BadOptException& e) - { - cerr << argv[0] << ": " << e.reason << endl; - usage(argv[0]); - return EXIT_FAILURE; - } - - if(opts.isSet("help")) - { - usage(argv[0]); - return EXIT_SUCCESS; - } - - if(opts.isSet("version")) - { - cout << ICEE_STRING_VERSION << endl; - return EXIT_SUCCESS; - } - - string headerExtension = opts.optArg("header-ext"); - string sourceExtension = opts.optArg("source-ext"); - - vectorextraHeaders = opts.argVec("add-header"); - - vector cppArgs; - vector optargs = opts.argVec("D"); - vector::const_iterator i; - for(i = optargs.begin(); i != optargs.end(); ++i) - { - cppArgs.push_back("-D" + *i); - } - - optargs = opts.argVec("U"); - for(i = optargs.begin(); i != optargs.end(); ++i) - { - cppArgs.push_back("-U" + *i); - } - - vector includePaths = opts.argVec("I"); - for(i = includePaths.begin(); i != includePaths.end(); ++i) - { - cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(*i)); - } - - bool preprocess = opts.isSet("E"); - - string include = opts.optArg("include-dir"); - - string output = opts.optArg("output-dir"); - - string dllExport = opts.optArg("dll-export"); - - bool impl = opts.isSet("impl"); - - bool depend = opts.isSet("depend"); - - bool debug = opts.isSet("debug"); - - bool ice = opts.isSet("ice"); - - bool caseSensitive = opts.isSet("case-sensitive"); - - if(args.empty()) - { - cerr << argv[0] << ": no input file" << endl; - usage(argv[0]); - return EXIT_FAILURE; - } - - int status = EXIT_SUCCESS; - - for(i = args.begin(); i != args.end(); ++i) - { - SignalHandler sigHandler; - - if(depend) - { - Preprocessor icecpp(argv[0], *i, cppArgs); - icecpp.printMakefileDependencies(Preprocessor::CPlusPlus, includePaths); - } - else - { - Preprocessor icecpp(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp.preprocess(false); - - if(cppHandle == 0) - { - return EXIT_FAILURE; - } - if(preprocess) - { - char buf[4096]; - while(fgets(buf, static_cast(sizeof(buf)), cppHandle) != NULL) - { - if(fputs(buf, stdout) == EOF) - { - return EXIT_FAILURE; - } - } - if(!icecpp.close()) - { - return EXIT_FAILURE; - } - } - else - { - UnitPtr u = Unit::createUnit(false, false, ice, caseSensitive); - int parseStatus = u->parse(*i, cppHandle, debug, Slice::IceE); - - if(!icecpp.close()) - { - u->destroy(); - return EXIT_FAILURE; - } - - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; - } - else - { - Gen gen(argv[0], icecpp.getBaseName(), headerExtension, sourceExtension, extraHeaders, include, - includePaths, dllExport, output, impl, ice); - if(!gen) - { - u->destroy(); - return EXIT_FAILURE; - } - gen.generate(u); - } - - u->destroy(); - } - } - } - - return status; -} diff --git a/cpp/src/slice2cppe/Makefile b/cpp/src/slice2cppe/Makefile deleted file mode 100644 index 6cecfbf2033..00000000000 --- a/cpp/src/slice2cppe/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -# ********************************************************************** -# -# Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. -# -# This copy of Ice is licensed to you under the terms described in the -# ICE_LICENSE file included in this distribution. -# -# ********************************************************************** - -top_srcdir = ../.. - -NAME = $(top_srcdir)/bin/slice2cppe - -TARGETS = $(NAME) - -OBJS = Gen.o \ - Main.o - -SRCS = $(OBJS:.o=.cpp) - -include $(top_srcdir)/config/Make.rules - -CPPFLAGS := -I. $(CPPFLAGS) - -$(NAME): $(OBJS) - rm -f $@ - $(CXX) $(LDFLAGS) -o $@ $(OBJS) -lSlice $(BASELIBS) $(MCPP_RPATH_LINK) - -install:: all - $(INSTALL_PROGRAM) $(NAME) $(install_bindir) - -include .depend diff --git a/cpp/src/slice2cppe/Makefile.mak b/cpp/src/slice2cppe/Makefile.mak deleted file mode 100644 index 40d52ace566..00000000000 --- a/cpp/src/slice2cppe/Makefile.mak +++ /dev/null @@ -1,61 +0,0 @@ -# ********************************************************************** -# -# Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. -# -# This copy of Ice is licensed to you under the terms described in the -# ICE_LICENSE file included in this distribution. -# -# ********************************************************************** - -top_srcdir = ..\.. - -NAME = $(top_srcdir)\bin\slice2cppe.exe - -TARGETS = $(NAME) - -OBJS = Gen.obj \ - Main.obj - -SRCS = $(OBJS:.obj=.cpp) - -!include $(top_srcdir)/config/Make.rules.mak - -CPPFLAGS = -I. $(CPPFLAGS) -DWIN32_LEAN_AND_MEAN - -!if "$(GENERATE_PDB)" == "yes" -PDBFLAGS = /pdb:$(NAME:.exe=.pdb) -!endif - -!if "$(CPP_COMPILER)" == "BCC2007" -RES_FILE = ,, Slice2CppE.res -!else -RES_FILE = Slice2CppE.res -!endif - -$(NAME): $(OBJS) Slice2CppE.res - $(LINK) $(LD_EXEFLAGS) $(PDBFLAGS) $(OBJS) $(SETARGV) $(PREOUT)$@ $(PRELIBS)slice$(LIBSUFFIX).lib \ - $(BASELIBS) $(RES_FILE) - @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) && \ - $(MT) -nologo -manifest $@.manifest -outputresource:$@;#1 && del /q $@.manifest - -clean:: - del /q $(NAME:.exe=.*) - del /q Slice2CppE.res - -install:: all - copy $(NAME) $(install_bindir) - - -!if "$(CPP_COMPILER)" == "BCC2007" && "$(OPTIMIZE)" != "yes" - -install:: all - copy $(NAME:.exe=.tds) $(install_bindir) - -!elseif "$(GENERATE_PDB)" == "yes" - -install:: all - copy $(NAME:.exe=.pdb) $(install_bindir) - -!endif - -!include .depend diff --git a/cpp/src/slice2cppe/Slice2CppE.rc b/cpp/src/slice2cppe/Slice2CppE.rc deleted file mode 100644 index 8c8dba404e8..00000000000 --- a/cpp/src/slice2cppe/Slice2CppE.rc +++ /dev/null @@ -1,34 +0,0 @@ -#include "winver.h" - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 3,3,0,0 - PRODUCTVERSION 3,3,0,0 - FILEFLAGSMASK VS_FFI_FILEFLAGSMASK -#ifdef _DEBUG - FILEFLAGS VS_FF_DEBUG -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE VFT_APP - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904e4" - BEGIN - VALUE "CompanyName", "ZeroC, Inc.\0" - VALUE "FileDescription", "Slice To C++ Translator\0" - VALUE "FileVersion", "3.3.0\0" - VALUE "InternalName", "slice2cppe\0" - VALUE "LegalCopyright", "Copyright (c) 2003 - 2008 ZeroC, Inc. All rights reserved.\0" - VALUE "OriginalFilename", "slice2cppe.exe\0" - VALUE "ProductName", "Ice-E\0" - VALUE "ProductVersion", "3.3.0\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1252 - END -END diff --git a/cpp/src/slice2javae/.depend b/cpp/src/slice2javae/.depend deleted file mode 100644 index 15803d2ade9..00000000000 --- a/cpp/src/slice2javae/.depend +++ /dev/null @@ -1,2 +0,0 @@ -Gen$(OBJEXT): Gen.cpp $(includedir)/IceUtil/DisableWarnings.h ./Gen.h $(includedir)/Slice/Parser.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Slice/JavaUtil.h $(includedir)/IceUtil/OutputUtil.h $(includedir)/IceUtil/Functional.h $(includedir)/IceUtil/Iterator.h -Main$(OBJEXT): Main.cpp $(includedir)/IceUtil/Options.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/RecMutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Exception.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Handle.h $(includedir)/Slice/Preprocessor.h $(includedir)/Slice/SignalHandler.h ./Gen.h $(includedir)/Slice/Parser.h $(includedir)/Slice/JavaUtil.h $(includedir)/IceUtil/OutputUtil.h diff --git a/cpp/src/slice2javae/Gen.cpp b/cpp/src/slice2javae/Gen.cpp deleted file mode 100644 index 59f91cb361d..00000000000 --- a/cpp/src/slice2javae/Gen.cpp +++ /dev/null @@ -1,3184 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -#include -#include -#include -#include -#include - -#include - -using namespace std; -using namespace Slice; - -// -// Don't use "using namespace IceUtil", or VC++ 6.0 complains -// about ambigious symbols for constructs like -// "IceUtil::constMemFun(&Slice::Exception::isLocal)". -// -using IceUtilInternal::Output; -using IceUtilInternal::nl; -using IceUtilInternal::sp; -using IceUtilInternal::sb; -using IceUtilInternal::eb; -using IceUtilInternal::spar; -using IceUtilInternal::epar; - -static string -sliceModeToIceMode(Operation::Mode opMode) -{ - string mode; - switch(opMode) - { - case Operation::Normal: - { - mode = "Ice.OperationMode.Normal"; - break; - } - case Operation::Nonmutating: - { - mode = "Ice.OperationMode.Nonmutating"; - break; - } - case Operation::Idempotent: - { - mode = "Ice.OperationMode.Idempotent"; - break; - } - default: - { - assert(false); - break; - } - } - return mode; -} - -static string -getDeprecateReason(const ContainedPtr& p1, const ContainedPtr& p2, const string& type) -{ - string deprecateMetadata, deprecateReason; - if(p1->findMetaData("deprecate", deprecateMetadata) || - (p2 != 0 && p2->findMetaData("deprecate", deprecateMetadata))) - { - deprecateReason = "This " + type + " has been deprecated."; - if(deprecateMetadata.find("deprecate:") == 0 && deprecateMetadata.size() > 10) - { - deprecateReason = deprecateMetadata.substr(10); - } - } - return deprecateReason; -} - -void -Slice::JavaEOutput::printHeader() -{ - static const char* header = -"// **********************************************************************\n" -"//\n" -"// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.\n" -"//\n" -"// This copy of Ice-E is licensed to you under the terms described in the\n" -"// ICEE_LICENSE file included in this distribution.\n" -"//\n" -"// **********************************************************************\n" - ; - - print(header); - print("\n// Ice-E version "); - print(ICEE_STRING_VERSION); -} - -Slice::JavaVisitor::JavaVisitor(const string& dir) : - JavaGenerator(dir, Slice::IceE) -{ -} - -Slice::JavaVisitor::~JavaVisitor() -{ -} - -JavaOutput* -Slice::JavaVisitor::createOutput() -{ - return new JavaEOutput; -} - -vector -Slice::JavaVisitor::getParams(const OperationPtr& op, const string& package) -{ - vector params; - - ParamDeclList paramList = op->parameters(); - for(ParamDeclList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) - { - StringList metaData = (*q)->getMetaData(); - string typeString = typeToString((*q)->type(), (*q)->isOutParam() ? TypeModeOut : TypeModeIn, package, - metaData); - params.push_back(typeString + ' ' + fixKwd((*q)->name())); - } - - return params; -} - -vector -Slice::JavaVisitor::getArgs(const OperationPtr& op) -{ - vector args; - - ParamDeclList paramList = op->parameters(); - for(ParamDeclList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) - { - args.push_back(fixKwd((*q)->name())); - } - - return args; -} - -void -Slice::JavaVisitor::writeThrowsClause(const string& package, const ExceptionList& throws) -{ - Output& out = output(); - if(throws.size() > 0) - { - out.inc(); - out << nl << "throws "; - out.useCurrentPosAsIndent(); - ExceptionList::const_iterator r; - int count = 0; - for(r = throws.begin(); r != throws.end(); ++r) - { - if(count > 0) - { - out << "," << nl; - } - out << getAbsolute(*r, package); - count++; - } - out.restoreIndent(); - out.dec(); - } -} - -void -Slice::JavaVisitor::writeHashCode(Output& out, const TypePtr& type, const string& name, int& iter) -{ - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - switch(builtin->kind()) - { - case Builtin::KindByte: - case Builtin::KindShort: - case Builtin::KindLong: - { - out << nl << "__h = 5 * __h + (int)" << name << ';'; - break; - } - case Builtin::KindBool: - { - out << nl << "__h = 5 * __h + (" << name << " ? 1 : 0);"; - break; - } - case Builtin::KindInt: - { - out << nl << "__h = 5 * __h + " << name << ';'; - break; - } - case Builtin::KindFloat: - { - out << nl << "__h = 5 * __h + java.lang.Float.floatToIntBits(" << name << ");"; - break; - } - case Builtin::KindDouble: - { - out << nl << "__h = 5 * __h + (int)java.lang.Double.doubleToLongBits(" << name << ");"; - break; - } - case Builtin::KindString: - { - out << nl << "if(" << name << " != null)"; - out << sb; - out << nl << "__h = 5 * __h + " << name << ".hashCode();"; - out << eb; - break; - } - case Builtin::KindObject: - case Builtin::KindObjectProxy: - case Builtin::KindLocalObject: - { - out << nl << "if(" << name << " != null)"; - out << sb; - out << nl << "__h = 5 * __h + " << name << ".hashCode();"; - out << eb; - break; - } - } - return; - } - - ProxyPtr prx = ProxyPtr::dynamicCast(type); - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); - DictionaryPtr dict = DictionaryPtr::dynamicCast(type); - if(prx || cl || dict) - { - out << nl << "if(" << name << " != null)"; - out << sb; - out << nl << "__h = 5 * __h + " << name << ".hashCode();"; - out << eb; - return; - } - - SequencePtr seq = SequencePtr::dynamicCast(type); - if(seq) - { - out << nl << "if(" << name << " != null)"; - out << sb; - out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < " << name << ".length; __i" << iter - << "++)"; - out << sb; - ostringstream elem; - elem << name << "[__i" << iter << ']'; - iter++; - writeHashCode(out, seq->type(), elem.str(), iter); - out << eb; - out << eb; - return; - } - - ConstructedPtr constructed = ConstructedPtr::dynamicCast(type); - assert(constructed); - out << nl << "__h = 5 * __h + " << name << ".hashCode();"; -} - -void -Slice::JavaVisitor::writeDispatch(Output& out, const ClassDefPtr& p) -{ - string name = fixKwd(p->name()); - string package = getPackage(p); - string scoped = p->scoped(); - ClassList bases = p->bases(); - - ClassList allBases = p->allBases(); - StringList ids; - transform(allBases.begin(), allBases.end(), back_inserter(ids), ::IceUtil::constMemFun(&Contained::scoped)); - StringList other; - other.push_back(scoped); - other.push_back("::Ice::Object"); - other.sort(); - ids.merge(other); - ids.unique(); - StringList::const_iterator firstIter = ids.begin(); - StringList::const_iterator scopedIter = find(ids.begin(), ids.end(), scoped); - assert(scopedIter != ids.end()); - StringList::difference_type scopedPos = IceUtilInternal::distance(firstIter, scopedIter); - - out << sp << nl << "public static final String[] __ids ="; - out << sb; - - { - StringList::const_iterator q = ids.begin(); - while(q != ids.end()) - { - out << nl << '"' << *q << '"'; - if(++q != ids.end()) - { - out << ','; - } - } - } - out << eb << ';'; - - out << sp << nl << "public boolean" << nl << "ice_isA(String s)"; - out << sb; - out << nl << "return IceUtil.Arrays.search(__ids, s) >= 0;"; - out << eb; - - out << sp << nl << "public boolean" << nl << "ice_isA(String s, Ice.Current __current)"; - out << sb; - out << nl << "return IceUtil.Arrays.search(__ids, s) >= 0;"; - out << eb; - - out << sp << nl << "public String[]" << nl << "ice_ids()"; - out << sb; - out << nl << "return __ids;"; - out << eb; - - out << sp << nl << "public String[]" << nl << "ice_ids(Ice.Current __current)"; - out << sb; - out << nl << "return __ids;"; - out << eb; - - out << sp << nl << "public String" << nl << "ice_id()"; - out << sb; - out << nl << "return __ids[" << scopedPos << "];"; - out << eb; - - out << sp << nl << "public String" << nl << "ice_id(Ice.Current __current)"; - out << sb; - out << nl << "return __ids[" << scopedPos << "];"; - out << eb; - - out << sp << nl << "public static String" << nl << "ice_staticId()"; - out << sb; - out << nl << "return __ids[" << scopedPos << "];"; - out << eb; - - OperationList ops = p->allOperations(); - OperationList::const_iterator r; - - // - // Write the "no Current" implementation of each operation. - // - for(r = ops.begin(); r != ops.end(); ++r) - { - OperationPtr op = *r; - string opName = op->name(); - - ContainerPtr container = op->container(); - ClassDefPtr cl = ClassDefPtr::dynamicCast(container); - assert(cl); - - vector params; - vector args; - TypePtr ret; - - opName = fixKwd(opName); - ret = op->returnType(); - params = getParams(op, package); - args = getArgs(op); - - ExceptionList throws = op->throws(); - throws.sort(); - throws.unique(); - - // - // Only generate a "no current" version of the operation if it hasn't been done in a base - // class already, because the "no current" version is final. - // - bool generateOperation = cl == p; // Generate if the operation is defined in this class. - if(!generateOperation) - { - // - // The operation is not defined in this class. - // - if(!bases.empty()) - { - // - // Check if the operation is already implemented by a base class. - // - bool implementedByBase = false; - if(!bases.front()->isInterface()) - { - OperationList baseOps = bases.front()->allOperations(); - OperationList::const_iterator i; - for(i = baseOps.begin(); i != baseOps.end(); ++i) - { - if((*i)->name() == op->name()) - { - implementedByBase = true; - break; - } - } - if(i == baseOps.end()) - { - generateOperation = true; - } - } - if(!generateOperation && !implementedByBase) - { - // - // No base class defines the operation. Check if one of the - // interfaces defines it, in which case this class must provide it. - // - if(bases.front()->isInterface() || bases.size() > 1) - { - generateOperation = true; - } - } - } - } - if(generateOperation) - { - out << sp << nl << "public final " << typeToString(ret, TypeModeReturn, package, op->getMetaData()) - << nl << opName << spar << params << epar; - writeThrowsClause(package, throws); - out << sb << nl; - if(ret) - { - out << nl << "return "; - } - out << opName << spar << args << "null" << epar << ';'; - out << eb; - } - } - - // - // Dispatch operations. We only generate methods for operations - // defined in this ClassDef, because we reuse existing methods - // for inherited operations. - // - ops = p->operations(); - for(r = ops.begin(); r != ops.end(); ++r) - { - OperationPtr op = *r; - StringList opMetaData = op->getMetaData(); - ContainerPtr container = op->container(); - ClassDefPtr cl = ClassDefPtr::dynamicCast(container); - assert(cl); - - string opName = op->name(); - out << sp << nl << "public static Ice.DispatchStatus" << nl << "___" << opName << '(' << name - << " __obj, IceInternal.Incoming __in, Ice.Current __current)"; - out << sb; - - TypePtr ret = op->returnType(); - - ParamDeclList inParams; - ParamDeclList outParams; - ParamDeclList paramList = op->parameters(); - ParamDeclList::const_iterator pli; - for(pli = paramList.begin(); pli != paramList.end(); ++pli) - { - if((*pli)->isOutParam()) - { - outParams.push_back(*pli); - } - else - { - inParams.push_back(*pli); - } - } - - ExceptionList throws = op->throws(); - throws.sort(); - throws.unique(); - - // - // Arrange exceptions into most-derived to least-derived order. If we don't - // do this, a base exception handler can appear before a derived exception - // handler, causing compiler warnings and resulting in the base exception - // being marshaled instead of the derived exception. - // -#if defined(__SUNPRO_CC) - throws.sort(Slice::derivedToBaseCompare); -#else - throws.sort(Slice::DerivedToBaseCompare()); -#endif - - int iter; - - out << nl << "__checkMode(" << sliceModeToIceMode(op->mode()) << ", __current.mode);"; - if(!inParams.empty()) - { - out << nl << "IceInternal.BasicStream __is = __in.is();"; - } - if(!outParams.empty() || ret || !throws.empty()) - { - out << nl << "IceInternal.BasicStream __os = __in.os();"; - } - - // - // Unmarshal 'in' parameters. - // - iter = 0; - for(pli = inParams.begin(); pli != inParams.end(); ++pli) - { - StringList metaData = (*pli)->getMetaData(); - TypePtr paramType = (*pli)->type(); - string paramName = fixKwd((*pli)->name()); - string typeS = typeToString(paramType, TypeModeIn, package, metaData); - BuiltinPtr builtin = BuiltinPtr::dynamicCast(paramType); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(paramType)) - { - out << nl << typeS << "Holder " << paramName << " = new " << typeS << "Holder();"; - writeMarshalUnmarshalCode(out, package, paramType, paramName, false, iter, true, - metaData, string()); - } - else - { - out << nl << typeS << ' ' << paramName << ';'; - writeMarshalUnmarshalCode(out, package, paramType, paramName, false, iter, false, metaData); - } - } - - // - // Create holders for 'out' parameters. - // - for(pli = outParams.begin(); pli != outParams.end(); ++pli) - { - string typeS = typeToString((*pli)->type(), TypeModeOut, package, (*pli)->getMetaData()); - out << nl << typeS << ' ' << fixKwd((*pli)->name()) << " = new " << typeS << "();"; - } - - // - // Call on the servant. - // - if(!throws.empty()) - { - out << nl << "try"; - out << sb; - } - out << nl; - if(ret) - { - string retS = typeToString(ret, TypeModeReturn, package, opMetaData); - out << retS << " __ret = "; - } - out << "__obj." << fixKwd(opName) << '('; - for(pli = inParams.begin(); pli != inParams.end(); ++pli) - { - TypePtr paramType = (*pli)->type(); - out << fixKwd((*pli)->name()); - BuiltinPtr builtin = BuiltinPtr::dynamicCast(paramType); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(paramType)) - { - out << ".value"; - } - out << ", "; - } - for(pli = outParams.begin(); pli != outParams.end(); ++pli) - { - out << fixKwd((*pli)->name()) << ", "; - } - out << "__current);"; - - // - // Marshal 'out' parameters and return value. - // - for(pli = outParams.begin(); pli != outParams.end(); ++pli) - { - writeMarshalUnmarshalCode(out, package, (*pli)->type(), fixKwd((*pli)->name()), true, iter, true, - (*pli)->getMetaData()); - } - if(ret) - { - writeMarshalUnmarshalCode(out, package, ret, "__ret", true, iter, false, opMetaData); - } - out << nl << "return Ice.DispatchStatus.DispatchOK;"; - - // - // Handle user exceptions. - // - if(!throws.empty()) - { - out << eb; - ExceptionList::const_iterator t; - for(t = throws.begin(); t != throws.end(); ++t) - { - string exS = getAbsolute(*t, package); - out << nl << "catch(" << exS << " ex)"; - out << sb; - out << nl << "__os.writeUserException(ex);"; - out << nl << "return Ice.DispatchStatus.DispatchUserException;"; - out << eb; - } - } - - out << eb; - } - - OperationList allOps = p->allOperations(); - if(!allOps.empty()) - { - StringList allOpNames; - transform(allOps.begin(), allOps.end(), back_inserter(allOpNames), ::IceUtil::constMemFun(&Contained::name)); - allOpNames.push_back("ice_id"); - allOpNames.push_back("ice_ids"); - allOpNames.push_back("ice_isA"); - allOpNames.push_back("ice_ping"); - allOpNames.sort(); - allOpNames.unique(); - - StringList::const_iterator q; - - out << sp << nl << "private final static String[] __all ="; - out << sb; - q = allOpNames.begin(); - while(q != allOpNames.end()) - { - out << nl << '"' << *q << '"'; - if(++q != allOpNames.end()) - { - out << ','; - } - } - out << eb << ';'; - - out << sp << nl << "public Ice.DispatchStatus" << nl - << "__dispatch(IceInternal.Incoming in, Ice.Current __current)"; - out << sb; - out << nl << "int pos = IceUtil.Arrays.search(__all, __current.operation);"; - out << nl << "if(pos < 0)"; - out << sb; - out << nl << "throw new Ice.OperationNotExistException(__current.id, __current.facet, __current.operation);"; - out << eb; - out << sp << nl << "switch(pos)"; - out << sb; - int i = 0; - for(q = allOpNames.begin(); q != allOpNames.end(); ++q) - { - string opName = *q; - - out << nl << "case " << i++ << ':'; - out << sb; - if(opName == "ice_id") - { - out << nl << "return ___ice_id(this, in, __current);"; - } - else if(opName == "ice_ids") - { - out << nl << "return ___ice_ids(this, in, __current);"; - } - else if(opName == "ice_isA") - { - out << nl << "return ___ice_isA(this, in, __current);"; - } - else if(opName == "ice_ping") - { - out << nl << "return ___ice_ping(this, in, __current);"; - } - else - { - // - // There's probably a better way to do this. - // - for(OperationList::const_iterator t = allOps.begin(); t != allOps.end(); ++t) - { - if((*t)->name() == (*q)) - { - ContainerPtr container = (*t)->container(); - ClassDefPtr cl = ClassDefPtr::dynamicCast(container); - assert(cl); - if(cl->scoped() == p->scoped()) - { - out << nl << "return ___" << opName << "(this, in, __current);"; - } - else - { - string base; - if(cl->isInterface()) - { - base = getAbsolute(cl, package, "_", "Disp"); - } - else - { - base = getAbsolute(cl, package); - } - out << nl << "return " << base << ".___" << opName << "(this, in, __current);"; - } - break; - } - } - } - out << eb; - } - out << eb; - out << nl << "if(IceUtil.Debug.ASSERT)"; - out << sb; - out << sp << nl << "IceUtil.Debug.Assert(false);"; - out << eb; - out << nl << "throw new Ice.OperationNotExistException(__current.id, __current.facet, __current.operation);"; - out << eb; - } -} - -Slice::Gen::Gen(const string& name, const string& base, const vector& includePaths, const string& dir) : - _base(base), - _includePaths(includePaths), - _dir(dir) -{ -} - -Slice::Gen::~Gen() -{ -} - -bool -Slice::Gen::operator!() const -{ - return false; -} - -void -Slice::Gen::generate(const UnitPtr& p) -{ - JavaGenerator::validateMetaData(p); - - OpsVisitor opsVisitor(_dir); - p->visit(&opsVisitor, false); - - PackageVisitor packageVisitor(_dir); - p->visit(&packageVisitor, false); - - TypesVisitor typesVisitor(_dir); - p->visit(&typesVisitor, false); - - HolderVisitor holderVisitor(_dir); - p->visit(&holderVisitor, false); - - HelperVisitor helperVisitor(_dir); - p->visit(&helperVisitor, false); - - ProxyVisitor proxyVisitor(_dir); - p->visit(&proxyVisitor, false); - - DispatcherVisitor dispatcherVisitor(_dir); - p->visit(&dispatcherVisitor, false); -} - -void -Slice::Gen::generateTie(const UnitPtr& p) -{ - TieVisitor tieVisitor(_dir); - p->visit(&tieVisitor, false); -} - -void -Slice::Gen::generateImpl(const UnitPtr& p) -{ - ImplVisitor implVisitor(_dir); - p->visit(&implVisitor, false); -} - -void -Slice::Gen::generateImplTie(const UnitPtr& p) -{ - ImplTieVisitor implTieVisitor(_dir); - p->visit(&implTieVisitor, false); -} - -Slice::Gen::OpsVisitor::OpsVisitor(const string& dir) : - JavaVisitor(dir) -{ -} - -bool -Slice::Gen::OpsVisitor::visitClassDefStart(const ClassDefPtr& p) -{ - // - // Don't generate an Operations interface for non-abstract classes - // - if(!p->isAbstract()) - { - return false; - } - - writeOperations(p, false); - writeOperations(p, true); - - return false; -} - -void -Slice::Gen::OpsVisitor::writeOperations(const ClassDefPtr& p, bool noCurrent) -{ - string name = p->name(); - ClassList bases = p->bases(); - string package = getPackage(p); - string opIntfName = "Operations"; - if(noCurrent) - { - opIntfName += "NC"; - } - string absolute = getAbsolute(p, "", "_", opIntfName); - - if(!open(absolute)) - { - return; - } - - Output& out = output(); - - // - // Generate the operations interface - // - out << sp << nl << "public interface " << '_' << name << opIntfName; - if((bases.size() == 1 && bases.front()->isAbstract()) || bases.size() > 1) - { - out << " extends "; - out.useCurrentPosAsIndent(); - ClassList::const_iterator q = bases.begin(); - bool first = true; - while(q != bases.end()) - { - if((*q)->isAbstract()) - { - if(!first) - { - out << ',' << nl; - } - else - { - first = false; - } - out << getAbsolute(*q, package, "_", opIntfName); - } - ++q; - } - out.restoreIndent(); - } - out << sb; - - OperationList ops = p->operations(); - OperationList::const_iterator r; - for(r = ops.begin(); r != ops.end(); ++r) - { - OperationPtr op = *r; - ContainerPtr container = op->container(); - ClassDefPtr cl = ClassDefPtr::dynamicCast(container); - string opname = op->name(); - - TypePtr ret; - vector params; - - params = getParams(op, package); - ret = op->returnType(); - - string deprecateReason = getDeprecateReason(op, p, "operation"); - - string retS = typeToString(ret, TypeModeReturn, package, op->getMetaData()); - - ExceptionList throws = op->throws(); - throws.sort(); - throws.unique(); - out << sp; - if(!deprecateReason.empty()) - { - out << nl << "/**"; - out << nl << " * @deprecated " << deprecateReason; - out << nl << " **/"; - } - out << nl << retS << ' ' << fixKwd(opname) << spar << params; - if(!noCurrent) - { - out << "Ice.Current __current"; - } - out << epar; - writeThrowsClause(package, throws); - out << ';'; - } - - out << eb; - - close(); -} - -Slice::Gen::TieVisitor::TieVisitor(const string& dir) : - JavaVisitor(dir) -{ -} - -bool -Slice::Gen::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"; - - // - // Don't generate a TIE class for a non-abstract class - // - if(!p->isAbstract()) - { - return false; - } - - if(!open(absolute)) - { - return false; - } - - Output& out = output(); - - // - // Generate the TIE class - // - out << sp << nl << "public class " << '_' << name << "Tie"; - if(p->isInterface()) - { - out << " extends " << '_' << name << "Disp implements Ice.TieBase"; - } - else - { - out << " extends " << fixKwd(name) << " implements Ice.TieBase"; - } - - out << sb; - - out << sp << nl << "public" << nl << '_' << name << "Tie()"; - out << sb; - out << eb; - - out << sp << nl << "public" << nl << '_' << name << "Tie(" << '_' << name << opIntfName - << " delegate)"; - out << sb; - out << nl << "_ice_delegate = delegate;"; - out << eb; - - out << sp << nl << "public java.lang.Object" << nl << "ice_delegate()"; - out << sb; - out << nl << "return _ice_delegate;"; - out << eb; - - out << sp << nl << "public void" << nl << "ice_delegate(java.lang.Object delegate)"; - out << sb; - out << nl << "_ice_delegate = (_" << name << opIntfName << ")delegate;"; - out << eb; - - out << sp << nl << "public boolean" << nl << "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" << nl << "hashCode()"; - out << sb; - out << nl << "return _ice_delegate.hashCode();"; - out << eb; - - OperationList ops = p->allOperations(); - OperationList::const_iterator r; - for(r = ops.begin(); r != ops.end(); ++r) - { - ContainerPtr container = (*r)->container(); - ClassDefPtr cl = ClassDefPtr::dynamicCast(container); - - string opName = fixKwd((*r)->name()); - - TypePtr ret = (*r)->returnType(); - string retS = typeToString(ret, TypeModeReturn, package, (*r)->getMetaData()); - - vector params = getParams((*r), package); - vector args = getArgs(*r); - - out << sp; - out << nl << "public " << retS << nl << opName << spar << params; - out << "Ice.Current __current"; - out << epar; - - ExceptionList throws = (*r)->throws(); - throws.sort(); - throws.unique(); - writeThrowsClause(package, throws); - out << sb; - out << nl; - if(ret) - { - out << "return "; - } - out << "_ice_delegate." << opName << spar << args; - out << "__current"; - out << epar << ';'; - out << eb; - } - - out << sp << nl << "private " << '_' << name << opIntfName << " _ice_delegate;"; - out << eb; - close(); - - return false; -} - -Slice::Gen::PackageVisitor::PackageVisitor(const string& dir) : - JavaVisitor(dir) -{ -} - -bool -Slice::Gen::PackageVisitor::visitModuleStart(const ModulePtr& p) -{ - DefinitionContextPtr dc = p->definitionContext(); - assert(dc); - StringList globalMetaData = dc->getMetaData(); - - static const string packagePrefix = "java:package:"; - - for(StringList::const_iterator q = globalMetaData.begin(); q != globalMetaData.end(); ++q) - { - string s = *q; - if(s.find(packagePrefix) == 0) - { - string markerClass = s.substr(packagePrefix.size()) + "." + fixKwd(p->name()) + "._Marker"; - - if(!open(markerClass)) - { - cerr << "can't open class `" << markerClass << "' for writing: " << strerror(errno) << endl; - return false; - } - - Output& out = output(); - out << sp << nl << "interface _Marker"; - out << sb; - out << eb; - - close(); - } - } - - return false; -} - -Slice::Gen::TypesVisitor::TypesVisitor(const string& dir) : - JavaVisitor(dir) -{ -} - -bool -Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) -{ - string name = p->name(); - ClassList bases = p->bases(); - ClassDefPtr baseClass; - if(!bases.empty() && !bases.front()->isInterface()) - { - baseClass = bases.front(); - } - - string package = getPackage(p); - string absolute = getAbsolute(p); - DataMemberList members = p->dataMembers(); - DataMemberList allDataMembers = p->allDataMembers(); - DataMemberList::const_iterator d; - - if(!open(absolute)) - { - return false; - } - - Output& out = output(); - - // - // Slice interfaces map to Java interfaces. - // - if(p->isInterface()) - { - out << sp << nl << "public interface " << fixKwd(name) << " extends "; - out.useCurrentPosAsIndent(); - out << "Ice.Object"; - out << "," << nl << '_' << name; - out << "Operations, _" << name << "OperationsNC"; - if(!bases.empty()) - { - ClassList::const_iterator q = bases.begin(); - while(q != bases.end()) - { - out << ',' << nl << getAbsolute(*q, package); - q++; - } - } - out.restoreIndent(); - } - else - { - out << sp << nl << "public "; - if(p->isAbstract()) - { - out << "abstract "; - } - out << "class " << fixKwd(name); - out.useCurrentPosAsIndent(); - if(bases.empty() || bases.front()->isInterface()) - { - out << " extends Ice.ObjectImpl"; - } - else - { - out << " extends "; - out << getAbsolute(baseClass, package); - bases.pop_front(); - } - - // - // Implement interfaces - // - StringList implements; - if(p->isAbstract()) - { - implements.push_back("_" + name + "Operations"); - implements.push_back("_" + name + "OperationsNC"); - } - if(!bases.empty()) - { - ClassList::const_iterator q = bases.begin(); - while(q != bases.end()) - { - implements.push_back(getAbsolute(*q, package)); - q++; - } - } - - if(!implements.empty()) - { - out << nl << " implements "; - out.useCurrentPosAsIndent(); - - StringList::const_iterator q = implements.begin(); - while(q != implements.end()) - { - if(q != implements.begin()) - { - out << ',' << nl; - } - out << *q; - q++; - } - - out.restoreIndent(); - } - - out.restoreIndent(); - } - - out << sb; - - if(!p->isInterface() && !allDataMembers.empty()) - { - // - // Constructors. - // - out << sp; - out << nl << "public " << name << "()"; - out << sb; - if(baseClass) - { - out << nl << "super();"; - } - out << eb; - - out << sp << nl << "public " << name << spar; - vector paramDecl; - for(d = allDataMembers.begin(); d != allDataMembers.end(); ++d) - { - string memberName = fixKwd((*d)->name()); - string memberType = typeToString((*d)->type(), TypeModeMember, package, (*d)->getMetaData()); - paramDecl.push_back(memberType + " " + memberName); - } - out << paramDecl << epar; - out << sb; - if(baseClass && allDataMembers.size() != members.size()) - { - out << nl << "super" << spar; - vector baseParamNames; - DataMemberList baseDataMembers = baseClass->allDataMembers(); - for(d = baseDataMembers.begin(); d != baseDataMembers.end(); ++d) - { - baseParamNames.push_back(fixKwd((*d)->name())); - } - out << baseParamNames << epar << ';'; - } - vector paramNames; - for(d = members.begin(); d != members.end(); ++d) - { - paramNames.push_back(fixKwd((*d)->name())); - } - for(vector::const_iterator i = paramNames.begin(); i != paramNames.end(); ++i) - { - out << nl << "this." << *i << " = " << *i << ';'; - } - out << eb; - } - - // - // Marshalling & dispatch support. - // - if(!p->isInterface()) - { - writeDispatch(out, p); - } - - if(!p->isInterface() && !members.empty()) - { - out << sp << nl << "protected void" << nl << "__copyFrom(java.lang.Object __obj)"; - out << sb; - if(baseClass) - { - out << nl << "super.__copyFrom(__obj);"; - } - out << nl << name << " __src = (" << name << ")__obj;"; - for(d = members.begin(); d != members.end(); ++d) - { - string memberName = fixKwd((*d)->name()); - out << nl << memberName << " = __src." << memberName << ";"; - } - out << eb; - } - - return true; -} - -void -Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) -{ - Output& out = output(); - out << eb; - close(); -} - -bool -Slice::Gen::TypesVisitor::visitExceptionStart(const ExceptionPtr& p) -{ - string name = fixKwd(p->name()); - string scoped = p->scoped(); - ExceptionPtr base = p->base(); - string package = getPackage(p); - string absolute = getAbsolute(p); - DataMemberList allDataMembers = p->allDataMembers(); - DataMemberList members = p->dataMembers(); - DataMemberList::const_iterator d; - - if(!open(absolute)) - { - return false; - } - - Output& out = output(); - - out << sp; - - string deprecateReason = getDeprecateReason(p, 0, "type"); - if(!deprecateReason.empty()) - { - out << nl << "/**"; - out << nl << " * @deprecated " << deprecateReason; - out << nl << " **/"; - } - - out << nl << "public class " << name << " extends "; - - if(!base) - { - if(p->isLocal()) - { - out << "Ice.LocalException"; - } - else - { - out << "Ice.UserException"; - } - } - else - { - out << getAbsolute(base, package); - } - out << sb; - - if(!allDataMembers.empty()) - { - // - // Constructors. - // - out << sp; - out << nl << "public " << name << "()"; - out << sb; - if(base) - { - out << nl << "super();"; - } - out << eb; - - out << sp << nl << "public " << name << spar; - vector paramDecl; - for(d = allDataMembers.begin(); d != allDataMembers.end(); ++d) - { - string memberName = fixKwd((*d)->name()); - string memberType = typeToString((*d)->type(), TypeModeMember, package, (*d)->getMetaData()); - paramDecl.push_back(memberType + " " + memberName); - } - out << paramDecl << epar; - out << sb; - if(base && allDataMembers.size() != members.size()) - { - out << nl << "super" << spar; - vector baseParamNames; - DataMemberList baseDataMembers = base->allDataMembers(); - for(d = baseDataMembers.begin(); d != baseDataMembers.end(); ++d) - { - baseParamNames.push_back(fixKwd((*d)->name())); - } - out << baseParamNames << epar << ';'; - } - vector paramNames; - for(d = members.begin(); d != members.end(); ++d) - { - paramNames.push_back(fixKwd((*d)->name())); - } - for(vector::const_iterator i = paramNames.begin(); i != paramNames.end(); ++i) - { - out << nl << "this." << *i << " = " << *i << ';'; - } - out << eb; - } - - out << sp << nl << "public String" << nl << "ice_name()"; - out << sb; - out << nl << "return \"" << scoped.substr(2) << "\";"; - out << eb; - - return true; -} - -void -Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) -{ - Output& out = output(); - - if(!p->isLocal()) - { - string name = fixKwd(p->name()); - string scoped = p->scoped(); - string package = getPackage(p); - ExceptionPtr base = p->base(); - - DataMemberList members = p->dataMembers(); - DataMemberList::const_iterator d; - int iter; - - out << sp << nl << "public void" << nl << "__write(IceInternal.BasicStream __os)"; - out << sb; - out << nl << "__os.writeString(\"" << scoped << "\");"; - out << nl << "__os.startWriteSlice();"; - iter = 0; - for(d = members.begin(); d != members.end(); ++d) - { - StringList metaData = (*d)->getMetaData(); - writeMarshalUnmarshalCode(out, package, (*d)->type(), fixKwd((*d)->name()), true, iter, false, metaData); - } - out << nl << "__os.endWriteSlice();"; - if(base) - { - out << nl << "super.__write(__os);"; - } - out << eb; - - DataMemberList allClassMembers = p->allClassDataMembers(); - if(allClassMembers.size() != 0) - { - out << sp << nl << "private class Patcher implements IceInternal.Patcher"; - out << sb; - if(allClassMembers.size() > 1) - { - out << sp << nl << "Patcher(int member)"; - out << sb; - out << nl << "__member = member;"; - out << eb; - } - - out << sp << nl << "public void" << nl << "patch(Ice.Object v)"; - out << sb; - if(allClassMembers.size() > 1) - { - out << nl << "switch(__member)"; - out << sb; - } - int memberCount = 0; - for(d = allClassMembers.begin(); d != allClassMembers.end(); ++d) - { - if(allClassMembers.size() > 1) - { - out.dec(); - out << nl << "case " << memberCount << ":"; - out.inc(); - } - if(allClassMembers.size() > 1) - { - out << nl << "__typeId = \"" << (*d)->type()->typeId() << "\";"; - } - string memberName = fixKwd((*d)->name()); - string memberType = typeToString((*d)->type(), TypeModeMember, package); - out << nl << memberName << " = (" << memberType << ")v;"; - if(allClassMembers.size() > 1) - { - out << nl << "break;"; - } - memberCount++; - } - if(allClassMembers.size() > 1) - { - out << eb; - } - out << eb; - - out << sp << nl << "public String" << nl << "type()"; - out << sb; - if(allClassMembers.size() > 1) - { - out << nl << "return __typeId;"; - } - else - { - out << nl << "return \"" << (*allClassMembers.begin())->type()->typeId() << "\";"; - } - out << eb; - - if(allClassMembers.size() > 1) - { - out << sp << nl << "private int __member;"; - out << nl << "private String __typeId;"; - } - out << eb; - } - out << sp << nl << "public void" << nl << "__read(IceInternal.BasicStream __is, boolean __rid)"; - out << sb; - out << nl << "if(__rid)"; - out << sb; - out << nl << "String myId = __is.readString();"; - out << eb; - out << nl << "__is.startReadSlice();"; - iter = 0; - DataMemberList classMembers = p->classDataMembers(); - for(d = members.begin(); d != members.end(); ++d) - { - ostringstream patchParams; - StringList metaData = (*d)->getMetaData(); - writeMarshalUnmarshalCode(out, package, (*d)->type(), fixKwd((*d)->name()), false, iter, false, metaData, - patchParams.str()); - } - out << nl << "__is.endReadSlice();"; - if(base) - { - out << nl << "super.__read(__is, true);"; - } - out << eb; - - } - - out << eb; - close(); -} - -bool -Slice::Gen::TypesVisitor::visitStructStart(const StructPtr& p) -{ - string name = fixKwd(p->name()); - string absolute = getAbsolute(p); - - if(!open(absolute)) - { - return false; - } - - Output& out = output(); - - out << sp; - - string deprecateReason = getDeprecateReason(p, 0, "type"); - if(!deprecateReason.empty()) - { - out << nl << "/**"; - out << nl << " * @deprecated " << deprecateReason; - out << nl << " **/"; - } - - out << nl << "public final class " << name; - out << sb; - - return true; -} - -void -Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) -{ - string package = getPackage(p); - - Output& out = output(); - - DataMemberList members = p->dataMembers(); - DataMemberList::const_iterator d; - int iter; - - string name = fixKwd(p->name()); - string typeS = typeToString(p, TypeModeIn, package); - - out << sp << nl << "public " << name << "()"; - out << sb; - out << eb; - - vector paramDecl; - vector paramNames; - vector::const_iterator q; - for(d = members.begin(); d != members.end(); ++d) - { - string memberName = fixKwd((*d)->name()); - string memberType = typeToString((*d)->type(), TypeModeMember, package, (*d)->getMetaData()); - paramDecl.push_back(memberType + " " + memberName); - paramNames.push_back(memberName); - } - - out << sp << nl << "public " << name << spar << paramDecl << epar; - out << sb; - for(q = paramNames.begin(); q != paramNames.end(); ++q) - { - out << nl << "this." << *q << " = " << *q << ';'; - } - out << eb; - - out << sp << nl << "public boolean" << nl << "equals(java.lang.Object rhs)"; - out << sb; - out << nl << typeS << " _r = null;"; - out << nl << "try"; - out << sb; - out << nl << "_r = (" << typeS << ")rhs;"; - out << eb; - out << nl << "catch(ClassCastException ex)"; - out << sb; - out << eb; - out << sp << nl << "if(_r != null)"; - out << sb; - for(d = members.begin(); d != members.end(); ++d) - { - string memberName = fixKwd((*d)->name()); - BuiltinPtr b = BuiltinPtr::dynamicCast((*d)->type()); - if(b) - { - switch(b->kind()) - { - case Builtin::KindByte: - case Builtin::KindBool: - case Builtin::KindShort: - case Builtin::KindInt: - case Builtin::KindLong: - case Builtin::KindFloat: - case Builtin::KindDouble: - { - out << nl << "if(" << memberName << " != _r." << memberName << ')'; - out << sb; - out << nl << "return false;"; - out << eb; - break; - } - - case Builtin::KindString: - case Builtin::KindObject: - case Builtin::KindObjectProxy: - case Builtin::KindLocalObject: - { - out << nl << "if(" << memberName << " != _r." << memberName << " && " << memberName - << " != null && !" << memberName << ".equals(_r." << memberName << "))"; - out << sb; - out << nl << "return false;"; - out << eb; - break; - } - } - } - else - { - // - // We treat sequences differently because the native equals() method for - // a Java array does not perform a deep comparison. We use the helper method - // IceUtil.Arrays.equals() to compare native arrays. - // - // For all other types, we can use the native equals() method. - // - SequencePtr seq = SequencePtr::dynamicCast((*d)->type()); - if(seq) - { - out << nl << "if(!IceUtil.Arrays.equals(" << memberName << ", _r." << memberName << "))"; - out << sb; - out << nl << "return false;"; - out << eb; - } - else - { - out << nl << "if(" << memberName << " != _r." << memberName << " && " << memberName - << " != null && !" << memberName << ".equals(_r." << memberName << "))"; - out << sb; - out << nl << "return false;"; - out << eb; - } - } - } - out << sp << nl << "return true;"; - out << eb; - out << sp << nl << "return false;"; - out << eb; - - out << sp << nl << "public int" << nl << "hashCode()"; - out << sb; - out << nl << "int __h = 0;"; - iter = 0; - for(d = members.begin(); d != members.end(); ++d) - { - string memberName = fixKwd((*d)->name()); - writeHashCode(out, (*d)->type(), memberName, iter); - } - out << nl << "return __h;"; - out << eb; - - out << sp << nl << "public java.lang.Object" << nl << "ice_clone()"; - out.inc(); - out << nl << "throws IceUtil.CloneException"; - out.dec(); - out << sb; - out << nl << "return new " << name << '('; - for(q = paramNames.begin(); q != paramNames.end(); ++q) - { - if(q != paramNames.begin()) - { - out << ", "; - } - out << *q; - } - out << ");"; - out << eb; - - if(!p->isLocal()) - { - out << sp << nl << "public void" << nl << "__write(IceInternal.BasicStream __os)"; - out << sb; - iter = 0; - for(d = members.begin(); d != members.end(); ++d) - { - StringList metaData = (*d)->getMetaData(); - writeMarshalUnmarshalCode(out, package, (*d)->type(), fixKwd((*d)->name()), true, iter, false, metaData); - } - out << eb; - - DataMemberList classMembers = p->classDataMembers(); - - if(classMembers.size() != 0) - { - out << sp << nl << "private class Patcher implements IceInternal.Patcher"; - out << sb; - if(classMembers.size() > 1) - { - out << sp << nl << "Patcher(int member)"; - out << sb; - out << nl << "__member = member;"; - out << eb; - } - - out << sp << nl << "public void" << nl << "patch(Ice.Object v)"; - out << sb; - if(classMembers.size() > 1) - { - out << nl << "switch(__member)"; - out << sb; - } - int memberCount = 0; - for(d = classMembers.begin(); d != classMembers.end(); ++d) - { - if(classMembers.size() > 1) - { - out.dec(); - out << nl << "case " << memberCount << ":"; - out.inc(); - } - if(classMembers.size() > 1) - { - out << nl << "__typeId = \"" << (*d)->type()->typeId() << "\";"; - } - string memberName = fixKwd((*d)->name()); - string memberType = typeToString((*d)->type(), TypeModeMember, package); - out << nl << memberName << " = (" << memberType << ")v;"; - if(classMembers.size() > 1) - { - out << nl << "break;"; - } - memberCount++; - } - if(classMembers.size() > 1) - { - out << eb; - } - out << eb; - - out << sp << nl << "public String" << nl << "type()"; - out << sb; - if(classMembers.size() > 1) - { - out << nl << "return __typeId;"; - } - else - { - out << nl << "return \"" << (*classMembers.begin())->type()->typeId() << "\";"; - } - out << eb; - - if(classMembers.size() > 1) - { - out << sp << nl << "private int __member;"; - out << nl << "private String __typeId;"; - } - out << eb; - } - - out << sp << nl << "public void" << nl << "__read(IceInternal.BasicStream __is)"; - out << sb; - iter = 0; - for(d = members.begin(); d != members.end(); ++d) - { - ostringstream patchParams; - StringList metaData = (*d)->getMetaData(); - writeMarshalUnmarshalCode(out, package, (*d)->type(), fixKwd((*d)->name()), false, iter, false, metaData, - patchParams.str()); - } - out << eb; - } - - out << eb; - close(); -} - -void -Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p) -{ - string name = fixKwd(p->name()); - ContainerPtr container = p->container(); - ContainedPtr contained = ContainedPtr::dynamicCast(container); - StringList metaData = p->getMetaData(); - string s = typeToString(p->type(), TypeModeMember, getPackage(contained), metaData); - Output& out = output(); - - out << sp; - - string deprecateReason = getDeprecateReason(p, contained, "member"); - if(!deprecateReason.empty()) - { - out << nl << "/**"; - out << nl << " * @deprecated " << deprecateReason; - out << nl << " **/"; - } - out << nl << "public " << s << ' ' << name << ';'; -} - -void -Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) -{ - string name = fixKwd(p->name()); - string absolute = getAbsolute(p); - EnumeratorList enumerators = p->getEnumerators(); - EnumeratorList::const_iterator en; - size_t sz = enumerators.size(); - - if(!open(absolute)) - { - return; - } - - Output& out = output(); - - out << sp; - - string deprecateReason = getDeprecateReason(p, 0, "type"); - if(!deprecateReason.empty()) - { - out << nl << "/**"; - out << nl << " * @deprecated " << deprecateReason; - out << nl << " **/"; - } - - out << nl << "public final class " << name; - out << sb; - out << nl << "private static " << name << "[] __values = new " << name << "[" << sz << "];"; - out << nl << "private int __value;"; - out << sp; - int n; - for(en = enumerators.begin(), n = 0; en != enumerators.end(); ++en, ++n) - { - string member = fixKwd((*en)->name()); - out << nl << "public static final int _" << member << " = " << n << ';'; - out << nl << "public static final " << name << ' ' << fixKwd(member) - << " = new " << name << "(_" << member << ");"; - } - - out << sp << nl << "public static " << name << nl << "convert(int val)"; - out << sb; - out << nl << "if(IceUtil.Debug.ASSERT)"; - out << sb; - out << nl << "IceUtil.Debug.Assert(val < " << sz << ");"; - out << eb; - out << nl << "return __values[val];"; - out << eb; - - out << sp << nl << "public int" << nl << "value()"; - out << sb; - out << nl << "return __value;"; - out << eb; - - out << sp << nl << "public String" << nl << "toString()"; - out << sb; - out << nl << "return __T[__value];"; - out << eb; - - out << sp << nl << "private" << nl << name << "(int val)"; - out << sb; - out << nl << "__value = val;"; - out << nl << "__values[val] = this;"; - out << eb; - - if(!p->isLocal()) - { - out << sp << nl << "public void" << nl << "__write(IceInternal.BasicStream __os)"; - out << sb; - if(sz <= 0x7f) - { - out << nl << "__os.writeByte((byte)__value);"; - } - else if(sz <= 0x7fff) - { - out << nl << "__os.writeShort((short)__value);"; - } - else - { - out << nl << "__os.writeInt(__value);"; - } - out << eb; - - out << sp << nl << "public static " << name << nl << "__read(IceInternal.BasicStream __is)"; - out << sb; - if(sz <= 0x7f) - { - out << nl << "int __v = __is.readByte();"; - } - else if(sz <= 0x7fff) - { - out << nl << "int __v = __is.readShort();"; - } - else - { - out << nl << "int __v = __is.readInt();"; - } - out << nl << "if(__v < 0 || __v >= " << sz << ')'; - out << sb; - out << nl << "throw new Ice.MarshalException();"; - out << eb; - out << nl << "return " << name << ".convert(__v);"; - out << eb; - } - - out << sp << nl << "final static private String[] __T ="; - out << sb; - en = enumerators.begin(); - while(en != enumerators.end()) - { - out << nl << "\"" << (*en)->name() << "\""; - if(++en != enumerators.end()) - { - out << ','; - } - } - out << eb << ';'; - - out << eb; - close(); -} - -void -Slice::Gen::TypesVisitor::visitConst(const ConstPtr& p) -{ - string name = fixKwd(p->name()); - string package = getPackage(p); - string absolute = getAbsolute(p); - TypePtr type = p->type(); - - if(!open(absolute)) - { - return; - } - Output& out = output(); - out << sp << nl << "public interface " << name; - out << sb; - out << nl << typeToString(type, TypeModeIn, package) << " value = "; - - BuiltinPtr bp; - EnumPtr ep; - if(bp = BuiltinPtr::dynamicCast(type)) - { - switch(bp->kind()) - { - case Builtin::KindString: - { - out << "\""; - - const string val = p->value(); - for(string::const_iterator c = val.begin(); c != val.end(); ++c) - { - if(isascii(*c) && isprint(*c)) - { - switch(*c) - { - case '\\': - case '"': - { - out << "\\"; - break; - } - } - out << *c; - } - else - { - switch(*c) - { - case '\r': - { - out << "\\r"; - break; - } - case '\n': - { - out << "\\n"; - break; - } - default: - { - unsigned char uc = *c; - ostringstream s; - s << "\\u"; - s.flags(ios_base::hex); - s.width(4); - s.fill('0'); - s << static_cast(uc); - out << s.str(); - break; - } - } - } - } - - out << "\""; - break; - } - case Builtin::KindByte: - { - int i = atoi(p->value().c_str()); - if(i > 127) - { - i -= 256; - } - out << i; // Slice byte runs from 0-255, Java byte runs from -128 - 127. - break; - } - case Builtin::KindLong: - { - out << p->value() << "L"; // Need to append "L" modifier for long constants. - break; - } - case Builtin::KindBool: - case Builtin::KindShort: - case Builtin::KindInt: - case Builtin::KindFloat: - case Builtin::KindDouble: - case Builtin::KindObject: - case Builtin::KindObjectProxy: - case Builtin::KindLocalObject: - { - out << p->value(); - break; - } - } - - } - else if(ep = EnumPtr::dynamicCast(type)) - { - string val = p->value(); - string::size_type pos = val.rfind(':'); - if(pos != string::npos) - { - val.erase(0, pos + 1); - } - out << getAbsolute(ep, package) << '.' << fixKwd(val); - } - else - { - out << p->value(); - } - out << ';' << eb; - close(); -} - -Slice::Gen::HolderVisitor::HolderVisitor(const string& dir) : - JavaVisitor(dir) -{ -} - -bool -Slice::Gen::HolderVisitor::visitClassDefStart(const ClassDefPtr& p) -{ - ClassDeclPtr decl = p->declaration(); - writeHolder(decl); - - string name = p->name(); - string absolute = getAbsolute(p, "", "", "PrxHolder"); - - if(open(absolute)) - { - Output& out = output(); - out << sp << nl << "public final class " << name << "PrxHolder"; - out << sb; - out << sp << nl << "public" << nl << name << "PrxHolder()"; - out << sb; - out << eb; - out << sp << nl << "public" << nl << name << "PrxHolder(" << name << "Prx value)"; - out << sb; - out << nl << "this.value = value;"; - out << eb; - out << sp << nl << "public " << name << "Prx value;"; - out << eb; - close(); - } - - return false; -} - -bool -Slice::Gen::HolderVisitor::visitStructStart(const StructPtr& p) -{ - writeHolder(p); - return false; -} - -void -Slice::Gen::HolderVisitor::visitSequence(const SequencePtr& p) -{ - writeHolder(p); -} - -void -Slice::Gen::HolderVisitor::visitDictionary(const DictionaryPtr& p) -{ - writeHolder(p); -} - -void -Slice::Gen::HolderVisitor::visitEnum(const EnumPtr& p) -{ - writeHolder(p); -} - -void -Slice::Gen::HolderVisitor::writeHolder(const TypePtr& p) -{ - ContainedPtr contained = ContainedPtr::dynamicCast(p); - assert(contained); - string name = contained->name(); - string absolute = getAbsolute(contained, "", "", "Holder"); - - if(open(absolute)) - { - Output& out = output(); - string typeS = typeToString(p, TypeModeIn, getPackage(contained)); - out << sp << nl << "public final class " << name << "Holder"; - out << sb; - out << sp << nl << "public" << nl << name << "Holder()"; - out << sb; - out << eb; - out << sp << nl << "public" << nl << name << "Holder(" << typeS << " value)"; - out << sb; - out << nl << "this.value = value;"; - out << eb; - out << sp << nl << "public " << typeS << " value;"; - out << eb; - close(); - } -} - -Slice::Gen::HelperVisitor::HelperVisitor(const string& dir) : - JavaVisitor(dir) -{ -} - -bool -Slice::Gen::HelperVisitor::visitClassDefStart(const ClassDefPtr& p) -{ - // - // Proxy helper - // - string name = p->name(); - string scoped = p->scoped(); - ClassList bases = p->bases(); - string package = getPackage(p); - string absolute = getAbsolute(p); - - if(!open(getAbsolute(p, "", "", "PrxHelper"))) - { - return false; - } - - Output& out = output(); - - // - // A proxy helper class serves two purposes: it implements the - // proxy interface, and provides static helper methods for use - // by applications (e.g., checkedCast, etc.) - // - out << sp << nl << "public final class " << name << "PrxHelper extends Ice.ObjectPrxHelperBase implements " << name - << "Prx"; - - out << sb; - - OperationList ops = p->allOperations(); - - OperationList::const_iterator r; - for(r = ops.begin(); r != ops.end(); ++r) - { - OperationPtr op = *r; - StringList opMetaData = op->getMetaData(); - ContainerPtr container = op->container(); - ClassDefPtr cl = ClassDefPtr::dynamicCast(container); - string opName = fixKwd(op->name()); - TypePtr ret = op->returnType(); - string retS = typeToString(ret, TypeModeReturn, package, op->getMetaData()); - int iter; - - vector params = getParams(op, package); - vector args = getArgs(op); - - ParamDeclList inParams; - ParamDeclList outParams; - ParamDeclList paramList = op->parameters(); - ParamDeclList::const_iterator pli; - for(pli = paramList.begin(); pli != paramList.end(); ++pli) - { - if((*pli)->isOutParam()) - { - outParams.push_back(*pli); - } - else - { - inParams.push_back(*pli); - } - } - - ExceptionList throws = op->throws(); - throws.sort(); - throws.unique(); - - // - // Write two versions of the operation - with and without a - // context parameter - // - out << sp; - out << nl << "public " << retS << nl << opName << spar << params << epar; - writeThrowsClause(package, throws); - out << sb; - out << nl; - if(ret) - { - out << "return "; - } - out << opName << spar << args << "null, false" << epar << ';'; - out << eb; - - out << sp; - out << nl << "public " << retS << nl << opName << spar << params << "java.util.Hashtable __ctx" << epar; - writeThrowsClause(package, throws); - out << sb; - out << nl; - if(ret) - { - out << "return "; - } - out << opName << spar << args << "__ctx, true" << epar << ';'; - out << eb; - - out << sp; - out << nl << "public " << retS << nl << opName << spar << params - << "java.util.Hashtable __ctx, boolean __explicitCtx" << epar; - writeThrowsClause(package, throws); - out << sb; - out << nl << "if(__explicitCtx && __ctx == null)"; - out << sb; - out << nl << "__ctx = _emptyContext;"; - out << eb; - out << nl << "int __cnt = 0;"; - out << nl << "while(true)"; - out << sb; - out << nl << "Ice.Connection __connection = null;"; - out << nl << "try"; - out << sb; - if(op->returnsData()) - { - out << nl << "__checkTwowayOnly(\"" << opName << "\");"; - } - out << nl << "__connection = ice_getConnection();"; - out << nl << "IceInternal.Outgoing __og = __connection.getOutgoing(_reference, \"" << op->name() << "\", " - << sliceModeToIceMode(op->sendMode()) << ", __ctx);"; - out << nl << "try"; - out << sb; - if(!inParams.empty()) - { - out << nl << "try"; - out << sb; - out << nl << "IceInternal.BasicStream __os = __og.stream();"; - iter = 0; - for(pli = inParams.begin(); pli != inParams.end(); ++pli) - { - writeMarshalUnmarshalCode(out, package, (*pli)->type(), fixKwd((*pli)->name()), true, iter, false, - (*pli)->getMetaData()); - } - out << eb; - out << nl << "catch(Ice.LocalException __ex)"; - out << sb; - out << nl << "__og.abort(__ex);"; - out << eb; - } - out << nl << "boolean __ok = __og.invoke();"; - out << nl << "try"; - out << sb; - out << nl << "IceInternal.BasicStream __is = __og.stream();"; - out << nl << "if(!__ok)"; - out << sb; - out << nl << "try"; - out << sb; - out << nl << "__is.throwException();"; - out << eb; - for(ExceptionList::const_iterator t = throws.begin(); t != throws.end(); ++t) - { - out << nl << "catch(" << getAbsolute(*t, package) << " __ex)"; - out << sb; - out << nl << "throw __ex;"; - out << eb; - } - out << nl << "catch(Ice.UserException __ex)"; - out << sb; - out << nl << "Ice.UnknownUserException __uex = new Ice.UnknownUserException();"; - out << nl << "__uex.unknown = __ex.ice_name();"; - out << nl << "throw __uex;"; - out << eb; - out << eb; - for(pli = outParams.begin(); pli != outParams.end(); ++pli) - { - writeMarshalUnmarshalCode(out, package, (*pli)->type(), fixKwd((*pli)->name()), false, iter, true, - (*pli)->getMetaData()); - } - if(ret) - { - out << nl << retS << " __ret;"; - writeMarshalUnmarshalCode(out, package, ret, "__ret", false, iter, false, opMetaData); - } - if(ret) - { - out << nl << "return __ret;"; - } - out << eb; - out << nl << "catch(Ice.LocalException __ex)"; - out << sb; - out << nl << "throw new IceInternal.LocalExceptionWrapper(__ex, false);"; - out << eb; - out << eb; - out << nl << "finally"; - out << sb; - out << nl << "__connection.reclaimOutgoing(__og);"; - out << eb; - if(!ret) - { - out << nl << "return ;"; - } - out << eb; - out << nl << "catch(IceInternal.LocalExceptionWrapper __ex)"; - out << sb; - if(op->mode() == Operation::Idempotent || op->mode() == Operation::Nonmutating) - { - out << nl << "__cnt = __handleExceptionWrapperRelaxed(__connection, __ex, __cnt);"; - } - else - { - out << nl << "__handleExceptionWrapper(__connection, __ex);"; - } - out << eb; - out << nl << "catch(Ice.LocalException __ex)"; - out << sb; - out << nl << "__cnt = __handleException(__connection, __ex, __cnt);"; - out << eb; - out << eb; - out << eb; - } - - out << sp << nl << "public static " << name << "Prx" << nl << "checkedCast(Ice.ObjectPrx b)"; - out << sb; - out << nl << name << "Prx d = null;"; - out << nl << "if(b != null)"; - out << sb; - out << nl << "try"; - out << sb; - out << nl << "d = (" << name << "Prx)b;"; - out << eb; - out << nl << "catch(ClassCastException ex)"; - out << sb; - out << nl << "if(b.ice_isA(\"" << scoped << "\"))"; - out << sb; - out << nl << name << "PrxHelper h = new " << name << "PrxHelper();"; - out << nl << "h.__copyFrom(b);"; - out << nl << "d = h;"; - out << eb; - out << eb; - out << eb; - out << nl << "return d;"; - out << eb; - - out << sp << nl << "public static " << name << "Prx" << nl << "checkedCast(Ice.ObjectPrx b, java.util.Hashtable ctx)"; - out << sb; - out << nl << name << "Prx d = null;"; - out << nl << "if(b != null)"; - out << sb; - out << nl << "try"; - out << sb; - out << nl << "d = (" << name << "Prx)b;"; - out << eb; - out << nl << "catch(ClassCastException ex)"; - out << sb; - out << nl << "if(b.ice_isA(\"" << scoped << "\", ctx))"; - out << sb; - out << nl << name << "PrxHelper h = new " << name << "PrxHelper();"; - out << nl << "h.__copyFrom(b);"; - out << nl << "d = h;"; - out << eb; - out << eb; - out << eb; - out << nl << "return d;"; - out << eb; - - out << sp << nl << "public static " << name << "Prx" << nl << "checkedCast(Ice.ObjectPrx b, String f)"; - out << sb; - out << nl << name << "Prx d = null;"; - out << nl << "if(b != null)"; - out << sb; - out << nl << "Ice.ObjectPrx bb = b.ice_facet(f);"; - out << nl << "try"; - out << sb; - out << nl << "if(bb.ice_isA(\"" << scoped << "\"))"; - out << sb; - out << nl << name << "PrxHelper h = new " << name << "PrxHelper();"; - out << nl << "h.__copyFrom(bb);"; - out << nl << "d = h;"; - out << eb; - out << eb; - out << nl << "catch(Ice.FacetNotExistException ex)"; - out << sb; - out << eb; - out << eb; - out << nl << "return d;"; - out << eb; - - out << sp << nl << "public static " << name << "Prx" - << nl << "checkedCast(Ice.ObjectPrx b, String f, java.util.Hashtable ctx)"; - out << sb; - out << nl << name << "Prx d = null;"; - out << nl << "if(b != null)"; - out << sb; - out << nl << "Ice.ObjectPrx bb = b.ice_facet(f);"; - out << nl << "try"; - out << sb; - out << nl << "if(bb.ice_isA(\"" << scoped << "\", ctx))"; - out << sb; - out << nl << name << "PrxHelper h = new " << name << "PrxHelper();"; - out << nl << "h.__copyFrom(bb);"; - out << nl << "d = h;"; - out << eb; - out << eb; - out << nl << "catch(Ice.FacetNotExistException ex)"; - out << sb; - out << eb; - out << eb; - out << nl << "return d;"; - out << eb; - - out << sp << nl << "public static " << name << "Prx" << nl << "uncheckedCast(Ice.ObjectPrx b)"; - out << sb; - out << nl << name << "Prx d = null;"; - out << nl << "if(b != null)"; - out << sb; - out << nl << name << "PrxHelper h = new " << name << "PrxHelper();"; - out << nl << "h.__copyFrom(b);"; - out << nl << "d = h;"; - out << eb; - out << nl << "return d;"; - out << eb; - - out << sp << nl << "public static " << name << "Prx" << nl << "uncheckedCast(Ice.ObjectPrx b, String f)"; - out << sb; - out << nl << name << "Prx d = null;"; - out << nl << "if(b != null)"; - out << sb; - out << nl << "Ice.ObjectPrx bb = b.ice_facet(f);"; - out << nl << name << "PrxHelper h = new " << name << "PrxHelper();"; - out << nl << "h.__copyFrom(bb);"; - out << nl << "d = h;"; - out << eb; - out << nl << "return d;"; - out << eb; - - out << sp << nl << "public static void" << nl << "__write(IceInternal.BasicStream __os, " << name << "Prx v)"; - out << sb; - out << nl << "__os.writeProxy(v);"; - out << eb; - - out << sp << nl << "public static " << name << "Prx" << nl << "__read(IceInternal.BasicStream __is)"; - out << sb; - out << nl << "Ice.ObjectPrx proxy = __is.readProxy();"; - out << nl << "if(proxy != null)"; - out << sb; - out << nl << name << "PrxHelper result = new " << name << "PrxHelper();"; - out << nl << "result.__copyFrom(proxy);"; - out << nl << "return result;"; - out << eb; - out << nl << "return null;"; - out << eb; - - out << eb; - close(); - - return false; -} - -bool -Slice::Gen::HelperVisitor::visitStructStart(const StructPtr& p) -{ - return false; -} - -void -Slice::Gen::HelperVisitor::visitSequence(const SequencePtr& p) -{ - // - // Don't generate helper for a sequence of a local type. - // - if(p->isLocal()) - { - return; - } - - string name = p->name(); - string absolute = getAbsolute(p); - string helper = getAbsolute(p, "", "", "Helper"); - string package = getPackage(p); - string typeS = typeToString(p, TypeModeIn, package); - - if(open(helper)) - { - Output& out = output(); - int iter; - - out << sp << nl << "public final class " << name << "Helper"; - out << sb; - - out << nl << "public static void" << nl << "write(IceInternal.BasicStream __os, " << typeS << " __v)"; - out << sb; - iter = 0; - writeSequenceMarshalUnmarshalCode(out, package, p, "__v", true, iter, false); - out << eb; - - out << sp << nl << "public static " << typeS << nl << "read(IceInternal.BasicStream __is)"; - out << sb; - out << nl << typeS << " __v;"; - iter = 0; - writeSequenceMarshalUnmarshalCode(out, package, p, "__v", false, iter, false); - out << nl << "return __v;"; - out << eb; - - out << eb; - close(); - } -} - -void -Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) -{ - // - // Don't generate helper for a dictionary containing a local type. - // - if(p->isLocal()) - { - return; - } - - TypePtr key = p->keyType(); - TypePtr value = p->valueType(); - - string absolute = getAbsolute(p); - string helper = getAbsolute(p, "", "", "Helper"); - - if(open(helper)) - { - Output& out = output(); - string name = p->name(); - string package = getPackage(p); - string keyS = typeToString(key, TypeModeIn, package); - string valueS = typeToString(value, TypeModeIn, package); - int iter; - int i; - - out << sp << nl << "public final class " << name << "Helper"; - out << sb; - - out << nl << "public static void" << nl << "write(IceInternal.BasicStream __os, " << "java.util.Hashtable __v)"; - out << sb; - out << nl << "if(__v == null)"; - out << sb; - out << nl << "__os.writeSize(0);"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << "__os.writeSize(__v.size());"; - out << nl << "java.util.Enumeration __i = __v.keys();"; - out << nl << "while(__i.hasMoreElements())"; - out << sb; - out << nl << "java.lang.Object key = __i.nextElement();"; - out << nl << "java.lang.Object value = __v.get(key);"; - iter = 0; - for(i = 0; i < 2; i++) - { - string val; - string arg; - TypePtr type; - if(i == 0) - { - arg = "key"; - type = key; - } - else - { - arg = "value"; - type = value; - } - - BuiltinPtr b = BuiltinPtr::dynamicCast(type); - if(b) - { - switch(b->kind()) - { - case Builtin::KindByte: - { - val = "((java.lang.Byte)" + arg + ").byteValue()"; - break; - } - case Builtin::KindBool: - { - val = "((java.lang.Boolean)" + arg + ").booleanValue()"; - break; - } - case Builtin::KindShort: - { - val = "((java.lang.Short)" + arg + ").shortValue()"; - break; - } - case Builtin::KindInt: - { - val = "((java.lang.Integer)" + arg + ").intValue()"; - break; - } - case Builtin::KindLong: - { - val = "((java.lang.Long)" + arg + ").longValue()"; - break; - } - case Builtin::KindFloat: - { - val = "((java.lang.Float)" + arg + ").floatValue()"; - break; - } - case Builtin::KindDouble: - { - val = "((java.lang.Double)" + arg + ").doubleValue()"; - break; - } - case Builtin::KindString: - case Builtin::KindObjectProxy: - { - break; - } - - case Builtin::KindObject: - case Builtin::KindLocalObject: - { - assert(false); - break; - } - } - } - - if(val.empty()) - { - val = "((" + typeToString(type, TypeModeIn, package) + ')' + arg + ')'; - } - writeMarshalUnmarshalCode(out, package, type, val, true, iter, false); - } - out << eb; - out << eb; - out << eb; - - out << sp << nl << "public static java.util.Hashtable"; - out << nl << "read(IceInternal.BasicStream __is)"; - out << sb; - // - // JDK 1.1 raises IllegalArgumentException if you pass 0 to the Hashtable constructor. - // - out << nl << "int __sz = __is.readSize();"; - out << nl << "java.util.Hashtable __r = new java.util.Hashtable(__sz == 0 ? 1 : __sz);"; - out << nl << "for(int __i = 0; __i < __sz; __i++)"; - out << sb; - iter = 0; - for(i = 0; i < 2; i++) - { - string arg; - TypePtr type; - if(i == 0) - { - arg = "__key"; - type = key; - } - else - { - arg = "__value"; - type = value; - } - - BuiltinPtr b = BuiltinPtr::dynamicCast(type); - if(b) - { - switch(b->kind()) - { - case Builtin::KindByte: - { - out << nl << "java.lang.Byte " << arg << " = new java.lang.Byte(__is.readByte());"; - break; - } - case Builtin::KindBool: - { - out << nl << "java.lang.Boolean " << arg << " = new java.lang.Boolean(__is.readBool());"; - break; - } - case Builtin::KindShort: - { - out << nl << "java.lang.Short " << arg << " = new java.lang.Short(__is.readShort());"; - break; - } - case Builtin::KindInt: - { - out << nl << "java.lang.Integer " << arg << " = new java.lang.Integer(__is.readInt());"; - break; - } - case Builtin::KindLong: - { - out << nl << "java.lang.Long " << arg << " = new java.lang.Long(__is.readLong());"; - break; - } - case Builtin::KindFloat: - { - out << nl << "java.lang.Float " << arg << " = new java.lang.Float(__is.readFloat());"; - break; - } - case Builtin::KindDouble: - { - out << nl << "java.lang.Double " << arg << " = new java.lang.Double(__is.readDouble());"; - break; - } - case Builtin::KindString: - { - out << nl << "java.lang.String " << arg << " = __is.readString();"; - break; - } - case Builtin::KindObjectProxy: - { - out << nl << "Ice.ObjectPrx " << arg << " = __is.readProxy();"; - break; - } - case Builtin::KindObject: - case Builtin::KindLocalObject: - { - assert(false); - break; - } - } - } - else - { - string s = typeToString(type, TypeModeIn, package); - out << nl << s << ' ' << arg << ';'; - writeMarshalUnmarshalCode(out, package, type, arg, false, iter, false); - } - } - out << nl << "__r.put(__key, __value);"; - out << eb; - out << nl << "return __r;"; - out << eb; - - out << eb; - close(); - } -} - -void -Slice::Gen::HelperVisitor::visitEnum(const EnumPtr& p) -{ -} - -Slice::Gen::ProxyVisitor::ProxyVisitor(const string& dir) : - JavaVisitor(dir) -{ -} - -bool -Slice::Gen::ProxyVisitor::visitClassDefStart(const ClassDefPtr& p) -{ - string name = p->name(); - ClassList bases = p->bases(); - string package = getPackage(p); - string absolute = getAbsolute(p, "", "", "Prx"); - - if(!open(absolute)) - { - return false; - } - - Output& out = output(); - - // - // Generate a Java interface as the user-visible type - // - out << sp << nl << "public interface " << name << "Prx extends "; - if(bases.empty()) - { - out << "Ice.ObjectPrx"; - } - else - { - out.useCurrentPosAsIndent(); - ClassList::const_iterator q = bases.begin(); - while(q != bases.end()) - { - out << getAbsolute(*q, package, "", "Prx"); - if(++q != bases.end()) - { - out << ',' << nl; - } - } - out.restoreIndent(); - } - - out << sb; - - return true; -} - -void -Slice::Gen::ProxyVisitor::visitClassDefEnd(const ClassDefPtr& p) -{ - Output& out = output(); - out << eb; - close(); -} - -void -Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) -{ - string name = fixKwd(p->name()); - ContainerPtr container = p->container(); - ClassDefPtr cl = ClassDefPtr::dynamicCast(container); - string package = getPackage(cl); - - Output& out = output(); - - TypePtr ret = p->returnType(); - string retS = typeToString(ret, TypeModeReturn, package, p->getMetaData()); - vector params = getParams(p, package); - ExceptionList throws = p->throws(); - throws.sort(); - throws.unique(); - - string deprecateReason = getDeprecateReason(p, cl, "type"); - - // - // Write two versions of the operation - with and without a - // context parameter. - // - out << sp; - if(!deprecateReason.empty()) - { - out << nl << "/**"; - out << nl << " * @deprecated " << deprecateReason; - out << nl << " **/"; - } - out << nl << "public " << retS << ' ' << name << spar << params << epar; - writeThrowsClause(package, throws); - out << ';'; - if(!deprecateReason.empty()) - { - out << nl << "/**"; - out << nl << " * @deprecated " << deprecateReason; - out << nl << " **/"; - } - out << nl << "public " << retS << ' ' << name << spar << params << "java.util.Hashtable __ctx" << epar; - writeThrowsClause(package, throws); - out << ';'; -} - -Slice::Gen::DispatcherVisitor::DispatcherVisitor(const string& dir) : - JavaVisitor(dir) -{ -} - -bool -Slice::Gen::DispatcherVisitor::visitClassDefStart(const ClassDefPtr& p) -{ - if(!p->isInterface()) - { - return false; - } - - string name = p->name(); - ClassList bases = p->bases(); - string absolute = getAbsolute(p, "", "_", "Disp"); - - if(!open(absolute)) - { - return false; - } - - Output& out = output(); - - out << sp << 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 IceUtil.CloneException"; - out.dec(); - out << sb; - out << nl << "throw new IceUtil.CloneException();"; - out << eb; - - writeDispatch(out, p); - - out << eb; - close(); - - return false; -} - -Slice::Gen::BaseImplVisitor::BaseImplVisitor(const string& dir) : - JavaVisitor(dir) -{ -} - -void -Slice::Gen::BaseImplVisitor::writeDecl(Output& out, const string& package, const string& name, const TypePtr& type, - const StringList& metaData) -{ - out << nl << typeToString(type, TypeModeIn, package, metaData) << ' ' << name; - - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - switch(builtin->kind()) - { - case Builtin::KindBool: - { - out << " = false"; - break; - } - case Builtin::KindByte: - { - out << " = (byte)0"; - break; - } - case Builtin::KindShort: - { - out << " = (short)0"; - break; - } - case Builtin::KindInt: - case Builtin::KindLong: - { - out << " = 0"; - break; - } - case Builtin::KindFloat: - { - out << " = (float)0.0"; - break; - } - case Builtin::KindDouble: - { - out << " = 0.0"; - break; - } - case Builtin::KindString: - { - out << " = \"\""; - break; - } - case Builtin::KindObject: - case Builtin::KindObjectProxy: - case Builtin::KindLocalObject: - { - out << " = null"; - break; - } - } - } - else - { - EnumPtr en = EnumPtr::dynamicCast(type); - if(en) - { - EnumeratorList enumerators = en->getEnumerators(); - out << " = " << getAbsolute(en, package) << '.' << fixKwd(enumerators.front()->name()); - } - else - { - out << " = null"; - } - } - - out << ';'; -} - -void -Slice::Gen::BaseImplVisitor::writeReturn(Output& out, const TypePtr& type) -{ - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) - { - switch(builtin->kind()) - { - case Builtin::KindBool: - { - out << nl << "return false;"; - break; - } - case Builtin::KindByte: - { - out << nl << "return (byte)0;"; - break; - } - case Builtin::KindShort: - { - out << nl << "return (short)0;"; - break; - } - case Builtin::KindInt: - case Builtin::KindLong: - { - out << nl << "return 0;"; - break; - } - case Builtin::KindFloat: - { - out << nl << "return (float)0.0;"; - break; - } - case Builtin::KindDouble: - { - out << nl << "return 0.0;"; - break; - } - case Builtin::KindString: - case Builtin::KindObjectProxy: - case Builtin::KindLocalObject: - { - out << nl << "return null;"; - break; - } - case Builtin::KindObject: - { - cerr << "Ice objects cannot be returned by value in IceE." << endl; - break; - } - } - return; - } - - out << nl << "return null;"; -} - -void -Slice::Gen::BaseImplVisitor::writeOperation(Output& out, const string& package, const OperationPtr& op, bool local) -{ - string opName = op->name(); - - TypePtr ret = op->returnType(); - StringList opMetaData = op->getMetaData(); - string retS = typeToString(ret, TypeModeReturn, package, opMetaData); - vector params = getParams(op, package); - - ContainerPtr container = op->container(); - ClassDefPtr cl = ClassDefPtr::dynamicCast(container); - - out << sp << nl << "public " << retS << nl << fixKwd(opName) << spar << params; - if(!local) - { - out << "Ice.Current __current"; - } - out << epar; - - ExceptionList throws = op->throws(); - throws.sort(); - throws.unique(); - - writeThrowsClause(package, throws); - - out << sb; - - // - // Return value - // - if(ret) - { - writeReturn(out, ret); - } - - out << eb; -} - -Slice::Gen::ImplVisitor::ImplVisitor(const string& dir) : - BaseImplVisitor(dir) -{ -} - -bool -Slice::Gen::ImplVisitor::visitClassDefStart(const ClassDefPtr& p) -{ - if(!p->isAbstract()) - { - return false; - } - - string name = p->name(); - ClassList bases = p->bases(); - string package = getPackage(p); - string absolute = getAbsolute(p, "", "", "I"); - - if(!open(absolute)) - { - return false; - } - - Output& out = output(); - - out << sp << nl << "public final class " << name << 'I'; - if(p->isInterface()) - { - out << " extends _" << name << "Disp"; - } - else - { - out << " extends " << fixKwd(name); - } - out << sb; - - out << nl << "public" << nl << name << "I()"; - out << sb; - out << eb; - - OperationList ops = p->allOperations(); - - OperationList::const_iterator r; - for(r = ops.begin(); r != ops.end(); ++r) - { - writeOperation(out, package, *r, false); - } - - out << eb; - close(); - - return false; -} - -Slice::Gen::ImplTieVisitor::ImplTieVisitor(const string& dir) : - BaseImplVisitor(dir) -{ -} - -bool -Slice::Gen::ImplTieVisitor::visitClassDefStart(const ClassDefPtr& p) -{ - if(!p->isAbstract()) - { - return false; - } - - string name = p->name(); - ClassList bases = p->bases(); - string package = getPackage(p); - string absolute = getAbsolute(p, "", "", "I"); - - if(!open(absolute)) - { - return false; - } - - Output& out = output(); - - // - // Use implementation inheritance in the following situations: - // - // * if a class extends another class - // * if a class implements a single interface - // * if an interface extends only one interface - // - bool inheritImpl = (!p->isInterface() && !bases.empty() && !bases.front()->isInterface()) || (bases.size() == 1); - - out << sp << nl << "public class " << name << 'I'; - if(inheritImpl) - { - out << " extends "; - if(bases.front()->isAbstract()) - { - out << bases.front()->name() << 'I'; - } - else - { - out << fixKwd(bases.front()->name()); - } - } - out << " implements " << '_' << name << "Operations"; - out << sb; - - out << nl << "public" << nl << name << "I()"; - out << sb; - out << eb; - - OperationList ops = p->allOperations(); - ops.sort(); - - OperationList baseOps; - if(inheritImpl) - { - baseOps = bases.front()->allOperations(); - baseOps.sort(); - } - - OperationList::const_iterator r; - for(r = ops.begin(); r != ops.end(); ++r) - { - if(inheritImpl && binary_search(baseOps.begin(), baseOps.end(), *r)) - { - out << sp; - out << nl << "/*"; - out << nl << " * Implemented by " << bases.front()->name() << 'I'; - out << nl << " *"; - writeOperation(out, package, *r, false); - out << sp; - out << nl << "*/"; - } - else - { - writeOperation(out, package, *r, false); - } - } - - out << eb; - close(); - - return false; -} diff --git a/cpp/src/slice2javae/Gen.h b/cpp/src/slice2javae/Gen.h deleted file mode 100644 index a09f3937b45..00000000000 --- a/cpp/src/slice2javae/Gen.h +++ /dev/null @@ -1,236 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -#ifndef GEN_H -#define GEN_H - -#include -#include - -// -// The Ice-E version. -// -#define ICEE_STRING_VERSION "1.2.0" // "A.B.C", with A=major, B=minor, C=patch -#define ICEE_INT_VERSION 10200 // AABBCC, with AA=major, BB=minor, CC=patch - -namespace Slice -{ - -class JavaEOutput : public JavaOutput -{ -public: - - virtual void printHeader(); -}; - -class JavaVisitor : public JavaGenerator, public ParserVisitor -{ -public: - - virtual ~JavaVisitor(); - -protected: - - JavaVisitor(const std::string&); - - virtual JavaOutput* createOutput(); - - // - // Compose the parameter lists for an operation. - // - std::vector getParams(const OperationPtr&, const std::string&); - - // - // Compose the argument lists for an operation. - // - std::vector getArgs(const OperationPtr&); - - // - // Generate a throws clause containing only non-local exceptions. - // - void writeThrowsClause(const std::string&, const ExceptionList&); - - // - // Generate code to compute a hash code for a type. - // - void writeHashCode(::IceUtilInternal::Output&, const TypePtr&, const std::string&, int&); - - // - // Generate dispatch methods for a class or interface. - // - void writeDispatch(::IceUtilInternal::Output&, const ClassDefPtr&); -}; - -class Gen : private ::IceUtil::noncopyable -{ -public: - - Gen(const std::string&, - const std::string&, - const std::vector&, - const std::string&); - ~Gen(); - - bool operator!() const; // Returns true if there was a constructor error - - void generate(const UnitPtr&); - void generateTie(const UnitPtr&); - void generateImpl(const UnitPtr&); - void generateImplTie(const UnitPtr&); - -private: - - std::string _base; - std::vector _includePaths; - std::string _dir; - - class OpsVisitor : public JavaVisitor - { - public: - - OpsVisitor(const std::string&); - - virtual bool visitClassDefStart(const ClassDefPtr&); - - private: - void writeOperations(const ClassDefPtr&, bool); - }; - - class TieVisitor : public JavaVisitor - { - public: - - TieVisitor(const std::string&); - - virtual bool visitClassDefStart(const ClassDefPtr&); - }; - - class PackageVisitor : public JavaVisitor - { - public: - - PackageVisitor(const std::string&); - - virtual bool visitModuleStart(const ModulePtr&); - }; - - class TypesVisitor : public JavaVisitor - { - public: - - TypesVisitor(const std::string&); - - virtual bool visitClassDefStart(const ClassDefPtr&); - virtual void visitClassDefEnd(const ClassDefPtr&); - virtual bool visitExceptionStart(const ExceptionPtr&); - virtual void visitExceptionEnd(const ExceptionPtr&); - virtual bool visitStructStart(const StructPtr&); - virtual void visitStructEnd(const StructPtr&); - virtual void visitEnum(const EnumPtr&); - virtual void visitConst(const ConstPtr&); - virtual void visitDataMember(const DataMemberPtr&); - }; - - class HolderVisitor : public JavaVisitor - { - public: - - HolderVisitor(const std::string&); - - virtual bool visitClassDefStart(const ClassDefPtr&); - virtual bool visitStructStart(const StructPtr&); - virtual void visitSequence(const SequencePtr&); - virtual void visitDictionary(const DictionaryPtr&); - virtual void visitEnum(const EnumPtr&); - - private: - - void writeHolder(const TypePtr&); - }; - - class HelperVisitor : public JavaVisitor - { - public: - - HelperVisitor(const std::string&); - - virtual bool visitClassDefStart(const ClassDefPtr&); - virtual bool visitStructStart(const StructPtr&); - virtual void visitSequence(const SequencePtr&); - virtual void visitDictionary(const DictionaryPtr&); - virtual void visitEnum(const EnumPtr&); - }; - - class ProxyVisitor : public JavaVisitor - { - public: - - ProxyVisitor(const std::string&); - - virtual bool visitClassDefStart(const ClassDefPtr&); - virtual void visitClassDefEnd(const ClassDefPtr&); - virtual void visitOperation(const OperationPtr&); - }; - - class DispatcherVisitor : public JavaVisitor - { - public: - - DispatcherVisitor(const std::string&); - - virtual bool visitClassDefStart(const ClassDefPtr&); - }; - - class BaseImplVisitor : public JavaVisitor - { - public: - - BaseImplVisitor(const std::string&); - - protected: - - // - // Generate code to emit a local variable declaration and initialize it - // if necessary. - // - void writeDecl(::IceUtilInternal::Output&, const std::string&, const std::string&, const TypePtr&, const StringList&); - - // - // Generate code to return a value. - // - void writeReturn(::IceUtilInternal::Output&, const TypePtr&); - - // - // Generate an operation. - // - void writeOperation(::IceUtilInternal::Output&, const std::string&, const OperationPtr&, bool); - }; - - class ImplVisitor : public BaseImplVisitor - { - public: - - ImplVisitor(const std::string&); - - virtual bool visitClassDefStart(const ClassDefPtr&); - }; - - class ImplTieVisitor : public BaseImplVisitor - { - public: - - ImplTieVisitor(const std::string&); - - virtual bool visitClassDefStart(const ClassDefPtr&); - }; -}; - -} - -#endif diff --git a/cpp/src/slice2javae/Main.cpp b/cpp/src/slice2javae/Main.cpp deleted file mode 100644 index 152022d4f99..00000000000 --- a/cpp/src/slice2javae/Main.cpp +++ /dev/null @@ -1,216 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -#include -#include -#include -#include - -using namespace std; -using namespace Slice; - -void -usage(const char* n) -{ - cerr << "Usage: " << n << " [options] slice-files...\n"; - cerr << - "Options:\n" - "-h, --help Show this message.\n" - "-v, --version Display the Ice version.\n" - "-DNAME Define NAME as 1.\n" - "-DNAME=DEF Define NAME as DEF.\n" - "-UNAME Remove any definition for NAME.\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" - "--impl Generate sample implementations.\n" - "--impl-tie Generate sample TIE implementations.\n" - "--depend Generate Makefile dependencies.\n" - "-d, --debug Print debug messages.\n" - "--ice Permit `Ice' prefix (for building Ice source code only)\n" - ; - // Note: --case-sensitive is intentionally not shown here! -} - -int -main(int argc, char* argv[]) -{ - IceUtilInternal::Options opts; - opts.addOpt("h", "help"); - opts.addOpt("v", "version"); - opts.addOpt("D", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); - opts.addOpt("U", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); - opts.addOpt("I", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); - opts.addOpt("E"); - opts.addOpt("", "output-dir", IceUtilInternal::Options::NeedArg); - opts.addOpt("", "tie"); - opts.addOpt("", "impl"); - opts.addOpt("", "impl-tie"); - opts.addOpt("", "depend"); - opts.addOpt("d", "debug"); - opts.addOpt("", "ice"); - opts.addOpt("", "case-sensitive"); - - vectorargs; - try - { - args = opts.parse(argc, (const char**)argv); - } - catch(const IceUtilInternal::BadOptException& e) - { - cerr << argv[0] << ": " << e.reason << endl; - usage(argv[0]); - return EXIT_FAILURE; - } - - if(opts.isSet("help")) - { - usage(argv[0]); - return EXIT_SUCCESS; - } - - if(opts.isSet("version")) - { - cout << ICEE_STRING_VERSION << endl; - return EXIT_SUCCESS; - } - - vector cppArgs; - vector optargs = opts.argVec("D"); - vector::const_iterator i; - for(i = optargs.begin(); i != optargs.end(); ++i) - { - cppArgs.push_back("-D" + *i); - } - - optargs = opts.argVec("U"); - for(i = optargs.begin(); i != optargs.end(); ++i) - { - cppArgs.push_back("-U" + *i); - } - - vector includePaths = opts.argVec("I"); - for(i = includePaths.begin(); i != includePaths.end(); ++i) - { - cppArgs.push_back("-I" + Preprocessor::normalizeIncludePath(*i)); - } - - bool preprocess = opts.isSet("E"); - - string output = opts.optArg("output-dir"); - - bool tie = opts.isSet("tie"); - - bool impl = opts.isSet("impl"); - - bool implTie = opts.isSet("impl-tie"); - - bool depend = opts.isSet("depend"); - - bool debug = opts.isSet("debug"); - - bool ice = opts.isSet("ice"); - - bool caseSensitive = opts.isSet("case-sensitive"); - - if(args.empty()) - { - cerr << argv[0] << ": no input file" << endl; - usage(argv[0]); - return EXIT_FAILURE; - } - - if(impl && implTie) - { - cerr << argv[0] << ": cannot specify both --impl and --impl-tie" << endl; - usage(argv[0]); - return EXIT_FAILURE; - } - - int status = EXIT_SUCCESS; - - for(i = args.begin(); i != args.end(); ++i) - { - SignalHandler sigHandler; - - if(depend) - { - Preprocessor icecpp(argv[0], *i, cppArgs); - icecpp.printMakefileDependencies(Preprocessor::Java, includePaths); - } - else - { - Preprocessor icecpp(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp.preprocess(false); - - if(cppHandle == 0) - { - return EXIT_FAILURE; - } - - if(preprocess) - { - char buf[4096]; - while(fgets(buf, static_cast(sizeof(buf)), cppHandle) != NULL) - { - if(fputs(buf, stdout) == EOF) - { - return EXIT_FAILURE; - } - } - if(!icecpp.close()) - { - return EXIT_FAILURE; - } - } - else - { - UnitPtr p = Unit::createUnit(false, false, ice, caseSensitive); - int parseStatus = p->parse(*i, cppHandle, debug, Slice::IceE); - - if(!icecpp.close()) - { - p->destroy(); - return EXIT_FAILURE; - } - - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; - } - else - { - Gen gen(argv[0], icecpp.getBaseName(), includePaths, output); - if(!gen) - { - p->destroy(); - return EXIT_FAILURE; - } - gen.generate(p); - if(tie) - { - gen.generateTie(p); - } - if(impl) - { - gen.generateImpl(p); - } - if(implTie) - { - gen.generateImplTie(p); - } - } - p->destroy(); - } - } - } - - return status; -} diff --git a/cpp/src/slice2javae/Makefile b/cpp/src/slice2javae/Makefile deleted file mode 100644 index 9313e6fb666..00000000000 --- a/cpp/src/slice2javae/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -# ********************************************************************** -# -# Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. -# -# This copy of Ice is licensed to you under the terms described in the -# ICE_LICENSE file included in this distribution. -# -# ********************************************************************** - -top_srcdir = ../.. - -NAME = $(top_srcdir)/bin/slice2javae - -TARGETS = $(NAME) - -OBJS = Gen.o \ - Main.o - -SRCS = $(OBJS:.o=.cpp) - -include $(top_srcdir)/config/Make.rules - -CPPFLAGS := -I. $(CPPFLAGS) - -$(NAME): $(OBJS) - rm -f $@ - $(CXX) $(LDFLAGS) -o $@ $(OBJS) -lSlice $(BASELIBS) $(MCPP_RPATH_LINK) - -install:: all - $(INSTALL_PROGRAM) $(NAME) $(install_bindir) - -include .depend diff --git a/cpp/src/slice2javae/Makefile.mak b/cpp/src/slice2javae/Makefile.mak deleted file mode 100644 index 17f1a5d603d..00000000000 --- a/cpp/src/slice2javae/Makefile.mak +++ /dev/null @@ -1,61 +0,0 @@ -# ********************************************************************** -# -# Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. -# -# This copy of Ice is licensed to you under the terms described in the -# ICE_LICENSE file included in this distribution. -# -# ********************************************************************** - -top_srcdir = ..\.. - -NAME = $(top_srcdir)\bin\slice2javae.exe - -TARGETS = $(NAME) - -OBJS = Gen.obj \ - Main.obj - -SRCS = $(OBJS:.obj=.cpp) - -!include $(top_srcdir)/config/Make.rules.mak - -CPPFLAGS = -I. $(CPPFLAGS) -DWIN32_LEAN_AND_MEAN - -!if "$(GENERATE_PDB)" == "yes" -PDBFLAGS = /pdb:$(NAME:.exe=.pdb) -!endif - -!if "$(CPP_COMPILER)" == "BCC2007" -RES_FILE = ,, Slice2JavaE.res -!else -RES_FILE = Slice2JavaE.res -!endif - -$(NAME): $(OBJS) Slice2JavaE.res - $(LINK) $(LD_EXEFLAGS) $(PDBFLAGS) $(OBJS) $(SETARGV) $(PREOUT)$@ $(PRELIBS)slice$(LIBSUFFIX).lib \ - $(BASELIBS) $(RES_FILE) - @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) && \ - $(MT) -nologo -manifest $@.manifest -outputresource:$@;#1 && del /q $@.manifest - -clean:: - del /q $(NAME:.exe=.*) - del /q Slice2JavaE.res - -install:: all - copy $(NAME) $(install_bindir) - - -!if "$(CPP_COMPILER)" == "BCC2007" && "$(OPTIMIZE)" != "yes" - -install:: all - copy $(NAME:.exe=.tds) $(install_bindir) - -!elseif "$(GENERATE_PDB)" == "yes" - -install:: all - copy $(NAME:.exe=.pdb) $(install_bindir) - -!endif - -!include .depend diff --git a/cpp/src/slice2javae/Slice2JavaE.rc b/cpp/src/slice2javae/Slice2JavaE.rc deleted file mode 100644 index d5cdd6a7bcb..00000000000 --- a/cpp/src/slice2javae/Slice2JavaE.rc +++ /dev/null @@ -1,34 +0,0 @@ -#include "winver.h" - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 3,3,0,0 - PRODUCTVERSION 3,3,0,0 - FILEFLAGSMASK VS_FFI_FILEFLAGSMASK -#ifdef _DEBUG - FILEFLAGS VS_FF_DEBUG -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE VFT_APP - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904e4" - BEGIN - VALUE "CompanyName", "ZeroC, Inc.\0" - VALUE "FileDescription", "Slice To Java Translator\0" - VALUE "FileVersion", "3.3.0\0" - VALUE "InternalName", "slice2javae\0" - VALUE "LegalCopyright", "Copyright (c) 2003 - 2008 ZeroC, Inc. All rights reserved.\0" - VALUE "OriginalFilename", "slice2javae.exe\0" - VALUE "ProductName", "Ice-E\0" - VALUE "ProductVersion", "3.3.0\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1252 - END -END -- cgit v1.2.3