nitc :: ModelBuilder :: build_a_mmodule
MModule
object
# Visit the AST and create the `MModule` object
private fun build_a_mmodule(mgroup: nullable MGroup, nmodule: AModule)
do
var mmodule = nmodule.mmodule
assert mmodule != null
# Check the module name
var decl = nmodule.n_moduledecl
if decl != null then
var decl_name = decl.n_name.n_id.text
if decl_name != mmodule.name then
warning(decl.n_name, "module-name-mismatch", "Error: module name mismatch; declared {decl_name} file named {mmodule.name}.")
end
end
# Check for conflicting module names in the package
if mgroup != null then
var others = model.get_mmodules_by_name(mmodule.name)
if others != null then for other in others do
if other != mmodule and mmodule2nmodule.has_key(mmodule) and other.mgroup!= null and other.mgroup.mpackage == mgroup.mpackage then
var node: ANode
if decl == null then node = nmodule else node = decl.n_name
error(node, "Error: a module named `{other.full_name}` already exists at {other.location}.")
break
end
end
end
nmodules.add(nmodule)
self.mmodule2nmodule[mmodule] = nmodule
var source = nmodule.location.file
if source != null then
assert source.mmodule == null
source.mmodule = mmodule
end
if decl != null then
# Extract documentation
var ndoc = decl.n_doc
if ndoc != null then
var mdoc = ndoc.to_mdoc
mmodule.mdoc = mdoc
mdoc.original_mentity = mmodule
end
# Is the module generated?
mmodule.is_generated = not decl.get_annotations("generated").is_empty
end
end
src/loader.nit:786,2--834,4