Files
hakorune/src/mir/builder/builder_value_kind.rs

48 lines
1.7 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.

use super::{MirBuilder, ValueId};
use crate::mir::{MirValueKind, TypedValueId};
impl MirBuilder {
// ============================================================================
// Phase 26-A: ValueId型安全化メソッド
// ============================================================================
/// 型付きValueIdを発行新API
/// Phase 136 P0: Use SSOT allocator (next_value_id) to respect function context
pub fn new_typed_value(&mut self, kind: MirValueKind) -> TypedValueId {
let id = self.next_value_id();
self.type_ctx.value_kinds.insert(id, kind);
TypedValueId::new(id, kind)
}
/// 既存ValueIdの型情報を取得
pub fn get_value_kind(&self, id: ValueId) -> Option<MirValueKind> {
self.type_ctx.value_kinds.get(&id).copied()
}
/// 既存ValueIdに型情報を後付けレガシー互換用
pub fn register_value_kind(&mut self, id: ValueId, kind: MirValueKind) {
self.type_ctx.value_kinds.insert(id, kind);
}
/// 型安全なパラメータ判定ValueIdベース - GUARD Bug Prevention
pub fn is_value_parameter(&self, id: ValueId) -> bool {
self.get_value_kind(id)
.map(|kind| kind.is_parameter())
.unwrap_or(false)
}
/// 型安全なローカル変数判定ValueIdベース
pub fn is_value_local(&self, id: ValueId) -> bool {
self.get_value_kind(id)
.map(|kind| kind.is_local())
.unwrap_or(false)
}
/// 型安全なLoopCarrier判定ValueIdベース
pub fn is_value_loop_carrier(&self, id: ValueId) -> bool {
self.get_value_kind(id)
.map(|kind| kind.is_loop_carrier())
.unwrap_or(false)
}
}