You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Interval order COME_FROMs in Python3
This bug had possibly caused lots of grammar pollution which may need addressing. We want to process COME_FROMs to the same offset to be in *descending* 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 Adjust Python 3 grammar for more COME_FROM -> COME_FROM_LOOP. And remove optional COME_FROM_LOOP where possible. Previously, the optional-ness was a result of inner nestings gobbling up the COME_FROM. We'll probably want to go back and fix this up in Python2.
This commit is contained in:
@@ -198,14 +198,21 @@ class Scanner3(Scanner):
|
||||
argval = inst.argval
|
||||
if inst.offset in jump_targets:
|
||||
jump_idx = 0
|
||||
for jump_offset in jump_targets[inst.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[inst.offset], reverse=True):
|
||||
come_from_name = 'COME_FROM'
|
||||
if (inst.offset in offset_action):
|
||||
action = offset_action[inst.offset]
|
||||
if (action.type == 'end'
|
||||
# Adjust the grammar and remove the below
|
||||
and (self.opName(jump_offset)[len('SETUP_'):]
|
||||
== action.name)
|
||||
# After the grammar is fully adjusted, remove the below
|
||||
# test
|
||||
and action.name in ['EXCEPT', 'LOOP', 'WITH']):
|
||||
come_from_name = '%s_%s' % (
|
||||
(come_from_name, action.name))
|
||||
|
Reference in New Issue
Block a user