From: Alexander Kornienko Date: Tue, 4 Jun 2013 16:58:03 +0000 (+0000) Subject: Added Lexer::getBufferEnd(). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=49e1d9814a34e4024a347c2fce8e9567c40e6bf5;p=clang 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183236 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Lex/Lexer.h b/include/clang/Lex/Lexer.h index cb4f57fb9c..9534c88355 100644 --- a/include/clang/Lex/Lexer.h +++ b/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/lib/Rewrite/Core/HTMLRewrite.cpp b/lib/Rewrite/Core/HTMLRewrite.cpp index 2d279f1ee4..2a5442afcd 100644 --- a/lib/Rewrite/Core/HTMLRewrite.cpp +++ b/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.