15
15
// it is written to a file which is read by the driver in order to decide which
16
16
// source files require recompilation.
17
17
18
- #include " swift/AST/ FrontendSourceFileDepGraphFactory.h"
18
+ #include " FrontendSourceFileDepGraphFactory.h"
19
19
20
20
// may not all be needed
21
21
#include " swift/AST/ASTContext.h"
@@ -298,16 +298,13 @@ std::string FrontendSourceFileDepGraphFactory::getFingerprint(SourceFile *SF) {
298
298
// MARK: FrontendSourceFileDepGraphFactory - adding collections of defined Decls
299
299
// ==============================================================================
300
300
// ==============================================================================
301
- // MARK: SourceFileDeclFinder
301
+ // MARK: DeclFinder
302
302
// ==============================================================================
303
303
304
304
namespace {
305
305
// / Takes all the Decls in a SourceFile, and collects them into buckets by
306
306
// / groups of DeclKinds. Also casts them to more specific types
307
- // / TODO: Factor with SourceFileDeclFinder
308
- struct SourceFileDeclFinder {
309
-
310
- public:
307
+ struct DeclFinder {
311
308
// / Existing system excludes private decls in some cases.
312
309
// / In the future, we might not want to do this, so use bool to decide.
313
310
const bool includePrivateDecls;
@@ -324,11 +321,16 @@ struct SourceFileDeclFinder {
324
321
ConstPtrPairVec<NominalTypeDecl, ValueDecl> valuesInExtensions;
325
322
ConstPtrVec<ValueDecl> classMembers;
326
323
324
+ using LookupClassMember = llvm::function_ref<void (VisibleDeclConsumer &)>;
325
+
326
+ public:
327
327
// / Construct me and separates the Decls.
328
328
// clang-format off
329
- SourceFileDeclFinder (const SourceFile *const SF, const bool includePrivateDecls)
329
+ DeclFinder (ArrayRef<Decl *> topLevelDecls,
330
+ const bool includePrivateDecls,
331
+ LookupClassMember lookupClassMember)
330
332
: includePrivateDecls(includePrivateDecls) {
331
- for (const Decl *const D : SF-> getTopLevelDecls () ) {
333
+ for (const Decl *const D : topLevelDecls ) {
332
334
select<ExtensionDecl, DeclKind::Extension>(D, extensions, false ) ||
333
335
select<OperatorDecl, DeclKind::InfixOperator, DeclKind::PrefixOperator,
334
336
DeclKind::PostfixOperator>(D, operators, false ) ||
@@ -345,7 +347,7 @@ struct SourceFileDeclFinder {
345
347
findNominalsFromExtensions ();
346
348
findNominalsInTopNominals ();
347
349
findValuesInExtensions ();
348
- findClassMembers (SF );
350
+ findClassMembers (lookupClassMember );
349
351
}
350
352
351
353
private:
@@ -419,7 +421,7 @@ struct SourceFileDeclFinder {
419
421
}
420
422
421
423
// / Class members are needed for dynamic lookup dependency nodes.
422
- void findClassMembers (const SourceFile * const SF ) {
424
+ void findClassMembers (LookupClassMember lookup ) {
423
425
struct Collector : public VisibleDeclConsumer {
424
426
ConstPtrVec<ValueDecl> &classMembers;
425
427
Collector (ConstPtrVec<ValueDecl> &classMembers)
@@ -429,7 +431,7 @@ struct SourceFileDeclFinder {
429
431
classMembers.push_back (VD);
430
432
}
431
433
} collector{classMembers};
432
- SF-> lookupClassMembers ({}, collector);
434
+ lookup ( collector);
433
435
}
434
436
435
437
// / Check \p D to see if it is one of the DeclKinds in the template
@@ -470,7 +472,10 @@ void FrontendSourceFileDepGraphFactory::addAllDefinedDecls() {
470
472
471
473
// Many kinds of Decls become top-level depends.
472
474
473
- SourceFileDeclFinder declFinder (SF, includePrivateDeps);
475
+ DeclFinder declFinder (SF->getTopLevelDecls (), includePrivateDeps,
476
+ [this ](VisibleDeclConsumer &consumer) {
477
+ SF->lookupClassMembers ({}, consumer);
478
+ });
474
479
475
480
addAllDefinedDeclsOfAGivenType<NodeKind::topLevel>(
476
481
declFinder.precedenceGroups );
0 commit comments