summaryrefslogtreecommitdiff
path: root/cpp/src/slice2freezej/Main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/slice2freezej/Main.cpp')
-rw-r--r--cpp/src/slice2freezej/Main.cpp328
1 files changed, 134 insertions, 194 deletions
diff --git a/cpp/src/slice2freezej/Main.cpp b/cpp/src/slice2freezej/Main.cpp
index dc3137a9dd3..f449b98d8db 100644
--- a/cpp/src/slice2freezej/Main.cpp
+++ b/cpp/src/slice2freezej/Main.cpp
@@ -29,19 +29,17 @@ struct Dict
class FreezeGenerator : public JavaGenerator
{
public:
- FreezeGenerator(const string&, bool, const string&);
+ FreezeGenerator(const string&, const string&);
bool generate(UnitPtr&, const Dict&);
private:
string _prog;
- bool _binary;
};
-FreezeGenerator::FreezeGenerator(const string& prog, bool binary, const string& dir)
+FreezeGenerator::FreezeGenerator(const string& prog, const string& dir)
: JavaGenerator(dir, string()),
- _prog(prog),
- _binary(binary)
+ _prog(prog)
{
}
@@ -200,43 +198,25 @@ FreezeGenerator::generate(UnitPtr& u, const Dict& dict)
<< "(Object o, Ice.Communicator communicator)";
out << sb;
out << nl << "assert(o instanceof " << typeS << ");";
- if(_binary)
- {
- out << nl << "IceInternal.BasicStream __os = "
- << "new IceInternal.BasicStream(Ice.Util.getInstance(communicator));";
- out << nl << "try";
- out << sb;
- iter = 0;
- writeMarshalUnmarshalCode(out, "", type, valS, true, iter, false);
- out << nl << "java.nio.ByteBuffer __buf = __os.prepareWrite();";
- out << nl << "byte[] __r = new byte[__buf.limit()];";
- out << nl << "__buf.get(__r);";
- out << nl << "return __r;";
- out << eb;
- out << nl << "finally";
- out << sb;
- out << nl << "__os.destroy();";
- out << eb;
- }
- else
+ out << nl << "IceInternal.BasicStream __os = "
+ << "new IceInternal.BasicStream(Ice.Util.getInstance(communicator));";
+ out << nl << "try";
+ out << sb;
+ iter = 0;
+ writeMarshalUnmarshalCode(out, "", type, valS, true, iter, false);
+ if(type->usesClasses())
{
- out << nl << "try";
- out << sb;
- out << nl << "java.io.StringWriter sw = new java.io.StringWriter();";
- out << nl << "java.io.PrintWriter pw = new java.io.PrintWriter(sw);";
- out << nl << "Ice.Stream __os = new IceXML.StreamI(communicator, pw);";
- string quotedKeyValue = "\"" + keyValue + "\"";
- iter = 0;
- writeGenericMarshalUnmarshalCode(out, "", type, quotedKeyValue, valS, true, iter, false);
- out << nl << "return sw.toString().getBytes(\"UTF8\");";
- out << eb;
- out << nl << "catch(java.io.UnsupportedEncodingException ex)";
- out << sb;
- out << nl << "Ice.SyscallException e = new Ice.SyscallException();";
- out << nl << "e.initCause(ex);";
- out << nl << "throw e;";
- out << eb;
+ out << nl << "__os.writePendingObjects();";
}
+ out << nl << "java.nio.ByteBuffer __buf = __os.prepareWrite();";
+ out << nl << "byte[] __r = new byte[__buf.limit()];";
+ out << nl << "__buf.get(__r);";
+ out << nl << "return __r;";
+ out << eb;
+ out << nl << "finally";
+ out << sb;
+ out << nl << "__os.destroy();";
+ out << eb;
out << eb;
//
@@ -245,163 +225,134 @@ FreezeGenerator::generate(UnitPtr& u, const Dict& dict)
out << sp << nl << "public Object" << nl << "decode" << keyValue
<< "(byte[] b, Ice.Communicator communicator)";
out << sb;
- if(_binary)
+ out << nl << "IceInternal.BasicStream __is = "
+ << "new IceInternal.BasicStream(Ice.Util.getInstance(communicator));";
+ out << nl << "try";
+ out << sb;
+ out << nl << "__is.resize(b.length, true);";
+ out << nl << "java.nio.ByteBuffer __buf = __is.prepareRead();";
+ out << nl << "__buf.position(0);";
+ out << nl << "__buf.put(b);";
+ out << nl << "__buf.position(0);";
+ iter = 0;
+ list<string> metaData;
+ string patchParams;
+ if((b && b->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(type))
{
- out << nl << "IceInternal.BasicStream __is = "
- << "new IceInternal.BasicStream(Ice.Util.getInstance(communicator));";
- out << nl << "try";
- out << sb;
- out << nl << "__is.resize(b.length, true);";
- out << nl << "java.nio.ByteBuffer __buf = __is.prepareRead();";
- out << nl << "__buf.position(0);";
- out << nl << "__buf.put(b);";
- out << nl << "__buf.position(0);";
- iter = 0;
- out << nl << typeS << " __r;";
- if(b)
- {
- switch(b->kind())
- {
- case Builtin::KindByte:
- {
- out << nl << "__r = new java.lang.Byte(__is.readByte());";
- break;
- }
- case Builtin::KindBool:
- {
- out << nl << "__r = new java.lang.Boolean(__is.readBool());";
- break;
- }
- case Builtin::KindShort:
- {
- out << nl << "__r = new java.lang.Short(__is.readShort());";
- break;
- }
- case Builtin::KindInt:
- {
- out << nl << "__r = new java.lang.Integer(__is.readInt());";
- break;
- }
- case Builtin::KindLong:
- {
- out << nl << "__r = new java.lang.Long(__is.readLong());";
- break;
- }
- case Builtin::KindFloat:
- {
- out << nl << "__r = new java.lang.Float(__is.readFloat());";
- break;
- }
- case Builtin::KindDouble:
- {
- out << nl << "__r = new java.lang.Double(__is.readDouble());";
- break;
- }
- case Builtin::KindString:
- case Builtin::KindObject:
- case Builtin::KindObjectProxy:
- case Builtin::KindLocalObject:
- {
- writeMarshalUnmarshalCode(out, "", type, "__r", false, iter, false);
- break;
- }
- }
- }
- else
- {
- writeMarshalUnmarshalCode(out, "", type, "__r", false, iter, false);
- }
- out << nl << "return __r;";
- out << eb;
- out << nl << "finally";
- out << sb;
- out << nl << "__is.destroy();";
- out << eb;
+ out << nl << "Patcher __p = new Patcher();";
+ patchParams = "__p";
}
else
{
- out << nl << "try";
- out << sb;
- out << nl << "final String data = _header + new String(b, \"UTF8\") + _footer;";
- out << nl << "Ice.Stream __is = new IceXML.StreamI(communicator, new java.io.StringReader(data));";
- string quotedKeyValue = "\"" + keyValue + "\"";
- iter = 0;
out << nl << typeS << " __r;";
- if(b)
+ }
+ if(b)
+ {
+ switch(b->kind())
{
- switch(b->kind())
+ case Builtin::KindByte:
{
- case Builtin::KindByte:
- {
- out << nl << "__r = new java.lang.Byte(__is.readByte(" << quotedKeyValue << "));";
- break;
- }
- case Builtin::KindBool:
- {
- out << nl << "__r = new java.lang.Boolean(__is.readBool(" << quotedKeyValue << "));";
- break;
- }
- case Builtin::KindShort:
- {
- out << nl << "__r = new java.lang.Short(__is.readShort(" << quotedKeyValue << "));";
- break;
- }
- case Builtin::KindInt:
- {
- out << nl << "__r = new java.lang.Integer(__is.readInt(" << quotedKeyValue << "));";
- break;
- }
- case Builtin::KindLong:
- {
- out << nl << "__r = new java.lang.Long(__is.readLong(" << quotedKeyValue << "));";
- break;
- }
- case Builtin::KindFloat:
- {
- out << nl << "__r = new java.lang.Float(__is.readFloat(" << quotedKeyValue << "));";
- break;
- }
- case Builtin::KindDouble:
- {
- out << nl << "__r = new java.lang.Double(__is.readDouble(" << quotedKeyValue << "));";
- break;
- }
- case Builtin::KindString:
- case Builtin::KindObject:
- case Builtin::KindObjectProxy:
- case Builtin::KindLocalObject:
- {
- writeGenericMarshalUnmarshalCode(out, "", type, quotedKeyValue, "__r", false, iter, false);
- break;
- }
+ out << nl << "__r = new java.lang.Byte(__is.readByte());";
+ break;
+ }
+ case Builtin::KindBool:
+ {
+ out << nl << "__r = new java.lang.Boolean(__is.readBool());";
+ break;
+ }
+ case Builtin::KindShort:
+ {
+ out << nl << "__r = new java.lang.Short(__is.readShort());";
+ break;
+ }
+ case Builtin::KindInt:
+ {
+ out << nl << "__r = new java.lang.Integer(__is.readInt());";
+ break;
+ }
+ case Builtin::KindLong:
+ {
+ out << nl << "__r = new java.lang.Long(__is.readLong());";
+ break;
+ }
+ case Builtin::KindFloat:
+ {
+ out << nl << "__r = new java.lang.Float(__is.readFloat());";
+ break;
+ }
+ case Builtin::KindDouble:
+ {
+ out << nl << "__r = new java.lang.Double(__is.readDouble());";
+ break;
+ }
+ case Builtin::KindString:
+ case Builtin::KindObject:
+ case Builtin::KindObjectProxy:
+ case Builtin::KindLocalObject:
+ {
+ writeMarshalUnmarshalCode(out, "", type, "__r", false, iter, false, metaData, patchParams);
+ break;
}
}
- else
- {
- writeGenericMarshalUnmarshalCode(out, "", type, quotedKeyValue, "__r", false, iter, false);
- }
+ }
+ else
+ {
+ writeMarshalUnmarshalCode(out, "", type, "__r", false, iter, false, metaData, patchParams);
+ }
+ if(type->usesClasses())
+ {
+ out << nl << "__is.readPendingObjects();";
+ }
+ if((b && b->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(type))
+ {
+ out << nl << "return __p.value;";
+ }
+ else
+ {
out << nl << "return __r;";
- out << eb;
- out << nl << "catch(java.io.UnsupportedEncodingException ex)";
- out << sb;
- out << nl << "Ice.SyscallException e = new Ice.SyscallException();";
- out << nl << "e.initCause(ex);";
- out << nl << "throw e;";
- out << eb;
}
out << eb;
+ out << nl << "finally";
+ out << sb;
+ out << nl << "__is.destroy();";
+ out << eb;
+ out << eb;
}
- if(!_binary)
+ //
+ // Patcher class.
+ //
+ BuiltinPtr b = BuiltinPtr::dynamicCast(valueType);
+ if((b && b->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(valueType))
{
- out << sp << nl << "private static final String _header = ";
- out.useCurrentPosAsIndent();
- out << "\"<ice:data xmlns=\\\"http://www.noorg.org/schemas\\\"\" +"
- << nl << "\" xmlns:ice=\\\"http://www.zeroc.com/schemas\\\"\" +"
- << nl << "\" xmlns:xsi=\\\"http://www.w3.org/2003/XMLSchema-instance\\\"\" +"
- << nl << "\" xsi:schemaLocation=\\\"http://www.noorg.org/schemas " << name << ".xsd\\\">\";";
- out.restoreIndent();
- out << nl << "private static final String _footer = \"</ice:data>\";";
+ string typeS = typeToString(valueType, TypeModeIn);
+ out << sp << nl << "private static class Patcher implements IceInternal.Patcher";
+ out << sb;
+ out << sp << nl << "public void" << nl << "patch(Ice.Object v)";
+ out << sb;
+ if(b)
+ {
+ out << nl << "value = v;";
+ }
+ else
+ {
+ out << nl << "value = (" << typeS << ")v;";
+ }
+ out << eb;
+ out << sp << nl << "public String" << nl << "type()";
+ out << sb;
+ if(b)
+ {
+ out << nl << "return \"::Ice::Object\";";
+ }
+ else
+ {
+ ClassDeclPtr decl = ClassDeclPtr::dynamicCast(valueType);
+ out << nl << "return \"" << decl->scoped() << "\";";
+ }
+ out << eb;
+ out << sp << nl << typeS << " value;";
+ out << eb;
}
out << eb;
@@ -428,7 +379,6 @@ usage(const char* 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"
- "--binary Use the binary encoding.\n"
"--output-dir DIR Create files in the directory DIR.\n"
"--depend Generate Makefile dependencies.\n"
"-d, --debug Print debug messages.\n"
@@ -443,7 +393,6 @@ main(int argc, char* argv[])
string cppArgs;
vector<string> includePaths;
string include;
- bool binary = false;
string output;
bool depend = false;
bool debug = false;
@@ -602,15 +551,6 @@ main(int argc, char* argv[])
}
argc -= 2;
}
- else if(strcmp(argv[idx], "--binary") == 0)
- {
- binary = true;
- for(int i = idx ; i + 1 < argc ; ++i)
- {
- argv[i] = argv[i + 1];
- }
- --argc;
- }
else if(strcmp(argv[idx], "--output-dir") == 0)
{
if(idx + 1 >= argc)
@@ -688,7 +628,7 @@ main(int argc, char* argv[])
u->mergeModules();
u->sort();
- FreezeGenerator gen(argv[0], binary, output);
+ FreezeGenerator gen(argv[0], output);
for(vector<Dict>::const_iterator p = dicts.begin(); p != dicts.end(); ++p)
{