aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Basic/SourceManager.h
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-01-06 01:55:26 +0000
committerTed Kremenek <kremenek@apple.com>2009-01-06 01:55:26 +0000
commitc16c208e8519476d838ad11fffc8e0ecea50550d (patch)
treecb1a831ffc1654d7f9136338925b6ba4033721b2 /include/clang/Basic/SourceManager.h
parent1e5f3ebb2982f8d7e414d5fc4808000b941563cc (diff)
Misc changes to SourceManager::ContentCache:
- 'Buffer' is now private and must be accessed via 'getBuffer()'. This paves the way for lazily mapping in source files on demand. - Added 'getSize()' (which gets the size of the content without necessarily accessing the MemBuffer) and 'getSizeBytesMapped()'. - Modifed SourceManager to use these new methods. This reduces the number of places that actually access the MemBuffer object for a file to those that actually look at the character data. These changes result in no performance change for -fsyntax-only on Cocoa.h. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61782 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/SourceManager.h')
-rw-r--r--include/clang/Basic/SourceManager.h36
1 files changed, 28 insertions, 8 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h
index 7d27a6ad59..175c40488c 100644
--- a/include/clang/Basic/SourceManager.h
+++ b/include/clang/Basic/SourceManager.h
@@ -48,16 +48,17 @@ namespace SrcMgr {
/// ContentCache - Once instance of this struct is kept for every file
/// loaded or used. This object owns the MemoryBuffer object.
- struct ContentCache {
+ class ContentCache {
+ /// Buffer - The actual buffer containing the characters from the input
+ /// file. This is owned by the ContentCache object.
+ 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 FileEntry* Entry;
- /// Buffer - The actual buffer containing the characters from the input
- /// file. This is owned by the ContentCache object.
- const llvm::MemoryBuffer* Buffer;
-
/// SourceLineCache - A new[]'d array of offsets for each source line. This
/// is lazily computed. This is owned by the ContentCache object.
unsigned* SourceLineCache;
@@ -65,9 +66,28 @@ namespace SrcMgr {
/// 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::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
+ /// arbitrary scratch buffer. If the ContentCache encapsulates a source
+ /// file this size is retrieved from the file's FileEntry.
+ unsigned getSize() const;
+
+ /// getSizeBytesMapped - Returns the number of bytes actually mapped for
+ /// this ContentCache. This can be 0 if the MemBuffer was not actually
+ /// instantiated.
+ unsigned getSizeBytesMapped() const;
+
+ void setBuffer(const llvm::MemoryBuffer* B) {
+ assert(!Buffer && "MemoryBuffer already set.");
+ Buffer = B;
+ }
ContentCache(const FileEntry* e = NULL)
- : Entry(e), Buffer(NULL), SourceLineCache(NULL), NumLines(0) {}
+ : Buffer(NULL), Entry(e), SourceLineCache(NULL), NumLines(0) {}
~ContentCache();
@@ -307,7 +327,7 @@ public:
/// getBuffer - Return the buffer for the specified FileID.
///
const llvm::MemoryBuffer *getBuffer(unsigned FileID) const {
- return getContentCache(FileID)->Buffer;
+ return getContentCache(FileID)->getBuffer();
}
/// getBufferData - Return a pointer to the start and end of the character
@@ -506,7 +526,7 @@ private:
/// getContentCache - Create or return a cached ContentCache for the specified
/// file. This returns null on failure.
const SrcMgr::ContentCache* getContentCache(const FileEntry* SourceFile);
-
+
/// createMemBufferContentCache - Create a new ContentCache for the specified
/// memory buffer.
const SrcMgr::ContentCache*