diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-10-05 00:22:33 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-10-05 00:22:33 +0000 |
commit | c7782d96c657eeb767bfea5117db49dc40e6356c (patch) | |
tree | baf78e80d2cbfacb521141025c0c03eaf2506bfd | |
parent | f03b888a12ccff7d54ddd8a79a0141cf23adbf67 (diff) |
[Modules] Introduce Module::TopHeaders which is a set of top-level headers
that are associated with a (sub)module.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165279 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/Module.h | 4 | ||||
-rw-r--r-- | include/clang/Serialization/ASTBitCodes.h | 10 | ||||
-rw-r--r-- | lib/Frontend/FrontendActions.cpp | 11 | ||||
-rw-r--r-- | lib/Lex/ModuleMap.cpp | 1 | ||||
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 18 | ||||
-rw-r--r-- | lib/Serialization/ASTWriter.cpp | 11 |
6 files changed, 47 insertions, 8 deletions
diff --git a/include/clang/Basic/Module.h b/include/clang/Basic/Module.h index cdf993cb4a..a53f87d7b7 100644 --- a/include/clang/Basic/Module.h +++ b/include/clang/Basic/Module.h @@ -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 diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h index 5f127d252f..57d896ee41 100644 --- a/include/clang/Serialization/ASTBitCodes.h +++ b/include/clang/Serialization/ASTBitCodes.h @@ -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. diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp index 24960cf6a0..f4ea5d3da0 100644 --- a/lib/Frontend/FrontendActions.cpp +++ b/lib/Frontend/FrontendActions.cpp @@ -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) diff --git a/lib/Lex/ModuleMap.cpp b/lib/Lex/ModuleMap.cpp index 5c9a9b4fef..a0caf03e77 100644 --- a/lib/Lex/ModuleMap.cpp +++ b/lib/Lex/ModuleMap.cpp @@ -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. diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 79173f50c5..ff418caf9e 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -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"); diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 59061792af..b8a0c28938 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -1952,6 +1952,11 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) { 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 unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(Abbrev); @@ -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()) { |