use crate::Pass;
use leo_ast::ProgramReconstructor;
use leo_errors::Result;
use leo_span::{Span, Symbol};
mod duplicate;
mod range_iterator;
use range_iterator::*;
mod statement;
mod program;
mod visitor;
use visitor::*;
pub struct UnrollingOutput {
pub loop_not_unrolled: Option<Span>,
pub loop_unrolled: bool,
}
pub struct Unrolling;
impl Pass for Unrolling {
type Input = ();
type Output = UnrollingOutput;
const NAME: &str = "Unrolling";
fn do_pass(_input: Self::Input, state: &mut crate::CompilerState) -> Result<Self::Output> {
let mut ast = std::mem::take(&mut state.ast);
let mut visitor =
UnrollingVisitor { state, program: Symbol::intern(""), loop_not_unrolled: None, loop_unrolled: false };
ast.ast = visitor.reconstruct_program(ast.ast);
visitor.state.handler.last_err().map_err(|e| *e)?;
visitor.state.ast = ast;
Ok(UnrollingOutput { loop_not_unrolled: visitor.loop_not_unrolled, loop_unrolled: visitor.loop_unrolled })
}
}