nitmetrics: add inheritance metrics computation
[nit.git] / src / metamodel / static_type.nit
index 7ebfaab..09db136 100644 (file)
@@ -68,14 +68,16 @@ redef class MMLocalProperty
 end
 
 class MMParam
-       readable var _mmtype: MMType
-       readable var _name: Symbol
+       var mmtype: MMType
+       var name: Symbol writable
 
        init ( t  : MMType, n : Symbol )
        do
-           _mmtype = t
-           _name = n
+           mmtype = t
+           name = n
        end
+
+       redef fun to_s do return "{name}: {mmtype}"
 end
 
 # Signature for local properties
@@ -148,12 +150,10 @@ class MMSignature
                        var tmp: String
                        var a = new Array[String].with_capacity(_params.length)
                        for i in [0.._params.length[ do
-                               #var pn = _params_name[i]
                                var p = _params[i]
-                               #a.add("{pn}: {p}")
                                a.add(p.to_s)
                        end
-                       s.append("({a.join(",")})")
+                       s.append("({a.join(", ")})")
                end
                var rt = _return_type
                if rt != null then s.append(": {rt}")
@@ -246,6 +246,17 @@ class MMSignature
        end
 end
 
+
+redef class MMExplicitImport
+       var signature : MMSignature
+
+       redef init( local_class : MMLocalClass, meth : MMMethod )
+       do
+               super
+               signature = meth.signature.adaptation_to( local_class.get_type )
+       end
+end
+
 # A closure in a signature
 class MMClosure
        # The name of the closure (without the !)
@@ -362,9 +373,9 @@ abstract class MMType
        # 'c' Must be a super-class of self
        # Example:
        #   class A[E]
-       #   class B[F] special A[F]
-       #   class C[G] special B[String]
-       #   class D special C[Float]
+       #   class B[F] super A[F]
+       #   class C[G] super B[String]
+       #   class D super C[Float]
        # 'A[Int]'.upcast_for('A') -> 'A[Int]'
        # 'A[Int]'.upcast_for('B') -> abort
        # 'B[Int]'.upcast_for('B') -> 'B[Int]'
@@ -453,7 +464,7 @@ class MMNullableType
        end
 end
 
-class MMTypeClass 
+abstract class MMTypeClass
        super MMType
        redef readable var _local_class: MMLocalClass
        redef fun mmmodule do return _local_class.mmmodule end
@@ -529,3 +540,37 @@ redef class MMModule
                return class_by_name(once ("Bool".to_symbol)).get_type
        end
 end
+
+# Explicitly imported cast
+class MMImportedCast
+       readable var _from : MMType
+       readable var _to : MMType
+
+       fun is_about_nullable_only : Bool
+       do
+           return ( _from.is_nullable and _to.as_nullable == _from ) or
+                  ( _to.is_nullable and _from.as_nullable == _to )
+       end
+
+       fun is_not_null_to_nullable : Bool
+       do
+           return not _from.is_nullable and _to.is_nullable
+       end
+
+       fun is_nullable_to_not_null : Bool
+       do
+           return _from.is_nullable and not _to.is_nullable
+       end
+
+       redef fun == ( o )
+       do
+               return o isa MMImportedCast and
+                       o.from == from and o.to == to
+       end
+end
+
+# Method local properties
+redef class MMMethod
+       # casts explicitely imported to be available from native implementation
+       fun explicit_casts : Set[ MMImportedCast ] is abstract
+end