You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
2.6 try statement (and below)
They may neeed arbitrary come_froms for each except clause
This commit is contained in:
@@ -22,10 +22,6 @@ class Python26Parser(Python2Parser):
|
||||
except_cond3 ::= DUP_TOP expr COMPARE_OP
|
||||
JUMP_IF_FALSE POP_TOP POP_TOP designator POP_TOP
|
||||
|
||||
# Might be a bug from when COME_FROM wasn't properly handled
|
||||
try_middle ::= JUMP_FORWARD COME_FROM except_stmts
|
||||
POP_TOP END_FINALLY come_froms
|
||||
|
||||
try_middle ::= JUMP_FORWARD COME_FROM except_stmts
|
||||
come_from_pop END_FINALLY COME_FROM
|
||||
|
||||
@@ -43,6 +39,9 @@ class Python26Parser(Python2Parser):
|
||||
trystmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
||||
try_middle
|
||||
|
||||
trystmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
||||
try_middle come_froms
|
||||
|
||||
tryelsestmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
||||
try_middle else_suite come_froms
|
||||
|
||||
|
@@ -143,13 +143,19 @@ class Scanner2(scan.Scanner):
|
||||
extended_arg = 0
|
||||
for offset in self.op_range(0, n):
|
||||
if offset in jump_targets:
|
||||
k = 0
|
||||
for j in jump_targets[offset]:
|
||||
jump_idx = 0
|
||||
# We want to process COME_FROMs to the same offset to be in *descending*
|
||||
# offset order so we have the larger range or biggest instruction interval
|
||||
# last. (I think they are sorted in increasing order, but for safety
|
||||
# we sort them). That way, specific COME_FROM tags will match up
|
||||
# properly. For example, a "loop" with an "if" nested in it should have the
|
||||
# "loop" tag last so the grammar rule matches that properly.
|
||||
for jump_offset in sorted(jump_targets[offset], reverse=True):
|
||||
tokens.append(Token(
|
||||
'COME_FROM', None, repr(j),
|
||||
offset="%s_%d" % (offset, k),
|
||||
'COME_FROM', None, repr(jump_offset),
|
||||
offset="%s_%d" % (offset, jump_idx),
|
||||
has_arg = True))
|
||||
k += 1
|
||||
jump_idx += 1
|
||||
|
||||
op = self.code[offset]
|
||||
opname = self.opc.opname[op]
|
||||
|
@@ -169,12 +169,19 @@ class Scanner26(scan.Scanner2):
|
||||
oparg = None; pattr = None
|
||||
|
||||
if offset in jump_targets:
|
||||
k = 0
|
||||
for j in jump_targets[offset]:
|
||||
tokens.append(Token('COME_FROM', None, repr(j),
|
||||
offset="%s_%d" % (offset, k),
|
||||
has_arg = True))
|
||||
k += 1
|
||||
jump_idx = 0
|
||||
# We want to process COME_FROMs to the same offset to be in *descending*
|
||||
# offset order so we have the larger range or biggest instruction interval
|
||||
# last. (I think they are sorted in increasing order, but for safety
|
||||
# we sort them). That way, specific COME_FROM tags will match up
|
||||
# properly. For example, a "loop" with an "if" nested in it should have the
|
||||
# "loop" tag last so the grammar rule matches that properly.
|
||||
for jump_offset in sorted(jump_targets[offset], reverse=True):
|
||||
tokens.append(Token(
|
||||
'COME_FROM', None, repr(jump_offset),
|
||||
offset="%s_%d" % (offset, jump_idx),
|
||||
has_arg = True))
|
||||
jump_idx += 1
|
||||
|
||||
has_arg = (op >= self.opc.HAVE_ARGUMENT)
|
||||
if has_arg:
|
||||
|
Reference in New Issue
Block a user