diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-08-09 04:46:57 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-08-09 04:46:57 +0000 |
commit | 2a6edb30d9de28dea35dc3dcbce31f1c4ad394b9 (patch) | |
tree | 2a8d238f19f2e771ec7d176bc976d22cfc8d5475 /clang/lib/Frontend/DependencyFile.cpp | |
parent | 2d7fbbc7be6c78370d2d7cc37fe7a8277ac0ff10 (diff) | |
download | llvm-2a6edb30d9de28dea35dc3dcbce31f1c4ad394b9.zip llvm-2a6edb30d9de28dea35dc3dcbce31f1c4ad394b9.tar.gz llvm-2a6edb30d9de28dea35dc3dcbce31f1c4ad394b9.tar.bz2 |
[modules] When building a dependency file, include module maps parsed in the
current compilation, not just those from imported modules.
llvm-svn: 244413
Diffstat (limited to 'clang/lib/Frontend/DependencyFile.cpp')
-rw-r--r-- | clang/lib/Frontend/DependencyFile.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/clang/lib/Frontend/DependencyFile.cpp b/clang/lib/Frontend/DependencyFile.cpp index 0995ab4..72de730 100644 --- a/clang/lib/Frontend/DependencyFile.cpp +++ b/clang/lib/Frontend/DependencyFile.cpp @@ -18,6 +18,7 @@ #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Lex/DirectoryLookup.h" #include "clang/Lex/LexDiagnostic.h" +#include "clang/Lex/ModuleMap.h" #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" #include "clang/Serialization/ASTReader.h" @@ -82,6 +83,20 @@ struct DepCollectorPPCallbacks : public PPCallbacks { } }; +struct DepCollectorMMCallbacks : public ModuleMapCallbacks { + DependencyCollector &DepCollector; + DepCollectorMMCallbacks(DependencyCollector &DC) : DepCollector(DC) {} + + void moduleMapFileRead(SourceLocation Loc, const FileEntry &Entry, + bool IsSystem) override { + StringRef Filename = Entry.getName(); + DepCollector.maybeAddDependency(Filename, /*FromModule*/false, + /*IsSystem*/IsSystem, + /*IsModuleFile*/false, + /*IsMissing*/false); + } +}; + struct DepCollectorASTListener : public ASTReaderListener { DependencyCollector &DepCollector; DepCollectorASTListener(DependencyCollector &L) : DepCollector(L) { } @@ -132,6 +147,8 @@ DependencyCollector::~DependencyCollector() { } void DependencyCollector::attachToPreprocessor(Preprocessor &PP) { PP.addPPCallbacks( llvm::make_unique<DepCollectorPPCallbacks>(*this, PP.getSourceManager())); + PP.getHeaderSearchInfo().getModuleMap().addModuleMapCallbacks( + llvm::make_unique<DepCollectorMMCallbacks>(*this)); } void DependencyCollector::attachToASTReader(ASTReader &R) { R.addListener(llvm::make_unique<DepCollectorASTListener>(*this)); @@ -185,6 +202,17 @@ public: bool includeModuleFiles() const { return IncludeModuleFiles; } }; +class DFGMMCallback : public ModuleMapCallbacks { + DFGImpl &Parent; +public: + DFGMMCallback(DFGImpl &Parent) : Parent(Parent) {} + void moduleMapFileRead(SourceLocation Loc, const FileEntry &Entry, + bool IsSystem) override { + if (!IsSystem || Parent.includeSystemHeaders()) + Parent.AddFilename(Entry.getName()); + } +}; + class DFGASTReaderListener : public ASTReaderListener { DFGImpl &Parent; public: @@ -217,6 +245,8 @@ DependencyFileGenerator *DependencyFileGenerator::CreateAndAttachToPreprocessor( DFGImpl *Callback = new DFGImpl(&PP, Opts); PP.addPPCallbacks(std::unique_ptr<PPCallbacks>(Callback)); + PP.getHeaderSearchInfo().getModuleMap().addModuleMapCallbacks( + llvm::make_unique<DFGMMCallback>(*Callback)); return new DependencyFileGenerator(Callback); } |