use crate::mir::{Cfg, Device, FieldConversion};
use super::recurse_objects_with_depth_mut;
pub fn run_pass(device: &mut Device) -> anyhow::Result<()> {
let mut current_depth = 0;
let mut cfg_stack = vec![Cfg::new(None)];
recurse_objects_with_depth_mut(&mut device.objects, &mut |object, depth| {
if depth < current_depth {
cfg_stack.pop();
current_depth = depth;
}
let cfg_attr = object.cfg_attr_mut();
let new_cfg_attr = cfg_attr.combine(cfg_stack.last().unwrap());
*cfg_attr = new_cfg_attr.clone();
for field in object.field_sets_mut().flatten() {
if let Some(FieldConversion::Enum { enum_value, .. }) = field.field_conversion.as_mut()
{
enum_value.cfg_attr = field.cfg_attr.combine(&new_cfg_attr);
}
}
if object.as_block_mut().is_some() {
cfg_stack.push(new_cfg_attr);
current_depth += 1;
}
Ok(())
})
}