| Server IP : 93.86.61.54 / Your IP : 216.73.216.156 Web Server : Apache/2.4.62 (Ubuntu) System : Linux rasin.ddns.net 6.8.0-124-generic #124~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 21:05:19 UTC x86_64 User : www-data ( 33) PHP Version : 8.4.22 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /lib/python3/dist-packages/pythran/optimizations/ |
Upload File : |
""" DeadCodeElimination remove useless code. """
from pythran.analyses import DefUseChains
from pythran.passmanager import Transformation
import pythran.metadata as metadata
class RemoveDeadFunctions(Transformation):
"""
Remove useless local functions
>>> import gast as ast
>>> from pythran import passmanager, backend, metadata
>>> pm = passmanager.PassManager("test")
>>> node = ast.parse("def foo(): return 1")
>>> _, node = pm.apply(RemoveDeadFunctions, node)
>>> print(pm.dump(backend.Python, node))
def foo():
return 1
>>> node = ast.parse("def foo(): return 1")
>>> metadata.add(node.body[0], metadata.Local())
>>> _, node = pm.apply(RemoveDeadFunctions, node)
>>> print(pm.dump(backend.Python, node))
<BLANKLINE>
"""
def __init__(self):
super(RemoveDeadFunctions, self).__init__(DefUseChains)
def visit_FunctionDef(self, node):
if metadata.get(node, metadata.Local):
if not self.def_use_chains.chains[node].users():
self.update = True
return None
return node