diff options
author | Jose <jose@zeroc.com> | 2016-01-04 22:32:23 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2016-01-04 22:32:23 +0100 |
commit | 683befcfdd7ee669e7bf8b8b6b02467a8d0b718d (patch) | |
tree | 35a9a1afe689ca123f94a08ca5d70c11fd06ce35 /cpp/src | |
parent | C++11 test fixes (diff) | |
download | ice-683befcfdd7ee669e7bf8b8b6b02467a8d0b718d.tar.bz2 ice-683befcfdd7ee669e7bf8b8b6b02467a8d0b718d.tar.xz ice-683befcfdd7ee669e7bf8b8b6b02467a8d0b718d.zip |
C++11 move compatibility definitions to a separate visitor
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 94 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.h | 13 |
2 files changed, 72 insertions, 35 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 04fd8add38f..e211232d4aa 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -721,6 +721,9 @@ Slice::Gen::generate(const UnitPtr& p) ImplVisitor implVisitor(implH, implC, _dllExport); p->visit(&implVisitor, false); }*/ + + Cpp11CompatibilityVisitor compatibilityVisitor(H, C, _dllExport); + p->visit(&compatibilityVisitor, false); generateChecksumMap(p); @@ -3149,12 +3152,9 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) if(!p->isAbstract() && !p->isLocal() && !_doneStaticSymbol) { // - // We need an instance here to trigger initialization if the implementation is in a shared library. + // We need an instance here to trigger initialization if the implementation is in a static library. // But we do this only once per source file, because a single instance is sufficient to initialize - // all of the globals in a shared library. - // - // For a Slice class Foo, we instantiate a dummy class Foo__staticInit instead of using a static - // Foo instance directly because Foo has a protected destructor. + // all of the globals in a compilation unit. // H.zeroIndent(); H << nl << "#if !defined(_MSC_VER) || (_MSC_VER < 1900)"; @@ -5455,22 +5455,7 @@ Slice::Gen::Cpp11ObjectDeclVisitor::visitClassDecl(const ClassDeclPtr& p) string name = fixKwd(p->name()); string scoped = fixKwd(p->scoped()); - - if(p->isLocal()) - { - H << sp << nl << "class " << name << ';'; - H << nl << "typedef ::std::shared_ptr< " << name << "> " << p->name() << "Ptr;"; - } - else if(p->isInterface()) - { - H << sp << nl << "class " << name << ';'; - H << nl << "typedef ::std::shared_ptr< " << name << "> " << p->name() << "Ptr;"; - } - else // Value class - { - H << sp << nl << "class " << name << ';'; - H << nl << "typedef ::std::shared_ptr< " << name << "> " << p->name() << "Ptr;"; - } + H << sp << nl << "class " << name << ';'; } void @@ -5542,7 +5527,7 @@ Slice::Gen::Cpp11TypesVisitor::visitExceptionStart(const ExceptionPtr& p) for(DataMemberList::const_iterator q = allDataMembers.begin(); q != allDataMembers.end(); ++q) { - string typeName = inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring); + string typeName = inputTypeToString((*q)->type(), (*q)->optional(), (*q)->getMetaData(), _useWstring, true); allTypes.push_back(typeName); allParamDecls.push_back(typeName + " __ice_" + fixKwd((*q)->name())); } @@ -5768,8 +5753,6 @@ Slice::Gen::Cpp11TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) string baseName = base ? fixKwd(base->scoped()) : string("::Ice::UserException"); - H << nl << "using " << baseName << "::__write;"; - H << nl << "using " << baseName << "::__read;"; } H.dec(); @@ -5779,10 +5762,6 @@ Slice::Gen::Cpp11TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) H << nl << "virtual void __writeImpl(::IceInternal::BasicStream*) const;"; H << nl << "virtual void __readImpl(::IceInternal::BasicStream*);"; - string baseName = base ? fixKwd(base->scoped()) : string("::Ice::UserException"); - H << nl << "using " << baseName << "::__writeImpl;"; - H << nl << "using " << baseName << "::__readImpl;"; - if(preserved && !basePreserved) { @@ -6054,7 +6033,6 @@ Slice::Gen::Cpp11ProxyDeclVisitor::visitClassDecl(const ClassDeclPtr& p) if(p->isInterface() || (def && !def->allOperations().empty())) { H << nl << "class " << p->name() << "Prx;"; - H << nl << "typedef ::std::shared_ptr<" << p->name() << "Prx> " << p->name() << "PrxPtr;"; } } } @@ -8493,3 +8471,61 @@ Slice::Gen::Cpp11StreamVisitor::visitEnum(const EnumPtr& p) H << eb << ";" << nl; } } + + +Slice::Gen::Cpp11CompatibilityVisitor::Cpp11CompatibilityVisitor(Output& h, Output& c, const string& dllExport) : + H(h), + C(c), + _dllExport(dllExport) +{ +} + +bool +Slice::Gen::Cpp11CompatibilityVisitor::visitModuleStart(const ModulePtr& p) +{ + if(!p->hasClassDecls()) + { + return false; + } + + string name = fixKwd(p->name()); + + H << sp << nl << "namespace " << name << nl << '{'; + return true; +} + +void +Slice::Gen::Cpp11CompatibilityVisitor::visitModuleEnd(const ModulePtr&) +{ + H << sp; + H << nl << '}'; +} + +void +Slice::Gen::Cpp11CompatibilityVisitor::visitClassDecl(const ClassDeclPtr& p) +{ + string t; + if(p->isLocal() && findMetaData("cpp11:type", p, t)) + { + return; + } + if(p->definition() && p->definition()->isDelegate()) + { + return; + } + + string name = fixKwd(p->name()); + string scoped = fixKwd(p->scoped()); + + H << sp << nl << "typedef ::std::shared_ptr<" << name << "> " << p->name() << "Ptr;"; + + if(!p->isLocal()) + { + ClassDefPtr def = p->definition(); + if(p->isInterface() || (def && !def->allOperations().empty())) + { + H << nl << "class " << p->name() << "Prx;"; + H << nl << "typedef ::std::shared_ptr<" << p->name() << "Prx> " << p->name() << "PrxPtr;"; + } + } +} diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h index da1f460529d..597892b19be 100644 --- a/cpp/src/slice2cpp/Gen.h +++ b/cpp/src/slice2cpp/Gen.h @@ -570,16 +570,17 @@ private: ::IceUtilInternal::Output& C; std::string _dllExport; }; - - class Cpp11InterfaceTraitsVisitor : private ::IceUtil::noncopyable, public ParserVisitor + + + class Cpp11CompatibilityVisitor : private ::IceUtil::noncopyable, public ParserVisitor { public: - Cpp11InterfaceTraitsVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&, const std::string&); + Cpp11CompatibilityVisitor(::IceUtilInternal::Output&, ::IceUtilInternal::Output&, const std::string&); - virtual bool visitUnitStart(const UnitPtr&); - virtual void visitUnitEnd(const UnitPtr&); - virtual bool visitClassDefStart(const ClassDefPtr&); + virtual bool visitModuleStart(const ModulePtr&); + virtual void visitModuleEnd(const ModulePtr&); + virtual void visitClassDecl(const ClassDeclPtr&); private: |