1use super::{ASTExprList, ASTExprOpType, ASTExprType, Context, Id, IdToASTExpr, Printer, Val};
5use libc::uintptr_t;
6use std::ffi::{CStr, CString};
7use std::os::raw::c_char;
8
9pub struct ASTExpr {
11 pub ptr: uintptr_t,
12 pub should_free_on_drop: bool,
13}
14
15extern "C" {
16
17 fn isl_ast_expr_list_insert(list: uintptr_t, pos: u32, el: uintptr_t) -> uintptr_t;
18
19 fn isl_ast_expr_list_clear(list: uintptr_t) -> uintptr_t;
20
21 fn isl_ast_expr_and(expr1: uintptr_t, expr2: uintptr_t) -> uintptr_t;
22
23 fn isl_ast_expr_and_then(expr1: uintptr_t, expr2: uintptr_t) -> uintptr_t;
24
25 fn isl_ast_expr_eq(expr1: uintptr_t, expr2: uintptr_t) -> uintptr_t;
26
27 fn isl_ast_expr_lt(expr1: uintptr_t, expr2: uintptr_t) -> uintptr_t;
28
29 fn isl_ast_expr_to_str(expr: uintptr_t) -> *const c_char;
30
31 fn isl_ast_expr_int_get_val(expr: uintptr_t) -> uintptr_t;
32
33 fn isl_ast_expr_le(expr1: uintptr_t, expr2: uintptr_t) -> uintptr_t;
34
35 fn isl_ast_expr_substitute_ids(expr: uintptr_t, id2expr: uintptr_t) -> uintptr_t;
36
37 fn isl_ast_expr_get_ctx(expr: uintptr_t) -> uintptr_t;
38
39 fn isl_ast_expr_sub(expr1: uintptr_t, expr2: uintptr_t) -> uintptr_t;
40
41 fn isl_ast_expr_address_of(expr: uintptr_t) -> uintptr_t;
42
43 fn isl_ast_expr_list_get_at(list: uintptr_t, index: i32) -> uintptr_t;
44
45 fn isl_ast_expr_list_copy(list: uintptr_t) -> uintptr_t;
46
47 fn isl_ast_expr_call(function: uintptr_t, arguments: uintptr_t) -> uintptr_t;
48
49 fn isl_ast_expr_get_op_type(expr: uintptr_t) -> i32;
50
51 fn isl_ast_expr_get_val(expr: uintptr_t) -> uintptr_t;
52
53 fn isl_ast_expr_ge(expr1: uintptr_t, expr2: uintptr_t) -> uintptr_t;
54
55 fn isl_ast_expr_list_set_at(list: uintptr_t, index: i32, el: uintptr_t) -> uintptr_t;
56
57 fn isl_ast_expr_get_op_arg(expr: uintptr_t, pos: i32) -> uintptr_t;
58
59 fn isl_ast_expr_op_get_n_arg(expr: uintptr_t) -> i32;
60
61 fn isl_ast_expr_access(array: uintptr_t, indices: uintptr_t) -> uintptr_t;
62
63 fn isl_ast_expr_list_dump(list: uintptr_t) -> ();
64
65 fn isl_ast_expr_get_op_n_arg(expr: uintptr_t) -> i32;
66
67 fn isl_ast_expr_from_val(v: uintptr_t) -> uintptr_t;
68
69 fn isl_ast_expr_list_alloc(ctx: uintptr_t, n: i32) -> uintptr_t;
70
71 fn isl_ast_expr_list_from_ast_expr(el: uintptr_t) -> uintptr_t;
72
73 fn isl_ast_expr_div(expr1: uintptr_t, expr2: uintptr_t) -> uintptr_t;
74
75 fn isl_ast_expr_dump(expr: uintptr_t) -> ();
76
77 fn isl_ast_expr_pdiv_q(expr1: uintptr_t, expr2: uintptr_t) -> uintptr_t;
78
79 fn isl_ast_expr_mul(expr1: uintptr_t, expr2: uintptr_t) -> uintptr_t;
80
81 fn isl_ast_expr_to_C_str(expr: uintptr_t) -> *const c_char;
82
83 fn isl_ast_expr_from_id(id: uintptr_t) -> uintptr_t;
84
85 fn isl_ast_expr_op_get_arg(expr: uintptr_t, pos: i32) -> uintptr_t;
86
87 fn isl_ast_expr_op_type_print_macro(type_: i32, p: uintptr_t) -> uintptr_t;
88
89 fn isl_ast_expr_list_to_str(list: uintptr_t) -> *const c_char;
90
91 fn isl_ast_expr_gt(expr1: uintptr_t, expr2: uintptr_t) -> uintptr_t;
92
93 fn isl_ast_expr_list_free(list: uintptr_t) -> uintptr_t;
94
95 fn isl_ast_expr_list_reverse(list: uintptr_t) -> uintptr_t;
96
97 fn isl_ast_expr_or_else(expr1: uintptr_t, expr2: uintptr_t) -> uintptr_t;
98
99 fn isl_ast_expr_id_get_id(expr: uintptr_t) -> uintptr_t;
100
101 fn isl_ast_expr_list_add(list: uintptr_t, el: uintptr_t) -> uintptr_t;
102
103 fn isl_ast_expr_list_swap(list: uintptr_t, pos1: u32, pos2: u32) -> uintptr_t;
104
105 fn isl_ast_expr_op_get_type(expr: uintptr_t) -> i32;
106
107 fn isl_ast_expr_list_set_ast_expr(list: uintptr_t, index: i32, el: uintptr_t) -> uintptr_t;
108
109 fn isl_ast_expr_add(expr1: uintptr_t, expr2: uintptr_t) -> uintptr_t;
110
111 fn isl_ast_expr_list_get_ctx(list: uintptr_t) -> uintptr_t;
112
113 fn isl_ast_expr_free(expr: uintptr_t) -> uintptr_t;
114
115 fn isl_ast_expr_or(expr1: uintptr_t, expr2: uintptr_t) -> uintptr_t;
116
117 fn isl_ast_expr_copy(expr: uintptr_t) -> uintptr_t;
118
119 fn isl_ast_expr_get_id(expr: uintptr_t) -> uintptr_t;
120
121 fn isl_ast_expr_list_get_ast_expr(list: uintptr_t, index: i32) -> uintptr_t;
122
123 fn isl_ast_expr_op_type_set_print_name(p: uintptr_t, type_: i32, name: *const c_char)
124 -> uintptr_t;
125
126 fn isl_ast_expr_to_list(el: uintptr_t) -> uintptr_t;
127
128 fn isl_ast_expr_list_size(list: uintptr_t) -> i32;
129
130 fn isl_ast_expr_get_type(expr: uintptr_t) -> i32;
131
132 fn isl_ast_expr_set_op_arg(expr: uintptr_t, pos: i32, arg: uintptr_t) -> uintptr_t;
133
134 fn isl_ast_expr_print_macros(expr: uintptr_t, p: uintptr_t) -> uintptr_t;
135
136 fn isl_ast_expr_list_concat(list1: uintptr_t, list2: uintptr_t) -> uintptr_t;
137
138 fn isl_ast_expr_list_n_ast_expr(list: uintptr_t) -> i32;
139
140 fn isl_ast_expr_list_drop(list: uintptr_t, first: u32, n: u32) -> uintptr_t;
141
142 fn isl_ast_expr_pdiv_r(expr1: uintptr_t, expr2: uintptr_t) -> uintptr_t;
143
144 fn isl_ast_expr_is_equal(expr1: uintptr_t, expr2: uintptr_t) -> i32;
145
146 fn isl_ast_expr_neg(expr: uintptr_t) -> uintptr_t;
147
148}
149
150impl ASTExpr {
151 pub fn list_insert(list: ASTExprList, pos: u32, el: ASTExpr) -> ASTExprList {
153 let mut list = list;
154 list.do_not_free_on_drop();
155 let list = list.ptr;
156 let mut el = el;
157 el.do_not_free_on_drop();
158 let el = el.ptr;
159 let isl_rs_result = unsafe { isl_ast_expr_list_insert(list, pos, el) };
160 let isl_rs_result = ASTExprList { ptr: isl_rs_result,
161 should_free_on_drop: true };
162 isl_rs_result
163 }
164
165 pub fn list_clear(list: ASTExprList) -> ASTExprList {
167 let mut list = list;
168 list.do_not_free_on_drop();
169 let list = list.ptr;
170 let isl_rs_result = unsafe { isl_ast_expr_list_clear(list) };
171 let isl_rs_result = ASTExprList { ptr: isl_rs_result,
172 should_free_on_drop: true };
173 isl_rs_result
174 }
175
176 pub fn and(self, expr2: ASTExpr) -> ASTExpr {
178 let expr1 = self;
179 let mut expr1 = expr1;
180 expr1.do_not_free_on_drop();
181 let expr1 = expr1.ptr;
182 let mut expr2 = expr2;
183 expr2.do_not_free_on_drop();
184 let expr2 = expr2.ptr;
185 let isl_rs_result = unsafe { isl_ast_expr_and(expr1, expr2) };
186 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
187 should_free_on_drop: true };
188 isl_rs_result
189 }
190
191 pub fn and_then(self, expr2: ASTExpr) -> ASTExpr {
193 let expr1 = self;
194 let mut expr1 = expr1;
195 expr1.do_not_free_on_drop();
196 let expr1 = expr1.ptr;
197 let mut expr2 = expr2;
198 expr2.do_not_free_on_drop();
199 let expr2 = expr2.ptr;
200 let isl_rs_result = unsafe { isl_ast_expr_and_then(expr1, expr2) };
201 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
202 should_free_on_drop: true };
203 isl_rs_result
204 }
205
206 pub fn eq(self, expr2: ASTExpr) -> ASTExpr {
208 let expr1 = self;
209 let mut expr1 = expr1;
210 expr1.do_not_free_on_drop();
211 let expr1 = expr1.ptr;
212 let mut expr2 = expr2;
213 expr2.do_not_free_on_drop();
214 let expr2 = expr2.ptr;
215 let isl_rs_result = unsafe { isl_ast_expr_eq(expr1, expr2) };
216 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
217 should_free_on_drop: true };
218 isl_rs_result
219 }
220
221 pub fn lt(self, expr2: ASTExpr) -> ASTExpr {
223 let expr1 = self;
224 let mut expr1 = expr1;
225 expr1.do_not_free_on_drop();
226 let expr1 = expr1.ptr;
227 let mut expr2 = expr2;
228 expr2.do_not_free_on_drop();
229 let expr2 = expr2.ptr;
230 let isl_rs_result = unsafe { isl_ast_expr_lt(expr1, expr2) };
231 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
232 should_free_on_drop: true };
233 isl_rs_result
234 }
235
236 pub fn to_str(&self) -> &str {
238 let expr = self;
239 let expr = expr.ptr;
240 let isl_rs_result = unsafe { isl_ast_expr_to_str(expr) };
241 let isl_rs_result = unsafe { CStr::from_ptr(isl_rs_result) };
242 let isl_rs_result = isl_rs_result.to_str().unwrap();
243 isl_rs_result
244 }
245
246 pub fn int_get_val(&self) -> Val {
248 let expr = self;
249 let expr = expr.ptr;
250 let isl_rs_result = unsafe { isl_ast_expr_int_get_val(expr) };
251 let isl_rs_result = Val { ptr: isl_rs_result,
252 should_free_on_drop: true };
253 isl_rs_result
254 }
255
256 pub fn le(self, expr2: ASTExpr) -> ASTExpr {
258 let expr1 = self;
259 let mut expr1 = expr1;
260 expr1.do_not_free_on_drop();
261 let expr1 = expr1.ptr;
262 let mut expr2 = expr2;
263 expr2.do_not_free_on_drop();
264 let expr2 = expr2.ptr;
265 let isl_rs_result = unsafe { isl_ast_expr_le(expr1, expr2) };
266 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
267 should_free_on_drop: true };
268 isl_rs_result
269 }
270
271 pub fn substitute_ids(self, id2expr: IdToASTExpr) -> ASTExpr {
273 let expr = self;
274 let mut expr = expr;
275 expr.do_not_free_on_drop();
276 let expr = expr.ptr;
277 let mut id2expr = id2expr;
278 id2expr.do_not_free_on_drop();
279 let id2expr = id2expr.ptr;
280 let isl_rs_result = unsafe { isl_ast_expr_substitute_ids(expr, id2expr) };
281 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
282 should_free_on_drop: true };
283 isl_rs_result
284 }
285
286 pub fn get_ctx(&self) -> Context {
288 let expr = self;
289 let expr = expr.ptr;
290 let isl_rs_result = unsafe { isl_ast_expr_get_ctx(expr) };
291 let isl_rs_result = Context { ptr: isl_rs_result,
292 should_free_on_drop: false };
293 isl_rs_result
294 }
295
296 pub fn sub(self, expr2: ASTExpr) -> ASTExpr {
298 let expr1 = self;
299 let mut expr1 = expr1;
300 expr1.do_not_free_on_drop();
301 let expr1 = expr1.ptr;
302 let mut expr2 = expr2;
303 expr2.do_not_free_on_drop();
304 let expr2 = expr2.ptr;
305 let isl_rs_result = unsafe { isl_ast_expr_sub(expr1, expr2) };
306 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
307 should_free_on_drop: true };
308 isl_rs_result
309 }
310
311 pub fn address_of(self) -> ASTExpr {
313 let expr = self;
314 let mut expr = expr;
315 expr.do_not_free_on_drop();
316 let expr = expr.ptr;
317 let isl_rs_result = unsafe { isl_ast_expr_address_of(expr) };
318 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
319 should_free_on_drop: true };
320 isl_rs_result
321 }
322
323 pub fn list_get_at(list: &ASTExprList, index: i32) -> ASTExpr {
325 let list = list.ptr;
326 let isl_rs_result = unsafe { isl_ast_expr_list_get_at(list, index) };
327 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
328 should_free_on_drop: true };
329 isl_rs_result
330 }
331
332 pub fn list_copy(list: &ASTExprList) -> ASTExprList {
334 let list = list.ptr;
335 let isl_rs_result = unsafe { isl_ast_expr_list_copy(list) };
336 let isl_rs_result = ASTExprList { ptr: isl_rs_result,
337 should_free_on_drop: true };
338 isl_rs_result
339 }
340
341 pub fn call(self, arguments: ASTExprList) -> ASTExpr {
343 let function = self;
344 let mut function = function;
345 function.do_not_free_on_drop();
346 let function = function.ptr;
347 let mut arguments = arguments;
348 arguments.do_not_free_on_drop();
349 let arguments = arguments.ptr;
350 let isl_rs_result = unsafe { isl_ast_expr_call(function, arguments) };
351 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
352 should_free_on_drop: true };
353 isl_rs_result
354 }
355
356 pub fn get_op_type(&self) -> ASTExprOpType {
358 let expr = self;
359 let expr = expr.ptr;
360 let isl_rs_result = unsafe { isl_ast_expr_get_op_type(expr) };
361 let isl_rs_result = ASTExprOpType::from_i32(isl_rs_result);
362 isl_rs_result
363 }
364
365 pub fn get_val(&self) -> Val {
367 let expr = self;
368 let expr = expr.ptr;
369 let isl_rs_result = unsafe { isl_ast_expr_get_val(expr) };
370 let isl_rs_result = Val { ptr: isl_rs_result,
371 should_free_on_drop: true };
372 isl_rs_result
373 }
374
375 pub fn ge(self, expr2: ASTExpr) -> ASTExpr {
377 let expr1 = self;
378 let mut expr1 = expr1;
379 expr1.do_not_free_on_drop();
380 let expr1 = expr1.ptr;
381 let mut expr2 = expr2;
382 expr2.do_not_free_on_drop();
383 let expr2 = expr2.ptr;
384 let isl_rs_result = unsafe { isl_ast_expr_ge(expr1, expr2) };
385 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
386 should_free_on_drop: true };
387 isl_rs_result
388 }
389
390 pub fn list_set_at(list: ASTExprList, index: i32, el: ASTExpr) -> ASTExprList {
392 let mut list = list;
393 list.do_not_free_on_drop();
394 let list = list.ptr;
395 let mut el = el;
396 el.do_not_free_on_drop();
397 let el = el.ptr;
398 let isl_rs_result = unsafe { isl_ast_expr_list_set_at(list, index, el) };
399 let isl_rs_result = ASTExprList { ptr: isl_rs_result,
400 should_free_on_drop: true };
401 isl_rs_result
402 }
403
404 pub fn get_op_arg(&self, pos: i32) -> ASTExpr {
406 let expr = self;
407 let expr = expr.ptr;
408 let isl_rs_result = unsafe { isl_ast_expr_get_op_arg(expr, pos) };
409 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
410 should_free_on_drop: true };
411 isl_rs_result
412 }
413
414 pub fn op_get_n_arg(&self) -> i32 {
416 let expr = self;
417 let expr = expr.ptr;
418 let isl_rs_result = unsafe { isl_ast_expr_op_get_n_arg(expr) };
419 isl_rs_result
420 }
421
422 pub fn access(self, indices: ASTExprList) -> ASTExpr {
424 let array = self;
425 let mut array = array;
426 array.do_not_free_on_drop();
427 let array = array.ptr;
428 let mut indices = indices;
429 indices.do_not_free_on_drop();
430 let indices = indices.ptr;
431 let isl_rs_result = unsafe { isl_ast_expr_access(array, indices) };
432 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
433 should_free_on_drop: true };
434 isl_rs_result
435 }
436
437 pub fn list_dump(list: &ASTExprList) -> () {
439 let list = list.ptr;
440 let isl_rs_result = unsafe { isl_ast_expr_list_dump(list) };
441 isl_rs_result
442 }
443
444 pub fn get_op_n_arg(&self) -> i32 {
446 let expr = self;
447 let expr = expr.ptr;
448 let isl_rs_result = unsafe { isl_ast_expr_get_op_n_arg(expr) };
449 isl_rs_result
450 }
451
452 pub fn from_val(v: Val) -> ASTExpr {
454 let mut v = v;
455 v.do_not_free_on_drop();
456 let v = v.ptr;
457 let isl_rs_result = unsafe { isl_ast_expr_from_val(v) };
458 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
459 should_free_on_drop: true };
460 isl_rs_result
461 }
462
463 pub fn list_alloc(ctx: &Context, n: i32) -> ASTExprList {
465 let ctx = ctx.ptr;
466 let isl_rs_result = unsafe { isl_ast_expr_list_alloc(ctx, n) };
467 let isl_rs_result = ASTExprList { ptr: isl_rs_result,
468 should_free_on_drop: true };
469 isl_rs_result
470 }
471
472 pub fn list_from_ast_expr(self) -> ASTExprList {
474 let el = self;
475 let mut el = el;
476 el.do_not_free_on_drop();
477 let el = el.ptr;
478 let isl_rs_result = unsafe { isl_ast_expr_list_from_ast_expr(el) };
479 let isl_rs_result = ASTExprList { ptr: isl_rs_result,
480 should_free_on_drop: true };
481 isl_rs_result
482 }
483
484 pub fn div(self, expr2: ASTExpr) -> ASTExpr {
486 let expr1 = self;
487 let mut expr1 = expr1;
488 expr1.do_not_free_on_drop();
489 let expr1 = expr1.ptr;
490 let mut expr2 = expr2;
491 expr2.do_not_free_on_drop();
492 let expr2 = expr2.ptr;
493 let isl_rs_result = unsafe { isl_ast_expr_div(expr1, expr2) };
494 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
495 should_free_on_drop: true };
496 isl_rs_result
497 }
498
499 pub fn dump(&self) -> () {
501 let expr = self;
502 let expr = expr.ptr;
503 let isl_rs_result = unsafe { isl_ast_expr_dump(expr) };
504 isl_rs_result
505 }
506
507 pub fn pdiv_q(self, expr2: ASTExpr) -> ASTExpr {
509 let expr1 = self;
510 let mut expr1 = expr1;
511 expr1.do_not_free_on_drop();
512 let expr1 = expr1.ptr;
513 let mut expr2 = expr2;
514 expr2.do_not_free_on_drop();
515 let expr2 = expr2.ptr;
516 let isl_rs_result = unsafe { isl_ast_expr_pdiv_q(expr1, expr2) };
517 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
518 should_free_on_drop: true };
519 isl_rs_result
520 }
521
522 pub fn mul(self, expr2: ASTExpr) -> ASTExpr {
524 let expr1 = self;
525 let mut expr1 = expr1;
526 expr1.do_not_free_on_drop();
527 let expr1 = expr1.ptr;
528 let mut expr2 = expr2;
529 expr2.do_not_free_on_drop();
530 let expr2 = expr2.ptr;
531 let isl_rs_result = unsafe { isl_ast_expr_mul(expr1, expr2) };
532 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
533 should_free_on_drop: true };
534 isl_rs_result
535 }
536
537 pub fn to_C_str(&self) -> &str {
539 let expr = self;
540 let expr = expr.ptr;
541 let isl_rs_result = unsafe { isl_ast_expr_to_C_str(expr) };
542 let isl_rs_result = unsafe { CStr::from_ptr(isl_rs_result) };
543 let isl_rs_result = isl_rs_result.to_str().unwrap();
544 isl_rs_result
545 }
546
547 pub fn from_id(id: Id) -> ASTExpr {
549 let mut id = id;
550 id.do_not_free_on_drop();
551 let id = id.ptr;
552 let isl_rs_result = unsafe { isl_ast_expr_from_id(id) };
553 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
554 should_free_on_drop: true };
555 isl_rs_result
556 }
557
558 pub fn op_get_arg(&self, pos: i32) -> ASTExpr {
560 let expr = self;
561 let expr = expr.ptr;
562 let isl_rs_result = unsafe { isl_ast_expr_op_get_arg(expr, pos) };
563 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
564 should_free_on_drop: true };
565 isl_rs_result
566 }
567
568 pub fn op_type_print_macro(type_: ASTExprOpType, p: Printer) -> Printer {
570 let type_ = type_.to_i32();
571 let mut p = p;
572 p.do_not_free_on_drop();
573 let p = p.ptr;
574 let isl_rs_result = unsafe { isl_ast_expr_op_type_print_macro(type_, p) };
575 let isl_rs_result = Printer { ptr: isl_rs_result,
576 should_free_on_drop: true };
577 isl_rs_result
578 }
579
580 pub fn list_to_str(list: &ASTExprList) -> &str {
582 let list = list.ptr;
583 let isl_rs_result = unsafe { isl_ast_expr_list_to_str(list) };
584 let isl_rs_result = unsafe { CStr::from_ptr(isl_rs_result) };
585 let isl_rs_result = isl_rs_result.to_str().unwrap();
586 isl_rs_result
587 }
588
589 pub fn gt(self, expr2: ASTExpr) -> ASTExpr {
591 let expr1 = self;
592 let mut expr1 = expr1;
593 expr1.do_not_free_on_drop();
594 let expr1 = expr1.ptr;
595 let mut expr2 = expr2;
596 expr2.do_not_free_on_drop();
597 let expr2 = expr2.ptr;
598 let isl_rs_result = unsafe { isl_ast_expr_gt(expr1, expr2) };
599 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
600 should_free_on_drop: true };
601 isl_rs_result
602 }
603
604 pub fn list_free(list: ASTExprList) -> ASTExprList {
606 let mut list = list;
607 list.do_not_free_on_drop();
608 let list = list.ptr;
609 let isl_rs_result = unsafe { isl_ast_expr_list_free(list) };
610 let isl_rs_result = ASTExprList { ptr: isl_rs_result,
611 should_free_on_drop: true };
612 isl_rs_result
613 }
614
615 pub fn list_reverse(list: ASTExprList) -> ASTExprList {
617 let mut list = list;
618 list.do_not_free_on_drop();
619 let list = list.ptr;
620 let isl_rs_result = unsafe { isl_ast_expr_list_reverse(list) };
621 let isl_rs_result = ASTExprList { ptr: isl_rs_result,
622 should_free_on_drop: true };
623 isl_rs_result
624 }
625
626 pub fn or_else(self, expr2: ASTExpr) -> ASTExpr {
628 let expr1 = self;
629 let mut expr1 = expr1;
630 expr1.do_not_free_on_drop();
631 let expr1 = expr1.ptr;
632 let mut expr2 = expr2;
633 expr2.do_not_free_on_drop();
634 let expr2 = expr2.ptr;
635 let isl_rs_result = unsafe { isl_ast_expr_or_else(expr1, expr2) };
636 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
637 should_free_on_drop: true };
638 isl_rs_result
639 }
640
641 pub fn id_get_id(&self) -> Id {
643 let expr = self;
644 let expr = expr.ptr;
645 let isl_rs_result = unsafe { isl_ast_expr_id_get_id(expr) };
646 let isl_rs_result = Id { ptr: isl_rs_result,
647 should_free_on_drop: true };
648 isl_rs_result
649 }
650
651 pub fn list_add(list: ASTExprList, el: ASTExpr) -> ASTExprList {
653 let mut list = list;
654 list.do_not_free_on_drop();
655 let list = list.ptr;
656 let mut el = el;
657 el.do_not_free_on_drop();
658 let el = el.ptr;
659 let isl_rs_result = unsafe { isl_ast_expr_list_add(list, el) };
660 let isl_rs_result = ASTExprList { ptr: isl_rs_result,
661 should_free_on_drop: true };
662 isl_rs_result
663 }
664
665 pub fn list_swap(list: ASTExprList, pos1: u32, pos2: u32) -> ASTExprList {
667 let mut list = list;
668 list.do_not_free_on_drop();
669 let list = list.ptr;
670 let isl_rs_result = unsafe { isl_ast_expr_list_swap(list, pos1, pos2) };
671 let isl_rs_result = ASTExprList { ptr: isl_rs_result,
672 should_free_on_drop: true };
673 isl_rs_result
674 }
675
676 pub fn op_get_type(&self) -> ASTExprOpType {
678 let expr = self;
679 let expr = expr.ptr;
680 let isl_rs_result = unsafe { isl_ast_expr_op_get_type(expr) };
681 let isl_rs_result = ASTExprOpType::from_i32(isl_rs_result);
682 isl_rs_result
683 }
684
685 pub fn list_set_ast_expr(list: ASTExprList, index: i32, el: ASTExpr) -> ASTExprList {
687 let mut list = list;
688 list.do_not_free_on_drop();
689 let list = list.ptr;
690 let mut el = el;
691 el.do_not_free_on_drop();
692 let el = el.ptr;
693 let isl_rs_result = unsafe { isl_ast_expr_list_set_ast_expr(list, index, el) };
694 let isl_rs_result = ASTExprList { ptr: isl_rs_result,
695 should_free_on_drop: true };
696 isl_rs_result
697 }
698
699 pub fn add(self, expr2: ASTExpr) -> ASTExpr {
701 let expr1 = self;
702 let mut expr1 = expr1;
703 expr1.do_not_free_on_drop();
704 let expr1 = expr1.ptr;
705 let mut expr2 = expr2;
706 expr2.do_not_free_on_drop();
707 let expr2 = expr2.ptr;
708 let isl_rs_result = unsafe { isl_ast_expr_add(expr1, expr2) };
709 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
710 should_free_on_drop: true };
711 isl_rs_result
712 }
713
714 pub fn list_get_ctx(list: &ASTExprList) -> Context {
716 let list = list.ptr;
717 let isl_rs_result = unsafe { isl_ast_expr_list_get_ctx(list) };
718 let isl_rs_result = Context { ptr: isl_rs_result,
719 should_free_on_drop: false };
720 isl_rs_result
721 }
722
723 pub fn free(self) -> ASTExpr {
725 let expr = self;
726 let mut expr = expr;
727 expr.do_not_free_on_drop();
728 let expr = expr.ptr;
729 let isl_rs_result = unsafe { isl_ast_expr_free(expr) };
730 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
731 should_free_on_drop: true };
732 isl_rs_result
733 }
734
735 pub fn or(self, expr2: ASTExpr) -> ASTExpr {
737 let expr1 = self;
738 let mut expr1 = expr1;
739 expr1.do_not_free_on_drop();
740 let expr1 = expr1.ptr;
741 let mut expr2 = expr2;
742 expr2.do_not_free_on_drop();
743 let expr2 = expr2.ptr;
744 let isl_rs_result = unsafe { isl_ast_expr_or(expr1, expr2) };
745 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
746 should_free_on_drop: true };
747 isl_rs_result
748 }
749
750 pub fn copy(&self) -> ASTExpr {
752 let expr = self;
753 let expr = expr.ptr;
754 let isl_rs_result = unsafe { isl_ast_expr_copy(expr) };
755 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
756 should_free_on_drop: true };
757 isl_rs_result
758 }
759
760 pub fn get_id(&self) -> Id {
762 let expr = self;
763 let expr = expr.ptr;
764 let isl_rs_result = unsafe { isl_ast_expr_get_id(expr) };
765 let isl_rs_result = Id { ptr: isl_rs_result,
766 should_free_on_drop: true };
767 isl_rs_result
768 }
769
770 pub fn list_get_ast_expr(list: &ASTExprList, index: i32) -> ASTExpr {
772 let list = list.ptr;
773 let isl_rs_result = unsafe { isl_ast_expr_list_get_ast_expr(list, index) };
774 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
775 should_free_on_drop: true };
776 isl_rs_result
777 }
778
779 pub fn op_type_set_print_name(p: Printer, type_: ASTExprOpType, name: &str) -> Printer {
781 let mut p = p;
782 p.do_not_free_on_drop();
783 let p = p.ptr;
784 let type_ = type_.to_i32();
785 let name = CString::new(name).unwrap();
786 let name = name.as_ptr();
787 let isl_rs_result = unsafe { isl_ast_expr_op_type_set_print_name(p, type_, name) };
788 let isl_rs_result = Printer { ptr: isl_rs_result,
789 should_free_on_drop: true };
790 isl_rs_result
791 }
792
793 pub fn to_list(self) -> ASTExprList {
795 let el = self;
796 let mut el = el;
797 el.do_not_free_on_drop();
798 let el = el.ptr;
799 let isl_rs_result = unsafe { isl_ast_expr_to_list(el) };
800 let isl_rs_result = ASTExprList { ptr: isl_rs_result,
801 should_free_on_drop: true };
802 isl_rs_result
803 }
804
805 pub fn list_size(list: &ASTExprList) -> i32 {
807 let list = list.ptr;
808 let isl_rs_result = unsafe { isl_ast_expr_list_size(list) };
809 isl_rs_result
810 }
811
812 pub fn get_type(&self) -> ASTExprType {
814 let expr = self;
815 let expr = expr.ptr;
816 let isl_rs_result = unsafe { isl_ast_expr_get_type(expr) };
817 let isl_rs_result = ASTExprType::from_i32(isl_rs_result);
818 isl_rs_result
819 }
820
821 pub fn set_op_arg(self, pos: i32, arg: ASTExpr) -> ASTExpr {
823 let expr = self;
824 let mut expr = expr;
825 expr.do_not_free_on_drop();
826 let expr = expr.ptr;
827 let mut arg = arg;
828 arg.do_not_free_on_drop();
829 let arg = arg.ptr;
830 let isl_rs_result = unsafe { isl_ast_expr_set_op_arg(expr, pos, arg) };
831 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
832 should_free_on_drop: true };
833 isl_rs_result
834 }
835
836 pub fn print_macros(&self, p: Printer) -> Printer {
838 let expr = self;
839 let expr = expr.ptr;
840 let mut p = p;
841 p.do_not_free_on_drop();
842 let p = p.ptr;
843 let isl_rs_result = unsafe { isl_ast_expr_print_macros(expr, p) };
844 let isl_rs_result = Printer { ptr: isl_rs_result,
845 should_free_on_drop: true };
846 isl_rs_result
847 }
848
849 pub fn list_concat(list1: ASTExprList, list2: ASTExprList) -> ASTExprList {
851 let mut list1 = list1;
852 list1.do_not_free_on_drop();
853 let list1 = list1.ptr;
854 let mut list2 = list2;
855 list2.do_not_free_on_drop();
856 let list2 = list2.ptr;
857 let isl_rs_result = unsafe { isl_ast_expr_list_concat(list1, list2) };
858 let isl_rs_result = ASTExprList { ptr: isl_rs_result,
859 should_free_on_drop: true };
860 isl_rs_result
861 }
862
863 pub fn list_n_ast_expr(list: &ASTExprList) -> i32 {
865 let list = list.ptr;
866 let isl_rs_result = unsafe { isl_ast_expr_list_n_ast_expr(list) };
867 isl_rs_result
868 }
869
870 pub fn list_drop(list: ASTExprList, first: u32, n: u32) -> ASTExprList {
872 let mut list = list;
873 list.do_not_free_on_drop();
874 let list = list.ptr;
875 let isl_rs_result = unsafe { isl_ast_expr_list_drop(list, first, n) };
876 let isl_rs_result = ASTExprList { ptr: isl_rs_result,
877 should_free_on_drop: true };
878 isl_rs_result
879 }
880
881 pub fn pdiv_r(self, expr2: ASTExpr) -> ASTExpr {
883 let expr1 = self;
884 let mut expr1 = expr1;
885 expr1.do_not_free_on_drop();
886 let expr1 = expr1.ptr;
887 let mut expr2 = expr2;
888 expr2.do_not_free_on_drop();
889 let expr2 = expr2.ptr;
890 let isl_rs_result = unsafe { isl_ast_expr_pdiv_r(expr1, expr2) };
891 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
892 should_free_on_drop: true };
893 isl_rs_result
894 }
895
896 pub fn is_equal(&self, expr2: &ASTExpr) -> bool {
898 let expr1 = self;
899 let expr1 = expr1.ptr;
900 let expr2 = expr2.ptr;
901 let isl_rs_result = unsafe { isl_ast_expr_is_equal(expr1, expr2) };
902 let isl_rs_result = match isl_rs_result {
903 0 => false,
904 1 => true,
905 _ => panic!("Got isl_bool = -1"),
906 };
907 isl_rs_result
908 }
909
910 pub fn neg(self) -> ASTExpr {
912 let expr = self;
913 let mut expr = expr;
914 expr.do_not_free_on_drop();
915 let expr = expr.ptr;
916 let isl_rs_result = unsafe { isl_ast_expr_neg(expr) };
917 let isl_rs_result = ASTExpr { ptr: isl_rs_result,
918 should_free_on_drop: true };
919 isl_rs_result
920 }
921
922 pub fn do_not_free_on_drop(&mut self) {
925 self.should_free_on_drop = false;
926 }
927}
928
929impl Drop for ASTExpr {
930 fn drop(&mut self) {
931 if self.should_free_on_drop {
932 unsafe {
933 isl_ast_expr_free(self.ptr);
934 }
935 }
936 }
937}