fluidattacks-blends-domain 0.2.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
//! Cfg builder that connects returns and exports to their declaration
//! children, retyping resolved multifile return values first.

use crate::query::adj_ast;
use crate::syntax::cfg::dispatchers::multifile::adjust_return_value;
use crate::syntax::cfg::{SyntaxCfgArgs, SyntaxCfgError};
use crate::syntax::{SyntaxGraph, SyntaxNode};
use crate::CodeGraph;
use crate::NodeId;

fn is_declaration(graph: &SyntaxGraph, c_id: NodeId) -> bool {
    matches!(
        graph.label_type(c_id),
        Some("Class" | "Declaration" | "MethodDeclaration" | "VariableDeclaration")
    )
}

pub fn build(
    args: &mut SyntaxCfgArgs<'_>,
    n_id: NodeId,
    nxt_id: Option<NodeId>,
) -> Result<NodeId, SyntaxCfgError> {
    if args.is_multifile
        && matches!(
            args.graph.nodes.get(&n_id),
            Some(SyntaxNode::Return { value_id: Some(_) })
        )
    {
        adjust_return_value(args.graph, n_id);
    }

    for c_id in adj_ast(args.graph, n_id, None, &[]) {
        if !is_declaration(args.graph, c_id) {
            continue;
        }
        let built = args.generic(c_id, nxt_id)?;
        args.graph.add_cfg_edge(n_id, built);
    }
    Ok(n_id)
}