Make SourceLocation::getFileLoc private to reduce the API exposure of
SourceLocation. This requires making some cleanups to token pasting
and _Pragma expansion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62490 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/TokenLexer.cpp b/lib/Lex/TokenLexer.cpp
index 7e56a43..82c4d92 100644
--- a/lib/Lex/TokenLexer.cpp
+++ b/lib/Lex/TokenLexer.cpp
@@ -388,13 +388,21 @@
} else {
PP.IncrementPasteCounter(false);
- // Make a lexer to lex this string from.
+ assert(ResultTokLoc.isFileID() &&
+ "Should be a raw location into scratch buffer");
SourceManager &SourceMgr = PP.getSourceManager();
- const char *ResultStrData = SourceMgr.getCharacterData(ResultTokLoc);
+ std::pair<FileID, unsigned> LocInfo =
+ SourceMgr.getDecomposedFileLoc(ResultTokLoc);
+
+ const char *ScratchBufStart =SourceMgr.getBufferData(LocInfo.first).first;
+
+ // Make a lexer to lex this string from. Lex just this one token.
+ const char *ResultStrData = ScratchBufStart+LocInfo.second;
// Make a lexer object so that we lex and expand the paste result.
- Lexer TL(ResultTokLoc, PP.getLangOptions(),
- SourceMgr.getBufferData(ResultTokLoc).first,
+ Lexer TL(SourceMgr.getLocForStartOfFile(LocInfo.first),
+ PP.getLangOptions(),
+ ScratchBufStart,
ResultStrData,
ResultStrData+LHSLen+RHSLen /*don't include null*/);