[cfe-commits] r38587 - in /cfe/cfe/trunk: Basic/SourceBuffer.cpp include/clang/Basic/SourceBuffer.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:22:58 PDT 2007
Author: sabre
Date: Wed Jul 11 11:22:58 2007
New Revision: 38587
URL: http://llvm.org/viewvc/llvm-project?rev=38587&view=rev
Log:
Add a new SourceBuffer::getNewMemBuffer method.
Modified:
cfe/cfe/trunk/Basic/SourceBuffer.cpp
cfe/cfe/trunk/include/clang/Basic/SourceBuffer.h
Modified: cfe/cfe/trunk/Basic/SourceBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Basic/SourceBuffer.cpp?rev=38587&r1=38586&r2=38587&view=diff
==============================================================================
--- cfe/cfe/trunk/Basic/SourceBuffer.cpp (original)
+++ cfe/cfe/trunk/Basic/SourceBuffer.cpp Wed Jul 11 11:22:58 2007
@@ -77,6 +77,20 @@
return new SourceBufferMem(StartPtr, EndPtr, BufferName);
}
+/// getNewMemBuffer - Allocate a new SourceBuffer of the specified size that
+/// is completely initialized to zeros. Note that the caller should
+/// initialize the memory allocated by this method. The memory is owned by
+/// the SourceBuffer object.
+SourceBuffer *SourceBuffer::getNewMemBuffer(unsigned Size,
+ const char *BufferName) {
+ char *Buf = new char[Size+1];
+ memset(Buf, 0, Size+1);
+ SourceBufferMem *SB = new SourceBufferMem(Buf, Buf+Size, BufferName);
+ // The memory for this buffer is owned by the SourceBuffer.
+ SB->MustDeleteBuffer = true;
+ return SB;
+}
+
//===----------------------------------------------------------------------===//
// SourceBufferFile implementation.
Modified: cfe/cfe/trunk/include/clang/Basic/SourceBuffer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/SourceBuffer.h?rev=38587&r1=38586&r2=38587&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/SourceBuffer.h (original)
+++ cfe/cfe/trunk/include/clang/Basic/SourceBuffer.h Wed Jul 11 11:22:58 2007
@@ -57,6 +57,13 @@
static SourceBuffer *getMemBuffer(const char *StartPtr, const char *EndPtr,
const char *BufferName = "");
+ /// getNewMemBuffer - Allocate a new SourceBuffer of the specified size that
+ /// is completely initialized to zeros. Note that the caller should
+ /// initialize the memory allocated by this method. The memory is owned by
+ /// the SourceBuffer object.
+ static SourceBuffer *getNewMemBuffer(unsigned Size,
+ const char *BufferName = "");
+
/// getSTDIN - Read all of stdin into a file buffer, and return it. This
/// fails if stdin is empty.
static SourceBuffer *getSTDIN();
More information about the cfe-commits
mailing list