From: Samuel Benzaquen Date: Tue, 22 Dec 2015 20:06:40 +0000 (+0000) Subject: [ASTMatchers] Add booleanType() matcher. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7de4c1419d119986cace639e9b8be3ff3dc4df2b;p=clang [ASTMatchers] Add booleanType() matcher. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256278 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index 6fcae748d8..7eebe4e411 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -3762,6 +3762,18 @@ AST_MATCHER_FUNCTION_P_OVERLOAD(internal::BindableMatcher, loc, new internal::TypeLocTypeMatcher(InnerMatcher)); } +/// \brief Matches type \c bool. +/// +/// Given +/// \code +/// struct S { bool func(); }; +/// \endcode +/// functionDecl(returns(boolType())) +/// matches "bool func();" +AST_MATCHER(Type, booleanType) { + return Node.isBooleanType(); +} + /// \brief Matches type \c void. /// /// Given diff --git a/lib/ASTMatchers/Dynamic/Registry.cpp b/lib/ASTMatchers/Dynamic/Registry.cpp index 762be25e91..5b1c5529aa 100644 --- a/lib/ASTMatchers/Dynamic/Registry.cpp +++ b/lib/ASTMatchers/Dynamic/Registry.cpp @@ -108,6 +108,7 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(autoType); REGISTER_MATCHER(binaryOperator); REGISTER_MATCHER(blockPointerType); + REGISTER_MATCHER(booleanType); REGISTER_MATCHER(breakStmt); REGISTER_MATCHER(builtinType); REGISTER_MATCHER(callExpr); diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 80f234338a..cd18df8410 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -4146,6 +4146,13 @@ TEST(TypeMatching, MatchesTypes) { EXPECT_TRUE(matches("struct S {};", qualType().bind("loc"))); } +TEST(TypeMatching, MatchesBool) { + EXPECT_TRUE(matches("struct S { bool func(); };", + cxxMethodDecl(returns(booleanType())))); + EXPECT_TRUE(notMatches("struct S { void func(); };", + cxxMethodDecl(returns(booleanType())))); +} + TEST(TypeMatching, MatchesVoid) { EXPECT_TRUE(matches("struct S { void func(); };", cxxMethodDecl(returns(voidType()))));