1 /// These are automatically generated checked C++ bindings for isl.
3 /// isl is a library for computing with integer sets and maps described by
4 /// Presburger formulas. On top of this, isl provides various tools for
5 /// polyhedral compilation, ranging from dependence analysis over scheduling
8 #ifndef ISL_CPP_CHECKED
9 #define ISL_CPP_CHECKED
18 #include <type_traits>
20 #if __cplusplus >= 201703L
28 #define ISLPP_STRINGIZE_(X) #X
29 #define ISLPP_STRINGIZE(X) ISLPP_STRINGIZE_(X)
31 #define ISLPP_ASSERT(test, message) \
35 fputs("Assertion \"" #test "\" failed at " __FILE__ \
36 ":" ISLPP_STRINGIZE(__LINE__) "\n " message "\n", \
41 /* Class used to check that isl::checked::boolean,
42 * isl::checked::stat and isl::checked::size values are checked for errors.
47 ISLPP_ASSERT(checked, "IMPLEMENTATION ERROR: Unchecked state");
53 mutable std::shared_ptr<checker> check = std::make_shared<checker>();
56 friend boolean manage(isl_bool val);
57 boolean(isl_bool val): val(val) {}
59 static boolean error() {
60 return boolean(isl_bool_error);
63 : val(isl_bool_error) {}
65 /* implicit */ boolean(bool val)
66 : val(val ? isl_bool_true : isl_bool_false) {}
71 check->checked = true;
75 bool is_error() const { check->checked = true; return val == isl_bool_error; }
76 bool is_false() const { check->checked = true; return val == isl_bool_false; }
77 bool is_true() const { check->checked = true; return val == isl_bool_true; }
79 explicit operator bool() const {
80 ISLPP_ASSERT(check->checked, "IMPLEMENTATION ERROR: Unchecked error state");
81 ISLPP_ASSERT(!is_error(), "IMPLEMENTATION ERROR: Unhandled error state");
86 if (val == isl_bool_true)
88 else if (val == isl_bool_false)
93 boolean operator!() const {
94 return boolean(*this).negate();
98 inline boolean manage(isl_bool val) {
105 /* implicit */ ctx(isl_ctx *ctx) : ptr(ctx) {}
114 #if __cplusplus >= 201703L
115 static void free_user(void *user) {
116 std::any *p = static_cast<std::any *>(user);
122 /* Class encapsulating an isl_stat value.
126 mutable std::shared_ptr<checker> check = std::make_shared<checker>();
129 friend stat manage(isl_stat val);
130 stat(isl_stat val) : val(val) {}
133 return stat(isl_stat_ok);
135 static stat error() {
136 return stat(isl_stat_error);
138 stat() : val(isl_stat_error) {}
141 check->checked = true;
145 bool is_error() const {
146 check->checked = true;
147 return val == isl_stat_error;
150 check->checked = true;
151 return val == isl_stat_ok;
155 inline stat manage(isl_stat val)
160 /* Class encapsulating an isl_size value.
164 mutable std::shared_ptr<checker> check = std::make_shared<checker>();
167 friend size manage(isl_size val);
168 size(isl_size val) : val(val) {}
170 size() : val(isl_size_error) {}
174 val = isl_size_error;
175 check->checked = true;
179 bool is_error() const {
180 check->checked = true;
181 return val == isl_size_error;
184 explicit operator unsigned() const {
185 ISLPP_ASSERT(check->checked,
186 "IMPLEMENTATION ERROR: Unchecked error state");
187 ISLPP_ASSERT(!is_error(),
188 "IMPLEMENTATION ERROR: Unhandled error state");
193 inline size manage(isl_size val)