From c95a037124b536f7ef975aeed0ea641c1c385c09 Mon Sep 17 00:00:00 2001 From: Axel Naumann Date: Fri, 12 Sep 2014 13:51:46 +0200 Subject: [PATCH] Remove unused Decl2FwdDecl; build (unique) fwd decl Transaction. --- core/metautils/inc/TMetaUtils.h | 3 --- core/metautils/src/TMetaUtils.cxx | 51 ++++++++++++++++++++++++--------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/core/metautils/inc/TMetaUtils.h b/core/metautils/inc/TMetaUtils.h index 2b6c168..5bf7306 100644 --- a/core/metautils/inc/TMetaUtils.h +++ b/core/metautils/inc/TMetaUtils.h @@ -693,9 +693,6 @@ const std::string& GetPathSeparator(); namespace AST2SourceTools { //______________________________________________________________________________ -const std::string Decl2FwdDecl(const clang::Decl& decl, - const cling::Interpreter& interp); -//______________________________________________________________________________ const std::string Decls2FwdDecls(const std::vector &decls, const cling::Interpreter& interp); diff --git a/core/metautils/src/TMetaUtils.cxx b/core/metautils/src/TMetaUtils.cxx index f9118e7..33bb8e3 100644 --- a/core/metautils/src/TMetaUtils.cxx +++ b/core/metautils/src/TMetaUtils.cxx @@ -4556,23 +4556,36 @@ const std::string& ROOT::TMetaUtils::GetPathSeparator() } //______________________________________________________________________________ -const std::string ROOT::TMetaUtils::AST2SourceTools::Decl2FwdDecl(const clang::Decl &decl, - const cling::Interpreter &interp) -{ - // Ugly const removal: wrong cling interfaces - clang::Decl *ncDecl = const_cast(&decl); - cling::Interpreter *ncInterp = const_cast(&interp); - clang::Sema &sema = ncInterp->getSema(); - cling::Transaction theTransaction(sema); - theTransaction.append(ncDecl); - if (auto *tsd = llvm::dyn_cast(ncDecl)) { - theTransaction.append(tsd->getSpecializedTemplate()); +static void addDeclToTransaction(clang::Decl *decl, + cling::Transaction &theTransaction, + std::set &addedDecls) +{ + if (decl->isFromASTFile()) return; + +// if (auto *nDecl = llvm::dyn_cast(decl)) { +// if (cling::utils::Analyze::IsStdOrCompilerDetails(*nDecl)){ +// return; +// } +// } + + // Templates + if (auto *tsd = llvm::dyn_cast(decl)) { + auto templ = tsd->getSpecializedTemplate(); + if (addedDecls.insert(templ).second) // no duplicates + theTransaction.append(tsd->getSpecializedTemplate()); + } + + // Contexts + auto *declForRecursion = decl; + while (auto *ctxt = declForRecursion->getDeclContext()) { + declForRecursion = llvm::dyn_cast_or_null(ctxt); + if (llvm::isa(declForRecursion) && // stop recursion at the last class/struct/ns + (addedDecls.insert(declForRecursion).second)) { // no duplicates + theTransaction.append(declForRecursion); + } else { + break; + } } - std::string newFwdDecl; - llvm::raw_string_ostream llvmOstr(newFwdDecl); - ncInterp->forwardDeclare(theTransaction, sema.getSourceManager(), llvmOstr, true, nullptr); - llvmOstr.flush(); - return newFwdDecl; } //______________________________________________________________________________ @@ -4583,13 +4596,11 @@ const std::string ROOT::TMetaUtils::AST2SourceTools::Decls2FwdDecls(const std::v cling::Interpreter *ncInterp = const_cast(&interp); clang::Sema &sema = ncInterp->getSema(); cling::Transaction theTransaction(sema); + std::set addedDecls; for (auto decl : decls) { // again waiting for cling clang::Decl *ncDecl = const_cast(decl); - theTransaction.append(ncDecl); - if (auto *tsd = llvm::dyn_cast(decl)) { - theTransaction.append(tsd->getSpecializedTemplate()); - } + addDeclToTransaction(ncDecl, theTransaction, addedDecls); } std::string newFwdDecl; llvm::raw_string_ostream llvmOstr(newFwdDecl); -- 1.8.2