diff options
Diffstat (limited to 'cpp/src')
-rwxr-xr-x | cpp/src/slice2cs/Gen.cpp | 350 | ||||
-rw-r--r-- | cpp/src/slice2cs/Gen.h | 26 | ||||
-rw-r--r-- | cpp/src/slice2cs/Main.cpp | 2 |
3 files changed, 332 insertions, 46 deletions
diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 8685aef385e..1670cce9052 100755 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -764,7 +764,7 @@ Slice::Gen::Gen(const string& name, const string& base, const vector<string>& in else { file = dir + slash + file; - file = dir + slash + fileImpl; + fileImpl = dir + slash + fileImpl; } } _out.open(file.c_str()); @@ -850,6 +850,13 @@ Slice::Gen::generate(const UnitPtr& p) } void +Slice::Gen::generateTie(const UnitPtr& p) +{ + TieVisitor tieVisitor(_out); + p->visit(&tieVisitor); +} + +void Slice::Gen::generateImpl(const UnitPtr& p) { ImplVisitor implVisitor(_impl); @@ -919,7 +926,7 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) { _out << "Ice.Object"; } - _out << ", " << name << "_Operations"; + _out << ", " << name << "_Operations, " << name << "_OperationsNC"; if(!bases.empty()) { ClassList::const_iterator q = bases.begin(); @@ -957,13 +964,13 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) } if(p->isAbstract()) { - _out << ", " << name << "_Operations"; + _out << ", " << name << "_Operations, " << name << "_OperationsNC"; } for(ClassList::const_iterator q = bases.begin(); q != bases.end(); ++q) { if((*q)->isAbstract()) { - _out << ',' << fixId((*q)->scoped()); + _out << ", " << fixId((*q)->scoped()); } } } @@ -2344,7 +2351,7 @@ Slice::Gen::ProxyVisitor::visitClassDefStart(const ClassDefPtr& p) _out << fixId((*q)->scoped()) << "Prx"; if(++q != bases.end()) { - _out << ',' << nl; + _out << ", "; } } } @@ -2404,18 +2411,32 @@ bool Slice::Gen::OpsVisitor::visitClassDefStart(const ClassDefPtr& p) { // - // Don't generate an Operations interface for non-abstract classes. + // Don't generate Operations interfaces for non-abstract classes. // if(!p->isAbstract()) { return false; } + writeOperations(p, false); + writeOperations(p, true); + + return false; +} + +void +Slice::Gen::OpsVisitor::writeOperations(const ClassDefPtr& p, bool noCurrent) +{ string name = fixId(p->name()); string scoped = fixId(p->scoped()); ClassList bases = p->bases(); + _out << sp << nl << "public interface " << name << "_Operations"; + if(noCurrent) + { + _out << "NC"; + } if((bases.size() == 1 && bases.front()->isAbstract()) || bases.size() > 1) { _out << " : "; @@ -2427,60 +2448,66 @@ Slice::Gen::OpsVisitor::visitClassDefStart(const ClassDefPtr& p) { if(!first) { - _out << ',' << nl; + _out << ", "; } else { first = false; } _out << fixId((*q)->scoped()) << "_Operations"; + if(noCurrent) + { + _out << "NC"; + } } ++q; } } - _out << sb; - return true; -} + OperationList ops = p->operations(); + OperationList::const_iterator r; + for(r = ops.begin(); r != ops.end(); ++r) + { + OperationPtr op = *r; + string name = fixId(op->name()); -void -Slice::Gen::OpsVisitor::visitClassDefEnd(const ClassDefPtr&) -{ - _out << eb; -} + TypePtr ret; + vector<string> params; -void -Slice::Gen::OpsVisitor::visitOperation(const OperationPtr& p) -{ - string name = fixId(p->name()); - ContainerPtr container = p->container(); - ClassDefPtr cl = ClassDefPtr::dynamicCast(container); + bool amd = !p->isLocal() && (p->hasMetaData("amd") || op->hasMetaData("amd")); - TypePtr ret; - vector<string> params; + if(amd) + { + params = getParamsAsync(op, true); + } + else + { + params = getParams(op); + ret = op->returnType(); + } - bool amd = !cl->isLocal() && (cl->hasMetaData("amd") || p->hasMetaData("amd")); + string retS = typeToString(ret); - if(amd) - { - params = getParamsAsync(p, true); - } - else - { - params = getParams(p); - ret = p->returnType(); + if(!noCurrent) + { + _out << sp << nl << retS << ' ' << name << (amd ? "_async" : "") << spar << params; + if(!p->isLocal()) + { + _out << "Ice.Current __current"; + } + _out << epar << ';'; + } + else + { + if(!p->isLocal()) + { + _out << sp << nl << retS << ' ' << name << (amd ? "_async" : "") << spar << params << epar << ';'; + } + } } - string retS = typeToString(ret); - - _out << sp << nl << retS << ' ' << name << (amd ? "_async" : "") << spar << params << epar << ';'; - - if(!cl->isLocal()) - { - _out << sp << nl << retS << ' ' << name << (amd ? "_async" : "") - << spar << params << "Ice.Current __current" << epar << ';'; - } + _out << eb; } Slice::Gen::HelperVisitor::HelperVisitor(IceUtil::Output& out) @@ -2901,7 +2928,7 @@ Slice::Gen::DelegateVisitor::visitClassDefStart(const ClassDefPtr& p) _out << fixId((*q)->scoped()) << "_Del"; if(++q != bases.end()) { - _out << ',' << nl; + _out << ", "; } } } @@ -3673,12 +3700,251 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) } } +Slice::Gen::TieVisitor::TieVisitor(IceUtil::Output& out) + : CsVisitor(out) +{ +} + +bool +Slice::Gen::TieVisitor::visitModuleStart(const ModulePtr& p) +{ + if(!p->hasClassDefs()) + { + return false; + } + + _out << sp << nl << "namespace " << fixId(p->name()); + _out << sb; + + return true; +} + +void +Slice::Gen::TieVisitor::visitModuleEnd(const ModulePtr&) +{ + _out << eb; +} + Slice::Gen::ImplVisitor::ImplVisitor(IceUtil::Output& out) : CsVisitor(out) { } bool +Slice::Gen::TieVisitor::visitClassDefStart(const ClassDefPtr& p) +{ + if(!p->isAbstract()) + { + return false; + } + + string name = fixId(p->name()); + + _out << sp << nl << "public class " << name << "_Tie : "; + if(p->isInterface()) + { + if(p->isLocal()) + { + _out << name; + } + else + { + _out << name << "_Disp"; + } + } + else + { + _out << name; + } + _out << sb; + + _out << sp << nl << "public " << name << "_Tie()"; + _out << sb; + _out << eb; + + _out << sp << nl << "public " << name << "_Tie(" << name << "_Operations del)"; + _out << sb; + _out << nl << "_ice_delegate = del;"; + _out << eb; + + _out << sp << nl << "public " << name << "_Operations ice_delegate()"; + _out << sb; + _out << nl << "return _ice_delegate;"; + _out << eb; + + _out << sp << nl << "public "; + if(!p->isInterface() || !p->isLocal()) + { + _out << "override "; + } + _out << "int ice_hash()"; + + _out << sb; + _out << nl << "return GetHashCode();"; + _out << eb; + + _out << sp << nl << "public override int GetHashCode()"; + _out << sb; + _out << nl << "return _ice_delegate == null ? 0 : _ice_delegate.GetHashCode();"; + _out << eb; + + _out << sp << nl << "public override bool Equals(object rhs)"; + _out << sb; + _out << nl << "if(object.ReferenceEquals(this, rhs))"; + _out << sb; + _out << nl << "return true;"; + _out << eb; + _out << nl << "if(!(rhs is " << name << "_Tie))"; + _out << sb; + _out << nl << "return false;"; + _out << eb; + _out << nl << "if(_ice_delegate == null)"; + _out << sb; + _out << nl << "return ((" << name << "_Tie)rhs)._ice_delegate == null;"; + _out << eb; + _out << nl << "return _ice_delegate.Equals(((" << name << "_Tie)rhs)._ice_delegate);"; + _out << eb; + + OperationList ops = p->operations(); + OperationList::const_iterator r; + for(r = ops.begin(); r != ops.end(); ++r) + { + bool hasAMD = p->hasMetaData("amd") || (*r)->hasMetaData("amd"); + string opName = fixId((*r)->name()); + if(hasAMD) + { + opName += "_async"; + } + + TypePtr ret = (*r)->returnType(); + string retS = typeToString(ret); + + vector<string> params; + vector<string> args; + if(hasAMD) + { + params = getParamsAsync((*r), true); + args = getArgsAsync(*r); + } + else + { + params = getParams((*r)); + args = getArgs(*r); + } + + _out << sp << nl << "public "; + if(!p->isInterface() || !p->isLocal()) + { + _out << "override "; + } + _out << (hasAMD ? "void" : retS) << ' ' << opName << spar << params; + if(!p->isLocal()) + { + _out << "Ice.Current __current"; + } + _out << epar; + _out << sb; + _out << nl; + if(ret && !hasAMD) + { + _out << "return "; + } + _out << "_ice_delegate." << opName << spar << args; + if(!p->isLocal()) + { + _out << "__current"; + } + _out << epar << ';'; + _out << eb; + } + + NameSet opNames; + ClassList bases = p->bases(); + for(ClassList::const_iterator i = bases.begin(); i != bases.end(); ++i) + { + writeInheritedOperations(*i, opNames); + } + + _out << sp << nl << "private " << name << "_Operations _ice_delegate;"; + + return true; +} + +void +Slice::Gen::TieVisitor::visitClassDefEnd(const ClassDefPtr&) +{ + _out << eb; +} + +void +Slice::Gen::TieVisitor::writeInheritedOperations(const ClassDefPtr& p, NameSet& opNames) +{ + OperationList ops = p->operations(); + OperationList::const_iterator r; + for(r = ops.begin(); r != ops.end(); ++r) + { + bool hasAMD = p->hasMetaData("amd") || (*r)->hasMetaData("amd"); + string opName = fixId((*r)->name()); + if(hasAMD) + { + opName += "_async"; + } + if(opNames.find(opName) != opNames.end()) + { + continue; + } + opNames.insert(opName); + + TypePtr ret = (*r)->returnType(); + string retS = typeToString(ret); + + vector<string> params; + vector<string> args; + if(hasAMD) + { + params = getParamsAsync((*r), true); + args = getArgsAsync(*r); + } + else + { + params = getParams((*r)); + args = getArgs(*r); + } + + _out << sp << nl << "public "; + if(!p->isInterface() || !p->isLocal()) + { + _out << "override "; + } + _out << (hasAMD ? "void" : retS) << ' ' << opName << spar << params; + if(!p->isLocal()) + { + _out << "Ice.Current __current"; + } + _out << epar; + _out << sb; + _out << nl; + if(ret && !hasAMD) + { + _out << "return "; + } + _out << "_ice_delegate." << opName << spar << args; + if(!p->isLocal()) + { + _out << "__current"; + } + _out << epar << ';'; + _out << eb; + } + + ClassList bases = p->bases(); + for(ClassList::const_iterator i = bases.begin(); i != bases.end(); ++i) + { + writeInheritedOperations(*i, opNames); + } +} + +bool Slice::Gen::ImplVisitor::visitModuleStart(const ModulePtr& p) { if(!p->hasClassDefs()) diff --git a/cpp/src/slice2cs/Gen.h b/cpp/src/slice2cs/Gen.h index b765bb2de67..756ea88f83c 100644 --- a/cpp/src/slice2cs/Gen.h +++ b/cpp/src/slice2cs/Gen.h @@ -50,6 +50,7 @@ public: bool operator!() const; // Returns true if there was a constructor error void generate(const UnitPtr&); + void generateTie(const UnitPtr&); void generateImpl(const UnitPtr&); private: @@ -106,8 +107,9 @@ private: 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&); + + private: + void writeOperations(const ClassDefPtr&, bool); }; class HelperVisitor : public CsVisitor @@ -184,6 +186,23 @@ private: virtual void visitOperation(const OperationPtr&); }; + class TieVisitor : public CsVisitor + { + public: + + TieVisitor(::IceUtil::Output&); + + virtual bool visitModuleStart(const ModulePtr&); + virtual void visitModuleEnd(const ModulePtr&); + virtual bool visitClassDefStart(const ClassDefPtr&); + virtual void visitClassDefEnd(const ClassDefPtr&); + + private: + + typedef ::std::set<::std::string> NameSet; + void writeInheritedOperations(const ClassDefPtr&, NameSet&); + }; + class ImplVisitor : public CsVisitor { public: @@ -194,6 +213,9 @@ private: virtual void visitModuleEnd(const ModulePtr&); virtual bool visitClassDefStart(const ClassDefPtr&); virtual void visitClassDefEnd(const ClassDefPtr&); + + private: + void writeOperation(const OperationPtr&, bool); ::std::string writeValue(const TypePtr&); }; diff --git a/cpp/src/slice2cs/Main.cpp b/cpp/src/slice2cs/Main.cpp index 583c0aad011..b101e76b700 100644 --- a/cpp/src/slice2cs/Main.cpp +++ b/cpp/src/slice2cs/Main.cpp @@ -242,12 +242,10 @@ main(int argc, char* argv[]) return EXIT_FAILURE; } gen.generate(p); -#if 0 if(tie) { gen.generateTie(p); } -#endif if(impl) { gen.generateImpl(p); |