Files
hakorune/src/mir/builder/calls/utils.rs
nyash-codex eee3dfaa83 refactor(builder): 箱理論リファクタリング Phase 1完了
🎯 builder_calls.rs (982行) を箱理論で責務別にモジュール分割

## 成果
 builder_calls.rs: 982行 → 766行(-216行、22%削減)
 calls/lowering.rs: 354行(新規、箱理論6段階パターン)
 calls/utils.rs: 45行(新規、ユーティリティ統一)
 ビルド・テスト完全成功(0エラー)

## 箱理論の実装
1. 責務ごとに箱に分離:
   - lowering: 関数lowering専用
   - utils: ユーティリティ統一
   - emit/build: Phase 2で実装予定

2. 境界を明確に:
   - mod.rs で公開インターフェース定義
   - pub(in crate::mir::builder) で適切な可視性制御

3. いつでも戻せる:
   - 段階的移行、各ステップでビルド確認
   - 既存API完全保持(互換性100%)

4. 巨大関数は分割:
   - lower_static_method_as_function: 125行 → 6段階に分解
   - lower_method_as_function: 80行 → 6段階に分解

## 箱理論6段階パターン
1. prepare_lowering_context - Context準備
2. create_function_skeleton - 関数スケルトン作成
3. setup_function_params - パラメータ設定
4. lower_function_body - 本体lowering
5. finalize_function - 関数finalize
6. restore_lowering_context - Context復元

## ファイル構成
src/mir/builder/
├── calls/
│   ├── mod.rs           # 公開インターフェース
│   ├── lowering.rs      # 関数lowering(354行)
│   └── utils.rs         # ユーティリティ(45行)
└── builder_calls.rs     # 削減版(766行)

## 次のステップ
Phase 2: emit.rs 作成(~500行移行)
Phase 3: build.rs 作成(~350行移行)
最終目標: builder_calls.rs を200行以内に

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Task先生 <task@anthropic.com>
2025-11-17 17:02:01 +09:00

46 lines
1.6 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! 🎯 箱理論: Call処理のユーティリティ関数群
//!
//! 責務:
//! - 型名パースparse_type_name_to_mir
//! - 文字列リテラル抽出extract_string_literal
//! - Call結果アテーションannotate_call_result_from_func_name
//! - Call target解決resolve_call_target
use crate::ast::ASTNode;
use crate::mir::builder::{MirBuilder, MirType, ValueId};
/// Map a user-facing type name to MIR type
pub fn parse_type_name_to_mir(name: &str) -> MirType {
super::special_handlers::parse_type_name_to_mir(name)
}
/// Extract string literal from AST node if possible
pub fn extract_string_literal(node: &ASTNode) -> Option<String> {
super::special_handlers::extract_string_literal(node)
}
impl MirBuilder {
/// Annotate a call result `dst` with the return type and origin if the callee
/// is a known user/static function in the current module.
pub(in crate::mir::builder) fn annotate_call_result_from_func_name<S: AsRef<str>>(
&mut self,
dst: ValueId,
func_name: S,
) {
super::annotation::annotate_call_result_from_func_name(self, dst, func_name)
}
/// Resolve function call target to type-safe Callee
/// Implements the core logic of compile-time function resolution
pub(in crate::mir::builder) fn resolve_call_target(
&self,
name: &str,
) -> Result<crate::mir::definitions::call_unified::Callee, String> {
super::method_resolution::resolve_call_target(
name,
&self.current_static_box,
&self.variable_map,
)
}
}