[clang] 747b134 - clang/Basic: Remove SourceManager::getBufferPointer, NFC

Duncan P. N. Exon Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 20 15:02:52 PDT 2020


Author: Duncan P. N. Exon Smith
Date: 2020-10-20T18:02:42-04:00
New Revision: 747b134d019ce99bc4463d09992634965ee95031

URL: https://github.com/llvm/llvm-project/commit/747b134d019ce99bc4463d09992634965ee95031
DIFF: https://github.com/llvm/llvm-project/commit/747b134d019ce99bc4463d09992634965ee95031.diff

LOG: clang/Basic: Remove SourceManager::getBufferPointer, NFC

Inline `Source::getBufferPointer` into its only remaining caller,
`getBufferOrNone`. No functionality change.

Differential Revision: https://reviews.llvm.org/D89430

Added: 
    

Modified: 
    clang/include/clang/Basic/SourceManager.h
    clang/lib/Basic/SourceManager.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h
index 905b706971d5..480fa51d6889 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -188,17 +188,6 @@ namespace SrcMgr {
     getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
                     SourceLocation Loc = SourceLocation()) const;
 
-  private:
-    /// Returns pointer to memory buffer.
-    ///
-    /// TODO: SourceManager needs access to this for now, but once that's done
-    /// we should remove this API.
-    const llvm::MemoryBuffer *getBufferPointer(DiagnosticsEngine &Diag,
-                                               FileManager &FM,
-                                               SourceLocation Loc) const;
-    friend class clang::SourceManager;
-
-  public:
     /// Returns the size of the content encapsulated by this
     /// ContentCache.
     ///

diff  --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index 51772d5aa335..27d2f398f3c6 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -121,22 +121,14 @@ const char *ContentCache::getInvalidBOM(StringRef BufStr) {
 llvm::Optional<llvm::MemoryBufferRef>
 ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
                               SourceLocation Loc) const {
-  if (auto *B = getBufferPointer(Diag, FM, Loc))
-    return B->getMemBufferRef();
-  return None;
-}
-
-const llvm::MemoryBuffer *
-ContentCache::getBufferPointer(DiagnosticsEngine &Diag, FileManager &FM,
-                               SourceLocation Loc) const {
   // Lazily create the Buffer for ContentCaches that wrap files.  If we already
   // computed it, just return what we have.
   if (isBufferInvalid())
-    return nullptr;
+    return None;
   if (auto *B = Buffer.getPointer())
-    return B;
+    return B->getMemBufferRef();
   if (!ContentsEntry)
-    return nullptr;
+    return None;
 
   // Check that the file's size fits in an 'unsigned' (with room for a
   // past-the-end value). This is deeply regrettable, but various parts of
@@ -153,7 +145,7 @@ ContentCache::getBufferPointer(DiagnosticsEngine &Diag, FileManager &FM,
         << ContentsEntry->getName();
 
     Buffer.setInt(Buffer.getInt() | InvalidFlag);
-    return nullptr;
+    return None;
   }
 
   auto BufferOrError = FM.getBufferForFile(ContentsEntry, IsFileVolatile);
@@ -173,7 +165,7 @@ ContentCache::getBufferPointer(DiagnosticsEngine &Diag, FileManager &FM,
           << ContentsEntry->getName() << BufferOrError.getError().message();
 
     Buffer.setInt(Buffer.getInt() | InvalidFlag);
-    return nullptr;
+    return None;
   }
 
   Buffer.setPointer(BufferOrError->release());
@@ -189,7 +181,7 @@ ContentCache::getBufferPointer(DiagnosticsEngine &Diag, FileManager &FM,
         << ContentsEntry->getName();
 
     Buffer.setInt(Buffer.getInt() | InvalidFlag);
-    return nullptr;
+    return None;
   }
 
   // If the buffer is valid, check to see if it has a UTF Byte Order Mark
@@ -202,10 +194,10 @@ ContentCache::getBufferPointer(DiagnosticsEngine &Diag, FileManager &FM,
     Diag.Report(Loc, diag::err_unsupported_bom)
       << InvalidBOM << ContentsEntry->getName();
     Buffer.setInt(Buffer.getInt() | InvalidFlag);
-    return nullptr;
+    return None;
   }
 
-  return Buffer.getPointer();
+  return Buffer.getPointer()->getMemBufferRef();
 }
 
 unsigned LineTableInfo::getLineTableFilenameID(StringRef Name) {


        


More information about the cfe-commits mailing list