summaryrefslogtreecommitdiffstats
path: root/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
diff options
context:
space:
mode:
authorSamuel Benzaquen <sbenza@google.com>2014-11-24 21:21:09 +0000
committerSamuel Benzaquen <sbenza@google.com>2014-11-24 21:21:09 +0000
commit074bbb698db6f2b4559a65a247e9d7aa0686de94 (patch)
tree6b1d510de2cccf6c1f0fe268be203bd99cb3d56d /clang/lib/ASTMatchers/ASTMatchersInternal.cpp
parent6953a3a6e006ee1f023e999a4304fddfbf70f1fc (diff)
downloadbcm5719-llvm-074bbb698db6f2b4559a65a247e9d7aa0686de94.tar.gz
bcm5719-llvm-074bbb698db6f2b4559a65a247e9d7aa0686de94.zip
Filter the toplevel matchers by kind.
Summary: Filter the toplevel matchers by kind. Decl and Stmt matchers are tied to a specific node kind and trying to match incompatible nodes is a waste. Precalculate a filtered list of matchers that have a chance of matching the node and ignore the rest. Speeds up our clang-tidy benchmark by ~10% Reviewers: klimek Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D6361 llvm-svn: 222688
Diffstat (limited to 'clang/lib/ASTMatchers/ASTMatchersInternal.cpp')
-rw-r--r--clang/lib/ASTMatchers/ASTMatchersInternal.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index c7d98b8a3a9..ca58d330d80 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -149,6 +149,11 @@ DynTypedMatcher DynTypedMatcher::trueMatcher(
return DynTypedMatcher(NodeKind, NodeKind, &*TrueMatcherInstance);
}
+bool DynTypedMatcher::canMatchNodesOfKind(
+ ast_type_traits::ASTNodeKind Kind) const {
+ return RestrictKind.isBaseOf(Kind);
+}
+
DynTypedMatcher DynTypedMatcher::dynCastTo(
const ast_type_traits::ASTNodeKind Kind) const {
auto Copy = *this;
@@ -172,6 +177,20 @@ bool DynTypedMatcher::matches(const ast_type_traits::DynTypedNode &DynNode,
return false;
}
+bool DynTypedMatcher::matchesNoKindCheck(
+ const ast_type_traits::DynTypedNode &DynNode, ASTMatchFinder *Finder,
+ BoundNodesTreeBuilder *Builder) const {
+ assert(RestrictKind.isBaseOf(DynNode.getNodeKind()));
+ if (Implementation->dynMatches(DynNode, Finder, Builder)) {
+ return true;
+ }
+ // Delete all bindings when a matcher does not match.
+ // This prevents unexpected exposure of bound nodes in unmatches
+ // branches of the match tree.
+ Builder->removeBindings([](const BoundNodesMap &) { return true; });
+ return false;
+}
+
llvm::Optional<DynTypedMatcher> DynTypedMatcher::tryBind(StringRef ID) const {
if (!AllowBind) return llvm::None;
auto Result = *this;
OpenPOWER on IntegriCloud