1use tidepool_repr::CoreExpr;
2
3pub type Changed = bool;
5
6pub trait Pass {
8 fn run(&self, expr: &mut CoreExpr) -> Changed;
10
11 fn name(&self) -> &str;
13}
14
15#[cfg(test)]
16mod tests {
17 use super::*;
18 use tidepool_repr::{CoreFrame, RecursiveTree, VarId};
19
20 struct NoOpPass;
21
22 impl Pass for NoOpPass {
23 fn run(&self, _expr: &mut CoreExpr) -> Changed {
24 false
25 }
26
27 fn name(&self) -> &str {
28 "NoOpPass"
29 }
30 }
31
32 #[test]
33 fn test_noop_pass() {
34 let pass = NoOpPass;
35 let mut expr = RecursiveTree {
36 nodes: vec![CoreFrame::Var(VarId(0))],
37 };
38 let changed = pass.run(&mut expr);
39 assert!(!changed);
40 assert_eq!(pass.name(), "NoOpPass");
41 }
42}