isl_rs/bindings/
term.rs

1// Automatically generated by isl_bindings_generator.
2// LICENSE: MIT
3
4use super::{Aff, Context, DimType, Error, LibISLError, Val};
5use libc::uintptr_t;
6
7/// Wraps `isl_term`.
8pub struct Term {
9    pub ptr: uintptr_t,
10    pub should_free_on_drop: bool,
11}
12
13extern "C" {
14
15    fn isl_term_copy(term: uintptr_t) -> uintptr_t;
16
17    fn isl_term_dim(term: uintptr_t, type_: i32) -> i32;
18
19    fn isl_term_free(term: uintptr_t) -> uintptr_t;
20
21    fn isl_term_get_coefficient_val(term: uintptr_t) -> uintptr_t;
22
23    fn isl_term_get_ctx(term: uintptr_t) -> uintptr_t;
24
25    fn isl_term_get_div(term: uintptr_t, pos: u32) -> uintptr_t;
26
27    fn isl_term_get_exp(term: uintptr_t, type_: i32, pos: u32) -> i32;
28
29}
30
31impl Term {
32    /// Wraps `isl_term_copy`.
33    pub fn copy(&self) -> Result<Term, LibISLError> {
34        let term = self;
35        let isl_rs_ctx = term.get_ctx();
36        let term = term.ptr;
37        let isl_rs_result = unsafe { isl_term_copy(term) };
38        let isl_rs_result = Term { ptr: isl_rs_result,
39                                   should_free_on_drop: true };
40        let err = isl_rs_ctx.last_error();
41        if err != Error::None_ {
42            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
43        }
44        Ok(isl_rs_result)
45    }
46
47    /// Wraps `isl_term_dim`.
48    pub fn dim(&self, type_: DimType) -> Result<i32, LibISLError> {
49        let term = self;
50        let isl_rs_ctx = term.get_ctx();
51        let term = term.ptr;
52        let type_ = type_.to_i32();
53        let isl_rs_result = unsafe { isl_term_dim(term, type_) };
54        let err = isl_rs_ctx.last_error();
55        if err != Error::None_ {
56            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
57        }
58        Ok(isl_rs_result)
59    }
60
61    /// Wraps `isl_term_free`.
62    pub fn free(self) -> Result<Term, LibISLError> {
63        let term = self;
64        let isl_rs_ctx = term.get_ctx();
65        let mut term = term;
66        term.do_not_free_on_drop();
67        let term = term.ptr;
68        let isl_rs_result = unsafe { isl_term_free(term) };
69        let isl_rs_result = Term { ptr: isl_rs_result,
70                                   should_free_on_drop: true };
71        let err = isl_rs_ctx.last_error();
72        if err != Error::None_ {
73            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
74        }
75        Ok(isl_rs_result)
76    }
77
78    /// Wraps `isl_term_get_coefficient_val`.
79    pub fn get_coefficient_val(&self) -> Result<Val, LibISLError> {
80        let term = self;
81        let isl_rs_ctx = term.get_ctx();
82        let term = term.ptr;
83        let isl_rs_result = unsafe { isl_term_get_coefficient_val(term) };
84        let isl_rs_result = Val { ptr: isl_rs_result,
85                                  should_free_on_drop: true };
86        let err = isl_rs_ctx.last_error();
87        if err != Error::None_ {
88            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
89        }
90        Ok(isl_rs_result)
91    }
92
93    /// Wraps `isl_term_get_ctx`.
94    pub fn get_ctx(&self) -> Context {
95        let term = self;
96        let term = term.ptr;
97        let isl_rs_result = unsafe { isl_term_get_ctx(term) };
98        let isl_rs_result = Context { ptr: isl_rs_result,
99                                      should_free_on_drop: false };
100        isl_rs_result
101    }
102
103    /// Wraps `isl_term_get_div`.
104    pub fn get_div(&self, pos: u32) -> Result<Aff, LibISLError> {
105        let term = self;
106        let isl_rs_ctx = term.get_ctx();
107        let term = term.ptr;
108        let isl_rs_result = unsafe { isl_term_get_div(term, pos) };
109        let isl_rs_result = Aff { ptr: isl_rs_result,
110                                  should_free_on_drop: true };
111        let err = isl_rs_ctx.last_error();
112        if err != Error::None_ {
113            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
114        }
115        Ok(isl_rs_result)
116    }
117
118    /// Wraps `isl_term_get_exp`.
119    pub fn get_exp(&self, type_: DimType, pos: u32) -> Result<i32, LibISLError> {
120        let term = self;
121        let isl_rs_ctx = term.get_ctx();
122        let term = term.ptr;
123        let type_ = type_.to_i32();
124        let isl_rs_result = unsafe { isl_term_get_exp(term, type_, pos) };
125        let err = isl_rs_ctx.last_error();
126        if err != Error::None_ {
127            return Err(LibISLError::new(err, isl_rs_ctx.last_error_msg()));
128        }
129        Ok(isl_rs_result)
130    }
131
132    /// Does not call isl_term_free() on being dropped. (For internal use only.)
133    pub fn do_not_free_on_drop(&mut self) {
134        self.should_free_on_drop = false;
135    }
136}
137
138impl Drop for Term {
139    fn drop(&mut self) {
140        if self.should_free_on_drop {
141            unsafe {
142                isl_term_free(self.ptr);
143            }
144        }
145    }
146}