Index: cfe/trunk/docs/LibASTMatchersReference.html =================================================================== --- cfe/trunk/docs/LibASTMatchersReference.html +++ cfe/trunk/docs/LibASTMatchersReference.html @@ -1448,6 +1448,21 @@ +
Matches enum types. + +Given + enum C { Green }; + enum S { Red }; + + C c; + S s; + +enumType() matches the type of the variable declarations of both c and +s. +
Matches FunctionProtoType nodes. Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h @@ -4654,6 +4654,21 @@ /// matches "typedef int X" AST_TYPE_MATCHER(TypedefType, typedefType); +/// \brief Matches enum types. +/// +/// Given +/// \code +/// enum C { Green }; +/// enum class S { Red }; +/// +/// C c; +/// S s; +/// \endcode +// +/// \c enumType() matches the type of the variable declarations of both \c c and +/// \c s. +AST_TYPE_MATCHER(EnumType, enumType); + /// \brief Matches template specialization types. /// /// Given Index: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp =================================================================== --- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp +++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp @@ -171,6 +171,7 @@ REGISTER_MATCHER(elaboratedType); REGISTER_MATCHER(enumConstantDecl); REGISTER_MATCHER(enumDecl); + REGISTER_MATCHER(enumType); REGISTER_MATCHER(equalsBoundNode); REGISTER_MATCHER(equalsIntegralValue); REGISTER_MATCHER(explicitCastExpr); Index: cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp =================================================================== --- cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -1299,6 +1299,13 @@ hasType(rValueReferenceType())))); } +TEST(TypeMatching, MatchesEnumTypes) { + EXPECT_TRUE(matches("enum Color { Green }; Color color;", + loc(enumType()))); + EXPECT_TRUE(matches("enum class Color { Green }; Color color;", + loc(enumType()))); +} + TEST(TypeMatching, MatchesPointersToConstTypes) { EXPECT_TRUE(matches("int b; int * const a = &b;", loc(pointerType())));