16 #include "llvm/Support/MemoryBuffer.h" 18 using namespace clang;
25 : SourceMgr(SM), CurBuffer(nullptr) {
35 const char *&DestPtr) {
37 AllocScratchBuffer(Len+2);
43 .getFile().getContentCache());
49 CurBuffer[BytesUsed++] =
'\n';
52 DestPtr = CurBuffer+BytesUsed;
55 memcpy(CurBuffer+BytesUsed, Buf, Len);
63 CurBuffer[BytesUsed-1] =
'\0';
68 void ScratchBuffer::AllocScratchBuffer(
unsigned RequestLen) {
77 std::unique_ptr<llvm::MemoryBuffer> OwnBuf =
78 llvm::MemoryBuffer::getNewMemBuffer(RequestLen,
"<scratch space>");
79 llvm::MemoryBuffer &Buf = *OwnBuf;
82 CurBuffer =
const_cast<char*
>(Buf.getBufferStart());
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
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...
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
Defines the SourceManager interface.
One instance of this struct is kept for every file loaded or used.
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.
unsigned * SourceLineCache
A bump pointer allocated array of offsets for each source line.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Dataflow Directional Tag Classes.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
ScratchBuffer(SourceManager &SM)
This class handles loading and caching of source files into memory.