diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2014-08-07 20:51:16 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2014-08-07 20:51:16 +0000 |
commit | 88d99e4f427350dc788a6a0a71c2f93be59a7cde (patch) | |
tree | 3720a7645fbbd613f842c0f14aadc4385415939b /clang/unittests/Frontend/FrontendActionTest.cpp | |
parent | ec2fac8a133bb6f28b8c38e47767b7e9e429e16d (diff) | |
download | bcm5719-llvm-88d99e4f427350dc788a6a0a71c2f93be59a7cde.tar.gz bcm5719-llvm-88d99e4f427350dc788a6a0a71c2f93be59a7cde.zip |
Flip the order the preprocessor and frontendaction are informed of the end of a file.
This allows using EndOfMainFile from a PPCallback to access data from the
action. The pattern of PPCallback referencing an action is common in clang-tidy.
Differential Revision: http://reviews.llvm.org/D4773
llvm-svn: 215145
Diffstat (limited to 'clang/unittests/Frontend/FrontendActionTest.cpp')
-rw-r--r-- | clang/unittests/Frontend/FrontendActionTest.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/clang/unittests/Frontend/FrontendActionTest.cpp b/clang/unittests/Frontend/FrontendActionTest.cpp index e39d00f6af3..44843eed137 100644 --- a/clang/unittests/Frontend/FrontendActionTest.cpp +++ b/clang/unittests/Frontend/FrontendActionTest.cpp @@ -100,4 +100,50 @@ TEST(ASTFrontendAction, IncrementalParsing) { EXPECT_EQ("x", test_action.decl_names[1]); } +struct TestPPCallbacks : public PPCallbacks { + TestPPCallbacks() : SeenEnd(false) {} + + void EndOfMainFile() override { SeenEnd = true; } + + bool SeenEnd; +}; + +class TestPPCallbacksFrontendAction : public PreprocessorFrontendAction { + TestPPCallbacks *Callbacks; + +public: + TestPPCallbacksFrontendAction(TestPPCallbacks *C) + : Callbacks(C), SeenEnd(false) {} + + void ExecuteAction() override { + Preprocessor &PP = getCompilerInstance().getPreprocessor(); + PP.addPPCallbacks(Callbacks); + PP.EnterMainSourceFile(); + } + void EndSourceFileAction() override { SeenEnd = Callbacks->SeenEnd; } + + bool SeenEnd; +}; + +TEST(PreprocessorFrontendAction, EndSourceFile) { + CompilerInvocation *Invocation = new CompilerInvocation; + Invocation->getPreprocessorOpts().addRemappedFile( + "test.cc", MemoryBuffer::getMemBuffer("int main() { float x; }")); + Invocation->getFrontendOpts().Inputs.push_back( + FrontendInputFile("test.cc", IK_CXX)); + Invocation->getFrontendOpts().ProgramAction = frontend::ParseSyntaxOnly; + Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; + CompilerInstance Compiler; + Compiler.setInvocation(Invocation); + Compiler.createDiagnostics(); + + TestPPCallbacks *Callbacks = new TestPPCallbacks; + TestPPCallbacksFrontendAction TestAction(Callbacks); + ASSERT_FALSE(Callbacks->SeenEnd); + ASSERT_FALSE(TestAction.SeenEnd); + ASSERT_TRUE(Compiler.ExecuteAction(TestAction)); + // Check that EndOfMainFile was called before EndSourceFileAction. + ASSERT_TRUE(TestAction.SeenEnd); +} + } // anonymous namespace |