Skip to content
Snippets Groups Projects
Commit 441c3af1 authored by Manuel Klimek's avatar Manuel Klimek
Browse files

Adds hasUnqualifiedDesugaredType to allow matching through type sugar.

Differential Revision: https://reviews.llvm.org/D27207

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288366 91177308-0d34-0410-b5e6-96231b3b80d8
parent 0eded94a
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
...@@ -2738,6 +2738,22 @@ AST_MATCHER_P_OVERLOAD(QualType, pointsTo, internal::Matcher<Decl>, ...@@ -2738,6 +2738,22 @@ AST_MATCHER_P_OVERLOAD(QualType, pointsTo, internal::Matcher<Decl>,
.matches(Node, Finder, Builder); .matches(Node, Finder, Builder);
} }
/// \brief Matches if the matched type matches the unqualified desugared
/// type of the matched node.
///
/// For example, in:
/// \code
/// class A {};
/// using B = A;
/// \endcode
/// The matcher type(hasUniqualifeidDesugaredType(recordType())) matches
/// both B and A.
AST_MATCHER_P(Type, hasUnqualifiedDesugaredType, internal::Matcher<Type>,
InnerMatcher) {
return InnerMatcher.matches(*Node.getUnqualifiedDesugaredType(), Finder,
Builder);
}
/// \brief Matches if the matched type is a reference type and the referenced /// \brief Matches if the matched type is a reference type and the referenced
/// type matches the specified matcher. /// type matches the specified matcher.
/// ///
......
...@@ -270,6 +270,7 @@ RegistryMaps::RegistryMaps() { ...@@ -270,6 +270,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(hasUnaryOperand); REGISTER_MATCHER(hasUnaryOperand);
REGISTER_MATCHER(hasUnarySelector); REGISTER_MATCHER(hasUnarySelector);
REGISTER_MATCHER(hasUnderlyingDecl); REGISTER_MATCHER(hasUnderlyingDecl);
REGISTER_MATCHER(hasUnqualifiedDesugaredType);
REGISTER_MATCHER(hasValueType); REGISTER_MATCHER(hasValueType);
REGISTER_MATCHER(ifStmt); REGISTER_MATCHER(ifStmt);
REGISTER_MATCHER(ignoringImplicit); REGISTER_MATCHER(ignoringImplicit);
......
...@@ -247,6 +247,15 @@ TEST(HasDeclaration, HasDeclarationOfCXXNewExpr) { ...@@ -247,6 +247,15 @@ TEST(HasDeclaration, HasDeclarationOfCXXNewExpr) {
cxxNewExpr(hasDeclaration(functionDecl(parameterCountIs(1)))))); cxxNewExpr(hasDeclaration(functionDecl(parameterCountIs(1))))));
} }
TEST(HasUnqualifiedDesugaredType, DesugarsUsing) {
EXPECT_TRUE(
matches("struct A {}; using B = A; B b;",
varDecl(hasType(hasUnqualifiedDesugaredType(recordType())))));
EXPECT_TRUE(
matches("struct A {}; using B = A; using C = B; C b;",
varDecl(hasType(hasUnqualifiedDesugaredType(recordType())))));
}
TEST(HasUnderlyingDecl, Matches) { TEST(HasUnderlyingDecl, Matches) {
EXPECT_TRUE(matches("namespace N { template <class T> void f(T t); }" EXPECT_TRUE(matches("namespace N { template <class T> void f(T t); }"
"template <class T> void g() { using N::f; f(T()); }", "template <class T> void g() { using N::f; f(T()); }",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment