2015-10-22 17:16:29 +02:00
|
|
|
module Register
|
2015-05-31 10:07:49 +02:00
|
|
|
|
2015-05-31 12:02:29 +02:00
|
|
|
# collect anything that is in the space but and reachable from init
|
2015-10-18 18:27:02 +02:00
|
|
|
module Collector
|
|
|
|
def collect
|
|
|
|
self.objects.clear
|
2015-07-30 18:18:41 +02:00
|
|
|
keep Parfait::Space.object_space , 0
|
2015-10-28 12:00:23 +01:00
|
|
|
constants.each {|o| keep(o,0)}
|
2015-05-31 10:07:49 +02:00
|
|
|
end
|
|
|
|
|
2015-07-30 18:18:41 +02:00
|
|
|
def keep object , depth
|
2015-05-31 12:02:29 +02:00
|
|
|
return if object.nil?
|
2015-07-30 18:18:41 +02:00
|
|
|
#puts "adding #{' ' * depth}:#{object.class}"
|
|
|
|
#puts "ADD #{object.first.class}, #{object.last.class}" if object.is_a? Array
|
2015-10-18 18:27:02 +02:00
|
|
|
return unless self.add_object object
|
2015-11-03 10:22:26 +01:00
|
|
|
# probably should make labels or even instructions derive from Parfait::Object, but . .
|
|
|
|
if object.is_a? Register::Label
|
|
|
|
object.each_label { |l| self.add_object(l)}
|
|
|
|
end
|
2015-07-21 14:40:25 +02:00
|
|
|
return unless object.respond_to? :has_layout?
|
2015-05-31 12:02:29 +02:00
|
|
|
layout = object.get_layout
|
2015-07-30 18:18:41 +02:00
|
|
|
keep(layout , depth + 1)
|
2015-10-26 11:23:52 +01:00
|
|
|
return if object.is_a? Symbol
|
2015-10-26 11:58:38 +01:00
|
|
|
layout.instance_names.each do |name|
|
2015-10-26 11:23:52 +01:00
|
|
|
#puts "Keep #{name} for #{object.class}"
|
2015-07-21 18:41:30 +02:00
|
|
|
inst = object.get_instance_variable name
|
2015-07-30 18:18:41 +02:00
|
|
|
keep(inst , depth + 1)
|
2015-05-31 10:07:49 +02:00
|
|
|
end
|
2015-10-25 18:16:12 +01:00
|
|
|
if object.is_a? Parfait::Indexed
|
2015-05-31 10:07:49 +02:00
|
|
|
object.each do |item|
|
2015-08-06 17:27:25 +02:00
|
|
|
#puts "Keep item "
|
2015-07-30 18:18:41 +02:00
|
|
|
keep(item , depth + 1)
|
2015-05-31 10:07:49 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|