From 1eba7aaffb15925cf3a7b2a2a43fb724120c64b6 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 27 May 2015 09:27:12 -0400 Subject: [PATCH] modelize: add `AAttrPropdef::mtype` to factorize the type access Signed-off-by: Jean Privat --- src/compiler/abstract_compiler.nit | 6 +++--- src/interpreter/naive_interpreter.nit | 2 +- src/modelize/modelize_property.nit | 8 +++++++- src/semantize/typing.nit | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index 2cf47e2..b8e78a5 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -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 diff --git a/src/interpreter/naive_interpreter.nit b/src/interpreter/naive_interpreter.nit index 16e0b48..91c4a87 100644 --- a/src/interpreter/naive_interpreter.nit +++ b/src/interpreter/naive_interpreter.nit @@ -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) diff --git a/src/modelize/modelize_property.nit b/src/modelize/modelize_property.nit index 91c552f..bd14308 100644 --- a/src/modelize/modelize_property.nit +++ b/src/modelize/modelize_property.nit @@ -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 diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index 44ed320..3bca2cb 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -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 -- 1.7.9.5