use std::marker::PhantomData;
use super::super::middle;
#[derive(Clone, Debug)]
pub struct Type<T> {
untyped: middle::Type,
_marker: PhantomData<*mut T>,
}
impl<T> Type<T> {
fn make(untyped: middle::Type) -> Self {
Type {
untyped: untyped,
_marker: PhantomData,
}
}
pub fn into_middle(self) -> middle::Type {
self.untyped
}
}
pub unsafe trait CType : Copy {
fn reify() -> Type<Self>;
}
macro_rules! impl_ffi_type {
($type_:ty, $cons:ident) => {
unsafe impl<> CType for $type_ {
fn reify() -> Type<Self> {
Type::make(middle::Type::$cons())
}
}
};
($type_:ident) => {
impl_ffi_type!($type_, $type_);
};
}
impl_ffi_type!(u8);
impl_ffi_type!(i8);
impl_ffi_type!(u16);
impl_ffi_type!(i16);
impl_ffi_type!(u32);
impl_ffi_type!(i32);
impl_ffi_type!(u64);
impl_ffi_type!(i64);
impl_ffi_type!(f32);
impl_ffi_type!(f64);
impl_ffi_type!(usize);
impl_ffi_type!(isize);
impl_ffi_type!((), void);
#[allow(non_camel_case_types)]
#[cfg(feature = "complex")]
pub type c_c32 = [f32; 2];
#[allow(non_camel_case_types)]
#[cfg(feature = "complex")]
pub type c_c64 = [f64; 2];
#[cfg(feature = "complex")]
impl_ffi_type!(c_c32, c32);
#[cfg(feature = "complex")]
impl_ffi_type!(c_c64, c64);
unsafe impl<T> CType for *const T {
fn reify() -> Type<Self> { Type::make(middle::Type::pointer()) }
}
unsafe impl<T> CType for *mut T {
fn reify() -> Type<Self> { Type::make(middle::Type::pointer()) }
}