Tooling: Call back for both begin and end of sources
newFrontendActionFactory() took a pointer to a callback to call when a source
file was done being processed by an action. This revision updates the callback
to include an ante-processing callback as well.
Callback-providing class renamed and callback functions themselves renamed.
Functions are no longer pure-virtual so users aren't forced to implement both
callbacks if one isn't needed.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182864 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/unittests/Tooling/ToolingTest.cpp b/unittests/Tooling/ToolingTest.cpp
index a9319f2..a7b9431 100644
--- a/unittests/Tooling/ToolingTest.cpp
+++ b/unittests/Tooling/ToolingTest.cpp
@@ -131,20 +131,26 @@
EXPECT_TRUE(Invocation.run());
}
-struct VerifyEndCallback : public EndOfSourceFileCallback {
- VerifyEndCallback() : Called(0), Matched(false) {}
- virtual void run() {
- ++Called;
+struct VerifyEndCallback : public SourceFileCallbacks {
+ VerifyEndCallback() : BeginCalled(0), EndCalled(0), Matched(false) {}
+ virtual bool BeginSource(CompilerInstance &CI,
+ StringRef Filename) LLVM_OVERRIDE {
+ ++BeginCalled;
+ return true;
+ }
+ virtual void EndSource() {
+ ++EndCalled;
}
ASTConsumer *newASTConsumer() {
return new FindTopLevelDeclConsumer(&Matched);
}
- unsigned Called;
+ unsigned BeginCalled;
+ unsigned EndCalled;
bool Matched;
};
#if !defined(_WIN32)
-TEST(newFrontendActionFactory, InjectsEndOfSourceFileCallback) {
+TEST(newFrontendActionFactory, InjectsSourceFileCallbacks) {
VerifyEndCallback EndCallback;
FixedCompilationDatabase Compilations("/", std::vector<std::string>());
@@ -159,7 +165,8 @@
Tool.run(newFrontendActionFactory(&EndCallback, &EndCallback));
EXPECT_TRUE(EndCallback.Matched);
- EXPECT_EQ(2u, EndCallback.Called);
+ EXPECT_EQ(2u, EndCallback.BeginCalled);
+ EXPECT_EQ(2u, EndCallback.EndCalled);
}
#endif