[modules] If we see a #include that maps to a module, but use of precompiled modules is disabled, track submodule visibility anyway if -fmodules-local-submodule-visibility is enabled. This, in effect, gives modules semantics but without precompilation.

llvm-svn: 237550
This commit is contained in:
Richard Smith 2015-05-18 03:52:30 +00:00
parent effdb198c2
commit a0aafa3853
5 changed files with 27 additions and 28 deletions

View File

@ -479,9 +479,6 @@ public:
/// FileEntry, uniquing them through the 'HeaderMaps' datastructure.
const HeaderMap *CreateHeaderMap(const FileEntry *FE);
/// Returns true if modules are enabled.
bool enabledModules() const { return LangOpts.Modules; }
/// \brief Retrieve the name of the module file that should be used to
/// load the given module.
///

View File

@ -595,7 +595,13 @@ const FileEntry *HeaderSearch::LookupFile(
RelativePath->append(Filename.begin(), Filename.end());
}
// Otherwise, just return the file.
return FileMgr.getFile(Filename, /*openFile=*/true);
const FileEntry *File = FileMgr.getFile(Filename, /*openFile=*/true);
if (File && SuggestedModule) {
// If there is a module that corresponds to this header, suggest it.
hasModuleMap(Filename, File->getDir(), /*SystemHeaderDir*/false);
*SuggestedModule = findModuleForHeader(File);
}
return File;
}
// This is the header that MSVC's header search would have found.
@ -1070,7 +1076,7 @@ StringRef HeaderSearch::getUniqueFrameworkName(StringRef Framework) {
bool HeaderSearch::hasModuleMap(StringRef FileName,
const DirectoryEntry *Root,
bool IsSystem) {
if (!enabledModules() || !LangOpts.ModulesImplicitMaps)
if (!HSOpts->ModuleMaps || !LangOpts.ModulesImplicitMaps)
return false;
SmallVector<const DirectoryEntry *, 2> FixUpDirectories;

View File

@ -1762,13 +1762,12 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
Callbacks->FileSkipped(*File, FilenameTok, FileCharacter);
// If this is a module import, make it visible if needed.
if (IsModuleImport) {
makeModuleVisible(SuggestedModule.getModule(), HashLoc);
if (auto *M = SuggestedModule.getModule()) {
makeModuleVisible(M, HashLoc);
if (IncludeTok.getIdentifierInfo()->getPPKeywordID() !=
tok::pp___include_macros)
EnterAnnotationToken(*this, HashLoc, End, tok::annot_module_include,
SuggestedModule.getModule());
EnterAnnotationToken(*this, HashLoc, End, tok::annot_module_include, M);
}
return;
}
@ -1782,31 +1781,27 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
FileID FID = SourceMgr.createFileID(File, IncludePos, FileCharacter);
assert(!FID.isInvalid() && "Expected valid file ID");
// Determine if we're switching to building a new submodule, and which one.
//
// FIXME: If we've already processed this header, just make it visible rather
// than entering it again.
ModuleMap::KnownHeader BuildingModule;
if (getLangOpts().Modules && !getLangOpts().CurrentModule.empty()) {
Module *RequestingModule = getModuleForLocation(FilenameLoc);
BuildingModule =
HeaderInfo.getModuleMap().findModuleForHeader(File, RequestingModule);
}
// If all is good, enter the new file!
if (EnterSourceFile(FID, CurDir, FilenameTok.getLocation()))
return;
// If we're walking into another part of the same module, let the parser
// know that any future declarations are within that other submodule.
if (BuildingModule) {
// Determine if we're switching to building a new submodule, and which one.
//
// FIXME: If we've already processed this header, just make it visible rather
// than entering it again.
if (auto *M = SuggestedModule.getModule()) {
assert(!CurSubmodule && "should not have marked this as a module yet");
CurSubmodule = BuildingModule.getModule();
CurSubmodule = M;
EnterSubmodule(CurSubmodule, HashLoc);
// Let the macro handling code know that any future macros are within
// the new submodule.
EnterSubmodule(M, HashLoc);
EnterAnnotationToken(*this, HashLoc, End, tok::annot_module_begin,
CurSubmodule);
// Let the parser know that any future declarations are within the new
// submodule.
// FIXME: There's no point doing this if we're handling a #__include_macros
// directive.
EnterAnnotationToken(*this, HashLoc, End, tok::annot_module_begin, M);
}
}

View File

@ -1,5 +1,5 @@
// RUN: rm -rf %t
// RUN: %clang -fsyntax-only -isystem %S/Inputs/System/usr/include -ffreestanding -fmodules -fmodules-cache-path=%t -D__need_wint_t -Werror=implicit-function-declaration %s
// RUN: %clang_cc1 -fsyntax-only -isystem %S/Inputs/System/usr/include -ffreestanding -fmodules -fmodules-cache-path=%t -D__need_wint_t -Werror=implicit-function-declaration %s
@import uses_other_constants;
const double other_value = DBL_MAX;

View File

@ -2,6 +2,7 @@
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/submodule-visibility -verify %s -DALLOW_NAME_LEAKAGE
// RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fmodules-cache-path=%t -I%S/Inputs/submodule-visibility -verify %s -DIMPORT
// RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fmodules-cache-path=%t -fmodule-name=x -I%S/Inputs/submodule-visibility -verify %s
// RUN: %clang_cc1 -fmodule-maps -fmodules-local-submodule-visibility -fmodules-cache-path=%t -I%S/Inputs/submodule-visibility -verify %s
#include "a.h"
#include "b.h"