From 486754660bb926339aefcf012a3f848592babb8b Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 28 Jul 2018 11:06:01 +0000 Subject: Vendor import of clang trunk r338150: https://llvm.org/svn/llvm-project/cfe/trunk@338150 --- lib/Frontend/DependencyFile.cpp | 45 ++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 10 deletions(-) (limited to 'lib/Frontend/DependencyFile.cpp') diff --git a/lib/Frontend/DependencyFile.cpp b/lib/Frontend/DependencyFile.cpp index 561eb9c4a316..f89722eeb9ed 100644 --- a/lib/Frontend/DependencyFile.cpp +++ b/lib/Frontend/DependencyFile.cpp @@ -63,7 +63,8 @@ struct DepCollectorPPCallbacks : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, - const Module *Imported) override { + const Module *Imported, + SrcMgr::CharacteristicKind FileType) override { if (!File) DepCollector.maybeAddDependency(FileName, /*FromModule*/false, /*IsSystem*/false, /*IsModuleFile*/false, @@ -162,6 +163,7 @@ class DFGImpl : public PPCallbacks { bool SeenMissingHeader; bool IncludeModuleFiles; DependencyOutputFormat OutputFormat; + unsigned InputFileIndex; private: bool FileMatchesDepCriteria(const char *Filename, @@ -176,26 +178,33 @@ public: AddMissingHeaderDeps(Opts.AddMissingHeaderDeps), SeenMissingHeader(false), IncludeModuleFiles(Opts.IncludeModuleFiles), - OutputFormat(Opts.OutputFormat) { + OutputFormat(Opts.OutputFormat), + InputFileIndex(0) { for (const auto &ExtraDep : Opts.ExtraDeps) { - AddFilename(ExtraDep); + if (AddFilename(ExtraDep)) + ++InputFileIndex; } } void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID) override; + + void FileSkipped(const FileEntry &SkippedFile, const Token &FilenameTok, + SrcMgr::CharacteristicKind FileType) override; + void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, - const Module *Imported) override; + const Module *Imported, + SrcMgr::CharacteristicKind FileType) override; void EndOfMainFile() override { OutputDependencyFile(); } - void AddFilename(StringRef Filename); + bool AddFilename(StringRef Filename); bool includeSystemHeaders() const { return IncludeSystemHeaders; } bool includeModuleFiles() const { return IncludeModuleFiles; } }; @@ -291,6 +300,16 @@ void DFGImpl::FileChanged(SourceLocation Loc, AddFilename(llvm::sys::path::remove_leading_dotslash(Filename)); } +void DFGImpl::FileSkipped(const FileEntry &SkippedFile, + const Token &FilenameTok, + SrcMgr::CharacteristicKind FileType) { + StringRef Filename = SkippedFile.getName(); + if (!FileMatchesDepCriteria(Filename.data(), FileType)) + return; + + AddFilename(llvm::sys::path::remove_leading_dotslash(Filename)); +} + void DFGImpl::InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, @@ -299,7 +318,8 @@ void DFGImpl::InclusionDirective(SourceLocation HashLoc, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, - const Module *Imported) { + const Module *Imported, + SrcMgr::CharacteristicKind FileType) { if (!File) { if (AddMissingHeaderDeps) AddFilename(FileName); @@ -308,9 +328,12 @@ void DFGImpl::InclusionDirective(SourceLocation HashLoc, } } -void DFGImpl::AddFilename(StringRef Filename) { - if (FilesSet.insert(Filename).second) +bool DFGImpl::AddFilename(StringRef Filename) { + if (FilesSet.insert(Filename).second) { Files.push_back(Filename); + return true; + } + return false; } /// Print the filename, with escaping or quoting that accommodates the three @@ -446,8 +469,10 @@ void DFGImpl::OutputDependencyFile() { // Create phony targets if requested. if (PhonyTarget && !Files.empty()) { - // Skip the first entry, this is always the input file itself. - for (auto I = Files.begin() + 1, E = Files.end(); I != E; ++I) { + unsigned Index = 0; + for (auto I = Files.begin(), E = Files.end(); I != E; ++I) { + if (Index++ == InputFileIndex) + continue; OS << '\n'; PrintFilename(OS, *I, OutputFormat); OS << ":\n"; -- cgit v1.2.3