Make a fundamental change to the way we represent the location of LexerToken's.
Now, instead of keeping a pointer to the start of the token in memory, we keep the
start of the token as a SourceLocation node. This means that each LexerToken knows
the full include stack it was created with, and means that the LexerToken isn't
reliant on a "CurLexer" member to be around (lexer tokens would previously go out of
scope when their lexers were deallocated).
This simplifies several things, and forces good cleanup elsewhere. Now the
Preprocessor is the one that knows how to dump tokens/macros and is the one that
knows how to get the spelling of a token (it has all the context).
llvm-svn: 38551
diff --git a/clang/Basic/SourceManager.cpp b/clang/Basic/SourceManager.cpp
index ad0b3d9..529b90d 100644
--- a/clang/Basic/SourceManager.cpp
+++ b/clang/Basic/SourceManager.cpp
@@ -109,6 +109,16 @@
return Result;
}
+/// getCharacterData - Return a pointer to the start of the specified location
+/// in the appropriate SourceBuffer. This returns null if it cannot be
+/// computed (e.g. invalid SourceLocation).
+const char *SourceManager::getCharacterData(SourceLocation SL) const {
+ if (unsigned FileID = SL.getFileID())
+ return getFileInfo(FileID)->Buffer->getBufferStart() + getFilePos(SL);
+ return 0;
+}
+
+
/// getColumnNumber - Return the column # for the specified include position.
/// this is significantly cheaper to compute than the line number. This returns
/// zero if the column number isn't known.