diff options
| author | Anton Bikineev <ant.bikineev@gmail.com> | 2019-07-25 11:54:13 +0000 |
|---|---|---|
| committer | Anton Bikineev <ant.bikineev@gmail.com> | 2019-07-25 11:54:13 +0000 |
| commit | 4e1d188be2868aef71f8603f28ca4703723cb97a (patch) | |
| tree | 277a14a406721769509fe9c0c3584738da32d5ea /clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp | |
| parent | ec67e73430889882861fb21a193f57cdf2c3a1d2 (diff) | |
| download | bcm5719-llvm-4e1d188be2868aef71f8603f28ca4703723cb97a.tar.gz bcm5719-llvm-4e1d188be2868aef71f8603f28ca4703723cb97a.zip | |
[clang] Add isDirectlyDerivedFrom AST matcher.
Differential Revision: https://reviews.llvm.org/D65092
llvm-svn: 367010
Diffstat (limited to 'clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp')
| -rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp index 8ab472e9dc8..0fedb0c8d60 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -331,6 +331,16 @@ TEST(DeclarationMatcher, ClassIsDerived) { EXPECT_TRUE(notMatches("class Y;", IsDerivedFromX)); EXPECT_TRUE(notMatches("", IsDerivedFromX)); + DeclarationMatcher IsDirectlyDerivedFromX = + cxxRecordDecl(isDirectlyDerivedFrom("X")); + + EXPECT_TRUE( + matches("class X {}; class Y : public X {};", IsDirectlyDerivedFromX)); + EXPECT_TRUE(notMatches("class X {};", IsDirectlyDerivedFromX)); + EXPECT_TRUE(notMatches("class X;", IsDirectlyDerivedFromX)); + EXPECT_TRUE(notMatches("class Y;", IsDirectlyDerivedFromX)); + EXPECT_TRUE(notMatches("", IsDirectlyDerivedFromX)); + DeclarationMatcher IsAX = cxxRecordDecl(isSameOrDerivedFrom("X")); EXPECT_TRUE(matches("class X {}; class Y : public X {};", IsAX)); @@ -341,13 +351,22 @@ TEST(DeclarationMatcher, ClassIsDerived) { DeclarationMatcher ZIsDerivedFromX = cxxRecordDecl(hasName("Z"), isDerivedFrom("X")); + DeclarationMatcher ZIsDirectlyDerivedFromX = + cxxRecordDecl(hasName("Z"), isDirectlyDerivedFrom("X")); EXPECT_TRUE( matches("class X {}; class Y : public X {}; class Z : public Y {};", ZIsDerivedFromX)); EXPECT_TRUE( + notMatches("class X {}; class Y : public X {}; class Z : public Y {};", + ZIsDirectlyDerivedFromX)); + EXPECT_TRUE( matches("class X {};" "template<class T> class Y : public X {};" "class Z : public Y<int> {};", ZIsDerivedFromX)); + EXPECT_TRUE(notMatches("class X {};" + "template<class T> class Y : public X {};" + "class Z : public Y<int> {};", + ZIsDirectlyDerivedFromX)); EXPECT_TRUE(matches("class X {}; template<class T> class Z : public X {};", ZIsDerivedFromX)); EXPECT_TRUE( @@ -411,6 +430,9 @@ TEST(DeclarationMatcher, ClassIsDerived) { matches("class X {}; class Y : public X {}; " "typedef Y V; typedef V W; class Z : public W {};", ZIsDerivedFromX)); + EXPECT_TRUE(notMatches("class X {}; class Y : public X {}; " + "typedef Y V; typedef V W; class Z : public W {};", + ZIsDirectlyDerivedFromX)); EXPECT_TRUE( matches("template<class T, class U> class X {}; " "template<class T> class A { class Z : public X<T, int> {}; };", @@ -467,6 +489,14 @@ TEST(DeclarationMatcher, ClassIsDerived) { "template<> struct X<0> : public A {};" "struct B : public X<42> {};", cxxRecordDecl(hasName("B"), isDerivedFrom(recordDecl(hasName("A")))))); + EXPECT_TRUE(notMatches( + "struct A {};" + "template<int> struct X;" + "template<int i> struct X : public X<i-1> {};" + "template<> struct X<0> : public A {};" + "struct B : public X<42> {};", + cxxRecordDecl(hasName("B"), + isDirectlyDerivedFrom(recordDecl(hasName("A")))))); // FIXME: Once we have better matchers for template type matching, // get rid of the Variable(...) matching and match the right template |

