forked from OSchip/llvm-project
Add an overridable MatchCallback::onEndOfTranslationUnit() function.
Differential Revision: http://llvm-reviews.chandlerc.com/D745 llvm-svn: 182798
This commit is contained in:
parent
d72b3ceb6b
commit
6a55bb2307
|
@ -97,6 +97,11 @@ public:
|
|||
///
|
||||
/// Optionally override to do per translation unit tasks.
|
||||
virtual void onStartOfTranslationUnit() {}
|
||||
|
||||
/// \brief Called at the end of each translation unit.
|
||||
///
|
||||
/// Optionally override to do per translation unit tasks.
|
||||
virtual void onEndOfTranslationUnit() {}
|
||||
};
|
||||
|
||||
/// \brief Called when parsing is finished. Intended for testing only.
|
||||
|
|
|
@ -278,6 +278,15 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void onEndOfTranslationUnit() {
|
||||
for (std::vector<std::pair<const internal::DynTypedMatcher*,
|
||||
MatchCallback*> >::const_iterator
|
||||
I = MatcherCallbackPairs->begin(), E = MatcherCallbackPairs->end();
|
||||
I != E; ++I) {
|
||||
I->second->onEndOfTranslationUnit();
|
||||
}
|
||||
}
|
||||
|
||||
void set_active_ast_context(ASTContext *NewActiveASTContext) {
|
||||
ActiveASTContext = NewActiveASTContext;
|
||||
}
|
||||
|
@ -679,6 +688,7 @@ private:
|
|||
Visitor.set_active_ast_context(&Context);
|
||||
Visitor.onStartOfTranslationUnit();
|
||||
Visitor.TraverseDecl(Context.getTranslationUnitDecl());
|
||||
Visitor.onEndOfTranslationUnit();
|
||||
Visitor.set_active_ast_context(NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -3934,5 +3934,26 @@ TEST(MatchFinder, InterceptsStartOfTranslationUnit) {
|
|||
EXPECT_TRUE(VerifyCallback.Called);
|
||||
}
|
||||
|
||||
class VerifyEndOfTranslationUnit : public MatchFinder::MatchCallback {
|
||||
public:
|
||||
VerifyEndOfTranslationUnit() : Called(false) {}
|
||||
virtual void run(const MatchFinder::MatchResult &Result) {
|
||||
EXPECT_FALSE(Called);
|
||||
}
|
||||
virtual void onEndOfTranslationUnit() {
|
||||
Called = true;
|
||||
}
|
||||
bool Called;
|
||||
};
|
||||
|
||||
TEST(MatchFinder, InterceptsEndOfTranslationUnit) {
|
||||
MatchFinder Finder;
|
||||
VerifyEndOfTranslationUnit 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
|
||||
|
|
Loading…
Reference in New Issue