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