diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/include/Slice/CPlusPlusUtil.h | 2 | ||||
-rw-r--r-- | cpp/include/Slice/Parser.h | 1 | ||||
-rw-r--r-- | cpp/src/Slice/CPlusPlusUtil.cpp | 49 | ||||
-rw-r--r-- | cpp/src/Slice/CsUtil.cpp | 16 | ||||
-rw-r--r-- | cpp/src/Slice/JavaUtil.cpp | 22 | ||||
-rw-r--r-- | cpp/src/Slice/Parser.cpp | 9 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 168 | ||||
-rw-r--r-- | cpp/src/slice2cs/Gen.cpp | 26 |
8 files changed, 199 insertions, 94 deletions
diff --git a/cpp/include/Slice/CPlusPlusUtil.h b/cpp/include/Slice/CPlusPlusUtil.h index 9d3bc8ebc94..413a855e2d3 100644 --- a/cpp/include/Slice/CPlusPlusUtil.h +++ b/cpp/include/Slice/CPlusPlusUtil.h @@ -65,6 +65,8 @@ SLICE_API std::string findMetaData(const StringList&, int = 0); SLICE_API bool inWstringModule(const SequencePtr&); SLICE_API std::string getDataMemberRef(const DataMemberPtr&); + +SLICE_API std::string classDefToDelegateString(const ClassDefPtr&, int = 0, bool = false); } #endif diff --git a/cpp/include/Slice/Parser.h b/cpp/include/Slice/Parser.h index b2854910d67..4722b625206 100644 --- a/cpp/include/Slice/Parser.h +++ b/cpp/include/Slice/Parser.h @@ -690,6 +690,7 @@ public: virtual std::string kindOf() const; virtual void visit(ParserVisitor*, bool); int compactId() const; + bool isDelegate() const; protected: diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp index 480feedd064..bc61ca61fe3 100644 --- a/cpp/src/Slice/CPlusPlusUtil.cpp +++ b/cpp/src/Slice/CPlusPlusUtil.cpp @@ -486,7 +486,7 @@ Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx "::Ice::LocalObjectPtr", "::Ice::ValuePtr" }; - + static const char* cpp11BuiltinTable[] = { "::Ice::Byte", @@ -543,6 +543,10 @@ Slice::typeToString(const TypePtr& type, const StringList& metaData, int typeCtx { return t; } + else if(cl->definition() && cl->definition()->isDelegate()) + { + return classDefToDelegateString(cl->definition()); + } else { if(cl->isInterface() && !cl->isLocal()) @@ -673,7 +677,7 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m "const ::Ice::LocalObjectPtr&", "const ::Ice::ValuePtr&" }; - + static const char* cpp11InputBuiltinTable[] = { "::Ice::Byte", @@ -738,6 +742,10 @@ Slice::inputTypeToString(const TypePtr& type, bool optional, const StringList& m { return "const ::std::shared_ptr<::Ice::Value>&"; } + else if(cl->definition() && cl->definition()->isDelegate()) + { + return classDefToDelegateString(cl->definition(), typeCtx, cpp11); + } else { return "const ::std::shared_ptr<" + fixKwd(cl->scoped()) + ">&"; @@ -829,7 +837,7 @@ Slice::outputTypeToString(const TypePtr& type, bool optional, const StringList& "::Ice::LocalObjectPtr&", "::Ice::ValuePtr&" }; - + static const char* cpp11OutputBuiltinTable[] = { "::Ice::Byte&", @@ -1258,7 +1266,7 @@ Slice::findMetaData(const string& prefix, const ClassDeclPtr& cl, string& value) { return true; } - + ClassDefPtr def = cl->definition(); return def ? findMetaData(prefix, def->getMetaData(), value) : false; } @@ -1406,3 +1414,36 @@ Slice::getDataMemberRef(const DataMemberPtr& p) return "(*" + name + ")"; } } + +string +Slice::classDefToDelegateString(const ClassDefPtr& cl, int typeCtx, bool cpp11) +{ + assert(cl->isDelegate()); + + // A delegate only has one operation + OperationPtr op = cl->allOperations().front(); + + TypePtr ret = op->returnType(); + string retS = returnTypeToString(ret, op->returnIsOptional(), op->getMetaData(), typeCtx, cpp11); + + string t = "::std::function<" + retS + " ("; + + ParamDeclList paramList = cl->allOperations().front()->parameters(); + for(ParamDeclList::iterator q = paramList.begin(); q != paramList.end(); ++q) + { + if((*q)->isOutParam()) + { + t += outputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), typeCtx, cpp11); + } + else + { + t += inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), typeCtx, cpp11); + } + + t += distance(q, paramList.end()) == 1 ? "" : ", "; + } + + t += ")>"; + + return t; +} diff --git a/cpp/src/Slice/CsUtil.cpp b/cpp/src/Slice/CsUtil.cpp index ac8f3d05e57..d02f8bdfd13 100644 --- a/cpp/src/Slice/CsUtil.cpp +++ b/cpp/src/Slice/CsUtil.cpp @@ -1179,7 +1179,7 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, << "> e__ = " << param << ".GetEnumerator();"; out << nl << "while(e__.MoveNext())"; out << sb; - string func = (builtin->kind() == Builtin::KindObject || + string func = (builtin->kind() == Builtin::KindObject || builtin->kind() == Builtin::KindValue) ? "writeObject" : "writeProxy"; out << nl << stream << '.' << func << "(e__.Current);"; out << eb; @@ -2639,5 +2639,19 @@ Slice::CsGenerator::MetaDataVisitor::validate(const ContainedPtr& cont) _history.insert(s); } } + + if(_history.count(s) == 0) + { + if(s == "delegate") + { + ClassDefPtr cl = ClassDefPtr::dynamicCast(cont); + if(cl && cl->isDelegate()) + { + continue; + } + emitWarning(cont->file(), cont->line(), msg + " `" + s + "'"); + _history.insert(s); + } + } } } diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp index dd35e40abb0..f84b30eb8d5 100644 --- a/cpp/src/Slice/JavaUtil.cpp +++ b/cpp/src/Slice/JavaUtil.cpp @@ -1640,7 +1640,7 @@ Slice::JavaGenerator::writeMarshalUnmarshalCode(Output& out, BuiltinPtr elemBuiltin = BuiltinPtr::dynamicCast(elemType); if(optionalParam && elemBuiltin && elemBuiltin->kind() != Builtin::KindObject && - elemBuiltin->kind() != Builtin::KindObjectProxy && elemBuiltin->kind() != Builtin::KindValue && + elemBuiltin->kind() != Builtin::KindObjectProxy && elemBuiltin->kind() != Builtin::KindValue && !hasTypeMetaData(seq, metaData)) { static const char* builtinTable[] = @@ -2343,7 +2343,7 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, { BuiltinPtr b = BuiltinPtr::dynamicCast(type); if(b && b->kind() != Builtin::KindObject && - b->kind() != Builtin::KindValue && + b->kind() != Builtin::KindValue && b->kind() != Builtin::KindObjectProxy) { switch(b->kind()) @@ -3201,7 +3201,7 @@ Slice::JavaGenerator::writeStreamDictionaryMarshalUnmarshalCode(Output& out, } } BuiltinPtr builtin = BuiltinPtr::dynamicCast(value); - if(!(builtin && (builtin->kind() == Builtin::KindObject || builtin->kind() == Builtin::KindValue)) && + if(!(builtin && (builtin->kind() == Builtin::KindObject || builtin->kind() == Builtin::KindValue)) && !ClassDeclPtr::dynamicCast(value)) { out << nl << "" << v << ".put(__key, __value);"; @@ -3536,7 +3536,7 @@ Slice::JavaGenerator::writeStreamSequenceMarshalUnmarshalCode(Output& out, { BuiltinPtr b = BuiltinPtr::dynamicCast(type); if(b && b->kind() != Builtin::KindObject && - b->kind() != Builtin::KindValue && + b->kind() != Builtin::KindValue && b->kind() != Builtin::KindObjectProxy) { switch(b->kind()) @@ -4280,6 +4280,11 @@ Slice::JavaGenerator::MetaDataVisitor::getMetaData(const ContainedPtr& cont) emitWarning(cont->file(), cont->line(), "ignoring invalid metadata `" + s + "'"); } + else if(s == "delegate") + { + result.push_back(s); + continue; + } _history.insert(s); } @@ -4337,6 +4342,15 @@ Slice::JavaGenerator::MetaDataVisitor::validateType(const SyntaxTreeBasePtr& p, // emitWarning(file, line, "ignoring invalid metadata `" + *i + "'"); } + else if(i->find("delegate") == 0) + { + ClassDefPtr cl = ClassDefPtr::dynamicCast(p); + if(cl && cl->isDelegate()) + { + continue; + } + emitWarning(file, line, "ignoring invalid metadata `" + *i + "'"); + } } } diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index c40ac42c544..02a26d39551 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -415,7 +415,7 @@ Slice::Contained::updateIncludeLevel() bool Slice::Contained::hasMetaData(const string& meta) const -{ +{ return find(_metaData.begin(), _metaData.end(), meta) != _metaData.end(); } @@ -3467,7 +3467,7 @@ Slice::ClassDef::classDataMembers() const if(q) { BuiltinPtr builtin = BuiltinPtr::dynamicCast(q->type()); - if((builtin && builtin->kind() == Builtin::KindObject) || + if((builtin && builtin->kind() == Builtin::KindObject) || (builtin && builtin->kind() == Builtin::KindValue) || ClassDeclPtr::dynamicCast(q->type())) { @@ -3658,6 +3658,11 @@ Slice::ClassDef::compactId() const return _compactId; } +bool +Slice::ClassDef::isDelegate() const +{ + return isLocal() && isInterface() && hasMetaData("delegate") && allOperations().size() == 1; +} Slice::ClassDef::ClassDef(const ContainerPtr& container, const string& name, int id, bool intf, const ClassList& bases, bool local) : SyntaxTreeBase(container->unit()), diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 961bac75c3c..b81b5a887dd 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -666,16 +666,16 @@ Slice::Gen::generate(const UnitPtr& p) Cpp11ProxyVisitor proxyVisitor(H, C, _dllExport); p->visit(&proxyVisitor, false); - + Cpp11InterfaceTraitsVisitor interfaceTraitsVisitor(H, C, _dllExport); p->visit(&interfaceTraitsVisitor, false); Cpp11LocalObjectVisitor localObjectVisitor(H, C, _dllExport, _stream); p->visit(&localObjectVisitor, false); - + Cpp11InterfaceVisitor interfaceVisitor(H, C, _dllExport, _stream); p->visit(&interfaceVisitor, false); - + Cpp11ValueVisitor valueVisitor(H, C, _dllExport, _stream); p->visit(&valueVisitor, false); @@ -2603,7 +2603,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) C << nl << "throw ::Ice::UnknownUserException(__FILE__, __LINE__, __ex.ice_name());"; C << eb; C << eb; - + if(ret || !outParams.empty()) { C << nl << "::IceInternal::BasicStream* __is = __result->__startReadParams();"; @@ -4056,10 +4056,10 @@ Slice::Gen::ObjectVisitor::emitOneShotConstructor(const ClassDefPtr& p) for(DataMemberList::const_iterator q = allDataMembers.begin(); q != allDataMembers.end(); ++q) { - + string typeName = inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring); bool dataMember = std::find(dataMembers.begin(), dataMembers.end(), (*q)) != dataMembers.end(); - allParamDecls.push_back(typeName + ((dataMember || callBaseConstuctors) ? + allParamDecls.push_back(typeName + ((dataMember || callBaseConstuctors) ? (" __ice_" + (*q)->name()) : (" /*__ice_" + (*q)->name() + "*/"))); } @@ -4077,7 +4077,7 @@ Slice::Gen::ObjectVisitor::emitOneShotConstructor(const ClassDefPtr& p) ClassList bases = p->bases(); ClassDefPtr base; - + if(!bases.empty() && !bases.front()->isInterface() && callBaseConstuctors) { if(emitVirtualBaseInitializers(bases.front(), virtualInheritance, true)) @@ -5609,7 +5609,7 @@ Slice::Gen::MetaDataVisitor::validate(const SyntaxTreeBasePtr& cont, const Strin { static const string cppPrefix = "cpp:"; static const string cpp11Prefix = "cpp11:"; - + for(StringList::const_iterator p = metaData.begin(); p != metaData.end(); ++p) { string s = *p; @@ -5620,7 +5620,7 @@ Slice::Gen::MetaDataVisitor::validate(const SyntaxTreeBasePtr& cont, const Strin if(cpp || cpp11) { const string prefix = cpp ? cppPrefix : cpp11Prefix; - + string ss = s.substr(prefix.size()); if(ss == "type:wstring" || ss == "type:string") { @@ -5656,7 +5656,7 @@ Slice::Gen::MetaDataVisitor::validate(const SyntaxTreeBasePtr& cont, const Strin { continue; } - + { ClassDefPtr cl = ClassDefPtr::dynamicCast(cont); if(cl && ((cpp && ss == "virtual") || (cpp11 && cl->isLocal() && ss.find("type:") == 0))) @@ -5672,7 +5672,7 @@ Slice::Gen::MetaDataVisitor::validate(const SyntaxTreeBasePtr& cont, const Strin { continue; } - + { ClassDeclPtr cl = ClassDeclPtr::dynamicCast(cont); if(cl && cpp11 && cl->isLocal() && ss.find("type:") == 0) @@ -5682,6 +5682,15 @@ Slice::Gen::MetaDataVisitor::validate(const SyntaxTreeBasePtr& cont, const Strin } emitWarning(file, line, "ignoring invalid metadata `" + s + "'"); } + if(s.find("delegate") == 0) + { + ClassDefPtr cl = ClassDefPtr::dynamicCast(cont); + if(cl && cl->isDelegate()) + { + continue; + } + emitWarning(file, line, "ignoring invalid metadata `" + s + "'"); + } _history.insert(s); } } @@ -5762,6 +5771,11 @@ Slice::Gen::Cpp11ObjectDeclVisitor::visitClassDecl(const ClassDeclPtr& p) { return; } + if(p->definition() && p->definition()->isDelegate()) + { + return; + } + string name = fixKwd(p->name()); string scoped = fixKwd(p->scoped()); @@ -6225,7 +6239,7 @@ Slice::Gen::Cpp11TypesVisitor::visitStructStart(const StructPtr& p) H << sp << nl << "struct " << name; H << sb; - + return true; } @@ -6310,14 +6324,14 @@ Slice::Gen::Cpp11TypesVisitor::visitDataMember(const DataMemberPtr& p) { string name = fixKwd(p->name()); H << nl << typeToString(p->type(), p->optional(), p->getMetaData(), _useWstring, true) << ' ' << name; - + string defaultValue = p->defaultValue(); if(!defaultValue.empty()) { H << " = "; writeConstantValue(H, p->type(), p->defaultValueType(), defaultValue, _useWstring, p->getMetaData(), true); } - + H << ';'; } @@ -6419,8 +6433,8 @@ Slice::Gen::Cpp11ProxyDeclVisitor::visitClassDecl(const ClassDeclPtr& p) { string name = fixKwd(p->name()); string scoped = fixKwd(p->scoped()); - - ClassDefPtr def = p->definition(); + + ClassDefPtr def = p->definition(); if(p->isInterface() || (def && !def->allOperations().empty())) { H << nl << "class " << p->name() << "Prx;"; @@ -6485,7 +6499,7 @@ Slice::Gen::Cpp11ProxyVisitor::visitClassDefStart(const ClassDefPtr& p) string scope = fixKwd(p->scope()); string scoped = fixKwd(p->scoped()); ClassList bases = p->bases(); - + ClassDefPtr base; if(!bases.empty() && !bases.front()->isInterface()) { @@ -6530,7 +6544,7 @@ Slice::Gen::Cpp11ProxyVisitor::visitClassDefEnd(const ClassDefPtr& p) // // No identity! // - + string prx = fixKwd(p->name() + "Prx"); H << nl << "::std::shared_ptr<" << prx << "> ice_context(const ::Ice::Context& __context) const"; @@ -6645,7 +6659,7 @@ Slice::Gen::Cpp11ProxyVisitor::visitClassDefEnd(const ClassDefPtr& p) H << sp; H << nl << "static const ::std::string& ice_staticId();"; - + H.dec(); H << sp << nl << "private: "; H.inc(); @@ -6654,16 +6668,16 @@ Slice::Gen::Cpp11ProxyVisitor::visitClassDefEnd(const ClassDefPtr& p) H << eb << ';'; string suffix = p->isInterface() ? "" : "Disp"; - + string scoped = fixKwd(p->scoped() + "Prx"); - + C << sp; C << nl << "const ::std::string&" << nl << scoped.substr(2) << "::ice_staticId()"; C << sb; C << nl << "return "<< fixKwd(p->scope() + p->name() + suffix).substr(2) << "::ice_staticId();"; C << eb; - + C << sp << nl << "::std::shared_ptr<::Ice::ObjectPrx>"; C << nl << scoped.substr(2) << "::__newInstance() const"; C << sb; @@ -6689,19 +6703,19 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) vector<string> params; vector<string> paramsDecl; - + vector<string> lambdaParams; vector<string> lambdaParamsDecl; - + vector<string> futureParamsDecl; - + vector<string> lambdaOutParams; vector<string> lambdaOutParamsDecl; - + ParamDeclList paramList = p->parameters(); ParamDeclList inParams; ParamDeclList outParams; - + string returnValueS = "returnValue"; for(ParamDeclList::const_iterator q = paramList.begin(); q != paramList.end(); ++q) @@ -6727,22 +6741,22 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) { params.push_back(typeString); paramsDecl.push_back(typeString + ' ' + paramName); - + lambdaParams.push_back(typeString); lambdaParamsDecl.push_back(typeString + ' ' + paramName); - + futureParamsDecl.push_back(typeString + ' ' + paramName); - + inParams.push_back(*q); } else { params.push_back(outputTypeString); paramsDecl.push_back(outputTypeString + ' ' + paramName); - + lambdaOutParams.push_back(typeString); lambdaOutParamsDecl.push_back(typeString + ' ' + paramName); - + outParams.push_back(*q); if((*q)->name() == "returnValue") { @@ -6750,7 +6764,7 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) } } } - + string scoped = fixKwd(cl->scope() + cl->name() + "Prx" + "::").substr(2); string deprecateSymbol = getDeprecateSymbol(p, cl); @@ -6842,13 +6856,13 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) C << "return "; } C << "__promise.get_future().get();"; - + if(!p->returnsData()) { C << eb; C << nl << "else if(ice_isOneway() || ice_isDatagram())"; C << sb; - + C << nl << name << "_async("; C.useCurrentPosAsIndent(); for(ParamDeclList::const_iterator q = inParams.begin(); q != inParams.end();) @@ -6875,7 +6889,7 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) C << nl << "__ctx);"; C.restoreIndent(); C << nl << "__promise.get_future().get();"; - + C << eb; C << nl << "else"; C << sb; @@ -6888,7 +6902,7 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) C << nl << "__promise.set_value();"; C << eb; } - + C << eb; H << sp; @@ -7033,7 +7047,7 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) C << nl << "throw std::current_exception();"; C << eb; C << eb; - C << eb << ","; + C << eb << ","; } else { @@ -7051,7 +7065,7 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) C << nl << "throw std::current_exception();"; C << eb; C << eb; - C << eb << ","; + C << eb << ","; } ExceptionList throws = p->throws(); @@ -7059,14 +7073,14 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) { throws.sort(); throws.unique(); - + // // Arrange exceptions into most-derived to least-derived order. If we don't // do this, a base exception handler can appear before a derived exception // handler, causing compiler warnings and resulting in the base exception // being marshaled instead of the derived exception. // - + #if defined(__SUNPRO_CC) throws.sort(derivedToBaseCompare); #else @@ -7106,9 +7120,9 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) C << nl << "::std::move(__exception), ::std::move(__sent), __ctx);"; C.dec(); C << eb; - + string futureT; - + if(retS == "void" && outParams.empty()) { futureT = "void"; @@ -7126,7 +7140,7 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) { futureT = "Result_" + name; } - + if(futureT.find("Result_") == 0) { // We need to generate a Result_ struct. @@ -7144,7 +7158,7 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) } H << eb << ";"; } - + H << sp; H << nl << "template<template<typename> class P = ::std::promise>"; H << nl << deprecateSymbol << "auto " << name << "_async" << spar << futureParamsDecl @@ -7175,7 +7189,7 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) H << nl; } H << "[__promise]("; - + if(retS != "void") { H << retS << " __ret"; @@ -7222,7 +7236,7 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) } H << nl << "__promise->set_value(::std::move(__result));"; } - + H << eb << ","; H << nl << "[__promise](::std::exception_ptr __ex)"; H << sb; @@ -7230,13 +7244,13 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) H << eb << ","; H << nl << "nullptr, __ctx);"; H.restoreIndent(); - + if(!p->returnsData()) { H << eb; H << nl << "else if(ice_isOneway() || ice_isDatagram())"; H << sb; - + H << nl << name << "_async("; H.useCurrentPosAsIndent(); for(ParamDeclList::const_iterator q = inParams.begin(); q != inParams.end();) @@ -7258,7 +7272,7 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) H << eb << ","; H << nl << "__ctx);"; H.restoreIndent(); - + H << eb; H << nl << "else"; H << sb; @@ -7270,7 +7284,7 @@ Slice::Gen::Cpp11ProxyVisitor::visitOperation(const OperationPtr& p) H << "nullptr, nullptr, nullptr, __ctx);"; H << eb; } - + H << nl << "return __promise->get_future();"; H << eb; } @@ -7406,7 +7420,7 @@ Slice::Gen::Cpp11LocalObjectVisitor::visitModuleStart(const ModulePtr& p) { return false; } - + _useWstring = setUseWstring(p, _useWstringHist, _useWstring); string name = fixKwd(p->name()); H << sp << nl << "namespace " << name << nl << '{'; @@ -7415,7 +7429,7 @@ Slice::Gen::Cpp11LocalObjectVisitor::visitModuleStart(const ModulePtr& p) void Slice::Gen::Cpp11LocalObjectVisitor::visitModuleEnd(const ModulePtr&) -{ +{ H << sp; H << nl << '}'; _useWstring = resetUseWstring(_useWstringHist); @@ -7434,6 +7448,11 @@ Slice::Gen::Cpp11LocalObjectVisitor::visitClassDefStart(const ClassDefPtr& p) H << sp << "typedef " << t << " " << fixKwd(p->name()) << ";"; return false; } + if(p->isDelegate()) + { + return false; + } + string name = fixKwd(p->name()); string scope = fixKwd(p->scope()); string scoped = fixKwd(p->scoped()); @@ -7719,7 +7738,7 @@ Slice::Gen::Cpp11LocalObjectVisitor::visitOperation(const OperationPtr& p) outParamsDeclAMI.push_back(typeString + ' ' + paramName); } } - + H << sp; H << nl << "virtual ::std::function<void ()>"; H << nl << name << "_async("; @@ -7763,7 +7782,7 @@ Slice::Gen::Cpp11InterfaceVisitor::visitModuleStart(const ModulePtr& p) { return false; } - + _useWstring = setUseWstring(p, _useWstringHist, _useWstring); string name = fixKwd(p->name()); H << sp << nl << "namespace " << name << nl << '{'; @@ -8042,7 +8061,7 @@ void Slice::Gen::Cpp11InterfaceVisitor::visitOperation(const OperationPtr& p) { string name = p->name(); - + TypePtr ret = p->returnType(); string retS = returnTypeToString(ret, p->returnIsOptional(), p->getMetaData(), _useWstring, true); @@ -8099,7 +8118,7 @@ Slice::Gen::Cpp11InterfaceVisitor::visitOperation(const OperationPtr& p) paramsDecl += paramName; args += paramName; } - + if(!paramList.empty()) { params += ", "; @@ -8121,7 +8140,7 @@ Slice::Gen::Cpp11InterfaceVisitor::visitOperation(const OperationPtr& p) paramsAMD += inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring, true); argsAMD += fixKwd(string(paramPrefix) + (*q)->name()); } - + if(ret) { string typeString = inputTypeToString(ret, p->returnIsOptional(), p->getMetaData(), _useWstring, true); @@ -8133,7 +8152,7 @@ Slice::Gen::Cpp11InterfaceVisitor::visitOperation(const OperationPtr& p) responseParamsDecl += ", "; } } - + for(ParamDeclList::iterator q = outParams.begin(); q != outParams.end(); ++q) { if(q != outParams.begin()) @@ -8149,7 +8168,7 @@ Slice::Gen::Cpp11InterfaceVisitor::visitOperation(const OperationPtr& p) bool isConst = (p->mode() == Operation::Nonmutating) || p->hasMetaData("cpp:const"); bool amd = (cl->hasMetaData("amd") || p->hasMetaData("amd")); - + ExceptionList throws = p->throws(); throws.sort(); throws.unique(); @@ -8165,7 +8184,7 @@ Slice::Gen::Cpp11InterfaceVisitor::visitOperation(const OperationPtr& p) #else throws.sort(Slice::DerivedToBaseCompare()); #endif - + string deprecateSymbol = getDeprecateSymbol(p, cl); H << sp; if(!amd) @@ -8189,9 +8208,9 @@ Slice::Gen::Cpp11InterfaceVisitor::visitOperation(const OperationPtr& p) } H << sp; - H << nl << "::Ice::DispatchStatus ___" << name << "(::IceInternal::Incoming&, const ::Ice::Current&)" + H << nl << "::Ice::DispatchStatus ___" << name << "(::IceInternal::Incoming&, const ::Ice::Current&)" << (isConst ? " const" : "") << ';'; - + C << sp; C << nl << "::Ice::DispatchStatus" << nl << scope.substr(2) << "___" << name << "(::IceInternal::Incoming& __inS" << ", const ::Ice::Current& __current)" << (isConst ? " const" : ""); @@ -8213,7 +8232,7 @@ Slice::Gen::Cpp11InterfaceVisitor::visitOperation(const OperationPtr& p) { C << nl << "__inS.readEmptyParams();"; } - + if(!amd) { writeAllocateCode(C, outParams, 0, true, _useWstring, true); @@ -8266,7 +8285,7 @@ Slice::Gen::Cpp11InterfaceVisitor::visitOperation(const OperationPtr& p) C << sb; C << nl << "std::rethrow_exception(e);"; C << eb; - + for(ExceptionList::const_iterator r = throws.begin(); r != throws.end(); ++r) { C << nl << "catch(const " << fixKwd((*r)->scoped()) << "& __ex)"; @@ -8278,20 +8297,20 @@ Slice::Gen::Cpp11InterfaceVisitor::visitOperation(const OperationPtr& p) C << eb; C << eb; } - + C << nl << "catch(const ::std::exception& __ex)"; C << sb; C << nl << "inS->ice_exception(__ex);"; C << eb; C << nl << "catch(...)"; C << sb; - C << nl << "inS->ice_exception();"; + C << nl << "inS->ice_exception();"; C << eb; C << eb << ";"; C << nl << "try"; C << sb; - + C << nl << name << "_async("; C.useCurrentPosAsIndent(); if(!argsAMD.empty()) @@ -8347,7 +8366,7 @@ Slice::Gen::Cpp11ValueVisitor::visitModuleStart(const ModulePtr& p) { return false; } - + _useWstring = setUseWstring(p, _useWstringHist, _useWstring); string name = fixKwd(p->name()); H << sp << nl << "namespace " << name << nl << '{'; @@ -8521,14 +8540,14 @@ Slice::Gen::Cpp11ValueVisitor::visitClassDefEnd(const ClassDefPtr& p) emitUpcall(base, "::__readImpl(__is);"); } C << eb; - + C << sp; C << nl << "::Ice::ValuePtr"; C << nl << scoped.substr(2) << "::ice_clone() const"; C << sb; C << nl << "return ::std::make_shared<" << scoped << ">(*this);"; C << eb; - + C << sp; C << nl << "const ::std::string&" << nl << scoped.substr(2) << "::ice_staticId()"; C << sb; @@ -8698,7 +8717,6 @@ Slice::Gen::Cpp11ObjectVisitor::emitOneShotConstructor(const ClassDefPtr& p) for(DataMemberList::const_iterator q = allDataMembers.begin(); q != allDataMembers.end(); ++q) { - string typeName = inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring, true); allParamDecls.push_back(typeName + " __ice_" + (*q)->name()); } @@ -8713,7 +8731,7 @@ Slice::Gen::Cpp11ObjectVisitor::emitOneShotConstructor(const ClassDefPtr& p) ClassList bases = p->bases(); ClassDefPtr base; - + if(!bases.empty() && !bases.front()->isInterface()) { if(emitVirtualBaseInitializers(bases.front(), false, true)) @@ -8926,8 +8944,8 @@ Slice::Gen::Cpp11InterfaceTraitsVisitor::visitClassDefStart(const ClassDefPtr& p H << nl << "static const std::string staticId;"; H << nl << "static const int compactId = " << p->compactId() << ";"; H << eb << ";"; - + C << sp; - C << nl << "const std::string Ice::InterfaceTraits<" << fixKwd(p->scoped()) << ">::staticId = \"" << p->scoped() << "\";"; + C << nl << "const std::string Ice::InterfaceTraits<" << fixKwd(p->scoped()) << ">::staticId = \"" << p->scoped() << "\";"; return true; } diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 12f86b183a0..e5288b6d1e7 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -1517,7 +1517,7 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) } string memberName = fixId((*d)->name(), DotNet::ICloneable, true); string memberType = typeToString((*d)->type(), (*d)->optional()); - + if(ClassDeclPtr::dynamicCast((*d)->type())) { _out << nl << "_instance." << memberName << " = (" << memberType << ")v;"; @@ -1526,14 +1526,14 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) { _out << nl << "_instance." << memberName << " = v;"; } - + if(classMembers.size() > 1) { _out << nl << "break;"; } memberCount++; } - + for(DataMemberList::const_iterator d = optionalMembers.begin(); d != optionalMembers.end(); ++d) { TypePtr paramType = (*d)->type(); @@ -1578,7 +1578,7 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) memberCount++; } } - + if(classMembers.size() > 1) { _out << eb; @@ -3036,6 +3036,16 @@ Slice::Gen::TypesVisitor::visitClassDefStart(const ClassDefPtr& p) _out << sp; emitAttributes(p); + + if(p->isDelegate()) + { + emitComVisibleAttribute(); + OperationPtr o = p->allOperations().front(); + _out << nl << "public delegate " << typeToString(o->returnType(), o->returnIsOptional()) << " "; + _out << fixId(name) << spar << getParams(o) << epar << ";"; + return false; + } + if(p->isInterface()) { emitComVisibleAttribute(); @@ -3864,7 +3874,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) } _out << eb; - + if(classMembers.size() != 0) { _out << sp; @@ -3943,7 +3953,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) } memberCount++; } - + for(DataMemberList::const_iterator q = optionalMembers.begin(); q != optionalMembers.end(); ++q) { @@ -3989,7 +3999,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) memberCount++; } } - + if(classMembers.size() > 1) { _out << eb; @@ -4014,7 +4024,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) _out << nl << "protected override void readImpl__(IceInternal.BasicStream is__)"; _out << sb; _out << nl << "is__.startReadSlice();"; - + int patchIter = 0; const bool needCustomPatcher = classMembers.size() > 1; for(DataMemberList::const_iterator q = dataMembers.begin(); q != dataMembers.end(); ++q) |