Class: Ikra::AST::TernaryNode

Inherits:
TreeNode show all
Defined in:
lib/ast/nodes.rb,
lib/ast/printer.rb,
lib/ast/visitor.rb

Constant Summary

Constants inherited from TreeNode

Ikra::AST::TreeNode::TYPE_INFO_VARS

Instance Attribute Summary collapse

Attributes inherited from Node

#parent

Instance Method Summary collapse

Methods inherited from TreeNode

#==, #enclosing_class, #find_behavior_node, #get_type, #is_begin_node?, #merge_union_type, #register_type_change, #replace, #replace_child, #symbol_table

Methods inherited from Node

#==, #eql?, #hash

Constructor Details

#initialize(condition:, true_val:, false_val:) ⇒ TernaryNode

Returns a new instance of TernaryNode.



581
582
583
584
585
586
587
588
589
# File 'lib/ast/nodes.rb', line 581

def initialize(condition:, true_val:, false_val:)
    @condition = condition
    @true_val = true_val
    @false_val = false_val

    condition.parent = self
    true_val.parent = self
    false_val.parent = self
end

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition.



577
578
579
# File 'lib/ast/nodes.rb', line 577

def condition
  @condition
end

#false_valObject (readonly)

Returns the value of attribute false_val.



579
580
581
# File 'lib/ast/nodes.rb', line 579

def false_val
  @false_val
end

#true_valObject (readonly)

Returns the value of attribute true_val.



578
579
580
# File 'lib/ast/nodes.rb', line 578

def true_val
  @true_val
end

Instance Method Details

#accept(visitor) ⇒ Object



170
171
172
# File 'lib/ast/visitor.rb', line 170

def accept(visitor)
    return visitor.visit_ternary_node(self)
end

#cloneObject



591
592
593
594
595
596
# File 'lib/ast/nodes.rb', line 591

def clone
    return TernaryNode.new(
        condition: @condition.clone,
        true_val: @true_val.clone,
        false_val: @false_val.clone)
end

#to_sObject



166
167
168
# File 'lib/ast/printer.rb', line 166

def to_s
    return "[TernaryNode: #{condition.to_s}, #{true_val.to_s}, #{false_val.to_s}]"
end