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 | e579328ec9a95acc7f181e04c58a747ba001d80f (patch) | |
tree | a205599a5bd2141448d12978b30870e5ef600996 /unittests/ASTMatchers/ASTMatchersTest.cpp | |
parent | 919b9557b4f0155dfaaea309493ff2a702fca676 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167271 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ASTMatchers/ASTMatchersTest.cpp')
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTest.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 8861881efa..ad5469348d 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/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 |