You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +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
|
except_cond3 ::= DUP_TOP expr COMPARE_OP
|
||||||
JUMP_IF_FALSE POP_TOP POP_TOP designator POP_TOP
|
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
|
try_middle ::= JUMP_FORWARD COME_FROM except_stmts
|
||||||
come_from_pop END_FINALLY COME_FROM
|
come_from_pop END_FINALLY COME_FROM
|
||||||
|
|
||||||
@@ -43,6 +39,9 @@ class Python26Parser(Python2Parser):
|
|||||||
trystmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
trystmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
||||||
try_middle
|
try_middle
|
||||||
|
|
||||||
|
trystmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
||||||
|
try_middle come_froms
|
||||||
|
|
||||||
tryelsestmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
tryelsestmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
||||||
try_middle else_suite come_froms
|
try_middle else_suite come_froms
|
||||||
|
|
||||||
|
@@ -143,13 +143,19 @@ class Scanner2(scan.Scanner):
|
|||||||
extended_arg = 0
|
extended_arg = 0
|
||||||
for offset in self.op_range(0, n):
|
for offset in self.op_range(0, n):
|
||||||
if offset in jump_targets:
|
if offset in jump_targets:
|
||||||
k = 0
|
jump_idx = 0
|
||||||
for j in jump_targets[offset]:
|
# 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(
|
tokens.append(Token(
|
||||||
'COME_FROM', None, repr(j),
|
'COME_FROM', None, repr(jump_offset),
|
||||||
offset="%s_%d" % (offset, k),
|
offset="%s_%d" % (offset, jump_idx),
|
||||||
has_arg = True))
|
has_arg = True))
|
||||||
k += 1
|
jump_idx += 1
|
||||||
|
|
||||||
op = self.code[offset]
|
op = self.code[offset]
|
||||||
opname = self.opc.opname[op]
|
opname = self.opc.opname[op]
|
||||||
|
@@ -169,12 +169,19 @@ class Scanner26(scan.Scanner2):
|
|||||||
oparg = None; pattr = None
|
oparg = None; pattr = None
|
||||||
|
|
||||||
if offset in jump_targets:
|
if offset in jump_targets:
|
||||||
k = 0
|
jump_idx = 0
|
||||||
for j in jump_targets[offset]:
|
# We want to process COME_FROMs to the same offset to be in *descending*
|
||||||
tokens.append(Token('COME_FROM', None, repr(j),
|
# offset order so we have the larger range or biggest instruction interval
|
||||||
offset="%s_%d" % (offset, k),
|
# last. (I think they are sorted in increasing order, but for safety
|
||||||
has_arg = True))
|
# we sort them). That way, specific COME_FROM tags will match up
|
||||||
k += 1
|
# 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)
|
has_arg = (op >= self.opc.HAVE_ARGUMENT)
|
||||||
if has_arg:
|
if has_arg:
|
||||||
|
Reference in New Issue
Block a user