Author: aaronballman Date: Wed Nov 29 13:21:51 2017 New Revision: 319360 URL: http://llvm.org/viewvc/llvm-project?rev=319360&view=rev Log: Add the hasDefinition() AST matcher to match class declarations that also have a definition.
Patch by Julie Hockett. Modified: cfe/trunk/docs/LibASTMatchersReference.html cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Modified: cfe/trunk/docs/LibASTMatchersReference.html URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=319360&r1=319359&r2=319360&view=diff ============================================================================== --- cfe/trunk/docs/LibASTMatchersReference.html (original) +++ cfe/trunk/docs/LibASTMatchersReference.html Wed Nov 29 13:21:51 2017 @@ -2307,6 +2307,15 @@ Usable as: Matcher<<a href="http://cl </pre></td></tr> +<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('hasDefinition0')"><a name="hasDefinition0Anchor">hasDefinition</a></td><td></td></tr> +<tr><td colspan="4" class="doc" id="hasDefinition0"><pre>Matches a class declaration that is defined. + +Example matches x (matcher = cxxRecordDecl(hasDefinition())) +class x {}; +class y; +</pre></td></tr> + + <tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html">CXXRecordDecl</a>></td><td class="name" onclick="toggle('isDerivedFrom1')"><a name="isDerivedFrom1Anchor">isDerivedFrom</a></td><td>std::string BaseName</td></tr> <tr><td colspan="4" class="doc" id="isDerivedFrom1"><pre>Overloaded method as shortcut for isDerivedFrom(hasName(...)). </pre></td></tr> Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=319360&r1=319359&r2=319360&view=diff ============================================================================== --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original) +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Wed Nov 29 13:21:51 2017 @@ -5853,6 +5853,17 @@ AST_MATCHER_P(CXXNewExpr, hasArraySize, InnerMatcher.matches(*Node.getArraySize(), Finder, Builder); } +/// \brief Matches a class declaration that is defined. +/// +/// Example matches x (matcher = cxxRecordDecl(hasDefinition())) +/// \code +/// class x {}; +/// class y; +/// \endcode +AST_MATCHER(CXXRecordDecl, hasDefinition) { + return Node.hasDefinition(); +} + } // namespace ast_matchers } // namespace clang Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=319360&r1=319359&r2=319360&view=diff ============================================================================== --- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original) +++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Wed Nov 29 13:21:51 2017 @@ -250,6 +250,7 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(hasDeclContext); REGISTER_MATCHER(hasDeducedType); REGISTER_MATCHER(hasDefaultArgument); + REGISTER_MATCHER(hasDefinition); REGISTER_MATCHER(hasDescendant); REGISTER_MATCHER(hasDestinationType); REGISTER_MATCHER(hasDynamicExceptionSpec); Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp?rev=319360&r1=319359&r2=319360&view=diff ============================================================================== --- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp (original) +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Wed Nov 29 13:21:51 2017 @@ -2008,5 +2008,26 @@ TEST(HasArraySize, Basic) { cxxNewExpr(hasArraySize(integerLiteral(equals(10)))))); } +TEST(HasDefinition, MatchesStructDefinition) { + EXPECT_TRUE(matches("struct x {};", + cxxRecordDecl(hasDefinition()))); + EXPECT_TRUE(notMatches("struct x;", + cxxRecordDecl(hasDefinition()))); +} + +TEST(HasDefinition, MatchesClassDefinition) { + EXPECT_TRUE(matches("class x {};", + cxxRecordDecl(hasDefinition()))); + EXPECT_TRUE(notMatches("class x;", + cxxRecordDecl(hasDefinition()))); +} + +TEST(HasDefinition, MatchesUnionDefinition) { + EXPECT_TRUE(matches("union x {};", + cxxRecordDecl(hasDefinition()))); + EXPECT_TRUE(notMatches("union x;", + cxxRecordDecl(hasDefinition()))); +} + } // namespace ast_matchers } // namespace clang _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits