Class: TypeProf::Core::Box

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Box

Returns a new instance of Box.



4
5
6
7
8
9
10
# File 'lib/typeprof/core/graph/box.rb', line 4

def initialize(node)
  @node = node
  @changes = ChangeSet.new(node, self)
  @destroyed = false
  $box_counts[Box] += 1
  $box_counts[self.class] += 1
end

Instance Attribute Details

#changesObject (readonly)

Returns the value of attribute changes.



12
13
14
# File 'lib/typeprof/core/graph/box.rb', line 12

def changes
  @changes
end

#destroyedObject (readonly)

Returns the value of attribute destroyed.



14
15
16
# File 'lib/typeprof/core/graph/box.rb', line 14

def destroyed
  @destroyed
end

#nodeObject (readonly)

Returns the value of attribute node.



14
15
16
# File 'lib/typeprof/core/graph/box.rb', line 14

def node
  @node
end

Instance Method Details

#destroy(genv) ⇒ Object



16
17
18
19
20
21
# File 'lib/typeprof/core/graph/box.rb', line 16

def destroy(genv)
  $box_counts[self.class] -= 1
  $box_counts[Box] -= 1
  @destroyed = true
  @changes.reinstall(genv) # rollback all changes
end

#diagnostics(genv, &blk) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/typeprof/core/graph/box.rb', line 42

def diagnostics(genv, &blk)
  raise self.to_s if !@changes
  @changes.diagnostics.each(&blk)
  @changes.boxes.each_value do |box|
    box.diagnostics(genv, &blk)
  end
end

#on_type_added(genv, src_tyvar, added_types) ⇒ Object



28
29
30
# File 'lib/typeprof/core/graph/box.rb', line 28

def on_type_added(genv, src_tyvar, added_types)
  genv.add_run(self)
end

#on_type_removed(genv, src_tyvar, removed_types) ⇒ Object



32
33
34
# File 'lib/typeprof/core/graph/box.rb', line 32

def on_type_removed(genv, src_tyvar, removed_types)
  genv.add_run(self)
end

#reuse(new_node) ⇒ Object



23
24
25
26
# File 'lib/typeprof/core/graph/box.rb', line 23

def reuse(new_node)
  @node = new_node
  @changes.reuse(new_node)
end

#run(genv) ⇒ Object



36
37
38
39
40
# File 'lib/typeprof/core/graph/box.rb', line 36

def run(genv)
  return if @destroyed
  run0(genv, @changes)
  @changes.reinstall(genv)
end

#to_sObject Also known as: inspect

@@new_id = 0



52
53
54
# File 'lib/typeprof/core/graph/box.rb', line 52

def to_s
  "#{ self.class.to_s.split("::").last[0] }#{ @id ||= $new_id += 1 }"
end