class TypeProf::Type::Local

Attributes

base_type[R]
id[R]
kind[R]

Public Class Methods

new(kind, id, base_type) click to toggle source
# File typeprof-0.15.2/lib/typeprof/container-type.rb, line 821
def initialize(kind, id, base_type)
  @kind = kind
  raise if @kind != Cell && @kind != Array && @kind != Hash
  @id = id
  raise unless base_type
  @base_type = base_type
end

Public Instance Methods

globalize(env, visited, depth) click to toggle source
# File typeprof-0.15.2/lib/typeprof/container-type.rb, line 840
def globalize(env, visited, depth)
  if visited[self] || depth <= 0
    Type.any
  else
    visited[self] = true
    elems = env.get_container_elem_types(@id)
    if elems
      elems = elems.globalize(env, visited, depth - 1)
    else
      # TODO: currently out-of-scope array cannot be accessed
      elems = @kind::Elements.dummy_elements
    end
    visited.delete(self)
    @kind.new(elems, @base_type)
  end
end
inspect() click to toggle source
# File typeprof-0.15.2/lib/typeprof/container-type.rb, line 831
def inspect
  "Type::Local[#{ @kind }, #{ @id }, base_type: #{ @base_type.inspect }]"
end
method_dispatch_info() click to toggle source
# File typeprof-0.15.2/lib/typeprof/container-type.rb, line 857
def method_dispatch_info
  @base_type.method_dispatch_info
end
screen_name(scratch) click to toggle source
# File typeprof-0.15.2/lib/typeprof/container-type.rb, line 835
def screen_name(scratch)
  #raise "Local type must not be included in signature"
  "Local[#{ @kind }]"
end
update_container_elem_type(subst, env, caller_ep, scratch) click to toggle source
# File typeprof-0.15.2/lib/typeprof/container-type.rb, line 861
def update_container_elem_type(subst, env, caller_ep, scratch)
  case
  when @kind == Cell
    tyvars = @base_type.klass.type_params.map {|name,| Type::Var.new(name) }
    # XXX: This should be skipped when the called methods belongs to superclass
    tyvars.each_with_index do |tyvar, idx|
      ty = subst[tyvar]
      if ty
        env, ty = scratch.localize_type(ty, env, caller_ep)
        env = scratch.update_container_elem_types(env, caller_ep, @id, @base_type) do |elems|
          elems.update(idx, ty)
        end
      end
    end
  when @kind == Array
    tyvar_elem = Type::Var.new(:Elem)
    if subst[tyvar_elem]
      ty = subst[tyvar_elem]
      env, ty = scratch.localize_type(ty, env, caller_ep)
      env = scratch.update_container_elem_types(env, caller_ep, @id, @base_type) do |elems|
        elems.update(nil, ty)
      end
    end
  when @kind == Hash
    tyvar_k = Type::Var.new(:K)
    tyvar_v = Type::Var.new(:V)
    if subst[tyvar_k] && subst[tyvar_v]
      k_ty = subst[tyvar_k]
      v_ty = subst[tyvar_v]
      alloc_site = AllocationSite.new(caller_ep)
      env, k_ty = scratch.localize_type(k_ty, env, caller_ep, alloc_site.add_id(:k))
      env, v_ty = scratch.localize_type(v_ty, env, caller_ep, alloc_site.add_id(:v))
      env = scratch.update_container_elem_types(env, caller_ep, @id, @base_type) do |elems|
        elems.update(k_ty, v_ty)
      end
    end
  end
  env
end