[PATCH] D89406: clang/{Format,Rewrite}: Stop using SourceManager::getBuffer, NFC
Duncan P. N. Exon Smith via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 14 10:02:49 PDT 2020
dexonsmith created this revision.
dexonsmith added a reviewer: arphaman.
Herald added a subscriber: ributzka.
dexonsmith requested review of this revision.
Update clang/lib/Format and clang/lib/Rewrite to use a `MemoryBufferRef`
from `getBufferOrFake` instead of `MemoryBuffer*` from `getBuffer`.
No functionality change here, since the call sites weren't checking if
the buffer was valid.
https://reviews.llvm.org/D89406
Files:
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Rewrite/HTMLRewrite.cpp
Index: clang/lib/Rewrite/HTMLRewrite.cpp
===================================================================
--- clang/lib/Rewrite/HTMLRewrite.cpp
+++ clang/lib/Rewrite/HTMLRewrite.cpp
@@ -107,9 +107,9 @@
void html::EscapeText(Rewriter &R, FileID FID,
bool EscapeSpaces, bool ReplaceTabs) {
- const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(FID);
- const char* C = Buf->getBufferStart();
- const char* FileEnd = Buf->getBufferEnd();
+ llvm::MemoryBufferRef Buf = R.getSourceMgr().getBufferOrFake(FID);
+ const char* C = Buf.getBufferStart();
+ const char* FileEnd = Buf.getBufferEnd();
assert (C <= FileEnd);
@@ -226,9 +226,9 @@
void html::AddLineNumbers(Rewriter& R, FileID FID) {
- const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(FID);
- const char* FileBeg = Buf->getBufferStart();
- const char* FileEnd = Buf->getBufferEnd();
+ llvm::MemoryBufferRef Buf = R.getSourceMgr().getBufferOrFake(FID);
+ const char* FileBeg = Buf.getBufferStart();
+ const char* FileEnd = Buf.getBufferEnd();
const char* C = FileBeg;
RewriteBuffer &RB = R.getEditBuffer(FID);
@@ -274,9 +274,9 @@
void html::AddHeaderFooterInternalBuiltinCSS(Rewriter &R, FileID FID,
StringRef title) {
- const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(FID);
- const char* FileStart = Buf->getBufferStart();
- const char* FileEnd = Buf->getBufferEnd();
+ llvm::MemoryBufferRef Buf = R.getSourceMgr().getBufferOrFake(FID);
+ const char* FileStart = Buf.getBufferStart();
+ const char* FileEnd = Buf.getBufferEnd();
SourceLocation StartLoc = R.getSourceMgr().getLocForStartOfFile(FID);
SourceLocation EndLoc = StartLoc.getLocWithOffset(FileEnd-FileStart);
Index: clang/lib/Format/FormatTokenLexer.cpp
===================================================================
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -763,7 +763,7 @@
unsigned FirstInLineOffset;
std::tie(ID, FirstInLineOffset) = SourceMgr.getDecomposedLoc(
Tokens[FirstInLineIndex]->getStartOfNonWhitespace());
- StringRef Buffer = SourceMgr.getBuffer(ID)->getBuffer();
+ StringRef Buffer = SourceMgr.getBufferOrFake(ID).getBuffer();
// Calculate the offset of the start of the current line.
auto LineOffset = Buffer.rfind('\n', FirstInLineOffset);
if (LineOffset == StringRef::npos) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89406.298174.patch
Type: text/x-patch
Size: 2430 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201014/0987ca7b/attachment.bin>
More information about the cfe-commits
mailing list