Skip to content

[Clang][ASTMatcher] Add dependentTemplateSpecializationType AST mat… #121435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions clang/docs/LibASTMatchersReference.html
Original file line number Diff line number Diff line change
Expand Up @@ -2546,6 +2546,17 @@ <h2 id="decl-matchers">Node Matchers</h2>
};
</pre></td></tr>

<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>&gt;</td><td class="name" onclick="toggle('dependentTemplateSpecializationType0')"><a name="dependentTemplateSpecializationType0Anchor">dependentTemplateSpecializationType</a></td><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1DependentTemplateSpecializationType.html">DependentTemplateSpecializationType</a>&gt;...</td></tr>
<tr><td colspan="4" class="doc" id="dependentTemplateSpecializationType0"><pre>Matches a dependent template specialization type.

Example matches A<T>::template B<T>

template<typename T> struct A;
template<typename T> struct declToImport {
typename A<T>::template B<T> a;
};
</pre></td></tr>

<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Type.html">Type</a>&gt;</td><td class="name" onclick="toggle('deducedTemplateSpecializationType0')"><a name="deducedTemplateSpecializationType0Anchor">deducedTemplateSpecializationType</a></td><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1DeducedTemplateSpecializationType.html">DeducedTemplateSpecializationType</a>&gt;...</td></tr>
<tr><td colspan="4" class="doc" id="deducedTemplateSpecializationType0"><pre>Matches C++17 deduced template specialization types, e.g. deduced class
template types.
Expand Down
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,8 @@ AST Matchers

- Add ``dependentNameType`` matcher to match a dependent name type.

- Add ``dependentTemplateSpecializationType`` matcher to match a dependent template specialization type.

clang-format
------------

Expand Down
12 changes: 12 additions & 0 deletions clang/include/clang/ASTMatchers/ASTMatchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7721,6 +7721,18 @@ AST_MATCHER_P(DecayedType, hasDecayedType, internal::Matcher<QualType>,
/// \endcode
extern const AstTypeMatcher<DependentNameType> dependentNameType;

/// Matches a dependent template specialization type
///
/// Example matches A<T>::template B<T>
/// \code
/// template<typename T> struct A;
/// template<typename T> struct declToImport {
/// typename A<T>::template B<T> a;
/// };
/// \endcode
extern const AstTypeMatcher<DependentTemplateSpecializationType>
dependentTemplateSpecializationType;

/// Matches declarations whose declaration context, interpreted as a
/// Decl, matches \c InnerMatcher.
///
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/ASTMatchers/ASTMatchersInternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,8 @@ const AstTypeMatcher<TemplateTypeParmType> templateTypeParmType;
const AstTypeMatcher<InjectedClassNameType> injectedClassNameType;
const AstTypeMatcher<DecayedType> decayedType;
const AstTypeMatcher<DependentNameType> dependentNameType;
const AstTypeMatcher<DependentTemplateSpecializationType>
dependentTemplateSpecializationType;
AST_TYPELOC_TRAVERSE_MATCHER_DEF(hasElementType,
AST_POLYMORPHIC_SUPPORTED_TYPES(ArrayType,
ComplexType));
Expand Down
1 change: 1 addition & 0 deletions clang/lib/ASTMatchers/Dynamic/Registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(declRefExpr);
REGISTER_MATCHER(dependentNameType);
REGISTER_MATCHER(dependentScopeDeclRefExpr);
REGISTER_MATCHER(dependentTemplateSpecializationType);
REGISTER_MATCHER(declStmt);
REGISTER_MATCHER(declaratorDecl);
REGISTER_MATCHER(decltypeType);
Expand Down
4 changes: 0 additions & 4 deletions clang/unittests/AST/ASTImporterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,10 +763,6 @@ TEST_P(ImportType, ImportPackExpansion) {
implicitCastExpr(has(declRefExpr()))))))));
}

const internal::VariadicDynCastAllOfMatcher<Type,
DependentTemplateSpecializationType>
dependentTemplateSpecializationType;

TEST_P(ImportType, ImportDependentTemplateSpecialization) {
MatchVerifier<Decl> Verifier;
testImport("template<typename T>"
Expand Down
15 changes: 15 additions & 0 deletions clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,21 @@ TEST_P(ASTMatchersTest, DependentNameType) {
dependentNameType()));
}

TEST_P(ASTMatchersTest, DependentTemplateSpecializationType) {
if (!GetParam().isCXX()) {
return;
}

EXPECT_TRUE(matches(
R"(
template<typename T> struct A;
template<typename T> struct declToImport {
typename A<T>::template B<T> a;
};
)",
dependentTemplateSpecializationType()));
}

TEST_P(ASTMatchersTest, RecordType) {
EXPECT_TRUE(matches("struct S {}; struct S s;",
recordType(hasDeclaration(recordDecl(hasName("S"))))));
Expand Down
Loading