5 $: << File.expand_path("~/Work/p4/zss/src/ParseTree/dev/lib")
7 require 'sexp_processor'
11 super { |h,k| h[k] = HashHash.new }
15 n # RAD cheat eliminating all ||= 0 (since I can't use ||= with HashHash)
19 class CallLogger < SexpProcessor
21 attr_accessor :klass, :meth
25 self.unsupported.delete :newline
26 self.require_empty = false
27 self.auto_shift_type = true
29 # @calls[klass][meth][call_type][called_method] = count
33 def process_class(exp)
34 self.klass = exp.shift
35 superklass = process exp.shift
36 body = process exp.shift
40 def process_module(exp)
41 self.klass = exp.shift
42 body = process exp.shift
49 body = process exp.shift
55 recv = process exp.shift
56 self.meth = :"#{recv.first}.#{exp.shift}"
57 body = process exp.shift
62 def process_fcall(exp)
63 if klass and meth then
65 args = process exp.shift
66 calls[klass][meth][:fcall][mesg] += 1 unless $p
71 def process_vcall(exp)
72 if klass and meth then
74 calls[klass][meth][:fcall][mesg] += 1 unless $p
82 args = process exp.shift
85 when [:const, :Ruby] then
86 old_mesg, mesg = mesg, args.last.last
87 :primitive if old_mesg == :primitive
90 when [:call, [:self], :class] then
94 calls[klass][meth][type][mesg] += 1 if type
101 %w(array hash string).each do |klass|
102 ARGV << "kernel/core/#{klass}.rb"
103 ARGV << "kernel/bootstrap/#{klass}.rb"
108 pt = ParseTree.new(false)
111 sexp = pt.parse_tree_for_string(File.read(path), path)
112 cl.process(sexp.first)
116 puts cl.calls.to_yaml.gsub(/ !map:HashHash/, '')