aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInstance.cpp
diff options
context:
space:
mode:
authoryronglin <yronglin777@gmail.com>2025-04-17 22:40:47 +0800
committerGitHub <noreply@github.com>2025-04-17 22:40:47 +0800
commitd83b639b4c62924deef504f46e573e7d995ea10d (patch)
treefda59205ff14c0c04d49ec15db174456c5cb42fa /clang/lib/Frontend/CompilerInstance.cpp
parent78857e7263ba555fb40b286c6b40fcd35a85a65a (diff)
downloadllvm-d83b639b4c62924deef504f46e573e7d995ea10d.zip
llvm-d83b639b4c62924deef504f46e573e7d995ea10d.tar.gz
llvm-d83b639b4c62924deef504f46e573e7d995ea10d.tar.bz2
Reland [clang] Unify `SourceLocation` and `IdentifierInfo*` pair-like data structures to `IdentifierLoc` (#136077)
This PR reland https://github.com/llvm/llvm-project/pull/135808, fixed some missed changes in LLDB. I found this issue when I working on https://github.com/llvm/llvm-project/pull/107168. Currently we have many similiar data structures like: - std::pair<IdentifierInfo *, SourceLocation>. - Element type of ModuleIdPath. - IdentifierLocPair. - IdentifierLoc. This PR unify these data structures to IdentifierLoc, moved IdentifierLoc definition to SourceLocation.h, and deleted other similer data structures. --------- Signed-off-by: yronglin <yronglin777@gmail.com>
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp53
1 files changed, 28 insertions, 25 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 243e0a3..93e4e31 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -35,6 +35,7 @@
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Sema/CodeCompleteConsumer.h"
+#include "clang/Sema/ParsedAttr.h"
#include "clang/Sema/Sema.h"
#include "clang/Serialization/ASTReader.h"
#include "clang/Serialization/GlobalModuleIndex.h"
@@ -2009,8 +2010,8 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
Module::NameVisibilityKind Visibility,
bool IsInclusionDirective) {
// Determine what file we're searching from.
- StringRef ModuleName = Path[0].first->getName();
- SourceLocation ModuleNameLoc = Path[0].second;
+ StringRef ModuleName = Path[0].getIdentifierInfo()->getName();
+ SourceLocation ModuleNameLoc = Path[0].getLoc();
// If we've already handled this import, just return the cached result.
// This one-element cache is important to eliminate redundant diagnostics
@@ -2026,7 +2027,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
// If we don't already have information on this module, load the module now.
Module *Module = nullptr;
ModuleMap &MM = getPreprocessor().getHeaderSearchInfo().getModuleMap();
- if (auto MaybeModule = MM.getCachedModuleLoad(*Path[0].first)) {
+ if (auto MaybeModule = MM.getCachedModuleLoad(*Path[0].getIdentifierInfo())) {
// Use the cached result, which may be nullptr.
Module = *MaybeModule;
// Config macros are already checked before building a module, but they need
@@ -2046,7 +2047,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
// * `Preprocessor::HandleHeaderIncludeOrImport` will never call this
// function as the `#include` or `#import` is textual.
- MM.cacheModuleLoad(*Path[0].first, Module);
+ MM.cacheModuleLoad(*Path[0].getIdentifierInfo(), Module);
} else {
ModuleLoadResult Result = findOrCompileModuleAndReadAST(
ModuleName, ImportLoc, ModuleNameLoc, IsInclusionDirective);
@@ -2055,7 +2056,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
if (!Result)
DisableGeneratingGlobalModuleIndex = true;
Module = Result;
- MM.cacheModuleLoad(*Path[0].first, Module);
+ MM.cacheModuleLoad(*Path[0].getIdentifierInfo(), Module);
}
// If we never found the module, fail. Otherwise, verify the module and link
@@ -2067,7 +2068,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
// a submodule.
bool MapPrivateSubModToTopLevel = false;
for (unsigned I = 1, N = Path.size(); I != N; ++I) {
- StringRef Name = Path[I].first->getName();
+ StringRef Name = Path[I].getIdentifierInfo()->getName();
clang::Module *Sub = Module->findSubmodule(Name);
// If the user is requesting Foo.Private and it doesn't exist, try to
@@ -2078,10 +2079,10 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
SmallString<128> PrivateModule(Module->Name);
PrivateModule.append("_Private");
- SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> PrivPath;
+ SmallVector<IdentifierLoc, 2> PrivPath;
auto &II = PP->getIdentifierTable().get(
PrivateModule, PP->getIdentifierInfo(Module->Name)->getTokenID());
- PrivPath.push_back(std::make_pair(&II, Path[0].second));
+ PrivPath.emplace_back(Path[0].getLoc(), &II);
std::string FileName;
// If there is a modulemap module or prebuilt module, load it.
@@ -2095,11 +2096,12 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
PP->markClangModuleAsAffecting(Module);
if (!getDiagnostics().isIgnored(
diag::warn_no_priv_submodule_use_toplevel, ImportLoc)) {
- getDiagnostics().Report(Path[I].second,
+ getDiagnostics().Report(Path[I].getLoc(),
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),
+ << Path[I].getIdentifierInfo() << Module->getFullModuleName()
+ << PrivateModule
+ << SourceRange(Path[0].getLoc(), Path[I].getLoc())
+ << FixItHint::CreateReplacement(SourceRange(Path[0].getLoc()),
PrivateModule);
getDiagnostics().Report(Sub->DefinitionLoc,
diag::note_private_top_level_defined);
@@ -2128,10 +2130,11 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
// 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),
+ getDiagnostics().Report(Path[I].getLoc(),
+ diag::err_no_submodule_suggest)
+ << Path[I].getIdentifierInfo() << Module->getFullModuleName()
+ << Best[0] << SourceRange(Path[0].getLoc(), Path[I - 1].getLoc())
+ << FixItHint::CreateReplacement(SourceRange(Path[I].getLoc()),
Best[0]);
Sub = Module->findSubmodule(Best[0]);
@@ -2141,9 +2144,9 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
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);
+ getDiagnostics().Report(Path[I].getLoc(), diag::err_no_submodule)
+ << Path[I].getIdentifierInfo() << Module->getFullModuleName()
+ << SourceRange(Path[0].getLoc(), Path[I - 1].getLoc());
break;
}
@@ -2161,8 +2164,8 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
// FIXME: Should we detect this at module load time? It seems fairly
// expensive (and rare).
getDiagnostics().Report(ImportLoc, diag::warn_missing_submodule)
- << Module->getFullModuleName()
- << SourceRange(Path.front().second, Path.back().second);
+ << Module->getFullModuleName()
+ << SourceRange(Path.front().getLoc(), Path.back().getLoc());
return ModuleLoadResult(Module, ModuleLoadResult::MissingExpected);
}
@@ -2171,7 +2174,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
if (Preprocessor::checkModuleIsAvailable(getLangOpts(), getTarget(),
*Module, getDiagnostics())) {
getDiagnostics().Report(ImportLoc, diag::note_module_import_here)
- << SourceRange(Path.front().second, Path.back().second);
+ << SourceRange(Path.front().getLoc(), Path.back().getLoc());
LastModuleImportLoc = ImportLoc;
LastModuleImportResult = ModuleLoadResult();
return ModuleLoadResult();
@@ -2296,9 +2299,9 @@ GlobalModuleIndex *CompilerInstance::loadGlobalModuleIndex(
Module *TheModule = I->second;
OptionalFileEntryRef Entry = TheModule->getASTFile();
if (!Entry) {
- SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> Path;
- Path.push_back(std::make_pair(
- getPreprocessor().getIdentifierInfo(TheModule->Name), TriggerLoc));
+ SmallVector<IdentifierLoc, 2> Path;
+ Path.emplace_back(TriggerLoc,
+ getPreprocessor().getIdentifierInfo(TheModule->Name));
std::reverse(Path.begin(), Path.end());
// Load a module as hidden. This also adds it to the global index.
loadModule(TheModule->DefinitionLoc, Path, Module::Hidden, false);