use sway_features::ExperimentalFeatures;
use crate::{
build_config::DbgGeneration,
language::parsed::{Declaration, TreeType},
BuildTarget,
};
pub struct Context {
pub experimental: ExperimentalFeatures,
module_has_configurable_block: bool,
destructured_struct_unique_suffix: usize,
destructured_tuple_unique_suffix: usize,
match_expression_matched_value_unique_suffix: usize,
for_unique_suffix: usize,
build_target: BuildTarget,
dbg_generation: DbgGeneration,
program_type: Option<TreeType>,
pub(crate) implementing_type: Option<Declaration>,
pub package_name: String,
}
impl Context {
pub fn new(
build_target: BuildTarget,
dbg_generation: DbgGeneration,
experimental: ExperimentalFeatures,
package_name: &str,
) -> Self {
Self {
build_target,
dbg_generation,
experimental,
module_has_configurable_block: std::default::Default::default(),
destructured_struct_unique_suffix: std::default::Default::default(),
destructured_tuple_unique_suffix: std::default::Default::default(),
match_expression_matched_value_unique_suffix: std::default::Default::default(),
for_unique_suffix: std::default::Default::default(),
program_type: std::default::Default::default(),
implementing_type: None,
package_name: package_name.to_string(),
}
}
pub fn set_module_has_configurable_block(&mut self, val: bool) {
self.module_has_configurable_block = val;
}
pub fn module_has_configurable_block(&self) -> bool {
self.module_has_configurable_block
}
pub fn next_destructured_struct_unique_suffix(&mut self) -> usize {
self.destructured_struct_unique_suffix += 1;
self.destructured_struct_unique_suffix
}
pub fn next_destructured_tuple_unique_suffix(&mut self) -> usize {
self.destructured_tuple_unique_suffix += 1;
self.destructured_tuple_unique_suffix
}
pub fn next_match_expression_matched_value_unique_suffix(&mut self) -> usize {
self.match_expression_matched_value_unique_suffix += 1;
self.match_expression_matched_value_unique_suffix
}
pub fn next_for_unique_suffix(&mut self) -> usize {
self.for_unique_suffix += 1;
self.for_unique_suffix
}
pub fn build_target(&self) -> BuildTarget {
self.build_target
}
pub fn is_dbg_generation_full(&self) -> bool {
matches!(self.dbg_generation, DbgGeneration::Full)
}
pub fn program_type(&self) -> Option<TreeType> {
self.program_type
}
pub fn set_program_type(&mut self, program_type: TreeType) {
self.program_type = Some(program_type);
}
}