From c6501ffe9706f75048a65930dbf3841b4221e6bb Mon Sep 17 00:00:00 2001 From: Philippe Canal Date: Fri, 31 Jan 2014 18:45:59 -0600 Subject: [PATCH] Introduce Transform::Config::DropDefaultArg Currently only implemented for the STL collection. This could eventually be used to allow customization of which default argument to strip and which class template. For now, it is only used to prevent the addition of template default template argument to the STL collection ... which we would any strip. This fixes the secondary issue in ROOT-6020 (one class template instance having more than one corresponding TClass due to the inconsistency in the normalization (not adding vs not stripping) --- include/cling/Utils/AST.h | 7 +++++++ lib/Utils/AST.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/cling/Utils/AST.h b/include/cling/Utils/AST.h index be322c84..01ba8788 100644 --- a/include/cling/Utils/AST.h +++ b/include/cling/Utils/AST.h @@ -27,6 +27,7 @@ namespace clang { class QualType; class Sema; class TagDecl; + class TemplateDecl; class Type; class TypedefNameDecl; } @@ -135,6 +136,12 @@ namespace utils { SkipCollection m_toSkip; ReplaceCollection m_toReplace; + ///\brief Returns the number of default argument that should be dropped. + /// from the name of the template instances. + /// + ///\param[in] decl - The declaration being analyzed. + unsigned int DropDefaultArg(clang::TemplateDecl &Template) const; + bool empty() const { return m_toSkip.size()==0 && m_toReplace.empty(); } }; diff --git a/lib/Utils/AST.cpp b/lib/Utils/AST.cpp index ba9ac819..02215198 100644 --- a/lib/Utils/AST.cpp +++ b/lib/Utils/AST.cpp @@ -583,6 +583,32 @@ namespace utils { return false; } + unsigned int + Transform::Config::DropDefaultArg(clang::TemplateDecl &Template) const + { + /// Return the number of default argument to drop. + + if (Analyze::IsStdClass(Template)) { + static const char *stls[] = //container names + {"vector","list","deque","map","multimap","set","multiset",0}; + static unsigned int values[] = //number of default arg. + {1,1,1,2,2,2,2}; + StringRef name = Template.getName(); + for(int k=0;stls[k];k++) { + if ( name.equals(stls[k]) ) return values[k]; + } + } + // Check in some struct if the Template decl is registered something like + /* + DefaultCollection::const_iterator iter; + iter = m_defaultArgs.find(&Template); + if (iter != m_defaultArgs.end()) { + return iter->second; + } + */ + return 0; + } + static bool ShouldKeepTypedef(QualType QT, const llvm::SmallSet& TypesToSkip) {