14 #include "llvm/ADT/SmallString.h"
15 #include "llvm/Support/raw_ostream.h"
16 using namespace clang;
21 raw_ostream *OutputFile;
22 unsigned CurrentIncludeDepth;
23 bool HasProcessedPredefines;
30 HeaderIncludesCallback(
const Preprocessor *PP,
bool ShowAllHeaders_,
31 raw_ostream *OutputFile_,
bool OwnsOutputFile_,
32 bool ShowDepth_,
bool MSStyle_)
33 :
SM(PP->getSourceManager()), OutputFile(OutputFile_),
34 CurrentIncludeDepth(0), HasProcessedPredefines(
false),
35 OwnsOutputFile(OwnsOutputFile_), ShowAllHeaders(ShowAllHeaders_),
36 ShowDepth(ShowDepth_), MSStyle(MSStyle_) {}
38 ~HeaderIncludesCallback()
override {
50 StringRef OutputPath,
bool ShowDepth,
52 raw_ostream *OutputFile = MSStyle ? &llvm::outs() : &llvm::errs();
53 bool OwnsOutputFile =
false;
56 if (!OutputPath.empty()) {
58 llvm::raw_fd_ostream *OS =
new llvm::raw_fd_ostream(
59 OutputPath.str(), EC, llvm::sys::fs::F_Append | llvm::sys::fs::F_Text);
66 OS->SetUseAtomicWrites(
true);
68 OwnsOutputFile =
true;
81 FileChangeReason Reason,
92 ++CurrentIncludeDepth;
94 if (CurrentIncludeDepth)
95 --CurrentIncludeDepth;
99 if (CurrentIncludeDepth == 1 && !HasProcessedPredefines)
100 HasProcessedPredefines =
true;
109 bool ShowHeader = (HasProcessedPredefines ||
110 (ShowAllHeaders && CurrentIncludeDepth > 2));
122 Msg +=
"Note: including file:";
126 for (
unsigned i = 1; i != CurrentIncludeDepth; ++i)
127 Msg += MSStyle ?
' ' :
'.';
135 OutputFile->write(Msg.data(), Msg.size());
void AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders=false, StringRef OutputPath="", bool ShowDepth=true, bool MSStyle=false)
bool isInvalid() const
Return true if this object is invalid or uninitialized.
Defines the SourceManager interface.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
This interface provides a way to observe the actions of the preprocessor as it does its thing...
Defines the clang::Preprocessor interface.
Represents an unpacked "presumed" location which can be presented to the user.
const char * getFilename() const
Return the presumed filename of this location.
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
DiagnosticsEngine & getDiagnostics() const
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)
This class handles loading and caching of source files into memory.
static std::string Stringify(StringRef Str, bool Charify=false)
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.