aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Basic/SourceManager.h
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-03-16 05:20:39 +0000
committerDouglas Gregor <dgregor@apple.com>2010-03-16 05:20:39 +0000
commit50f6af7a6d6951a63f3da7d4c5a7d3965bf73b63 (patch)
tree28f78b0fe61c0b7a80cf3ccf0d1c39a884986120 /include/clang/Basic/SourceManager.h
parent36c35ba0aca641e60e5dbee8efbc620c08b9bd61 (diff)
Introduce optional "Invalid" parameters to routines that invoke the
SourceManager's getBuffer() and, therefore, could fail, along with Preprocessor::getSpelling(). Use the Invalid parameters in the literal parsers (string, floating point, integral, character) to make them robust against errors that stem from, e.g., PCH files that are not consistent with the underlying file system. I still need to audit every use caller to all of these routines, to determine which ones need specific handling of error conditions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98608 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/SourceManager.h')
-rw-r--r--include/clang/Basic/SourceManager.h33
1 files changed, 22 insertions, 11 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h
index 5e3cfd2b3c..9657ee4f1a 100644
--- a/include/clang/Basic/SourceManager.h
+++ b/include/clang/Basic/SourceManager.h
@@ -417,7 +417,11 @@ public:
unsigned Offset = 0);
/// \brief Retrieve the memory buffer associated with the given file.
- const llvm::MemoryBuffer *getMemoryBufferForFile(const FileEntry *File);
+ ///
+ /// \param Invalid If non-NULL, will be set \c true if an error
+ /// occurs while retrieving the memory buffer.
+ const llvm::MemoryBuffer *getMemoryBufferForFile(const FileEntry *File,
+ bool *Invalid = 0);
/// \brief Override the contents of the given source file by providing an
/// already-allocated buffer.
@@ -438,8 +442,9 @@ 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.
- const llvm::MemoryBuffer *getBuffer(FileID FID) const {
- return getSLocEntry(FID).getFile().getContentCache()->getBuffer(Diag);
+ const llvm::MemoryBuffer *getBuffer(FileID FID, bool *Invalid = 0) const {
+ return getSLocEntry(FID).getFile().getContentCache()->getBuffer(Diag,
+ Invalid);
}
/// getFileEntryForID - Returns the FileEntry record for the provided FileID.
@@ -571,31 +576,37 @@ public:
/// getCharacterData - Return a pointer to the start of the specified location
/// in the appropriate spelling MemoryBuffer.
- const char *getCharacterData(SourceLocation SL) const;
+ ///
+ /// \param Invalid If non-NULL, will be set \c true if an error occurs.
+ const char *getCharacterData(SourceLocation SL, bool *Invalid = 0) const;
/// getColumnNumber - Return the column # for the specified file position.
/// This is significantly cheaper to compute than the line number. This
/// returns zero if the column number isn't known. This may only be called on
/// a file sloc, so you must choose a spelling or instantiation location
/// before calling this method.
- unsigned getColumnNumber(FileID FID, unsigned FilePos) const;
- unsigned getSpellingColumnNumber(SourceLocation Loc) const;
- unsigned getInstantiationColumnNumber(SourceLocation Loc) const;
+ unsigned getColumnNumber(FileID FID, unsigned FilePos,
+ bool *Invalid = 0) const;
+ unsigned getSpellingColumnNumber(SourceLocation Loc,
+ bool *Invalid = 0) const;
+ unsigned getInstantiationColumnNumber(SourceLocation Loc,
+ bool *Invalid = 0) const;
/// getLineNumber - Given a SourceLocation, return the spelling line number
/// for the position indicated. This requires building and caching a table of
/// line offsets for the MemoryBuffer, so this is not cheap: use only when
/// about to emit a diagnostic.
- unsigned getLineNumber(FileID FID, unsigned FilePos) const;
+ unsigned getLineNumber(FileID FID, unsigned FilePos, bool *Invalid = 0) const;
- unsigned getInstantiationLineNumber(SourceLocation Loc) const;
- unsigned getSpellingLineNumber(SourceLocation Loc) const;
+ unsigned getInstantiationLineNumber(SourceLocation Loc,
+ bool *Invalid = 0) const;
+ unsigned getSpellingLineNumber(SourceLocation Loc, bool *Invalid = 0) const;
/// Return the filename or buffer identifier of the buffer the location is in.
/// Note that this name does not respect #line directives. Use getPresumedLoc
/// for normal clients.
- const char *getBufferName(SourceLocation Loc) const;
+ const char *getBufferName(SourceLocation Loc, bool *Invalid = 0) const;
/// getFileCharacteristic - return the file characteristic of the specified
/// source location, indicating whether this is a normal file, a system