class TypeProf::Core::IsAFilter

Attributes

next_vtx[R]

Public Class Methods

new(genv, node, prev_vtx, neg, const_read) click to toggle source
# File typeprof-0.30.1/lib/typeprof/core/graph/filter.rb, line 40
def initialize(genv, node, prev_vtx, neg, const_read)
  @node = node
  @types = Set[]
  @const_read = const_read
  @const_read.followers << self
  @next_vtx = Vertex.new(node)
  prev_vtx.add_edge(genv, self)
  @neg = neg
end

Public Instance Methods

on_type_added(genv, src_var, added_types) click to toggle source
# File typeprof-0.30.1/lib/typeprof/core/graph/filter.rb, line 52
def on_type_added(genv, src_var, added_types)
  added_types.each do |ty|
    @types << ty
  end
  run(genv)
end
on_type_removed(genv, src_var, removed_types) click to toggle source
# File typeprof-0.30.1/lib/typeprof/core/graph/filter.rb, line 59
def on_type_removed(genv, src_var, removed_types)
  removed_types.each do |ty|
    @types.delete(ty) || raise
  end
  run(genv)
end
run(genv) click to toggle source
# File typeprof-0.30.1/lib/typeprof/core/graph/filter.rb, line 66
def run(genv)
  if @const_read && @const_read.cpath
    passed_types = []
    @types.each do |ty|
      base_ty = ty.base_type(genv)
      subclass = false
      genv.each_superclass(base_ty.mod, base_ty.is_a?(Type::Singleton)) do |mod, singleton|
        if mod.cpath == @const_read.cpath
          subclass = true
          break
        end
      end
      passed_types << ty if subclass != @neg
    end
  else
    passed_types = @types.to_a
  end
  added_types = passed_types - @next_vtx.types.keys
  removed_types = @next_vtx.types.keys - passed_types
  @next_vtx.on_type_added(genv, self, added_types)
  @next_vtx.on_type_removed(genv, self, removed_types)
end
to_s() click to toggle source

@@new_id = 0

# File typeprof-0.30.1/lib/typeprof/core/graph/filter.rb, line 91
def to_s
  "NF#{ @id ||= $new_id += 1 } -> #{ @next_vtx }"
end