use super::SsaConstPropagationVisitor;
use leo_ast::{AstReconstructor, Constructor, Function, Library, ProgramReconstructor, ProgramScope, Statement};
impl ProgramReconstructor for SsaConstPropagationVisitor<'_> {
fn reconstruct_library(&mut self, input: Library) -> Library {
input
}
fn reconstruct_program_scope(&mut self, input: ProgramScope) -> ProgramScope {
self.program = input.program_id.as_symbol();
ProgramScope {
program_id: input.program_id,
parents: input.parents.into_iter().map(|(s, t)| (s, self.reconstruct_type(t).0)).collect(),
consts: input
.consts
.into_iter()
.map(|(i, c)| match self.reconstruct_const(c) {
(Statement::Const(declaration), _) => (i, declaration),
_ => panic!("`reconstruct_const` can only return `Statement::Const`"),
})
.collect(),
composites: input.composites.into_iter().map(|(i, c)| (i, self.reconstruct_composite(c))).collect(),
mappings: input.mappings.into_iter().map(|(id, mapping)| (id, self.reconstruct_mapping(mapping))).collect(),
storage_variables: input
.storage_variables
.into_iter()
.map(|(id, storage_variable)| (id, self.reconstruct_storage_variable(storage_variable)))
.collect(),
functions: input.functions.into_iter().map(|(i, f)| (i, self.reconstruct_function(f))).collect(),
interfaces: input.interfaces.into_iter().map(|(i, int)| (i, self.reconstruct_interface(int))).collect(),
constructor: input.constructor.map(|c| self.reconstruct_constructor(c)),
span: input.span,
}
}
fn reconstruct_function(&mut self, mut input: Function) -> Function {
self.constants.clear();
input.block = self.reconstruct_block(input.block).0;
self.constants.clear();
input
}
fn reconstruct_constructor(&mut self, mut input: Constructor) -> Constructor {
self.constants.clear();
input.block = self.reconstruct_block(input.block).0;
self.constants.clear();
input
}
}