1515// it is written to a file which is read by the driver in order to decide which
1616// source files require recompilation.
1717
18- #include " swift/AST/ FrontendSourceFileDepGraphFactory.h"
18+ #include " FrontendSourceFileDepGraphFactory.h"
1919
2020// may not all be needed
2121#include " swift/AST/ASTContext.h"
@@ -298,16 +298,13 @@ std::string FrontendSourceFileDepGraphFactory::getFingerprint(SourceFile *SF) {
298298// MARK: FrontendSourceFileDepGraphFactory - adding collections of defined Decls
299299// ==============================================================================
300300// ==============================================================================
301- // MARK: SourceFileDeclFinder
301+ // MARK: DeclFinder
302302// ==============================================================================
303303
304304namespace {
305305// / Takes all the Decls in a SourceFile, and collects them into buckets by
306306// / groups of DeclKinds. Also casts them to more specific types
307- // / TODO: Factor with SourceFileDeclFinder
308- struct SourceFileDeclFinder {
309-
310- public:
307+ struct DeclFinder {
311308 // / Existing system excludes private decls in some cases.
312309 // / In the future, we might not want to do this, so use bool to decide.
313310 const bool includePrivateDecls;
@@ -324,11 +321,16 @@ struct SourceFileDeclFinder {
324321 ConstPtrPairVec<NominalTypeDecl, ValueDecl> valuesInExtensions;
325322 ConstPtrVec<ValueDecl> classMembers;
326323
324+ using LookupClassMember = llvm::function_ref<void (VisibleDeclConsumer &)>;
325+
326+ public:
327327 // / Construct me and separates the Decls.
328328 // clang-format off
329- SourceFileDeclFinder (const SourceFile *const SF, const bool includePrivateDecls)
329+ DeclFinder (ArrayRef<Decl *> topLevelDecls,
330+ const bool includePrivateDecls,
331+ LookupClassMember lookupClassMember)
330332 : includePrivateDecls(includePrivateDecls) {
331- for (const Decl *const D : SF-> getTopLevelDecls () ) {
333+ for (const Decl *const D : topLevelDecls ) {
332334 select<ExtensionDecl, DeclKind::Extension>(D, extensions, false ) ||
333335 select<OperatorDecl, DeclKind::InfixOperator, DeclKind::PrefixOperator,
334336 DeclKind::PostfixOperator>(D, operators, false ) ||
@@ -345,7 +347,7 @@ struct SourceFileDeclFinder {
345347 findNominalsFromExtensions ();
346348 findNominalsInTopNominals ();
347349 findValuesInExtensions ();
348- findClassMembers (SF );
350+ findClassMembers (lookupClassMember );
349351 }
350352
351353private:
@@ -419,7 +421,7 @@ struct SourceFileDeclFinder {
419421 }
420422
421423 // / Class members are needed for dynamic lookup dependency nodes.
422- void findClassMembers (const SourceFile * const SF ) {
424+ void findClassMembers (LookupClassMember lookup ) {
423425 struct Collector : public VisibleDeclConsumer {
424426 ConstPtrVec<ValueDecl> &classMembers;
425427 Collector (ConstPtrVec<ValueDecl> &classMembers)
@@ -429,7 +431,7 @@ struct SourceFileDeclFinder {
429431 classMembers.push_back (VD);
430432 }
431433 } collector{classMembers};
432- SF-> lookupClassMembers ({}, collector);
434+ lookup ( collector);
433435 }
434436
435437 // / Check \p D to see if it is one of the DeclKinds in the template
@@ -470,7 +472,10 @@ void FrontendSourceFileDepGraphFactory::addAllDefinedDecls() {
470472
471473 // Many kinds of Decls become top-level depends.
472474
473- SourceFileDeclFinder declFinder (SF, includePrivateDeps);
475+ DeclFinder declFinder (SF->getTopLevelDecls (), includePrivateDeps,
476+ [this ](VisibleDeclConsumer &consumer) {
477+ SF->lookupClassMembers ({}, consumer);
478+ });
474479
475480 addAllDefinedDeclsOfAGivenType<NodeKind::topLevel>(
476481 declFinder.precedenceGroups );
0 commit comments