]> granicus.if.org Git - clang/commitdiff
Quick fix for layering that broke shared library build.
authorJohn Thompson <John.Thompson.JTSoftware@gmail.com>
Wed, 23 Apr 2014 19:04:32 +0000 (19:04 +0000)
committerJohn Thompson <John.Thompson.JTSoftware@gmail.com>
Wed, 23 Apr 2014 19:04:32 +0000 (19:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207011 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/ASTUnit.h
include/clang/Frontend/CompilerInstance.h
include/clang/Lex/ModuleLoader.h
lib/Frontend/CompilerInstance.cpp
lib/Sema/SemaLookup.cpp
unittests/Basic/SourceManagerTest.cpp
unittests/Lex/LexerTest.cpp
unittests/Lex/PPCallbacksTest.cpp
unittests/Lex/PPConditionalDirectiveRecordTest.cpp

index 666e5dd7c72dad1cee6ae6572484de7e2adb527a..b730cb9da762968e0c7e73809325724f6f773e53 100644 (file)
@@ -874,8 +874,10 @@ public:
   void makeModuleVisible(Module *Mod, Module::NameVisibilityKind Visibility,
                          SourceLocation ImportLoc, bool Complain) override {}
 
-  GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc)
+  GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override
     { return 0; }
+  bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override
+    { return 0; };
 };
 
 } // namespace clang
index 1a89a8a156fa29ec167ce95fe2d0dded15489fd9..a7368bd1497681cc298fb3e3683e5b0cc4c24db1 100644 (file)
@@ -700,7 +700,9 @@ public:
     return ModuleLoader::HadFatalFailure;
   }
 
-  GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc);
+  GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override;
+
+  bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override;
 };
 
 } // end namespace clang
index 0a690812a92059ccd790d121408113e5d1479977..7869799c2c5413595946d737edf3789bdde53874 100644 (file)
@@ -113,7 +113,14 @@ public:
   /// \param TriggerLoc The location for what triggered the load.
   /// \returns Returns null if load failed.
   virtual GlobalModuleIndex *loadGlobalModuleIndex(
-                                            SourceLocation TriggerLoc) = 0;
+                                                SourceLocation TriggerLoc) = 0;
+
+  /// Check global module index for missing imports.
+  /// \param Name The symbol name to look for.
+  /// \param TriggerLoc The location for what triggered the load.
+  /// \returns Returns true if any modules with that symbol found.
+  virtual bool lookupMissingImports(StringRef Name,
+                                    SourceLocation TriggerLoc) = 0;
 
   bool HadFatalFailure;
 };
index 79b96ab6890657a5e1c3cb4af5ac6ccb68280ec1..b74c288cdaaf645e636de208dfa9f8726dec20fb 100644 (file)
@@ -1466,3 +1466,29 @@ GlobalModuleIndex *CompilerInstance::loadGlobalModuleIndex(
   }
   return GlobalIndex;
 }
+
+// Check global module index for missing imports.
+bool
+CompilerInstance::lookupMissingImports(StringRef Name,
+                                       SourceLocation TriggerLoc) {
+  // Look for the symbol in non-imported modules, but only if an error
+  // actually occurred.
+  if (!buildingModule()) {
+    // Load global module index, or retrieve a previously loaded one.
+    GlobalModuleIndex *GlobalIndex = loadGlobalModuleIndex(
+      TriggerLoc);
+
+    // Only if we have a global index.
+    if (GlobalIndex) {
+      GlobalModuleIndex::HitSet FoundModules;
+
+      // Find the modules that reference the identifier.
+      // Note that this only finds top-level modules.
+      // We'll let diagnoseTypo find the actual declaration module.
+      if (GlobalIndex->lookupIdentifier(Name, FoundModules))
+        return true;
+    }
+  }
+
+  return false;
+}
index c0d49a7dd94a9b165e7c172b49bb869d329d6330..e8ef5ac6b98d3944e2c4c8abccbe5e203620af77 100644 (file)
@@ -23,8 +23,6 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/LangOptions.h"
-#include "clang/Lex/HeaderSearch.h"
-#include "clang/Lex/ModuleLoader.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/ExternalSemaSource.h"
@@ -35,8 +33,6 @@
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/TemplateDeduction.h"
 #include "clang/Sema/TypoCorrection.h"
-#include "clang/Serialization/GlobalModuleIndex.h"
-#include "clang/Serialization/Module.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -3986,29 +3982,13 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName,
 
   TypoCorrectionConsumer Consumer(*this, Typo);
 
-  // Get the module loader (usually compiler instance).
-  ModuleLoader &Loader = PP.getModuleLoader();
-
-  // Look for the symbol in non-imported modules, but only if an error
-  // actually occurred.
-  if ((Mode == CTK_ErrorRecovery) && !Loader.buildingModule() &&
-      getLangOpts().Modules && getLangOpts().ModulesSearchAll) {
-    // Load global module index, or retrieve a previously loaded one.
-    GlobalModuleIndex *GlobalIndex = Loader.loadGlobalModuleIndex(
-      TypoName.getLocStart());
-
-    // Only if we have a global index.
-    if (GlobalIndex) {
-      GlobalModuleIndex::HitSet FoundModules;
-
-      // Find the modules that reference the identifier.
-      // Note that this only finds top-level modules.
-      // We'll let diagnoseTypo find the actual declaration module.
-      if (GlobalIndex->lookupIdentifier(Typo->getName(), FoundModules)) {
-        TypoCorrection TC(TypoName.getName(), (NestedNameSpecifier *)0, 0);
-        TC.setCorrectionRange(SS, TypoName);
-        TC.setRequiresImport(true);
-      }
+  if ((Mode == CTK_ErrorRecovery) &&  getLangOpts().Modules &&
+      getLangOpts().ModulesSearchAll) {
+    if (PP.getModuleLoader().lookupMissingImports(Typo->getName(),
+                                               TypoName.getLocStart())) {
+      TypoCorrection TC(TypoName.getName(), (NestedNameSpecifier *)0, 0);
+      TC.setCorrectionRange(SS, TypoName);
+      TC.setRequiresImport(true);
     }
   }
 
index b3796c34fecce5f11002a25285ae2837d8ba2f6f..88c3fb76ca09d93d0f7a64971b65e3b60e11be96 100644 (file)
@@ -52,20 +52,22 @@ protected:
 };
 
 class VoidModuleLoader : public ModuleLoader {
-  virtual ModuleLoadResult loadModule(SourceLocation ImportLoc, 
-                                      ModuleIdPath Path,
-                                      Module::NameVisibilityKind Visibility,
-                                      bool IsInclusionDirective) {
+  ModuleLoadResult loadModule(SourceLocation ImportLoc, 
+                              ModuleIdPath Path,
+                              Module::NameVisibilityKind Visibility,
+                              bool IsInclusionDirective) override {
     return ModuleLoadResult();
   }
 
-  virtual void makeModuleVisible(Module *Mod,
-                                 Module::NameVisibilityKind Visibility,
-                                 SourceLocation ImportLoc,
-                                 bool Complain) { }
+  void makeModuleVisible(Module *Mod,
+                         Module::NameVisibilityKind Visibility,
+                         SourceLocation ImportLoc,
+                         bool Complain) override { }
 
-  virtual GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc)
+  GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override
     { return 0; }
+  bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override
+    { return 0; };
 };
 
 TEST_F(SourceManagerTest, isBeforeInTranslationUnit) {
index 8aa95c966ad58410fe480024d8fa1e36c8c1a3aa..0faad459837c7721b7bd1eceb58edcdd770d9be9 100644 (file)
@@ -29,20 +29,22 @@ using namespace clang;
 namespace {
 
 class VoidModuleLoader : public ModuleLoader {
-  virtual ModuleLoadResult loadModule(SourceLocation ImportLoc, 
-                                      ModuleIdPath Path,
-                                      Module::NameVisibilityKind Visibility,
-                                      bool IsInclusionDirective) {
+  ModuleLoadResult loadModule(SourceLocation ImportLoc, 
+                              ModuleIdPath Path,
+                              Module::NameVisibilityKind Visibility,
+                              bool IsInclusionDirective) override {
     return ModuleLoadResult();
   }
 
-  virtual void makeModuleVisible(Module *Mod,
-                                 Module::NameVisibilityKind Visibility,
-                                 SourceLocation ImportLoc,
-                                 bool Complain) { }
+  void makeModuleVisible(Module *Mod,
+                         Module::NameVisibilityKind Visibility,
+                         SourceLocation ImportLoc,
+                         bool Complain) override { }
 
-  virtual GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc)
+  GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override
     { return 0; }
+  bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override
+    { return 0; };
 };
 
 // The test fixture.
index 3c953c209124900f1152d99e6b0ed71156c3c29b..bdc026a223cdac398d2f540459d496346145551d 100644 (file)
@@ -34,20 +34,22 @@ namespace {
 
 // Stub out module loading.
 class VoidModuleLoader : public ModuleLoader {
-  virtual ModuleLoadResult loadModule(SourceLocation ImportLoc, 
-                                      ModuleIdPath Path,
-                                      Module::NameVisibilityKind Visibility,
-                                      bool IsInclusionDirective) {
+  ModuleLoadResult loadModule(SourceLocation ImportLoc, 
+                              ModuleIdPath Path,
+                              Module::NameVisibilityKind Visibility,
+                              bool IsInclusionDirective) override {
     return ModuleLoadResult();
   }
 
-  virtual void makeModuleVisible(Module *Mod,
-                                 Module::NameVisibilityKind Visibility,
-                                 SourceLocation ImportLoc,
-                                 bool Complain) { }
+  void makeModuleVisible(Module *Mod,
+                         Module::NameVisibilityKind Visibility,
+                         SourceLocation ImportLoc,
+                         bool Complain) override { }
 
-  virtual GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc)
+  GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override
     { return 0; }
+  bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override
+    { return 0; };
 };
 
 // Stub to collect data from InclusionDirective callbacks.
index 4e22589069dd48a0d33eb300970657fbf5c22633..bacc899beccd33479dc2b4af86eed61522b01e43 100644 (file)
@@ -53,20 +53,22 @@ protected:
 };
 
 class VoidModuleLoader : public ModuleLoader {
-  virtual ModuleLoadResult loadModule(SourceLocation ImportLoc, 
-                                      ModuleIdPath Path,
-                                      Module::NameVisibilityKind Visibility,
-                                      bool IsInclusionDirective) {
+  ModuleLoadResult loadModule(SourceLocation ImportLoc, 
+                              ModuleIdPath Path,
+                              Module::NameVisibilityKind Visibility,
+                              bool IsInclusionDirective) override {
     return ModuleLoadResult();
   }
 
-  virtual void makeModuleVisible(Module *Mod,
-                                 Module::NameVisibilityKind Visibility,
-                                 SourceLocation ImportLoc,
-                                 bool Complain) { }
+  void makeModuleVisible(Module *Mod,
+                         Module::NameVisibilityKind Visibility,
+                         SourceLocation ImportLoc,
+                         bool Complain) override { }
 
-  virtual GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc)
+  GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override
     { return 0; }
+  bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override
+    { return 0; };
 };
 
 TEST_F(PPConditionalDirectiveRecordTest, PPRecAPI) {