Author: malcolm.parsons Date: Thu Dec 8 05:46:22 2016 New Revision: 289042
URL: http://llvm.org/viewvc/llvm-project?rev=289042&view=rev Log: [ASTMatcher] Add hasReplacementType matcher for SubstTemplateTypeParmType Summary: Needed for https://reviews.llvm.org/D27166 Reviewers: sbenza, bkramer, klimek Subscribers: aemerson, cfe-commits Differential Revision: https://reviews.llvm.org/D27447 Modified: cfe/trunk/docs/LibASTMatchersReference.html 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=289042&r1=289041&r2=289042&view=diff ============================================================================== --- cfe/trunk/docs/LibASTMatchersReference.html (original) +++ cfe/trunk/docs/LibASTMatchersReference.html Thu Dec 8 05:46:22 2016 @@ -5421,6 +5421,20 @@ sizeof. </pre></td></tr> +<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1SubstTemplateTypeParmType.html">SubstTemplateTypeParmType</a>></td><td class="name" onclick="toggle('hasReplacementType0')"><a name="hasReplacementType0Anchor">hasReplacementType</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>></td></tr> +<tr><td colspan="4" class="doc" id="hasReplacementType0"><pre>Matches template type parameter substitutions that have a replacement +type that matches the provided matcher. + +Given + template <typename T> + double F(T t); + int i; + double j = F(i); + +substTemplateTypeParmType(hasReplacementType(type())) matches int +</pre></td></tr> + + <tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1SwitchStmt.html">SwitchStmt</a>></td><td class="name" onclick="toggle('forEachSwitchCase0')"><a name="forEachSwitchCase0Anchor">forEachSwitchCase</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1SwitchCase.html">SwitchCase</a>> InnerMatcher</td></tr> <tr><td colspan="4" class="doc" id="forEachSwitchCase0"><pre>Matches each case or default statement belonging to the given switch statement. This matcher may produce multiple matches. Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=289042&r1=289041&r2=289042&view=diff ============================================================================== --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original) +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Thu Dec 8 05:46:22 2016 @@ -5019,6 +5019,22 @@ AST_MATCHER_P(ElaboratedType, namesType, /// \c substTemplateTypeParmType() matches the type of 't' but not '1' AST_TYPE_MATCHER(SubstTemplateTypeParmType, substTemplateTypeParmType); +/// \brief Matches template type parameter substitutions that have a replacement +/// type that matches the provided matcher. +/// +/// Given +/// \code +/// template <typename T> +/// double F(T t); +/// int i; +/// double j = F(i); +/// \endcode +/// +/// \c substTemplateTypeParmType(hasReplacementType(type())) matches int +AST_TYPE_TRAVERSE_MATCHER( + hasReplacementType, getReplacementType, + AST_POLYMORPHIC_SUPPORTED_TYPES(SubstTemplateTypeParmType)); + /// \brief Matches template type parameter types. /// /// Example matches T, but not int. Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=289042&r1=289041&r2=289042&view=diff ============================================================================== --- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original) +++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Thu Dec 8 05:46:22 2016 @@ -252,6 +252,7 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(hasQualifier); REGISTER_MATCHER(hasRangeInit); REGISTER_MATCHER(hasReceiverType); + REGISTER_MATCHER(hasReplacementType); REGISTER_MATCHER(hasReturnValue); REGISTER_MATCHER(hasRHS); REGISTER_MATCHER(hasSelector); Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp?rev=289042&r1=289041&r2=289042&view=diff ============================================================================== --- cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp (original) +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp Thu Dec 8 05:46:22 2016 @@ -2204,5 +2204,22 @@ TEST(Matcher, HasAnyDeclaration) { functionDecl(hasName("bar")))))); } +TEST(SubstTemplateTypeParmType, HasReplacementType) +{ + std::string Fragment = "template<typename T>" + "double F(T t);" + "int i;" + "double j = F(i);"; + EXPECT_TRUE(matches(Fragment, substTemplateTypeParmType(hasReplacementType( + qualType(asString("int")))))); + EXPECT_TRUE(notMatches(Fragment, substTemplateTypeParmType(hasReplacementType( + qualType(asString("double")))))); + EXPECT_TRUE( + notMatches("template<int N>" + "double F();" + "double j = F<5>();", + substTemplateTypeParmType(hasReplacementType(qualType())))); +} + } // namespace ast_matchers } // namespace clang _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits