diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-07-26 21:36:20 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-07-26 21:36:20 +0000 |
commit | f4f6c9db68465b886ec2e596feaa6ecc782395a4 (patch) | |
tree | ca67e8ec2c873019829102d882a29f56120b98fb /include/clang/Basic/SourceManager.h | |
parent | 6bdeb4024a7422bbd61fad403383af76b0581d45 (diff) |
Introduce basic support for loading a precompiled preamble while
reparsing an ASTUnit. When saving a preamble, create a buffer larger
than the actual file we're working with but fill everything from the
end of the preamble to the end of the file with spaces (so the lexer
will quickly skip them). When we load the file, create a buffer of the
same size, filling it with the file and then spaces. Then, instruct
the lexer to start lexing after the preamble, therefore continuing the
parse from the spot where the preamble left off.
It's now possible to perform a simple preamble build + parse (+
reparse) with ASTUnit. However, one has to disable a bunch of checking
in the PCH reader to do so. That part isn't committed; it will likely
be handled with some other kind of flag (e.g., -fno-validate-pch).
As part of this, fix some issues with null termination of the memory
buffers created for the preamble; we were trying to explicitly
NULL-terminate them, even though they were also getting implicitly
NULL terminated, leading to excess warnings about NULL characters in
source files.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109445 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/SourceManager.h')
-rw-r--r-- | include/clang/Basic/SourceManager.h | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 5d98fb9253..b6a1ac4492 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -53,10 +53,17 @@ namespace SrcMgr { /// ContentCache - Once instance of this struct is kept for every file /// loaded or used. This object owns the MemoryBuffer object. class ContentCache { + enum CCFlags { + /// \brief Whether the buffer is invalid. + InvalidFlag = 0x01, + /// \brief Whether the buffer should not be freed on destruction. + DoNotFreeFlag = 0x02 + }; + /// Buffer - The actual buffer containing the characters from the input /// file. This is owned by the ContentCache object. - /// The bit indicates whether the buffer is invalid. - mutable llvm::PointerIntPair<const llvm::MemoryBuffer *, 1, bool> Buffer; + /// The bits indicate indicates whether the buffer is invalid. + mutable llvm::PointerIntPair<const llvm::MemoryBuffer *, 2> Buffer; public: /// Reference to the file entry. This reference does not own @@ -106,8 +113,18 @@ namespace SrcMgr { /// \brief Replace the existing buffer (which will be deleted) /// with the given buffer. - void replaceBuffer(const llvm::MemoryBuffer *B); + void replaceBuffer(const llvm::MemoryBuffer *B, bool DoNotFree = false); + /// \brief Determine whether the buffer itself is invalid. + bool isBufferInvalid() const { + return Buffer.getInt() & InvalidFlag; + } + + /// \brief Determine whether the buffer should be freed. + bool shouldFreeBuffer() const { + return (Buffer.getInt() & DoNotFreeFlag) == 0; + } + ContentCache(const FileEntry *Ent = 0) : Buffer(0, false), Entry(Ent), SourceLineCache(0), NumLines(0) {} @@ -490,9 +507,13 @@ public: /// \param Buffer the memory buffer whose contents will be used as the /// data in the given source file. /// + /// \param DoNotFree If true, then the buffer will not be freed when the + /// source manager is destroyed. + /// /// \returns true if an error occurred, false otherwise. bool overrideFileContents(const FileEntry *SourceFile, - const llvm::MemoryBuffer *Buffer); + const llvm::MemoryBuffer *Buffer, + bool DoNotFree = false); //===--------------------------------------------------------------------===// // FileID manipulation methods. |