diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2017-01-28 22:15:22 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2017-01-28 22:15:22 +0000 |
commit | 96a06e0ec059330a18adc34531b6cc8125edf459 (patch) | |
tree | 9ad0e180a5dd67846814a3efc0b04c92afcbac4f /clang/lib/Serialization/ModuleManager.cpp | |
parent | 14afc8e7b83e643ed56580d8e935f77a7a6ae52c (diff) | |
download | llvm-96a06e0ec059330a18adc34531b6cc8125edf459.zip llvm-96a06e0ec059330a18adc34531b6cc8125edf459.tar.gz llvm-96a06e0ec059330a18adc34531b6cc8125edf459.tar.bz2 |
Modules: Return ModuleFile& from ModuleManager::begin, etc.; NFC
Hide the pointer indirection in ModuleManager::begin, ModuleManager::end,
ModuleManager::rbegin, and ModuleManager::rend. Besides tidying up the call
sites, this is preparation for making ownership of ModuleFile explicit.
llvm-svn: 293394
Diffstat (limited to 'clang/lib/Serialization/ModuleManager.cpp')
-rw-r--r-- | clang/lib/Serialization/ModuleManager.cpp | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp index c0f59d4..730b6fd 100644 --- a/clang/lib/Serialization/ModuleManager.cpp +++ b/clang/lib/Serialization/ModuleManager.cpp @@ -195,7 +195,9 @@ void ModuleManager::removeModules( VisitOrder.clear(); // Collect the set of module file pointers that we'll be removing. - llvm::SmallPtrSet<ModuleFile *, 4> victimSet(first, last); + llvm::SmallPtrSet<ModuleFile *, 4> victimSet( + (llvm::pointer_iterator<ModuleIterator>(first)), + (llvm::pointer_iterator<ModuleIterator>(last))); auto IsVictim = [&](ModuleFile *MF) { return victimSet.count(MF); @@ -209,8 +211,8 @@ void ModuleManager::removeModules( // Remove the modules from the PCH chain. for (auto I = first; I != last; ++I) { - if (!(*I)->isModule()) { - PCHChain.erase(std::find(PCHChain.begin(), PCHChain.end(), *I), + if (!I->isModule()) { + PCHChain.erase(std::find(PCHChain.begin(), PCHChain.end(), &*I), PCHChain.end()); break; } @@ -218,10 +220,10 @@ void ModuleManager::removeModules( // Delete the modules and erase them from the various structures. for (ModuleIterator victim = first; victim != last; ++victim) { - Modules.erase((*victim)->File); + Modules.erase(victim->File); if (modMap) { - StringRef ModuleName = (*victim)->ModuleName; + StringRef ModuleName = victim->ModuleName; if (Module *mod = modMap->findModule(ModuleName)) { mod->setASTFile(nullptr); } @@ -230,14 +232,15 @@ void ModuleManager::removeModules( // Files that didn't make it through ReadASTCore successfully will be // rebuilt (or there was an error). Invalidate them so that we can load the // new files that will be renamed over the old ones. - if (LoadedSuccessfully.count(*victim) == 0) - FileMgr.invalidateCache((*victim)->File); + if (LoadedSuccessfully.count(&*victim) == 0) + FileMgr.invalidateCache(victim->File); - delete *victim; + delete &*victim; } // Remove the modules from the chain. - Chain.erase(first, last); + Chain.erase(Chain.begin() + (first - begin()), + Chain.begin() + (last - begin())); } void @@ -317,11 +320,11 @@ void ModuleManager::visit(llvm::function_ref<bool(ModuleFile &M)> Visitor, Queue.reserve(N); llvm::SmallVector<unsigned, 4> UnusedIncomingEdges; UnusedIncomingEdges.resize(size()); - for (ModuleFile *M : llvm::reverse(*this)) { - unsigned Size = M->ImportedBy.size(); - UnusedIncomingEdges[M->Index] = Size; + for (ModuleFile &M : llvm::reverse(*this)) { + unsigned Size = M.ImportedBy.size(); + UnusedIncomingEdges[M.Index] = Size; if (!Size) - Queue.push_back(M); + Queue.push_back(&M); } // Traverse the graph, making sure to visit a module before visiting any @@ -436,7 +439,7 @@ namespace llvm { struct GraphTraits<ModuleManager> { typedef ModuleFile *NodeRef; typedef llvm::SetVector<ModuleFile *>::const_iterator ChildIteratorType; - typedef ModuleManager::ModuleConstIterator nodes_iterator; + typedef pointer_iterator<ModuleManager::ModuleConstIterator> nodes_iterator; static ChildIteratorType child_begin(NodeRef Node) { return Node->Imports.begin(); @@ -447,11 +450,11 @@ namespace llvm { } static nodes_iterator nodes_begin(const ModuleManager &Manager) { - return Manager.begin(); + return nodes_iterator(Manager.begin()); } static nodes_iterator nodes_end(const ModuleManager &Manager) { - return Manager.end(); + return nodes_iterator(Manager.end()); } }; |