1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2009 Jean-Sebastien Gelinas <calestar@gmail.com>
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 # Module containing all bases for the reachable from init method analysis
18 package reachable_from_init_method_analysis
22 import reachable_method_analysis
25 # This attribute is the ReachableFromInitMethodAnalysis results
26 readable writable var _rfima
: nullable ReachableFromInitMethodAnalysis = null
28 # This method will create a file and output the name of all methods reachable
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")
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")
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
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