summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/JavaUtil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/Slice/JavaUtil.cpp')
-rw-r--r--cpp/src/Slice/JavaUtil.cpp403
1 files changed, 265 insertions, 138 deletions
diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp
index ef32beafda6..781b020c0c8 100644
--- a/cpp/src/Slice/JavaUtil.cpp
+++ b/cpp/src/Slice/JavaUtil.cpp
@@ -550,6 +550,23 @@ Slice::JavaGenerator::getStaticId(const TypePtr& type, const string& package) co
}
}
+bool
+Slice::JavaGenerator::useOptionalMapping(const OperationPtr& p)
+{
+ //
+ // The "java:optional" metadata can be applied to an operation or its
+ // interface to force the mapping to use the Ice.Optional types.
+ //
+ // Without the tag, parameters use the normal (non-optional) mapping.
+ //
+ static const string tag = "java:optional";
+
+ ClassDefPtr cl = ClassDefPtr::dynamicCast(p->container());
+ assert(cl);
+
+ return p->hasMetaData(tag) || cl->hasMetaData(tag);
+}
+
string
Slice::JavaGenerator::getOptionalType(const TypePtr& type)
{
@@ -667,6 +684,20 @@ Slice::JavaGenerator::typeToString(const TypePtr& type,
"Ice.ObjectPrxHolder",
"Ice.LocalObjectHolder"
};
+ static const char* builtinOptionalTable[] =
+ {
+ "Ice.ByteOptional",
+ "Ice.BooleanOptional",
+ "Ice.ShortOptional",
+ "Ice.IntOptional",
+ "Ice.LongOptional",
+ "Ice.FloatOptional",
+ "Ice.DoubleOptional",
+ "???",
+ "???",
+ "???",
+ "???"
+ };
if(!type)
{
@@ -679,7 +710,26 @@ Slice::JavaGenerator::typeToString(const TypePtr& type,
{
if(optional)
{
- return "Ice.Optional<" + typeToObjectString(builtin, TypeModeIn, package, metaData, formal) + ">";
+ switch(builtin->kind())
+ {
+ case Builtin::KindByte:
+ case Builtin::KindBool:
+ case Builtin::KindShort:
+ case Builtin::KindInt:
+ case Builtin::KindLong:
+ case Builtin::KindFloat:
+ case Builtin::KindDouble:
+ {
+ return builtinOptionalTable[builtin->kind()];
+ }
+ case Builtin::KindString:
+ case Builtin::KindObject:
+ case Builtin::KindObjectProxy:
+ case Builtin::KindLocalObject:
+ {
+ break;
+ }
+ }
}
else
{
@@ -860,7 +910,8 @@ void
Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
const string& package,
const TypePtr& type,
- OptionalMode optional,
+ OptionalMode mode,
+ bool optionalMapping,
int tag,
const string& param,
bool marshal,
@@ -871,7 +922,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
{
string stream = marshal ? "__os" : "__is";
string v;
- if(holder && optional == OptionalNone)
+ if(holder)
{
v = param + ".value";
}
@@ -880,6 +931,8 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
v = param;
}
+ const bool optionalParam = mode == OptionalInParam || mode == OptionalOutParam || mode == OptionalReturnParam;
+
BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
if(builtin)
{
@@ -889,7 +942,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
{
if(marshal)
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".writeByte(" << tag << ", " << v << ");";
}
@@ -900,7 +953,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
}
else
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".readByte(" << tag << ", " << v << ");";
}
@@ -915,7 +968,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
{
if(marshal)
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".writeBool(" << tag << ", " << v << ");";
}
@@ -926,7 +979,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
}
else
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".readBool(" << tag << ", " << v << ");";
}
@@ -941,7 +994,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
{
if(marshal)
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".writeShort(" << tag << ", " << v << ");";
}
@@ -952,7 +1005,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
}
else
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".readShort(" << tag << ", " << v << ");";
}
@@ -967,7 +1020,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
{
if(marshal)
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".writeInt(" << tag << ", " << v << ");";
}
@@ -978,7 +1031,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
}
else
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".readInt(" << tag << ", " << v << ");";
}
@@ -993,7 +1046,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
{
if(marshal)
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".writeLong(" << tag << ", " << v << ");";
}
@@ -1004,7 +1057,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
}
else
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".readLong(" << tag << ", " << v << ");";
}
@@ -1019,7 +1072,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
{
if(marshal)
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".writeFloat(" << tag << ", " << v << ");";
}
@@ -1030,7 +1083,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
}
else
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".readFloat(" << tag << ", " << v << ");";
}
@@ -1045,7 +1098,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
{
if(marshal)
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".writeDouble(" << tag << ", " << v << ");";
}
@@ -1056,7 +1109,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
}
else
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".readDouble(" << tag << ", " << v << ");";
}
@@ -1071,7 +1124,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
{
if(marshal)
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".writeString(" << tag << ", " << v << ");";
}
@@ -1082,7 +1135,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
}
else
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".readString(" << tag << ", " << v << ");";
}
@@ -1097,7 +1150,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
{
if(marshal)
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".writeObject(" << tag << ", " << v << ");";
}
@@ -1108,11 +1161,11 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
}
else
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".readObject(" << tag << ", " << param << ");";
}
- else if(holder && optional == OptionalNone)
+ else if(holder && mode == OptionalNone)
{
out << nl << stream << ".readObject(" << param << ");";
}
@@ -1134,11 +1187,11 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
{
if(marshal)
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".writeProxy(" << tag << ", " << v << ");";
}
- else if(optional == OptionalMember)
+ else if(mode == OptionalMember)
{
out << nl << stream << ".startSize();";
out << nl << stream << ".writeProxy(" << v << ");";
@@ -1151,11 +1204,11 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
}
else
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".readProxy(" << tag << ", " << v << ");";
}
- else if(optional == OptionalMember)
+ else if(mode == OptionalMember)
{
out << nl << stream << ".skip(4);";
out << nl << v << " = " << stream << ".readProxy();";
@@ -1182,17 +1235,29 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
string typeS = typeToString(type, TypeModeIn, package);
if(marshal)
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
- out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt(" << tag
- << ", " << getOptionalType(type) << "))";
- out << sb;
- out << nl << stream << ".startSize();";
- out << nl << typeS << "Helper.__write(" << stream << ", " << v << ".get());";
- out << nl << stream << ".endSize();";
- out << eb;
+ if(optionalMapping)
+ {
+ out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt(" << tag
+ << ", " << getOptionalType(type) << "))";
+ out << sb;
+ out << nl << stream << ".startSize();";
+ out << nl << typeS << "Helper.__write(" << stream << ", " << v << ".get());";
+ out << nl << stream << ".endSize();";
+ out << eb;
+ }
+ else
+ {
+ out << nl << "if(" << stream << ".writeOpt(" << tag << ", " << getOptionalType(type) << "))";
+ out << sb;
+ out << nl << stream << ".startSize();";
+ out << nl << typeS << "Helper.__write(" << stream << ", " << v << ");";
+ out << nl << stream << ".endSize();";
+ out << eb;
+ }
}
- else if(optional == OptionalMember)
+ else if(mode == OptionalMember)
{
out << nl << stream << ".startSize();";
out << nl << typeS << "Helper.__write(" << stream << ", " << v << ");";
@@ -1205,19 +1270,22 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
}
else
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalType(type) << "))";
out << sb;
out << nl << stream << ".skip(4);";
out << nl << v << ".set(" << typeS << "Helper.__read(" << stream << "));";
out << eb;
- out << nl << "else";
- out << sb;
- out << nl << v << ".clear();";
- out << eb;
+ if(mode == OptionalOutParam)
+ {
+ out << nl << "else";
+ out << sb;
+ out << nl << v << ".clear();";
+ out << eb;
+ }
}
- else if(optional == OptionalMember)
+ else if(mode == OptionalMember)
{
out << nl << stream << ".skip(4);";
out << nl << v << " = " << typeS << "Helper.__read(" << stream << ");";
@@ -1235,7 +1303,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
{
if(marshal)
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << stream << ".writeObject(" << tag << ", " << v << ");";
}
@@ -1246,7 +1314,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
}
else
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
string typeS = typeToString(type, TypeModeIn, package);
out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalType(type) << "))";
@@ -1254,14 +1322,17 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
out << nl << stream << ".readObject(new Ice.OptionalObject(" << v << ", " << typeS << ".class, "
<< getStaticId(type, package) << "));";
out << eb;
- out << nl << "else";
- out << sb;
- out << nl << v << ".clear();";
- out << eb;
+ if(mode == OptionalOutParam)
+ {
+ out << nl << "else";
+ out << sb;
+ out << nl << v << ".clear();";
+ out << eb;
+ }
}
else
{
- if(holder && optional == OptionalNone)
+ if(holder && mode == OptionalNone)
{
out << nl << stream << ".readObject(" << param << ");";
}
@@ -1286,28 +1357,44 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
{
if(marshal)
{
- if(optional != OptionalNone)
+ if(optionalParam || mode == OptionalMember)
{
- if(optional == OptionalParam)
+ string val;
+
+ if(optionalParam)
{
- out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt(" << tag
- << ", " << getOptionalType(type) << "))";
+ if(optionalMapping)
+ {
+ out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt("
+ << tag << ", " << getOptionalType(type) << "))";
+ val = v + ".get()";
+ }
+ else
+ {
+ out << nl << "if(" << stream << ".writeOpt(" << tag << ", " << getOptionalType(type) << "))";
+ val = v;
+ }
+
out << sb;
}
+ else
+ {
+ val = v;
+ }
if(st->isVariableLength())
{
out << nl << stream << ".startSize();";
- out << nl << v << ".__write(" << stream << ");";
+ out << nl << val << ".__write(" << stream << ");";
out << nl << stream << ".endSize();";
}
else
{
out << nl << stream << ".writeSize(" << st->minWireSize() << ");";
- out << nl << v << ".__write(" << stream << ");";
+ out << nl << val << ".__write(" << stream << ");";
}
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << eb;
}
@@ -1321,7 +1408,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
{
string typeS = typeToString(type, TypeModeIn, package, metaData);
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalType(type) << "))";
out << sb;
@@ -1340,12 +1427,16 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
out << nl << v << ".set(__tmpOpt);";
out << eb;
- out << nl << "else";
- out << sb;
- out << nl << v << ".clear();";
- out << eb;
+
+ if(mode == OptionalOutParam)
+ {
+ out << nl << "else";
+ out << sb;
+ out << nl << v << ".clear();";
+ out << eb;
+ }
}
- else if(optional == OptionalMember)
+ else if(mode == OptionalMember)
{
if(st->isVariableLength())
{
@@ -1372,13 +1463,23 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
{
if(marshal)
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
- out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt(" << tag
- << ", " << getOptionalType(type) << "))";
- out << sb;
- out << nl << v << ".__write(" << stream << ");";
- out << eb;
+ if(optionalMapping)
+ {
+ out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt(" << tag
+ << ", " << getOptionalType(type) << "))";
+ out << sb;
+ out << nl << v << ".get().__write(" << stream << ");";
+ out << eb;
+ }
+ else
+ {
+ out << nl << "if(" << stream << ".writeOpt(" << tag << ", " << getOptionalType(type) << "))";
+ out << sb;
+ out << nl << v << ".__write(" << stream << ");";
+ out << eb;
+ }
}
else
{
@@ -1389,16 +1490,19 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
{
string typeS = typeToString(type, TypeModeIn, package, metaData);
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalType(type) << "))";
out << sb;
out << nl << v << ".set(" << typeS << ".__read(" << stream << "));";
out << eb;
- out << nl << "else";
- out << sb;
- out << nl << v << ".clear();";
- out << eb;
+ if(mode == OptionalOutParam)
+ {
+ out << nl << "else";
+ out << sb;
+ out << nl << v << ".clear();";
+ out << eb;
+ }
}
else
{
@@ -1411,7 +1515,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
DictionaryPtr dict = DictionaryPtr::dynamicCast(type);
if(dict)
{
- if(optional != OptionalNone)
+ if(optionalParam || mode == OptionalMember)
{
string typeS = typeToString(type, TypeModeIn, package, metaData);
TypePtr keyType = dict->keyType();
@@ -1419,16 +1523,24 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
if(marshal)
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
- out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt(" << tag
- << ", " << getOptionalType(type) << "))";
- out << sb;
+ if(optionalMapping)
+ {
+ out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt("
+ << tag << ", " << getOptionalType(type) << "))";
+ out << sb;
+ }
+ else
+ {
+ out << nl << "if(" << stream << ".writeOpt(" << tag << ", " << getOptionalType(type) << "))";
+ out << sb;
+ }
}
if(keyType->isVariableLength() || valueType->isVariableLength())
{
- string d = optional == OptionalParam ? v + ".get()" : v;
+ string d = optionalParam && optionalMapping ? v + ".get()" : v;
out << nl << stream << ".startSize();";
writeDictionaryMarshalUnmarshalCode(out, package, dict, d, marshal, iter, true, metaData);
out << nl << stream << ".endSize();";
@@ -1437,7 +1549,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
{
const int wireSize = keyType->minWireSize() + valueType->minWireSize();
string tmpName;
- if(optional == OptionalParam)
+ if(optionalParam && optionalMapping)
{
tmpName = "__optDict";
out << nl << "final " << typeS << ' ' << tmpName << " = " << v << ".get();";
@@ -1446,14 +1558,13 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
{
tmpName = v;
}
- out << nl << "final int __optSize = " << tmpName << " == null ? 0 : " << tmpName
- << ".size();";
+ out << nl << "final int __optSize = " << tmpName << " == null ? 0 : " << tmpName << ".size();";
out << nl << stream << ".writeSize(__optSize > 254 ? __optSize * " << wireSize
<< " + 5 : __optSize * " << wireSize << " + 1);";
writeDictionaryMarshalUnmarshalCode(out, package, dict, tmpName, marshal, iter, true, metaData);
}
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << eb;
}
@@ -1462,7 +1573,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
{
string tmpName;
- if(optional == OptionalParam)
+ if(optionalParam)
{
tmpName = "__optDict";
out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalType(type) << "))";
@@ -1485,14 +1596,17 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
writeDictionaryMarshalUnmarshalCode(out, package, dict, tmpName, marshal, iter, true, metaData);
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << v << ".set(" << tmpName << ");";
out << eb;
- out << nl << "else";
- out << sb;
- out << nl << v << ".clear();";
- out << eb;
+ if(mode == OptionalOutParam)
+ {
+ out << nl << "else";
+ out << sb;
+ out << nl << v << ".clear();";
+ out << eb;
+ }
}
}
}
@@ -1506,13 +1620,13 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
SequencePtr seq = SequencePtr::dynamicCast(type);
if(seq)
{
- if(optional != OptionalNone)
+ if(optionalParam || mode == OptionalMember)
{
string typeS = typeToString(type, TypeModeIn, package, metaData);
TypePtr elemType = seq->type();
BuiltinPtr elemBuiltin = BuiltinPtr::dynamicCast(elemType);
- if(optional == OptionalParam && elemBuiltin && elemBuiltin->kind() != Builtin::KindObject &&
+ if(optionalParam && elemBuiltin && elemBuiltin->kind() != Builtin::KindObject &&
elemBuiltin->kind() != Builtin::KindObjectProxy && !hasTypeMetaData(seq, metaData))
{
static const char* builtinTable[] =
@@ -1525,6 +1639,9 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
"Float",
"Double",
"String",
+ "???",
+ "???",
+ "???"
};
switch(elemBuiltin->kind())
@@ -1564,16 +1681,24 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
if(marshal)
{
- if(optional == OptionalParam)
+ if(optionalParam)
{
- out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt(" << tag
- << ", " << getOptionalType(type) << "))";
+ if(optionalMapping)
+ {
+ out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt("
+ << tag << ", " << getOptionalType(type) << "))";
+ }
+ else
+ {
+ out << nl << "if(" << stream << ".writeOpt(" << tag << ", " << getOptionalType(type) << "))";
+ }
+
out << sb;
}
if(elemType->isVariableLength())
{
- string s = optional == OptionalParam ? v + ".get()" : v;
+ string s = optionalParam && optionalMapping ? v + ".get()" : v;
out << nl << stream << ".startSize();";
writeSequenceMarshalUnmarshalCode(out, package, seq, s, marshal, iter, true, metaData);
out << nl << stream << ".endSize();";
@@ -1587,7 +1712,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
//
string tmpName;
- if(optional == OptionalParam)
+ if(optionalParam && optionalMapping)
{
tmpName = "__optSeq";
out << nl << "final " << typeS << ' ' << tmpName << " = " << v << ".get();";
@@ -1624,7 +1749,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
//
// This just writes a byte sequence.
//
- string s = optional == OptionalParam ? v + ".get()" : v;
+ string s = optionalParam && optionalMapping ? v + ".get()" : v;
writeSequenceMarshalUnmarshalCode(out, package, seq, s, marshal, iter, true, metaData);
}
else
@@ -1634,7 +1759,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
//
string tmpName;
- if(optional == OptionalParam)
+ if(optionalParam && optionalMapping)
{
tmpName = "__optSeq";
out << nl << "final " << typeS << ' ' << tmpName << " = " << v << ".get();";
@@ -1667,7 +1792,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
writeSequenceMarshalUnmarshalCode(out, package, seq, tmpName, marshal, iter, true, metaData);
}
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << eb;
}
@@ -1675,7 +1800,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
else
{
string tmpName;
- if(optional == OptionalParam)
+ if(optionalParam)
{
tmpName = "__optSeq";
out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalType(type) << "))";
@@ -1717,14 +1842,17 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out,
writeSequenceMarshalUnmarshalCode(out, package, seq, tmpName, marshal, iter, true, metaData);
- if(optional == OptionalParam)
+ if(optionalParam)
{
out << nl << v << ".set(" << tmpName << ");";
out << eb;
- out << nl << "else";
- out << sb;
- out << nl << v << ".clear();";
- out << eb;
+ if(mode == OptionalOutParam)
+ {
+ out << nl << "else";
+ out << sb;
+ out << nl << v << ".clear();";
+ out << eb;
+ }
}
}
}
@@ -1843,7 +1971,7 @@ Slice::JavaGenerator::writeDictionaryMarshalUnmarshalCode(Output& out,
arg = "__e.getValue()";
type = value;
}
- writeMarshalUnmarshalCode(out, package, type, OptionalNone, 0, arg, true, iter, false);
+ writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, arg, true, iter, false);
}
out << eb;
out << eb;
@@ -1877,14 +2005,15 @@ Slice::JavaGenerator::writeDictionaryMarshalUnmarshalCode(Output& out,
{
string keyTypeStr = typeToObjectString(key, TypeModeIn, package);
string valueTypeStr = typeToObjectString(value, TypeModeIn, package);
- writeMarshalUnmarshalCode(out, package, type, OptionalNone, 0, arg, false, iter, false, StringList(),
+ writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, arg, false, iter, false,
+ StringList(),
"new IceInternal.DictionaryPatcher<" + keyTypeStr + ", " + valueTypeStr +
">(" + v + ", " + typeS + ".class, \"" + type->typeId() + "\", __key)");
}
else
{
out << nl << typeS << ' ' << arg << ';';
- writeMarshalUnmarshalCode(out, package, type, OptionalNone, 0, arg, false, iter, false);
+ writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, arg, false, iter, false);
}
}
BuiltinPtr builtin = BuiltinPtr::dynamicCast(value);
@@ -2051,7 +2180,7 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
string typeS = typeToString(type, TypeModeIn, package);
out << nl << "for(" << typeS << " __elem : " << v << ')';
out << sb;
- writeMarshalUnmarshalCode(out, package, type, OptionalNone, 0, "__elem", true, iter, false);
+ writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, "__elem", true, iter, false);
out << eb;
out << eb; // else
}
@@ -2098,13 +2227,13 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
ostringstream patchParams;
patchParams << "new IceInternal.ListPatcher<" << origContentS << ">(" << v << ", " << origContentS
<< ".class, __type" << iter << ", __i" << iter << ')';
- writeMarshalUnmarshalCode(out, package, type, OptionalNone, 0, "__elem", false, iter, false,
- StringList(), patchParams.str());
+ writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, "__elem", false, iter,
+ false, StringList(), patchParams.str());
}
else
{
out << nl << cont << " __elem;";
- writeMarshalUnmarshalCode(out, package, type, OptionalNone, 0, "__elem", false, iter, false);
+ writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, "__elem", false, iter, false);
}
if(!isObject)
{
@@ -2243,7 +2372,7 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
ostringstream o;
o << v << "[__i" << iter << "]";
iter++;
- writeMarshalUnmarshalCode(out, package, type, OptionalNone, 0, o.str(), true, iter, false);
+ writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, o.str(), true, iter, false);
out << eb;
out << eb;
}
@@ -2328,12 +2457,12 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
{
patchParams << "new IceInternal.SequencePatcher(" << v << ", " << origContentS
<< ".class, __type" << iter << ", __i" << iter << ')';
- writeMarshalUnmarshalCode(out, package, type, OptionalNone, 0, o.str(), false, iter, false,
- StringList(), patchParams.str());
+ writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, o.str(), false, iter,
+ false, StringList(), patchParams.str());
}
else
{
- writeMarshalUnmarshalCode(out, package, type, OptionalNone, 0, o.str(), false, iter, false);
+ writeMarshalUnmarshalCode(out, package, type, OptionalNone, false, 0, o.str(), false, iter, false);
}
out << eb;
iter++;
@@ -2346,7 +2475,7 @@ void
Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out,
const string& package,
const TypePtr& type,
- OptionalMode optional,
+ bool optional,
int tag,
const string& param,
bool marshal,
@@ -2355,11 +2484,9 @@ Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out,
const StringList& metaData,
const string& patchParams)
{
- assert(optional != OptionalParam); // Stream API doesn't support Ice.Optional<>.
-
string stream = marshal ? "__outS" : "__inS";
string v;
- if(holder && optional == OptionalNone)
+ if(holder && !optional)
{
v = param + ".value";
}
@@ -2477,7 +2604,7 @@ Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out,
}
else
{
- if(holder && optional == OptionalNone)
+ if(holder && !optional)
{
out << nl << stream << ".readObject(" << param << ");";
}
@@ -2499,7 +2626,7 @@ Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out,
{
if(marshal)
{
- if(optional == OptionalMember)
+ if(optional)
{
out << nl << stream << ".startSize();";
out << nl << stream << ".writeProxy(" << v << ");";
@@ -2512,7 +2639,7 @@ Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out,
}
else
{
- if(optional == OptionalMember)
+ if(optional)
{
out << nl << stream << ".skip(4);";
}
@@ -2535,7 +2662,7 @@ Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out,
string typeS = typeToString(type, TypeModeIn, package);
if(marshal)
{
- if(optional == OptionalMember)
+ if(optional)
{
out << nl << stream << ".startSize();";
out << nl << typeS << "Helper.write(" << stream << ", " << v << ");";
@@ -2548,7 +2675,7 @@ Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out,
}
else
{
- if(optional == OptionalMember)
+ if(optional)
{
out << nl << stream << ".skip(4);";
}
@@ -2566,7 +2693,7 @@ Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out,
}
else
{
- if(holder && optional == OptionalNone)
+ if(holder && !optional)
{
out << nl << stream << ".readObject(" << param << ");";
}
@@ -2590,7 +2717,7 @@ Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out,
{
if(marshal)
{
- if(optional != OptionalNone)
+ if(optional)
{
if(st->isVariableLength())
{
@@ -2612,7 +2739,7 @@ Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out,
else
{
string typeS = typeToString(type, TypeModeIn, package);
- if(optional == OptionalMember)
+ if(optional)
{
if(st->isVariableLength())
{
@@ -2652,7 +2779,7 @@ Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out,
DictionaryPtr dict = DictionaryPtr::dynamicCast(type);
if(dict)
{
- if(optional != OptionalNone)
+ if(optional)
{
string typeS = typeToString(type, TypeModeIn, package, metaData);
TypePtr keyType = dict->keyType();
@@ -2699,7 +2826,7 @@ Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out,
SequencePtr seq = SequencePtr::dynamicCast(type);
if(seq)
{
- if(optional != OptionalNone)
+ if(optional)
{
string typeS = typeToString(type, TypeModeIn, package, metaData);
TypePtr elemType = seq->type();
@@ -2927,7 +3054,7 @@ Slice::JavaGenerator::writeStreamDictionaryMarshalUnmarshalCode(Output& out,
arg = "__e.getValue()";
type = value;
}
- writeStreamMarshalUnmarshalCode(out, package, type, OptionalNone, 0, arg, true, iter, false);
+ writeStreamMarshalUnmarshalCode(out, package, type, false, 0, arg, true, iter, false);
}
out << eb;
out << eb;
@@ -2962,7 +3089,7 @@ Slice::JavaGenerator::writeStreamDictionaryMarshalUnmarshalCode(Output& out,
{
string keyTypeStr = typeToObjectString(key, TypeModeIn, package);
string valueTypeStr = typeToObjectString(value, TypeModeIn, package);
- writeStreamMarshalUnmarshalCode(out, package, type, OptionalNone, 0, arg, false, iter, false,
+ writeStreamMarshalUnmarshalCode(out, package, type, false, 0, arg, false, iter, false,
StringList(), "new IceInternal.DictionaryPatcher<" + keyTypeStr +
", " + valueTypeStr + ">(" + v + ", " + s + ".class, \"" +
type->typeId() + "\", __key)");
@@ -2970,7 +3097,7 @@ Slice::JavaGenerator::writeStreamDictionaryMarshalUnmarshalCode(Output& out,
else
{
out << nl << s << ' ' << arg << ';';
- writeStreamMarshalUnmarshalCode(out, package, type, OptionalNone, 0, arg, false, iter, false);
+ writeStreamMarshalUnmarshalCode(out, package, type, false, 0, arg, false, iter, false);
}
}
BuiltinPtr builtin = BuiltinPtr::dynamicCast(value);
@@ -3136,7 +3263,7 @@ Slice::JavaGenerator::writeStreamSequenceMarshalUnmarshalCode(Output& out,
string typeS = typeToString(type, TypeModeIn, package);
out << nl << "for(" << typeS << " __elem : " << v << ')';
out << sb;
- writeStreamMarshalUnmarshalCode(out, package, type, OptionalNone, 0, "__elem", true, iter, false);
+ writeStreamMarshalUnmarshalCode(out, package, type, false, 0, "__elem", true, iter, false);
out << eb;
out << eb; // else
}
@@ -3183,13 +3310,13 @@ Slice::JavaGenerator::writeStreamSequenceMarshalUnmarshalCode(Output& out,
ostringstream patchParams;
patchParams << "new IceInternal.ListPatcher<" << origContentS << ">(" << v << ", " << origContentS
<< ".class, __type" << iter << ", __i" << iter << ')';
- writeStreamMarshalUnmarshalCode(out, package, type, OptionalNone, 0, "__elem", false, iter, false,
+ writeStreamMarshalUnmarshalCode(out, package, type, false, 0, "__elem", false, iter, false,
StringList(), patchParams.str());
}
else
{
out << nl << cont << " __elem;";
- writeStreamMarshalUnmarshalCode(out, package, type, OptionalNone, 0, "__elem", false, iter, false);
+ writeStreamMarshalUnmarshalCode(out, package, type, false, 0, "__elem", false, iter, false);
}
if(!isObject)
{
@@ -3328,7 +3455,7 @@ Slice::JavaGenerator::writeStreamSequenceMarshalUnmarshalCode(Output& out,
ostringstream o;
o << v << "[__i" << iter << "]";
iter++;
- writeStreamMarshalUnmarshalCode(out, package, type, OptionalNone, 0, o.str(), true, iter, false);
+ writeStreamMarshalUnmarshalCode(out, package, type, false, 0, o.str(), true, iter, false);
out << eb;
out << eb;
}
@@ -3413,12 +3540,12 @@ Slice::JavaGenerator::writeStreamSequenceMarshalUnmarshalCode(Output& out,
{
patchParams << "new IceInternal.SequencePatcher(" << v << ", " << origContentS
<< ".class, __type" << iter << ", __i" << iter << ')';
- writeStreamMarshalUnmarshalCode(out, package, type, OptionalNone, 0, o.str(), false, iter, false,
+ writeStreamMarshalUnmarshalCode(out, package, type, false, 0, o.str(), false, iter, false,
StringList(), patchParams.str());
}
else
{
- writeStreamMarshalUnmarshalCode(out, package, type, OptionalNone, 0, o.str(), false, iter, false);
+ writeStreamMarshalUnmarshalCode(out, package, type, false, 0, o.str(), false, iter, false);
}
out << eb;
iter++;