-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[Clang][ASTMatcher] Add a matcher for the name of a DependentScopeDeclRefExpr #121656
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
Changes from 1 commit
4cd4888
e653a69
3ad4bd0
27bb7d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
|
||
|
|
||
| clang-format | ||
| ------------ | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3257,6 +3257,17 @@ AST_MATCHER_P(CXXDependentScopeMemberExpr, memberHasSameNameAsBoundNode, | |
| }); | ||
| } | ||
|
|
||
| /// Matches the dependent name of a dependent scope decl ref expr | ||
|
||
| /// | ||
| /// 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. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2235,6 +2235,21 @@ TEST_P(ASTMatchersTest, ArgumentCountIs_CXXConstructExpr) { | |
| Constructor1Arg)); | ||
| } | ||
|
|
||
| TEST_P(ASTMatchersTest, hasDependentName_DependentScopeDeclRefExpr) { | ||
|
||
| 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( | ||
|
||
| 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: | ||
|
|
||
There was a problem hiding this comment.
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