fluidattacks-blends-domain 0.2.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
//! Cfg builder that threads a block's children one statement at a time.

use crate::query::adj_ast;
use crate::syntax::cfg::{SyntaxCfgArgs, SyntaxCfgError};
use crate::NodeId;

pub fn build(
    args: &mut SyntaxCfgArgs<'_>,
    n_id: NodeId,
    nxt_id: Option<NodeId>,
) -> Result<NodeId, SyntaxCfgError> {
    let c_ids = adj_ast(args.graph, n_id, None, &[]);
    let Some(first_child) = c_ids.first().copied() else {
        return Ok(n_id);
    };
    args.graph.add_cfg_edge(n_id, first_child);

    let nexts = c_ids.iter().skip(1).copied().map(Some).chain([nxt_id]);
    for (&c_id, nxt) in c_ids.iter().zip(nexts) {
        args.generic(c_id, nxt)?;
    }

    Ok(n_id)
}