Class: TypeProf::Core::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/typeprof/core/env/method.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, f_ary_arg, f_args, next_boxes, formals = nil) ⇒ Block

: (AST::BlockNode, Vertex, Array, Array, FormalArguments?) -> void



600
601
602
603
604
605
606
607
608
# File 'lib/typeprof/core/env/method.rb', line 600

def initialize(node, f_ary_arg, f_args, next_boxes, formals = nil)
  @node = node
  @f_ary_arg = f_ary_arg
  @f_args = f_args
  @next_boxes = next_boxes
  # Set when the body is entered like a method rather than yielded to, which
  # is to say for a lambda: the full formals then bind the call's arguments.
  @formals = formals
end

Instance Attribute Details

#f_args ⇒ Object (readonly)

Returns the value of attribute f_args.



610
611
612
# File 'lib/typeprof/core/env/method.rb', line 610

def f_args
  @f_args
end

#next_boxes ⇒ Object (readonly)

Returns the value of attribute next_boxes.



610
611
612
# File 'lib/typeprof/core/env/method.rb', line 610

def next_boxes
  @next_boxes
end

#node ⇒ Object (readonly)

Returns the value of attribute node.



610
611
612
# File 'lib/typeprof/core/env/method.rb', line 610

def node
  @node
end

Instance Method Details

#accept_args(genv, changes, caller_positionals) ⇒ Object



623
624
625
626
627
628
629
630
631
632
633
# File 'lib/typeprof/core/env/method.rb', line 623

def accept_args(genv, changes, caller_positionals)
  if caller_positionals.size == 1 && @f_args.size >= 2 && !@formals
    # A block deconstructs a sole array argument over its parameters; a
    # lambda takes it as the one argument it is.
    changes.add_edge(genv, caller_positionals[0], @f_ary_arg)
  else
    caller_positionals.zip(@f_args) do |a_arg, f_arg|
      changes.add_edge(genv, a_arg, f_arg) if f_arg
    end
  end
end

#add_ret(genv, changes, ret) ⇒ Object



635
636
637
638
639
# File 'lib/typeprof/core/env/method.rb', line 635

def add_ret(genv, changes, ret)
  @next_boxes.each do |box|
    changes.add_edge(genv, box.a_ret, ret)
  end
end

#pass_arguments(genv, changes, a_args) ⇒ Object

The arguments of a call that enters this body directly, as Proc#call does.



613
614
615
616
617
618
619
620
621
# File 'lib/typeprof/core/env/method.rb', line 613

def pass_arguments(genv, changes, a_args)
  if @formals
    a_args = a_args.with_keywords_normalized_for(@node)
    @formals.pass_arguments(changes, genv, a_args, @node)
    changes.add_edge(genv, a_args.block, @formals.block) if @formals.block && a_args.block
  else
    accept_args(genv, changes, a_args.positionals)
  end
end