[llvm-commits] [llvm] r121380 - in /llvm/trunk: include/llvm/Support/FileSystem.h lib/Support/PathV2.cpp

Michael J. Spencer bigcheesegs at gmail.com
Thu Dec 9 09:37:02 PST 2010


Author: mspencer
Date: Thu Dec  9 11:37:02 2010
New Revision: 121380

URL: http://llvm.org/viewvc/llvm-project?rev=121380&view=rev
Log:
Support/FileSystem: Change file_status predicate functions that cannot fail to
return their result instead of an error_code. Also add some missing predicate
functions.

Modified:
    llvm/trunk/include/llvm/Support/FileSystem.h
    llvm/trunk/lib/Support/PathV2.cpp

Modified: llvm/trunk/include/llvm/Support/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=121380&r1=121379&r2=121380&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FileSystem.h (original)
+++ llvm/trunk/include/llvm/Support/FileSystem.h Thu Dec  9 11:37:02 2010
@@ -231,11 +231,9 @@
 /// @brief Does file exist?
 ///
 /// @param status A file_status previously returned from stat.
-/// @param result Set to true if the file represented by status exists, false if
-///               it does not. Undefined otherwise.
-/// @results errc::success if result has been successfully set, otherwise a
-///          platform specific error_code.
-error_code exists(file_status status, bool &result);
+/// @results True if the file represented by status exists, false if it does
+///          not.
+bool exists(file_status status);
 
 /// @brief Does file exist?
 ///
@@ -246,6 +244,17 @@
 ///          platform specific error_code.
 error_code exists(const Twine &path, bool &result);
 
+/// @brief Do file_status's represent the same thing?
+///
+/// @param A Input file_status.
+/// @param B Input file_status.
+///
+/// assert(status_known(A) || status_known(B));
+///
+/// @results True if A and B both represent the same file system entity, false
+///          otherwise.
+bool equivalent(file_status A, file_status B);
+
 /// @brief Do paths represent the same thing?
 ///
 /// @param A Input path A.
@@ -266,12 +275,9 @@
 
 /// @brief Does status represent a directory?
 ///
-/// @param status A file_status previously returned from stat.
-/// @param result Set to true if the file represented by status is a directory,
-///               false if it is not. Undefined otherwise.
-/// @results errc::success if result has been successfully set, otherwise a
-///          platform specific error_code.
-error_code is_directory(file_status status, bool &result);
+/// @param status A file_status previously returned from status.
+/// @results status.type() == file_type::directory_file.
+bool is_directory(file_status status);
 
 /// @brief Is path a directory?
 ///
@@ -293,12 +299,9 @@
 
 /// @brief Does status represent a regular file?
 ///
-/// @param status A file_status previously returned from stat.
-/// @param result Set to true if the file represented by status is a regular
-///               file, false if it is not. Undefined otherwise.
-/// @results errc::success if result has been successfully set, otherwise a
-///          platform specific error_code.
-error_code is_regular_file(file_status status, bool &result);
+/// @param status A file_status previously returned from status.
+/// @results status_known(status) && status.type() == file_type::regular_file.
+bool is_regular_file(file_status status);
 
 /// @brief Is path a regular file?
 ///
@@ -309,16 +312,13 @@
 ///          platform specific error_code.
 error_code is_regular_file(const Twine &path, bool &result);
 
-/// @brief Does status represent something that exists but is not a directory,
-///        regular file, or symlink?
+/// @brief Does this status represent something that exists but is not a
+///        directory, regular file, or symlink?
 ///
-/// @param status A file_status previously returned from stat.
-/// @param result Set to true if the file represented by status exists, but is
-///               not a directory, regular file, or a symlink, false if it does
-///               not. Undefined otherwise.
-/// @results errc::success if result has been successfully set, otherwise a
-///          platform specific error_code.
-error_code is_other(file_status status, bool &result);
+/// @param status A file_status previously returned from status.
+/// @results exists(s) && !is_regular_file(s) && !is_directory(s) &&
+///          !is_symlink(s)
+bool is_other(file_status status);
 
 /// @brief Is path something that exists but is not a directory,
 ///        regular file, or symlink?
@@ -333,11 +333,8 @@
 /// @brief Does status represent a symlink?
 ///
 /// @param status A file_status previously returned from stat.
-/// @param result Set to true if the file represented by status is a symlink,
-///               false if it is not. Undefined otherwise.
-/// @results errc::success if result has been successfully set, otherwise a
-///          platform specific error_code.
-error_code is_symlink(file_status status, bool &result);
+/// @param result status.type() == symlink_file.
+bool is_symlink(file_status status);
 
 /// @brief Is path a symlink?
 ///
@@ -393,6 +390,12 @@
 /// @brief Is status available?
 ///
 /// @param path Input path.
+/// @results True if status() != status_error.
+bool status_known(file_status s);
+
+/// @brief Is status available?
+///
+/// @param path Input path.
 /// @param result Set to true if status() != status_error.
 /// @results errc::success if result has been successfully set, otherwise a
 ///          platform specific error_code.

Modified: llvm/trunk/lib/Support/PathV2.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/PathV2.cpp?rev=121380&r1=121379&r2=121380&view=diff
==============================================================================
--- llvm/trunk/lib/Support/PathV2.cpp (original)
+++ llvm/trunk/lib/Support/PathV2.cpp Thu Dec  9 11:37:02 2010
@@ -625,6 +625,33 @@
   return create_directory(p, existed);
 }
 
+bool exists(file_status status) {
+  return status_known(status) && status.type() != file_type::file_not_found;
+}
+
+bool status_known(file_status s) {
+  return s.type() != file_type::status_error;
+}
+
+bool is_directory(file_status status) {
+  return status.type() == file_type::directory_file;
+}
+
+bool is_regular_file(file_status status) {
+  return status.type() == file_type::regular_file;
+}
+
+bool is_symlink(file_status status) {
+  return status.type() == file_type::symlink_file;
+}
+
+bool is_other(file_status status) {
+  return exists(status) &&
+         !is_regular_file(status) &&
+         !is_directory(status) &&
+         !is_symlink(status);
+}
+
 void directory_entry::replace_filename(const Twine &filename, file_status st,
                                        file_status symlink_st) {
   SmallString<128> path(Path.begin(), Path.end());





More information about the llvm-commits mailing list