[llvm] r186376 - Instead friending status, provide windows and posix constructors to file_status.

Rafael Espindola rafael.espindola at gmail.com
Mon Jul 15 19:55:33 PDT 2013


Author: rafael
Date: Mon Jul 15 21:55:33 2013
New Revision: 186376

URL: http://llvm.org/viewvc/llvm-project?rev=186376&view=rev
Log:
Instead friending status, provide windows and posix constructors to file_status.

This opens the way of having static helpers in the .inc files that can
construct a file_status.

Modified:
    llvm/trunk/include/llvm/Support/FileSystem.h
    llvm/trunk/lib/Support/Unix/Path.inc
    llvm/trunk/lib/Support/Windows/Path.inc

Modified: llvm/trunk/include/llvm/Support/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=186376&r1=186375&r2=186376&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FileSystem.h (original)
+++ llvm/trunk/include/llvm/Support/FileSystem.h Mon Jul 15 21:55:33 2013
@@ -164,14 +164,29 @@ class file_status
   uint32_t FileIndexLow;
   #endif
   friend bool equivalent(file_status A, file_status B);
-  friend error_code status(const Twine &path, file_status &result);
   friend error_code getUniqueID(const Twine Path, uint64_t &Result);
   file_type Type;
   perms Perms;
 public:
-  explicit file_status(file_type v=file_type::status_error, 
-                      perms prms=perms_not_known)
-    : Type(v), Perms(prms) {}
+  file_status() : Type(file_type::status_error) {}
+  file_status(file_type Type) : Type(Type) {}
+
+  #if defined(LLVM_ON_UNIX)
+    file_status(file_type Type, perms Perms, dev_t Dev, ino_t Ino, time_t MTime,
+                uid_t UID, gid_t GID, off_t Size)
+        : fs_st_dev(Dev), fs_st_ino(Ino), fs_st_mtime(MTime), fs_st_uid(UID),
+          fs_st_gid(GID), fs_st_size(Size), Type(Type), Perms(Perms) {}
+  #elif defined(LLVM_ON_WIN32)
+    file_status(file_type Type, uint32_t LastWriteTimeHigh,
+                uint32_t LastWriteTimeLow, uint32_t VolumeSerialNumber,
+                uint32_t FileSizeHigh, uint32_t FileSizeLow,
+                uint32_t FileIndexHigh, uint32_t FileIndexLow)
+        : LastWriteTimeHigh(LastWriteTimeHigh),
+          LastWriteTimeLow(LastWriteTimeLow),
+          VolumeSerialNumber(VolumeSerialNumber), FileSizeHigh(FileSizeHigh),
+          FileSizeLow(FileSizeLow), FileIndexHigh(FileIndexHigh),
+          FileIndexLow(FileIndexLow), Type(Type), Perms(perms_not_known) {}
+  #endif
 
   // getters
   file_type type() const { return Type; }
@@ -434,21 +449,6 @@ inline bool equivalent(const Twine &A, c
   return !equivalent(A, B, result) && result;
 }
 
-/// @brief Get file size.
-///
-/// @param Path Input path.
-/// @param Result Set to the size of the file in \a Path.
-/// @returns errc::success if result has been successfully set, otherwise a
-///          platform specific error_code.
-inline error_code file_size(const Twine &Path, uint64_t &Result) {
-  file_status Status;
-  error_code EC = status(Path, Status);
-  if (EC)
-    return EC;
-  Result = Status.getSize();
-  return error_code::success();
-}
-
 /// @brief Does status represent a directory?
 ///
 /// @param status A file_status previously returned from status.
@@ -529,6 +529,21 @@ error_code is_symlink(const Twine &path,
 ///          platform specific error_code.
 error_code status(const Twine &path, file_status &result);
 
+/// @brief Get file size.
+///
+/// @param Path Input path.
+/// @param Result Set to the size of the file in \a Path.
+/// @returns errc::success if result has been successfully set, otherwise a
+///          platform specific error_code.
+inline error_code file_size(const Twine &Path, uint64_t &Result) {
+  file_status Status;
+  error_code EC = status(Path, Status);
+  if (EC)
+    return EC;
+  Result = Status.getSize();
+  return error_code::success();
+}
+
 error_code setLastModificationAndAccessTime(int FD, TimeValue Time);
 
 /// @brief Is status available?

Modified: llvm/trunk/lib/Support/Unix/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Path.inc?rev=186376&r1=186375&r2=186376&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Path.inc (original)
+++ llvm/trunk/lib/Support/Unix/Path.inc Mon Jul 15 21:55:33 2013
@@ -556,28 +556,24 @@ error_code status(const Twine &path, fil
   }
 
   perms prms = static_cast<perms>(status.st_mode);
-  
+  file_type Type = file_type::type_unknown;
+
   if (S_ISDIR(status.st_mode))
-    result = file_status(file_type::directory_file, prms);
+    Type = file_type::directory_file;
   else if (S_ISREG(status.st_mode))
-    result = file_status(file_type::regular_file, prms);
+    Type = file_type::regular_file;
   else if (S_ISBLK(status.st_mode))
-    result = file_status(file_type::block_file, prms);
+    Type = file_type::block_file;
   else if (S_ISCHR(status.st_mode))
-    result = file_status(file_type::character_file, prms);
+    Type = file_type::character_file;
   else if (S_ISFIFO(status.st_mode))
-    result = file_status(file_type::fifo_file, prms);
+    Type = file_type::fifo_file;
   else if (S_ISSOCK(status.st_mode))
-    result = file_status(file_type::socket_file, prms);
-  else
-    result = file_status(file_type::type_unknown, prms);
+    Type = file_type::socket_file;
 
-  result.fs_st_dev = status.st_dev;
-  result.fs_st_ino = status.st_ino;
-  result.fs_st_mtime = status.st_mtime;
-  result.fs_st_uid = status.st_uid;
-  result.fs_st_gid = status.st_gid;
-  result.fs_st_size = status.st_size;
+  result =
+      file_status(Type, prms, status.st_dev, status.st_ino, status.st_mtime,
+                  status.st_uid, status.st_gid, status.st_size);
 
   return error_code::success();
 }

Modified: llvm/trunk/lib/Support/Windows/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Path.inc?rev=186376&r1=186375&r2=186376&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Path.inc (original)
+++ llvm/trunk/lib/Support/Windows/Path.inc Mon Jul 15 21:55:33 2013
@@ -632,7 +632,6 @@ error_code status(const Twine &path, fil
   if (attr & FILE_ATTRIBUTE_DIRECTORY)
     result = file_status(file_type::directory_file);
   else {
-    result = file_status(file_type::regular_file);
     ScopedFileHandle h(
       ::CreateFileW(path_utf16.begin(),
                     0, // Attributes only.
@@ -646,15 +645,13 @@ error_code status(const Twine &path, fil
     BY_HANDLE_FILE_INFORMATION Info;
     if (!::GetFileInformationByHandle(h, &Info))
       goto handle_status_error;
-    result.FileIndexHigh      = Info.nFileIndexHigh;
-    result.FileIndexLow       = Info.nFileIndexLow;
-    result.FileSizeHigh       = Info.nFileSizeHigh;
-    result.FileSizeLow        = Info.nFileSizeLow;
-    result.LastWriteTimeHigh  = Info.ftLastWriteTime.dwHighDateTime;
-    result.LastWriteTimeLow   = Info.ftLastWriteTime.dwLowDateTime;
-    result.VolumeSerialNumber = Info.dwVolumeSerialNumber;
-  }
 
+    result = file_status(
+        file_type::regular_file, Info.ftLastWriteTime.dwHighDateTime,
+        Info.ftLastWriteTime.dwLowDateTime, Info.dwVolumeSerialNumber,
+        Info.nFileSizeHigh, Info.nFileSizeLow, Info.nFileIndexHigh,
+        Info.nFileIndexLow);
+  }
   return error_code::success();
 
 handle_status_error:





More information about the llvm-commits mailing list