diff options
author | Manuel Klimek <klimek@google.com> | 2012-11-02 01:31:03 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2012-11-02 01:31:03 +0000 |
commit | bd0e2b71110a8c3ef6c398e29d2254ec1d787a21 (patch) | |
tree | 93cc4ca7af3c36fb867bf493f58da4a4594bac46 /clang/unittests/ASTMatchers/ASTMatchersTest.cpp | |
parent | 7dcadc6dbe42a91cd88804a5994eab987b42c753 (diff) | |
download | bcm5719-llvm-bd0e2b71110a8c3ef6c398e29d2254ec1d787a21.tar.gz bcm5719-llvm-bd0e2b71110a8c3ef6c398e29d2254ec1d787a21.zip |
Insert interception point onStartOfTranslationUnit.
Often users of the ASTMatchers want to add tasks that are done once per
translation unit, for example, cleaning up caches. Combined with the
interception point for the end of source file one can add to the factory
creation, this covers the cases we've seen users need.
llvm-svn: 167271
Diffstat (limited to 'clang/unittests/ASTMatchers/ASTMatchersTest.cpp')
-rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index 8861881efa9..ad5469348d5 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -3366,5 +3366,26 @@ TEST(MatchFinder, CanMatchStatementsRecursively) { new VerifyRecursiveMatch<clang::Stmt>("if", declStmt()))); } +class VerifyStartOfTranslationUnit : public MatchFinder::MatchCallback { +public: + VerifyStartOfTranslationUnit() : Called(false) {} + virtual void run(const MatchFinder::MatchResult &Result) { + EXPECT_TRUE(Called); + } + virtual void onStartOfTranslationUnit() { + Called = true; + } + bool Called; +}; + +TEST(MatchFinder, InterceptsStartOfTranslationUnit) { + MatchFinder Finder; + VerifyStartOfTranslationUnit VerifyCallback; + Finder.addMatcher(decl(), &VerifyCallback); + OwningPtr<FrontendActionFactory> Factory(newFrontendActionFactory(&Finder)); + ASSERT_TRUE(tooling::runToolOnCode(Factory->create(), "int x;")); + EXPECT_TRUE(VerifyCallback.Called); +} + } // end namespace ast_matchers } // end namespace clang |