Go to the documentation of this file.
23 #include "llvm/ADT/StringSet.h"
24 #include "llvm/ADT/StringSwitch.h"
25 #include "llvm/Support/FileSystem.h"
26 #include "llvm/Support/Path.h"
27 #include "llvm/Support/raw_ostream.h"
29 using namespace clang;
32 struct DepCollectorPPCallbacks :
public PPCallbacks {
38 : DepCollector(L),
SM(
SM), Diags(Diags) {}
50 SM.getFileID(
SM.getExpansionLoc(Loc))))
52 llvm::sys::path::remove_leading_dotslash(*
Filename),
60 llvm::sys::path::remove_leading_dotslash(SkippedFile.
getName());
68 StringRef FileName,
bool IsAngled,
71 StringRef RelativePath,
const Module *Imported,
80 void HasInclude(
SourceLocation Loc, StringRef SpelledFilename,
bool IsAngled,
86 llvm::sys::path::remove_leading_dotslash(
File->getName());
101 bool IsSystem)
override {
113 bool needsInputFileVisitation()
override {
return true; }
114 bool needsSystemInputFileVisitation()
override {
117 void visitModuleFile(StringRef
Filename,
123 bool visitInputFile(StringRef
Filename,
bool IsSystem,
124 bool IsOverridden,
bool IsExplicitModule)
override {
125 if (IsOverridden || IsExplicitModule)
136 bool FromModule,
bool IsSystem,
144 StringRef SearchPath;
148 llvm::sys::path::native(TmpPath);
149 std::transform(TmpPath.begin(), TmpPath.end(), TmpPath.begin(), ::tolower);
150 SearchPath = TmpPath.str();
155 if (Seen.insert(SearchPath).second) {
163 return llvm::StringSwitch<bool>(
Filename)
164 .Case(
"<built-in>",
true)
165 .Case(
"<stdin>",
true)
170 bool IsSystem,
bool IsModuleFile,
181 std::make_unique<DepCollectorMMCallbacks>(*
this));
184 R.
addListener(std::make_unique<DepCollectorASTListener>(*
this));
189 : OutputFile(Opts.OutputFile), Targets(Opts.Targets),
190 IncludeSystemHeaders(Opts.IncludeSystemHeaders),
191 PhonyTarget(Opts.UsePhonyTargets),
192 AddMissingHeaderDeps(Opts.AddMissingHeaderDeps), SeenMissingHeader(
false),
193 IncludeModuleFiles(Opts.IncludeModuleFiles),
194 OutputFormat(Opts.OutputFormat), InputFileIndex(0) {
195 for (
const auto &ExtraDep : Opts.
ExtraDeps) {
203 if (AddMissingHeaderDeps)
210 bool IsSystem,
bool IsModuleFile,
214 if (AddMissingHeaderDeps)
216 SeenMissingHeader =
true;
219 if (IsModuleFile && !IncludeModuleFiles)
225 if (IncludeSystemHeaders)
287 llvm::sys::path::native(
Filename.str(), NativePath);
293 if (NativePath.find_first_of(
" #${}^!") != StringRef::npos)
294 OS <<
'\"' << NativePath <<
'\"';
300 for (
unsigned i = 0, e = NativePath.size(); i != e; ++i) {
301 if (NativePath[i] ==
'#')
303 else if (NativePath[i] ==
' ') {
306 while (j > 0 && NativePath[--j] ==
'\\')
308 }
else if (NativePath[i] ==
'$')
315 if (SeenMissingHeader) {
321 llvm::raw_fd_ostream
OS(OutputFile, EC, llvm::sys::fs::OF_TextWithCRLF);
323 Diags.
Report(diag::err_fe_error_opening) << OutputFile << EC.message();
335 const unsigned MaxColumns = 75;
336 unsigned Columns = 0;
338 for (StringRef
Target : Targets) {
339 unsigned N =
Target.size();
342 }
else if (Columns + N + 2 > MaxColumns) {
359 for (StringRef
File : Files) {
363 unsigned N =
File.size();
364 if (Columns + (N + 1) + 2 > MaxColumns) {
375 if (PhonyTarget && !Files.empty()) {
377 for (
auto I = Files.begin(), E = Files.end(); I != E; ++I) {
378 if (Index++ == InputFileIndex)
DependencyOutputOptions - Options for controlling the compiler dependency file generation.
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
bool sawDependency(StringRef Filename, bool FromModule, bool IsSystem, bool IsModuleFile, bool IsMissing) final override
Called when a new file is seen.
std::vector< std::pair< std::string, ExtraDepKind > > ExtraDeps
A list of extra dependencies (filename and kind) to be used for every target.
Encodes a location in the source.
This interface provides a way to observe the actions of the preprocessor as it does its thing.
void finishedMainFile(DiagnosticsEngine &Diags) override
Called when the end of the main file is reached.
Concrete class used by the front-end to report problems and issues.
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
Token - This structure provides full information about a lexed token.
This class handles loading and caching of source files into memory.
virtual void attachToPreprocessor(Preprocessor &PP)
virtual void finishedMainFile(DiagnosticsEngine &Diags)
Called when the end of the main file is reached.
static bool isSpecialFilename(StringRef Filename)
void addListener(std::unique_ptr< ASTReaderListener > L)
Add an AST callback listener.
DependencyOutputFormat
DependencyOutputFormat - Format for the compiler dependency file.
virtual ~DependencyCollector()
Describes a module or submodule.
void attachToPreprocessor(Preprocessor &PP) override
virtual bool sawDependency(StringRef Filename, bool FromModule, bool IsSystem, bool IsModuleFile, bool IsMissing)
Called when a new file is seen.
An interface for collecting the dependencies of a compilation.
Cached information about one file (either on disk or in the virtual file system).
SourceManager & getSourceManager() const
StringRef getName() const
Record the location of an inclusion directive, such as an #include or #import statement.
void addModuleMapCallbacks(std::unique_ptr< ModuleMapCallbacks > Callback)
Add a module map callback.
A mechanism to observe the actions of the module map parser as it reads module map files.
Represents a character-granular source range.
virtual bool needSystemDependencies()
Return true if system files should be passed to sawDependency().
Reads an AST files chain containing the contents of a translation unit.
DependencyFileGenerator(const DependencyOutputOptions &Opts)
virtual void attachToASTReader(ASTReader &R)
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)
DiagnosticsEngine & getDiagnostics() const
Abstract interface for callback invocations by the ASTReader.
void SetSuppressIncludeNotFoundError(bool Suppress)
StringRef getName() const
void outputDependencyFile(llvm::raw_ostream &OS)
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool isSystem(CharacteristicKind CK)
Determine whether a file / directory characteristic is for system code.
ModuleKind
Specifies the kind of module that has been loaded.
virtual void maybeAddDependency(StringRef Filename, bool FromModule, bool IsSystem, bool IsModuleFile, bool IsMissing)
Add a dependency Filename if it has not been seen before and sawDependency() returns true.
ArrayRef< std::string > getDependencies() const
static void PrintFilename(raw_ostream &OS, StringRef Filename, DependencyOutputFormat OutputFormat)
Print the filename, with escaping or quoting that accommodates the three most likely tools that use d...
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
HeaderSearch & getHeaderSearchInfo() const
bool addDependency(StringRef Filename)
Return true if the filename was added to the list of dependencies, false otherwise.
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.