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:
rocky
2016-09-26 08:31:28 -04:00
parent c87710dd4b
commit 1fc8ac4700
5 changed files with 74 additions and 56 deletions

View File

@@ -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))