diff options
author | Douglas Gregor <dgregor@apple.com> | 2013-01-12 01:29:50 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2013-01-12 01:29:50 +0000 |
commit | ca2ab45341c448284cf93770018c717810575f86 (patch) | |
tree | f8434f1e91f4069e6bf65e51883e62bb34d8a86c /lib | |
parent | 7d37b8bb101c872801e6d2ce82eec377a94ce042 (diff) |
Provide Decl::getOwningModule(), which determines the (sub)module in
which a particular declaration resides. Use this information to
customize the "definition of 'blah' must be imported from another
module" diagnostic with the module the user actually has to
import. Additionally, recover by importing that module, so we don't
complain about other names in that module.
Still TODO: coming up with decent Fix-Its for these cases, and expand
this recovery approach for other name lookup failures.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172290 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/DeclBase.cpp | 5 | ||||
-rw-r--r-- | lib/Frontend/CompilerInstance.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 12 | ||||
-rw-r--r-- | lib/Sema/SemaType.cpp | 11 | ||||
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 6 |
5 files changed, 36 insertions, 4 deletions
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index 5dccaac020..d8b63611fd 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -59,6 +59,11 @@ void *Decl::AllocateDeserializedDecl(const ASTContext &Context, return Result; } +Module *Decl::getOwningModuleSlow() const { + assert(isFromASTFile() && "Not from AST file?"); + return getASTContext().getExternalSource()->getModule(getOwningModuleID()); +} + const char *Decl::getDeclKindName() const { switch (DeclKind) { default: llvm_unreachable("Declaration not in DeclNodes.inc!"); diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index f31301c6e9..5b2be91967 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -1201,3 +1201,9 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, LastModuleImportResult = ModuleLoadResult(Module, false); return LastModuleImportResult; } + +void CompilerInstance::makeModuleVisible(Module *Mod, + Module::NameVisibilityKind Visibility){ + ModuleManager->makeModuleVisible(Mod, Visibility); +} + diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 0cf1238220..c3a2ad1123 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -11173,6 +11173,18 @@ DeclResult Sema::ActOnModuleImport(SourceLocation AtLoc, return Import; } +void Sema::createImplicitModuleImport(SourceLocation Loc, Module *Mod) { + // Create the implicit import declaration. + TranslationUnitDecl *TU = getASTContext().getTranslationUnitDecl(); + ImportDecl *ImportD = ImportDecl::CreateImplicit(getASTContext(), TU, + Loc, Mod, Loc); + TU->addDecl(ImportD); + Consumer.HandleImplicitImportDecl(ImportD); + + // Make the module visible. + PP.getModuleLoader().makeModuleVisible(Mod, Module::AllVisible); +} + void Sema::ActOnPragmaRedefineExtname(IdentifierInfo* Name, IdentifierInfo* AliasName, SourceLocation PragmaLoc, diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 60db55aff3..59c1dea8ff 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -4392,9 +4392,14 @@ bool Sema::RequireCompleteType(SourceLocation Loc, QualType T, // repeating the diagnostic. // FIXME: Add a Fix-It that imports the corresponding module or includes // the header. - if (isSFINAEContext() || HiddenDefinitions.insert(Def)) { - Diag(Loc, diag::err_module_private_definition) << T; - Diag(Def->getLocation(), diag::note_previous_definition); + Module *Owner = Def->getOwningModule(); + Diag(Loc, diag::err_module_private_definition) + << T << Owner->getFullModuleName(); + Diag(Def->getLocation(), diag::note_previous_definition); + + if (!isSFINAEContext()) { + // Recover by implicitly importing this module. + createImplicitModuleImport(Loc, Owner); } } diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index a4436d1671..986eee1c95 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -6200,7 +6200,11 @@ Module *ASTReader::getSubmodule(SubmoduleID GlobalID) { return SubmodulesLoaded[GlobalID - NUM_PREDEF_SUBMODULE_IDS]; } - + +Module *ASTReader::getModule(unsigned ID) { + return getSubmodule(ID); +} + Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) { return DecodeSelector(getGlobalSelectorID(M, LocalID)); } |