Class: TypeProf::Core::IVarReadBox
- Defined in:
- lib/typeprof/core/graph/box.rb
Instance Attribute Summary collapse
-
#const_read ⇒ Object
readonly
Returns the value of attribute const_read.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#ret ⇒ Object
readonly
Returns the value of attribute ret.
Attributes inherited from Box
Instance Method Summary collapse
- #destroy(genv) ⇒ Object
-
#initialize(node, genv, cpath, singleton, name) ⇒ IVarReadBox
constructor
A new instance of IVarReadBox.
- #run0(genv, changes) ⇒ Object
Methods inherited from Box
#add_symbol_proc_call_box, #destroy_symbol_proc_call_boxes, #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.
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 |
# File 'lib/typeprof/core/graph/box.rb', line 1382 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_read ⇒ Object (readonly)
Returns the value of attribute const_read.
1393 1394 1395 |
# File 'lib/typeprof/core/graph/box.rb', line 1393 def const_read @const_read end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
1393 1394 1395 |
# File 'lib/typeprof/core/graph/box.rb', line 1393 def node @node end |
#ret ⇒ Object (readonly)
Returns the value of attribute ret.
1393 1394 1395 |
# File 'lib/typeprof/core/graph/box.rb', line 1393 def ret @ret end |
Instance Method Details
#destroy(genv) ⇒ Object
1395 1396 1397 1398 |
# File 'lib/typeprof/core/graph/box.rb', line 1395 def destroy(genv) genv.resolve_cpath(@cpath).ivar_reads.delete(self) super(genv) end |
#run0(genv, changes) ⇒ Object
1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 |
# File 'lib/typeprof/core/graph/box.rb', line 1400 def run0(genv, changes) mod = genv.resolve_cpath(@cpath) singleton = @singleton cur_ive = mod.get_ivar(singleton, @name) target_vtx = nil target_decls = nil genv.each_direct_superclass(mod, singleton) do |mod, singleton| ive = mod.get_ivar(singleton, @name) # Subscribe to every visited ive so that, if one later acquires an # RBS declaration, this box is re-run and switches to the declared # type instead of the inferred one. changes.add_depended_value_entity(ive) if ive.exist? target_vtx = ive.vtx target_decls = ive.decls unless ive.decls.empty? break if target_decls end end if target_decls # When declarations exist, return declared types instead of assigned types target_decls.each do |decl| subst = {} if decl.cpath decl_mod = genv.resolve_cpath(decl.cpath) if decl_mod.type_params && !decl_mod.type_params.empty? subst = decl_mod.type_params.to_h do |param, _default_ty| [param, Vertex.new(@node)] end end end vtx = decl.type.covariant_vertex(genv, changes, subst) changes.add_edge(genv, vtx, @ret) end elsif target_vtx edges = [] if target_vtx != cur_ive.vtx edges << [cur_ive.vtx, @proxy] << [@proxy, target_vtx] end edges << [target_vtx, @ret] edges.each do |src, dst| changes.add_edge(genv, src, dst) end end end |