rta: use callsites to do the analysis
[nit.git] / src / collect_super_sends.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Collect super sends
16 module collect_super_sends
17
18 import modelbuilder
19 private import modelize_property
20 private import typing
21
22 private class CollectSuperSends
23 super Visitor
24 var modelbuilder: ModelBuilder
25 var res = new ArraySet[MMethodDef]
26 var mpropdef: nullable MMethodDef
27
28 # Get a new visitor on a classef to add type count in `typecount`.
29 init(modelbuilder: ModelBuilder)
30 do
31 self.modelbuilder = modelbuilder
32 end
33
34 redef fun visit(n)
35 do
36 if n isa AMethPropdef then
37 assert mpropdef == null
38 mpropdef = n.mpropdef
39 n.visit_all(self)
40 mpropdef = null
41 return
42 end
43 n.visit_all(self)
44 if n isa ASuperExpr and n.callsite == null then
45 var mprop = mpropdef
46 assert mprop != null
47 res.add(mprop)
48 end
49 end
50 end
51
52 redef class ModelBuilder
53 # Visit the AST and return all method definitions that performs a `super`.
54 fun collect_super_sends: Set[MMethodDef]
55 do
56 var visitor = new CollectSuperSends(self)
57
58 # Visit all the source code to collect data
59 for nmodule in self.nmodules do
60 visitor.enter_visit(nmodule)
61 end
62
63 return visitor.res
64 end
65 end