rubyx-debugger/app/register_view.rb

65 lines
1.5 KiB
Ruby
Raw Normal View History

2015-07-26 11:51:57 +02:00
2015-07-22 15:22:54 +02:00
class RegisterView
include React::Component
2015-07-23 19:08:40 +02:00
required_param :interpreter
2015-07-26 11:51:57 +02:00
required_param :register
define_state :objects_id
define_state :fields => []
before_mount do
interpreter.register_event(:register_changed, self)
2015-07-29 15:39:15 +02:00
interpreter.register_event(:object_changed, self)
2015-07-26 11:51:57 +02:00
register_changed( register , nil , interpreter.registers[register])
end
2015-07-26 11:51:57 +02:00
def register_changed reg , old , value
2015-07-29 15:39:15 +02:00
reg = reg.symbol unless reg.is_a? Symbol
2015-07-26 11:51:57 +02:00
return unless reg == register
objects_id! value
calc_fields
end
2015-07-22 15:22:54 +02:00
2015-07-29 15:39:15 +02:00
def object_changed reg
reg = reg.symbol unless reg.is_a? Symbol
return unless reg == register
2015-07-30 14:05:57 +02:00
#puts "Object changed in #{reg}"
2015-07-29 15:39:15 +02:00
calc_fields
end
2015-07-26 11:51:57 +02:00
def calc_fields
#puts "My id #{objects_id} , #{objects_id.class}"
2015-07-26 11:51:57 +02:00
object = Virtual.machine.objects[objects_id]
if object and ! object.is_a?(String)
has_fields = []
clazz = object.class.name.split("::").last
#puts "found #{clazz}"
has_fields << clazz
2015-07-26 11:51:57 +02:00
object.get_instance_variables.each do |variable|
f = object.get_instance_variable(variable)
has_fields << f
2015-07-22 15:22:54 +02:00
end
2015-07-26 11:51:57 +02:00
fields! has_fields
2015-07-22 15:22:54 +02:00
end
end
2015-07-25 20:04:20 +02:00
2015-07-26 11:51:57 +02:00
def render
div.register_view do
div do
2015-07-26 11:51:57 +02:00
objects_id.to_s
end
fields.each do |attribute|
2015-07-26 11:51:57 +02:00
div.col_md_12 do
"#{marker(attribute)} - #{attribute.object_id}".span
2015-07-26 11:51:57 +02:00
end
end
end
2015-07-25 20:04:20 +02:00
end
2015-07-26 11:51:57 +02:00
def marker var
2015-07-29 15:39:15 +02:00
return "W" if var.is_a? String
var.class.name.split("::").last[0]
end
2015-07-22 15:22:54 +02:00
end