diff options
author | Manuel Klimek <klimek@google.com> | 2013-02-01 13:41:35 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2013-02-01 13:41:35 +0000 |
commit | 191c093af13a7defa77c70e868b53102d679bb2b (patch) | |
tree | 0fb895d5f6372699db0dadad032ba21f01acf437 /clang/lib/ASTMatchers/ASTMatchFinder.cpp | |
parent | 540bacb1b96d1d9ec323127132c0d14d2b031a3e (diff) | |
download | bcm5719-llvm-191c093af13a7defa77c70e868b53102d679bb2b.tar.gz bcm5719-llvm-191c093af13a7defa77c70e868b53102d679bb2b.zip |
Re-design the convenience interfaces on MatchFinder.
First, this implements a match() method on MatchFinder; this allows us
to get rid of the findAll implementation, as findAll is really a special
case of recursive matchers on match.
Instead of findAll, provide a convenience function match() that lets
users iterate easily over the results instead of needing to implement
callbacks.
llvm-svn: 174172
Diffstat (limited to 'clang/lib/ASTMatchers/ASTMatchFinder.cpp')
-rw-r--r-- | clang/lib/ASTMatchers/ASTMatchFinder.cpp | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp b/clang/lib/ASTMatchers/ASTMatchFinder.cpp index 3c797982ade..3a3c1fb6e17 100644 --- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp +++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp @@ -467,6 +467,26 @@ public: return matchesAncestorOfRecursively(Node, Matcher, Builder, MatchMode); } + // Matches all registered matchers on the given node and calls the + // result callback for every node that matches. + void match(const ast_type_traits::DynTypedNode& Node) { + for (std::vector<std::pair<const internal::DynTypedMatcher*, + MatchCallback*> >::const_iterator + I = MatcherCallbackPairs->begin(), E = MatcherCallbackPairs->end(); + I != E; ++I) { + BoundNodesTreeBuilder Builder; + if (I->first->matches(Node, this, &Builder)) { + BoundNodesTree BoundNodes = Builder.build(); + MatchVisitor Visitor(ActiveASTContext, I->second); + BoundNodes.visitMatches(&Visitor); + } + } + } + + template <typename T> void match(const T &Node) { + match(ast_type_traits::DynTypedNode::create(Node)); + } + // Implements ASTMatchFinder::getASTContext. virtual ASTContext &getASTContext() const { return *ActiveASTContext; } @@ -544,24 +564,6 @@ private: return false; } - // Matches all registered matchers on the given node and calls the - // result callback for every node that matches. - template <typename T> - void match(const T &node) { - for (std::vector<std::pair<const internal::DynTypedMatcher*, - MatchCallback*> >::const_iterator - I = MatcherCallbackPairs->begin(), E = MatcherCallbackPairs->end(); - I != E; ++I) { - BoundNodesTreeBuilder Builder; - if (I->first->matches(ast_type_traits::DynTypedNode::create(node), - this, &Builder)) { - BoundNodesTree BoundNodes = Builder.build(); - MatchVisitor Visitor(ActiveASTContext, I->second); - BoundNodes.visitMatches(&Visitor); - } - } - } - std::vector<std::pair<const internal::DynTypedMatcher*, MatchCallback*> > *const MatcherCallbackPairs; ASTContext *ActiveASTContext; @@ -777,16 +779,11 @@ ASTConsumer *MatchFinder::newASTConsumer() { return new internal::MatchASTConsumer(&MatcherCallbackPairs, ParsingDone); } -void MatchFinder::findAll(const Decl &Node, ASTContext &Context) { - internal::MatchASTVisitor Visitor(&MatcherCallbackPairs); - Visitor.set_active_ast_context(&Context); - Visitor.TraverseDecl(const_cast<Decl*>(&Node)); -} - -void MatchFinder::findAll(const Stmt &Node, ASTContext &Context) { +void MatchFinder::match(const clang::ast_type_traits::DynTypedNode &Node, + ASTContext &Context) { internal::MatchASTVisitor Visitor(&MatcherCallbackPairs); Visitor.set_active_ast_context(&Context); - Visitor.TraverseStmt(const_cast<Stmt*>(&Node)); + Visitor.match(Node); } void MatchFinder::registerTestCallbackAfterParsing( |