r215448 - Use StringRef instead of MemoryBuffer&.

Rafael Espindola rafael.espindola at gmail.com
Tue Aug 12 08:46:24 PDT 2014


Author: rafael
Date: Tue Aug 12 10:46:24 2014
New Revision: 215448

URL: http://llvm.org/viewvc/llvm-project?rev=215448&view=rev
Log:
Use StringRef instead of MemoryBuffer&.

This code doesn't care where the data it is processing comes from, so a
StringRef is probably the most natural interface.

Modified:
    cfe/trunk/include/clang/Lex/Lexer.h
    cfe/trunk/lib/Frontend/ASTUnit.cpp
    cfe/trunk/lib/Frontend/FrontendActions.cpp
    cfe/trunk/lib/Lex/Lexer.cpp

Modified: cfe/trunk/include/clang/Lex/Lexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Lexer.h?rev=215448&r1=215447&r2=215448&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/trunk/include/clang/Lex/Lexer.h Tue Aug 12 10:46:24 2014
@@ -405,7 +405,7 @@ public:
   /// \returns The offset into the file where the preamble ends and the rest
   /// of the file begins along with a boolean value indicating whether 
   /// the preamble ends at the beginning of a new line.
-  static std::pair<unsigned, bool> ComputePreamble(llvm::MemoryBuffer &Buffer,
+  static std::pair<unsigned, bool> ComputePreamble(StringRef Buffer,
                                                    const LangOptions &LangOpts,
                                                    unsigned MaxLines = 0);
 

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=215448&r1=215447&r2=215448&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Tue Aug 12 10:46:24 2014
@@ -1254,8 +1254,8 @@ ASTUnit::ComputePreamble(CompilerInvocat
   }
 
   return std::make_pair(
-      Buffer,
-      Lexer::ComputePreamble(*Buffer, *Invocation.getLangOpts(), MaxLines));
+      Buffer, Lexer::ComputePreamble(Buffer->getBuffer(),
+                                     *Invocation.getLangOpts(), MaxLines));
 }
 
 ASTUnit::PreambleFileHash

Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=215448&r1=215447&r2=215448&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Tue Aug 12 10:46:24 2014
@@ -686,7 +686,8 @@ void PrintPreambleAction::ExecuteAction(
   llvm::MemoryBuffer *Buffer
       = CI.getFileManager().getBufferForFile(getCurrentFile());
   if (Buffer) {
-    unsigned Preamble = Lexer::ComputePreamble(*Buffer, CI.getLangOpts()).first;
+    unsigned Preamble =
+        Lexer::ComputePreamble(Buffer->getBuffer(), CI.getLangOpts()).first;
     llvm::outs().write(Buffer->getBufferStart(), Preamble);
     delete Buffer;
   }

Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=215448&r1=215447&r2=215448&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Tue Aug 12 10:46:24 2014
@@ -540,7 +540,7 @@ namespace {
   };
 }
 
-std::pair<unsigned, bool> Lexer::ComputePreamble(llvm::MemoryBuffer &Buffer,
+std::pair<unsigned, bool> Lexer::ComputePreamble(StringRef Buffer,
                                                  const LangOptions &LangOpts,
                                                  unsigned MaxLines) {
   // Create a lexer starting at the beginning of the file. Note that we use a
@@ -548,8 +548,8 @@ std::pair<unsigned, bool> Lexer::Compute
   // position within the file.
   const unsigned StartOffset = 1;
   SourceLocation FileLoc = SourceLocation::getFromRawEncoding(StartOffset);
-  Lexer TheLexer(FileLoc, LangOpts, Buffer.getBufferStart(),
-                 Buffer.getBufferStart(), Buffer.getBufferEnd());
+  Lexer TheLexer(FileLoc, LangOpts, Buffer.begin(), Buffer.begin(),
+                 Buffer.end());
   TheLexer.SetCommentRetentionState(true);
 
   // StartLoc will differ from FileLoc if there is a BOM that was skipped.
@@ -563,9 +563,9 @@ std::pair<unsigned, bool> Lexer::Compute
 
   unsigned MaxLineOffset = 0;
   if (MaxLines) {
-    const char *CurPtr = Buffer.getBufferStart();
+    const char *CurPtr = Buffer.begin();
     unsigned CurLine = 0;
-    while (CurPtr != Buffer.getBufferEnd()) {
+    while (CurPtr != Buffer.end()) {
       char ch = *CurPtr++;
       if (ch == '\n') {
         ++CurLine;
@@ -573,8 +573,8 @@ std::pair<unsigned, bool> Lexer::Compute
           break;
       }
     }
-    if (CurPtr != Buffer.getBufferEnd())
-      MaxLineOffset = CurPtr - Buffer.getBufferStart();
+    if (CurPtr != Buffer.end())
+      MaxLineOffset = CurPtr - Buffer.begin();
   }
 
   do {





More information about the cfe-commits mailing list