diff options
author | Michi Henning <michi@zeroc.com> | 2004-02-23 04:45:14 +0000 |
---|---|---|
committer | Michi Henning <michi@zeroc.com> | 2004-02-23 04:45:14 +0000 |
commit | c90dc0cea415c7b1329486a843c1b02573d4a389 (patch) | |
tree | d3dc22ea3ddec3fe88fb21173329c3eb62dc034a /cpp/src | |
parent | Added AMI/AMD tests for exception slicing to project. (diff) | |
download | ice-c90dc0cea415c7b1329486a843c1b02573d4a389.tar.bz2 ice-c90dc0cea415c7b1329486a843c1b02573d4a389.tar.xz ice-c90dc0cea415c7b1329486a843c1b02573d4a389.zip |
More code generation changes for Icicle.
Diffstat (limited to 'cpp/src')
-rwxr-xr-x | cpp/src/Slice/CsUtil.cpp | 872 | ||||
-rwxr-xr-x | cpp/src/slice2cs/Gen.cpp | 400 |
2 files changed, 424 insertions, 848 deletions
diff --git a/cpp/src/Slice/CsUtil.cpp b/cpp/src/Slice/CsUtil.cpp index 70cb4777d3d..b5cd0f17fe5 100755 --- a/cpp/src/Slice/CsUtil.cpp +++ b/cpp/src/Slice/CsUtil.cpp @@ -215,8 +215,7 @@ void Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, const TypePtr& type, const string& param, - bool marshal, - int& iter) + bool marshal) { string stream = marshal ? "__os" : "__is"; @@ -467,11 +466,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, SequencePtr seq = SequencePtr::dynamicCast(type); if(seq) { - // writeSequenceMarshalUnmarshalCode(out, scope, seq, v, marshal, iter, true, metaData); TODO - if(!marshal) - { - out << nl << param << " = null;"; - } + writeSequenceMarshalUnmarshalCode(out, seq, param, marshal); return; } @@ -487,821 +482,90 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, out << nl << param << " = " << typeS << "Helper.read(" << stream << ");"; } } -#if 0 - -void -Slice::CsGenerator::writeMarshalUnmarshalCode(Output& out, - const string& scope, - const TypePtr& type, - const string& param, - bool marshal, - int& iter, - bool holder, - const list<string>& metaData, - const string& patchParams) -{ - 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 - { - if(holder) - { - out << nl << stream << ".readObject(" << param << ".getPatcher());"; - } - else - { - if(patchParams.empty()) - { - out << nl << stream << ".readObject(new Patcher());"; - } - else - { - out << nl << stream << ".readObject(" << patchParams << ");"; - } - } - } - 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); - if(holder) - { - out << nl << stream << ".readObject(" << param << ".getPatcher());"; - } - else - { - if(patchParams.empty()) - { - out << nl << stream << ".readObject(new Patcher());"; - } - else - { - out << nl << stream << ".readObject(" << patchParams << ");"; - } - } - } - 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) - { - writeSequenceMarshalUnmarshalCode(out, scope, seq, v, marshal, iter, true, metaData); - 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::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, - const string& scope, const SequencePtr& seq, const string& param, - bool marshal, - int& iter, - bool useHelper, - const list<string>& metaData) + bool marshal) { string stream = marshal ? "__os" : "__is"; - string v = param; - - // - // Check for metadata that overrides the default sequence - // mapping. If no metadata is found, we use a regular Java - // array. If metadata is found, the value of the metadata - // must be the name of a class which implements the - // java.util.List interface. - // - // There are two sources of metadata - that passed into - // this function (which most likely comes from a data - // member definition), and that associated with the type - // itself. If data member metadata is found, and does - // not match the type's metadata, then we cannot use - // the type's Helper class for marshalling - we must - // generate marshalling code inline. - // - string listType = findMetaData(metaData); - list<string> typeMetaData = seq->getMetaData(); - if(listType.empty()) - { - listType = findMetaData(typeMetaData); - } - else - { - string s = findMetaData(typeMetaData); - if(listType != s) - { - useHelper = false; - } - } - // - // If we can use the sequence's helper, it's easy. - // - if(useHelper) - { - string typeS = getAbsolute(seq->scoped(), scope); - if(marshal) - { - out << nl << typeS << "Helper.write(" << stream << ", " << v << ");"; - } - else - { - out << nl << v << " = " << typeS << "Helper.read(" << stream << ");"; - } - return; - } - - // - // Determine sequence depth - // - int depth = 0; - TypePtr origContent = seq->type(); - SequencePtr s = SequencePtr::dynamicCast(origContent); - while(s) - { - // - // Stop if the inner sequence type has metadata. - // - string m = findMetaData(s->getMetaData()); - if(!m.empty()) - { - break; - } - depth++; - origContent = s->type(); - s = SequencePtr::dynamicCast(origContent); - } - string origContentS = typeToString(origContent, TypeModeIn, scope); - - if(!listType.empty()) + TypePtr type = seq->type(); + BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); + if(builtin) { - // - // Marshal/unmarshal a custom sequence type - // - BuiltinPtr b = BuiltinPtr::dynamicCast(seq->type()); - if(b && b->kind() != Builtin::KindObject && b->kind() != Builtin::KindObjectProxy) - { - if(marshal) - { - out << nl << "if(" << v << " == null)"; - out << sb; - out << nl << stream << ".writeSize(0);"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << stream << ".writeSize(" << v << ".size());"; - ostringstream o; - o << "__i" << iter; - string it = o.str(); - iter++; - out << nl << "java.util.Iterator " << it << " = " << v << ".iterator();"; - out << nl << "while(" << it << ".hasNext())"; - out << sb; - - switch(b->kind()) - { - case Builtin::KindByte: - { - out << nl << "java.lang.Byte __elem = (java.lang.Byte)" << it << ".next();"; - out << nl << stream << ".writeByte(__elem.byteValue());"; - break; - } - case Builtin::KindBool: - { - out << nl << "java.lang.Boolean __elem = (java.lang.Boolean)" << it << ".next();"; - out << nl << stream << ".writeBool(__elem.booleanValue());"; - break; - } - case Builtin::KindShort: - { - out << nl << "java.lang.Short __elem = (java.lang.Short)" << it << ".next();"; - out << nl << stream << ".writeShort(__elem.shortValue());"; - break; - } - case Builtin::KindInt: - { - out << nl << "java.lang.Integer __elem = (java.lang.Integer)" << it << ".next();"; - out << nl << stream << ".writeInt(__elem.intValue());"; - break; - } - case Builtin::KindLong: - { - out << nl << "java.lang.Long __elem = (java.lang.Long)" << it << ".next();"; - out << nl << stream << ".writeLong(__elem.longValue());"; - break; - } - case Builtin::KindFloat: - { - out << nl << "java.lang.Float __elem = (java.lang.Float)" << it << ".next();"; - out << nl << stream << ".writeFloat(__elem.floatValue());"; - break; - } - case Builtin::KindDouble: - { - out << nl << "java.lang.Double __elem = (java.lang.Double)" << it << ".next();"; - out << nl << stream << ".writeDouble(__elem.doubleValue());"; - break; - } - case Builtin::KindString: - { - out << nl << "java.lang.String __elem = (java.lang.String)" << it << ".next();"; - out << nl << stream << ".writeString(__elem);"; - break; - } - case Builtin::KindObject: - case Builtin::KindObjectProxy: - case Builtin::KindLocalObject: - { - assert(false); - break; - } - } - out << eb; // while - out << eb; - } - else - { - out << nl << v << " = new " << listType << "();"; - ostringstream o; - o << origContentS << "[]"; - int d = depth; - while(d--) - { - o << "[]"; - } - switch(b->kind()) - { - case Builtin::KindByte: - { - out << nl << o.str() << " __seq" << iter << " = " << stream << ".readByteSeq();"; - out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __seq" << iter - << ".length; __i" << iter << "++)"; - out << sb; - out << nl << v << ".add(new java.lang.Byte(__seq" << iter << "[__i" << iter << "]));"; - out << eb; - iter++; - break; - } - case Builtin::KindBool: - { - out << nl << o.str() << " __seq" << iter << " = " << stream << ".readBoolSeq();"; - out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __seq" << iter - << ".length; __i" << iter << "++)"; - out << sb; - out << nl << v << ".add(__seq" << iter << "[__i" << iter - << "] ? java.lang.Boolean.TRUE : java.lang.Boolean.FALSE);"; - out << eb; - iter++; - break; - } - case Builtin::KindShort: - { - out << nl << o.str() << " __seq" << iter << " = " << stream << ".readShortSeq();"; - out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __seq" << iter - << ".length; __i" << iter << "++)"; - out << sb; - out << nl << v << ".add(new java.lang.Short(__seq" << iter << "[__i" << iter << "]));"; - out << eb; - iter++; - break; - } - case Builtin::KindInt: - { - out << nl << o.str() << " __seq" << iter << " = " << stream << ".readIntSeq();"; - out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __seq" << iter - << ".length; __i" << iter << "++)"; - out << sb; - out << nl << v << ".add(new java.lang.Integer(__seq" << iter << "[__i" << iter << "]));"; - out << eb; - iter++; - break; - } - case Builtin::KindLong: - { - out << nl << o.str() << " __seq" << iter << " = " << stream << ".readLongSeq();"; - out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __seq" << iter - << ".length; __i" << iter << "++)"; - out << sb; - out << nl << v << ".add(new java.lang.Long(__seq" << iter << "[__i" << iter << "]));"; - out << eb; - iter++; - break; - } - case Builtin::KindFloat: - { - out << nl << o.str() << " __seq" << iter << " = " << stream << ".readFloatSeq();"; - out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __seq" << iter - << ".length; __i" << iter << "++)"; - out << sb; - out << nl << v << ".add(new java.lang.Float(__seq" << iter << "[__i" << iter << "]));"; - out << eb; - iter++; - break; - } - case Builtin::KindDouble: - { - out << nl << o.str() << " __seq" << iter << " = " << stream << ".readDoubleSeq();"; - out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __seq" << iter - << ".length; __i" << iter << "++)"; - out << sb; - out << nl << v << ".add(new java.lang.Double(__seq" << iter << "[__i" << iter << "]));"; - out << eb; - iter++; - break; - } - case Builtin::KindString: - { - out << nl << o.str() << " __seq" << iter << " = " << stream << ".readStringSeq();"; - out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __seq" << iter - << ".length; __i" << iter << "++)"; - out << sb; - out << nl << v << ".add(__seq" << iter << "[__i" << iter << "]);"; - out << eb; - iter++; - break; - } - case Builtin::KindObject: - case Builtin::KindObjectProxy: - case Builtin::KindLocalObject: - { - assert(false); - break; - } - } - } - } - else - { - string typeS = getAbsolute(seq->scoped(), scope); - if(marshal) - { - out << nl << "if(" << v << " == null)"; - out << sb; - out << nl << stream << ".writeSize(0);"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << stream << ".writeSize(" << v << ".size());"; - ostringstream o; - o << "__i" << iter; - iter++; - string it = o.str(); - out << nl << "java.util.Iterator " << it << " = " << v << ".iterator();"; - out << nl << "while(" << it << ".hasNext())"; - out << sb; - out << nl << origContentS << " __elem = (" << origContentS << ")" << it << ".next();"; - writeMarshalUnmarshalCode(out, scope, seq->type(), "__elem", true, iter, false); - out << eb; // while - out << eb; // else - } - else - { - bool isObject = false; - BuiltinPtr builtin = BuiltinPtr::dynamicCast(origContent); - if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(origContent)) - { - isObject = true; - } - out << nl << v << " = new " << listType << "();"; - out << nl << "final int __len" << iter << " = " << stream << ".readSize();"; - if(isObject) - { - if(builtin) - { - out << nl << "final String __type" << iter << " = Ice.ObjectImpl.ice_staticId();"; - } - else - { - out << nl << "final String __type" << iter << " = " << origContentS << ".ice_staticId();"; - } - } - out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __len" << iter << "; __i" << iter - << "++)"; - out << sb; - if(isObject) + switch(builtin->kind()) + { + case Builtin::KindObject: + case Builtin::KindObjectProxy: + { + if(marshal) { - // - // Add a null value to the list as a placeholder for the element. - // - out << nl << v << ".add(null);"; - ostringstream patchParams; - patchParams << "new IceInternal.ListPatcher(" << v << ", " << origContentS << ".class, __type" - << iter << ", __i" << iter << ')'; - writeMarshalUnmarshalCode(out, scope, seq->type(), "__elem", false, iter, false, - list<string>(), patchParams.str()); + out << nl << "if(__v == null)"; + out << sb; + out << nl << "__os.writeSize(0);"; + out << eb; + out << nl << "else"; + out << sb; + out << nl << "__os.writeSize(" << param << ".Count);"; + out << nl << "for(int __i = 0; __i < " << param << ".Count; ++__i)"; + out << sb; + string func = builtin->kind() == Builtin::KindObject ? "writeObject" : "writeProxy"; + out << nl << "__os." << func << "(__v[__i]);"; + out << eb; + out << eb; } else { - out << nl << origContentS << " __elem;"; - writeMarshalUnmarshalCode(out, scope, seq->type(), "__elem", false, iter, false); + if(builtin->kind() == Builtin::KindObject) + { + out << nl << "__v = new Ice.ObjectSeq();"; + out << nl << "int __len = __is.readSize();"; + out << nl << "for(int __i = 0; __i < __len; ++__i)"; + out << sb; + out << nl << "__is.readObject(new IceInternal.SequencePatcher(" + << "__v, Ice.Object.GetType(), Ice.ObjectImpl.ice_staticId(), __i));"; + out << eb; + } + else + { + out << nl << "__v = new Ice.ObjectProxySeq();"; + out << nl << "int __len = __is.readSize();"; + out << nl << "for(int __i = 0; __i < __len; ++__i)"; + out << sb; + out << nl << "__v.Add(__is.readProxy());"; + out << eb; + } } - iter++; - if(!isObject) + break; + } + default: + { + string typeS = typeToString(type); + typeS[0] = toupper(typeS[0]); + if(marshal) { - out << nl << v << ".add(__elem);"; + out << nl << "__os.write" << typeS << "Seq(" << param << ".ToArray());"; } - out << eb; - } - } + else + { + out << nl << param << " = new " << fixId(seq->scoped()) << "(__is.read" << typeS << "Seq());"; + } + break; + } + } } else { - BuiltinPtr b = BuiltinPtr::dynamicCast(seq->type()); - if(b && b->kind() != Builtin::KindObject && b->kind() != Builtin::KindObjectProxy) - { - 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: - case Builtin::KindLocalObject: - { - assert(false); - break; - } - } - } - else - { - if(marshal) - { - out << nl << "if(" << v << " == null)"; - out << sb; - out << nl << stream << ".writeSize(0);"; - out << eb; - out << nl << "else"; - out << sb; - out << nl << stream << ".writeSize(" << v << ".length);"; - out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < " << v << ".length; __i" << iter - << "++)"; - out << sb; - ostringstream o; - o << v << "[__i" << iter << "]"; - iter++; - writeMarshalUnmarshalCode(out, scope, seq->type(), o.str(), true, iter, false); - out << eb; - out << eb; - } - else - { - bool isObject = false; - if((b && b->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(origContent)) - { - isObject = true; - } - out << nl << "final int __len" << iter << " = " << stream << ".readSize();"; - if(isObject) - { - if(b) - { - out << nl << "final String __type" << iter << " = Ice.ObjectImpl.ice_staticId();"; - } - else - { - out << nl << "final String __type" << iter << " = " << origContentS << ".ice_staticId();"; - } - } - out << nl << v << " = new " << origContentS << "[__len" << iter << "]"; - int d = depth; - while(d--) - { - out << "[]"; - } - out << ';'; - out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __len" << iter << "; __i" << iter - << "++)"; - out << sb; - ostringstream o; - o << v << "[__i" << iter << "]"; - ostringstream patchParams; - if(isObject) - { - patchParams << "new IceInternal.SequencePatcher(" << v << ", " << origContentS - << ".class, __type" << iter << ", __i" << iter << ')'; - writeMarshalUnmarshalCode(out, scope, seq->type(), o.str(), false, iter, false, - list<string>(), patchParams.str()); - } - else - { - writeMarshalUnmarshalCode(out, scope, seq->type(), o.str(), false, iter, false); - } - iter++; - out << eb; - } - } - } -} - -string -Slice::CsGenerator::findMetaData(const list<string>& metaData) -{ - static const string prefix = "cs:"; - for(list<string>::const_iterator q = metaData.begin(); q != metaData.end(); ++q) - { - if((*q).find(prefix) == 0) - { - return (*q).substr(prefix.size()); - } + if(marshal) + { + out << nl << fixId(seq->scoped()) << "Helper.write(__os, " << param << ");"; + } + else + { + out << nl << param << " = " << fixId(seq->scoped()) << "Helper.read(__is);"; + } } - - return ""; + return; } -#endif diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index af2b3cedca6..006cbdab7b3 100755 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -114,17 +114,13 @@ Slice::CsVisitor::writeInheritedOperations(const ClassDefPtr& p) void Slice::CsVisitor::writeDispatch(const ClassDefPtr& p) { - _out << sp << nl << "#region Slice type-related members"; - - _out << sp << nl << "public static new string[] __ids = "; - _out << sb; - - string scoped = fixId(p->name()); + string name = fixId(p->name()); + string scoped = p->scoped(); ClassList allBases = p->allBases(); StringList ids; transform(allBases.begin(), allBases.end(), back_inserter(ids), ::IceUtil::constMemFun(&Contained::scoped)); StringList other; - other.push_back(scoped); + other.push_back(p->scoped()); other.push_back("::Ice::Object"); other.sort(); ids.merge(other); @@ -134,6 +130,11 @@ Slice::CsVisitor::writeDispatch(const ClassDefPtr& p) assert(scopedIter != ids.end()); StringList::difference_type scopedPos = ice_distance(firstIter, scopedIter); + _out << sp << nl << "#region Slice type-related members"; + + _out << sp << nl << "public static new string[] __ids = "; + _out << sb; + StringList::const_iterator q = ids.begin(); while(q != ids.end()) { @@ -169,7 +170,336 @@ Slice::CsVisitor::writeDispatch(const ClassDefPtr& p) _out << nl << "return __ids[" << scopedPos << "];"; _out << eb; - _out << sp << nl << "#endregion;"; // Slice type-related members + _out << sp << nl << "#endregion"; // Slice type-related members + + _out << sp << nl << "#region Operation dispatch"; + + OperationList ops = p->operations(); + OperationList::const_iterator r; + for(r = ops.begin(); r != ops.end(); ++r) + { + OperationPtr op = *r; + ContainerPtr container = op->container(); + ClassDefPtr cl = ClassDefPtr::dynamicCast(container); + assert(cl); + + string opName = fixId(op->name()); + _out << sp << nl << "public static IceInternal.DispatchStatus ___" << opName << '(' << name + << " __obj, IceInternal.Incoming __in, Ice.Current __current)"; + _out << sb; + + bool amd = p->hasMetaData("amd") || op->hasMetaData("amd"); + if(!amd) + { + TypePtr ret = op->returnType(); + + TypeStringList inParams; + TypeStringList outParams; + ParamDeclList paramList = op->parameters(); + for(ParamDeclList::const_iterator pli = paramList.begin(); pli != paramList.end(); ++pli) + { + if((*pli)->isOutParam()) + { + outParams.push_back(make_pair((*pli)->type(), (*pli)->name())); + } + else + { + inParams.push_back(make_pair((*pli)->type(), (*pli)->name())); + } + } + + ExceptionList throws = op->throws(); + throws.sort(); + throws.unique(); + remove_if(throws.begin(), throws.end(), IceUtil::constMemFun(&Exception::isLocal)); + + TypeStringList::const_iterator q; + + if(!inParams.empty()) + { + _out << nl << "IceInternal.BasicStream __is = __in.istr();"; + } + if(!outParams.empty() || ret || !throws.empty()) + { + _out << nl << "IceInternal.BasicStream __os = __in.ostr();"; + } + + // + // Unmarshal 'in' parameters. + // + for(q = inParams.begin(); q != inParams.end(); ++q) + { + string typeS = typeToString(q->first); + BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first); + if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(q->first)) + { + _out << nl << typeS << "Holder " << fixId(q->second) << " = new " << typeS << "Holder();"; + writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false); + } + else + { + _out << nl << typeS << ' ' << fixId(q->second) << ';'; + writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false); + } + } + if(op->sendsClasses()) + { + _out << nl << "__is.readPendingObjects();"; + } + + for(q = outParams.begin(); q != outParams.end(); ++q) + { + string typeS = typeToString(q->first); + _out << nl << typeS << ' ' << fixId(q->second) << ";"; + } + + // + // Call on the servant. + // + if(!throws.empty()) + { + _out << nl << "try"; + _out << sb; + } + _out << nl; + if(ret) + { + string retS = typeToString(ret); + _out << retS << " __ret = "; + } + _out << "__obj." << opName << '('; + for(q = inParams.begin(); q != inParams.end(); ++q) + { + _out << fixId(q->second); + BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first); + if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(q->first)) + { + _out << ".value"; + } + _out << ", "; + } + for(q = outParams.begin(); q != outParams.end(); ++q) + { + _out << "out " << fixId(q->second) << ", "; + } + _out << "__current);"; + + // + // Marshal 'out' parameters and return value. + // + for(q = outParams.begin(); q != outParams.end(); ++q) + { + writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), true); + } + if(ret) + { + writeMarshalUnmarshalCode(_out, ret, "__ret", true); + } + if(op->returnsClasses()) + { + _out << nl << "__os.writePendingObjects();"; + } + _out << nl << "return IceInternal.DispatchStatus.DispatchOK;"; + + // + // Handle user exceptions. + // + if(!throws.empty()) + { + _out << eb; + ExceptionList::const_iterator t; + for(t = throws.begin(); t != throws.end(); ++t) + { + string exS = fixId((*t)->scoped()); + _out << nl << "catch(" << exS << " ex)"; + _out << sb; + _out << nl << "__os.writeUserException(ex);"; + _out << nl << "return IceInternal.DispatchStatus.DispatchUserException;"; + _out << eb; + } + } + + _out << eb; + } + else + { +#if 0 + TypeStringList inParams; + ParamDeclList paramList = op->parameters(); + for(ParamDeclList::const_iterator pli = paramList.begin(); pli != paramList.end(); ++pli) + { + if(!(*pli)->isOutParam()) + { + inParams.push_back(make_pair((*pli)->type(), (*pli)->name())); + } + } + + TypeStringList::const_iterator q; + int iter; + + if(!inParams.empty()) + { + _out << nl << "IceInternal.BasicStream __is = __in.istr();"; + } + + // + // Unmarshal 'in' parameters. + // + for(q = inParams.begin(); q != inParams.end(); ++q) + { + string typeS = typeToString(q->first); + BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first); + if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(q->first)) + { + _out << nl << typeS << "Holder " << fixId(q->second) << " = new " << typeS << "Holder();"; + writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false); + } + else + { + _out << nl << typeS << ' ' << fixId(q->second) << ';'; + writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false); + } + } + if(op->sendsClasses()) + { + _out << nl << "__is.readPendingObjects();"; + } + + // + // Call on the servant. + // + string classNameAMD = "AMD_" + fixId(p->name()); + _out << nl << classNameAMD << '_' << opName << " __cb = new _" << classNameAMD << '_' << opName + << "(__in);"; + _out << nl << "try"; + _out << sb; + _out << nl << "__obj." << opName << (amd ? "_async(__cb, " : "("); + for(q = inParams.begin(); q != inParams.end(); ++q) + { + _out << fixId(q->second); + BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first); + if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(q->first)) + { + _out << ".value"; + } + _out << ", "; + } + _out << "__current);"; + _out << eb; + _out << nl << "catch(java.lang.Exception ex)"; + _out << sb; + _out << nl << "__cb.ice_exception(ex);"; + _out << eb; +#endif + _out << nl << "return IceInternal.DispatchStatus.DispatchAsync;"; + + _out << eb; + } + } + + OperationList allOps = p->allOperations(); + if(!allOps.empty()) + { + StringList allOpNames; + transform(allOps.begin(), allOps.end(), back_inserter(allOpNames), ::IceUtil::constMemFun(&Contained::name)); + allOpNames.push_back("ice_facets"); + allOpNames.push_back("ice_id"); + allOpNames.push_back("ice_ids"); + allOpNames.push_back("ice_isA"); + allOpNames.push_back("ice_ping"); + allOpNames.sort(); + allOpNames.unique(); + + StringList::const_iterator q; + + _out << sp << nl << "private static string[] __all ="; + _out << sb; + q = allOpNames.begin(); + while(q != allOpNames.end()) + { + _out << nl << '"' << *q << '"'; + if(++q != allOpNames.end()) + { + _out << ','; + } + } + _out << eb << ';'; + + _out << sp << nl << "public override IceInternal.DispatchStatus " + << "__dispatch(IceInternal.Incoming __in, Ice.Current __current)"; + _out << sb; + _out << nl << "int pos = _System.Array.BinarySearch(__all, __current.operation);"; + _out << nl << "if(pos < 0)"; + _out << sb; + _out << nl << "return IceInternal.DispatchStatus.DispatchOperationNotExist;"; + _out << eb; + _out << sp << nl << "switch(pos)"; + _out << sb; + int i = 0; + for(q = allOpNames.begin(); q != allOpNames.end(); ++q) + { + string opName = fixId(*q); + + _out << nl << "case " << i++ << ':'; + _out << sb; + if(opName == "ice_facets") + { + _out << nl << "return ___ice_facets(this, __in, __current);"; + } + else if(opName == "ice_id") + { + _out << nl << "return ___ice_id(this, __in, __current);"; + } + else if(opName == "ice_ids") + { + _out << nl << "return ___ice_ids(this, __in, __current);"; + } + else if(opName == "ice_isA") + { + _out << nl << "return ___ice_isA(this, __in, __current);"; + } + else if(opName == "ice_ping") + { + _out << nl << "return ___ice_ping(this, __in, __current);"; + } + else + { + // + // There's probably a better way to do this + // + for(OperationList::const_iterator t = allOps.begin(); t != allOps.end(); ++t) + { + if((*t)->name() == (*q)) + { + ContainerPtr container = (*t)->container(); + ClassDefPtr cl = ClassDefPtr::dynamicCast(container); + assert(cl); + if(cl->scoped() == p->scoped()) + { + _out << nl << "return ___" << opName << "(this, __in, __current);"; + } + else + { + string base = fixId(cl->scoped()); + if(cl->isInterface()) + { + base = base + "_Disp"; + } + _out << nl << "return " << base << ".___" << opName << "(this, __in, __current);"; + } + break; + } + } + } + _out << eb; + } + _out << eb; + _out << sp << nl << "_System.Diagnostics.Debug.Assert(false);"; + _out << nl << "return IceInternal.DispatchStatus.DispatchOperationNotExist;"; + _out << eb; + } + + _out << sp << nl << "#endregion"; // Operation dispatch } string @@ -415,7 +745,6 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) DataMemberList members = p->dataMembers(); DataMemberList::const_iterator d; - int iter; _out << sp << nl << "#region Marshaling support"; @@ -423,11 +752,10 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) _out << sb; _out << nl << "__os.writeTypeId(ice_staticId());"; _out << nl << "__os.startWriteSlice();"; - iter = 0; for(d = members.begin(); d != members.end(); ++d) { StringList metaData = (*d)->getMetaData(); - // TODO: writeMarshalUnmarshalCode(_out, package, (*d)->type(), fixId((*d)->name()), true, iter, false, metaData); + writeMarshalUnmarshalCode(_out, (*d)->type(), fixId((*d)->name()), true); } _out << nl << "__os.endWriteSlice();"; _out << nl << "base.__write(__os, __marshalFacets);"; @@ -464,10 +792,10 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) } if(allClassMembers.size() > 1) { - _out << nl << "__typeId = \"" << (*q)->type()->typeId() << "\";"; + _out << nl << "__typeId = \"" << (*d)->type()->typeId() << "\";"; } - string memberName = fixId((*q)->name()); - string memberType = typeToString((*q)->type()); + string memberName = fixId((*d)->name()); + string memberType = typeToString((*d)->type()); _out << nl << memberName << " = (" << memberType << ")v;"; if(allClassMembers.size() > 1) { @@ -508,7 +836,6 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) _out << nl << "string myId = __is.readTypeId();"; _out << eb; _out << nl << "__is.startReadSlice();"; - iter = 0; DataMemberList classMembers = p->classDataMembers(); long classMemberCount = allClassMembers.size() - classMembers.size(); for(d = members.begin(); d != members.end(); ++d) @@ -523,8 +850,7 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p) patchParams << "new Patcher(" << classMemberCount++ << ')'; } } - // TODO: writeMarshalUnmarshalCode(_out, package, (*d)->type(), fixId((*d)->name()), false, iter, false, metaData, patchParams.str()); - writeMarshalUnmarshalCode(_out, (*d)->type(), fixId((*d)->name()), false, iter); + writeMarshalUnmarshalCode(_out, (*d)->type(), fixId((*d)->name()), false); } _out << nl << "__is.endReadSlice();"; _out << nl << "base.__read(__is, true);"; @@ -1036,16 +1362,14 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) string scoped = p->scoped(); ExceptionPtr base = p->base(); - int iter; _out << sp << nl << "public override void __write(IceInternal.BasicStream __os)"; _out << sb; _out << nl << "__os.writeString(\"" << scoped << "\");"; _out << nl << "__os.startWriteSlice();"; - iter = 0; for(q = dataMembers.begin(); q != dataMembers.end(); ++q) { - // TODO: writeMarshalUnmarshalCode(_out, package, (*d)->type(), fixId((*d)->name()), true, iter, false, metaData); + writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name()), true); } _out << nl << "__os.endWriteSlice();"; if(base) @@ -1127,7 +1451,6 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) _out << nl << "string myId = __is.readString();"; _out << eb; _out << nl << "__is.startReadSlice();"; - iter = 0; DataMemberList classMembers = p->classDataMembers(); long classMemberCount = allClassMembers.size() - classMembers.size(); for(q = dataMembers.begin(); q != dataMembers.end(); ++q) @@ -1141,7 +1464,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) patchParams << "new Patcher(" << classMemberCount++ << ')'; } } - // TODO: writeMarshalUnmarshalCode(_out, package, (*d)->type(), fixId((*d)->name()), false, iter, false, metaData, patchParams.str()); + writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name()), false); } _out << nl << "__is.endReadSlice();"; if(base) @@ -1255,7 +1578,6 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) DataMemberList dataMembers = p->dataMembers(); DataMemberList::const_iterator q; - int iter; _out << sp << nl << "#endregion"; // Slice data members @@ -1267,7 +1589,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) _out << sb; for(q = dataMembers.begin(); q != dataMembers.end(); ++q) { - writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name()), true, iter); + writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name()), true); } _out << eb; @@ -1342,7 +1664,6 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) _out << sp << nl << "public void __read(IceInternal.BasicStream __is)"; _out << sb; - iter = 0; int classMemberCount = 0; for(q = dataMembers.begin(); q != dataMembers.end(); ++q) { @@ -1355,7 +1676,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) patchParams << "new Patcher(" << classMemberCount++ << ')'; } } - writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name()), false, iter); + writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name()), false); } _out << eb; @@ -2229,22 +2550,18 @@ Slice::Gen::HelperVisitor::visitSequence(const SequencePtr& p) string name = fixId(p->name()); string typeS = typeToString(p); - int iter; - _out << sp << nl << "public sealed class " << name << "Helper"; _out << sb; _out << nl << "public static void" << nl << "write(IceInternal.BasicStream __os, " << typeS << " __v)"; _out << sb; - iter = 0; - // writeSequenceMarshalUnmarshalCode(_out, package, p, "__v", true, iter, false); TODO + writeSequenceMarshalUnmarshalCode(_out, p, "__v", true); _out << eb; _out << sp << nl << "public static " << typeS << nl << "read(IceInternal.BasicStream __is)"; _out << sb; _out << nl << typeS << " __v;"; - iter = 0; - writeMarshalUnmarshalCode(_out, p, "__v", false, iter); + writeSequenceMarshalUnmarshalCode(_out, p, "__v", false); _out << nl << "return __v;"; _out << eb; @@ -2268,7 +2585,6 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) string name = fixId(p->name()); string keyS = typeToString(key); string valueS = typeToString(value); - int iter; // TODO: needed? _out << sp << nl << "public sealed class " << name << "Helper"; _out << sb; @@ -2284,11 +2600,10 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) _out << nl << "__os.writeSize(__v.Count);"; _out << nl << "foreach(_System.Collections.DictionaryEntry __e in __v)"; _out << sb; - iter = 0; string keyArg = "(" + keyS + ")__e.Key"; - writeMarshalUnmarshalCode(_out, key, keyArg, true, iter); + writeMarshalUnmarshalCode(_out, key, keyArg, true); string valueArg = "(" + valueS + ")__e.Value"; - writeMarshalUnmarshalCode(_out, value, valueArg, true, iter); + writeMarshalUnmarshalCode(_out, value, valueArg, true); _out << eb; _out << eb; @@ -2303,9 +2618,9 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) _out << nl << "for(int __i = 0; __i < __sz; ++__i)"; _out << sb; _out << nl << keyS << " __k;"; - writeMarshalUnmarshalCode(_out, key, "__k", false, iter); + writeMarshalUnmarshalCode(_out, key, "__k", false); _out << nl << valueS << " __v;"; - writeMarshalUnmarshalCode(_out, value, "__v", false, iter); + writeMarshalUnmarshalCode(_out, value, "__v", false); _out << nl << "__r[__k] = __v;"; _out << eb; _out << nl << "return __r;"; @@ -2318,7 +2633,6 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p) _out << nl << "while(__i.hasNext())"; _out << sb; _out << nl << "java.util.Map.Entry __e = (java.util.Map.Entry)" << "__i.next();"; - iter = 0; for(i = 0; i < 2; i++) { string val; @@ -2698,7 +3012,6 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) string opName = fixId(op->name()); TypePtr ret = op->returnType(); string retS = typeToString(ret); - int iter; TypeStringList inParams; TypeStringList outParams; @@ -2744,10 +3057,9 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) { _out << nl << "IceInternal.BasicStream __is = __out.istr();"; } - iter = 0; for(q = inParams.begin(); q != inParams.end(); ++q) { - writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), true, iter); + writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), true); } if(op->sendsClasses()) { @@ -2785,7 +3097,7 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) } for(q = outParams.begin(); q != outParams.end(); ++q) { - writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false, iter); + writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false); #if 0 // TODO: write marshal/unmarshal code here and remove initialization if(isValueType(q->first)) @@ -2817,7 +3129,7 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) else { _out << nl << retS << " __ret;"; - writeMarshalUnmarshalCode(_out, ret, "__ret", false, iter); + writeMarshalUnmarshalCode(_out, ret, "__ret", false); #if 0 if(isValueType(ret)) { |