Class: TypeProf::Core::SplatBox

Inherits:
Box
  • Object
show all
Defined in:
lib/typeprof/core/graph/box.rb

Instance Attribute Summary collapse

Attributes inherited from Box

#changes, #destroyed, #node

Instance Method Summary collapse

Methods inherited from Box

#add_symbol_proc_call_box, #destroy, #destroy_symbol_proc_call_boxes, #on_type_added, #on_type_removed, #reuse, #run, #to_s

Constructor Details

#initialize(node, genv, ary, idx, unresolved_recv = nil) ⇒ SplatBox

Returns a new instance of SplatBox.



633
634
635
636
637
638
639
640
641
# File 'lib/typeprof/core/graph/box.rb', line 633

def initialize(node, genv, ary, idx, unresolved_recv = nil)
  super(node)
  @ary = ary
  @idx = idx
  @unresolved_recv = unresolved_recv
  @ary.add_edge(genv, self)
  @unresolved_recv.add_edge(genv, self) if @unresolved_recv
  @ret = Vertex.new(node)
end

Instance Attribute Details

#ary ⇒ Object (readonly)

Returns the value of attribute ary.



643
644
645
# File 'lib/typeprof/core/graph/box.rb', line 643

def ary
  @ary
end

#idx ⇒ Object (readonly)

Returns the value of attribute idx.



643
644
645
# File 'lib/typeprof/core/graph/box.rb', line 643

def idx
  @idx
end

#ret ⇒ Object (readonly)

Returns the value of attribute ret.



643
644
645
# File 'lib/typeprof/core/graph/box.rb', line 643

def ret
  @ret
end

Instance Method Details

#run0(genv, changes) ⇒ Object



645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
# File 'lib/typeprof/core/graph/box.rb', line 645

def run0(genv, changes)
  @ary.each_type do |ty|
    case ty
    when Type::Instance
      if ty.mod == genv.mod_ary
        changes.add_edge(genv, ty.args[0], @ret)
      else
        "???"
      end
    when Type::Array
      if @idx && @idx < ty.elems.size
        changes.add_edge(genv, ty.elems[@idx], @ret)
      else
        changes.add_edge(genv, ty.get_elem(genv, @idx), @ret)
      end
    else
      "???"
    end
  end
  # For types where to_a is not defined, [*x] wraps x as [x]
  if @unresolved_recv
    @unresolved_recv.each_type do |ty|
      changes.add_edge(genv, Source.new(ty), @ret)
    end
  end
end