[pypy-svn] r7447 - in pypy/trunk/src/pypy: annotation objspace/flow translator/tool translator/tool/pygame
mgedmin at codespeak.net
mgedmin at codespeak.net
Fri Nov 19 16:06:35 CET 2004
Author: mgedmin
Date: Fri Nov 19 16:06:34 2004
New Revision: 7447
Modified:
pypy/trunk/src/pypy/annotation/factory.py
pypy/trunk/src/pypy/objspace/flow/flowcontext.py
pypy/trunk/src/pypy/objspace/flow/objspace.py
pypy/trunk/src/pypy/translator/tool/make_dot.py
pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py
pypy/trunk/src/pypy/translator/tool/pygame/flowviewer.py
Log:
Annotator now remembers which functions are really methods by putting the class
into func_dict. Flow graphs now show class names for methods.
Modified: pypy/trunk/src/pypy/annotation/factory.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/factory.py (original)
+++ pypy/trunk/src/pypy/annotation/factory.py Fri Nov 19 16:06:34 2004
@@ -14,6 +14,7 @@
from pypy.annotation.model import unionof, immutablevalue
from pypy.interpreter.miscutils import getthreadlocals
from pypy.interpreter.pycode import CO_VARARGS
+from pypy.tool.hack import func_with_new_name
class BlockedInference(Exception):
@@ -168,6 +169,7 @@
if func.im_self is not None:
s_self = immutablevalue(func.im_self)
args = [s_self] + list(args)
+ func.im_func.class_ = func.im_class
func = func.im_func
assert isinstance(func, FunctionType), "expected function, got %r"%func
# do we need to specialize this function in several versions?
@@ -198,11 +200,7 @@
if isinstance(thing, FunctionType):
# XXX XXX XXX HAAAAAAAAAAAACK
self.bookkeeper.annotator.translator.getflowgraph(thing)
- thing = new.function(thing.func_code,
- thing.func_globals,
- name or thing.func_name,
- thing.func_defaults,
- thing.func_closure)
+ thing = func_with_new_name(thing, name or thing.func_name)
elif isinstance(thing, (type, ClassType)):
assert not "not working yet"
thing = type(thing)(name or thing.__name__, (thing,))
@@ -237,6 +235,8 @@
# ignore some special attributes
if name.startswith('_') and not isinstance(value, FunctionType):
continue
+ if isinstance(value, FunctionType):
+ value.class_ = cls # remember that this is really a method
# although self.getallfactories() is currently empty,
# the following might still invalidate some blocks if it
# generalizes existing values in parent classes
Modified: pypy/trunk/src/pypy/objspace/flow/flowcontext.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/flowcontext.py (original)
+++ pypy/trunk/src/pypy/objspace/flow/flowcontext.py Fri Nov 19 16:06:34 2004
@@ -75,7 +75,8 @@
class FlowExecutionContext(ExecutionContext):
- def __init__(self, space, code, globals, constargs={}, closure=None):
+ def __init__(self, space, code, globals, constargs={}, closure=None,
+ name=None):
ExecutionContext.__init__(self, space)
self.code = code
self.w_globals = w_globals = space.wrap(globals)
@@ -95,7 +96,7 @@
self.joinpoints[joinpoint] = [] # list of blocks
initialblock = SpamBlock(FrameState(frame).copy())
self.pendingblocks = [initialblock]
- self.graph = FunctionGraph(code.co_name, initialblock)
+ self.graph = FunctionGraph(name or code.co_name, initialblock)
def create_frame(self):
# create an empty frame suitable for the code object
Modified: pypy/trunk/src/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/objspace.py (original)
+++ pypy/trunk/src/pypy/objspace/flow/objspace.py Fri Nov 19 16:06:34 2004
@@ -115,14 +115,17 @@
closure = None
else:
closure = [extract_cell_content(c) for c in func.func_closure]
- ec = flowcontext.FlowExecutionContext(self, code, func.func_globals,
- constargs, closure)
- self.setup_executioncontext(ec)
- ec.build_flow()
+ # CallableFactory.pycall may add class_ to functions that are methods
name = func.func_name
+ class_ = getattr(func, 'class_', None)
+ if class_ is not None:
+ name = '%s.%s' % (class_.__name__, name)
for c in "<>&!":
name = name.replace(c, '_')
- ec.graph.name = name
+ ec = flowcontext.FlowExecutionContext(self, code, func.func_globals,
+ constargs, closure, name)
+ self.setup_executioncontext(ec)
+ ec.build_flow()
checkgraph(ec.graph)
return ec.graph
Modified: pypy/trunk/src/pypy/translator/tool/make_dot.py
==============================================================================
--- pypy/trunk/src/pypy/translator/tool/make_dot.py (original)
+++ pypy/trunk/src/pypy/translator/tool/make_dot.py Fri Nov 19 16:06:34 2004
@@ -10,7 +10,7 @@
from py.process import cmdexec
class DotGen:
-
+
def __init__(self, graphname, rankdir=None):
self.graphname = graphname
self.lines = []
@@ -72,7 +72,11 @@
class FlowGraphDotGen(DotGen):
+ def __init__(self, graphname, rankdir=None):
+ DotGen.__init__(self, graphname.replace('.', '_'), rankdir)
+
def emit_subgraph(self, name, node):
+ name = name.replace('.', '_')
self.blocks = {}
self.prefix = name
self.enter_subgraph(name)
@@ -93,7 +97,7 @@
def visit_FunctionGraph(self, funcgraph):
name = self.prefix # +'_'+funcgraph.name
- data = name
+ data = funcgraph.name
if hasattr(funcgraph, 'source'):
source = funcgraph.source.replace('"', '\\"')
data += "\\n" + "\\l".join(source.split('\n'))
Modified: pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py
==============================================================================
--- pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py (original)
+++ pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py Fri Nov 19 16:06:34 2004
@@ -17,7 +17,7 @@
'red': (255,0,0),
'green': (0,255,0),
}
-re_nonword=re.compile(r'(\W+)')
+re_nonword=re.compile(r'([^0-9a-zA-Z_.]+)')
def highlight_color(color):
intensity = sum(color)
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 Fri Nov 19 16:06:34 2004
@@ -164,7 +164,11 @@
dotgen.emit_node('entry', fillcolor="green", shape="octagon",
label="Translator\\nEntry Point")
for func in functions:
- data = self.labelof(func, func.func_name)
+ 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 highlight_functions:
kw = {'fillcolor': '#ffcccc'}
else:
More information about the Pypy-commit
mailing list