From b7a7819473709c01ea024a2dc15e99d38f0f8760 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 4 Jan 2012 23:32:19 +0000 Subject: 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 --- lib/Frontend/CompilerInstance.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'lib/Frontend/CompilerInstance.cpp') diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 498f6fbfc0..1f0d87c062 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -1222,25 +1222,26 @@ Module *CompilerInstance::loadModule(SourceLocation ImportLoc, if (Path.size() > 1) { for (unsigned I = 1, N = Path.size(); I != N; ++I) { StringRef Name = Path[I].first->getName(); - llvm::StringMap::iterator Pos - = Module->SubModules.find(Name); + clang::Module *Sub = Module->findSubmodule(Name); - if (Pos == Module->SubModules.end()) { + if (!Sub) { // Attempt to perform typo correction to find a module name that works. llvm::SmallVector Best; unsigned BestEditDistance = (std::numeric_limits::max)(); - for (llvm::StringMap::iterator - J = Module->SubModules.begin(), - JEnd = Module->SubModules.end(); + for (clang::Module::submodule_iterator J = Module->submodule_begin(), + JEnd = Module->submodule_end(); J != JEnd; ++J) { - unsigned ED = Name.edit_distance(J->getValue()->Name, + unsigned ED = Name.edit_distance((*J)->Name, /*AllowReplacements=*/true, BestEditDistance); if (ED <= BestEditDistance) { - if (ED < BestEditDistance) + if (ED < BestEditDistance) { Best.clear(); - Best.push_back(J->getValue()->Name); + BestEditDistance = ED; + } + + Best.push_back((*J)->Name); } } @@ -1252,11 +1253,12 @@ Module *CompilerInstance::loadModule(SourceLocation ImportLoc, << SourceRange(Path[0].second, Path[I-1].second) << FixItHint::CreateReplacement(SourceRange(Path[I].second), Best[0]); - Pos = Module->SubModules.find(Best[0]); + + Sub = Module->findSubmodule(Best[0]); } } - if (Pos == Module->SubModules.end()) { + if (!Sub) { // No submodule by this name. Complain, and don't look for further // submodules. getDiagnostics().Report(Path[I].second, diag::err_no_submodule) @@ -1265,7 +1267,7 @@ Module *CompilerInstance::loadModule(SourceLocation ImportLoc, break; } - Module = Pos->getValue(); + Module = Sub; } } -- cgit v1.2.3-18-g5258