modelize: add `AAttrPropdef::mtype` to factorize the type access
authorJean Privat <jean@pryen.org>
Wed, 27 May 2015 13:27:12 +0000 (09:27 -0400)
committerJean Privat <jean@pryen.org>
Mon, 8 Jun 2015 21:21:21 +0000 (17:21 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/compiler/abstract_compiler.nit
src/interpreter/naive_interpreter.nit
src/modelize/modelize_property.nit
src/semantize/typing.nit

index 2cf47e2..b8e78a5 100644 (file)
@@ -2444,7 +2444,7 @@ redef class AAttrPropdef
                        var res
                        if is_lazy then
                                var set
-                               var ret = self.mpropdef.static_mtype
+                               var ret = self.mtype
                                var useiset = not ret.is_c_primitive and not ret isa MNullableType
                                var guard = self.mlazypropdef.mproperty
                                if useiset then
@@ -2472,7 +2472,7 @@ redef class AAttrPropdef
                        assert arguments.length == 2
                        v.write_attribute(self.mpropdef.mproperty, arguments.first, arguments[1])
                        if is_lazy then
-                               var ret = self.mpropdef.static_mtype
+                               var ret = self.mtype
                                var useiset = not ret.is_c_primitive and not ret isa MNullableType
                                if not useiset then
                                        v.write_attribute(self.mlazypropdef.mproperty, arguments.first, v.bool_instance(true))
@@ -2498,7 +2498,7 @@ redef class AAttrPropdef
                v.frame = frame
 
                var value
-               var mtype = self.mpropdef.static_mtype
+               var mtype = self.mtype
                assert mtype != null
 
                var nexpr = self.n_expr
index 16e0b48..91c4a87 100644 (file)
@@ -1251,7 +1251,7 @@ redef class AAttrPropdef
                end
                var mpropdef = self.mpropdef
                if mpropdef == null then return
-               var mtype = mpropdef.static_mtype.as(not null)
+               var mtype = self.mtype.as(not null)
                mtype = mtype.anchor_to(v.mainmodule, recv.mtype.as(MClassType))
                if mtype isa MNullableType then
                        v.write_attribute(self.mpropdef.mproperty, recv, v.null_instance)
index 91c552f..bd14308 100644 (file)
@@ -1135,6 +1135,10 @@ end
 redef class AAttrPropdef
        redef type MPROPDEF: MAttributeDef
 
+       # The static type of the property (declared, inferred or inherited)
+       # This attribute is also used to check if the property was analyzed and is valid.
+       var mtype: nullable MType
+
        # Is the node tagged `noinit`?
        var noinit = false
 
@@ -1359,6 +1363,8 @@ redef class AAttrPropdef
                        return
                end
 
+               self.mtype = mtype
+
                if mpropdef != null then
                        mpropdef.static_mtype = mtype
                end
@@ -1389,7 +1395,7 @@ redef class AAttrPropdef
                var mpropdef = self.mpropdef
                if mpropdef == null then return # Error thus skipped
                var ntype = self.n_type
-               var mtype = self.mpropdef.static_mtype
+               var mtype = self.mtype
                if mtype == null then return # Error thus skipped
 
                var mclassdef = mpropdef.mclassdef
index 44ed320..3bca2cb 100644 (file)
@@ -768,7 +768,7 @@ redef class AAttrPropdef
 
                var nexpr = self.n_expr
                if nexpr != null then
-                       var mtype = self.mpropdef.static_mtype
+                       var mtype = self.mtype
                        v.visit_expr_subtype(nexpr, mtype)
                end
                var nblock = self.n_block