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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260872
91177308-0d34-0410-b5e6-
96231b3b80d8
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.
///
REGISTER_MATCHER(innerType);
REGISTER_MATCHER(integerLiteral);
REGISTER_MATCHER(isAnonymous);
+ REGISTER_MATCHER(isAnyCharacter);
+ REGISTER_MATCHER(isAnyPointer);
REGISTER_MATCHER(isArrow);
REGISTER_MATCHER(isBaseInitializer);
REGISTER_MATCHER(isCatchAll);
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()))));
}