diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-03-16 00:35:39 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-03-16 00:35:39 +0000 |
commit | 36c35ba0aca641e60e5dbee8efbc620c08b9bd61 (patch) | |
tree | cadd5c4b1bbe39cc1d5e07b4f1940a3d2431a31e /include/clang/Basic/SourceManager.h | |
parent | f715ca12bfc9fddfde75f98a197424434428b821 (diff) |
Use SourceManager's Diagnostic object for all file-reading errors,
simplifying the SourceManager interfaces somewhat.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98598 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/SourceManager.h')
-rw-r--r-- | include/clang/Basic/SourceManager.h | 60 |
1 files changed, 11 insertions, 49 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 4d423058fb..5e3cfd2b3c 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -35,50 +35,6 @@ class FileManager; class FileEntry; class LineTableInfo; -/// \brief Class used as a return value by operations that return an -/// \c llvm::MemoryBuffer. -/// -/// Since not all source-manager routines that return buffers are guaranteed -/// to succeed, -class BufferResult { - struct FailureData; - llvm::PointerUnion<const llvm::MemoryBuffer *, FailureData *> Data; - - // Cannot copy buffer result structures - BufferResult &operator=(const BufferResult &Other); - -public: - BufferResult(const BufferResult &Other); - BufferResult(const llvm::MemoryBuffer *Buffer) : Data(Buffer) { } - BufferResult(const char *FileName, llvm::StringRef ErrorStr, - const llvm::MemoryBuffer *Buffer = 0); - ~BufferResult(); - - // \brief Determine whether there was any failure when finding this buffer. - bool isInvalid() const; - - /// \brief Retrieve the memory buffer that this result refers to. If an - /// error occurs, emits a diagnostic via the given diagnostics object and - /// may return NULL. - const llvm::MemoryBuffer *getBuffer(Diagnostic &Diags) const; - - /// \brief Retrieve the memory buffer that this result refers to. If an error - /// occurs, provides the file name and a non-empty error string to indicate - /// what failed, and may return NULL. - const llvm::MemoryBuffer *getBuffer(llvm::StringRef &FileName, - std::string &Error) const; - - // FIXME: TEMPORARY! Allows a buffer result to be interpreted as a buffer, - // which is very unsafe (but is used throughout Clang). Note that this will - // spit a diagnostic to standard error before returning the buffer. - operator const llvm::MemoryBuffer *() const; - - // FIXME: TEMPORARY! Allows a buffer result to be interpreted like a smart - // pointer to a buffer, which is very unsafe. Note that this will emit a - // diagnostic to standard error before returning the buffer. - const llvm::MemoryBuffer * operator->() const { return *this; } -}; - /// SrcMgr - Public enums and private classes that are part of the /// SourceManager implementation. /// @@ -115,8 +71,14 @@ namespace SrcMgr { /// if SourceLineCache is non-null. unsigned NumLines; - /// getBuffer - Returns the memory buffer for the associated content. - BufferResult getBuffer() const; + /// getBuffer - Returns the memory buffer for the associated content. + /// + /// \param Diag Object through which diagnostics will be emitted it the + /// buffer cannot be retrieved. + /// + /// \param Invalid If non-NULL, will be set \c true if an error occurred. + const llvm::MemoryBuffer *getBuffer(Diagnostic &Diag, + bool *Invalid = 0) 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 @@ -455,7 +417,7 @@ public: unsigned Offset = 0); /// \brief Retrieve the memory buffer associated with the given file. - BufferResult getMemoryBufferForFile(const FileEntry *File); + const llvm::MemoryBuffer *getMemoryBufferForFile(const FileEntry *File); /// \brief Override the contents of the given source file by providing an /// already-allocated buffer. @@ -476,8 +438,8 @@ public: /// getBuffer - Return the buffer for the specified FileID. If there is an /// error opening this buffer the first time, this manufactures a temporary /// buffer and returns a non-empty error string. - BufferResult getBuffer(FileID FID) const{ - return getSLocEntry(FID).getFile().getContentCache()->getBuffer(); + const llvm::MemoryBuffer *getBuffer(FileID FID) const { + return getSLocEntry(FID).getFile().getContentCache()->getBuffer(Diag); } /// getFileEntryForID - Returns the FileEntry record for the provided FileID. |