rubyx/lib/mom/if_statement.rb

29 lines
810 B
Ruby
Raw Normal View History

module Mom
2017-09-06 11:11:30 +02:00
class IfStatement < Statement
attr_reader :condition , :if_true , :if_false
attr_accessor :hoisted
def initialize( cond , if_true , if_false = nil)
@condition = cond
@if_true = if_true
@if_false = if_false
end
2017-09-06 11:51:24 +02:00
def flatten
2017-09-08 12:12:24 +02:00
head = hoisted.flatten
true_label = Label.new( "true_label_#{object_id}")
false_label = Label.new( "false_label_#{object_id}")
merge_label = Label.new( "merge_label_#{object_id}")
head.append condition.flatten( true_label: true_label , false_label: false_label)
head.append true_label
head.append if_true.flatten( merge_label: merge_label)
head.append false_label
head.append if_false.flatten( merge_label: merge_label)
head.append merge_label
head
2017-09-06 11:51:24 +02:00
end
end
end