1use super::{
5 Aff, Context, DimType, Error, Id, LibISLError, PwAff, PwAffList, Set, Space, UnionPwAffList,
6 UnionPwMultiAff, UnionSet, Val,
7};
8use libc::uintptr_t;
9use std::ffi::{CStr, CString};
10use std::os::raw::c_char;
11
12pub struct UnionPwAff {
14 pub ptr: uintptr_t,
15 pub should_free_on_drop: bool,
16}
17
18extern "C" {
19
20 fn isl_union_pw_aff_add(upa1: uintptr_t, upa2: uintptr_t) -> uintptr_t;
21
22 fn isl_union_pw_aff_add_pw_aff(upa: uintptr_t, pa: uintptr_t) -> uintptr_t;
23
24 fn isl_union_pw_aff_aff_on_domain(domain: uintptr_t, aff: uintptr_t) -> uintptr_t;
25
26 fn isl_union_pw_aff_align_params(upa: uintptr_t, model: uintptr_t) -> uintptr_t;
27
28 fn isl_union_pw_aff_bind_id(upa: uintptr_t, id: uintptr_t) -> uintptr_t;
29
30 fn isl_union_pw_aff_coalesce(upa: uintptr_t) -> uintptr_t;
31
32 fn isl_union_pw_aff_copy(upa: uintptr_t) -> uintptr_t;
33
34 fn isl_union_pw_aff_dim(upa: uintptr_t, type_: i32) -> i32;
35
36 fn isl_union_pw_aff_domain(upa: uintptr_t) -> uintptr_t;
37
38 fn isl_union_pw_aff_drop_dims(upa: uintptr_t, type_: i32, first: u32, n: u32) -> uintptr_t;
39
40 fn isl_union_pw_aff_drop_unused_params(upa: uintptr_t) -> uintptr_t;
41
42 fn isl_union_pw_aff_dump(upa: uintptr_t) -> ();
43
44 fn isl_union_pw_aff_empty(space: uintptr_t) -> uintptr_t;
45
46 fn isl_union_pw_aff_empty_ctx(ctx: uintptr_t) -> uintptr_t;
47
48 fn isl_union_pw_aff_empty_space(space: uintptr_t) -> uintptr_t;
49
50 fn isl_union_pw_aff_extract_pw_aff(upa: uintptr_t, space: uintptr_t) -> uintptr_t;
51
52 fn isl_union_pw_aff_find_dim_by_name(upa: uintptr_t, type_: i32, name: *const c_char) -> i32;
53
54 fn isl_union_pw_aff_floor(upa: uintptr_t) -> uintptr_t;
55
56 fn isl_union_pw_aff_free(upa: uintptr_t) -> uintptr_t;
57
58 fn isl_union_pw_aff_from_aff(aff: uintptr_t) -> uintptr_t;
59
60 fn isl_union_pw_aff_from_pw_aff(pa: uintptr_t) -> uintptr_t;
61
62 fn isl_union_pw_aff_get_ctx(upa: uintptr_t) -> uintptr_t;
63
64 fn isl_union_pw_aff_get_pw_aff_list(upa: uintptr_t) -> uintptr_t;
65
66 fn isl_union_pw_aff_get_space(upa: uintptr_t) -> uintptr_t;
67
68 fn isl_union_pw_aff_gist(upa: uintptr_t, context: uintptr_t) -> uintptr_t;
69
70 fn isl_union_pw_aff_gist_params(upa: uintptr_t, context: uintptr_t) -> uintptr_t;
71
72 fn isl_union_pw_aff_intersect_domain(upa: uintptr_t, uset: uintptr_t) -> uintptr_t;
73
74 fn isl_union_pw_aff_intersect_domain_space(upa: uintptr_t, space: uintptr_t) -> uintptr_t;
75
76 fn isl_union_pw_aff_intersect_domain_union_set(upa: uintptr_t, uset: uintptr_t) -> uintptr_t;
77
78 fn isl_union_pw_aff_intersect_domain_wrapped_domain(upa: uintptr_t, uset: uintptr_t)
79 -> uintptr_t;
80
81 fn isl_union_pw_aff_intersect_domain_wrapped_range(upa: uintptr_t, uset: uintptr_t)
82 -> uintptr_t;
83
84 fn isl_union_pw_aff_intersect_params(upa: uintptr_t, set: uintptr_t) -> uintptr_t;
85
86 fn isl_union_pw_aff_involves_nan(upa: uintptr_t) -> i32;
87
88 fn isl_union_pw_aff_max_val(upa: uintptr_t) -> uintptr_t;
89
90 fn isl_union_pw_aff_min_val(upa: uintptr_t) -> uintptr_t;
91
92 fn isl_union_pw_aff_mod_val(upa: uintptr_t, f: uintptr_t) -> uintptr_t;
93
94 fn isl_union_pw_aff_n_pw_aff(upa: uintptr_t) -> i32;
95
96 fn isl_union_pw_aff_neg(upa: uintptr_t) -> uintptr_t;
97
98 fn isl_union_pw_aff_param_on_domain_id(domain: uintptr_t, id: uintptr_t) -> uintptr_t;
99
100 fn isl_union_pw_aff_plain_is_equal(upa1: uintptr_t, upa2: uintptr_t) -> i32;
101
102 fn isl_union_pw_aff_pullback_union_pw_multi_aff(upa: uintptr_t, upma: uintptr_t) -> uintptr_t;
103
104 fn isl_union_pw_aff_pw_aff_on_domain(domain: uintptr_t, pa: uintptr_t) -> uintptr_t;
105
106 fn isl_union_pw_aff_read_from_str(ctx: uintptr_t, str_: *const c_char) -> uintptr_t;
107
108 fn isl_union_pw_aff_reset_user(upa: uintptr_t) -> uintptr_t;
109
110 fn isl_union_pw_aff_scale_down_val(upa: uintptr_t, v: uintptr_t) -> uintptr_t;
111
112 fn isl_union_pw_aff_scale_val(upa: uintptr_t, v: uintptr_t) -> uintptr_t;
113
114 fn isl_union_pw_aff_set_dim_name(upa: uintptr_t, type_: i32, pos: u32, s: *const c_char)
115 -> uintptr_t;
116
117 fn isl_union_pw_aff_sub(upa1: uintptr_t, upa2: uintptr_t) -> uintptr_t;
118
119 fn isl_union_pw_aff_subtract_domain(upa: uintptr_t, uset: uintptr_t) -> uintptr_t;
120
121 fn isl_union_pw_aff_subtract_domain_space(upa: uintptr_t, space: uintptr_t) -> uintptr_t;
122
123 fn isl_union_pw_aff_subtract_domain_union_set(upa: uintptr_t, uset: uintptr_t) -> uintptr_t;
124
125 fn isl_union_pw_aff_to_list(el: uintptr_t) -> uintptr_t;
126
127 fn isl_union_pw_aff_to_str(upa: uintptr_t) -> *const c_char;
128
129 fn isl_union_pw_aff_union_add(upa1: uintptr_t, upa2: uintptr_t) -> uintptr_t;
130
131 fn isl_union_pw_aff_val_on_domain(domain: uintptr_t, v: uintptr_t) -> uintptr_t;
132
133 fn isl_union_pw_aff_zero_union_set(upa: uintptr_t) -> uintptr_t;
134
135}
136
137impl UnionPwAff {
138 pub fn add(self, upa2: UnionPwAff) -> Result<UnionPwAff, LibISLError> {
140 let upa1 = self;
141 let isl_rs_ctx = upa1.get_ctx();
142 let mut upa1 = upa1;
143 upa1.do_not_free_on_drop();
144 let upa1 = upa1.ptr;
145 let mut upa2 = upa2;
146 upa2.do_not_free_on_drop();
147 let upa2 = upa2.ptr;
148 let isl_rs_result = unsafe { isl_union_pw_aff_add(upa1, upa2) };
149 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
150 should_free_on_drop: true };
151 let err = isl_rs_ctx.last_error();
152 if err != Error::None_ {
153 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
154 }
155 Ok(isl_rs_result)
156 }
157
158 pub fn add_pw_aff(self, pa: PwAff) -> Result<UnionPwAff, LibISLError> {
160 let upa = self;
161 let isl_rs_ctx = upa.get_ctx();
162 let mut upa = upa;
163 upa.do_not_free_on_drop();
164 let upa = upa.ptr;
165 let mut pa = pa;
166 pa.do_not_free_on_drop();
167 let pa = pa.ptr;
168 let isl_rs_result = unsafe { isl_union_pw_aff_add_pw_aff(upa, pa) };
169 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
170 should_free_on_drop: true };
171 let err = isl_rs_ctx.last_error();
172 if err != Error::None_ {
173 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
174 }
175 Ok(isl_rs_result)
176 }
177
178 pub fn aff_on_domain(domain: UnionSet, aff: Aff) -> Result<UnionPwAff, LibISLError> {
180 let isl_rs_ctx = domain.get_ctx();
181 let mut domain = domain;
182 domain.do_not_free_on_drop();
183 let domain = domain.ptr;
184 let mut aff = aff;
185 aff.do_not_free_on_drop();
186 let aff = aff.ptr;
187 let isl_rs_result = unsafe { isl_union_pw_aff_aff_on_domain(domain, aff) };
188 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
189 should_free_on_drop: true };
190 let err = isl_rs_ctx.last_error();
191 if err != Error::None_ {
192 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
193 }
194 Ok(isl_rs_result)
195 }
196
197 pub fn align_params(self, model: Space) -> Result<UnionPwAff, LibISLError> {
199 let upa = self;
200 let isl_rs_ctx = upa.get_ctx();
201 let mut upa = upa;
202 upa.do_not_free_on_drop();
203 let upa = upa.ptr;
204 let mut model = model;
205 model.do_not_free_on_drop();
206 let model = model.ptr;
207 let isl_rs_result = unsafe { isl_union_pw_aff_align_params(upa, model) };
208 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
209 should_free_on_drop: true };
210 let err = isl_rs_ctx.last_error();
211 if err != Error::None_ {
212 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
213 }
214 Ok(isl_rs_result)
215 }
216
217 pub fn bind_id(self, id: Id) -> Result<UnionSet, LibISLError> {
219 let upa = self;
220 let isl_rs_ctx = upa.get_ctx();
221 let mut upa = upa;
222 upa.do_not_free_on_drop();
223 let upa = upa.ptr;
224 let mut id = id;
225 id.do_not_free_on_drop();
226 let id = id.ptr;
227 let isl_rs_result = unsafe { isl_union_pw_aff_bind_id(upa, id) };
228 let isl_rs_result = UnionSet { ptr: isl_rs_result,
229 should_free_on_drop: true };
230 let err = isl_rs_ctx.last_error();
231 if err != Error::None_ {
232 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
233 }
234 Ok(isl_rs_result)
235 }
236
237 pub fn coalesce(self) -> Result<UnionPwAff, LibISLError> {
239 let upa = self;
240 let isl_rs_ctx = upa.get_ctx();
241 let mut upa = upa;
242 upa.do_not_free_on_drop();
243 let upa = upa.ptr;
244 let isl_rs_result = unsafe { isl_union_pw_aff_coalesce(upa) };
245 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
246 should_free_on_drop: true };
247 let err = isl_rs_ctx.last_error();
248 if err != Error::None_ {
249 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
250 }
251 Ok(isl_rs_result)
252 }
253
254 pub fn copy(&self) -> Result<UnionPwAff, LibISLError> {
256 let upa = self;
257 let isl_rs_ctx = upa.get_ctx();
258 let upa = upa.ptr;
259 let isl_rs_result = unsafe { isl_union_pw_aff_copy(upa) };
260 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
261 should_free_on_drop: true };
262 let err = isl_rs_ctx.last_error();
263 if err != Error::None_ {
264 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
265 }
266 Ok(isl_rs_result)
267 }
268
269 pub fn dim(&self, type_: DimType) -> Result<i32, LibISLError> {
271 let upa = self;
272 let isl_rs_ctx = upa.get_ctx();
273 let upa = upa.ptr;
274 let type_ = type_.to_i32();
275 let isl_rs_result = unsafe { isl_union_pw_aff_dim(upa, type_) };
276 let err = isl_rs_ctx.last_error();
277 if err != Error::None_ {
278 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
279 }
280 Ok(isl_rs_result)
281 }
282
283 pub fn domain(self) -> Result<UnionSet, LibISLError> {
285 let upa = self;
286 let isl_rs_ctx = upa.get_ctx();
287 let mut upa = upa;
288 upa.do_not_free_on_drop();
289 let upa = upa.ptr;
290 let isl_rs_result = unsafe { isl_union_pw_aff_domain(upa) };
291 let isl_rs_result = UnionSet { ptr: isl_rs_result,
292 should_free_on_drop: true };
293 let err = isl_rs_ctx.last_error();
294 if err != Error::None_ {
295 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
296 }
297 Ok(isl_rs_result)
298 }
299
300 pub fn drop_dims(self, type_: DimType, first: u32, n: u32) -> Result<UnionPwAff, LibISLError> {
302 let upa = self;
303 let isl_rs_ctx = upa.get_ctx();
304 let mut upa = upa;
305 upa.do_not_free_on_drop();
306 let upa = upa.ptr;
307 let type_ = type_.to_i32();
308 let isl_rs_result = unsafe { isl_union_pw_aff_drop_dims(upa, type_, first, n) };
309 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
310 should_free_on_drop: true };
311 let err = isl_rs_ctx.last_error();
312 if err != Error::None_ {
313 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
314 }
315 Ok(isl_rs_result)
316 }
317
318 pub fn drop_unused_params(self) -> Result<UnionPwAff, LibISLError> {
320 let upa = self;
321 let isl_rs_ctx = upa.get_ctx();
322 let mut upa = upa;
323 upa.do_not_free_on_drop();
324 let upa = upa.ptr;
325 let isl_rs_result = unsafe { isl_union_pw_aff_drop_unused_params(upa) };
326 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
327 should_free_on_drop: true };
328 let err = isl_rs_ctx.last_error();
329 if err != Error::None_ {
330 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
331 }
332 Ok(isl_rs_result)
333 }
334
335 pub fn dump(&self) -> Result<(), LibISLError> {
337 let upa = self;
338 let isl_rs_ctx = upa.get_ctx();
339 let upa = upa.ptr;
340 let isl_rs_result = unsafe { isl_union_pw_aff_dump(upa) };
341 let err = isl_rs_ctx.last_error();
342 if err != Error::None_ {
343 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
344 }
345 Ok(isl_rs_result)
346 }
347
348 pub fn empty(space: Space) -> Result<UnionPwAff, LibISLError> {
350 let isl_rs_ctx = space.get_ctx();
351 let mut space = space;
352 space.do_not_free_on_drop();
353 let space = space.ptr;
354 let isl_rs_result = unsafe { isl_union_pw_aff_empty(space) };
355 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
356 should_free_on_drop: true };
357 let err = isl_rs_ctx.last_error();
358 if err != Error::None_ {
359 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
360 }
361 Ok(isl_rs_result)
362 }
363
364 pub fn empty_ctx(ctx: &Context) -> Result<UnionPwAff, LibISLError> {
366 let isl_rs_ctx = Context { ptr: ctx.ptr,
367 should_free_on_drop: false };
368 let ctx = ctx.ptr;
369 let isl_rs_result = unsafe { isl_union_pw_aff_empty_ctx(ctx) };
370 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
371 should_free_on_drop: true };
372 let err = isl_rs_ctx.last_error();
373 if err != Error::None_ {
374 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
375 }
376 Ok(isl_rs_result)
377 }
378
379 pub fn empty_space(space: Space) -> Result<UnionPwAff, LibISLError> {
381 let isl_rs_ctx = space.get_ctx();
382 let mut space = space;
383 space.do_not_free_on_drop();
384 let space = space.ptr;
385 let isl_rs_result = unsafe { isl_union_pw_aff_empty_space(space) };
386 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
387 should_free_on_drop: true };
388 let err = isl_rs_ctx.last_error();
389 if err != Error::None_ {
390 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
391 }
392 Ok(isl_rs_result)
393 }
394
395 pub fn extract_pw_aff(&self, space: Space) -> Result<PwAff, LibISLError> {
397 let upa = self;
398 let isl_rs_ctx = upa.get_ctx();
399 let upa = upa.ptr;
400 let mut space = space;
401 space.do_not_free_on_drop();
402 let space = space.ptr;
403 let isl_rs_result = unsafe { isl_union_pw_aff_extract_pw_aff(upa, space) };
404 let isl_rs_result = PwAff { ptr: isl_rs_result,
405 should_free_on_drop: true };
406 let err = isl_rs_ctx.last_error();
407 if err != Error::None_ {
408 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
409 }
410 Ok(isl_rs_result)
411 }
412
413 pub fn find_dim_by_name(&self, type_: DimType, name: &str) -> Result<i32, LibISLError> {
415 let upa = self;
416 let isl_rs_ctx = upa.get_ctx();
417 let upa = upa.ptr;
418 let type_ = type_.to_i32();
419 let name = CString::new(name).unwrap();
420 let name = name.as_ptr();
421 let isl_rs_result = unsafe { isl_union_pw_aff_find_dim_by_name(upa, type_, name) };
422 let err = isl_rs_ctx.last_error();
423 if err != Error::None_ {
424 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
425 }
426 Ok(isl_rs_result)
427 }
428
429 pub fn floor(self) -> Result<UnionPwAff, LibISLError> {
431 let upa = self;
432 let isl_rs_ctx = upa.get_ctx();
433 let mut upa = upa;
434 upa.do_not_free_on_drop();
435 let upa = upa.ptr;
436 let isl_rs_result = unsafe { isl_union_pw_aff_floor(upa) };
437 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
438 should_free_on_drop: true };
439 let err = isl_rs_ctx.last_error();
440 if err != Error::None_ {
441 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
442 }
443 Ok(isl_rs_result)
444 }
445
446 pub fn free(self) -> Result<UnionPwAff, LibISLError> {
448 let upa = self;
449 let isl_rs_ctx = upa.get_ctx();
450 let mut upa = upa;
451 upa.do_not_free_on_drop();
452 let upa = upa.ptr;
453 let isl_rs_result = unsafe { isl_union_pw_aff_free(upa) };
454 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
455 should_free_on_drop: true };
456 let err = isl_rs_ctx.last_error();
457 if err != Error::None_ {
458 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
459 }
460 Ok(isl_rs_result)
461 }
462
463 pub fn from_aff(aff: Aff) -> Result<UnionPwAff, LibISLError> {
465 let isl_rs_ctx = aff.get_ctx();
466 let mut aff = aff;
467 aff.do_not_free_on_drop();
468 let aff = aff.ptr;
469 let isl_rs_result = unsafe { isl_union_pw_aff_from_aff(aff) };
470 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
471 should_free_on_drop: true };
472 let err = isl_rs_ctx.last_error();
473 if err != Error::None_ {
474 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
475 }
476 Ok(isl_rs_result)
477 }
478
479 pub fn from_pw_aff(pa: PwAff) -> Result<UnionPwAff, LibISLError> {
481 let isl_rs_ctx = pa.get_ctx();
482 let mut pa = pa;
483 pa.do_not_free_on_drop();
484 let pa = pa.ptr;
485 let isl_rs_result = unsafe { isl_union_pw_aff_from_pw_aff(pa) };
486 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
487 should_free_on_drop: true };
488 let err = isl_rs_ctx.last_error();
489 if err != Error::None_ {
490 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
491 }
492 Ok(isl_rs_result)
493 }
494
495 pub fn get_ctx(&self) -> Context {
497 let upa = self;
498 let upa = upa.ptr;
499 let isl_rs_result = unsafe { isl_union_pw_aff_get_ctx(upa) };
500 let isl_rs_result = Context { ptr: isl_rs_result,
501 should_free_on_drop: false };
502 isl_rs_result
503 }
504
505 pub fn get_pw_aff_list(&self) -> Result<PwAffList, LibISLError> {
507 let upa = self;
508 let isl_rs_ctx = upa.get_ctx();
509 let upa = upa.ptr;
510 let isl_rs_result = unsafe { isl_union_pw_aff_get_pw_aff_list(upa) };
511 let isl_rs_result = PwAffList { ptr: isl_rs_result,
512 should_free_on_drop: true };
513 let err = isl_rs_ctx.last_error();
514 if err != Error::None_ {
515 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
516 }
517 Ok(isl_rs_result)
518 }
519
520 pub fn get_space(&self) -> Result<Space, LibISLError> {
522 let upa = self;
523 let isl_rs_ctx = upa.get_ctx();
524 let upa = upa.ptr;
525 let isl_rs_result = unsafe { isl_union_pw_aff_get_space(upa) };
526 let isl_rs_result = Space { ptr: isl_rs_result,
527 should_free_on_drop: true };
528 let err = isl_rs_ctx.last_error();
529 if err != Error::None_ {
530 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
531 }
532 Ok(isl_rs_result)
533 }
534
535 pub fn gist(self, context: UnionSet) -> Result<UnionPwAff, LibISLError> {
537 let upa = self;
538 let isl_rs_ctx = upa.get_ctx();
539 let mut upa = upa;
540 upa.do_not_free_on_drop();
541 let upa = upa.ptr;
542 let mut context = context;
543 context.do_not_free_on_drop();
544 let context = context.ptr;
545 let isl_rs_result = unsafe { isl_union_pw_aff_gist(upa, context) };
546 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
547 should_free_on_drop: true };
548 let err = isl_rs_ctx.last_error();
549 if err != Error::None_ {
550 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
551 }
552 Ok(isl_rs_result)
553 }
554
555 pub fn gist_params(self, context: Set) -> Result<UnionPwAff, LibISLError> {
557 let upa = self;
558 let isl_rs_ctx = upa.get_ctx();
559 let mut upa = upa;
560 upa.do_not_free_on_drop();
561 let upa = upa.ptr;
562 let mut context = context;
563 context.do_not_free_on_drop();
564 let context = context.ptr;
565 let isl_rs_result = unsafe { isl_union_pw_aff_gist_params(upa, context) };
566 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
567 should_free_on_drop: true };
568 let err = isl_rs_ctx.last_error();
569 if err != Error::None_ {
570 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
571 }
572 Ok(isl_rs_result)
573 }
574
575 pub fn intersect_domain(self, uset: UnionSet) -> Result<UnionPwAff, LibISLError> {
577 let upa = self;
578 let isl_rs_ctx = upa.get_ctx();
579 let mut upa = upa;
580 upa.do_not_free_on_drop();
581 let upa = upa.ptr;
582 let mut uset = uset;
583 uset.do_not_free_on_drop();
584 let uset = uset.ptr;
585 let isl_rs_result = unsafe { isl_union_pw_aff_intersect_domain(upa, uset) };
586 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
587 should_free_on_drop: true };
588 let err = isl_rs_ctx.last_error();
589 if err != Error::None_ {
590 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
591 }
592 Ok(isl_rs_result)
593 }
594
595 pub fn intersect_domain_space(self, space: Space) -> Result<UnionPwAff, LibISLError> {
597 let upa = self;
598 let isl_rs_ctx = upa.get_ctx();
599 let mut upa = upa;
600 upa.do_not_free_on_drop();
601 let upa = upa.ptr;
602 let mut space = space;
603 space.do_not_free_on_drop();
604 let space = space.ptr;
605 let isl_rs_result = unsafe { isl_union_pw_aff_intersect_domain_space(upa, space) };
606 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
607 should_free_on_drop: true };
608 let err = isl_rs_ctx.last_error();
609 if err != Error::None_ {
610 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
611 }
612 Ok(isl_rs_result)
613 }
614
615 pub fn intersect_domain_union_set(self, uset: UnionSet) -> Result<UnionPwAff, LibISLError> {
617 let upa = self;
618 let isl_rs_ctx = upa.get_ctx();
619 let mut upa = upa;
620 upa.do_not_free_on_drop();
621 let upa = upa.ptr;
622 let mut uset = uset;
623 uset.do_not_free_on_drop();
624 let uset = uset.ptr;
625 let isl_rs_result = unsafe { isl_union_pw_aff_intersect_domain_union_set(upa, uset) };
626 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
627 should_free_on_drop: true };
628 let err = isl_rs_ctx.last_error();
629 if err != Error::None_ {
630 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
631 }
632 Ok(isl_rs_result)
633 }
634
635 pub fn intersect_domain_wrapped_domain(self, uset: UnionSet)
637 -> Result<UnionPwAff, LibISLError> {
638 let upa = self;
639 let isl_rs_ctx = upa.get_ctx();
640 let mut upa = upa;
641 upa.do_not_free_on_drop();
642 let upa = upa.ptr;
643 let mut uset = uset;
644 uset.do_not_free_on_drop();
645 let uset = uset.ptr;
646 let isl_rs_result = unsafe { isl_union_pw_aff_intersect_domain_wrapped_domain(upa, uset) };
647 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
648 should_free_on_drop: true };
649 let err = isl_rs_ctx.last_error();
650 if err != Error::None_ {
651 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
652 }
653 Ok(isl_rs_result)
654 }
655
656 pub fn intersect_domain_wrapped_range(self, uset: UnionSet) -> Result<UnionPwAff, LibISLError> {
658 let upa = self;
659 let isl_rs_ctx = upa.get_ctx();
660 let mut upa = upa;
661 upa.do_not_free_on_drop();
662 let upa = upa.ptr;
663 let mut uset = uset;
664 uset.do_not_free_on_drop();
665 let uset = uset.ptr;
666 let isl_rs_result = unsafe { isl_union_pw_aff_intersect_domain_wrapped_range(upa, uset) };
667 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
668 should_free_on_drop: true };
669 let err = isl_rs_ctx.last_error();
670 if err != Error::None_ {
671 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
672 }
673 Ok(isl_rs_result)
674 }
675
676 pub fn intersect_params(self, set: Set) -> Result<UnionPwAff, LibISLError> {
678 let upa = self;
679 let isl_rs_ctx = upa.get_ctx();
680 let mut upa = upa;
681 upa.do_not_free_on_drop();
682 let upa = upa.ptr;
683 let mut set = set;
684 set.do_not_free_on_drop();
685 let set = set.ptr;
686 let isl_rs_result = unsafe { isl_union_pw_aff_intersect_params(upa, set) };
687 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
688 should_free_on_drop: true };
689 let err = isl_rs_ctx.last_error();
690 if err != Error::None_ {
691 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
692 }
693 Ok(isl_rs_result)
694 }
695
696 pub fn involves_nan(&self) -> Result<bool, LibISLError> {
698 let upa = self;
699 let isl_rs_ctx = upa.get_ctx();
700 let upa = upa.ptr;
701 let isl_rs_result = unsafe { isl_union_pw_aff_involves_nan(upa) };
702 let isl_rs_result = match isl_rs_result {
703 0 => false,
704 1 => true,
705 _ => panic!("Got isl_bool = -1"),
706 };
707 let err = isl_rs_ctx.last_error();
708 if err != Error::None_ {
709 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
710 }
711 Ok(isl_rs_result)
712 }
713
714 pub fn max_val(self) -> Result<Val, LibISLError> {
716 let upa = self;
717 let isl_rs_ctx = upa.get_ctx();
718 let mut upa = upa;
719 upa.do_not_free_on_drop();
720 let upa = upa.ptr;
721 let isl_rs_result = unsafe { isl_union_pw_aff_max_val(upa) };
722 let isl_rs_result = Val { ptr: isl_rs_result,
723 should_free_on_drop: true };
724 let err = isl_rs_ctx.last_error();
725 if err != Error::None_ {
726 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
727 }
728 Ok(isl_rs_result)
729 }
730
731 pub fn min_val(self) -> Result<Val, LibISLError> {
733 let upa = self;
734 let isl_rs_ctx = upa.get_ctx();
735 let mut upa = upa;
736 upa.do_not_free_on_drop();
737 let upa = upa.ptr;
738 let isl_rs_result = unsafe { isl_union_pw_aff_min_val(upa) };
739 let isl_rs_result = Val { ptr: isl_rs_result,
740 should_free_on_drop: true };
741 let err = isl_rs_ctx.last_error();
742 if err != Error::None_ {
743 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
744 }
745 Ok(isl_rs_result)
746 }
747
748 pub fn mod_val(self, f: Val) -> Result<UnionPwAff, LibISLError> {
750 let upa = self;
751 let isl_rs_ctx = upa.get_ctx();
752 let mut upa = upa;
753 upa.do_not_free_on_drop();
754 let upa = upa.ptr;
755 let mut f = f;
756 f.do_not_free_on_drop();
757 let f = f.ptr;
758 let isl_rs_result = unsafe { isl_union_pw_aff_mod_val(upa, f) };
759 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
760 should_free_on_drop: true };
761 let err = isl_rs_ctx.last_error();
762 if err != Error::None_ {
763 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
764 }
765 Ok(isl_rs_result)
766 }
767
768 pub fn n_pw_aff(&self) -> Result<i32, LibISLError> {
770 let upa = self;
771 let isl_rs_ctx = upa.get_ctx();
772 let upa = upa.ptr;
773 let isl_rs_result = unsafe { isl_union_pw_aff_n_pw_aff(upa) };
774 let err = isl_rs_ctx.last_error();
775 if err != Error::None_ {
776 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
777 }
778 Ok(isl_rs_result)
779 }
780
781 pub fn neg(self) -> Result<UnionPwAff, LibISLError> {
783 let upa = self;
784 let isl_rs_ctx = upa.get_ctx();
785 let mut upa = upa;
786 upa.do_not_free_on_drop();
787 let upa = upa.ptr;
788 let isl_rs_result = unsafe { isl_union_pw_aff_neg(upa) };
789 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
790 should_free_on_drop: true };
791 let err = isl_rs_ctx.last_error();
792 if err != Error::None_ {
793 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
794 }
795 Ok(isl_rs_result)
796 }
797
798 pub fn param_on_domain_id(domain: UnionSet, id: Id) -> Result<UnionPwAff, LibISLError> {
800 let isl_rs_ctx = domain.get_ctx();
801 let mut domain = domain;
802 domain.do_not_free_on_drop();
803 let domain = domain.ptr;
804 let mut id = id;
805 id.do_not_free_on_drop();
806 let id = id.ptr;
807 let isl_rs_result = unsafe { isl_union_pw_aff_param_on_domain_id(domain, id) };
808 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
809 should_free_on_drop: true };
810 let err = isl_rs_ctx.last_error();
811 if err != Error::None_ {
812 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
813 }
814 Ok(isl_rs_result)
815 }
816
817 pub fn plain_is_equal(&self, upa2: &UnionPwAff) -> Result<bool, LibISLError> {
819 let upa1 = self;
820 let isl_rs_ctx = upa1.get_ctx();
821 let upa1 = upa1.ptr;
822 let upa2 = upa2.ptr;
823 let isl_rs_result = unsafe { isl_union_pw_aff_plain_is_equal(upa1, upa2) };
824 let isl_rs_result = match isl_rs_result {
825 0 => false,
826 1 => true,
827 _ => panic!("Got isl_bool = -1"),
828 };
829 let err = isl_rs_ctx.last_error();
830 if err != Error::None_ {
831 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
832 }
833 Ok(isl_rs_result)
834 }
835
836 pub fn pullback_union_pw_multi_aff(self, upma: UnionPwMultiAff)
838 -> Result<UnionPwAff, LibISLError> {
839 let upa = self;
840 let isl_rs_ctx = upa.get_ctx();
841 let mut upa = upa;
842 upa.do_not_free_on_drop();
843 let upa = upa.ptr;
844 let mut upma = upma;
845 upma.do_not_free_on_drop();
846 let upma = upma.ptr;
847 let isl_rs_result = unsafe { isl_union_pw_aff_pullback_union_pw_multi_aff(upa, upma) };
848 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
849 should_free_on_drop: true };
850 let err = isl_rs_ctx.last_error();
851 if err != Error::None_ {
852 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
853 }
854 Ok(isl_rs_result)
855 }
856
857 pub fn pw_aff_on_domain(domain: UnionSet, pa: PwAff) -> Result<UnionPwAff, LibISLError> {
859 let isl_rs_ctx = domain.get_ctx();
860 let mut domain = domain;
861 domain.do_not_free_on_drop();
862 let domain = domain.ptr;
863 let mut pa = pa;
864 pa.do_not_free_on_drop();
865 let pa = pa.ptr;
866 let isl_rs_result = unsafe { isl_union_pw_aff_pw_aff_on_domain(domain, pa) };
867 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
868 should_free_on_drop: true };
869 let err = isl_rs_ctx.last_error();
870 if err != Error::None_ {
871 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
872 }
873 Ok(isl_rs_result)
874 }
875
876 pub fn read_from_str(ctx: &Context, str_: &str) -> Result<UnionPwAff, LibISLError> {
878 let isl_rs_ctx = Context { ptr: ctx.ptr,
879 should_free_on_drop: false };
880 let ctx = ctx.ptr;
881 let str_ = CString::new(str_).unwrap();
882 let str_ = str_.as_ptr();
883 let isl_rs_result = unsafe { isl_union_pw_aff_read_from_str(ctx, str_) };
884 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
885 should_free_on_drop: true };
886 let err = isl_rs_ctx.last_error();
887 if err != Error::None_ {
888 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
889 }
890 Ok(isl_rs_result)
891 }
892
893 pub fn reset_user(self) -> Result<UnionPwAff, LibISLError> {
895 let upa = self;
896 let isl_rs_ctx = upa.get_ctx();
897 let mut upa = upa;
898 upa.do_not_free_on_drop();
899 let upa = upa.ptr;
900 let isl_rs_result = unsafe { isl_union_pw_aff_reset_user(upa) };
901 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
902 should_free_on_drop: true };
903 let err = isl_rs_ctx.last_error();
904 if err != Error::None_ {
905 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
906 }
907 Ok(isl_rs_result)
908 }
909
910 pub fn scale_down_val(self, v: Val) -> Result<UnionPwAff, LibISLError> {
912 let upa = self;
913 let isl_rs_ctx = upa.get_ctx();
914 let mut upa = upa;
915 upa.do_not_free_on_drop();
916 let upa = upa.ptr;
917 let mut v = v;
918 v.do_not_free_on_drop();
919 let v = v.ptr;
920 let isl_rs_result = unsafe { isl_union_pw_aff_scale_down_val(upa, v) };
921 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
922 should_free_on_drop: true };
923 let err = isl_rs_ctx.last_error();
924 if err != Error::None_ {
925 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
926 }
927 Ok(isl_rs_result)
928 }
929
930 pub fn scale_val(self, v: Val) -> Result<UnionPwAff, LibISLError> {
932 let upa = self;
933 let isl_rs_ctx = upa.get_ctx();
934 let mut upa = upa;
935 upa.do_not_free_on_drop();
936 let upa = upa.ptr;
937 let mut v = v;
938 v.do_not_free_on_drop();
939 let v = v.ptr;
940 let isl_rs_result = unsafe { isl_union_pw_aff_scale_val(upa, v) };
941 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
942 should_free_on_drop: true };
943 let err = isl_rs_ctx.last_error();
944 if err != Error::None_ {
945 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
946 }
947 Ok(isl_rs_result)
948 }
949
950 pub fn set_dim_name(self, type_: DimType, pos: u32, s: &str)
952 -> Result<UnionPwAff, LibISLError> {
953 let upa = self;
954 let isl_rs_ctx = upa.get_ctx();
955 let mut upa = upa;
956 upa.do_not_free_on_drop();
957 let upa = upa.ptr;
958 let type_ = type_.to_i32();
959 let s = CString::new(s).unwrap();
960 let s = s.as_ptr();
961 let isl_rs_result = unsafe { isl_union_pw_aff_set_dim_name(upa, type_, pos, s) };
962 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
963 should_free_on_drop: true };
964 let err = isl_rs_ctx.last_error();
965 if err != Error::None_ {
966 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
967 }
968 Ok(isl_rs_result)
969 }
970
971 pub fn sub(self, upa2: UnionPwAff) -> Result<UnionPwAff, LibISLError> {
973 let upa1 = self;
974 let isl_rs_ctx = upa1.get_ctx();
975 let mut upa1 = upa1;
976 upa1.do_not_free_on_drop();
977 let upa1 = upa1.ptr;
978 let mut upa2 = upa2;
979 upa2.do_not_free_on_drop();
980 let upa2 = upa2.ptr;
981 let isl_rs_result = unsafe { isl_union_pw_aff_sub(upa1, upa2) };
982 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
983 should_free_on_drop: true };
984 let err = isl_rs_ctx.last_error();
985 if err != Error::None_ {
986 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
987 }
988 Ok(isl_rs_result)
989 }
990
991 pub fn subtract_domain(self, uset: UnionSet) -> Result<UnionPwAff, LibISLError> {
993 let upa = self;
994 let isl_rs_ctx = upa.get_ctx();
995 let mut upa = upa;
996 upa.do_not_free_on_drop();
997 let upa = upa.ptr;
998 let mut uset = uset;
999 uset.do_not_free_on_drop();
1000 let uset = uset.ptr;
1001 let isl_rs_result = unsafe { isl_union_pw_aff_subtract_domain(upa, uset) };
1002 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
1003 should_free_on_drop: true };
1004 let err = isl_rs_ctx.last_error();
1005 if err != Error::None_ {
1006 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
1007 }
1008 Ok(isl_rs_result)
1009 }
1010
1011 pub fn subtract_domain_space(self, space: Space) -> Result<UnionPwAff, LibISLError> {
1013 let upa = self;
1014 let isl_rs_ctx = upa.get_ctx();
1015 let mut upa = upa;
1016 upa.do_not_free_on_drop();
1017 let upa = upa.ptr;
1018 let mut space = space;
1019 space.do_not_free_on_drop();
1020 let space = space.ptr;
1021 let isl_rs_result = unsafe { isl_union_pw_aff_subtract_domain_space(upa, space) };
1022 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
1023 should_free_on_drop: true };
1024 let err = isl_rs_ctx.last_error();
1025 if err != Error::None_ {
1026 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
1027 }
1028 Ok(isl_rs_result)
1029 }
1030
1031 pub fn subtract_domain_union_set(self, uset: UnionSet) -> Result<UnionPwAff, LibISLError> {
1033 let upa = self;
1034 let isl_rs_ctx = upa.get_ctx();
1035 let mut upa = upa;
1036 upa.do_not_free_on_drop();
1037 let upa = upa.ptr;
1038 let mut uset = uset;
1039 uset.do_not_free_on_drop();
1040 let uset = uset.ptr;
1041 let isl_rs_result = unsafe { isl_union_pw_aff_subtract_domain_union_set(upa, uset) };
1042 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
1043 should_free_on_drop: true };
1044 let err = isl_rs_ctx.last_error();
1045 if err != Error::None_ {
1046 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
1047 }
1048 Ok(isl_rs_result)
1049 }
1050
1051 pub fn to_list(self) -> Result<UnionPwAffList, LibISLError> {
1053 let el = self;
1054 let isl_rs_ctx = el.get_ctx();
1055 let mut el = el;
1056 el.do_not_free_on_drop();
1057 let el = el.ptr;
1058 let isl_rs_result = unsafe { isl_union_pw_aff_to_list(el) };
1059 let isl_rs_result = UnionPwAffList { ptr: isl_rs_result,
1060 should_free_on_drop: true };
1061 let err = isl_rs_ctx.last_error();
1062 if err != Error::None_ {
1063 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
1064 }
1065 Ok(isl_rs_result)
1066 }
1067
1068 pub fn to_str(&self) -> Result<&str, LibISLError> {
1070 let upa = self;
1071 let isl_rs_ctx = upa.get_ctx();
1072 let upa = upa.ptr;
1073 let isl_rs_result = unsafe { isl_union_pw_aff_to_str(upa) };
1074 let isl_rs_result = unsafe { CStr::from_ptr(isl_rs_result) };
1075 let isl_rs_result = isl_rs_result.to_str().unwrap();
1076 let err = isl_rs_ctx.last_error();
1077 if err != Error::None_ {
1078 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
1079 }
1080 Ok(isl_rs_result)
1081 }
1082
1083 pub fn union_add(self, upa2: UnionPwAff) -> Result<UnionPwAff, LibISLError> {
1085 let upa1 = self;
1086 let isl_rs_ctx = upa1.get_ctx();
1087 let mut upa1 = upa1;
1088 upa1.do_not_free_on_drop();
1089 let upa1 = upa1.ptr;
1090 let mut upa2 = upa2;
1091 upa2.do_not_free_on_drop();
1092 let upa2 = upa2.ptr;
1093 let isl_rs_result = unsafe { isl_union_pw_aff_union_add(upa1, upa2) };
1094 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
1095 should_free_on_drop: true };
1096 let err = isl_rs_ctx.last_error();
1097 if err != Error::None_ {
1098 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
1099 }
1100 Ok(isl_rs_result)
1101 }
1102
1103 pub fn val_on_domain(domain: UnionSet, v: Val) -> Result<UnionPwAff, LibISLError> {
1105 let isl_rs_ctx = domain.get_ctx();
1106 let mut domain = domain;
1107 domain.do_not_free_on_drop();
1108 let domain = domain.ptr;
1109 let mut v = v;
1110 v.do_not_free_on_drop();
1111 let v = v.ptr;
1112 let isl_rs_result = unsafe { isl_union_pw_aff_val_on_domain(domain, v) };
1113 let isl_rs_result = UnionPwAff { ptr: isl_rs_result,
1114 should_free_on_drop: true };
1115 let err = isl_rs_ctx.last_error();
1116 if err != Error::None_ {
1117 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
1118 }
1119 Ok(isl_rs_result)
1120 }
1121
1122 pub fn zero_union_set(self) -> Result<UnionSet, LibISLError> {
1124 let upa = self;
1125 let isl_rs_ctx = upa.get_ctx();
1126 let mut upa = upa;
1127 upa.do_not_free_on_drop();
1128 let upa = upa.ptr;
1129 let isl_rs_result = unsafe { isl_union_pw_aff_zero_union_set(upa) };
1130 let isl_rs_result = UnionSet { ptr: isl_rs_result,
1131 should_free_on_drop: true };
1132 let err = isl_rs_ctx.last_error();
1133 if err != Error::None_ {
1134 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
1135 }
1136 Ok(isl_rs_result)
1137 }
1138
1139 pub fn do_not_free_on_drop(&mut self) {
1142 self.should_free_on_drop = false;
1143 }
1144}
1145
1146impl Drop for UnionPwAff {
1147 fn drop(&mut self) {
1148 if self.should_free_on_drop {
1149 unsafe {
1150 isl_union_pw_aff_free(self.ptr);
1151 }
1152 }
1153 }
1154}