Phase 25.1 完了成果: - ✅ LoopForm v2 テスト・ドキュメント・コメント完備 - 4ケース(A/B/C/D)完全テストカバレッジ - 最小再現ケース作成(SSAバグ調査用) - SSOT文書作成(loopform_ssot.md) - 全ソースに [LoopForm] コメントタグ追加 - ✅ Stage-1 CLI デバッグ環境構築 - stage1_cli.hako 実装 - stage1_bridge.rs ブリッジ実装 - デバッグツール作成(stage1_debug.sh/stage1_minimal.sh) - アーキテクチャ改善提案文書 - ✅ 環境変数削減計画策定 - 25変数の完全調査・分類 - 6段階削減ロードマップ(25→5、80%削減) - 即時削除可能変数特定(NYASH_CONFIG/NYASH_DEBUG) Phase 26-D からの累積変更: - PHI実装改善(ExitPhiBuilder/HeaderPhiBuilder等) - MIRビルダーリファクタリング - 型伝播・最適化パス改善 - その他約300ファイルの累積変更 🎯 技術的成果: - SSAバグ根本原因特定(条件分岐内loop変数変更) - Region+next_iパターン適用完了(UsingCollectorBox等) - LoopFormパターン文書化・テスト化完了 - セルフホスティング基盤強化 Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: ChatGPT <noreply@openai.com> Co-Authored-By: Task Assistant <task@anthropic.com>
264 lines
5.8 KiB
Rust
264 lines
5.8 KiB
Rust
//! Lightweight wrapper structs around ASTNode variants (non-breaking).
|
|
//!
|
|
//! Purpose: provide a gentle path to work with structured nodes via
|
|
//! TryFrom/From without changing the canonical AST enum. This enables
|
|
//! gradual refactors in builders by converting once at the boundary and
|
|
//! then matching on small, typed wrappers.
|
|
|
|
use super::{ASTNode, Span};
|
|
|
|
// ----------------
|
|
// Statements
|
|
// ----------------
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct AssignStmt {
|
|
pub target: Box<ASTNode>,
|
|
pub value: Box<ASTNode>,
|
|
pub span: Span,
|
|
}
|
|
|
|
impl TryFrom<ASTNode> for AssignStmt {
|
|
type Error = ASTNode;
|
|
fn try_from(node: ASTNode) -> Result<Self, Self::Error> {
|
|
match node {
|
|
ASTNode::Assignment {
|
|
target,
|
|
value,
|
|
span,
|
|
} => Ok(AssignStmt {
|
|
target,
|
|
value,
|
|
span,
|
|
}),
|
|
other => Err(other),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<AssignStmt> for ASTNode {
|
|
fn from(s: AssignStmt) -> Self {
|
|
ASTNode::Assignment {
|
|
target: s.target,
|
|
value: s.value,
|
|
span: s.span,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct ReturnStmt {
|
|
pub value: Option<Box<ASTNode>>,
|
|
pub span: Span,
|
|
}
|
|
|
|
impl TryFrom<ASTNode> for ReturnStmt {
|
|
type Error = ASTNode;
|
|
fn try_from(node: ASTNode) -> Result<Self, Self::Error> {
|
|
match node {
|
|
ASTNode::Return { value, span } => Ok(ReturnStmt { value, span }),
|
|
other => Err(other),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<ReturnStmt> for ASTNode {
|
|
fn from(s: ReturnStmt) -> Self {
|
|
ASTNode::Return {
|
|
value: s.value,
|
|
span: s.span,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct IfStmt {
|
|
pub condition: Box<ASTNode>,
|
|
pub then_body: Vec<ASTNode>,
|
|
pub else_body: Option<Vec<ASTNode>>,
|
|
pub span: Span,
|
|
}
|
|
|
|
impl TryFrom<ASTNode> for IfStmt {
|
|
type Error = ASTNode;
|
|
fn try_from(node: ASTNode) -> Result<Self, Self::Error> {
|
|
match node {
|
|
ASTNode::If {
|
|
condition,
|
|
then_body,
|
|
else_body,
|
|
span,
|
|
} => Ok(IfStmt {
|
|
condition,
|
|
then_body,
|
|
else_body,
|
|
span,
|
|
}),
|
|
other => Err(other),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<IfStmt> for ASTNode {
|
|
fn from(s: IfStmt) -> Self {
|
|
ASTNode::If {
|
|
condition: s.condition,
|
|
then_body: s.then_body,
|
|
else_body: s.else_body,
|
|
span: s.span,
|
|
}
|
|
}
|
|
}
|
|
|
|
// ----------------
|
|
// Expressions
|
|
// ----------------
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct BinaryExpr {
|
|
pub operator: super::BinaryOperator,
|
|
pub left: Box<ASTNode>,
|
|
pub right: Box<ASTNode>,
|
|
pub span: Span,
|
|
}
|
|
|
|
impl TryFrom<ASTNode> for BinaryExpr {
|
|
type Error = ASTNode;
|
|
fn try_from(node: ASTNode) -> Result<Self, Self::Error> {
|
|
match node {
|
|
ASTNode::BinaryOp {
|
|
operator,
|
|
left,
|
|
right,
|
|
span,
|
|
} => Ok(BinaryExpr {
|
|
operator,
|
|
left,
|
|
right,
|
|
span,
|
|
}),
|
|
other => Err(other),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<BinaryExpr> for ASTNode {
|
|
fn from(e: BinaryExpr) -> Self {
|
|
ASTNode::BinaryOp {
|
|
operator: e.operator,
|
|
left: e.left,
|
|
right: e.right,
|
|
span: e.span,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct CallExpr {
|
|
pub name: String,
|
|
pub arguments: Vec<ASTNode>,
|
|
pub span: Span,
|
|
}
|
|
|
|
impl TryFrom<ASTNode> for CallExpr {
|
|
type Error = ASTNode;
|
|
fn try_from(node: ASTNode) -> Result<Self, Self::Error> {
|
|
match node {
|
|
ASTNode::FunctionCall {
|
|
name,
|
|
arguments,
|
|
span,
|
|
} => Ok(CallExpr {
|
|
name,
|
|
arguments,
|
|
span,
|
|
}),
|
|
other => Err(other),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<CallExpr> for ASTNode {
|
|
fn from(c: CallExpr) -> Self {
|
|
ASTNode::FunctionCall {
|
|
name: c.name,
|
|
arguments: c.arguments,
|
|
span: c.span,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct MethodCallExpr {
|
|
pub object: Box<ASTNode>,
|
|
pub method: String,
|
|
pub arguments: Vec<ASTNode>,
|
|
pub span: Span,
|
|
}
|
|
|
|
impl TryFrom<ASTNode> for MethodCallExpr {
|
|
type Error = ASTNode;
|
|
fn try_from(node: ASTNode) -> Result<Self, Self::Error> {
|
|
match node {
|
|
ASTNode::MethodCall {
|
|
object,
|
|
method,
|
|
arguments,
|
|
span,
|
|
} => Ok(MethodCallExpr {
|
|
object,
|
|
method,
|
|
arguments,
|
|
span,
|
|
}),
|
|
other => Err(other),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<MethodCallExpr> for ASTNode {
|
|
fn from(m: MethodCallExpr) -> Self {
|
|
ASTNode::MethodCall {
|
|
object: m.object,
|
|
method: m.method,
|
|
arguments: m.arguments,
|
|
span: m.span,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct FieldAccessExpr {
|
|
pub object: Box<ASTNode>,
|
|
pub field: String,
|
|
pub span: Span,
|
|
}
|
|
|
|
impl TryFrom<ASTNode> for FieldAccessExpr {
|
|
type Error = ASTNode;
|
|
fn try_from(node: ASTNode) -> Result<Self, Self::Error> {
|
|
match node {
|
|
ASTNode::FieldAccess {
|
|
object,
|
|
field,
|
|
span,
|
|
} => Ok(FieldAccessExpr {
|
|
object,
|
|
field,
|
|
span,
|
|
}),
|
|
other => Err(other),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<FieldAccessExpr> for ASTNode {
|
|
fn from(f: FieldAccessExpr) -> Self {
|
|
ASTNode::FieldAccess {
|
|
object: f.object,
|
|
field: f.field,
|
|
span: f.span,
|
|
}
|
|
}
|
|
}
|