From: Richard Smith Date: Fri, 1 Nov 2013 02:19:14 +0000 (+0000) Subject: Simplify computation of visible module set. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8b1ab400d40b96f4634eb0c29986218c2905fda4;p=clang Simplify computation of visible module set. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193850 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/Module.h b/include/clang/Basic/Module.h index 3d8b75b471..e8d774e1eb 100644 --- a/include/clang/Basic/Module.h +++ b/include/clang/Basic/Module.h @@ -403,10 +403,10 @@ public: submodule_iterator submodule_end() { return SubModules.end(); } submodule_const_iterator submodule_end() const { return SubModules.end(); } - /// \brief Returns the exported modules based on the wildcard restrictions. + /// \brief Appends this module's list of exported modules to \p Exported. /// - /// This returns a subset of immediately imported modules (the ones that are - /// exported), not the complete set of exported modules. + /// This provides a subset of immediately imported modules (the ones that are + /// directly exported), not the complete set of exported modules. void getExportedModules(SmallVectorImpl &Exported) const; static StringRef getModuleInputBufferName() { diff --git a/lib/Basic/Module.cpp b/lib/Basic/Module.cpp index ccf7077d6f..4818e8d173 100644 --- a/lib/Basic/Module.cpp +++ b/lib/Basic/Module.cpp @@ -253,22 +253,13 @@ void Module::buildVisibleModulesCache() const { VisibleModulesCache.insert(this); // Every imported module is visible. - // Every module exported by an imported module is visible. - llvm::SmallPtrSet Visited; - llvm::SmallVector Exports; - SmallVector Stack(Imports.begin(), Imports.end()); + SmallVector Stack(Imports.begin(), Imports.end()); while (!Stack.empty()) { Module *CurrModule = Stack.pop_back_val(); - VisibleModulesCache.insert(CurrModule); - - CurrModule->getExportedModules(Exports); - for (SmallVectorImpl::iterator I = Exports.begin(), - E = Exports.end(); - I != E; ++I) { - Module *Exported = *I; - if (Visited.insert(Exported)) - Stack.push_back(Exported); - } + + // Every module transitively exported by an imported module is visible. + if (VisibleModulesCache.insert(CurrModule).second) + CurrModule->getExportedModules(Stack); } }