forked from OSchip/llvm-project
Expose a new form of the getToken method.
llvm-svn: 38595
This commit is contained in:
parent
2dffd2b445
commit
098dfc5e7e
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue