pub mod array;
pub mod binary;
pub mod callable;
#[cfg(any(docs, feature = "closure"))]
#[cfg_attr(docs, doc(cfg(feature = "closure")))]
pub mod closure;
pub mod long;
pub mod object;
pub mod string;
pub mod zval;
use std::{ffi::c_void, ptr};
use crate::bindings::{
zend_type, IS_MIXED, MAY_BE_ANY, MAY_BE_BOOL, _IS_BOOL, _ZEND_IS_VARIADIC_BIT,
_ZEND_SEND_MODE_SHIFT, _ZEND_TYPE_NULLABLE_BIT,
};
use super::enums::DataType;
pub type ZendType = zend_type;
impl ZendType {
pub fn empty(pass_by_ref: bool, is_variadic: bool) -> Self {
Self {
ptr: ptr::null::<c_void>() as *mut c_void,
type_mask: Self::arg_info_flags(pass_by_ref, is_variadic),
}
}
pub fn empty_from_type(
type_: DataType,
pass_by_ref: bool,
is_variadic: bool,
allow_null: bool,
) -> Self {
Self {
ptr: ptr::null::<c_void>() as *mut c_void,
type_mask: Self::type_init_code(type_, pass_by_ref, is_variadic, allow_null),
}
}
pub(crate) fn arg_info_flags(pass_by_ref: bool, is_variadic: bool) -> u32 {
((pass_by_ref as u32) << _ZEND_SEND_MODE_SHIFT)
| (if is_variadic {
_ZEND_IS_VARIADIC_BIT
} else {
0
})
}
pub(crate) fn type_init_code(
type_: DataType,
pass_by_ref: bool,
is_variadic: bool,
allow_null: bool,
) -> u32 {
let type_ = type_ as u32;
(if type_ == _IS_BOOL {
MAY_BE_BOOL
} else if type_ == IS_MIXED {
MAY_BE_ANY
} else {
1 << type_
}) | (if allow_null {
_ZEND_TYPE_NULLABLE_BIT
} else {
0
}) | Self::arg_info_flags(pass_by_ref, is_variadic)
}
}