14 #include "llvm/ADT/SmallString.h"
15 #include "llvm/Support/raw_ostream.h"
16 using namespace clang;
21 raw_ostream *OutputFile;
23 unsigned CurrentIncludeDepth;
24 bool HasProcessedPredefines;
31 HeaderIncludesCallback(
const Preprocessor *PP,
bool ShowAllHeaders_,
32 raw_ostream *OutputFile_,
34 bool OwnsOutputFile_,
bool ShowDepth_,
bool MSStyle_)
35 :
SM(PP->getSourceManager()), OutputFile(OutputFile_), DepOpts(DepOpts),
36 CurrentIncludeDepth(0), HasProcessedPredefines(
false),
37 OwnsOutputFile(OwnsOutputFile_), ShowAllHeaders(ShowAllHeaders_),
38 ShowDepth(ShowDepth_), MSStyle(MSStyle_) {}
40 ~HeaderIncludesCallback()
override {
55 bool ShowDepth,
unsigned CurrentIncludeDepth,
64 Msg +=
"Note: including file:";
68 for (
unsigned i = 1; i != CurrentIncludeDepth; ++i)
69 Msg += MSStyle ?
' ' :
'.';
83 bool ShowAllHeaders, StringRef OutputPath,
84 bool ShowDepth,
bool MSStyle) {
85 raw_ostream *OutputFile = &llvm::errs();
86 bool OwnsOutputFile =
false;
92 llvm_unreachable(
"Invalid destination for /showIncludes output!");
94 OutputFile = &llvm::errs();
97 OutputFile = &llvm::outs();
103 if (!OutputPath.empty()) {
105 llvm::raw_fd_ostream *OS =
new llvm::raw_fd_ostream(
106 OutputPath.str(), EC,
107 llvm::sys::fs::OF_Append | llvm::sys::fs::OF_TextWithCRLF);
115 OwnsOutputFile =
true;
124 for (
const auto &Header : DepOpts.
ExtraDeps)
127 &PP, ShowAllHeaders, OutputFile, DepOpts, OwnsOutputFile, ShowDepth,
132 FileChangeReason Reason,
143 ++CurrentIncludeDepth;
145 if (CurrentIncludeDepth)
146 --CurrentIncludeDepth;
150 if (CurrentIncludeDepth == 1 && !HasProcessedPredefines) {
151 if (!DepOpts.ShowIncludesPretendHeader.empty()) {
153 ShowDepth, 2, MSStyle);
155 HasProcessedPredefines =
true;
165 bool ShowHeader = (HasProcessedPredefines ||
166 (ShowAllHeaders && CurrentIncludeDepth > 2));
167 unsigned IncludeDepth = CurrentIncludeDepth;
168 if (!HasProcessedPredefines)
170 else if (!DepOpts.ShowIncludesPretendHeader.empty())
173 if (!DepOpts.IncludeSystemHeaders &&
isSystem(NewFileType))
182 UserLoc.
getFilename() != StringRef(
"<command line>")) {
188 void HeaderIncludesCallback::FileSkipped(
const FileEntryRef &SkippedFile,
const
191 if (!DepOpts.ShowSkippedHeaderIncludes)
194 if (!DepOpts.IncludeSystemHeaders &&
isSystem(FileType))
198 CurrentIncludeDepth + 1, MSStyle);