use crate::Pass;
use leo_ast::ProgramReconstructor as _;
use leo_errors::Result;
use leo_span::{Span, Symbol};
mod expression;
mod program;
mod statement;
mod visitor;
use visitor::*;
pub struct ConstPropagationOutput {
pub changed: bool,
pub const_not_evaluated: Option<Span>,
pub array_index_not_evaluated: Option<Span>,
}
pub struct ConstPropagation;
impl Pass for ConstPropagation {
type Input = ();
type Output = ConstPropagationOutput;
const NAME: &str = "ConstPropagation";
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 = ConstPropagationVisitor {
state,
program: Symbol::intern(""),
changed: false,
const_not_evaluated: None,
array_index_not_evaluated: None,
};
ast.ast = visitor.reconstruct_program(ast.ast);
visitor.state.handler.last_err().map_err(|e| *e)?;
visitor.state.ast = ast;
Ok(ConstPropagationOutput {
changed: visitor.changed,
const_not_evaluated: visitor.const_not_evaluated,
array_index_not_evaluated: visitor.array_index_not_evaluated,
})
}
}