Class: Ikra::AST::SendNode

Inherits:
TreeNode show all
Defined in:
lib/ast/nodes.rb,
lib/ast/printer.rb,
lib/ast/visitor.rb,
lib/types/inference/ast_inference.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, #is_begin_node?, #merge_union_type, #register_type_change, #replace, #symbol_table

Methods inherited from Node

#==, #eql?, #hash

Constructor Details

#initialize(receiver:, selector:, arguments: [], block_argument: nil) ⇒ SendNode

Returns a new instance of SendNode.



642
643
644
645
646
647
648
649
650
651
652
# File 'lib/ast/nodes.rb', line 642

def initialize(receiver:, selector:, arguments: [], block_argument: nil)
    @receiver = receiver
    @selector = selector
    @arguments = arguments
    @block_argument = block_argument

    receiver.parent = self
    arguments.each do |arg|
        arg.parent = self
    end
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



639
640
641
# File 'lib/ast/nodes.rb', line 639

def arguments
  @arguments
end

#block_argumentObject

Returns the value of attribute block_argument.



640
641
642
# File 'lib/ast/nodes.rb', line 640

def block_argument
  @block_argument
end

#receiverObject (readonly)

Returns the value of attribute receiver.



637
638
639
# File 'lib/ast/nodes.rb', line 637

def receiver
  @receiver
end

#return_type_by_recv_typeObject

Mapping: Receiver type –> Return value of send



138
139
140
# File 'lib/types/inference/ast_inference.rb', line 138

def return_type_by_recv_type
    @return_type_by_recv_type ||= {}
end

#selectorObject (readonly)

Returns the value of attribute selector.



638
639
640
# File 'lib/ast/nodes.rb', line 638

def selector
  @selector
end

Instance Method Details

#accept(visitor) ⇒ Object



182
183
184
# File 'lib/ast/visitor.rb', line 182

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

#cloneObject



654
655
656
657
658
659
660
# File 'lib/ast/nodes.rb', line 654

def clone
    return SendNode.new(
        receiver: @receiver.clone,
        selector: @selector,
        arguments: @arguments.map do |a| a.clone end,
        block_argument: block_argument == nil ? nil : block_argument.clone)
end

#replace_child(node, another_node) ⇒ Object



662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
# File 'lib/ast/nodes.rb', line 662

def replace_child(node, another_node)
    if @receiver.equal?(node)
        @receiver = another_node
        another_node.parent = self
    end

    @arguments = @arguments.map do |arg|
        if node.equal?(arg)
            another_node.parent = self
            another_node
        else
            arg
        end
    end
end

#to_sObject



182
183
184
185
186
187
188
# File 'lib/ast/printer.rb', line 182

def to_s
    args = arguments.map do |arg|
        arg.to_s
    end.join("; ")

    return "[SendNode: #{receiver.to_s}.#{selector.to_s}(#{args})]"
end