From 0f9f019ff8fc6dcc7ae13328c60cc4164ae13782 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Thu, 15 Nov 2012 03:29:05 +0000 Subject: [PATCH] Do not use data recursion in ASTMatchFinder. The matchers rely on the complete AST being traversed as shown by the new test cases. llvm-svn: 168022 --- clang/lib/ASTMatchers/ASTMatchFinder.cpp | 9 +++++++++ clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp b/clang/lib/ASTMatchers/ASTMatchFinder.cpp index 6ff125b..04a2b35 100644 --- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp +++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp @@ -58,6 +58,9 @@ private: bool shouldVisitTemplateInstantiations() const { return true; } bool shouldVisitImplicitCode() const { return true; } + // Disables data recursion. We intercept Traverse* methods in the RAV, which + // are not triggered during data recursion. + bool shouldUseDataRecursionFor(clang::Stmt *S) const { return false; } template bool TraverseNode(T *Node, bool (VisitorBase::*traverse)(T*)) { @@ -222,6 +225,9 @@ public: bool shouldVisitTemplateInstantiations() const { return true; } bool shouldVisitImplicitCode() const { return true; } + // Disables data recursion. We intercept Traverse* methods in the RAV, which + // are not triggered during data recursion. + bool shouldUseDataRecursionFor(clang::Stmt *S) const { return false; } private: // Used for updating the depth during traversal. @@ -471,6 +477,9 @@ public: bool shouldVisitTemplateInstantiations() const { return true; } bool shouldVisitImplicitCode() const { return true; } + // Disables data recursion. We intercept Traverse* methods in the RAV, which + // are not triggered during data recursion. + bool shouldUseDataRecursionFor(clang::Stmt *S) const { return false; } private: // Implements a BoundNodesTree::Visitor that calls a MatchCallback with diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index e15940a..6d8c000 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -947,6 +947,25 @@ TEST(Matcher, HasOperatorNameForOverloadedOperatorCall) { OpCallLessLess)); } +TEST(Matcher, NestedOverloadedOperatorCalls) { + EXPECT_TRUE(matchAndVerifyResultTrue( + "class Y { }; " + "Y& operator&&(Y& x, Y& y) { return x; }; " + "Y a; Y b; Y c; Y d = a && b && c;", + operatorCallExpr(hasOverloadedOperatorName("&&")).bind("x"), + new VerifyIdIsBoundTo("x", 2))); + EXPECT_TRUE(matches( + "class Y { }; " + "Y& operator&&(Y& x, Y& y) { return x; }; " + "Y a; Y b; Y c; Y d = a && b && c;", + operatorCallExpr(hasParent(operatorCallExpr())))); + EXPECT_TRUE(matches( + "class Y { }; " + "Y& operator&&(Y& x, Y& y) { return x; }; " + "Y a; Y b; Y c; Y d = a && b && c;", + operatorCallExpr(hasDescendant(operatorCallExpr())))); +} + TEST(Matcher, ThisPointerType) { StatementMatcher MethodOnY = memberCallExpr(thisPointerType(recordDecl(hasName("Y")))); -- 2.7.4