Store the submodules of a module in source order, as they are stored

in the module map. This provides a bit more predictability for the
user, as well as eliminating the need to sort the submodules when
serializing them.

llvm-svn: 147564
This commit is contained in:
Douglas Gregor
2012-01-04 23:32:19 +00:00
parent f716839580
commit eb90e83085
8 changed files with 96 additions and 84 deletions

View File

@@ -20,11 +20,27 @@
#include "llvm/ADT/StringSwitch.h"
using namespace clang;
Module::Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent,
bool IsFramework, bool IsExplicit)
: Name(Name), DefinitionLoc(DefinitionLoc), Parent(Parent),
Umbrella(), IsAvailable(true), IsFromModuleFile(false),
IsFramework(IsFramework), IsExplicit(IsExplicit), InferSubmodules(false),
InferExplicitSubmodules(false), InferExportWildcard(false),
NameVisibility(Hidden)
{
if (Parent) {
if (!Parent->isAvailable())
IsAvailable = false;
Parent->SubModuleIndex[Name] = Parent->SubModules.size();
Parent->SubModules.push_back(this);
}
}
Module::~Module() {
for (llvm::StringMap<Module *>::iterator I = SubModules.begin(),
IEnd = SubModules.end();
for (submodule_iterator I = submodule_begin(), IEnd = submodule_end();
I != IEnd; ++I) {
delete I->getValue();
delete *I;
}
}
@@ -126,15 +142,23 @@ void Module::addRequirement(StringRef Feature, const LangOptions &LangOpts) {
continue;
Current->IsAvailable = false;
for (llvm::StringMap<Module *>::iterator Sub = Current->SubModules.begin(),
SubEnd = Current->SubModules.end();
for (submodule_iterator Sub = Current->submodule_begin(),
SubEnd = Current->submodule_end();
Sub != SubEnd; ++Sub) {
if (Sub->second->IsAvailable)
Stack.push_back(Sub->second);
if ((*Sub)->IsAvailable)
Stack.push_back(*Sub);
}
}
}
Module *Module::findSubmodule(StringRef Name) const {
llvm::StringMap<unsigned>::const_iterator Pos = SubModuleIndex.find(Name);
if (Pos == SubModuleIndex.end())
return 0;
return SubModules[Pos->getValue()];
}
static void printModuleId(llvm::raw_ostream &OS, const ModuleId &Id) {
for (unsigned I = 0, N = Id.size(); I != N; ++I) {
if (I)
@@ -181,10 +205,9 @@ void Module::print(llvm::raw_ostream &OS, unsigned Indent) const {
OS << "\"\n";
}
for (llvm::StringMap<Module *>::const_iterator MI = SubModules.begin(),
MIEnd = SubModules.end();
for (submodule_const_iterator MI = submodule_begin(), MIEnd = submodule_end();
MI != MIEnd; ++MI)
MI->getValue()->print(OS, Indent + 2);
(*MI)->print(OS, Indent + 2);
for (unsigned I = 0, N = Exports.size(); I != N; ++I) {
OS.indent(Indent + 2);