1use super::{Context, Error, LibISLError, UnionPwMultiAff};
5use libc::uintptr_t;
6use std::ffi::CStr;
7use std::os::raw::c_char;
8
9pub struct UnionPwMultiAffList {
11 pub ptr: uintptr_t,
12 pub should_free_on_drop: bool,
13}
14
15extern "C" {
16
17 fn isl_union_pw_multi_aff_list_add(list: uintptr_t, el: uintptr_t) -> uintptr_t;
18
19 fn isl_union_pw_multi_aff_list_alloc(ctx: uintptr_t, n: i32) -> uintptr_t;
20
21 fn isl_union_pw_multi_aff_list_clear(list: uintptr_t) -> uintptr_t;
22
23 fn isl_union_pw_multi_aff_list_concat(list1: uintptr_t, list2: uintptr_t) -> uintptr_t;
24
25 fn isl_union_pw_multi_aff_list_copy(list: uintptr_t) -> uintptr_t;
26
27 fn isl_union_pw_multi_aff_list_drop(list: uintptr_t, first: u32, n: u32) -> uintptr_t;
28
29 fn isl_union_pw_multi_aff_list_dump(list: uintptr_t) -> ();
30
31 fn isl_union_pw_multi_aff_list_free(list: uintptr_t) -> uintptr_t;
32
33 fn isl_union_pw_multi_aff_list_from_union_pw_multi_aff(el: uintptr_t) -> uintptr_t;
34
35 fn isl_union_pw_multi_aff_list_get_at(list: uintptr_t, index: i32) -> uintptr_t;
36
37 fn isl_union_pw_multi_aff_list_get_ctx(list: uintptr_t) -> uintptr_t;
38
39 fn isl_union_pw_multi_aff_list_get_union_pw_multi_aff(list: uintptr_t, index: i32)
40 -> uintptr_t;
41
42 fn isl_union_pw_multi_aff_list_insert(list: uintptr_t, pos: u32, el: uintptr_t) -> uintptr_t;
43
44 fn isl_union_pw_multi_aff_list_n_union_pw_multi_aff(list: uintptr_t) -> i32;
45
46 fn isl_union_pw_multi_aff_list_reverse(list: uintptr_t) -> uintptr_t;
47
48 fn isl_union_pw_multi_aff_list_set_at(list: uintptr_t, index: i32, el: uintptr_t) -> uintptr_t;
49
50 fn isl_union_pw_multi_aff_list_set_union_pw_multi_aff(list: uintptr_t, index: i32,
51 el: uintptr_t)
52 -> uintptr_t;
53
54 fn isl_union_pw_multi_aff_list_size(list: uintptr_t) -> i32;
55
56 fn isl_union_pw_multi_aff_list_swap(list: uintptr_t, pos1: u32, pos2: u32) -> uintptr_t;
57
58 fn isl_union_pw_multi_aff_list_to_str(list: uintptr_t) -> *const c_char;
59
60}
61
62impl UnionPwMultiAffList {
63 pub fn add(self, el: UnionPwMultiAff) -> Result<UnionPwMultiAffList, LibISLError> {
65 let list = self;
66 let isl_rs_ctx = list.get_ctx();
67 let mut list = list;
68 list.do_not_free_on_drop();
69 let list = list.ptr;
70 let mut el = el;
71 el.do_not_free_on_drop();
72 let el = el.ptr;
73 let isl_rs_result = unsafe { isl_union_pw_multi_aff_list_add(list, el) };
74 let isl_rs_result = UnionPwMultiAffList { ptr: isl_rs_result,
75 should_free_on_drop: true };
76 let err = isl_rs_ctx.last_error();
77 if err != Error::None_ {
78 let err_msg = isl_rs_ctx.last_error_msg();
79 isl_rs_ctx.reset_error();
80 return Err(LibISLError::new(err, err_msg));
81 }
82 Ok(isl_rs_result)
83 }
84
85 pub fn alloc(ctx: &Context, n: i32) -> Result<UnionPwMultiAffList, LibISLError> {
87 let isl_rs_ctx = Context { ptr: ctx.ptr,
88 should_free_on_drop: false };
89 let ctx = ctx.ptr;
90 let isl_rs_result = unsafe { isl_union_pw_multi_aff_list_alloc(ctx, n) };
91 let isl_rs_result = UnionPwMultiAffList { ptr: isl_rs_result,
92 should_free_on_drop: true };
93 let err = isl_rs_ctx.last_error();
94 if err != Error::None_ {
95 let err_msg = isl_rs_ctx.last_error_msg();
96 isl_rs_ctx.reset_error();
97 return Err(LibISLError::new(err, err_msg));
98 }
99 Ok(isl_rs_result)
100 }
101
102 pub fn clear(self) -> Result<UnionPwMultiAffList, LibISLError> {
104 let list = self;
105 let isl_rs_ctx = list.get_ctx();
106 let mut list = list;
107 list.do_not_free_on_drop();
108 let list = list.ptr;
109 let isl_rs_result = unsafe { isl_union_pw_multi_aff_list_clear(list) };
110 let isl_rs_result = UnionPwMultiAffList { ptr: isl_rs_result,
111 should_free_on_drop: true };
112 let err = isl_rs_ctx.last_error();
113 if err != Error::None_ {
114 let err_msg = isl_rs_ctx.last_error_msg();
115 isl_rs_ctx.reset_error();
116 return Err(LibISLError::new(err, err_msg));
117 }
118 Ok(isl_rs_result)
119 }
120
121 pub fn concat(self, list2: UnionPwMultiAffList) -> Result<UnionPwMultiAffList, LibISLError> {
123 let list1 = self;
124 let isl_rs_ctx = list1.get_ctx();
125 let mut list1 = list1;
126 list1.do_not_free_on_drop();
127 let list1 = list1.ptr;
128 let mut list2 = list2;
129 list2.do_not_free_on_drop();
130 let list2 = list2.ptr;
131 let isl_rs_result = unsafe { isl_union_pw_multi_aff_list_concat(list1, list2) };
132 let isl_rs_result = UnionPwMultiAffList { ptr: isl_rs_result,
133 should_free_on_drop: true };
134 let err = isl_rs_ctx.last_error();
135 if err != Error::None_ {
136 let err_msg = isl_rs_ctx.last_error_msg();
137 isl_rs_ctx.reset_error();
138 return Err(LibISLError::new(err, err_msg));
139 }
140 Ok(isl_rs_result)
141 }
142
143 pub fn copy(&self) -> Result<UnionPwMultiAffList, LibISLError> {
145 let list = self;
146 let isl_rs_ctx = list.get_ctx();
147 let list = list.ptr;
148 let isl_rs_result = unsafe { isl_union_pw_multi_aff_list_copy(list) };
149 let isl_rs_result = UnionPwMultiAffList { ptr: isl_rs_result,
150 should_free_on_drop: true };
151 let err = isl_rs_ctx.last_error();
152 if err != Error::None_ {
153 let err_msg = isl_rs_ctx.last_error_msg();
154 isl_rs_ctx.reset_error();
155 return Err(LibISLError::new(err, err_msg));
156 }
157 Ok(isl_rs_result)
158 }
159
160 pub fn drop(self, first: u32, n: u32) -> Result<UnionPwMultiAffList, LibISLError> {
162 let list = self;
163 let isl_rs_ctx = list.get_ctx();
164 let mut list = list;
165 list.do_not_free_on_drop();
166 let list = list.ptr;
167 let isl_rs_result = unsafe { isl_union_pw_multi_aff_list_drop(list, first, n) };
168 let isl_rs_result = UnionPwMultiAffList { ptr: isl_rs_result,
169 should_free_on_drop: true };
170 let err = isl_rs_ctx.last_error();
171 if err != Error::None_ {
172 let err_msg = isl_rs_ctx.last_error_msg();
173 isl_rs_ctx.reset_error();
174 return Err(LibISLError::new(err, err_msg));
175 }
176 Ok(isl_rs_result)
177 }
178
179 pub fn dump(&self) -> Result<(), LibISLError> {
181 let list = self;
182 let isl_rs_ctx = list.get_ctx();
183 let list = list.ptr;
184 let isl_rs_result = unsafe { isl_union_pw_multi_aff_list_dump(list) };
185 let err = isl_rs_ctx.last_error();
186 if err != Error::None_ {
187 let err_msg = isl_rs_ctx.last_error_msg();
188 isl_rs_ctx.reset_error();
189 return Err(LibISLError::new(err, err_msg));
190 }
191 Ok(isl_rs_result)
192 }
193
194 pub fn free(self) -> Result<UnionPwMultiAffList, LibISLError> {
196 let list = self;
197 let isl_rs_ctx = list.get_ctx();
198 let mut list = list;
199 list.do_not_free_on_drop();
200 let list = list.ptr;
201 let isl_rs_result = unsafe { isl_union_pw_multi_aff_list_free(list) };
202 let isl_rs_result = UnionPwMultiAffList { ptr: isl_rs_result,
203 should_free_on_drop: true };
204 let err = isl_rs_ctx.last_error();
205 if err != Error::None_ {
206 let err_msg = isl_rs_ctx.last_error_msg();
207 isl_rs_ctx.reset_error();
208 return Err(LibISLError::new(err, err_msg));
209 }
210 Ok(isl_rs_result)
211 }
212
213 pub fn from_union_pw_multi_aff(el: UnionPwMultiAff)
215 -> Result<UnionPwMultiAffList, LibISLError> {
216 let isl_rs_ctx = el.get_ctx();
217 let mut el = el;
218 el.do_not_free_on_drop();
219 let el = el.ptr;
220 let isl_rs_result = unsafe { isl_union_pw_multi_aff_list_from_union_pw_multi_aff(el) };
221 let isl_rs_result = UnionPwMultiAffList { ptr: isl_rs_result,
222 should_free_on_drop: true };
223 let err = isl_rs_ctx.last_error();
224 if err != Error::None_ {
225 let err_msg = isl_rs_ctx.last_error_msg();
226 isl_rs_ctx.reset_error();
227 return Err(LibISLError::new(err, err_msg));
228 }
229 Ok(isl_rs_result)
230 }
231
232 pub fn get_at(&self, index: i32) -> Result<UnionPwMultiAff, LibISLError> {
234 let list = self;
235 let isl_rs_ctx = list.get_ctx();
236 let list = list.ptr;
237 let isl_rs_result = unsafe { isl_union_pw_multi_aff_list_get_at(list, index) };
238 let isl_rs_result = UnionPwMultiAff { ptr: isl_rs_result,
239 should_free_on_drop: true };
240 let err = isl_rs_ctx.last_error();
241 if err != Error::None_ {
242 let err_msg = isl_rs_ctx.last_error_msg();
243 isl_rs_ctx.reset_error();
244 return Err(LibISLError::new(err, err_msg));
245 }
246 Ok(isl_rs_result)
247 }
248
249 pub fn get_ctx(&self) -> Context {
251 let list = self;
252 let list = list.ptr;
253 let isl_rs_result = unsafe { isl_union_pw_multi_aff_list_get_ctx(list) };
254 let isl_rs_result = Context { ptr: isl_rs_result,
255 should_free_on_drop: false };
256 isl_rs_result
257 }
258
259 pub fn get_union_pw_multi_aff(&self, index: i32) -> Result<UnionPwMultiAff, LibISLError> {
261 let list = self;
262 let isl_rs_ctx = list.get_ctx();
263 let list = list.ptr;
264 let isl_rs_result =
265 unsafe { isl_union_pw_multi_aff_list_get_union_pw_multi_aff(list, index) };
266 let isl_rs_result = UnionPwMultiAff { ptr: isl_rs_result,
267 should_free_on_drop: true };
268 let err = isl_rs_ctx.last_error();
269 if err != Error::None_ {
270 let err_msg = isl_rs_ctx.last_error_msg();
271 isl_rs_ctx.reset_error();
272 return Err(LibISLError::new(err, err_msg));
273 }
274 Ok(isl_rs_result)
275 }
276
277 pub fn insert(self, pos: u32, el: UnionPwMultiAff) -> Result<UnionPwMultiAffList, LibISLError> {
279 let list = self;
280 let isl_rs_ctx = list.get_ctx();
281 let mut list = list;
282 list.do_not_free_on_drop();
283 let list = list.ptr;
284 let mut el = el;
285 el.do_not_free_on_drop();
286 let el = el.ptr;
287 let isl_rs_result = unsafe { isl_union_pw_multi_aff_list_insert(list, pos, el) };
288 let isl_rs_result = UnionPwMultiAffList { ptr: isl_rs_result,
289 should_free_on_drop: true };
290 let err = isl_rs_ctx.last_error();
291 if err != Error::None_ {
292 let err_msg = isl_rs_ctx.last_error_msg();
293 isl_rs_ctx.reset_error();
294 return Err(LibISLError::new(err, err_msg));
295 }
296 Ok(isl_rs_result)
297 }
298
299 pub fn n_union_pw_multi_aff(&self) -> Result<i32, LibISLError> {
301 let list = self;
302 let isl_rs_ctx = list.get_ctx();
303 let list = list.ptr;
304 let isl_rs_result = unsafe { isl_union_pw_multi_aff_list_n_union_pw_multi_aff(list) };
305 let err = isl_rs_ctx.last_error();
306 if err != Error::None_ {
307 let err_msg = isl_rs_ctx.last_error_msg();
308 isl_rs_ctx.reset_error();
309 return Err(LibISLError::new(err, err_msg));
310 }
311 Ok(isl_rs_result)
312 }
313
314 pub fn reverse(self) -> Result<UnionPwMultiAffList, LibISLError> {
316 let list = self;
317 let isl_rs_ctx = list.get_ctx();
318 let mut list = list;
319 list.do_not_free_on_drop();
320 let list = list.ptr;
321 let isl_rs_result = unsafe { isl_union_pw_multi_aff_list_reverse(list) };
322 let isl_rs_result = UnionPwMultiAffList { ptr: isl_rs_result,
323 should_free_on_drop: true };
324 let err = isl_rs_ctx.last_error();
325 if err != Error::None_ {
326 let err_msg = isl_rs_ctx.last_error_msg();
327 isl_rs_ctx.reset_error();
328 return Err(LibISLError::new(err, err_msg));
329 }
330 Ok(isl_rs_result)
331 }
332
333 pub fn set_at(self, index: i32, el: UnionPwMultiAff)
335 -> Result<UnionPwMultiAffList, LibISLError> {
336 let list = self;
337 let isl_rs_ctx = list.get_ctx();
338 let mut list = list;
339 list.do_not_free_on_drop();
340 let list = list.ptr;
341 let mut el = el;
342 el.do_not_free_on_drop();
343 let el = el.ptr;
344 let isl_rs_result = unsafe { isl_union_pw_multi_aff_list_set_at(list, index, el) };
345 let isl_rs_result = UnionPwMultiAffList { ptr: isl_rs_result,
346 should_free_on_drop: true };
347 let err = isl_rs_ctx.last_error();
348 if err != Error::None_ {
349 let err_msg = isl_rs_ctx.last_error_msg();
350 isl_rs_ctx.reset_error();
351 return Err(LibISLError::new(err, err_msg));
352 }
353 Ok(isl_rs_result)
354 }
355
356 pub fn set_union_pw_multi_aff(self, index: i32, el: UnionPwMultiAff)
358 -> Result<UnionPwMultiAffList, LibISLError> {
359 let list = self;
360 let isl_rs_ctx = list.get_ctx();
361 let mut list = list;
362 list.do_not_free_on_drop();
363 let list = list.ptr;
364 let mut el = el;
365 el.do_not_free_on_drop();
366 let el = el.ptr;
367 let isl_rs_result =
368 unsafe { isl_union_pw_multi_aff_list_set_union_pw_multi_aff(list, index, el) };
369 let isl_rs_result = UnionPwMultiAffList { ptr: isl_rs_result,
370 should_free_on_drop: true };
371 let err = isl_rs_ctx.last_error();
372 if err != Error::None_ {
373 let err_msg = isl_rs_ctx.last_error_msg();
374 isl_rs_ctx.reset_error();
375 return Err(LibISLError::new(err, err_msg));
376 }
377 Ok(isl_rs_result)
378 }
379
380 pub fn size(&self) -> Result<i32, LibISLError> {
382 let list = self;
383 let isl_rs_ctx = list.get_ctx();
384 let list = list.ptr;
385 let isl_rs_result = unsafe { isl_union_pw_multi_aff_list_size(list) };
386 let err = isl_rs_ctx.last_error();
387 if err != Error::None_ {
388 let err_msg = isl_rs_ctx.last_error_msg();
389 isl_rs_ctx.reset_error();
390 return Err(LibISLError::new(err, err_msg));
391 }
392 Ok(isl_rs_result)
393 }
394
395 pub fn swap(self, pos1: u32, pos2: u32) -> Result<UnionPwMultiAffList, LibISLError> {
397 let list = self;
398 let isl_rs_ctx = list.get_ctx();
399 let mut list = list;
400 list.do_not_free_on_drop();
401 let list = list.ptr;
402 let isl_rs_result = unsafe { isl_union_pw_multi_aff_list_swap(list, pos1, pos2) };
403 let isl_rs_result = UnionPwMultiAffList { ptr: isl_rs_result,
404 should_free_on_drop: true };
405 let err = isl_rs_ctx.last_error();
406 if err != Error::None_ {
407 let err_msg = isl_rs_ctx.last_error_msg();
408 isl_rs_ctx.reset_error();
409 return Err(LibISLError::new(err, err_msg));
410 }
411 Ok(isl_rs_result)
412 }
413
414 pub fn to_str(&self) -> Result<&str, LibISLError> {
416 let list = self;
417 let isl_rs_ctx = list.get_ctx();
418 let list = list.ptr;
419 let isl_rs_result = unsafe { isl_union_pw_multi_aff_list_to_str(list) };
420 let isl_rs_result = unsafe { CStr::from_ptr(isl_rs_result) };
421 let isl_rs_result = isl_rs_result.to_str().unwrap();
422 let err = isl_rs_ctx.last_error();
423 if err != Error::None_ {
424 let err_msg = isl_rs_ctx.last_error_msg();
425 isl_rs_ctx.reset_error();
426 return Err(LibISLError::new(err, err_msg));
427 }
428 Ok(isl_rs_result)
429 }
430
431 pub fn do_not_free_on_drop(&mut self) {
434 self.should_free_on_drop = false;
435 }
436}
437
438impl Drop for UnionPwMultiAffList {
439 fn drop(&mut self) {
440 if self.should_free_on_drop {
441 unsafe {
442 isl_union_pw_multi_aff_list_free(self.ptr);
443 }
444 }
445 }
446}