isl_rs/bindings/
restriction.rs1use super::{Context, Error, LibISLError, Map, Set};
5use libc::uintptr_t;
6
7pub struct Restriction {
9 pub ptr: uintptr_t,
10 pub should_free_on_drop: bool,
11}
12
13extern "C" {
14
15 fn isl_restriction_empty(source_map: uintptr_t) -> uintptr_t;
16
17 fn isl_restriction_free(restr: uintptr_t) -> uintptr_t;
18
19 fn isl_restriction_get_ctx(restr: uintptr_t) -> uintptr_t;
20
21 fn isl_restriction_input(source_restr: uintptr_t, sink_restr: uintptr_t) -> uintptr_t;
22
23 fn isl_restriction_none(source_map: uintptr_t) -> uintptr_t;
24
25 fn isl_restriction_output(source_restr: uintptr_t) -> uintptr_t;
26
27}
28
29impl Restriction {
30 pub fn empty(source_map: Map) -> Result<Restriction, LibISLError> {
32 let isl_rs_ctx = source_map.get_ctx();
33 let mut source_map = source_map;
34 source_map.do_not_free_on_drop();
35 let source_map = source_map.ptr;
36 let isl_rs_result = unsafe { isl_restriction_empty(source_map) };
37 let isl_rs_result = Restriction { ptr: isl_rs_result,
38 should_free_on_drop: true };
39 let err = isl_rs_ctx.last_error();
40 if err != Error::None_ {
41 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
42 }
43 Ok(isl_rs_result)
44 }
45
46 pub fn free(self) -> Result<Restriction, LibISLError> {
48 let restr = self;
49 let isl_rs_ctx = restr.get_ctx();
50 let mut restr = restr;
51 restr.do_not_free_on_drop();
52 let restr = restr.ptr;
53 let isl_rs_result = unsafe { isl_restriction_free(restr) };
54 let isl_rs_result = Restriction { ptr: isl_rs_result,
55 should_free_on_drop: true };
56 let err = isl_rs_ctx.last_error();
57 if err != Error::None_ {
58 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
59 }
60 Ok(isl_rs_result)
61 }
62
63 pub fn get_ctx(&self) -> Context {
65 let restr = self;
66 let restr = restr.ptr;
67 let isl_rs_result = unsafe { isl_restriction_get_ctx(restr) };
68 let isl_rs_result = Context { ptr: isl_rs_result,
69 should_free_on_drop: false };
70 isl_rs_result
71 }
72
73 pub fn input(source_restr: Set, sink_restr: Set) -> Result<Restriction, LibISLError> {
75 let isl_rs_ctx = source_restr.get_ctx();
76 let mut source_restr = source_restr;
77 source_restr.do_not_free_on_drop();
78 let source_restr = source_restr.ptr;
79 let mut sink_restr = sink_restr;
80 sink_restr.do_not_free_on_drop();
81 let sink_restr = sink_restr.ptr;
82 let isl_rs_result = unsafe { isl_restriction_input(source_restr, sink_restr) };
83 let isl_rs_result = Restriction { ptr: isl_rs_result,
84 should_free_on_drop: true };
85 let err = isl_rs_ctx.last_error();
86 if err != Error::None_ {
87 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
88 }
89 Ok(isl_rs_result)
90 }
91
92 pub fn none(source_map: Map) -> Result<Restriction, LibISLError> {
94 let isl_rs_ctx = source_map.get_ctx();
95 let mut source_map = source_map;
96 source_map.do_not_free_on_drop();
97 let source_map = source_map.ptr;
98 let isl_rs_result = unsafe { isl_restriction_none(source_map) };
99 let isl_rs_result = Restriction { ptr: isl_rs_result,
100 should_free_on_drop: true };
101 let err = isl_rs_ctx.last_error();
102 if err != Error::None_ {
103 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
104 }
105 Ok(isl_rs_result)
106 }
107
108 pub fn output(source_restr: Set) -> Result<Restriction, LibISLError> {
110 let isl_rs_ctx = source_restr.get_ctx();
111 let mut source_restr = source_restr;
112 source_restr.do_not_free_on_drop();
113 let source_restr = source_restr.ptr;
114 let isl_rs_result = unsafe { isl_restriction_output(source_restr) };
115 let isl_rs_result = Restriction { ptr: isl_rs_result,
116 should_free_on_drop: true };
117 let err = isl_rs_ctx.last_error();
118 if err != Error::None_ {
119 return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
120 }
121 Ok(isl_rs_result)
122 }
123
124 pub fn do_not_free_on_drop(&mut self) {
127 self.should_free_on_drop = false;
128 }
129}
130
131impl Drop for Restriction {
132 fn drop(&mut self) {
133 if self.should_free_on_drop {
134 unsafe {
135 isl_restriction_free(self.ptr);
136 }
137 }
138 }
139}