tools: add 'relative_to' to Locations
authorJean-Sebastien Gelinas <calestar@gmail.com>
Thu, 16 Jul 2009 16:35:46 +0000 (12:35 -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/location.nit
src/syntax/syntax_base.nit
tests/sav/base_array_alt1.sav
tests/sav/base_closure6.sav
tests/sav/base_closure6_alt1.sav
tests/sav/base_if_expr_alt1.sav
tests/sav/error_array_ambig.sav
tests/sav/test_array_comb_alt1.sav
tests/sav/test_array_comb_alt2.sav

index 085e980..c3eb80d 100644 (file)
@@ -68,15 +68,28 @@ special Comparable
        end
 
        redef fun to_s: String do
+               var file_part = file
+               if file_part.length > 0 then file_part += ":"
+
                if line_start == line_end then
                        if column_start == column_end then
-                               return "{file}:{line_start},{column_start}"
+                               return "{file_part}{line_start},{column_start}"
                        else
-                               return "{file}:{line_start},{column_start}--{column_end}"
+                               return "{file_part}{line_start},{column_start}--{column_end}"
                        end
                else
-                       return "{file}:{line_start},{column_start}--{line_end}:{column_end}"
+                       return "{file_part}{line_start},{column_start}--{line_end}:{column_end}"
+               end
+       end
+
+       fun relative_to(loc: nullable Location): String do
+               var relative: Location
+               if loc != null and loc.file == self.file then
+                       relative = new Location("", self.line_start, self.line_end, self.column_start, self.column_end)
+               else
+                       relative = new Location(self.file, self.line_start, self.line_end, self.column_start, self.column_end)
                end
+               return relative.to_s
        end
 
        redef fun <(other: OTHER): Bool do
index 0f1440b..351fe86 100644 (file)
@@ -448,7 +448,12 @@ special Visitor
                                if node == null then
                                        error(n, "Type error: no most general type. Got {n.stype} and {stype}.")
                                else
-                                       error(n, "Type error: no most general type. Got {n.stype} and {stype} at {node.locate}.")
+                                       var loc = node.location
+                                       if loc == null then
+                                               error(n, "Type error: no most general type. Got {n.stype} and {stype} at ????.")
+                                       else
+                                               error(n, "Type error: no most general type. Got {n.stype} and {stype} at {loc.relative_to(n.location)}.")
+                                       end
                                end
                                return null
                        end
index 26d2566..5868bc8 100644 (file)
@@ -1 +1 @@
-alt/base_array_alt1.nit:27,15--18: Type error: no most general type. Got Bool and Int at alt/base_array_alt1.nit:27,11--12.
+alt/base_array_alt1.nit:27,15--18: Type error: no most general type. Got Bool and Int at 27,11--12.
index ebd57db..674e569 100644 (file)
@@ -1,2 +1,2 @@
 ./base_closure6.nit:55,25: Type error: no most general type. Got V and U.
-./base_closure6.nit:65,8: Type error: no most general type. Got V and U at ./base_closure6.nit:64,8.
+./base_closure6.nit:65,8: Type error: no most general type. Got V and U at 64,8.
index 41fc33a..bf562be 100644 (file)
@@ -1,4 +1,4 @@
 alt/base_closure6_alt1.nit:53,5--25: Type error: expected U, got T
 alt/base_closure6_alt1.nit:55,25: Type error: no most general type. Got V and U.
 alt/base_closure6_alt1.nit:57,5--61:8: Type error: expected U, got T
-alt/base_closure6_alt1.nit:65,8: Type error: no most general type. Got V and U at alt/base_closure6_alt1.nit:64,8.
+alt/base_closure6_alt1.nit:65,8: Type error: no most general type. Got V and U at 64,8.
index 136c35c..348201d 100644 (file)
@@ -1 +1 @@
-alt/base_if_expr_alt1.nit:39,35: Type error: no most general type. Got Int and A at alt/base_if_expr_alt1.nit:39,24--28.
+alt/base_if_expr_alt1.nit:39,35: Type error: no most general type. Got Int and A at 39,24--28.
index f05fdee..dbacb81 100644 (file)
@@ -1 +1 @@
-./error_array_ambig.nit:17,13--15: Type error: no most general type. Got Char and Int at ./error_array_ambig.nit:17,10.
+./error_array_ambig.nit:17,13--15: Type error: no most general type. Got Char and Int at 17,10.
index 2dc2b75..d81a890 100644 (file)
@@ -1 +1 @@
-alt/test_array_comb_alt1.nit:23,19--21: Type error: no most general type. Got String and nullable Int at alt/test_array_comb_alt1.nit:23,16.
+alt/test_array_comb_alt1.nit:23,19--21: Type error: no most general type. Got String and nullable Int at 23,16.
index 531d390..f27b705 100644 (file)
@@ -1 +1 @@
-alt/test_array_comb_alt2.nit:24,19--21: Type error: no most general type. Got String and nullable Int at alt/test_array_comb_alt2.nit:24,16.
+alt/test_array_comb_alt2.nit:24,19--21: Type error: no most general type. Got String and nullable Int at 24,16.