Lift VFS from clang to llvm (NFC)

This patch moves the virtual file system form clang to llvm so it can be
used by more projects.

Concretely the patch:
 - Moves VirtualFileSystem.{h|cpp} from clang/Basic to llvm/Support.
 - Moves the corresponding unit test from clang to llvm.
 - Moves the vfs namespace from clang::vfs to llvm::vfs.
 - Formats the lines affected by this change, mostly this is the result of
   the added llvm namespace.

RFC on the mailing list:
http://lists.llvm.org/pipermail/llvm-dev/2018-October/126657.html

Differential revision: https://reviews.llvm.org/D52783

llvm-svn: 344140
diff --git a/clang/lib/Frontend/PrecompiledPreamble.cpp b/clang/lib/Frontend/PrecompiledPreamble.cpp
index c6dd89c..1930af1 100644
--- a/clang/lib/Frontend/PrecompiledPreamble.cpp
+++ b/clang/lib/Frontend/PrecompiledPreamble.cpp
@@ -14,7 +14,6 @@
 #include "clang/Frontend/PrecompiledPreamble.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/Basic/TargetInfo.h"
-#include "clang/Basic/VirtualFileSystem.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendActions.h"
@@ -30,6 +29,7 @@
 #include "llvm/Support/Mutex.h"
 #include "llvm/Support/MutexGuard.h"
 #include "llvm/Support/Process.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include <limits>
 #include <utility>
 
@@ -48,17 +48,17 @@
 #endif
 }
 
-IntrusiveRefCntPtr<vfs::FileSystem>
+IntrusiveRefCntPtr<llvm::vfs::FileSystem>
 createVFSOverlayForPreamblePCH(StringRef PCHFilename,
                                std::unique_ptr<llvm::MemoryBuffer> PCHBuffer,
-                               IntrusiveRefCntPtr<vfs::FileSystem> VFS) {
+                               IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
   // We want only the PCH file from the real filesystem to be available,
   // so we create an in-memory VFS with just that and overlay it on top.
-  IntrusiveRefCntPtr<vfs::InMemoryFileSystem> PCHFS(
-      new vfs::InMemoryFileSystem());
+  IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> PCHFS(
+      new llvm::vfs::InMemoryFileSystem());
   PCHFS->addFile(PCHFilename, 0, std::move(PCHBuffer));
-  IntrusiveRefCntPtr<vfs::OverlayFileSystem> Overlay(
-      new vfs::OverlayFileSystem(VFS));
+  IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> Overlay(
+      new llvm::vfs::OverlayFileSystem(VFS));
   Overlay->pushOverlay(PCHFS);
   return Overlay;
 }
@@ -232,7 +232,8 @@
 llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
     const CompilerInvocation &Invocation,
     const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds,
-    DiagnosticsEngine &Diagnostics, IntrusiveRefCntPtr<vfs::FileSystem> VFS,
+    DiagnosticsEngine &Diagnostics,
+    IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
     std::shared_ptr<PCHContainerOperations> PCHContainerOps, bool StoreInMemory,
     PreambleCallbacks &Callbacks) {
   assert(VFS && "VFS is null");
@@ -410,7 +411,7 @@
 bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation,
                                    const llvm::MemoryBuffer *MainFileBuffer,
                                    PreambleBounds Bounds,
-                                   vfs::FileSystem *VFS) const {
+                                   llvm::vfs::FileSystem *VFS) const {
 
   assert(
       Bounds.Size <= MainFileBuffer->getBufferSize() &&
@@ -437,7 +438,7 @@
   // remapping or unsaved_files.
   std::map<llvm::sys::fs::UniqueID, PreambleFileHash> OverriddenFiles;
   for (const auto &R : PreprocessorOpts.RemappedFiles) {
-    vfs::Status Status;
+    llvm::vfs::Status Status;
     if (!moveOnNoError(VFS->status(R.second), Status)) {
       // If we can't stat the file we're remapping to, assume that something
       // horrible happened.
@@ -449,7 +450,7 @@
   }
 
   for (const auto &RB : PreprocessorOpts.RemappedFileBuffers) {
-    vfs::Status Status;
+    llvm::vfs::Status Status;
     if (!moveOnNoError(VFS->status(RB.first), Status))
       return false;
 
@@ -459,7 +460,7 @@
 
   // Check whether anything has changed.
   for (const auto &F : FilesInPreamble) {
-    vfs::Status Status;
+    llvm::vfs::Status Status;
     if (!moveOnNoError(VFS->status(F.first()), Status)) {
       // If we can't stat the file, assume that something horrible happened.
       return false;
@@ -485,14 +486,14 @@
 }
 
 void PrecompiledPreamble::AddImplicitPreamble(
-    CompilerInvocation &CI, IntrusiveRefCntPtr<vfs::FileSystem> &VFS,
+    CompilerInvocation &CI, IntrusiveRefCntPtr<llvm::vfs::FileSystem> &VFS,
     llvm::MemoryBuffer *MainFileBuffer) const {
   PreambleBounds Bounds(PreambleBytes.size(), PreambleEndsAtStartOfLine);
   configurePreamble(Bounds, CI, VFS, MainFileBuffer);
 }
 
 void PrecompiledPreamble::OverridePreamble(
-    CompilerInvocation &CI, IntrusiveRefCntPtr<vfs::FileSystem> &VFS,
+    CompilerInvocation &CI, IntrusiveRefCntPtr<llvm::vfs::FileSystem> &VFS,
     llvm::MemoryBuffer *MainFileBuffer) const {
   auto Bounds = ComputePreambleBounds(*CI.getLangOpts(), MainFileBuffer, 0);
   configurePreamble(Bounds, CI, VFS, MainFileBuffer);
@@ -680,7 +681,7 @@
 
 void PrecompiledPreamble::configurePreamble(
     PreambleBounds Bounds, CompilerInvocation &CI,
-    IntrusiveRefCntPtr<vfs::FileSystem> &VFS,
+    IntrusiveRefCntPtr<llvm::vfs::FileSystem> &VFS,
     llvm::MemoryBuffer *MainFileBuffer) const {
   assert(VFS);
 
@@ -701,13 +702,14 @@
 
 void PrecompiledPreamble::setupPreambleStorage(
     const PCHStorage &Storage, PreprocessorOptions &PreprocessorOpts,
-    IntrusiveRefCntPtr<vfs::FileSystem> &VFS) {
+    IntrusiveRefCntPtr<llvm::vfs::FileSystem> &VFS) {
   if (Storage.getKind() == PCHStorage::Kind::TempFile) {
     const TempPCHFile &PCHFile = Storage.asFile();
     PreprocessorOpts.ImplicitPCHInclude = PCHFile.getFilePath();
 
     // Make sure we can access the PCH file even if we're using a VFS
-    IntrusiveRefCntPtr<vfs::FileSystem> RealFS = vfs::getRealFileSystem();
+    IntrusiveRefCntPtr<llvm::vfs::FileSystem> RealFS =
+        llvm::vfs::getRealFileSystem();
     auto PCHPath = PCHFile.getFilePath();
     if (VFS == RealFS || VFS->exists(PCHPath))
       return;