# encoding: utf-8 # frozen_string_literal: true module Carbon module Compiler module Visitor class Preparation module Statements Preparation.on Node::Statement::Return => :visit_ignore Preparation.on Node::Statement::If => :visit_statement_if Preparation.on Node::Statement::ElsIf => :visit_statement_if def visit_statement_if(node) @context = :if condition = accept(node.condition) @context = :normal node.update(condition: condition, body: accept(node.body), follow: accept(node.follow)) end Preparation.on Node::Statement::Else => :visit_statement_else def visit_statement_else(node) node.update(body: accept(node.body)) end Preparation.on Node::Statement::Catch => :visit_statement_catch def visit_statement_catch(node) visit_statement_body_follow(node) end Preparation.on Node::Statement::Try => :visit_statement_body_follow def visit_statement_body_follow(node) node.merge(body: accept(node.body), follow: accept(node.follow)) end Preparation.on Node::Statement::While => :visit_statement_while def visit_statement_while(node) @context = :while expr = accept(node.condition) @context = :normal node.update(condition: expr, body: accept(node.body)) end Preparation.on Node::Statement::For => :visit_statement_for def visit_statement_for(node) @context = :"for:init" initial = accept(node.initial) @context = :"for:cond" condition = accept(node.condition) @context = :"for:incr" increment = accept(node.increment) @context = :normal node.update(initial: initial, condition: condition, increment: increment, body: accept(node.body)) end Preparation.on Node::Statement::Finally => :visit_statement_body def visit_statement_body(node) node.merge(body: accept(node.body)) end Preparation.on Node::Statement::Let => :visit_statement_let def visit_statement_let(node) node.merge(type: accept(node.type)) end end end end end end