Class: AdLint::Ld::FunctionCallGraph

Inherits:
Object
  • Object
show all
Defined in:
lib/adlint/ld/object.rb

Instance Method Summary collapse

Constructor Details

#initializeFunctionCallGraph

Returns a new instance of FunctionCallGraph.



567
568
569
# File 'lib/adlint/ld/object.rb', line 567

def initialize
  @callee_index = Hash.new { |hash, key| hash[key] = Set.new }
end

Instance Method Details

#add(funcall) ⇒ Object



571
572
573
# File 'lib/adlint/ld/object.rb', line 571

def add(funcall)
  @callee_index[funcall.callee].add(funcall)
end

#all_callers_of(fun) ⇒ Object



575
576
577
# 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) ⇒ Object



580
581
582
# 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) ⇒ Object



585
586
587
588
589
590
591
592
593
# 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