You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 09:22:40 +08:00
Reduce spurious "continue" statements
This commit is contained in:
@@ -519,6 +519,25 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
node == AST('return_stmt',
|
||||
[AST('ret_expr', [NONE]), Token('RETURN_VALUE')]))
|
||||
|
||||
def n_continue_stmt(self, node):
|
||||
if node[0] == 'CONTINUE':
|
||||
t = node[0]
|
||||
if not t.linestart:
|
||||
# Artificially-added "continue" statements derived from JUMP_ABSOLUTE
|
||||
# don't have line numbers associated with them.
|
||||
# If this is a CONTINUE is to the same target as a JUMP_ABSOLUTE following it,
|
||||
# then the "continue" can be suppressed.
|
||||
op, offset = t.op, t.offset
|
||||
next_offset = self.scanner.next_offset(op, offset)
|
||||
scanner = self.scanner
|
||||
code = scanner.code
|
||||
next_inst = code[next_offset]
|
||||
if (scanner.opc.opname[next_inst] == 'JUMP_ABSOLUTE'
|
||||
and t.pattr == code[next_offset+1]):
|
||||
# Suppress "continue"
|
||||
self.prune()
|
||||
self.default(node)
|
||||
|
||||
def n_return_stmt(self, node):
|
||||
if self.params['isLambda']:
|
||||
self.preorder(node[0])
|
||||
|
Reference in New Issue
Block a user