diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Slice/CsUtil.cpp | 35 | ||||
-rw-r--r-- | cpp/src/Slice/JavaUtil.cpp | 47 | ||||
-rw-r--r-- | cpp/src/slice2cs/Gen.cpp | 54 | ||||
-rw-r--r-- | cpp/src/slice2java/Gen.cpp | 71 | ||||
-rw-r--r-- | cpp/src/slice2js/Gen.cpp | 14 |
5 files changed, 154 insertions, 67 deletions
diff --git a/cpp/src/Slice/CsUtil.cpp b/cpp/src/Slice/CsUtil.cpp index 85b811292ee..be424b7b67b 100644 --- a/cpp/src/Slice/CsUtil.cpp +++ b/cpp/src/Slice/CsUtil.cpp @@ -629,48 +629,27 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, { if(marshal) { + const string write = streamingAPI ? "ice_write" : "write__"; if(!isValueType(st)) { - out << nl << "if(" << param << " == null)"; - out << sb; - string typeS = typeToString(st); - out << nl << typeS << " tmp__ = new " << typeS << "();"; - out << nl << "tmp__."; - out << (streamingAPI ? "ice_write" : "write__") << "(" << stream << ");"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << param << "." << (streamingAPI ? "ice_write" : "write__") << "(" << stream << ");"; - out << eb; + out << nl << typeToString(st) << "." << write << "(" << stream << ", " << param << ");"; } else { - if(streamingAPI) - { - out << nl << param << ".ice_write(" << stream << ");"; - } - else - { - out << nl << param << ".write__(" << stream << ");"; - } + out << nl << param << "." << write << "(" << stream << ");"; } } else { if(!isValueType(st)) { - out << nl << "if(" << param << " == null)"; - out << sb; - out << nl << param << " = new " << typeToString(type) << "();"; - out << eb; - } - if(streamingAPI) - { - out << nl << param << ".ice_read(" << stream << ");"; + const string read = streamingAPI ? "ice_readNew" : "readNew__"; + out << nl << param << " = " << typeToString(type) << "." << read << "(" << stream << ");"; } else { - out << nl << param << ".read__(" << stream << ");"; + const string read = streamingAPI ? "ice_read" : "read__"; + out << nl << param << "." << read << "(" << stream << ");"; } } return; diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp index 0b2a3cbef7e..c6ba85f14a2 100644 --- a/cpp/src/Slice/JavaUtil.cpp +++ b/cpp/src/Slice/JavaUtil.cpp @@ -1424,12 +1424,12 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out, StructPtr st = StructPtr::dynamicCast(type); if(st) { + string typeS = typeToString(type, TypeModeIn, package, metaData); if(marshal) { if(optionalParam || mode == OptionalMember) { string val; - if(optionalParam) { if(optionalMapping) @@ -1443,7 +1443,6 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out, out << nl << "if(" << stream << ".writeOpt(" << tag << ", " << getOptionalFormat(type) << "))"; val = v; } - out << sb; } else @@ -1454,15 +1453,14 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out, if(st->isVariableLength()) { out << nl << "int __pos = " << stream << ".startSize();"; - out << nl << val << ".__write(" << stream << ");"; + out << nl << typeS << ".__write(" << stream << ", " << val << ");"; out << nl << stream << ".endSize(__pos);"; } else { out << nl << stream << ".writeSize(" << st->minWireSize() << ");"; - out << nl << val << ".__write(" << stream << ");"; + out << nl << typeS << ".__write(" << stream << ", " << val << ");"; } - if(optionalParam) { out << eb; @@ -1470,13 +1468,11 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out, } else { - out << nl << v << ".__write(" << stream << ");"; + out << nl << typeS << ".__write(" << stream << ", " << v << ");"; } } else { - string typeS = typeToString(type, TypeModeIn, package, metaData); - if(optionalParam) { out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(type) << "))"; @@ -1515,13 +1511,11 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out, { out << nl << stream << ".skipSize();"; } - out << nl << v << " = new " << typeS << "();"; - out << nl << v << ".__read(" << stream << ");"; + out << nl << v << " = " << typeS << ".__readNew(" << stream << ");"; } else { - out << nl << v << " = new " << typeS << "();"; - out << nl << v << ".__read(" << stream << ");"; + out << nl << v << " = " << typeS << ".__readNew(" << stream << ");"; } } return; @@ -1530,6 +1524,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out, EnumPtr en = EnumPtr::dynamicCast(type); if(en) { + string typeS = typeToString(type, TypeModeIn, package, metaData); if(marshal) { if(optionalParam) @@ -1539,26 +1534,24 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out, out << nl << "if(" << v << " != null && " << v << ".isSet() && " << stream << ".writeOpt(" << tag << ", " << getOptionalFormat(type) << "))"; out << sb; - out << nl << v << ".get().__write(" << stream << ");"; + out << nl << typeS << ".__write(" << stream << ", " << v << ".get());"; out << eb; } else { out << nl << "if(" << stream << ".writeOpt(" << tag << ", " << getOptionalFormat(type) << "))"; out << sb; - out << nl << v << ".__write(" << stream << ");"; + out << nl << typeS << ".__write(" << stream << ", " << v << ");"; out << eb; } } else { - out << nl << v << ".__write(" << stream << ");"; + out << nl << typeS << ".__write(" << stream << ", " << v << ");"; } } else { - string typeS = typeToString(type, TypeModeIn, package, metaData); - if(optionalParam) { out << nl << "if(" << stream << ".readOpt(" << tag << ", " << getOptionalFormat(type) << "))"; @@ -2849,6 +2842,7 @@ Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out, StructPtr st = StructPtr::dynamicCast(type); if(st) { + string typeS = typeToString(type, TypeModeIn, package); if(marshal) { if(optional) @@ -2856,23 +2850,22 @@ Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out, if(st->isVariableLength()) { out << nl << "int __pos = " << stream << ".startSize();"; - out << nl << v << ".ice_write(" << stream << ");"; + out << nl << typeS << ".ice_write(" << stream << ", " << v << ");"; out << nl << stream << ".endSize(__pos);"; } else { out << nl << stream << ".writeSize(" << st->minWireSize() << ");"; - out << nl << v << ".ice_write(" << stream << ");"; + out << nl << typeS << ".ice_write(" << stream << ", " << v << ");"; } } else { - out << nl << v << ".ice_write(" << stream << ");"; + out << nl << typeS << ".ice_write(" << stream << ", " << v << ");"; } } else { - string typeS = typeToString(type, TypeModeIn, package); if(optional) { if(st->isVariableLength()) @@ -2883,14 +2876,8 @@ Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out, { out << nl << stream << ".skipSize();"; } - out << nl << v << " = new " << typeS << "();"; - out << nl << v << ".ice_read(" << stream << ");"; - } - else - { - out << nl << v << " = new " << typeS << "();"; - out << nl << v << ".ice_read(" << stream << ");"; } + out << nl << v << " = " << typeS << ".ice_readNew(" << stream << ");"; } return; } @@ -2898,13 +2885,13 @@ Slice::JavaGenerator::writeStreamMarshalUnmarshalCode(Output& out, EnumPtr en = EnumPtr::dynamicCast(type); if(en) { + string typeS = typeToString(type, TypeModeIn, package); if(marshal) { - out << nl << v << ".ice_write(" << stream << ");"; + out << nl << typeS << ".ice_write(" << stream << ", " << v << ");"; } else { - string typeS = typeToString(type, TypeModeIn, package); out << nl << v << " = " << typeS << ".ice_read(" << stream << ");"; } return; diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 969472d97db..63adc6076c2 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -4323,6 +4323,31 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) } _out << eb; + if(isClass) + { + emitGeneratedCodeAttribute(); + _out << nl << "public static void write__(IceInternal.BasicStream os__, " << name << " v__)"; + _out << sb; + _out << nl << "if(v__ == null)"; + _out << sb; + _out << nl << "nullMarshalValue__.write__(os__);"; + _out << eb; + _out << nl << "else"; + _out << sb; + _out << nl << "v__.write__(os__);"; + _out << eb; + _out << eb; + + _out << sp; + emitGeneratedCodeAttribute(); + _out << nl << "public static " << name << " readNew__(IceInternal.BasicStream is__)"; + _out << sb; + _out << nl << name << " v__ = new " << name << "();"; + _out << nl << "v__.read__(is__);"; + _out << nl << "return v__;"; + _out << eb; + } + if(_stream) { _out << sp; @@ -4346,8 +4371,37 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) classMemberCount); } _out << eb; + + if(isClass) + { + emitGeneratedCodeAttribute(); + _out << nl << "public static void ice_write(Ice.OutputStream outS__, " << name << " v__)"; + _out << sb; + _out << nl << "if(v__ == null)"; + _out << sb; + _out << nl << "nullMarshalValue__.ice_write(outS__);"; + _out << eb; + _out << nl << "else"; + _out << sb; + _out << nl << "v__.ice_write(outS__);"; + _out << eb; + _out << eb; + + _out << sp; + emitGeneratedCodeAttribute(); + _out << nl << "public static " << name << " ice_readNew(Ice.InputStream inS__)"; + _out << sb; + _out << nl << name << " v__ = new " << name << "();"; + _out << nl << "v__.ice_read(inS__);"; + _out << nl << "return v__;"; + _out << eb; + } } + if(isClass) + { + _out << nl << nl << "private static readonly " << name << " nullMarshalValue__ = new " << name << "();"; + } _out << sp << nl << "#endregion"; // Marshalling support } diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp index f4443814e3f..50700977c11 100644 --- a/cpp/src/slice2java/Gen.cpp +++ b/cpp/src/slice2java/Gen.cpp @@ -4010,6 +4010,49 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) } out << eb; } + + out << sp << nl << "static public void" << nl << "__write(IceInternal.BasicStream __os, " << name << " __v)"; + out << sb; + out << nl << "if(__v == null)"; + out << sb; + out << nl << "__nullMarshalValue.__write(__os);"; + out << eb; + out << nl << "else"; + out << sb; + out << nl << "__v.__write(__os);"; + out << eb; + out << eb; + + out << sp << nl << "static public " << name << nl << "__readNew(IceInternal.BasicStream __is)"; + out << sb; + out << nl << name << " __v = new " << name << "();"; + out << nl << "__v.__read(__is);"; + out << nl << "return __v;"; + out << eb; + + if(_stream) + { + out << sp << nl << "static public void" << nl << "ice_write(Ice.OutputStream __outS, " << name << " __v)"; + out << sb; + out << nl << "if(__v == null)"; + out << sb; + out << nl << "__nullMarshalValue.ice_write(__outS);"; + out << eb; + out << nl << "else"; + out << sb; + out << nl << "__v.ice_write(__outS);"; + out << eb; + out << eb; + + out << sp << nl << "static public " << name << nl << "ice_readNew(Ice.InputStream __inS)"; + out << sb; + out << nl << name << " __v = new " << name << "();"; + out << nl << "__v.ice_read(__inS);"; + out << nl << "return __v;"; + out << eb; + } + + out << nl << nl << "private static final " << name << " __nullMarshalValue = new " << name << "();"; } out << sp << nl << "public static final long serialVersionUID = "; @@ -4383,6 +4426,19 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) out << nl << "__os.writeEnum(value(), " << p->maxValue() << ");"; out << eb; + out << sp << nl << "public static void" << nl << "__write(IceInternal.BasicStream __os, " << name << " __v)"; + out << sb; + out << nl << "if(__v == null)"; + out << sb; + string firstEnum = fixKwd(enumerators.front()->name()); + out << nl << "__os.writeEnum(" << absolute << '.' << firstEnum << ".value(), " << p->maxValue() << ");"; + out << eb; + out << nl << "else"; + out << sb; + out << nl << "__os.writeEnum(__v.value(), " << p->maxValue() << ");"; + out << eb; + out << eb; + out << sp << nl << "public static " << name << nl << "__read(IceInternal.BasicStream __is)"; out << sb; out << nl << "int __v = __is.readEnum(" << p->maxValue() << ");"; @@ -4396,6 +4452,18 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) out << nl << "__outS.writeEnum(value(), " << p->maxValue() << ");"; out << eb; + out << sp << nl << "public static void" << nl << "ice_write(Ice.OutputStream __outS, " << name << " __v)"; + out << sb; + out << nl << "if(__v == null)"; + out << sb; + out << nl << "__outS.writeEnum(" << absolute << '.' << firstEnum << ".value(), " << p->maxValue() << ");"; + out << eb; + out << nl << "else"; + out << sb; + out << nl << "__outS.writeEnum(__v.value(), " << p->maxValue() << ");"; + out << eb; + out << eb; + out << sp << nl << "public static " << name << nl << "ice_read(Ice.InputStream __inS)"; out << sb; out << nl << "int __v = __inS.readEnum(" << p->maxValue() << ");"; @@ -4752,7 +4820,7 @@ Slice::Gen::HelperVisitor::visitClassDefStart(const ClassDefPtr& p) out << sb; if(op->returnsData()) { - out << nl << "IceInternal.OutgoingAsync __result = IceInternal.OutgoingAsync.check(__iresult, this, __" + out << nl << "IceInternal.OutgoingAsync __result = IceInternal.OutgoingAsync.check(__iresult, this, __" << op->name() << "_name);"; out << nl << "try"; out << sb; @@ -6744,4 +6812,3 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) } } } - diff --git a/cpp/src/slice2js/Gen.cpp b/cpp/src/slice2js/Gen.cpp index 610d671238a..1597220563e 100644 --- a/cpp/src/slice2js/Gen.cpp +++ b/cpp/src/slice2js/Gen.cpp @@ -582,14 +582,14 @@ Slice::Gen::Gen(const string& base, const vector<string>& includePaths, const st { _fileBase = base.substr(pos + 1); } - + string file = _fileBase + ".js"; if(!dir.empty()) { file = dir + '/' + file; } - + _out.open(file.c_str()); if(!_out) { @@ -599,7 +599,7 @@ Slice::Gen::Gen(const string& base, const vector<string>& includePaths, const st } FileTracker::instance()->addFile(file); - + printHeader(); printGeneratedHeader(_out, _fileBase + ".ice"); } @@ -616,7 +616,7 @@ Slice::Gen::Gen(const string& base, const vector<string>& includePaths, const st { _fileBase = base.substr(pos + 1); } - + printHeader(); printGeneratedHeader(_out, _fileBase + ".ice"); } @@ -1815,7 +1815,7 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) _out << sp; writeDocComment(p, getDeprecateReason(p, 0, "type")); - _out << nl << localScope << '.' << name << " = Slice.defineEnum({"; + _out << nl << localScope << '.' << name << " = Slice.defineEnum(["; _out.inc(); _out << nl; @@ -1834,9 +1834,9 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) _out << ", "; } } - _out << "'" << fixId((*en)->name()) << "':" << (*en)->value(); + _out << "['" << fixId((*en)->name()) << "', " << (*en)->value() << ']'; } - _out << "});"; + _out << "]);"; _out.dec(); // |