use super::vars::NamingConvention;
#[derive(Clone, Debug)]
pub struct PicusParams {
expr_cutoff: Option<usize>,
entrypoint: Option<String>,
naming_convention: NamingConvention,
optimize: bool,
inline: bool,
}
impl PicusParams {
pub fn naming_convention(&self) -> NamingConvention {
self.naming_convention
}
pub fn optimize(&self) -> bool {
self.optimize
}
pub fn expr_cutoff(&self) -> Option<usize> {
self.expr_cutoff
}
pub fn entrypoint(&self) -> &str {
self.entrypoint.as_deref().unwrap_or("Main")
}
fn new() -> Self {
Self {
expr_cutoff: None,
entrypoint: None,
naming_convention: NamingConvention::Short,
optimize: true,
inline: false,
}
}
pub fn inline(&self) -> bool {
self.inline
}
}
impl Default for PicusParams {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Default)]
pub struct PicusParamsBuilder(PicusParams);
impl PicusParamsBuilder {
pub fn new() -> Self {
Self(PicusParams::new())
}
pub fn expr_cutoff(&mut self, expr_cutoff: usize) -> &mut Self {
self.0.expr_cutoff = Some(expr_cutoff);
self
}
pub fn no_expr_cutoff(&mut self) -> &mut Self {
self.0.expr_cutoff = None;
self
}
pub fn entrypoint(&mut self, name: &str) -> &mut Self {
self.0.entrypoint = Some(name.to_owned());
self
}
pub fn short_names(&mut self) -> &mut Self {
self.0.naming_convention = NamingConvention::Short;
self
}
pub fn optimize(&mut self) -> &mut Self {
self.0.optimize = true;
self
}
pub fn no_optimize(&mut self) -> &mut Self {
self.0.optimize = false;
self
}
pub fn inline(&mut self) -> &mut Self {
self.0.inline = true;
self
}
pub fn no_inline(&mut self) -> &mut Self {
self.0.inline = false;
self
}
pub fn build(&mut self) -> PicusParams {
std::mem::take(&mut self.0)
}
}
impl From<PicusParamsBuilder> for PicusParams {
fn from(builder: PicusParamsBuilder) -> PicusParams {
builder.0
}
}