Class: TypeProf::Core::IVarReadBox

Inherits:
Box
  • Object
show all
Defined in:
lib/typeprof/core/graph/box.rb

Instance Attribute Summary collapse

Attributes inherited from Box

#changes, #destroyed

Instance Method Summary collapse

Methods inherited from Box

#on_type_added, #on_type_removed, #reuse, #run, #to_s

Constructor Details

#initialize(node, genv, cpath, singleton, name) ⇒ IVarReadBox

Returns a new instance of IVarReadBox.



960
961
962
963
964
965
966
967
968
969
# File 'lib/typeprof/core/graph/box.rb', line 960

def initialize(node, genv, cpath, singleton, name)
  super(node)
  @cpath = cpath
  @singleton = singleton
  @name = name
  genv.resolve_cpath(cpath).ivar_reads << self
  @proxy = Vertex.new(node)
  @ret = Vertex.new(node)
  genv.add_run(self)
end

Instance Attribute Details

#const_readObject (readonly)

Returns the value of attribute const_read.



971
972
973
# File 'lib/typeprof/core/graph/box.rb', line 971

def const_read
  @const_read
end

#nodeObject (readonly)

Returns the value of attribute node.



971
972
973
# File 'lib/typeprof/core/graph/box.rb', line 971

def node
  @node
end

#retObject (readonly)

Returns the value of attribute ret.



971
972
973
# File 'lib/typeprof/core/graph/box.rb', line 971

def ret
  @ret
end

Instance Method Details

#destroy(genv) ⇒ Object



973
974
975
976
# File 'lib/typeprof/core/graph/box.rb', line 973

def destroy(genv)
  genv.resolve_cpath(@cpath).ivar_reads.delete(self)
  super(genv)
end

#run0(genv, changes) ⇒ Object



978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
# File 'lib/typeprof/core/graph/box.rb', line 978

def run0(genv, changes)
  mod = genv.resolve_cpath(@cpath)
  singleton = @singleton
  cur_ive = mod.get_ivar(singleton, @name)
  target_vtx = nil
  genv.each_direct_superclass(mod, singleton) do |mod, singleton|
    ive = mod.get_ivar(singleton, @name)
    if ive.exist?
      target_vtx = ive.vtx
    end
  end
  edges = []
  if target_vtx
    if target_vtx != cur_ive.vtx
      edges << [cur_ive.vtx, @proxy] << [@proxy, target_vtx]
    end
    edges << [target_vtx, @ret]
  else
    # TODO: error?
  end
  edges.each do |src, dst|
    changes.add_edge(genv, src, dst)
  end
end