doc: use 'module' instead of 'package' in comments
[nit.git] / src / analysis / reachable_from_init_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 from init method analysis
18 package reachable_from_init_method_analysis
19
20 import icode
21 import program
22 import reachable_method_analysis
23
24 redef class Program
25 # This attribute is the ReachableFromInitMethodAnalysis results
26 readable writable var _rfima: nullable ReachableFromInitMethodAnalysis = null
27
28 # This method will create a file and output the name of all methods reachable
29 # from an init in it
30 fun dump_reachable_methods_from_init(directory_name: String) do
31 var f = new OFStream.open("{directory_name}/{main_module.name}.reachable_methods_from_init.log")
32 with_each_methods !action(m) do
33 if rfima.is_method_reachable_from_init(m) then
34 f.write("{m.full_name}\n")
35 end
36 end
37 f.close
38 end
39
40 # This method will create a file and output the name of all reachable methods that
41 # can not be reached from an init in it
42 fun dump_unreachable_methods_from_init(directory_name: String) do
43 var f = new OFStream.open("{directory_name}/{main_module.name}.unreachable_methods_from_init.log")
44 with_each_methods !action(m) do
45 if not rfima.is_method_reachable_from_init(m) and rma.is_method_reachable(m) then
46 f.write("{m.full_name}\n")
47 end
48 end
49 f.close
50 end
51 end
52
53 # Subclasses of this class would represent an analysis that produces
54 # at least a way of knowing if a property is reachable from at least
55 # one init in the program
56 class ReachableFromInitMethodAnalysis
57 fun is_iroutine_reachable_from_init(ir: nullable IRoutine): Bool is abstract
58 fun is_method_reachable_from_init(method: MMMethod): Bool is abstract
59 end
60
61 # Default behavior is to say that all methods/iroutines are reachable
62 # from at least one init
63 class DefaultReachableFromInitMethodAnalysis
64 special ReachableFromInitMethodAnalysis
65 redef fun is_iroutine_reachable_from_init(ir: nullable IRoutine): Bool do return true
66 redef fun is_method_reachable_from_init(method: MMMethod): Bool do return true
67
68 init do end
69 end