class Ikra::AST::IfNode

Attributes

condition[R]
false_body_stmts[R]
true_body_stmts[R]

Public Class Methods

new(condition:, true_body_stmts:, false_body_stmts: nil) click to toggle source
# File lib/ast/nodes.rb, line 548
def initialize(condition:, true_body_stmts:, false_body_stmts: nil)
    if true_body_stmts == nil
        # Handle empty `true` block
        true_body_stmts = BeginNode.new
    end

    if false_body_stmts == nil
        # Handle empty `false` block
        false_body_stmts = BeginNode.new
    end

    @condition = condition
    @true_body_stmts = true_body_stmts
    @false_body_stmts = false_body_stmts

    condition.parent = self
    true_body_stmts.parent = self 
    false_body_stmts.parent = self
end

Public Instance Methods

accept(visitor) click to toggle source
# File lib/ast/visitor.rb, line 164
def accept(visitor)
    return visitor.visit_if_node(self)
end
clone() click to toggle source
# File lib/ast/nodes.rb, line 568
def clone
    return IfNode.new(
        condition: @condition.clone,
        true_body_stmts: @true_body_stmts.clone,
        false_body_stmts: @false_body_stmts.clone)
end
to_s() click to toggle source
# File lib/ast/printer.rb, line 156
def to_s
    if false_body_stmts != nil
        return "[IfNode: #{condition.to_s}, #{true_body_stmts.to_s}, #{false_body_stmts.to_s}]"
    else
        return "[IfNode: #{condition.to_s}, #{true_body_stmts.to_s}]"
    end
end