summaryrefslogtreecommitdiffstats
path: root/clang/lib/ASTMatchers/ASTMatchFinder.cpp
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2013-11-07 22:30:36 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2013-11-07 22:30:36 +0000
commita2334162cffc91f31898f79b0a286474e8365ce9 (patch)
treeb6663a0327d0ff955c358b05942453eae9a14559 /clang/lib/ASTMatchers/ASTMatchFinder.cpp
parent2b94713053aef3ca42e4e555ed6e04e41215762d (diff)
downloadbcm5719-llvm-a2334162cffc91f31898f79b0a286474e8365ce9.tar.gz
bcm5719-llvm-a2334162cffc91f31898f79b0a286474e8365ce9.zip
Introduce MatchFinder::matchAST.
Differential Revision: http://llvm-reviews.chandlerc.com/D2115 llvm-svn: 194223
Diffstat (limited to 'clang/lib/ASTMatchers/ASTMatchFinder.cpp')
-rw-r--r--clang/lib/ASTMatchers/ASTMatchFinder.cpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
index 6ca5afc2496..f6dcb9779ab 100644
--- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -744,25 +744,19 @@ bool MatchASTVisitor::TraverseNestedNameSpecifierLoc(
class MatchASTConsumer : public ASTConsumer {
public:
- MatchASTConsumer(
- std::vector<std::pair<internal::DynTypedMatcher, MatchCallback *> > *
- MatcherCallbackPairs,
- MatchFinder::ParsingDoneTestCallback *ParsingDone)
- : Visitor(MatcherCallbackPairs), ParsingDone(ParsingDone) {}
+ MatchASTConsumer(MatchFinder *Finder,
+ MatchFinder::ParsingDoneTestCallback *ParsingDone)
+ : Finder(Finder), ParsingDone(ParsingDone) {}
private:
virtual void HandleTranslationUnit(ASTContext &Context) {
if (ParsingDone != NULL) {
ParsingDone->run();
}
- Visitor.set_active_ast_context(&Context);
- Visitor.onStartOfTranslationUnit();
- Visitor.TraverseDecl(Context.getTranslationUnitDecl());
- Visitor.onEndOfTranslationUnit();
- Visitor.set_active_ast_context(NULL);
+ Finder->matchAST(Context);
}
- MatchASTVisitor Visitor;
+ MatchFinder *Finder;
MatchFinder::ParsingDoneTestCallback *ParsingDone;
};
@@ -836,7 +830,7 @@ bool MatchFinder::addDynamicMatcher(const internal::DynTypedMatcher &NodeMatch,
}
ASTConsumer *MatchFinder::newASTConsumer() {
- return new internal::MatchASTConsumer(&MatcherCallbackPairs, ParsingDone);
+ return new internal::MatchASTConsumer(this, ParsingDone);
}
void MatchFinder::match(const clang::ast_type_traits::DynTypedNode &Node,
@@ -846,6 +840,14 @@ void MatchFinder::match(const clang::ast_type_traits::DynTypedNode &Node,
Visitor.match(Node);
}
+void MatchFinder::matchAST(ASTContext &Context) {
+ internal::MatchASTVisitor Visitor(&MatcherCallbackPairs);
+ Visitor.set_active_ast_context(&Context);
+ Visitor.onStartOfTranslationUnit();
+ Visitor.TraverseDecl(Context.getTranslationUnitDecl());
+ Visitor.onEndOfTranslationUnit();
+}
+
void MatchFinder::registerTestCallbackAfterParsing(
MatchFinder::ParsingDoneTestCallback *NewParsingDone) {
ParsingDone = NewParsingDone;
OpenPOWER on IntegriCloud