diff options
author | Daniel Jasper <djasper@google.com> | 2012-08-24 05:12:34 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2012-08-24 05:12:34 +0000 |
commit | 2dc75ed2ef2fa3cbfd8b2ed88eb2369f3fcd98a9 (patch) | |
tree | 79ef054eabbbeca01d3885696b43f3d5a074ca06 /unittests | |
parent | 56fd9084b11ee31fed996e4b58fc099284d1c8be (diff) |
Rename the ASTMatchers to better match AST nodes. Now, all
ASTMatchers have the same name as the corresponding AST nodes
but are lower case. The only exceptions are the "CXX" prefixes
which are not copied over to the matcher names as the goal is to
actually remove these prefixes from the AST node names.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162536 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/AST/DeclPrinterTest.cpp | 92 | ||||
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTest.cpp | 922 | ||||
-rw-r--r-- | unittests/Tooling/RefactoringCallbacksTest.cpp | 14 |
3 files changed, 517 insertions, 511 deletions
diff --git a/unittests/AST/DeclPrinterTest.cpp b/unittests/AST/DeclPrinterTest.cpp index 43cc48da82..758b34cd43 100644 --- a/unittests/AST/DeclPrinterTest.cpp +++ b/unittests/AST/DeclPrinterTest.cpp @@ -120,7 +120,7 @@ bool runToolOnCode(clang::FrontendAction *ToolAction, const Twine &Code, StringRef ExpectedPrinted) { return PrintedDeclMatches(Code, ArrayRef<const char *>(), - nameableDeclaration(hasName(DeclName)).bind("id"), + namedDecl(hasName(DeclName)).bind("id"), ExpectedPrinted); } @@ -139,7 +139,7 @@ bool runToolOnCode(clang::FrontendAction *ToolAction, const Twine &Code, StringRef ExpectedPrinted) { return PrintedDeclMatches(Code, ArrayRef<const char *>("-std=c++11"), - nameableDeclaration(hasName(DeclName)).bind("id"), + namedDecl(hasName(DeclName)).bind("id"), ExpectedPrinted); } @@ -399,7 +399,7 @@ TEST(DeclPrinter, TestFunctionDecl14) { "void A(T t) { }" "template<>" "void A(int N) { }", - function(hasName("A"), isExplicitTemplateSpecialization()).bind("id"), + functionDecl(hasName("A"), isExplicitTemplateSpecialization()).bind("id"), "void A(int N)")); // WRONG; Should be: "template <> void A(int N);")); } @@ -410,7 +410,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl1) { "struct A {" " A();" "};", - constructor(ofClass(hasName("A"))).bind("id"), + constructorDecl(ofClass(hasName("A"))).bind("id"), "")); // WRONG; Should be: "A();" } @@ -420,7 +420,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl2) { "struct A {" " A(int a);" "};", - constructor(ofClass(hasName("A"))).bind("id"), + constructorDecl(ofClass(hasName("A"))).bind("id"), "")); // WRONG; Should be: "A(int a);" } @@ -430,7 +430,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl3) { "struct A {" " A(const A &a);" "};", - constructor(ofClass(hasName("A"))).bind("id"), + constructorDecl(ofClass(hasName("A"))).bind("id"), "")); // WRONG; Should be: "A(const A &a);" } @@ -440,7 +440,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl4) { "struct A {" " A(const A &a, int = 0);" "};", - constructor(ofClass(hasName("A"))).bind("id"), + constructorDecl(ofClass(hasName("A"))).bind("id"), "")); // WRONG; Should be: "A(const A &a, int = 0);" } @@ -450,7 +450,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl5) { "struct A {" " A(const A &&a);" "};", - constructor(ofClass(hasName("A"))).bind("id"), + constructorDecl(ofClass(hasName("A"))).bind("id"), "")); // WRONG; Should be: "A(const A &&a);" } @@ -460,7 +460,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl6) { "struct A {" " explicit A(int a);" "};", - constructor(ofClass(hasName("A"))).bind("id"), + constructorDecl(ofClass(hasName("A"))).bind("id"), "")); // WRONG; Should be: "explicit A(int a);" } @@ -471,7 +471,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl7) { " constexpr A();" "};", ArrayRef<const char *>("-std=c++11"), - constructor(ofClass(hasName("A"))).bind("id"), + constructorDecl(ofClass(hasName("A"))).bind("id"), "")); // WRONG; Should be: "constexpr A();" } @@ -482,7 +482,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl8) { " A() = default;" "};", ArrayRef<const char *>("-std=c++11"), - constructor(ofClass(hasName("A"))).bind("id"), + constructorDecl(ofClass(hasName("A"))).bind("id"), "")); // WRONG; Should be: "A() = default;" } @@ -493,7 +493,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl9) { " A() = delete;" "};", ArrayRef<const char *>("-std=c++11"), - constructor(ofClass(hasName("A"))).bind("id"), + constructorDecl(ofClass(hasName("A"))).bind("id"), " = delete")); // WRONG; Should be: "A() = delete;" } @@ -504,7 +504,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl10) { "struct A {" " A(const A &a);" "};", - constructor(ofClass(hasName("A"))).bind("id"), + constructorDecl(ofClass(hasName("A"))).bind("id"), "")); // WRONG; Should be: "A(const A &a);" } @@ -515,7 +515,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl11) { "struct A : public T... {" " A(T&&... ts) : T(ts)... {}" "};", - constructor(ofClass(hasName("A"))).bind("id"), + constructorDecl(ofClass(hasName("A"))).bind("id"), "A<T...>(T &&ts...) : T(ts)")); // WRONG; Should be: "A(T&&... ts) : T(ts)..." } @@ -526,7 +526,7 @@ TEST(DeclPrinter, TestCXXDestructorDecl1) { "struct A {" " ~A();" "};", - destructor(ofClass(hasName("A"))).bind("id"), + destructorDecl(ofClass(hasName("A"))).bind("id"), "void ~A()")); // WRONG; Should be: "~A();" } @@ -536,7 +536,7 @@ TEST(DeclPrinter, TestCXXDestructorDecl2) { "struct A {" " virtual ~A();" "};", - destructor(ofClass(hasName("A"))).bind("id"), + destructorDecl(ofClass(hasName("A"))).bind("id"), "virtual void ~A()")); // WRONG; Should be: "virtual ~A();" } @@ -546,7 +546,7 @@ TEST(DeclPrinter, TestCXXConversionDecl1) { "struct A {" " operator int();" "};", - method(ofClass(hasName("A"))).bind("id"), + methodDecl(ofClass(hasName("A"))).bind("id"), "int operator int()")); // WRONG; Should be: "operator int();" } @@ -556,7 +556,7 @@ TEST(DeclPrinter, TestCXXConversionDecl2) { "struct A {" " operator bool();" "};", - method(ofClass(hasName("A"))).bind("id"), + methodDecl(ofClass(hasName("A"))).bind("id"), "bool operator _Bool()")); // WRONG; Should be: "operator bool();" } @@ -567,7 +567,7 @@ TEST(DeclPrinter, TestCXXConversionDecl3) { "struct A {" " operator Z();" "};", - method(ofClass(hasName("A"))).bind("id"), + methodDecl(ofClass(hasName("A"))).bind("id"), "Z operator struct Z()")); // WRONG; Should be: "operator Z();" } @@ -579,7 +579,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction1) { " void *operator new(std::size_t);" "};", ArrayRef<const char *>("-std=c++11"), - method(ofClass(hasName("Z"))).bind("id"), + methodDecl(ofClass(hasName("Z"))).bind("id"), "void *operator new(std::size_t)")); // Should be: with semicolon } @@ -591,7 +591,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction2) { " void *operator new[](std::size_t);" "};", ArrayRef<const char *>("-std=c++11"), - method(ofClass(hasName("Z"))).bind("id"), + methodDecl(ofClass(hasName("Z"))).bind("id"), "void *operator new[](std::size_t)")); // Should be: with semicolon } @@ -602,7 +602,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction3) { " void operator delete(void *);" "};", ArrayRef<const char *>("-std=c++11"), - method(ofClass(hasName("Z"))).bind("id"), + methodDecl(ofClass(hasName("Z"))).bind("id"), "void operator delete(void *) noexcept")); // Should be: with semicolon, without noexcept? } @@ -612,7 +612,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction4) { "struct Z {" " void operator delete(void *);" "};", - method(ofClass(hasName("Z"))).bind("id"), + methodDecl(ofClass(hasName("Z"))).bind("id"), "void operator delete(void *)")); // Should be: with semicolon } @@ -623,7 +623,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction5) { " void operator delete[](void *);" "};", ArrayRef<const char *>("-std=c++11"), - method(ofClass(hasName("Z"))).bind("id"), + methodDecl(ofClass(hasName("Z"))).bind("id"), "void operator delete[](void *) noexcept")); // Should be: with semicolon, without noexcept? } @@ -651,7 +651,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_Operator1) { ASSERT_TRUE(PrintedDeclMatches( Code, - method(ofClass(hasName("Z"))).bind("id"), + methodDecl(ofClass(hasName("Z"))).bind("id"), Expected)); } } @@ -675,7 +675,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_Operator2) { ASSERT_TRUE(PrintedDeclMatches( Code, - method(ofClass(hasName("Z"))).bind("id"), + methodDecl(ofClass(hasName("Z"))).bind("id"), Expected)); } } @@ -902,7 +902,7 @@ TEST(DeclPrinter, TestClassTemplateDecl1) { ASSERT_TRUE(PrintedDeclMatches( "template<typename T>" "struct A { T a; };", - classTemplate(hasName("A")).bind("id"), + classTemplateDecl(hasName("A")).bind("id"), "template <typename T> struct A {\n}")); // Should be: with semicolon, with { ... } } @@ -911,7 +911,7 @@ TEST(DeclPrinter, TestClassTemplateDecl2) { ASSERT_TRUE(PrintedDeclMatches( "template<typename T = int>" "struct A { T a; };", - classTemplate(hasName("A")).bind("id"), + classTemplateDecl(hasName("A")).bind("id"), "template <typename T = int> struct A {\n}")); // Should be: with semicolon, with { ... } } @@ -920,7 +920,7 @@ TEST(DeclPrinter, TestClassTemplateDecl3) { ASSERT_TRUE(PrintedDeclMatches( "template<class T>" "struct A { T a; };", - classTemplate(hasName("A")).bind("id"), + classTemplateDecl(hasName("A")).bind("id"), "template <class T> struct A {\n}")); // Should be: with semicolon, with { ... } } @@ -929,7 +929,7 @@ TEST(DeclPrinter, TestClassTemplateDecl4) { ASSERT_TRUE(PrintedDeclMatches( "template<typename T, typename U>" "struct A { T a; U b; };", - classTemplate(hasName("A")).bind("id"), + classTemplateDecl(hasName("A")).bind("id"), "template <typename T, typename U> struct A {\n}")); // Should be: with semicolon, with { ... } } @@ -938,7 +938,7 @@ TEST(DeclPrinter, TestClassTemplateDecl5) { ASSERT_TRUE(PrintedDeclMatches( "template<int N>" "struct A { int a[N]; };", - classTemplate(hasName("A")).bind("id"), + classTemplateDecl(hasName("A")).bind("id"), "template <int N> struct A {\n}")); // Should be: with semicolon, with { ... } } @@ -947,7 +947,7 @@ TEST(DeclPrinter, TestClassTemplateDecl6) { ASSERT_TRUE(PrintedDeclMatches( "template<int N = 42>" "struct A { int a[N]; };", - classTemplate(hasName("A")).bind("id"), + classTemplateDecl(hasName("A")).bind("id"), "template <int N = 42> struct A {\n}")); // Should be: with semicolon, with { ... } } @@ -957,7 +957,7 @@ TEST(DeclPrinter, TestClassTemplateDecl7) { "typedef int MyInt;" "template<MyInt N>" "struct A { int a[N]; };", - classTemplate(hasName("A")).bind("id"), + classTemplateDecl(hasName("A")).bind("id"), "template <MyInt N> struct A {\n}")); // Should be: with semicolon, with { ... } } @@ -965,7 +965,7 @@ TEST(DeclPrinter, TestClassTemplateDecl7) { TEST(DeclPrinter, TestClassTemplateDecl8) { ASSERT_TRUE(PrintedDeclMatches( "template<template<typename U> class T> struct A { };", - classTemplate(hasName("A")).bind("id"), + classTemplateDecl(hasName("A")).bind("id"), "template <template <typename U> class T> struct A {\n}")); // Should be: with semicolon, with { ... } } @@ -974,7 +974,7 @@ TEST(DeclPrinter, TestClassTemplateDecl9) { ASSERT_TRUE(PrintedDeclMatches( "template<typename T> struct Z { };" "template<template<typename U> class T = Z> struct A { };", - classTemplate(hasName("A")).bind("id"), + classTemplateDecl(hasName("A")).bind("id"), "template <template <typename U> class T> struct A {\n}")); // Should be: with semicolon, with { ... } } @@ -983,7 +983,7 @@ TEST(DeclPrinter, TestClassTemplateDecl10) { ASSERT_TRUE(PrintedDeclCXX11Matches( "template<typename... T>" "struct A { int a; };", - classTemplate(hasName("A")).bind("id"), + classTemplateDecl(hasName("A")).bind("id"), "template <typename ... T> struct A {\n}")); // Should be: with semicolon, with { ... }, without spaces before '...' } @@ -992,7 +992,7 @@ TEST(DeclPrinter, TestClassTemplateDecl11) { ASSERT_TRUE(PrintedDeclCXX11Matches( "template<typename... T>" "struct A : public T... { int a; };", - classTemplate(hasName("A")).bind("id"), + classTemplateDecl(hasName("A")).bind("id"), "template <typename ... T> struct A : public T... {\n}")); // Should be: with semicolon, with { ... }, without spaces before '...' } @@ -1003,7 +1003,7 @@ TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl1) { "struct A { T a; U b; };" "template<typename T>" "struct A<T, int> { T a; };", - classTemplateSpecialization().bind("id"), + classTemplateSpecializationDecl().bind("id"), "struct A {\n}")); // WRONG; Should be: "template<typename T> struct A<T, int> { ... }" } @@ -1014,7 +1014,7 @@ TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl2) { "struct A { T a; };" "template<typename T>" "struct A<T *> { T a; };", - classTemplateSpecialization().bind("id"), + classTemplateSpecializationDecl().bind("id"), "struct A {\n}")); // WRONG; Should be: "template<typename T> struct A<T *> { ... }" } @@ -1025,7 +1025,7 @@ TEST(DeclPrinter, TestClassTemplateSpecializationDecl1) { "struct A { T a; };" "template<>" "struct A<int> { int a; };", - classTemplateSpecialization().bind("id"), + classTemplateSpecializationDecl().bind("id"), "struct A {\n}")); // WRONG; Should be: "template<> struct A<int> { ... }" } @@ -1034,7 +1034,7 @@ TEST(DeclPrinter, TestFunctionTemplateDecl1) { ASSERT_TRUE(PrintedDeclMatches( "template<typename T>" "void A(T &t);", - functionTemplate(hasName("A")).bind("id"), + functionTemplateDecl(hasName("A")).bind("id"), "template <typename T> void A(T &t)")); // Should be: with semicolon } @@ -1043,7 +1043,7 @@ TEST(DeclPrinter, TestFunctionTemplateDecl2) { ASSERT_TRUE(PrintedDeclMatches( "template<typename T>" "void A(T &t) { }", - functionTemplate(hasName("A")).bind("id"), + functionTemplateDecl(hasName("A")).bind("id"), "template <typename T> void A(T &t)")); // Should be: with semicolon } @@ -1052,7 +1052,7 @@ TEST(DeclPrinter, TestFunctionTemplateDecl3) { ASSERT_TRUE(PrintedDeclCXX11Matches( "template<typename... T>" "void A(T... a);", - functionTemplate(hasName("A")).bind("id"), + functionTemplateDecl(hasName("A")).bind("id"), "template <typename ... T> void A(T a...)")); // WRONG; Should be: "template <typename ... T> void A(T... a)" // (not "T a...") @@ -1062,7 +1062,7 @@ TEST(DeclPrinter, TestFunctionTemplateDecl3) { TEST(DeclPrinter, TestFunctionTemplateDecl4) { ASSERT_TRUE(PrintedDeclMatches( "struct Z { template<typename T> void A(T t); };", - functionTemplate(hasName("A")).bind("id"), + functionTemplateDecl(hasName("A")).bind("id"), "template <typename T> void A(T t)")); // Should be: with semicolon } @@ -1070,7 +1070,7 @@ TEST(DeclPrinter, TestFunctionTemplateDecl4) { TEST(DeclPrinter, TestFunctionTemplateDecl5) { ASSERT_TRUE(PrintedDeclMatches( "struct Z { template<typename T> void A(T t) {} };", - functionTemplate(hasName("A")).bind("id"), + functionTemplateDecl(hasName("A")).bind("id"), "template <typename T> void A(T t)")); // Should be: with semicolon } @@ -1080,7 +1080,7 @@ TEST(DeclPrinter, TestFunctionTemplateDecl6) { "template<typename T >struct Z {" " template<typename U> void A(U t) {}" "};", - functionTemplate(hasName("A")).bind("id"), + functionTemplateDecl(hasName("A")).bind("id"), "template <typename U> void A(U t)")); // Should be: with semicolon } diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index a7c64b3fe7..81f6808208 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -19,21 +19,21 @@ namespace ast_matchers { #if GTEST_HAS_DEATH_TEST TEST(HasNameDeathTest, DiesOnEmptyName) { ASSERT_DEBUG_DEATH({ - DeclarationMatcher HasEmptyName = record(hasName("")); + DeclarationMatcher HasEmptyName = recordDecl(hasName("")); EXPECT_TRUE(notMatches("class X {};", HasEmptyName)); }, ""); } TEST(HasNameDeathTest, DiesOnEmptyPattern) { ASSERT_DEBUG_DEATH({ - DeclarationMatcher HasEmptyName = record(matchesName("")); + DeclarationMatcher HasEmptyName = recordDecl(matchesName("")); EXPECT_TRUE(notMatches("class X {};", HasEmptyName)); }, ""); } TEST(IsDerivedFromDeathTest, DiesOnEmptyBaseName) { ASSERT_DEBUG_DEATH({ - DeclarationMatcher IsDerivedFromEmpty = record(isDerivedFrom("")); + DeclarationMatcher IsDerivedFromEmpty = recordDecl(isDerivedFrom("")); EXPECT_TRUE(notMatches("class X {};", IsDerivedFromEmpty)); }, ""); } @@ -46,7 +46,7 @@ TEST(Decl, MatchesDeclarations) { } TEST(NameableDeclaration, MatchesVariousDecls) { - DeclarationMatcher NamedX = nameableDeclaration(hasName("X")); + DeclarationMatcher NamedX = namedDecl(hasName("X")); EXPECT_TRUE(matches("typedef int X;", NamedX)); EXPECT_TRUE(matches("int X;", NamedX)); EXPECT_TRUE(matches("class foo { virtual void X(); };", NamedX)); @@ -59,7 +59,7 @@ TEST(NameableDeclaration, MatchesVariousDecls) { } TEST(NameableDeclaration, REMatchesVariousDecls) { - DeclarationMatcher NamedX = nameableDeclaration(matchesName("::X")); + DeclarationMatcher NamedX = namedDecl(matchesName("::X")); EXPECT_TRUE(matches("typedef int Xa;", NamedX)); EXPECT_TRUE(matches("int Xb;", NamedX)); EXPECT_TRUE(matches("class foo { virtual void Xc(); };", NamedX)); @@ -70,11 +70,11 @@ TEST(NameableDeclaration, REMatchesVariousDecls) { EXPECT_TRUE(notMatches("#define Xkl 1", NamedX)); - DeclarationMatcher StartsWithNo = nameableDeclaration(matchesName("::no")); + DeclarationMatcher StartsWithNo = namedDecl(matchesName("::no")); EXPECT_TRUE(matches("int no_foo;", StartsWithNo)); EXPECT_TRUE(matches("class foo { virtual void nobody(); };", StartsWithNo)); - DeclarationMatcher Abc = nameableDeclaration(matchesName("a.*b.*c")); + DeclarationMatcher Abc = namedDecl(matchesName("a.*b.*c")); EXPECT_TRUE(matches("int abc;", Abc)); EXPECT_TRUE(matches("int aFOObBARc;", Abc)); EXPECT_TRUE(notMatches("int cab;", Abc)); @@ -82,7 +82,7 @@ TEST(NameableDeclaration, REMatchesVariousDecls) { } TEST(DeclarationMatcher, MatchClass) { - DeclarationMatcher ClassMatcher(record()); + DeclarationMatcher ClassMatcher(recordDecl()); #if !defined(_MSC_VER) EXPECT_FALSE(matches("", ClassMatcher)); #else @@ -90,7 +90,7 @@ TEST(DeclarationMatcher, MatchClass) { EXPECT_TRUE(matches("", ClassMatcher)); #endif - DeclarationMatcher ClassX = record(record(hasName("X"))); + DeclarationMatcher ClassX = recordDecl(recordDecl(hasName("X"))); EXPECT_TRUE(matches("class X;", ClassX)); EXPECT_TRUE(matches("class X {};", ClassX)); EXPECT_TRUE(matches("template<class T> class X {};", ClassX)); @@ -98,7 +98,7 @@ TEST(DeclarationMatcher, MatchClass) { } TEST(DeclarationMatcher, ClassIsDerived) { - DeclarationMatcher IsDerivedFromX = record(isDerivedFrom("X")); + DeclarationMatcher IsDerivedFromX = recordDecl(isDerivedFrom("X")); EXPECT_TRUE(matches("class X {}; class Y : public X {};", IsDerivedFromX)); EXPECT_TRUE(matches("class X {}; class Y : public X {};", IsDerivedFromX)); @@ -108,7 +108,7 @@ TEST(DeclarationMatcher, ClassIsDerived) { EXPECT_TRUE(notMatches("", IsDerivedFromX)); DeclarationMatcher ZIsDerivedFromX = - record(hasName("Z"), isDerivedFrom("X")); + recordDecl(hasName("Z"), isDerivedFrom("X")); EXPECT_TRUE( matches("class X {}; class Y : public X {}; class Z : public Y {};", ZIsDerivedFromX)); @@ -239,19 +239,17 @@ TEST(DeclarationMatcher, ClassIsDerived) { "void f() { Z<float> z_float; Z<double> z_double; Z<char> z_char; }"; EXPECT_TRUE(matches( RecursiveTemplateOneParameter, - variable(hasName("z_float"), - hasInitializer(hasType(record(isDerivedFrom("Base1"))))))); + varDecl(hasName("z_float"), + hasInitializer(hasType(recordDecl(isDerivedFrom("Base1"))))))); EXPECT_TRUE(notMatches( RecursiveTemplateOneParameter, - variable( - hasName("z_float"), - hasInitializer(hasType(record(isDerivedFrom("Base2"))))))); + varDecl(hasName("z_float"), + hasInitializer(hasType(recordDecl(isDerivedFrom("Base2"))))))); EXPECT_TRUE(matches( RecursiveTemplateOneParameter, - variable( - hasName("z_char"), - hasInitializer(hasType(record(isDerivedFrom("Base1"), - isDerivedFrom("Base2"))))))); + varDecl(hasName("z_char"), + hasInitializer(hasType(recordDecl(isDerivedFrom("Base1"), + isDerivedFrom("Base2"))))))); const char *RecursiveTemplateTwoParameters = "class Base1 {}; class Base2 {};" @@ -266,40 +264,37 @@ TEST(DeclarationMatcher, ClassIsDerived) { " Z<char, void> z_char; }"; EXPECT_TRUE(matches( RecursiveTemplateTwoParameters, - variable( - hasName("z_float"), - hasInitializer(hasType(record(isDerivedFrom("Base1"))))))); + varDecl(hasName("z_float"), + hasInitializer(hasType(recordDecl(isDerivedFrom("Base1"))))))); EXPECT_TRUE(notMatches( RecursiveTemplateTwoParameters, - variable( - hasName("z_float"), - hasInitializer(hasType(record(isDerivedFrom("Base2"))))))); + varDecl(hasName("z_float"), + hasInitializer(hasType(recordDecl(isDerivedFrom("Base2"))))))); EXPECT_TRUE(matches( RecursiveTemplateTwoParameters, - variable( - hasName("z_char"), - hasInitializer(hasType(record(isDerivedFrom("Base1"), - isDerivedFrom("Base2"))))))); + varDecl(hasName("z_char"), + hasInitializer(hasType(recordDecl(isDerivedFrom("Base1"), + isDerivedFrom("Base2"))))))); EXPECT_TRUE(matches( "namespace ns { class X {}; class Y : public X {}; }", - record(isDerivedFrom("::ns::X")))); + recordDecl(isDerivedFrom("::ns::X")))); EXPECT_TRUE(notMatches( "class X {}; class Y : public X {};", - record(isDerivedFrom("::ns::X")))); + recordDecl(isDerivedFrom("::ns::X")))); EXPECT_TRUE(matches( "class X {}; class Y : public X {};", - record(isDerivedFrom(record(hasName("X")).bind("test"))))); + recordDecl(isDerivedFrom(recordDecl(hasName("X")).bind("test"))))); } TEST(ClassTemplate, DoesNotMatchClass) { - DeclarationMatcher ClassX = classTemplate(hasName("X")); + DeclarationMatcher ClassX = classTemplateDecl(hasName("X")); EXPECT_TRUE(notMatches("class X;", ClassX)); EXPECT_TRUE(notMatches("class X {};", ClassX)); } TEST(ClassTemplate, MatchesClassTemplate) { - DeclarationMatcher ClassX = classTemplate(hasName("X")); + DeclarationMatcher ClassX = classTemplateDecl(hasName("X")); EXPECT_TRUE(matches("template<typename T> class X {};", ClassX)); EXPECT_TRUE(matches("class Z { template<class T> class X {}; };", ClassX)); } @@ -307,32 +302,33 @@ TEST(ClassTemplate, MatchesClassTemplate) { TEST(ClassTemplate, DoesNotMatchClassTemplateExplicitSpecialization) { EXPECT_TRUE(notMatches("template<typename T> class X { };" "template<> class X<int> { int a; };", - classTemplate(hasName("X"), - hasDescendant(field(hasName("a")))))); + classTemplateDecl(hasName("X"), + hasDescendant(fieldDecl(hasName("a")))))); } TEST(ClassTemplate, DoesNotMatchClassTemplatePartialSpecialization) { EXPECT_TRUE(notMatches("template<typename T, typename U> class X { };" "template<typename T> class X<T, int> { int a; };", - classTemplate(hasName("X"), - hasDescendant(field(hasName("a")))))); + classTemplateDecl(hasName("X"), + hasDescendant(fieldDecl(hasName("a")))))); } TEST(AllOf, AllOverloadsWork) { const char Program[] = "struct T { }; int f(int, T*); void g(int x) { T t; f(x, &t); }"; EXPECT_TRUE(matches(Program, - call(allOf(callee(function(hasName("f"))), - hasArgument(0, declarationReference(to(variable()))))))); + callExpr(allOf(callee(functionDecl(hasName("f"))), + hasArgument(0, declRefExpr(to(varDecl()))))))); EXPECT_TRUE(matches(Program, - call(allOf(callee(function(hasName("f"))), - hasArgument(0, declarationReference(to(variable()))), - hasArgument(1, hasType(pointsTo(record(hasName("T"))))))))); + callExpr(allOf(callee(functionDecl(hasName("f"))), + hasArgument(0, declRefExpr(to(varDecl()))), + hasArgument(1, hasType(pointsTo( + recordDecl(hasName("T"))))))))); } TEST(DeclarationMatcher, MatchAnyOf) { DeclarationMatcher YOrZDerivedFromX = - record(anyOf(hasName("Y"), allOf(isDerivedFrom("X"), hasName("Z")))); + recordDecl(anyOf(hasName("Y"), allOf(isDerivedFrom("X"), hasName("Z")))); EXPECT_TRUE( matches("class X {}; class Z : public X {};", YOrZDerivedFromX)); EXPECT_TRUE(matches("class Y {};", YOrZDerivedFromX)); @@ -341,13 +337,13 @@ TEST(DeclarationMatcher, MatchAnyOf) { EXPECT_TRUE(notMatches("class Z {};", YOrZDerivedFromX)); DeclarationMatcher XOrYOrZOrU = - record(anyOf(hasName("X"), hasName("Y"), hasName("Z"), hasName("U"))); + recordDecl(anyOf(hasName("X"), hasName("Y"), hasName("Z"), hasName("U"))); EXPECT_TRUE(matches("class X {};", XOrYOrZOrU)); EXPECT_TRUE(notMatches("class V {};", XOrYOrZOrU)); DeclarationMatcher XOrYOrZOrUOrV = - record(anyOf(hasName("X"), hasName("Y"), hasName("Z"), hasName("U"), - hasName("V"))); + recordDecl(anyOf(hasName("X"), hasName("Y"), hasName("Z"), hasName("U"), + hasName("V"))); EXPECT_TRUE(matches("class X {};", XOrYOrZOrUOrV)); EXPECT_TRUE(matches("class Y {};", XOrYOrZOrUOrV)); EXPECT_TRUE(matches("class Z {};", XOrYOrZOrUOrV)); @@ -357,13 +353,12 @@ TEST(DeclarationMatcher, MatchAnyOf) { } TEST(DeclarationMatcher, MatchHas) { - DeclarationMatcher HasClassX = record(has(record(hasName("X")))); - + DeclarationMatcher HasClassX = recordDecl(has(recordDecl(hasName("X")))); EXPECT_TRUE(matches("class Y { class X {}; };", HasClassX)); EXPECT_TRUE(matches("class X {};", HasClassX)); DeclarationMatcher YHasClassX = - record(hasName("Y"), has(record(hasName("X")))); + recordDecl(hasName("Y"), has(recordDecl(hasName("X")))); EXPECT_TRUE(matches("class Y { class X {}; };", YHasClassX)); EXPECT_TRUE(notMatches("class X {};", YHasClassX)); EXPECT_TRUE( @@ -372,14 +367,14 @@ TEST(DeclarationMatcher, MatchHas) { TEST(DeclarationMatcher, MatchHasRecursiveAllOf) { DeclarationMatcher Recursive = - record( - has(record( - has(record(hasName("X"))), - has(record(hasName("Y"))), + recordDecl( + has(recordDecl( + has(recordDecl(hasName("X"))), + has(recordDecl(hasName("Y"))), hasName("Z"))), - has(record( - has(record(hasName("A"))), - has(record(hasName("B"))), + has(recordDecl( + has(recordDecl(hasName("A"))), + has(recordDecl(hasName("B"))), hasName("C"))), hasName("F")); @@ -430,21 +425,21 @@ TEST(DeclarationMatcher, MatchHasRecursiveAllOf) { TEST(DeclarationMatcher, MatchHasRecursiveAnyOf) { DeclarationMatcher Recursive = - record( + recordDecl( anyOf( - has(record( + has(recordDecl( anyOf( - has(record( + has(recordDecl( hasName("X"))), - has(record( + has(recordDecl( hasName("Y"))), hasName("Z")))), - has(record( + has(recordDecl( anyOf( hasName("C"), - has(record( + has(recordDecl( hasName("A"))), - has(record( + has(recordDecl( hasName("B")))))), hasName("F"))); @@ -461,7 +456,7 @@ TEST(DeclarationMatcher, MatchHasRecursiveAnyOf) { TEST(DeclarationMatcher, MatchNot) { DeclarationMatcher NotClassX = - record( + recordDecl( isDerivedFrom("Y"), unless(hasName("Y")), unless(hasName("X"))); @@ -474,11 +469,11 @@ TEST(DeclarationMatcher, MatchNot) { NotClassX)); DeclarationMatcher ClassXHasNotClassY = - record( + recordDecl( hasName("X"), - has(record(hasName("Z"))), + has(recordDecl(hasName("Z"))), unless( - has(record(hasName("Y"))))); + has(recordDecl(hasName("Y"))))); EXPECT_TRUE(matches("class X { class Z {}; };", ClassXHasNotClassY)); EXPECT_TRUE(notMatches("class X { class Y {}; class Z {}; };", ClassXHasNotClassY)); @@ -486,8 +481,8 @@ TEST(DeclarationMatcher, MatchNot) { TEST(DeclarationMatcher, HasDescendant) { DeclarationMatcher ZDescendantClassX = - record( - hasDescendant(record(hasName("X"))), + recordDecl( + hasDescendant(recordDecl(hasName("X"))), hasName("Z")); EXPECT_TRUE(matches("class Z { class X {}; };", ZDescendantClassX)); EXPECT_TRUE( @@ -501,8 +496,8 @@ TEST(DeclarationMatcher, HasDescendant) { EXPECT_TRUE(notMatches("class Z {};", ZDescendantClassX)); DeclarationMatcher ZDescendantClassXHasClassY = - record( - hasDescendant(record(has(record(hasName("Y"))), + recordDecl( + hasDescendant(recordDecl(has(recordDecl(hasName("Y"))), hasName("X"))), hasName("Z")); EXPECT_TRUE(matches("class Z { class X { class Y {}; }; };", @@ -524,9 +519,9 @@ TEST(DeclarationMatcher, HasDescendant) { "};", ZDescendantClassXHasClassY)); DeclarationMatcher ZDescendantClassXDescendantClassY = - record( - hasDescendant(record(hasDescendant(record(hasName("Y"))), - hasName("X"))), + recordDecl( + hasDescendant(recordDecl(hasDescendant(recordDecl(hasName("Y"))), + hasName("X"))), hasName("Z")); EXPECT_TRUE( matches("class Z { class A { class X { class B { class Y {}; }; }; }; };", @@ -553,7 +548,7 @@ TEST(Enum, MatchesEnums) { } TEST(EnumConstant, Matches) { - DeclarationMatcher Matcher = enumConstant(hasName("A")); + DeclarationMatcher Matcher = enumConstantDecl(hasName("A")); EXPECT_TRUE(matches("enum X{ A };", Matcher)); EXPECT_TRUE(notMatches("enum X{ B };", Matcher)); EXPECT_TRUE(notMatches("enum X {};", Matcher)); @@ -561,9 +556,8 @@ TEST(EnumConstant, Matches) { TEST(StatementMatcher, Has) { StatementMatcher HasVariableI = - expression( - hasType(pointsTo(record(hasName("X")))), - has(declarationReference(to(variable(hasName("i")))))); + expr(hasType(pointsTo(recordDecl(hasName("X")))), + has(declRefExpr(to(varDecl(hasName("i")))))); EXPECT_TRUE(matches( "class X; X *x(int); void c() { int i; x(i); }", HasVariableI)); @@ -573,9 +567,8 @@ TEST(StatementMatcher, Has) { TEST(StatementMatcher, HasDescendant) { StatementMatcher HasDescendantVariableI = - expression( - hasType(pointsTo(record(hasName("X")))), - hasDescendant(declarationReference(to(variable(hasName("i")))))); + expr(hasType(pointsTo(recordDecl(hasName("X")))), + hasDescendant(declRefExpr(to(varDecl(hasName("i")))))); EXPECT_TRUE(matches( "class X; X *x(bool); bool b(int); void c() { int i; x(b(i)); }", @@ -586,19 +579,19 @@ TEST(StatementMatcher, HasDescendant) { } TEST(TypeMatcher, MatchesClassType) { - TypeMatcher TypeA = hasDeclaration(record(hasName("A"))); + TypeMatcher TypeA = hasDeclaration(recordDecl(hasName("A"))); EXPECT_TRUE(matches("class A { public: A *a; };", TypeA)); EXPECT_TRUE(notMatches("class A {};", TypeA)); - TypeMatcher TypeDerivedFromA = hasDeclaration(record(isDerivedFrom("A"))); + TypeMatcher TypeDerivedFromA = hasDeclaration(recordDecl(isDerivedFrom("A"))); EXPECT_TRUE(matches("class A {}; class B : public A { public: B *b; };", TypeDerivedFromA)); EXPECT_TRUE(notMatches("class A {};", TypeA)); TypeMatcher TypeAHasClassB = hasDeclaration( - record(hasName("A"), has(record(hasName("B"))))); + recordDecl(hasName("A"), has(recordDecl(hasName("B"))))); EXPECT_TRUE( matches("class A { public: A *a; class B {}; };", TypeAHasClassB)); @@ -652,7 +645,7 @@ private: }; TEST(Matcher, BindMatchedNodes) { - DeclarationMatcher ClassX = has(record(hasName("::X")).bind("x")); + DeclarationMatcher ClassX = has(recordDecl(hasName("::X")).bind("x")); EXPECT_TRUE(matchAndVerifyResultTrue("class X {};", ClassX, new VerifyIdIsBoundToDecl<CXXRecordDecl>("x"))); @@ -661,13 +654,14 @@ TEST(Matcher, BindMatchedNodes) { ClassX, new VerifyIdIsBoundToDecl<CXXRecordDecl>("other-id"))); TypeMatcher TypeAHasClassB = hasDeclaration( - record(hasName("A"), has(record(hasName("B")).bind("b")))); + recordDecl(hasName("A"), has(recordDecl(hasName("B")).bind("b")))); EXPECT_TRUE(matchAndVerifyResultTrue("class A { public: A *a; class B {}; };", TypeAHasClassB, new VerifyIdIsBoundToDecl<Decl>("b"))); - StatementMatcher MethodX = call(callee(method(hasName("x")))).bind("x"); + StatementMatcher MethodX = + callExpr(callee(methodDecl(hasName("x")))).bind("x"); EXPECT_TRUE(matchAndVerifyResultTrue("class A { void x() { x(); } };", MethodX, @@ -677,11 +671,11 @@ TEST(Matcher, BindMatchedNodes) { TEST(Matcher, BindTheSameNameInAlternatives) { StatementMatcher matcher = anyOf( binaryOperator(hasOperatorName("+"), - hasLHS(expression().bind("x")), + hasLHS(expr().bind("x")), hasRHS(integerLiteral(equals(0)))), binaryOperator(hasOperatorName("+"), hasLHS(integerLiteral(equals(0))), - hasRHS(expression().bind("x")))); + hasRHS(expr().bind("x")))); EXPECT_TRUE(matchAndVerifyResultTrue( // The first branch of the matcher binds x to 0 but then fails. @@ -692,54 +686,55 @@ TEST(Matcher, BindTheSameNameInAlternatives) { } TEST(HasType, TakesQualTypeMatcherAndMatchesExpr) { - TypeMatcher ClassX = hasDeclaration(record(hasName("X"))); + TypeMatcher ClassX = hasDeclaration(recordDecl(hasName("X"))); EXPECT_TRUE( - matches("class X {}; void y(X &x) { x; }", expression(hasType(ClassX)))); + matches("class X {}; void y(X &x) { x; }", expr(hasType(ClassX)))); EXPECT_TRUE( notMatches("class X {}; void y(X *x) { x; }", - expression(hasType(ClassX)))); + expr(hasType(ClassX)))); EXPECT_TRUE( matches("class X {}; void y(X *x) { x; }", - expression(hasType(pointsTo(ClassX))))); + expr(hasType(pointsTo(ClassX))))); } TEST(HasType, TakesQualTypeMatcherAndMatchesValueDecl) { - TypeMatcher ClassX = hasDeclaration(record(hasName("X"))); + TypeMatcher ClassX = hasDeclaration(recordDecl(hasName("X"))); EXPECT_TRUE( - matches("class X {}; void y() { X x; }", variable(hasType(ClassX)))); + matches("class X {}; void y() { X x; }", varDecl(hasType(ClassX)))); EXPECT_TRUE( - notMatches("class X {}; void y() { X *x; }", variable(hasType(ClassX)))); + notMatches("class X {}; void y() { X *x; }", varDecl(hasType(ClassX)))); EXPECT_TRUE( matches("class X {}; void y() { X *x; }", - |