Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
Do not use data recursion in ASTMatchFinder.
Browse files Browse the repository at this point in the history
The matchers rely on the complete AST being traversed as shown by the new test cases.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168022 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
djasper committed Nov 15, 2012
1 parent 5d23eea commit 278057f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/ASTMatchers/ASTMatchFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class ParentMapASTVisitor : public RecursiveASTVisitor<ParentMapASTVisitor> {

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 <typename T>
bool TraverseNode(T *Node, bool (VisitorBase::*traverse)(T*)) {
Expand Down Expand Up @@ -222,6 +225,9 @@ class MatchChildASTVisitor

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.
Expand Down Expand Up @@ -471,6 +477,9 @@ class MatchASTVisitor : public RecursiveASTVisitor<MatchASTVisitor>,

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
Expand Down
19 changes: 19 additions & 0 deletions unittests/ASTMatchers/ASTMatchersTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CXXOperatorCallExpr>("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"))));
Expand Down

0 comments on commit 278057f

Please sign in to comment.