summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2002-03-06 23:09:58 +0000
committerMark Spruiell <mes@zeroc.com>2002-03-06 23:09:58 +0000
commit2b08f2cd933fac999a96cbb1b2c544b77005efa6 (patch)
treef18fb93db8d66ffb1b3edb51fff0d77417ab618a /cpp/src
parentadding getInstance; adding support for command-line arg stripping (diff)
downloadice-2b08f2cd933fac999a96cbb1b2c544b77005efa6.tar.bz2
ice-2b08f2cd933fac999a96cbb1b2c544b77005efa6.tar.xz
ice-2b08f2cd933fac999a96cbb1b2c544b77005efa6.zip
refactoring slice2java; adding slice2freezej
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Slice/.depend1
-rw-r--r--cpp/src/Slice/JavaUtil.cpp1192
-rw-r--r--cpp/src/Slice/Makefile3
-rw-r--r--cpp/src/slice2freezej/.depend1
-rw-r--r--cpp/src/slice2freezej/Main.cpp539
-rw-r--r--cpp/src/slice2freezej/Makefile29
-rw-r--r--cpp/src/slice2freezej/slice2freezej.dsp106
-rw-r--r--cpp/src/slice2java/Gen.cpp1165
-rw-r--r--cpp/src/slice2java/Gen.h67
9 files changed, 1873 insertions, 1230 deletions
diff --git a/cpp/src/Slice/.depend b/cpp/src/Slice/.depend
index b0082d16456..54fc035d039 100644
--- a/cpp/src/Slice/.depend
+++ b/cpp/src/Slice/.depend
@@ -2,3 +2,4 @@ Scanner.o: Scanner.cpp ../Slice/GrammarUtil.h ../../include/Slice/Parser.h ../..
Grammar.o: Grammar.cpp ../Slice/GrammarUtil.h ../../include/Slice/Parser.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h
Parser.o: Parser.cpp ../../include/IceUtil/Functional.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Slice/Parser.h ../../include/IceUtil/Shared.h
CPlusPlusUtil.o: CPlusPlusUtil.cpp ../../include/Slice/CPlusPlusUtil.h ../../include/Slice/Parser.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/OutputUtil.h
+JavaUtil.o: JavaUtil.cpp ../../include/Slice/JavaUtil.h ../../include/Slice/Parser.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/OutputUtil.h ../../include/IceUtil/Functional.h
diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp
new file mode 100644
index 00000000000..52a64efcfb2
--- /dev/null
+++ b/cpp/src/Slice/JavaUtil.cpp
@@ -0,0 +1,1192 @@
+// **********************************************************************
+//
+// Copyright (c) 2002
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#include <Slice/JavaUtil.h>
+#include <IceUtil/Functional.h>
+#include <limits>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#ifdef WIN32
+#include <direct.h>
+#endif
+
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
+using namespace std;
+using namespace Slice;
+using namespace IceUtil;
+
+Slice::JavaGenerator::JavaGenerator(const string& dir, const string& package) :
+ _dir(dir),
+ _package(package),
+ _out(0)
+{
+}
+
+Slice::JavaGenerator::~JavaGenerator()
+{
+ assert(_out == 0);
+}
+
+bool
+Slice::JavaGenerator::open(const string& absolute)
+{
+ string package;
+ string file;
+ string path = _dir;
+
+ assert(_out == 0);
+
+ string::size_type pos = absolute.rfind('.');
+ if (pos != string::npos)
+ {
+ package = absolute.substr(0, pos);
+ file = absolute.substr(pos + 1);
+ string dir = package;
+
+ //
+ // Create package directories if necessary
+ //
+ pos = 0;
+ string::size_type start = 0;
+ do
+ {
+ if (!path.empty())
+ {
+ path += "/";
+ }
+ pos = dir.find('.', start);
+ if (pos != string::npos)
+ {
+ path += dir.substr(start, pos - start);
+ start = pos + 1;
+ }
+ else
+ {
+ path += dir.substr(start);
+ }
+
+ struct stat st;
+ int result;
+ result = stat(path.c_str(), &st);
+ if (result == 0)
+ {
+ continue;
+ }
+#ifdef WIN32
+ result = _mkdir(path.c_str());
+#else
+ result = mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
+#endif
+ if (result != 0)
+ {
+ cerr << "can't create directory `" << path << "': "
+ << strerror(errno) << endl;
+ return false;
+ }
+ }
+ while (pos != string::npos);
+ }
+ else
+ {
+ file = absolute;
+ }
+ file += ".java";
+
+ //
+ // Open class file
+ //
+ if (!path.empty())
+ {
+ path += "/";
+ }
+ path += file;
+ _out = new Output();
+ _out->open(path.c_str());
+ if (!(*_out))
+ {
+ cerr << "can't open `" << path << "' for writing: "
+ << strerror(errno) << endl;
+ close();
+ return false;
+ }
+
+ printHeader();
+
+ if (!package.empty())
+ {
+ *_out << sp << nl << "package " << package << ';';
+ }
+
+ return true;
+}
+
+void
+Slice::JavaGenerator::close()
+{
+ assert(_out != 0);
+ *_out << nl;
+ delete _out;
+ _out = 0;
+}
+
+Output&
+Slice::JavaGenerator::output() const
+{
+ assert(_out != 0);
+ return *_out;
+}
+
+string
+Slice::JavaGenerator::fixKwd(const string& name) const
+{
+ //
+ // Alphabetical list of Java keywords
+ //
+ static const char* keywords[] =
+ {
+ "abstract", "assert", "boolean", "break", "byte", "case", "catch",
+ "char", "class", "clone", "const", "continue", "default", "do",
+ "double", "else", "equals", "extends", "false", "final", "finalize",
+ "finally", "float", "for", "getClass", "goto", "hashCode", "if",
+ "implements", "import", "instanceof", "int", "interface", "long",
+ "native", "new", "notify", "notifyAll", "null", "package", "private",
+ "protected", "public", "return", "short", "static", "super", "switch",
+ "synchronized", "this", "throw", "throws", "toString", "transient",
+ "true", "try", "void", "volatile", "wait", "while"
+ };
+
+ int i = 0;
+ int j = sizeof(keywords) / sizeof(const char*);
+
+ while (i < j)
+ {
+ int mid = (i + j) / 2;
+ string str = keywords[mid];
+ int n = str.compare(name);
+ if (n == 0)
+ {
+ string result = "_" + name;
+ return result;
+ }
+ else if (n > 0)
+ {
+ j = mid;
+ }
+ else
+ {
+ i = mid + 1;
+ }
+ }
+
+ return name;
+}
+
+string
+Slice::JavaGenerator::getAbsolute(const string& scoped,
+ const string& scope,
+ const string& prefix,
+ const string& suffix) const
+{
+ string result;
+ string::size_type start = 0;
+
+ if (!scope.empty())
+ {
+ //
+ // Only remove the scope if the resulting symbol is unscoped.
+ // For example:
+ //
+ // scope=::A, scoped=::A::B, result=B
+ // scope=::A, scoped=::A::B::C, result=::A::B::C
+ //
+ string::size_type scopeSize = scope.size();
+ if (scoped.compare(0, scopeSize, scope) == 0)
+ {
+ start = scoped.find(':', scopeSize);
+ if (start == string::npos)
+ {
+ start = scopeSize;
+ }
+ else
+ {
+ start = 0;
+ }
+ }
+ }
+
+ //
+ // Skip leading "::"
+ //
+ if (scoped[start] == ':')
+ {
+ assert(scoped[start + 1] == ':');
+ start += 2;
+ }
+
+ //
+ // Convert all occurrences of "::" to "."
+ //
+ string::size_type pos;
+ do
+ {
+ pos = scoped.find(':', start);
+ string fix;
+ if (pos == string::npos)
+ {
+ fix = prefix + fixKwd(scoped.substr(start)) + suffix;
+ }
+ else
+ {
+ assert(scoped[pos + 1] == ':');
+ fix = fixKwd(scoped.substr(start, pos - start));
+ start = pos + 2;
+ }
+
+ if (!result.empty())
+ {
+ result += ".";
+ }
+ result += fix;
+ }
+ while (pos != string::npos);
+
+ if (!_package.empty())
+ {
+ return _package + "." + result;
+ }
+ else
+ {
+ return result;
+ }
+}
+
+string
+Slice::JavaGenerator::typeToString(const TypePtr& type,
+ TypeMode mode,
+ const string& scope) const
+{
+ static const char* builtinTable[] =
+ {
+ "byte",
+ "boolean",
+ "short",
+ "int",
+ "long",
+ "float",
+ "double",
+ "String",
+ "Ice.Object",
+ "Ice.ObjectPrx",
+ "Ice.LocalObject"
+ };
+ static const char* builtinHolderTable[] =
+ {
+ "Ice.ByteHolder",
+ "Ice.BooleanHolder",
+ "Ice.ShortHolder",
+ "Ice.IntHolder",
+ "Ice.LongHolder",
+ "Ice.FloatHolder",
+ "Ice.DoubleHolder",
+ "Ice.StringHolder",
+ "Ice.ObjectHolder",
+ "Ice.ObjectPrxHolder",
+ "Ice.LocalObjectHolder"
+ };
+
+ if (!type)
+ {
+ assert(mode == TypeModeReturn);
+ return "void";
+ }
+
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
+ if (builtin)
+ {
+ if (mode == TypeModeOut)
+ {
+ return builtinHolderTable[builtin->kind()];
+ }
+ else
+ {
+ return builtinTable[builtin->kind()];
+ }
+ }
+
+ ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
+ if (cl)
+ {
+ string result = getAbsolute(cl->scoped(), scope);
+ if (mode == TypeModeOut)
+ {
+ result += "Holder";
+ }
+ return result;
+ }
+
+ ProxyPtr proxy = ProxyPtr::dynamicCast(type);
+ if (proxy)
+ {
+ string result = getAbsolute(proxy->_class()->scoped() + "Prx", scope);
+ if (mode == TypeModeOut)
+ {
+ result += "Holder";
+ }
+ return result;
+ }
+
+ DictionaryPtr dict = DictionaryPtr::dynamicCast(type);
+ if (dict)
+ {
+ if (mode == TypeModeOut)
+ {
+ return getAbsolute(dict->scoped(), scope) + "Holder";
+ }
+ else
+ {
+ return "java.util.Map";
+ }
+ }
+
+ SequencePtr seq = SequencePtr::dynamicCast(type);
+ if (seq)
+ {
+ if (mode == TypeModeOut)
+ {
+ return getAbsolute(seq->scoped(), scope) + "Holder";
+ }
+ else
+ {
+ TypePtr content = seq->type();
+ return typeToString(content, mode, scope) + "[]";
+ }
+ }
+
+ ContainedPtr contained = ContainedPtr::dynamicCast(type);
+ if (contained)
+ {
+ if (mode == TypeModeOut)
+ {
+ return getAbsolute(contained->scoped(), scope) + "Holder";
+ }
+ else
+ {
+ return getAbsolute(contained->scoped(), scope);
+ }
+ }
+
+ return "???";
+}
+
+void
+Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
+ const string& scope,
+ const TypePtr& type,
+ const string& param,
+ bool marshal,
+ int& iter,
+ bool holder)
+{
+ string stream = marshal ? "__os" : "__is";
+ string v;
+ if (holder)
+ {
+ v = param + ".value";
+ }
+ else
+ {
+ v = param;
+ }
+
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
+ if (builtin)
+ {
+ switch (builtin->kind())
+ {
+ case Builtin::KindByte:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeByte(" << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readByte();";
+ }
+ break;
+ }
+ case Builtin::KindBool:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeBool(" << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readBool();";
+ }
+ break;
+ }
+ case Builtin::KindShort:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeShort(" << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readShort();";
+ }
+ break;
+ }
+ case Builtin::KindInt:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeInt(" << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readInt();";
+ }
+ break;
+ }
+ case Builtin::KindLong:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeLong(" << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readLong();";
+ }
+ break;
+ }
+ case Builtin::KindFloat:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeFloat(" << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readFloat();";
+ }
+ break;
+ }
+ case Builtin::KindDouble:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeDouble(" << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readDouble();";
+ }
+ break;
+ }
+ case Builtin::KindString:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeString(" << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readString();";
+ }
+ break;
+ }
+ case Builtin::KindObject:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeObject(" << v << ");";
+ }
+ else
+ {
+ out << nl << "v = " << stream << ".readObject(\"\", null);";
+ }
+ break;
+ }
+ case Builtin::KindObjectProxy:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeProxy(" << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readProxy();";
+ }
+ break;
+ }
+ case Builtin::KindLocalObject:
+ {
+ assert(false);
+ break;
+ }
+ }
+ return;
+ }
+
+ ProxyPtr prx = ProxyPtr::dynamicCast(type);
+ if (prx)
+ {
+ string typeS = typeToString(type, TypeModeIn, scope);
+ if (marshal)
+ {
+ out << nl << typeS << "Helper.__write(" << stream << ", "
+ << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << typeS << "Helper.__read(" << stream
+ << ");";
+ }
+ return;
+ }
+
+ ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
+ if (cl)
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeObject(" << v << ");";
+ }
+ else
+ {
+ string typeS = typeToString(type, TypeModeIn, scope);
+ ClassDefPtr def = cl->definition();
+ if (def && !def->isAbstract())
+ {
+ out << nl << v << " = (" << typeS << ')' << stream << ".readObject(" << typeS << ".__classIds[0], "
+ << typeS << "._factory);";
+ }
+ else
+ {
+ out << nl << v << " = (" << typeS << ')' << stream << ".readObject(\"\", null);";
+ }
+ }
+ return;
+ }
+
+ StructPtr st = StructPtr::dynamicCast(type);
+ if (st)
+ {
+ if (marshal)
+ {
+ out << nl << v << ".__write(" << stream << ");";
+ }
+ else
+ {
+ string typeS = typeToString(type, TypeModeIn, scope);
+ out << nl << v << " = new " << typeS << "();";
+ out << nl << v << ".__read(" << stream << ");";
+ }
+ return;
+ }
+
+ EnumPtr en = EnumPtr::dynamicCast(type);
+ if (en)
+ {
+ if (marshal)
+ {
+ out << nl << v << ".__write(" << stream << ");";
+ }
+ else
+ {
+ string typeS = typeToString(type, TypeModeIn, scope);
+ out << nl << v << " = " << typeS << ".__read(" << stream << ");";
+ }
+ return;
+ }
+
+ SequencePtr seq = SequencePtr::dynamicCast(type);
+ if (seq)
+ {
+ BuiltinPtr b = BuiltinPtr::dynamicCast(seq->type());
+ if (b)
+ {
+ switch (b->kind())
+ {
+ case Builtin::KindByte:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeByteSeq(" << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readByteSeq();";
+ }
+ break;
+ }
+ case Builtin::KindBool:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeBoolSeq(" << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readBoolSeq();";
+ }
+ break;
+ }
+ case Builtin::KindShort:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeShortSeq(" << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream
+ << ".readShortSeq();";
+ }
+ break;
+ }
+ case Builtin::KindInt:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeIntSeq(" << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readIntSeq();";
+ }
+ break;
+ }
+ case Builtin::KindLong:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeLongSeq(" << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readLongSeq();";
+ }
+ break;
+ }
+ case Builtin::KindFloat:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeFloatSeq(" << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream
+ << ".readFloatSeq();";
+ }
+ break;
+ }
+ case Builtin::KindDouble:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeDoubleSeq(" << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream
+ << ".readDoubleSeq();";
+ }
+ break;
+ }
+ case Builtin::KindString:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeStringSeq(" << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream
+ << ".readStringSeq();";
+ }
+ break;
+ }
+ case Builtin::KindObject:
+ case Builtin::KindObjectProxy:
+ {
+ string typeS = getAbsolute(seq->scoped(), scope);
+ if (marshal)
+ {
+ out << nl << typeS << "Helper.write(" << stream
+ << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << typeS << "Helper.read("
+ << stream << ");";
+ }
+ break;
+ }
+ case Builtin::KindLocalObject:
+ {
+ assert(false);
+ break;
+ }
+ }
+ }
+ else
+ {
+ ContainedPtr cont = ContainedPtr::dynamicCast(type);
+ assert(cont);
+ string typeS = getAbsolute(cont->scoped(), scope);
+ if (marshal)
+ {
+ out << nl << typeS << "Helper.write(" << stream << ", "
+ << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << typeS << "Helper.read(" << stream
+ << ");";
+ }
+ }
+ return;
+ }
+
+ ConstructedPtr constructed = ConstructedPtr::dynamicCast(type);
+ assert(constructed);
+ string typeS = getAbsolute(constructed->scoped(), scope);
+ if (marshal)
+ {
+ out << nl << typeS << "Helper.write(" << stream << ", "
+ << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << typeS << "Helper.read(" << stream
+ << ");";
+ }
+}
+
+void
+Slice::JavaGenerator::writeGenericMarshalUnmarshalCode(Output& out,
+ const string& scope,
+ const TypePtr& type,
+ const string& tn,
+ const string& param,
+ bool marshal,
+ int& iter,
+ bool holder)
+{
+ string stream = marshal ? "__os" : "__is";
+ string v;
+ if (holder)
+ {
+ v = param + ".value";
+ }
+ else
+ {
+ v = param;
+ }
+
+ string name;
+ if (tn.empty())
+ {
+ name = "\"" + param + "\"";
+ }
+ else
+ {
+ name = tn;
+ }
+
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
+ if (builtin)
+ {
+ switch (builtin->kind())
+ {
+ case Builtin::KindByte:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeByte(" << name << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readByte(" << name << ");";
+ }
+ break;
+ }
+ case Builtin::KindBool:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeBool(" << name << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readBool(" << name << ");";
+ }
+ break;
+ }
+ case Builtin::KindShort:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeShort(" << name << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readShort(" << name << ");";
+ }
+ break;
+ }
+ case Builtin::KindInt:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeInt(" << name << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readInt(" << name << ");";
+ }
+ break;
+ }
+ case Builtin::KindLong:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeLong(" << name << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readLong(" << name << ");";
+ }
+ break;
+ }
+ case Builtin::KindFloat:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeFloat(" << name << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readFloat(" << name << ");";
+ }
+ break;
+ }
+ case Builtin::KindDouble:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeDouble(" << name << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readDouble(" << name << ");";
+ }
+ break;
+ }
+ case Builtin::KindString:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeString(" << name << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readString(" << name << ");";
+ }
+ break;
+ }
+ case Builtin::KindObject:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeObject(" << name << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << "v = " << stream << ".readObject(" << name << ", \"\", null);";
+ }
+ break;
+ }
+ case Builtin::KindObjectProxy:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeProxy(" << name << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readProxy(" << name << ");";
+ }
+ break;
+ }
+ case Builtin::KindLocalObject:
+ {
+ assert(false);
+ break;
+ }
+ }
+ return;
+ }
+
+ ProxyPtr prx = ProxyPtr::dynamicCast(type);
+ if (prx)
+ {
+ string typeS = typeToString(type, TypeModeIn, scope);
+ if (marshal)
+ {
+ out << nl << typeS << "Helper.ice_marshal(" << name << ", " << stream << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << typeS << "Helper.ice_unmarshal(" << name << ", " << stream << ");";
+ }
+ return;
+ }
+
+ ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
+ if (cl)
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeObject(" << name << ", " << v << ");";
+ }
+ else
+ {
+ string typeS = typeToString(type, TypeModeIn, scope);
+ ClassDefPtr def = cl->definition();
+ if (def && !def->isAbstract())
+ {
+ out << nl << v << " = (" << typeS << ')' << stream << ".readObject(" << name << ", " << typeS
+ << ".__classIds[0], " << typeS << "._factory);";
+ }
+ else
+ {
+ out << nl << v << " = (" << typeS << ')' << stream << ".readObject(" << name << ", \"\", null);";
+ }
+ }
+ return;
+ }
+
+ StructPtr st = StructPtr::dynamicCast(type);
+ if (st)
+ {
+ if (marshal)
+ {
+ out << nl << v << ".ice_marshal(" << name << ", " << stream << ");";
+ }
+ else
+ {
+ string typeS = typeToString(type, TypeModeIn, scope);
+ out << nl << v << " = new " << typeS << "();";
+ out << nl << v << ".ice_unmarshal(" << name << ", " << stream << ");";
+ }
+ return;
+ }
+
+ EnumPtr en = EnumPtr::dynamicCast(type);
+ if (en)
+ {
+ if (marshal)
+ {
+ out << nl << v << ".ice_marshal(" << name << ", " << stream << ");";
+ }
+ else
+ {
+ string typeS = typeToString(type, TypeModeIn, scope);
+ out << nl << v << " = " << typeS << ".ice_unmarshal(" << name << ", " << stream << ");";
+ }
+ return;
+ }
+
+ SequencePtr seq = SequencePtr::dynamicCast(type);
+ if (seq)
+ {
+ BuiltinPtr b = BuiltinPtr::dynamicCast(seq->type());
+ if (b)
+ {
+ switch (b->kind())
+ {
+ case Builtin::KindByte:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeByteSeq(" << name << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readByteSeq(" << name << ");";
+ }
+ break;
+ }
+ case Builtin::KindBool:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeBoolSeq(" << name << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readBoolSeq(" << name << ");";
+ }
+ break;
+ }
+ case Builtin::KindShort:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeShortSeq(" << name << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readShortSeq(" << name << ");";
+ }
+ break;
+ }
+ case Builtin::KindInt:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeIntSeq(" << name << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readIntSeq(" << name << ");";
+ }
+ break;
+ }
+ case Builtin::KindLong:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeLongSeq(" << name << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readLongSeq(" << name << ");";
+ }
+ break;
+ }
+ case Builtin::KindFloat:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeFloatSeq(" << name << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readFloatSeq(" << name << ");";
+ }
+ break;
+ }
+ case Builtin::KindDouble:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeDoubleSeq(" << name << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readDoubleSeq(" << name << ");";
+ }
+ break;
+ }
+ case Builtin::KindString:
+ {
+ if (marshal)
+ {
+ out << nl << stream << ".writeStringSeq(" << name << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << stream << ".readStringSeq(" << name << ");";
+ }
+ break;
+ }
+ case Builtin::KindObject:
+ case Builtin::KindObjectProxy:
+ {
+ string typeS = getAbsolute(seq->scoped(), scope);
+ if (marshal)
+ {
+ out << nl << typeS << "Helper.ice_marshal(" << name << ", " << stream << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << typeS << "Helper.ice_unmarshal(" << name << ", " << stream << ");";
+ }
+ break;
+ }
+ case Builtin::KindLocalObject:
+ {
+ assert(false);
+ break;
+ }
+ }
+ }
+ else
+ {
+ ContainedPtr cont = ContainedPtr::dynamicCast(type);
+ assert(cont);
+ string typeS = getAbsolute(cont->scoped(), scope);
+ if (marshal)
+ {
+ out << nl << typeS << "Helper.ice_marshal(" << name << ", " << stream << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << typeS << "Helper.ice_unmarshal(" << name << ", " << stream << ");";
+ }
+ }
+ return;
+ }
+
+ ConstructedPtr constructed = ConstructedPtr::dynamicCast(type);
+ assert(constructed);
+ string typeS = getAbsolute(constructed->scoped(), scope);
+ if (marshal)
+ {
+ out << nl << typeS << "Helper.ice_marshal(" << name << ", " << stream << ", " << v << ");";
+ }
+ else
+ {
+ out << nl << v << " = " << typeS << "Helper.ice_unmarshal(" << name << ", " << stream << ");";
+ }
+}
+
+void
+Slice::JavaGenerator::printHeader()
+{
+ static const char* header =
+"// **********************************************************************\n"
+"//\n"
+"// Copyright (c) 2002\n"
+"// MutableRealms, Inc.\n"
+"// Huntsville, AL, USA\n"
+"//\n"
+"// All Rights Reserved\n"
+"//\n"
+"// **********************************************************************\n"
+ ;
+
+ Output& out = output();
+ out << header;
+ out << "\n// Ice version " << ICE_STRING_VERSION;
+}
diff --git a/cpp/src/Slice/Makefile b/cpp/src/Slice/Makefile
index 378b6a89c80..9faa3c0bf23 100644
--- a/cpp/src/Slice/Makefile
+++ b/cpp/src/Slice/Makefile
@@ -21,7 +21,8 @@ TARGETS = $(NAME) $(VERSIONED_NAME)
OBJS = Scanner.o \
Grammar.o \
Parser.o \
- CPlusPlusUtil.o
+ CPlusPlusUtil.o \
+ JavaUtil.o
SRCS = $(OBJS:.o=.cpp)
diff --git a/cpp/src/slice2freezej/.depend b/cpp/src/slice2freezej/.depend
new file mode 100644
index 00000000000..89e603a0600
--- /dev/null
+++ b/cpp/src/slice2freezej/.depend
@@ -0,0 +1 @@
+Main.o: Main.cpp ../../include/Slice/JavaUtil.h ../../include/Slice/Parser.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/OutputUtil.h
diff --git a/cpp/src/slice2freezej/Main.cpp b/cpp/src/slice2freezej/Main.cpp
new file mode 100644
index 00000000000..1fbd2ccb45a
--- /dev/null
+++ b/cpp/src/slice2freezej/Main.cpp
@@ -0,0 +1,539 @@
+// **********************************************************************
+//
+// Copyright (c) 2002
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#include <Slice/JavaUtil.h>
+#include <fstream>
+
+using namespace std;
+using namespace Slice;
+using namespace IceUtil;
+
+struct Dict
+{
+ string name;
+ string key;
+ string value;
+};
+
+class FreezeGenerator : public JavaGenerator
+{
+public:
+ FreezeGenerator(const string&, const string&);
+
+ bool generate(UnitPtr&, const Dict&);
+
+private:
+ string _prog;
+};
+
+FreezeGenerator::FreezeGenerator(const string& prog, const string& dir)
+ : JavaGenerator(dir, string()),
+ _prog(prog)
+{
+}
+
+bool
+FreezeGenerator::generate(UnitPtr& unit, const Dict& dict)
+{
+ static const char* builtinTable[] =
+ {
+ "java.lang.Byte",
+ "java.lang.Boolean",
+ "java.lang.Short",
+ "java.lang.Integer",
+ "java.lang.Long",
+ "java.lang.Float",
+ "java.lang.Double",
+ "java.lang.String",
+ "Ice.Object",
+ "Ice.ObjectPrx",
+ "Ice.LocalObject"
+ };
+
+ string name;
+ string::size_type pos = dict.name.rfind('.');
+ if (pos == string::npos)
+ {
+ name = dict.name;
+ }
+ else
+ {
+ name = dict.name.substr(pos + 1);
+ }
+
+ TypeList keyTypes = unit->lookupType(dict.key, false);
+ if (keyTypes.empty())
+ {
+ cerr << _prog << ": `" << dict.key << "' is not a valid type" << endl;
+ return false;
+ }
+ TypePtr keyType = keyTypes.front();
+
+ TypeList valueTypes = unit->lookupType(dict.value, false);
+ if (valueTypes.empty())
+ {
+ cerr << _prog << ": `" << dict.value << "' is not a valid type" << endl;
+ return false;
+ }
+ TypePtr valueType = valueTypes.front();
+
+ if (!open(dict.name))
+ {
+ cerr << _prog << ": unable to open class " << dict.name << endl;
+ return false;
+ }
+
+ Output& out = output();
+
+ out << sp << nl << "public class " << name << " extends Freeze.Map";
+ out << sb;
+
+ for (int i = 0; i < 2; i++)
+ {
+ string keyValue;
+ string keyValueTag;
+ TypePtr type;
+
+ if (i == 0)
+ {
+ keyValue = "Key";
+ keyValueTag = "\"" + dict.key + "\"";
+ type = keyType;
+ }
+ else
+ {
+ keyValue = "Value";
+ keyValueTag = "\"" + dict.value + "\"";
+ type = valueType;
+ }
+
+ string typeS, valS;
+ BuiltinPtr b = BuiltinPtr::dynamicCast(type);
+ if (b)
+ {
+ typeS = builtinTable[b->kind()];
+ switch (b->kind())
+ {
+ case Builtin::KindByte:
+ {
+ valS = "((java.lang.Byte)o).byteValue()";
+ break;
+ }
+ case Builtin::KindBool:
+ {
+ valS = "((java.lang.Boolean)o).booleanValue()";
+ break;
+ }
+ case Builtin::KindShort:
+ {
+ valS = "((java.lang.Short)o).shortValue()";
+ break;
+ }
+ case Builtin::KindInt:
+ {
+ valS = "((java.lang.Integer)o).intValue()";
+ break;
+ }
+ case Builtin::KindLong:
+ {
+ valS = "((java.lang.Long)o).longValue()";
+ break;
+ }
+ case Builtin::KindFloat:
+ {
+ valS = "((java.lang.Float)o).floatValue()";
+ break;
+ }
+ case Builtin::KindDouble:
+ {
+ valS = "((java.lang.Double)o).doubleValue()";
+ break;
+ }
+ case Builtin::KindString:
+ case Builtin::KindObject:
+ case Builtin::KindObjectProxy:
+ case Builtin::KindLocalObject:
+ {
+ valS = "(" + typeS + ")o";
+ break;
+ }
+ }
+ }
+ else
+ {
+ typeS = typeToString(type, TypeModeIn);
+ valS = "(" + typeS + ")o";
+ }
+
+ int iter = 0;
+
+ //
+ // encode
+ //
+ out << sp << nl << "public byte[]" << nl << "encode" << keyValue
+ << "(Object o, Ice.Communicator communicator)";
+ out << sb;
+ out << nl << "assert(o instanceof " << typeS << ");";
+ out << nl << "java.io.StringWriter sw = new java.io.StringWriter();";
+ out << nl << "java.io.PrintWriter pw = new java.io.PrintWriter(sw);";
+ out << nl << "pw.print(\"<data>\");";
+ out << nl << "Ice.Stream __os = new IceXML.StreamI(communicator, pw);";
+ writeGenericMarshalUnmarshalCode(out, "", type, keyValueTag, valS, true, iter, false);
+ out << nl << "pw.print(\"</data>\");";
+ out << nl << "pw.flush();";
+ out << nl << "return sw.toString().getBytes();";
+ out << eb;
+
+ //
+ // decode
+ //
+ out << sp << nl << "public Object" << nl << "decode" << keyValue
+ << "(byte[] b, Ice.Communicator communicator)";
+ out << sb;
+ out << nl << "java.io.StringReader sr = new java.io.StringReader(new String(b));";
+ out << nl << "Ice.Stream __is = new IceXML.StreamI(communicator, sr);";
+ out << nl << typeS << " __r;";
+ if (b)
+ {
+ switch (b->kind())
+ {
+ case Builtin::KindByte:
+ {
+ out << nl << "__r = new java.lang.Byte(__is.readByte(" << keyValueTag << "));";
+ break;
+ }
+ case Builtin::KindBool:
+ {
+ out << nl << "__r = new java.lang.Boolean(__is.readBool(" << keyValueTag << "));";
+ break;
+ }
+ case Builtin::KindShort:
+ {
+ out << nl << "__r = new java.lang.Short(__is.readShort(" << keyValueTag << "));";
+ break;
+ }
+ case Builtin::KindInt:
+ {
+ out << nl << "__r = new java.lang.Integer(__is.readInt(" << keyValueTag << "));";
+ break;
+ }
+ case Builtin::KindLong:
+ {
+ out << nl << "__r = new java.lang.Long(__is.readLong(" << keyValueTag << "));";
+ break;
+ }
+ case Builtin::KindFloat:
+ {
+ out << nl << "__r = new java.lang.Float(__is.readFloat(" << keyValueTag << "));";
+ break;
+ }
+ case Builtin::KindDouble:
+ {
+ out << nl << "__r = new java.lang.Double(__is.readDouble(" << keyValueTag << "));";
+ break;
+ }
+ case Builtin::KindString:
+ case Builtin::KindObject:
+ case Builtin::KindObjectProxy:
+ case Builtin::KindLocalObject:
+ {
+ writeGenericMarshalUnmarshalCode(out, "", type, keyValueTag, "__r", false, iter, false);
+ break;
+ }
+ }
+ }
+ else
+ {
+ writeGenericMarshalUnmarshalCode(out, "", type, keyValueTag, "__r", false, iter, false);
+ }
+ out << nl << "return __r;";
+ out << eb;
+ }
+
+ out << eb;
+
+ close();
+
+ return true;
+}
+
+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"
+ "--include-dir DIR Use DIR as the header include directory.\n"
+ "--dict NAME,KEY,VALUE Create a Freeze dictionary with the name NAME,\n"
+ " using KEY as key, and VALUE as value. This\n"
+ " option may be specified multiple times for\n"
+ " different names. NAME may be a scoped name.\n"
+ "--output-dir DIR Create files in the directory DIR.\n"
+ "-d, --debug Print debug messages.\n"
+ ;
+}
+
+int
+main(int argc, char* argv[])
+{
+ string cpp("cpp");
+ vector<string> includePaths;
+ string include;
+ string output;
+ bool debug = false;
+ vector<Dict> dicts;
+
+ int idx = 1;
+ while (idx < argc)
+ {
+ if (strncmp(argv[idx], "-I", 2) == 0)
+ {
+ cpp += ' ';
+ cpp += argv[idx];
+
+ string path = argv[idx] + 2;
+ if (path.length())
+ {
+ includePaths.push_back(path);
+ }
+
+ for (int i = idx ; i + 1 < argc ; ++i)
+ {
+ argv[i] = argv[i + 1];
+ }
+ --argc;
+ }
+ else if (strncmp(argv[idx], "-D", 2) == 0 || strncmp(argv[idx], "-U", 2) == 0)
+ {
+ cpp += ' ';
+ cpp += argv[idx];
+
+ for (int i = idx ; i + 1 < argc ; ++i)
+ {
+ argv[i] = argv[i + 1];
+ }
+ --argc;
+ }
+ else if (strcmp(argv[idx], "--dict") == 0)
+ {
+ if (idx + 1 >= argc || argv[idx + 1][0] == '-')
+ {
+ cerr << argv[0] << ": argument expected for`" << argv[idx] << "'" << endl;
+ usage(argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ string s = argv[idx + 1];
+ s.erase(remove_if(s.begin(), s.end(), isspace), s.end());
+
+ Dict dict;
+
+ string::size_type pos;
+ pos = s.find(',');
+ if (pos != string::npos)
+ {
+ dict.name = s.substr(0, pos);
+ s.erase(0, pos + 1);
+ }
+ pos = s.find(',');
+ if (pos != string::npos)
+ {
+ dict.key = s.substr(0, pos);
+ s.erase(0, pos + 1);
+ }
+ dict.value = s;
+
+ if (dict.name.empty())
+ {
+ cerr << argv[0] << ": " << argv[idx] << ": no name specified" << endl;
+ usage(argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ if (dict.key.empty())
+ {
+ cerr << argv[0] << ": " << argv[idx] << ": no key specified" << endl;
+ usage(argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ if (dict.value.empty())
+ {
+ cerr << argv[0] << ": " << argv[idx] << ": no value specified" << endl;
+ usage(argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ dicts.push_back(dict);
+
+ for (int i = idx ; i + 2 < argc ; ++i)
+ {
+ argv[i] = argv[i + 2];
+ }
+ argc -= 2;
+ }
+ else if (strcmp(argv[idx], "-h") == 0 || strcmp(argv[idx], "--help") == 0)
+ {
+ usage(argv[0]);
+ return EXIT_SUCCESS;
+ }
+ else if (strcmp(argv[idx], "-v") == 0 || strcmp(argv[idx], "--version") == 0)
+ {
+ cout << ICE_STRING_VERSION << endl;
+ return EXIT_SUCCESS;
+ }
+ else if (strcmp(argv[idx], "-d") == 0 || strcmp(argv[idx], "--debug") == 0)
+ {
+ debug = true;
+ for (int i = idx ; i + 1 < argc ; ++i)
+ {
+ argv[i] = argv[i + 1];
+ }
+ --argc;
+ }
+ else if (strcmp(argv[idx], "--include-dir") == 0)
+ {
+ if (idx + 1 >= argc)
+ {
+ cerr << argv[0] << ": argument expected for`" << argv[idx] << "'" << endl;
+ usage(argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ include = argv[idx + 1];
+ for (int i = idx ; i + 2 < argc ; ++i)
+ {
+ argv[i] = argv[i + 2];
+ }
+ argc -= 2;
+ }
+ else if (strcmp(argv[idx], "--output-dir") == 0)
+ {
+ if (idx + 1 >= argc)
+ {
+ cerr << argv[0] << ": argument expected for`" << argv[idx] << "'" << endl;
+ usage(argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ output = argv[idx + 1];
+ for (int i = idx ; i + 2 < argc ; ++i)
+ {
+ argv[i] = argv[i + 2];
+ }
+ argc -= 2;
+ }
+ else if (argv[idx][0] == '-')
+ {
+ cerr << argv[0] << ": unknown option `" << argv[idx] << "'" << endl;
+ usage(argv[0]);
+ return EXIT_FAILURE;
+ }
+ else
+ {
+ ++idx;
+ }
+ }
+
+ if (dicts.empty())
+ {
+ cerr << argv[0] << ": no Freeze types specified" << endl;
+ usage(argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ UnitPtr unit = Unit::createUnit(true, false);
+
+ StringList includes;
+
+ int status = EXIT_SUCCESS;
+
+ for (idx = 1 ; idx < argc ; ++idx)
+ {
+ string base(argv[idx]);
+ string suffix;
+ string::size_type pos = base.rfind('.');
+ if (pos != string::npos)
+ {
+ suffix = base.substr(pos);
+ transform(suffix.begin(), suffix.end(), suffix.begin(), tolower);
+ }
+ if (suffix != ".ice")
+ {
+ cerr << argv[0] << ": input files must end with `.ice'" << endl;
+ return EXIT_FAILURE;
+ }
+
+ ifstream test(argv[idx]);
+ if (!test)
+ {
+ cerr << argv[0] << ": can't open `" << argv[idx] << "' for reading: " << strerror(errno) << endl;
+ return EXIT_FAILURE;
+ }
+ test.close();
+
+ string cmd = cpp + " " + argv[idx];
+#ifdef WIN32
+ FILE* cppHandle = _popen(cmd.c_str(), "r");
+#else
+ FILE* cppHandle = popen(cmd.c_str(), "r");
+#endif
+ if (cppHandle == 0)
+ {
+ cerr << argv[0] << ": can't run C++ preprocessor: " << strerror(errno) << endl;
+ unit->destroy();
+ return EXIT_FAILURE;
+ }
+
+ status = unit->parse(cppHandle, debug);
+
+#ifdef WIN32
+ _pclose(cppHandle);
+#else
+ pclose(cppHandle);
+#endif
+ }
+
+ if (status == EXIT_SUCCESS)
+ {
+ unit->mergeModules();
+ unit->sort();
+
+ FreezeGenerator gen(argv[0], output);
+
+ for (vector<Dict>::const_iterator p = dicts.begin(); p != dicts.end(); ++p)
+ {
+ try
+ {
+ if (!gen.generate(unit, *p))
+ {
+ unit->destroy();
+ return EXIT_FAILURE;
+ }
+ }
+ catch(...)
+ {
+ cerr << argv[0] << ": unknown exception" << endl;
+ unit->destroy();
+ return EXIT_FAILURE;
+ }
+ }
+ }
+
+ unit->destroy();
+
+ return status;
+}
diff --git a/cpp/src/slice2freezej/Makefile b/cpp/src/slice2freezej/Makefile
new file mode 100644
index 00000000000..365e5ca5d9d
--- /dev/null
+++ b/cpp/src/slice2freezej/Makefile
@@ -0,0 +1,29 @@
+# **********************************************************************
+#
+# Copyright (c) 2001
+# MutableRealms, Inc.
+# Huntsville, AL, USA
+#
+# All Rights Reserved
+#
+# **********************************************************************
+
+top_srcdir = ../..
+
+NAME = $(top_srcdir)/bin/slice2freezej
+
+TARGETS = $(NAME)
+
+OBJS = Main.o
+
+SRCS = $(OBJS:.o=.cpp)
+
+include $(top_srcdir)/config/Make.rules
+
+CPPFLAGS := -I. $(CPPFLAGS)
+
+$(NAME): $(OBJS)
+ rm -f $@
+ $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJS) -lSlice $(BASELIBS)
+
+include .depend
diff --git a/cpp/src/slice2freezej/slice2freezej.dsp b/cpp/src/slice2freezej/slice2freezej.dsp
new file mode 100644
index 00000000000..43de96ae7a3
--- /dev/null
+++ b/cpp/src/slice2freezej/slice2freezej.dsp
@@ -0,0 +1,106 @@
+# Microsoft Developer Studio Project File - Name="slice2freezej" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=slice2freezej - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "slice2freezej.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "slice2freezej.mak" CFG="slice2freezej - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "slice2freezej - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "slice2freezej - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=xicl6.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "slice2freezej - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /WX /GR /GX /O2 /I "." /I "../../include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_UNICODE" /YX /FD /c
+# SUBTRACT CPP /Fr
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=xilink6.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 setargv.obj /nologo /subsystem:console /machine:I386 /out:"../../bin/slice2freezej.exe" /libpath:"../../lib"
+# SUBTRACT LINK32 /debug /nodefaultlib
+
+!ELSEIF "$(CFG)" == "slice2freezej - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /WX /Gm /GR /GX /Zi /Od /I "." /I "../../include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_UNICODE" /YX /FD /GZ /c
+# SUBTRACT CPP /Fr
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=xilink6.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 setargv.obj /nologo /subsystem:console /debug /machine:I386 /out:"../../bin/slice2freezej.exe" /pdbtype:sept /libpath:"../../lib"
+# SUBTRACT LINK32 /nodefaultlib
+
+!ENDIF
+
+# Begin Target
+
+# Name "slice2freezej - Win32 Release"
+# Name "slice2freezej - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\Main.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp
index 1690ef57d49..9e22432f0ca 100644
--- a/cpp/src/slice2java/Gen.cpp
+++ b/cpp/src/slice2java/Gen.cpp
@@ -12,381 +12,17 @@
#include <Gen.h>
#include <limits>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#ifdef WIN32
-#include <direct.h>
-#endif
-
-#ifndef WIN32
-#include <unistd.h>
-#endif
-
using namespace std;
using namespace Slice;
using namespace IceUtil;
Slice::JavaVisitor::JavaVisitor(const string& dir, const string& package) :
- _dir(dir),
- _package(package),
- _out(0)
+ JavaGenerator(dir, package)
{
}
Slice::JavaVisitor::~JavaVisitor()
{
- assert(_out == 0);
-}
-
-bool
-Slice::JavaVisitor::open(const string& absolute)
-{
- string package;
- string file;
- string path = _dir;
-
- assert(_out == 0);
-
- string::size_type pos = absolute.rfind('.');
- if (pos != string::npos)
- {
- package = absolute.substr(0, pos);
- file = absolute.substr(pos + 1);
- string dir = package;
-
- //
- // Create package directories if necessary
- //
- pos = 0;
- string::size_type start = 0;
- do
- {
- if (!path.empty())
- {
- path += "/";
- }
- pos = dir.find('.', start);
- if (pos != string::npos)
- {
- path += dir.substr(start, pos - start);
- start = pos + 1;
- }
- else
- {
- path += dir.substr(start);
- }
-
- struct stat st;
- int result;
- result = stat(path.c_str(), &st);
- if (result == 0)
- {
- continue;
- }
-#ifdef WIN32
- result = _mkdir(path.c_str());
-#else
- result = mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
-#endif
- if (result != 0)
- {
- cerr << "can't create directory `" << path << "': "
- << strerror(errno) << endl;
- return false;
- }
- }
- while (pos != string::npos);
- }
- else
- {
- file = absolute;
- }
- file += ".java";
-
- //
- // Open class file
- //
- if (!path.empty())
- {
- path += "/";
- }
- path += file;
- _out = new Output();
- _out->open(path.c_str());
- if (!(*_out))
- {
- cerr << "can't open `" << path << "' for writing: "
- << strerror(errno) << endl;
- close();
- return false;
- }
-
- printHeader();
-
- if (!package.empty())
- {
- *_out << sp << nl << "package " << package << ';';
- }
-
- return true;
-}
-
-void
-Slice::JavaVisitor::close()
-{
- assert(_out != 0);
- *_out << nl;
- delete _out;
- _out = 0;
-}
-
-Output&
-Slice::JavaVisitor::output() const
-{
- assert(_out != 0);
- return *_out;
-}
-
-string
-Slice::JavaVisitor::fixKwd(const string& name) const
-{
- //
- // Alphabetical list of Java keywords
- //
- static const char* keywords[] =
- {
- "abstract", "assert", "boolean", "break", "byte", "case", "catch",
- "char", "class", "clone", "const", "continue", "default", "do",
- "double", "else", "equals", "extends", "false", "final", "finalize",
- "finally", "float", "for", "getClass", "goto", "hashCode", "if",
- "implements", "import", "instanceof", "int", "interface", "long",
- "native", "new", "notify", "notifyAll", "null", "package", "private",
- "protected", "public", "return", "short", "static", "super", "switch",
- "synchronized", "this", "throw", "throws", "toString", "transient",
- "true", "try", "void", "volatile", "wait", "while"
- };
-
- int i = 0;
- int j = sizeof(keywords) / sizeof(const char*);
-
- while (i < j)
- {
- int mid = (i + j) / 2;
- string str = keywords[mid];
- int n = str.compare(name);
- if (n == 0)
- {
- string result = "_" + name;
- return result;
- }
- else if (n > 0)
- {
- j = mid;
- }
- else
- {
- i = mid + 1;
- }
- }
-
- return name;
-}
-
-string
-Slice::JavaVisitor::getAbsolute(const string& scoped,
- const string& scope,
- const string& prefix,
- const string& suffix) const
-{
- string result;
- string::size_type start = 0;
-
- if (!scope.empty())
- {
- //
- // Only remove the scope if the resulting symbol is unscoped.
- // For example:
- //
- // scope=::A, scoped=::A::B, result=B
- // scope=::A, scoped=::A::B::C, result=::A::B::C
- //
- string::size_type scopeSize = scope.size();
- if (scoped.compare(0, scopeSize, scope) == 0)
- {
- start = scoped.find(':', scopeSize);
- if (start == string::npos)
- {
- start = scopeSize;
- }
- else
- {
- start = 0;
- }
- }
- }
-
- //
- // Skip leading "::"
- //
- if (scoped[start] == ':')
- {
- assert(scoped[start + 1] == ':');
- start += 2;
- }
-
- //
- // Convert all occurrences of "::" to "."
- //
- string::size_type pos;
- do
- {
- pos = scoped.find(':', start);
- string fix;
- if (pos == string::npos)
- {
- fix = prefix + fixKwd(scoped.substr(start)) + suffix;
- }
- else
- {
- assert(scoped[pos + 1] == ':');
- fix = fixKwd(scoped.substr(start, pos - start));
- start = pos + 2;
- }
-
- if (!result.empty())
- {
- result += ".";
- }
- result += fix;
- }
- while (pos != string::npos);
-
- if (!_package.empty())
- {
- return _package + "." + result;
- }
- else
- {
- return result;
- }
-}
-
-string
-Slice::JavaVisitor::typeToString(const TypePtr& type, TypeMode mode,
- const string& scope) const
-{
- static const char* builtinTable[] =
- {
- "byte",
- "boolean",
- "short",
- "int",
- "long",
- "float",
- "double",
- "String",
- "Ice.Object",
- "Ice.ObjectPrx",
- "Ice.LocalObject"
- };
- static const char* builtinHolderTable[] =
- {
- "Ice.ByteHolder",
- "Ice.BooleanHolder",
- "Ice.ShortHolder",
- "Ice.IntHolder",
- "Ice.LongHolder",
- "Ice.FloatHolder",
- "Ice.DoubleHolder",
- "Ice.StringHolder",
- "Ice.ObjectHolder",
- "Ice.ObjectPrxHolder",
- "Ice.LocalObjectHolder"
- };
-
- if (!type)
- {
- assert(mode == TypeModeReturn);
- return "void";
- }
-
- BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
- if (builtin)
- {
- if (mode == TypeModeOut)
- {
- return builtinHolderTable[builtin->kind()];
- }
- else
- {
- return builtinTable[builtin->kind()];
- }
- }
-
- ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
- if (cl)
- {
- string result = getAbsolute(cl->scoped(), scope);
- if (mode == TypeModeOut)
- {
- result += "Holder";
- }
- return result;
- }
-
- ProxyPtr proxy = ProxyPtr::dynamicCast(type);
- if (proxy)
- {
- string result = getAbsolute(proxy->_class()->scoped() + "Prx", scope);
- if (mode == TypeModeOut)
- {
- result += "Holder";
- }
- return result;
- }
-
- DictionaryPtr dict = DictionaryPtr::dynamicCast(type);
- if (dict)
- {
- if (mode == TypeModeOut)
- {
- return getAbsolute(dict->scoped(), scope) + "Holder";
- }
- else
- {
- return "java.util.Map";
- }
- }
-
- SequencePtr seq = SequencePtr::dynamicCast(type);
- if (seq)
- {
- if (mode == TypeModeOut)
- {
- return getAbsolute(seq->scoped(), scope) + "Holder";
- }
- else
- {
- TypePtr content = seq->type();
- return typeToString(content, mode, scope) + "[]";
- }
- }
-
- ContainedPtr contained = ContainedPtr::dynamicCast(type);
- if (contained)
- {
- if (mode == TypeModeOut)
- {
- return getAbsolute(contained->scoped(), scope) + "Holder";
- }
- else
- {
- return getAbsolute(contained->scoped(), scope);
- }
- }
-
- return "???";
}
string
@@ -536,785 +172,6 @@ Slice::JavaVisitor::writeDelegateThrowsClause(const string& scope,
}
void
-Slice::JavaVisitor::writeMarshalUnmarshalCode(Output& out, const string& scope,
- const TypePtr& type,
- const string& param,
- bool marshal, int& iter,
- bool holder)
-{
- string stream = marshal ? "__os" : "__is";
- string v;
- if (holder)
- {
- v = param + ".value";
- }
- else
- {
- v = param;
- }
-
- BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
- if (builtin)
- {
- switch (builtin->kind())
- {
- case Builtin::KindByte:
- {
- if (marshal)
- {
- out << nl << stream << ".writeByte(" << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readByte();";
- }
- break;
- }
- case Builtin::KindBool:
- {
- if (marshal)
- {
- out << nl << stream << ".writeBool(" << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readBool();";
- }
- break;
- }
- case Builtin::KindShort:
- {
- if (marshal)
- {
- out << nl << stream << ".writeShort(" << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readShort();";
- }
- break;
- }
- case Builtin::KindInt:
- {
- if (marshal)
- {
- out << nl << stream << ".writeInt(" << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readInt();";
- }
- break;
- }
- case Builtin::KindLong:
- {
- if (marshal)
- {
- out << nl << stream << ".writeLong(" << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readLong();";
- }
- break;
- }
- case Builtin::KindFloat:
- {
- if (marshal)
- {
- out << nl << stream << ".writeFloat(" << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readFloat();";
- }
- break;
- }
- case Builtin::KindDouble:
- {
- if (marshal)
- {
- out << nl << stream << ".writeDouble(" << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readDouble();";
- }
- break;
- }
- case Builtin::KindString:
- {
- if (marshal)
- {
- out << nl << stream << ".writeString(" << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readString();";
- }
- break;
- }
- case Builtin::KindObject:
- {
- if (marshal)
- {
- out << nl << stream << ".writeObject(" << v << ");";
- }
- else
- {
- out << nl << "v = " << stream << ".readObject(\"\", null);";
- }
- break;
- }
- case Builtin::KindObjectProxy:
- {
- if (marshal)
- {
- out << nl << stream << ".writeProxy(" << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readProxy();";
- }
- break;
- }
- case Builtin::KindLocalObject:
- {
- assert(false);
- break;
- }
- }
- return;
- }
-
- ProxyPtr prx = ProxyPtr::dynamicCast(type);
- if (prx)
- {
- string typeS = typeToString(type, TypeModeIn, scope);
- if (marshal)
- {
- out << nl << typeS << "Helper.__write(" << stream << ", "
- << v << ");";
- }
- else
- {
- out << nl << v << " = " << typeS << "Helper.__read(" << stream
- << ");";
- }
- return;
- }
-
- ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
- if (cl)
- {
- if (marshal)
- {
- out << nl << stream << ".writeObject(" << v << ");";
- }
- else
- {
- string typeS = typeToString(type, TypeModeIn, scope);
- ClassDefPtr def = cl->definition();
- if (def && !def->isAbstract())
- {
- out << nl << v << " = (" << typeS << ')' << stream << ".readObject(" << typeS << ".__classIds[0], "
- << typeS << "._factory);";
- }
- else
- {
- out << nl << v << " = (" << typeS << ')' << stream << ".readObject(\"\", null);";
- }
- }
- return;
- }
-
- StructPtr st = StructPtr::dynamicCast(type);
- if (st)
- {
- if (marshal)
- {
- out << nl << v << ".__write(" << stream << ");";
- }
- else
- {
- string typeS = typeToString(type, TypeModeIn, scope);
- out << nl << v << " = new " << typeS << "();";
- out << nl << v << ".__read(" << stream << ");";
- }
- return;
- }
-
- EnumPtr en = EnumPtr::dynamicCast(type);
- if (en)
- {
- if (marshal)
- {
- out << nl << v << ".__write(" << stream << ");";
- }
- else
- {
- string typeS = typeToString(type, TypeModeIn, scope);
- out << nl << v << " = " << typeS << ".__read(" << stream << ");";
- }
- return;
- }
-
- SequencePtr seq = SequencePtr::dynamicCast(type);
- if (seq)
- {
- BuiltinPtr b = BuiltinPtr::dynamicCast(seq->type());
- if (b)
- {
- switch (b->kind())
- {
- case Builtin::KindByte:
- {
- if (marshal)
- {
- out << nl << stream << ".writeByteSeq(" << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readByteSeq();";
- }
- break;
- }
- case Builtin::KindBool:
- {
- if (marshal)
- {
- out << nl << stream << ".writeBoolSeq(" << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readBoolSeq();";
- }
- break;
- }
- case Builtin::KindShort:
- {
- if (marshal)
- {
- out << nl << stream << ".writeShortSeq(" << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream
- << ".readShortSeq();";
- }
- break;
- }
- case Builtin::KindInt:
- {
- if (marshal)
- {
- out << nl << stream << ".writeIntSeq(" << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readIntSeq();";
- }
- break;
- }
- case Builtin::KindLong:
- {
- if (marshal)
- {
- out << nl << stream << ".writeLongSeq(" << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readLongSeq();";
- }
- break;
- }
- case Builtin::KindFloat:
- {
- if (marshal)
- {
- out << nl << stream << ".writeFloatSeq(" << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream
- << ".readFloatSeq();";
- }
- break;
- }
- case Builtin::KindDouble:
- {
- if (marshal)
- {
- out << nl << stream << ".writeDoubleSeq(" << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream
- << ".readDoubleSeq();";
- }
- break;
- }
- case Builtin::KindString:
- {
- if (marshal)
- {
- out << nl << stream << ".writeStringSeq(" << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream
- << ".readStringSeq();";
- }
- break;
- }
- case Builtin::KindObject:
- case Builtin::KindObjectProxy:
- {
- string typeS = getAbsolute(seq->scoped(), scope);
- if (marshal)
- {
- out << nl << typeS << "Helper.write(" << stream
- << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << typeS << "Helper.read("
- << stream << ");";
- }
- break;
- }
- case Builtin::KindLocalObject:
- {
- assert(false);
- break;
- }
- }
- }
- else
- {
- ContainedPtr cont = ContainedPtr::dynamicCast(type);
- assert(cont);
- string typeS = getAbsolute(cont->scoped(), scope);
- if (marshal)
- {
- out << nl << typeS << "Helper.write(" << stream << ", "
- << v << ");";
- }
- else
- {
- out << nl << v << " = " << typeS << "Helper.read(" << stream
- << ");";
- }
- }
- return;
- }
-
- ConstructedPtr constructed = ConstructedPtr::dynamicCast(type);
- assert(constructed);
- string typeS = getAbsolute(constructed->scoped(), scope);
- if (marshal)
- {
- out << nl << typeS << "Helper.write(" << stream << ", "
- << v << ");";
- }
- else
- {
- out << nl << v << " = " << typeS << "Helper.read(" << stream
- << ");";
- }
-}
-
-void
-Slice::JavaVisitor::writeGenericMarshalUnmarshalCode(Output& out,
- const string& scope,
- const TypePtr& type,
- const string& tn,
- const string& param,
- bool marshal,
- int& iter,
- bool holder)
-{
- string stream = marshal ? "__os" : "__is";
- string v;
- if (holder)
- {
- v = param + ".value";
- }
- else
- {
- v = param;
- }
-
- string name;
- if (tn.empty())
- {
- name = "\"" + param + "\"";
- }
- else
- {
- name = tn;
- }
-
- BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
- if (builtin)
- {
- switch (builtin->kind())
- {
- case Builtin::KindByte:
- {
- if (marshal)
- {
- out << nl << stream << ".writeByte(" << name << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readByte(" << name << ");";
- }
- break;
- }
- case Builtin::KindBool:
- {
- if (marshal)
- {
- out << nl << stream << ".writeBool(" << name << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readBool(" << name << ");";
- }
- break;
- }
- case Builtin::KindShort:
- {
- if (marshal)
- {
- out << nl << stream << ".writeShort(" << name << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readShort(" << name << ");";
- }
- break;
- }
- case Builtin::KindInt:
- {
- if (marshal)
- {
- out << nl << stream << ".writeInt(" << name << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readInt(" << name << ");";
- }
- break;
- }
- case Builtin::KindLong:
- {
- if (marshal)
- {
- out << nl << stream << ".writeLong(" << name << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readLong(" << name << ");";
- }
- break;
- }
- case Builtin::KindFloat:
- {
- if (marshal)
- {
- out << nl << stream << ".writeFloat(" << name << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readFloat(" << name << ");";
- }
- break;
- }
- case Builtin::KindDouble:
- {
- if (marshal)
- {
- out << nl << stream << ".writeDouble(" << name << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readDouble(" << name << ");";
- }
- break;
- }
- case Builtin::KindString:
- {
- if (marshal)
- {
- out << nl << stream << ".writeString(" << name << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readString(" << name << ");";
- }
- break;
- }
- case Builtin::KindObject:
- {
- if (marshal)
- {
- out << nl << stream << ".writeObject(" << name << ", " << v << ");";
- }
- else
- {
- out << nl << "v = " << stream << ".readObject(" << name << ", \"\", null);";
- }
- break;
- }
- case Builtin::KindObjectProxy:
- {
- if (marshal)
- {
- out << nl << stream << ".writeProxy(" << name << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readProxy(" << name << ");";
- }
- break;
- }
- case Builtin::KindLocalObject:
- {
- assert(false);
- break;
- }
- }
- return;
- }
-
- ProxyPtr prx = ProxyPtr::dynamicCast(type);
- if (prx)
- {
- string typeS = typeToString(type, TypeModeIn, scope);
- if (marshal)
- {
- out << nl << typeS << "Helper.ice_marshal(" << name << ", " << stream << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << typeS << "Helper.ice_unmarshal(" << name << ", " << stream << ");";
- }
- return;
- }
-
- ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
- if (cl)
- {
- if (marshal)
- {
- out << nl << stream << ".writeObject(" << name << ", " << v << ");";
- }
- else
- {
- string typeS = typeToString(type, TypeModeIn, scope);
- ClassDefPtr def = cl->definition();
- if (def && !def->isAbstract())
- {
- out << nl << v << " = (" << typeS << ')' << stream << ".readObject(" << name << ", " << typeS
- << ".__classIds[0], " << typeS << "._factory);";
- }
- else
- {
- out << nl << v << " = (" << typeS << ')' << stream << ".readObject(" << name << ", \"\", null);";
- }
- }
- return;
- }
-
- StructPtr st = StructPtr::dynamicCast(type);
- if (st)
- {
- if (marshal)
- {
- out << nl << v << ".ice_marshal(" << name << ", " << stream << ");";
- }
- else
- {
- string typeS = typeToString(type, TypeModeIn, scope);
- out << nl << v << " = new " << typeS << "();";
- out << nl << v << ".ice_unmarshal(" << name << ", " << stream << ");";
- }
- return;
- }
-
- EnumPtr en = EnumPtr::dynamicCast(type);
- if (en)
- {
- if (marshal)
- {
- out << nl << v << ".ice_marshal(" << name << ", " << stream << ");";
- }
- else
- {
- string typeS = typeToString(type, TypeModeIn, scope);
- out << nl << v << " = " << typeS << ".ice_unmarshal(" << name << ", " << stream << ");";
- }
- return;
- }
-
- SequencePtr seq = SequencePtr::dynamicCast(type);
- if (seq)
- {
- BuiltinPtr b = BuiltinPtr::dynamicCast(seq->type());
- if (b)
- {
- switch (b->kind())
- {
- case Builtin::KindByte:
- {
- if (marshal)
- {
- out << nl << stream << ".writeByteSeq(" << name << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readByteSeq(" << name << ");";
- }
- break;
- }
- case Builtin::KindBool:
- {
- if (marshal)
- {
- out << nl << stream << ".writeBoolSeq(" << name << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readBoolSeq(" << name << ");";
- }
- break;
- }
- case Builtin::KindShort:
- {
- if (marshal)
- {
- out << nl << stream << ".writeShortSeq(" << name << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readShortSeq(" << name << ");";
- }
- break;
- }
- case Builtin::KindInt:
- {
- if (marshal)
- {
- out << nl << stream << ".writeIntSeq(" << name << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readIntSeq(" << name << ");";
- }
- break;
- }
- case Builtin::KindLong:
- {
- if (marshal)
- {
- out << nl << stream << ".writeLongSeq(" << name << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readLongSeq(" << name << ");";
- }
- break;
- }
- case Builtin::KindFloat:
- {
- if (marshal)
- {
- out << nl << stream << ".writeFloatSeq(" << name << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readFloatSeq(" << name << ");";
- }
- break;
- }
- case Builtin::KindDouble:
- {
- if (marshal)
- {
- out << nl << stream << ".writeDoubleSeq(" << name << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readDoubleSeq(" << name << ");";
- }
- break;
- }
- case Builtin::KindString:
- {
- if (marshal)
- {
- out << nl << stream << ".writeStringSeq(" << name << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << stream << ".readStringSeq(" << name << ");";
- }
- break;
- }
- case Builtin::KindObject:
- case Builtin::KindObjectProxy:
- {
- string typeS = getAbsolute(seq->scoped(), scope);
- if (marshal)
- {
- out << nl << typeS << "Helper.ice_marshal(" << name << ", " << stream << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << typeS << "Helper.ice_unmarshal(" << name << ", " << stream << ");";
- }
- break;
- }
- case Builtin::KindLocalObject:
- {
- assert(false);
- break;
- }
- }
- }
- else
- {
- ContainedPtr cont = ContainedPtr::dynamicCast(type);
- assert(cont);
- string typeS = getAbsolute(cont->scoped(), scope);
- if (marshal)
- {
- out << nl << typeS << "Helper.ice_marshal(" << name << ", " << stream << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << typeS << "Helper.ice_unmarshal(" << name << ", " << stream << ");";
- }
- }
- return;
- }
-
- ConstructedPtr constructed = ConstructedPtr::dynamicCast(type);
- assert(constructed);
- string typeS = getAbsolute(constructed->scoped(), scope);
- if (marshal)
- {
- out << nl << typeS << "Helper.ice_marshal(" << name << ", " << stream << ", " << v << ");";
- }
- else
- {
- out << nl << v << " = " << typeS << "Helper.ice_unmarshal(" << name << ", " << stream << ");";
- }
-}
-
-void
Slice::JavaVisitor::writeHashCode(Output& out, const TypePtr& type,
const string& name, int& iter)
{
@@ -1766,26 +623,6 @@ Slice::JavaVisitor::writeDispatch(Output& out, const ClassDefPtr& p)
}
}
-void
-Slice::JavaVisitor::printHeader()
-{
- static const char* header =
-"// **********************************************************************\n"
-"//\n"
-"// Copyright (c) 2001\n"
-"// MutableRealms, Inc.\n"
-"// Huntsville, AL, USA\n"
-"//\n"
-"// All Rights Reserved\n"
-"//\n"
-"// **********************************************************************\n"
- ;
-
- Output& out = output();
- out << header;
- out << "\n// Ice version " << ICE_STRING_VERSION;
-}
-
Slice::Gen::Gen(const string& name, const string& base,
const vector<string>& includePaths,
const string& package, const string& dir) :
diff --git a/cpp/src/slice2java/Gen.h b/cpp/src/slice2java/Gen.h
index 37dee41d708..b4b1ea5e60a 100644
--- a/cpp/src/slice2java/Gen.h
+++ b/cpp/src/slice2java/Gen.h
@@ -11,14 +11,12 @@
#ifndef GEN_H
#define GEN_H
-#include <Slice/Parser.h>
-#include <IceUtil/OutputUtil.h>
-//#include <JavaUtil.h>
+#include <Slice/JavaUtil.h>
namespace Slice
{
-class JavaVisitor : public ::IceUtil::noncopyable, public ParserVisitor
+class JavaVisitor : public JavaGenerator, public ParserVisitor
{
public:
@@ -29,44 +27,6 @@ protected:
JavaVisitor(const std::string&, const std::string&);
//
- // Given the fully-scoped Java class name, create any intermediate
- // package directories and open the class file
- //
- bool open(const std::string&);
- void close();
-
- ::IceUtil::Output& output() const;
-
- //
- // Check a symbol against any of the Java keywords. If a
- // match is found, return the symbol with a leading underscore.
- //
- std::string fixKwd(const std::string&) const;
-
- //
- // Convert a scoped name into a Java class name. If an optional
- // scope is provided, the scope will be removed from the result.
- //
- std::string getAbsolute(const std::string&,
- const std::string& = std::string(),
- const std::string& = std::string(),
- const std::string& = std::string()) const;
-
- //
- // Get the Java name for a type. If an optional scope is provided,
- // the scope will be removed from the result if possible.
- //
- enum TypeMode
- {
- TypeModeIn,
- TypeModeOut,
- TypeModeMember,
- TypeModeReturn
- };
- std::string typeToString(const TypePtr&, TypeMode mode,
- const std::string& = std::string()) const;
-
- //
// Compose the parameter list for an operation
//
std::string getParams(const OperationPtr&, const std::string&);
@@ -88,20 +48,6 @@ protected:
void writeDelegateThrowsClause(const std::string&, const ExceptionList&);
//
- // Generate code to marshal or unmarshal a type
- //
- void writeMarshalUnmarshalCode(::IceUtil::Output&, const std::string&, const TypePtr&,
- const std::string&, bool, int&,
- bool = false);
-
- //
- // Generate generic code to marshal or unmarshal a type
- //
- void writeGenericMarshalUnmarshalCode(::IceUtil::Output&, const std::string&, const TypePtr&,
- const std::string&, const std::string&, bool, int&,
- bool = false);
-
- //
// Generate code to compute a hash code for a type
//
void writeHashCode(::IceUtil::Output&, const TypePtr&, const std::string&, int&);
@@ -110,15 +56,6 @@ protected:
// Generate dispatch methods for a class or interface
//
void writeDispatch(::IceUtil::Output&, const ClassDefPtr&);
-
-private:
-
- void printHeader();
-
- std::string _dir;
- std::string _package;
-
- ::IceUtil::Output* _out;
};
class Gen : public ::IceUtil::noncopyable