fluidattacks-blends-domain 0.3.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
//! Counterpart of `blends/syntax/builders/class_decl.py` (the `StackGraph`
//! definition setup is excluded: the migration covers only AST, Syntax and CFG).

use alloc::string::String;

use crate::syntax::builders::utils::{enter_scope_stack, exit_scope_stack_if_current};
use crate::syntax::SyntaxNode;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::NodeId;

#[allow(
    dead_code,
    reason = "wired when a consuming language reader lands, #26553"
)]
#[allow(
    clippy::too_many_arguments,
    reason = "mirrors the Python build_class_node inputs"
)]
pub fn build_class_node(
    args: &mut SyntaxGraphArgs<'_>,
    n_id: NodeId,
    name: String,
    block_id: Option<NodeId>,
    attr_list_ids: &[NodeId],
    inherited_class: Option<String>,
    modifiers_id: Option<NodeId>,
    access_modifiers: Option<String>,
) -> Result<NodeId, SyntaxGraphError> {
    args.syntax_graph.add_node(
        n_id,
        SyntaxNode::Class {
            name,
            block_id,
            modifiers_id,
            inherited_class: inherited_class.filter(|value| !value.is_empty()),
            access_modifiers: access_modifiers.filter(|value| !value.is_empty()),
        },
    );

    enter_scope_stack(args.syntax_graph, args.metadata, n_id);

    if let Some(block_id) = block_id {
        let built = args.generic(block_id)?;
        args.syntax_graph.add_ast_edge(n_id, built);
    }

    for attr_list_id in attr_list_ids {
        let built = args.generic(*attr_list_id)?;
        args.syntax_graph.add_ast_edge(n_id, built);
    }

    if let Some(modifiers_id) = modifiers_id {
        let built = args.generic(modifiers_id)?;
        args.syntax_graph.add_ast_edge(n_id, built);
    }

    args.metadata.class_path.pop();

    exit_scope_stack_if_current(args.metadata, n_id);

    Ok(n_id)
}