[clang] d07b290 - DependencyScanning: pull factory function into MinimizedVFS, NFC

Duncan P. N. Exon Smith via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 12 14:25:21 PDT 2020


Author: Duncan P. N. Exon Smith
Date: 2020-10-12T17:25:10-04:00
New Revision: d07b290e4b7c55823895e88b683de4178ffc66db

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

LOG: DependencyScanning: pull factory function into MinimizedVFS, NFC

Avoid need for getBufferPtr API, simplifying another patch. No
functionality change.

Added: 
    

Modified: 
    clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index b1b87e7fa573..63eab82820cc 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -217,9 +217,11 @@ class MinimizedVFSFile final : public llvm::vfs::File {
                    llvm::vfs::Status Stat)
       : Buffer(std::move(Buffer)), Stat(std::move(Stat)) {}
 
-  llvm::ErrorOr<llvm::vfs::Status> status() override { return Stat; }
+  static llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
+  create(const CachedFileSystemEntry *Entry,
+         ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings);
 
-  const llvm::MemoryBuffer *getBufferPtr() const { return Buffer.get(); }
+  llvm::ErrorOr<llvm::vfs::Status> status() override { return Stat; }
 
   llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
   getBuffer(const Twine &Name, int64_t FileSize, bool RequiresNullTerminator,
@@ -234,9 +236,11 @@ class MinimizedVFSFile final : public llvm::vfs::File {
   llvm::vfs::Status Stat;
 };
 
-llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
-createFile(const CachedFileSystemEntry *Entry,
-           ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings) {
+} // end anonymous namespace
+
+llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>> MinimizedVFSFile::create(
+    const CachedFileSystemEntry *Entry,
+    ExcludedPreprocessorDirectiveSkipMapping *PPSkipMappings) {
   if (Entry->isDirectory())
     return llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>(
         std::make_error_code(std::errc::is_a_directory));
@@ -248,14 +252,12 @@ createFile(const CachedFileSystemEntry *Entry,
                                        /*RequiresNullTerminator=*/false),
       *Entry->getStatus());
   if (!Entry->getPPSkippedRangeMapping().empty() && PPSkipMappings)
-    (*PPSkipMappings)[Result->getBufferPtr()] =
+    (*PPSkipMappings)[Result->Buffer.get()] =
         &Entry->getPPSkippedRangeMapping();
   return llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>(
       std::unique_ptr<llvm::vfs::File>(std::move(Result)));
 }
 
-} // end anonymous namespace
-
 llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
 DependencyScanningWorkerFilesystem::openFileForRead(const Twine &Path) {
   SmallString<256> OwnedFilename;
@@ -265,5 +267,5 @@ DependencyScanningWorkerFilesystem::openFileForRead(const Twine &Path) {
       getOrCreateFileSystemEntry(Filename);
   if (!Result)
     return Result.getError();
-  return createFile(Result.get(), PPSkipMappings);
+  return MinimizedVFSFile::create(Result.get(), PPSkipMappings);
 }


        


More information about the cfe-commits mailing list