|
12 | 12 | #include "Protocol.h"
|
13 | 13 | #include "SourceCode.h"
|
14 | 14 | #include "index/Symbol.h"
|
15 |
| -#include "support/Logger.h" |
16 | 15 | #include "support/Path.h"
|
17 | 16 | #include "clang/Basic/TokenKinds.h"
|
18 | 17 | #include "clang/Format/Format.h"
|
19 | 18 | #include "clang/Lex/HeaderSearch.h"
|
20 | 19 | #include "clang/Lex/PPCallbacks.h"
|
21 | 20 | #include "clang/Tooling/Inclusions/HeaderIncludes.h"
|
22 | 21 | #include "llvm/ADT/ArrayRef.h"
|
23 |
| -#include "llvm/ADT/StringExtras.h" |
24 | 22 | #include "llvm/ADT/StringRef.h"
|
25 | 23 | #include "llvm/ADT/StringSet.h"
|
26 | 24 | #include "llvm/Support/Error.h"
|
@@ -64,7 +62,7 @@ struct Inclusion {
|
64 | 62 | llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Inclusion &);
|
65 | 63 | bool operator==(const Inclusion &LHS, const Inclusion &RHS);
|
66 | 64 |
|
67 |
| -// Contains information about one file in the build graph and its direct |
| 65 | +// Contains information about one file in the build grpah and its direct |
68 | 66 | // dependencies. Doesn't own the strings it references (IncludeGraph is
|
69 | 67 | // self-contained).
|
70 | 68 | struct IncludeGraphNode {
|
@@ -114,54 +112,34 @@ operator|=(IncludeGraphNode::SourceFlag &A, IncludeGraphNode::SourceFlag B) {
|
114 | 112 | // in any non-preamble inclusions.
|
115 | 113 | class IncludeStructure {
|
116 | 114 | public:
|
117 |
| - // HeaderID identifies file in the include graph. It corresponds to a |
118 |
| - // FileEntry rather than a FileID, but stays stable across preamble & main |
119 |
| - // file builds. |
120 |
| - enum class HeaderID : unsigned {}; |
121 |
| - |
122 |
| - llvm::Optional<HeaderID> getID(const FileEntry *Entry) const; |
123 |
| - HeaderID getOrCreateID(const FileEntry *Entry); |
124 |
| - |
125 |
| - StringRef getRealPath(HeaderID ID) const { |
126 |
| - assert(static_cast<unsigned>(ID) <= RealPathNames.size()); |
127 |
| - return RealPathNames[static_cast<unsigned>(ID)]; |
128 |
| - } |
| 115 | + std::vector<Inclusion> MainFileIncludes; |
129 | 116 |
|
130 | 117 | // Return all transitively reachable files.
|
131 | 118 | llvm::ArrayRef<std::string> allHeaders() const { return RealPathNames; }
|
132 | 119 |
|
133 | 120 | // Return all transitively reachable files, and their minimum include depth.
|
134 | 121 | // All transitive includes (absolute paths), with their minimum include depth.
|
135 | 122 | // Root --> 0, #included file --> 1, etc.
|
136 |
| - // Root is the ID of the header being visited first. |
137 |
| - // Usually it is getID(SM.getFileEntryForID(SM.getMainFileID())->getName()). |
138 |
| - llvm::DenseMap<HeaderID, unsigned> includeDepth(HeaderID Root) const; |
| 123 | + // Root is clang's name for a file, which may not be absolute. |
| 124 | + // Usually it should be SM.getFileEntryForID(SM.getMainFileID())->getName(). |
| 125 | + llvm::StringMap<unsigned> includeDepth(llvm::StringRef Root) const; |
139 | 126 |
|
140 |
| - // Maps HeaderID to the ids of the files included from it. |
141 |
| - llvm::DenseMap<HeaderID, SmallVector<HeaderID>> IncludeChildren; |
142 |
| - |
143 |
| - std::vector<Inclusion> MainFileIncludes; |
144 |
| - |
145 |
| - std::string dump() { |
146 |
| - std::string Result = |
147 |
| - "RealPathNames: " + |
148 |
| - llvm::join(RealPathNames.begin(), RealPathNames.end(), ", "); |
149 |
| - Result += "; NameToIndex: "; |
150 |
| - for (const auto &NameIndex : NameToIndex) { |
151 |
| - Result += NameIndex.first().str() + ' ' + |
152 |
| - std::to_string(static_cast<unsigned>(NameIndex.second)) + ", "; |
153 |
| - } |
154 |
| - return Result; |
155 |
| - } |
| 127 | + // This updates IncludeDepth(), but not MainFileIncludes. |
| 128 | + void recordInclude(llvm::StringRef IncludingName, |
| 129 | + llvm::StringRef IncludedName, |
| 130 | + llvm::StringRef IncludedRealName); |
156 | 131 |
|
157 | 132 | private:
|
158 |
| - std::vector<std::string> RealPathNames; // In HeaderID order. |
159 |
| - // HeaderID maps the FileEntry::Name to the internal representation. |
160 | 133 | // Identifying files in a way that persists from preamble build to subsequent
|
161 |
| - // builds is surprisingly hard. FileID is unavailable in |
162 |
| - // InclusionDirective(), and RealPathName and UniqueID are not preserved in |
163 |
| - // the preamble. |
164 |
| - llvm::StringMap<HeaderID> NameToIndex; |
| 134 | + // builds is surprisingly hard. FileID is unavailable in InclusionDirective(), |
| 135 | + // and RealPathName and UniqueID are not preserved in the preamble. |
| 136 | + // We use the FileEntry::Name, which is stable, interned into a "file index". |
| 137 | + // The paths we want to expose are the RealPathName, so store those too. |
| 138 | + std::vector<std::string> RealPathNames; // In file index order. |
| 139 | + unsigned fileIndex(llvm::StringRef Name); |
| 140 | + llvm::StringMap<unsigned> NameToIndex; // Values are file indexes. |
| 141 | + // Maps a file's index to that of the files it includes. |
| 142 | + llvm::DenseMap<unsigned, llvm::SmallVector<unsigned>> IncludeChildren; |
165 | 143 | };
|
166 | 144 |
|
167 | 145 | /// Returns a PPCallback that visits all inclusions in the main file.
|
@@ -227,31 +205,4 @@ class IncludeInserter {
|
227 | 205 | } // namespace clangd
|
228 | 206 | } // namespace clang
|
229 | 207 |
|
230 |
| -namespace llvm { |
231 |
| - |
232 |
| -// Support Tokens as DenseMap keys. |
233 |
| -template <> struct DenseMapInfo<clang::clangd::IncludeStructure::HeaderID> { |
234 |
| - static inline clang::clangd::IncludeStructure::HeaderID getEmptyKey() { |
235 |
| - return static_cast<clang::clangd::IncludeStructure::HeaderID>( |
236 |
| - DenseMapInfo<unsigned>::getEmptyKey()); |
237 |
| - } |
238 |
| - |
239 |
| - static inline clang::clangd::IncludeStructure::HeaderID getTombstoneKey() { |
240 |
| - return static_cast<clang::clangd::IncludeStructure::HeaderID>( |
241 |
| - DenseMapInfo<unsigned>::getTombstoneKey()); |
242 |
| - } |
243 |
| - |
244 |
| - static unsigned |
245 |
| - getHashValue(const clang::clangd::IncludeStructure::HeaderID &Tag) { |
246 |
| - return hash_value(static_cast<unsigned>(Tag)); |
247 |
| - } |
248 |
| - |
249 |
| - static bool isEqual(const clang::clangd::IncludeStructure::HeaderID &LHS, |
250 |
| - const clang::clangd::IncludeStructure::HeaderID &RHS) { |
251 |
| - return LHS == RHS; |
252 |
| - } |
253 |
| -}; |
254 |
| - |
255 |
| -} // namespace llvm |
256 |
| - |
257 | 208 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_HEADERS_H
|
0 commit comments