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
This commit is contained in:
Felix Berger 2016-02-15 04:00:39 +00:00
parent c0571e1261
commit cc9df3b9cc
3 changed files with 23 additions and 0 deletions

View File

@ -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.
///

View File

@ -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);

View File

@ -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()))));
}