Class: Ikra::AST::IfNode
- Defined in:
- lib/ast/nodes.rb,
lib/ast/printer.rb,
lib/ast/visitor.rb
Constant Summary
Constants inherited from TreeNode
Instance Attribute Summary collapse
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#false_body_stmts ⇒ Object
readonly
Returns the value of attribute false_body_stmts.
-
#true_body_stmts ⇒ Object
readonly
Returns the value of attribute true_body_stmts.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #clone ⇒ Object
-
#initialize(condition:, true_body_stmts:, false_body_stmts: nil) ⇒ IfNode
constructor
A new instance of IfNode.
- #to_s ⇒ Object
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
Constructor Details
#initialize(condition:, true_body_stmts:, false_body_stmts: nil) ⇒ IfNode
Returns a new instance of IfNode.
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
# 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 |
Instance Attribute Details
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
544 545 546 |
# File 'lib/ast/nodes.rb', line 544 def condition @condition end |
#false_body_stmts ⇒ Object (readonly)
Returns the value of attribute false_body_stmts.
546 547 548 |
# File 'lib/ast/nodes.rb', line 546 def false_body_stmts @false_body_stmts end |
#true_body_stmts ⇒ Object (readonly)
Returns the value of attribute true_body_stmts.
545 546 547 |
# File 'lib/ast/nodes.rb', line 545 def true_body_stmts @true_body_stmts end |
Instance Method Details
#accept(visitor) ⇒ Object
164 165 166 |
# File 'lib/ast/visitor.rb', line 164 def accept(visitor) return visitor.visit_if_node(self) end |
#clone ⇒ Object
568 569 570 571 572 573 |
# 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 ⇒ Object
156 157 158 159 160 161 162 |
# 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 |