# Extends the current importations according to imported rules about conditional importation
fun apply_conditional_importations(mmodule: MModule)
do
# Because a conditional importation may cause additional conditional importation, use a fixed point
# The rules are checked naively because we assume that it does not worth to be optimized
var check_conditional_importations = true
while check_conditional_importations do
check_conditional_importations = false
for ci in conditional_importations do
# Check conditions
for i in [1..ci.length[ do
var m = ci[i]
# Is imported?
if mmodule == m or not mmodule.in_importation.greaters.has(m) then continue label
end
# Still here? It means that all conditions modules are loaded and imported
# Identify the module to automatically import
var sup = ci.first
var ast = sup.load(self)
if ast == null then continue
# Do nothing if already imported
if mmodule.in_importation.greaters.has(sup) then continue label
# Import it
self.toolcontext.info("{mmodule} conditionally imports {sup}", 3)
# TODO visibility rules (currently always public)
mmodule.set_visibility_for(sup, public_visibility)
# TODO linearization rules (currently added at the end in the order of the rules)
mmodule.set_imported_mmodules([sup])
# Prepare to reapply the rules
check_conditional_importations = true
end label
end
end
src/loader.nit:1074,2--1111,4