]> granicus.if.org Git - clang/commitdiff
Added Lexer::getBufferEnd().
authorAlexander Kornienko <alexfh@google.com>
Tue, 4 Jun 2013 16:58:03 +0000 (16:58 +0000)
committerAlexander Kornienko <alexfh@google.com>
Tue, 4 Jun 2013 16:58:03 +0000 (16:58 +0000)
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

include/clang/Lex/Lexer.h
lib/Rewrite/Core/HTMLRewrite.cpp

index cb4f57fb9cf4e0084db304efbe0f694ccdf50f04..9534c88355e14190ddf8c8ffb2edee3d004191ff 100644 (file)
@@ -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.
index 2d279f1ee4a13766aec169e43084495875eb30d1..2a5442afcd5122bbc50bc495e35ea58d24f9b55d 100644 (file)
@@ -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.