diff options
-rw-r--r-- | include/clang/Basic/FileManager.h | 3 | ||||
-rw-r--r-- | include/clang/Serialization/ASTReader.h | 9 | ||||
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 23 |
3 files changed, 26 insertions, 9 deletions
diff --git a/include/clang/Basic/FileManager.h b/include/clang/Basic/FileManager.h index bab05acba0..83fb4e0c5a 100644 --- a/include/clang/Basic/FileManager.h +++ b/include/clang/Basic/FileManager.h @@ -187,6 +187,9 @@ public: /// \param openFile if true and the file exists, it will be opened. const FileEntry *getFile(StringRef Filename, bool openFile = false); + /// \brief Returns the current file system options + const FileSystemOptions &getFileSystemOptions() { return FileSystemOpts; } + /// \brief Retrieve a file entry for a "virtual" file that acts as /// if there were a file with the given name on disk. The file /// itself is not accessed. diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 0113e6f98d..591369009c 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -24,6 +24,8 @@ #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/PreprocessingRecord.h" #include "clang/Basic/Diagnostic.h" +#include "clang/Basic/FileManager.h" +#include "clang/Basic/FileSystemOptions.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/SourceManager.h" #include "llvm/ADT/APFloat.h" @@ -395,7 +397,9 @@ class ModuleManager { SmallVector<Module*, 2> Chain; /// \brief All loaded modules, indexed by name. - llvm::StringMap<Module*> Modules; + llvm::DenseMap<const FileEntry *, Module *> Modules; + + FileManager FileMgr; public: typedef SmallVector<Module*, 2>::iterator ModuleIterator; @@ -403,6 +407,7 @@ public: typedef SmallVector<Module*, 2>::reverse_iterator ModuleReverseIterator; typedef std::pair<uint32_t, StringRef> ModuleOffset; + ModuleManager(const FileSystemOptions &FSO); ~ModuleManager(); /// \brief Forward iterator to traverse all loaded modules @@ -436,7 +441,7 @@ public: Module &operator[](unsigned Index) const { return *Chain[Index]; } /// \brief Returns the module associated with the given name - Module *lookup(StringRef Name) { return Modules.lookup(Name); } + Module *lookup(StringRef Name); /// \brief Number of modules loaded unsigned size() const { return Chain.size(); } diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index a0f8f68dfd..8e214a3bcf 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -5324,7 +5324,8 @@ ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), - Consumer(0), RelocatablePCH(false), isysroot(isysroot), + Consumer(0), ModuleMgr(FileMgr.getFileSystemOptions()), + RelocatablePCH(false), isysroot(isysroot), DisableValidation(DisableValidation), DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0), TotalNumSLocEntries(0), @@ -5343,7 +5344,8 @@ ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, Diagnostic &Diags, StringRef isysroot, bool DisableValidation, bool DisableStatCache) : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr), - Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0), + Diags(Diags), SemaObj(0), PP(0), Context(0), + Consumer(0), ModuleMgr(FileMgr.getFileSystemOptions()), RelocatablePCH(false), isysroot(isysroot), DisableValidation(DisableValidation), DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0), @@ -5403,6 +5405,11 @@ Module::~Module() { delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); } +Module *ModuleManager::lookup(StringRef Name) { + const FileEntry *Entry = FileMgr.getFile(Name); + return Modules[Entry]; +} + /// \brief Creates a new module and adds it to the list of known modules Module &ModuleManager::addModule(StringRef FileName, ModuleKind Type) { Module *Prev = !size() ? 0 : &getLastModule(); @@ -5411,7 +5418,8 @@ Module &ModuleManager::addModule(StringRef FileName, ModuleKind Type) { Current->FileName = FileName.str(); Chain.push_back(Current); - Modules[FileName.str()] = Current; + const FileEntry *Entry = FileMgr.getFile(FileName); + Modules[Entry] = Current; if (Prev) Prev->NextInSource = Current; @@ -5423,15 +5431,16 @@ Module &ModuleManager::addModule(StringRef FileName, ModuleKind Type) { /// \brief Exports the list of loaded modules with their corresponding names void ModuleManager::exportLookup(SmallVector<ModuleOffset, 16> &Target) { Target.reserve(size()); - for (llvm::StringMap<Module*>::const_iterator - I = Modules.begin(), E = Modules.end(); + for (ModuleConstIterator I = Chain.begin(), E = Chain.end(); I != E; ++I) { - Target.push_back(ModuleOffset(I->getValue()->SLocEntryBaseOffset, - I->getKey())); + Target.push_back(ModuleOffset((*I)->SLocEntryBaseOffset, + (*I)->FileName)); } std::sort(Target.begin(), Target.end()); } +ModuleManager::ModuleManager(const FileSystemOptions &FSO) : FileMgr(FSO) { } + ModuleManager::~ModuleManager() { for (unsigned i = 0, e = Chain.size(); i != e; ++i) delete Chain[e - i - 1]; |