forked from OSchip/llvm-project
[clang] NFC: Remove benign condition
This commit is contained in:
parent
9089a1dff0
commit
269baa7bfc
|
@ -1990,90 +1990,88 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
|
|||
// Verify that the rest of the module path actually corresponds to
|
||||
// a submodule.
|
||||
bool MapPrivateSubModToTopLevel = false;
|
||||
if (Path.size() > 1) {
|
||||
for (unsigned I = 1, N = Path.size(); I != N; ++I) {
|
||||
StringRef Name = Path[I].first->getName();
|
||||
clang::Module *Sub = Module->findSubmodule(Name);
|
||||
for (unsigned I = 1, N = Path.size(); I != N; ++I) {
|
||||
StringRef Name = Path[I].first->getName();
|
||||
clang::Module *Sub = Module->findSubmodule(Name);
|
||||
|
||||
// If the user is requesting Foo.Private and it doesn't exist, try to
|
||||
// match Foo_Private and emit a warning asking for the user to write
|
||||
// @import Foo_Private instead. FIXME: remove this when existing clients
|
||||
// migrate off of Foo.Private syntax.
|
||||
if (!Sub && PP->getLangOpts().ImplicitModules && Name == "Private" &&
|
||||
Module == Module->getTopLevelModule()) {
|
||||
SmallString<128> PrivateModule(Module->Name);
|
||||
PrivateModule.append("_Private");
|
||||
// If the user is requesting Foo.Private and it doesn't exist, try to
|
||||
// match Foo_Private and emit a warning asking for the user to write
|
||||
// @import Foo_Private instead. FIXME: remove this when existing clients
|
||||
// migrate off of Foo.Private syntax.
|
||||
if (!Sub && PP->getLangOpts().ImplicitModules && Name == "Private" &&
|
||||
Module == Module->getTopLevelModule()) {
|
||||
SmallString<128> PrivateModule(Module->Name);
|
||||
PrivateModule.append("_Private");
|
||||
|
||||
SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> PrivPath;
|
||||
auto &II = PP->getIdentifierTable().get(
|
||||
PrivateModule, PP->getIdentifierInfo(Module->Name)->getTokenID());
|
||||
PrivPath.push_back(std::make_pair(&II, Path[0].second));
|
||||
SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> PrivPath;
|
||||
auto &II = PP->getIdentifierTable().get(
|
||||
PrivateModule, PP->getIdentifierInfo(Module->Name)->getTokenID());
|
||||
PrivPath.push_back(std::make_pair(&II, Path[0].second));
|
||||
|
||||
if (PP->getHeaderSearchInfo().lookupModule(PrivateModule, ImportLoc,
|
||||
true, !IsInclusionDirective))
|
||||
Sub =
|
||||
loadModule(ImportLoc, PrivPath, Visibility, IsInclusionDirective);
|
||||
if (Sub) {
|
||||
MapPrivateSubModToTopLevel = true;
|
||||
if (!getDiagnostics().isIgnored(
|
||||
diag::warn_no_priv_submodule_use_toplevel, ImportLoc)) {
|
||||
getDiagnostics().Report(Path[I].second,
|
||||
diag::warn_no_priv_submodule_use_toplevel)
|
||||
<< Path[I].first << Module->getFullModuleName() << PrivateModule
|
||||
<< SourceRange(Path[0].second, Path[I].second)
|
||||
<< FixItHint::CreateReplacement(SourceRange(Path[0].second),
|
||||
PrivateModule);
|
||||
getDiagnostics().Report(Sub->DefinitionLoc,
|
||||
diag::note_private_top_level_defined);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!Sub) {
|
||||
// Attempt to perform typo correction to find a module name that works.
|
||||
SmallVector<StringRef, 2> Best;
|
||||
unsigned BestEditDistance = (std::numeric_limits<unsigned>::max)();
|
||||
|
||||
for (clang::Module::submodule_iterator J = Module->submodule_begin(),
|
||||
JEnd = Module->submodule_end();
|
||||
J != JEnd; ++J) {
|
||||
unsigned ED = Name.edit_distance((*J)->Name,
|
||||
/*AllowReplacements=*/true,
|
||||
BestEditDistance);
|
||||
if (ED <= BestEditDistance) {
|
||||
if (ED < BestEditDistance) {
|
||||
Best.clear();
|
||||
BestEditDistance = ED;
|
||||
}
|
||||
|
||||
Best.push_back((*J)->Name);
|
||||
}
|
||||
}
|
||||
|
||||
// If there was a clear winner, user it.
|
||||
if (Best.size() == 1) {
|
||||
if (PP->getHeaderSearchInfo().lookupModule(PrivateModule, ImportLoc,
|
||||
true, !IsInclusionDirective))
|
||||
Sub =
|
||||
loadModule(ImportLoc, PrivPath, Visibility, IsInclusionDirective);
|
||||
if (Sub) {
|
||||
MapPrivateSubModToTopLevel = true;
|
||||
if (!getDiagnostics().isIgnored(
|
||||
diag::warn_no_priv_submodule_use_toplevel, ImportLoc)) {
|
||||
getDiagnostics().Report(Path[I].second,
|
||||
diag::err_no_submodule_suggest)
|
||||
<< Path[I].first << Module->getFullModuleName() << Best[0]
|
||||
<< SourceRange(Path[0].second, Path[I-1].second)
|
||||
<< FixItHint::CreateReplacement(SourceRange(Path[I].second),
|
||||
Best[0]);
|
||||
diag::warn_no_priv_submodule_use_toplevel)
|
||||
<< Path[I].first << Module->getFullModuleName() << PrivateModule
|
||||
<< SourceRange(Path[0].second, Path[I].second)
|
||||
<< FixItHint::CreateReplacement(SourceRange(Path[0].second),
|
||||
PrivateModule);
|
||||
getDiagnostics().Report(Sub->DefinitionLoc,
|
||||
diag::note_private_top_level_defined);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Sub = Module->findSubmodule(Best[0]);
|
||||
if (!Sub) {
|
||||
// Attempt to perform typo correction to find a module name that works.
|
||||
SmallVector<StringRef, 2> Best;
|
||||
unsigned BestEditDistance = (std::numeric_limits<unsigned>::max)();
|
||||
|
||||
for (clang::Module::submodule_iterator J = Module->submodule_begin(),
|
||||
JEnd = Module->submodule_end();
|
||||
J != JEnd; ++J) {
|
||||
unsigned ED = Name.edit_distance((*J)->Name,
|
||||
/*AllowReplacements=*/true,
|
||||
BestEditDistance);
|
||||
if (ED <= BestEditDistance) {
|
||||
if (ED < BestEditDistance) {
|
||||
Best.clear();
|
||||
BestEditDistance = ED;
|
||||
}
|
||||
|
||||
Best.push_back((*J)->Name);
|
||||
}
|
||||
}
|
||||
|
||||
if (!Sub) {
|
||||
// No submodule by this name. Complain, and don't look for further
|
||||
// submodules.
|
||||
getDiagnostics().Report(Path[I].second, diag::err_no_submodule)
|
||||
<< Path[I].first << Module->getFullModuleName()
|
||||
<< SourceRange(Path[0].second, Path[I-1].second);
|
||||
break;
|
||||
}
|
||||
// If there was a clear winner, user it.
|
||||
if (Best.size() == 1) {
|
||||
getDiagnostics().Report(Path[I].second,
|
||||
diag::err_no_submodule_suggest)
|
||||
<< Path[I].first << Module->getFullModuleName() << Best[0]
|
||||
<< SourceRange(Path[0].second, Path[I-1].second)
|
||||
<< FixItHint::CreateReplacement(SourceRange(Path[I].second),
|
||||
Best[0]);
|
||||
|
||||
Module = Sub;
|
||||
Sub = Module->findSubmodule(Best[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!Sub) {
|
||||
// No submodule by this name. Complain, and don't look for further
|
||||
// submodules.
|
||||
getDiagnostics().Report(Path[I].second, diag::err_no_submodule)
|
||||
<< Path[I].first << Module->getFullModuleName()
|
||||
<< SourceRange(Path[0].second, Path[I-1].second);
|
||||
break;
|
||||
}
|
||||
|
||||
Module = Sub;
|
||||
}
|
||||
|
||||
// Make the named module visible, if it's not already part of the module
|
||||
|
|
Loading…
Reference in New Issue