]> granicus.if.org Git - clang/commitdiff
make "ContentCache::Buffer" mutable to avoid a const_cast.
authorChris Lattner <sabre@nondot.org>
Sat, 17 Jan 2009 03:54:16 +0000 (03:54 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 17 Jan 2009 03:54:16 +0000 (03:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62403 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/SourceManager.h
lib/Basic/SourceManager.cpp

index 9a67627485c6069ed19eb503c8fa434cb42a7d4b..4db38017cc4d180a706e677200e45dbe444e3de8 100644 (file)
@@ -51,24 +51,24 @@ namespace SrcMgr {
   class ContentCache {
     /// Buffer - The actual buffer containing the characters from the input
     /// file.  This is owned by the ContentCache object.
-    const llvm::MemoryBuffer* Buffer;
+    mutable const llvm::MemoryBuffer *Buffer;
 
   public:
     /// Reference to the file entry.  This reference does not own
     /// the FileEntry object.  It is possible for this to be NULL if
     /// the ContentCache encapsulates an imaginary text buffer.
-    const FileEntryEntry;
+    const FileEntry *Entry;
     
     /// SourceLineCache - A new[]'d array of offsets for each source line.  This
     /// is lazily computed.  This is owned by the ContentCache object.
-    unsignedSourceLineCache;
+    unsigned *SourceLineCache;
     
     /// NumLines - The number of lines in this ContentCache.  This is only valid
     /// if SourceLineCache is non-null.
     unsigned NumLines;
     
     /// getBuffer - Returns the memory buffer for the associated content.
-    const llvm::MemoryBuffergetBuffer() const;
+    const llvm::MemoryBuffer *getBuffer() const;
     
     /// getSize - Returns the size of the content encapsulated by this
     ///  ContentCache. This can be the size of the source file or the size of an
@@ -81,12 +81,12 @@ namespace SrcMgr {
     ///  instantiated.
     unsigned getSizeBytesMapped() const;
     
-    void setBuffer(const llvm::MemoryBufferB) {
+    void setBuffer(const llvm::MemoryBuffer *B) {
       assert(!Buffer && "MemoryBuffer already set.");
       Buffer = B;
     }
         
-    ContentCache(const FileEntrye = NULL)
+    ContentCache(const FileEntry *e = NULL)
       : Buffer(NULL), Entry(e), SourceLineCache(NULL), NumLines(0) {}
 
     ~ContentCache();
@@ -94,7 +94,7 @@ namespace SrcMgr {
     /// The copy ctor does not allow copies where source object has either
     ///  a non-NULL Buffer or SourceLineCache.  Ownership of allocated memory
     ///  is not transfered, so this is a logical error.
-    ContentCache(const ContentCacheRHS) : Buffer(NULL),SourceLineCache(NULL) {
+    ContentCache(const ContentCache &RHS) : Buffer(NULL),SourceLineCache(NULL) {
       Entry = RHS.Entry;
 
       assert (RHS.Buffer == NULL && RHS.SourceLineCache == NULL
@@ -104,16 +104,16 @@ namespace SrcMgr {
     }
     
     /// Emit - Emit this ContentCache to Bitcode.
-    void Emit(llvm::SerializerS) const;
+    void Emit(llvm::Serializer &S) const;
     
     /// ReadToSourceManager - Reconstitute a ContentCache from Bitcode
     //   and store it in the specified SourceManager.
-    static void ReadToSourceManager(llvm::Deserializer& D, SourceManager& SMgr,
-                                    FileManager* FMgr, std::vector<char>&  Buf);
+    static void ReadToSourceManager(llvm::Deserializer &D, SourceManager &SM,
+                                    FileManager *FMgr, std::vector<char> &Buf);
     
   private:
     // Disable assignments.
-    ContentCacheoperator=(const ContentCache& RHS);    
+    ContentCache &operator=(const ContentCache& RHS);    
   };  
 
   /// FileIDInfo - Information about a FileID, basically just the logical file
@@ -150,7 +150,7 @@ namespace SrcMgr {
     unsigned FileCharacteristic : 2;
     
     /// Content - Information about the source buffer itself.
-    const ContentCacheContent;
+    const ContentCache *Content;
 
   public:
     /// get - Return a FileIDInfo object.
index fa0a9bb565adf34199406698dc621ba6581de47a..1240262007e3bb3e9e1c53c31a993664b7364a66 100644 (file)
@@ -56,9 +56,7 @@ const llvm::MemoryBuffer* ContentCache::getBuffer() const {
   if (!Buffer && Entry) {
     // FIXME: Should we support a way to not have to do this check over
     //   and over if we cannot open the file?
-    // FIXME: This const_cast is ugly.  Should we make getBuffer() non-const?
-    const_cast<ContentCache*>(this)->Buffer = 
-      MemoryBuffer::getFile(Entry->getName(), 0, Entry->getSize());
+    Buffer = MemoryBuffer::getFile(Entry->getName(), 0, Entry->getSize());
   }
 #endif
   return Buffer;