[pypy-svn] r13829 - pypy/dist/pypy/tool

tismer at codespeak.net tismer at codespeak.net
Fri Jun 24 21:02:01 CEST 2005


Author: tismer
Date: Fri Jun 24 21:02:00 2005
New Revision: 13829

Modified:
   pypy/dist/pypy/tool/asterisk.py
Log:
started to resolve line numbers.
going home for today, my stomach hurts...

Modified: pypy/dist/pypy/tool/asterisk.py
==============================================================================
--- pypy/dist/pypy/tool/asterisk.py	(original)
+++ pypy/dist/pypy/tool/asterisk.py	Fri Jun 24 21:02:00 2005
@@ -8,6 +8,8 @@
 Then examine each 'import *' by importing that module
 and looking for those globals.
 Replace the 'import *' by the list found.
+More advanced: If the new import has more than, say, 5 entries,
+rewrite the import to use module.name throughout the source.
 """
 
 import dis, cStringIO, sys
@@ -20,7 +22,18 @@
         return sys.stdout.getvalue()
     finally:
         sys.stdout = hold
-    
+
+def offset2lineno(c, stopat):
+    tab = c.co_lnotab
+    line = c.co_firstlineno
+    addr = 0
+    for i in range(0, len(tab), 2):
+        addr = addr + ord(tab[i])
+        if addr > stopat:
+            break
+        line = line + ord(tab[i+1])
+    return line
+
 def globalsof(code, globrefs=None, stars=None, globals=None):
     names = code.co_names
     vars = code.co_varnames
@@ -106,9 +119,9 @@
             which[star] = []
             for key in self.get_from_star(star).keys():
                 implicit[key] = star
-        # sort out in which star import we find what
-        # note that we walked star imports in order
-        # so we are sure to resolve ambiguities correctly
+        # sort out in which star import we find what.
+        # note that we walked star imports in order,
+        # so we are sure to resolve ambiguities correctly.
         for name in self.get_unknown_globals():
             mod = implicit[name]
             which[mod].append(name)



More information about the Pypy-commit mailing list