From cc9df3b9cc5f8c8671c91775ba7f3c410650f72c Mon Sep 17 00:00:00 2001 From: Felix Berger Date: Mon, 15 Feb 2016 04:00:39 +0000 Subject: [PATCH] Add isAnyPointer() matchers. Register missing matchers. Summary: The isAnyPointer() matcher is useful for http://reviews.llvm.org/D15623. Reviewers: alexfh, klimek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D15819 llvm-svn: 260872 --- clang/include/clang/ASTMatchers/ASTMatchers.h | 13 +++++++++++++ clang/lib/ASTMatchers/Dynamic/Registry.cpp | 2 ++ clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 8 ++++++++ 3 files changed, 23 insertions(+) diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index 5192ac3c9830..92fcced9d8d9 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -3673,6 +3673,19 @@ AST_MATCHER(QualType, isAnyCharacter) { return Node->isAnyCharacterType(); } +//// \brief Matches QualType nodes that are of any pointer type. +/// +/// Given +/// \code +/// int *i = nullptr; +/// int j; +/// \endcode +/// varDecl(hasType(isAnyPointer())) +/// matches "int *i", but not "int j". +AST_MATCHER(QualType, isAnyPointer) { + return Node->isAnyPointerType(); +} + /// \brief Matches QualType nodes that are const-qualified, i.e., that /// include "top-level" const. /// diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp index 8948d18e8f0f..e69688c5a62e 100644 --- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp +++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp @@ -264,6 +264,8 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(innerType); REGISTER_MATCHER(integerLiteral); REGISTER_MATCHER(isAnonymous); + REGISTER_MATCHER(isAnyCharacter); + REGISTER_MATCHER(isAnyPointer); REGISTER_MATCHER(isArrow); REGISTER_MATCHER(isBaseInitializer); REGISTER_MATCHER(isCatchAll); diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index 5578e066a222..4672fb8f335e 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -1479,6 +1479,14 @@ TEST(IsInteger, ReportsNoFalsePositives) { to(varDecl(hasType(isInteger())))))))); } +TEST(IsAnyPointer, MatchesPointers) { + EXPECT_TRUE(matches("int* i = nullptr;", varDecl(hasType(isAnyPointer())))); +} + +TEST(IsAnyPointer, ReportsNoFalsePositives) { + EXPECT_TRUE(notMatches("int i = 0;", varDecl(hasType(isAnyPointer())))); +} + TEST(IsAnyCharacter, MatchesCharacters) { EXPECT_TRUE(matches("char i = 0;", varDecl(hasType(isAnyCharacter())))); }