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
@@ -577,12 +578,12 @@ void ASTContext::operator delete(void *Data) throw() {
577
578
AlignedFree (Data);
578
579
}
579
580
580
- ASTContext *ASTContext::get (LangOptions &langOpts,
581
- TypeCheckerOptions &typeckOpts, SILOptions &silOpts,
582
- SearchPathOptions &SearchPathOpts,
583
- ClangImporterOptions &ClangImporterOpts ,
584
- symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts ,
585
- SourceManager &SourceMgr, DiagnosticEngine &Diags ) {
581
+ ASTContext *ASTContext::get (
582
+ LangOptions &langOpts, TypeCheckerOptions &typeckOpts, SILOptions &silOpts,
583
+ SearchPathOptions &SearchPathOpts, ClangImporterOptions &ClangImporterOpts ,
584
+ symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts ,
585
+ SourceManager &SourceMgr, DiagnosticEngine &Diags ,
586
+ std::function< bool (llvm::StringRef, bool )> PreModuleImportCallback ) {
586
587
// If more than two data structures are concatentated, then the aggregate
587
588
// size math needs to become more complicated due to per-struct alignment
588
589
// constraints.
@@ -593,19 +594,21 @@ ASTContext *ASTContext::get(LangOptions &langOpts,
593
594
impl = reinterpret_cast <void *>(
594
595
llvm::alignAddr (impl, llvm::Align (alignof (Implementation))));
595
596
new (impl) Implementation ();
596
- return new (mem)
597
- ASTContext (langOpts, typeckOpts, silOpts, SearchPathOpts ,
598
- ClangImporterOpts, SymbolGraphOpts, SourceMgr, Diags);
597
+ return new (mem) ASTContext (langOpts, typeckOpts, silOpts, SearchPathOpts,
598
+ ClangImporterOpts, SymbolGraphOpts, SourceMgr ,
599
+ Diags, PreModuleImportCallback );
599
600
}
600
601
601
- ASTContext::ASTContext (LangOptions &langOpts, TypeCheckerOptions &typeckOpts,
602
- SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
603
- ClangImporterOptions &ClangImporterOpts,
604
- symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
605
- SourceManager &SourceMgr, DiagnosticEngine &Diags)
602
+ ASTContext::ASTContext (
603
+ LangOptions &langOpts, TypeCheckerOptions &typeckOpts, SILOptions &silOpts,
604
+ SearchPathOptions &SearchPathOpts, ClangImporterOptions &ClangImporterOpts,
605
+ symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
606
+ SourceManager &SourceMgr, DiagnosticEngine &Diags,
607
+ std::function<bool (llvm::StringRef, bool )> PreModuleImportCallback)
606
608
: LangOpts(langOpts), TypeCheckerOpts(typeckOpts), SILOpts(silOpts),
607
609
SearchPathOpts (SearchPathOpts), ClangImporterOpts(ClangImporterOpts),
608
610
SymbolGraphOpts(SymbolGraphOpts), SourceMgr(SourceMgr), Diags(Diags),
611
+ PreModuleImportCallback(PreModuleImportCallback),
609
612
evaluator(Diags, langOpts), TheBuiltinModule(createBuiltinModule(*this )),
610
613
StdlibModuleName(getIdentifier(STDLIB_NAME)),
611
614
SwiftShimsModuleName(getIdentifier(SWIFT_SHIMS_NAME)),
@@ -621,18 +624,18 @@ ASTContext::ASTContext(LangOptions &langOpts, TypeCheckerOptions &typeckOpts,
621
624
The##SHORT_ID##Type(new (*this , AllocationArena::Permanent) \
622
625
ID##Type(*this )),
623
626
#include " swift/AST/TypeNodes.def"
624
- TheIEEE32Type (new (*this , AllocationArena::Permanent)
625
- BuiltinFloatType(BuiltinFloatType::IEEE32,*this )),
626
- TheIEEE64Type(new (*this , AllocationArena::Permanent)
627
- BuiltinFloatType(BuiltinFloatType::IEEE64,*this )),
628
- TheIEEE16Type(new (*this , AllocationArena::Permanent)
629
- BuiltinFloatType(BuiltinFloatType::IEEE16,*this )),
630
- TheIEEE80Type(new (*this , AllocationArena::Permanent)
631
- BuiltinFloatType(BuiltinFloatType::IEEE80,*this )),
632
- TheIEEE128Type(new (*this , AllocationArena::Permanent)
633
- BuiltinFloatType(BuiltinFloatType::IEEE128, *this )),
634
- ThePPC128Type(new (*this , AllocationArena::Permanent)
635
- BuiltinFloatType(BuiltinFloatType::PPC128, *this )) {
627
+ TheIEEE32Type (new (*this , AllocationArena::Permanent)
628
+ BuiltinFloatType(BuiltinFloatType::IEEE32, *this )),
629
+ TheIEEE64Type(new (*this , AllocationArena::Permanent)
630
+ BuiltinFloatType(BuiltinFloatType::IEEE64, *this )),
631
+ TheIEEE16Type(new (*this , AllocationArena::Permanent)
632
+ BuiltinFloatType(BuiltinFloatType::IEEE16, *this )),
633
+ TheIEEE80Type(new (*this , AllocationArena::Permanent)
634
+ BuiltinFloatType(BuiltinFloatType::IEEE80, *this )),
635
+ TheIEEE128Type(new (*this , AllocationArena::Permanent)
636
+ BuiltinFloatType(BuiltinFloatType::IEEE128, *this )),
637
+ ThePPC128Type(new (*this , AllocationArena::Permanent)
638
+ BuiltinFloatType(BuiltinFloatType::PPC128, *this )) {
636
639
637
640
// Initialize all of the known identifiers.
638
641
#define IDENTIFIER_WITH_NAME (Name, IdStr ) Id_##Name = getIdentifier(IdStr);
@@ -2210,6 +2213,8 @@ ASTContext::getModule(ImportPath::Module ModulePath) {
2210
2213
return M;
2211
2214
2212
2215
auto moduleID = ModulePath[0 ];
2216
+ if (PreModuleImportCallback)
2217
+ PreModuleImportCallback (moduleID.Item .str (), false /* =IsOverlay*/ );
2213
2218
for (auto &importer : getImpl ().ModuleLoaders ) {
2214
2219
if (ModuleDecl *M = importer->loadModule (moduleID.Loc , ModulePath)) {
2215
2220
if (LangOpts.EnableModuleLoadingRemarks ) {
@@ -2234,12 +2239,17 @@ ModuleDecl *ASTContext::getOverlayModule(const FileUnit *FU) {
2234
2239
return Existing;
2235
2240
}
2236
2241
2242
+ if (PreModuleImportCallback) {
2243
+ SmallString<16 > path;
2244
+ ModPath.getString (path);
2245
+ if (!path.empty ())
2246
+ PreModuleImportCallback (path.str (), /* IsOverlay=*/ true );
2247
+ }
2237
2248
for (auto &importer : getImpl ().ModuleLoaders ) {
2238
2249
if (importer.get () == getClangModuleLoader ())
2239
2250
continue ;
2240
- if (ModuleDecl *M = importer->loadModule (SourceLoc (), ModPath)) {
2251
+ if (ModuleDecl *M = importer->loadModule (SourceLoc (), ModPath))
2241
2252
return M;
2242
- }
2243
2253
}
2244
2254
2245
2255
return nullptr ;
0 commit comments