rubyx-debugger/lib/views/object_view.rb

76 lines
2.1 KiB
Ruby
Raw Normal View History

require_relative "ref_view"
class ObjectView < ListView
2015-10-04 21:39:02 +02:00
# z is the z-index
2015-08-23 02:16:32 +02:00
def initialize object_id , interpreter = nil , z = nil
@object_id = object_id
2015-08-23 02:16:32 +02:00
@z = z
@interpreter = interpreter
@interpreter.register_event(:object_changed, self) if interpreter
super( content_elements )
end
def draw
@element = super(@interpreter ? "ul.nav!" : "ul")
prepend_element div("li" , "-------------------------")
prepend_element div( "li" ) << div("span" , class_header(@object_id) )
2015-08-22 17:19:07 +02:00
return @element
2015-07-14 12:07:28 +02:00
end
def object_changed reg , at
2015-10-27 17:09:50 +01:00
puts "Object changed in #{reg} , at #{at}"
for_object = @interpreter.get_register( reg )
return unless for_object == @object_id
2015-10-04 21:39:02 +02:00
#puts "Object changed #{for_object} , at #{at}"
2015-10-27 11:44:02 +01:00
object = Register.machine.objects[@object_id]
2015-10-04 21:39:02 +02:00
raise "error #{@object_id} , #{at}" unless object and ! object.is_a?(String)
variable = object.get_instance_variables.get(at)
2015-10-22 13:44:37 +02:00
if(variable)
f = object.get_instance_variable(variable)
else
2015-10-27 17:09:50 +01:00
variable = (at - object.class.get_length_index).to_s
2015-10-22 13:44:37 +02:00
f = object.internal_object_get(at)
end
#puts "got var name #{variable}#{variable.class} for #{at}, #{f}"
2015-10-27 17:09:50 +01:00
view = RefView.new( variable , oid(f) , @z )
if( @children[at-1] )
replace_at(at-1 , view)
2015-10-22 13:44:37 +02:00
else
append_view(view)
end
end
def class_header(id)
2015-10-27 11:44:02 +01:00
object = Register.machine.objects[id]
clazz = object.class.name.split("::").last
[clazz, id].join " : "
end
def content_elements
2015-10-27 11:44:02 +01:00
object = Register.machine.objects[@object_id]
fields = []
if object and ! object.is_a?(String)
object.get_instance_variables.each do |variable|
f = object.get_instance_variable(variable)
2015-10-27 17:09:50 +01:00
fields << RefView.new( variable , oid(f) , @z )
end
2015-10-27 17:09:50 +01:00
if( object.is_a?(Parfait::Indexed) )
2015-08-25 11:54:44 +02:00
index = 1
2015-10-27 17:09:50 +01:00
object.each do | o|
puts "gett #{o}"
fields << RefView.new( index.to_s , oid(o) , @z )
2015-08-25 11:54:44 +02:00
index += 1
end
end
end
fields
end
2015-10-27 17:09:50 +01:00
def oid o
return o if o.is_a? Fixnum
return o.object_id
end
end