mod dynamic_to_choice;
mod empty_enums;
mod empty_unions;
mod flatten_complex_type;
mod flatten_unions;
mod merge_choice_cardinality;
mod merge_enum_unions;
mod misc;
mod remove_duplicates;
mod replace_xs_any_type_with_any_element;
mod resolve_typedefs;
mod simplify_mixed_types;
mod unrestricted_base;
use thiserror::Error;
use crate::models::{meta::MetaTypes, TypeIdent};
use self::misc::{BaseMap, TypedefMap};
pub use self::unrestricted_base::UnrestrictedBaseFlags;
#[must_use]
#[derive(Debug)]
pub struct Optimizer {
types: MetaTypes,
bases: Option<BaseMap>,
typedefs: Option<TypedefMap>,
}
#[derive(Error, Debug)]
pub enum Error {
#[error("Unknown type identifier: {0}!")]
UnknownType(TypeIdent),
#[error("The type is not a union type: {0}!")]
ExpectedUnion(TypeIdent),
#[error("The type is not a complex choice type: {0}!")]
ExpectedComplexChoice(TypeIdent),
#[error("The type is not a complex type: {0}!")]
ExpectedComplexType(TypeIdent),
#[error("Complex type {0} is missing a content type!")]
MissingContentType(TypeIdent),
#[error("Complex type {0} is expected to have a choice content!")]
ExpectedChoiceContent(TypeIdent),
#[error("Complex type {0} is expected to have content with unbound occurrence!")]
ExpectedUnboundContent(TypeIdent),
#[error("Complex type {0} has an unexpected content type!")]
UnexpectedContentType(TypeIdent),
#[error("Complex type {0} contains an unexpected element in it's content type!")]
UnexpectedElementInContent(TypeIdent),
#[error("{0}")]
Custom(String),
}
macro_rules! get_bases {
($this:expr) => {{
if $this.bases.is_none() {
$this.bases = Some(crate::pipeline::optimizer::BaseMap::new(&$this.types));
}
$this.bases.as_ref().unwrap()
}};
}
macro_rules! get_typedefs {
($this:expr) => {{
if $this.typedefs.is_none() {
$this.typedefs = Some(crate::pipeline::optimizer::TypedefMap::new(&$this.types));
}
$this.typedefs.as_ref().unwrap()
}};
}
pub(super) use get_bases;
pub(super) use get_typedefs;
impl Optimizer {
pub fn new(types: MetaTypes) -> Self {
Self {
types,
bases: None,
typedefs: None,
}
}
#[must_use]
pub fn finish(self) -> MetaTypes {
self.types
}
}