@@ -560,6 +560,54 @@ void CompilerInstance::createASTContext() {
560
560
561
561
// ExternalASTSource
562
562
563
+ namespace {
564
+ // Helper to recursively read the module names for all modules we're adding.
565
+ // We mark these as known and redirect any attempt to load that module to
566
+ // the files we were handed.
567
+ struct ReadModuleNames : ASTReaderListener {
568
+ CompilerInstance &CI;
569
+ llvm::SmallVector<IdentifierInfo*, 8 > LoadedModules;
570
+
571
+ ReadModuleNames (CompilerInstance &CI) : CI(CI) {}
572
+
573
+ void ReadModuleName (StringRef ModuleName) override {
574
+ LoadedModules.push_back (
575
+ CI.getPreprocessor ().getIdentifierInfo (ModuleName));
576
+ }
577
+
578
+ void registerAll () {
579
+ ModuleMap &MM = CI.getPreprocessor ().getHeaderSearchInfo ().getModuleMap ();
580
+ for (auto *II : LoadedModules)
581
+ MM.cacheModuleLoad (*II, MM.findModule (II->getName ()));
582
+ LoadedModules.clear ();
583
+ }
584
+
585
+ void markAllUnavailable () {
586
+ for (auto *II : LoadedModules) {
587
+ if (Module *M = CI.getPreprocessor ()
588
+ .getHeaderSearchInfo ()
589
+ .getModuleMap ()
590
+ .findModule (II->getName ())) {
591
+ M->HasIncompatibleModuleFile = true ;
592
+
593
+ // Mark module as available if the only reason it was unavailable
594
+ // was missing headers.
595
+ SmallVector<Module *, 2 > Stack;
596
+ Stack.push_back (M);
597
+ while (!Stack.empty ()) {
598
+ Module *Current = Stack.pop_back_val ();
599
+ if (Current->IsUnimportable ) continue ;
600
+ Current->IsAvailable = true ;
601
+ Stack.insert (Stack.end (),
602
+ Current->submodule_begin (), Current->submodule_end ());
603
+ }
604
+ }
605
+ }
606
+ LoadedModules.clear ();
607
+ }
608
+ };
609
+ } // namespace
610
+
563
611
void CompilerInstance::createPCHExternalASTSource (
564
612
StringRef Path, DisableValidationForModuleKind DisableValidation,
565
613
bool AllowPCHWithCompilerErrors, void *DeserializationListener,
@@ -1647,52 +1695,6 @@ bool CompilerInstance::loadModuleFile(StringRef FileName) {
1647
1695
*FrontendTimerGroup);
1648
1696
llvm::TimeRegion TimeLoading (FrontendTimerGroup ? &Timer : nullptr );
1649
1697
1650
- // Helper to recursively read the module names for all modules we're adding.
1651
- // We mark these as known and redirect any attempt to load that module to
1652
- // the files we were handed.
1653
- struct ReadModuleNames : ASTReaderListener {
1654
- CompilerInstance &CI;
1655
- llvm::SmallVector<IdentifierInfo*, 8 > LoadedModules;
1656
-
1657
- ReadModuleNames (CompilerInstance &CI) : CI(CI) {}
1658
-
1659
- void ReadModuleName (StringRef ModuleName) override {
1660
- LoadedModules.push_back (
1661
- CI.getPreprocessor ().getIdentifierInfo (ModuleName));
1662
- }
1663
-
1664
- void registerAll () {
1665
- ModuleMap &MM = CI.getPreprocessor ().getHeaderSearchInfo ().getModuleMap ();
1666
- for (auto *II : LoadedModules)
1667
- MM.cacheModuleLoad (*II, MM.findModule (II->getName ()));
1668
- LoadedModules.clear ();
1669
- }
1670
-
1671
- void markAllUnavailable () {
1672
- for (auto *II : LoadedModules) {
1673
- if (Module *M = CI.getPreprocessor ()
1674
- .getHeaderSearchInfo ()
1675
- .getModuleMap ()
1676
- .findModule (II->getName ())) {
1677
- M->HasIncompatibleModuleFile = true ;
1678
-
1679
- // Mark module as available if the only reason it was unavailable
1680
- // was missing headers.
1681
- SmallVector<Module *, 2 > Stack;
1682
- Stack.push_back (M);
1683
- while (!Stack.empty ()) {
1684
- Module *Current = Stack.pop_back_val ();
1685
- if (Current->IsUnimportable ) continue ;
1686
- Current->IsAvailable = true ;
1687
- Stack.insert (Stack.end (),
1688
- Current->submodule_begin (), Current->submodule_end ());
1689
- }
1690
- }
1691
- }
1692
- LoadedModules.clear ();
1693
- }
1694
- };
1695
-
1696
1698
// If we don't already have an ASTReader, create one now.
1697
1699
if (!TheASTReader)
1698
1700
createASTReader ();
0 commit comments