Skip to content

Commit 6d82050

Browse files
[clang] Delete duplicate code in sourcemanager
1 parent 346da3d commit 6d82050

File tree

2 files changed

+4
-62
lines changed

2 files changed

+4
-62
lines changed

clang/include/clang/Basic/SourceManager.h

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,43 +1275,24 @@ class SourceManager : public RefCountedBase<SourceManager> {
12751275
/// start of the buffer of the location.
12761276
FileIDAndOffset getDecomposedLoc(SourceLocation Loc) const {
12771277
FileID FID = getFileID(Loc);
1278-
auto *Entry = getSLocEntryOrNull(FID);
1279-
if (!Entry)
1280-
return std::make_pair(FileID(), 0);
1281-
return std::make_pair(FID, Loc.getOffset() - Entry->getOffset());
1278+
const SrcMgr::SLocEntry &Entry = getSLocEntry(FID);
1279+
return std::make_pair(FID, Loc.getOffset() - Entry.getOffset());
12821280
}
12831281

12841282
/// Decompose the specified location into a raw FileID + Offset pair.
12851283
///
12861284
/// If the location is an expansion record, walk through it until we find
12871285
/// the final location expanded.
12881286
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);
1287+
return getDecomposedLoc(getExpansionLoc(Loc));
12991288
}
13001289

13011290
/// Decompose the specified location into a raw FileID + Offset pair.
13021291
///
13031292
/// If the location is an expansion record, walk through it until we find
13041293
/// its spelling record.
13051294
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);
1295+
return getDecomposedLoc(getSpellingLoc(Loc));
13151296
}
13161297

13171298
/// Returns the "included/expanded in" decomposed location of the given
@@ -1979,10 +1960,6 @@ class SourceManager : public RefCountedBase<SourceManager> {
19791960
SourceLocation getSpellingLocSlowCase(SourceLocation Loc) const;
19801961
SourceLocation getFileLocSlowCase(SourceLocation Loc) const;
19811962

1982-
FileIDAndOffset
1983-
getDecomposedExpansionLocSlowCase(const SrcMgr::SLocEntry *E) const;
1984-
FileIDAndOffset getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E,
1985-
unsigned Offset) const;
19861963
void computeMacroArgsCache(MacroArgsMap &MacroArgsCache, FileID FID) const;
19871964
void associateFileChunkWithMacroArgExp(MacroArgsMap &MacroArgsCache,
19881965
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)