Prepare Nit code for inherited and automatic constructors.
[nit.git] / src / metamodel / static_type.nit
index fe7fa44..8109d17 100644 (file)
@@ -57,11 +57,17 @@ redef class MMLocalProperty
        # The signature of the property (where it is declared)
        readable writable attr _signature: MMSignature
 
+       attr _signatures_cache: HashMap[MMType, MMSignature] = new HashMap[MMType, MMSignature]
+
        # Return the adapted signature of self for a receiver of type t
        meth signature_for(t: MMType): MMSignature do
-               var x = self
-               assert x isa MMConcreteProperty
-               return x.signature.adaptation_to(t)
+               if t == local_class.get_type then return signature
+
+               if _signatures_cache.has_key(t) then return _signatures_cache[t]
+
+               var res = signature.adaptation_to(t)
+               _signatures_cache[t] = res
+               return res
        end
 end
 
@@ -91,8 +97,7 @@ class MMSignature
                        return true
                end
                assert _recv.module == s.recv.module
-               assert arity == s.arity
-               assert (_return_type == null) == (s.return_type == null)
+               if arity != s.arity or (_return_type == null) != (s.return_type == null) then return false
                if _return_type != null and not _return_type < s.return_type then
                        return false
                end
@@ -210,29 +215,6 @@ abstract class MMType
        # a double dispatch is needed
        meth is_supertype(t: MMType): Bool is abstract
 
-       # Select a method from its name
-       meth select_method(name: Symbol): MMMethod
-       do
-               assert local_class != null
-               assert name != null
-               var res = select_property(local_class.method(name))
-               assert res isa MMMethod
-               return res
-       end
-       
-       # Select an attribute from its name
-       meth select_attribute(name: Symbol): MMAttribute
-       do
-               assert name != null
-               assert local_class != null
-               var res = select_property(local_class.attribute(name))
-               assert res isa MMAttribute
-               return res
-       end
-
-       # Select a local property from its global property
-       meth select_property(t: MMGlobalProperty): MMLocalProperty is abstract
-
        # Adapt self to another module
        meth for_module(mod: MMModule): MMType is abstract
 
@@ -286,15 +268,6 @@ special MMTypeClass
                return  t.local_class.cshe <= _local_class
        end
 
-       redef meth select_property(g)
-       do
-               assert _local_class != null
-               if g == null then
-                       return null
-               end
-               return _local_class[g]
-       end
-
        redef meth for_module(mod)
        do
                var t: MMType = self
@@ -307,7 +280,7 @@ special MMTypeClass
 
        redef meth adapt_to(recv) do return self
 
-       redef init(c: MMLocalClass)
+       init(c: MMLocalClass)
        do
                super(c)
        end