]> granicus.if.org Git - clang/commitdiff
Change MemoryBuffer* to MemoryBuffer& parameter to Lexer::ComputePreamble
authorDavid Blaikie <dblaikie@gmail.com>
Mon, 11 Aug 2014 22:08:06 +0000 (22:08 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Mon, 11 Aug 2014 22:08:06 +0000 (22:08 +0000)
(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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215391 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/Lexer.h
lib/Frontend/ASTUnit.cpp
lib/Frontend/FrontendActions.cpp
lib/Lex/Lexer.cpp

index edcf883eced3f912b020001c4ad1bf2fc5d94307..034bc8c9795f1d749d64c572eac9f7ef3200c43a 100644 (file)
@@ -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
index 0b740e7a116409ca3338b214941b532b6c8ed8c2..f6c2a405159c9df6545dfedb6389d2b7c54bdaac 100644 (file)
@@ -1252,10 +1252,10 @@ ASTUnit::ComputePreamble(CompilerInvocation &Invocation,
 
     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
index 903abe2d61f3cbc6af0363feeae8b754580031e9..e5830d6ae68763698701a433e8e1e12b06dab829 100644 (file)
@@ -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;
   }
index 6f6b50b246d715949e54023fcf89ab7ff3715e3d..efee609fc101c4a20fdffc7bb32a81d065fc19f2 100644 (file)
@@ -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::MemoryBuffer *Buffer,
 
   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::MemoryBuffer *Buffer,
           break;
       }
     }
-    if (CurPtr != Buffer->getBufferEnd())
-      MaxLineOffset = CurPtr - Buffer->getBufferStart();
+    if (CurPtr != Buffer.getBufferEnd())
+      MaxLineOffset = CurPtr - Buffer.getBufferStart();
   }
 
   do {