-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[llvm][Support] Make sys::fs::file_t into a seperate type #160588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cachemeifyoucan
wants to merge
8
commits into
main
Choose a base branch
from
users/cachemeifyoucan/spr/llvmsupport-make-sysfsfile_t-into-a-seperate-type
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2f9ef51
[𝘀𝗽𝗿] initial version
cachemeifyoucan 9690e48
clang-format
cachemeifyoucan a67cbb3
fix some comments
cachemeifyoucan 724d163
fix windows build attempt
cachemeifyoucan 964978d
fix windows attempt 2
cachemeifyoucan dc3d12c
rebase and retest
cachemeifyoucan 27a3e43
address review get() -> native_handle() and constexpr invalid value
cachemeifyoucan 6e9c978
fix windows
cachemeifyoucan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| /// \file | ||
| /// This file declares llvm::sys::fs::file_t type. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_SUPPORT_FILE_H | ||
| #define LLVM_SUPPORT_FILE_H | ||
|
|
||
| #include "llvm/Support/Compiler.h" | ||
|
|
||
| namespace llvm::sys::fs { | ||
|
|
||
| /// This class wraps the platform specific file handle/descriptor type to | ||
| /// provide an unified representation. | ||
| struct file_t { | ||
| #if defined(_WIN32) | ||
| /// A Win32 HANDLE is a typedef of void* | ||
| using value_type = void *; | ||
| #else | ||
| /// A file descriptor on UNIX. | ||
| using value_type = int; | ||
| #endif | ||
| value_type Value; | ||
|
|
||
| /// Value for an invalid file descriptor/handle. | ||
| #if defined(_WIN32) | ||
| static constexpr value_type Invalid = INVALID_FILE_HANDLE; | ||
| #else | ||
| static constexpr value_type Invalid = -1; | ||
| #endif | ||
|
|
||
| /// Default constructor to invalid file. | ||
| file_t() : Value(Invalid) {} | ||
|
|
||
| /// Implicit constructor from underlying value. | ||
| // TODO: Make this explicit to flush out type mismatches. | ||
| file_t(value_type Value) : Value(Value) {} | ||
|
|
||
| /// Is a valid file. | ||
| bool isValid() const { return Value != Invalid; } | ||
|
|
||
| /// Get the underlying value and return a platform specific value. | ||
| value_type native_handle() const { return Value; } | ||
| }; | ||
|
|
||
| inline bool operator==(file_t LHS, file_t RHS) { | ||
| return LHS.native_handle() == RHS.native_handle(); | ||
| } | ||
|
|
||
| inline bool operator!=(file_t LHS, file_t RHS) { return !(LHS == RHS); } | ||
|
|
||
| } // namespace llvm::sys::fs | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would "_t" mean in this context? Previously it was a short for "typedef", but here should we keep that? Or make it something more explicit, like
file?file_desc?file_descriptor?file_handle?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is mostly keeping the source compatibility with the old name to avoid the need to updating the entire project.
I don't mind doing that but just seems unnecessary. Maybe I can still use a deprecated
typedeffromfile_tto the new type name to avoid a hard transition. I am open to new name suggestions.