diff options
author | Jose <jose@zeroc.com> | 2017-01-27 19:12:46 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2017-01-27 19:12:46 +0100 |
commit | 5a5f5676a2d4af74d213eb7835a5613538b49a7c (patch) | |
tree | cebb4145ada0c5b155df01ca9ebcd09f8d41b967 /cpp/src/slice2cs | |
parent | Fixed Python controller dispatch interfaces (diff) | |
download | ice-5a5f5676a2d4af74d213eb7835a5613538b49a7c.tar.bz2 ice-5a5f5676a2d4af74d213eb7835a5613538b49a7c.tar.xz ice-5a5f5676a2d4af74d213eb7835a5613538b49a7c.zip |
CSharp do not generate proxy for class without operations
Diffstat (limited to 'cpp/src/slice2cs')
-rw-r--r-- | cpp/src/slice2cs/CsUtil.cpp | 86 | ||||
-rw-r--r-- | cpp/src/slice2cs/Gen.cpp | 34 |
2 files changed, 85 insertions, 35 deletions
diff --git a/cpp/src/slice2cs/CsUtil.cpp b/cpp/src/slice2cs/CsUtil.cpp index f430dfd5f01..4ef46b5e2df 100644 --- a/cpp/src/slice2cs/CsUtil.cpp +++ b/cpp/src/slice2cs/CsUtil.cpp @@ -17,11 +17,9 @@ #include <sys/stat.h> #ifdef _WIN32 -#include <direct.h> -#endif - -#ifndef _WIN32 -#include <unistd.h> +# include <direct.h> +#else +# include <unistd.h> #endif using namespace std; @@ -329,7 +327,15 @@ Slice::CsGenerator::typeToString(const TypePtr& type, bool optional, bool local) ProxyPtr proxy = ProxyPtr::dynamicCast(type); if(proxy) { - return fixId(proxy->_class()->scoped() + "Prx"); + ClassDefPtr def = proxy->_class()->definition(); + if(def->isInterface() || def->allOperations().size() > 0) + { + return fixId(proxy->_class()->scoped() + "Prx"); + } + else + { + return "Ice.ObjectPrx"; + } } SequencePtr seq = SequencePtr::dynamicCast(type); @@ -655,14 +661,29 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, ProxyPtr prx = ProxyPtr::dynamicCast(type); if(prx) { - string typeS = typeToString(type); - if(marshal) + ClassDefPtr def = prx->_class()->definition(); + if(def->isInterface() || def->allOperations().size() > 0) { - out << nl << typeS << "Helper.write(" << stream << ", " << param << ");"; + string typeS = typeToString(type); + if (marshal) + { + out << nl << typeS << "Helper.write(" << stream << ", " << param << ");"; + } + else + { + out << nl << param << " = " << typeS << "Helper.read(" << stream << ");"; + } } else { - out << nl << param << " = " << typeS << "Helper.read(" << stream << ");"; + if(marshal) + { + out << nl << stream << ".writeProxy(" << param << ");"; + } + else + { + out << nl << param << " = " << stream << ".readProxy()" << ';'; + } } return; } @@ -1164,9 +1185,14 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, const string limitID = isArray ? "Length" : "Count"; BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); - if(builtin) + ProxyPtr proxy = ProxyPtr::dynamicCast(type); + ClassDefPtr def = proxy ? proxy->_class()->definition() : 0; + bool isObjectProxySeq = def && !def->isInterface() && def->allOperations().size() == 0; + Builtin::Kind kind = builtin ? builtin->kind() : Builtin::KindObjectProxy; + + if(builtin || isObjectProxySeq) { - switch(builtin->kind()) + switch(kind) { case Builtin::KindValue: case Builtin::KindObject: @@ -1201,8 +1227,8 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, << "> e = " << param << ".GetEnumerator();"; out << nl << "while(e.MoveNext())"; out << sb; - string func = (builtin->kind() == Builtin::KindObject || - builtin->kind() == Builtin::KindValue) ? "writeValue" : "writeProxy"; + string func = (kind == Builtin::KindObject || + kind == Builtin::KindValue) ? "writeValue" : "writeProxy"; out << nl << stream << '.' << func << "(e.Current);"; out << eb; } @@ -1211,8 +1237,8 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, { out << nl << "for(int ix = 0; ix < " << param << '.' << limitID << "; ++ix)"; out << sb; - string func = (builtin->kind() == Builtin::KindObject || - builtin->kind() == Builtin::KindValue) ? "writeValue" : "writeProxy"; + string func = (kind == Builtin::KindObject || + kind == Builtin::KindValue) ? "writeValue" : "writeProxy"; out << nl << stream << '.' << func << '(' << param << "[ix]);"; out << eb; } @@ -1221,9 +1247,12 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, else { out << nl << "int " << param << "_lenx = " << stream << ".readAndCheckSeqSize(" - << static_cast<unsigned>(builtin->minWireSize()) << ");"; - out << nl << param << " = new "; - if((builtin->kind() == Builtin::KindObject || builtin->kind() == Builtin::KindValue)) + << static_cast<unsigned>(type->minWireSize()) << ");"; + if(!isStack) + { + out << nl << param << " = new "; + } + if((kind == Builtin::KindObject || kind == Builtin::KindValue)) { if(isArray) { @@ -1271,7 +1300,11 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, } else { - if(isArray) + if(isStack) + { + out << nl << "Ice.ObjectPrx[] " << param << "_tmp = new Ice.ObjectPrx[" << param << "_lenx];"; + } + else if(isArray) { out << "Ice.ObjectPrx[" << param << "_lenx];"; } @@ -1288,11 +1321,13 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, { out << typeToString(seq) << "(" << param << "_lenx);"; } + out << nl << "for(int ix = 0; ix < " << param << "_lenx; ++ix)"; out << sb; - if(isArray) + if(isArray || isStack) { - out << nl << param << "[ix] = " << stream << ".readProxy();"; + string v = isArray ? param : param + "_tmp"; + out << nl << v << "[ix] = " << stream << ".readProxy();"; } else { @@ -1302,6 +1337,13 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, } } out << eb; + + if(isStack) + { + out << nl << "_System.Array.Reverse(" << param << "_tmp);"; + out << nl << param << " = new _System.Collections.Generic." << genericType << "<" << typeS << ">(" + << param << "_tmp);"; + } } break; } diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 83ba89df350..0008249211a 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -3951,7 +3951,7 @@ Slice::Gen::ProxyVisitor::visitModuleEnd(const ModulePtr&) bool Slice::Gen::ProxyVisitor::visitClassDefStart(const ClassDefPtr& p) { - if(p->isLocal()) + if(p->isLocal() || (!p->isInterface() && p->allOperations().size() == 0)) { return false; } @@ -3963,20 +3963,28 @@ Slice::Gen::ProxyVisitor::visitClassDefStart(const ClassDefPtr& p) writeDocComment(p, getDeprecateReason(p, 0, p->isInterface() ? "interface" : "class")); emitGeneratedCodeAttribute(); _out << nl << "public interface " << name << "Prx : "; - if(bases.empty()) + + vector<string> baseInterfaces; + for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q) { - _out << "Ice.ObjectPrx"; + ClassDefPtr def = *q; + if(def->isInterface() || def->allOperations().size() > 0) + { + baseInterfaces.push_back(fixId((*q)->scoped() + "Prx")); + } } - else + + if(baseInterfaces.empty()) { - ClassList::const_iterator q = bases.begin(); - while(q != bases.end()) + baseInterfaces.push_back("Ice.ObjectPrx"); + } + + for(vector<string>::const_iterator q = baseInterfaces.begin(); q != baseInterfaces.end();) + { + _out << *q; + if(++q != baseInterfaces.end()) { - _out << fixId((*q)->scoped() + "Prx"); - if(++q != bases.end()) - { - _out << ", "; - } + _out << ", "; } } _out << sb; @@ -4286,7 +4294,7 @@ Slice::Gen::HelperVisitor::visitModuleEnd(const ModulePtr&) bool Slice::Gen::HelperVisitor::visitClassDefStart(const ClassDefPtr& p) { - if(p->isLocal()) + if(p->isLocal() || (!p->isInterface() && p->allOperations().size() == 0)) { return false; } @@ -5540,7 +5548,7 @@ Slice::Gen::ImplVisitor::visitModuleEnd(const ModulePtr&) bool Slice::Gen::ImplVisitor::visitClassDefStart(const ClassDefPtr& p) { - if(!p->isAbstract()) + if(p->allOperations().size() == 0) { return false; } |