|
23 | 23 |
|
24 | 24 | namespace swift {
|
25 | 25 |
|
| 26 | +/// Augments a buffer that was created specifically to hold generated source |
| 27 | +/// code with the reasons for it being generated. |
| 28 | +class GeneratedSourceInfo { |
| 29 | +public: |
| 30 | + /// The kind of generated source code. |
| 31 | + enum Kind { |
| 32 | + /// The expansion of a macro. |
| 33 | + MacroExpansion, |
| 34 | + |
| 35 | + /// A new function body that is replacing an existing function body. |
| 36 | + ReplacedFunctionBody, |
| 37 | + } kind; |
| 38 | + |
| 39 | + /// The buffer ID for the enclosing buffer, in which originalSourceRange |
| 40 | + /// resides. |
| 41 | + unsigned originalBufferID; |
| 42 | + |
| 43 | + /// The source range in the enclosing buffer where this source was generated. |
| 44 | + /// |
| 45 | + /// This could point at a macro expansion or at the implicit location at |
| 46 | + /// which source code was generated. Conceptually, one can think of the |
| 47 | + /// buffer described by a \c GeneratedSource instance as replacing the |
| 48 | + /// code in the \c originalSourceRange. |
| 49 | + SourceRange originalSourceRange; |
| 50 | + |
| 51 | + /// The source range in the generated-source buffer where the generated |
| 52 | + /// code exists. This might be a subrange of the buffer containing the |
| 53 | + /// generated source, but it will never be from a different buffer. |
| 54 | + SourceRange generatedSourceRange; |
| 55 | + |
| 56 | + /// The opaque pointer for an ASTNode. |
| 57 | + void *astNode; |
| 58 | +}; |
| 59 | + |
26 | 60 | /// This class manages and owns source buffers.
|
27 | 61 | class SourceManager {
|
28 | 62 | public:
|
@@ -51,7 +85,10 @@ class SourceManager {
|
51 | 85 | /// to speed up stats.
|
52 | 86 | mutable llvm::DenseMap<StringRef, llvm::vfs::Status> StatusCache;
|
53 | 87 |
|
54 |
| - /// Holds replaced ranges. Keys are orignal ranges, and values are new ranges |
| 88 | + /// Holds generated source information, indexed by the buffer ID. |
| 89 | + llvm::DenseMap<unsigned, GeneratedSourceInfo> GeneratedSourceInfos; |
| 90 | + |
| 91 | + /// Holds replaced ranges. Keys are original ranges, and values are new ranges |
55 | 92 | /// in different buffers. This is used for code completion and ASTContext
|
56 | 93 | /// reusing compilation.
|
57 | 94 | llvm::DenseMap<SourceRange, SourceRange> ReplacedRanges;
|
@@ -108,9 +145,12 @@ class SourceManager {
|
108 | 145 | const llvm::DenseMap<SourceRange, SourceRange> &getReplacedRanges() const {
|
109 | 146 | return ReplacedRanges;
|
110 | 147 | }
|
111 |
| - void setReplacedRange(SourceRange Orig, SourceRange New) { |
112 |
| - ReplacedRanges[Orig] = New; |
113 |
| - } |
| 148 | + |
| 149 | + /// Set the generated source information associated with a given buffer. |
| 150 | + void setGeneratedSourceInfo(unsigned bufferID, GeneratedSourceInfo); |
| 151 | + |
| 152 | + /// Retrieve the generated source information for the given buffer. |
| 153 | + Optional<GeneratedSourceInfo> getGeneratedSourceInfo(unsigned bufferID) const; |
114 | 154 |
|
115 | 155 | /// Record the starting source location of a regex literal.
|
116 | 156 | void recordRegexLiteralStartLoc(SourceLoc loc) {
|
|
0 commit comments