refactor(control_tree): Phase 128 - add value_ast to Assign for Normalized lowering

This commit is contained in:
nyash-codex
2025-12-18 07:01:39 +09:00
parent 85ee761858
commit 44762a2467

View File

@ -55,7 +55,11 @@ pub struct AstNodeHandle(pub Box<ASTNode>);
#[derive(Debug, Clone, PartialEq)]
pub enum StepStmtKind {
LocalDecl { vars: Vec<String> },
Assign { target: Option<String> },
Assign {
target: Option<String>,
/// Phase 128: assignment value AST (for Normalized lowering)
value_ast: Option<AstNodeHandle>,
},
Print,
Return {
/// Phase 123: return value AST (for Normalized lowering)
@ -188,7 +192,7 @@ impl StepStmtKind {
fn to_compact_string(&self) -> String {
match self {
StepStmtKind::LocalDecl { vars } => format!("local({})", vars.join(",")),
StepStmtKind::Assign { target } => match target {
StepStmtKind::Assign { target, .. } => match target {
Some(name) => format!("assign({name})"),
None => "assign(?)".to_string(),
},
@ -374,7 +378,7 @@ impl StepTreeBuilderBox {
},
StepTreeFeatures::default(),
),
ASTNode::Assignment { span, .. } => (
ASTNode::Assignment { span, value, .. } => (
StepNode::Stmt {
kind: StepStmtKind::Assign {
target: match ast {
@ -384,6 +388,8 @@ impl StepTreeBuilderBox {
},
_ => None,
},
/// Phase 128: Store value AST for Normalized lowering
value_ast: Some(AstNodeHandle(value.clone())),
},
span: span.clone(),
},
@ -507,12 +513,14 @@ fn walk_for_facts(node: &StepNode, facts: &mut StepTreeFacts) {
facts.add_write(v.clone());
}
}
StepStmtKind::Assign { target } => {
StepStmtKind::Assign { target, value_ast } => {
if let Some(name) = target.as_ref() {
facts.add_write(name.clone());
}
// Note: Assign RHS is not in StepStmtKind
// We rely on If/Loop condition AST for reads extraction
// Phase 128: Extract reads from assignment value AST
if let Some(ast) = value_ast {
extract_variables_from_ast(&ast.0, facts);
}
}
StepStmtKind::Print => {}
StepStmtKind::Return { value_ast } => {