metamodel: new MMType::is_valid method
authorJean Privat <jean@pryen.org>
Thu, 18 Jun 2009 20:39:16 +0000 (16:39 -0400)
committerJean Privat <jean@pryen.org>
Wed, 24 Jun 2009 19:47:34 +0000 (15:47 -0400)
is_valid is used to discriminate fully build MMType from others.
Currently, only MMTypeFormal require it.
Previous behavior of returning null on invalid MMTypeFormal's methods is disabled.

syntax_base.nit is adapted to the new behavior.

Signed-off-by: Jean Privat <jean@pryen.org>

src/metamodel/static_type.nit
src/metamodel/type_formal.nit
src/syntax/syntax_base.nit

index 25b41f8..e8b5704 100644 (file)
@@ -308,6 +308,10 @@ abstract class MMType
        # The local class that self direclty or indirectly refers to
        meth local_class: MMLocalClass is abstract
 
+       # Is the type a valid one
+       # For instance, circular dependency on formal types is invalid
+       meth is_valid: Bool do return true
+
        # Is self a valid subtype of t
        meth <(t : MMType): Bool is abstract
 
index fb24352..fcbcb87 100644 (file)
@@ -28,20 +28,23 @@ end
 # Formal types are named indirect types
 class MMTypeFormal
 special MMType
+       redef meth is_valid do return _bound != null
+
        # The name of the type
        readable attr _name: Symbol 
 
        # The type refered
-       readable attr _bound: MMType 
+       meth bound: MMType
+       do
+               assert is_valid
+               return _bound
+       end
+       attr _bound: MMType
 
        redef meth <(t) do return t != null and (t == self or t.is_supertype(_bound))
        redef meth is_supertype(t) do return _bound.is_supertype(t)
        redef meth direct_type do return _bound.direct_type
-       redef meth local_class
-       do
-               if _bound == null then return null
-               return _bound.local_class
-       end
+       redef meth local_class do return _bound.local_class
 
        redef meth to_s do return _name.to_s
 
index 85231ed..bbb972c 100644 (file)
@@ -606,7 +606,9 @@ redef class AType
        redef meth get_stype(v)
        do
                var t = get_unchecked_stype(v)
-               if t != null then check_conform(v)
+               if t == null then return null
+               if not t.is_valid then return null
+               check_conform(v)
                return t
        end
 
@@ -620,8 +622,9 @@ redef class AType
                        for i in [0..arity[ do
                                var p = n_types[i]
                                var pt = p.get_stype(v)
-                               var bt = local_class.get_formal(i).bound
-                               if bt == null then return
+                               var b = local_class.get_formal(i)
+                               if not b.is_valid then return
+                               var bt = b.bound
                                bt = bt.adapt_to(st) # We need to abapt because of F-genericity
                                v.check_conform(p, pt, bt)
                        end