Skip to content

Commit

Permalink
Make RecursiveASTVisitor call WalkUpFrom for operators when the data …
Browse files Browse the repository at this point in the history
…recursion queue is absent

Reviewers: eduucaldas, ymandel, rsmith

Reviewed By: eduucaldas

Subscribers: gribozavr2, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82889
  • Loading branch information
gribozavr committed Jul 3, 2020
1 parent 7b0be96 commit 8bf4c40
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
4 changes: 4 additions & 0 deletions clang/include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ template <typename Derived> class RecursiveASTVisitor {
if (!getDerived().shouldTraversePostOrder()) \
TRY_TO(WalkUpFromUnary##NAME(S)); \
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr()); \
if (!Queue && getDerived().shouldTraversePostOrder()) \
TRY_TO(WalkUpFromUnary##NAME(S)); \
return true; \
} \
bool WalkUpFromUnary##NAME(UnaryOperator *S) { \
Expand All @@ -433,6 +435,8 @@ template <typename Derived> class RecursiveASTVisitor {
TRY_TO(WalkUpFromBin##NAME(S)); \
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLHS()); \
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRHS()); \
if (!Queue && getDerived().shouldTraversePostOrder()) \
TRY_TO(WalkUpFromBin##NAME(S)); \
return true; \
} \
bool WalkUpFromBin##NAME(BINOP_TYPE *S) { \
Expand Down
21 changes: 12 additions & 9 deletions clang/unittests/Tooling/RecursiveASTVisitorTests/Callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,14 +606,13 @@ TraverseUnaryMinus UnaryOperator(-)
WalkUpFromStmt IntegerLiteral(3)
)txt"));

// FIXME: The following log should include a call to WalkUpFromStmt for
// UnaryOperator(-).
EXPECT_TRUE(visitorCallbackLogEqual(
RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
R"txt(
WalkUpFromStmt IntegerLiteral(1)
TraverseUnaryMinus UnaryOperator(-)
WalkUpFromStmt IntegerLiteral(2)
WalkUpFromStmt UnaryOperator(-)
WalkUpFromStmt IntegerLiteral(3)
WalkUpFromStmt CompoundStmt
)txt"));
Expand Down Expand Up @@ -675,7 +674,6 @@ WalkUpFromExpr IntegerLiteral(3)
WalkUpFromStmt IntegerLiteral(3)
)txt"));

// FIXME: The following log should include a call to WalkUpFromUnaryMinus.
EXPECT_TRUE(visitorCallbackLogEqual(
RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
R"txt(
Expand All @@ -684,6 +682,9 @@ WalkUpFromExpr IntegerLiteral(1)
TraverseUnaryMinus UnaryOperator(-)
WalkUpFromExpr IntegerLiteral(2)
WalkUpFromStmt IntegerLiteral(2)
WalkUpFromUnaryMinus UnaryOperator(-)
WalkUpFromExpr UnaryOperator(-)
WalkUpFromStmt UnaryOperator(-)
WalkUpFromExpr IntegerLiteral(3)
WalkUpFromStmt IntegerLiteral(3)
WalkUpFromStmt CompoundStmt
Expand Down Expand Up @@ -996,15 +997,14 @@ TraverseBinAdd BinaryOperator(+)
WalkUpFromStmt IntegerLiteral(4)
)txt"));

// FIXME: The following log should include a call to WalkUpFromStmt for
// BinaryOperator(+).
EXPECT_TRUE(visitorCallbackLogEqual(
RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
R"txt(
WalkUpFromStmt IntegerLiteral(1)
TraverseBinAdd BinaryOperator(+)
WalkUpFromStmt IntegerLiteral(2)
WalkUpFromStmt IntegerLiteral(3)
WalkUpFromStmt BinaryOperator(+)
WalkUpFromStmt IntegerLiteral(4)
WalkUpFromStmt CompoundStmt
)txt"));
Expand Down Expand Up @@ -1067,7 +1067,6 @@ WalkUpFromExpr IntegerLiteral(4)
WalkUpFromStmt IntegerLiteral(4)
)txt"));

// FIXME: The following log should include a call to WalkUpFromBinAdd.
EXPECT_TRUE(visitorCallbackLogEqual(
RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
R"txt(
Expand All @@ -1078,6 +1077,9 @@ TraverseBinAdd BinaryOperator(+)
WalkUpFromStmt IntegerLiteral(2)
WalkUpFromExpr IntegerLiteral(3)
WalkUpFromStmt IntegerLiteral(3)
WalkUpFromBinAdd BinaryOperator(+)
WalkUpFromExpr BinaryOperator(+)
WalkUpFromStmt BinaryOperator(+)
WalkUpFromExpr IntegerLiteral(4)
WalkUpFromStmt IntegerLiteral(4)
WalkUpFromStmt CompoundStmt
Expand Down Expand Up @@ -1396,15 +1398,14 @@ TraverseBinAddAssign CompoundAssignOperator(+=)
WalkUpFromStmt IntegerLiteral(3)
)txt"));

// FIXME: The following log should include a call to WalkUpFromStmt for
// CompoundAssignOperator(+=).
EXPECT_TRUE(visitorCallbackLogEqual(
RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
R"txt(
WalkUpFromStmt IntegerLiteral(1)
TraverseBinAddAssign CompoundAssignOperator(+=)
WalkUpFromStmt DeclRefExpr(a)
WalkUpFromStmt IntegerLiteral(2)
WalkUpFromStmt CompoundAssignOperator(+=)
WalkUpFromStmt IntegerLiteral(3)
WalkUpFromStmt CompoundStmt
)txt"));
Expand Down Expand Up @@ -1470,7 +1471,6 @@ WalkUpFromExpr IntegerLiteral(3)
WalkUpFromStmt IntegerLiteral(3)
)txt"));

// FIXME: The following log should include a call to WalkUpFromBinAddAssign.
EXPECT_TRUE(visitorCallbackLogEqual(
RecordingVisitor(ShouldTraversePostOrder::Yes), Code,
R"txt(
Expand All @@ -1481,6 +1481,9 @@ TraverseBinAddAssign CompoundAssignOperator(+=)
WalkUpFromStmt DeclRefExpr(a)
WalkUpFromExpr IntegerLiteral(2)
WalkUpFromStmt IntegerLiteral(2)
WalkUpFromBinAddAssign CompoundAssignOperator(+=)
WalkUpFromExpr CompoundAssignOperator(+=)
WalkUpFromStmt CompoundAssignOperator(+=)
WalkUpFromExpr IntegerLiteral(3)
WalkUpFromStmt IntegerLiteral(3)
WalkUpFromStmt CompoundStmt
Expand Down

0 comments on commit 8bf4c40

Please sign in to comment.