tools: remove 'locate' from nodes and visitor
authorJean-Sebastien Gelinas <calestar@gmail.com>
Thu, 16 Jul 2009 18:45:51 +0000 (14:45 -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/compiling/compiling_methods.nit
src/mmloader.nit
src/parser/parser_prod.nit
src/parser/xss/nodes.xss
src/syntax/control_flow.nit
src/syntax/mmbuilder.nit
src/syntax/syntax.nit
src/syntax/syntax_base.nit
src/syntax/typing.nit

index 4233c68..f189355 100644 (file)
@@ -952,7 +952,7 @@ redef class AInternMethPropdef
                        s = "BOX_NativeString((char*)malloc((UNTAG_Int({p[1]}) * sizeof(char))))"
 
                else
-                       stderr.write("{locate}: Fatal error: unknown intern method {method.full_name}.\n")
+                       stderr.write("{location}: Fatal error: unknown intern method {method.full_name}.\n")
                        exit(1)
                end
                if method.signature.return_type != null and s == null then
index 0533e02..0ab6078 100644 (file)
@@ -36,6 +36,14 @@ special Comparable
 
                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
@@ -57,7 +65,7 @@ special MMContext
                        _message_sorter.sort(_messages)
 
                        for m in _messages do
-                               stderr.write("{m.text}\n")
+                               stderr.write("{m}\n")
                        end
 
                        _messages.clear
index a45f736..d6b9606 100644 (file)
@@ -34,19 +34,14 @@ redef class PNode
        # Thus, call "v.visit(e)" for each node e starting from the last child
        fun visit_all_reverse(v: Visitor) is abstract
 
-       # Give a human readable location of the node.
-       fun locate: String
-       do
-               if location == null then
-                       return "????"
-               end
-               return location.to_s
-       end
-
        # Debug method: output a message prefixed with the location.
        fun printl(str: String)
        do
-               print("{locate}: {str}\n")
+               if location == null then
+                       print("???: {str}\n")
+               else
+                       print("{location}: {str}\n")
+               end
        end
 end
 
index 60a1ec9..e927a58 100644 (file)
@@ -64,19 +64,14 @@ redef class PNode
        # Thus, call "v.visit(e)" for each node e starting from the last child
        fun visit_all_reverse(v: Visitor) is abstract
 
-       # Give a human readable location of the node.
-       fun locate: String
-       do
-               if location == null then
-                       return "????"
-               end
-               return location.to_s
-       end
-
        # Debug method: output a message prefixed with the location.
        fun printl(str: String)
        do
-               print("{locate}: {str}\n")
+               if location == null then
+                       print("???: {str}\n")
+               else
+                       print("{location}: {str}\n")
+               end
        end
 end
 
index 44d1270..1509473 100644 (file)
@@ -51,7 +51,8 @@ abstract class VariableContext
                        _visitor.error(n, "Error: variable '{v}' is possibly unset.")
                        var x = self
                        while true do
-                               print "  {x.node.locate}: {x._set_variables.join(", ")} ; {x._dico.join(", ")}"
+                               var loc = x.node.location
+                               print "  {if loc != null then loc.to_s else "????"}: {x._set_variables.join(", ")} ; {x._dico.join(", ")}"
                                var x0 = x
                                if x0 isa SubVariableContext then
                                        x = x0.prev
@@ -183,7 +184,7 @@ abstract class VariableContext
        redef fun to_s
        do
                var s = new Buffer
-               s.append(node.locate)
+               s.append(node.location.to_s)
                for v in _all_variables do
                        var t = stype(v)
                        if t == null then continue
index 942dea7..b9a026a 100644 (file)
@@ -450,7 +450,7 @@ redef class AModule
                end
                if no_import != null then
                        if not module_names_to_import.is_empty then
-                               tc.error(null, "{no_import.locate}: Error: Top modules cannot import other modules.")
+                               tc.error(no_import.location, "Error: Top modules cannot import other modules.")
                        end
                else if module_names_to_import.is_empty then
                        var stdname = once "standard".to_symbol
index 6cd9022..8f38abd 100644 (file)
@@ -37,7 +37,7 @@ special ModuleLoader
                if node_tree.n_base == null then
                        var err = node_tree.n_eof
                        assert err isa PError
-                       context.fatal_error(err.location, "{err.locate}: {err.message}")
+                       context.fatal_error(err.location, err.message)
                end
                var node_module = node_tree.n_base
                assert node_module isa AModule
index 351fe86..96cb5f1 100644 (file)
@@ -355,26 +355,19 @@ special Visitor
        # Display an error for a given syntax node
        fun error(n: nullable PNode, s: String)
        do
-               _tc.error(n.location, "{locate(n)}: {s}")
+               _tc.error(if n == null then null else n.location, 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}")
+               _tc.fatal_error(if n == null then null else n.location, s)
        end
 
        # Display a warning for a given syntax node
        fun warning(n: nullable PNode, s: String)
        do
-               _tc.warning(n.location, "{locate(n)}: {s}")
-       end
-
-       #
-       fun locate(n: nullable PNode): String
-       do
-               if n != null then return n.locate
-               return _module.location.file
+               _tc.warning(if n == null then null else n.location, s)
        end
 
        # Check conformity and display error
@@ -397,7 +390,12 @@ special Visitor
        do
                if not n.is_typed then
                        if tc.error_count == 0 then
-                               print("{n.locate} not typed but not error")
+                               var loc = n.location
+                               if loc == null then
+                                       print("Unknown node not typed but not error")
+                               else
+                                       print("{loc} not typed but not error")
+                               end
                                abort
                        end
                        # An error occured in a sub node,
index c29bffe..c74cd70 100644 (file)
@@ -302,11 +302,11 @@ redef class PExpr
        redef fun stype
        do
                if not is_typed then
-                       print "{locate}: not is_typed"
+                       print "{location}: not is_typed"
                        abort
                end
                if is_statement then
-                       print "{locate}: is_statement"
+                       print "{location}: is_statement"
                        abort
                end
                return _stype.as(not null)