[clang] 86d9e1c - [clang] Delete duplicate code in sourcemanager (#166236)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 5 02:45:37 PST 2025
Author: SKill
Date: 2025-11-05T18:45:32+08:00
New Revision: 86d9e1c035fe14a18751523108ffdef092910b14
URL: https://github.com/llvm/llvm-project/commit/86d9e1c035fe14a18751523108ffdef092910b14
DIFF: https://github.com/llvm/llvm-project/commit/86d9e1c035fe14a18751523108ffdef092910b14.diff
LOG: [clang] Delete duplicate code in sourcemanager (#166236)
Now that the `SourceManager::getExpansionLoc` and
`SourceManager::getSpellingLoc` functions are efficient, delete
unnecessary code duplicate in `SourceManager::getDecomposedExpansionLoc`
and `SourceManager::getDecomposedSpellingLoc` methods.
Added:
Modified:
clang/include/clang/Basic/SourceManager.h
clang/lib/Basic/SourceManager.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h
index ed967fd47dc83..6d9d074d78026 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -1286,16 +1286,7 @@ class SourceManager : public RefCountedBase<SourceManager> {
/// If the location is an expansion record, walk through it until we find
/// the final location expanded.
FileIDAndOffset getDecomposedExpansionLoc(SourceLocation Loc) const {
- FileID FID = getFileID(Loc);
- auto *E = getSLocEntryOrNull(FID);
- if (!E)
- return std::make_pair(FileID(), 0);
-
- unsigned Offset = Loc.getOffset()-E->getOffset();
- if (Loc.isFileID())
- return std::make_pair(FID, Offset);
-
- return getDecomposedExpansionLocSlowCase(E);
+ return getDecomposedLoc(getExpansionLoc(Loc));
}
/// Decompose the specified location into a raw FileID + Offset pair.
@@ -1303,15 +1294,7 @@ class SourceManager : public RefCountedBase<SourceManager> {
/// If the location is an expansion record, walk through it until we find
/// its spelling record.
FileIDAndOffset getDecomposedSpellingLoc(SourceLocation Loc) const {
- FileID FID = getFileID(Loc);
- auto *E = getSLocEntryOrNull(FID);
- if (!E)
- return std::make_pair(FileID(), 0);
-
- unsigned Offset = Loc.getOffset()-E->getOffset();
- if (Loc.isFileID())
- return std::make_pair(FID, Offset);
- return getDecomposedSpellingLocSlowCase(E, Offset);
+ return getDecomposedLoc(getSpellingLoc(Loc));
}
/// Returns the "included/expanded in" decomposed location of the given
@@ -1979,10 +1962,6 @@ class SourceManager : public RefCountedBase<SourceManager> {
SourceLocation getSpellingLocSlowCase(SourceLocation Loc) const;
SourceLocation getFileLocSlowCase(SourceLocation Loc) const;
- FileIDAndOffset
- getDecomposedExpansionLocSlowCase(const SrcMgr::SLocEntry *E) const;
- FileIDAndOffset getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E,
- unsigned Offset) const;
void computeMacroArgsCache(MacroArgsMap &MacroArgsCache, FileID FID) const;
void associateFileChunkWithMacroArgExp(MacroArgsMap &MacroArgsCache,
FileID FID,
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index 97aa0f2aa59b9..7dc81c50f87a2 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -928,41 +928,6 @@ SourceLocation SourceManager::getFileLocSlowCase(SourceLocation Loc) const {
return Loc;
}
-FileIDAndOffset SourceManager::getDecomposedExpansionLocSlowCase(
- const SrcMgr::SLocEntry *E) const {
- // If this is an expansion record, walk through all the expansion points.
- FileID FID;
- SourceLocation Loc;
- unsigned Offset;
- do {
- Loc = E->getExpansion().getExpansionLocStart();
-
- FID = getFileID(Loc);
- E = &getSLocEntry(FID);
- Offset = Loc.getOffset()-E->getOffset();
- } while (!Loc.isFileID());
-
- return std::make_pair(FID, Offset);
-}
-
-FileIDAndOffset
-SourceManager::getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E,
- unsigned Offset) const {
- // If this is an expansion record, walk through all the expansion points.
- FileID FID;
- SourceLocation Loc;
- do {
- Loc = E->getExpansion().getSpellingLoc();
- Loc = Loc.getLocWithOffset(Offset);
-
- FID = getFileID(Loc);
- E = &getSLocEntry(FID);
- Offset = Loc.getOffset()-E->getOffset();
- } while (!Loc.isFileID());
-
- return std::make_pair(FID, Offset);
-}
-
/// getImmediateSpellingLoc - Given a SourceLocation object, return the
/// spelling location referenced by the ID. This is the first level down
/// towards the place where the characters that make up the lexed token can be
More information about the cfe-commits
mailing list