LLVM: include/llvm/Support/LogicalResult.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9#ifndef LLVM_SUPPORT_LOGICALRESULT_H
10#define LLVM_SUPPORT_LOGICALRESULT_H
11
12#include
13#include
14
15namespace llvm {
16
17
18
19
20
21
22
23
24
25struct [[nodiscard]] LogicalResult {
26public:
27
28
29 static LogicalResult success(bool IsSuccess = true) {
30 return LogicalResult(IsSuccess);
31 }
32
33
34
35 static LogicalResult failure(bool IsFailure = true) {
36 return LogicalResult(!IsFailure);
37 }
38
39
40 constexpr bool succeeded() const { return IsSuccess; }
41
42
43 constexpr bool failed() const { return !IsSuccess; }
44
45private:
46 LogicalResult(bool IsSuccess) : IsSuccess(IsSuccess) {}
47
48
49
50 bool IsSuccess;
51};
52
53
54
58
59
60
64
65
66
68
69
70
72
73
74
75
76template class [[nodiscard]] FailureOr : public std::optional {
77public:
78
79
82 "success should be constructed with an instance of 'T'");
83 }
87 template <typename U,
88 std::enable_if_t<std::is_constructible<T, U>::value> * = nullptr>
92
94
95private:
96
97 using std::optional<T>::operator bool;
98 using std::optional<T>::has_value;
99};
100
101
102template <typename T,
103 typename = std::enable_if_t<!std::is_convertible_v<T, bool>>>
107
108
109
110
111
112
113
114
115
116
117
118
119class [[nodiscard]] ParseResult : public LogicalResult {
120public:
122
123
124 constexpr explicit operator bool() const { return failed(); }
125};
126}
127
128#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
This class provides support for representing a failure result, or a valid value of type T.
Definition LogicalResult.h:76
FailureOr(const T &Y)
Definition LogicalResult.h:86
FailureOr()
Definition LogicalResult.h:84
FailureOr(LogicalResult Result)
Allow constructing from a LogicalResult.
Definition LogicalResult.h:80
FailureOr(T &&Y)
Definition LogicalResult.h:85
FailureOr(const FailureOr< U > &Other)
Definition LogicalResult.h:89
ParseResult(LogicalResult Result=success())
Definition LogicalResult.h:121
This is an optimization pass for GlobalISel generic memory operations.
bool succeeded(LogicalResult Result)
Utility function that returns true if the provided LogicalResult corresponds to a success value.
Definition LogicalResult.h:67
bool failed(LogicalResult Result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
Definition LogicalResult.h:71
LogicalResult failure(bool IsFailure=true)
Utility function to generate a LogicalResult.
Definition LogicalResult.h:61
LogicalResult success(bool IsSuccess=true)
Utility function to generate a LogicalResult.
Definition LogicalResult.h:55
Implement std::hash so that hash_code can be used in STL containers.
This class represents an efficient way to signal success or failure.
Definition LogicalResult.h:25
static LogicalResult failure(bool IsFailure=true)
If isFailure is true a failure result is generated, otherwise a 'success' result is generated.
Definition LogicalResult.h:35
constexpr bool succeeded() const
Returns true if the provided LogicalResult corresponds to a success value.
Definition LogicalResult.h:40
constexpr bool failed() const
Returns true if the provided LogicalResult corresponds to a failure value.
Definition LogicalResult.h:43
static LogicalResult success(bool IsSuccess=true)
If isSuccess is true a success result is generated, otherwise a 'failure' result is generated.
Definition LogicalResult.h:29