[cfe-commits] r101813 - in /cfe/trunk: include/clang/Lex/PPCallbacks.h lib/Lex/PPDirectives.cpp

Chris Lattner sabre at nondot.org
Mon Apr 19 13:44:31 PDT 2010


Author: lattner
Date: Mon Apr 19 15:44:31 2010
New Revision: 101813

URL: http://llvm.org/viewvc/llvm-project?rev=101813&view=rev
Log:
add a PPCallback handler for a skipped #include, patch by
Zhanyong Wan!

Modified:
    cfe/trunk/include/clang/Lex/PPCallbacks.h
    cfe/trunk/lib/Lex/PPDirectives.cpp

Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=101813&r1=101812&r2=101813&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PPCallbacks.h (original)
+++ cfe/trunk/include/clang/Lex/PPCallbacks.h Mon Apr 19 15:44:31 2010
@@ -44,6 +44,14 @@
                            SrcMgr::CharacteristicKind FileType) {
   }
 
+  /// FileSkipped - This callback is invoked whenever a source file is
+  /// skipped as the result of header guard optimization.  ParentFile
+  /// is the file that #includes the skipped file.  FilenameTok is the
+  /// token in ParentFile that indicates the skipped file.
+  virtual void FileSkipped(const FileEntry &ParentFile,
+                           const Token &FilenameTok,
+                           SrcMgr::CharacteristicKind FileType) {
+  }
 
   /// EndOfMainFile - This callback is invoked when the end of the main file is
   /// reach, no subsequent callbacks will be made.
@@ -96,6 +104,13 @@
     Second->FileChanged(Loc, Reason, FileType);
   }
 
+  virtual void FileSkipped(const FileEntry &ParentFile,
+                           const Token &FilenameTok,
+                           SrcMgr::CharacteristicKind FileType) {
+    First->FileSkipped(ParentFile, FilenameTok, FileType);
+    Second->FileSkipped(ParentFile, FilenameTok, FileType);
+  }
+
   virtual void EndOfMainFile() {
     First->EndOfMainFile();
     Second->EndOfMainFile();

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=101813&r1=101812&r2=101813&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Mon Apr 19 15:44:31 2010
@@ -1088,11 +1088,6 @@
     return;
   }
 
-  // Ask HeaderInfo if we should enter this #include file.  If not, #including
-  // this file will have no effect.
-  if (!HeaderInfo.ShouldEnterIncludeFile(File, isImport))
-    return;
-
   // The #included file will be considered to be a system header if either it is
   // in a system include directory, or if the #includer is a system include
   // header.
@@ -1100,6 +1095,15 @@
     std::max(HeaderInfo.getFileDirFlavor(File),
              SourceMgr.getFileCharacteristic(FilenameTok.getLocation()));
 
+  // Ask HeaderInfo if we should enter this #include file.  If not, #including
+  // this file will have no effect.
+  if (!HeaderInfo.ShouldEnterIncludeFile(File, isImport)) {
+    if (Callbacks) {
+      Callbacks->FileSkipped(*File, FilenameTok, FileCharacter);
+    }
+    return;
+  }
+
   // Look up the file, create a File ID for it.
   FileID FID = SourceMgr.createFileID(File, FilenameTok.getLocation(),
                                       FileCharacter);
@@ -1667,4 +1671,3 @@
   return SkipExcludedConditionalBlock(CI.IfLoc, /*Foundnonskip*/true,
                                       /*FoundElse*/CI.FoundElse);
 }
-





More information about the cfe-commits mailing list