diff options
| -rw-r--r-- | clang/Basic/SourceBuffer.cpp | 280 | ||||
| -rw-r--r-- | clang/Basic/SourceManager.cpp | 22 | ||||
| -rw-r--r-- | clang/Driver/clang.cpp | 10 | ||||
| -rw-r--r-- | clang/Lex/Lexer.cpp | 5 | ||||
| -rw-r--r-- | clang/Lex/Preprocessor.cpp | 2 | ||||
| -rw-r--r-- | clang/Lex/ScratchBuffer.cpp | 10 | ||||
| -rw-r--r-- | clang/clang.xcodeproj/project.pbxproj | 10 | ||||
| -rw-r--r-- | clang/include/clang/Basic/Diagnostic.h | 1 | ||||
| -rw-r--r-- | clang/include/clang/Basic/SourceBuffer.h | 85 | ||||
| -rw-r--r-- | clang/include/clang/Basic/SourceManager.h | 23 | ||||
| -rw-r--r-- | clang/include/clang/Lex/Lexer.h | 9 | ||||
| -rw-r--r-- | clang/include/clang/Lex/ScratchBuffer.h | 5 |
12 files changed, 43 insertions, 419 deletions
diff --git a/clang/Basic/SourceBuffer.cpp b/clang/Basic/SourceBuffer.cpp deleted file mode 100644 index 0635a477234..00000000000 --- a/clang/Basic/SourceBuffer.cpp +++ /dev/null @@ -1,280 +0,0 @@ -//===--- SourceBuffer.cpp - C Language Family Source Buffer Impl. ---------===// -// -// The LLVM Compiler Infrastructure -// -// This file was developed by Chris Lattner and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file implements the SourceBuffer interface. -// -//===----------------------------------------------------------------------===// - -#include "clang/Basic/SourceBuffer.h" -#include "clang/Basic/FileManager.h" -#include "llvm/System/MappedFile.h" -#include "llvm/System/Process.h" -#include <cstdio> -#include <cstring> -#include <cerrno> -using namespace llvm; -using namespace clang; - -//===----------------------------------------------------------------------===// -// SourceBuffer implementation itself. -//===----------------------------------------------------------------------===// - -SourceBuffer::~SourceBuffer() { - if (MustDeleteBuffer) - delete [] BufferStart; -} - -/// initCopyOf - Initialize this source buffer with a copy of the specified -/// memory range. We make the copy so that we can null terminate it -/// successfully. -void SourceBuffer::initCopyOf(const char *BufStart, const char *BufEnd) { - size_t Size = BufEnd-BufStart; - BufferStart = new char[Size+1]; - BufferEnd = BufferStart+Size; - memcpy(const_cast<char*>(BufferStart), BufStart, Size); - *const_cast<char*>(BufferEnd) = 0; // Null terminate buffer. - MustDeleteBuffer = false; -} - -/// init - Initialize this SourceBuffer as a reference to externally allocated -/// memory, memory that we know is already null terminated. -void SourceBuffer::init(const char *BufStart, const char *BufEnd) { - assert(BufEnd[0] == 0 && "Buffer is not null terminated!"); - BufferStart = BufStart; - BufferEnd = BufEnd; - MustDeleteBuffer = false; -} - -//===----------------------------------------------------------------------===// -// SourceBufferMem implementation. -//===----------------------------------------------------------------------===// - -namespace { -class SourceBufferMem : public SourceBuffer { - std::string FileID; -public: - SourceBufferMem(const char *Start, const char *End, const char *FID) - : FileID(FID) { - init(Start, End); - } - - virtual const char *getBufferIdentifier() const { - return FileID.c_str(); - } -}; -} - -/// getMemBuffer - Open the specified memory range as a SourceBuffer. Note -/// that EndPtr[0] must be a null byte and be accessible! -SourceBuffer *SourceBuffer::getMemBuffer(const char *StartPtr, - const char *EndPtr, - const char *BufferName) { - return new SourceBufferMem(StartPtr, EndPtr, BufferName); -} - -/// getNewUninitMemBuffer - 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::getNewUninitMemBuffer(unsigned Size, - const char *BufferName) { - char *Buf = new char[Size+1]; - Buf[Size] = 0; - SourceBufferMem *SB = new SourceBufferMem(Buf, Buf+Size, BufferName); - // The memory for this buffer is owned by the SourceBuffer. - SB->MustDeleteBuffer = true; - return SB; -} - -/// 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) { - SourceBuffer *SB = getNewUninitMemBuffer(Size, BufferName); - memset(const_cast<char*>(SB->getBufferStart()), 0, Size+1); - return SB; -} - - -//===----------------------------------------------------------------------===// -// SourceBufferMMapFile implementation. -//===----------------------------------------------------------------------===// - -namespace { -class SourceBufferMMapFile : public SourceBuffer { - sys::MappedFile File; -public: - SourceBufferMMapFile(const sys::Path &Filename); - - virtual const char *getBufferIdentifier() const { - return File.path().c_str(); - } - - ~SourceBufferMMapFile(); -}; -} - -SourceBufferMMapFile::SourceBufferMMapFile(const sys::Path &Filename) { - // FIXME: This does an extra stat syscall to figure out the size, but we - // already know the size! - bool Failure = File.open(Filename); - Failure = Failure; // Silence warning in no-asserts mode. - assert(!Failure && "Can't open file??"); - - File.map(); - - size_t Size = File.size(); - - static unsigned PageSize = sys::Process::GetPageSize(); - assert(((PageSize & (PageSize-1)) == 0) && PageSize && - "Page size is not a power of 2!"); - - // If this file is not an exact multiple of the system page size (common - // case), then the OS has zero terminated the buffer for us. - if ((Size & (PageSize-1))) { - init(File.charBase(), File.charBase()+Size); - } else { - // Otherwise, we allocate a new memory buffer and copy the data over - initCopyOf(File.charBase(), File.charBase()+Size); - - // No need to keep the file mapped any longer. - File.unmap(); - } -} - -SourceBufferMMapFile::~SourceBufferMMapFile() { - File.unmap(); -} - -//===----------------------------------------------------------------------===// -// SourceBuffer::getFile implementation. -//===----------------------------------------------------------------------===// - -SourceBuffer *SourceBuffer::getFile(const char *FilenameStart, unsigned FnSize, - int64_t FileSize) { - sys::PathWithStatus P(FilenameStart, FnSize); -#if 1 - return new SourceBufferMMapFile(P); -#else - - // If the user didn't specify a filesize, do a stat to find it. - if (FileSize == -1) { - const sys::FileStatus *FS = P.getFileStatus(); - if (FS == 0) return 0; // Error stat'ing file. - - FileSize = FS->fileSize; - } - - // If the file is larger than some threshold, use mmap, otherwise use 'read'. - if (FileSize >= 4096*4) - return new SourceBufferMMapFile(P); - - SourceBuffer *SB = getNewUninitMemBuffer(FileSize, FilenameStart); - char *BufPtr = const_cast<char*>(SB->getBufferStart()); - - int FD = ::open(FilenameStart, O_RDONLY); - if (FD == -1) { - delete SB; - return 0; - } - - unsigned BytesLeft = FileSize; - while (BytesLeft) { - ssize_t NumRead = ::read(FD, BufPtr, BytesLeft); - if (NumRead != -1) { - BytesLeft -= NumRead; - BufPtr += NumRead; - } else if (errno == EINTR) { - // try again - } else { - // error reading. - close(FD); - delete SB; - return 0; - } - } - close(FD); - - return SB; -#endif -} - -#if 0 -SourceBuffer *SourceBuffer::getFile(const FileEntry *FileEnt) { -#if 0 - // FIXME: - return getFile(FileEnt->getName(), strlen(FileEnt->getName()), - FileEnt->getSize()); -#endif - - // If the file is larger than some threshold, use 'read', otherwise use mmap. - if (FileEnt->getSize() >= 4096*4) - return new SourceBufferMMapFile(sys::Path(FileEnt->getName(), - strlen(FileEnt->getName()))); - - SourceBuffer *SB = getNewUninitMemBuffer(FileEnt->getSize(), - FileEnt->getName()); - char *BufPtr = const_cast<char*>(SB->getBufferStart()); - - int FD = ::open(FileEnt->getName(), O_RDONLY); - if (FD == -1) { - delete SB; - return 0; - } - - unsigned BytesLeft = FileEnt->getSize(); - while (BytesLeft) { - ssize_t NumRead = ::read(FD, BufPtr, BytesLeft); - if (NumRead != -1) { - BytesLeft -= NumRead; - BufPtr += NumRead; - } else if (errno == EINTR) { - // try again - } else { - // error reading. - close(FD); - delete SB; - return 0; - } - } - close(FD); - - return SB; -} -#endif - -//===----------------------------------------------------------------------===// -// SourceBuffer::getSTDIN implementation. -//===----------------------------------------------------------------------===// - -namespace { -class STDINBufferFile : public SourceBuffer { -public: - virtual const char *getBufferIdentifier() const { - return "<stdin>"; - } -}; -} - -SourceBuffer *SourceBuffer::getSTDIN() { - char Buffer[4096*4]; - - std::vector<char> FileData; - - // Read in all of the data from stdin, we cannot mmap stdin. - while (size_t ReadBytes = fread(Buffer, 1, 4096*4, stdin)) - FileData.insert(FileData.end(), Buffer, Buffer+ReadBytes); - - size_t Size = FileData.size(); - SourceBuffer *B = new STDINBufferFile(); - B->initCopyOf(&FileData[0], &FileData[Size]); - return B; -} diff --git a/clang/Basic/SourceManager.cpp b/clang/Basic/SourceManager.cpp index 8ed49d351a0..fd4a0e50259 100644 --- a/clang/Basic/SourceManager.cpp +++ b/clang/Basic/SourceManager.cpp @@ -13,7 +13,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/FileManager.h" -#include "clang/Basic/SourceBuffer.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/System/Path.h" #include <algorithm> #include <iostream> @@ -43,20 +43,20 @@ SourceManager::~SourceManager() { #include <sys/fcntl.h> #include <cerrno> -static const SourceBuffer *ReadFileFast(const FileEntry *FileEnt) { +static const MemoryBuffer *ReadFileFast(const FileEntry *FileEnt) { #if 0 // FIXME: Reintroduce this and zap this function once the common llvm stuff // is fast for the small case. - return SourceBuffer::getFile(FileEnt->getName(), strlen(FileEnt->getName()), + return MemoryBuffer::getFile(FileEnt->getName(), strlen(FileEnt->getName()), FileEnt->getSize()); #endif // If the file is larger than some threshold, use 'read', otherwise use mmap. if (FileEnt->getSize() >= 4096*4) - return SourceBuffer::getFile(FileEnt->getName(), strlen(FileEnt->getName()), + return MemoryBuffer::getFile(FileEnt->getName(), strlen(FileEnt->getName()), FileEnt->getSize()); - SourceBuffer *SB = SourceBuffer::getNewUninitMemBuffer(FileEnt->getSize(), + MemoryBuffer *SB = MemoryBuffer::getNewUninitMemBuffer(FileEnt->getSize(), FileEnt->getName()); char *BufPtr = const_cast<char*>(SB->getBufferStart()); @@ -99,7 +99,7 @@ SourceManager::getInfoRec(const FileEntry *FileEnt) { return &*I; // Nope, get information. - const SourceBuffer *File = ReadFileFast(FileEnt); + const MemoryBuffer *File = ReadFileFast(FileEnt); if (File == 0) return 0; @@ -117,7 +117,7 @@ SourceManager::getInfoRec(const FileEntry *FileEnt) { /// createMemBufferInfoRec - Create a new info record for the specified memory /// buffer. This does no caching. const InfoRec * -SourceManager::createMemBufferInfoRec(const SourceBuffer *Buffer) { +SourceManager::createMemBufferInfoRec(const MemoryBuffer *Buffer) { // Add a new info record to the MemBufferInfos list and return it. FileInfo FI; FI.Buffer = Buffer; @@ -196,7 +196,7 @@ SourceLocation SourceManager::getInstantiationLoc(SourceLocation PhysLoc, /// getCharacterData - Return a pointer to the start of the specified location -/// in the appropriate SourceBuffer. +/// in the appropriate MemoryBuffer. const char *SourceManager::getCharacterData(SourceLocation SL) const { // Note that this is a hot function in the getSpelling() path, which is // heavily used by -E mode. @@ -228,7 +228,7 @@ unsigned SourceManager::getColumnNumber(SourceLocation Loc) const { if (FileID == 0) return 0; unsigned FilePos = getFilePos(Loc); - const SourceBuffer *Buffer = getBuffer(FileID); + const MemoryBuffer *Buffer = getBuffer(FileID); const char *Buf = Buffer->getBufferStart(); unsigned LineStart = FilePos; @@ -250,7 +250,7 @@ std::string SourceManager::getSourceName(SourceLocation Loc) { /// getLineNumber - Given a SourceLocation, return the physical line number /// for the position indicated. This requires building and caching a table of -/// line offsets for the SourceBuffer, so this is not cheap: use only when +/// line offsets for the MemoryBuffer, so this is not cheap: use only when /// about to emit a diagnostic. unsigned SourceManager::getLineNumber(SourceLocation Loc) { Loc = getLogicalLoc(Loc); @@ -261,7 +261,7 @@ unsigned SourceManager::getLineNumber(SourceLocation Loc) { // If this is the first use of line information for this buffer, compute the /// SourceLineCache for it on demand. if (FileInfo->SourceLineCache == 0) { - const SourceBuffer *Buffer = FileInfo->Buffer; + const MemoryBuffer *Buffer = FileInfo->Buffer; // Find the file offsets of all of the *physical* source lines. This does // not look at trigraphs, escaped newlines, or anything else tricky. diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp index e4181e3bece..3870bf4fd33 100644 --- a/clang/Driver/clang.cpp +++ b/clang/Driver/clang.cpp @@ -28,10 +28,10 @@ #include "clang/Lex/HeaderSearch.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/FileManager.h" -#include "clang/Basic/SourceBuffer.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/System/MappedFile.h" #include "llvm/System/Signals.h" #include <iostream> @@ -360,7 +360,7 @@ PrintIncludeStack(SourceLocation Pos) { unsigned LineNo = SourceMgr.getLineNumber(Pos); - const SourceBuffer *Buffer = SourceMgr.getBuffer(FileID); + const MemoryBuffer *Buffer = SourceMgr.getBuffer(FileID); std::cerr << "In file included from " << Buffer->getBufferIdentifier() << ":" << LineNo << ":\n"; } @@ -372,7 +372,7 @@ void DiagnosticPrinterSTDERR::HandleDiagnostic(Diagnostic::Level Level, const std::string &Extra) { unsigned LineNo = 0, FilePos = 0, FileID = 0, ColNo = 0; unsigned LineStart = 0, LineEnd = 0; - const SourceBuffer *Buffer = 0; + const MemoryBuffer *Buffer = 0; if (Pos.isValid()) { LineNo = SourceMgr.getLineNumber(Pos); @@ -944,7 +944,7 @@ static void ProcessInputFile(const std::string &InFile, return; } } else { - SourceBuffer *SB = SourceBuffer::getSTDIN(); + MemoryBuffer *SB = MemoryBuffer::getSTDIN(); if (SB) MainFileID = SourceMgr.createFileIDForMemBuffer(SB); if (MainFileID == 0) { std::cerr << "Error reading standard input! Empty?\n"; @@ -959,7 +959,7 @@ static void ProcessInputFile(const std::string &InFile, // Memory buffer must end with a null byte! PrologMacros.push_back(0); - SourceBuffer *SB = SourceBuffer::getMemBuffer(&PrologMacros.front(), + MemoryBuffer *SB = MemoryBuffer::getMemBuffer(&PrologMacros.front(), &PrologMacros.back(), "<predefines>"); assert(SB && "Cannot fail to create predefined source buffer"); diff --git a/clang/Lex/Lexer.cpp b/clang/Lex/Lexer.cpp index 4a57ac2c74b..810f10da4d1 100644 --- a/clang/Lex/Lexer.cpp +++ b/clang/Lex/Lexer.cpp @@ -27,9 +27,8 @@ #include "clang/Lex/Lexer.h" #include "clang/Lex/Preprocessor.h" #include "clang/Basic/Diagnostic.h" -#include "clang/Basic/SourceBuffer.h" #include "clang/Basic/SourceLocation.h" -#include "llvm/Config/alloca.h" +#include "llvm/Support/MemoryBuffer.h" #include <cctype> #include <iostream> using namespace llvm; @@ -37,7 +36,7 @@ using namespace clang; static void InitCharacterInfo(); -Lexer::Lexer(const SourceBuffer *File, unsigned fileid, Preprocessor &pp, +Lexer::Lexer(const MemoryBuffer *File, unsigned fileid, Preprocessor &pp, const char *BufStart, const char *BufEnd) : BufferEnd(BufEnd ? BufEnd : File->getBufferEnd()), InputFile(File), CurFileID(fileid), PP(pp), Features(PP.getLangOptions()) { diff --git a/clang/Lex/Preprocessor.cpp b/clang/Lex/Preprocessor.cpp index 7654d22d053..cbdb0ff3868 100644 --- a/clang/Lex/Preprocessor.cpp +++ b/clang/Lex/Preprocessor.cpp @@ -339,7 +339,7 @@ void Preprocessor::EnterSourceFile(unsigned FileID, if (MaxIncludeStackDepth < IncludeMacroStack.size()) MaxIncludeStackDepth = IncludeMacroStack.size(); - const SourceBuffer *Buffer = SourceMgr.getBuffer(FileID); + const MemoryBuffer *Buffer = SourceMgr.getBuffer(FileID); Lexer *TheLexer = new Lexer(Buffer, FileID, *this); if (isMainFile) TheLexer->setIsMainFile(); EnterSourceFileWithLexer(TheLexer, CurDir); diff --git a/clang/Lex/ScratchBuffer.cpp b/clang/Lex/ScratchBuffer.cpp index 65887f2dfa7..a53bb2e17ea 100644 --- a/clang/Lex/ScratchBuffer.cpp +++ b/clang/Lex/ScratchBuffer.cpp @@ -12,8 +12,8 @@ //===----------------------------------------------------------------------===// #include "clang/Lex/ScratchBuffer.h" -#include "clang/Basic/SourceBuffer.h" #include "clang/Basic/SourceManager.h" +#include "llvm/Support/MemoryBuffer.h" using namespace llvm; using namespace clang; @@ -27,7 +27,7 @@ ScratchBuffer::ScratchBuffer(SourceManager &SM) : SourceMgr(SM), CurBuffer(0) { FileID = 0; } -/// getToken - Splat the specified text into a temporary SourceBuffer and +/// getToken - Splat the specified text into a temporary MemoryBuffer 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. @@ -48,7 +48,7 @@ SourceLocation ScratchBuffer::getToken(const char *Buf, unsigned Len) { } -/// getToken - Splat the specified text into a temporary SourceBuffer and +/// getToken - Splat the specified text into a temporary MemoryBuffer 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, @@ -64,8 +64,8 @@ void ScratchBuffer::AllocScratchBuffer(unsigned RequestLen) { if (RequestLen < ScratchBufSize) RequestLen = ScratchBufSize; - SourceBuffer *Buf = - SourceBuffer::getNewMemBuffer(RequestLen, "<scratch space>"); + MemoryBuffer *Buf = + MemoryBuffer::getNewMemBuffer(RequestLen, "<scratch space>"); FileID = SourceMgr.createFileIDForMemBuffer(Buf); CurBuffer = const_cast<char*>(Buf->getBufferStart()); BytesUsed = 0; diff --git a/clang/clang.xcodeproj/project.pbxproj b/clang/clang.xcodeproj/project.pbxproj index 6ecffce7a65..3118a160b60 100644 --- a/clang/clang.xcodeproj/project.pbxproj +++ b/clang/clang.xcodeproj/project.pbxproj @@ -68,7 +68,6 @@ DED7D7410A524295003AD0FB /* Diagnostic.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DED7D7310A524295003AD0FB /* Diagnostic.h */; }; DED7D7420A524295003AD0FB /* DiagnosticKinds.def in CopyFiles */ = {isa = PBXBuildFile; fileRef = DED7D7320A524295003AD0FB /* DiagnosticKinds.def */; }; DED7D7430A524295003AD0FB /* FileManager.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DED7D7330A524295003AD0FB /* FileManager.h */; }; - DED7D7440A524295003AD0FB /* SourceBuffer.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DED7D7340A524295003AD0FB /* SourceBuffer.h */; }; DED7D7450A524295003AD0FB /* SourceLocation.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DED7D7350A524295003AD0FB /* SourceLocation.h */; }; DED7D7460A524295003AD0FB /* SourceManager.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DED7D7360A524295003AD0FB /* SourceManager.h */; }; DED7D7470A524295003AD0FB /* TokenKinds.def in CopyFiles */ = {isa = PBXBuildFile; fileRef = DED7D7370A524295003AD0FB /* TokenKinds.def */; }; @@ -82,7 +81,6 @@ DED7D74F0A524295003AD0FB /* Preprocessor.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DED7D7400A524295003AD0FB /* Preprocessor.h */; }; DED7D77A0A5242C7003AD0FB /* Diagnostic.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DED7D75D0A5242C7003AD0FB /* Diagnostic.cpp */; }; DED7D77B0A5242C7003AD0FB /* FileManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DED7D75E0A5242C7003AD0FB /* FileManager.cpp */; }; - DED7D7880A5242C7003AD0FB /* SourceBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DED7D76C0A5242C7003AD0FB /* SourceBuffer.cpp */; }; DED7D7890A5242C7003AD0FB /* SourceManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DED7D76D0A5242C7003AD0FB /* SourceManager.cpp */; }; DED7D78A0A5242C7003AD0FB /* TokenKinds.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DED7D76E0A5242C7003AD0FB /* TokenKinds.cpp */; }; DED7D7C20A5242E6003AD0FB /* IdentifierTable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DED7D79D0A5242E6003AD0FB /* IdentifierTable.cpp */; }; @@ -106,7 +104,6 @@ DED7D7410A524295003AD0FB /* Diagnostic.h in CopyFiles */, DED7D7420A524295003AD0FB /* DiagnosticKinds.def in CopyFiles */, DED7D7430A524295003AD0FB /* FileManager.h in CopyFiles */, - DED7D7440A524295003AD0FB /* SourceBuffer.h in CopyFiles */, DED7D7450A524295003AD0FB /* SourceLocation.h in CopyFiles */, DED7D7460A524295003AD0FB /* SourceManager.h in CopyFiles */, DED7D7470A524295003AD0FB /* TokenKinds.def in CopyFiles */, @@ -216,7 +213,6 @@ DED7D7310A524295003AD0FB /* Diagnostic.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Diagnostic.h; sourceTree = "<group>"; }; DED7D7320A524295003AD0FB /* DiagnosticKinds.def */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = DiagnosticKinds.def; sourceTree = "<group>"; }; DED7D7330A524295003AD0FB /* FileManager.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FileManager.h; sourceTree = "<group>"; }; - DED7D7340A524295003AD0FB /* SourceBuffer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SourceBuffer.h; sourceTree = "<group>"; }; DED7D7350A524295003AD0FB /* SourceLocation.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SourceLocation.h; sourceTree = "<group>"; }; DED7D7360A524295003AD0FB /* SourceManager.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SourceManager.h; sourceTree = "<group>"; }; DED7D7370A524295003AD0FB /* TokenKinds.def */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = TokenKinds.def; sourceTree = "<group>"; }; @@ -230,7 +226,6 @@ DED7D7400A524295003AD0FB /* Preprocessor.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Preprocessor.h; sourceTree = "<group>"; }; DED7D75D0A5242C7003AD0FB /* Diagnostic.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Diagnostic.cpp; sourceTree = "<group>"; }; DED7D75E0A5242C7003AD0FB /* FileManager.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FileManager.cpp; sourceTree = "<group>"; }; - DED7D76C0A5242C7003AD0FB /* SourceBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SourceBuffer.cpp; sourceTree = "<group>"; }; DED7D76D0A5242C7003AD0FB /* SourceManager.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SourceManager.cpp; sourceTree = "<group>"; }; DED7D76E0A5242C7003AD0FB /* TokenKinds.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = TokenKinds.cpp; sourceTree = "<group>"; }; DED7D79D0A5242E6003AD0FB /* IdentifierTable.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = IdentifierTable.cpp; sourceTree = "<group>"; }; @@ -394,7 +389,6 @@ DED7D7320A524295003AD0FB /* DiagnosticKinds.def */, DED7D7330A524295003AD0FB /* FileManager.h */, DE06B73D0A8307640050E87E /* LangOptions.h */, - DED7D7340A524295003AD0FB /* SourceBuffer.h */, DED7D7350A524295003AD0FB /* SourceLocation.h */, DED7D7360A524295003AD0FB /* SourceManager.h */, DE46BF270AE0A82D00CC047C /* TargetInfo.h */, @@ -431,7 +425,6 @@ children = ( DED7D75D0A5242C7003AD0FB /* Diagnostic.cpp */, DED7D75E0A5242C7003AD0FB /* FileManager.cpp */, - DED7D76C0A5242C7003AD0FB /* SourceBuffer.cpp */, DED7D76D0A5242C7003AD0FB /* SourceManager.cpp */, DED7D76E0A5242C7003AD0FB /* TokenKinds.cpp */, DED626C80AE0C065001E80A4 /* TargetInfo.cpp */, @@ -483,12 +476,10 @@ 08FB7793FE84155DC02AAC07 /* Project object */ = { isa = PBXProject; buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */; - compatibilityVersion = "Xcode 2.4"; hasScannedForEncodings = 1; mainGroup = 08FB7794FE84155DC02AAC07 /* clang */; projectDirPath = ""; projectRoot = ""; - shouldCheckCompatibility = 1; targets = ( 8DD76F620486A84900D96B5E /* clang */, ); @@ -502,7 +493,6 @@ files = ( DED7D77A0A5242C7003AD0FB /* Diagnostic.cpp in Sources */, DED7D77B0A5242C7003AD0FB /* FileManager.cpp in Sources */, - DED7D7880A5242C7003AD0FB /* SourceBuffer.cpp in Sources */, DED7D7890A5242C7003AD0FB /* SourceManager.cpp in Sources */, DED7D78A0A5242C7003AD0FB /* TokenKinds.cpp in Sources */, DED7D7C20A5242E6003AD0FB /* IdentifierTable.cpp in Sources */, diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h index 85680792afc..2c9b1ce1d77 100644 --- a/clang/include/clang/Basic/Diagnostic.h +++ b/clang/include/clang/Basic/Diagnostic.h @@ -19,7 +19,6 @@ namespace llvm { namespace clang { class DiagnosticClient; - class SourceBuffer; class SourceLocation; // Import the diagnostic enums themselves. diff --git a/clang/include/clang/Basic/SourceBuffer.h b/clang/include/clang/Basic/SourceBuffer.h deleted file mode 100644 index b91e6a70ec2..00000000000 --- a/clang/include/clang/Basic/SourceBuffer.h +++ /dev/null @@ -1,85 +0,0 @@ -//===--- SourceBuffer.h - C Language Family Source Buffer -------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file was developed by Chris Lattner and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines the SourceBuffer interface. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_SOURCEBUFFER_H -#define LLVM_CLANG_SOURCEBUFFER_H - -#include "llvm/Support/DataTypes.h" - -namespace llvm { -namespace clang { - -/// SourceBuffer - This interface provides simple read-only access to the raw -/// bits in a source file in a memory efficient way. In addition to basic -/// access to the characters in the file, this interface guarantees you can read -/// one character past the end of the file, and that this character will read as -/// '\0'. -class SourceBuffer { - const char *BufferStart; // Start of the buffer. - const char *BufferEnd; // End of the buffer. - - /// MustDeleteBuffer - True if we allocated this buffer. If so, the - /// destructor must know the delete[] it. - bool MustDeleteBuffer; -protected: - SourceBuffer() : MustDeleteBuffer(false) {} - void init(const char *BufStart, const char *BufEnd); - void initCopyOf(const char *BufStart, const char *BufEnd); -public: - virtual ~SourceBuffer(); - - const char *getBufferStart() const { return BufferStart; } - const char *getBufferEnd() const { return BufferEnd; } - unsigned getBufferSize() const { return BufferEnd-BufferStart; } - - /// getBufferIdentifier - Return an identifier for this buffer, typically the - /// filename it was read from. - virtual const char *getBufferIdentifier() const { - return "Unknown buffer"; - } - - /// getFile - Open the specified file as a SourceBuffer, returning a new - /// SourceBuffer if successful, otherwise returning null. If FileSize is - /// specified, this means that the client knows that the file exists and that - /// it has the specified size. - static SourceBuffer *getFile(const char *FilenameStart, unsigned FnSize, - int64_t FileSize = -1); - - /// getMemBuffer - Open the specified memory range as a SourceBuffer. Note - /// that EndPtr[0] must be a null byte and be accessible! - 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 = ""); - - /// getNewUninitMemBuffer - Allocate a new SourceBuffer of the specified size - /// that is not initialized. Note that the caller should initialize the - /// memory allocated by this method. The memory is owned by the SourceBuffer - /// object. - static SourceBuffer *getNewUninitMemBuffer(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(); -}; - -} // end namespace clang -} // end namespace llvm - -#endif diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index 2967ebe85c8..ba39d214b55 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -20,9 +20,10 @@ #include <list> namespace llvm { +class MemoryBuffer; + namespace clang { -class SourceBuffer; class SourceManager; class FileEntry; class IdentifierTokenInfo; @@ -31,11 +32,11 @@ class IdentifierTokenInfo; /// namespace SrcMgr { /// FileInfo - Once instance of this struct is kept for every file loaded or - /// used. This object owns the SourceBuffer object. + /// used. This object owns the MemoryBuffer object. struct FileInfo { /// Buffer - The actual buffer containing the characters from the input /// file. - const SourceBuffer *Buffer; + const MemoryBuffer *Buffer; /// SourceLineCache - A new[]'d array of offsets for each source line. This /// is lazily computed. @@ -62,7 +63,7 @@ namespace SrcMgr { /// For the primary translation unit, it comes from SourceLocation() aka 0. /// /// There are three types of FileID's: - /// 1. Normal SourceBuffer (file). These are represented by a "InfoRec *", + /// 1. Normal MemoryBuffer (file). These are represented by a "InfoRec *", /// describing the source file, and a Chunk number, which factors into /// the SourceLocation's offset from the start of the buffer. /// 2. Macro Expansions. These indicate that the logical location is @@ -141,7 +142,7 @@ namespace SrcMgr { /// SourceManager - This file handles loading and caching of source files into -/// memory. This object owns the SourceBuffer objects for all of the loaded +/// memory. This object owns the MemoryBuffer objects for all of the loaded /// files and assigns unique FileID's for each unique #include chain. /// /// The SourceManager can be queried for information about SourceLocation @@ -186,8 +187,8 @@ public: /// createFileIDForMemBuffer - Create a new FileID that represents the /// specified memory buffer. This does no caching of the buffer and takes - /// ownership of the SourceBuffer, so only pass a SourceBuffer to this once. - unsigned createFileIDForMemBuffer(const SourceBuffer *Buffer) { + /// ownership of the MemoryBuffer, so only pass a MemoryBuffer to this once. + unsigned createFileIDForMemBuffer(const MemoryBuffer *Buffer) { return createFileID(createMemBufferInfoRec(Buffer), SourceLocation()); } @@ -199,7 +200,7 @@ public: /// getBuffer - Return the buffer for the specified FileID. /// - const SourceBuffer *getBuffer(unsigned FileID) const { + const MemoryBuffer *getBuffer(unsigned FileID) const { return getFileInfo(FileID)->Buffer; } @@ -224,7 +225,7 @@ public: } /// getCharacterData - Return a pointer to the start of the specified location - /// in the appropriate SourceBuffer. + /// in the appropriate MemoryBuffer. const char *getCharacterData(SourceLocation SL) const; /// getColumnNumber - Return the column # for the specified include position. @@ -234,7 +235,7 @@ public: /// getLineNumber - Given a SourceLocation, return the physical line number /// for the position indicated. This requires building and caching a table of - /// line offsets for the SourceBuffer, so this is not cheap: use only when + /// line offsets for the MemoryBuffer, so this is not cheap: use only when /// about to emit a diagnostic. unsigned getLineNumber(SourceLocation Loc); @@ -297,7 +298,7 @@ private: /// createMemBufferInfoRec - Create a new info record for the specified memory /// buffer. This does no caching. - const SrcMgr::InfoRec *createMemBufferInfoRec(const SourceBuffer *Buffer); + const SrcMgr::InfoRec *createMemBufferInfoRec(const MemoryBuffer *Buffer); const SrcMgr::FileIDInfo *getFIDInfo(unsigned FileID) const { assert(FileID-1 < FileIDs.size() && "Invalid FileID!"); diff --git a/clang/include/clang/Lex/Lexer.h b/clang/include/clang/Lex/Lexer.h index 4f25c3712a6..0d77372410f 100644 --- a/clang/include/clang/Lex/Lexer.h +++ b/clang/include/clang/Lex/Lexer.h @@ -21,10 +21,11 @@ #include <vector> namespace llvm { +class MemoryBuffer; + namespace clang { class Diagnostic; class Preprocessor; -class SourceBuffer; /// Lexer - This provides a simple interface that turns a text buffer into a /// stream of tokens. This provides no support for file reading or buffering, @@ -34,7 +35,7 @@ class Lexer { //===--------------------------------------------------------------------===// // Constant configuration values for this lexer. const char * const BufferEnd; // End of the buffer. - const SourceBuffer *InputFile; // The file we are reading from. + const MemoryBuffer *InputFile; // The file we are reading from. unsigned CurFileID; // FileID for the current input file. Preprocessor &PP; // Preprocessor object controlling lexing. LangOptions Features; // Features enabled by this language (cache). @@ -95,9 +96,9 @@ public: /// Lexer constructor - Create a new lexer object for the specified buffer /// with the specified preprocessor managing the lexing process. This lexer - /// assumes that the specified SourceBuffer and Preprocessor objects will + /// assumes that the specified MemoryBuffer and Preprocessor objects will /// outlive it, but doesn't take ownership of either pointer. - Lexer(const SourceBuffer *InBuffer, unsigned CurFileID, Preprocessor &PP, + Lexer(const MemoryBuffer *InBuffer, unsigned CurFileID, Preprocessor &PP, const char *BufStart = 0, const char *BufEnd = 0); /// getFeatures - Return the language features currently enabled. NOTE: this diff --git a/clang/include/clang/Lex/ScratchBuffer.h b/clang/include/clang/Lex/ScratchBuffer.h index 1d58f81078b..a78487957b8 100644 --- a/clang/include/clang/Lex/ScratchBuffer.h +++ b/clang/include/clang/Lex/ScratchBuffer.h @@ -17,7 +17,6 @@ namespace llvm { namespace clang { class SourceManager; - class SourceBuffer; class SourceLocation; /// ScratchBuffer - This class exposes a simple interface for the dynamic @@ -31,13 +30,13 @@ class ScratchBuffer { public: ScratchBuffer(SourceManager &SM); - /// getToken - Splat the specified text into a temporary SourceBuffer and + /// getToken - Splat the specified text into a temporary MemoryBuffer 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 getToken(const char *Buf, unsigned Len, SourceLocation SourceLoc); - /// getToken - Splat the specified text into a temporary SourceBuffer and + /// getToken - Splat the specified text into a temporary MemoryBuffer 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. |

