The collect visits all classes and properties of mainmodule
and its imported modules.
After the visit, the attributes of self
are filled.
# Collect all types used in covariant and contravariant positions.
#
# The collect visits all classes and properties of `mainmodule` and its imported modules.
#
# After the visit, the attributes of `self` are filled.
fun collect(mainmodule: MModule)
do
for m in mainmodule.in_importation.greaters do
for cd in m.mclassdefs do
if cd.is_intro then
pts.add_all(cd.mclass.mparameters)
var a = cd.mclass.arity
if a == 0 then
cpt_class.inc("non generic")
else if a == 1 then
cpt_class.inc("with 1 formal type parameter")
else
cpt_class.inc("with {a} formal type parameters")
end
end
for t in cd.supertypes do
# Supertype (covariant)
if t.need_anchor then covar_classes.add(t)
end
for pd in cd.mpropdefs do
if exclude_private and pd.mproperty.visibility <= private_visibility then continue
if pd isa MMethodDef then
# Parameters (contravariant)
for p in pd.msignature.mparameters do
var t = p.mtype.undecorate
if not t.need_anchor then
# OK
else if t isa MParameterType then
contravar_pt.add(t)
else if t isa MVirtualType then
# TODO?
else if t isa MClassType then
contravar_classes.add(t)
else
abort
end
end
# Return (covariant)
var t = pd.msignature.return_mtype
if t != null and t.need_anchor then
t = t.undecorate
if t isa MParameterType then
covar_pt.add(t)
else if t isa MVirtualType then
# TODO?
else if t isa MClassType then
covar_classes.add(t)
else
abort
end
end
else if pd isa MAttributeDef then
# Attribute (invariant)
var t = pd.static_mtype
if t != null and t.need_anchor then
t = t.undecorate
if t isa MParameterType then
covar_pt.add t
contravar_pt.add t
else if t isa MVirtualType then
# TODO?
else if t isa MClassType then
covar_classes.add(t)
contravar_classes.add(t)
else
abort
end
end
else if pd isa MVirtualTypeDef then
# Virtual type bound (covariant)
var t = pd.bound
if t != null and t.need_anchor then
t = t.undecorate
if t isa MParameterType then
covar_pt.add t
else if t isa MVirtualType then
# TODO?
else if t isa MClassType then
covar_classes.add(t)
else
abort
end
end
end
end
end
end
end
src/metrics/detect_variance_constraints.nit:87,2--179,4