In Files

  • typeprof-0.12.0/lib/typeprof.rb
  • typeprof-0.12.0/lib/typeprof/analyzer.rb
  • typeprof-0.12.0/lib/typeprof/arguments.rb
  • typeprof-0.12.0/lib/typeprof/block.rb
  • typeprof-0.12.0/lib/typeprof/builtin.rb
  • typeprof-0.12.0/lib/typeprof/cli.rb
  • typeprof-0.12.0/lib/typeprof/config.rb
  • typeprof-0.12.0/lib/typeprof/container-type.rb
  • typeprof-0.12.0/lib/typeprof/export.rb
  • typeprof-0.12.0/lib/typeprof/import.rb
  • typeprof-0.12.0/lib/typeprof/insns-def.rb
  • typeprof-0.12.0/lib/typeprof/iseq.rb
  • typeprof-0.12.0/lib/typeprof/method.rb
  • typeprof-0.12.0/lib/typeprof/type.rb
  • typeprof-0.12.0/lib/typeprof/utils.rb
  • typeprof-0.12.0/lib/typeprof/version.rb

Class/Module Index [+]

Quicksearch

TypeProf

Public Class Methods

analyze(config) click to toggle source
 
               # File typeprof-0.12.0/lib/typeprof/config.rb, line 63
def self.analyze(config)
  # Deploy the config to the TypeProf::Config (Note: This is thread unsafe)
  if TypeProf.const_defined?(:Config)
    TypeProf.send(:remove_const, :Config)
  end
  TypeProf.const_set(:Config, config)

  if Config.options[:stackprof]
    require "stackprof"
    out = "typeprof-stackprof-#{ Config.options[:stackprof] }.dump"
    StackProf.start(mode: Config.options[:stackprof], out: out, raw: true)
  end

  scratch = Scratch.new
  Builtin.setup_initial_global_env(scratch)

  Config.gem_rbs_features.each do |feature|
    Import.import_library(scratch, feature)
  end

  prologue_ctx = Context.new(nil, nil, nil)
  prologue_ep = ExecutionPoint.new(prologue_ctx, -1, nil)
  prologue_env = Env.new(StaticEnv.new(Type.bot, Type.nil, false, true), [], [], Utils::HashWrapper.new({}))

  Config.rb_files.each do |rb|
    if rb.is_a?(Array) # [String name, String content]
      iseq = ISeq.compile_str(*rb.reverse)
    else
      iseq = ISeq.compile(rb)
    end
    ep, env = TypeProf.starting_state(iseq)
    scratch.merge_env(ep, env)
    scratch.add_callsite!(ep.ctx, prologue_ep, prologue_env) {|ty, ep| }
  end

  rbs_files = []
  rbs_codes = []
  Config.rbs_files.each do |rbs|
    if rbs.is_a?(Array) # [String name, String content]
      rbs_codes << rbs
    else
      rbs_files << rbs
    end
  end
  Import.import_rbs_files(scratch, rbs_files)
  rbs_codes.each do |name, content|
    Import.import_rbs_code(scratch, name, content)
  end

  result = scratch.type_profile

  if Config.output.respond_to?(:write)
    scratch.report(result, Config.output)
  else
    open(Config.output, "w") do |output|
      scratch.report(result, output)
    end
  end

rescue TypeProfError => exc
  exc.report(Config.output)

ensure
  if Config.options[:stackprof] && defined?(StackProf)
    StackProf.stop
    StackProf.results
  end
end
            
starting_state(iseq) click to toggle source
 
               # File typeprof-0.12.0/lib/typeprof/config.rb, line 132
def self.starting_state(iseq)
  cref = CRef.new(:bottom, Type::Builtin[:obj], false) # object
  recv = Type::Instance.new(Type::Builtin[:obj])
  ctx = Context.new(iseq, cref, nil)
  ep = ExecutionPoint.new(ctx, 0, nil)
  locals = [Type.nil] * iseq.locals.size
  env = Env.new(StaticEnv.new(recv, Type.nil, false, false), locals, [], Utils::HashWrapper.new({}))

  return ep, env
end