From e22bc3753ed1c4527f3ca5b40d314d050124b0a8 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Mon, 21 Jul 2014 22:27:20 -0400 Subject: [PATCH] modelize_property: add a guard for lazy attributes Signed-off-by: Jean Privat --- src/modelize_property.nit | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/modelize_property.nit b/src/modelize_property.nit index 9c269d5..fb21a65 100644 --- a/src/modelize_property.nit +++ b/src/modelize_property.nit @@ -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) -- 1.7.9.5