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 method analysis
18 package reachable_method_analysis
24 # This attribute is the ReachableMethodAnalysis results
25 readable writable var _rma
: nullable ReachableMethodAnalysis = null
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")
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")
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 interface ReachableMethodAnalysis
54 fun is_iroutine_reachable
(ir
: nullable IRoutine): Bool is abstract
55 fun is_method_reachable
(method
: MMMethod): Bool is abstract
58 # Default behavior is to say that all methods/iroutines are reachable
59 class DefaultReachableMethodAnalysis
60 super 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