Switch the ModuleManager over to using a FileManager and FileEntry* as part of its lookup instead of the filename. This is a more correct unique identifier, as symlinks can be handled by the FileManager.

llvm-svn: 136363
This commit is contained in:
Jonathan D. Turner 2011-07-28 17:20:23 +00:00
parent b0e6899398
commit ecc2740b32
3 changed files with 26 additions and 9 deletions

View File

@ -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.

View File

@ -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(); }

View File

@ -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];