[cfe-commits] r136363 - in /cfe/trunk: include/clang/Basic/FileManager.h include/clang/Serialization/ASTReader.h lib/Serialization/ASTReader.cpp
Jonathan D. Turner
jonathan.d.turner at gmail.com
Thu Jul 28 10:20:23 PDT 2011
Author: jonturner
Date: Thu Jul 28 12:20:23 2011
New Revision: 136363
URL: http://llvm.org/viewvc/llvm-project?rev=136363&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Basic/FileManager.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/lib/Serialization/ASTReader.cpp
Modified: cfe/trunk/include/clang/Basic/FileManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=136363&r1=136362&r2=136363&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/trunk/include/clang/Basic/FileManager.h Thu Jul 28 12:20:23 2011
@@ -187,6 +187,9 @@
/// \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.
Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=136363&r1=136362&r2=136363&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Thu Jul 28 12:20:23 2011
@@ -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 @@
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 @@
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 @@
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(); }
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=136363&r1=136362&r2=136363&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu Jul 28 12:20:23 2011
@@ -5324,7 +5324,8 @@
: 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 @@
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 @@
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 @@
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 @@
/// \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];
More information about the cfe-commits
mailing list