aboutsummaryrefslogtreecommitdiff
path: root/lib/Rewrite/HTMLRewrite.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-03-15 22:54:52 +0000
committerDouglas Gregor <dgregor@apple.com>2010-03-15 22:54:52 +0000
commitaea67dbd653a2dd6dd5cc2159279e81e855b2482 (patch)
treebd96a24447cf5a504d84556ed129f6366f2fae2d /lib/Rewrite/HTMLRewrite.cpp
parent37cafb077ad5b170acae77e566638603011ef4c0 (diff)
Introduce a new BufferResult class to act as the return type of
SourceManager's getBuffer() (and similar) operations. This abstract can be used to force callers to cope with errors in getBuffer(), such as missing files and changed files. Fix a bunch of callers to use the new interface. Add some very basic checks for file consistency (file size, modification time) into ContentCache::getBuffer(), although these checks don't help much until we've updated the main callers (e.g., SourceManager::getSpelling()). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98585 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Rewrite/HTMLRewrite.cpp')
-rw-r--r--lib/Rewrite/HTMLRewrite.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp
index 342b0e6ef5..cf1c779b3e 100644
--- a/lib/Rewrite/HTMLRewrite.cpp
+++ b/lib/Rewrite/HTMLRewrite.cpp
@@ -43,8 +43,18 @@ void html::HighlightRange(Rewriter &R, SourceLocation B, SourceLocation E,
// Include the whole end token in the range.
EOffset += Lexer::MeasureTokenLength(E, R.getSourceMgr(), R.getLangOpts());
+ llvm::StringRef FileName;
+ std::string ErrorStr;
+ const char *BufferStart = SM.getBufferData(FID, FileName, ErrorStr).first;
+ if (!BufferStart) {
+ // FIXME: Add a diagnostic object somewhere?
+ fprintf(stderr, "error: cannot open file '%s': %s\n",
+ FileName.str().c_str(), ErrorStr.c_str());
+ return;
+ }
+
HighlightRange(R.getEditBuffer(FID), BOffset, EOffset,
- SM.getBufferData(FID).first, StartTag, EndTag);
+ BufferStart, StartTag, EndTag);
}
/// HighlightRange - This is the same as the above method, but takes