if nmodule == null then continue # Skip error
# Load imported module
build_module_importation(nmodule)
-
- mmodules.add(nmodule.mmodule.as(not null))
+ var mmodule = nmodule.mmodule
+ if mmodule == null then continue # skip error
+ mmodules.add mmodule
end
var time1 = get_time
self.toolcontext.info("*** END PARSE: {time1-time0} ***", 2)
if nmodule == null then continue # Skip error
# Load imported module
build_module_importation(nmodule)
-
- res.add(nmodule.mmodule.as(not null))
+ var mmodule = nmodule.mmodule
+ if mmodule == null then continue # Skip error
+ res.add mmodule
end
end
return res
var nmodule = self.load_module(af)
if nmodule == null then continue # Skip error
build_module_importation(nmodule)
- mmodules.add(nmodule.mmodule.as(not null))
+ var mmodule = nmodule.mmodule
+ if mmodule == null then continue # Skip error
+ mmodules.add mmodule
else
self.toolcontext.info("ignore file {af}", 2)
end
if nmodule == null then continue # Skip error
# Load imported module
build_module_importation(nmodule)
-
- mmodules.add(nmodule.mmodule.as(not null))
+ var mmodule = nmodule.mmodule
+ if mmodule == null then continue # Skip error
+ mmodules.add mmodule
end
var time1 = get_time
self.toolcontext.info("*** END PARSE: {time1-time0} ***", 2)
if candidate == null then
if mgroup != null then
- error(anode, "Error: cannot find module {name} from {mgroup.name}. tried {lookpaths.join(", ")}")
+ error(anode, "Error: cannot find module `{name}` from `{mgroup.name}`. Tried: {lookpaths.join(", ")}.")
else
- error(anode, "Error: cannot find module {name}. tried {lookpaths.join(", ")}")
+ error(anode, "Error: cannot find module `{name}`. Tried: {lookpaths.join(", ")}.")
end
return null
end
if res == null then return null # Forward error
# Load imported module
build_module_importation(res)
- return res.mmodule.as(not null)
+ return res.mmodule
end
# Search a module `name` from path `lookpaths`.
var abs_candidate = module_absolute_path(candidate)
var abs_try_file = module_absolute_path(try_file)
if abs_candidate != abs_try_file then
- toolcontext.error(location, "Error: conflicting module file for {name}: {candidate} {try_file}")
+ toolcontext.error(location, "Error: conflicting module file for `{name}`: `{candidate}` `{try_file}`")
end
end
end
var abs_candidate = module_absolute_path(candidate)
var abs_try_file = module_absolute_path(try_file)
if abs_candidate != abs_try_file then
- toolcontext.error(location, "Error: conflicting module file for {name}: {candidate} {try_file}")
+ toolcontext.error(location, "Error: conflicting module file for `{name}`: `{candidate}` `{try_file}`")
end
end
end
return mgroups[rdp]
end
- # Hack, a group is determined by:
+ # Hack, a group is determined by one of the following:
# * the presence of a honomymous nit file
# * the fact that the directory is named `src`
+ # * the fact that there is a sub-directory named `src`
var pn = rdp.basename(".nit")
var mp = dirpath.join_path(pn + ".nit").simplify_path
+ # dirpath2 is the root directory
+ # dirpath is the src subdirectory directory, if any, else it is the same that dirpath2
var dirpath2 = dirpath
if not mp.file_exists then
if pn == "src" then
dirpath2 = rdp.dirname
pn = dirpath2.basename("")
else
- return null
+ # Check a `src` subdirectory
+ dirpath = dirpath2 / "src"
+ if not dirpath.file_exists then
+ # All rules failed, so return null
+ return null
+ end
end
end
# check parent directory
- var parentpath = dirpath.join_path("..").simplify_path
+ var parentpath = dirpath2.join_path("..").simplify_path
var parent = get_mgroup(parentpath)
var mgroup
end
mgroup.filepath = dirpath
- mgroups[rdp] = mgroup
+ mgroups[module_absolute_path(dirpath)] = mgroup
+ mgroups[module_absolute_path(dirpath2)] = mgroup
return mgroup
end
fun load_module_ast(filename: String): nullable AModule
do
if filename.file_extension != "nit" then
- self.toolcontext.error(null, "Error: file {filename} is not a valid nit module.")
+ self.toolcontext.error(null, "Error: file `{filename}` is not a valid nit module.")
return null
end
if not filename.file_exists then
- self.toolcontext.error(null, "Error: file {filename} not found.")
+ self.toolcontext.error(null, "Error: file `{filename}` not found.")
return null
end
if decl != null then
var decl_name = decl.n_name.n_id.text
if decl_name != mod_name then
- error(decl.n_name, "Error: module name missmatch; declared {decl_name} file named {mod_name}")
+ error(decl.n_name, "Error: module name mismatch; declared {decl_name} file named {mod_name}.")
end
end
if other.mgroup!= null and other.mgroup.mproject == mgroup.mproject 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}")
+ error(node, "Error: a module named `{other.full_name}` already exists at {other.location}.")
break
end
end
if aimport.n_name.n_quad != null then mgroup = null # Start from top level
for grp in aimport.n_name.n_path do
var path = search_mmodule_by_name(grp, mgroup, grp.text)
- if path == null then return # Skip error
+ if path == null then
+ nmodule.mmodule = null # invalidate the module
+ return # Skip error
+ end
mgroup = path.mgroup
end
var mod_name = aimport.n_name.n_id.text
var sup = self.get_mmodule_by_name(aimport.n_name, mgroup, mod_name)
- if sup == null then continue # Skip error
+ if sup == null then
+ nmodule.mmodule = null # invalidate the module
+ continue # Skip error
+ end
aimport.mmodule = sup
imported_modules.add(sup)
var mvisibility = aimport.n_visibility.mvisibility
if mvisibility == protected_visibility then
error(aimport.n_visibility, "Error: only properties can be protected.")
+ nmodule.mmodule = null # invalidate the module
return
end
if sup == mmodule then
- error(aimport.n_name, "Error: Dependency loop in module {mmodule}.")
+ error(aimport.n_name, "Error: dependency loop in module {mmodule}.")
+ nmodule.mmodule = null # invalidate the module
end
if sup.in_importation < mmodule then
- error(aimport.n_name, "Error: Dependency loop between modules {mmodule} and {sup}.")
+ error(aimport.n_name, "Error: dependency loop between modules {mmodule} and {sup}.")
+ nmodule.mmodule = null # invalidate the module
return
end
mmodule.set_visibility_for(sup, mvisibility)
if stdimport then
var mod_name = "standard"
var sup = self.get_mmodule_by_name(nmodule, null, mod_name)
- if sup != null then # Skip error
+ if sup == null then
+ nmodule.mmodule = null # invalidate the module
+ else # Skip error
imported_modules.add(sup)
mmodule.set_visibility_for(sup, public_visibility)
end