Skip to content

Commit

Permalink
Make Lexer::GetBeginningOfToken able to handle macro arg expansion lo…
Browse files Browse the repository at this point in the history
…cations.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137795 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
akyrtzi committed Aug 17, 2011
1 parent ac836e4 commit 0e87062
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions lib/Lex/Lexer.cpp
Expand Up @@ -416,9 +416,10 @@ unsigned Lexer::MeasureTokenLength(SourceLocation Loc,
return TheTok.getLength();
}

SourceLocation Lexer::GetBeginningOfToken(SourceLocation Loc,
const SourceManager &SM,
const LangOptions &LangOpts) {
static SourceLocation getBeginningOfFileToken(SourceLocation Loc,
const SourceManager &SM,
const LangOptions &LangOpts) {
assert(Loc.isFileID());
std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
if (LocInfo.first.isInvalid())
return Loc;
Expand Down Expand Up @@ -475,6 +476,25 @@ SourceLocation Lexer::GetBeginningOfToken(SourceLocation Loc,
return Loc;
}

SourceLocation Lexer::GetBeginningOfToken(SourceLocation Loc,
const SourceManager &SM,
const LangOptions &LangOpts) {
if (Loc.isFileID())
return getBeginningOfFileToken(Loc, SM, LangOpts);

if (!SM.isMacroArgExpansion(Loc))
return Loc;

SourceLocation FileLoc = SM.getSpellingLoc(Loc);
SourceLocation BeginFileLoc = getBeginningOfFileToken(FileLoc, SM, LangOpts);
std::pair<FileID, unsigned> FileLocInfo = SM.getDecomposedLoc(FileLoc);
std::pair<FileID, unsigned> BeginFileLocInfo= SM.getDecomposedLoc(BeginFileLoc);
assert(FileLocInfo.first == BeginFileLocInfo.first &&
FileLocInfo.second >= BeginFileLocInfo.second);
return Loc.getFileLocWithOffset(SM.getDecomposedLoc(BeginFileLoc).second -
SM.getDecomposedLoc(FileLoc).second);
}

namespace {
enum PreambleDirectiveKind {
PDK_Skipped,
Expand Down

0 comments on commit 0e87062

Please sign in to comment.