nullable: convert lib, tools and tests
[nit.git] / src / mmloader.nit
index ad35e01..13adce2 100644 (file)
@@ -40,13 +40,17 @@ special MMContext
        # Display a warning
        meth warning(s: String)
        do
-               if not _opt_warn.value then return
+               if _opt_warn.value == 0 then return
                stderr.write("{s}\n")
-               _warning_count = _warning_count + 1
+               if _opt_warn.value == 1 then
+                       _warning_count = _warning_count + 1
+               else
+                       _error_count = _error_count + 1
+               end
        end
 
        # Paths where to locate modules files
-       readable attr _paths: Array[String]
+       readable attr _paths: Array[String] = new Array[String]
 
        # List of module loaders
        attr _loaders: Array[ModuleLoader] = new Array[ModuleLoader]
@@ -55,7 +59,7 @@ special MMContext
        readable attr _option_context: OptionContext = new OptionContext
 
        # Option --warn
-       readable attr _opt_warn: OptionBool = new OptionBool("Show warnings", "-W", "--warn")
+       readable attr _opt_warn: OptionCount = new OptionCount("Show warnings", "-W", "--warn")
 
        # Option --path
        readable attr _opt_path: OptionArray = new OptionArray("Set include path for loaders (may be used more than once)", "-I", "--path")
@@ -85,7 +89,6 @@ special MMContext
                option_context.parse(args)
 
                # Setup the paths value
-               _paths = new Array[String]
                paths.append(opt_path.value)
 
                var path_env = once ("NIT_PATH".to_symbol).environ
@@ -106,7 +109,7 @@ special MMContext
        # Load and process a module in a directory (or a parent directory).
        # If the module is already loaded, just return it without further processing.
        # If no module is found, just return null without complaining.
-       private meth try_to_load(module_name: Symbol, dir: MMDirectory): MMModule
+       private meth try_to_load(module_name: Symbol, dir: MMDirectory): nullable MMModule
        do
                # Look in the module directory
                for m in dir.modules do
@@ -186,11 +189,11 @@ special MMContext
 
        # Locate, load and analysis a module (and its supermodules).
        # If the module is already loaded, just return it without further processing.
-       meth get_module(module_name: Symbol, from: MMModule): MMModule
+       meth get_module(module_name: Symbol, from: nullable MMModule): MMModule
        do
                var m: MMModule
                if from != null then
-                       var dir = from.directory
+                       var dir: nullable MMDirectory = from.directory
                        while dir != null do
                                var m = try_to_load(module_name, dir)
                                if m != null then return m
@@ -233,7 +236,7 @@ class ModuleLoader
        meth file_type: String is abstract
 
        # Try to load a new module directory
-       meth try_to_load_dir(dirname: Symbol, parent_dir: MMDirectory): MMDirectory
+       meth try_to_load_dir(dirname: Symbol, parent_dir: MMDirectory): nullable MMDirectory
        do
                var fname = "{parent_dir.path}/{dirname}/"
                if not fname.file_exists then return null