- # 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 `null`.
+ fun mpropdef2node(mpropdef: MPropDef): nullable ANode
+ do
+ var res
+ res = mpropdef2npropdef.get_or_null(mpropdef)
+ if res != null then
+ # Run the phases on it
+ toolcontext.run_phases_on_npropdef(res)
+ return res
+ end
+ 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
+ # Run the phases on it
+ toolcontext.run_phases_on_npropdef(npropdef)
+ res.add(npropdef)
+ end
+ end
+ return res
+ end