isl_rs/bindings/
aff_list.rs

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