Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions clang/include/clang/Basic/SourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,22 @@ class SourceManager : public RefCountedBase<SourceManager> {
return getSpellingLocSlowCase(Loc);
}

/// Given a SourceLocation object, return the refined spelling
/// location referenced by the ID.
///
/// The key difference to \ref getSpellingLoc is that the source location
/// for macro body is resolved to the expansion site.
///
/// This is the place where the characters that make up the lexed token
/// can be found.
SourceLocation getRefinedSpellingLoc(SourceLocation Loc) const {
// Handle the non-mapped case inline, defer to out of line code to handle
// expansions.
if (Loc.isFileID())
return Loc;
return getRefinedSpellingLocSlowCase(Loc);
}

/// Given a SourceLocation object, return the spelling location
/// referenced by the ID.
///
Expand Down Expand Up @@ -1977,6 +1993,7 @@ class SourceManager : public RefCountedBase<SourceManager> {

SourceLocation getExpansionLocSlowCase(SourceLocation Loc) const;
SourceLocation getSpellingLocSlowCase(SourceLocation Loc) const;
SourceLocation getRefinedSpellingLocSlowCase(SourceLocation Loc) const;
SourceLocation getFileLocSlowCase(SourceLocation Loc) const;

FileIDAndOffset
Expand Down
15 changes: 15 additions & 0 deletions clang/lib/Basic/SourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,21 @@ SourceLocation SourceManager::getSpellingLocSlowCase(SourceLocation Loc) const {
return Loc;
}

SourceLocation
SourceManager::getRefinedSpellingLocSlowCase(SourceLocation Loc) const {
do {
const SLocEntry &Entry = getSLocEntry(getFileID(Loc));
const ExpansionInfo &ExpInfo = Entry.getExpansion();
if (ExpInfo.isMacroArgExpansion()) {
Loc = ExpInfo.getSpellingLoc().getLocWithOffset(Loc.getOffset() -
Entry.getOffset());
} else {
Loc = ExpInfo.getExpansionLocStart();
}
} while (!Loc.isFileID());
return Loc;
}

SourceLocation SourceManager::getFileLocSlowCase(SourceLocation Loc) const {
do {
if (isMacroArgExpansion(Loc))
Expand Down
Loading