module TypeProf::Reporters

Public Instance Methods

filter_backtrace(trace) click to toggle source
# File typeprof-0.21.8/lib/typeprof/export.rb, line 20
def filter_backtrace(trace)
  ntrace = [trace.first]
  trace.each_cons(2) do |ep1, ep2|
    ntrace << ep2 if ep1.ctx != ep2.ctx
  end
  ntrace
end
generate_analysis_trace(state, visited, backward_edge) click to toggle source
# File typeprof-0.21.8/lib/typeprof/export.rb, line 5
def generate_analysis_trace(state, visited, backward_edge)
  return nil if visited[state]
  visited[state] = true
  prev_states = backward_edges[state]
  if prev_states
    prev_states.each_key do |pstate|
      trace = generate_analysis_trace(pstate, visited, backward_edge)
      return [state] + trace if trace
    end
    nil
  else
    []
  end
end
show_error(errors, backward_edge, output) click to toggle source
# File typeprof-0.21.8/lib/typeprof/export.rb, line 39
def show_error(errors, backward_edge, output)
  return if errors.empty?
  return unless Config.current.options[:show_errors]

  output.puts "# Errors"
  errors.each do |ep, msg|
    if ENV["TP_DETAIL"]
      backtrace = filter_backtrace(generate_analysis_trace(ep, {}, backward_edge))
    else
      backtrace = [ep]
    end
    loc, *backtrace = backtrace.map do |ep|
      ep&.source_location
    end
    output.puts "#{ loc }: #{ msg }"
    backtrace.each do |loc|
      output.puts "        from #{ loc }"
    end
  end
  output.puts
end
show_gvars(scratch, gvars, output) click to toggle source
# File typeprof-0.21.8/lib/typeprof/export.rb, line 71
def show_gvars(scratch, gvars, output)
  gvars = gvars.dump.filter_map do |gvar_name, entry|
    if entry.type != Type.bot && !entry.rbs_declared
      [gvar_name, entry]
    end
  end
  # A signature for global variables is not supported in RBS
  return if gvars.empty?

  output.puts "# Global variables"
  gvars.each do |gvar_name, entry|
    output.puts "#{ gvar_name }: #{ entry.type.screen_name(scratch) }"
  end
  output.puts
end
show_message(terminated, output) click to toggle source
# File typeprof-0.21.8/lib/typeprof/export.rb, line 28
def show_message(terminated, output)
  if Config.current.options[:show_typeprof_version]
    output.puts "# TypeProf #{ VERSION }"
    output.puts
  end
  if terminated
    output.puts "# CAUTION: Type profiling was terminated prematurely because of the limitation"
    output.puts
  end
end
show_reveal_types(scratch, reveal_types, output) click to toggle source
# File typeprof-0.21.8/lib/typeprof/export.rb, line 61
def show_reveal_types(scratch, reveal_types, output)
  return if reveal_types.empty?

  output.puts "# Revealed types"
  reveal_types.each do |source_location, ty|
    output.puts "#  #{ source_location } #=> #{ ty.screen_name(scratch) }"
  end
  output.puts
end