Merge branch 'annotations'
authorJean Privat <jean@pryen.org>
Sat, 27 Jul 2013 01:09:45 +0000 (21:09 -0400)
committerJean Privat <jean@pryen.org>
Sat, 27 Jul 2013 01:09:45 +0000 (21:09 -0400)
src/model/model.nit
src/model/model_base.nit
src/modelbuilder.nit
src/more_collections.nit [new file with mode: 0644]
src/naive_interpreter.nit
src/rapid_type_analysis.nit

index 3d6440b..80d643f 100644 (file)
@@ -32,6 +32,7 @@ module model
 import poset
 import location
 import model_base
+private import more_collections
 
 redef class Model
        # All known classes
@@ -750,8 +751,6 @@ abstract class MType
 
        # Return the nullable version of the type
        # If the type is already nullable then self is returned
-       #
-       # FIXME: DO NOT WORK YET
        fun as_nullable: MType
        do
                var res = self.as_nullable_cache
@@ -1142,7 +1141,6 @@ class MParameterType
 end
 
 # A type prefixed with "nullable"
-# FIXME Stub implementation
 class MNullableType
        super MType
 
@@ -1661,8 +1659,6 @@ abstract class MPropDef
        #
        # This method is used to determine what method is called by a super.
        #
-       # FIXME: IMPLEMENTED AS A static designation, it is ugly
-       #
        # REQUIRE: not mtype.need_anchor
        fun lookup_next_definition(mmodule: MModule, mtype: MType): MPROPDEF
        do
index 834a731..b2483d9 100644 (file)
@@ -18,76 +18,7 @@ module model_base
 
 import poset
 import location
-
-# Simple way to store an HashMap[K, Array[V]]
-# FIXME: this should move to its own module
-class MultiHashMap[K: Object, V]
-       super HashMap[K, Array[V]]
-
-       # Add `v' to the array associated with `k'.
-       # If there is no array associated, then create it.
-       fun add_one(k: K, v: V)
-       do
-               if self.has_key(k) then
-                       self[k].add(v)
-               else
-                       self[k] = [v]
-               end
-       end
-
-       init do end
-end
-
-# Simple way to store an HashMap[K1, HashMap[K2, V]]
-# FIXME: this should move to its own module
-class HashMap2[K1: Object, K2: Object, V]
-       private var level1: HashMap[K1, HashMap[K2, V]] = new HashMap[K1, HashMap[K2, V]]
-       fun [](k1: K1, k2: K2): nullable V
-       do
-               var level1 = self.level1
-               if not level1.has_key(k1) then return null
-               var level2 = level1[k1]
-               if not level2.has_key(k2) then return null
-               return level2[k2]
-       end
-       fun []=(k1: K1, k2: K2, v: V)
-       do
-               var level1 = self.level1
-               var level2: HashMap[K2, V]
-               if not level1.has_key(k1) then
-                       level2 = new HashMap[K2, V]
-                       level1[k1] = level2
-               else
-                       level2 = level1[k1]
-               end
-               level2[k2] = v
-       end
-end
-
-# Simple way to store an HashMap[K1, HashMap[K2, HashMap[K3, V]]]
-# FIXME: this should move to its own module
-class HashMap3[K1: Object, K2: Object, K3: Object, V]
-       private var level1: HashMap[K1, HashMap2[K2, K3, V]] = new HashMap[K1, HashMap2[K2, K3, V]]
-       fun [](k1: K1, k2: K2, k3: K3): nullable V
-       do
-               var level1 = self.level1
-               if not level1.has_key(k1) then return null
-               var level2 = level1[k1]
-               return level2[k2, k3]
-       end
-       fun []=(k1: K1, k2: K2, k3: K3, v: V)
-       do
-               var level1 = self.level1
-               var level2: HashMap2[K2, K3, V]
-               if not level1.has_key(k1) then
-                       level2 = new HashMap2[K2, K3, V]
-                       level1[k1] = level2
-               else
-                       level2 = level1[k1]
-               end
-               level2[k2, k3] = v
-       end
-end
+private import more_collections
 
 # The container class of a Nit object-oriented model.
 # A model knows modules, classes and properties and can retrieve them.
index b0a5652..fd13faa 100644 (file)
@@ -29,6 +29,8 @@ import opts
 import toolcontext
 import phase
 
+private import more_collections
+
 ###
 
 redef class ToolContext
diff --git a/src/more_collections.nit b/src/more_collections.nit
new file mode 100644 (file)
index 0000000..2369c13
--- /dev/null
@@ -0,0 +1,93 @@
+# 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.
+
+# Highly specific, but useful, collections-related classes.
+module more_collections
+
+# Simple way to store an HashMap[K, Array[V]]
+class MultiHashMap[K: Object, V]
+       super HashMap[K, Array[V]]
+
+       # Add `v' to the array associated with `k'.
+       # If there is no array associated, then create it.
+       fun add_one(k: K, v: V)
+       do
+               if self.has_key(k) then
+                       self[k].add(v)
+               else
+                       self[k] = [v]
+               end
+       end
+
+       init do end
+end
+
+# Simple way to store an HashMap[K1, HashMap[K2, V]]
+class HashMap2[K1: Object, K2: Object, V]
+       private var level1: HashMap[K1, HashMap[K2, V]] = new HashMap[K1, HashMap[K2, V]]
+
+       # Return the value associated to the keys `k1` and `k2`.
+       # Return `null` if no such a value.
+       fun [](k1: K1, k2: K2): nullable V
+       do
+               var level1 = self.level1
+               if not level1.has_key(k1) then return null
+               var level2 = level1[k1]
+               if not level2.has_key(k2) then return null
+               return level2[k2]
+       end
+
+       # Set `v` the value associated to the keys `k1` and `k2`.
+       fun []=(k1: K1, k2: K2, v: V)
+       do
+               var level1 = self.level1
+               var level2: HashMap[K2, V]
+               if not level1.has_key(k1) then
+                       level2 = new HashMap[K2, V]
+                       level1[k1] = level2
+               else
+                       level2 = level1[k1]
+               end
+               level2[k2] = v
+       end
+end
+
+# Simple way to store an HashMap[K1, HashMap[K2, HashMap[K3, V]]]
+class HashMap3[K1: Object, K2: Object, K3: Object, V]
+       private var level1: HashMap[K1, HashMap2[K2, K3, V]] = new HashMap[K1, HashMap2[K2, K3, V]]
+
+       # Return the value associated to the keys `k1`, `k2`, and `k3`.
+       # Return `null` if no such a value.
+       fun [](k1: K1, k2: K2, k3: K3): nullable V
+       do
+               var level1 = self.level1
+               if not level1.has_key(k1) then return null
+               var level2 = level1[k1]
+               return level2[k2, k3]
+       end
+
+       # Set `v` the value associated to the keys `k1`, `k2`, and `k3`.
+       fun []=(k1: K1, k2: K2, k3: K3, v: V)
+       do
+               var level1 = self.level1
+               var level2: HashMap2[K2, K3, V]
+               if not level1.has_key(k1) then
+                       level2 = new HashMap2[K2, K3, V]
+                       level1[k1] = level2
+               else
+                       level2 = level1[k1]
+               end
+               level2[k2, k3] = v
+       end
+end
index 90f8483..7e6fb6f 100644 (file)
@@ -466,7 +466,6 @@ private class NaiveInterpreter
 
        # Check that non nullable attributes of `recv' are correctly initialized.
        # This function is used as the last instruction of a new
-       # FIXME: this will work better once there is nullable types
        fun check_init_instance(recv: Instance)
        do
                if not recv isa MutableInstance then return
@@ -1586,7 +1585,6 @@ redef class ASuperExpr
 
                # stantard call-next-method
                var mpropdef = v.frame.mpropdef
-               # FIXME: we do not want an ugly static call!
                mpropdef = mpropdef.lookup_next_definition(v.mainmodule, recv.mtype)
                assert mpropdef isa MMethodDef
                var res = v.call(mpropdef, args)
index fe49d70..bb368ee 100644 (file)
@@ -592,15 +592,9 @@ redef class ASuperExpr
                        return
                end
 
-               #FIXME: we do not want an ugly static call!
-               var mpropdef = v.mpropdef
-               var mpropdefs = mpropdef.mproperty.lookup_super_definitions(mpropdef.mclassdef.mmodule, mpropdef.mclassdef.bound_mtype)
-               if mpropdefs.length != 1 then
-                       debug("MPRODFEFS for super {mpropdef} for {v.receiver}: {mpropdefs.join(", ")}")
-               end
-               var msuperpropdef = mpropdefs.first
-               assert msuperpropdef isa MMethodDef
-               v.analysis.add_static_call(v.receiver, msuperpropdef)
+               var mpropdef = v.mpropdef.lookup_next_definition(v.analysis.mainmodule, v.receiver)
+               assert mpropdef isa MMethodDef
+               v.analysis.add_static_call(v.receiver, mpropdef)
        end
 end