|
21 | 21 | #include "llvm/ADT/Hashing.h" |
22 | 22 | #include "llvm/ADT/SetVector.h" |
23 | 23 | #include "llvm/ADT/SmallPtrSet.h" |
| 24 | +#include "llvm/ADT/STLExtras.h" |
24 | 25 |
|
25 | 26 | namespace swift { |
26 | 27 |
|
@@ -152,11 +153,11 @@ class SourceFile final : public FileUnit { |
152 | 153 | /// been validated. |
153 | 154 | llvm::SetVector<ValueDecl *> UnvalidatedDeclsWithOpaqueReturnTypes; |
154 | 155 |
|
155 | | - /// The list of top-level declarations in the source file. This is \c None if |
| 156 | + /// The list of top-level items in the source file. This is \c None if |
156 | 157 | /// they have not yet been parsed. |
157 | 158 | /// FIXME: Once addTopLevelDecl/prependTopLevelDecl |
158 | 159 | /// have been removed, this can become an optional ArrayRef. |
159 | | - Optional<std::vector<Decl *>> Decls; |
| 160 | + Optional<std::vector<ASTNode>> Items; |
160 | 161 |
|
161 | 162 | /// The list of hoisted declarations. See Decl::isHoisted(). |
162 | 163 | /// This is only used by lldb. |
@@ -207,40 +208,37 @@ class SourceFile final : public FileUnit { |
207 | 208 |
|
208 | 209 | /// Appends the given declaration to the end of the top-level decls list. Do |
209 | 210 | /// not add any additional uses of this function. |
210 | | - void addTopLevelDecl(Decl *d) { |
211 | | - // Force decl parsing if we haven't already. |
212 | | - (void)getTopLevelDecls(); |
213 | | - Decls->push_back(d); |
214 | | - } |
| 211 | + void addTopLevelDecl(Decl *d); |
215 | 212 |
|
216 | 213 | /// Prepends a declaration to the top-level decls list. |
217 | 214 | /// |
218 | 215 | /// FIXME: This entrypoint exists to support LLDB. Calls to this function are |
219 | 216 | /// always a mistake, and additional uses should not be added. |
220 | 217 | /// |
221 | 218 | /// See rdar://58355191 |
222 | | - void prependTopLevelDecl(Decl *d) { |
223 | | - // Force decl parsing if we haven't already. |
224 | | - (void)getTopLevelDecls(); |
225 | | - Decls->insert(Decls->begin(), d); |
226 | | - } |
| 219 | + void prependTopLevelDecl(Decl *d); |
227 | 220 |
|
228 | 221 | /// Add a hoisted declaration. See Decl::isHoisted(). |
229 | 222 | void addHoistedDecl(Decl *d); |
230 | 223 |
|
| 224 | + /// Retrieves an immutable view of the list of top-level items in this file. |
| 225 | + ArrayRef<ASTNode> getTopLevelItems() const; |
| 226 | + |
231 | 227 | /// Retrieves an immutable view of the list of top-level decls in this file. |
| 228 | + /// |
| 229 | + /// NOTE: Please use getTopLevelItems() instead. |
232 | 230 | ArrayRef<Decl *> getTopLevelDecls() const; |
233 | 231 |
|
234 | 232 | /// Retrieves an immutable view of the list of hoisted decls in this file. |
235 | 233 | /// See Decl::isHoisted(). |
236 | 234 | ArrayRef<Decl *> getHoistedDecls() const; |
237 | 235 |
|
238 | | - /// Retrieves an immutable view of the top-level decls if they have already |
| 236 | + /// Retrieves an immutable view of the top-level items if they have already |
239 | 237 | /// been parsed, or \c None if they haven't. Should only be used for dumping. |
240 | | - Optional<ArrayRef<Decl *>> getCachedTopLevelDecls() const { |
241 | | - if (!Decls) |
| 238 | + Optional<ArrayRef<ASTNode>> getCachedTopLevelItems() const { |
| 239 | + if (!Items) |
242 | 240 | return None; |
243 | | - return llvm::makeArrayRef(*Decls); |
| 241 | + return llvm::makeArrayRef(*Items); |
244 | 242 | } |
245 | 243 |
|
246 | 244 | /// Retrieve the parsing options for the file. |
@@ -522,7 +520,7 @@ class SourceFile final : public FileUnit { |
522 | 520 | // FIXME: Ideally the parser state should be an output of |
523 | 521 | // ParseSourceFileRequest, but the evaluator doesn't currently support |
524 | 522 | // move-only outputs for cached requests. |
525 | | - (void)getTopLevelDecls(); |
| 523 | + (void)getTopLevelItems(); |
526 | 524 |
|
527 | 525 | auto *state = DelayedParserState.get(); |
528 | 526 | assert(state && "Didn't set any delayed parser state!"); |
|
0 commit comments