aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/ScratchBuffer.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-01-26 19:29:26 +0000
committerChris Lattner <sabre@nondot.org>2009-01-26 19:29:26 +0000
commit47246be8ac5b0ddde6c402b8fc6946b6135487b5 (patch)
tree7d62292bae42147bda438278b0cba02eb818db50 /lib/Lex/ScratchBuffer.cpp
parent550faa3a6bb394eaa4013fcff0582434f4e924af (diff)
This change refactors some of the low-level lexer interfaces a bit.
Token now has a class of kinds for "literals", which include numeric constants, strings, etc. These tokens can optionally have a pointer to the start of the token in the lexer buffer. This makes it faster to get spelling and do other gymnastics, because we don't have to go through source locations. This change is performance neutral, but will make other changes more feasible down the road. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63028 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/ScratchBuffer.cpp')
-rw-r--r--lib/Lex/ScratchBuffer.cpp16
1 files changed, 5 insertions, 11 deletions
diff --git a/lib/Lex/ScratchBuffer.cpp b/lib/Lex/ScratchBuffer.cpp
index 695a5365fa..9253bc0944 100644
--- a/lib/Lex/ScratchBuffer.cpp
+++ b/lib/Lex/ScratchBuffer.cpp
@@ -30,10 +30,14 @@ ScratchBuffer::ScratchBuffer(SourceManager &SM) : SourceMgr(SM), CurBuffer(0) {
/// return a SourceLocation that refers to the token. This is just like the
/// method below, but returns a location that indicates the physloc of the
/// token.
-SourceLocation ScratchBuffer::getToken(const char *Buf, unsigned Len) {
+SourceLocation ScratchBuffer::getToken(const char *Buf, unsigned Len,
+ const char *&DestPtr) {
if (BytesUsed+Len > ScratchBufSize)
AllocScratchBuffer(Len);
+ // Return a pointer to the character data.
+ DestPtr = CurBuffer+BytesUsed;
+
// Copy the token data into the buffer.
memcpy(CurBuffer+BytesUsed, Buf, Len);
@@ -43,16 +47,6 @@ SourceLocation ScratchBuffer::getToken(const char *Buf, unsigned Len) {
return BufferStartLoc.getFileLocWithOffset(BytesUsed-Len);
}
-
-/// getToken - Splat the specified text into a temporary MemoryBuffer and
-/// return a SourceLocation that refers to the token. The SourceLoc value
-/// gives a virtual location that the token will appear to be from.
-SourceLocation ScratchBuffer::getToken(const char *Buf, unsigned Len,
- SourceLocation SourceLoc) {
- // Map the physloc to the specified sourceloc.
- return SourceMgr.createInstantiationLoc(getToken(Buf, Len), SourceLoc, Len);
-}
-
void ScratchBuffer::AllocScratchBuffer(unsigned RequestLen) {
// Only pay attention to the requested length if it is larger than our default
// page size. If it is, we allocate an entire chunk for it. This is to