do
if not toolcontext.opt_detect_variance_constraints.value and not toolcontext.opt_all.value then return
- print "--- Metrics of covariance detection ---"
+ print "--- Detection of variance constraints on formal parameter types ---"
var k = new DetectVarianceConstraints
k.collect(mainmodule)
end
end
-redef class MParameterType
- # The fully-qualified name of the formal parameter.
- fun full_name: String do return "{mclass.full_name}::{name}"
-end
-
# A specific analysis that detects the variance constraints of formal parameters.
#
# The client has 3 steps to do:
if pd isa MMethodDef then
# Parameters (contravariant)
for p in pd.msignature.mparameters do
- var t = p.mtype.as_notnullable
+ var t = p.mtype.undecorate
if not t.need_anchor then
# OK
else if t isa MParameterType then
# Return (covariant)
var t = pd.msignature.return_mtype
if t != null and t.need_anchor then
- t = t.as_notnullable
+ t = t.undecorate
if t isa MParameterType then
covar_pt.add(t)
else if t isa MVirtualType then
# Attribute (invariant)
var t = pd.static_mtype
if t != null and t.need_anchor then
- t = t.as_notnullable
+ t = t.undecorate
if t isa MParameterType then
covar_pt.add t
contravar_pt.add t
# Virtual type bound (covariant)
var t = pd.bound
if t != null and t.need_anchor then
- t = t.as_notnullable
+ t = t.undecorate
if t isa MParameterType then
covar_pt.add t
else if t isa MVirtualType then
# Process the generic types in a covariant position
for c in covar_classes do for i in [0..c.mclass.arity[ do
# The type used in the argument
- var ta = c.arguments[i].as_notnullable
+ var ta = c.arguments[i].undecorate
# The associated formal parameter
var tp = c.mclass.mparameters[i]
# Process the generic types in a contravariant position
for c in contravar_classes do for i in [0..c.mclass.arity[ do
# The type used in the argument
- var ta = c.arguments[i].as_notnullable
+ var ta = c.arguments[i].undecorate
# The associated formal parameter
var tp = c.mclass.mparameters[i]