use super::ProcessingAsyncVisitor;
use leo_ast::{
AstReconstructor,
ConstParameter,
Function,
Input,
Node,
Output,
ProgramReconstructor,
ProgramScope,
Statement,
};
impl ProgramReconstructor for ProcessingAsyncVisitor<'_> {
fn reconstruct_program_scope(&mut self, input: ProgramScope) -> ProgramScope {
self.current_program = input.program_id.name.name;
let mut reconstructed_functions: Vec<_> =
input.functions.iter().map(|(name, func)| (*name, self.reconstruct_function(func.clone()))).collect();
reconstructed_functions.append(&mut self.new_async_functions);
ProgramScope {
program_id: input.program_id,
composites: input.composites.into_iter().map(|(id, def)| (id, self.reconstruct_composite(def))).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: reconstructed_functions,
constructor: input.constructor,
consts: input
.consts
.into_iter()
.map(|(id, stmt)| match self.reconstruct_const(stmt) {
(Statement::Const(decl), _) => (id, decl),
_ => panic!("`reconstruct_const` must return `Statement::Const`"),
})
.collect(),
span: input.span,
}
}
fn reconstruct_function(&mut self, input: Function) -> Function {
self.current_function = input.name();
self.in_scope(input.id(), |slf| Function {
annotations: input.annotations,
variant: input.variant,
identifier: input.identifier,
const_parameters: input
.const_parameters
.iter()
.map(|param| ConstParameter { type_: slf.reconstruct_type(param.type_.clone()).0, ..param.clone() })
.collect(),
input: input
.input
.iter()
.map(|input| Input { type_: slf.reconstruct_type(input.type_.clone()).0, ..input.clone() })
.collect(),
output: input
.output
.iter()
.map(|output| Output { type_: slf.reconstruct_type(output.type_.clone()).0, ..output.clone() })
.collect(),
output_type: slf.reconstruct_type(input.output_type).0,
block: slf.reconstruct_block(input.block).0,
span: input.span,
id: input.id,
})
}
}