Class: TypeProf::Core::Source

Inherits:
BasicVertex show all
Defined in:
lib/typeprof/core/graph/vertex.rb

Instance Attribute Summary

Attributes inherited from BasicVertex

#types

Instance Method Summary collapse

Methods inherited from BasicVertex

#each_type

Constructor Details

#initialize(*tys) ⇒ Source

Returns a new instance of Source.



74
75
76
77
78
79
80
81
# File 'lib/typeprof/core/graph/vertex.rb', line 74

def initialize(*tys)
  types = {}
  tys.each do |ty|
    raise ty.inspect unless ty.is_a?(Type)
    types[ty] = true
  end
  super(types)
end

Instance Method Details

#add_edge(genv, nvtx) ⇒ Object



96
97
98
# File 'lib/typeprof/core/graph/vertex.rb', line 96

def add_edge(genv, nvtx)
  nvtx.on_type_added(genv, self, @types.keys)
end

#new_vertex(genv, origin) ⇒ Object



90
91
92
93
94
# File 'lib/typeprof/core/graph/vertex.rb', line 90

def new_vertex(genv, origin)
  nvtx = Vertex.new(origin)
  add_edge(genv, nvtx)
  nvtx
end

#on_type_added(genv, src_var, added_types) ⇒ Object



83
84
85
# File 'lib/typeprof/core/graph/vertex.rb', line 83

def on_type_added(genv, src_var, added_types)
  # TODO: need to report error?
end

#on_type_removed(genv, src_var, removed_types) ⇒ Object



87
88
# File 'lib/typeprof/core/graph/vertex.rb', line 87

def on_type_removed(genv, src_var, removed_types)
end

#remove_edge(genv, nvtx) ⇒ Object



100
101
102
# File 'lib/typeprof/core/graph/vertex.rb', line 100

def remove_edge(genv, nvtx)
  nvtx.on_type_removed(genv, self, @types.keys)
end

#showObject



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/typeprof/core/graph/vertex.rb', line 104

def show
  Fiber[:show_rec] ||= Set.empty
  if Fiber[:show_rec].include?(self)
    "...(recursive)..."
  else
    begin
      Fiber[:show_rec] << self
      @types.empty? ? "untyped" : @types.keys.map {|ty| ty.show }.sort.join(" | ")
    ensure
      Fiber[:show_rec].delete(self) || raise
    end
  end
end

#to_sObject Also known as: inspect



118
119
120
# File 'lib/typeprof/core/graph/vertex.rb', line 118

def to_s
  "<src:#{ show }>"
end