Skip to content

Commit 86d9e1c

Browse files
[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.
1 parent 28e024f commit 86d9e1c

File tree

2 files changed

+2
-58
lines changed

2 files changed

+2
-58
lines changed

clang/include/clang/Basic/SourceManager.h

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,32 +1286,15 @@ class SourceManager : public RefCountedBase<SourceManager> {
12861286
/// If the location is an expansion record, walk through it until we find
12871287
/// the final location expanded.
12881288
FileIDAndOffset getDecomposedExpansionLoc(SourceLocation Loc) const {
1289-
FileID FID = getFileID(Loc);
1290-
auto *E = getSLocEntryOrNull(FID);
1291-
if (!E)
1292-
return std::make_pair(FileID(), 0);
1293-
1294-
unsigned Offset = Loc.getOffset()-E->getOffset();
1295-
if (Loc.isFileID())
1296-
return std::make_pair(FID, Offset);
1297-
1298-
return getDecomposedExpansionLocSlowCase(E);
1289+
return getDecomposedLoc(getExpansionLoc(Loc));
12991290
}
13001291

13011292
/// Decompose the specified location into a raw FileID + Offset pair.
13021293
///
13031294
/// If the location is an expansion record, walk through it until we find
13041295
/// its spelling record.
13051296
FileIDAndOffset getDecomposedSpellingLoc(SourceLocation Loc) const {
1306-
FileID FID = getFileID(Loc);
1307-
auto *E = getSLocEntryOrNull(FID);
1308-
if (!E)
1309-
return std::make_pair(FileID(), 0);
1310-
1311-
unsigned Offset = Loc.getOffset()-E->getOffset();
1312-
if (Loc.isFileID())
1313-
return std::make_pair(FID, Offset);
1314-
return getDecomposedSpellingLocSlowCase(E, Offset);
1297+
return getDecomposedLoc(getSpellingLoc(Loc));
13151298
}
13161299

13171300
/// Returns the "included/expanded in" decomposed location of the given
@@ -1979,10 +1962,6 @@ class SourceManager : public RefCountedBase<SourceManager> {
19791962
SourceLocation getSpellingLocSlowCase(SourceLocation Loc) const;
19801963
SourceLocation getFileLocSlowCase(SourceLocation Loc) const;
19811964

1982-
FileIDAndOffset
1983-
getDecomposedExpansionLocSlowCase(const SrcMgr::SLocEntry *E) const;
1984-
FileIDAndOffset getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E,
1985-
unsigned Offset) const;
19861965
void computeMacroArgsCache(MacroArgsMap &MacroArgsCache, FileID FID) const;
19871966
void associateFileChunkWithMacroArgExp(MacroArgsMap &MacroArgsCache,
19881967
FileID FID,

clang/lib/Basic/SourceManager.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -928,41 +928,6 @@ SourceLocation SourceManager::getFileLocSlowCase(SourceLocation Loc) const {
928928
return Loc;
929929
}
930930

931-
FileIDAndOffset SourceManager::getDecomposedExpansionLocSlowCase(
932-
const SrcMgr::SLocEntry *E) const {
933-
// If this is an expansion record, walk through all the expansion points.
934-
FileID FID;
935-
SourceLocation Loc;
936-
unsigned Offset;
937-
do {
938-
Loc = E->getExpansion().getExpansionLocStart();
939-
940-
FID = getFileID(Loc);
941-
E = &getSLocEntry(FID);
942-
Offset = Loc.getOffset()-E->getOffset();
943-
} while (!Loc.isFileID());
944-
945-
return std::make_pair(FID, Offset);
946-
}
947-
948-
FileIDAndOffset
949-
SourceManager::getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E,
950-
unsigned Offset) const {
951-
// If this is an expansion record, walk through all the expansion points.
952-
FileID FID;
953-
SourceLocation Loc;
954-
do {
955-
Loc = E->getExpansion().getSpellingLoc();
956-
Loc = Loc.getLocWithOffset(Offset);
957-
958-
FID = getFileID(Loc);
959-
E = &getSLocEntry(FID);
960-
Offset = Loc.getOffset()-E->getOffset();
961-
} while (!Loc.isFileID());
962-
963-
return std::make_pair(FID, Offset);
964-
}
965-
966931
/// getImmediateSpellingLoc - Given a SourceLocation object, return the
967932
/// spelling location referenced by the ID. This is the first level down
968933
/// towards the place where the characters that make up the lexed token can be

0 commit comments

Comments
 (0)