summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2004-03-09 03:29:32 +0000
committerMichi Henning <michi@zeroc.com>2004-03-09 03:29:32 +0000
commitba07fd51fff5b7eea6837be95f9e692fa8c5a8e4 (patch)
treee0fa5581460564e2f12cdb5db0a15ab58db200bc /cpp/src
parentfixing VC6 link error (diff)
downloadice-ba07fd51fff5b7eea6837be95f9e692fa8c5a8e4.tar.bz2
ice-ba07fd51fff5b7eea6837be95f9e692fa8c5a8e4.tar.xz
ice-ba07fd51fff5b7eea6837be95f9e692fa8c5a8e4.zip
Intermediate check-in prior to removing IComparable.
Diffstat (limited to 'cpp/src')
-rwxr-xr-xcpp/src/Slice/CsUtil.cpp150
-rwxr-xr-xcpp/src/slice2cs/Gen.cpp484
-rw-r--r--cpp/src/slice2cs/Gen.h3
-rw-r--r--cpp/src/slice2cs/Main.cpp21
4 files changed, 195 insertions, 463 deletions
diff --git a/cpp/src/Slice/CsUtil.cpp b/cpp/src/Slice/CsUtil.cpp
index b5cd0f17fe5..58d668e68a3 100755
--- a/cpp/src/Slice/CsUtil.cpp
+++ b/cpp/src/Slice/CsUtil.cpp
@@ -62,7 +62,7 @@ lookupKwd(const string& name)
"IsSynchronized", "Item", "Keys", "List", "MemberWiseClone", "Message", "OnClear", "OnClearComplete",
"OnGet", "OnInsert", "OnInsertComplete", "OnRemove", "OnRemoveComplete", "OnSet", "OnSetComplete",
"OnValidate", "ReferenceEquals", "Remove", "RemoveAt", "Source", "StackTrace", "SyncRoot", "TargetSite",
- "ToString", "Values",
+ "ToString", "Values", "checked_cast", "unchecked_cast"
};
found = binary_search(&memberList[0],
&memberList[sizeof(memberList) / sizeof(*memberList)],
@@ -215,10 +215,24 @@ void
Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out,
const TypePtr& type,
const string& param,
- bool marshal)
+ bool marshal,
+ bool seqElem)
{
string stream = marshal ? "__os" : "__is";
+ string startAssign;
+ string endAssign;
+ if(seqElem)
+ {
+ startAssign = ".Add(";
+ endAssign = ")";
+ }
+ else
+ {
+ startAssign = " = ";
+ endAssign = "";
+ }
+
BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
if(builtin)
{
@@ -232,7 +246,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out,
}
else
{
- out << nl << param << " = " << stream << ".readByte();";
+ out << nl << param << startAssign << stream << ".readByte()" << endAssign << ";";
}
break;
}
@@ -244,7 +258,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out,
}
else
{
- out << nl << param << " = " << stream << ".readBool();";
+ out << nl << param << startAssign << stream << ".readBool()" << endAssign << ";";
}
break;
}
@@ -256,7 +270,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out,
}
else
{
- out << nl << param << " = " << stream << ".readShort();";
+ out << nl << param << startAssign << stream << ".readShort()" << endAssign << ";";
}
break;
}
@@ -268,7 +282,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out,
}
else
{
- out << nl << param << " = " << stream << ".readInt();";
+ out << nl << param << startAssign << stream << ".readInt()" << endAssign << ";";
}
break;
}
@@ -280,7 +294,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out,
}
else
{
- out << nl << param << " = " << stream << ".readLong();";
+ out << nl << param << startAssign << stream << ".readLong()" << endAssign << ";";
}
break;
}
@@ -292,7 +306,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out,
}
else
{
- out << nl << param << " = " << stream << ".readFloat();";
+ out << nl << param << startAssign << stream << ".readFloat()" << endAssign << ";";
}
break;
}
@@ -304,7 +318,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out,
}
else
{
- out << nl << param << " = " << stream << ".readDouble();";
+ out << nl << param << startAssign << stream << ".readDouble()" << endAssign << ";";
}
break;
}
@@ -316,7 +330,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out,
}
else
{
- out << nl << param << " = " << stream << ".readString();";
+ out << nl << param << startAssign << stream << ".readString()" << endAssign << ";";
}
break;
}
@@ -350,13 +364,14 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out,
#endif
case Builtin::KindObjectProxy:
{
+ string typeS = typeToString(type);
if(marshal)
{
out << nl << stream << ".writeProxy(" << param << ");";
}
else
{
- out << nl << param << " = " << stream << ".readProxy();";
+ out << nl << param << startAssign << stream << ".readProxy()" << endAssign << ";";
}
break;
}
@@ -379,12 +394,11 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out,
}
else
{
- out << nl << param << " = " << typeS << "Helper.__read(" << stream << ");";
+ out << nl << param << startAssign << typeS << "Helper.__read(" << stream << ")" << endAssign << ";";
}
return;
}
-#if 0
ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type);
if(cl)
{
@@ -394,26 +408,10 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out,
}
else
{
- string typeS = typeToString(type);
- if(holder)
- {
- out << nl << stream << ".readObject(" << param << ".getPatcher());";
- }
- else
- {
- if(patchParams.empty())
- {
- out << nl << stream << ".readObject(new Patcher());";
- }
- else
- {
- out << nl << stream << ".readObject(" << patchParams << ");";
- }
- }
+ out << nl << param << " = " << stream << ".readObject(new Patcher());";
}
return;
}
-#endif
StructPtr st = StructPtr::dynamicCast(type);
if(st)
@@ -458,7 +456,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out,
}
else
{
- out << nl << param << " = " << cast << stream << "." << func << "();";
+ out << nl << param << startAssign << cast << stream << "." << func << "()" << endAssign << ";";
}
return;
}
@@ -466,7 +464,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out,
SequencePtr seq = SequencePtr::dynamicCast(type);
if(seq)
{
- writeSequenceMarshalUnmarshalCode(out, seq, param, marshal);
+ writeSequenceMarshalUnmarshalCode(out, seq, param, marshal, seqElem);
return;
}
@@ -479,7 +477,7 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out,
}
else
{
- out << nl << param << " = " << typeS << "Helper.read(" << stream << ");";
+ out << nl << param << startAssign << typeS << "Helper.read(" << stream << ")" << endAssign << ";";
}
}
@@ -487,10 +485,24 @@ void
Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
const SequencePtr& seq,
const string& param,
- bool marshal)
+ bool marshal,
+ bool seqElem)
{
string stream = marshal ? "__os" : "__is";
+ string startAssign;
+ string endAssign;
+ if(seqElem)
+ {
+ startAssign = ".Add(";
+ endAssign = ")";
+ }
+ else
+ {
+ startAssign = " = ";
+ endAssign = "";
+ }
+
TypePtr type = seq->type();
BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
if(builtin)
@@ -502,17 +514,17 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
{
if(marshal)
{
- out << nl << "if(__v == null)";
+ out << nl << "if(" << param << " == null)";
out << sb;
- out << nl << "__os.writeSize(0);";
+ out << nl << stream << ".writeSize(0);";
out << eb;
out << nl << "else";
out << sb;
- out << nl << "__os.writeSize(" << param << ".Count);";
+ out << nl << stream << ".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 << nl << stream << "." << func << "(" << param << "[__i]);";
out << eb;
out << eb;
}
@@ -520,21 +532,21 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
{
if(builtin->kind() == Builtin::KindObject)
{
- out << nl << "__v = new Ice.ObjectSeq();";
- out << nl << "int __len = __is.readSize();";
+ out << nl << param << " = new Ice.ObjectSeq();";
+ out << nl << "int __len = " << stream << ".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 << nl << stream << ".readObject(new IceInternal.SequencePatcher("
+ << param << ", typeof(Ice.Object), Ice.ObjectImpl.ice_staticId(), __i));";
out << eb;
}
else
{
- out << nl << "__v = new Ice.ObjectProxySeq();";
- out << nl << "int __len = __is.readSize();";
+ out << nl << param << " = new Ice.ObjectProxySeq();";
+ out << nl << "int __len = " << stream << ".readSize();";
out << nl << "for(int __i = 0; __i < __len; ++__i)";
out << sb;
- out << nl << "__v.Add(__is.readProxy());";
+ out << nl << param << ".Add(" << stream << ".readProxy());";
out << eb;
}
}
@@ -546,26 +558,64 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
typeS[0] = toupper(typeS[0]);
if(marshal)
{
- out << nl << "__os.write" << typeS << "Seq(" << param << ".ToArray());";
+ out << nl << stream << ".write" << typeS << "Seq(" << param << ".ToArray());";
}
else
{
- out << nl << param << " = new " << fixId(seq->scoped()) << "(__is.read" << typeS << "Seq());";
+ out << nl << param << startAssign << "new " << fixId(seq->scoped()) << "(" << stream
+ << ".read" << typeS << "Seq())" << endAssign << ";";
}
break;
}
}
+ return;
}
- else
+
+ EnumPtr en = EnumPtr::dynamicCast(type);
+ if(en)
{
if(marshal)
{
- out << nl << fixId(seq->scoped()) << "Helper.write(__os, " << param << ");";
+ out << nl << stream << ".writeSize(" << param << ".Count);";
+ out << nl << "for(int __i = 0; __i < " << param << ".Count; ++__i)";
+ out << sb;
+ writeMarshalUnmarshalCode(out, type, param + "[__i]", marshal, true);
+ out << eb;
}
else
{
- out << nl << param << " = " << fixId(seq->scoped()) << "Helper.read(__is);";
+ out << nl << param << startAssign << "new " << fixId(seq->scoped()) << "()" << endAssign << ";";
+ out << nl << "int sz = " << stream << ".readSize();";
+ out << nl << "for(int __i = 0; __i < sz; ++__i)";
+ out << sb;
+ writeMarshalUnmarshalCode(out, type, param, marshal, true);
+ out << eb;
}
+ return;
}
+
+ string typeS = typeToString(type);
+ if(marshal)
+ {
+ string func = ProxyPtr::dynamicCast(type) ? "__write" : "write";
+ out << nl << stream << ".writeSize(" << param << ".Count);";
+ out << nl << "for(int __i = 0; __i < " << param << ".Count; ++__i)";
+ out << sb;
+ out << nl << typeS << "Helper." << func << "(" << stream << ", " << param << "[__i]);";
+ out << eb;
+ }
+ else
+ {
+ string func = ProxyPtr::dynamicCast(type) ? "__read" : "read";
+ out << nl << param << startAssign << "new " << fixId(seq->scoped()) << "()" << endAssign << ";";
+ out << sb;
+ out << nl << "int sz = " << stream << ".readSize();";
+ out << nl << "for(int __i = 0; __i < sz; ++__i)";
+ out << sb;
+ out << nl << param << ".Add(" << typeS << "Helper." << func << "(" << stream << "));";
+ out << eb;
+ out << eb;
+ }
+
return;
}
diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp
index 006cbdab7b3..4c1b78ffb92 100755
--- a/cpp/src/slice2cs/Gen.cpp
+++ b/cpp/src/slice2cs/Gen.cpp
@@ -234,12 +234,12 @@ Slice::CsVisitor::writeDispatch(const ClassDefPtr& p)
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);
+ writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false, false);
}
else
{
_out << nl << typeS << ' ' << fixId(q->second) << ';';
- writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false);
+ writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false, false);
}
}
if(op->sendsClasses())
@@ -289,11 +289,11 @@ Slice::CsVisitor::writeDispatch(const ClassDefPtr& p)
//
for(q = outParams.begin(); q != outParams.end(); ++q)
{
- writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), true);
+ writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), true, false);
}
if(ret)
{
- writeMarshalUnmarshalCode(_out, ret, "__ret", true);
+ writeMarshalUnmarshalCode(_out, ret, "__ret", true, false);
}
if(op->returnsClasses())
{
@@ -323,74 +323,6 @@ Slice::CsVisitor::writeDispatch(const ClassDefPtr& p)
}
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;
@@ -542,11 +474,31 @@ Slice::CsVisitor::getArgs(const OperationPtr& op)
return args;
}
-Slice::Gen::Gen(const string& name, const string& base, const vector<string>& includePaths)
+Slice::Gen::Gen(const string& name, const string& base, const vector<string>& includePaths, const string& dir)
: _base(base),
_includePaths(includePaths)
-{
- string file = base + ".cs";
+{
+ string file;
+ if(!dir.empty())
+ {
+ string slash = "/";
+ string::size_type pos = base.rfind('/');
+ if(pos == string::npos)
+ {
+ pos = base.rfind('\\');
+ slash = "\\";
+ }
+ if(pos != string::npos)
+ {
+ string fileBase(base, pos + 1);
+ cerr << "fileBase = " << fileBase << endl;
+ file = dir + slash + fileBase + ".cs";
+ }
+ }
+ else
+ {
+ file = base + ".cs";
+ }
_out.open(file.c_str());
if(!_out)
{
@@ -755,7 +707,7 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p)
for(d = members.begin(); d != members.end(); ++d)
{
StringList metaData = (*d)->getMetaData();
- writeMarshalUnmarshalCode(_out, (*d)->type(), fixId((*d)->name()), true);
+ writeMarshalUnmarshalCode(_out, (*d)->type(), fixId((*d)->name()), true, false);
}
_out << nl << "__os.endWriteSlice();";
_out << nl << "base.__write(__os, __marshalFacets);";
@@ -850,7 +802,7 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p)
patchParams << "new Patcher(" << classMemberCount++ << ')';
}
}
- writeMarshalUnmarshalCode(_out, (*d)->type(), fixId((*d)->name()), false);
+ writeMarshalUnmarshalCode(_out, (*d)->type(), fixId((*d)->name()), false, false);
}
_out << nl << "__is.endReadSlice();";
_out << nl << "base.__read(__is, true);";
@@ -1068,7 +1020,7 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p)
bool isValue = isValueType(p->type());
_out << sp << nl << "public class " << name
- << " : _System.Collections.CollectionBase, _System.IComparable, _System.ICloneable";
+ << " : _System.Collections.CollectionBase, _System.IComparable, _System.ICloneable, Ice.SequenceBase";
_out << sb;
_out << sp << nl << "#region Constructors";
@@ -1249,6 +1201,15 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p)
_out << sp << nl << "#endregion"; // ICloneable members
+ _out << sp << nl << "#region SequenceBase members";
+
+ _out << sp << nl << "public void set(int index, object o)";
+ _out << sb;
+ _out << nl << "InnerList[index] = (" << name << ")o;";
+ _out << eb;
+
+ _out << sp << nl << "#endregion"; // SequenceBase members
+
_out << sp << nl << "#region Object members";
_out << sp << nl << "public override int GetHashCode()";
@@ -1369,7 +1330,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
_out << nl << "__os.startWriteSlice();";
for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
- writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name()), true);
+ writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name()), true, false);
}
_out << nl << "__os.endWriteSlice();";
if(base)
@@ -1464,7 +1425,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
patchParams << "new Patcher(" << classMemberCount++ << ')';
}
}
- writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name()), false);
+ writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name()), false, false);
}
_out << nl << "__is.endReadSlice();";
if(base)
@@ -1589,7 +1550,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);
+ writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name()), true, false);
}
_out << eb;
@@ -1676,7 +1637,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p)
patchParams << "new Patcher(" << classMemberCount++ << ')';
}
}
- writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name()), false);
+ writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name()), false, false);
}
_out << eb;
@@ -1817,7 +1778,7 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
_out << sb;
_out << nl << "foreach(_System.Collections.DictionaryEntry e in __d)";
_out << sb;
- _out << nl << "Dictionary.Add(e.Key, e.Value);";
+ _out << nl << "InnerHashtable.Add(e.Key, e.Value);";
_out << eb;
_out << eb;
@@ -1831,12 +1792,12 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
_out << sb;
_out << nl << "get";
_out << sb;
- _out << nl << "return (" << vs << ")Dictionary[key];";
+ _out << nl << "return (" << vs << ")InnerHashtable[key];";
_out << eb;
_out << nl << "set";
_out << sb;
- _out << nl << "Dictionary[key] = value;";
+ _out << nl << "InnerHashtable[key] = value;";
_out << eb;
_out << eb;
@@ -1846,7 +1807,7 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
_out << sb;
_out << nl << "get";
_out << sb;
- _out << nl << "return Dictionary.Keys;";
+ _out << nl << "return InnerHashtable.Keys;";
_out << eb;
_out << eb;
@@ -1854,7 +1815,7 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
_out << sb;
_out << nl << "get";
_out << sb;
- _out << nl << "return Dictionary.Values;";
+ _out << nl << "return InnerHashtable.Values;";
_out << eb;
_out << eb;
@@ -1866,7 +1827,14 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
_out << sb;
_out << nl << "foreach(_System.Collections.DictionaryEntry e in __d)";
_out << sb;
- _out << nl << "Dictionary.Add(e.Key, e.Value);";
+ _out << nl << "try";
+ _out << sb;
+ _out << nl << "InnerHashtable.Add(e.Key, e.Value);";
+ _out << eb;
+ _out << nl << "catch(_System.ArgumentException)";
+ _out << sb;
+ _out << nl << "// ignore";
+ _out << eb;
_out << eb;
_out << eb;
@@ -1876,17 +1844,17 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
_out << sp << nl << "public void Add(" << ks << " key, " << vs << " value)";
_out << sb;
- _out << nl << "Dictionary[key] = value;";
+ _out << nl << "InnerHashtable.Add(key, value);";
_out << eb;
_out << sp << nl << "public void Remove(" << ks << " key)";
_out << sb;
- _out << nl << "Dictionary.Remove(key);";
+ _out << nl << "InnerHashtable.Remove(key);";
_out << eb;
_out << sp << nl << "public bool Contains(" << ks << " key)";
_out << sb;
- _out << nl << "return Dictionary.Contains(key);";
+ _out << nl << "return InnerHashtable.Contains(key);";
_out << eb;
_out << sp << nl << "#endregion"; // IDictionary members
@@ -1988,7 +1956,7 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
_out << sp << nl << "public object Clone()";
_out << sb;
_out << nl << name << " __ret = new " << name << "();";
- _out << nl << "foreach(System.Collections.DictionaryEntry e in Dictionary)";
+ _out << nl << "foreach(System.Collections.DictionaryEntry e in InnerHashtable)";
_out << sb;
_out << nl << "__ret[(" << ks << ")e.Key] = (" << vs << ")e.Value;";
_out << eb;
@@ -2002,7 +1970,7 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
_out << sp << nl << "public override int GetHashCode()";
_out << sb;
_out << nl << "int hash = 0;";
- _out << nl << "foreach(_System.Collections.DictionaryEntry e in Dictionary)";
+ _out << nl << "foreach(_System.Collections.DictionaryEntry e in InnerHashtable)";
_out << sb;
_out << nl << "hash = 5 * hash + e.Key.GetHashCode();";
if(!valueIsValue)
@@ -2553,15 +2521,15 @@ Slice::Gen::HelperVisitor::visitSequence(const SequencePtr& p)
_out << sp << nl << "public sealed class " << name << "Helper";
_out << sb;
- _out << nl << "public static void" << nl << "write(IceInternal.BasicStream __os, " << typeS << " __v)";
+ _out << nl << "public static void write(IceInternal.BasicStream __os, " << typeS << " __v)";
_out << sb;
- writeSequenceMarshalUnmarshalCode(_out, p, "__v", true);
+ writeSequenceMarshalUnmarshalCode(_out, p, "__v", true, false);
_out << eb;
- _out << sp << nl << "public static " << typeS << nl << "read(IceInternal.BasicStream __is)";
+ _out << sp << nl << "public static " << typeS << " read(IceInternal.BasicStream __is)";
_out << sb;
_out << nl << typeS << " __v;";
- writeSequenceMarshalUnmarshalCode(_out, p, "__v", false);
+ writeSequenceMarshalUnmarshalCode(_out, p, "__v", false, false);
_out << nl << "return __v;";
_out << eb;
@@ -2579,6 +2547,7 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p)
return;
}
+
TypePtr key = p->keyType();
TypePtr value = p->valueType();
@@ -2601,9 +2570,9 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p)
_out << nl << "foreach(_System.Collections.DictionaryEntry __e in __v)";
_out << sb;
string keyArg = "(" + keyS + ")__e.Key";
- writeMarshalUnmarshalCode(_out, key, keyArg, true);
+ writeMarshalUnmarshalCode(_out, key, keyArg, true, false);
string valueArg = "(" + valueS + ")__e.Value";
- writeMarshalUnmarshalCode(_out, value, valueArg, true);
+ writeMarshalUnmarshalCode(_out, value, valueArg, true, false);
_out << eb;
_out << eb;
@@ -2618,9 +2587,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);
+ writeMarshalUnmarshalCode(_out, key, "__k", false, false);
_out << nl << valueS << " __v;";
- writeMarshalUnmarshalCode(_out, value, "__v", false);
+ writeMarshalUnmarshalCode(_out, value, "__v", false, false);
_out << nl << "__r[__k] = __v;";
_out << eb;
_out << nl << "return __r;";
@@ -2629,277 +2598,6 @@ Slice::Gen::HelperVisitor::visitDictionary(const DictionaryPtr& p)
_out << eb;
-#if 0
- _out << nl << "while(__i.hasNext())";
- _out << sb;
- _out << nl << "java.util.Map.Entry __e = (java.util.Map.Entry)" << "__i.next();";
- for(i = 0; i < 2; i++)
- {
- string val;
- string arg;
- TypePtr type;
- if(i == 0)
- {
- arg = "__e.getKey()";
- type = key;
- }
- else
- {
- arg = "__e.getValue()";
- type = value;
- }
-
- BuiltinPtr b = BuiltinPtr::dynamicCast(type);
- if(b)
- {
- switch(b->kind())
- {
- case Builtin::KindByte:
- {
- val = "((java.lang.Byte)" + arg + ").byteValue()";
- break;
- }
- case Builtin::KindBool:
- {
- val = "((java.lang.Boolean)" + arg + ").booleanValue()";
- break;
- }
- case Builtin::KindShort:
- {
- val = "((java.lang.Short)" + arg + ").shortValue()";
- break;
- }
- case Builtin::KindInt:
- {
- val = "((java.lang.Integer)" + arg + ").intValue()";
- break;
- }
- case Builtin::KindLong:
- {
- val = "((java.lang.Long)" + arg + ").longValue()";
- break;
- }
- case Builtin::KindFloat:
- {
- val = "((java.lang.Float)" + arg + ").floatValue()";
- break;
- }
- case Builtin::KindDouble:
- {
- val = "((java.lang.Double)" + arg + ").doubleValue()";
- break;
- }
- case Builtin::KindString:
- case Builtin::KindObject:
- case Builtin::KindObjectProxy:
- {
- break;
- }
- case Builtin::KindLocalObject:
- {
- assert(false);
- break;
- }
- }
- }
-
- if(val.empty())
- {
- val = "((" + typeToString(type, TypeModeIn, package) + ')' + arg + ')';
- }
- writeMarshalUnmarshalCode(_out, package, type, val, true, iter, false);
- }
- _out << eb;
- _out << eb;
- _out << eb;
-
- BuiltinPtr builtin = BuiltinPtr::dynamicCast(value);
- if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(value))
- {
- //
- // The dictionary uses class values.
- //
- _out << sp << nl << "private static class Patcher implements IceInternal.Patcher";
- _out << sb;
- string keyTypeS = keyS;
- BuiltinPtr b = BuiltinPtr::dynamicCast(key);
- if(b)
- {
- switch(b->kind())
- {
- case Builtin::KindByte:
- {
- keyTypeS = "java.lang.Byte";
- break;
- }
- case Builtin::KindBool:
- {
- keyTypeS = "java.lang.Boolean";
- break;
- }
- case Builtin::KindShort:
- {
- keyTypeS = "java.lang.Short";
- break;
- }
- case Builtin::KindInt:
- {
- keyTypeS = "java.lang.Integer";
- break;
- }
- case Builtin::KindLong:
- {
- keyTypeS = "java.lang.Long";
- break;
- }
- case Builtin::KindFloat:
- {
- keyTypeS = "java.lang.Float";
- break;
- }
- case Builtin::KindDouble:
- {
- keyTypeS = "java.lang.Double";
- break;
- }
- default:
- {
- break; // Do nothing
- }
- }
- }
- _out << sp << nl << "Patcher(java.util.Map m, " << keyTypeS << " key)";
- _out << sb;
- _out << nl << "__m = m;";
- _out << nl << "__key = key;";
- _out << eb;
-
- _out << sp << nl << "public void" << nl << "patch(Ice.Object v)";
- _out << sb;
- _out << nl << valueS << " _v = (" << valueS << ")v;";
- _out << nl << "__m.put(__key, v);";
- _out << eb;
-
- _out << sp << nl << "public String" << nl << "type()";
- _out << sb;
- _out << nl << "return \"" << value->typeId() << "\";";
- _out << eb;
-
- _out << sp << nl << "private java.util.Map __m;";
- _out << nl << "private " << keyTypeS << " __key;";
- _out << eb;
- }
-
- _out << sp << nl << "public static java.util.Map" << nl << "read(IceInternal.BasicStream __is)";
- _out << sb;
- _out << nl << "int __sz = __is.readSize();";
- _out << nl << "java.util.Map __r = new java.util.HashMap(__sz);";
- _out << nl << "for(int __i = 0; __i < __sz; __i++)";
- _out << sb;
- iter = 0;
- for(i = 0; i < 2; i++)
- {
- string arg;
- TypePtr type;
- if(i == 0)
- {
- arg = "__key";
- type = key;
- }
- else
- {
- arg = "__value";
- type = value;
- }
-
- BuiltinPtr b = BuiltinPtr::dynamicCast(type);
- if(b)
- {
- switch(b->kind())
- {
- case Builtin::KindByte:
- {
- _out << nl << "java.lang.Byte " << arg << " = new java.lang.Byte(__is.readByte());";
- break;
- }
- case Builtin::KindBool:
- {
- _out << nl << "java.lang.Boolean " << arg << " = new java.lang.Boolean(__is.readBool());";
- break;
- }
- case Builtin::KindShort:
- {
- _out << nl << "java.lang.Short " << arg << " = new java.lang.Short(__is.readShort());";
- break;
- }
- case Builtin::KindInt:
- {
- _out << nl << "java.lang.Integer " << arg << " = new java.lang.Integer(__is.readInt());";
- break;
- }
- case Builtin::KindLong:
- {
- _out << nl << "java.lang.Long " << arg << " = new java.lang.Long(__is.readLong());";
- break;
- }
- case Builtin::KindFloat:
- {
- _out << nl << "java.lang.Float " << arg << " = new java.lang.Float(__is.readFloat());";
- break;
- }
- case Builtin::KindDouble:
- {
- _out << nl << "java.lang.Double " << arg << " = new java.lang.Double(__is.readDouble());";
- break;
- }
- case Builtin::KindString:
- {
- _out << nl << "java.lang.String " << arg << " = __is.readString();";
- break;
- }
- case Builtin::KindObject:
- {
- _out << nl << "__is.readObject(new Patcher(__r, __key));";
- break;
- }
- case Builtin::KindObjectProxy:
- {
- _out << nl << "Ice.ObjectPrx " << arg << " = __is.readProxy();";
- break;
- }
- case Builtin::KindLocalObject:
- {
- assert(false);
- break;
- }
- }
- }
- else
- {
- string s = typeToString(type, TypeModeIn, package);
- BuiltinPtr builtin2 = BuiltinPtr::dynamicCast(type);
- if((builtin2 && builtin2->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(type))
- {
- writeMarshalUnmarshalCode(_out, package, type, arg, false, iter, false, StringList(),
- "new Patcher(__r, __key)");
- }
- else
- {
- _out << nl << s << ' ' << arg << ';';
- writeMarshalUnmarshalCode(_out, package, type, arg, false, iter, false);
- }
- }
- }
- if(!(builtin && builtin->kind() == Builtin::KindObject) && !ClassDeclPtr::dynamicCast(value))
- {
- _out << nl << "__r.put(__key, __value);";
- }
- _out << eb;
- _out << nl << "return __r;";
- _out << eb;
-
- _out << eb;
-#endif
}
Slice::Gen::DelegateVisitor::DelegateVisitor(IceUtil::Output& out)
@@ -3059,7 +2757,7 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p)
}
for(q = inParams.begin(); q != inParams.end(); ++q)
{
- writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), true);
+ writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), true, false);
}
if(op->sendsClasses())
{
@@ -3097,26 +2795,7 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p)
}
for(q = outParams.begin(); q != outParams.end(); ++q)
{
- writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false);
-#if 0
- // TODO: write marshal/unmarshal code here and remove initialization
- if(isValueType(q->first))
- {
- BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->first);
- if(builtin && builtin->kind() == Builtin::KindBool)
- {
- _out << fixId(q->second) << " = false;";
- }
- else
- {
- _out << fixId(q->second) << " = 0;";
- }
- }
- else
- {
- _out << fixId(q->second) << " = null;";
- }
-#endif
+ writeMarshalUnmarshalCode(_out, q->first, fixId(q->second), false, false);
}
if(ret)
{
@@ -3129,24 +2808,7 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p)
else
{
_out << nl << retS << " __ret;";
- writeMarshalUnmarshalCode(_out, ret, "__ret", false);
-#if 0
- if(isValueType(ret))
- {
- if(builtin && builtin->kind() == Builtin::KindBool)
- {
- _out << " = false;";
- }
- else
- {
- _out << " = 0;";
- }
- }
- else
- {
- _out << " = null;";
- }
-#endif
+ writeMarshalUnmarshalCode(_out, ret, "__ret", false, false);
}
}
if(op->returnsClasses())
diff --git a/cpp/src/slice2cs/Gen.h b/cpp/src/slice2cs/Gen.h
index 1e1b1eb8cb6..3d54abd9946 100644
--- a/cpp/src/slice2cs/Gen.h
+++ b/cpp/src/slice2cs/Gen.h
@@ -43,7 +43,8 @@ public:
Gen(const std::string&,
const std::string&,
- const std::vector<std::string>&);
+ const std::vector<std::string>&,
+ const std::string&);
~Gen();
bool operator!() const; // Returns true if there was a constructor error
diff --git a/cpp/src/slice2cs/Main.cpp b/cpp/src/slice2cs/Main.cpp
index f2b644ce2ff..4ed1ce800c8 100644
--- a/cpp/src/slice2cs/Main.cpp
+++ b/cpp/src/slice2cs/Main.cpp
@@ -30,6 +30,7 @@ usage(const char* n)
"-DNAME=DEF Define NAME as DEF.\n"
"-UNAME Remove any definition for NAME.\n"
"-IDIR Put DIR in the include file search path.\n"
+ "--output-dir DIR Create files in the directory DIR.\n"
"--tie Generate TIE classes.\n"
"--impl Generate sample implementations.\n"
"--impl-tie Generate sample TIE implementations.\n"
@@ -45,6 +46,7 @@ main(int argc, char* argv[])
{
string cppArgs;
vector<string> includePaths;
+ string output;
bool tie = false;
bool impl = false;
bool implTie = false;
@@ -116,6 +118,23 @@ main(int argc, char* argv[])
}
--argc;
}
+ else if(strcmp(argv[idx], "--output-dir") == 0)
+ {
+ if(idx + 1 >= argc)
+ {
+ cerr << argv[0] << ": argument expected for`" << argv[idx]
+ << "'" << endl;
+ usage(argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ output = argv[idx + 1];
+ for(int i = idx ; i + 2 < argc ; ++i)
+ {
+ argv[i] = argv[i + 2];
+ }
+ argc -= 2;
+ }
else if(strcmp(argv[idx], "--case-sensitive") == 0)
{
caseSensitive = true;
@@ -221,7 +240,7 @@ main(int argc, char* argv[])
}
else
{
- Gen gen(argv[0], icecpp.getBaseName(), includePaths);
+ Gen gen(argv[0], icecpp.getBaseName(), includePaths, output);
if(!gen)
{
p->destroy();