[pypy-svn] r7324 - in pypy/trunk/src/pypy: annotation translator/tool/pygame

mgedmin at codespeak.net mgedmin at codespeak.net
Wed Nov 17 15:30:19 CET 2004


Author: mgedmin
Date: Wed Nov 17 15:30:18 2004
New Revision: 7324

Modified:
   pypy/trunk/src/pypy/annotation/model.py
   pypy/trunk/src/pypy/translator/tool/pygame/flowviewer.py
Log:
Show the origin of an annotation (if it is available) in the variable bindings
history graph.



Modified: pypy/trunk/src/pypy/annotation/model.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/model.py	(original)
+++ pypy/trunk/src/pypy/annotation/model.py	Wed Nov 17 15:30:18 2004
@@ -65,7 +65,7 @@
             SomeObject._coming_from[id(self)] = position_key
         return self
     def origin(self):
-        return SomeObject._coming_from[id(self)]
+        return SomeObject._coming_from.get(id(self), None)
     origin = property(origin)
 
 

Modified: pypy/trunk/src/pypy/translator/tool/pygame/flowviewer.py
==============================================================================
--- pypy/trunk/src/pypy/translator/tool/pygame/flowviewer.py	(original)
+++ pypy/trunk/src/pypy/translator/tool/pygame/flowviewer.py	Wed Nov 17 15:30:18 2004
@@ -19,28 +19,32 @@
 class VariableHistoryGraphLayout(GraphLayout):
     """ A GraphLayout showing the history of variable bindings. """
 
-    def __init__(self, translator, info, caused_by, history, func_names):
+    def __init__(self, translator, name, info, caused_by, history, func_names):
         self.links = {}
         self.func_by_name = {}
         self.translator = translator
         self.func_names = func_names
         dotgen = DotGen('binding')
-        label = "Most recent binding\\n\\n%s" % nottoowide(info)
+        label = "Most recent binding of %s\\n\\n%s" % (name, nottoowide(info))
+        if info.origin is not None:
+            label += "\\n" + self.createlink(info.origin, 'Originated at')
         if caused_by is not None:
-            label += '\\n' + self.createlink(caused_by)
+            label += '\\n' + self.createlink(caused_by.position_key)
         dotgen.emit_node('0', shape="box", color="red", label=label)
         for n, (data, caused_by) in zip(range(len(history)), history):
             label = nottoowide(data)
+            if data.origin is not None:
+                label += "\\n" + self.createlink(data.origin, 'Originated at')
             if caused_by is not None:
-                label += '\\n' + self.createlink(caused_by)
+                label += '\\n' + self.createlink(caused_by.position_key)
             dotgen.emit_node(str(n+1), shape="box", label=label)
             dotgen.emit_edge(str(n+1), str(n))
         links = self.links  # GraphLayout.__init__ will override it with {}
         GraphLayout.__init__(self, dotgen.generate(target='plain'))
         self.links.update(links)
 
-    def createlink(self, factory):
-        fn, block, pos = factory.position_key
+    def createlink(self, position_key, wording='Caused by a call from'):
+        fn, block, pos = position_key
         fn_name = self.func_names.get(fn, fn.func_name)
         basename = fn_name
         n = 1
@@ -52,7 +56,7 @@
         blockname = block.__class__.__name__
         self.links[fn_name] = '%s, %s, position %r' % (basename, blockname,
                                                        pos)
-        return 'Caused by a call from %s' % fn_name
+        return '%s %s' % (wording, fn_name)
 
     def followlink(self, funcname):
         func = self.func_by_name[funcname]
@@ -75,12 +79,14 @@
         GraphLayout.__init__(self, fn)
         # make the dictionary of links -- one per annotated variable
         self.binding_history = {}
+        self.current_value = {}
         self.caused_by = {}
         if self.annotator:
             for var in self.annotator.bindings:
                 s_value = self.annotator.binding(var)
                 info = '%s: %s' % (var.name, s_value)
                 self.links[var.name] = info
+                self.current_value[var.name] = s_value
                 self.caused_by[var.name] = self.annotator.binding_caused_by[var]
             for var, history in self.annotator.bindingshistory.items():
                 cause_history = self.annotator.binding_cause_history[var]
@@ -88,12 +94,12 @@
 
     def followlink(self, varname):
         # clicking on a variable name shows its binding history
-        info = self.links[varname]
+        cur_value = self.current_value[varname]
         caused_by = self.caused_by[varname]
         history = list(self.binding_history.get(varname, []))
         history.reverse()
-        return VariableHistoryGraphLayout(self.translator, info, caused_by,
-                                          history, self.func_names)
+        return VariableHistoryGraphLayout(self.translator, varname, cur_value,
+                                          caused_by, history, self.func_names)
 
 
 def nottoowide(text, width=72):



More information about the Pypy-commit mailing list