Author: congliu Date: Fri Jun 24 04:38:03 2016 New Revision: 273659 URL: http://llvm.org/viewvc/llvm-project?rev=273659&view=rev Log: IgnoringImplicit matcher.
Modified: cfe/trunk/docs/LibASTMatchersReference.html cfe/trunk/docs/tools/dump_ast_matchers.py (contents, props changed) cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp Modified: cfe/trunk/docs/LibASTMatchersReference.html URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=273659&r1=273658&r2=273659&view=diff ============================================================================== --- cfe/trunk/docs/LibASTMatchersReference.html (original) +++ cfe/trunk/docs/LibASTMatchersReference.html Fri Jun 24 04:38:03 2016 @@ -2347,7 +2347,7 @@ Given private: int c; }; fieldDecl(isPrivate()) - matches 'int c;' + matches 'int c;' </pre></td></tr> @@ -2361,7 +2361,7 @@ Given private: int c; }; fieldDecl(isProtected()) - matches 'int b;' + matches 'int b;' </pre></td></tr> @@ -2375,7 +2375,7 @@ Given private: int c; }; fieldDecl(isPublic()) - matches 'int a;' + matches 'int a;' </pre></td></tr> @@ -4455,6 +4455,25 @@ only match the declarations for b, c, an </pre></td></tr> +<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('ignoringImplicit0')"><a name="ignoringImplicit0Anchor">ignoringImplicit</a></td><td>ast_matchers::Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> +<tr><td colspan="4" class="doc" id="ignoringImplicit0"><pre>Matches expressions that match InnerMatcher after any implicit AST +nodes are stripped off. + +Parentheses and explicit casts are not discarded. +Given + class C {}; + C a = C(); + C b; + C c = b; +The matchers + varDecl(hasInitializer(ignoringImplicit(cxxConstructExpr()))) +would match the declarations for a, b, and c. +While + varDecl(hasInitializer(cxxConstructExpr())) +only match the declarations for b and c. +</pre></td></tr> + + <tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>></td><td class="name" onclick="toggle('ignoringParenCasts0')"><a name="ignoringParenCasts0Anchor">ignoringParenCasts</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> <tr><td colspan="4" class="doc" id="ignoringParenCasts0"><pre>Matches expressions that match InnerMatcher after parentheses and casts are stripped off. Modified: cfe/trunk/docs/tools/dump_ast_matchers.py URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/tools/dump_ast_matchers.py?rev=273659&r1=273658&r2=273659&view=diff ============================================================================== (empty) Propchange: cfe/trunk/docs/tools/dump_ast_matchers.py ------------------------------------------------------------------------------ svn:executable = * Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=273659&r1=273658&r2=273659&view=diff ============================================================================== --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original) +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Jun 24 04:38:03 2016 @@ -548,6 +548,32 @@ AST_POLYMORPHIC_MATCHER_P( Builder); } +/// \brief Matches expressions that match InnerMatcher after any implicit AST +/// nodes are stripped off. +/// +/// Parentheses and explicit casts are not discarded. +/// Given +/// \code +/// class C {}; +/// C a = C(); +/// C b; +/// C c = b; +/// \endcode +/// The matchers +/// \code +/// varDecl(hasInitializer(ignoringImplicit(cxxConstructExpr()))) +/// \endcode +/// would match the declarations for a, b, and c. +/// While +/// \code +/// varDecl(hasInitializer(cxxConstructExpr())) +/// \endcode +/// only match the declarations for b and c. +AST_MATCHER_P(Expr, ignoringImplicit, ast_matchers::internal::Matcher<Expr>, + InnerMatcher) { + return InnerMatcher.matches(*Node.IgnoreImplicit(), Finder, Builder); +} + /// \brief Matches expressions that match InnerMatcher after any implicit casts /// are stripped off. /// Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=273659&r1=273658&r2=273659&view=diff ============================================================================== --- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original) +++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Fri Jun 24 04:38:03 2016 @@ -265,6 +265,7 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(hasUnarySelector); REGISTER_MATCHER(hasValueType); REGISTER_MATCHER(ifStmt); + REGISTER_MATCHER(ignoringImplicit); REGISTER_MATCHER(ignoringImpCasts); REGISTER_MATCHER(ignoringParenCasts); REGISTER_MATCHER(ignoringParenImpCasts); Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp?rev=273659&r1=273658&r2=273659&view=diff ============================================================================== --- cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp (original) +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp Fri Jun 24 04:38:03 2016 @@ -1088,6 +1088,16 @@ TEST(HasImplicitDestinationType, DoesNot unless(anything()))))); } +TEST(IgnoringImplicit, MatchesImplicit) { + EXPECT_TRUE(matches("class C {}; C a = C();", + varDecl(has(ignoringImplicit(cxxConstructExpr()))))); +} + +TEST(IgnoringImplicit, DoesNotMatchIncorrectly) { + EXPECT_TRUE( + notMatches("class C {}; C a = C();", varDecl(has(cxxConstructExpr())))); +} + TEST(IgnoringImpCasts, MatchesImpCasts) { // This test checks that ignoringImpCasts matches when implicit casts are // present and its inner matcher alone does not match. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits