feat(control_tree): add StepTreeContract and signature (dev-only)

This commit is contained in:
nyash-codex
2025-12-18 00:57:58 +09:00
parent 9bcda215f8
commit 14730c227f
4 changed files with 445 additions and 15 deletions

View File

@ -70,6 +70,18 @@ pub(crate) fn detect_break_in_body(body: &[ASTNode]) -> bool {
false
}
/// Detect if a loop body contains return statements
///
/// This is used for dev-only parity checks with structure SSOT (StepTree).
pub(crate) fn detect_return_in_body(body: &[ASTNode]) -> bool {
for stmt in body {
if has_return_node(stmt) {
return true;
}
}
false
}
/// Extract full feature set from loop body AST
///
/// This is the main entry point for feature extraction. It analyzes the loop body
@ -273,6 +285,26 @@ fn has_break_node(node: &ASTNode) -> bool {
}
}
/// Recursive helper to check if AST node contains return
fn has_return_node(node: &ASTNode) -> bool {
match node {
ASTNode::Return { .. } => true,
ASTNode::If {
then_body,
else_body,
..
} => {
then_body.iter().any(has_return_node)
|| else_body
.as_ref()
.map_or(false, |e| e.iter().any(has_return_node))
}
ASTNode::Loop { body, .. } => body.iter().any(has_return_node),
ASTNode::ScopeBox { body, .. } => body.iter().any(has_return_node),
_ => false,
}
}
#[cfg(test)]
mod tests {
use super::*;