diff options
| author | Chris Lattner <sabre@nondot.org> | 2006-06-30 06:09:36 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2006-06-30 06:09:36 +0000 |
| commit | 098dfc5e7e3608c739f0e88244898681e46491be (patch) | |
| tree | 3b558643f92171b81c94262186f4b55d92a1679e /clang/Lex/ScratchBuffer.cpp | |
| parent | 2dffd2b445b94c34b2d8bb7b435455fd52949dfe (diff) | |
| download | bcm5719-llvm-098dfc5e7e3608c739f0e88244898681e46491be.tar.gz bcm5719-llvm-098dfc5e7e3608c739f0e88244898681e46491be.zip | |
Expose a new form of the getToken method.
llvm-svn: 38595
Diffstat (limited to 'clang/Lex/ScratchBuffer.cpp')
| -rw-r--r-- | clang/Lex/ScratchBuffer.cpp | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/clang/Lex/ScratchBuffer.cpp b/clang/Lex/ScratchBuffer.cpp index d0138530dbe..49d4e00dbbe 100644 --- a/clang/Lex/ScratchBuffer.cpp +++ b/clang/Lex/ScratchBuffer.cpp @@ -27,30 +27,38 @@ ScratchBuffer::ScratchBuffer(SourceManager &SM) : SourceMgr(SM), CurBuffer(0) { FileID = 0; } - /// getToken - Splat the specified text into a temporary SourceBuffer 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) { +/// 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) { if (BytesUsed+Len > ScratchBufSize) AllocScratchBuffer(Len); - + // Copy the token data into the buffer. memcpy(CurBuffer+BytesUsed, Buf, Len); - unsigned InstantiationFileID = - SourceMgr.createFileIDForMacroExp(SourceLoc, FileID); - - // Create the initial SourceLocation. - SourceLocation Loc(InstantiationFileID, BytesUsed); - assert(BytesUsed < (1 << SourceLocation::FilePosBits) && - "Out of range file position!"); - // Remember that we used these bytes. BytesUsed += Len; + + assert(BytesUsed-Len < (1 << SourceLocation::FilePosBits) && + "Out of range file position!"); - return Loc; + return SourceLocation(FileID, BytesUsed-Len); +} + + +/// getToken - Splat the specified text into a temporary SourceBuffer 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) { + SourceLocation PhysLoc = getToken(Buf, Len); + + // Map the physloc to the specified sourceloc. + unsigned InstantiationFileID = + SourceMgr.createFileIDForMacroExp(SourceLoc, PhysLoc.getFileID()); + return SourceLocation(InstantiationFileID, PhysLoc.getRawFilePos()); } void ScratchBuffer::AllocScratchBuffer(unsigned RequestLen) { |

