[FileCollector] Change coding style from LLDB to LLVM (NFC)
authorJonas Devlieghere <jonas@devlieghere.com>
Thu, 25 Jul 2019 00:17:39 +0000 (00:17 +0000)
committerJonas Devlieghere <jonas@devlieghere.com>
Thu, 25 Jul 2019 00:17:39 +0000 (00:17 +0000)
This patch changes the coding style of the FileCollector from the LLDB
to the LLVM coding style. Alex recently lifted it into LLVM and I
volunteered to do the conversion.

llvm-svn: 366966

lldb/include/lldb/Utility/FileCollector.h
lldb/include/lldb/Utility/Reproducer.h
lldb/source/Host/common/FileSystem.cpp
lldb/source/Plugins/ExpressionParser/Clang/ModuleDependencyCollector.h
llvm/include/llvm/Support/FileCollector.h
llvm/lib/Support/FileCollector.cpp

index 96d03a8..22c1c6d 100644 (file)
@@ -22,17 +22,17 @@ public:
   FileCollector(const FileSpec &root, const FileSpec &overlay) :
     llvm::FileCollector(root.GetPath(), overlay.GetPath()) {}
 
-  using llvm::FileCollector::AddFile;
+  using llvm::FileCollector::addFile;
 
-  void AddFile(const FileSpec &file) {
-      std::string path = file.GetPath();
-      llvm::FileCollector::AddFile(path);
+  void addFile(const FileSpec &file) {
+    std::string path = file.GetPath();
+    llvm::FileCollector::addFile(path);
   }
 
   /// Write the yaml mapping (for the VFS) to the given file.
-  std::error_code WriteMapping(const FileSpec &mapping_file) {
+  std::error_code writeMapping(const FileSpec &mapping_file) {
     std::string path = mapping_file.GetPath();
-    return llvm::FileCollector::WriteMapping(path);
+    return llvm::FileCollector::writeMapping(path);
   }
 };
 
index 670041d..1c4486b 100644 (file)
@@ -99,9 +99,9 @@ public:
   void Keep() override {
     auto mapping = GetRoot().CopyByAppendingPathComponent(Info::file);
     // Temporary files that are removed during execution can cause copy errors.
-    if (auto ec = m_collector.CopyFiles(/*stop_on_error=*/false))
+    if (auto ec = m_collector.copyFiles(/*stop_on_error=*/false))
       return;
-    m_collector.WriteMapping(mapping);
+    m_collector.writeMapping(mapping);
   }
 
   static char ID;
index d5ac05b..8fc4ff4 100644 (file)
@@ -280,7 +280,7 @@ std::shared_ptr<DataBufferLLVM>
 FileSystem::CreateDataBuffer(const llvm::Twine &path, uint64_t size,
                              uint64_t offset) {
   if (m_collector)
-    m_collector->AddFile(path);
+    m_collector->addFile(path);
 
   const bool is_volatile = !IsLocal(path);
   const ErrorOr<std::string> external_path = GetExternalPath(path);
@@ -418,7 +418,7 @@ static mode_t GetOpenMode(uint32_t permissions) {
 Status FileSystem::Open(File &File, const FileSpec &file_spec, uint32_t options,
                         uint32_t permissions, bool should_close_fd) {
   if (m_collector)
-    m_collector->AddFile(file_spec);
+    m_collector->addFile(file_spec);
 
   if (File.IsValid())
     File.Close();
index 0e959f8..ad4c469 100644 (file)
@@ -23,7 +23,7 @@ public:
 
   void addFile(llvm::StringRef Filename,
                llvm::StringRef FileDst = {}) override {
-    m_file_collector.AddFile(Filename);
+    m_file_collector.addFile(Filename);
   }
 
   bool insertSeen(llvm::StringRef Filename) override { return false; }
index 518546a..64c60bc 100644 (file)
@@ -23,51 +23,49 @@ namespace llvm {
 /// the VFS.
 class FileCollector {
 public:
-  FileCollector(std::string root, std::string overlay);
+  FileCollector(std::string Root, std::string OverlayRoot);
 
-  void AddFile(const Twine &file);
+  void addFile(const Twine &file);
 
   /// Write the yaml mapping (for the VFS) to the given file.
-  std::error_code WriteMapping(StringRef mapping_file);
+  std::error_code writeMapping(StringRef mapping_file);
 
   /// Copy the files into the root directory.
   ///
-  /// When stop_on_error is true (the default) we abort as soon as one file
+  /// When StopOnError is true (the default) we abort as soon as one file
   /// cannot be copied. This is relatively common, for example when a file was
   /// removed after it was added to the mapping.
-  std::error_code CopyFiles(bool stop_on_error = true);
+  std::error_code copyFiles(bool StopOnError = true);
 
 private:
-  void AddFileImpl(StringRef src_path);
+  void addFileImpl(StringRef SrcPath);
 
-  bool MarkAsSeen(StringRef path) { return m_seen.insert(path).second; }
+  bool markAsSeen(StringRef Path) { return Seen.insert(Path).second; }
 
-  bool GetRealPath(StringRef src_path,
-                   SmallVectorImpl<char> &result);
+  bool getRealPath(StringRef SrcPath, SmallVectorImpl<char> &Result);
 
-  void AddFileToMapping(StringRef virtual_path,
-                        StringRef real_path) {
-    m_vfs_writer.addFileMapping(virtual_path, real_path);
+  void addFileToMapping(StringRef VirtualPath, StringRef RealPath) {
+    VFSWriter.addFileMapping(VirtualPath, RealPath);
   }
 
 protected:
   /// Synchronizes adding files.
-  std::mutex m_mutex;
+  std::mutex Mutex;
 
   /// The root directory where files are copied.
-  std::string m_root;
+  std::string Root;
 
   /// The root directory where the VFS overlay lives.
-  std::string m_overlay_root;
+  std::string OverlayRoot;
 
   /// Tracks already seen files so they can be skipped.
-  StringSet<> m_seen;
+  StringSet<> Seen;
 
   /// The yaml mapping writer.
-  vfs::YAMLVFSWriter m_vfs_writer;
+  vfs::YAMLVFSWriter VFSWriter;
 
-  /// Caches real_path calls when resolving symlinks.
-  StringMap<std::string> m_symlink_map;
+  /// Caches RealPath calls when resolving symlinks.
+  StringMap<std::string> SymlinkMap;
 };
 
 } // end namespace llvm
index 05bea66..b0e67ec 100644 (file)
 
 using namespace llvm;
 
-static bool IsCaseSensitivePath(StringRef path) {
-  SmallString<256> tmp_dest = path, upper_dest, real_dest;
+static bool isCaseSensitivePath(StringRef Path) {
+  SmallString<256> TmpDest = Path, UpperDest, RealDest;
 
   // Remove component traversals, links, etc.
-  if (!sys::fs::real_path(path, tmp_dest))
+  if (!sys::fs::real_path(Path, TmpDest))
     return true; // Current default value in vfs.yaml
-  path = tmp_dest;
+  Path = TmpDest;
 
   // Change path to all upper case and ask for its real path, if the latter
   // exists and is equal to path, it's not case sensitive. Default to case
   // sensitive in the absence of real_path, since this is the YAMLVFSWriter
   // default.
-  upper_dest = path.upper();
-  if (sys::fs::real_path(upper_dest, real_dest) && path.equals(real_dest))
+  UpperDest = Path.upper();
+  if (sys::fs::real_path(UpperDest, RealDest) && Path.equals(RealDest))
     return false;
   return true;
 }
 
-FileCollector::FileCollector(std::string root, std::string overlay_root)
-    : m_root(std::move(root)), m_overlay_root(std::move(overlay_root)) {
-  sys::fs::create_directories(this->m_root, true);
+FileCollector::FileCollector(std::string Root, std::string OverlayRoot)
+    : Root(std::move(Root)), OverlayRoot(std::move(OverlayRoot)) {
+  sys::fs::create_directories(this->Root, true);
 }
 
-bool FileCollector::GetRealPath(StringRef src_path,
-                                SmallVectorImpl<char> &result) {
-  SmallString<256> real_path;
-  StringRef FileName = sys::path::filename(src_path);
-  std::string directory = sys::path::parent_path(src_path).str();
-  auto dir_with_symlink = m_symlink_map.find(directory);
+bool FileCollector::getRealPath(StringRef SrcPath,
+                                SmallVectorImpl<char> &Result) {
+  SmallString<256> RealPath;
+  StringRef FileName = sys::path::filename(SrcPath);
+  std::string Directory = sys::path::parent_path(SrcPath).str();
+  auto DirWithSymlink = SymlinkMap.find(Directory);
 
   // Use real_path to fix any symbolic link component present in a path.
-  // Computing the real path is expensive, cache the search through the
-  // parent path directory.
-  if (dir_with_symlink == m_symlink_map.end()) {
-    auto ec = sys::fs::real_path(directory, real_path);
-    if (ec)
+  // Computing the real path is expensive, cache the search through the parent
+  // path Directory.
+  if (DirWithSymlink == SymlinkMap.end()) {
+    auto EC = sys::fs::real_path(Directory, RealPath);
+    if (EC)
       return false;
-    m_symlink_map[directory] = real_path.str();
+    SymlinkMap[Directory] = RealPath.str();
   } else {
-    real_path = dir_with_symlink->second;
+    RealPath = DirWithSymlink->second;
   }
 
-  sys::path::append(real_path, FileName);
-  result.swap(real_path);
+  sys::path::append(RealPath, FileName);
+  Result.swap(RealPath);
   return true;
 }
 
-void FileCollector::AddFile(const Twine &file) {
-  std::lock_guard<std::mutex> lock(m_mutex);
-  std::string file_str = file.str();
-  if (MarkAsSeen(file_str))
-    AddFileImpl(file_str);
+void FileCollector::addFile(const Twine &file) {
+  std::lock_guard<std::mutex> lock(Mutex);
+  std::string FileStr = file.str();
+  if (markAsSeen(FileStr))
+    addFileImpl(FileStr);
 }
 
-void FileCollector::AddFileImpl(StringRef src_path) {
+void FileCollector::addFileImpl(StringRef SrcPath) {
   // We need an absolute src path to append to the root.
-  SmallString<256> absolute_src = src_path;
-  sys::fs::make_absolute(absolute_src);
+  SmallString<256> AbsoluteSrc = SrcPath;
+  sys::fs::make_absolute(AbsoluteSrc);
 
   // Canonicalize src to a native path to avoid mixed separator styles.
-  sys::path::native(absolute_src);
+  sys::path::native(AbsoluteSrc);
 
   // Remove redundant leading "./" pieces and consecutive separators.
-  absolute_src = sys::path::remove_leading_dotslash(absolute_src);
+  AbsoluteSrc = sys::path::remove_leading_dotslash(AbsoluteSrc);
 
   // Canonicalize the source path by removing "..", "." components.
-  SmallString<256> virtual_path = absolute_src;
-  sys::path::remove_dots(virtual_path, /*remove_dot_dot=*/true);
+  SmallString<256> VirtualPath = AbsoluteSrc;
+  sys::path::remove_dots(VirtualPath, /*remove_dot_dot=*/true);
 
   // If a ".." component is present after a symlink component, remove_dots may
   // lead to the wrong real destination path. Let the source be canonicalized
   // like that but make sure we always use the real path for the destination.
-  SmallString<256> copy_from;
-  if (!GetRealPath(absolute_src, copy_from))
-    copy_from = virtual_path;
+  SmallString<256> CopyFrom;
+  if (!getRealPath(AbsoluteSrc, CopyFrom))
+    CopyFrom = VirtualPath;
 
-  SmallString<256> dst_path = StringRef(m_root);
-  sys::path::append(dst_path, sys::path::relative_path(copy_from));
+  SmallString<256> DstPath = StringRef(Root);
+  sys::path::append(DstPath, sys::path::relative_path(CopyFrom));
 
   // Always map a canonical src path to its real path into the YAML, by doing
   // this we map different virtual src paths to the same entry in the VFS
   // overlay, which is a way to emulate symlink inside the VFS; this is also
   // needed for correctness, not doing that can lead to module redefinition
   // errors.
-  AddFileToMapping(virtual_path, dst_path);
+  addFileToMapping(VirtualPath, DstPath);
 }
 
 /// Set the access and modification time for the given file from the given
 /// status object.
 static std::error_code
-CopyAccessAndModificationTime(StringRef filename,
-                              const sys::fs::file_status &stat) {
-  int fd;
+copyAccessAndModificationTime(StringRef Filename,
+                              const sys::fs::file_status &Stat) {
+  int FD;
 
-  if (auto ec =
-          sys::fs::openFileForWrite(filename, fd, sys::fs::CD_OpenExisting))
-    return ec;
+  if (auto EC =
+          sys::fs::openFileForWrite(Filename, FD, sys::fs::CD_OpenExisting))
+    return EC;
 
-  if (auto ec = sys::fs::setLastAccessAndModificationTime(
-          fd, stat.getLastAccessedTime(), stat.getLastModificationTime()))
-    return ec;
+  if (auto EC = sys::fs::setLastAccessAndModificationTime(
+          FD, Stat.getLastAccessedTime(), Stat.getLastModificationTime()))
+    return EC;
 
-  if (auto ec = sys::Process::SafelyCloseFileDescriptor(fd))
-    return ec;
+  if (auto EC = sys::Process::SafelyCloseFileDescriptor(FD))
+    return EC;
 
   return {};
 }
 
-std::error_code FileCollector::CopyFiles(bool stop_on_error) {
-  for (auto &entry : m_vfs_writer.getMappings()) {
+std::error_code FileCollector::copyFiles(bool StopOnError) {
+  for (auto &entry : VFSWriter.getMappings()) {
     // Create directory tree.
-    if (std::error_code ec =
+    if (std::error_code EC =
             sys::fs::create_directories(sys::path::parent_path(entry.RPath),
                                         /*IgnoreExisting=*/true)) {
-      if (stop_on_error)
-        return ec;
+      if (StopOnError)
+        return EC;
     }
 
     // Copy file over.
-    if (std::error_code ec = sys::fs::copy_file(entry.VPath, entry.RPath)) {
-      if (stop_on_error)
-        return ec;
+    if (std::error_code EC = sys::fs::copy_file(entry.VPath, entry.RPath)) {
+      if (StopOnError)
+        return EC;
     }
 
     // Copy over permissions.
     if (auto perms = sys::fs::getPermissions(entry.VPath)) {
-      if (std::error_code ec = sys::fs::setPermissions(entry.RPath, *perms)) {
-        if (stop_on_error)
-          return ec;
+      if (std::error_code EC = sys::fs::setPermissions(entry.RPath, *perms)) {
+        if (StopOnError)
+          return EC;
       }
     }
 
     // Copy over modification time.
-    sys::fs::file_status stat;
-    if (std::error_code ec = sys::fs::status(entry.VPath, stat)) {
-      if (stop_on_error)
-        return ec;
+    sys::fs::file_status Stat;
+    if (std::error_code EC = sys::fs::status(entry.VPath, Stat)) {
+      if (StopOnError)
+        return EC;
       continue;
     }
-    CopyAccessAndModificationTime(entry.RPath, stat);
+    copyAccessAndModificationTime(entry.RPath, Stat);
   }
   return {};
 }
 
-std::error_code FileCollector::WriteMapping(StringRef mapping_file) {
-  std::lock_guard<std::mutex> lock(m_mutex);
+std::error_code FileCollector::writeMapping(StringRef mapping_file) {
+  std::lock_guard<std::mutex> lock(Mutex);
 
-  StringRef root = m_overlay_root;
-  m_vfs_writer.setOverlayDir(root);
-  m_vfs_writer.setCaseSensitivity(IsCaseSensitivePath(root));
-  m_vfs_writer.setUseExternalNames(false);
+  VFSWriter.setOverlayDir(OverlayRoot);
+  VFSWriter.setCaseSensitivity(isCaseSensitivePath(OverlayRoot));
+  VFSWriter.setUseExternalNames(false);
 
-  std::error_code ec;
-  raw_fd_ostream os(mapping_file, ec, sys::fs::F_Text);
-  if (ec)
-    return ec;
+  std::error_code EC;
+  raw_fd_ostream os(mapping_file, EC, sys::fs::F_Text);
+  if (EC)
+    return EC;
 
-  m_vfs_writer.write(os);
+  VFSWriter.write(os);
 
   return {};
 }