X-Git-Url: http://nitlanguage.org diff --git a/src/modelize/modelize_property.nit b/src/modelize/modelize_property.nit index 757f85d..fef5ca9 100644 --- a/src/modelize/modelize_property.nit +++ b/src/modelize/modelize_property.nit @@ -17,7 +17,7 @@ # Analysis and verification of property definitions to instantiate model element module modelize_property -import modelize_class +intrude import modelize_class private import annotation redef class ToolContext @@ -36,9 +36,40 @@ private class ModelizePropertyPhase end redef class ModelBuilder - # Register the npropdef associated to each mpropdef - # FIXME: why not refine the `MPropDef` class with a nullable attribute? - var mpropdef2npropdef = new HashMap[MPropDef, APropdef] + # Registration of the npropdef associated to each mpropdef. + # + # Public clients need to use `mpropdef2node` to access stuff. + private var mpropdef2npropdef = new HashMap[MPropDef, APropdef] + + # Retrieve the associated AST node of a mpropertydef. + # This method is used to associate model entity with syntactic entities. + # + # If the property definition is not associated with a node, returns node. + fun mpropdef2node(mpropdef: MPropDef): nullable ANode + do + var res: nullable ANode = mpropdef2npropdef.get_or_null(mpropdef) + if res != null then return res + if mpropdef isa MMethodDef and mpropdef.mproperty.is_root_init then + res = mclassdef2nclassdef.get_or_null(mpropdef.mclassdef) + if res != null then return res + end + 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. @@ -439,6 +470,7 @@ redef class APropdef return false end + if mprop isa MMethod and mprop.is_root_init then return true if kwredef == null then if need_redef then modelbuilder.error(self, "Redef error: {mclassdef.mclass}::{mprop.name} is an inherited property. To redefine it, add the redef keyword.") @@ -621,9 +653,20 @@ redef class AMethPropdef if parent isa ATopClassdef then mprop.is_toplevel = true self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, false, mprop) else - if not mprop.is_root_init and not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, not self isa AMainMethPropdef, mprop) then return + if not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, not self isa AMainMethPropdef, mprop) then return check_redef_property_visibility(modelbuilder, self.n_visibility, mprop) end + + # Check name conflicts in the local class for constructors. + if is_init then + for p, n in mclassdef.mprop2npropdef do + if p != mprop and p isa MMethod and p.name == name then + check_redef_keyword(modelbuilder, mclassdef, n_kwredef, false, p) + break + end + end + end + mclassdef.mprop2npropdef[mprop] = self var mpropdef = new MMethodDef(mclassdef, mprop, self.location) @@ -677,6 +720,9 @@ redef class AMethPropdef msignature = mpropdef.mproperty.intro.msignature if msignature == null then return # Skip error + # The local signature is adapted to use the local formal types, if any. + msignature = msignature.resolve_for(mclassdef.mclass.mclass_type, mclassdef.bound_mtype, mmodule, false) + # Check inherited signature arity if param_names.length != msignature.arity then var node: ANode @@ -952,7 +998,11 @@ redef class AAttrPropdef var msignature = mreadpropdef.mproperty.intro.msignature if msignature == null then return # Error, thus skipped inherited_type = msignature.return_mtype - if mtype == null then mtype = inherited_type + if inherited_type != null then + # The inherited type is adapted to use the local formal types, if any. + inherited_type = inherited_type.resolve_for(mclassdef.mclass.mclass_type, mclassdef.bound_mtype, mmodule, false) + if mtype == null then mtype = inherited_type + end end var nexpr = self.n_expr @@ -1138,6 +1188,11 @@ redef class ATypePropdef var mpropdef = new MVirtualTypeDef(mclassdef, mprop, self.location) self.mpropdef = mpropdef modelbuilder.mpropdef2npropdef[mpropdef] = self + if mpropdef.is_intro then + modelbuilder.toolcontext.info("{mpropdef} introduces new type {mprop.full_name}", 4) + else + modelbuilder.toolcontext.info("{mpropdef} redefines type {mprop.full_name}", 4) + end set_doc(mpropdef, modelbuilder) var atfixed = get_single_annotation("fixed", modelbuilder)