Class: TypeProf::Core::Vertex

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BasicVertex

#each_type, #show

Constructor Details

#initialize(origin) ⇒ Vertex

Returns a new instance of Vertex.



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/typeprof/core/graph/vertex.rb', line 125

def initialize(origin)
  # Note that origin is just for debug.
  # When an AST node is reused, the value of the origin will be invalid.
  case origin
  when AST::Node
  when RBS::AST::Declarations::Base
  when ValueEntity
  when ActualArguments
  when Array
  when Symbol
  else
    raise "unknown class: #{ origin.class }"
  end
  @next_vtxs = Set[]
  super({})
end

Instance Attribute Details

#next_vtxsObject (readonly)

Returns the value of attribute next_vtxs.



142
143
144
# File 'lib/typeprof/core/graph/vertex.rb', line 142

def next_vtxs
  @next_vtxs
end

#typesObject (readonly)

Returns the value of attribute types.



142
143
144
# File 'lib/typeprof/core/graph/vertex.rb', line 142

def types
  @types
end

Instance Method Details

#add_edge(genv, nvtx) ⇒ Object



190
191
192
193
# File 'lib/typeprof/core/graph/vertex.rb', line 190

def add_edge(genv, nvtx)
  @next_vtxs << nvtx
  nvtx.on_type_added(genv, self, @types.keys) unless @types.empty?
end

#new_vertex(genv, origin) ⇒ Object



184
185
186
187
188
# File 'lib/typeprof/core/graph/vertex.rb', line 184

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

#on_type_added(genv, src_var, added_types) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/typeprof/core/graph/vertex.rb', line 144

def on_type_added(genv, src_var, added_types)
  new_added_types = []
  added_types.each do |ty|
    if @types[ty]
      @types[ty] << src_var
    else
      set = Set[]
      begin
        @types[ty] = set
      rescue
        @types_to_be_added[ty] = set
      end
      set << src_var
      new_added_types << ty
    end
  end
  unless new_added_types.empty?
    @next_vtxs.each do |nvtx|
      nvtx.on_type_added(genv, self, new_added_types)
    end
  end
end

#on_type_removed(genv, src_var, removed_types) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/typeprof/core/graph/vertex.rb', line 167

def on_type_removed(genv, src_var, removed_types)
  new_removed_types = []
  removed_types.each do |ty|
    raise "!!! not implemented" if @types_to_be_added[ty]
    @types[ty].delete(src_var) || raise
    if @types[ty].empty?
      @types.delete(ty) || raise
      new_removed_types << ty
    end
  end
  unless new_removed_types.empty?
    @next_vtxs.each do |nvtx|
      nvtx.on_type_removed(genv, self, new_removed_types)
    end
  end
end

#remove_edge(genv, nvtx) ⇒ Object



195
196
197
198
# File 'lib/typeprof/core/graph/vertex.rb', line 195

def remove_edge(genv, nvtx)
  @next_vtxs.delete(nvtx) || raise
  nvtx.on_type_removed(genv, self, @types.keys) unless @types.empty?
end

#to_sObject Also known as: inspect



202
203
204
# File 'lib/typeprof/core/graph/vertex.rb', line 202

def to_s
  "v#{ @id ||= $new_id += 1 }"
end