[PATCH] D93596: [ASTMatchers] Traverse-ignore range-for implementation details
Stephen Kelly via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 20 05:38:32 PST 2020
steveire created this revision.
steveire added a reviewer: aaron.ballman.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D93596
Files:
clang/lib/ASTMatchers/ASTMatchFinder.cpp
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===================================================================
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -2580,6 +2580,31 @@
EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
EXPECT_TRUE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
}
+ {
+ auto M = binaryOperator(hasOperatorName("!="));
+ EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+ EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+ }
+ {
+ auto M = unaryOperator(hasOperatorName("++"));
+ EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+ EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+ }
+ {
+ auto M = declStmt(hasSingleDecl(varDecl(matchesName("__range"))));
+ EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+ EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+ }
+ {
+ auto M = declStmt(hasSingleDecl(varDecl(matchesName("__begin"))));
+ EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+ EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+ }
+ {
+ auto M = declStmt(hasSingleDecl(varDecl(matchesName("__end"))));
+ EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+ EXPECT_FALSE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+ }
Code = R"cpp(
void rangeFor()
Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===================================================================
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -413,6 +413,22 @@
// The following Visit*() and Traverse*() functions "override"
// methods in RecursiveASTVisitor.
+ bool TraverseCXXForRangeStmt(CXXForRangeStmt *S,
+ DataRecursionQueue *Queue = nullptr) {
+ if (!WalkUpFromCXXForRangeStmt(S))
+ return false;
+ for (Stmt *SubStmt : getStmtChildren(S)) {
+ if (SubStmt == S->getInit() || SubStmt == S->getLoopVarStmt() ||
+ SubStmt == S->getRangeInit() || SubStmt == S->getBody()) {
+ TraverseStmt(SubStmt, Queue);
+ } else {
+ ASTNodeNotSpelledInSourceScope RAII(this, true);
+ TraverseStmt(SubStmt, Queue);
+ }
+ }
+ return true;
+ }
+
bool VisitTypedefNameDecl(TypedefNameDecl *DeclNode) {
// When we see 'typedef A B', we add name 'B' to the set of names
// A's canonical type maps to. This is necessary for implementing
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93596.312973.patch
Type: text/x-patch
Size: 2593 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201220/119c1683/attachment.bin>
More information about the cfe-commits
mailing list