clang 10.0.0git

ModuleDepCollector.h
Go to the documentation of this file.
1 //===- ModuleDepCollector.h - Callbacks to collect deps ---------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_TOOLING_DEPENDENCY_SCANNING_MODULE_DEP_COLLECTOR_H
11 #define LLVM_CLANG_TOOLING_DEPENDENCY_SCANNING_MODULE_DEP_COLLECTOR_H
12
13 #include "clang/Basic/LLVM.h"
14 #include "clang/Basic/SourceManager.h"
15 #include "clang/Frontend/Utils.h"
16 #include "clang/Lex/HeaderSearch.h"
17 #include "clang/Lex/PPCallbacks.h"
18 #include "clang/Serialization/ASTReader.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/StringSet.h"
21 #include "llvm/Support/raw_ostream.h"
22
23 #include <string>
24
25 namespace clang {
26 namespace tooling {
27 namespace dependencies {
28
29 class DependencyConsumer;
30
31 struct ModuleDeps {
32 std::string ModuleName;
33 std::string ClangModuleMapFile;
34 std::string ModulePCMPath;
35 std::string ContextHash;
36 llvm::StringSet<> FileDeps;
37 llvm::StringSet<> ClangModuleDeps;
38 bool ImportedByMainFile = false;
39 };
40
41 class ModuleDepCollector;
42
43 class ModuleDepCollectorPP final : public PPCallbacks {
44 public:
45 ModuleDepCollectorPP(CompilerInstance &I, ModuleDepCollector &MDC)
46 : Instance(I), MDC(MDC) {}
47
48 void FileChanged(SourceLocation Loc, FileChangeReason Reason,
49 SrcMgr::CharacteristicKind FileType,
50 FileID PrevFID) override;
51 void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
52 StringRef FileName, bool IsAngled,
53 CharSourceRange FilenameRange, const FileEntry *File,
54 StringRef SearchPath, StringRef RelativePath,
55 const Module *Imported,
56 SrcMgr::CharacteristicKind FileType) override;
57
58 void EndOfMainFile() override;
59
60 private:
61 CompilerInstance &Instance;
62 ModuleDepCollector &MDC;
63 llvm::DenseSet<const Module *> DirectDeps;
64
65 void handleTopLevelModule(const Module *M);
66 void addAllSubmoduleDeps(const Module *M, ModuleDeps &MD);
67 void addModuleDep(const Module *M, ModuleDeps &MD);
68
69 void addDirectDependencies(const Module *Mod);
70 };
71
72 class ModuleDepCollector final : public DependencyCollector {
73 public:
74 ModuleDepCollector(CompilerInstance &I, DependencyConsumer &C);
75
76 void attachToPreprocessor(Preprocessor &PP) override;
77 void attachToASTReader(ASTReader &R) override;
78
79 private:
80 friend ModuleDepCollectorPP;
81
82 CompilerInstance &Instance;
83 DependencyConsumer &Consumer;
84 std::string MainFile;
85 std::string ContextHash;
86 std::vector<std::string> MainDeps;
87 std::unordered_map<std::string, ModuleDeps> Deps;
88 };
89
90 } // end namespace dependencies
91 } // end namespace tooling
92 } // end namespace clang
93
94 #endif // LLVM_CLANG_TOOLING_DEPENDENCY_SCANNING_MODULE_DEP_COLLECTOR_H
clang::DependencyCollector
An interface for collecting the dependencies of a compilation.
Definition: Utils.h:76
SourceManager.h
Defines the SourceManager interface.
clang::tooling::dependencies::ModuleDepCollectorPP
Definition: ModuleDepCollector.h:43
llvm::DenseSet
Definition: Sema.h:71
ASTReader.h
HeaderSearch.h
clang::SrcMgr::CharacteristicKind
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
Definition: SourceManager.h:77
clang::PPCallbacks
This interface provides a way to observe the actions of the preprocessor as it does its thing...
Definition: PPCallbacks.h:35
clang::tooling::dependencies::ModuleDeps::ModuleName
std::string ModuleName
Definition: ModuleDepCollector.h:32
clang::tooling::dependencies::ModuleDeps::FileDeps
llvm::StringSet FileDeps
Definition: ModuleDepCollector.h:36
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
clang::Module
Describes a module or submodule.
Definition: Module.h:64
clang::tooling::dependencies::ModuleDepCollectorPP::ModuleDepCollectorPP
ModuleDepCollectorPP(CompilerInstance &I, ModuleDepCollector &MDC)
Definition: ModuleDepCollector.h:45
LLVM.h
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Utils.h
clang::tooling::dependencies::DependencyConsumer
Definition: DependencyScanningWorker.h:33
clang::tooling::dependencies::ModuleDeps
Definition: ModuleDepCollector.h:31
clang::CharSourceRange
Represents a character-granular source range.
Definition: SourceLocation.h:250
clang::tooling::dependencies::ModuleDeps::ClangModuleDeps
llvm::StringSet ClangModuleDeps
Definition: ModuleDepCollector.h:37
clang::PPCallbacks::FileChangeReason
FileChangeReason
Definition: PPCallbacks.h:39
clang::tooling::dependencies::ModuleDeps::ClangModuleMapFile
std::string ClangModuleMapFile
Definition: ModuleDepCollector.h:33
clang::InclusionDirective
Record the location of an inclusion directive, such as an #include or #import statement.
Definition: PreprocessingRecord.h:208
clang::tooling::dependencies::ModuleDeps::ImportedByMainFile
bool ImportedByMainFile
Definition: ModuleDepCollector.h:38
clang::CompilerInstance
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Definition: CompilerInstance.h:72
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::tooling::dependencies::ModuleDeps::ContextHash
std::string ContextHash
Definition: ModuleDepCollector.h:35
clang::FileEntry
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:78
clang::tooling::dependencies::ModuleDeps::ModulePCMPath
std::string ModulePCMPath
Definition: ModuleDepCollector.h:34
clang::FileID
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Definition: SourceLocation.h:38
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
clang::ASTReader
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:340
PPCallbacks.h
Defines the PPCallbacks interface.
clang::tooling::dependencies::ModuleDepCollector
Definition: ModuleDepCollector.h:72
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:128