nitg: new module `collect_super_sends` to use when RTA is disabled
authorJean Privat <jean@pryen.org>
Tue, 11 Feb 2014 16:07:00 +0000 (11:07 -0500)
committerJean Privat <jean@pryen.org>
Wed, 12 Feb 2014 15:05:49 +0000 (10:05 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/collect_super_sends.nit [new file with mode: 0644]
src/separate_compiler.nit

diff --git a/src/collect_super_sends.nit b/src/collect_super_sends.nit
new file mode 100644 (file)
index 0000000..9e6f9b0
--- /dev/null
@@ -0,0 +1,65 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# 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.
+
+# Collect super sends
+module collect_super_sends
+
+import modelbuilder
+private import modelize_property
+private import typing
+
+private class CollectSuperSends
+       super Visitor
+       var modelbuilder: ModelBuilder
+       var res = new ArraySet[MMethodDef]
+       var mpropdef: nullable MMethodDef
+
+       # Get a new visitor on a classef to add type count in `typecount`.
+       init(modelbuilder: ModelBuilder)
+       do
+               self.modelbuilder = modelbuilder
+       end
+
+       redef fun visit(n)
+       do
+               if n isa AMethPropdef then
+                       assert mpropdef == null
+                       mpropdef = n.mpropdef
+                       n.visit_all(self)
+                       mpropdef = null
+                       return
+               end
+               n.visit_all(self)
+               if n isa ASuperExpr and n.mproperty == null then
+                       var mprop = mpropdef
+                       assert mprop != null
+                       res.add(mprop)
+               end
+       end
+end
+
+redef class ModelBuilder
+       # Visit the AST and return all method definitions that performs a `super`.
+       fun collect_super_sends: Set[MMethodDef]
+       do
+               var visitor = new CollectSuperSends(self)
+
+               # Visit all the source code to collect data
+               for nmodule in self.nmodules do
+                       visitor.enter_visit(nmodule)
+               end
+
+               return visitor.res
+       end
+end
index 666dfd4..e553259 100644 (file)
@@ -18,6 +18,7 @@ module separate_compiler
 import abstract_compiler
 import layout_builders
 import rapid_type_analysis
+import collect_super_sends
 
 # Add separate compiler specific options
 redef class ToolContext
@@ -270,7 +271,12 @@ class SeparateCompiler
                end
 
                # lookup super calls and add it to the list of mmethods to build layout with
-               var super_calls = runtime_type_analysis.live_super_sends
+               var super_calls
+               if runtime_type_analysis != null then
+                       super_calls = runtime_type_analysis.live_super_sends
+               else
+                       super_calls = modelbuilder.collect_super_sends
+               end
                for mmethoddef in super_calls do
                        var mclass = mmethoddef.mclassdef.mclass
                        mmethods[mclass].add(mmethoddef)