aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/ModuleMap.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2012-01-04 23:32:19 +0000
committerDouglas Gregor <dgregor@apple.com>2012-01-04 23:32:19 +0000
commitb7a7819473709c01ea024a2dc15e99d38f0f8760 (patch)
tree5fbbadeec73aba8aed448bfaf2f67401042d1b0d /lib/Lex/ModuleMap.cpp
parente5e42ae2694f2c4709dac3d84e3e6e5fac86c244 (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/Lex/ModuleMap.cpp')
-rw-r--r--lib/Lex/ModuleMap.cpp36
1 files changed, 11 insertions, 25 deletions
diff --git a/lib/Lex/ModuleMap.cpp b/lib/Lex/ModuleMap.cpp
index f43abc8615..42257f5624 100644
--- a/lib/Lex/ModuleMap.cpp
+++ b/lib/Lex/ModuleMap.cpp
@@ -263,26 +263,20 @@ Module *ModuleMap::lookupModuleQualified(StringRef Name, Module *Context) {
if (!Context)
return findModule(Name);
- llvm::StringMap<Module *>::iterator Sub = Context->SubModules.find(Name);
- if (Sub != Context->SubModules.end())
- return Sub->getValue();
-
- return 0;
+ return Context->findSubmodule(Name);
}
std::pair<Module *, bool>
ModuleMap::findOrCreateModule(StringRef Name, Module *Parent, bool IsFramework,
bool IsExplicit) {
// Try to find an existing module with this name.
- if (Module *Found = Parent? Parent->SubModules[Name] : Modules[Name])
- return std::make_pair(Found, false);
+ if (Module *Sub = lookupModuleQualified(Name, Parent))
+ return std::make_pair(Sub, false);
// Create a new module with this name.
Module *Result = new Module(Name, SourceLocation(), Parent, IsFramework,
IsExplicit);
- if (Parent)
- Parent->SubModules[Name] = Result;
- else
+ if (!Parent)
Modules[Name] = Result;
return std::make_pair(Result, true);
}
@@ -311,12 +305,9 @@ ModuleMap::inferFrameworkModule(StringRef ModuleName,
Module *Result = new Module(ModuleName, SourceLocation(), Parent,
/*IsFramework=*/true, /*IsExplicit=*/false);
-
- if (Parent)
- Parent->SubModules[ModuleName] = Result;
- else
+ if (!Parent)
Modules[ModuleName] = Result;
-
+
// umbrella header "umbrella-header-name"
Result->Umbrella = UmbrellaHeader;
Headers[UmbrellaHeader] = Result;
@@ -798,15 +789,10 @@ void ModuleMapParser::parseModuleDecl() {
SourceLocation LBraceLoc = consumeToken();
// Determine whether this (sub)module has already been defined.
- llvm::StringMap<Module *> &ModuleSpace
- = ActiveModule? ActiveModule->SubModules : Map.Modules;
- llvm::StringMap<Module *>::iterator ExistingModule
- = ModuleSpace.find(ModuleName);
- if (ExistingModule != ModuleSpace.end()) {
+ if (Module *Existing = Map.lookupModuleQualified(ModuleName, ActiveModule)) {
Diags.Report(ModuleNameLoc, diag::err_mmap_module_redefinition)
<< ModuleName;
- Diags.Report(ExistingModule->getValue()->DefinitionLoc,
- diag::note_mmap_prev_definition);
+ Diags.Report(Existing->DefinitionLoc, diag::note_mmap_prev_definition);
// Skip the module definition.
skipUntil(MMToken::RBrace);
@@ -818,9 +804,9 @@ void ModuleMapParser::parseModuleDecl() {
}
// Start defining this module.
- ActiveModule = new Module(ModuleName, ModuleNameLoc, ActiveModule, Framework,
- Explicit);
- ModuleSpace[ModuleName] = ActiveModule;
+ ActiveModule = Map.findOrCreateModule(ModuleName, ActiveModule, Framework,
+ Explicit).first;
+ ActiveModule->DefinitionLoc = ModuleNameLoc;
bool Done = false;
do {