Class: TypeProf::Core::ValueEntity

Inherits:
Object
  • Object
show all
Defined in:
lib/typeprof/core/env/value_entity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeValueEntity

Returns a new instance of ValueEntity.



3
4
5
6
7
8
# File 'lib/typeprof/core/env/value_entity.rb', line 3

def initialize
  @decls = Set.empty
  @defs = Set.empty
  @read_boxes = Set.empty
  @vtx = Vertex.new(self)
end

Instance Attribute Details

#declsObject (readonly)

Returns the value of attribute decls.



10
11
12
# File 'lib/typeprof/core/env/value_entity.rb', line 10

def decls
  @decls
end

#defsObject (readonly)

Returns the value of attribute defs.



10
11
12
# File 'lib/typeprof/core/env/value_entity.rb', line 10

def defs
  @defs
end

#read_boxesObject (readonly)

Returns the value of attribute read_boxes.



10
11
12
# File 'lib/typeprof/core/env/value_entity.rb', line 10

def read_boxes
  @read_boxes
end

#vtxObject (readonly)

Returns the value of attribute vtx.



10
11
12
# File 'lib/typeprof/core/env/value_entity.rb', line 10

def vtx
  @vtx
end

Instance Method Details

#add_decl(decl) ⇒ Object



12
13
14
# File 'lib/typeprof/core/env/value_entity.rb', line 12

def add_decl(decl)
  @decls << decl
end

#add_def(def_) ⇒ Object



28
29
30
# File 'lib/typeprof/core/env/value_entity.rb', line 28

def add_def(def_)
  @defs << def_
end

#exist?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/typeprof/core/env/value_entity.rb', line 36

def exist?
  !@decls.empty? || !@defs.empty?
end

#on_const_added(genv, cpath) ⇒ Object



40
41
42
43
44
45
# File 'lib/typeprof/core/env/value_entity.rb', line 40

def on_const_added(genv, cpath)
  unless exist?
    parent_mod = genv.resolve_cpath(cpath[0..-2])
    genv.add_static_eval_queue(:inner_modules_changed, [parent_mod, cpath[-1]])
  end
end

#on_const_removed(genv, cpath) ⇒ Object



47
48
49
50
51
52
# File 'lib/typeprof/core/env/value_entity.rb', line 47

def on_const_removed(genv, cpath)
  unless exist?
    parent_mod = genv.resolve_cpath(cpath[0..-2])
    genv.add_static_eval_queue(:inner_modules_changed, [parent_mod, cpath[-1]])
  end
end

#on_decl_changed(genv) ⇒ Object

Re-run all read boxes that depend on this entity. Used when a declaration is added or removed so that dependents (e.g. an IVarReadBox that previously fell back to the inferred type) can observe the new state.



24
25
26
# File 'lib/typeprof/core/env/value_entity.rb', line 24

def on_decl_changed(genv)
  @read_boxes.each {|box| genv.add_run(box) }
end

#remove_decl(decl) ⇒ Object



16
17
18
# File 'lib/typeprof/core/env/value_entity.rb', line 16

def remove_decl(decl)
  @decls.delete(decl) || raise
end

#remove_def(def_) ⇒ Object



32
33
34
# File 'lib/typeprof/core/env/value_entity.rb', line 32

def remove_def(def_)
  @defs.delete(def_) || raise
end