15 #include "llvm/ADT/SmallString.h"
16 #include "llvm/Support/raw_ostream.h"
17 using namespace clang;
22 raw_ostream *OutputFile;
24 unsigned CurrentIncludeDepth;
25 bool HasProcessedPredefines;
32 HeaderIncludesCallback(
const Preprocessor *PP,
bool ShowAllHeaders_,
33 raw_ostream *OutputFile_,
35 bool OwnsOutputFile_,
bool ShowDepth_,
bool MSStyle_)
36 :
SM(PP->getSourceManager()), OutputFile(OutputFile_), DepOpts(DepOpts),
37 CurrentIncludeDepth(0), HasProcessedPredefines(
false),
38 OwnsOutputFile(OwnsOutputFile_), ShowAllHeaders(ShowAllHeaders_),
39 ShowDepth(ShowDepth_), MSStyle(MSStyle_) {}
41 ~HeaderIncludesCallback()
override {
53 bool ShowDepth,
unsigned CurrentIncludeDepth,
62 Msg +=
"Note: including file:";
66 for (
unsigned i = 1; i != CurrentIncludeDepth; ++i)
67 Msg += MSStyle ?
' ' :
'.';
81 bool ShowAllHeaders, StringRef OutputPath,
82 bool ShowDepth,
bool MSStyle) {
83 raw_ostream *OutputFile = MSStyle ? &llvm::outs() : &llvm::errs();
84 bool OwnsOutputFile =
false;
87 if (!OutputPath.empty()) {
89 llvm::raw_fd_ostream *OS =
new llvm::raw_fd_ostream(
90 OutputPath.str(), EC, llvm::sys::fs::F_Append | llvm::sys::fs::F_Text);
98 OwnsOutputFile =
true;
107 for (
const auto &Header : DepOpts.
ExtraDeps)
110 &PP, ShowAllHeaders, OutputFile, DepOpts, OwnsOutputFile, ShowDepth,
115 FileChangeReason Reason,
126 ++CurrentIncludeDepth;
128 if (CurrentIncludeDepth)
129 --CurrentIncludeDepth;
133 if (CurrentIncludeDepth == 1 && !HasProcessedPredefines) {
134 if (!DepOpts.ShowIncludesPretendHeader.empty()) {
136 ShowDepth, 2, MSStyle);
138 HasProcessedPredefines =
true;
148 bool ShowHeader = (HasProcessedPredefines ||
149 (ShowAllHeaders && CurrentIncludeDepth > 2));
150 unsigned IncludeDepth = CurrentIncludeDepth;
151 if (!HasProcessedPredefines)
153 else if (!DepOpts.ShowIncludesPretendHeader.empty())
162 UserLoc.
getFilename() != StringRef(
"<command line>")) {
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 DependencyOutputOptions &DepOpts, 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.
DependencyOutputOptions - Options for controlling the compiler dependency file generation.
std::vector< std::string > ExtraDeps
A list of filenames to be used as extra dependencies for every target.
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.