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_as_init
24 # This attribute is the ReachableAsInitAnalysis results
25 readable writable var _rai
: nullable ReachableAsInitAnalysis = null
27 # This method will create a file and output all inits reachable as init in it
28 fun dump_reachable_as_init_methods
(directory_name
: String) do
29 var f
= new OFStream.open
("{directory_name}/{main_module.name}.reachable_methods_as_init.log")
30 with_each_live_local_classes
!action
(c
) do
31 for g
in c
.global_properties
do
33 if not p
.global
.is_init_for
(c
) then continue
35 if rai
.is_method_reachable_as_init
(p
, c
) then
36 f
.write
("{p.full_name}\n")
44 # Subclasses of this class would represent an analysis that produces
45 # at least a way of knowing if an initializer is called at least once
46 # as an initializer (and not as part of another initializer)
48 class ReachableAsInitAnalysis
49 fun is_method_reachable_as_init
(method
: MMMethod, c
: MMLocalClass): Bool is abstract
52 # Default behavior is to say that all initializers are called as init
53 class DefaultReachableAsInitAnalysis
54 super ReachableAsInitAnalysis
55 redef fun is_method_reachable_as_init
(method
: MMMethod, c
: MMLocalClass): Bool do
56 if method
.global
.is_init
and method
.global
.is_init_for
(c
) then return true