modelize_property: add a guard for lazy attributes
authorJean Privat <jean@pryen.org>
Tue, 22 Jul 2014 02:27:20 +0000 (22:27 -0400)
committerJean Privat <jean@pryen.org>
Tue, 22 Jul 2014 11:58:09 +0000 (07:58 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/modelize_property.nit

index 9c269d5..fb21a65 100644 (file)
@@ -648,6 +648,12 @@ redef class AAttrPropdef
        # Is the node taggeg lazy?
        var is_lazy = false
 
+       # The guard associated to a lasy attribute.
+       # Because some engines does not have a working `isset`,
+       # this additionnal attribute is used to guard the lazy initialization.
+       # TODO: to remove once isset is correctly implemented
+       var mlazypropdef: nullable MAttributeDef
+
        # The associated getter (read accessor) if any
        var mreadpropdef: nullable MMethodDef writable
        # The associated setter (write accessor) if any
@@ -728,6 +734,9 @@ redef class AAttrPropdef
                                        modelbuilder.error(atlazy, "Error: a lazy attribute needs a value")
                                end
                                is_lazy = true
+                               var mlazyprop = new MAttribute(mclassdef, "lazy _" + name, none_visibility)
+                               var mlazypropdef = new MAttributeDef(mclassdef, mlazyprop, self.location)
+                               self.mlazypropdef = mlazypropdef
                        end
 
                        var atreadonly = self.get_single_annotation("readonly", modelbuilder)
@@ -852,7 +861,7 @@ redef class AAttrPropdef
                        mreadpropdef.msignature = msignature
                end
 
-               var msritepropdef = self.mwritepropdef
+               var mwritepropdef = self.mwritepropdef
                if mwritepropdef != null then
                        var name: String
                        if n_id != null then
@@ -864,6 +873,11 @@ redef class AAttrPropdef
                        var msignature = new MSignature([mparameter], null)
                        mwritepropdef.msignature = msignature
                end
+
+               var mlazypropdef = self.mlazypropdef
+               if mlazypropdef != null then
+                       mlazypropdef.static_mtype = modelbuilder.model.get_mclasses_by_name("Bool").first.mclass_type
+               end
        end
 
        redef fun check_signature(modelbuilder)