class DEBUGGER__::SourceRepository

Constants

SrcInfo

Public Class Methods

new() click to toggle source
# File debug-1.4.0/lib/debug/source_repository.rb, line 9
def initialize
  @files = {} # filename => SrcInfo
end

Public Instance Methods

add(iseq, src) click to toggle source
# File debug-1.4.0/lib/debug/source_repository.rb, line 13
def add iseq, src
  if (path = iseq.absolute_path) && File.exist?(path)
    add_path path
  elsif src
    add_iseq iseq, src
  end
end
all_iseq(iseq, rs = []) click to toggle source
# File debug-1.4.0/lib/debug/source_repository.rb, line 21
def all_iseq iseq, rs = []
  rs << iseq
  iseq.each_child{|ci|
    all_iseq(ci, rs)
  }
  rs
end
get(iseq) click to toggle source
# File debug-1.4.0/lib/debug/source_repository.rb, line 61
def get iseq
  if si = get_si(iseq)
    si.src
  end
end
get_colored(iseq) click to toggle source
# File debug-1.4.0/lib/debug/source_repository.rb, line 69
def get_colored iseq
  if si = get_si(iseq)
    si.colored || begin
      si.colored = colorize_code(si.src.join).lines
    end
  end
end

Private Instance Methods

add_iseq(iseq, src) click to toggle source
# File debug-1.4.0/lib/debug/source_repository.rb, line 29
        def add_iseq iseq, src
  line = iseq.first_line
  if line > 1
    src = ("\n" * (line - 1)) + src
  end
  si = SrcInfo.new(src.lines)

  all_iseq(iseq).each{|e|
    e.instance_variable_set(:@debugger_si, si)
    e.freeze
  }
end
add_path(path) click to toggle source
# File debug-1.4.0/lib/debug/source_repository.rb, line 42
        def add_path path
  src = File.read(path)
  src = src.gsub("\r\n", "\n") # CRLF -> LF
  @files[path] = SrcInfo.new(src.lines)
rescue SystemCallError
end
get_si(iseq) click to toggle source
# File debug-1.4.0/lib/debug/source_repository.rb, line 49
        def get_si iseq
  return unless iseq

  if iseq.instance_variable_defined?(:@debugger_si)
    iseq.instance_variable_get(:@debugger_si)
  elsif @files.has_key?(path = iseq.absolute_path)
    @files[path]
  elsif path
    add_path(path)
  end
end