Class: TypeProf::Core::Box
- Inherits:
-
Object
- Object
- TypeProf::Core::Box
- Defined in:
- lib/typeprof/core/graph/box.rb
Direct Known Subclasses
CVarReadBox, ConstReadBox, EscapeBox, GVarReadBox, HashSplatBox, IVarReadBox, InstanceTypeBox, KeywordMergeBox, MAsgnBox, MethodAliasBox, MethodCallBox, MethodDeclBox, MethodDefBox, SplatBox, TypeReadBox
Instance Attribute Summary collapse
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#destroyed ⇒ Object
readonly
Returns the value of attribute destroyed.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
- #add_symbol_proc_call_box(_changes, genv, sym, caller_positionals, caller_keywords = nil) ⇒ Object
- #destroy(genv) ⇒ Object
- #destroy_symbol_proc_call_boxes(genv) ⇒ Object
-
#initialize(node) ⇒ Box
constructor
A new instance of Box.
- #on_type_added(genv, src_tyvar, added_types) ⇒ Object
- #on_type_removed(genv, src_tyvar, removed_types) ⇒ Object
- #reuse(new_node) ⇒ Object
- #run(genv) ⇒ Object
- #run0(genv, changes) ⇒ Object
- #to_s ⇒ Object (also: #inspect)
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
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
12 13 14 |
# File 'lib/typeprof/core/graph/box.rb', line 12 def changes @changes end |
#destroyed ⇒ Object (readonly)
Returns the value of attribute destroyed.
14 15 16 |
# File 'lib/typeprof/core/graph/box.rb', line 14 def destroyed @destroyed end |
#node ⇒ Object (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
#add_symbol_proc_call_box(_changes, genv, sym, caller_positionals, caller_keywords = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/typeprof/core/graph/box.rb', line 47 def add_symbol_proc_call_box(_changes, genv, sym, caller_positionals, caller_keywords = nil) return if caller_positionals.empty? recv = caller_positionals.first positionals = caller_positionals[1..] @symbol_proc_call_boxes ||= {} @symbol_proc_call_boxes[[recv, sym, *positionals, caller_keywords]] ||= begin a_args = ActualArguments.new(positionals, ::Array.new(positionals.size, false), caller_keywords, nil) MethodCallBox.new(@node, genv, recv, sym, a_args, false) end end |
#destroy(genv) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/typeprof/core/graph/box.rb', line 16 def destroy(genv) $box_counts[self.class] -= 1 $box_counts[Box] -= 1 @destroyed = true destroy_symbol_proc_call_boxes(genv) @changes.reinstall(genv) # rollback all changes end |
#destroy_symbol_proc_call_boxes(genv) ⇒ Object
59 60 61 62 63 |
# File 'lib/typeprof/core/graph/box.rb', line 59 def destroy_symbol_proc_call_boxes(genv) return unless @symbol_proc_call_boxes @symbol_proc_call_boxes.each_value { |box| box.destroy(genv) } @symbol_proc_call_boxes = nil end |
#on_type_added(genv, src_tyvar, added_types) ⇒ Object
29 30 31 |
# File 'lib/typeprof/core/graph/box.rb', line 29 def on_type_added(genv, src_tyvar, added_types) genv.add_run(self) end |
#on_type_removed(genv, src_tyvar, removed_types) ⇒ Object
33 34 35 |
# File 'lib/typeprof/core/graph/box.rb', line 33 def on_type_removed(genv, src_tyvar, removed_types) genv.add_run(self) end |
#reuse(new_node) ⇒ Object
24 25 26 27 |
# File 'lib/typeprof/core/graph/box.rb', line 24 def reuse(new_node) @node = new_node @changes.reuse(new_node) end |
#run(genv) ⇒ Object
37 38 39 40 41 |
# File 'lib/typeprof/core/graph/box.rb', line 37 def run(genv) return if @destroyed run0(genv, @changes) @changes.reinstall(genv) end |
#run0(genv, changes) ⇒ Object
43 44 45 |
# File 'lib/typeprof/core/graph/box.rb', line 43 def run0(genv, changes) raise NotImplementedError end |
#to_s ⇒ Object Also known as: inspect
65 66 67 |
# File 'lib/typeprof/core/graph/box.rb', line 65 def to_s "#{ self.class.to_s.split("::").last }#{ @id ||= $new_id += 1 }" end |