use super::{Context, Error, LibISLError, Map, Set};
use libc::uintptr_t;
pub struct Restriction {
pub ptr: uintptr_t,
pub should_free_on_drop: bool,
}
extern "C" {
fn isl_restriction_empty(source_map: uintptr_t) -> uintptr_t;
fn isl_restriction_free(restr: uintptr_t) -> uintptr_t;
fn isl_restriction_get_ctx(restr: uintptr_t) -> uintptr_t;
fn isl_restriction_input(source_restr: uintptr_t, sink_restr: uintptr_t) -> uintptr_t;
fn isl_restriction_none(source_map: uintptr_t) -> uintptr_t;
fn isl_restriction_output(source_restr: uintptr_t) -> uintptr_t;
}
impl Restriction {
pub fn empty(source_map: Map) -> Result<Restriction, LibISLError> {
let isl_rs_ctx = source_map.get_ctx();
let mut source_map = source_map;
source_map.do_not_free_on_drop();
let source_map = source_map.ptr;
let isl_rs_result = unsafe { isl_restriction_empty(source_map) };
let isl_rs_result = Restriction { ptr: isl_rs_result,
should_free_on_drop: true };
let err = isl_rs_ctx.last_error();
if err != Error::None_ {
let err_msg = isl_rs_ctx.last_error_msg();
isl_rs_ctx.reset_error();
return Err(LibISLError::new(err, err_msg));
}
Ok(isl_rs_result)
}
pub fn free(self) -> Result<Restriction, LibISLError> {
let restr = self;
let isl_rs_ctx = restr.get_ctx();
let mut restr = restr;
restr.do_not_free_on_drop();
let restr = restr.ptr;
let isl_rs_result = unsafe { isl_restriction_free(restr) };
let isl_rs_result = Restriction { ptr: isl_rs_result,
should_free_on_drop: true };
let err = isl_rs_ctx.last_error();
if err != Error::None_ {
let err_msg = isl_rs_ctx.last_error_msg();
isl_rs_ctx.reset_error();
return Err(LibISLError::new(err, err_msg));
}
Ok(isl_rs_result)
}
pub fn get_ctx(&self) -> Context {
let restr = self;
let restr = restr.ptr;
let isl_rs_result = unsafe { isl_restriction_get_ctx(restr) };
let isl_rs_result = Context { ptr: isl_rs_result,
should_free_on_drop: false };
isl_rs_result
}
pub fn input(source_restr: Set, sink_restr: Set) -> Result<Restriction, LibISLError> {
let isl_rs_ctx = source_restr.get_ctx();
let mut source_restr = source_restr;
source_restr.do_not_free_on_drop();
let source_restr = source_restr.ptr;
let mut sink_restr = sink_restr;
sink_restr.do_not_free_on_drop();
let sink_restr = sink_restr.ptr;
let isl_rs_result = unsafe { isl_restriction_input(source_restr, sink_restr) };
let isl_rs_result = Restriction { ptr: isl_rs_result,
should_free_on_drop: true };
let err = isl_rs_ctx.last_error();
if err != Error::None_ {
let err_msg = isl_rs_ctx.last_error_msg();
isl_rs_ctx.reset_error();
return Err(LibISLError::new(err, err_msg));
}
Ok(isl_rs_result)
}
pub fn none(source_map: Map) -> Result<Restriction, LibISLError> {
let isl_rs_ctx = source_map.get_ctx();
let mut source_map = source_map;
source_map.do_not_free_on_drop();
let source_map = source_map.ptr;
let isl_rs_result = unsafe { isl_restriction_none(source_map) };
let isl_rs_result = Restriction { ptr: isl_rs_result,
should_free_on_drop: true };
let err = isl_rs_ctx.last_error();
if err != Error::None_ {
let err_msg = isl_rs_ctx.last_error_msg();
isl_rs_ctx.reset_error();
return Err(LibISLError::new(err, err_msg));
}
Ok(isl_rs_result)
}
pub fn output(source_restr: Set) -> Result<Restriction, LibISLError> {
let isl_rs_ctx = source_restr.get_ctx();
let mut source_restr = source_restr;
source_restr.do_not_free_on_drop();
let source_restr = source_restr.ptr;
let isl_rs_result = unsafe { isl_restriction_output(source_restr) };
let isl_rs_result = Restriction { ptr: isl_rs_result,
should_free_on_drop: true };
let err = isl_rs_ctx.last_error();
if err != Error::None_ {
let err_msg = isl_rs_ctx.last_error_msg();
isl_rs_ctx.reset_error();
return Err(LibISLError::new(err, err_msg));
}
Ok(isl_rs_result)
}
pub fn do_not_free_on_drop(&mut self) {
self.should_free_on_drop = false;
}
}
impl Drop for Restriction {
fn drop(&mut self) {
if self.should_free_on_drop {
unsafe {
isl_restriction_free(self.ptr);
}
}
}
}