Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions clang/docs/LibASTMatchersReference.html
Original file line number Diff line number Diff line change
Expand Up @@ -3449,6 +3449,19 @@ <h2 id="narrowing-matchers">Narrowing Matchers</h2>
</pre></td></tr>


<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1DependentScopeDeclRefExpr.html">DependentScopeDeclRefExpr</a>&gt;</td><td class="name" onclick="toggle('hasDependentName0')"><a name="hasDependentName0Anchor">hasDependentName</a></td><td>std::string N</td></tr>
<tr><td colspan="4" class="doc" id="hasDependentName0"><pre>Matches the dependent name of a dependent scope decl ref expr.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "of a DependentScopeDeclRefExpr" would read better to me


Matches the dependent name of a dependent scope decl ref expr

Given:

template &lt;class T&lt; class X : T { void f() { T::v; } };

dependentScopeDeclRefExpr(hasDependentName("v")) matches `T::v`
</pre></td></tr>


<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1CXXDependentScopeMemberExpr.html">CXXDependentScopeMemberExpr</a>&gt;</td><td class="name" onclick="toggle('memberHasSameNameAsBoundNode0')"><a name="memberHasSameNameAsBoundNode0Anchor">memberHasSameNameAsBoundNode</a></td><td>std::string BindingID</td></tr>
<tr><td colspan="4" class="doc" id="memberHasSameNameAsBoundNode0"><pre>Matches template-dependent, but known, member names against an already-bound
node
Expand Down
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,8 @@ AST Matchers

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

- Add ``hasDependentName`` matcher to match the dependent name of a dependent scope decl ref expr.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise here, "of a DependentScopeDeclRefExpr"


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

Expand Down
11 changes: 11 additions & 0 deletions clang/include/clang/ASTMatchers/ASTMatchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3257,6 +3257,17 @@ AST_MATCHER_P(CXXDependentScopeMemberExpr, memberHasSameNameAsBoundNode,
});
}

/// Matches the dependent name of a dependent scope decl ref expr
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise here, "of a DependentScopeDeclRefExpr"

///
/// Given:
/// \code
/// template <class T> class X : T { void f() { T::v; } };
/// \endcode
/// \c dependentScopeDeclRefExpr(hasDependentName("v")) matches `T::v`
AST_MATCHER_P(DependentScopeDeclRefExpr, hasDependentName, std::string, N) {
return Node.getDeclName().getAsString() == N;
}

/// Matches C++ classes that are directly or indirectly derived from a class
/// matching \c Base, or Objective-C classes that directly or indirectly
/// subclass a class matching \c Base.
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 @@ -314,6 +314,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(hasDeducedType);
REGISTER_MATCHER(hasDefaultArgument);
REGISTER_MATCHER(hasDefinition);
REGISTER_MATCHER(hasDependentName);
REGISTER_MATCHER(hasDescendant);
REGISTER_MATCHER(hasDestinationType);
REGISTER_MATCHER(hasDirectBase);
Expand Down
15 changes: 15 additions & 0 deletions clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2235,6 +2235,21 @@ TEST_P(ASTMatchersTest, ArgumentCountIs_CXXConstructExpr) {
Constructor1Arg));
}

TEST_P(ASTMatchersTest, hasDependentName_DependentScopeDeclRefExpr) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: looking at other tests in this file, the test names start with a capital letter (e.g. HasSize_CXX) even if the matcher they are testing starts with lowercase (e.g. hasSize)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if (!GetParam().isCXX() || GetParam().hasDelayedTemplateParsing()) {
// FIXME: Fix this test to work with delayed template parsing.
return;
}

EXPECT_TRUE(matches("template <class T> class X : T { void f() { T::v; } };",
dependentScopeDeclRefExpr(hasDependentName("v"))));

EXPECT_TRUE(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have a test case where the dependent name refers to a function (specifically a static member function, since I think that will get a DependentScopeDeclRefExpr rather than a CXXDepdendentScopeMemberExpr).

Come to think of it, this applies for the test for dependentScopeDeclRefExpr itself.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thank you for suggesting it :D

matches("template <typename T> struct S { static T Foo; };"
"template <typename T> void declToImport() { (void)S<T>::Foo; }",
dependentScopeDeclRefExpr(hasDependentName("Foo"))));
}

TEST(ASTMatchersTest, NamesMember_CXXDependentScopeMemberExpr) {

// Member functions:
Expand Down
Loading