Skip to content

Commit 33a35df

Browse files
committed
Added Lexer::getBufferEnd().
Summary: There's Lexer::getBufferStart(), and we need getBufferEnd() to access the whole input buffer in clang::format::reformat. We don't want to rely on the fact that the Lexer::BufferEnd always points to '\0', as there can be embedded '\0's as well. Reviewers: jordan_rose Reviewed By: jordan_rose CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D916 llvm-svn: 183236
1 parent f0dc11a commit 33a35df

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

clang/include/clang/Lex/Lexer.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ class Lexer : public PreprocessorLexer {
202202
/// lexer has nothing to reset to.
203203
void resetExtendedTokenMode();
204204

205-
const char *getBufferStart() const { return BufferStart; }
205+
/// Gets source code buffer.
206+
StringRef getBuffer() const {
207+
return StringRef(BufferStart, BufferEnd - BufferStart);
208+
}
206209

207210
/// ReadToEndOfLine - Read the rest of the current preprocessor line as an
208211
/// uninterpreted string. This switches the lexer out of directive mode.

clang/lib/Rewrite/Core/HTMLRewrite.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ void html::SyntaxHighlight(Rewriter &R, FileID FID, const Preprocessor &PP) {
361361
const SourceManager &SM = PP.getSourceManager();
362362
const llvm::MemoryBuffer *FromFile = SM.getBuffer(FID);
363363
Lexer L(FID, FromFile, SM, PP.getLangOpts());
364-
const char *BufferStart = L.getBufferStart();
364+
const char *BufferStart = L.getBuffer().data();
365365

366366
// Inform the preprocessor that we want to retain comments as tokens, so we
367367
// can highlight them.

0 commit comments

Comments
 (0)