summaryrefslogtreecommitdiffstats
path: root/clang/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
commit5a7971e0c31a10959d555b3c321baece799afb73 (patch)
treecb7e2df548c6736937c020807fbea9144b55d04a /clang/lib/Lex/ScratchBuffer.cpp
parent4b4622454c2836ed27bf2fcb5ad30256fe14802e (diff)
downloadbcm5719-llvm-5a7971e0c31a10959d555b3c321baece799afb73.tar.gz
bcm5719-llvm-5a7971e0c31a10959d555b3c321baece799afb73.zip
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. llvm-svn: 63028
Diffstat (limited to 'clang/lib/Lex/ScratchBuffer.cpp')
-rw-r--r--clang/lib/Lex/ScratchBuffer.cpp16
1 files changed, 5 insertions, 11 deletions
diff --git a/clang/lib/Lex/ScratchBuffer.cpp b/clang/lib/Lex/ScratchBuffer.cpp
index 695a5365faf..9253bc0944d 100644
--- a/clang/lib/Lex/ScratchBuffer.cpp
+++ b/clang/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
OpenPOWER on IntegriCloud