]> granicus.if.org Git - clang/commitdiff
Updated some comments.
authorTed Kremenek <kremenek@apple.com>
Tue, 30 Oct 2007 22:57:35 +0000 (22:57 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 30 Oct 2007 22:57:35 +0000 (22:57 +0000)
Disabled assignments for ContentCache.
Copy-ctor for ContentCache now has an assertion preventing it to
be copied from an object that already has an allocated buffer.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43526 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 59103caf2985f78a99ef0000966b22972a7a1a27..5c960a7d1562485890125a645a3d3239191c7f20 100644 (file)
@@ -116,11 +116,14 @@ const ContentCache* SourceManager::getContentCache(const FileEntry *FileEnt) {
 }
 
 
-/// createMemBufferInfoRec - Create a new info record for the specified memory
+/// createMemBufferInfoRec - Create a new ContentCache for the specified memory
 /// buffer.  This does no caching.
 const ContentCache*
 SourceManager::createMemBufferContentCache(const MemoryBuffer *Buffer) {
-  // Add a new info record to the MemBufferInfos list and return it.
+  // Add a new ContentCache to the MemBufferInfos list and return it.  We
+  // must default construct the object first that the instance actually
+  // stored within MemBufferInfos actually owns the Buffer, and not any
+  // temporary we would use in the call to "push_back".
   MemBufferInfos.push_back(ContentCache());
   ContentCache& Entry = const_cast<ContentCache&>(MemBufferInfos.back());
   Entry.Buffer = Buffer;
@@ -128,9 +131,9 @@ SourceManager::createMemBufferContentCache(const MemoryBuffer *Buffer) {
 }
 
 
-/// createFileID - Create a new fileID for the specified InfoRec and include
-/// position.  This works regardless of whether the InfoRec corresponds to a
-/// file or some other input source.
+/// createFileID - Create a new fileID for the specified ContentCache and 
+/// include position.  This works regardless of whether the ContentCache
+/// corresponds to a file or some other input source.
 unsigned SourceManager::createFileID(const ContentCache *File,
                                      SourceLocation IncludePos) {
   // If FileEnt is really large (e.g. it's a large .i file), we may not be able
index 9c687c3e65f06385631459610cd3389279ff615f..6392e899e35753eae2686e7844cba46a80acbb0d 100644 (file)
@@ -58,6 +58,22 @@ namespace SrcMgr {
     : Entry(e), Buffer(NULL), SourceLineCache(NULL), NumLines(0) {}
 
     ~ContentCache();
+    
+    /// 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 ContentCache& RHS) : Buffer(NULL),SourceLineCache(NULL) {
+      Entry = RHS.Entry;
+
+      assert (RHS.Buffer == NULL && RHS.SourceLineCache == NULL
+              && "Passed ContentCache object cannot own a buffer.");
+              
+      NumLines = RHS.NumLines;      
+    }
+    
+  private:
+    // Disable assignments.
+    ContentCache& operator=(const ContentCache& RHS);    
   };  
 
   /// FileIDInfo - Information about a FileID, basically just the logical file
@@ -74,9 +90,9 @@ namespace SrcMgr {
   /// This information encodes the #include chain that a token was instantiated
   /// from.
   ///
-  /// FileIDInfos contain a "InfoRec *", describing the source file, and a Chunk
-  /// number, which allows a SourceLocation to index into very large files
-  /// (those which there are not enough FilePosBits to address).
+  /// FileIDInfos contain a "ContentCache *", describing the source file, 
+  /// and a Chunk number, which allows a SourceLocation to index into very
+  /// large files (those which there are not enough FilePosBits to address).
   ///
   struct FileIDInfo {
   private:
@@ -158,12 +174,15 @@ namespace clang {
 /// etc.
 class SourceManager {
   /// FileInfos - Memoized information about all of the files tracked by this
-  /// SourceManager.
+  /// SourceManager.  This set allows us to merge ContentCache entries based
+  /// on their FileEntry*.  All ContentCache objects will thus have unique,
+  /// non-null, FileEntry pointers.  
   std::set<SrcMgr::ContentCache> FileInfos;
   
   /// MemBufferInfos - Information about various memory buffers that we have
   /// read in.  This is a list, instead of a vector, because we need pointers to
-  /// the FileInfo objects to be stable.
+  /// the FileInfo objects to be stable.  All FileEntry* within the
+  /// stored ContentCache objects are NULL, as they do not refer to a file.
   std::list<SrcMgr::ContentCache> MemBufferInfos;
   
   /// FileIDs - Information about each FileID.  FileID #0 is not valid, so all