Expose a new form of the getToken method.

llvm-svn: 38595
This commit is contained in:
Chris Lattner 2006-06-30 06:09:36 +00:00
parent 2dffd2b445
commit 098dfc5e7e
2 changed files with 30 additions and 16 deletions

View File

@ -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. 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);
// Remember that we used these bytes.
BytesUsed += Len;
assert(BytesUsed-Len < (1 << SourceLocation::FilePosBits) &&
"Out of range file position!");
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) {
if (BytesUsed+Len > ScratchBufSize)
AllocScratchBuffer(Len);
// Copy the token data into the buffer.
memcpy(CurBuffer+BytesUsed, Buf, Len);
SourceLocation PhysLoc = getToken(Buf, Len);
// Map the physloc to the specified sourceloc.
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;
return Loc;
SourceMgr.createFileIDForMacroExp(SourceLoc, PhysLoc.getFileID());
return SourceLocation(InstantiationFileID, PhysLoc.getRawFilePos());
}
void ScratchBuffer::AllocScratchBuffer(unsigned RequestLen) {

View File

@ -37,6 +37,12 @@ public:
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);
};