From 598a06b9066ab5176456fa50b6f8eff6a72bac25 Mon Sep 17 00:00:00 2001 From: Gabor Horvath Date: Tue, 15 Dec 2015 08:35:45 +0000 Subject: [PATCH] Add a new matcher to match character types. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255627 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/ASTMatchers/ASTMatchers.h | 14 ++++++++++++++ unittests/ASTMatchers/ASTMatchersTest.cpp | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index 6a5f5ee57c..6fcae748d8 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -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. /// diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 9aefb07809..80f234338a 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -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()))); -- 2.40.0