refactor: Extract utilities from control_flow.rs (Phase 6)
- Created utils.rs with extract_loop_variable_from_condition helper - Extracted ~30 lines of utility logic - control_flow/mod.rs now delegates to utils module - All builds pass, no behavior changes
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
//! - Phase 3: JoinIR routing (joinir/routing.rs) ✅
|
||||
//! - Phase 4: Merge implementation (joinir/merge/) ✅
|
||||
//! - Phase 5: Exception handling (exception/) ✅
|
||||
//! - Phase 6: Utility functions (utils.rs) ✅
|
||||
|
||||
use super::ValueId;
|
||||
use crate::ast::ASTNode;
|
||||
@ -19,6 +20,9 @@ pub(in crate::mir::builder) mod joinir;
|
||||
// Phase 5: Exception handling
|
||||
pub(in crate::mir::builder) mod exception;
|
||||
|
||||
// Phase 6: Utility functions
|
||||
pub(in crate::mir::builder) mod utils;
|
||||
|
||||
impl super::MirBuilder {
|
||||
/// Control-flow: block
|
||||
pub(super) fn cf_block(&mut self, statements: Vec<ASTNode>) -> Result<ValueId, String> {
|
||||
@ -138,35 +142,9 @@ impl super::MirBuilder {
|
||||
/// For `i < 3`, extracts `i`.
|
||||
/// For `arr.length() > 0`, extracts `arr`.
|
||||
///
|
||||
/// This is a minimal implementation that handles simple comparison patterns.
|
||||
/// Delegates to utils::extract_loop_variable_from_condition for implementation.
|
||||
fn extract_loop_variable_from_condition(&self, condition: &ASTNode) -> Result<String, String> {
|
||||
use crate::ast::BinaryOperator;
|
||||
|
||||
match condition {
|
||||
ASTNode::BinaryOp {
|
||||
operator, left, ..
|
||||
} if matches!(
|
||||
operator,
|
||||
BinaryOperator::Less
|
||||
| BinaryOperator::Greater
|
||||
| BinaryOperator::LessEqual
|
||||
| BinaryOperator::GreaterEqual
|
||||
) =>
|
||||
{
|
||||
// Binary comparison: extract variable from left side
|
||||
match &**left {
|
||||
ASTNode::Variable { name, .. } => Ok(name.clone()),
|
||||
_ => Err(format!(
|
||||
"[cf_loop/pattern1] Cannot extract loop variable from condition: {:?}",
|
||||
condition
|
||||
)),
|
||||
}
|
||||
}
|
||||
_ => Err(format!(
|
||||
"[cf_loop/pattern1] Unsupported loop condition pattern: {:?}",
|
||||
condition
|
||||
)),
|
||||
}
|
||||
utils::extract_loop_variable_from_condition(condition)
|
||||
}
|
||||
|
||||
/// Control-flow: throw
|
||||
|
||||
Reference in New Issue
Block a user