123456789_123456789_123456789_123456789_123456789_

Class: TypeProf::Type::Array

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

Overview

Do not insert Array type to local environment, stack, etc.

Constant Summary

::TypeProf::Type - Inherited

Builtin, DummySubstitution

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(elems, base_type) ⇒ Array

[ GitHub ]

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

def initialize(elems, base_type)
  raise unless elems.is_a?(Array::Elements)
  @elems = elems # Array::Elements
  raise unless base_type
  @base_type = base_type
end

Instance Attribute Details

#base_type (readonly)

[ GitHub ]

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

attr_reader :elems, :base_type

#elems (readonly)

[ GitHub ]

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

attr_reader :elems, :base_type

Instance Method Details

#generate_substitution

[ GitHub ]

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

def generate_substitution
  { Type::Var.new(:Elem) => @elems.squash }
end

#inspect

[ GitHub ]

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

def inspect
  "Type::Array[#{ @elems.inspect }, base_type: #{ @base_type.inspect }]"
  #@base_type.inspect
end

#limit_size(limit)

[ GitHub ]

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

def limit_size(limit)
  return Type.any if limit <= 0
  Array.new(@elems.limit_size(limit - 1), @base_type)
end

#localize(env, alloc_site, depth)

[ GitHub ]

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

def localize(env, alloc_site, depth)
  return env, Type.any if depth <= 0
  alloc_site = alloc_site.add_id(:ary).add_id(@base_type)
  env, elems = @elems.localize(env, alloc_site, depth - 1)
  ty = Local.new(Array, alloc_site, @base_type)
  env = env.deploy_type(alloc_site, elems)
  return env, ty
end

#method_dispatch_info

[ GitHub ]

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

def method_dispatch_info
  raise
end

#screen_name(scratch)

[ GitHub ]

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

def screen_name(scratch)
  str = @elems.screen_name(scratch)
  if str =~ /\A\*\[(.*)\]\z/
    str = @base_type.klass.type_params.map {|var_name,| var_name == :Elem ? $1 : "untyped" }.join(", ")
    str = "#{ @base_type.screen_name(scratch) }[#{ str }]"
  end
  str
end

#substitute(subst, depth)

[ GitHub ]

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

def substitute(subst, depth)
  return Type.any if depth <= 0
  elems = @elems.substitute(subst, depth - 1)
  Array.new(elems, @base_type)
end