analysis: add an analysis to know if a method/iroutine is reachable from an init
authorJean-Sebastien Gelinas <calestar@gmail.com>
Wed, 21 Oct 2009 19:13:40 +0000 (15:13 -0400)
committerJean Privat <jean@pryen.org>
Mon, 11 Jan 2010 21:52:31 +0000 (16:52 -0500)
Signed-off-by: Jean-Sebastien Gelinas <calestar@gmail.com>
Signed-off-by: Jean Privat <jean@pryen.org>

src/analysis/analysis.nit
src/analysis/reachable_from_init_method_analysis.nit [new file with mode: 0644]

index 45af7fd..881cfec 100644 (file)
@@ -31,6 +31,7 @@ import inline_methods
 import instantiated_type_analysis
 import reachable_method_analysis
 import reachable_as_init
+import reachable_from_init_method_analysis
 
 # Global Analysis implementation
 import cha_analysis
@@ -70,7 +71,10 @@ redef class Program
                var rai_builder = new ReachableAsInitBuilder(self)
                rai_builder.work
                rai = rai_builder.context
+
+               rfima = new DefaultReachableFromInitMethodAnalysis
        end
+
        # This method will optimize the program (in global compilation only)
        # Those are done before analysis
        fun do_global_pre_analysis_optimizations do
diff --git a/src/analysis/reachable_from_init_method_analysis.nit b/src/analysis/reachable_from_init_method_analysis.nit
new file mode 100644 (file)
index 0000000..ae055d6
--- /dev/null
@@ -0,0 +1,45 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2009 Jean-Sebastien Gelinas <calestar@gmail.com>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Package containing all bases for the reachable from init method analysis
+package reachable_from_init_method_analysis
+
+import icode
+import program
+import reachable_method_analysis
+
+redef class Program
+       # This attribute is the ReachableFromInitMethodAnalysis results
+       readable writable var _rfima: nullable ReachableFromInitMethodAnalysis = null
+end
+
+# Subclasses of this class would represent an analysis that produces
+# at least a way of knowing if a property is reachable from at least
+# one init in the program
+class ReachableFromInitMethodAnalysis
+       fun is_iroutine_reachable_from_init(ir: nullable IRoutine): Bool is abstract
+       fun is_method_reachable_from_init(method: MMMethod): Bool is abstract
+end
+
+# Default behavior is to say that all methods/iroutines are reachable
+# from at least one init
+class DefaultReachableFromInitMethodAnalysis
+special ReachableFromInitMethodAnalysis
+       redef fun is_iroutine_reachable_from_init(ir: nullable IRoutine): Bool do return true
+       redef fun is_method_reachable_from_init(method: MMMethod): Bool do return true
+
+       init do end
+end