use crate::collections::*; use crate::protocol::*; use super::visitor::*; pub(crate) struct PassRewriting { statement_buffer: ScopedBuffer, } impl PassRewriting { pub(crate) fn new() -> Self { Self{ statement_buffer: ScopedBuffer::with_capacity(16), } } } impl Visitor for PassRewriting { // --- Visiting procedures fn visit_component_definition(&mut self, ctx: &mut Ctx, id: ComponentDefinitionId) -> VisitorResult { let def = &ctx.heap[id]; let body_id = def.body; return self.visit_block_stmt(ctx, body_id); } fn visit_function_definition(&mut self, ctx: &mut Ctx, id: FunctionDefinitionId) -> VisitorResult { let def = &ctx.heap[id]; let body_id = def.body; return self.visit_block_stmt(ctx, body_id); } // --- Visiting statements (that are not the select statement) fn visit_block_stmt(&mut self, ctx: &mut Ctx, id: BlockStatementId) -> VisitorResult { let block_stmt = &ctx.heap[id]; let stmt_section = self.statement_buffer.start_section_initialized(&block_stmt.statements); for stmt_idx in 0..stmt_section.len() { self.visit_stmt(ctx, stmt_section[stmt_idx])?; } stmt_section.forget(); return Ok(()) } fn visit_labeled_stmt(&mut self, ctx: &mut Ctx, id: LabeledStatementId) -> VisitorResult { let labeled_stmt = &ctx.heap[id]; let body_id = labeled_stmt.body; return self.visit_stmt(ctx, body_id); } fn visit_if_stmt(&mut self, ctx: &mut Ctx, id: IfStatementId) -> VisitorResult { let if_stmt = &ctx.heap[id]; let true_body_id = if_stmt.true_body; let false_body_id = if_stmt.false_body; self.visit_block_stmt(ctx, true_body_id)?; if let Some(false_body_id) = false_body_id { self.visit_block_stmt(ctx, false_body_id)?; } return Ok(()) } fn visit_while_stmt(&mut self, ctx: &mut Ctx, id: WhileStatementId) -> VisitorResult { let while_stmt = &ctx.heap[id]; let body_id = while_stmt.body; return self.visit_block_stmt(ctx, body_id); } // --- Visiting the select statement fn visit_select_stmt(&mut self, ctx: &mut Ctx, id: SelectStatementId) -> VisitorResult { let stmt = &ctx.heap[id]; return Ok(()) } }