From a37e110def03a8829081a775e33f6b91a1fdd161 Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Thu, 1 Dec 2016 15:45:06 +0000 Subject: [PATCH] Adds hasUnqualifiedDesugaredType to allow matching through type sugar. Differential Revision: https://reviews.llvm.org/D27207 llvm-svn: 288366 --- clang/docs/LibASTMatchersReference.html | 260 +++++++++++---------- clang/include/clang/ASTMatchers/ASTMatchers.h | 16 ++ clang/lib/ASTMatchers/Dynamic/Registry.cpp | 1 + .../ASTMatchers/ASTMatchersTraversalTest.cpp | 9 + 4 files changed, 162 insertions(+), 124 deletions(-) diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html index 367ecde..69c58e9 100644 --- a/clang/docs/LibASTMatchersReference.html +++ b/clang/docs/LibASTMatchersReference.html @@ -3758,8 +3758,8 @@ Example 2 (conditional binary operator): matches opaqueValueExpr(condition) -Matcher<AddrLabelExpr>hasDeclarationMatcher<Decl> InnerMatcher -
Matches a node if the declaration associated with that node
+Matcher<AddrLabelExpr>hasDeclarationMatcher<Decl>  InnerMatcher
+
Matches a node if the declaration associated with that node
 matches the given matcher.
 
 The associated declaration is:
@@ -3772,13 +3772,13 @@ The associated declaration is:
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
 
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<CXXNewExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>,
-  Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>,
+  Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>,
+  Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>,
+  Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>,
+  Matcher<TagType>, Matcher<TemplateSpecializationType>,
+  Matcher<TemplateTypeParmType>, Matcher<TypedefType>,
+  Matcher<UnresolvedUsingType>
 
@@ -4004,13 +4004,13 @@ The associated declaration is: Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. -Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, - Matcher<CXXNewExpr>, - Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, - Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, - Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, - Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>, - Matcher<TypedefType>, Matcher<UnresolvedUsingType> +Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>, + Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, + Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, + Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, + Matcher<TagType>, Matcher<TemplateSpecializationType>, + Matcher<TemplateTypeParmType>, Matcher<TypedefType>, + Matcher<UnresolvedUsingType>
@@ -4174,8 +4174,8 @@ Example matches A() in the last line -Matcher<CXXNewExpr>hasDeclarationMatcher<Decl> InnerMatcher -
Matches a node if the declaration associated with that node
+Matcher<CXXNewExpr>hasDeclarationMatcher<Decl>  InnerMatcher
+
Matches a node if the declaration associated with that node
 matches the given matcher.
 
 The associated declaration is:
@@ -4188,13 +4188,13 @@ The associated declaration is:
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
 
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<CXXNewExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>,
-  Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>,
+  Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>,
+  Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>,
+  Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>,
+  Matcher<TagType>, Matcher<TemplateSpecializationType>,
+  Matcher<TemplateTypeParmType>, Matcher<TypedefType>,
+  Matcher<UnresolvedUsingType>
 
@@ -4323,13 +4323,13 @@ The associated declaration is: Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. -Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, - Matcher<CXXNewExpr>, - Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, - Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, - Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, - Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>, - Matcher<TypedefType>, Matcher<UnresolvedUsingType> +Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>, + Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, + Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, + Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, + Matcher<TagType>, Matcher<TemplateSpecializationType>, + Matcher<TemplateTypeParmType>, Matcher<TypedefType>, + Matcher<UnresolvedUsingType>
@@ -4438,8 +4438,8 @@ with compoundStmt() -Matcher<DeclRefExpr>hasDeclarationMatcher<Decl> InnerMatcher -
Matches a node if the declaration associated with that node
+Matcher<DeclRefExpr>hasDeclarationMatcher<Decl>  InnerMatcher
+
Matches a node if the declaration associated with that node
 matches the given matcher.
 
 The associated declaration is:
@@ -4452,13 +4452,13 @@ The associated declaration is:
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
 
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<CXXNewExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>,
-  Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>,
+  Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>,
+  Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>,
+  Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>,
+  Matcher<TagType>, Matcher<TemplateSpecializationType>,
+  Matcher<TemplateTypeParmType>, Matcher<TypedefType>,
+  Matcher<UnresolvedUsingType>
 
@@ -4602,8 +4602,8 @@ declaration of d.
-Matcher<EnumType>hasDeclarationMatcher<Decl> InnerMatcher -
Matches a node if the declaration associated with that node
+Matcher<EnumType>hasDeclarationMatcher<Decl>  InnerMatcher
+
Matches a node if the declaration associated with that node
 matches the given matcher.
 
 The associated declaration is:
@@ -4616,13 +4616,13 @@ The associated declaration is:
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
 
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<CXXNewExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>,
-  Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>,
+  Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>,
+  Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>,
+  Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>,
+  Matcher<TagType>, Matcher<TemplateSpecializationType>,
+  Matcher<TemplateTypeParmType>, Matcher<TypedefType>,
+  Matcher<UnresolvedUsingType>
 
@@ -4934,8 +4934,8 @@ FIXME: Unit test this matcher
-Matcher<InjectedClassNameType>hasDeclarationMatcher<Decl> InnerMatcher -
Matches a node if the declaration associated with that node
+Matcher<InjectedClassNameType>hasDeclarationMatcher<Decl>  InnerMatcher
+
Matches a node if the declaration associated with that node
 matches the given matcher.
 
 The associated declaration is:
@@ -4948,18 +4948,18 @@ The associated declaration is:
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
 
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<CXXNewExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>,
-  Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>,
+  Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>,
+  Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>,
+  Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>,
+  Matcher<TagType>, Matcher<TemplateSpecializationType>,
+  Matcher<TemplateTypeParmType>, Matcher<TypedefType>,
+  Matcher<UnresolvedUsingType>
 
-Matcher<LabelStmt>hasDeclarationMatcher<Decl> InnerMatcher -
Matches a node if the declaration associated with that node
+Matcher<LabelStmt>hasDeclarationMatcher<Decl>  InnerMatcher
+
Matches a node if the declaration associated with that node
 matches the given matcher.
 
 The associated declaration is:
@@ -4972,13 +4972,13 @@ The associated declaration is:
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
 
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<CXXNewExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>,
-  Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>,
+  Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>,
+  Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>,
+  Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>,
+  Matcher<TagType>, Matcher<TemplateSpecializationType>,
+  Matcher<TemplateTypeParmType>, Matcher<TypedefType>,
+  Matcher<UnresolvedUsingType>
 
@@ -4996,13 +4996,13 @@ The associated declaration is: Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. -Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, - Matcher<CXXNewExpr>, - Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, - Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, - Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, - Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>, - Matcher<TypedefType>, Matcher<UnresolvedUsingType> +Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>, + Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, + Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, + Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, + Matcher<TagType>, Matcher<TemplateSpecializationType>, + Matcher<TemplateTypeParmType>, Matcher<TypedefType>, + Matcher<UnresolvedUsingType>
@@ -5256,13 +5256,13 @@ The associated declaration is: Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. -Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, - Matcher<CXXNewExpr>, - Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, - Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, - Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, - Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>, - Matcher<TypedefType>, Matcher<UnresolvedUsingType> +Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>, + Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, + Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, + Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, + Matcher<TagType>, Matcher<TemplateSpecializationType>, + Matcher<TemplateTypeParmType>, Matcher<TypedefType>, + Matcher<UnresolvedUsingType>
@@ -5328,13 +5328,13 @@ The associated declaration is: Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. -Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, - Matcher<CXXNewExpr>, - Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, - Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, - Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, - Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>, - Matcher<TypedefType>, Matcher<UnresolvedUsingType> +Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>, + Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, + Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, + Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, + Matcher<TagType>, Matcher<TemplateSpecializationType>, + Matcher<TemplateTypeParmType>, Matcher<TypedefType>, + Matcher<UnresolvedUsingType> @@ -5457,13 +5457,13 @@ The associated declaration is: Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. -Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, - Matcher<CXXNewExpr>, - Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, - Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, - Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, - Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>, - Matcher<TypedefType>, Matcher<UnresolvedUsingType> +Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>, + Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, + Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, + Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, + Matcher<TagType>, Matcher<TemplateSpecializationType>, + Matcher<TemplateTypeParmType>, Matcher<TypedefType>, + Matcher<UnresolvedUsingType> @@ -5570,13 +5570,13 @@ The associated declaration is: Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. -Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, - Matcher<CXXNewExpr>, - Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, - Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, - Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, - Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>, - Matcher<TypedefType>, Matcher<UnresolvedUsingType> +Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>, + Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, + Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, + Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, + Matcher<TagType>, Matcher<TemplateSpecializationType>, + Matcher<TemplateTypeParmType>, Matcher<TypedefType>, + Matcher<UnresolvedUsingType> @@ -5614,13 +5614,13 @@ The associated declaration is: Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. -Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, - Matcher<CXXNewExpr>, - Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, - Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, - Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, - Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>, - Matcher<TypedefType>, Matcher<UnresolvedUsingType> +Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>, + Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, + Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, + Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, + Matcher<TagType>, Matcher<TemplateSpecializationType>, + Matcher<TemplateTypeParmType>, Matcher<TypedefType>, + Matcher<UnresolvedUsingType> @@ -5667,13 +5667,25 @@ The associated declaration is: Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. -Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, - Matcher<CXXNewExpr>, - Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, - Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, - Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, - Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>, - Matcher<TypedefType>, Matcher<UnresolvedUsingType> +Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>, + Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, + Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, + Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, + Matcher<TagType>, Matcher<TemplateSpecializationType>, + Matcher<TemplateTypeParmType>, Matcher<TypedefType>, + Matcher<UnresolvedUsingType> + + + +Matcher<Type>hasUnqualifiedDesugaredTypeMatcher<Type> InnerMatcher +
Matches if the matched type matches the unqualified desugared
+type of the matched node.
+
+For example, in:
+  class A {};
+  using B = A;
+The matcher type(hasUniqualifeidDesugaredType(recordType())) matches
+both B and A.
 
@@ -5710,13 +5722,13 @@ The associated declaration is: Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. -Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, - Matcher<CXXNewExpr>, - Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, - Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, - Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, - Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>, - Matcher<TypedefType>, Matcher<UnresolvedUsingType> +Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>, + Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, + Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, + Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, + Matcher<TagType>, Matcher<TemplateSpecializationType>, + Matcher<TemplateTypeParmType>, Matcher<TypedefType>, + Matcher<UnresolvedUsingType> diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index b558e7e..409786e 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -2738,6 +2738,22 @@ AST_MATCHER_P_OVERLOAD(QualType, pointsTo, internal::Matcher, .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, + InnerMatcher) { + return InnerMatcher.matches(*Node.getUnqualifiedDesugaredType(), Finder, + Builder); +} + /// \brief Matches if the matched type is a reference type and the referenced /// type matches the specified matcher. /// diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp index 9741a50..eca8a1a 100644 --- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp +++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp @@ -270,6 +270,7 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(hasUnaryOperand); REGISTER_MATCHER(hasUnarySelector); REGISTER_MATCHER(hasUnderlyingDecl); + REGISTER_MATCHER(hasUnqualifiedDesugaredType); REGISTER_MATCHER(hasValueType); REGISTER_MATCHER(ifStmt); REGISTER_MATCHER(ignoringImplicit); diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp index 08940b7..27f0669 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp @@ -247,6 +247,15 @@ TEST(HasDeclaration, HasDeclarationOfCXXNewExpr) { 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) { EXPECT_TRUE(matches("namespace N { template void f(T t); }" "template void g() { using N::f; f(T()); }", -- 2.7.4