[PATCH] D26742: [RecursiveASTVisitor] Fix post-order traversal of UnaryOperator
This revision was automatically updated to reflect the committed changes. Closed by commit rL288923: [RecursiveASTVisitor] Fix post-order traversal of UnaryOperator (authored by malcolm.parsons). Changed prior to commit: https://reviews.llvm.org/D26742?vs=78165=80621#toc Repository: rL LLVM https://reviews.llvm.org/D26742 Files: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp Index: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h === --- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h +++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h @@ -357,7 +357,8 @@ #define OPERATOR(NAME) \ bool TraverseUnary##NAME(UnaryOperator *S, \ DataRecursionQueue *Queue = nullptr) { \ -TRY_TO(WalkUpFromUnary##NAME(S)); \ +if (!getDerived().shouldTraversePostOrder()) \ + TRY_TO(WalkUpFromUnary##NAME(S)); \ TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr()); \ return true; \ } \ Index: cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp === --- cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp +++ cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp @@ -34,6 +34,11 @@ bool shouldTraversePostOrder() const { return VisitPostOrder; } +bool VisitUnaryOperator(UnaryOperator *Op) { + VisitedNodes.push_back(Op->getOpcodeStr(Op->getOpcode())); + return true; +} + bool VisitBinaryOperator(BinaryOperator *Op) { VisitedNodes.push_back(Op->getOpcodeStr()); return true; @@ -76,7 +81,7 @@ auto ASTUnit = tooling::buildASTFromCode( "class A {" " class B {" -"int foo() { while(4) { int i = 9; } return (1 + 3) + 2; }" +"int foo() { while(4) { int i = 9; int j = -i; } return (1 + 3) + 2; }" " };" "};" ); @@ -87,7 +92,7 @@ Visitor.TraverseTranslationUnitDecl(TU); std::vector expected = { -"4", "9", "i", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B", "A" +"4", "9", "i", "-", "j", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B", "A" }; // Compare the list of actually visited nodes // with the expected list of visited nodes. Index: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h === --- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h +++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h @@ -357,7 +357,8 @@ #define OPERATOR(NAME) \ bool TraverseUnary##NAME(UnaryOperator *S, \ DataRecursionQueue *Queue = nullptr) { \ -TRY_TO(WalkUpFromUnary##NAME(S)); \ +if (!getDerived().shouldTraversePostOrder()) \ + TRY_TO(WalkUpFromUnary##NAME(S));\ TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr()); \ return true; \ }\ Index: cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp === --- cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp +++ cfe/trunk/unittests/AST/PostOrderASTVisitor.cpp @@ -34,6 +34,11 @@ bool shouldTraversePostOrder() const { return VisitPostOrder; } +bool VisitUnaryOperator(UnaryOperator *Op) { + VisitedNodes.push_back(Op->getOpcodeStr(Op->getOpcode())); + return true; +} + bool VisitBinaryOperator(BinaryOperator *Op) { VisitedNodes.push_back(Op->getOpcodeStr()); return true; @@ -76,7 +81,7 @@ auto ASTUnit = tooling::buildASTFromCode( "class A {" " class B {" -"int foo() { while(4) { int i = 9; } return (1 + 3) + 2; }" +"int foo() { while(4) { int i = 9; int j = -i; } return (1 + 3) + 2; }" " };" "};" ); @@ -87,7 +92,7 @@ Visitor.TraverseTranslationUnitDecl(TU); std::vector expected = { -"4", "9", "i", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B", "A" +"4", "9", "i", "-", "j", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B", "A" }; // Compare the list of actually visited nodes // with the expected list of visited nodes. ___ cfe-commits mailing list cfe-commits@lists.llvm.org
[PATCH] D26742: [RecursiveASTVisitor] Fix post-order traversal of UnaryOperator
teemperor added a reviewer: rsmith. teemperor added a comment. Looks good to me. I'll add Richard because he also merged/approved the original post-order patch. https://reviews.llvm.org/D26742 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26742: [RecursiveASTVisitor] Fix post-order traversal of UnaryOperator
malcolm.parsons created this revision. malcolm.parsons added reviewers: aaron.ballman, klimek, teemperor, doug.gregor. malcolm.parsons added a subscriber: cfe-commits. https://reviews.llvm.org/D26742 Files: include/clang/AST/RecursiveASTVisitor.h unittests/AST/PostOrderASTVisitor.cpp Index: unittests/AST/PostOrderASTVisitor.cpp === --- unittests/AST/PostOrderASTVisitor.cpp +++ unittests/AST/PostOrderASTVisitor.cpp @@ -34,6 +34,11 @@ bool shouldTraversePostOrder() const { return VisitPostOrder; } +bool VisitUnaryOperator(UnaryOperator *Op) { + VisitedNodes.push_back(Op->getOpcodeStr(Op->getOpcode())); + return true; +} + bool VisitBinaryOperator(BinaryOperator *Op) { VisitedNodes.push_back(Op->getOpcodeStr()); return true; @@ -76,7 +81,7 @@ auto ASTUnit = tooling::buildASTFromCode( "class A {" " class B {" -"int foo() { while(4) { int i = 9; } return (1 + 3) + 2; }" +"int foo() { while(4) { int i = 9; int j = -i; } return (1 + 3) + 2; }" " };" "};" ); @@ -87,7 +92,7 @@ Visitor.TraverseTranslationUnitDecl(TU); std::vector expected = { -"4", "9", "i", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B", "A" +"4", "9", "i", "-", "j", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B", "A" }; // Compare the list of actually visited nodes // with the expected list of visited nodes. Index: include/clang/AST/RecursiveASTVisitor.h === --- include/clang/AST/RecursiveASTVisitor.h +++ include/clang/AST/RecursiveASTVisitor.h @@ -357,7 +357,8 @@ #define OPERATOR(NAME) \ bool TraverseUnary##NAME(UnaryOperator *S, \ DataRecursionQueue *Queue = nullptr) { \ -TRY_TO(WalkUpFromUnary##NAME(S)); \ +if (!getDerived().shouldTraversePostOrder()) \ + TRY_TO(WalkUpFromUnary##NAME(S)); \ TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr()); \ return true; \ } \ Index: unittests/AST/PostOrderASTVisitor.cpp === --- unittests/AST/PostOrderASTVisitor.cpp +++ unittests/AST/PostOrderASTVisitor.cpp @@ -34,6 +34,11 @@ bool shouldTraversePostOrder() const { return VisitPostOrder; } +bool VisitUnaryOperator(UnaryOperator *Op) { + VisitedNodes.push_back(Op->getOpcodeStr(Op->getOpcode())); + return true; +} + bool VisitBinaryOperator(BinaryOperator *Op) { VisitedNodes.push_back(Op->getOpcodeStr()); return true; @@ -76,7 +81,7 @@ auto ASTUnit = tooling::buildASTFromCode( "class A {" " class B {" -"int foo() { while(4) { int i = 9; } return (1 + 3) + 2; }" +"int foo() { while(4) { int i = 9; int j = -i; } return (1 + 3) + 2; }" " };" "};" ); @@ -87,7 +92,7 @@ Visitor.TraverseTranslationUnitDecl(TU); std::vector expected = { -"4", "9", "i", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B", "A" +"4", "9", "i", "-", "j", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B", "A" }; // Compare the list of actually visited nodes // with the expected list of visited nodes. Index: include/clang/AST/RecursiveASTVisitor.h === --- include/clang/AST/RecursiveASTVisitor.h +++ include/clang/AST/RecursiveASTVisitor.h @@ -357,7 +357,8 @@ #define OPERATOR(NAME) \ bool TraverseUnary##NAME(UnaryOperator *S, \ DataRecursionQueue *Queue = nullptr) { \ -TRY_TO(WalkUpFromUnary##NAME(S)); \ +if (!getDerived().shouldTraversePostOrder()) \ + TRY_TO(WalkUpFromUnary##NAME(S));\ TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr()); \ return true; \ }\ ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits