[PATCH] D80623: WIP: Add an API to simplify setting TraversalKind in clang-tidy matchers
Stephen Kelly via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 5 06:04:21 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG538677abbde4: Add an API to simplify setting TraversalKind in clang-tidy matchers (authored by stephenkelly).
Changed prior to commit:
https://reviews.llvm.org/D80623?vs=313386&id=321729#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D80623/new/
https://reviews.llvm.org/D80623
Files:
clang/include/clang/ASTMatchers/ASTMatchFinder.h
clang/lib/ASTMatchers/ASTMatchFinder.cpp
Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===================================================================
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1036,6 +1036,7 @@
Callback(Callback) {}
void visitMatch(const BoundNodes& BoundNodesView) override {
+ TraversalKindScope RAII(*Context, Callback->getCheckTraversalKind());
Callback->run(MatchFinder::MatchResult(BoundNodesView, Context));
}
@@ -1335,7 +1336,10 @@
void MatchFinder::addMatcher(const DeclarationMatcher &NodeMatch,
MatchCallback *Action) {
- Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
+ if (auto TK = Action->getCheckTraversalKind())
+ Matchers.DeclOrStmt.emplace_back(traverse(*TK, NodeMatch), Action);
+ else
+ Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
Matchers.AllCallbacks.insert(Action);
}
@@ -1347,7 +1351,10 @@
void MatchFinder::addMatcher(const StatementMatcher &NodeMatch,
MatchCallback *Action) {
- Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
+ if (auto TK = Action->getCheckTraversalKind())
+ Matchers.DeclOrStmt.emplace_back(traverse(*TK, NodeMatch), Action);
+ else
+ Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
Matchers.AllCallbacks.insert(Action);
}
@@ -1436,5 +1443,10 @@
StringRef MatchFinder::MatchCallback::getID() const { return "<unknown>"; }
+llvm::Optional<TraversalKind>
+MatchFinder::MatchCallback::getCheckTraversalKind() const {
+ return llvm::None;
+}
+
} // end namespace ast_matchers
} // end namespace clang
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===================================================================
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -110,6 +110,12 @@
/// This id is used, for example, for the profiling output.
/// It defaults to "<unknown>".
virtual StringRef getID() const;
+
+ /// TraversalKind to use while matching and processing
+ /// the result nodes. This API is temporary to facilitate
+ /// third parties porting existing code to the default
+ /// behavior of clang-tidy.
+ virtual llvm::Optional<TraversalKind> getCheckTraversalKind() const;
};
/// Called when parsing is finished. Intended for testing only.
@@ -280,6 +286,11 @@
void run(const MatchFinder::MatchResult &Result) override {
Nodes.push_back(Result.Nodes);
}
+
+ llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
+ return llvm::None;
+ }
+
SmallVector<BoundNodes, 1> Nodes;
};
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80623.321729.patch
Type: text/x-patch
Size: 2676 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210205/f0671a77/attachment-0001.bin>
More information about the cfe-commits
mailing list