use super::array::Array;
use super::table::Table;
use super::{FLAG_MASK, HINTS_BIT, Item, ItemMetadata, NOT_PROJECTED, TAG_MASK, TAG_SHIFT};
pub(crate) const FULL_MATCH_BIT: u32 = 1 << 30;
pub(crate) const IGNORE_SOURCE_ORDER_BIT: u32 = 1 << 29;
pub(crate) const IGNORE_SOURCE_STYLE_BIT: u32 = 1 << 28;
pub(crate) const ARRAY_REORDERED_BIT: u32 = 1 << 27;
pub(crate) const EXPANDED_BIT: u32 = 1 << 25;
pub(crate) const IGNORE_SOURCE_FORMATTING_RECURSIVELY_BIT: u32 = 1 << 24;
impl ItemMetadata {
#[inline]
pub(crate) fn projected_index(&self) -> u32 {
self.start_and_tag >> TAG_SHIFT
}
#[inline]
fn hints_preserve_mask(&self) -> u32 {
((self.end_and_flag as i32) >> 31) as u32 | FLAG_MASK
}
#[inline]
pub(crate) fn set_reprojected_index(&mut self, index: usize) -> bool {
if index <= (u32::MAX >> TAG_SHIFT) as usize {
self.start_and_tag = (self.start_and_tag & TAG_MASK) | ((index as u32) << TAG_SHIFT);
self.end_and_flag = (self.end_and_flag & self.hints_preserve_mask()) | HINTS_BIT;
true
} else {
false
}
}
#[inline]
pub(crate) fn set_reprojected_to_none(&mut self) {
self.start_and_tag |= NOT_PROJECTED;
self.end_and_flag =
(self.end_and_flag & (self.hints_preserve_mask() & !FULL_MATCH_BIT)) | HINTS_BIT;
}
#[inline]
pub(crate) fn set_reprojected_full_match(&mut self) {
self.end_and_flag |= FULL_MATCH_BIT;
}
#[inline]
pub(crate) fn is_reprojected_full_match(&self) -> bool {
self.end_and_flag & FULL_MATCH_BIT != 0
}
#[inline]
pub(crate) fn set_ignore_source_order(&mut self) {
self.end_and_flag |= HINTS_BIT | IGNORE_SOURCE_ORDER_BIT;
}
#[inline]
pub(crate) fn ignore_source_order(&self) -> bool {
self.end_and_flag & (HINTS_BIT | IGNORE_SOURCE_ORDER_BIT)
== (HINTS_BIT | IGNORE_SOURCE_ORDER_BIT)
}
#[inline]
pub(crate) fn set_array_reordered(&mut self) {
self.end_and_flag |= HINTS_BIT | ARRAY_REORDERED_BIT;
}
#[inline]
pub(crate) fn array_reordered(&self) -> bool {
self.end_and_flag & (HINTS_BIT | ARRAY_REORDERED_BIT) == (HINTS_BIT | ARRAY_REORDERED_BIT)
}
#[inline]
pub(crate) fn set_ignore_source_style(&mut self) {
self.end_and_flag |= HINTS_BIT | IGNORE_SOURCE_STYLE_BIT;
}
#[inline]
pub(crate) fn ignore_source_style(&self) -> bool {
self.end_and_flag & (HINTS_BIT | IGNORE_SOURCE_STYLE_BIT)
== (HINTS_BIT | IGNORE_SOURCE_STYLE_BIT)
}
#[inline]
pub(crate) fn set_expanded(&mut self) {
self.end_and_flag |= HINTS_BIT | EXPANDED_BIT;
}
#[inline]
pub(crate) fn is_expanded(&self) -> bool {
self.end_and_flag & (HINTS_BIT | EXPANDED_BIT) == (HINTS_BIT | EXPANDED_BIT)
}
#[inline]
pub(crate) fn clear_expanded(&mut self) {
self.end_and_flag &= !EXPANDED_BIT;
}
#[inline]
pub(crate) fn set_ignore_source_formatting_recursively(&mut self) {
self.end_and_flag |= HINTS_BIT | IGNORE_SOURCE_FORMATTING_RECURSIVELY_BIT;
}
#[inline]
pub(crate) fn ignore_source_formatting_recursively(&self) -> bool {
self.end_and_flag & (HINTS_BIT | IGNORE_SOURCE_FORMATTING_RECURSIVELY_BIT)
== (HINTS_BIT | IGNORE_SOURCE_FORMATTING_RECURSIVELY_BIT)
}
}
impl<'de> Item<'de> {
pub(crate) fn projected<'a>(&self, inputs: &[&'a Item<'a>]) -> Option<&'a Item<'a>> {
let index = self.meta.projected_index();
inputs.get(index as usize).copied()
}
pub(crate) fn set_reprojected_to_none(&mut self) {
self.meta.set_reprojected_to_none();
}
pub(crate) fn set_reprojected_index(&mut self, index: usize) -> bool {
self.meta.set_reprojected_index(index)
}
pub(crate) fn set_reprojected_full_match(&mut self) {
self.meta.set_reprojected_full_match();
}
pub(crate) fn is_reprojected_full_match(&self) -> bool {
self.meta.is_reprojected_full_match()
}
pub fn set_ignore_source_formatting_recursively(&mut self) {
self.meta.set_ignore_source_formatting_recursively();
}
#[must_use]
pub fn ignore_source_formatting_recursively(&self) -> bool {
self.meta.ignore_source_formatting_recursively()
}
#[inline]
pub(crate) fn is_subsection(&self) -> bool {
self.has_header_bit() || self.is_implicit_table() || self.is_aot()
}
#[inline]
#[cfg(test)]
pub(crate) fn set_flag(&mut self, flag: u32) {
self.meta.set_flag(flag);
}
}
impl<'de> Table<'de> {
pub fn set_ignore_source_order(&mut self) {
self.meta.set_ignore_source_order();
}
#[must_use]
pub fn ignore_source_order(&self) -> bool {
self.meta.ignore_source_order()
}
pub fn set_ignore_source_style(&mut self) {
self.meta.set_ignore_source_style();
}
#[must_use]
pub fn ignore_source_style(&self) -> bool {
self.meta.ignore_source_style()
}
#[must_use]
pub fn is_auto_style(&self) -> bool {
self.meta.is_auto_style()
}
}
impl<'de> Array<'de> {
#[must_use]
pub fn is_auto_style(&self) -> bool {
self.meta.is_auto_style()
}
#[must_use]
pub fn is_expanded(&self) -> bool {
self.meta.is_expanded()
}
pub fn set_expanded(&mut self) {
self.meta.set_expanded();
}
pub fn clear_expanded(&mut self) {
self.meta.clear_expanded();
}
}