[cfe-commits] r124749 - in /cfe/trunk: include/clang/Frontend/Utils.h lib/Frontend/HeaderIncludeGen.cpp

Daniel Dunbar daniel at zuster.org
Wed Feb 2 13:11:24 PST 2011


Author: ddunbar
Date: Wed Feb  2 15:11:24 2011
New Revision: 124749

URL: http://llvm.org/viewvc/llvm-project?rev=124749&view=rev
Log:
Frontend: Add support (unused) for showing all "interesting" headers, not just
ones outside the predefines buffer (which is what -H does).

Modified:
    cfe/trunk/include/clang/Frontend/Utils.h
    cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp

Modified: cfe/trunk/include/clang/Frontend/Utils.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/Utils.h?rev=124749&r1=124748&r2=124749&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/Utils.h (original)
+++ cfe/trunk/include/clang/Frontend/Utils.h Wed Feb  2 15:11:24 2011
@@ -75,7 +75,15 @@
 
 /// AttachHeaderIncludeGen - Create a header include list generator, and attach
 /// it to the given preprocessor.
-void AttachHeaderIncludeGen(Preprocessor &PP);
+///
+/// \param ShowAllHeaders - If true, show all header information instead of just
+/// headers following the predefines buffer. This is useful for making sure
+/// includes mentioned on the command line are also reported, but differs from
+/// the default behavior used by -H.
+/// \param OutputPath - If non-empty, a path to write the header include
+/// information to, instead of writing to stderr.
+void AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders = false,
+                            llvm::StringRef OutputPath = "");
 
 /// CacheTokens - Cache tokens for use with PCH. Note that this requires
 /// a seekable stream.

Modified: cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp?rev=124749&r1=124748&r2=124749&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp (original)
+++ cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp Wed Feb  2 15:11:24 2011
@@ -10,40 +10,28 @@
 #include "clang/Frontend/Utils.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Preprocessor.h"
-/*
-#include "clang/Basic/Diagnostic.h"
-#include "clang/Frontend/PreprocessorOutputOptions.h"
-#include "clang/Lex/MacroInfo.h"
-#include "clang/Lex/PPCallbacks.h"
-#include "clang/Lex/Pragma.h"
-#include "clang/Lex/TokenConcatenation.h"
-#include "llvm/ADT/SmallString.h"
-#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Config/config.h"
-#include "llvm/Support/raw_ostream.h"
-#include <cstdio>
-*/
 using namespace clang;
 
 namespace {
 class HeaderIncludesCallback : public PPCallbacks {
   SourceManager &SM;
   unsigned CurrentIncludeDepth;
+  bool ShowAllHeaders;
   bool HasProcessedPredefines;
 
 public:
-  HeaderIncludesCallback(const Preprocessor *PP)
+  HeaderIncludesCallback(const Preprocessor *PP, bool ShowAllHeaders_)
     : SM(PP->getSourceManager()), CurrentIncludeDepth(0),
-      HasProcessedPredefines(false) {}
+      ShowAllHeaders(ShowAllHeaders_), HasProcessedPredefines(false) {}
 
   virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason,
                            SrcMgr::CharacteristicKind FileType);
 };
 }
 
-void clang::AttachHeaderIncludeGen(Preprocessor &PP) {
-  PP.addPPCallbacks(new HeaderIncludesCallback(&PP));
+void clang::AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders,
+                                   llvm::StringRef OutputPath) {
+  PP.addPPCallbacks(new HeaderIncludesCallback(&PP, ShowAllHeaders));
 }
 
 void HeaderIncludesCallback::FileChanged(SourceLocation Loc,
@@ -67,9 +55,16 @@
     if (CurrentIncludeDepth == 0 && !HasProcessedPredefines)
       HasProcessedPredefines = true;
   }
-  
-  // Dump the header include information we are past the predefines buffer.
-  if (HasProcessedPredefines && Reason == PPCallbacks::EnterFile) {
+
+  // Show the header if we are (a) past the predefines, or (b) showing all
+  // headers and in the predefines at a depth past the initial file and command
+  // line buffers.
+  bool ShowHeader = (HasProcessedPredefines ||
+                     (ShowAllHeaders && CurrentIncludeDepth > 2));
+
+  // Dump the header include information we are past the predefines buffer or
+  // are showing all headers.
+  if (ShowHeader && Reason == PPCallbacks::EnterFile) {
     // Write to a temporary string to avoid unnecessary flushing on errs().
     llvm::SmallString<512> Filename(UserLoc.getFilename());
     Lexer::Stringify(Filename);





More information about the cfe-commits mailing list