use llvm_sys::core::{LLVMGetArrayLength, LLVMGetElementType};
use llvm_sys::prelude::LLVMTypeRef;
use std::marker::PhantomData;
use crate::types::*;
use crate::{FromLLVMType, TypeRef};
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct ArrayType<'ctx>(LLVMTypeRef, PhantomData<&'ctx ()>);
impl_send_sync!(ArrayType);
impl<'ctx> ArrayType<'ctx> {
pub fn element_type(&self) -> Type<'ctx> {
Type::from_llvm(unsafe { LLVMGetElementType(self.0) })
}
pub fn num_elements(&self) -> usize {
unsafe { LLVMGetArrayLength(self.0) as usize }
}
}
impl<'ctx> AsType<'ctx> for ArrayType<'ctx> {
fn as_type(&self) -> Type<'ctx> {
Type::Array(self.clone())
}
}
impl_positional_type_ref!(ArrayType, 0);
impl_positional_from_llvm_type!(ArrayType);