X-Git-Url: http://nitlanguage.org diff --git a/src/mmloader.nit b/src/mmloader.nit index 9a00c8c..0ab6078 100644 --- a/src/mmloader.nit +++ b/src/mmloader.nit @@ -23,9 +23,27 @@ import metamodel import opts import location -private class Message +class Message +special Comparable + redef type OTHER: Message + readable attr _location: nullable Location readable attr _text: String + + redef fun <(other: OTHER): Bool do + if location == null then return true + if other.location == null then return false + + return location.as(not null) < other.location.as(not null) + end + + redef fun to_s: String do + if location == null then + return text + else + return "{location}: {text}" + end + end end # Global context for tools @@ -39,12 +57,15 @@ special MMContext # Messages var _messages: Array[Message] = new Array[Message] + var _message_sorter: ComparableSorter[Message] = new ComparableSorter[Message] fun check_errors do if _messages.length > 0 then + _message_sorter.sort(_messages) + for m in _messages do - stderr.write("{m.text}\n") + stderr.write("{m}\n") end _messages.clear @@ -60,6 +81,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 @@ -176,8 +204,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) @@ -215,8 +242,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 @@ -224,8 +250,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 @@ -248,8 +273,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 @@ -317,8 +341,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