summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/ScratchBuffer.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-03-08 08:16:41 +0000
committerChris Lattner <sabre@nondot.org>2009-03-08 08:16:41 +0000
commit7253991f9da1acb0890666be476a9ddb4d162b5b (patch)
treed2ebe791f1e45da34209c06bc23faea5d47d00ab /clang/lib/Lex/ScratchBuffer.cpp
parent139d87b80563b4ad3fff5b757317f1d8a33d4864 (diff)
downloadbcm5719-llvm-7253991f9da1acb0890666be476a9ddb4d162b5b.tar.gz
bcm5719-llvm-7253991f9da1acb0890666be476a9ddb4d162b5b.zip
add \n characters to the scratch buffer *before* returned tokens.
This prevents caret diagnostics from the scratch buffer from including other tokens in the scratch buffer that occurred beforei them. llvm-svn: 66375
Diffstat (limited to 'clang/lib/Lex/ScratchBuffer.cpp')
-rw-r--r--clang/lib/Lex/ScratchBuffer.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/clang/lib/Lex/ScratchBuffer.cpp b/clang/lib/Lex/ScratchBuffer.cpp
index c73cd68a4c5..28f3d7ff45b 100644
--- a/clang/lib/Lex/ScratchBuffer.cpp
+++ b/clang/lib/Lex/ScratchBuffer.cpp
@@ -32,8 +32,12 @@ ScratchBuffer::ScratchBuffer(SourceManager &SM) : SourceMgr(SM), CurBuffer(0) {
/// token.
SourceLocation ScratchBuffer::getToken(const char *Buf, unsigned Len,
const char *&DestPtr) {
- if (BytesUsed+Len+1 > ScratchBufSize)
- AllocScratchBuffer(Len);
+ if (BytesUsed+Len+2 > ScratchBufSize)
+ AllocScratchBuffer(Len+2);
+
+ // Prefix the token with a \n, so that it looks like it is the first thing on
+ // its own virtual line in caret diagnostics.
+ CurBuffer[BytesUsed++] = '\n';
// Return a pointer to the character data.
DestPtr = CurBuffer+BytesUsed;
@@ -56,7 +60,7 @@ 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
// support gigantic tokens, which almost certainly won't happen. :)
- if (RequestLen+1 < ScratchBufSize)
+ if (RequestLen < ScratchBufSize)
RequestLen = ScratchBufSize;
llvm::MemoryBuffer *Buf =
OpenPOWER on IntegriCloud