r215391 - Change MemoryBuffer* to MemoryBuffer& parameter to Lexer::ComputePreamble

David Blaikie dblaikie at gmail.com
Mon Aug 11 15:08:06 PDT 2014


Author: dblaikie
Date: Mon Aug 11 17:08:06 2014
New Revision: 215391

URL: http://llvm.org/viewvc/llvm-project?rev=215391&view=rev
Log:
Change MemoryBuffer* to MemoryBuffer& parameter to Lexer::ComputePreamble

(dropping const from the reference as MemoryBuffer is immutable already,
so const is just redundant - and while I'd personally put const
everywhere, that's not the LLVM Way (see llvm::Type for another example
of an immutable type where "const" is omitted for brevity))

Changing the pointer argument to a reference parameter makes call sites
identical between callers with unique_ptrs or raw pointers, minimizing
the churn in a pending unique_ptr migrations.

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=215391&r1=215390&r2=215391&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/trunk/include/clang/Lex/Lexer.h Mon Aug 11 17:08:06 2014
@@ -405,9 +405,9 @@ 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(const llvm::MemoryBuffer *Buffer, const LangOptions &LangOpts,
-                  unsigned MaxLines = 0);
+  static std::pair<unsigned, bool> ComputePreamble(llvm::MemoryBuffer &Buffer,
+                                                   const LangOptions &LangOpts,
+                                                   unsigned MaxLines = 0);
 
   /// \brief Checks that the given token is the first token that occurs after
   /// the given location (this excludes comments and whitespace). Returns the

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=215391&r1=215390&r2=215391&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Mon Aug 11 17:08:06 2014
@@ -1252,10 +1252,10 @@ ASTUnit::ComputePreamble(CompilerInvocat
 
     CreatedBuffer = true;
   }
-  
-  return std::make_pair(Buffer, Lexer::ComputePreamble(Buffer,
-                                                       *Invocation.getLangOpts(),
-                                                       MaxLines));
+
+  return std::make_pair(
+      Buffer,
+      Lexer::ComputePreamble(*Buffer, *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=215391&r1=215390&r2=215391&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Mon Aug 11 17:08:06 2014
@@ -685,7 +685,7 @@ 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, 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=215391&r1=215390&r2=215391&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Mon Aug 11 17:08:06 2014
@@ -540,16 +540,16 @@ namespace {
   };
 }
 
-std::pair<unsigned, bool>
-Lexer::ComputePreamble(const llvm::MemoryBuffer *Buffer,
-                       const LangOptions &LangOpts, unsigned MaxLines) {
+std::pair<unsigned, bool> Lexer::ComputePreamble(llvm::MemoryBuffer &Buffer,
+                                                 const LangOptions &LangOpts,
+                                                 unsigned MaxLines) {
   // Create a lexer starting at the beginning of the file. Note that we use a
   // "fake" file source location at offset 1 so that the lexer will track our
   // 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.getBufferStart(),
+                 Buffer.getBufferStart(), Buffer.getBufferEnd());
   TheLexer.SetCommentRetentionState(true);
 
   // StartLoc will differ from FileLoc if there is a BOM that was skipped.
@@ -563,9 +563,9 @@ Lexer::ComputePreamble(const llvm::Memor
 
   unsigned MaxLineOffset = 0;
   if (MaxLines) {
-    const char *CurPtr = Buffer->getBufferStart();
+    const char *CurPtr = Buffer.getBufferStart();
     unsigned CurLine = 0;
-    while (CurPtr != Buffer->getBufferEnd()) {
+    while (CurPtr != Buffer.getBufferEnd()) {
       char ch = *CurPtr++;
       if (ch == '\n') {
         ++CurLine;
@@ -573,8 +573,8 @@ Lexer::ComputePreamble(const llvm::Memor
           break;
       }
     }
-    if (CurPtr != Buffer->getBufferEnd())
-      MaxLineOffset = CurPtr - Buffer->getBufferStart();
+    if (CurPtr != Buffer.getBufferEnd())
+      MaxLineOffset = CurPtr - Buffer.getBufferStart();
   }
 
   do {





More information about the cfe-commits mailing list