rubyx-debugger/lib/views/source_view.rb

61 lines
1.6 KiB
Ruby
Raw Normal View History

require_relative "html_converter"
2015-10-29 15:49:14 +01:00
class SourceView < ElementView
def initialize interpreter
@interpreter = interpreter
@interpreter.register_event(:instruction_changed, self)
end
def draw
2015-11-01 17:11:38 +01:00
@text = div(".text")
@ticker = div(".ticker")
@element = div(".source_view") << div("h4.source" , "Class.Method") << @ticker << @text
2015-10-29 15:49:14 +01:00
@element
end
def instruction_changed
i = @interpreter.instruction
return "" unless i
update_method
2015-10-29 15:49:14 +01:00
case i.source
2018-04-03 17:24:57 +02:00
when Mom::Instruction
2018-04-06 12:03:39 +02:00
@ticker.text = i.source.class.name
# if e = @text.at_css("#i#{id}")
# if (old = @text.at_css(".fade_in"))
# old.remove_class("fade_in")
# end
# e.add_class "fade_in"
# end
2015-10-29 15:49:14 +01:00
when String
2015-10-29 15:53:46 +01:00
@ticker.text = i.source
2018-04-03 17:24:57 +02:00
when Risc::Instruction
2016-12-25 16:49:09 +01:00
@ticker.text = i.source.to_s
2015-10-29 15:49:14 +01:00
else
raise i.source.class.name
end
end
2015-11-01 12:03:03 +01:00
def update_method
i = @interpreter.instruction
if i.is_a?(Risc::FunctionReturn)
link = @interpreter.get_register( i.register )
2015-11-04 19:29:09 +01:00
#puts "Link #{link}"
raise "No link method" unless link
i = link
end
return unless (i.is_a? Risc::Label)
2016-12-25 16:49:09 +01:00
return unless i.is_method
puts i.name
cl_t_name , method_name = *i.name.split(".")
class_name = cl_t_name.split(" ").last.split("_").first
2018-04-03 17:24:57 +02:00
clazz = Parfait.object_space.get_class_by_name class_name
2016-12-25 16:49:09 +01:00
raise "No class for #{cl_name} , #{i.name}" unless clazz
type = clazz.instance_type
2018-04-03 17:24:57 +02:00
method = type.get_method( method_name )
2015-11-04 19:29:09 +01:00
@element.at_css(".source").text = i.name
@text.inner_html = HtmlConverter.new.process( method.source )
2015-10-29 18:10:02 +01:00
end
2015-10-29 15:49:14 +01:00
end