From 33a35dff8305e01d15fbf881f500ac7ad1b020f1 Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Tue, 4 Jun 2013 16:58:03 +0000 Subject: [PATCH] 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 --- clang/include/clang/Lex/Lexer.h | 5 ++++- clang/lib/Rewrite/Core/HTMLRewrite.cpp | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Lex/Lexer.h b/clang/include/clang/Lex/Lexer.h index cb4f57fb9cf4..9534c88355e1 100644 --- a/clang/include/clang/Lex/Lexer.h +++ b/clang/include/clang/Lex/Lexer.h @@ -202,7 +202,10 @@ public: /// lexer has nothing to reset to. void resetExtendedTokenMode(); - const char *getBufferStart() const { return BufferStart; } + /// Gets source code buffer. + StringRef getBuffer() const { + return StringRef(BufferStart, BufferEnd - BufferStart); + } /// ReadToEndOfLine - Read the rest of the current preprocessor line as an /// uninterpreted string. This switches the lexer out of directive mode. diff --git a/clang/lib/Rewrite/Core/HTMLRewrite.cpp b/clang/lib/Rewrite/Core/HTMLRewrite.cpp index 2d279f1ee4a1..2a5442afcd51 100644 --- a/clang/lib/Rewrite/Core/HTMLRewrite.cpp +++ b/clang/lib/Rewrite/Core/HTMLRewrite.cpp @@ -361,7 +361,7 @@ void html::SyntaxHighlight(Rewriter &R, FileID FID, const Preprocessor &PP) { const SourceManager &SM = PP.getSourceManager(); const llvm::MemoryBuffer *FromFile = SM.getBuffer(FID); Lexer L(FID, FromFile, SM, PP.getLangOpts()); - const char *BufferStart = L.getBufferStart(); + const char *BufferStart = L.getBuffer().data(); // Inform the preprocessor that we want to retain comments as tokens, so we // can highlight them.