diff options
author | Haojian Wu <hokein@google.com> | 2016-07-29 13:57:27 +0000 |
---|---|---|
committer | Haojian Wu <hokein@google.com> | 2016-07-29 13:57:27 +0000 |
commit | e1aebbab1ef3ca0040fa262fe7bcf4830200d2c9 (patch) | |
tree | 14424457c2cb24d9dda22444027872efe0537ce8 /include/clang/ASTMatchers | |
parent | 003e6f400e495cbbae7ecf4aa908c37c78c7e15a (diff) |
[ASTMatcher] Add hasTemplateArgument/hasAnyTemplateArgument support in functionDecl.
Reviewers: klimek
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D22957
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@277142 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/ASTMatchers')
-rw-r--r-- | include/clang/ASTMatchers/ASTMatchers.h | 29 | ||||
-rw-r--r-- | include/clang/ASTMatchers/ASTMatchersInternal.h | 7 |
2 files changed, 30 insertions, 6 deletions
diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index 8c079bae41..6f59b82520 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -556,22 +556,32 @@ AST_MATCHER(Decl, isImplicit) { return Node.isImplicit(); } -/// \brief Matches classTemplateSpecializations that have at least one -/// TemplateArgument matching the given InnerMatcher. +/// \brief Matches classTemplateSpecializations, templateSpecializationType and +/// functionDecl that have at least one TemplateArgument matching the given +/// InnerMatcher. /// /// Given /// \code /// template<typename T> class A {}; /// template<> class A<double> {}; /// A<int> a; +/// +/// template<typenmae T> f() {}; +/// void func() { f<int>(); }; +/// \endcode +/// /// \endcode /// classTemplateSpecializationDecl(hasAnyTemplateArgument( /// refersToType(asString("int")))) /// matches the specialization \c A<int> +/// +/// functionDecl(hasAnyTemplateArgument(refersToType(asString("int")))) +/// matches the specialization \c f<int> AST_POLYMORPHIC_MATCHER_P( hasAnyTemplateArgument, AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl, - TemplateSpecializationType), + TemplateSpecializationType, + FunctionDecl), internal::Matcher<TemplateArgument>, InnerMatcher) { ArrayRef<TemplateArgument> List = internal::getTemplateSpecializationArgs(Node); @@ -698,22 +708,29 @@ AST_MATCHER_P(QualType, ignoringParens, return InnerMatcher.matches(Node.IgnoreParens(), Finder, Builder); } -/// \brief Matches classTemplateSpecializations where the n'th TemplateArgument -/// matches the given InnerMatcher. +/// \brief Matches classTemplateSpecializations, templateSpecializationType and +/// functionDecl where the n'th TemplateArgument matches the given InnerMatcher. /// /// Given /// \code /// template<typename T, typename U> class A {}; /// A<bool, int> b; /// A<int, bool> c; +/// +/// template<typenmae T> f() {}; +/// void func() { f<int>(); }; /// \endcode /// classTemplateSpecializationDecl(hasTemplateArgument( /// 1, refersToType(asString("int")))) /// matches the specialization \c A<bool, int> +/// +/// functionDecl(hasTemplateArgument(0, refersToType(asString("int")))) +/// matches the specialization \c f<int> AST_POLYMORPHIC_MATCHER_P2( hasTemplateArgument, AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl, - TemplateSpecializationType), + TemplateSpecializationType, + FunctionDecl), unsigned, N, internal::Matcher<TemplateArgument>, InnerMatcher) { ArrayRef<TemplateArgument> List = internal::getTemplateSpecializationArgs(Node); diff --git a/include/clang/ASTMatchers/ASTMatchersInternal.h b/include/clang/ASTMatchers/ASTMatchersInternal.h index c2c01fbd78..b9e3157707 100644 --- a/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -1638,6 +1638,13 @@ getTemplateSpecializationArgs(const TemplateSpecializationType &T) { return llvm::makeArrayRef(T.getArgs(), T.getNumArgs()); } +inline ArrayRef<TemplateArgument> +getTemplateSpecializationArgs(const FunctionDecl &FD) { + if (const auto* TemplateArgs = FD.getTemplateSpecializationArgs()) + return TemplateArgs->asArray(); + return ArrayRef<TemplateArgument>(); +} + struct NotEqualsBoundNodePredicate { bool operator()(const internal::BoundNodesMap &Nodes) const { return Nodes.getNode(ID) != Node; |