changeset 189:67503a9dd613

util: errors are printed to be read by the eclipse plugin
author Sigurd Meldgaard <stm@daimi.au.dk>
date Wed, 16 Dec 2009 15:21:17 +0100
parents 4b8cd0370fa7
children d26bcb7dc691
files pysmcl/util.py
diffstat 1 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/pysmcl/util.py	Wed Dec 16 15:20:37 2009 +0100
+++ b/pysmcl/util.py	Wed Dec 16 15:21:17 2009 +0100
@@ -1,10 +1,19 @@
+import pysmcl.pretty_print as pp
+import pysmcl.ast_wrapper as ast
+
 """ Utilities for the static analysis tool
 """
 def error(msg, loc=None):
     """Print the error message.
     *loc* is an ast-node at the given location."""
-    loc_tuple = (loc.lineno, loc.col_offset)
-#    print ast.dump(loc)
     if loc:
-        print "at %s" % (loc_tuple, ),
-    print msg
+        if isinstance(loc, ast.expr):
+            l = len(pp.expr_string(loc))
+        elif isinstance(loc, ast.stmt):
+            l = len(pp.pprint_string(loc))
+        else:
+            raise "Loc must be an expression or statement node"
+        loc_tuple = (loc.lineno, loc.col_offset, l)
+    else:
+        loc_tuple = (0,0,1)
+    print "error: %d %d %d (%s)" % (loc_tuple + (msg,))