class AdLint::Ld::FunctionCallGraphBuilder

Attributes

graph[R]

Public Class Methods

new(fun_map) click to toggle source
# File lib/adlint/ld/object.rb, line 613
def initialize(fun_map)
  @fun_map = fun_map
  @graph = FunctionCallGraph.new
end

Public Instance Methods

execute(met_fpath) click to toggle source
# File lib/adlint/ld/object.rb, line 620
def execute(met_fpath)
  sma_wd = Pathname.pwd
  CSV.foreach(met_fpath) do |csv_row|
    if rec = MetricRecord.of(csv_row, sma_wd)
      case
      when rec.version?
        sma_wd = Pathname.new(rec.exec_working_directory)
      when rec.function_call?
        caller_ref, callee_fun = lookup_functions_by_call(rec)
        if caller_ref && callee_fun
          @graph.add(FunctionCall.new(caller_ref, callee_fun))
        end
      end
    end
  end
end

Private Instance Methods

lookup_functions_by_call(funcall_rec) click to toggle source
# File lib/adlint/ld/object.rb, line 638
def lookup_functions_by_call(funcall_rec)
  caller_fun = @fun_map.lookup_functions(
    funcall_rec.caller_function.name).find { |fun|
      fun.location.fpath == funcall_rec.location.fpath
    }
  if caller_fun
    caller_ref = ObjectReferrer.of_function(caller_fun)
  else
    return nil, nil
  end

  callee_funs = @fun_map.lookup_functions(funcall_rec.callee_function.name)

  callee_fun = callee_funs.first
  callee_funs.each do |fun|
    if fun.location.fpath == caller_ref.location.fpath
      callee_fun = fun
      break
    end
  end

  return caller_ref, callee_fun
end