class AdLint::Ld::FunctionCallGraph

Public Class Methods

new() click to toggle source
# File lib/adlint/ld/object.rb, line 567
def initialize
  @callee_index = Hash.new { |hash, key| hash[key] = Set.new }
end

Public Instance Methods

add(funcall) click to toggle source
# File lib/adlint/ld/object.rb, line 571
def add(funcall)
  @callee_index[funcall.callee].add(funcall)
end
all_callers_of(fun) click to toggle source
# File lib/adlint/ld/object.rb, line 575
def all_callers_of(fun)
  direct_callers_of(fun) + indirect_callers_of(fun)
end
direct_callers_of(fun) click to toggle source
# File lib/adlint/ld/object.rb, line 580
def direct_callers_of(fun)
  @callee_index[fun].map { |funcall| funcall.caller }.to_set
end
indirect_callers_of(fun) click to toggle source
# File lib/adlint/ld/object.rb, line 585
def indirect_callers_of(fun)
  direct_callers_of(fun).reduce(Set.new) do |res, ref|
    if fun = ref.function
      res + collect_callers_of(fun, res)
    else
      res
    end
  end
end

Private Instance Methods

collect_callers_of(fun, exclusions) click to toggle source
# File lib/adlint/ld/object.rb, line 597
def collect_callers_of(fun, exclusions)
  direct_callers_of(fun).reduce(Set.new) do |res, ref|
    case
    when exclusions.include?(ref)
      res.add(ref)
    when caller_fun = ref.function
      res.add(ref) + collect_callers_of(caller_fun, exclusions + res)
    else
      res.add(ref)
    end
  end
end