|
18 | 18 | #include "clang/Basic/FileManager.h"
|
19 | 19 | #include "llvm/ADT/ArrayRef.h"
|
20 | 20 | #include "llvm/ADT/DenseSet.h"
|
| 21 | +#include "llvm/ADT/TinyPtrVector.h" |
21 | 22 | #include "llvm/Support/SourceMgr.h"
|
22 | 23 | #include <map>
|
23 | 24 | #include <optional>
|
24 | 25 | #include <vector>
|
25 | 26 |
|
| 27 | +namespace swift { |
| 28 | + class SourceFile; |
| 29 | +} |
| 30 | + |
| 31 | +namespace llvm { |
| 32 | + template <> struct PointerLikeTypeTraits<swift::SourceFile *> { |
| 33 | + public: |
| 34 | + static inline swift::SourceFile *getFromVoidPointer(void *P) { |
| 35 | + return (swift::SourceFile *)P; |
| 36 | + } |
| 37 | + static inline void *getAsVoidPointer(swift::SourceFile *S) { |
| 38 | + return (void *)S; |
| 39 | + } |
| 40 | + enum { NumLowBitsAvailable = /*swift::DeclContextAlignInBits=*/ 3 }; |
| 41 | + }; |
| 42 | +} |
| 43 | + |
26 | 44 | namespace swift {
|
27 | 45 |
|
28 | 46 | class CustomAttr;
|
29 | 47 | class DeclContext;
|
| 48 | +class SourceFile; |
30 | 49 |
|
31 | 50 | /// Augments a buffer that was created specifically to hold generated source
|
32 | 51 | /// code with the reasons for it being generated.
|
@@ -123,6 +142,13 @@ class SourceManager {
|
123 | 142 | /// is an unfortunate hack needed to allow for correct re-lexing.
|
124 | 143 | llvm::DenseSet<SourceLoc> RegexLiteralStartLocs;
|
125 | 144 |
|
| 145 | + /// Mapping from each buffer ID to the source files that describe it |
| 146 | + /// semantically. |
| 147 | + llvm::DenseMap< |
| 148 | + unsigned, |
| 149 | + llvm::TinyPtrVector<SourceFile *> |
| 150 | + > bufferIDToSourceFiles; |
| 151 | + |
126 | 152 | std::map<const char *, VirtualFile> VirtualFiles;
|
127 | 153 | mutable std::pair<const char *, const VirtualFile*> CachedVFile = {nullptr, nullptr};
|
128 | 154 |
|
@@ -323,6 +349,13 @@ class SourceManager {
|
323 | 349 | /// Adds a memory buffer to the SourceManager, taking ownership of it.
|
324 | 350 | unsigned addNewSourceBuffer(std::unique_ptr<llvm::MemoryBuffer> Buffer);
|
325 | 351 |
|
| 352 | + /// Record the source file as having the given buffer ID. |
| 353 | + void recordSourceFile(unsigned bufferID, SourceFile *sourceFile); |
| 354 | + |
| 355 | + /// Retrieve the source files for the given buffer ID. |
| 356 | + llvm::TinyPtrVector<SourceFile *> |
| 357 | + getSourceFilesForBufferID(unsigned bufferID) const; |
| 358 | + |
326 | 359 | /// Add a \c #sourceLocation-defined virtual file region of \p Length.
|
327 | 360 | void createVirtualFile(SourceLoc Loc, StringRef Name, int LineOffset,
|
328 | 361 | unsigned Length);
|
|
0 commit comments