Debian Codegraph @

rpython/flowspace/pygraph.py

raw symbols SCIP
1 """
2 Implements flow graphs for Python callables
3 """
4 from rpython.flowspace.model import FunctionGraph, Constant, Variable
5 from rpython.flowspace.framestate import FrameState
6
7 class PyGraph(FunctionGraph):
8 """
9 Flow graph for a Python function
10 """
11
12 def __init__(self, func, code):
13 from rpython.flowspace.flowcontext import SpamBlock
14 locals = [None] * code.co_nlocals
15 for i in range(code.formalargcount):
16 locals[i] = Variable(code.co_varnames[i])
17 state = FrameState(locals, [], None, [], 0)
18 initialblock = SpamBlock(state)
19 super(PyGraph, self).__init__(self._sanitize_funcname(func), initialblock)
20 self.func = func
21 self.signature = code.signature
22 self.defaults = func.__defaults__ or ()
23
24 @staticmethod
25 def _sanitize_funcname(func):
26 # CallableFactory.pycall may add class_ to functions that are methods
27 name = func.__name__
28 class_ = getattr(func, 'class_', None)
29 if class_ is not None:
30 name = '%s.%s' % (class_.__name__, name)
31 for c in "<>&!":
32 name = name.replace(c, '_')
33 return name