forked from OSchip/llvm-project
[Modules] Introduce Module::TopHeaders which is a set of top-level headers
that are associated with a (sub)module. llvm-svn: 165279
This commit is contained in:
parent
abc721ab4d
commit
c597c8c48b
|
@ -21,6 +21,7 @@
|
|||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/ADT/SetVector.h"
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
@ -72,6 +73,9 @@ public:
|
|||
/// \brief The headers that are part of this module.
|
||||
llvm::SmallVector<const FileEntry *, 2> Headers;
|
||||
|
||||
/// \brief The top-level headers associated with this module.
|
||||
llvm::SmallSetVector<const FileEntry *, 2> TopHeaders;
|
||||
|
||||
/// \brief The set of language features required to use this module.
|
||||
///
|
||||
/// If any of these features is not present, the \c IsAvailable bit
|
||||
|
|
|
@ -537,16 +537,18 @@ namespace clang {
|
|||
SUBMODULE_UMBRELLA_HEADER = 2,
|
||||
/// \brief Specifies a header that falls into this (sub)module.
|
||||
SUBMODULE_HEADER = 3,
|
||||
/// \brief Specifies a top-level header that falls into this (sub)module.
|
||||
SUBMODULE_TOPHEADER = 4,
|
||||
/// \brief Specifies an umbrella directory.
|
||||
SUBMODULE_UMBRELLA_DIR = 4,
|
||||
SUBMODULE_UMBRELLA_DIR = 5,
|
||||
/// \brief Specifies the submodules that are imported by this
|
||||
/// submodule.
|
||||
SUBMODULE_IMPORTS = 5,
|
||||
SUBMODULE_IMPORTS = 6,
|
||||
/// \brief Specifies the submodules that are re-exported from this
|
||||
/// submodule.
|
||||
SUBMODULE_EXPORTS = 6,
|
||||
SUBMODULE_EXPORTS = 7,
|
||||
/// \brief Specifies a required feature.
|
||||
SUBMODULE_REQUIRES = 7
|
||||
SUBMODULE_REQUIRES = 8
|
||||
};
|
||||
|
||||
/// \brief Record types used within a comments block.
|
||||
|
|
|
@ -132,7 +132,7 @@ ASTConsumer *GenerateModuleAction::CreateASTConsumer(CompilerInstance &CI,
|
|||
}
|
||||
|
||||
/// \brief Collect the set of header includes needed to construct the given
|
||||
/// module.
|
||||
/// module and update the TopHeaders file set of the module.
|
||||
///
|
||||
/// \param Module The module we're collecting includes from.
|
||||
///
|
||||
|
@ -149,15 +149,18 @@ static void collectModuleHeaderIncludes(const LangOptions &LangOpts,
|
|||
|
||||
// Add includes for each of these headers.
|
||||
for (unsigned I = 0, N = Module->Headers.size(); I != N; ++I) {
|
||||
const FileEntry *Header = Module->Headers[I];
|
||||
Module->TopHeaders.insert(Header);
|
||||
if (LangOpts.ObjC1)
|
||||
Includes += "#import \"";
|
||||
else
|
||||
Includes += "#include \"";
|
||||
Includes += Module->Headers[I]->getName();
|
||||
Includes += Header->getName();
|
||||
Includes += "\"\n";
|
||||
}
|
||||
|
||||
if (const FileEntry *UmbrellaHeader = Module->getUmbrellaHeader()) {
|
||||
Module->TopHeaders.insert(UmbrellaHeader);
|
||||
if (Module->Parent) {
|
||||
// Include the umbrella header for submodules.
|
||||
if (LangOpts.ObjC1)
|
||||
|
@ -184,9 +187,11 @@ static void collectModuleHeaderIncludes(const LangOptions &LangOpts,
|
|||
|
||||
// If this header is marked 'unavailable' in this module, don't include
|
||||
// it.
|
||||
if (const FileEntry *Header = FileMgr.getFile(Dir->path()))
|
||||
if (const FileEntry *Header = FileMgr.getFile(Dir->path())) {
|
||||
if (ModMap.isHeaderInUnavailableModule(Header))
|
||||
continue;
|
||||
Module->TopHeaders.insert(Header);
|
||||
}
|
||||
|
||||
// Include this header umbrella header for submodules.
|
||||
if (LangOpts.ObjC1)
|
||||
|
|
|
@ -152,6 +152,7 @@ Module *ModuleMap::findModuleForHeader(const FileEntry *File) {
|
|||
StringRef Name = llvm::sys::path::stem(File->getName());
|
||||
Result = findOrCreateModule(Name, Result, /*IsFramework=*/false,
|
||||
Explicit).first;
|
||||
Result->TopHeaders.insert(File);
|
||||
|
||||
// If inferred submodules export everything they import, add a
|
||||
// wildcard to the set of exports.
|
||||
|
|
|
@ -3230,7 +3230,23 @@ ASTReader::ASTReadResult ASTReader::ReadSubmoduleBlock(ModuleFile &F) {
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case SUBMODULE_TOPHEADER: {
|
||||
if (First) {
|
||||
Error("missing submodule metadata record at beginning of block");
|
||||
return Failure;
|
||||
}
|
||||
|
||||
if (!CurrentModule)
|
||||
break;
|
||||
|
||||
// FIXME: Be more lazy about this!
|
||||
StringRef FileName(BlobStart, BlobLen);
|
||||
if (const FileEntry *File = PP.getFileManager().getFile(FileName))
|
||||
CurrentModule->TopHeaders.insert(File);
|
||||
break;
|
||||
}
|
||||
|
||||
case SUBMODULE_UMBRELLA_DIR: {
|
||||
if (First) {
|
||||
Error("missing submodule metadata record at beginning of block");
|
||||
|
|
|
@ -1951,6 +1951,11 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) {
|
|||
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
|
||||
unsigned HeaderAbbrev = Stream.EmitAbbrev(Abbrev);
|
||||
|
||||
Abbrev = new BitCodeAbbrev();
|
||||
Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TOPHEADER));
|
||||
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
|
||||
unsigned TopHeaderAbbrev = Stream.EmitAbbrev(Abbrev);
|
||||
|
||||
Abbrev = new BitCodeAbbrev();
|
||||
Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR));
|
||||
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name
|
||||
|
@ -2022,6 +2027,12 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) {
|
|||
Stream.EmitRecordWithBlob(HeaderAbbrev, Record,
|
||||
Mod->Headers[I]->getName());
|
||||
}
|
||||
for (unsigned I = 0, N = Mod->TopHeaders.size(); I != N; ++I) {
|
||||
Record.clear();
|
||||
Record.push_back(SUBMODULE_TOPHEADER);
|
||||
Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record,
|
||||
Mod->TopHeaders[I]->getName());
|
||||
}
|
||||
|
||||
// Emit the imports.
|
||||
if (!Mod->Imports.empty()) {
|
||||
|
|
Loading…
Reference in New Issue