|
42 | 42 | #include "swift/AST/PropertyWrappers.h"
|
43 | 43 | #include "swift/AST/ProtocolConformance.h"
|
44 | 44 | #include "swift/AST/RawComment.h"
|
45 |
| -#include "swift/AST/SearchPathOptions.h" |
46 | 45 | #include "swift/AST/SILLayout.h"
|
| 46 | +#include "swift/AST/SearchPathOptions.h" |
47 | 47 | #include "swift/AST/SemanticAttrs.h"
|
48 | 48 | #include "swift/AST/SourceFile.h"
|
49 | 49 | #include "swift/AST/SubstitutionMap.h"
|
|
65 | 65 | #include "llvm/IR/LLVMContext.h"
|
66 | 66 | #include "llvm/Support/Allocator.h"
|
67 | 67 | #include "llvm/Support/Compiler.h"
|
| 68 | +#include "llvm/Support/FormatVariadic.h" |
68 | 69 | #include <algorithm>
|
69 | 70 | #include <memory>
|
70 | 71 |
|
@@ -692,6 +693,12 @@ void ASTContext::setStatsReporter(UnifiedStatsReporter *stats) {
|
692 | 693 | Stats = stats;
|
693 | 694 | }
|
694 | 695 |
|
| 696 | +/// Set a new module loading callback function. |
| 697 | +void ASTContext::setPreModuleImportCallback( |
| 698 | + std::function<bool(llvm::StringRef, bool)> Callback) { |
| 699 | + PreModuleImportCallback = Callback; |
| 700 | +} |
| 701 | + |
695 | 702 | RC<syntax::SyntaxArena> ASTContext::getSyntaxArena() const {
|
696 | 703 | return getImpl().TheSyntaxArena;
|
697 | 704 | }
|
@@ -2210,6 +2217,8 @@ ASTContext::getModule(ImportPath::Module ModulePath) {
|
2210 | 2217 | return M;
|
2211 | 2218 |
|
2212 | 2219 | auto moduleID = ModulePath[0];
|
| 2220 | + if (PreModuleImportCallback) |
| 2221 | + PreModuleImportCallback(moduleID.Item.str(), false /*=IsOverlay*/); |
2213 | 2222 | for (auto &importer : getImpl().ModuleLoaders) {
|
2214 | 2223 | if (ModuleDecl *M = importer->loadModule(moduleID.Loc, ModulePath)) {
|
2215 | 2224 | if (LangOpts.EnableModuleLoadingRemarks) {
|
@@ -2237,9 +2246,14 @@ ModuleDecl *ASTContext::getOverlayModule(const FileUnit *FU) {
|
2237 | 2246 | for (auto &importer : getImpl().ModuleLoaders) {
|
2238 | 2247 | if (importer.get() == getClangModuleLoader())
|
2239 | 2248 | continue;
|
2240 |
| - if (ModuleDecl *M = importer->loadModule(SourceLoc(), ModPath)) { |
2241 |
| - return M; |
| 2249 | + if (PreModuleImportCallback) { |
| 2250 | + SmallString<256> path; |
| 2251 | + ModPath.getString(path); |
| 2252 | + if (!path.empty()) |
| 2253 | + PreModuleImportCallback(path.str(), true /*=IsOverlay*/); |
2242 | 2254 | }
|
| 2255 | + if (ModuleDecl *M = importer->loadModule(SourceLoc(), ModPath)) |
| 2256 | + return M; |
2243 | 2257 | }
|
2244 | 2258 |
|
2245 | 2259 | return nullptr;
|
|
0 commit comments