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



646
647
648
649
650
651
652
653
654
# File 'lib/typeprof/core/graph/box.rb', line 646

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

#aryObject (readonly)

Returns the value of attribute ary.



656
657
658
# File 'lib/typeprof/core/graph/box.rb', line 656

def ary
  @ary
end

#idxObject (readonly)

Returns the value of attribute idx.



656
657
658
# File 'lib/typeprof/core/graph/box.rb', line 656

def idx
  @idx
end

#retObject (readonly)

Returns the value of attribute ret.



656
657
658
# File 'lib/typeprof/core/graph/box.rb', line 656

def ret
  @ret
end

Instance Method Details

#run0(genv, changes) ⇒ Object



658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
# File 'lib/typeprof/core/graph/box.rb', line 658

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