class TypeProf::Core::BasicVertex
Attributes
types[R]
Public Class Methods
new(types)
click to toggle source
# File typeprof-0.30.1/lib/typeprof/core/graph/vertex.rb, line 3 def initialize(types) @types = types @types_to_be_added = {} end
Public Instance Methods
check_match(genv, changes, vtx)
click to toggle source
# File typeprof-0.30.1/lib/typeprof/core/graph/vertex.rb, line 23 def check_match(genv, changes, vtx) vtx.each_type do |ty| if ty.is_a?(Type::Var) changes.add_edge(genv, self, ty.vtx) if self != ty.vtx return true end end return true if @types.empty? return true if vtx.types.empty? each_type do |ty| return true if vtx.types.include?(ty) # fast path if ty.check_match(genv, changes, vtx) return true end end return false end
each_type(&blk)
click to toggle source
# File typeprof-0.30.1/lib/typeprof/core/graph/vertex.rb, line 10 def each_type(&blk) @types.each_key(&blk) until @types_to_be_added.empty? h = @types_to_be_added.dup h.each do |ty, source| @types[ty] = source end @types_to_be_added.clear h.each_key(&blk) end end
show()
click to toggle source
# File typeprof-0.30.1/lib/typeprof/core/graph/vertex.rb, line 44 def show Fiber[:show_rec] ||= Set[] if Fiber[:show_rec].include?(self) "untyped" else begin Fiber[:show_rec] << self types = [] bot = @types.keys.any? {|ty| ty.is_a?(Type::Bot) } optional = true_exist = false_exist = false each_type do |ty| if ty.is_a?(Type::Instance) case ty.mod.cpath when [:NilClass] then optional = true when [:TrueClass] then true_exist = true when [:FalseClass] then false_exist = true end end end bool = true_exist && false_exist types << "bool" if bool each_type do |ty, _source| if ty.is_a?(Type::Instance) next if ty.mod.cpath == [:NilClass] next if bool && (ty.mod.cpath == [:TrueClass] || ty.mod.cpath == [:FalseClass]) end next if ty.is_a?(Type::Bot) types << ty.show end types = types.uniq.sort case types.size when 0 optional ? "nil" : bot ? "bot" : "untyped" when 1 types.first + (optional ? "?" : "") else "(#{ types.join(" | ") })" + (optional ? "?" : "") end ensure Fiber[:show_rec].delete(self) || raise end end end