import poset
import location
import model_base
+private import more_collections
redef class Model
# All known classes
# 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
end
# A type prefixed with "nullable"
-# FIXME Stub implementation
class MNullableType
super MType
#
# 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
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.
import toolcontext
import phase
+private import more_collections
+
###
redef class ToolContext
--- /dev/null
+# 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
# 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
# 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)
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