Add a new matcher to match character types.

llvm-svn: 255627
This commit is contained in:
Gabor Horvath 2015-12-15 08:35:45 +00:00
parent e3556420c1
commit 009c5d52e3
2 changed files with 22 additions and 0 deletions

View File

@ -3533,6 +3533,20 @@ AST_MATCHER(QualType, isInteger) {
return Node->isIntegerType();
}
/// \brief Matches QualType nodes that are of character type.
///
/// Given
/// \code
/// void a(char);
/// void b(wchar_t);
/// void c(double);
/// \endcode
/// functionDecl(hasAnyParameter(hasType(isAnyCharacter())))
/// matches "a(char)", "b(wchar_t)", but not "c(double)".
AST_MATCHER(QualType, isAnyCharacter) {
return Node->isAnyCharacterType();
}
/// \brief Matches QualType nodes that are const-qualified, i.e., that
/// include "top-level" const.
///

View File

@ -1469,6 +1469,14 @@ TEST(IsInteger, ReportsNoFalsePositives) {
to(varDecl(hasType(isInteger()))))))));
}
TEST(IsAnyCharacter, MatchesCharacters) {
EXPECT_TRUE(matches("char i = 0;", varDecl(hasType(isAnyCharacter()))));
}
TEST(IsAnyCharacter, ReportsNoFalsePositives) {
EXPECT_TRUE(notMatches("int i;", varDecl(hasType(isAnyCharacter()))));
}
TEST(IsArrow, MatchesMemberVariablesViaArrow) {
EXPECT_TRUE(matches("class Y { void x() { this->y; } int y; };",
memberExpr(isArrow())));