diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-01-04 23:32:19 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-01-04 23:32:19 +0000 |
commit | b7a7819473709c01ea024a2dc15e99d38f0f8760 (patch) | |
tree | 5fbbadeec73aba8aed448bfaf2f67401042d1b0d /lib/Basic/Module.cpp | |
parent | e5e42ae2694f2c4709dac3d84e3e6e5fac86c244 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147564 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/Module.cpp')
-rw-r--r-- | lib/Basic/Module.cpp | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/lib/Basic/Module.cpp b/lib/Basic/Module.cpp index feec5f0258..c5bc86de81 100644 --- a/lib/Basic/Module.cpp +++ b/lib/Basic/Module.cpp @@ -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); |