Update to RDoc 2.1.0 r112
[rbx.git] / tools / senders.rb
blob1c58ce7903ff453469dc9213f1671fc0435e65ee
1 #!/usr/bin/ruby -ws
3 $p ||= false
5 $: << File.expand_path("~/Work/p4/zss/src/ParseTree/dev/lib")
6 require 'parse_tree'
7 require 'sexp_processor'
9 class HashHash < Hash
10   def initialize
11     super { |h,k| h[k] = HashHash.new }
12   end
14   def + n
15     n # RAD cheat eliminating all ||= 0 (since I can't use ||= with HashHash)
16   end
17 end
19 class CallLogger < SexpProcessor
20   attr_reader :calls
21   attr_accessor :klass, :meth
23   def initialize
24     super
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
30     @calls = HashHash.new
31   end
33   def process_class(exp)
34     self.klass = exp.shift
35     superklass = process exp.shift
36     body       = process exp.shift
37     s()
38   end
40   def process_module(exp)
41     self.klass = exp.shift
42     body       = process exp.shift
43     self.klass = nil
44     s()
45   end
47   def process_defn(exp)
48     self.meth = exp.shift
49     body      = process exp.shift
50     self.meth = nil
51     s()
52   end
54   def process_defs(exp)
55     recv      = process exp.shift
56     self.meth = :"#{recv.first}.#{exp.shift}"
57     body      = process exp.shift
58     self.meth = nil
59     s()
60   end
62   def process_fcall(exp)
63     if klass and meth then
64       mesg = exp.shift
65       args = process exp.shift
66       calls[klass][meth][:fcall][mesg] += 1 unless $p
67     end
68     s()
69   end
71   def process_vcall(exp)
72     if klass and meth then
73       mesg = exp.shift
74       calls[klass][meth][:fcall][mesg] += 1 unless $p
75     end
76     s()
77   end
79   def process_call(exp)
80     recv = exp.shift
81     mesg = exp.shift
82     args = process exp.shift
84     type = case recv
85            when [:const, :Ruby] then
86              old_mesg, mesg = mesg, args.last.last
87              :primitive if old_mesg == :primitive
88            when [:self] then
89              :self unless $p
90            when [:call, [:self], :class] then
91              :class unless $p
92            end
94     calls[klass][meth][type][mesg] += 1 if type
96     s()
97   end
98 end
100 if ARGV.empty? then
101   %w(array hash string).each do |klass|
102     ARGV << "kernel/core/#{klass}.rb"
103     ARGV << "kernel/bootstrap/#{klass}.rb"
104   end
107 cl = CallLogger.new
108 pt = ParseTree.new(false)
110 ARGV.each do |path|
111   sexp = pt.parse_tree_for_string(File.read(path), path)
112   cl.process(sexp.first)
115 require 'yaml'
116 puts cl.calls.to_yaml.gsub(/ !map:HashHash/, '')