forked from OSchip/llvm-project
[ASTMatchers] Add booleanType() matcher.
llvm-svn: 256278
This commit is contained in:
parent
a61deb249b
commit
bd3232af03
clang
include/clang/ASTMatchers
lib/ASTMatchers/Dynamic
unittests/ASTMatchers
|
@ -3762,6 +3762,18 @@ AST_MATCHER_FUNCTION_P_OVERLOAD(internal::BindableMatcher<TypeLoc>, loc,
|
||||||
new internal::TypeLocTypeMatcher(InnerMatcher));
|
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.
|
/// \brief Matches type \c void.
|
||||||
///
|
///
|
||||||
/// Given
|
/// Given
|
||||||
|
|
|
@ -108,6 +108,7 @@ RegistryMaps::RegistryMaps() {
|
||||||
REGISTER_MATCHER(autoType);
|
REGISTER_MATCHER(autoType);
|
||||||
REGISTER_MATCHER(binaryOperator);
|
REGISTER_MATCHER(binaryOperator);
|
||||||
REGISTER_MATCHER(blockPointerType);
|
REGISTER_MATCHER(blockPointerType);
|
||||||
|
REGISTER_MATCHER(booleanType);
|
||||||
REGISTER_MATCHER(breakStmt);
|
REGISTER_MATCHER(breakStmt);
|
||||||
REGISTER_MATCHER(builtinType);
|
REGISTER_MATCHER(builtinType);
|
||||||
REGISTER_MATCHER(callExpr);
|
REGISTER_MATCHER(callExpr);
|
||||||
|
|
|
@ -4146,6 +4146,13 @@ TEST(TypeMatching, MatchesTypes) {
|
||||||
EXPECT_TRUE(matches("struct S {};", qualType().bind("loc")));
|
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) {
|
TEST(TypeMatching, MatchesVoid) {
|
||||||
EXPECT_TRUE(matches("struct S { void func(); };",
|
EXPECT_TRUE(matches("struct S { void func(); };",
|
||||||
cxxMethodDecl(returns(voidType()))));
|
cxxMethodDecl(returns(voidType()))));
|
||||||
|
|
Loading…
Reference in New Issue