summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2003-12-05 08:28:43 +0000
committerMichi Henning <michi@zeroc.com>2003-12-05 08:28:43 +0000
commite8546c312a1ae7e9b67649dcc50dded80a7582c1 (patch)
tree499b4e8747ca04186c4e6b469e24d174eed267bd /cpp/src
parentAdded ifndef/endif guards (diff)
downloadice-e8546c312a1ae7e9b67649dcc50dded80a7582c1.tar.bz2
ice-e8546c312a1ae7e9b67649dcc50dded80a7582c1.tar.xz
ice-e8546c312a1ae7e9b67649dcc50dded80a7582c1.zip
*** empty log message ***
Diffstat (limited to 'cpp/src')
-rwxr-xr-xcpp/src/Slice/CsUtil.cpp52
-rwxr-xr-xcpp/src/slice2cs/Gen.cpp629
-rw-r--r--cpp/src/slice2cs/Gen.h26
3 files changed, 579 insertions, 128 deletions
diff --git a/cpp/src/Slice/CsUtil.cpp b/cpp/src/Slice/CsUtil.cpp
index 195fb5f43f2..ca76add0bff 100755
--- a/cpp/src/Slice/CsUtil.cpp
+++ b/cpp/src/Slice/CsUtil.cpp
@@ -104,7 +104,9 @@ splitScopedName(const string& scoped)
// but with all components that are C# keywords replaced by
// their "@"-prefixed version; otherwise, if the passed name is
// not scoped, but a C# keyword, return the "@"-prefixed name;
-// otherwise, return the name unchanged.
+// otherwise, return the name unchanged. For the first component
+// of a scoped name, also escape the reserved "Microsoft" and
+// "System" namespaces.
//
string
Slice::CsGenerator::fixKwd(const string& name)
@@ -122,21 +124,18 @@ Slice::CsGenerator::fixKwd(const string& name)
stringstream result;
for(StringList::const_iterator i = ids.begin(); i != ids.end(); ++i)
{
- if(i != ids.begin())
- {
- result << '.';
- }
- else
+ if(i == ids.begin())
{
if(*i == "Microsoft" || *i == "System")
{
- result << "_cs_" + *i;
- }
- else
- {
- result << *i;
+ result << "_cs_";
}
}
+ else
+ {
+ result << '.';
+ }
+ result << *i;
}
return result.str();
}
@@ -144,6 +143,11 @@ Slice::CsGenerator::fixKwd(const string& name)
string
Slice::CsGenerator::typeToString(const TypePtr& type)
{
+ if(!type)
+ {
+ return "void";
+ }
+
static const char* builtinTable[] =
{
"byte",
@@ -180,6 +184,32 @@ Slice::CsGenerator::typeToString(const TypePtr& type)
return "???";
}
+bool
+Slice::CsGenerator::isValueType(const TypePtr& type)
+{
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
+ if(builtin)
+ {
+ switch(builtin->kind())
+ {
+ case Builtin::KindString:
+ case Builtin::KindObject:
+ case Builtin::KindObjectProxy:
+ case Builtin::KindLocalObject:
+ {
+ return false;
+ break;
+ }
+ }
+ return true;
+ }
+ if(EnumPtr::dynamicCast(type))
+ {
+ return true;
+ }
+ return false;
+}
+
#if 0
void
diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp
index 6da20b6f61b..c480c106130 100755
--- a/cpp/src/slice2cs/Gen.cpp
+++ b/cpp/src/slice2cs/Gen.cpp
@@ -98,8 +98,12 @@ Slice::Gen::operator!() const
void
Slice::Gen::generate(const UnitPtr& p)
{
+ OpsVisitor opsVisitor(_out);
+ p->visit(&opsVisitor);
TypesVisitor typesVisitor(_out);
p->visit(&typesVisitor);
+ ProxyVisitor proxyVisitor(_out);
+ p->visit(&proxyVisitor);
}
void
@@ -125,6 +129,113 @@ Slice::Gen::printHeader()
_out << "\n// Ice version " << ICE_STRING_VERSION;
}
+Slice::Gen::OpsVisitor::OpsVisitor(IceUtil::Output& out) :
+ CsVisitor(out)
+{
+}
+
+bool
+Slice::Gen::OpsVisitor::visitModuleStart(const ModulePtr& p)
+{
+ string name = fixKwd(fixGlobal(p));
+ _out << sp << nl << "namespace " << name;
+ _out << sb;
+ _out << nl << "#region " << name << " members";
+
+ return true;
+}
+
+void
+Slice::Gen::OpsVisitor::visitModuleEnd(const ModulePtr& p)
+{
+ _out << sp << nl << "#endregion"; // module
+ _out << eb;
+}
+
+bool
+Slice::Gen::OpsVisitor::visitClassDefStart(const ClassDefPtr& p)
+{
+ //
+ // Don't generate an _Operations interface for non-abstract classes.
+ //
+ if(!p->isAbstract())
+ {
+ return false;
+ }
+
+ string name = fixKwd(fixGlobal(p));
+ string scoped = fixKwd(p->scoped());
+ ClassList bases = p->bases();
+
+ _out << sp << nl << "public interface " << name << "_Operations";
+ if((bases.size() == 1 && bases.front()->isAbstract()) || bases.size() > 1)
+ {
+ _out << " : ";
+ _out.useCurrentPosAsIndent();
+ ClassList::const_iterator q = bases.begin();
+ bool first = true;
+ while(q != bases.end())
+ {
+ if((*q)->isAbstract())
+ {
+ if(!first)
+ {
+ _out << ',' << nl;
+ }
+ else
+ {
+ first = false;
+ }
+ _out << fixKwd((*q)->scoped()) << "_Operations";
+ }
+ ++q;
+ }
+ _out.restoreIndent();
+ }
+
+ _out << sb;
+ _out << sp << nl << "#region " << name << "_Operations members";
+
+ return true;
+}
+
+void
+Slice::Gen::OpsVisitor::visitClassDefEnd(const ClassDefPtr& p)
+{
+ _out << sp << nl << "#endregion"; // _Operations members
+ _out << eb;
+}
+
+void
+Slice::Gen::OpsVisitor::visitOperation(const OperationPtr& p)
+{
+ string name = fixKwd(p->name());
+
+ _out << sp << nl << typeToString(p->returnType()) << " " << name << "(";
+ ParamDeclList paramList = p->parameters();
+ for(ParamDeclList::const_iterator q = paramList.begin(); q != paramList.end(); ++q)
+ {
+ if(q != paramList.begin())
+ {
+ _out << ", ";
+ }
+ if((*q)->isOutParam())
+ {
+ _out << "ref ";
+ }
+ _out << typeToString((*q)->type()) << " " << fixKwd((*q)->name());
+ }
+ if(!ClassDefPtr::dynamicCast(p->container())->isLocal())
+ {
+ if(!paramList.empty())
+ {
+ _out << ", ";
+ }
+ _out << "Ice.Current __current";
+ }
+ _out << ");";
+}
+
Slice::Gen::TypesVisitor::TypesVisitor(IceUtil::Output& out) :
CsVisitor(out)
{
@@ -155,15 +266,11 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p)
string scoped = fixKwd(p->scoped());
ClassList bases = p->bases();
- _out << sp << nl << "public ";
- if(p->isAbstract())
- {
- _out << "abstract ";
- }
- _out << "class " << name << " : ";
- if(bases.empty())
+ if(p->isInterface())
{
- if(p->isLocal())
+ _out << sp << nl << "public interface " << name << " : ";
+ _out.useCurrentPosAsIndent();
+ if(p->isLocal())
{
_out << "Ice.LocalObject";
}
@@ -171,24 +278,58 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p)
{
_out << "Ice.Object";
}
+ _out << ',' << nl << name << "_Operations";
+ if(bases.empty())
+ {
+ ClassList::const_iterator q = bases.begin();
+ while(q != bases.end())
+ {
+ _out << ',' << nl << fixKwd((*q)->scoped());
+ }
+ }
+ _out.restoreIndent();
}
else
{
- ClassList::const_iterator q = bases.begin();
- while(q != bases.end())
+ _out << sp << nl << "public ";
+ if(p->isAbstract())
{
- _out << fixKwd((*q)->scoped());
- if(++q != bases.end())
+ _out << "abstract ";
+ }
+ _out << "class " << name << " : ";
+
+ _out.useCurrentPosAsIndent();
+ if(bases.empty() || bases.front()->isInterface())
+ {
+ if(p->isLocal())
+ {
+ _out << "Ice.LocalObjectImpl";
+ }
+ else
{
- _out << ',' << nl;
+ _out << "Ice.ObjectImpl";
}
}
+ else
+ {
+ _out << fixKwd(bases.front()->scoped());
+ bases.pop_front();
+ }
+ _out << ',' << nl << name << "_Operations";
+ for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q)
+ {
+ _out << ',' << nl << fixKwd((*q)->scoped()) << "_Operations";
+ }
+ _out.restoreIndent();
}
- _out << sb;
- _out << sp << nl << "#region " << name << " members";
+ _out << sb;
- _out << sp << nl << "#region Slice data members and operations";
+ if(!p->isInterface())
+ {
+ _out << sp << nl << "#region " << name << " members";
+ _out << sp << nl << "#region Slice data members and operations";
+ }
return true;
}
@@ -198,112 +339,183 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p)
{
string name = fixKwd(fixGlobal(p));
string scoped = fixKwd(p->scoped());
- ClassList bases = p->bases();
DataMemberList dataMembers = p->dataMembers();
DataMemberList::const_iterator q;
- _out << sp << nl << "#endregion"; // Slice data members and operations
- _out << sp << nl << "#region IComparable members";
-
- _out << sp << nl << "public override int CompareTo(object __other)";
- _out << sb;
- _out << nl << "if(__other == null)";
- _out << sb;
- _out << nl << "return 1;";
- _out << eb;
- _out << nl << "if(object.ReferenceEquals(this, __other))";
- _out << sb;
- _out << nl << "return 0;";
- _out << eb;
- _out << nl << "if(!(__other is " << name << "))";
- _out << sb;
- _out << nl << "throw new System.ArgumentException(\"expected argument of type `" << name << "'\", \"__other\");";
- _out << eb;
- _out << nl << "int __ret = base.CompareTo(__other);";
- _out << nl << "if(__ret != 0)";
- _out << sb;
- _out << nl << "return __ret;";
- _out << eb;
- for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
+ if(!p->isInterface())
{
- string memberName = fixKwd((*q)->name());
- _out << nl << "if((object)" << memberName << " == null && __other != null)";
+ _out << sp << nl << "#endregion"; // Slice data members and operations
+
+ ClassList bases = p->bases();
+ if(!bases.empty() && !bases.front()->isInterface())
+ {
+ bases.pop_front();
+ }
+ if(!bases.empty())
+ {
+ _out << sp << nl << "#region Inherited Slice operations";
+
+ OperationList allOps;
+ for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q)
+ {
+ OperationList tmp = (*q)->allOperations();
+ allOps.splice(allOps.end(), tmp);
+ }
+ allOps.sort();
+ allOps.unique();
+ for(OperationList::const_iterator op = allOps.begin(); op != allOps.end(); ++op)
+ {
+ string name = fixKwd((*op)->name());
+ string scoped = fixKwd((*op)->scoped());
+
+ _out << sp << nl << "public abstract " << typeToString((*op)->returnType()) << " " << name << "(";
+ ParamDeclList paramList = (*op)->parameters();
+ for(ParamDeclList::const_iterator q = paramList.begin(); q != paramList.end(); ++q)
+ {
+ if(q != paramList.begin())
+ {
+ _out << ", ";
+ }
+ if((*q)->isOutParam())
+ {
+ _out << "ref ";
+ }
+ _out << typeToString((*q)->type()) << " " << fixKwd((*q)->name());
+ }
+ if(!p->isLocal())
+ {
+ if(!paramList.empty())
+ {
+ _out << ", ";
+ }
+ _out << "Ice.Current __current";
+ }
+ _out << ");";
+ }
+
+ _out << sp << nl << "#endregion"; // Inherited Slice operations
+ }
+
+ _out << sp << nl << "#region IComparable members";
+
+ _out << sp << nl << "public override int CompareTo(object __other)";
_out << sb;
- _out << nl << "return -1;";
+ _out << nl << "if(__other == null)";
+ _out << sb;
+ _out << nl << "return 1;";
_out << eb;
- _out << nl << "if((__ret = " << memberName << ".CompareTo(((" << name << ")__other)."
- << memberName << ")) != 0)";
+ _out << nl << "if(object.ReferenceEquals(this, __other))";
+ _out << sb;
+ _out << nl << "return 0;";
+ _out << eb;
+ _out << nl << "if(!(__other is " << name << "))";
+ _out << sb;
+ _out << nl << "throw new System.ArgumentException(\"expected argument of type `"
+ << name << "'\", \"__other\");";
+ _out << eb;
+ _out << nl << "int __ret = base.CompareTo(__other);";
+ _out << nl << "if(__ret != 0)";
_out << sb;
_out << nl << "return __ret;";
_out << eb;
- }
- _out << nl << "return 0;";
+ for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
+ {
+ string memberName = fixKwd((*q)->name());
+ if(!isValueType((*q)->type()))
+ {
+ _out << nl << "if(" << memberName << " == null && ((" << name << ")__other)."
+ << memberName << " != null)";
+ _out << sb;
+ _out << nl << "return -1;";
+ _out << eb;
+ }
+ _out << nl << "if((__ret = " << memberName << ".CompareTo(((" << name << ")__other)."
+ << memberName << ")) != 0)";
+ _out << sb;
+ _out << nl << "return __ret;";
+ _out << eb;
+ }
+ _out << nl << "return 0;";
- _out << eb;
+ _out << eb;
- _out << sp << nl << "#endregion"; // IComparable members
+ _out << sp << nl << "#endregion"; // IComparable members
- _out << sp << nl << "#region Comparison operators";
+ _out << sp << nl << "#region Comparison operators";
- _out << sp << nl << "public static bool operator==(" << name << " __lhs, " << name << " __rhs)";
- _out << sb;
- _out << nl << "return Equals(__lhs, __rhs);";
- _out << eb;
+ _out << sp << nl << "public static bool operator==(" << name << " __lhs, " << name << " __rhs)";
+ _out << sb;
+ _out << nl << "return Equals(__lhs, __rhs);";
+ _out << eb;
- _out << sp << nl << "public static bool operator!=(" << name << " __lhs, " << name << " __rhs)";
- _out << sb;
- _out << nl << "return !Equals(__lhs, __rhs);";
- _out << eb;
+ _out << sp << nl << "public static bool operator!=(" << name << " __lhs, " << name << " __rhs)";
+ _out << sb;
+ _out << nl << "return !Equals(__lhs, __rhs);";
+ _out << eb;
- _out << sp << nl << "public static bool operator<(" << name << " __lhs, " << name << " __rhs)";
- _out << sb;
- _out << nl << "return __lhs == null ? __rhs != null : __lhs.CompareTo(__rhs) < 0;";
- _out << eb;
+ _out << sp << nl << "public static bool operator<(" << name << " __lhs, " << name << " __rhs)";
+ _out << sb;
+ _out << nl << "return __lhs == null ? __rhs != null : __lhs.CompareTo(__rhs) < 0;";
+ _out << eb;
- _out << sp << nl << "public static bool operator>(" << name << " __lhs, " << name << " __rhs)";
- _out << sb;
- _out << nl << "return __lhs == null ? false : __lhs.CompareTo(__rhs) > 0;";
- _out << eb;
+ _out << sp << nl << "public static bool operator>(" << name << " __lhs, " << name << " __rhs)";
+ _out << sb;
+ _out << nl << "return __lhs == null ? false : __lhs.CompareTo(__rhs) > 0;";
+ _out << eb;
- _out << sp << nl << "public static bool operator<=(" << name << " __lhs, " << name << " __rhs)";
- _out << sb;
- _out << nl << "return __lhs == null ? true : __lhs.CompareTo(__rhs) <= 0;";
- _out << eb;
+ _out << sp << nl << "public static bool operator<=(" << name << " __lhs, " << name << " __rhs)";
+ _out << sb;
+ _out << nl << "return __lhs == null ? true : __lhs.CompareTo(__rhs) <= 0;";
+ _out << eb;
- _out << sp << nl << "public static bool operator>=(" << name << " __lhs, " << name << " __rhs)";
- _out << sb;
- _out << nl << "return __lhs == null ? __rhs == null : __lhs.CompareTo(__rhs) >= 0;";
- _out << eb;
+ _out << sp << nl << "public static bool operator>=(" << name << " __lhs, " << name << " __rhs)";
+ _out << sb;
+ _out << nl << "return __lhs == null ? __rhs == null : __lhs.CompareTo(__rhs) >= 0;";
+ _out << eb;
- _out << sp << nl << "#endregion"; // Comparison operators
+ _out << sp << nl << "#endregion"; // Comparison operators
- _out << sp << nl << "#region Object members";
+ _out << sp << nl << "#region Object members";
- _out << sp << nl << "public override int GetHashCode()";
- _out << sb;
- _out << nl << "int __h = 0;";
- for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
- {
- string memberName = fixKwd((*q)->name());
- _out << nl << "__h = (__h << 5) ^ " << memberName << ".GetHashCode();";
- }
- _out << nl << "return __h;";
- _out << eb;
+ _out << sp << nl << "public override int GetHashCode()";
+ _out << sb;
+ _out << nl << "int __h = 0;";
+ for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
+ {
+ string memberName = fixKwd((*q)->name());
+ bool isValue = isValueType((*q)->type());
+ if(!isValue)
+ {
+ _out << nl << "if(" << memberName << " != null)";
+ _out << sb;
+ }
+ _out << nl << "__h = (__h << 3) ^ " << memberName << ".GetHashCode();";
+ if(!isValue)
+ {
+ _out << eb;
+ }
+ }
+ _out << nl << "return __h;";
+ _out << eb;
- _out << sp << nl << "public override bool Equals(object other)";
- _out << sb;
- _out << nl << "return CompareTo(other) == 0;";
- _out << eb;
+ _out << sp << nl << "public override bool Equals(object other)";
+ _out << sb;
+ _out << nl << "return CompareTo(other) == 0;";
+ _out << eb;
- _out << sp << nl << "public static bool Equals(" << name << " __lhs, " << name << " __rhs)";
- _out << sb;
- _out << nl << "return __lhs == null ? __rhs == null : __lhs.CompareTo(__rhs) == 0;";
- _out << eb;
+ _out << sp << nl << "public static bool Equals(" << name << " __lhs, " << name << " __rhs)";
+ _out << sb;
+ _out << nl << "return __lhs == null ? __rhs == null : __lhs.CompareTo(__rhs) == 0;";
+ _out << eb;
- _out << sp << nl << "#endregion"; // Object members
+ _out << sp << nl << "#endregion"; // Object members
+ }
- _out << sp << nl << "#endregion"; // class
+ if(!p->isInterface())
+ {
+ _out << sp << nl << "#endregion"; // class
+ }
_out << eb;
}
@@ -311,8 +523,12 @@ Slice::Gen::TypesVisitor::visitClassDefEnd(const ClassDefPtr& p)
void
Slice::Gen::TypesVisitor::visitOperation(const OperationPtr& p)
{
+ if(ClassDefPtr::dynamicCast(p->container())->isInterface())
+ {
+ return;
+ }
+
string name = fixKwd(p->name());
- string scoped = fixKwd(p->scoped());
_out << sp << nl << "public abstract " << typeToString(p->returnType()) << " " << name << "(";
ParamDeclList paramList = p->parameters();
@@ -328,6 +544,14 @@ Slice::Gen::TypesVisitor::visitOperation(const OperationPtr& p)
}
_out << typeToString((*q)->type()) << " " << fixKwd((*q)->name());
}
+ if(!ClassDefPtr::dynamicCast(p->container())->isLocal())
+ {
+ if(!paramList.empty())
+ {
+ _out << ", ";
+ }
+ _out << "Ice.Current __current";
+ }
_out << ");";
}
@@ -336,6 +560,7 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p)
{
string name = fixKwd(fixGlobal(p));
string s = typeToString(p->type());
+ bool isValue = isValueType(p->type());
_out << sp << nl << "public class " << name
<< " : System.Collections.CollectionBase, System.IComparable";
@@ -409,10 +634,13 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p)
_out << nl << "int __limit = System.Math.Min(this.Count, ((" << name << ")__other).Count);";
_out << nl << "for(int __i = 0; __i < __limit; ++__i)";
_out << sb;
- _out << nl << "if((object)this[__i] == null && (object)((" << name << ")__other)[__i] != null)";
- _out << sb;
- _out << nl << "return -1;";
- _out << eb;
+ if(!isValue)
+ {
+ _out << nl << "if(this[__i] == null && ((" << name << ")__other)[__i] != null)";
+ _out << sb;
+ _out << nl << "return -1;";
+ _out << eb;
+ }
_out << nl << "int __ret = this[__i].CompareTo(((" << name << ")__other)[__i]);";
_out << nl << "if(__ret != 0)";
_out << sb;
@@ -466,19 +694,32 @@ Slice::Gen::TypesVisitor::visitSequence(const SequencePtr& p)
_out << nl << "int hash = 0;";
_out << nl << "for(int i = 0; i < Count; ++i)";
_out << sb;
- _out << nl << "hash = (hash << 5) ^ this[i].GetHashCode();";
+ if(!isValue)
+ {
+ _out << nl << "if((object)this[i] != null)";
+ _out << sb;
+ }
+ _out << nl << "hash = (hash << 3) ^ this[i].GetHashCode();";
+ if(!isValue)
+ {
+ _out << eb;
+ }
_out << eb;
_out << nl << "return hash;";
_out << eb;
_out << sp << nl << "public override bool Equals(object other)";
_out << sb;
+ _out << nl << "if(Count != ((" << name << ")other).Count)";
+ _out << sb;
+ _out << nl << "return false;";
+ _out << eb;
_out << nl << "return CompareTo(other) == 0;";
_out << eb;
_out << sp << nl << "public static bool Equals(" << name << " __lhs, " << name << " __rhs)";
_out << sb;
- _out << nl << "return __lhs == null ? __rhs == null : __lhs.CompareTo(__rhs) == 0;";
+ _out << nl << "return __lhs == null ? __rhs == null : __lhs.Equals(__rhs);";
_out << eb;
_out << sp << nl << "#endregion"; // Object members
@@ -561,7 +802,17 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
string memberName = fixKwd((*q)->name());
- _out << nl << "__h = (__h << 5) ^ " << memberName << ".GetHashCode();";
+ bool isValue = isValueType((*q)->type());
+ if(!isValue)
+ {
+ _out << nl << "if((object)" << memberName << " != null)";
+ _out << sb;
+ }
+ _out << nl << "__h = (__h << 3) ^ " << memberName << ".GetHashCode();";
+ if(!isValue)
+ {
+ _out << eb;
+ }
}
_out << nl << "return __h;";
_out << eb;
@@ -583,7 +834,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
string memberName = fixKwd((*q)->name());
- _out << nl << "if(this." << memberName << " != ((" << name << ")__other)." << memberName << ")";
+ _out << nl << "if(!" << memberName << ".Equals(((" << name << ")__other)." << memberName << "))";
_out << sb;
_out << nl << "return false;";
_out << eb;
@@ -648,10 +899,13 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p)
for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
string memberName = fixKwd((*q)->name());
- _out << nl << "if((object)" << memberName << " == null && __other != null)";
- _out << sb;
- _out << nl << "return -1;";
- _out << eb;
+ if(!isValueType((*q)->type()))
+ {
+ _out << nl << "if(" << memberName << " == null && ((" << name << ")__other)." << memberName << " != null)";
+ _out << sb;
+ _out << nl << "return -1;";
+ _out << eb;
+ }
_out << nl << "if((__ret = " << memberName << ".CompareTo(((" << name << ")__other)."
<< memberName << ")) != 0)";
_out << sb;
@@ -705,7 +959,17 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p)
for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
{
string memberName = fixKwd((*q)->name());
- _out << nl << "__h = (__h << 5) ^ " << memberName << ".GetHashCode();";
+ bool isValue = isValueType((*q)->type());
+ if(!isValue)
+ {
+ _out << nl << "if(" << memberName << " != null)";
+ _out << sb;
+ }
+ _out << nl << "__h = (__h << 3) ^ " << memberName << ".GetHashCode();";
+ if(!isValue)
+ {
+ _out << eb;
+ }
}
_out << nl << "return __h;";
_out << eb;
@@ -733,6 +997,7 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
string name = fixKwd(fixGlobal(p));
string ks = typeToString(p->keyType());
string vs = typeToString(p->valueType());
+ bool valueIsValue = isValueType(p->valueType());
_out << sp << nl << "public class " << name
<< " : System.Collections.DictionaryBase, System.IComparable";
@@ -836,10 +1101,13 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
_out << nl << "System.Array.Sort(__vrhs);";
_out << nl << "for(int i = 0; i < __limit; ++i)";
_out << sb;
- _out << nl << "if((object)__vlhs[i] == null && (object)__vrhs[i] != null)";
- _out << sb;
- _out << nl << "return -1;";
- _out << eb;
+ if(!valueIsValue)
+ {
+ _out << nl << "if(__vlhs[i] == null && __vrhs[i] != null)";
+ _out << sb;
+ _out << nl << "return -1;";
+ _out << eb;
+ }
_out << nl << "int ret = __vlhs[i].CompareTo(__vrhs[i]);";
_out << nl << "if(ret != 0)";
_out << sb;
@@ -892,20 +1160,33 @@ Slice::Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
_out << nl << "int hash = 0;";
_out << nl << "foreach(System.Collections.DictionaryEntry e in Dictionary)";
_out << sb;
- _out << nl << "hash = (hash << 5) ^ e.Key.GetHashCode();";
- _out << nl << "hash = (hash << 5) ^ e.Value.GetHashCode();";
+ _out << nl << "hash = (hash << 3) ^ e.Key.GetHashCode();";
+ if(!valueIsValue)
+ {
+ _out << nl << "if(e.Value != null)";
+ _out << sb;
+ }
+ _out << nl << "hash = (hash << 3) ^ e.Value.GetHashCode();";
+ if(!valueIsValue)
+ {
+ _out << eb;
+ }
_out << eb;
_out << nl << "return hash;";
_out << eb;
_out << sp << nl << "public override bool Equals(object other)";
_out << sb;
+ _out << nl << "if(Count != ((" << name << ")other).Count)";
+ _out << sb;
+ _out << nl << "return false;";
+ _out << eb;
_out << nl << "return CompareTo(other) == 0;";
_out << eb;
_out << sp << nl << "public static bool Equals(" << name << " __lhs, " << name << " __rhs)";
_out << sb;
- _out << nl << "return __lhs == null ? __rhs == null : __lhs.CompareTo(__rhs) == 0;";
+ _out << nl << "return __lhs == null ? __rhs == null : __lhs.Equals(__rhs);";
_out << eb;
_out << sp << nl << "#endregion"; // Object members
@@ -1013,3 +1294,117 @@ Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p)
{
_out << sp << nl << "public " << typeToString(p->type()) << " " << fixKwd(p->name()) << ";";
}
+
+Slice::Gen::ProxyVisitor::ProxyVisitor(IceUtil::Output& out) :
+ CsVisitor(out)
+{
+}
+
+bool
+Slice::Gen::ProxyVisitor::visitModuleStart(const ModulePtr& p)
+{
+ string name = fixKwd(fixGlobal(p));
+ _out << sp << nl << "namespace " << name;
+ _out << sb;
+ _out << nl << "#region " << name << " members";
+
+ return true;
+}
+
+void
+Slice::Gen::ProxyVisitor::visitModuleEnd(const ModulePtr& p)
+{
+ _out << sp << nl << "#endregion"; // module
+ _out << eb;
+}
+
+bool
+Slice::Gen::ProxyVisitor::visitClassDefStart(const ClassDefPtr& p)
+{
+ if(p->isLocal())
+ {
+ return false;
+ }
+
+ string name = fixKwd(fixGlobal(p));
+ string scoped = fixKwd(p->scoped());
+ ClassList bases = p->bases();
+
+ _out << sp << nl << "public interface " << name << "Prx : ";
+ if(bases.empty())
+ {
+ _out << "Ice.ObjectPrx";
+ }
+ else
+ {
+ _out.useCurrentPosAsIndent();
+ ClassList::const_iterator q = bases.begin();
+ while(q != bases.end())
+ {
+ _out << fixKwd((*q)->scoped()) << "Prx";
+ if(++q != bases.end())
+ {
+ _out << ',' << nl;
+ }
+ }
+ _out.restoreIndent();
+ }
+
+ _out << sb;
+
+ _out << sp << nl << "#region " << name << "Prx members";
+
+ return true;
+}
+
+void
+Slice::Gen::ProxyVisitor::visitClassDefEnd(const ClassDefPtr& p)
+{
+
+ _out << sp << nl << "#endregion"; // Prx members
+
+ _out << eb;
+}
+
+void
+Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
+{
+ string name = fixKwd(p->name());
+ ParamDeclList paramList = p->parameters();
+ ParamDeclList::const_iterator q;
+
+ _out << sp << nl << typeToString(p->returnType()) << " " << name << "(";
+ for(q = paramList.begin(); q != paramList.end(); ++q)
+ {
+ if(q != paramList.begin())
+ {
+ _out << ", ";
+ }
+ if((*q)->isOutParam())
+ {
+ _out << "ref ";
+ }
+ _out << typeToString((*q)->type()) << " " << fixKwd((*q)->name());
+ }
+ _out << ");";
+
+ _out << nl << typeToString(p->returnType()) << " " << name << "(";
+ for(q = paramList.begin(); q != paramList.end(); ++q)
+ {
+ if(q != paramList.begin())
+ {
+ _out << ", ";
+ }
+ if((*q)->isOutParam())
+ {
+ _out << "ref ";
+ }
+ _out << typeToString((*q)->type()) << " " << fixKwd((*q)->name());
+ }
+ if(!paramList.empty())
+ {
+ _out << ", ";
+ }
+ _out << "System.Collections.Hashtable __context";
+ _out << ");";
+}
diff --git a/cpp/src/slice2cs/Gen.h b/cpp/src/slice2cs/Gen.h
index dcc3bc59685..888edc9badb 100644
--- a/cpp/src/slice2cs/Gen.h
+++ b/cpp/src/slice2cs/Gen.h
@@ -54,6 +54,19 @@ private:
void printHeader();
+ class OpsVisitor : public CsVisitor
+ {
+ public:
+
+ OpsVisitor(::IceUtil::Output&);
+
+ virtual bool visitModuleStart(const ModulePtr&);
+ virtual void visitModuleEnd(const ModulePtr&);
+ virtual bool visitClassDefStart(const ClassDefPtr&);
+ virtual void visitClassDefEnd(const ClassDefPtr&);
+ virtual void visitOperation(const OperationPtr&);
+ };
+
class TypesVisitor : public CsVisitor
{
public:
@@ -75,6 +88,19 @@ private:
virtual void visitConst(const ConstPtr&);
virtual void visitDataMember(const DataMemberPtr&);
};
+
+ class ProxyVisitor : public CsVisitor
+ {
+ public:
+
+ ProxyVisitor(::IceUtil::Output&);
+
+ virtual bool visitModuleStart(const ModulePtr&);
+ virtual void visitModuleEnd(const ModulePtr&);
+ virtual bool visitClassDefStart(const ClassDefPtr&);
+ virtual void visitClassDefEnd(const ClassDefPtr&);
+ virtual void visitOperation(const OperationPtr&);
+ };
};
}