]> granicus.if.org Git - clang/commitdiff
push line markers through -E mode.
authorChris Lattner <sabre@nondot.org>
Fri, 27 Mar 2009 17:13:49 +0000 (17:13 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 27 Mar 2009 17:13:49 +0000 (17:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67854 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPDirectives.cpp
tools/clang-cc/PrintPreprocessedOutput.cpp

index 5797b12ebc81216f95ab4a01edc9f0ca85af2fc5..c5dc7abd08b8c5899411b9c998a0f2209c8852b2 100644 (file)
@@ -692,6 +692,10 @@ void Preprocessor::HandleLineDirective(Token &Tok) {
   }
   
   SourceMgr.AddLineNote(DigitTok.getLocation(), LineNo, FilenameID);
+  
+  if (Callbacks)
+    Callbacks->FileChanged(DigitTok.getLocation(), PPCallbacks::RenameFile,
+                           SrcMgr::C_User);
 }
 
 /// ReadLineMarkerFlags - Parse and validate any flags at the end of a GNU line
@@ -823,6 +827,24 @@ void Preprocessor::HandleDigitDirective(Token &DigitTok) {
   SourceMgr.AddLineNote(DigitTok.getLocation(), LineNo, FilenameID,
                         IsFileEntry, IsFileExit, 
                         IsSystemHeader, IsExternCHeader);
+  
+  // If the preprocessor has callbacks installed, notify them of the #line
+  // change.  This is used so that the line marker comes out in -E mode for
+  // example.
+  if (Callbacks) {
+    PPCallbacks::FileChangeReason Reason = PPCallbacks::RenameFile;
+    if (IsFileEntry)
+      Reason = PPCallbacks::EnterFile;
+    else if (IsFileExit)
+      Reason = PPCallbacks::ExitFile;
+    SrcMgr::CharacteristicKind FileKind = SrcMgr::C_User;
+    if (IsExternCHeader)
+      FileKind = SrcMgr::C_ExternCSystem;
+    else if (IsSystemHeader)
+      FileKind = SrcMgr::C_System;
+    
+    Callbacks->FileChanged(DigitTok.getLocation(), Reason, FileKind);
+  }
 }
 
 
index 0e95c914c4a9b473b8901412b83b20b6d08ede15..34974bfd7d04961d16c5a54d8d8b05331ead1662 100644 (file)
@@ -172,6 +172,7 @@ void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc,
   }
   
   Loc = SourceMgr.getInstantiationLoc(Loc);
+  // FIXME: Should use presumed line #!
   CurLine = SourceMgr.getInstantiationLineNumber(Loc);
 
   if (DisableLineMarkers) return;