modelize: add and use method `collect_attr_propdef`
authorJean Privat <jean@pryen.org>
Thu, 4 Dec 2014 19:32:54 +0000 (14:32 -0500)
committerJean Privat <jean@pryen.org>
Thu, 4 Dec 2014 19:32:54 +0000 (14:32 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/compiler/abstract_compiler.nit
src/interpreter/naive_interpreter.nit
src/modelize/modelize_property.nit
src/rapid_type_analysis.nit

index a6d6d86..6329dac 100644 (file)
@@ -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
index da8d02e..bf1a365 100644 (file)
@@ -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
index faaf149..ee66019 100644 (file)
@@ -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)
index 7fcb4bc..32b13e3 100644 (file)
@@ -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)