[pypy-svn] r10223 - pypy/dist/pypy/translator/tool

pedronis at codespeak.net pedronis at codespeak.net
Fri Apr 1 17:06:52 CEST 2005


Author: pedronis
Date: Fri Apr  1 17:06:52 2005
New Revision: 10223

Modified:
   pypy/dist/pypy/translator/tool/graphpage.py
Log:
start refactoring of graph pages to work on supporting workaround displays when the whole call graph is too huge



Modified: pypy/dist/pypy/translator/tool/graphpage.py
==============================================================================
--- pypy/dist/pypy/translator/tool/graphpage.py	(original)
+++ pypy/dist/pypy/translator/tool/graphpage.py	Fri Apr  1 17:06:52 2005
@@ -175,58 +175,21 @@
         
         self.source = dotgen.generate(target=None)
 
+class BaseTranslatorPage(GraphPage):
+    """Abstract GraphPage for showing some of the call graph between functions
+    and possibily the class hierarchy."""
 
-class TranslatorPage(GraphPage):
-    """A GraphPage showing a the call graph between functions
-    as well as the class hierarchy."""
+    def graph_name(self, *args):
+        raise NotImplementedError
 
-    def compute(self, translator):
+    def compute(self, translator, *args):
         self.translator = translator
         self.object_by_name = {}
         self.name_by_object = {}
-        dotgen = DotGen('translator')
+        dotgen = DotGen(self.graph_name(*args))
         dotgen.emit('mclimit=15.0')
 
-        # show the call graph
-        functions = translator.functions
-        blocked_functions = {}
-        if translator.annotator:
-            # don't use translator.annotator.blocked_functions here because
-            # it is not populated until the annotator finishes.
-            annotated = translator.annotator.annotated
-            for fn, graph in translator.flowgraphs.items():
-                def visit(node):
-                    if annotated.get(node) is False:
-                        blocked_functions[fn] = True
-                traverse(visit, graph)
-        highlight_functions = getattr(translator, 'highlight_functions', {}) # XXX
-        dotgen.emit_node('entry', fillcolor="green", shape="octagon",
-                         label="Translator\\nEntry Point")
-        for func in functions:
-            name = func.func_name
-            class_ = getattr(func, 'class_', None)
-            if class_ is not None:
-                name = '%s.%s' % (class_.__name__, name)
-            data = self.labelof(func, name)
-            if func in blocked_functions:
-                kw = {'fillcolor': 'red'}
-            elif func in highlight_functions:
-                kw = {'fillcolor': '#ffcccc'}
-            else:
-                kw = {}
-            dotgen.emit_node(nameof(func), label=data, shape="box", **kw)
-        dotgen.emit_edge('entry', nameof(functions[0]), color="green")
-        for f1, f2 in translator.callgraph.itervalues():
-            dotgen.emit_edge(nameof(f1), nameof(f2))
-
-        # show the class hierarchy
-        if self.translator.annotator:
-            dotgen.emit_node(nameof(None), color="red", shape="octagon",
-                             label="Root Class\\nobject")
-            for classdef in self.translator.annotator.getuserclassdefinitions():
-                data = self.labelof(classdef, classdef.cls.__name__)
-                dotgen.emit_node(nameof(classdef), label=data, shape="box")
-                dotgen.emit_edge(nameof(classdef.basedef), nameof(classdef))
+        self.do_compute(dotgen, *args)
         
         self.source = dotgen.generate(target=None)
 
@@ -246,6 +209,32 @@
                                       source.split('\n')[0])
             self.links[name] = data
 
+    def get_blocked_functions(self, functions):
+        translator = self.translator
+        blocked_functions = {}
+        if translator.annotator:
+            # don't use translator.annotator.blocked_functions here because
+            # it is not populated until the annotator finishes.
+            annotated = translator.annotator.annotated
+            for fn in functions:
+                graph = translator.flowgraphs[fn]
+                def visit(node):
+                    if annotated.get(node) is False:
+                        blocked_functions[fn] = True
+                traverse(visit, graph)
+
+        return blocked_functions
+
+    def compute_class_hieararchy(self, dotgen):
+        # show the class hierarchy
+        if self.translator.annotator:
+            dotgen.emit_node(nameof(None), color="red", shape="octagon",
+                             label="Root Class\\nobject")
+            for classdef in self.translator.annotator.getuserclassdefinitions():
+                data = self.labelof(classdef, classdef.cls.__name__)
+                dotgen.emit_node(nameof(classdef), label=data, shape="box")
+                dotgen.emit_edge(nameof(classdef.basedef), nameof(classdef))
+             
     def labelof(self, obj, objname):
         name = objname
         i = 1
@@ -263,6 +252,43 @@
         else:
             return FlowGraphPage(self.translator, [obj], self.name_by_object)
 
+class TranslatorPage(BaseTranslatorPage):
+    """A GraphPage showing a the call graph between functions
+    as well as the class hierarchy."""
+
+    def graph_name(self):
+        return 'translator'
+
+    def do_compute(self, dotgen):
+        translator = self.translator
+
+        # show the call graph
+        functions = translator.functions
+        blocked_functions = self.get_blocked_functions(functions)
+
+        highlight_functions = getattr(translator, 'highlight_functions', {}) # XXX
+        dotgen.emit_node('entry', fillcolor="green", shape="octagon",
+                         label="Translator\\nEntry Point")
+        for func in functions:
+            name = func.func_name
+            class_ = getattr(func, 'class_', None)
+            if class_ is not None:
+                name = '%s.%s' % (class_.__name__, name)
+            data = self.labelof(func, name)
+            if func in blocked_functions:
+                kw = {'fillcolor': 'red'}
+            elif func in highlight_functions:
+                kw = {'fillcolor': '#ffcccc'}
+            else:
+                kw = {}
+            dotgen.emit_node(nameof(func), label=data, shape="box", **kw)
+        dotgen.emit_edge('entry', nameof(functions[0]), color="green")
+        for f1, f2 in translator.callgraph.itervalues():
+            dotgen.emit_edge(nameof(f1), nameof(f2))
+
+        # show the class hierarchy
+        self.compute_class_hieararchy(dotgen)
+
 
 def nameof(obj, cache={}):
     # NB. the purpose of the cache is not performance, but to ensure that



More information about the Pypy-commit mailing list