123456789_123456789_123456789_123456789_123456789_

Class: TypeProf::Type::Local

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: TypeProf::Type::ContainerType
Defined in: lib/typeprof/container-type.rb

Constant Summary

::TypeProf::Type - Inherited

Builtin, DummySubstitution

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(kind, id, base_type) ⇒ Local

[ GitHub ]

  
# File '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

Instance Attribute Details

#base_type (readonly)

[ GitHub ]

  
# File 'lib/typeprof/container-type.rb', line 829

attr_reader :kind, :id, :base_type

#id (readonly)

[ GitHub ]

  
# File 'lib/typeprof/container-type.rb', line 829

attr_reader :kind, :id, :base_type

#kind (readonly)

[ GitHub ]

  
# File 'lib/typeprof/container-type.rb', line 829

attr_reader :kind, :id, :base_type

Instance Method Details

#globalize(env, visited, depth)

[ GitHub ]

  
# File '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

[ GitHub ]

  
# File 'lib/typeprof/container-type.rb', line 831

def inspect
  "Type::Local[#{ @kind }, #{ @id }, base_type: #{ @base_type.inspect }]"
end

#method_dispatch_info

[ GitHub ]

  
# File 'lib/typeprof/container-type.rb', line 857

def method_dispatch_info
  @base_type.method_dispatch_info
end

#screen_name(scratch)

[ GitHub ]

  
# File '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)

[ GitHub ]

  
# File '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