diff options
-rw-r--r-- | clang/include/clang/ASTMatchers/ASTMatchers.h | 279 | ||||
-rw-r--r-- | clang/unittests/AST/DeclPrinterTest.cpp | 92 | ||||
-rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 922 | ||||
-rw-r--r-- | clang/unittests/Tooling/RefactoringCallbacksTest.cpp | 14 |
4 files changed, 646 insertions, 661 deletions
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index 8e797c11fc5..2cd409c3e3f 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -14,7 +14,7 @@ // a functional in-language DSL to express queries over the C++ AST. // // For example, to match a class with a certain name, one would call: -// record(hasName("MyClass")) +// recordDecl(hasName("MyClass")) // which returns a matcher that can be used to find all AST nodes that declare // a class named 'MyClass'. // @@ -25,7 +25,7 @@ // // For example, when we're interested in child classes of a certain class, we // would write: -// record(hasName("MyClass"), hasChild(id("child", record()))) +// recordDecl(hasName("MyClass"), hasChild(id("child", recordDecl()))) // When the match is found via the MatchFinder, a user provided callback will // be called with a BoundNodes instance that contains a mapping from the // strings that we provided for the id(...) calls to the nodes that were @@ -157,9 +157,7 @@ const internal::VariadicDynCastAllOfMatcher<Decl, Decl> decl; /// } U; /// }; /// \endcode -const internal::VariadicDynCastAllOfMatcher< - Decl, - NamedDecl> nameableDeclaration; +const internal::VariadicDynCastAllOfMatcher<Decl, NamedDecl> namedDecl; /// \brief Matches C++ class declarations. /// @@ -170,7 +168,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \endcode const internal::VariadicDynCastAllOfMatcher< Decl, - CXXRecordDecl> record; + CXXRecordDecl> recordDecl; /// \brief Matches C++ class template declarations. /// @@ -180,7 +178,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \endcode const internal::VariadicDynCastAllOfMatcher< Decl, - ClassTemplateDecl> classTemplate; + ClassTemplateDecl> classTemplateDecl; /// \brief Matches C++ class template specializations. /// @@ -190,11 +188,11 @@ const internal::VariadicDynCastAllOfMatcher< /// template<> class A<double> {}; /// A<int> a; /// \endcode -/// classTemplateSpecialization() +/// classTemplateSpecializationDecl() /// matches the specializations \c A<int> and \c A<double> const internal::VariadicDynCastAllOfMatcher< Decl, - ClassTemplateSpecializationDecl> classTemplateSpecialization; + ClassTemplateSpecializationDecl> classTemplateSpecializationDecl; /// \brief Matches classTemplateSpecializations that have at least one /// TemplateArgument matching the given InnerMatcher. @@ -205,7 +203,7 @@ const internal::VariadicDynCastAllOfMatcher< /// template<> class A<double> {}; /// A<int> a; /// \endcode -/// classTemplateSpecialization(hasAnyTemplateArgument( +/// classTemplateSpecializationDecl(hasAnyTemplateArgument( /// refersToType(asString("int")))) /// matches the specialization \c A<int> AST_MATCHER_P(ClassTemplateSpecializationDecl, hasAnyTemplateArgument, @@ -233,14 +231,14 @@ AST_MATCHER_P(ClassTemplateSpecializationDecl, hasAnyTemplateArgument, /// \endcode /// The matchers /// \code -/// variable(hasInitializer(ignoringImpCasts(integerLiteral()))) -/// variable(hasInitializer(ignoringImpCasts(declarationReference()))) +/// varDecl(hasInitializer(ignoringImpCasts(integerLiteral()))) +/// varDecl(hasInitializer(ignoringImpCasts(declRefExpr()))) /// \endcode /// would match the declarations for a, b, c, and d, but not e. /// While /// \code -/// variable(hasInitializer(integerLiteral())) -/// variable(hasInitializer(declarationReference())) +/// varDecl(hasInitializer(integerLiteral())) +/// varDecl(hasInitializer(declRefExpr())) /// \endcode /// only match the declarations for b, c, and d. AST_MATCHER_P(Expr, ignoringImpCasts, @@ -260,10 +258,10 @@ AST_MATCHER_P(Expr, ignoringImpCasts, /// char d = char(0); /// \endcode /// The matcher -/// variable(hasInitializer(ignoringParenCasts(integerLiteral()))) +/// varDecl(hasInitializer(ignoringParenCasts(integerLiteral()))) /// would match the declarations for a, b, c, and d. /// while -/// variable(hasInitializer(integerLiteral())) +/// varDecl(hasInitializer(integerLiteral())) /// only match the declaration for a. AST_MATCHER_P(Expr, ignoringParenCasts, internal::Matcher<Expr>, InnerMatcher) { return InnerMatcher.matches(*Node.IgnoreParenCasts(), Finder, Builder); @@ -283,14 +281,12 @@ AST_MATCHER_P(Expr, ignoringParenCasts, internal::Matcher<Expr>, InnerMatcher) { /// long e = ((long) 0l); /// \endcode /// The matchers -/// variable(hasInitializer(ignoringParenImpCasts( -/// integerLiteral()))) -/// variable(hasInitializer(ignoringParenImpCasts( -/// declarationReference()))) +/// varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral()))) +/// varDecl(hasInitializer(ignoringParenImpCasts(declRefExpr()))) /// would match the declarations for a, b, c, and d, but not e. /// while -/// variable(hasInitializer(integerLiteral())) -/// variable(hasInitializer(declarationReference())) +/// varDecl(hasInitializer(integerLiteral())) +/// varDecl(hasInitializer(declRefExpr())) /// would only match the declaration for a. AST_MATCHER_P(Expr, ignoringParenImpCasts, internal::Matcher<Expr>, InnerMatcher) { @@ -306,7 +302,7 @@ AST_MATCHER_P(Expr, ignoringParenImpCasts, /// A<bool, int> b; /// A<int, bool> c; /// \endcode -/// classTemplateSpecialization(hasTemplateArgument( +/// classTemplateSpecializationDecl(hasTemplateArgument( /// 1, refersToType(asString("int")))) /// matches the specialization \c A<bool, int> AST_MATCHER_P2(ClassTemplateSpecializationDecl, hasTemplateArgument, @@ -325,7 +321,7 @@ AST_MATCHER_P2(ClassTemplateSpecializationDecl, hasTemplateArgument, /// template<typename T> struct A {}; /// A<X> a; /// \endcode -/// classTemplateSpecialization(hasAnyTemplateArgument( +/// classTemplateSpecializationDecl(hasAnyTemplateArgument( /// refersToType(class(hasName("X"))))) /// matches the specialization \c A<X> AST_MATCHER_P(TemplateArgument, refersToType, @@ -343,9 +339,9 @@ AST_MATCHER_P(TemplateArgument, refersToType, /// struct B { B* next; }; /// A<&B::next> a; /// \endcode -/// classTemplateSpecialization(hasAnyTemplateArgument( -/// refersToDeclaration(field(hasName("next")))) -/// matches the specialization \c A<&B::next> with \c field(...) matching +/// classTemplateSpecializationDecl(hasAnyTemplateArgument( +/// refersToDeclaration(fieldDecl(hasName("next")))) +/// matches the specialization \c A<&B::next> with \c fieldDecl(...) matching /// \c B::next AST_MATCHER_P(TemplateArgument, refersToDeclaration, internal::Matcher<Decl>, InnerMatcher) { @@ -367,7 +363,7 @@ AST_MATCHER_P(TemplateArgument, refersToDeclaration, /// \endcode const internal::VariadicDynCastAllOfMatcher< Decl, - CXXConstructorDecl> constructor; + CXXConstructorDecl> constructorDecl; /// \brief Matches explicit C++ destructor declarations. /// @@ -378,7 +374,9 @@ const internal::VariadicDynCastAllOfMatcher< /// virtual ~Foo(); /// }; /// \endcode -const internal::VariadicDynCastAllOfMatcher<Decl, CXXDestructorDecl> destructor; +const internal::VariadicDynCastAllOfMatcher< + Decl, + CXXDestructorDecl> destructorDecl; /// \brief Matches enum declarations. /// @@ -400,7 +398,7 @@ const internal::VariadicDynCastAllOfMatcher<Decl, EnumDecl> enumDecl; /// \endcode const internal::VariadicDynCastAllOfMatcher< Decl, - EnumConstantDecl> enumConstant; + EnumConstantDecl> enumConstantDecl; /// \brief Matches method declarations. /// @@ -408,7 +406,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \code /// class X { void y() }; /// \endcode -const internal::VariadicDynCastAllOfMatcher<Decl, CXXMethodDecl> method; +const internal::VariadicDynCastAllOfMatcher<Decl, CXXMethodDecl> methodDecl; /// \brief Matches variable declarations. /// @@ -419,7 +417,7 @@ const internal::VariadicDynCastAllOfMatcher<Decl, CXXMethodDecl> method; /// \code /// int a; /// \endcode -const internal::VariadicDynCastAllOfMatcher<Decl, VarDecl> variable; +const internal::VariadicDynCastAllOfMatcher<Decl, VarDecl> varDecl; /// \brief Matches field declarations. /// @@ -427,9 +425,9 @@ const internal::VariadicDynCastAllOfMatcher<Decl, VarDecl> variable; /// \code /// class X { int m; }; /// \endcode -/// field() +/// fieldDecl() /// matches 'm'. -const internal::VariadicDynCastAllOfMatcher<Decl, FieldDecl> field; +const internal::VariadicDynCastAllOfMatcher<Decl, FieldDecl> fieldDecl; /// \brief Matches function declarations. /// @@ -437,7 +435,7 @@ const internal::VariadicDynCastAllOfMatcher<Decl, FieldDecl> field; /// \code /// void f(); /// \endcode -const internal::VariadicDynCastAllOfMatcher<Decl, FunctionDecl> function; +const internal::VariadicDynCastAllOfMatcher<Decl, FunctionDecl> functionDecl; /// \brief Matches C++ function template declarations. /// @@ -447,7 +445,7 @@ const internal::VariadicDynCastAllOfMatcher<Decl, FunctionDecl> function; /// \endcode const internal::VariadicDynCastAllOfMatcher< Decl, - FunctionTemplateDecl> functionTemplate; + FunctionTemplateDecl> functionTemplateDecl; /// \brief Matches statements. /// @@ -455,9 +453,9 @@ const internal::VariadicDynCastAllOfMatcher< /// \code /// { ++a; } /// \endcode -/// statement() +/// stmt() /// matches both the compound statement '{ ++a; }' and '++a'. -const internal::VariadicDynCastAllOfMatcher<Stmt, Stmt> statement; +const internal::VariadicDynCastAllOfMatcher<Stmt, Stmt> stmt; /// \brief Matches declaration statements. /// @@ -465,11 +463,11 @@ const internal::VariadicDynCastAllOfMatcher<Stmt, Stmt> statement; /// \code /// int a; /// \endcode -/// declarationStatement() +/// declStmt() /// matches 'int a'. const internal::VariadicDynCastAllOfMatcher< Stmt, - DeclStmt> declarationStatement; + DeclStmt> declStmt; /// \brief Matches member expressions. /// @@ -480,11 +478,9 @@ const internal::VariadicDynCastAllOfMatcher< /// int a; static int b; /// }; /// \endcode -/// memberExpression() +/// memberExpr() /// matches this->x, x, y.x, a, this->b -const internal::VariadicDynCastAllOfMatcher< - Stmt, - MemberExpr> memberExpression; +const internal::VariadicDynCastAllOfMatcher<Stmt, MemberExpr> memberExpr; /// \brief Matches call expressions. /// @@ -494,7 +490,7 @@ const internal::VariadicDynCastAllOfMatcher< /// x.y(); /// y(); /// \endcode -const internal::VariadicDynCastAllOfMatcher<Stmt, CallExpr> call; +const internal::VariadicDynCastAllOfMatcher<Stmt, CallExpr> callExpr; /// \brief Matches member call expressions. /// @@ -503,7 +499,9 @@ const internal::VariadicDynCastAllOfMatcher<Stmt, CallExpr> call; /// X x; /// x.y(); /// \endcode -const internal::VariadicDynCastAllOfMatcher<Stmt, CXXMemberCallExpr> memberCall; +const internal::VariadicDynCastAllOfMatcher< + Stmt, + CXXMemberCallExpr> memberCallExpr; /// \brief Matches init list expressions. /// @@ -531,7 +529,7 @@ const internal::VariadicDynCastAllOfMatcher<Decl, UsingDecl> usingDecl; /// \brief Matches constructor call expressions (including implicit ones). /// /// Example matches string(ptr, n) and ptr within arguments of f -/// (matcher = constructorCall()) +/// (matcher = constructExpr()) /// \code /// void f(const string &a, const string &b); /// char *ptr; @@ -540,19 +538,19 @@ const internal::VariadicDynCastAllOfMatcher<Decl, UsingDecl> usingDecl; /// \endcode const internal::VariadicDynCastAllOfMatcher< Stmt, - CXXConstructExpr> constructorCall; + CXXConstructExpr> constructExpr; /// \brief Matches nodes where temporaries are created. /// /// Example matches FunctionTakesString(GetStringByValue()) -/// (matcher = bindTemporaryExpression()) +/// (matcher = bindTemporaryExpr()) /// \code /// FunctionTakesString(GetStringByValue()); /// FunctionTakesStringByPointer(GetStringPointer()); /// \endcode const internal::VariadicDynCastAllOfMatcher< Stmt, - CXXBindTemporaryExpr> bindTemporaryExpression; + CXXBindTemporaryExpr> bindTemporaryExpr; /// \brief Matches new expressions. /// @@ -560,11 +558,9 @@ const internal::VariadicDynCastAllOfMatcher< /// \code /// new X; /// \endcode -/// newExpression() +/// newExpr() /// matches 'new X'. -const internal::VariadicDynCastAllOfMatcher< - Stmt, - CXXNewExpr> newExpression; +const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNewExpr> newExpr; /// \brief Matches delete expressions. /// @@ -572,11 +568,9 @@ const internal::VariadicDynCastAllOfMatcher< /// \code /// delete X; /// \endcode -/// deleteExpression() +/// deleteExpr() /// matches 'delete X'. -const internal::VariadicDynCastAllOfMatcher< - Stmt, - CXXDeleteExpr> deleteExpression; +const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDeleteExpr> deleteExpr; /// \brief Matches array subscript expressions. /// @@ -594,14 +588,14 @@ const internal::VariadicDynCastAllOfMatcher< /// /// Example matches the CXXDefaultArgExpr placeholder inserted for the /// default value of the second parameter in the call expression f(42) -/// (matcher = defaultArgument()) +/// (matcher = defaultArgExpr()) /// \code /// void f(int x, int y = 0); /// f(42); /// \endcode const internal::VariadicDynCastAllOfMatcher< Stmt, - CXXDefaultArgExpr> defaultArgument; + CXXDefaultArgExpr> defaultArgExpr; /// \brief Matches overloaded operator calls. /// @@ -611,7 +605,7 @@ const internal::VariadicDynCastAllOfMatcher< /// FIXME: figure out why these do not match? /// /// Example matches both operator<<((o << b), c) and operator<<(o, b) -/// (matcher = overloadedOperatorCall()) +/// (matcher = operatorCallExpr()) /// \code /// ostream &operator<< (ostream &out, int i) { }; /// ostream &o; int b = 1, c = 1; @@ -619,7 +613,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \endcode const internal::VariadicDynCastAllOfMatcher< Stmt, - CXXOperatorCallExpr> overloadedOperatorCall; + CXXOperatorCallExpr> operatorCallExpr; /// \brief Matches expressions. /// @@ -627,9 +621,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \code /// void f() { x(); } /// \endcode -const internal::VariadicDynCastAllOfMatcher< - Stmt, - Expr> expression; +const internal::VariadicDynCastAllOfMatcher<Stmt, Expr> expr; /// \brief Matches expressions that refer to declarations. /// @@ -638,9 +630,7 @@ const internal::VariadicDynCastAllOfMatcher< /// bool x; /// if (x) {} /// \endcode -const internal::VariadicDynCastAllOfMatcher< - Stmt, - DeclRefExpr> declarationReference; +const internal::VariadicDynCastAllOfMatcher<Stmt, DeclRefExpr> declRefExpr; /// \brief Matches if statements. /// @@ -656,8 +646,7 @@ const internal::VariadicDynCastAllOfMatcher<Stmt, IfStmt> ifStmt; /// \code /// for (;;) {} /// \endcode -const internal::VariadicDynCastAllOfMatcher< - Stmt, ForStmt> forStmt; +const internal::VariadicDynCastAllOfMatcher<Stmt, ForStmt> forStmt; /// \brief Matches the increment statement of a for loop. /// @@ -677,7 +666,7 @@ AST_MATCHER_P(ForStmt, hasIncrement, internal::Matcher<Stmt>, /// \brief Matches the initialization statement of a for loop. /// /// Example: -/// forStmt(hasLoopInit(declarationStatement())) +/// forStmt(hasLoopInit(declStmt())) /// matches 'int x = 0' in /// \code /// for (int x = 0; x < N; ++x) { } @@ -696,9 +685,7 @@ AST_MATCHER_P(ForStmt, hasLoopInit, internal::Matcher<Stmt>, /// \endcode /// whileStmt() /// matches 'while (true) {}'. -const internal::VariadicDynCastAllOfMatcher< - Stmt, - WhileStmt> whileStmt; +const internal::VariadicDynCastAllOfMatcher<Stmt, WhileStmt> whileStmt; /// \brief Matches do statements. /// @@ -718,9 +705,7 @@ const internal::VariadicDynCastAllOfMatcher<Stmt, DoStmt> doStmt; /// \endcode /// switchCase() /// matches 'case 42: break;' and 'default: break;'. -const internal::VariadicDynCastAllOfMatcher< - Stmt, - SwitchCase> switchCase; +const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchCase> switchCase; /// \brief Matches compound statements. /// @@ -728,9 +713,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \code /// for (;;) {{}} /// \endcode -const internal::VariadicDynCastAllOfMatcher< - Stmt, - CompoundStmt> compoundStatement; +const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundStmt> compoundStmt; /// \brief Matches bool literals. /// @@ -816,7 +799,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \endcode const internal::VariadicDynCastAllOfMatcher< Expr, - CXXReinterpretCastExpr> reinterpretCast; + CXXReinterpretCastExpr> reinterpretCastExpr; /// \brief Matches a C++ static_cast expression. /// @@ -824,7 +807,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \see reinterpretCast /// /// Example: -/// staticCast() +/// staticCastExpr() /// matches /// static_cast<long>(8) /// in @@ -833,12 +816,12 @@ const internal::VariadicDynCastAllOfMatcher< /// \endcode const internal::VariadicDynCastAllOfMatcher< Expr, - CXXStaticCastExpr> staticCast; + CXXStaticCastExpr> staticCastExpr; /// \brief Matches a dynamic_cast expression. /// /// Example: -/// dynamicCast() +/// dynamicCastExpr() /// matches /// dynamic_cast<D*>(&b); /// in @@ -849,7 +832,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \endcode const internal::VariadicDynCastAllOfMatcher< Expr, - CXXDynamicCastExpr> dynamicCast; + CXXDynamicCastExpr> dynamicCastExpr; /// \brief Matches a const_cast expression. /// @@ -861,7 +844,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \endcode const internal::VariadicDynCastAllOfMatcher< Expr, - CXXConstCastExpr> constCast; + CXXConstCastExpr> constCastExpr; /// \brief Matches explicit cast expressions. /// @@ -886,7 +869,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \endcode const internal::VariadicDynCastAllOfMatcher< Expr, - ExplicitCastExpr> explicitCast; + ExplicitCastExpr> explicitCastExpr; /// \brief Matches the implicit cast nodes of Clang's AST. /// @@ -894,7 +877,7 @@ const internal::VariadicDynCastAllOfMatcher< /// eliding, as well as any type conversions. const internal::VariadicDynCastAllOfMatcher< Expr, - ImplicitCastExpr> implicitCast; + ImplicitCastExpr> implicitCastExpr; /// \brief Matches any cast nodes of Clang's AST. /// @@ -909,9 +892,7 @@ const internal::VariadicDynCastAllOfMatcher< /// int i = (0); /// int k = 0; /// \endcode -const internal::VariadicDynCastAllOfMatcher< - Expr, - CastExpr> castExpr; +const internal::VariadicDynCastAllOfMatcher<Expr, CastExpr> castExpr; /// \brief Matches functional cast expressions /// @@ -923,7 +904,7 @@ const internal::VariadicDynCastAllOfMatcher< /// \endcode const internal::VariadicDynCastAllOfMatcher< Expr, - CXXFunctionalCastExpr> functionalCast; + CXXFunctionalCastExpr> functionalCastExpr; /// \brief Various overloads for the anyOf matcher. /// @{ @@ -1096,7 +1077,7 @@ AST_MATCHER_P(NamedDecl, matchesName, std::string, RegExp) { /// "operator" prefix, such as "<<", for OverloadedOperatorCall's. /// /// Example matches a << b -/// (matcher == overloadedOperatorCall(hasOverloadedOperatorName("<<"))) +/// (matcher == operatorCallExpr(hasOverloadedOperatorName("<<"))) /// \code /// a << b; /// c && d; // assuming both operator<< @@ -1142,7 +1123,7 @@ inline internal::Matcher<CXXRecordDecl> isDerivedFrom(StringRef BaseName) { /// \brief Matches AST nodes that have child AST nodes that match the /// provided matcher. /// -/// Example matches X, Y (matcher = record(has(record(hasName("X"))) +/// Example matches X, Y (matcher = recordDecl(has(recordDecl(hasName("X"))) /// \code /// class X {}; // Matches X, because X::X is a class of name X inside X. /// class Y { class X {}; }; @@ -1163,7 +1144,7 @@ internal::ArgumentAdaptingMatcher<internal::HasMatcher, ChildT> has( /// provided matcher. /// /// Example matches X, Y, Z -/// (matcher = record(hasDescendant(record(hasName("X"))))) +/// (matcher = recordDecl(hasDescendant(recordDecl(hasName("X"))))) /// \code /// class X {}; // Matches X, because X::X is a class of name X inside X. /// class Y { class X {}; }; @@ -1185,7 +1166,7 @@ hasDescendant(const internal::Matcher<DescendantT> &DescendantMatcher) { /// \brief Matches AST nodes that have child AST nodes that match the /// provided matcher. /// -/// Example matches X, Y (matcher = record(forEach(record(hasName("X"))) +/// Example matches X, Y (matcher = recordDecl(forEach(recordDecl(hasName("X"))) /// \code /// class X {}; // Matches X, because X::X is a class of name X inside X. /// class Y { class X {}; }; @@ -1210,7 +1191,7 @@ internal::ArgumentAdaptingMatcher<internal::ForEachMatcher, ChildT> forEach( /// provided matcher. /// /// Example matches X, A, B, C -/// (matcher = record(forEachDescendant(record(hasName("X"))))) +/// (matcher = recordDecl(forEachDescendant(recordDecl(hasName("X"))))) /// \code /// class X {}; // Matches X, because X::X is a class of name X inside X. /// class A { class X {}; }; @@ -1223,7 +1204,7 @@ internal::ArgumentAdaptingMatcher<internal::ForEachMatcher, ChildT> forEach( /// each result that matches instead of only on the first one. /// /// Note: Recursively combined ForEachDescendant can cause many matches: -/// record(forEachDescendant(record(forEachDescendant(record())))) +/// recordDecl(forEachDescendant(recordDecl(forEachDescendant(recordDecl())))) /// will match 10 times (plus injected class name matches) on: /// \code /// class A { class B { class C { class D { class E {}; }; }; }; }; @@ -1241,7 +1222,7 @@ forEachDescendant( /// \brief Matches if the provided matcher does not match. /// -/// Example matches Y (matcher = record(unless(hasName("X")))) +/// Example matches Y (matcher = recordDecl(unless(hasName("X")))) /// \code /// class X {}; /// class Y {}; @@ -1269,7 +1250,7 @@ inline internal::PolymorphicMatcherWithParam1< internal::HasDeclarationMatcher, /// \brief Matches on the implicit object argument of a member call expression. /// -/// Example matches y.x() (matcher = call(on(hasType(record(hasName("Y")))))) +/// Example matches y.x() (matcher = callExpr(on(hasType(recordDecl(hasName("Y")))))) /// \code /// class Y { public: void x(); }; /// void z() { Y y; y.x(); }", @@ -1292,7 +1273,7 @@ AST_MATCHER_P(CXXMemberCallExpr, on, internal::Matcher<Expr>, /// class Y { void x() { this->x(); x(); Y y; y.x(); } }; /// void f() { f(); } /// \endcode -/// call(callee(expression())) +/// callExpr(callee(expr())) /// matches this->x(), x(), y.x(), f() /// with callee(...) /// matching this->x, x, y.x, f respectively @@ -1311,7 +1292,7 @@ AST_MATCHER_P(CallExpr, callee, internal::Matcher<Stmt>, /// \brief Matches if the call expression's callee's declaration matches the /// given matcher. /// -/// Example matches y.x() (matcher = call(callee(method(hasName("x"))))) +/// Example matches y.x() (matcher = callExpr(callee(methodDecl(hasName("x"))))) /// \code /// class Y { public: void x(); }; /// void z() { Y y; y.x(); @@ -1324,10 +1305,8 @@ inline internal::Matcher<CallExpr> callee( /// \brief Matches if the expression's or declaration's type matches a type /// matcher. /// -/// Example matches x (matcher = expression(hasType( -/// hasDeclaration(record(hasName("X")))))) -/// and z (matcher = variable(hasType( -/// hasDeclaration(record(hasName("X")))))) +/// Example matches x (matcher = expr(hasType(recordDecl(hasName("X"))))) +/// and z (matcher = varDecl(hasType(recordDecl(hasName("X"))))) /// \code /// class X {}; /// void y(X &x) { x; X z; } @@ -1345,12 +1324,12 @@ AST_POLYMORPHIC_MATCHER_P(hasType, internal::Matcher<QualType>, /// /// In case of a value declaration (for example a variable declaration), /// this resolves one layer of indirection. For example, in the value -/// declaration "X x;", record(hasName("X")) matches the declaration of X, -/// while variable(hasType(record(hasName("X")))) matches the declaration +/// declaration "X x;", recordDecl(hasName("X")) matches the declaration of X, +/// while varDecl(hasType(recordDecl(hasName("X")))) matches the declaration /// of x." /// -/// Example matches x (matcher = expression(hasType(record(hasName("X"))))) -/// and z (matcher = variable(hasType(record(hasName("X"))))) +/// Example matches x (matcher = expr(hasType(recordDecl(hasName("X"))))) +/// and z (matcher = varDecl(hasType(recordDecl(hasName("X"))))) /// \code /// class X {}; /// void y(X &x) { x; X z; } @@ -1372,7 +1351,7 @@ hasType(const internal::Matcher<Decl> &InnerMatcher) { /// class Y { public: void x(); }; /// void z() { Y* y; y->x(); } /// \endcode -/// call(on(hasType(asString("class Y *")))) +/// callExpr(on(hasType(asString("class Y *")))) /// matches y->x() AST_MATCHER_P(QualType, asString, std::string, Name) { return Name == Node.getAsString(); @@ -1382,7 +1361,7 @@ AST_MATCHER_P(QualType, asString, std::string, Name) { /// matches the specified matcher. /// /// Example matches y->x() -/// (matcher = call(on(hasType(pointsTo(record(hasName("Y"))))))) +/// (matcher = callExpr(on(hasType(pointsTo(recordDecl(hasName("Y"))))))) /// \code /// class Y { public: void x(); }; /// void z() { Y *y; y->x(); } @@ -1405,7 +1384,7 @@ inline internal::Matcher<QualType> pointsTo( /// type matches the specified matcher. /// /// Example matches X &x and const X &y -/// (matcher = variable(hasType(references(record(hasName("X")))))) +/// (matcher = varDecl(hasType(references(recordDecl(hasName("X")))))) /// \code /// class X { /// void a(X b) { @@ -1453,7 +1432,7 @@ inline internal::Matcher<CXXMemberCallExpr> thisPointerType( /// specified matcher. /// /// Example matches x in if(x) -/// (matcher = declarationReference(to(variable(hasName("x"))))) +/// (matcher = declRefExpr(to(varDecl(hasName("x"))))) /// \code /// bool x; /// if (x) {} @@ -1479,7 +1458,7 @@ AST_MATCHER_P(DeclRefExpr, to, internal::Matcher<Decl>, /// a::f(); // .. but not this. /// } /// \endcode -/// declarationReference(throughUsingDeclaration(anything())) +/// declRefExpr(throughUsingDeclaration(anything())) /// matches \c f() AST_MATCHER_P(DeclRefExpr, throughUsingDecl, internal::Matcher<UsingShadowDecl>, InnerMatcher) { @@ -1497,7 +1476,7 @@ AST_MATCHER_P(DeclRefExpr, throughUsingDecl, /// int a, b; /// int c; /// \endcode -/// declarationStatement(hasSingleDecl(anything())) +/// declStmt(hasSingleDecl(anything())) /// matches 'int c;' but not 'int a, b;'. AST_MATCHER_P(DeclStmt, hasSingleDecl, internal::Matcher<Decl>, InnerMatcher) { if (Node.isSingleDecl()) { @@ -1510,7 +1489,7 @@ AST_MATCHER_P(DeclStmt, hasSingleDecl, internal::Matcher<Decl>, InnerMatcher) { /// \brief Matches a variable declaration that has an initializer expression /// that matches the given matcher. /// -/// Example matches x (matcher = variable(hasInitializer(call()))) +/// Example matches x (matcher = varDecl(hasInitializer(callExpr()))) /// \code /// bool y() { return true; } /// bool x = y(); @@ -1526,7 +1505,7 @@ AST_MATCHER_P( /// \brief Checks that a call expression or a constructor call expression has /// a specific number of arguments (including absent default arguments). /// -/// Example matches f(0, 0) (matcher = call(argumentCountIs(2))) +/// Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2))) /// \code /// void f(int x, int y); /// f(0, 0); @@ -1543,7 +1522,7 @@ AST_POLYMORPHIC_MATCHER_P(argumentCountIs, unsigned, N) { /// call expression. /// /// Example matches y in x(y) -/// (matcher = call(hasArgument(0, declarationReference()))) +/// (matcher = callExpr(hasArgument(0, declRefExpr()))) /// \code /// void x(int) { int y; x(y); } /// \endcode @@ -1584,10 +1563,10 @@ AST_MATCHER_P(DeclStmt, declCountIs, unsigned, N) { /// int c; /// int d = 2, e; /// \endcode -/// declarationStatement(containsDeclaration( -/// 0, variable(hasInitializer(anything())))) +/// declStmt(containsDeclaration( +/// 0, varDecl(hasInitializer(anything())))) /// matches only 'int d = 2, e;', and -/// declarationStatement(containsDeclaration(1, variable())) +/// declStmt(containsDeclaration(1, varDecl())) /// \code /// matches 'int a, b = 0' as well as 'int d = 2, e;' /// but 'int c;' is not matched. @@ -1611,7 +1590,7 @@ AST_MATCHER_P2(DeclStmt, containsDeclaration, unsigned, N, /// int foo_; /// }; /// \endcode -/// record(has(constructor(hasAnyConstructorInitializer(anything())))) +/// recordDecl(has(constructorDecl(hasAnyConstructorInitializer(anything())))) /// record matches Foo, hasAnyConstructorInitializer matches foo_(1) AST_MATCHER_P(CXXConstructorDecl, hasAnyConstructorInitializer, internal::Matcher<CXXCtorInitializer>, InnerMatcher) { @@ -1633,7 +1612,7 @@ AST_MATCHER_P(CXXConstructorDecl, hasAnyConstructorInitializer, /// int foo_; /// }; /// \endcode -/// record(has(constructor(hasAnyConstructorInitializer( +/// recordDecl(has(constructorDecl(hasAnyConstructorInitializer( /// forField(hasName("foo_")))))) /// matches Foo /// with forField matching foo_ @@ -1653,7 +1632,7 @@ AST_MATCHER_P(CXXCtorInitializer, forField, /// int foo_; /// }; /// \endcode -/// record(has(constructor(hasAnyConstructorInitializer( +/// recordDecl(has(constructorDecl(hasAnyConstructorInitializer( /// withInitializer(integerLiteral(equals(1))))))) /// matches Foo /// with withInitializer matching (1) @@ -1675,7 +1654,7 @@ AST_MATCHER_P(CXXCtorInitializer, withInitializer, /// string foo_; /// }; /// \endcode -/// constructor(hasAnyConstructorInitializer(isWritten())) +/// constructorDecl(hasAnyConstructorInitializer(isWritten())) /// will match Foo(int), but not Foo() AST_MATCHER(CXXCtorInitializer, isWritten) { return Node.isWritten(); @@ -1694,7 +1673,7 @@ AST_MATCHER(CXXConstructorDecl, isImplicit) { /// \code /// void x(int, int, int) { int y; x(1, y, 42); } /// \endcode -/// call(hasAnyArgument(declarationReference())) +/// callExpr(hasAnyArgument(declRefExpr())) /// matches x(1, y, 42) /// with hasAnyArgument(...) /// matching y @@ -1719,7 +1698,7 @@ AST_POLYMORPHIC_MATCHER_P(hasAnyArgument, internal::Matcher<Expr>, /// \code /// class X { void f(int x) {} }; /// \endcode -/// method(hasParameter(0, hasType(variable()))) +/// methodDecl(hasParameter(0, hasType(varDecl()))) /// matches f(int x) {} /// with hasParameter(...) /// matching int x @@ -1739,7 +1718,7 @@ AST_MATCHER_P2(FunctionDecl, hasParameter, /// \code /// class X { void f(int x, int y, int z) {} }; /// \endcode -/// method(hasAnyParameter(hasName("y"))) +/// methodDecl(hasAnyParameter(hasName("y"))) /// matches f(int x, int y, int z) {} /// with hasAnyParameter(...) /// matching int y @@ -1759,7 +1738,7 @@ AST_MATCHER_P(FunctionDecl, hasAnyParameter, /// \code /// class X { int f() { return 1; } }; /// \endcode -/// method(returns(asString("int"))) +/// methodDecl(returns(asString("int"))) /// matches int f() { return 1; } AST_MATCHER_P(FunctionDecl, returns, internal::Matcher<QualType>, InnerMatcher) { @@ -1774,7 +1753,7 @@ AST_MATCHER_P(FunctionDecl, returns, /// extern "C" { void g() {} } /// void h() {} /// \endcode -/// function(isExternC()) +/// functionDecl(isExternC()) /// matches the declaration of f and g, but not the declaration h AST_MATCHER(FunctionDecl, isExternC) { return Node.isExternC(); @@ -1840,9 +1819,9 @@ AST_MATCHER_P(ArraySubscriptExpr, hasIndex, /// int i[5]; /// void f() { i[1] = 42; } /// \endcode -/// arraySubscriptExpression(hasBase(implicitCast( -/// hasSourceExpression(declarationReference())))) -/// matches \c i[1] with the \c declarationReference() matching \c i +/// arraySubscriptExpression(hasBase(implicitCastExpr( +/// hasSourceExpression(declRefExpr())))) +/// matches \c i[1] with the \c declRefExpr() matching \c i AST_MATCHER_P(ArraySubscriptExpr, hasBase, internal::Matcher<Expr>, InnerMatcher) { if (const Expr* Expression = Node.getBase()) @@ -1857,9 +1836,9 @@ AST_MATCHER_P(ArraySubscriptExpr, hasBase, /// \code /// for (;;) {} /// \endcode -/// hasBody(compoundStatement()) +/// hasBody(compoundStmt()) /// matches 'for (;;) {}' -/// with compoundStatement() +/// with compoundStmt() /// matching '{}' AST_POLYMORPHIC_MATCHER_P(hasBody, internal::Matcher<Stmt>, InnerMatcher) { @@ -1880,9 +1859,9 @@ AST_POLYMORPHIC_MATCHER_P(hasBody, internal::Matcher<Stmt>, /// \code /// { {}; 1+2; } /// \endcode -/// hasAnySubstatement(compoundStatement()) +/// hasAnySubstatement(compoundStmt()) /// matches '{ {}; 1+2; }' -/// with compoundStatement() +/// with compoundStmt() /// matching '{}' AST_MATCHER_P(CompoundStmt, hasAnySubstatement, internal::Matcher<Stmt>, InnerMatcher) { @@ -1901,7 +1880,7 @@ AST_MATCHER_P(CompoundStmt, hasAnySubstatement, /// \code /// { for (;;) {} } /// \endcode -/// compoundStatement(statementCountIs(0))) +/// compoundStmt(statementCountIs(0))) /// matches '{}' /// but does not match the outer compound statement. AST_MATCHER_P(CompoundStmt, statementCountIs, unsigned, N) { @@ -1989,7 +1968,7 @@ AST_MATCHER_P(UnaryOperator, hasUnaryOperand, /// \brief Matches if the cast's source expression matches the given matcher. /// /// Example: matches "a string" (matcher = -/// hasSourceExpression(constructorCall())) +/// hasSourceExpression(constructExpr())) /// \code /// class URL { URL(string); }; /// URL url = "a string"; @@ -2072,7 +2051,7 @@ isDefinition() { /// this to? /// /// Example matches A() in the last line -/// (matcher = constructorCall(hasDeclaration(method( +/// (matcher = constructExpr(hasDeclaration(methodDecl( /// ofClass(hasName("A")))))) /// \code /// class A { @@ -2101,7 +2080,7 @@ AST_MATCHER_P(CXXMethodDecl, ofClass, /// static int b; /// }; /// \endcode -/// memberExpression(isArrow()) +/// memberExpr(isArrow()) /// matches this->x, x, y.x, a, this->b inline internal::Matcher<MemberExpr> isArrow() { return makeMatcher(new internal::IsArrowMatcher()); @@ -2115,7 +2094,7 @@ inline internal::Matcher<MemberExpr> isArrow() { /// void b(long); /// void c(double); /// \endcode -/// function(hasAnyParameter(hasType(isInteger()))) +/// functionDecl(hasAnyParameter(hasType(isInteger()))) /// matches "a(int)", "b(long)", but not "c(double)". AST_MATCHER(QualType, isInteger) { return Node->isIntegerType(); @@ -2132,7 +2111,7 @@ AST_MATCHER(QualType, isInteger) { /// void d(const int*); /// void e(int const) {}; /// \endcode -/// function(hasAnyParameter(hasType(isConstQualified()))) +/// functionDecl(hasAnyParameter(hasType(isConstQualified()))) /// matches "void b(int const)", "void c(const int)" and /// "void e(int const) {}". It does not match d as there /// is no top-level const on the parameter type "const int *". @@ -2149,7 +2128,7 @@ inline internal::Matcher<QualType> isConstQualified() { /// int i(second.first); /// int j(first.second); /// \endcode -/// memberExpression(member(hasName("first"))) +/// memberExpr(member(hasName("first"))) /// matches second.first /// but not first.second (because the member name there is "second"). AST_MATCHER_P(MemberExpr, member, @@ -2165,7 +2144,7 @@ AST_MATCHER_P(MemberExpr, member, /// struct X { int m; }; /// void f(X x) { x.m; m; } /// \endcode -/// memberExpression(hasObjectExpression(hasType(record(hasName("X"))))))) +/// memberExpr(hasObjectExpression(hasType(recordDecl(hasName("X"))))))) /// matches "x.m" and "m" /// with hasObjectExpression(...) /// matching "x" and the implicit object expression of "m" which has type X*. @@ -2202,7 +2181,7 @@ AST_MATCHER_P(UsingDecl, hasAnyUsingShadowDecl, /// using X::a; /// using X::b; /// \endcode -/// usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(function()))) +/// usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(functionDecl()))) /// matches \code using X::b \endcode /// but not \code using X::a \endcode AST_MATCHER_P(UsingShadowDecl, hasTargetDecl, @@ -2221,7 +2200,7 @@ AST_MATCHER_P(UsingShadowDecl, hasTargetDecl, /// \code /// template <typename T> class X {}; class A {}; template class X<A>; /// \endcode -/// record(hasName("::X"), isTemplateInstantiation()) +/// recordDecl(hasName("::X"), isTemplateInstantiation()) /// matches the template instantiation of X<A>. /// /// But given @@ -2229,7 +2208,7 @@ AST_MATCHER_P(UsingShadowDecl, hasTargetDecl, /// template <typename T> class X {}; class A {}; /// template <> class X<A> {}; X<A> x; /// \endcode -/// record(hasName("::X"), isTemplateInstantiation()) +/// recordDecl(hasName("::X"), isTemplateInstantiation()) /// does not match, as X<A> is an explicit template specialization. /// /// Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl> @@ -2248,7 +2227,7 @@ isTemplateInstantiation() { /// template<typename T> void A(T t) { } /// template<> void A(int N) { } /// \endcode -/// function(isExplicitTemplateSpecialization()) +/// functionDecl(isExplicitTemplateSpecialization()) /// matches the specialization A<int>(). /// /// Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl> diff --git a/clang/unittests/AST/DeclPrinterTest.cpp b/clang/unittests/AST/DeclPrinterTest.cpp index 43cc48da829..758b34cd437 100644 --- a/clang/unittests/AST/DeclPrinterTest.cpp +++ b/clang/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/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index a7c64b3fe75..81f68082081 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/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) { EXPECT_TRUE(matches("class Y {}; class X { void x(int x) {} };", - method(hasAnyParameter(hasName("x"))))); + methodDecl(hasAnyParameter(hasName("x"))))); EXPECT_TRUE(notMatches("class Y {}; class X { void x(int) {} };", - method(hasAnyParameter(hasName("x"))))); + methodDecl(hasAnyParameter(hasName("x"))))); } TEST(Matcher, MatchesClassTemplateSpecialization) { EXPECT_TRUE(matches("template<typename T> struct A {};" "template<> struct A<int> {};", - classTemplateSpecialization())); + classTemplateSpecializationDecl())); EXPECT_TRUE(matches("template<typename T> struct A {}; A<int> a;", - classTemplateSpecialization())); + classTemplateSpecializationDecl())); EXPECT_TRUE(notMatches("template<typename T> struct A {};", - classTemplateSpecialization())); + classTemplateSpecializationDecl())); } TEST(Matcher, MatchesTypeTemplateArgument) { EXPECT_TRUE(matches( "template<typename T> struct B {};" "B<int> b;", - classTemplateSpecialization(hasAnyTemplateArgument(refersToType( + classTemplateSpecializationDecl(hasAnyTemplateArgument(refersToType( asString("int")))))); } @@ -1192,25 +1192,25 @@ TEST(Matcher, MatchesDeclarationReferenceTemplateArgument) { "struct B { int next; };" "template<int(B::*next_ptr)> struct A {};" "A<&B::next> a;", - classTemplateSpecialization(hasAnyTemplateArgument( - refersToDeclaration(field(hasName("next"))))))); + classTemplateSpecializationDecl(hasAnyTemplateArgument( + refersToDeclaration(fieldDecl(hasName("next"))))))); } TEST(Matcher, MatchesSpecificArgument) { EXPECT_TRUE(matches( "template<typename T, typename U> class A {};" "A<bool, int> a;", - classTemplateSpecialization(hasTemplateArgument( + classTemplateSpecializationDecl(hasTemplateArgument( 1, refersToType(asString("int")))))); EXPECT_TRUE(notMatches( "template<typename T, typename U> class A {};" "A<int, bool> a;", - classTemplateSpecialization(hasTemplateArgument( + classTemplateSpecializationDecl(hasTemplateArgument( 1, refersToType(asString("int")))))); } TEST(Matcher, ConstructorCall) { - StatementMatcher Constructor = expression(constructorCall()); + StatementMatcher Constructor = expr(constructExpr()); EXPECT_TRUE( matches("class X { public: X(); }; void x() { X x; }", Constructor)); @@ -1224,8 +1224,8 @@ TEST(Matcher, ConstructorCall) { } TEST(Matcher, ConstructorArgument) { - StatementMatcher Constructor = expression(constructorCall( - hasArgument(0, declarationReference(to(variable(hasName("y"))))))); + StatementMatcher Constructor = expr(constructExpr( + hasArgument(0, declRefExpr(to(varDecl(hasName("y"))))))); EXPECT_TRUE( matches("class X { public: X(int); }; void x() { int y; X x(y); }", @@ -1240,8 +1240,8 @@ TEST(Matcher, ConstructorArgument) { notMatches("class X { public: X(int); }; void x() { int z; X x(z); }", Constructor)); - StatementMatcher WrongIndex = expression(constructorCall( - hasArgument(42, declarationReference(to(variable(hasName("y"))))))); + StatementMatcher WrongIndex = expr(constructExpr( + hasArgument(42, declRefExpr(to(varDecl(hasName("y"))))))); EXPECT_TRUE( notMatches("class X { public: X(int); }; void x() { int y; X x(y); }", WrongIndex)); @@ -1249,7 +1249,7 @@ TEST(Matcher, ConstructorArgument) { TEST(Matcher, ConstructorArgumentCount) { StatementMatcher Constructor1Arg = - expression(constructorCall(argumentCountIs(1))); + expr(constructExpr(argumentCountIs(1))); EXPECT_TRUE( matches("class X { public: X(int); }; void x() { X x(0); }", @@ -1266,7 +1266,7 @@ TEST(Matcher, ConstructorArgumentCount) { } TEST(Matcher, BindTemporaryExpression) { - StatementMatcher TempExpression = expression(bindTemporaryExpression()); + StatementMatcher TempExpression = expr(bindTemporaryExpr()); std::string ClassString = "class string { public: string(); ~string(); }; "; @@ -1298,42 +1298,43 @@ TEST(Matcher, BindTemporaryExpression) { TEST(ConstructorDeclaration, SimpleCase) { EXPECT_TRUE(matches("class Foo { Foo(int i); };", - constructor(ofClass(hasName("Foo"))))); + constructorDecl(ofClass(hasName("Foo"))))); EXPECT_TRUE(notMatches("class Foo { Foo(int i); };", - constructor(ofClass(hasName("Bar"))))); + constructorDecl(ofClass(hasName("Bar"))))); } TEST(ConstructorDeclaration, IsImplicit) { // This one doesn't match because the constructor is not added by the // compiler (it is not needed). EXPECT_TRUE(notMatches("class Foo { };", - constructor(isImplicit()))); + constructorDecl(isImplicit()))); // The compiler added the implicit default constructor. EXPECT_TRUE(matches("class Foo { }; Foo* f = new Foo();", - constructor(isImplicit()))); + constructorDecl(isImplicit()))); EXPECT_TRUE(matches("class Foo { Foo(){} };", - constructor(unless(isImplicit())))); + constructorDecl(unless(isImplicit())))); } TEST(DestructorDeclaration, MatchesVirtualDestructor) { EXPECT_TRUE(matches("class Foo { virtual ~Foo(); };", - destructor(ofClass(hasName("Foo"))))); + destructorDecl(ofClass(hasName("Foo"))))); } TEST(DestructorDeclaration, DoesNotMatchImplicitDestructor) { - EXPECT_TRUE(notMatches("class Foo {};", destructor(ofClass(hasName("Foo"))))); + EXPECT_TRUE(notMatches("class Foo {};", + destructorDecl(ofClass(hasName("Foo"))))); } TEST(HasAnyConstructorInitializer, SimpleCase) { EXPECT_TRUE(notMatches( "class Foo { Foo() { } };", - constructor(hasAnyConstructorInitializer(anything())))); + constructorDecl(hasAnyConstructorInitializer(anything())))); EXPECT_TRUE(matches( "class Foo {" " Foo() : foo_() { }" " int foo_;" "};", - constructor(hasAnyConstructorInitializer(anything())))); + constructorDecl(hasAnyConstructorInitializer(anything())))); } TEST(HasAnyConstructorInitializer, ForField) { @@ -1344,12 +1345,12 @@ TEST(HasAnyConstructorInitializer, ForField) { " Baz foo_;" " Baz bar_;" "};"; - EXPECT_TRUE(matches(Code, constructor(hasAnyConstructorInitializer( - forField(hasType(record(hasName("Baz")))))))); - EXPECT_TRUE(matches(Code, constructor(hasAnyConstructorInitializer( + EXPECT_TRUE(matches(Code, constructorDecl(hasAnyConstructorInitializer( + forField(hasType(recordDecl(hasName("Baz")))))))); + EXPECT_TRUE(matches(Code, constructorDecl(hasAnyConstructorInitializer( forField(hasName("foo_")))))); - EXPECT_TRUE(notMatches(Code, constructor(hasAnyConstructorInitializer( - forField(hasType(record(hasName("Bar")))))))); + EXPECT_TRUE(notMatches(Code, constructorDecl(hasAnyConstructorInitializer( + forField(hasType(recordDecl(hasName("Bar")))))))); } TEST(HasAnyConstructorInitializer, WithInitializer) { @@ -1358,9 +1359,9 @@ TEST(HasAnyConstructorInitializer, WithInitializer) { " Foo() : foo_(0) { }" " int foo_;" "};"; - EXPECT_TRUE(matches(Code, constructor(hasAnyConstructorInitializer( + EXPECT_TRUE(matches(Code, constructorDecl(hasAnyConstructorInitializer( withInitializer(integerLiteral(equals(0))))))); - EXPECT_TRUE(notMatches(Code, constructor(hasAnyConstructorInitializer( + EXPECT_TRUE(notMatches(Code, constructorDecl(hasAnyConstructorInitializer( withInitializer(integerLiteral(equals(1))))))); } @@ -1372,16 +1373,16 @@ TEST(HasAnyConstructorInitializer, IsWritten) { " Bar foo_;" " Bar bar_;" "};"; - EXPECT_TRUE(matches(Code, constructor(hasAnyConstructorInitializer( + EXPECT_TRUE(matches(Code, constructorDecl(hasAnyConstructorInitializer( allOf(forField(hasName("foo_")), isWritten()))))); - EXPECT_TRUE(notMatches(Code, constructor(hasAnyConstructorInitializer( + EXPECT_TRUE(notMatches(Code, constructorDecl(hasAnyConstructorInitializer( allOf(forField(hasName("bar_")), isWritten()))))); - EXPECT_TRUE(matches(Code, constructor(hasAnyConstructorInitializer( + EXPECT_TRUE(matches(Code, constructorDecl(hasAnyConstructorInitializer( allOf(forField(hasName("bar_")), unless(isWritten())))))); } TEST(Matcher, NewExpression) { - StatementMatcher New = expression(newExpression()); + StatementMatcher New = expr(newExpr()); EXPECT_TRUE(matches("class X { public: X(); }; void x() { new X; }", New)); EXPECT_TRUE( @@ -1392,9 +1393,8 @@ TEST(Matcher, NewExpression) { } TEST(Matcher, NewExpressionArgument) { - StatementMatcher New = expression(constructorCall( - hasArgument( - 0, declarationReference(to(variable(hasName("y"))))))); + StatementMatcher New = expr(constructExpr( + hasArgument(0, declRefExpr(to(varDecl(hasName("y"))))))); EXPECT_TRUE( matches("class X { public: X(int); }; void x() { int y; new X(y); }", @@ -1406,16 +1406,15 @@ TEST(Matcher, NewExpressionArgument) { notMatches("class X { public: X(int); }; void x() { int z; new X(z); }", New)); - StatementMatcher WrongIndex = expression(constructorCall( - hasArgument( - 42, declarationReference(to(variable(hasName("y"))))))); + StatementMatcher WrongIndex = expr(constructExpr( + hasArgument(42, declRefExpr(to(varDecl(hasName("y"))))))); EXPECT_TRUE( notMatches("class X { public: X(int); }; void x() { int y; new X(y); }", WrongIndex)); } TEST(Matcher, NewExpressionArgumentCount) { - StatementMatcher New = constructorCall(argumentCountIs(1)); + StatementMatcher New = constructExpr(argumentCountIs(1)); EXPECT_TRUE( matches("class X { public: X(int); }; void x() { new X(0); }", New)); @@ -1426,11 +1425,11 @@ TEST(Matcher, NewExpressionArgumentCount) { TEST(Matcher, DeleteExpression) { EXPECT_TRUE(matches("struct A {}; void f(A* a) { delete a; }", - deleteExpression())); + deleteExpr())); } TEST(Matcher, DefaultArgument) { - StatementMatcher Arg = defaultArgument(); + StatementMatcher Arg = defaultArgExpr(); EXPECT_TRUE(matches("void x(int, int = 0) { int y; x(y); }", Arg)); EXPECT_TRUE( @@ -1439,7 +1438,7 @@ TEST(Matcher, DefaultArgument) { } TEST(Matcher, StringLiterals) { - StatementMatcher Literal = expression(stringLiteral()); + StatementMatcher Literal = expr(stringLiteral()); EXPECT_TRUE(matches("const char *s = \"string\";", Literal)); // wide string EXPECT_TRUE(matches("const wchar_t *s = L\"string\";", Literal)); @@ -1450,7 +1449,7 @@ TEST(Matcher, StringLiterals) { } TEST(Matcher, CharacterLiterals) { - StatementMatcher CharLiteral = expression(characterLiteral()); + StatementMatcher CharLiteral = expr(characterLiteral()); EXPECT_TRUE(matches("const char c = 'c';", CharLiteral)); // wide character EXPECT_TRUE(matches("const char c = L'c';", CharLiteral)); @@ -1460,7 +1459,7 @@ TEST(Matcher, CharacterLiterals) { } TEST(Matcher, IntegerLiterals) { - StatementMatcher HasIntLiteral = expression(integerLiteral()); + StatementMatcher HasIntLiteral = expr(integerLiteral()); EXPECT_TRUE(matches("int i = 10;", HasIntLiteral)); EXPECT_TRUE(matches("int i = 0x1AB;", HasIntLiteral)); EXPECT_TRUE(matches("int i = 10L;", HasIntLiteral)); @@ -1701,87 +1700,91 @@ TEST(ArraySubscriptMatchers, ArrayIndex) { TEST(ArraySubscriptMatchers, MatchesArrayBase) { EXPECT_TRUE(matches( "int i[2]; void f() { i[1] = 2; }", - arraySubscriptExpr(hasBase(implicitCast( - hasSourceExpression(declarationReference())))))); + arraySubscriptExpr(hasBase(implicitCastExpr( + hasSourceExpression(declRefExpr())))))); } TEST(Matcher, HasNameSupportsNamespaces) { EXPECT_TRUE(matches("namespace a { namespace b { class C; } }", - record(hasName("a::b::C")))); + recordDecl(hasName("a::b::C")))); EXPECT_TRUE(matches("namespace a { namespace b { class C; } }", - record(hasName("::a::b::C")))); + recordDecl(hasName("::a::b::C")))); EXPECT_TRUE(matches("namespace a { namespace b { class C; } }", - record(hasName("b::C")))); + recordDecl(hasName("b::C")))); EXPECT_TRUE(matches("namespace a { namespace b { class C; } }", - record(hasName("C")))); + recordDecl(hasName("C")))); EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }", - record(hasName("c::b::C")))); + recordDecl(hasName("c::b::C")))); EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }", - record(hasName("a::c::C")))); + recordDecl(hasName("a::c::C")))); EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }", - record(hasName("a::b::A")))); + recordDecl(hasName("a::b::A")))); EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }", - record(hasName("::C")))); + recordDecl(hasName("::C")))); EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }", - record(hasName("::b::C")))); + recordDecl(hasName("::b::C")))); EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }", - record(hasName("z::a::b::C")))); + recordDecl(hasName("z::a::b::C")))); EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }", - record(hasName("a+b::C")))); + recordDecl(hasName("a+b::C")))); EXPECT_TRUE(notMatches("namespace a { namespace b { class AC; } }", - record(hasName("C")))); + recordDecl(hasName("C")))); } TEST(Matcher, HasNameSupportsOuterClasses) { EXPECT_TRUE( - matches("class A { class B { class C; }; };", record(hasName("A::B::C")))); + matches("class A { class B { class C; }; };", + recordDecl(hasName("A::B::C")))); EXPECT_TRUE( matches("class A { class B { class C; }; };", - record(hasName("::A::B::C")))); + recordDecl(hasName("::A::B::C")))); EXPECT_TRUE( - matches("class A { class B { class C; }; };", record(hasName("B::C")))); + matches("class A { class B { class C; }; };", + recordDecl(hasName("B::C")))); EXPECT_TRUE( - matches("class A { class B { class C; }; };", record(hasName("C")))); + matches("class A { class B { class C; }; };", + recordDecl(hasName("C")))); EXPECT_TRUE( notMatches("class A { class B { class C; }; };", - record(hasName("c::B::C")))); + recordDecl(hasName("c::B::C")))); EXPECT_TRUE( notMatches("class A { class B { class C; }; };", - record(hasName("A::c::C")))); + recordDecl(hasName("A::c::C")))); EXPECT_TRUE( notMatches("class A { class B { class C; }; };", - record(hasName("A::B::A")))); + recordDecl(hasName("A::B::A")))); EXPECT_TRUE( - notMatches("class A { class B { class C; }; };", record(hasName("::C")))); + notMatches("class A { class B { class C; }; };", + recordDecl(hasName("::C")))); EXPECT_TRUE( notMatches("class A { class B { class C; }; };", - record(hasName("::B::C")))); + recordDecl(hasName("::B::C")))); EXPECT_TRUE(notMatches("class A { class B { class C; }; };", - record(hasName("z::A::B::C")))); + recordDecl(hasName("z::A::B::C")))); EXPECT_TRUE( notMatches("class A { class B { class C; }; };", - record(hasName("A+B::C")))); + recordDecl(hasName("A+B::C")))); } TEST(Matcher, IsDefinition) { DeclarationMatcher DefinitionOfClassA = - record(hasName("A"), isDefinition()); + recordDecl(hasName("A"), isDefinition()); EXPECT_TRUE(matches("class A {};", DefinitionOfClassA)); EXPECT_TRUE(notMatches("class A;", DefinitionOfClassA)); DeclarationMatcher DefinitionOfVariableA = - variable(hasName("a"), isDefinition()); + varDecl(hasName("a"), isDefinition()); EXPECT_TRUE(matches("int a;", DefinitionOfVariableA)); EXPECT_TRUE(notMatches("extern int a;", DefinitionOfVariableA)); DeclarationMatcher DefinitionOfMethodA = - method(hasName("a"), isDefinition()); + methodDecl(hasName("a"), isDefinition()); EXPECT_TRUE(matches("class A { void a() {} };", DefinitionOfMethodA)); EXPECT_TRUE(notMatches("class A { void a(); };", DefinitionOfMethodA)); } TEST(Matcher, OfClass) { - StatementMatcher Constructor = constructorCall(hasDeclaration(method( + StatementMatcher Constructor = constructExpr(hasDeclaration(methodDecl( ofClass(hasName("X"))))); EXPECT_TRUE( @@ -1798,7 +1801,8 @@ TEST(Matcher, VisitsTemplateInstantiations) { EXPECT_TRUE(matches( "class A { public: void x(); };" "template <typename T> class B { public: void y() { T t; t.x(); } };" - "void f() { B<A> b; b.y(); }", call(callee(method(hasName("x")))))); + "void f() { B<A> b; b.y(); }", + callExpr(callee(methodDecl(hasName("x")))))); EXPECT_TRUE(matches( "class A { public: void x(); };" @@ -1808,8 +1812,9 @@ TEST(Matcher, VisitsTemplateInstantiations) { "};" "void f() {" " C::B<A> b; b.y();" - "}", record(hasName("C"), - hasDescendant(call(callee(method(hasName("x")))))))); + "}", + recordDecl(hasName("C"), + hasDescendant(callExpr(callee(methodDecl(hasName("x")))))))); } TEST(Matcher, HandlesNullQualTypes) { @@ -1828,7 +1833,7 @@ TEST(Matcher, HandlesNullQualTypes) { "void g() {" " f(0);" "}", - expression(hasType(TypeMatcher( + expr(hasType(TypeMatcher( anyOf( TypeMatcher(hasDeclaration(anything())), pointsTo(AnyType), @@ -1845,7 +1850,7 @@ AST_MATCHER_P(Decl, just, internal::Matcher<Decl>, AMatcher) { } TEST(AstMatcherPMacro, Works) { - DeclarationMatcher HasClassB = just(has(record(hasName("B")).bind("b"))); + DeclarationMatcher HasClassB = just(has(recordDecl(hasName("B")).bind("b"))); EXPECT_TRUE(matchAndVerifyResultTrue("class A { class B {}; };", HasClassB, new VerifyIdIsBoundToDecl<Decl>("b"))); @@ -1870,7 +1875,8 @@ AST_POLYMORPHIC_MATCHER_P( } TEST(AstPolymorphicMatcherPMacro, Works) { - DeclarationMatcher HasClassB = polymorphicHas(record(hasName("B")).bind("b")); + DeclarationMatcher HasClassB = + polymorphicHas(recordDecl(hasName("B")).bind("b")); EXPECT_TRUE(matchAndVerifyResultTrue("class A { class B {}; };", HasClassB, new VerifyIdIsBoundToDecl<Decl>("b"))); @@ -1882,7 +1888,7 @@ TEST(AstPolymorphicMatcherPMacro, Works) { HasClassB, new VerifyIdIsBoundToDecl<Decl>("b"))); StatementMatcher StatementHasClassB = - polymorphicHas(record(hasName("B"))); + polymorphicHas(recordDecl(hasName("B"))); EXPECT_TRUE(matches("void x() { class B {}; }", StatementHasClassB)); } @@ -1901,7 +1907,7 @@ TEST(For, ForLoopInternals) { TEST(For, NegativeForLoopInternals) { EXPECT_TRUE(notMatches("void f(){ for (int i = 0; ; ++i); }", - forStmt(hasCondition(expression())))); + forStmt(hasCondition(expr())))); EXPECT_TRUE(notMatches("void f() {int i; for (; i < 4; ++i) {} }", forStmt(hasLoopInit(anything())))); } @@ -1912,29 +1918,29 @@ TEST(For, ReportsNoFalsePositives) { } TEST(CompoundStatement, HandlesSimpleCases) { - EXPECT_TRUE(notMatches("void f();", compoundStatement())); - EXPECT_TRUE(matches("void f() {}", compoundStatement())); - EXPECT_TRUE(matches("void f() {{}}", compoundStatement())); + EXPECT_TRUE(notMatches("void f();", compoundStmt())); + EXPECT_TRUE(matches("void f() {}", compoundStmt())); + EXPECT_TRUE(matches("void f() {{}}", compoundStmt())); } TEST(CompoundStatement, DoesNotMatchEmptyStruct) { // It's not a compound statement just because there's "{}" in the source // text. This is an AST search, not grep. EXPECT_TRUE(notMatches("namespace n { struct S {}; }", - compoundStatement())); + compoundStmt())); EXPECT_TRUE(matches("namespace n { struct S { void f() {{}} }; }", - compoundStatement())); + compoundStmt())); } TEST(HasBody, FindsBodyOfForWhileDoLoops) { EXPECT_TRUE(matches("void f() { for(;;) {} }", - forStmt(hasBody(compoundStatement())))); + forStmt(hasBody(compoundStmt())))); EXPECT_TRUE(notMatches("void f() { for(;;); }", - forStmt(hasBody(compoundStatement())))); + forStmt(hasBody(compoundStmt())))); EXPECT_TRUE(matches("void f() { while(true) {} }", - whileStmt(hasBody(compoundStatement())))); + whileStmt(hasBody(compoundStmt())))); EXPECT_TRUE(matches("void f() { do {} while(true); }", - doStmt(hasBody(compoundStatement())))); + doStmt(hasBody(compoundStmt())))); } TEST(HasAnySubstatement, MatchesForTopLevelCompoundStatement) { @@ -1942,67 +1948,67 @@ TEST(HasAnySubstatement, MatchesForTopLevelCompoundStatement) { // definition, and the function body itself must be a compound // statement. EXPECT_TRUE(matches("void f() { for (;;); }", - compoundStatement(hasAnySubstatement(forStmt())))); + compoundStmt(hasAnySubstatement(forStmt())))); } TEST(HasAnySubstatement, IsNotRecursive) { // It's really "has any immediate substatement". EXPECT_TRUE(notMatches("void f() { if (true) for (;;); }", - compoundStatement(hasAnySubstatement(forStmt())))); + compoundStmt(hasAnySubstatement(forStmt())))); } TEST(HasAnySubstatement, MatchesInNestedCompoundStatements) { EXPECT_TRUE(matches("void f() { if (true) { for (;;); } }", - compoundStatement(hasAnySubstatement(forStmt())))); + compoundStmt(hasAnySubstatement(forStmt())))); } TEST(HasAnySubstatement, FindsSubstatementBetweenOthers) { EXPECT_TRUE(matches("void f() { 1; 2; 3; for (;;); 4; 5; 6; }", - compoundStatement(hasAnySubstatement(forStmt())))); + compoundStmt(hasAnySubstatement(forStmt())))); } TEST(StatementCountIs, FindsNoStatementsInAnEmptyCompoundStatement) { EXPECT_TRUE(matches("void f() { }", - compoundStatement(statementCountIs(0)))); + compoundStmt(statementCountIs(0)))); EXPECT_TRUE(notMatches("void f() {}", - compoundStatement(statementCountIs(1)))); + compoundStmt(statementCountIs(1)))); } TEST(StatementCountIs, AppearsToMatchOnlyOneCount) { EXPECT_TRUE(matches("void f() { 1; }", - compoundStatement(statementCountIs(1)))); + compoundStmt(statementCountIs(1)))); EXPECT_TRUE(notMatches("void f() { 1; }", - compoundStatement(statementCountIs(0)))); + compoundStmt(statementCountIs(0)))); EXPECT_TRUE(notMatches("void f() { 1; }", - compoundStatement(statementCountIs(2)))); + compoundStmt(statementCountIs(2)))); } TEST(StatementCountIs, WorksWithMultipleStatements) { EXPECT_TRUE(matches("void f() { 1; 2; 3; }", - compoundStatement(statementCountIs(3)))); + compoundStmt(statementCountIs(3)))); } TEST(StatementCountIs, WorksWithNestedCompoundStatements) { EXPECT_TRUE(matches("void f() { { 1; } { 1; 2; 3; 4; } }", - compoundStatement(statementCountIs(1)))); + compoundStmt(statementCountIs(1)))); EXPECT_TRUE(matches("void f() { { 1; } { 1; 2; 3; 4; } }", - compoundStatement(statementCountIs(2)))); + compoundStmt(statementCountIs(2)))); EXPECT_TRUE(notMatches("void f() { { 1; } { 1; 2; 3; 4; } }", - compoundStatement(statementCountIs(3)))); + compoundStmt(statementCountIs(3)))); EXPECT_TRUE(matches("void f() { { 1; } { 1; 2; 3; 4; } }", - compoundStatement(statementCountIs(4)))); + compoundStmt(statementCountIs(4)))); } TEST(Member, WorksInSimplestCase) { EXPECT_TRUE(matches("struct { int first; } s; int i(s.first);", - memberExpression(member(hasName("first"))))); + memberExpr(member(hasName("first"))))); } TEST(Member, DoesNotMatchTheBaseExpression) { // Don't pick out the wrong part of the member expression, this should // be checking the member (name) only. EXPECT_TRUE(notMatches("struct { int i; } first; int i(first.i);", - memberExpression(member(hasName("first"))))); + memberExpr(member(hasName("first"))))); } TEST(Member, MatchesInMemberFunctionCall) { @@ -2010,224 +2016,224 @@ TEST(Member, MatchesInMemberFunctionCall) { " struct { void first() {}; } s;" " s.first();" "};", - memberExpression(member(hasName("first"))))); + memberExpr(member(hasName("first"))))); } TEST(Member, MatchesMemberAllocationFunction) { EXPECT_TRUE(matches("namespace std { typedef typeof(sizeof(int)) size_t; }" "class X { void *operator new(std::size_t); };", - method(ofClass(hasName("X"))))); + methodDecl(ofClass(hasName("X"))))); EXPECT_TRUE(matches("class X { void operator delete(void*); };", - method(ofClass(hasName("X"))))); + methodDecl(ofClass(hasName("X"))))); - EXPECT_TRUE(matches("namespace std { typedef typeof(sizeof(int)) size_t; }" - "class X { void operator delete[](void*, std::size_t); };", - method(ofClass(hasName("X"))))); + EXPECT_TRUE(matches( + "namespace std { typedef typeof(sizeof(int)) size_t; }" + "class X { void operator delete[](void*, std::size_t); };", + methodDecl(ofClass(hasName("X"))))); } TEST(HasObjectExpression, DoesNotMatchMember) { EXPECT_TRUE(notMatches( "class X {}; struct Z { X m; }; void f(Z z) { z.m; }", - memberExpression(hasObjectExpression(hasType(record(hasName("X"))))))); + memberExpr(hasObjectExpression(hasType(recordDecl(hasName("X"))))))); } TEST(HasObjectExpression, MatchesBaseOfVariable) { EXPECT_TRUE(matches( "struct X { int m; }; void f(X x) { x.m; }", - memberExpression(hasObjectExpression(hasType(record(hasName("X"))))))); + memberExpr(hasObjectExpression(hasType(recordDecl(hasName("X"))))))); EXPECT_TRUE(matches( "struct X { int m; }; void f(X* x) { x->m; }", - memberExpression(hasObjectExpression( - hasType(pointsTo(record(hasName("X")))))))); + memberExpr(hasObjectExpression( + hasType(pointsTo(recordDecl(hasName("X")))))))); } TEST(HasObjectExpression, MatchesObjectExpressionOfImplicitlyFormedMemberExpression) { EXPECT_TRUE(matches( "class X {}; struct S { X m; void f() { this->m; } };", - memberExpression(hasObjectExpression( - hasType(pointsTo(record(hasName("S")))))))); + memberExpr(hasObjectExpression( + hasType(pointsTo(recordDecl(hasName("S")))))))); EXPECT_TRUE(matches( "class X {}; struct S { X m; void f() { m; } };", - memberExpression(hasObjectExpression( - hasType(pointsTo(record(hasName("S")))))))); + memberExpr(hasObjectExpression( + hasType(pointsTo(recordDecl(hasName("S")))))))); } TEST(Field, DoesNotMatchNonFieldMembers) { - EXPECT_TRUE(notMatches("class X { void m(); };", field(hasName("m")))); - EXPECT_TRUE(notMatches("class X { class m {}; };", field(hasName("m")))); - EXPECT_TRUE(notMatches("class X { enum { m }; };", field(hasName("m")))); - EXPECT_TRUE(notMatches("class X { enum m {}; };", field(hasName("m")))); + EXPECT_TRUE(notMatches("class X { void m(); };", fieldDecl(hasName("m")))); + EXPECT_TRUE(notMatches("class X { class m {}; };", fieldDecl(hasName("m")))); + EXPECT_TRUE(notMatches("class X { enum { m }; };", fieldDecl(hasName("m")))); + EXPECT_TRUE(notMatches("class X { enum m {}; };", fieldDecl(hasName("m")))); } TEST(Field, MatchesField) { - EXPECT_TRUE(matches("class X { int m; };", field(hasName("m")))); + EXPECT_TRUE(matches("class X { int m; };", fieldDecl(hasName("m")))); } TEST(IsConstQualified, MatchesConstInt) { EXPECT_TRUE(matches("const int i = 42;", - variable(hasType(isConstQualified())))); + varDecl(hasType(isConstQualified())))); } TEST(IsConstQualified, MatchesConstPointer) { EXPECT_TRUE(matches("int i = 42; int* const p(&i);", - variable(hasType(isConstQualified())))); + varDecl(hasType(isConstQualified())))); } TEST(IsConstQualified, MatchesThroughTypedef) { EXPECT_TRUE(matches("typedef const int const_int; const_int i = 42;", - variable(hasType(isConstQualified())))); + varDecl(hasType(isConstQualified())))); EXPECT_TRUE(matches("typedef int* int_ptr; const int_ptr p(0);", - variable(hasType(isConstQualified())))); + varDecl(hasType(isConstQualified())))); } TEST(IsConstQualified, DoesNotMatchInappropriately) { EXPECT_TRUE(notMatches("typedef int nonconst_int; nonconst_int i = 42;", - variable(hasType(isConstQualified())))); + varDecl(hasType(isConstQualified())))); EXPECT_TRUE(notMatches("int const* p;", - variable(hasType(isConstQualified())))); + varDecl(hasType(isConstQualified())))); } TEST(CastExpression, MatchesExplicitCasts) { EXPECT_TRUE(matches("char *p = reinterpret_cast<char *>(&p);", - expression(castExpr()))); - EXPECT_TRUE(matches("void *p = (void *)(&p);", expression(castExpr()))); + expr(castExpr()))); + EXPECT_TRUE(matches("void *p = (void *)(&p);", expr(castExpr()))); EXPECT_TRUE(matches("char q, *p = const_cast<char *>(&q);", - expression(castExpr()))); - EXPECT_TRUE(matches("char c = char(0);", expression(castExpr()))); + expr(castExpr()))); + EXPECT_TRUE(matches("char c = char(0);", expr(castExpr()))); } TEST(CastExpression, MatchesImplicitCasts) { // This test creates an implicit cast from int to char. - EXPECT_TRUE(matches("char c = 0;", expression(castExpr()))); + EXPECT_TRUE(matches("char c = 0;", expr(castExpr()))); // This test creates an implicit cast from lvalue to rvalue. - EXPECT_TRUE(matches("char c = 0, d = c;", expression(castExpr()))); + EXPECT_TRUE(matches("char c = 0, d = c;", expr(castExpr()))); } TEST(CastExpression, DoesNotMatchNonCasts) { - EXPECT_TRUE(notMatches("char c = '0';", expression(castExpr()))); - EXPECT_TRUE(notMatches("char c, &q = c;", expression(castExpr()))); - EXPECT_TRUE(notMatches("int i = (0);", expression(castExpr()))); - EXPECT_TRUE(notMatches("int i = 0;", expression(castExpr()))); + EXPECT_TRUE(notMatches("char c = '0';", expr(castExpr()))); + EXPECT_TRUE(notMatches("char c, &q = c;", expr(castExpr()))); + EXPECT_TRUE(notMatches("int i = (0);", expr(castExpr()))); + EXPECT_TRUE(notMatches("int i = 0;", expr(castExpr()))); } TEST(ReinterpretCast, MatchesSimpleCase) { EXPECT_TRUE(matches("char* p = reinterpret_cast<char*>(&p);", - expression(reinterpretCast()))); + expr(reinterpretCastExpr()))); } TEST(ReinterpretCast, DoesNotMatchOtherCasts) { EXPECT_TRUE(notMatches("char* p = (char*)(&p);", - expression(reinterpretCast()))); + expr(reinterpretCastExpr()))); EXPECT_TRUE(notMatches("char q, *p = const_cast<char*>(&q);", - expression(reinterpretCast()))); + expr(reinterpretCastExpr()))); EXPECT_TRUE(notMatches("void* p = static_cast<void*>(&p);", - expression(reinterpretCast()))); + expr(reinterpretCastExpr()))); EXPECT_TRUE(notMatches("struct B { virtual ~B() {} }; struct D : B {};" "B b;" "D* p = dynamic_cast<D*>(&b);", - expression(reinterpretCast()))); + expr(reinterpretCastExpr()))); } TEST(FunctionalCast, MatchesSimpleCase) { std::string foo_class = "class Foo { public: Foo(char*); };"; EXPECT_TRUE(matches(foo_class + "void r() { Foo f = Foo(\"hello world\"); }", - expression(functionalCast()))); + expr(functionalCastExpr()))); } TEST(FunctionalCast, DoesNotMatchOtherCasts) { std::string FooClass = "class Foo { public: Foo(char*); };"; EXPECT_TRUE( notMatches(FooClass + "void r() { Foo f = (Foo) \"hello world\"; }", - expression(functionalCast()))); + expr(functionalCastExpr()))); EXPECT_TRUE( notMatches(FooClass + "void r() { Foo f = \"hello world\"; }", - expression(functionalCast()))); + expr(functionalCastExpr()))); } TEST(DynamicCast, MatchesSimpleCase) { EXPECT_TRUE(matches("struct B { virtual ~B() {} }; struct D : B {};" "B b;" "D* p = dynamic_cast<D*>(&b);", - expression(dynamicCast()))); + expr(dynamicCastExpr()))); } TEST(StaticCast, MatchesSimpleCase) { EXPECT_TRUE(matches("void* p(static_cast<void*>(&p));", - expression(staticCast()))); + expr(staticCastExpr()))); } TEST(StaticCast, DoesNotMatchOtherCasts) { EXPECT_TRUE(notMatches("char* p = (char*)(&p);", - expression(staticCast()))); + expr(staticCastExpr()))); EXPECT_TRUE(notMatches("char q, *p = const_cast<char*>(&q);", - expression(staticCast()))); + expr(staticCastExpr()))); EXPECT_TRUE(notMatches("void* p = reinterpret_cast<char*>(&p);", - expression(staticCast()))); + expr(staticCastExpr()))); EXPECT_TRUE(notMatches("struct B { virtual ~B() {} }; struct D : B {};" "B b;" "D* p = dynamic_cast<D*>(&b);", - expression(staticCast()))); + expr(staticCastExpr()))); } TEST(HasDestinationType, MatchesSimpleCase) { EXPECT_TRUE(matches("char* p = static_cast<char*>(0);", - expression( - staticCast(hasDestinationType( - pointsTo(TypeMatcher(anything()))))))); + expr(staticCastExpr(hasDestinationType( + pointsTo(TypeMatcher(anything()))))))); } TEST(HasImplicitDestinationType, MatchesSimpleCase) { // This test creates an implicit const cast. EXPECT_TRUE(matches("int x; const int i = x;", - expression(implicitCast( + expr(implicitCastExpr( hasImplicitDestinationType(isInteger()))))); // This test creates an implicit array-to-pointer cast. EXPECT_TRUE(matches("int arr[3]; int *p = arr;", - expression(implicitCast(hasImplicitDestinationType( + expr(implicitCastExpr(hasImplicitDestinationType( pointsTo(TypeMatcher(anything()))))))); } TEST(HasImplicitDestinationType, DoesNotMatchIncorrectly) { // This test creates an implicit cast from int to char. EXPECT_TRUE(notMatches("char c = 0;", - expression(implicitCast(hasImplicitDestinationType( + expr(implicitCastExpr(hasImplicitDestinationType( unless(anything())))))); // This test creates an implicit array-to-pointer cast. EXPECT_TRUE(notMatches("int arr[3]; int *p = arr;", - expression(implicitCast(hasImplicitDestinationType( + expr(implicitCastExpr(hasImplicitDestinationType( unless(anything())))))); } TEST(ImplicitCast, MatchesSimpleCase) { // This test creates an implicit const cast. EXPECT_TRUE(matches("int x = 0; const int y = x;", - variable(hasInitializer(implicitCast())))); + varDecl(hasInitializer(implicitCastExpr())))); // This test creates an implicit cast from int to char. EXPECT_TRUE(matches("char c = 0;", - variable(hasInitializer(implicitCast())))); + varDecl(hasInitializer(implicitCastExpr())))); // This test creates an implicit array-to-pointer cast. EXPECT_TRUE(matches("int arr[6]; int *p = arr;", - variable(hasInitializer(implicitCast())))); + varDecl(hasInitializer(implicitCastExpr())))); } TEST(ImplicitCast, DoesNotMatchIncorrectly) { - // This test verifies that implicitCast() matches exactly when implicit casts + // This test verifies that implicitCastExpr() matches exactly when implicit casts // are present, and that it ignores explicit and paren casts. // These two test cases have no casts. EXPECT_TRUE(notMatches("int x = 0;", - variable(hasInitializer(implicitCast())))); + varDecl(hasInitializer(implicitCastExpr())))); EXPECT_TRUE(notMatches("int x = 0, &y = x;", - variable(hasInitializer(implicitCast())))); + varDecl(hasInitializer(implicitCastExpr())))); EXPECT_TRUE(notMatches("int x = 0; double d = (double) x;", - variable(hasInitializer(implicitCast())))); + varDecl(hasInitializer(implicitCastExpr())))); EXPECT_TRUE(notMatches("const int *p; int *q = const_cast<int *>(p);", - variable(hasInitializer(implicitCast())))); + varDecl(hasInitializer(implicitCastExpr())))); EXPECT_TRUE(notMatches("int x = (0);", - variable(hasInitializer(implicitCast())))); + varDecl(hasInitializer(implicitCastExpr())))); } TEST(IgnoringImpCasts, MatchesImpCasts) { @@ -2235,11 +2241,11 @@ TEST(IgnoringImpCasts, MatchesImpCasts) { // present and its inner matcher alone does not match. // Note that this test creates an implicit const cast. EXPECT_TRUE(matches("int x = 0; const int y = x;", - variable(hasInitializer(ignoringImpCasts( - declarationReference(to(variable(hasName("x"))))))))); + varDecl(hasInitializer(ignoringImpCasts( + declRefExpr(to(varDecl(hasName("x"))))))))); // This test creates an implict cast from int to char. EXPECT_TRUE(matches("char x = 0;", - variable(hasInitializer(ignoringImpCasts( + varDecl(hasInitializer(ignoringImpCasts( integerLiteral(equals(0))))))); } @@ -2248,82 +2254,82 @@ TEST(IgnoringImpCasts, DoesNotMatchIncorrectly) { // matcher does not match. // Note that the first test creates an implicit const cast. EXPECT_TRUE(notMatches("int x; const int y = x;", - variable(hasInitializer(ignoringImpCasts( + varDecl(hasInitializer(ignoringImpCasts( unless(anything())))))); EXPECT_TRUE(notMatches("int x; int y = x;", - variable(hasInitializer(ignoringImpCasts( + varDecl(hasInitializer(ignoringImpCasts( unless(anything())))))); // These tests verify that ignoringImplictCasts does not look through explicit // casts or parentheses. EXPECT_TRUE(notMatches("char* p = static_cast<char*>(0);", - variable(hasInitializer(ignoringImpCasts( - integerLiteral()))))); + varDecl(hasInitializer(ignoringImpCasts( + integerLiteral()))))); EXPECT_TRUE(notMatches("int i = (0);", - variable(hasInitializer(ignoringImpCasts( - integerLiteral()))))); + varDecl(hasInitializer(ignoringImpCasts( + integerLiteral()))))); EXPECT_TRUE(notMatches("float i = (float)0;", - variable(hasInitializer(ignoringImpCasts( - integerLiteral()))))); + varDecl(hasInitializer(ignoringImpCasts( + integerLiteral()))))); EXPECT_TRUE(notMatches("float i = float(0);", - variable(hasInitializer(ignoringImpCasts( - integerLiteral()))))); + varDecl(hasInitializer(ignoringImpCasts( + integerLiteral()))))); } TEST(IgnoringImpCasts, MatchesWithoutImpCasts) { // This test verifies that expressions that do not have implicit casts // still match the inner matcher. EXPECT_TRUE(matches("int x = 0; int &y = x;", - variable(hasInitializer(ignoringImpCasts( - declarationReference(to(variable(hasName("x"))))))))); + varDecl(hasInitializer(ignoringImpCasts( + declRefExpr(to(varDecl(hasName("x"))))))))); } TEST(IgnoringParenCasts, MatchesParenCasts) { // This test checks that ignoringParenCasts matches when parentheses and/or // casts are present and its inner matcher alone does not match. EXPECT_TRUE(matches("int x = (0);", - variable(hasInitializer(ignoringParenCasts( - integerLiteral(equals(0))))))); + varDecl(hasInitializer(ignoringParenCasts( + integerLiteral(equals(0))))))); EXPECT_TRUE(matches("int x = (((((0)))));", - variable(hasInitializer(ignoringParenCasts( - integerLiteral(equals(0))))))); + varDecl(hasInitializer(ignoringParenCasts( + integerLiteral(equals(0))))))); // This test creates an implict cast from int to char in addition to the // parentheses. EXPECT_TRUE(matches("char x = (0);", - variable(hasInitializer(ignoringParenCasts( - integerLiteral(equals(0))))))); + varDecl(hasInitializer(ignoringParenCasts( + integerLiteral(equals(0))))))); EXPECT_TRUE(matches("char x = (char)0;", - variable(hasInitializer(ignoringParenCasts( - integerLiteral(equals(0))))))); + varDecl(hasInitializer(ignoringParenCasts( + integerLiteral(equals(0))))))); EXPECT_TRUE(matches("char* p = static_cast<char*>(0);", - variable(hasInitializer(ignoringParenCasts( + varDecl(hasInitializer(ignoringParenCasts( integerLiteral(equals(0))))))); } TEST(IgnoringParenCasts, MatchesWithoutParenCasts) { // This test verifies that expressions that do not have any casts still match. EXPECT_TRUE(matches("int x = 0;", - variable(hasInitializer(ignoringParenCasts( - integerLiteral(equals(0))))))); + varDecl(hasInitializer(ignoringParenCasts( + integerLiteral(equals(0))))))); } TEST(IgnoringParenCasts, DoesNotMatchIncorrectly) { // These tests verify that ignoringImpCasts does not match if the inner // matcher does not match. EXPECT_TRUE(notMatches("int x = ((0));", - variable(hasInitializer(ignoringParenCasts( + varDecl(hasInitializer(ignoringParenCasts( unless(anything())))))); // This test creates an implicit cast from int to char in addition to the // parentheses. EXPECT_TRUE(notMatches("char x = ((0));", - variable(hasInitializer(ignoringParenCasts( + varDecl(hasInitializer(ignoringParenCasts( unless(anything())))))); EXPECT_TRUE(notMatches("char *x = static_cast<char *>((0));", - variable(hasInitializer(ignoringParenCasts( + varDecl(hasInitializer(ignoringParenCasts( unless(anything())))))); } @@ -2333,23 +2339,23 @@ TEST(IgnoringParenAndImpCasts, MatchesParenImpCasts) { // does not match. // Note that this test creates an implicit const cast. EXPECT_TRUE(matches("int x = 0; const int y = x;", - variable(hasInitializer(ignoringParenImpCasts( - declarationReference(to(variable(hasName("x"))))))))); + varDecl(hasInitializer(ignoringParenImpCasts( + declRefExpr(to(varDecl(hasName("x"))))))))); // This test creates an implicit cast from int to char. EXPECT_TRUE(matches("const char x = (0);", - variable(hasInitializer(ignoringParenImpCasts( - integerLiteral(equals(0))))))); + varDecl(hasInitializer(ignoringParenImpCasts( + integerLiteral(equals(0))))))); } TEST(IgnoringParenAndImpCasts, MatchesWithoutParenImpCasts) { // This test verifies that expressions that do not have parentheses or // implicit casts still match. EXPECT_TRUE(matches("int x = 0; int &y = x;", - variable(hasInitializer(ignoringParenImpCasts( - declarationReference(to(variable(hasName("x"))))))))); + varDecl(hasInitializer(ignoringParenImpCasts( + declRefExpr(to(varDecl(hasName("x"))))))))); EXPECT_TRUE(matches("int x = 0;", - variable(hasInitializer(ignoringParenImpCasts( - integerLiteral(equals(0))))))); + varDecl(hasInitializer(ignoringParenImpCasts( + integerLiteral(equals(0))))))); } TEST(IgnoringParenAndImpCasts, DoesNotMatchIncorrectly) { @@ -2357,56 +2363,56 @@ TEST(IgnoringParenAndImpCasts, DoesNotMatchIncorrectly) { // the inner matcher does not match. // This test creates an implicit cast. EXPECT_TRUE(notMatches("char c = ((3));", - variable(hasInitializer(ignoringParenImpCasts( + varDecl(hasInitializer(ignoringParenImpCasts( unless(anything())))))); // These tests verify that ignoringParenAndImplictCasts does not look // through explicit casts. EXPECT_TRUE(notMatches("float y = (float(0));", - variable(hasInitializer(ignoringParenImpCasts( - integerLiteral()))))); + varDecl(hasInitializer(ignoringParenImpCasts( + integerLiteral()))))); EXPECT_TRUE(notMatches("float y = (float)0;", - variable(hasInitializer(ignoringParenImpCasts( - integerLiteral()))))); + varDecl(hasInitializer(ignoringParenImpCasts( + integerLiteral()))))); EXPECT_TRUE(notMatches("char* p = static_cast<char*>(0);", - variable(hasInitializer(ignoringParenImpCasts( - integerLiteral()))))); + varDecl(hasInitializer(ignoringParenImpCasts( + integerLiteral()))))); } TEST(HasSourceExpression, MatchesImplicitCasts) { EXPECT_TRUE(matches("class string {}; class URL { public: URL(string s); };" "void r() {string a_string; URL url = a_string; }", - expression(implicitCast( - hasSourceExpression(constructorCall()))))); + expr(implicitCastExpr( + hasSourceExpression(constructExpr()))))); } TEST(HasSourceExpression, MatchesExplicitCasts) { EXPECT_TRUE(matches("float x = static_cast<float>(42);", - expression(explicitCast( - hasSourceExpression(hasDescendant( - expression(integerLiteral()))))))); + expr(explicitCastExpr( + hasSourceExpression(hasDescendant( + expr(integerLiteral()))))))); } TEST(Statement, DoesNotMatchDeclarations) { - EXPECT_TRUE(notMatches("class X {};", statement())); + EXPECT_TRUE(notMatches("class X {};", stmt())); } TEST(Statement, MatchesCompoundStatments) { - EXPECT_TRUE(matches("void x() {}", statement())); + EXPECT_TRUE(matches("void x() {}", stmt())); } TEST(DeclarationStatement, DoesNotMatchCompoundStatements) { - EXPECT_TRUE(notMatches("void x() {}", declarationStatement())); + EXPECT_TRUE(notMatches("void x() {}", declStmt())); } TEST(DeclarationStatement, MatchesVariableDeclarationStatements) { - EXPECT_TRUE(matches("void x() { int a; }", declarationStatement())); + EXPECT_TRUE(matches("void x() { int a; }", declStmt())); } TEST(InitListExpression, MatchesInitListExpression) { EXPECT_TRUE(matches("int a[] = { 1, 2 };", initListExpr(hasType(asString("int [2]"))))); EXPECT_TRUE(matches("struct B { int x, y; }; B b = { 5, 6 };", - initListExpr(hasType(record(hasName("B")))))); + initListExpr(hasType(recordDecl(hasName("B")))))); } TEST(UsingDeclaration, MatchesUsingDeclarations) { @@ -2422,24 +2428,24 @@ TEST(UsingDeclaration, MatchesShadowUsingDelcarations) { TEST(UsingDeclaration, MatchesSpecificTarget) { EXPECT_TRUE(matches("namespace f { int a; void b(); } using f::b;", usingDecl(hasAnyUsingShadowDecl( - hasTargetDecl(function()))))); + hasTargetDecl(functionDecl()))))); EXPECT_TRUE(notMatches("namespace f { int a; void b(); } using f::a;", usingDecl(hasAnyUsingShadowDecl( - hasTargetDecl(function()))))); + hasTargetDecl(functionDecl()))))); } TEST(UsingDeclaration, ThroughUsingDeclaration) { EXPECT_TRUE(matches( "namespace a { void f(); } using a::f; void g() { f(); }", - declarationReference(throughUsingDecl(anything())))); + declRefExpr(throughUsingDecl(anything())))); EXPECT_TRUE(notMatches( "namespace a { void f(); } using a::f; void g() { a::f(); }", - declarationReference(throughUsingDecl(anything())))); + declRefExpr(throughUsingDecl(anything())))); } TEST(SingleDecl, IsSingleDecl) { StatementMatcher SingleDeclStmt = - declarationStatement(hasSingleDecl(variable(hasInitializer(anything())))); + declStmt(hasSingleDecl(varDecl(hasInitializer(anything())))); EXPECT_TRUE(matches("void f() {int a = 4;}", SingleDeclStmt)); EXPECT_TRUE(notMatches("void f() {int a;}", SingleDeclStmt)); EXPECT_TRUE(notMatches("void f() {int a = 4, b = 3;}", @@ -2447,28 +2453,26 @@ TEST(SingleDecl, IsSingleDecl) { } TEST(DeclStmt, ContainsDeclaration) { - DeclarationMatcher MatchesInit = variable(hasInitializer(anything())); + DeclarationMatcher MatchesInit = varDecl(hasInitializer(anything())); EXPECT_TRUE(matches("void f() {int a = 4;}", - declarationStatement(containsDeclaration(0, - MatchesInit)))); + declStmt(containsDeclaration(0, MatchesInit)))); EXPECT_TRUE(matches("void f() {int a = 4, b = 3;}", - declarationStatement(containsDeclaration(0, MatchesInit), - containsDeclaration(1, - MatchesInit)))); + declStmt(containsDeclaration(0, MatchesInit), + containsDeclaration(1, MatchesInit)))); unsigned WrongIndex = 42; EXPECT_TRUE(notMatches("void f() {int a = 4, b = 3;}", - declarationStatement(containsDeclaration(WrongIndex, + declStmt(containsDeclaration(WrongIndex, MatchesInit)))); } TEST(DeclCount, DeclCountIsCorrect) { EXPECT_TRUE(matches("void f() {int i,j;}", - declarationStatement(declCountIs(2)))); + declStmt(declCountIs(2)))); EXPECT_TRUE(notMatches("void f() {int i,j; int k;}", - declarationStatement(declCountIs(3)))); + declStmt(declCountIs(3)))); EXPECT_TRUE(notMatches("void f() {int i,j, k, l;}", - declarationStatement(declCountIs(3)))); + declStmt(declCountIs(3)))); } TEST(While, MatchesWhileLoops) { @@ -2496,40 +2500,42 @@ TEST(SwitchCase, MatchesCase) { TEST(HasConditionVariableStatement, DoesNotMatchCondition) { EXPECT_TRUE(notMatches( "void x() { if(true) {} }", - ifStmt(hasConditionVariableStatement(declarationStatement())))); + ifStmt(hasConditionVariableStatement(declStmt())))); EXPECT_TRUE(notMatches( "void x() { int x; if((x = 42)) {} }", - ifStmt(hasConditionVariableStatement(declarationStatement())))); + ifStmt(hasConditionVariableStatement(declStmt())))); } TEST(HasConditionVariableStatement, MatchesConditionVariables) { EXPECT_TRUE(matches( "void x() { if(int* a = 0) {} }", - ifStmt(hasConditionVariableStatement(declarationStatement())))); + ifStmt(hasConditionVariableStatement(declStmt())))); } TEST(ForEach, BindsOneNode) { EXPECT_TRUE(matchAndVerifyResultTrue("class C { int x; };", - record(hasName("C"), forEach(field(hasName("x")).bind("x"))), + recordDecl(hasName("C"), forEach(fieldDecl(hasName("x")).bind("x"))), new VerifyIdIsBoundToDecl<FieldDecl>("x", 1))); } TEST(ForEach, BindsMultipleNodes) { EXPECT_TRUE(matchAndVerifyResultTrue("class C { int x; int y; int z; };", - record(hasName("C"), forEach(field().bind("f"))), + recordDecl(hasName("C"), forEach(fieldDecl().bind("f"))), new VerifyIdIsBoundToDecl<FieldDecl>("f", 3))); } TEST(ForEach, BindsRecursiveCombinations) { EXPECT_TRUE(matchAndVerifyResultTrue( "class C { class D { int x; int y; }; class E { int y; int z; }; };", - record(hasName("C"), forEach(record(forEach(field().bind("f"))))), + recordDecl(hasName("C"), + forEach(recordDecl(forEach(fieldDecl().bind("f"))))), new VerifyIdIsBoundToDecl<FieldDecl>("f", 4))); } TEST(ForEachDescendant, BindsOneNode) { EXPECT_TRUE(matchAndVerifyResultTrue("class C { class D { int x; }; };", - record(hasName("C"), forEachDescendant(field(hasName("x")).bind("x"))), + recordDecl(hasName("C"), + forEachDescendant(fieldDecl(hasName("x")).bind("x"))), new VerifyIdIsBoundToDecl<FieldDecl>("x", 1))); } @@ -2537,7 +2543,7 @@ TEST(ForEachDescendant, BindsMultipleNodes) { EXPECT_TRUE(matchAndVerifyResultTrue( "class C { class D { int x; int y; }; " " class E { class F { int y; int z; }; }; };", - record(hasName("C"), forEachDescendant(field().bind("f"))), + recordDecl(hasName("C"), forEachDescendant(fieldDecl().bind("f"))), new VerifyIdIsBoundToDecl<FieldDecl>("f", 4))); } @@ -2545,8 +2551,8 @@ TEST(ForEachDescendant, BindsRecursiveCombinations) { EXPECT_TRUE(matchAndVerifyResultTrue( "class C { class D { " " class E { class F { class G { int y; int z; }; }; }; }; };", - record(hasName("C"), forEachDescendant(record( - forEachDescendant(field().bind("f"))))), + recordDecl(hasName("C"), forEachDescendant(recordDecl( + forEachDescendant(fieldDecl().bind("f"))))), new VerifyIdIsBoundToDecl<FieldDecl>("f", 8))); } @@ -2557,18 +2563,18 @@ TEST(IsTemplateInstantiation, MatchesImplicitClassTemplateInstantiation) { EXPECT_TRUE(matches( "template <typename T> class X {}; class A {}; X<A> x;", - record(hasName("::X"), isTemplateInstantiation()))); + recordDecl(hasName("::X"), isTemplateInstantiation()))); EXPECT_TRUE(matches( "template <typename T> class X { T t; }; class A {}; X<A> x;", - record(isTemplateInstantiation(), hasDescendant( - field(hasType(record(hasName("A")))))))); + recordDecl(isTemplateInstantiation(), hasDescendant( + fieldDecl(hasType(recordDecl(hasName("A")))))))); } TEST(IsTemplateInstantiation, MatchesImplicitFunctionTemplateInstantiation) { EXPECT_TRUE(matches( "template <typename T> void f(T t) {} class A {}; void g() { f(A()); }", - function(hasParameter(0, hasType(record(hasName("A")))), + functionDecl(hasParameter(0, hasType(recordDecl(hasName("A")))), isTemplateInstantiation()))); } @@ -2576,8 +2582,8 @@ TEST(IsTemplateInstantiation, MatchesExplicitClassTemplateInstantiation) { EXPECT_TRUE(matches( "template <typename T> class X { T t; }; class A {};" "template class X<A>;", - record(isTemplateInstantiation(), hasDescendant( - field(hasType(record(hasName("A")))))))); + recordDecl(isTemplateInstantiation(), hasDescendant( + fieldDecl(hasType(recordDecl(hasName("A")))))))); } TEST(IsTemplateInstantiation, @@ -2585,7 +2591,7 @@ TEST(IsTemplateInstantiation, EXPECT_TRUE(matches( "template <typename T> class X {};" "template <typename T> class X<T*> {}; class A {}; X<A*> x;", - record(hasName("::X"), isTemplateInstantiation()))); + recordDecl(hasName("::X"), isTemplateInstantiation()))); } TEST(IsTemplateInstantiation, @@ -2596,7 +2602,7 @@ TEST(IsTemplateInstantiation, " template <typename U> class Y { U u; };" " Y<A> y;" "};", - record(hasName("::X::Y"), isTemplateInstantiation()))); + recordDecl(hasName("::X::Y"), isTemplateInstantiation()))); } TEST(IsTemplateInstantiation, DoesNotMatchInstantiationsInsideOfInstantiation) { @@ -2609,30 +2615,30 @@ TEST(IsTemplateInstantiation, DoesNotMatchInstantiationsInsideOfInstantiation) { " template <typename U> class Y { U u; };" " Y<T> y;" "}; X<A> x;", - record(hasName("::X<A>::Y"), unless(isTemplateInstantiation())))); + recordDecl(hasName("::X<A>::Y"), unless(isTemplateInstantiation())))); } TEST(IsTemplateInstantiation, DoesNotMatchExplicitClassTemplateSpecialization) { EXPECT_TRUE(notMatches( "template <typename T> class X {}; class A {};" "template <> class X<A> {}; X<A> x;", - record(hasName("::X"), isTemplateInstantiation()))); + recordDecl(hasName("::X"), isTemplateInstantiation()))); } TEST(IsTemplateInstantiation, DoesNotMatchNonTemplate) { EXPECT_TRUE(notMatches( "class A {}; class Y { A a; };", - record(isTemplateInstantiation()))); + recordDecl(isTemplateInstantiation()))); } TEST(IsExplicitTemplateSpecialization, DoesNotMatchPrimaryTemplate) { EXPECT_TRUE(notMatches( "template <typename T> class X {};", - record(isExplicitTemplateSpecialization()))); + recordDecl(isExplicitTemplateSpecialization()))); EXPECT_TRUE(notMatches( "template <typename T> void f(T t);", - function(isExplicitTemplateSpecialization()))); + functionDecl(isExplicitTemplateSpecialization()))); } TEST(IsExplicitTemplateSpecialization, @@ -2640,21 +2646,21 @@ TEST(IsExplicitTemplateSpecialization, EXPECT_TRUE(notMatches( "template <typename T> class X {};" "template class X<int>; extern template class X<long>;", - record(isExplicitTemplateSpecialization()))); + recordDecl(isExplicitTemplateSpecialization()))); EXPECT_TRUE(notMatches( "template <typename T> void f(T t) {}" "template void f(int t); extern template void f(long t);", - function(isExplicitTemplateSpecialization()))); + functionDecl(isExplicitTemplateSpecialization()))); } TEST(IsExplicitTemplateSpecialization, DoesNotMatchImplicitTemplateInstantiations) { EXPECT_TRUE(notMatches( "template <typename T> class X {}; X<int> x;", - record(isExplicitTemplateSpecialization()))); + recordDecl(isExplicitTemplateSpecialization()))); EXPECT_TRUE(notMatches( "template <typename T> void f(T t); void g() { f(10); }", - function(isExplicitTemplateSpecialization()))); + functionDecl(isExplicitTemplateSpecialization()))); } TEST(IsExplicitTemplateSpecialization, @@ -2662,11 +2668,11 @@ TEST(IsExplicitTemplateSpecialization, EXPECT_TRUE(matches( "template <typename T> class X {};" "template<> class X<int> {};", - record(isExplicitTemplateSpecialization()))); + recordDecl(isExplicitTemplateSpecialization()))); EXPECT_TRUE(matches( "template <typename T> void f(T t) {}" "template<> void f(int t) {}", - function(isExplicitTemplateSpecialization()))); + functionDecl(isExplicitTemplateSpecialization()))); } } // end namespace ast_matchers diff --git a/clang/unittests/Tooling/RefactoringCallbacksTest.cpp b/clang/unittests/Tooling/RefactoringCallbacksTest.cpp index 00eb193d74c..7add3856b2b 100644 --- a/clang/unittests/Tooling/RefactoringCallbacksTest.cpp +++ b/clang/unittests/Tooling/RefactoringCallbacksTest.cpp @@ -40,28 +40,28 @@ TEST(RefactoringCallbacksTest, ReplacesStmtsWithString) { std::string Code = "void f() { int i = 1; }"; std::string Expected = "void f() { ; }"; ReplaceStmtWithText Callback("id", ";"); - expectRewritten(Code, Expected, id("id", declarationStatement()), Callback); + expectRewritten(Code, Expected, id("id", declStmt()), Callback); } TEST(RefactoringCallbacksTest, ReplacesStmtsInCalledMacros) { std::string Code = "#define A void f() { int i = 1; }\nA"; std::string Expected = "#define A void f() { ; }\nA"; ReplaceStmtWithText Callback("id", ";"); - expectRewritten(Code, Expected, id("id", declarationStatement()), Callback); + expectRewritten(Code, Expected, id("id", declStmt()), Callback); } TEST(RefactoringCallbacksTest, IgnoresStmtsInUncalledMacros) { std::string Code = "#define A void f() { int i = 1; }"; std::string Expected = "#define A void f() { int i = 1; }"; ReplaceStmtWithText Callback("id", ";"); - expectRewritten(Code, Expected, id("id", declarationStatement()), Callback); + expectRewritten(Code, Expected, id("id", declStmt()), Callback); } TEST(RefactoringCallbacksTest, ReplacesInteger) { std::string Code = "void f() { int i = 1; }"; std::string Expected = "void f() { int i = 2; }"; ReplaceStmtWithText Callback("id", "2"); - expectRewritten(Code, Expected, id("id", expression(integerLiteral())), + expectRewritten(Code, Expected, id("id", expr(integerLiteral())), Callback); } @@ -72,7 +72,7 @@ TEST(RefactoringCallbacksTest, ReplacesStmtWithStmt) { expectRewritten(Code, Expected, id("always-false", conditionalOperator( hasCondition(boolLiteral(equals(false))), - hasFalseExpression(id("should-be", expression())))), + hasFalseExpression(id("should-be", expr())))), Callback); } @@ -82,8 +82,8 @@ TEST(RefactoringCallbacksTest, ReplacesIfStmt) { ReplaceIfStmtWithItsBody Callback("id", true); expectRewritten(Code, Expected, id("id", ifStmt( - hasCondition(implicitCast(hasSourceExpression( - declarationReference(to(variable(hasName("a"))))))))), + hasCondition(implicitCastExpr(hasSourceExpression( + declRefExpr(to(varDecl(hasName("a"))))))))), Callback); } |