NagyDonat wrote:
> The `AllowedAccess` was added as separate member because logically it is
> different from the opened or closed state of the stream. It can be handled
> like an optional member that is valid only in the opened state.
I understand why you say this, but after some thinking I disagree.
An attribute named "allowed access" should be relevant for _any_ stream, and it
should be set to "no access" or something equivalent for closed (and failed to
open) streams. The current code sets `AllowedAccess == ReadWrite` for `Closed`
streams, which is very confusing for the readers (even if it ends up being
ignored).
The type `AllowedAccessTy` should distinguish at least four possible values:
`enum AllowedAccessTy {ReadWrite, Read, Write, NoAccess};` – and then it is
very awkward to maintain a separate `Kind` which is only relevant in the
`NoAccess` case to distinguish `Closed` and `OpenFailed`.
**My primary proposal** is equivalent to what @tigbr suggested: you should get
rid of the enum `Kind` and extend `AllowedAccessTy` to
```c++
enum AllowedAccessTy {
ReadWrite,
Read,
Write,
NoAccess,
NoAccessOpenFailed
};
```
However you should keep the methods `isOpened()` etc. – and e.g. `isOpened()`
should return true if the `AllowedAccess` is one of `ReadWrite`, `Read` or
`Write`.
**Another alternative approach** is that you introduce a principled allowed
access type with four possible values as `enum AllowedAccessTy {ReadWrite,
Read, Write, NoAccess};` and replace `Kind` with an `IsOpenFailed` field that
is usually false but can be true when the `AllowedAccess` is `NoAccess`.
-------
> Instead of merging these states into a single enum it is better to add a new
> state map that stores extra information about opened streams and can contain
> `ErrorState`, `FilePositionIndeterminate` and `AllowedAccess`.
Adding a second separate state map would make the code significantly more
complex – it would be worse than the current state of the PR.
https://github.com/llvm/llvm-project/pull/229134
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits