20
20
21
21
#include " swift/Basic/LLVM.h"
22
22
#include " swift/AST/Import.h"
23
+ #include " clang/Tooling/DependencyScanning/DependencyScanningService.h"
24
+ #include " clang/Tooling/DependencyScanning/DependencyScanningTool.h"
23
25
#include " llvm/ADT/ArrayRef.h"
24
26
#include " llvm/ADT/Optional.h"
25
27
#include " llvm/ADT/StringSet.h"
@@ -305,6 +307,7 @@ class SwiftPlaceholderModuleDependencyStorage : public ModuleDependenciesStorage
305
307
}
306
308
};
307
309
310
+ // MARK: Module Dependencies
308
311
// / Describes the dependencies of a given module.
309
312
// /
310
313
// / The dependencies of a module include all of the source files that go
@@ -475,6 +478,7 @@ using ModuleDependenciesKindRefMap =
475
478
llvm::StringMap<const ModuleDependencies *>,
476
479
ModuleDependenciesKindHash>;
477
480
481
+ // MARK: GlobalModuleDependenciesCache
478
482
// / A cache describing the set of module dependencies that has been queried
479
483
// / thus far. This cache records/stores the actual Dependency values and can be
480
484
// / preserved across different scanning actions (e.g. in
@@ -523,7 +527,7 @@ class GlobalModuleDependenciesCache {
523
527
getDependenciesMap (ModuleDependenciesKind kind) const ;
524
528
525
529
public:
526
- GlobalModuleDependenciesCache () {} ;
530
+ GlobalModuleDependenciesCache ();
527
531
GlobalModuleDependenciesCache (const GlobalModuleDependenciesCache &) = delete ;
528
532
GlobalModuleDependenciesCache &
529
533
operator =(const GlobalModuleDependenciesCache &) = delete ;
@@ -592,6 +596,7 @@ class GlobalModuleDependenciesCache {
592
596
}
593
597
};
594
598
599
+ // MARK: ModuleDependenciesCache
595
600
// / This "local" dependencies cache persists only for the duration of a given
596
601
// / scanning action, and wraps an instance of a `GlobalModuleDependenciesCache`
597
602
// / which may carry cached scanning information from prior scanning actions.
@@ -609,21 +614,17 @@ class ModuleDependenciesCache {
609
614
610
615
// / Name of the module under scan
611
616
StringRef mainScanModuleName;
617
+ // / Set containing all of the Clang modules that have already been seen.
618
+ llvm::StringSet<> alreadySeenClangModules;
619
+ // / The 'persistent' Clang dependency scanner service
620
+ // / TODO: Share this service among common scanner invocations
621
+ clang::tooling::dependencies::DependencyScanningService clangScanningService;
622
+ // / The Clang dependency scanner tool
623
+ clang::tooling::dependencies::DependencyScanningTool clangScanningTool;
612
624
613
625
// / Discovered Clang modules are only cached locally.
614
626
llvm::StringMap<ModuleDependenciesVector> clangModuleDependencies;
615
627
616
- // / Function that will delete \c clangImpl properly.
617
- void (*clangImplDeleter)(ClangModuleDependenciesCacheImpl *) = nullptr ;
618
- // / Additional information needed for Clang dependency scanning.
619
- ClangModuleDependenciesCacheImpl *clangImpl = nullptr ;
620
-
621
- // / Free up the storage associated with the Clang implementation.
622
- void destroyClangImpl () {
623
- if (this ->clangImplDeleter )
624
- this ->clangImplDeleter (this ->clangImpl );
625
- }
626
-
627
628
// / Retrieve the dependencies map that corresponds to the given dependency
628
629
// / kind.
629
630
llvm::StringMap<const ModuleDependencies *> &
@@ -647,28 +648,20 @@ class ModuleDependenciesCache {
647
648
StringRef mainScanModuleName);
648
649
ModuleDependenciesCache (const ModuleDependenciesCache &) = delete ;
649
650
ModuleDependenciesCache &operator =(const ModuleDependenciesCache &) = delete ;
650
- virtual ~ModuleDependenciesCache () { destroyClangImpl (); }
651
651
652
652
public:
653
- // / Set the Clang-specific implementation data.
654
- void
655
- setClangImpl (ClangModuleDependenciesCacheImpl *clangImpl,
656
- void (*clangImplDeleter)(ClangModuleDependenciesCacheImpl *)) {
657
- destroyClangImpl ();
658
-
659
- this ->clangImpl = clangImpl;
660
- this ->clangImplDeleter = clangImplDeleter;
661
- }
662
-
663
- // / Retrieve the Clang-specific implementation data;
664
- ClangModuleDependenciesCacheImpl *getClangImpl () const {
665
- return clangImpl;
666
- }
667
-
668
653
// / Whether we have cached dependency information for the given module.
669
654
bool hasDependencies (StringRef moduleName,
670
655
ModuleLookupSpecifics details) const ;
671
656
657
+ // / Produce a reference to the Clang scanner tool associated with this cache
658
+ clang::tooling::dependencies::DependencyScanningTool& getClangScannerTool () {
659
+ return clangScanningTool;
660
+ }
661
+ llvm::StringSet<>& getAlreadySeenClangModules () {
662
+ return alreadySeenClangModules;
663
+ }
664
+
672
665
// / Look for module dependencies for a module with the given name given
673
666
// / current search paths.
674
667
// /
0 commit comments