Class: TypeProf::Core::BasicVertex
- Inherits:
-
Object
- Object
- TypeProf::Core::BasicVertex
- Defined in:
- lib/typeprof/core/graph/vertex.rb
Instance Attribute Summary collapse
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
- #each_type(&blk) ⇒ Object
-
#initialize(types) ⇒ BasicVertex
constructor
A new instance of BasicVertex.
- #new_vertex(genv, origin) ⇒ Object
- #show ⇒ Object
Constructor Details
#initialize(types) ⇒ BasicVertex
Returns a new instance of BasicVertex.
3 4 5 6 |
# File 'lib/typeprof/core/graph/vertex.rb', line 3 def initialize(types) @types = types @types_to_be_added = {} end |
Instance Attribute Details
#types ⇒ Object (readonly)
Returns the value of attribute types.
8 9 10 |
# File 'lib/typeprof/core/graph/vertex.rb', line 8 def types @types end |
Instance Method Details
#each_type(&blk) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File '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 |
#new_vertex(genv, origin) ⇒ Object
67 68 69 |
# File 'lib/typeprof/core/graph/vertex.rb', line 67 def new_vertex(genv, origin) raise NotImplementedError end |
#show ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/typeprof/core/graph/vertex.rb', line 23 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 |