]> granicus.if.org Git - clang/commitdiff
PPCallbacks: Add hook for reaching the end of the main file, and fix DependencyFile...
authorDaniel Dunbar <daniel@zuster.org>
Tue, 23 Mar 2010 05:09:10 +0000 (05:09 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 23 Mar 2010 05:09:10 +0000 (05:09 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99257 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/PPCallbacks.h
include/clang/Lex/Preprocessor.h
lib/Frontend/DependencyFile.cpp
lib/Frontend/FrontendAction.cpp
lib/Lex/PPLexerChange.cpp
lib/Lex/Preprocessor.cpp

index dd24fb7d7ba25fb0d806d731114097d5adc4a690..e891e94d4cbc52733cc9a4bf3b0f19d2d6fc69c1 100644 (file)
@@ -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);
index 23c118d1fc630338a72176ebf03070b967366c58..312a760e01d380b9b3840f4a60fc6c3564b7c130 100644 (file)
@@ -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.
index de2b056dc7ce0c482c4c7676d42894233429abbb..14aee3559c9e4e025258056b202c86af1aa3a5bd 100644 (file)
@@ -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);
 };
 }
 
index 66df7a61917b42afab81dc506edc8bbf95239f84..110612d03b5860562e38cae8bdf713c95169f347 100644 (file)
@@ -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();
index 6d1c132fc0a95739e5bff94847fa2718988210f2..335d3db627dd398fbcb97aef39120b7b807c1efe 100644 (file)
@@ -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;
 }
 
index 9d59300d213e823c1c1c74c93b4411226ca91112..8b4b1ddf414938a78cd8d1d95df50eec5da29146 100644 (file)
@@ -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.