Most specific first, most general last
REQUIRE: not mtype.need_anchor
to simplify the API (no anchor
parameter)
REQUIRE: mtype.has_mproperty(mmodule, self)
# Return all definitions in a linearization order
# Most specific first, most general last
#
# REQUIRE: `not mtype.need_anchor` to simplify the API (no `anchor` parameter)
# REQUIRE: `mtype.has_mproperty(mmodule, self)`
fun lookup_all_definitions(mmodule: MModule, mtype: MType): Array[MPROPDEF]
do
mtype = mtype.undecorate
var cache = self.lookup_all_definitions_cache[mmodule, mtype]
if cache != null then return cache
assert not mtype.need_anchor
assert mtype.has_mproperty(mmodule, self)
#print "select prop {mproperty} for {mtype} in {self}"
# First, select all candidates
var candidates = new Array[MPROPDEF]
for mpropdef in self.mpropdefs do
# If the definition is not imported by the module, then skip
if not mmodule.in_importation <= mpropdef.mclassdef.mmodule then continue
# If the definition is not inherited by the type, then skip
if not mtype.is_subtype(mmodule, null, mpropdef.mclassdef.bound_mtype) then continue
# Else, we keep it
candidates.add(mpropdef)
end
# Fast track for only one candidate
if candidates.length <= 1 then
self.lookup_all_definitions_cache[mmodule, mtype] = candidates
return candidates
end
mmodule.linearize_mpropdefs(candidates)
candidates = candidates.reversed
self.lookup_all_definitions_cache[mmodule, mtype] = candidates
return candidates
end
src/model/model.nit:2356,2--2392,4