llvm.org GIT mirror llvm / 37db5d6
Remove the MappedFile::charBase member, rename base -> getBase() and make getBase() return a const-correct pointer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49025 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
3 changed file(s) with 11 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
2424
2525 /// This class provides an abstraction for a memory mapped file in the
2626 /// operating system's filesystem. It provides platform independent operations
27 /// for mapping a file into memory for both read access.
27 /// for mapping a file into memory for read access.
2828 class MappedFile {
2929 sys::PathWithStatus Path; ///< Path to the file.
3030 void *BasePtr; ///< Pointer to the base memory address
4343 /// This function determines if the file is currently mapped or not.
4444 bool isMapped() const { return BasePtr != 0; }
4545
46 /// This function returns a void* pointer to the base address of the file
46 /// getBase - Returns a const void* pointer to the base address of the file
4747 /// mapping. This is the memory address of the first byte in the file.
48 /// Note that although a non-const pointer is returned, the memory might
49 /// not actually be writable, depending on the MappingOptions used when
50 /// the MappedFile was opened.
51 void* base() const { return BasePtr; }
52
53 /// This function returns a char* pointer to the base address of the file
54 /// mapping. This is the memory address of the first byte in the file.
55 /// Note that although a non-const pointer is returned, the memory might
56 /// not actually be writable, depending on the MappingOptions used when
57 /// the MappedFile was opened.
58 char* charBase() const { return reinterpret_cast(BasePtr); }
48 const void *getBase() const { return BasePtr; }
5949
6050 /// This function returns a reference to the sys::Path object kept by the
6151 /// MappedFile object. This contains the path to the file that is or
2727 ///
2828 void SourceFile::calculateLineOffsets() const {
2929 assert(LineOffset.empty() && "Line offsets already computed!");
30 const char *BufPtr = File.charBase();
30 const char *BufPtr = (const char *)File.getBase();
3131 const char *FileStart = BufPtr;
3232 const char *FileEnd = FileStart + File.size();
3333 do {
6060 if (LineNo >= LineOffset.size()) return;
6161
6262 // Otherwise, they are asking for a valid line, which we can fulfill.
63 LineStart = File.charBase()+LineOffset[LineNo];
63 LineStart = (const char *)File.getBase()+LineOffset[LineNo];
6464
6565 if (LineNo+1 < LineOffset.size())
66 LineEnd = File.charBase()+LineOffset[LineNo+1];
66 LineEnd = (const char *)File.getBase()+LineOffset[LineNo+1];
6767 else
68 LineEnd = File.charBase() + File.size();
68 LineEnd = (const char *)File.getBase() + File.size();
6969
7070 // If the line ended with a newline, strip it off.
7171 while (LineEnd != LineStart && (LineEnd[-1] == '\n' || LineEnd[-1] == '\r'))
172172
173173 // If this file is not an exact multiple of the system page size (common
174174 // case), then the OS has zero terminated the buffer for us.
175 if ((Size & (PageSize-1))) {
176 init(File.charBase(), File.charBase()+Size);
175 const char *FileBase = static_cast(File.getBase());
176 if ((Size & (PageSize-1)) != 0) {
177 init(FileBase, FileBase+Size);
177178 } else {
178179 // Otherwise, we allocate a new memory buffer and copy the data over
179 initCopyOf(File.charBase(), File.charBase()+Size);
180 initCopyOf(FileBase, FileBase+Size);
180181
181182 // No need to keep the file mapped any longer.
182183 File.unmap();