isl_rs/bindings/
restriction.rs

1// Automatically generated by isl_bindings_generator.
2// LICENSE: MIT
3
4use super::{Context, Error, LibISLError, Map, Set};
5use libc::uintptr_t;
6
7/// Wraps `isl_restriction`.
8pub 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    /// Wraps `isl_restriction_empty`.
31    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            let err_msg = isl_rs_ctx.last_error_msg();
42            isl_rs_ctx.reset_error();
43            return Err(LibISLError::new(err, err_msg));
44        }
45        Ok(isl_rs_result)
46    }
47
48    /// Wraps `isl_restriction_free`.
49    pub fn free(self) -> Result<Restriction, LibISLError> {
50        let restr = self;
51        let isl_rs_ctx = restr.get_ctx();
52        let mut restr = restr;
53        restr.do_not_free_on_drop();
54        let restr = restr.ptr;
55        let isl_rs_result = unsafe { isl_restriction_free(restr) };
56        let isl_rs_result = Restriction { ptr: isl_rs_result,
57                                          should_free_on_drop: true };
58        let err = isl_rs_ctx.last_error();
59        if err != Error::None_ {
60            let err_msg = isl_rs_ctx.last_error_msg();
61            isl_rs_ctx.reset_error();
62            return Err(LibISLError::new(err, err_msg));
63        }
64        Ok(isl_rs_result)
65    }
66
67    /// Wraps `isl_restriction_get_ctx`.
68    pub fn get_ctx(&self) -> Context {
69        let restr = self;
70        let restr = restr.ptr;
71        let isl_rs_result = unsafe { isl_restriction_get_ctx(restr) };
72        let isl_rs_result = Context { ptr: isl_rs_result,
73                                      should_free_on_drop: false };
74        isl_rs_result
75    }
76
77    /// Wraps `isl_restriction_input`.
78    pub fn input(source_restr: Set, sink_restr: Set) -> Result<Restriction, LibISLError> {
79        let isl_rs_ctx = source_restr.get_ctx();
80        let mut source_restr = source_restr;
81        source_restr.do_not_free_on_drop();
82        let source_restr = source_restr.ptr;
83        let mut sink_restr = sink_restr;
84        sink_restr.do_not_free_on_drop();
85        let sink_restr = sink_restr.ptr;
86        let isl_rs_result = unsafe { isl_restriction_input(source_restr, sink_restr) };
87        let isl_rs_result = Restriction { ptr: isl_rs_result,
88                                          should_free_on_drop: true };
89        let err = isl_rs_ctx.last_error();
90        if err != Error::None_ {
91            let err_msg = isl_rs_ctx.last_error_msg();
92            isl_rs_ctx.reset_error();
93            return Err(LibISLError::new(err, err_msg));
94        }
95        Ok(isl_rs_result)
96    }
97
98    /// Wraps `isl_restriction_none`.
99    pub fn none(source_map: Map) -> Result<Restriction, LibISLError> {
100        let isl_rs_ctx = source_map.get_ctx();
101        let mut source_map = source_map;
102        source_map.do_not_free_on_drop();
103        let source_map = source_map.ptr;
104        let isl_rs_result = unsafe { isl_restriction_none(source_map) };
105        let isl_rs_result = Restriction { ptr: isl_rs_result,
106                                          should_free_on_drop: true };
107        let err = isl_rs_ctx.last_error();
108        if err != Error::None_ {
109            let err_msg = isl_rs_ctx.last_error_msg();
110            isl_rs_ctx.reset_error();
111            return Err(LibISLError::new(err, err_msg));
112        }
113        Ok(isl_rs_result)
114    }
115
116    /// Wraps `isl_restriction_output`.
117    pub fn output(source_restr: Set) -> Result<Restriction, LibISLError> {
118        let isl_rs_ctx = source_restr.get_ctx();
119        let mut source_restr = source_restr;
120        source_restr.do_not_free_on_drop();
121        let source_restr = source_restr.ptr;
122        let isl_rs_result = unsafe { isl_restriction_output(source_restr) };
123        let isl_rs_result = Restriction { ptr: isl_rs_result,
124                                          should_free_on_drop: true };
125        let err = isl_rs_ctx.last_error();
126        if err != Error::None_ {
127            let err_msg = isl_rs_ctx.last_error_msg();
128            isl_rs_ctx.reset_error();
129            return Err(LibISLError::new(err, err_msg));
130        }
131        Ok(isl_rs_result)
132    }
133
134    /// Does not call isl_restriction_free() on being dropped. (For internal use
135    /// only.)
136    pub fn do_not_free_on_drop(&mut self) {
137        self.should_free_on_drop = false;
138    }
139}
140
141impl Drop for Restriction {
142    fn drop(&mut self) {
143        if self.should_free_on_drop {
144            unsafe {
145                isl_restriction_free(self.ptr);
146            }
147        }
148    }
149}