Class: Ikra::AST::BeginNode

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

Constant Summary

Constants inherited from TreeNode

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, #merge_union_type, #register_type_change, #replace, #symbol_table

Methods inherited from Node

#==, #eql?, #hash

Constructor Details

#initialize(body_stmts: []) ⇒ BeginNode

Returns a new instance of BeginNode.



602
603
604
605
606
607
608
# File 'lib/ast/nodes.rb', line 602

def initialize(body_stmts: [])
    @body_stmts = body_stmts

    body_stmts.each do |stmt|
        stmt.parent = self
    end
end

Instance Attribute Details

#body_stmtsObject (readonly)

Returns the value of attribute body_stmts.



600
601
602
# File 'lib/ast/nodes.rb', line 600

def body_stmts
  @body_stmts
end

Instance Method Details

#accept(visitor) ⇒ Object



176
177
178
# File 'lib/ast/visitor.rb', line 176

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

#add_statement(node) ⇒ Object



615
616
617
618
# File 'lib/ast/nodes.rb', line 615

def add_statement(node)
    body_stmts.push(node)
    node.parent = self
end

#cloneObject



610
611
612
613
# File 'lib/ast/nodes.rb', line 610

def clone
    return BeginNode.new(
        body_stmts: @body_stmts.map do |s| s.clone end)
end

#is_begin_node?Boolean

Returns:

  • (Boolean)


631
632
633
# File 'lib/ast/nodes.rb', line 631

def is_begin_node?
    true
end

#replace_child(node, another_node) ⇒ Object



620
621
622
623
624
625
626
627
628
629
# File 'lib/ast/nodes.rb', line 620

def replace_child(node, another_node)
    @body_stmts = @body_stmts.map do |stmt|
        if node.equal?(stmt)
            another_node.parent = self
            another_node
        else
            stmt
        end
    end
end

#to_sObject



172
173
174
175
176
177
178
# File 'lib/ast/printer.rb', line 172

def to_s
    stmts = body_stmts.map do |stmt|
        stmt.to_s
    end.join(";\n")

    return "[BeginNode: {#{stmts}}]"
end