diff options
author | Jonathan D. Turner <jonathan.d.turner@gmail.com> | 2011-07-26 18:21:30 +0000 |
---|---|---|
committer | Jonathan D. Turner <jonathan.d.turner@gmail.com> | 2011-07-26 18:21:30 +0000 |
commit | b2b0823d002e541b4364409f8fd488daf7d5bf0b (patch) | |
tree | 921cbf32dd5f72543aac668bbabfb5deaf78bf55 /clang/lib/Serialization/ASTReader.cpp | |
parent | 613958c82c09f550797631b558e50d191cdbfe7d (diff) | |
download | bcm5719-llvm-b2b0823d002e541b4364409f8fd488daf7d5bf0b.tar.gz bcm5719-llvm-b2b0823d002e541b4364409f8fd488daf7d5bf0b.zip |
This patch extends the previous patch by starting to incorporate more functionality, like lookup-by-name and exporting lookup tables, into the module manager. Methods now have documentation. A few more functions have been switched over to the new iterator style and away from manual/explicit iteration. Ultimately we want to move away from name lookup here, as symlinks make filenames not a safe unique value, but we use it here as a stopgap before better measures are in place (namely instead using FileEntry* from a global FileManager).
llvm-svn: 136107
Diffstat (limited to 'clang/lib/Serialization/ASTReader.cpp')
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 14ba59c1e04..3994fe6b7b1 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -2223,7 +2223,7 @@ ASTReader::ReadASTBlock(Module &F) { uint32_t Offset = io::ReadUnalignedLE32(Data); uint16_t Len = io::ReadUnalignedLE16(Data); StringRef Name = StringRef((const char*)Data, Len); - Module *OM = Modules.lookup(Name); + Module *OM = ModuleMgr.lookup(Name); if (!OM) { Error("SourceLocation remap refers to unknown module"); return Failure; @@ -2236,7 +2236,6 @@ ASTReader::ReadASTBlock(Module &F) { break; } - case SOURCE_MANAGER_LINE_TABLE: if (ParseLineTable(F, Record)) return Failure; @@ -2637,19 +2636,7 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, ASTReader::ASTReadResult ASTReader::ReadASTCore(StringRef FileName, ModuleKind Type) { - Module *Prev = !ModuleMgr.size() ? 0 : &ModuleMgr.getLastModule(); - ModuleMgr.addModule(Type); - Module &F = ModuleMgr.getLastModule(); - if (Prev) - Prev->NextInSource = &F; - else - FirstInSource = &F; - F.Loaders.push_back(Prev); - - Modules[FileName.str()] = &F; - - // Set the AST file name. - F.FileName = FileName; + Module &F = ModuleMgr.addModule(FileName, Type); if (FileName != "-") { CurrentDir = llvm::sys::path::parent_path(FileName); @@ -4388,7 +4375,7 @@ void ASTReader::InitializeSema(Sema &S) { SemaObj->StdBadAlloc = SemaDeclRefs[1]; } - for (Module *F = FirstInSource; F; F = F->NextInSource) { + for (Module *F = &ModuleMgr.getPrimaryModule(); F; F = F->NextInSource) { // If there are @selector references added them to its pool. This is for // implementation of -Wselector. @@ -5275,7 +5262,7 @@ 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), FirstInSource(0), RelocatablePCH(false), isysroot(isysroot), + Consumer(0), RelocatablePCH(false), isysroot(isysroot), DisableValidation(DisableValidation), DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0), TotalNumSLocEntries(0), @@ -5294,7 +5281,7 @@ 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), FirstInSource(0), + Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0), RelocatablePCH(false), isysroot(isysroot), DisableValidation(DisableValidation), DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0), @@ -5352,3 +5339,37 @@ Module::~Module() { delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable); delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); } + +/// \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(); + Module *Current = new Module(Type); + + Current->FileName = FileName.str(); + + Chain.push_back(Current); + Modules[FileName.str()] = Current; + + if (Prev) + Prev->NextInSource = Current; + Current->Loaders.push_back(Prev); + + return *Current; +} + +/// \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(); + I != E; ++I) { + Target.push_back(ModuleOffset(I->getValue()->SLocEntryBaseOffset, + I->getKey())); + } + std::sort(Target.begin(), Target.end()); +} + +ModuleManager::~ModuleManager() { + for (unsigned i = 0, e = Chain.size(); i != e; ++i) + delete Chain[e - i - 1]; +} |