Skip to main content

fold_root

Function fold_root 

Source
pub fn fold_root<L: Lang>(
    lang: &mut L,
    root: L::Id,
    rules: &[Box<dyn Rule<L>>],
    cfg: &Config,
) -> Option<(L::Id, &'static str)>
Expand description

对「根即 Replace 目标」的提案求值:返回 (新根, 规则名)。

引擎 pass 对 walk 根的 Replace 无法应用(无父槽可写——字段 init 场景:static int x = 1+2 的 init 节点就是根,Replace 找不到 parent.set_child)。本函数让门面(拥有容器结构的一方, 如 CompilationUnit 的字段声明)拿到新根自行回写,并循环到不动点。

只接受 target == root 的 Replace;成本门槛与 pass 相同(严格正)。