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 bool ShowDepth,
unsigned CurrentIncludeDepth,
59 Msg +=
"Note: including file:";
63 for (
unsigned i = 1; i != CurrentIncludeDepth; ++i)
64 Msg += MSStyle ?
' ' :
'.';
72 OutputFile->write(Msg.data(), Msg.size());
77 const std::vector<std::string> &ExtraHeaders,
79 StringRef OutputPath,
bool ShowDepth,
81 raw_ostream *OutputFile = MSStyle ? &llvm::outs() : &llvm::errs();
82 bool OwnsOutputFile =
false;
85 if (!OutputPath.empty()) {
87 llvm::raw_fd_ostream *OS =
new llvm::raw_fd_ostream(
88 OutputPath.str(), EC, llvm::sys::fs::F_Append | llvm::sys::fs::F_Text);
96 OwnsOutputFile =
true;
105 for (
auto Header : ExtraHeaders) {
117 FileChangeReason Reason,
128 ++CurrentIncludeDepth;
130 if (CurrentIncludeDepth)
131 --CurrentIncludeDepth;
135 if (CurrentIncludeDepth == 1 && !HasProcessedPredefines)
136 HasProcessedPredefines =
true;
145 bool ShowHeader = (HasProcessedPredefines ||
146 (ShowAllHeaders && CurrentIncludeDepth > 2));
152 ShowDepth, CurrentIncludeDepth, MSStyle);
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...
void AttachHeaderIncludeGen(Preprocessor &PP, const std::vector< std::string > &ExtraHeaders, bool ShowAllHeaders=false, StringRef OutputPath="", bool ShowDepth=true, bool MSStyle=false)
AttachHeaderIncludeGen - Create a header include list generator, and attach it to the given preproces...
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.
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)
Stringify - Convert the specified string into a C string by escaping '\' and " characters. This does not add surrounding ""'s to the string.
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.