Class: TypeProf::Core::TypeReadBox

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

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

Constructor Details

#initialize(node, genv, rbs_type) ⇒ TypeReadBox

Returns a new instance of TypeReadBox.



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

def initialize(node, genv, rbs_type)
  super(node)
  @rbs_type = rbs_type
  @ret = Vertex.new(node)
  genv.add_run(self)
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



81
82
83
# File 'lib/typeprof/core/graph/box.rb', line 81

def node
  @node
end

#rbs_typeObject (readonly)

Returns the value of attribute rbs_type.



81
82
83
# File 'lib/typeprof/core/graph/box.rb', line 81

def rbs_type
  @rbs_type
end

#retObject (readonly)

Returns the value of attribute ret.



81
82
83
# File 'lib/typeprof/core/graph/box.rb', line 81

def ret
  @ret
end

Instance Method Details

#run0(genv, changes) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/typeprof/core/graph/box.rb', line 83

def run0(genv, changes)
  # Create substitution map for type parameters if we're in a SigInstanceVariableNode within a generic class
  subst = {}
  if @node.is_a?(AST::SigInstanceVariableNode) && @node.cpath
    mod = genv.resolve_cpath(@node.cpath)
    if mod.type_params && !mod.type_params.empty?
      # Create a substitution map where each type parameter maps to a type variable vertex
      subst = mod.type_params.to_h do |param|
        type_var_vtx = Vertex.new(@node)
        [param, type_var_vtx]
      end
    end
  end

  vtx = @rbs_type.covariant_vertex(genv, changes, subst)
  changes.add_edge(genv, vtx, @ret)
end