more 2.7 control flow bug fixing

This commit is contained in:
rocky 2016-11-20 06:55:08 -05:00
parent 195bbc746b
commit 2bc316d6f0
3 changed files with 10 additions and 5 deletions

View File

@ -41,7 +41,7 @@ def test_if_in_for():
scan.build_lines_data(code, n)
scan.build_prev_op(n)
fjt = scan.find_jump_targets(False)
assert{64: [42], 67: [42], 42: [16, 41], 19: [6]} == fjt
assert{64: [42], 67: [42, 42], 42: [16, 41], 19: [6]} == fjt
assert scan.structs == [
{'start': 0, 'end': 80, 'type': 'root'},
{'start': 3, 'end': 64, 'type': 'if-then'},

View File

@ -45,7 +45,10 @@ class Python27Parser(Python2Parser):
def p_jump27(self, args):
"""
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD COME_FROM
come_froms ::= come_froms COME_FROM
come_froms ::= COME_FROM
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD come_froms
bp_come_from ::= POP_BLOCK COME_FROM
# FIXME: Common with 3.0+

View File

@ -875,8 +875,9 @@ class Scanner2(scan.Scanner):
oparg = self.get_argument(offset)
if label is None:
if (op in self.opc.hasjrel and
(self.version < 2.0 or op != self.opc.FOR_ITER)):
if op in self.opc.hasjrel and self.opc.opname[op] != 'FOR_ITER':
# if (op in self.opc.hasjrel and
# (self.version < 2.0 or op != self.opc.FOR_ITER)):
label = offset + 3 + oparg
elif self.version == 2.7 and op in self.opc.hasjabs:
if op in (self.opc.JUMP_IF_FALSE_OR_POP,
@ -906,7 +907,7 @@ class Scanner2(scan.Scanner):
and code[offset+4] == self.opc.END_FINALLY))):
# FIXME: rocky: I think we need something like this...
if offset not in set(self.ignore_if):
if offset not in set(self.ignore_if) or self.version == 2.7:
source = (self.setup_loops[label]
if label in self.setup_loops else offset)
targets[label] = targets.get(label, []) + [source]
@ -922,6 +923,7 @@ class Scanner2(scan.Scanner):
# DEBUG:
if debug in ('both', 'after'):
print(targets)
import pprint as pp
pp.pprint(self.structs)