use crate::FunctionInliner;
use leo_ast::{Function, ProgramReconstructor, ProgramScope};
use leo_span::Symbol;
use indexmap::IndexMap;
impl ProgramReconstructor for FunctionInliner<'_> {
fn reconstruct_program_scope(&mut self, input: ProgramScope) -> ProgramScope {
let order = self.call_graph.post_order().unwrap();
let mut function_map: IndexMap<Symbol, Function> = input.functions.into_iter().collect();
for function_name in &order {
if let Some(function) = function_map.remove(function_name) {
let reconstructed_function = self.reconstruct_function(function);
self.reconstructed_functions.push((*function_name, reconstructed_function));
}
}
assert!(function_map.is_empty(), "All functions in the program scope should have been processed.");
let functions = core::mem::take(&mut self.reconstructed_functions).into_iter().collect();
ProgramScope {
program_id: input.program_id,
structs: input.structs,
mappings: input.mappings,
functions,
consts: input.consts,
span: input.span,
}
}
}