tools: add 'fatal_error' to ToolContext and visitor
authorJean-Sebastien Gelinas <calestar@gmail.com>
Fri, 10 Jul 2009 16:09:29 +0000 (12:09 -0400)
committerJean Privat <jean@pryen.org>
Thu, 23 Jul 2009 22:50:17 +0000 (18:50 -0400)
Signed-off-by: Jean-Sebastien Gelinas <calestar@gmail.com>
Signed-off-by: Jean Privat <jean@pryen.org>

src/mmloader.nit
src/nitc.nit
src/syntax/syntax.nit
src/syntax/syntax_base.nit

index 409da1f..0533e02 100644 (file)
@@ -73,6 +73,13 @@ special MMContext
                _error_count = _error_count + 1
        end
 
+       # Add an error, show errors and quit
+       fun fatal_error(l: nullable Location, s: String)
+       do
+               error(l,s)
+               check_errors
+       end
+
        # Display a warning
        fun warning(l: nullable Location, s: String)
        do
@@ -189,8 +196,7 @@ special MMContext
                                var full_name = dir.full_name_for(module_name)
                                if _processing_modules.has(full_name) then
                                        # FIXME: Generate better error
-                                       error(null, "Error: Dependency loop for module {full_name}")
-                                       check_errors
+                                       fatal_error(null, "Error: Dependency loop for module {full_name}")
                                end
                                _processing_modules.add(full_name)
                                var m = l.load_and_process_module(self, module_name, dir)
@@ -228,8 +234,7 @@ special MMContext
                end
 
                if not filename.file_exists then
-                       error(null, "Error: File {filename} not found.")
-                       check_errors
+                       fatal_error(null, "Error: File {filename} not found.")
                        abort
                end
 
@@ -237,8 +242,7 @@ special MMContext
                var m = try_to_load(module_name, dir)
                if m != null then return m
 
-               error(null, "Error: {filename} is not a NIT source module.")
-               check_errors
+               fatal_error(null, "Error: {filename} is not a NIT source module.")
                abort
        end
 
@@ -261,8 +265,7 @@ special MMContext
                        if m != null then return m
                end
                # FIXME: Generate better error
-               error(null, "Error: No ressource found for module {module_name}.")
-               check_errors
+               fatal_error(null, "Error: No ressource found for module {module_name}.")
                abort
        end
 
@@ -330,8 +333,7 @@ class ModuleLoader
                end
 
                if file.eof then
-                       context.error(null, "Error: Problem in opening file {filename}")
-                       context.check_errors
+                       context.fatal_error(null, "Error: Problem in opening file {filename}")
                end
                var m = parse_file(context, file, filename, module_name, dir)
                if file != stdin then file.close
index 3e962d2..6e7657f 100644 (file)
@@ -70,8 +70,7 @@ special AbstractCompiler
                                if dir.file_exists then clibdir = dir
                        end
                        if clibdir == null then
-                               error(null, "Error: Cannot locate NIT C library directory. Uses --clibdir or envvar NIT_DIR.")
-                               check_errors
+                               fatal_error(null, "Error: Cannot locate NIT C library directory. Uses --clibdir or envvar NIT_DIR.")
                        end
                end
                bindir = opt_bindir.value
@@ -86,8 +85,7 @@ special AbstractCompiler
                                if dir.file_exists then bindir = dir
                        end
                        if bindir == null then
-                               error(null, "Error: Cannot locate NIT tools directory. Uses --bindir or envvar NIT_DIR.")
-                               check_errors
+                               fatal_error(null, "Error: Cannot locate NIT tools directory. Uses --bindir or envvar NIT_DIR.")
                        end
                end
        end
index d35ad6a..6cd9022 100644 (file)
@@ -37,8 +37,7 @@ special ModuleLoader
                if node_tree.n_base == null then
                        var err = node_tree.n_eof
                        assert err isa PError
-                       context.error(err.location, "{err.locate}: {err.message}")
-                       context.check_errors
+                       context.fatal_error(err.location, "{err.locate}: {err.message}")
                end
                var node_module = node_tree.n_base
                assert node_module isa AModule
index 3f40293..0f1440b 100644 (file)
@@ -358,6 +358,12 @@ special Visitor
                _tc.error(n.location, "{locate(n)}: {s}")
        end
 
+       # Add an error, show errors and quit
+       fun fatal_error(n: nullable PNode, s: String)
+       do
+               _tc.fatal_error(n.location, "{locate(n)}: {s}")
+       end
+
        # Display a warning for a given syntax node
        fun warning(n: nullable PNode, s: String)
        do