Skip to content
Snippets Groups Projects
Commit dbd8209b authored by Daniel Dunbar's avatar Daniel Dunbar
Browse files

PPCallbacks: Add hook for reaching the end of the main file, and fix...

PPCallbacks: Add hook for reaching the end of the main file, and fix DependencyFile to not do work in its destructor.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99257 91177308-0d34-0410-b5e6-96231b3b80d8
parent d9e0c0fc
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,12 @@ public:
SrcMgr::CharacteristicKind FileType) {
}
/// EndOfMainFile - This callback is invoked when the end of the main file is
/// reach, no subsequent callbacks will be made.
virtual void EndOfMainFile() {
}
/// Ident - This callback is invoked when a #ident or #sccs directive is read.
///
virtual void Ident(SourceLocation Loc, const std::string &str) {
......@@ -90,6 +96,11 @@ public:
Second->FileChanged(Loc, Reason, FileType);
}
virtual void EndOfMainFile() {
First->EndOfMainFile();
Second->EndOfMainFile();
}
virtual void Ident(SourceLocation Loc, const std::string &str) {
First->Ident(Loc, str);
Second->Ident(Loc, str);
......
......@@ -368,6 +368,10 @@ public:
/// which implicitly adds the builtin defines etc.
bool EnterMainSourceFile();
/// EndSourceFile - Inform the preprocessor callbacks that processing is
/// complete.
void EndSourceFile();
/// EnterSourceFile - Add a source file to the top of the include stack and
/// start lexing tokens from it instead of the current buffer. Return true
/// and fill in ErrorStr with the error information on failure.
......
......@@ -48,14 +48,15 @@ public:
IncludeSystemHeaders(Opts.IncludeSystemHeaders),
PhonyTarget(Opts.UsePhonyTargets) {}
~DependencyFileCallback() {
virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType);
virtual void EndOfMainFile() {
OutputDependencyFile();
OS->flush();
delete OS;
OS = 0;
}
virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType);
};
}
......
......@@ -169,6 +169,10 @@ void FrontendAction::EndSourceFile() {
CI.setASTContext(0);
}
// Inform the preprocessor we are done.
if (CI.hasPreprocessor())
CI.getPreprocessor().EndSourceFile();
if (CI.getFrontendOpts().ShowStats) {
llvm::errs() << "\nSTATISTICS FOR '" << getCurrentFile() << "':\n";
CI.getPreprocessor().PrintStats();
......
......@@ -255,6 +255,7 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) {
if (!I->second->isUsed())
Diag(I->second->getDefinitionLoc(), diag::pp_macro_not_used);
}
return true;
}
......
......@@ -519,6 +519,11 @@ bool Preprocessor::EnterMainSourceFile() {
return EnterSourceFile(FID, 0, ErrorStr);
}
void Preprocessor::EndSourceFile() {
// Notify the client that we reached the end of the source file.
if (Callbacks)
Callbacks->EndOfMainFile();
}
//===----------------------------------------------------------------------===//
// Lexer Event Handling.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment