From 55578fd5fc25207ae43b5b36b3d097d00ac5f919 Mon Sep 17 00:00:00 2001 From: Samuel Benzaquen Date: Wed, 26 Aug 2015 16:15:59 +0000 Subject: [PATCH] [ASTMatchers] Add type matcher for SubstTemplateTypeParmType. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@246037 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/ASTMatchers/ASTMatchers.h | 14 ++++++++++++++ lib/ASTMatchers/Dynamic/Registry.cpp | 1 + unittests/ASTMatchers/ASTMatchersTest.cpp | 12 ++++++++++++ 3 files changed, 27 insertions(+) diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index cd80bab8db..46f30f06d5 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -3936,6 +3936,20 @@ AST_MATCHER_P(ElaboratedType, namesType, internal::Matcher, return InnerMatcher.matches(Node.getNamedType(), Finder, Builder); } +/// \brief Matches types that represent the result of substituting a type for a +/// template type parameter. +/// +/// Given +/// \code +/// template +/// void F(T t) { +/// int i = 1 + t; +/// } +/// \code +/// +/// \c substTemplateTypeParmType() matches the type of 't' but not '1' +AST_TYPE_MATCHER(SubstTemplateTypeParmType, substTemplateTypeParmType); + /// \brief Matches declarations whose declaration context, interpreted as a /// Decl, matches \c InnerMatcher. /// diff --git a/lib/ASTMatchers/Dynamic/Registry.cpp b/lib/ASTMatchers/Dynamic/Registry.cpp index 19cad2554b..1544b08434 100644 --- a/lib/ASTMatchers/Dynamic/Registry.cpp +++ b/lib/ASTMatchers/Dynamic/Registry.cpp @@ -327,6 +327,7 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(stmt); REGISTER_MATCHER(stringLiteral); REGISTER_MATCHER(substNonTypeTemplateParmExpr); + REGISTER_MATCHER(substTemplateTypeParmType); REGISTER_MATCHER(switchCase); REGISTER_MATCHER(switchStmt); REGISTER_MATCHER(templateArgument); diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index c04f0fb82d..5bc66f6c03 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -4331,6 +4331,18 @@ TEST(ElaboratedTypeNarrowing, namesType) { elaboratedType(elaboratedType(namesType(typedefType()))))); } +TEST(TypeMatching, MatchesSubstTemplateTypeParmType) { + const std::string code = "template " + "int F() {" + " return 1 + T();" + "}" + "int i = F();"; + EXPECT_FALSE(matches(code, binaryOperator(hasLHS( + expr(hasType(substTemplateTypeParmType())))))); + EXPECT_TRUE(matches(code, binaryOperator(hasRHS( + expr(hasType(substTemplateTypeParmType())))))); +} + TEST(NNS, MatchesNestedNameSpecifiers) { EXPECT_TRUE(matches("namespace ns { struct A {}; } ns::A a;", nestedNameSpecifier())); -- 2.40.0