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 {
52 bool ShowDepth,
unsigned CurrentIncludeDepth,
61 Msg +=
"Note: including file:";
65 for (
unsigned i = 1; i != CurrentIncludeDepth; ++i)
66 Msg += MSStyle ?
' ' :
'.';
80 bool ShowAllHeaders, StringRef OutputPath,
81 bool ShowDepth,
bool MSStyle) {
82 raw_ostream *OutputFile = &llvm::errs();
83 bool OwnsOutputFile =
false;
89 llvm_unreachable(
"Invalid destination for /showIncludes output!");
91 OutputFile = &llvm::errs();
94 OutputFile = &llvm::outs();
100 if (!OutputPath.empty()) {
102 llvm::raw_fd_ostream *OS =
new llvm::raw_fd_ostream(
103 OutputPath.str(), EC,
104 llvm::sys::fs::OF_Append | llvm::sys::fs::OF_Text);
112 OwnsOutputFile =
true;
121 for (
const auto &Header : DepOpts.
ExtraDeps)
124 &PP, ShowAllHeaders, OutputFile, DepOpts, OwnsOutputFile, ShowDepth,
129 FileChangeReason Reason,
140 ++CurrentIncludeDepth;
142 if (CurrentIncludeDepth)
143 --CurrentIncludeDepth;
147 if (CurrentIncludeDepth == 1 && !HasProcessedPredefines) {
148 if (!DepOpts.ShowIncludesPretendHeader.empty()) {
150 ShowDepth, 2, MSStyle);
152 HasProcessedPredefines =
true;
162 bool ShowHeader = (HasProcessedPredefines ||
163 (ShowAllHeaders && CurrentIncludeDepth > 2));
164 unsigned IncludeDepth = CurrentIncludeDepth;
165 if (!HasProcessedPredefines)
167 else if (!DepOpts.ShowIncludesPretendHeader.empty())
176 UserLoc.
getFilename() != StringRef(
"<command line>")) {
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...
ShowIncludesDestination ShowIncludesDest
Destination of cl.exe style /showIncludes info.
bool isInvalid() const
Return true if this object is invalid or uninitialized.
Defines the clang::Preprocessor interface.
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...
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.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Dataflow Directional Tag Classes.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
DiagnosticsEngine & getDiagnostics() const
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 i) escaping '\' and " characters and ii) ...
Engages in a tight little dance with the lexer to efficiently preprocess tokens.