diff options
Diffstat (limited to 'unittests/ASTMatchers/ASTMatchersTest.cpp')
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTest.cpp | 922 |
1 files changed, 464 insertions, 458 deletions
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; }", - variable(hasType(pointsTo(ClassX))))); + varDecl(hasType(pointsTo(ClassX))))); } TEST(HasType, TakesDeclMatcherAndMatchesExpr) { - DeclarationMatcher ClassX = record(hasName("X")); + DeclarationMatcher ClassX = 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)))); } TEST(HasType, TakesDeclMatcherAndMatchesValueDecl) { - DeclarationMatcher ClassX = record(hasName("X")); + DeclarationMatcher ClassX = 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)))); } TEST(Matcher, Call) { // FIXME: Do we want to overload Call() to directly take // Matcher<Decl>, too? - StatementMatcher MethodX = call(hasDeclaration(method(hasName("x")))); + StatementMatcher MethodX = callExpr(hasDeclaration(methodDecl(hasName("x")))); EXPECT_TRUE(matches("class Y { void x() { x(); } };", MethodX)); EXPECT_TRUE(notMatches("class Y { void x() {} };", MethodX)); - StatementMatcher MethodOnY = memberCall(on(hasType(record(hasName("Y"))))); + StatementMatcher MethodOnY = + memberCallExpr(on(hasType(recordDecl(hasName("Y"))))); EXPECT_TRUE( matches("class Y { public: void x(); }; void z() { Y y; y.x(); }", @@ -758,7 +753,7 @@ TEST(Matcher, Call) { MethodOnY)); StatementMatcher MethodOnYPointer = - memberCall(on(hasType(pointsTo(record(hasName("Y")))))); + memberCallExpr(on(hasType(pointsTo(recordDecl(hasName("Y")))))); EXPECT_TRUE( matches("class Y { public: void x(); }; void z() { Y *y; y->x(); }", @@ -780,17 +775,17 @@ TEST(Matcher, Call) { TEST(HasType, MatchesAsString) { EXPECT_TRUE( matches("class Y { public: void x(); }; void z() {Y* y; y->x(); }", - memberCall(on(hasType(asString("class Y *")))))); + memberCallExpr(on(hasType(asString("class Y *")))))); EXPECT_TRUE(matches("class X { void x(int x) {} };", - method(hasParameter(0, hasType(asString("int")))))); + methodDecl(hasParameter(0, hasType(asString("int")))))); EXPECT_TRUE(matches("namespace ns { struct A {}; } struct B { ns::A a; };", - field(hasType(asString("ns::A"))))); + fieldDecl(hasType(asString("ns::A"))))); EXPECT_TRUE(matches("namespace { struct A {}; } struct B { A a; };", - field(hasType(asString("struct <anonymous>::A"))))); + fieldDecl(hasType(asString("struct <anonymous>::A"))))); } TEST(Matcher, OverloadedOperatorCall) { - StatementMatcher OpCall = overloadedOperatorCall(); + StatementMatcher OpCall = operatorCallExpr(); // Unary operator EXPECT_TRUE(matches("class Y { }; " "bool operator!(Y x) { return false; }; " @@ -817,12 +812,12 @@ TEST(Matcher, OverloadedOperatorCall) { TEST(Matcher, HasOperatorNameForOverloadedOperatorCall) { StatementMatcher OpCallAndAnd = - overloadedOperatorCall(hasOverloadedOperatorName("&&")); + operatorCallExpr(hasOverloadedOperatorName("&&")); EXPECT_TRUE(matches("class Y { }; " "bool operator&&(Y x, Y y) { return true; }; " "Y a; Y b; bool c = a && b;", OpCallAndAnd)); StatementMatcher OpCallLessLess = - overloadedOperatorCall(hasOverloadedOperatorName("<<")); + operatorCallExpr(hasOverloadedOperatorName("<<")); EXPECT_TRUE(notMatches("class Y { }; " "bool operator&&(Y x, Y y) { return true; }; " "Y a; Y b; bool c = a && b;", @@ -831,7 +826,7 @@ TEST(Matcher, HasOperatorNameForOverloadedOperatorCall) { TEST(Matcher, ThisPointerType) { StatementMatcher MethodOnY = - memberCall(thisPointerType(record(hasName("Y")))); + memberCallExpr(thisPointerType(recordDecl(hasName("Y")))); EXPECT_TRUE( matches("class Y { public: void x(); }; void z() { Y y; y.x(); }", @@ -861,9 +856,9 @@ TEST(Matcher, ThisPointerType) { TEST(Matcher, VariableUsage) { StatementMatcher Reference = - declarationReference(to( - variable(hasInitializer( - memberCall(thisPointerType(record(hasName("Y")))))))); + declRefExpr(to( + varDecl(hasInitializer( + memberCallExpr(thisPointerType(recordDecl(hasName("Y")))))))); EXPECT_TRUE(matches( "class Y {" @@ -888,12 +883,12 @@ TEST(Matcher, VariableUsage) { TEST(Matcher, FindsVarDeclInFuncitonParameter) { EXPECT_TRUE(matches( "void f(int i) {}", - variable(hasName("i")))); + varDecl(hasName("i")))); } TEST(Matcher, CalledVariable) { - StatementMatcher CallOnVariableY = expression( - memberCall(on(declarationReference(to(variable(hasName("y"))))))); + StatementMatcher CallOnVariableY = expr( + memberCallExpr(on(declRefExpr(to(varDecl(hasName("y"))))))); EXPECT_TRUE(matches( "class Y { public: void x() { Y y; y.x(); } };", CallOnVariableY)); @@ -930,81 +925,81 @@ TEST(UnaryExpressionOrTypeTraitExpression, MatchesCorrectType) { hasArgumentOfType(asString("float"))))); EXPECT_TRUE(matches( "struct A {}; void x() { A a; int b = sizeof(a); }", - sizeOfExpr(hasArgumentOfType(hasDeclaration(record(hasName("A"))))))); + sizeOfExpr(hasArgumentOfType(hasDeclaration(recordDecl(hasName("A"))))))); EXPECT_TRUE(notMatches("void x() { int a = sizeof(a); }", sizeOfExpr( - hasArgumentOfType(hasDeclaration(record(hasName("string"))))))); + hasArgumentOfType(hasDeclaration(recordDecl(hasName("string"))))))); } TEST(MemberExpression, DoesNotMatchClasses) { - EXPECT_TRUE(notMatches("class Y { void x() {} };", memberExpression())); + EXPECT_TRUE(notMatches("class Y { void x() {} };", memberExpr())); } TEST(MemberExpression, MatchesMemberFunctionCall) { - EXPECT_TRUE(matches("class Y { void x() { x(); } };", memberExpression())); + EXPECT_TRUE(matches("class Y { void x() { x(); } };", memberExpr())); } TEST(MemberExpression, MatchesVariable) { EXPECT_TRUE( - matches("class Y { void x() { this->y; } int y; };", memberExpression())); + matches("class Y { void x() { this->y; } int y; };", memberExpr())); EXPECT_TRUE( - matches("class Y { void x() { y; } int y; };", memberExpression())); + matches("class Y { void x() { y; } int y; };", memberExpr())); EXPECT_TRUE( - matches("class Y { void x() { Y y; y.y; } int y; };", - memberExpression())); + matches("class Y { void x() { Y y; y.y; } int y; };", memberExpr())); } TEST(MemberExpression, MatchesStaticVariable) { EXPECT_TRUE(matches("class Y { void x() { this->y; } static int y; };", - memberExpression())); + memberExpr())); EXPECT_TRUE(notMatches("class Y { void x() { y; } static int y; };", - memberExpression())); + memberExpr())); EXPECT_TRUE(notMatches("class Y { void x() { Y::y; } static int y; };", - memberExpression())); + memberExpr())); } TEST(IsInteger, MatchesIntegers) { - EXPECT_TRUE(matches("int i = 0;", variable(hasType(isInteger())))); - EXPECT_TRUE(matches("long long i = 0; void f(long long) { }; void g() {f(i);}", - call(hasArgument(0, declarationReference( - to(variable(hasType(isInteger())))))))); + EXPECT_TRUE(matches("int i = 0;", varDecl(hasType(isInteger())))); + EXPECT_TRUE(matches( + "long long i = 0; void f(long long) { }; void g() {f(i);}", + callExpr(hasArgument(0, declRefExpr( + to(varDecl(hasType(isInteger())))))))); } TEST(IsInteger, ReportsNoFalsePositives) { - EXPECT_TRUE(notMatches("int *i;", variable(hasType(isInteger())))); + EXPECT_TRUE(notMatches("int *i;", varDecl(hasType(isInteger())))); EXPECT_TRUE(notMatches("struct T {}; T t; void f(T *) { }; void g() {f(&t);}", - call(hasArgument(0, declarationReference( - to(variable(hasType(isInteger())))))))); + callExpr(hasArgument(0, declRefExpr( + to(varDecl(hasType(isInteger())))))))); } TEST(IsArrow, MatchesMemberVariablesViaArrow) { EXPECT_TRUE(matches("class Y { void x() { this->y; } int y; };", - memberExpression(isArrow()))); + memberExpr(isArrow()))); EXPECT_TRUE(matches("class Y { void x() { y; } int y; };", - memberExpression(isArrow()))); + memberExpr(isArrow()))); EXPECT_TRUE(notMatches("class Y { void x() { (*this).y; } int y; };", - memberExpression(isArrow()))); + memberExpr(isArrow()))); } TEST(IsArrow, MatchesStaticMemberVariablesViaArrow) { EXPECT_TRUE(matches("class Y { void x() { this->y; } static int y; };", - memberExpression(isArrow()))); + memberExpr(isArrow()))); EXPECT_TRUE(notMatches("class Y { void x() { y; } static int y; };", - memberExpression(isArrow()))); + memberExpr(isArrow()))); EXPECT_TRUE(notMatches("class Y { void x() { (*this).y; } static int y; };", - memberExpression(isArrow()))); + memberExpr(isArrow()))); } TEST(IsArrow, MatchesMemberCallsViaArrow) { EXPECT_TRUE(matches("class Y { void x() { this->x(); } };", - memberExpression(isArrow()))); + memberExpr(isArrow()))); EXPECT_TRUE(matches("class Y { void x() { x(); } };", - memberExpression(isArrow()))); + memberExpr(isArrow()))); EXPECT_TRUE(notMatches("class Y { void x() { Y y; y.x(); } };", - memberExpression(isArrow()))); + memberExpr(isArrow()))); } TEST(Callee, MatchesDeclarations) { - StatementMatcher CallMethodX = call(callee(method(hasName("x")))); + StatementMatcher CallMethodX = callExpr(callee(methodDecl(hasName("x")))); EXPECT_TRUE(matches("class Y { void x() { x(); } };", CallMethodX)); EXPECT_TRUE(notMatches("class Y { void x() {} };", CallMethodX)); @@ -1012,13 +1007,13 @@ TEST(Callee, MatchesDeclarations) { TEST(Callee, MatchesMemberExpressions) { EXPECT_TRUE(matches("class Y { void x() { this->x(); } };", - call(callee(memberExpression())))); + callExpr(callee(memberExpr())))); EXPECT_TRUE( - notMatches("class Y { void x() { this->x(); } };", call(callee(call())))); + notMatches("class Y { void x() { this->x(); } };", callExpr(callee(callExpr())))); } TEST(Function, MatchesFunctionDeclarations) { - StatementMatcher CallFunctionF = call(callee(function(hasName("f")))); + StatementMatcher CallFunctionF = callExpr(callee(functionDecl(hasName("f")))); EXPECT_TRUE(matches("void f() { f(); }", CallFunctionF)); EXPECT_TRUE(notMatches("void f() { }", CallFunctionF)); @@ -1046,48 +1041,48 @@ TEST(Function, MatchesFunctionDeclarations) { TEST(FunctionTemplate, MatchesFunctionTemplateDeclarations) { EXPECT_TRUE( matches("template <typename T> void f(T t) {}", - functionTemplate(hasName("f")))); + functionTemplateDecl(hasName("f")))); } TEST(FunctionTemplate, DoesNotMatchFunctionDeclarations) { EXPECT_TRUE( notMatches("void f(double d); void f(int t) {}", - functionTemplate(hasName("f")))); + functionTemplateDecl(hasName("f")))); } TEST(FunctionTemplate, DoesNotMatchFunctionTemplateSpecializations) { EXPECT_TRUE( notMatches("void g(); template <typename T> void f(T t) {}" "template <> void f(int t) { g(); }", - functionTemplate(hasName("f"), - hasDescendant(declarationReference( - to(function(hasName("g")))))))); + functionTemplateDecl(hasName("f"), + hasDescendant(declRefExpr(to( + functionDecl(hasName("g")))))))); } TEST(Matcher, Argument) { - StatementMatcher CallArgumentY = expression(call( - hasArgument(0, declarationReference(to(variable(hasName("y"))))))); + StatementMatcher CallArgumentY = expr(callExpr( + hasArgument(0, declRefExpr(to(varDecl(hasName("y"))))))); EXPECT_TRUE(matches("void x(int) { int y; x(y); }", CallArgumentY)); EXPECT_TRUE( matches("class X { void x(int) { int y; x(y); } };", CallArgumentY)); EXPECT_TRUE(notMatches("void x(int) { int z; x(z); }", CallArgumentY)); - StatementMatcher WrongIndex = expression(call( - hasArgument(42, declarationReference(to(variable(hasName("y"))))))); + StatementMatcher WrongIndex = expr(callExpr( + hasArgument(42, declRefExpr(to(varDecl(hasName("y"))))))); EXPECT_TRUE(notMatches("void x(int) { int y; x(y); }", WrongIndex)); } TEST(Matcher, AnyArgument) { - StatementMatcher CallArgumentY = expression(call( - hasAnyArgument(declarationReference(to(variable(hasName("y"))))))); + StatementMatcher CallArgumentY = expr(callExpr( + hasAnyArgument(declRefExpr(to(varDecl(hasName("y"))))))); EXPECT_TRUE(matches("void x(int, int) { int y; x(1, y); }", CallArgumentY)); EXPECT_TRUE(matches("void x(int, int) { int y; x(y, 42); }", CallArgumentY)); EXPECT_TRUE(notMatches("void x(int, int) { x(1, 2); }", CallArgumentY)); } TEST(Matcher, ArgumentCount) { - StatementMatcher Call1Arg = expression(call(argumentCountIs(1))); + StatementMatcher Call1Arg = expr(callExpr(argumentCountIs(1))); EXPECT_TRUE(matches("void x(int) { x(0); }", Call1Arg)); EXPECT_TRUE(matches("class X { void x(int) { x(0); } };", Call1Arg)); @@ -1095,8 +1090,8 @@ TEST(Matcher, ArgumentCount) { } TEST(Matcher, References) { - DeclarationMatcher ReferenceClassX = variable( - hasType(references(record(hasName("X"))))); + DeclarationMatcher ReferenceClassX = varDecl( + hasType(references(recordDecl(hasName("X"))))); EXPECT_TRUE(matches("class X {}; void y(X y) { X &x = y; }", ReferenceClassX)); EXPECT_TRUE( @@ -1109,81 +1104,86 @@ TEST(Matcher, References) { TEST(HasParameter, CallsInnerMatcher) { EXPECT_TRUE(matches("class X { void x(int) {} };", - method(hasParameter(0, variable())))); + methodDecl(hasParameter(0, varDecl())))); EXPECT_TRUE(notMatches("class X { void x(int) {} };", - method(hasParameter(0, hasName("x"))))); + methodDecl(hasParameter(0, hasName("x"))))); } TEST(HasParameter, DoesNotMatchIfIndexOutOfBounds) { EXPECT_TRUE(notMatches("class X { void x(int) {} };", - method(hasParameter(42, variable())))); + methodDecl(hasParameter(42, varDecl())))); } TEST(HasType, MatchesParameterVariableTypesStrictly) { EXPECT_TRUE(matches("class X { void x(X x) {} };", - method(hasParameter(0, hasType(record(hasName("X"))))))); + methodDecl(hasParameter(0, hasType(recordDecl(hasName("X"))))))); EXPECT_TRUE(notMatches("class X { void x(const X &x) {} };", - method(hasParameter(0, hasType(record(hasName("X"))))))); + methodDecl(hasParameter(0, hasType(recordDecl(hasName("X"))))))); EXPECT_TRUE(matches("class X { void x(const X *x) {} };", - method(hasParameter(0, hasType(pointsTo(record(hasName("X")))))))); + methodDecl(hasParameter(0, + hasType(pointsTo(recordDecl(hasName("X")))))))); EXPECT_TRUE(matches("class X { void x(const X &x) {} };", - method(hasParameter(0, hasType(references(record(hasName("X")))))))); + methodDecl(hasParameter(0, + hasType(references(recordDecl(hasName("X")))))))); } TEST(HasAnyParameter, MatchesIndependentlyOfPosition) { EXPECT_TRUE(matches("class Y {}; class X { void x(X x, Y y) {} };", - method(hasAnyParameter(hasType(record(hasName("X"))))))); + methodDecl(hasAnyParameter(hasType(recordDecl(hasName("X"))))))); EXPECT_TRUE(matches("class Y {}; class X { void x(Y y, X x) {} };", - method(hasAnyParameter(hasType(record(hasName("X"))))))); + methodDecl(hasAnyParameter(hasType(recordDecl(hasName("X"))))))); } TEST(Returns, MatchesReturnTypes) { EXPECT_TRUE(matches("class Y { int f() { return 1; } };", - function(returns(asString("int"))))); + functionDecl(returns(asString("int"))))); EXPECT_TRUE(notMatches("class Y { int f() { return 1; } };", - function(returns(asString("float"))))); + functionDecl(returns(asString("float"))))); EXPECT_TRUE(matches("class Y { Y getMe() { return *this; } };", - function(returns(hasDeclaration(record(hasName("Y"))))))); + functionDecl(returns(hasDeclaration( + recordDecl(hasName("Y"))))))); } TEST(IsExternC, MatchesExternCFunctionDeclarations) { - EXPECT_TRUE(matches("extern \"C\" void f() {}", function(isExternC()))); - EXPECT_TRUE(matches("extern \"C\" { void f() {} }", function(isExternC()))); - EXPECT_TRUE(notMatches("void f() {}", function(isExternC()))); + EXPECT_TRUE(matches("extern \"C\" void f() {}", functionDecl(isExternC()))); + EXPECT_TRUE(matches("extern \"C\" { void f() {} }", + functionDecl(isExternC()))); + EXPECT_TRUE(notMatches("void f() {}", functionDecl(isExternC()))); } TEST(HasAnyParameter, DoesntMatchIfInnerMatcherDoesntMatch) { EXPECT_TRUE(notMatches("class Y {}; class X { void x(int) {} };", - method(hasAnyParameter(hasType(record(hasName("X"))))))); + methodDecl(hasAnyParameter(hasType(recordDecl(hasName("X"))))))); } TEST(HasAnyParameter, DoesNotMatchThisPointer) { EXPECT_TRUE(notMatches("class Y {}; class X { void x() {} };", - method(hasAnyParameter(hasType(pointsTo(record(hasName("X")))))))); + methodDecl(hasAnyParameter(hasType(pointsTo( + recordDecl(hasName("X")))))))); } TEST(HasName, MatchesParameterVariableDeclartions |