From 86bb94f55565c8f7a86b4076318ec837741d6212 Mon Sep 17 00:00:00 2001 From: John Thompson Date: Wed, 23 Apr 2014 19:04:32 +0000 Subject: [PATCH] Quick fix for layering that broke shared library build. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207011 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Frontend/ASTUnit.h | 4 ++- include/clang/Frontend/CompilerInstance.h | 4 ++- include/clang/Lex/ModuleLoader.h | 9 ++++- lib/Frontend/CompilerInstance.cpp | 26 ++++++++++++++ lib/Sema/SemaLookup.cpp | 34 ++++--------------- unittests/Basic/SourceManagerTest.cpp | 20 ++++++----- unittests/Lex/LexerTest.cpp | 20 ++++++----- unittests/Lex/PPCallbacksTest.cpp | 20 ++++++----- .../Lex/PPConditionalDirectiveRecordTest.cpp | 20 ++++++----- 9 files changed, 91 insertions(+), 66 deletions(-) diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index 666e5dd7c7..b730cb9da7 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -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 diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h index 1a89a8a156..a7368bd149 100644 --- a/include/clang/Frontend/CompilerInstance.h +++ b/include/clang/Frontend/CompilerInstance.h @@ -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 diff --git a/include/clang/Lex/ModuleLoader.h b/include/clang/Lex/ModuleLoader.h index 0a690812a9..7869799c2c 100644 --- a/include/clang/Lex/ModuleLoader.h +++ b/include/clang/Lex/ModuleLoader.h @@ -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; }; diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 79b96ab689..b74c288cda 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -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; +} diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index c0d49a7dd9..e8ef5ac6b9 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -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); } } diff --git a/unittests/Basic/SourceManagerTest.cpp b/unittests/Basic/SourceManagerTest.cpp index b3796c34fe..88c3fb76ca 100644 --- a/unittests/Basic/SourceManagerTest.cpp +++ b/unittests/Basic/SourceManagerTest.cpp @@ -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) { diff --git a/unittests/Lex/LexerTest.cpp b/unittests/Lex/LexerTest.cpp index 8aa95c966a..0faad45983 100644 --- a/unittests/Lex/LexerTest.cpp +++ b/unittests/Lex/LexerTest.cpp @@ -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. diff --git a/unittests/Lex/PPCallbacksTest.cpp b/unittests/Lex/PPCallbacksTest.cpp index 3c953c2091..bdc026a223 100644 --- a/unittests/Lex/PPCallbacksTest.cpp +++ b/unittests/Lex/PPCallbacksTest.cpp @@ -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. diff --git a/unittests/Lex/PPConditionalDirectiveRecordTest.cpp b/unittests/Lex/PPConditionalDirectiveRecordTest.cpp index 4e22589069..bacc899bec 100644 --- a/unittests/Lex/PPConditionalDirectiveRecordTest.cpp +++ b/unittests/Lex/PPConditionalDirectiveRecordTest.cpp @@ -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) { -- 2.40.0