[cfe-commits] r38595 - in /cfe/cfe/trunk: Lex/ScratchBuffer.cpp include/clang/Lex/ScratchBuffer.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:23:02 PDT 2007
Author: sabre
Date: Wed Jul 11 11:23:02 2007
New Revision: 38595
URL: http://llvm.org/viewvc/llvm-project?rev=38595&view=rev
Log:
Expose a new form of the getToken method.
Modified:
cfe/cfe/trunk/Lex/ScratchBuffer.cpp
cfe/cfe/trunk/include/clang/Lex/ScratchBuffer.h
Modified: cfe/cfe/trunk/Lex/ScratchBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/ScratchBuffer.cpp?rev=38595&r1=38594&r2=38595&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/ScratchBuffer.cpp (original)
+++ cfe/cfe/trunk/Lex/ScratchBuffer.cpp Wed Jul 11 11:23:02 2007
@@ -27,30 +27,38 @@
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) {
Modified: cfe/cfe/trunk/include/clang/Lex/ScratchBuffer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/ScratchBuffer.h?rev=38595&r1=38594&r2=38595&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/ScratchBuffer.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/ScratchBuffer.h Wed Jul 11 11:23:02 2007
@@ -37,6 +37,12 @@
SourceLocation getToken(const char *Buf, unsigned Len,
SourceLocation SourceLoc);
+ /// getToken - Splat the specified text into a temporary SourceBuffer and
+ /// return a SourceLocation that refers to the token. This is just like the
+ /// previous method, but returns a location that indicates the physloc of the
+ /// token.
+ SourceLocation getToken(const char *Buf, unsigned Len);
+
private:
void AllocScratchBuffer(unsigned RequestLen);
};
More information about the cfe-commits
mailing list