16 #include "llvm/Support/MemoryBuffer.h"
18 using namespace clang;
25 : SourceMgr(SM), CurBuffer(nullptr) {
35 const char *&DestPtr) {
37 AllocScratchBuffer(Len+2);
41 CurBuffer[BytesUsed++] =
'\n';
44 DestPtr = CurBuffer+BytesUsed;
47 memcpy(CurBuffer+BytesUsed, Buf, Len);
55 CurBuffer[BytesUsed-1] =
'\0';
60 void ScratchBuffer::AllocScratchBuffer(
unsigned RequestLen) {
69 std::unique_ptr<llvm::MemoryBuffer> OwnBuf =
70 llvm::MemoryBuffer::getNewMemBuffer(RequestLen,
"<scratch space>");
71 llvm::MemoryBuffer &Buf = *OwnBuf;
74 CurBuffer =
const_cast<char*
>(Buf.getBufferStart());
SourceLocation getToken(const char *Buf, unsigned Len, const char *&DestPtr)
getToken - Splat the specified text into a temporary MemoryBuffer and return a SourceLocation that re...
Defines the SourceManager interface.
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
static const unsigned ScratchBufSize
FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, unsigned LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
Encodes a location in the source.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
ScratchBuffer(SourceManager &SM)
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
This class handles loading and caching of source files into memory.