tools: order messages by line number/column
authorJean-Sebastien Gelinas <calestar@gmail.com>
Thu, 23 Jul 2009 05:29:08 +0000 (01:29 -0400)
committerJean Privat <jean@pryen.org>
Thu, 23 Jul 2009 22:48:00 +0000 (18:48 -0400)
Trivial hack by Jean Privat <jean@pryen.org>:
Rename _sorter as _message_sorter

Signed-off-by: Jean-Sebastien Gelinas <calestar@gmail.com>
Signed-off-by: Jean Privat <jean@pryen.org>

src/mmloader.nit
tests/sav/error_type_not_ok3.sav
tests/sav/error_type_not_ok4.sav

index 9a00c8c..409da1f 100644 (file)
@@ -23,9 +23,19 @@ 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
 end
 
 # Global context for tools
@@ -39,10 +49,13 @@ 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")
                        end
index 2584182..a522087 100644 (file)
@@ -1,2 +1,2 @@
-./error_type_not_ok3.nit:23,18--21: Type error: class Fail not found in module error_type_not_ok3.
 ./error_type_not_ok3.nit:20,12--15: Type error: class Fail not found in module error_type_not_ok3.
+./error_type_not_ok3.nit:23,18--21: Type error: class Fail not found in module error_type_not_ok3.
index db72bf0..fbf5f4d 100644 (file)
@@ -1,7 +1,7 @@
+./error_type_not_ok4.nit:21,10--13: Type error: class Fail not found in module error_type_not_ok4.
 ./error_type_not_ok4.nit:25,16--19: Type error: class Fail not found in module error_type_not_ok4.
 ./error_type_not_ok4.nit:29,28--31: Type error: class Fail not found in module error_type_not_ok4.
 ./error_type_not_ok4.nit:30,12--15: Type error: class Fail not found in module error_type_not_ok4.
 ./error_type_not_ok4.nit:31,18--21: Type error: class Fail not found in module error_type_not_ok4.
 ./error_type_not_ok4.nit:32,10--13: Type error: class Fail not found in module error_type_not_ok4.
 ./error_type_not_ok4.nit:33,16--19: Type error: class Fail not found in module error_type_not_ok4.
-./error_type_not_ok4.nit:21,10--13: Type error: class Fail not found in module error_type_not_ok4.