From 08b6eeeb10e557a7e265cb1b364829ee2317c7dd Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Thu, 4 Dec 2014 14:32:54 -0500 Subject: [PATCH] modelize: add and use method `collect_attr_propdef` Signed-off-by: Jean Privat --- src/compiler/abstract_compiler.nit | 16 ++++------------ src/interpreter/naive_interpreter.nit | 8 +------- src/modelize/modelize_property.nit | 15 +++++++++++++++ src/rapid_type_analysis.nit | 5 +---- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index a6d6d86..6329dac 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -914,12 +914,8 @@ extern void nitni_global_ref_decr( struct nitni_ref *ref ) { var cds = mtype.collect_mclassdefs(self.mainmodule).to_a self.mainmodule.linearize_mclassdefs(cds) for cd in cds do - if not self.modelbuilder.mclassdef2nclassdef.has_key(cd) then continue - var n = self.modelbuilder.mclassdef2nclassdef[cd] - for npropdef in n.n_propdefs do - if npropdef isa AAttrPropdef then - npropdef.init_expr(v, recv) - end + for npropdef in modelbuilder.collect_attr_propdef(cd) do + npropdef.init_expr(v, recv) end end end @@ -930,12 +926,8 @@ extern void nitni_global_ref_decr( struct nitni_ref *ref ) { var cds = mtype.collect_mclassdefs(self.mainmodule).to_a self.mainmodule.linearize_mclassdefs(cds) for cd in cds do - if not self.modelbuilder.mclassdef2nclassdef.has_key(cd) then continue - var n = self.modelbuilder.mclassdef2nclassdef[cd] - for npropdef in n.n_propdefs do - if npropdef isa AAttrPropdef then - npropdef.check_expr(v, recv) - end + for npropdef in modelbuilder.collect_attr_propdef(cd) do + npropdef.check_expr(v, recv) end end end diff --git a/src/interpreter/naive_interpreter.nit b/src/interpreter/naive_interpreter.nit index da8d02e..bf1a365 100644 --- a/src/interpreter/naive_interpreter.nit +++ b/src/interpreter/naive_interpreter.nit @@ -518,13 +518,7 @@ class NaiveInterpreter var cds = mtype.collect_mclassdefs(self.mainmodule).to_a self.mainmodule.linearize_mclassdefs(cds) for cd in cds do - if not self.modelbuilder.mclassdef2nclassdef.has_key(cd) then continue - var n = self.modelbuilder.mclassdef2nclassdef[cd] - for npropdef in n.n_propdefs do - if npropdef isa AAttrPropdef then - res.add(npropdef) - end - end + res.add_all(modelbuilder.collect_attr_propdef(cd)) end cache[mtype] = res diff --git a/src/modelize/modelize_property.nit b/src/modelize/modelize_property.nit index faaf149..ee66019 100644 --- a/src/modelize/modelize_property.nit +++ b/src/modelize/modelize_property.nit @@ -55,6 +55,21 @@ redef class ModelBuilder return null end + # Retrieve all the attributes nodes localy definied + # FIXME think more about this method and how the separations separate/global and ast/model should be done. + fun collect_attr_propdef(mclassdef: MClassDef): Array[AAttrPropdef] + do + var res = new Array[AAttrPropdef] + var n = mclassdef2nclassdef.get_or_null(mclassdef) + if n == null then return res + for npropdef in n.n_propdefs do + if npropdef isa AAttrPropdef then + res.add(npropdef) + end + end + return res + end + # Build the properties of `nclassdef`. # REQUIRE: all superclasses are built. private fun build_properties(nclassdef: AClassdef) diff --git a/src/rapid_type_analysis.nit b/src/rapid_type_analysis.nit index 7fcb4bc..32b13e3 100644 --- a/src/rapid_type_analysis.nit +++ b/src/rapid_type_analysis.nit @@ -343,10 +343,7 @@ class RapidTypeAnalysis var bound_mtype = mtype.anchor_to(mainmodule, recv) for cd in bound_mtype.collect_mclassdefs(mainmodule) do - if not self.modelbuilder.mclassdef2nclassdef.has_key(cd) then continue - var nclassdef = self.modelbuilder.mclassdef2nclassdef[cd] - for npropdef in nclassdef.n_propdefs do - if not npropdef isa AAttrPropdef then continue + for npropdef in modelbuilder.collect_attr_propdef(cd) do if not npropdef.has_value then continue var mpropdef = npropdef.mpropdef.as(not null) -- 1.7.9.5