Author: Stephen Kelly Date: 2020-01-20T11:18:35Z New Revision: 514e3c3694a3457ea5c1b89420246fd845791afd
URL: https://github.com/llvm/llvm-project/commit/514e3c3694a3457ea5c1b89420246fd845791afd DIFF: https://github.com/llvm/llvm-project/commit/514e3c3694a3457ea5c1b89420246fd845791afd.diff LOG: Add missing tests for parent traversal Added: Modified: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp Removed: ################################################################################ diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp index b0696fdb8a75..27f446467fa3 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp @@ -1633,6 +1633,15 @@ void foo() traverse(ast_type_traits::TK_IgnoreImplicitCastsAndParentheses, Matcher))); + auto ParentMatcher = floatLiteral(hasParent(varDecl(hasName("i")))); + + EXPECT_TRUE( + notMatches(VarDeclCode, traverse(ast_type_traits::TK_AsIs, ParentMatcher))); + EXPECT_TRUE( + matches(VarDeclCode, + traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource, + ParentMatcher))); + EXPECT_TRUE( matches(VarDeclCode, decl(traverse(ast_type_traits::TK_AsIs, anyOf(cxxRecordDecl(), varDecl()))))); @@ -1714,6 +1723,13 @@ void bar() functionDecl(hasName("foo"), traverse(ast_type_traits::TK_AsIs, hasDescendant(floatLiteral()))))); + EXPECT_TRUE( + notMatches(Code, traverse(ast_type_traits::TK_AsIs, floatLiteral(hasParent(callExpr(callee(functionDecl(hasName("foo"))))))))); + EXPECT_TRUE( + matches(Code, + traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource, + floatLiteral(hasParent(callExpr(callee(functionDecl(hasName("foo"))))))))); + Code = R"cpp( void foo() { @@ -1724,6 +1740,10 @@ void foo() matches(Code, traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource, varDecl(hasInitializer(integerLiteral(equals(3))))))); + EXPECT_TRUE( + matches(Code, + traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource, + integerLiteral(equals(3), hasParent(varDecl(hasName("i"))))))); } template <typename MatcherT> @@ -1905,12 +1925,21 @@ void func14() { returnStmt(forFunction(functionDecl(hasName("func1"))), hasReturnValue(integerLiteral(equals(42))))))); + EXPECT_TRUE(matches( + Code, traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource, + integerLiteral(equals(42), hasParent(returnStmt(forFunction(functionDecl(hasName("func1")))))) + ))); + EXPECT_TRUE(matches( Code, traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource, returnStmt(forFunction(functionDecl(hasName("func2"))), hasReturnValue(cxxTemporaryObjectExpr( hasArgument(0, integerLiteral(equals(42))))))))); + EXPECT_TRUE(matches( + Code, + traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource, + integerLiteral(equals(42), hasParent(cxxTemporaryObjectExpr(hasParent(returnStmt(forFunction(functionDecl(hasName("func2"))))))))))); EXPECT_TRUE(matches( Code, traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource, @@ -1919,6 +1948,10 @@ void func14() { cxxFunctionalCastExpr(hasSourceExpression( integerLiteral(equals(42))))))))); + EXPECT_TRUE(matches( + Code, traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource, + integerLiteral(equals(42), hasParent(cxxFunctionalCastExpr(hasParent(returnStmt(forFunction(functionDecl(hasName("func3")))) ))))))); + EXPECT_TRUE(matches( Code, traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource, returnStmt(forFunction(functionDecl(hasName("func4"))), @@ -1957,18 +1990,32 @@ void func14() { hasReturnValue( declRefExpr(to(varDecl(hasName("a"))))))))); + EXPECT_TRUE(matches( + Code, traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource, + declRefExpr(to(varDecl(hasName("a"))), hasParent(returnStmt(forFunction(functionDecl(hasName("func10"))))))))); + EXPECT_TRUE(matches( Code, traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource, returnStmt(forFunction(functionDecl(hasName("func11"))), hasReturnValue( declRefExpr(to(varDecl(hasName("b"))))))))); + EXPECT_TRUE(matches( + Code, traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource, + declRefExpr(to(varDecl(hasName("b"))), hasParent(returnStmt(forFunction(functionDecl(hasName("func11")))))) + ))); + EXPECT_TRUE(matches( Code, traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource, returnStmt(forFunction(functionDecl(hasName("func12"))), hasReturnValue( declRefExpr(to(varDecl(hasName("c"))))))))); + EXPECT_TRUE(matches( + Code, traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource, + declRefExpr(to(varDecl(hasName("c"))), hasParent(returnStmt(forFunction(functionDecl(hasName("func12")))))) + ))); + EXPECT_TRUE(matches( Code, traverse( @@ -1980,6 +2027,19 @@ void func14() { varDecl(hasName("c"))))))), has(parmVarDecl(hasName("d"))))))); + EXPECT_TRUE(matches( + Code, + traverse( + ast_type_traits::TK_IgnoreUnlessSpelledInSource, + declRefExpr(to(varDecl(hasName("a"))), hasParent( lambdaExpr(forFunction(functionDecl(hasName("func13")))) ))))); + + EXPECT_TRUE(matches( + Code, + traverse( + ast_type_traits::TK_IgnoreUnlessSpelledInSource, + varDecl(hasName("b"), hasInitializer(declRefExpr(to( + varDecl(hasName("c"))))), hasParent( lambdaExpr(forFunction(functionDecl(hasName("func13")))) ))))); + EXPECT_TRUE(matches( Code, traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource, lambdaExpr( _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits