doc: use 'module' instead of 'package' in comments
[nit.git] / src / analysis / reachable_method_analysis.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2009 Jean-Sebastien Gelinas <calestar@gmail.com>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Module containing all bases for the reachable method analysis
18 package reachable_method_analysis
19
20 import icode
21 import program
22
23 redef class Program
24 # This attribute is the ReachableMethodAnalysis results
25 readable writable var _rma: nullable ReachableMethodAnalysis = null
26
27 # This method will create a file and output all reachable method names in it
28 fun dump_reachable_methods(directory_name: String, algo: String) do
29 var f = new OFStream.open("{directory_name}/{main_module.name}.reachable_methods.{algo}.log")
30 with_each_methods !action(m) do
31 if rma.is_method_reachable(m) then
32 f.write("{m.full_name}\n")
33 end
34 end
35 f.close
36 end
37
38 # This method will create a file and output all unreachable method names in it
39 fun dump_unreachable_methods(directory_name: String, algo: String) do
40 var f = new OFStream.open("{directory_name}/{main_module.name}.unreachable_methods.{algo}.log")
41 with_each_methods !action(m) do
42 if not rma.is_method_reachable(m) then
43 f.write("{m.full_name}\n")
44 end
45 end
46 f.close
47 end
48 end
49
50 # Subclasses of this class would represent an analysis that produces
51 # at least a way of knowing if a property is reachable from the entry
52 # point of the program
53 class ReachableMethodAnalysis
54 fun is_iroutine_reachable(ir: nullable IRoutine): Bool is abstract
55 fun is_method_reachable(method: MMMethod): Bool is abstract
56 end
57
58 # Default behavior is to say that all methods/iroutines are reachable
59 class DefaultReachableMethodAnalysis
60 special ReachableMethodAnalysis
61 redef fun is_iroutine_reachable(ir: nullable IRoutine): Bool do return true
62 redef fun is_method_reachable(method: MMMethod): Bool do return true
63
64 init do end
65 end